Skip to content

Commit 0096b2e

Browse files
committed
fix: limit value inline editor hight
fix: disable wrap in inline editor feat: dblclick value cells to open row editor feat: add option to toggle line wrap in row editor fix: disable resize in value textara in row editor chore: update tips fix: make Storage dropdown clearable
1 parent 24f6ec7 commit 0096b2e

File tree

3 files changed

+71
-31
lines changed

3 files changed

+71
-31
lines changed

sources/localstorage-editor/popup.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ body {
22
background: lightgray;
33
min-width: 640px;
44
min-height: 480px;
5-
padding: 0px;
5+
padding: 5px;
66
overflow: hidden;
77
}
88

@@ -17,3 +17,9 @@ button {
1717
#tip {
1818
font-size: 0.8em;
1919
}
20+
21+
.tabulator-cell.tabulator-editable textarea {
22+
min-height: calc(2 * 22px) !important;
23+
max-height: calc(10 * 22px) !important;
24+
white-space: nowrap !important;
25+
}

sources/localstorage-editor/popup.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<p>
1717
<label>
1818
Storage:
19-
<select disabled>
19+
<select>
2020
<option value="Local">Local</option>
2121
<option value="Session">Session</option>
2222
</select>
@@ -26,15 +26,20 @@
2626
<p>
2727
<label>
2828
Key:
29-
<input style="width: 100%" value="" disabled />
29+
<input style="width: 100%" value="" />
3030
</label>
3131
</p>
3232

3333
<p>
3434
<label>
3535
Value:
36+
<abbr title="toggle line wrap">
37+
<input type="checkbox" checked />
38+
(?)
39+
</abbr>
3640
<textarea
37-
style="width: 100%; height: 380px"
41+
style="width: 100%; height: 380px; white-space: nowrap; resize: none;"
42+
;
3843
spellcheck="false"
3944
></textarea>
4045
</label>
@@ -51,10 +56,9 @@
5156
<button id="impbtn" title="clipboard import">&darr;Import</button>
5257
<button id="cpybtn" title="copy selected">&uarr;Copy</button>
5358
<button id="expbtn" title="download selected">&uarr;Download</button>
54-
<abbr title="toggle inital check state"
59+
<abbr title="inital check state"
5560
><input type="checkbox" id="checkState" />(?)</abbr
5661
>
57-
<!-- button id="detachbtn" title="detach">Detach &#x21ea;</button -->
5862
</fieldset>
5963
<fieldset>
6064
<div id="log"></div>

sources/localstorage-editor/popup.js

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const confirmBtn = editDialog.querySelector("#confirmBtn");
1515
const selectEl = editDialog.querySelector("select"); // store
1616
const inputEl = editDialog.querySelector("input"); // key
1717
const textareaEl = editDialog.querySelector("textarea"); // value
18+
const wrapCheckboxEl = editDialog.querySelector('input[type="checkbox"]'); // key
1819

19-
let editorTempCell = null;
20+
let editorTempRow = null;
2021

2122
// button refs
2223
const impbtn = document.getElementById("impbtn");
@@ -30,14 +31,15 @@ const log = document.getElementById("log");
3031
const tip = document.getElementById("tip");
3132

3233
const tips = [
33-
"Duplicate items with Copy & Import quickly",
34-
"Filter do not change selections",
34+
"Duplicate items with Copy & Import",
35+
"Filter dont change selections",
3536
"Copy & Download act on selected items",
36-
"Imported items become selected after Import",
37-
"Hover Cells to show validation errors",
38-
"Reorder rows before Copy or Download",
39-
"Discard to drop all not submitted changes",
40-
"Middle click the toolbar button to open detached",
37+
"Imported items become selected",
38+
"Hover cells to show validation errors",
39+
"Reorder before Copy or Download",
40+
"Discard drops all not submitted changes",
41+
"Middle click the toolbar button to open it detached",
42+
"Double click on a value cell to open the row editor",
4143
];
4244

4345
let validateAndHighlightTimer;
@@ -274,10 +276,12 @@ var uniqueKey = function (cell, value, parameters) {
274276
return true;
275277
};
276278

279+
/*
280+
// when it contains linebreaks, we go into full editor mode
277281
var editCheck = function (cell) {
278-
const lines = cell.getValue().split(/\r\n|\r|\n/);
279-
return lines.length < 10;
282+
return cell.getValue().split(/\r\n|\r|\n/).length < 10;
280283
};
284+
*/
281285

