@yuneta/gobj-ui 7.26.44 → 7.26.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -20
- package/dist/gobj-ui.cjs.js +326 -37
- package/dist/gobj-ui.es.js +327 -39
- package/index.js +1 -0
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +4 -1
- package/scripts/validate-locales.mjs +709 -178
- package/src/c_yui_form.js +116 -50
- package/src/c_yui_node.js +3 -1
- package/src/c_yui_schema_editor.js +3 -0
- package/src/c_yui_shell.js +113 -12
- package/src/c_yui_window.js +44 -5
- package/src/form_table_edits_ask.wiring.test.js +11 -2
- package/src/form_table_rows.wiring.test.js +284 -9
- package/src/form_time_cell_editor.js +143 -0
- package/src/form_time_cell_editor.test.js +116 -0
- package/src/i18n_key_functions.js +2 -2
- package/src/i18n_key_functions.test.js +45 -7
- package/src/node_nav_events.wiring.test.js +6 -0
- package/src/schema_editor_diagram_click.wiring.test.js +28 -0
- package/src/shell_escape_taken.wiring.test.js +34 -0
- package/src/shell_focus_trap.js +47 -1
- package/src/shell_focus_trap.test.js +95 -0
- package/src/shell_modals.js +2 -2
- package/src/shell_stop_overlays.wiring.test.js +143 -0
- package/src/tabulator_edit_internals.test.js +50 -0
- package/src/window_dialog.wiring.test.js +80 -1
- package/src/window_rect_rounding.wiring.test.js +45 -0
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
* getData() with copies and a row's getData() with the row itself,
|
|
27
27
|
* draws a row by running its formatter, says `dataChanged` per row
|
|
28
28
|
* added, synchronously, and builds itself a turn after it is made.
|
|
29
|
+
* A click on a row toggles it before `rowClick`, as Tabulator's
|
|
30
|
+
* SelectRow does when the table selects rows: a form that toggled
|
|
31
|
+
* it again in `rowClick` (7.26.44) undid every click.
|
|
29
32
|
*
|
|
30
33
|
* Copyright (c) 2026, ArtGins.
|
|
31
34
|
* All Rights Reserved.
|
|
@@ -62,12 +65,22 @@ vi.mock("tabulator-tables", () => {
|
|
|
62
65
|
localize: {
|
|
63
66
|
installLang: () => {
|
|
64
67
|
}
|
|
68
|
+
},
|
|
69
|
+
edit: {
|
|
70
|
+
currentCell: false,
|
|
71
|
+
cancelEdit: () => {
|
|
72
|
+
this.modules.edit.currentCell = false;
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
};
|
|
67
76
|
tables.push(this);
|
|
68
|
-
/* Tabulator builds itself a turn after it is made
|
|
77
|
+
/* Tabulator builds itself a turn after it is made, with
|
|
78
|
+
* the rows it was given (`data`), saying no `dataChanged`. */
|
|
69
79
|
setTimeout(() => {
|
|
70
80
|
if(!this.destroyed) {
|
|
81
|
+
for(const record of (settings && settings.data) || []) {
|
|
82
|
+
this.add(record, true);
|
|
83
|
+
}
|
|
71
84
|
this.initialized = true;
|
|
72
85
|
this.emit("tableBuilt");
|
|
73
86
|
}
|
|
@@ -97,7 +110,7 @@ vi.mock("tabulator-tables", () => {
|
|
|
97
110
|
throw new Error("Table Not Initialized");
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
|
-
add(record) {
|
|
113
|
+
add(record, silent) {
|
|
101
114
|
const $row = document.createElement("div");
|
|
102
115
|
this.element.appendChild($row);
|
|
103
116
|
const row = {data: record, $row: $row};
|
|
@@ -105,7 +118,7 @@ vi.mock("tabulator-tables", () => {
|
|
|
105
118
|
getElement: () => row.$row,
|
|
106
119
|
getData: () => row.data,
|
|
107
120
|
toggleSelect: () => {
|
|
108
|
-
|
|
121
|
+
this.toggle_row(row);
|
|
109
122
|
},
|
|
110
123
|
delete: () => {
|
|
111
124
|
this.delete_row(this.rows.indexOf(row));
|
|
@@ -115,7 +128,9 @@ vi.mock("tabulator-tables", () => {
|
|
|
115
128
|
this.settings.rowFormatter(row.component);
|
|
116
129
|
}
|
|
117
130
|
this.rows.push(row);
|
|
118
|
-
|
|
131
|
+
if(!silent) {
|
|
132
|
+
this.emit("dataChanged");
|
|
133
|
+
}
|
|
119
134
|
return row.component;
|
|
120
135
|
}
|
|
121
136
|
addRow(record) {
|
|
@@ -128,6 +143,26 @@ vi.mock("tabulator-tables", () => {
|
|
|
128
143
|
this.calls.addData++;
|
|
129
144
|
return Promise.resolve(records.map((record) => this.add(record)));
|
|
130
145
|
}
|
|
146
|
+
/* SelectRow's own toggle, gated by `selectableRowsCheck`. */
|
|
147
|
+
toggle_row(row) {
|
|
148
|
+
let check = this.options.selectableRowsCheck || (() => true);
|
|
149
|
+
if(check(row.component)) {
|
|
150
|
+
row.selected = !row.selected;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/* A click on a row: SelectRow toggles it on its own `click`
|
|
154
|
+
* when the table selects rows, then Tabulator says `rowClick`. */
|
|
155
|
+
click_row(index) {
|
|
156
|
+
const row = this.rows[index];
|
|
157
|
+
let selectable_rows = this.options.selectableRows;
|
|
158
|
+
if(selectable_rows === true || typeof selectable_rows === "number") {
|
|
159
|
+
this.toggle_row(row);
|
|
160
|
+
}
|
|
161
|
+
this.emit("rowClick", {
|
|
162
|
+
preventDefault: () => {
|
|
163
|
+
}
|
|
164
|
+
}, row.component);
|
|
165
|
+
}
|
|
131
166
|
getRows() {
|
|
132
167
|
return this.rows.map((row) => row.component);
|
|
133
168
|
}
|
|
@@ -159,8 +194,23 @@ vi.mock("tabulator-tables", () => {
|
|
|
159
194
|
}
|
|
160
195
|
this.settings.rowFormatter(row.component);
|
|
161
196
|
}
|
|
197
|
+
/* A cell editor opened in a row, as a click on a cell does. */
|
|
198
|
+
open_editor(index) {
|
|
199
|
+
this.modules.edit.currentCell = this.rows[index];
|
|
200
|
+
}
|
|
201
|
+
/* What Tabulator 6.6.0 does when it wipes its rows with an
|
|
202
|
+
* editor open: the row that holds it closes it, and the redraw
|
|
203
|
+
* that follows walks the rows already wiped -- it throws when
|
|
204
|
+
* any row came before. */
|
|
205
|
+
wipe_rows() {
|
|
206
|
+
const editing = this.modules.edit.currentCell;
|
|
207
|
+
if(editing && this.rows.indexOf(editing) > 0) {
|
|
208
|
+
throw new TypeError("Cannot read properties of undefined (reading 'add')");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
162
211
|
clearData() {
|
|
163
212
|
this.must_be_built();
|
|
213
|
+
this.wipe_rows();
|
|
164
214
|
for(const row of this.rows) {
|
|
165
215
|
while(row.$row.firstChild) {
|
|
166
216
|
row.$row.removeChild(row.$row.firstChild);
|
|
@@ -178,6 +228,7 @@ vi.mock("tabulator-tables", () => {
|
|
|
178
228
|
setLocale() {
|
|
179
229
|
}
|
|
180
230
|
destroy() {
|
|
231
|
+
this.wipe_rows();
|
|
181
232
|
this.destroyed = true;
|
|
182
233
|
}
|
|
183
234
|
}
|
|
@@ -187,7 +238,7 @@ vi.mock("tabulator-tables", () => {
|
|
|
187
238
|
const {
|
|
188
239
|
SDATA_END, gclass_create,
|
|
189
240
|
gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
190
|
-
gobj_start, gobj_stop, gobj_destroy, gobj_send_event, gobj_read_attr,
|
|
241
|
+
gobj_start, gobj_stop, gobj_destroy, gobj_send_event, gobj_read_attr, gobj_write_attr,
|
|
191
242
|
set_log_callback,
|
|
192
243
|
} = await import("@yuneta/gobj-js");
|
|
193
244
|
const {register_c_yui_form} = await import("./c_yui_form.js");
|
|
@@ -489,15 +540,33 @@ describe("a table is loaded in one call", () => {
|
|
|
489
540
|
expect(close_asks(form)).toBe(false);
|
|
490
541
|
expect(errors()).toEqual([]);
|
|
491
542
|
});
|
|
543
|
+
|
|
544
|
+
/* Up to 7.26.44 a nested table was built empty and loaded after
|
|
545
|
+
* its build -- laid out twice and redrawn once more, per row: with
|
|
546
|
+
* a nested table per row, most of the time of a load. */
|
|
547
|
+
test("a nested table is BUILT with its rows: no load of its own, no redraw", async () => {
|
|
548
|
+
const host_record = record();
|
|
549
|
+
const {form, first} = build(host_record);
|
|
550
|
+
await settle();
|
|
551
|
+
await new Promise(resolve => setTimeout(resolve, 60));
|
|
552
|
+
const alarms = alarms_of(first);
|
|
553
|
+
const triggers = triggers_of(alarms, 0);
|
|
554
|
+
expect(triggers.rows.map((r) => r.data)).toEqual([{measure: "temperature", value: 30}]);
|
|
555
|
+
expect(triggers.calls.addData).toBe(0);
|
|
556
|
+
expect(triggers.calls.redraw).toBe(0);
|
|
557
|
+
/* A copy: an edit there does not write into the record. */
|
|
558
|
+
triggers.edit_cell(0, "value", 31);
|
|
559
|
+
expect(host_record.alarms[0].triggers[0].value).toBe(30);
|
|
560
|
+
expect(gobj_read_attr(form, "record").alarms[0].triggers[0].value).toBe(30);
|
|
561
|
+
expect(gobj_read_attr(form, "edited")).toBe(true);
|
|
562
|
+
expect(errors()).toEqual([]);
|
|
563
|
+
});
|
|
492
564
|
});
|
|
493
565
|
|
|
494
566
|
describe("a click on a row", () => {
|
|
495
567
|
function click(alarms, index)
|
|
496
568
|
{
|
|
497
|
-
alarms.
|
|
498
|
-
preventDefault: () => {
|
|
499
|
-
}
|
|
500
|
-
}, alarms.rows[index].component);
|
|
569
|
+
alarms.click_row(index);
|
|
501
570
|
}
|
|
502
571
|
|
|
503
572
|
test("does not WRITE the `selectable` attribute, and selects nothing when Tabulator selects no rows", async () => {
|
|
@@ -516,6 +585,8 @@ describe("a click on a row", () => {
|
|
|
516
585
|
const alarms = alarms_of(first);
|
|
517
586
|
click(alarms, 1);
|
|
518
587
|
expect(alarms.rows[1].selected).toBe(true);
|
|
588
|
+
click(alarms, 1);
|
|
589
|
+
expect(alarms.rows[1].selected).toBeFalsy();
|
|
519
590
|
expect(errors()).toEqual([]);
|
|
520
591
|
});
|
|
521
592
|
|
|
@@ -531,3 +602,207 @@ describe("a click on a row", () => {
|
|
|
531
602
|
expect(errors()).toEqual([]);
|
|
532
603
|
});
|
|
533
604
|
});
|
|
605
|
+
|
|
606
|
+
/* Tabulator 6.6.0's row checkbox goes through `selectableRowsCheck`
|
|
607
|
+
* (toggleRow), but the box ticks on its own first, so a refused
|
|
608
|
+
* toggle leaves it ticked over a row that is not selected; and its
|
|
609
|
+
* header box calls selectRow(), which asks no check at all and
|
|
610
|
+
* selects every row. Checked in Chromium: with `selectable: false`
|
|
611
|
+
* the row box ticked and selected nothing, the header selected every
|
|
612
|
+
* row; and with the default `selectableRows` ("highlight") the
|
|
613
|
+
* `selectable` of the form was not asked at all. */
|
|
614
|
+
describe("the checkbox column", () => {
|
|
615
|
+
test("is not drawn when the form is not selectable", async () => {
|
|
616
|
+
const {first} = build(record(), null, {with_checkbox: true, selectable: false});
|
|
617
|
+
await settle();
|
|
618
|
+
const alarms = alarms_of(first);
|
|
619
|
+
expect(alarms.settings.rowHeader).toBeUndefined();
|
|
620
|
+
expect(triggers_of(alarms, 0).settings.rowHeader).toBeUndefined();
|
|
621
|
+
expect(errors()).toEqual([]);
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
test("is drawn when it is, and every toggle asks the form's `selectable`", async () => {
|
|
625
|
+
const {form, first} = build(record(), null, {with_checkbox: true});
|
|
626
|
+
await settle();
|
|
627
|
+
const alarms = alarms_of(first);
|
|
628
|
+
expect(alarms.settings.rowHeader.formatter).toBe("rowSelection");
|
|
629
|
+
expect(typeof alarms.settings.selectableRowsCheck).toBe("function");
|
|
630
|
+
expect(alarms.settings.selectableRowsCheck()).toBe(true);
|
|
631
|
+
gobj_write_attr(form, "selectable", false);
|
|
632
|
+
expect(alarms.settings.selectableRowsCheck()).toBe(false);
|
|
633
|
+
expect(errors()).toEqual([]);
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
/* A cell half typed: Tabulator says `dataChanged` only when its editor
|
|
638
|
+
* commits, and a host that reloads the form by code asks `edited`
|
|
639
|
+
* first -- the reload dropped what was typed without a question. */
|
|
640
|
+
describe("typing in a cell editor", () => {
|
|
641
|
+
/* The document double does not bubble: the event is handed to the
|
|
642
|
+
* table's element with the box as its target, as a browser does. */
|
|
643
|
+
function type_in(alarms, $box)
|
|
644
|
+
{
|
|
645
|
+
alarms.element.dispatchEvent({type: "input", target: $box, bubbles: true});
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function editing_box($row, editing)
|
|
649
|
+
{
|
|
650
|
+
const $cell = document.createElement("div");
|
|
651
|
+
$cell.className = editing ? "tabulator-cell tabulator-editing" : "tabulator-col";
|
|
652
|
+
const $box = document.createElement("input");
|
|
653
|
+
$cell.appendChild($box);
|
|
654
|
+
$row.appendChild($cell);
|
|
655
|
+
return $box;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
test("is `edited` at once, before the editor commits", async () => {
|
|
659
|
+
const {form, first} = build(record());
|
|
660
|
+
await settle();
|
|
661
|
+
const alarms = alarms_of(first);
|
|
662
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
663
|
+
type_in(alarms, editing_box(alarms.rows[0].$row, true));
|
|
664
|
+
expect(gobj_read_attr(form, "edited")).toBe(true);
|
|
665
|
+
expect(errors()).toEqual([]);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
test("but not a box that edits no cell (a header filter)", async () => {
|
|
669
|
+
const {form, first} = build(record());
|
|
670
|
+
await settle();
|
|
671
|
+
const alarms = alarms_of(first);
|
|
672
|
+
type_in(alarms, editing_box(alarms.element, false));
|
|
673
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
/* A time column was edited by Tabulator's `datetime` with a `format`,
|
|
678
|
+
* which needs luxon, which nobody gives gobj-ui: in Chromium it said
|
|
679
|
+
* "'date' editor 'format' param is dependant on luxon.js", opened
|
|
680
|
+
* empty, and threw when committed. */
|
|
681
|
+
describe("a time column of a table", () => {
|
|
682
|
+
test("is edited by the form's own editor, which needs no luxon", async () => {
|
|
683
|
+
const first = tables.length;
|
|
684
|
+
const app = gobj_create_pure_child(`trapp${++seq}`, "C_TEST_TR_APP", {}, yuno);
|
|
685
|
+
gobj_start(app);
|
|
686
|
+
const form = gobj_create_pure_child(`trform${seq}`, "C_YUI_FORM", {
|
|
687
|
+
template: {
|
|
688
|
+
events: {
|
|
689
|
+
type: "array",
|
|
690
|
+
flag: ["writable", "persistent", "table"],
|
|
691
|
+
table: {
|
|
692
|
+
when: {type: "integer", flag: ["writable", "persistent", "time"]}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
record: {events: [{when: 1700000000}]},
|
|
697
|
+
editable: true,
|
|
698
|
+
}, app);
|
|
699
|
+
gobj_start(form);
|
|
700
|
+
await settle();
|
|
701
|
+
const column = tables[first].settings.columns.find((c) => c.field === "when");
|
|
702
|
+
expect(typeof column.editor).toBe("function");
|
|
703
|
+
const params = column.editorParams({getValue: () => 1700000000});
|
|
704
|
+
expect(params.format).toBeUndefined();
|
|
705
|
+
expect(params.elementAttributes["aria-label"]).toBe("when");
|
|
706
|
+
expect(params.elementAttributes.title).toBe("when");
|
|
707
|
+
gobj_stop(form);
|
|
708
|
+
gobj_destroy(form);
|
|
709
|
+
expect(errors()).toEqual([]);
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
/* A click in a nested table is the nested table's: it bubbled up to
|
|
714
|
+
* the row that holds it, and Tabulator 6.6.0's SelectRow -- listening
|
|
715
|
+
* on that row's element -- toggled the outer row too (Chromium). So
|
|
716
|
+
* does a Shift+press, which starts its range selection. */
|
|
717
|
+
describe("a click in a nested table", () => {
|
|
718
|
+
function event(type, init)
|
|
719
|
+
{
|
|
720
|
+
let stopped = 0;
|
|
721
|
+
const ev = Object.assign({
|
|
722
|
+
type: type,
|
|
723
|
+
bubbles: true,
|
|
724
|
+
preventDefault() {
|
|
725
|
+
},
|
|
726
|
+
stopPropagation() {
|
|
727
|
+
stopped++;
|
|
728
|
+
},
|
|
729
|
+
}, init || {});
|
|
730
|
+
return {ev, stopped: () => stopped};
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
test("does not reach the row that holds the table", async () => {
|
|
734
|
+
const {first} = build(record(), null, {tabulator_settings: {selectableRows: true}});
|
|
735
|
+
await settle();
|
|
736
|
+
const $nested = alarms_of(first).rows[0].$row.querySelector(".yui-tabulator-table-nested");
|
|
737
|
+
|
|
738
|
+
const click = event("click");
|
|
739
|
+
$nested.dispatchEvent(click.ev);
|
|
740
|
+
expect(click.stopped()).toBe(1);
|
|
741
|
+
|
|
742
|
+
const shift_press = event("mousedown", {shiftKey: true});
|
|
743
|
+
$nested.dispatchEvent(shift_press.ev);
|
|
744
|
+
expect(shift_press.stopped()).toBe(1);
|
|
745
|
+
|
|
746
|
+
/* A plain press goes on: what closes a popup listens for it. */
|
|
747
|
+
const press = event("mousedown", {shiftKey: false});
|
|
748
|
+
$nested.dispatchEvent(press.ev);
|
|
749
|
+
expect(press.stopped()).toBe(0);
|
|
750
|
+
expect(errors()).toEqual([]);
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
describe("a cell editor open while its table goes", () => {
|
|
755
|
+
function warnings()
|
|
756
|
+
{
|
|
757
|
+
return logged.filter((l) => /warn|error/i.test(l.level) || /WARNING|ERROR/.test(l.msg));
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
test("a reload with an editor open in the second row reloads the rows", async () => {
|
|
761
|
+
const {form, first} = build(record());
|
|
762
|
+
await settle();
|
|
763
|
+
const alarms = alarms_of(first);
|
|
764
|
+
alarms.open_editor(1);
|
|
765
|
+
triggers_of(alarms, 1).open_editor(0);
|
|
766
|
+
gobj_send_event(form, "EV_LOAD_RECORD", {
|
|
767
|
+
template_version: 7,
|
|
768
|
+
alarms: [{name: "cold", triggers: [{measure: "temperature", value: 5}]}]
|
|
769
|
+
}, form);
|
|
770
|
+
await settle();
|
|
771
|
+
expect(shown(alarms)).toEqual([{name: "cold", values: [5]}]);
|
|
772
|
+
expect(warnings()).toEqual([]);
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
test("a destroy with an editor open in a second row destroys every table, silently", async () => {
|
|
776
|
+
const before = live();
|
|
777
|
+
const {form, first} = build({
|
|
778
|
+
template_version: 7,
|
|
779
|
+
alarms: [
|
|
780
|
+
{name: "a", triggers: [{measure: "m", value: 1}, {measure: "n", value: 2}]},
|
|
781
|
+
{name: "b", triggers: [{measure: "m", value: 3}]}
|
|
782
|
+
]
|
|
783
|
+
});
|
|
784
|
+
await settle();
|
|
785
|
+
const alarms = alarms_of(first);
|
|
786
|
+
alarms.open_editor(1);
|
|
787
|
+
triggers_of(alarms, 0).open_editor(1);
|
|
788
|
+
gobj_stop(form);
|
|
789
|
+
gobj_destroy(form);
|
|
790
|
+
expect(live() - before).toBe(0);
|
|
791
|
+
expect(warnings()).toEqual([]);
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
/* The guard reads Tabulator's edit module, which is no public
|
|
795
|
+
* API: a Tabulator that moved it would leave the guard doing
|
|
796
|
+
* nothing, and the crash back. That is said. */
|
|
797
|
+
test("a Tabulator with no edit module is said, not trusted", async () => {
|
|
798
|
+
const {form, first} = build(record());
|
|
799
|
+
await settle();
|
|
800
|
+
const alarms = alarms_of(first);
|
|
801
|
+
alarms.modules.edit = {editingCell: false, cancel: () => {}}; /* renamed */
|
|
802
|
+
gobj_send_event(form, "EV_LOAD_RECORD", record(), form);
|
|
803
|
+
await settle();
|
|
804
|
+
const said = warnings().map((l) => l.msg);
|
|
805
|
+
expect(said.length).toBe(1);
|
|
806
|
+
expect(said[0]).toContain("has no modules.edit.currentCell/cancelEdit()");
|
|
807
|
+
});
|
|
808
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
* form_time_cell_editor.js
|
|
3
|
+
*
|
|
4
|
+
* The cell editor of a `time` / `now` column in a table of
|
|
5
|
+
* C_YUI_FORM: a `datetime-local` box, as the form's own time
|
|
6
|
+
* field, converting with the same helpers (form_time_value.js)
|
|
7
|
+
* -- an epoch in SECONDS for an integer column, an ISO text
|
|
8
|
+
* for a string one -- and to the second (`step` 1).
|
|
9
|
+
*
|
|
10
|
+
* Up to gobj-ui 7.26.45 the column used Tabulator's `datetime`
|
|
11
|
+
* editor with a `format`, which needs luxon, and nothing gives
|
|
12
|
+
* gobj-ui luxon: the editor said "'date' editor 'format' param
|
|
13
|
+
* is dependant on luxon.js" in the console, opened empty, and
|
|
14
|
+
* threw when it was committed. Its format ("dd/MM/yyyy hh:mm",
|
|
15
|
+
* 12-hour) could not have read an epoch either. Luxon is not
|
|
16
|
+
* taken in for it: one editor is not worth a dependency every
|
|
17
|
+
* app would have to dedupe, and the conversion it needs is the
|
|
18
|
+
* one the form already makes.
|
|
19
|
+
*
|
|
20
|
+
* It behaves as Tabulator's own: `elementAttributes` are
|
|
21
|
+
* written on the box (the column's name, see
|
|
22
|
+
* yui_tabulator_name_editor), a true blur or Enter commits,
|
|
23
|
+
* Escape cancels, `verticalNavigation: "editor"` keeps the
|
|
24
|
+
* arrows, and a value that did not change is a cancel.
|
|
25
|
+
*
|
|
26
|
+
* Copyright (c) 2026, ArtGins.
|
|
27
|
+
* All Rights Reserved.
|
|
28
|
+
****************************************************************************/
|
|
29
|
+
import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
|
|
30
|
+
|
|
31
|
+
/************************************************************
|
|
32
|
+
* A cell's value -> the text of the box ("" when empty).
|
|
33
|
+
************************************************************/
|
|
34
|
+
function time_to_datetime_local(value, real_type)
|
|
35
|
+
{
|
|
36
|
+
if(value === null || value === undefined || value === "") {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
if(real_type === "string") {
|
|
40
|
+
return date_to_datetime_local(new Date(String(value)));
|
|
41
|
+
}
|
|
42
|
+
let seconds = Number(value);
|
|
43
|
+
if(!Number.isFinite(seconds)) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
return date_to_datetime_local(new Date(seconds * 1000));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/************************************************************
|
|
50
|
+
* The text of the box -> the cell's value (null when empty).
|
|
51
|
+
************************************************************/
|
|
52
|
+
function datetime_local_to_time(text, real_type)
|
|
53
|
+
{
|
|
54
|
+
let epoch = datetime_local_to_epoch(text);
|
|
55
|
+
if(epoch === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if(real_type === "string") {
|
|
59
|
+
return new Date(epoch * 1000).toISOString();
|
|
60
|
+
}
|
|
61
|
+
return epoch;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/************************************************************
|
|
65
|
+
* The editor of a time column whose values are `real_type`
|
|
66
|
+
* ("integer": epoch seconds; "string": ISO text).
|
|
67
|
+
************************************************************/
|
|
68
|
+
function form_time_cell_editor(real_type)
|
|
69
|
+
{
|
|
70
|
+
return function(cell, onRendered, success, cancel, editorParams) {
|
|
71
|
+
let params = editorParams || {};
|
|
72
|
+
let vertical = params.verticalNavigation || "editor";
|
|
73
|
+
let original = cell.getValue();
|
|
74
|
+
let original_text = time_to_datetime_local(original, real_type);
|
|
75
|
+
|
|
76
|
+
let input = document.createElement("input");
|
|
77
|
+
input.type = "datetime-local";
|
|
78
|
+
input.setAttribute("step", "1");
|
|
79
|
+
input.style.padding = "4px";
|
|
80
|
+
input.style.width = "100%";
|
|
81
|
+
input.style.boxSizing = "border-box";
|
|
82
|
+
let attrs = params.elementAttributes;
|
|
83
|
+
if(attrs && typeof attrs === "object") {
|
|
84
|
+
for(let key of Object.keys(attrs)) {
|
|
85
|
+
input.setAttribute(key, attrs[key]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
input.value = original_text;
|
|
89
|
+
|
|
90
|
+
onRendered(function() {
|
|
91
|
+
if(cell.getType() === "cell") {
|
|
92
|
+
input.focus({preventScroll: true});
|
|
93
|
+
input.style.height = "100%";
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let commit = function() {
|
|
98
|
+
if(input.value === original_text) {
|
|
99
|
+
cancel();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let value = datetime_local_to_time(input.value, real_type);
|
|
103
|
+
if(value === original || (value === null && original_text === "")) {
|
|
104
|
+
cancel();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
success(value);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/* Only a TRUE blur: not the one of the browser's own picker. */
|
|
111
|
+
input.addEventListener("blur", function(e) {
|
|
112
|
+
if(e.relatedTarget || e.rangeParent || e.explicitOriginalTarget !== input) {
|
|
113
|
+
commit();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
input.addEventListener("keydown", function(e) {
|
|
118
|
+
switch(e.key) {
|
|
119
|
+
case "Enter":
|
|
120
|
+
commit();
|
|
121
|
+
break;
|
|
122
|
+
case "Escape":
|
|
123
|
+
cancel();
|
|
124
|
+
break;
|
|
125
|
+
case "End":
|
|
126
|
+
case "Home":
|
|
127
|
+
e.stopPropagation();
|
|
128
|
+
break;
|
|
129
|
+
case "ArrowUp":
|
|
130
|
+
case "ArrowDown":
|
|
131
|
+
if(vertical === "editor") {
|
|
132
|
+
e.stopImmediatePropagation();
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return input;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export {form_time_cell_editor, time_to_datetime_local, datetime_local_to_time};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_time_cell_editor.test.js
|
|
3
|
+
*
|
|
4
|
+
* The cell editor of a time column of C_YUI_FORM's tables. Up to
|
|
5
|
+
* gobj-ui 7.26.45 it was Tabulator's `datetime` with a `format`,
|
|
6
|
+
* which needs luxon -- nobody gives gobj-ui luxon: it opened empty,
|
|
7
|
+
* said so in the console, and threw when committed.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026, ArtGins.
|
|
10
|
+
* All Rights Reserved.
|
|
11
|
+
***********************************************************************/
|
|
12
|
+
import {describe, test, expect} from "vitest";
|
|
13
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
14
|
+
|
|
15
|
+
install_dom_double();
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
form_time_cell_editor, time_to_datetime_local, datetime_local_to_time,
|
|
19
|
+
} = await import("./form_time_cell_editor.js");
|
|
20
|
+
const {date_to_datetime_local} = await import("./form_time_value.js");
|
|
21
|
+
|
|
22
|
+
/* A local wall time and its epoch, whatever the zone of the run. */
|
|
23
|
+
const WALL = "2026-03-14T09:26:53";
|
|
24
|
+
const EPOCH = Math.floor(new Date(WALL).getTime() / 1000);
|
|
25
|
+
|
|
26
|
+
function open_editor(value, real_type, params)
|
|
27
|
+
{
|
|
28
|
+
const said = {success: [], cancel: 0, rendered: null};
|
|
29
|
+
const cell = {
|
|
30
|
+
getValue: () => value,
|
|
31
|
+
getType: () => "cell",
|
|
32
|
+
};
|
|
33
|
+
const $input = form_time_cell_editor(real_type)(
|
|
34
|
+
cell,
|
|
35
|
+
(fn) => {
|
|
36
|
+
said.rendered = fn;
|
|
37
|
+
},
|
|
38
|
+
(v) => {
|
|
39
|
+
said.success.push(v);
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
said.cancel++;
|
|
44
|
+
},
|
|
45
|
+
params || {}
|
|
46
|
+
);
|
|
47
|
+
return {$input, said};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function key(name)
|
|
51
|
+
{
|
|
52
|
+
return {
|
|
53
|
+
type: "keydown", key: name,
|
|
54
|
+
stopPropagation() {}, stopImmediatePropagation() {}, preventDefault() {},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe("a time column's cell editor", () => {
|
|
59
|
+
test("shows an epoch in seconds as a local time, to the second", () => {
|
|
60
|
+
const {$input} = open_editor(EPOCH, "integer");
|
|
61
|
+
expect($input.type).toBe("datetime-local");
|
|
62
|
+
expect($input.getAttribute("step")).toBe("1");
|
|
63
|
+
expect($input.value).toBe(WALL);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("gives back an epoch in seconds", () => {
|
|
67
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
68
|
+
$input.value = "2026-03-14T10:00:00";
|
|
69
|
+
$input.dispatchEvent(key("Enter"));
|
|
70
|
+
expect(said.success).toEqual([Math.floor(new Date("2026-03-14T10:00:00").getTime() / 1000)]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("an ISO text column stays an ISO text", () => {
|
|
74
|
+
const iso = new Date(EPOCH * 1000).toISOString();
|
|
75
|
+
const {$input, said} = open_editor(iso, "string");
|
|
76
|
+
expect($input.value).toBe(WALL);
|
|
77
|
+
$input.value = "2026-03-14T10:00:00";
|
|
78
|
+
$input.dispatchEvent(key("Enter"));
|
|
79
|
+
expect(said.success).toEqual([new Date("2026-03-14T10:00:00").toISOString()]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("an unchanged value is a cancel, and so is Escape", () => {
|
|
83
|
+
const a = open_editor(EPOCH, "integer");
|
|
84
|
+
a.$input.dispatchEvent(key("Enter"));
|
|
85
|
+
expect(a.said.success).toEqual([]);
|
|
86
|
+
expect(a.said.cancel).toBe(1);
|
|
87
|
+
|
|
88
|
+
const b = open_editor(EPOCH, "integer");
|
|
89
|
+
b.$input.value = "2026-03-14T10:00:00";
|
|
90
|
+
b.$input.dispatchEvent(key("Escape"));
|
|
91
|
+
expect(b.said.success).toEqual([]);
|
|
92
|
+
expect(b.said.cancel).toBe(1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("an empty cell opens empty, and emptied commits null", () => {
|
|
96
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
97
|
+
$input.value = "";
|
|
98
|
+
$input.dispatchEvent(key("Enter"));
|
|
99
|
+
expect(said.success).toEqual([null]);
|
|
100
|
+
expect(open_editor(null, "integer").$input.value).toBe("");
|
|
101
|
+
expect(open_editor(undefined, "string").$input.value).toBe("");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("writes the attributes it is given: the column's name", () => {
|
|
105
|
+
const {$input} = open_editor(EPOCH, "integer", {
|
|
106
|
+
elementAttributes: {"aria-label": "since", title: "since"}
|
|
107
|
+
});
|
|
108
|
+
expect($input.getAttribute("aria-label")).toBe("since");
|
|
109
|
+
expect($input.getAttribute("title")).toBe("since");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("the conversions are each other's inverse", () => {
|
|
113
|
+
expect(datetime_local_to_time(time_to_datetime_local(EPOCH, "integer"), "integer")).toBe(EPOCH);
|
|
114
|
+
expect(time_to_datetime_local(EPOCH, "integer")).toBe(date_to_datetime_local(new Date(EPOCH * 1000)));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -284,13 +284,13 @@ export const I18N_KEY_FUNCTIONS = Object.freeze([
|
|
|
284
284
|
{module: "c_yui_shell.js", name: "build_toolbar", exported: false,
|
|
285
285
|
keys: ["1.toolbar.aria_label", "1.toolbar.items[].name", "1.toolbar.items[].aria_label",
|
|
286
286
|
"1.toolbar.items[].tooltip", "1.toolbar.items[].wordmark", "1.toolbar.items[].id"],
|
|
287
|
-
fallbacks: {"1.toolbar.items[].id": ["1.toolbar.items[].aria_label"]}},
|
|
287
|
+
fallbacks: {"1.toolbar.items[].id": ["1.toolbar.items[].aria_label", "1.toolbar.items[].name"]}},
|
|
288
288
|
{module: "c_yui_shell.js", name: "build_toolbar_action_item", exported: false,
|
|
289
289
|
keys: ["1.name", "1.aria_label", "1.tooltip", "1.id"],
|
|
290
290
|
fallbacks: {"1.id": ["1.aria_label", "1.name"]}},
|
|
291
291
|
{module: "c_yui_shell.js", name: "build_toolbar_brand_item", exported: false,
|
|
292
292
|
keys: ["1.name", "1.aria_label", "1.tooltip", "1.wordmark", "1.id"],
|
|
293
|
-
fallbacks: {"1.id": ["1.aria_label"]}},
|
|
293
|
+
fallbacks: {"1.id": ["1.aria_label", "1.name"]}},
|
|
294
294
|
{module: "c_yui_shell.js", name: "build_toolbar_avatar_item", exported: false,
|
|
295
295
|
keys: ["1.name", "1.aria_label", "1.tooltip", "1.id"],
|
|
296
296
|
fallbacks: {"1.id": ["1.aria_label", "1.name"]}},
|