282286
async function onDOMContentLoaded() {
283287
if (isNaN(TABID)) {
@@ -293,7 +297,7 @@ async function onDOMContentLoaded() {
293297
columnDefaults: {
294298
resizable: false,
295299
},
296-
placeholder: "No items found",
300+
placeholder: "No items",
297301
layout: "fitDataStretch",
298302
pagination: false,
299303
movableRows: true,
@@ -342,12 +346,13 @@ async function onDOMContentLoaded() {
342346
hozAlign: "left",
343347
headerFilter: "list",
344348
editor: "list",
349+
//verticalNavigation: "hybrid",
345350
editorParams: { values: ["Local", "Session"] },
346351
headerFilterPlaceholder: "Select",
347352
headerFilterFunc: storeHeaderFilter,
348353
headerFilterParams: {
354+
clearable: true,
349355
values: ["Local", "Session"],
350-
verticalNavigation: "hybrid",
351356
multiselect: true,
352357
},
353358
validator: ["in:Local|Session", "required"],
@@ -387,11 +392,13 @@ async function onDOMContentLoaded() {
387392
width: "25%",
388393
headerFilter: "input",
389394
headerFilterPlaceholder: "Filter",
395+
formatter: "plaintext",
390396
editor: "input",
391397
editorParams: {
392398
elementAttributes: {
393399
spellcheck: "false",
394400
},
401+
shiftEnterSubmit: true,
395402
},
396403
},
397404

@@ -401,28 +408,32 @@ async function onDOMContentLoaded() {
401408
headerFilter: "input",
402409
headerFilterPlaceholder: "Filter",
403410
editor: "textarea",
404-
editable: editCheck,
411+
//editable: editCheck,
405412
editorParams: {
406413
elementAttributes: {
407414
spellcheck: "false",
415+
wrap: "off",
408416
},
409417
verticalNavigation: "editor",
410418
variableHeight: true,
411419
shiftEnterSubmit: true,
412420
},
413421
formatter: "plaintext",
414-
cellClick: function (e, cell) {
422+
/**/
423+
cellDblClick: function (e, cell) {
424+
//if(!editCheck(cell)){
425+
editDialog.showModal();
426+
editDialog.focus(); // focus something else first !!
415427
const rowData = cell.getRow().getData();
416-
if (!(rowData.value.split(/\r\n|\r|\n/).length < 10)) {
417-
editorTempCell = cell;
418-
textareaEl.value = rowData.value;
419-
selectEl.value = rowData.store;
420-
inputEl.value = rowData.key;
421-
editDialog.showModal();
422-
textareaEl.focus();
423-
textareaEl.setSelectionRange(0, 0);
424-
}
428+
editorTempRow = cell.getRow();
429+
textareaEl.value = rowData.value;
430+
selectEl.value = rowData.store;
431+
inputEl.value = rowData.key;
432+
textareaEl.focus();
433+
textareaEl.setSelectionRange(0, 0);
434+
//}
425435
},
436+
/**/
426437
},
427438
],
428439
});
@@ -438,6 +449,7 @@ async function onDOMContentLoaded() {
438449
});
439450

440451
// load data
452+
table.alert("Loading data");
441453
const data = await getTblData();
442454
data.forEach(async (e, index) => {
443455
table.addRow(e, true);
@@ -451,6 +463,8 @@ async function onDOMContentLoaded() {
451463
}
452464
});
453465

466+
table.clearAlert();
467+
454468
tableData = table.getData();
455469

456470
// do this after the inital data load
@@ -462,10 +476,26 @@ async function onDOMContentLoaded() {
462476

463477
confirmBtn.addEventListener("click", (event) => {
464478
event.preventDefault(); // dont submit fake form
465-
editorTempCell.setValue(textareaEl.value, true);
479+
480+
editorTempRow.update({
481+
store: selectEl.value,
482+
key: inputEl.value,
483+
value: textareaEl.value,
484+
});
485+
466486
editDialog.close();
467487
});
468-
}
488+
489+
//table.getColumn("store").setHeaderFilterValue(["Local","Session"]);
490+
491+
wrapCheckboxEl.addEventListener("click", (evt) => {
492+
if (evt.target.checked) {
493+
textareaEl.style.whiteSpace = "nowrap";
494+
} else {
495+
textareaEl.style.whiteSpace = "wrap";
496+
}
497+
});
498+
} // onDOMContentLoaded
469499

470500
function onChange(evt) {
471501
let id = evt.target.id;

0 commit comments

Comments
 (0)