@yuneta/gobj-ui 7.26.46 → 7.26.47

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.
@@ -60,6 +60,7 @@ vi.mock("tabulator-tables", () => {
60
60
  this.initialized = false;
61
61
  this.destroyed = false;
62
62
  this.rows = [];
63
+ this.row_header = null;
63
64
  this.calls = {addRow: 0, addData: 0, redraw: 0};
64
65
  this.modules = {
65
66
  localize: {
@@ -166,6 +167,28 @@ vi.mock("tabulator-tables", () => {
166
167
  getRows() {
167
168
  return this.rows.map((row) => row.component);
168
169
  }
170
+ /* The structured columns start with the row header, as
171
+ * Tabulator's (ColumnManager.columns). */
172
+ getColumns(structured) {
173
+ const def = this.settings && this.settings.rowHeader;
174
+ if(!structured || !def) {
175
+ return [];
176
+ }
177
+ if(!this.row_header) {
178
+ const header = {visible: def.visible !== false};
179
+ this.row_header = {
180
+ getDefinition: () => def,
181
+ isVisible: () => header.visible,
182
+ show: () => {
183
+ header.visible = true;
184
+ },
185
+ hide: () => {
186
+ header.visible = false;
187
+ },
188
+ };
189
+ }
190
+ return [this.row_header];
191
+ }
169
192
  getData() {
170
193
  return this.rows.map((row) => structuredClone(row.data));
171
194
  }
@@ -612,12 +635,39 @@ describe("a click on a row", () => {
612
635
  * row; and with the default `selectableRows` ("highlight") the
613
636
  * `selectable` of the form was not asked at all. */
614
637
  describe("the checkbox column", () => {
615
- test("is not drawn when the form is not selectable", async () => {
638
+ test("is not shown when the form is not selectable", async () => {
616
639
  const {first} = build(record(), null, {with_checkbox: true, selectable: false});
617
640
  await settle();
618
641
  const alarms = alarms_of(first);
619
- expect(alarms.settings.rowHeader).toBeUndefined();
620
- expect(triggers_of(alarms, 0).settings.rowHeader).toBeUndefined();
642
+ expect(alarms.getColumns(true)[0].isVisible()).toBe(false);
643
+ expect(triggers_of(alarms, 0).getColumns(true)[0].isVisible()).toBe(false);
644
+ expect(errors()).toEqual([]);
645
+ });
646
+
647
+ /* Up to 7.26.46 `selectable` was read when a table was built: written
648
+ * false after it, the boxes stayed, and ticked over rows that the
649
+ * check no longer let be selected. */
650
+ test("follows `selectable` written after the tables are built", async () => {
651
+ const {form, first} = build(record(), null, {with_checkbox: true});
652
+ await settle();
653
+ const alarms = alarms_of(first);
654
+ const nested = triggers_of(alarms, 0);
655
+ expect(alarms.getColumns(true)[0].isVisible()).toBe(true);
656
+ gobj_write_attr(form, "selectable", false);
657
+ expect(alarms.getColumns(true)[0].isVisible()).toBe(false);
658
+ expect(nested.getColumns(true)[0].isVisible()).toBe(false);
659
+ gobj_write_attr(form, "selectable", true);
660
+ expect(alarms.getColumns(true)[0].isVisible()).toBe(true);
661
+ expect(nested.getColumns(true)[0].isVisible()).toBe(true);
662
+ expect(errors()).toEqual([]);
663
+ });
664
+
665
+ test("a table built after `selectable` was written follows it", async () => {
666
+ const {form, first} = build(record(), (f) => {
667
+ gobj_write_attr(f, "selectable", false);
668
+ }, {with_checkbox: true});
669
+ await settle();
670
+ expect(alarms_of(first).getColumns(true)[0].isVisible()).toBe(false);
621
671
  expect(errors()).toEqual([]);
622
672
  });
623
673
 
@@ -634,6 +684,36 @@ describe("the checkbox column", () => {
634
684
  });
635
685
  });
636
686
 
687
+ /* Enter in a box of a <form> is an implicit submission: the browser
688
+ * clicks the form's first SUBMIT button, and with none and a single text
689
+ * box it submits the form. Up to 7.26.46 the table's "add" button had no
690
+ * `type`, so it was that button: Enter in any field (or in a cell editor
691
+ * that stays open) added an empty row; and a form of one text box
692
+ * reloaded the page (Chromium and Firefox). */
693
+ describe("Enter in a box of the form", () => {
694
+ test("the table's add button is no submit button", async () => {
695
+ const {form} = build(record());
696
+ await settle();
697
+ const $container = gobj_read_attr(form, "$container");
698
+ const $buttons = Array.from($container.querySelector("form").querySelectorAll("button"));
699
+ expect($buttons.length).toBeGreaterThan(0);
700
+ for(const $b of $buttons) {
701
+ expect($b.getAttribute("type"), $b.className).toBe("button");
702
+ }
703
+ });
704
+
705
+ test("the form is never submitted", async () => {
706
+ const {form} = build(record());
707
+ await settle();
708
+ const $form = gobj_read_attr(form, "$container").querySelector("form");
709
+ let prevented = 0;
710
+ $form.dispatchEvent({type: "submit", target: $form, preventDefault() {
711
+ prevented++;
712
+ }, stopPropagation() {}});
713
+ expect(prevented).toBe(1);
714
+ });
715
+ });
716
+
637
717
  /* A cell half typed: Tabulator says `dataChanged` only when its editor
638
718
  * commits, and a host that reloads the form by code asks `edited`
639
719
  * first -- the reload dropped what was typed without a question. */
@@ -672,6 +752,54 @@ describe("typing in a cell editor", () => {
672
752
  type_in(alarms, editing_box(alarms.element, false));
673
753
  expect(gobj_read_attr(form, "edited")).toBe(false);
674
754
  });
755
+
756
+ /* Escape, or a box left as it was: what was typed is gone, and up
757
+ * to 7.26.46 it still counted -- closing asked about nothing. */
758
+ test("a cancelled edit gives back the `edited` the form had when it opened", async () => {
759
+ const {form, first} = build(record());
760
+ await settle();
761
+ const alarms = alarms_of(first);
762
+ alarms.emit("cellEditing");
763
+ type_in(alarms, editing_box(alarms.rows[0].$row, true));
764
+ expect(gobj_read_attr(form, "edited")).toBe(true);
765
+ alarms.emit("cellEditCancelled");
766
+ expect(gobj_read_attr(form, "edited")).toBe(false);
767
+ expect(gobj_read_attr(form, "changes")).toBe(false);
768
+ expect(close_asks(form)).toBe(false);
769
+
770
+ /* An edit already made stays one: the cancel gives back what
771
+ * was there when THIS editor opened. */
772
+ alarms.edit_cell(0, "name", "renamed");
773
+ expect(gobj_read_attr(form, "edited")).toBe(true);
774
+ alarms.emit("cellEditing");
775
+ type_in(alarms, editing_box(alarms.rows[0].$row, true));
776
+ alarms.emit("cellEditCancelled");
777
+ expect(gobj_read_attr(form, "edited")).toBe(true);
778
+ expect(errors()).toEqual([]);
779
+ });
780
+
781
+ test("a cancel gives nothing back when something else changed the form meanwhile", async () => {
782
+ const {form, first} = build(record());
783
+ await settle();
784
+ const alarms = alarms_of(first);
785
+ alarms.emit("cellEditing");
786
+ type_in(alarms, editing_box(alarms.rows[0].$row, true));
787
+ alarms.edit_cell(1, "name", "elsewhere");
788
+ alarms.emit("cellEditCancelled");
789
+ expect(gobj_read_attr(form, "edited")).toBe(true);
790
+ expect(errors()).toEqual([]);
791
+ });
792
+
793
+ test("a committed edit stays `edited`", async () => {
794
+ const {form, first} = build(record());
795
+ await settle();
796
+ const alarms = alarms_of(first);
797
+ alarms.emit("cellEditing");
798
+ type_in(alarms, editing_box(alarms.rows[0].$row, true));
799
+ alarms.edit_cell(0, "name", "typed");
800
+ expect(gobj_read_attr(form, "edited")).toBe(true);
801
+ expect(errors()).toEqual([]);
802
+ });
675
803
  });
676
804
 
677
805
  /* A time column was edited by Tabulator's `datetime` with a `format`,
@@ -708,6 +836,44 @@ describe("a time column of a table", () => {
708
836
  gobj_destroy(form);
709
837
  expect(errors()).toEqual([]);
710
838
  });
839
+
840
+ /* Up to 7.26.46 the cell showed the raw epoch (1700000000). */
841
+ test("shows its time as the local clock the editor opens on, not the epoch", async () => {
842
+ const first = tables.length;
843
+ const app = gobj_create_pure_child(`trapp${++seq}`, "C_TEST_TR_APP", {}, yuno);
844
+ gobj_start(app);
845
+ const form = gobj_create_pure_child(`trform${seq}`, "C_YUI_FORM", {
846
+ template: {
847
+ events: {
848
+ type: "array",
849
+ flag: ["writable", "persistent", "table"],
850
+ table: {
851
+ when: {type: "integer", flag: ["writable", "persistent", "time"]},
852
+ at: {type: "string", flag: ["writable", "persistent", "time"]}
853
+ }
854
+ }
855
+ },
856
+ record: {events: []},
857
+ editable: true,
858
+ }, app);
859
+ gobj_start(form);
860
+ await settle();
861
+ const columns = tables[first].settings.columns;
862
+ const text = (field, value) => {
863
+ const column = columns.find((c) => c.field === field);
864
+ const out = column.formatter({getValue: () => value});
865
+ return typeof out === "string" ? out : out.textContent;
866
+ };
867
+ const wall = "2026-03-14T09:26:53";
868
+ const epoch = Math.floor(new Date(wall).getTime() / 1000);
869
+ expect(text("when", epoch)).toBe("2026-03-14 09:26:53");
870
+ expect(text("at", new Date(epoch * 1000).toISOString())).toBe("2026-03-14 09:26:53");
871
+ expect(text("when", null)).toBe("");
872
+ expect(text("at", "not a time")).toBe("not a time");
873
+ gobj_stop(form);
874
+ gobj_destroy(form);
875
+ expect(errors()).toEqual([]);
876
+ });
711
877
  });
712
878
 
713
879
  /* A click in a nested table is the nested table's: it bubbled up to
@@ -23,27 +23,30 @@
23
23
  * Escape cancels, `verticalNavigation: "editor"` keeps the
24
24
  * arrows, and a value that did not change is a cancel.
25
25
  *
26
+ * A date with a part cleared is NOT a value: the box answers
27
+ * `value ""` for it, as for an empty box, and only
28
+ * `validity.badInput` tells them apart. Enter leaves the
29
+ * editor open with `aria-invalid` until the date is whole
30
+ * again (or Escape); a blur cancels, and the cell keeps what
31
+ * it had. Up to gobj-ui 7.26.46 both committed null: one
32
+ * Backspace and Enter erased the stored time. To clear a time
33
+ * on purpose, clear EVERY part of the box: an empty box
34
+ * commits null. (Inside the box Tab moves between its parts,
35
+ * as the browser does: it does not leave the cell.)
36
+ *
26
37
  * Copyright (c) 2026, ArtGins.
27
38
  * All Rights Reserved.
28
39
  ****************************************************************************/
29
- import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
40
+ import {
41
+ date_to_datetime_local, datetime_local_to_epoch, time_value_to_date, epoch_to_time_value
42
+ } from "./form_time_value.js";
30
43
 
31
44
  /************************************************************
32
45
  * A cell's value -> the text of the box ("" when empty).
33
46
  ************************************************************/
34
47
  function time_to_datetime_local(value, real_type)
35
48
  {
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));
49
+ return date_to_datetime_local(time_value_to_date(value, real_type));
47
50
  }
48
51
 
49
52
  /************************************************************
@@ -51,14 +54,7 @@ function time_to_datetime_local(value, real_type)
51
54
  ************************************************************/
52
55
  function datetime_local_to_time(text, real_type)
53
56
  {
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;
57
+ return epoch_to_time_value(datetime_local_to_epoch(text), real_type);
62
58
  }
63
59
 
64
60
  /************************************************************
@@ -94,7 +90,22 @@ function form_time_cell_editor(real_type)
94
90
  }
95
91
  });
96
92
 
97
- let commit = function() {
93
+ /* A part of the date cleared (one Backspace) reads "" as an
94
+ * empty box does: only badInput tells "not a time yet" from
95
+ * "no time". */
96
+ let incomplete = function() {
97
+ return !!(input.validity && input.validity.badInput);
98
+ };
99
+
100
+ let commit = function(from_blur) {
101
+ if(incomplete()) {
102
+ if(from_blur) {
103
+ cancel();
104
+ } else {
105
+ input.setAttribute("aria-invalid", "true");
106
+ }
107
+ return;
108
+ }
98
109
  if(input.value === original_text) {
99
110
  cancel();
100
111
  return;
@@ -110,14 +121,20 @@ function form_time_cell_editor(real_type)
110
121
  /* Only a TRUE blur: not the one of the browser's own picker. */
111
122
  input.addEventListener("blur", function(e) {
112
123
  if(e.relatedTarget || e.rangeParent || e.explicitOriginalTarget !== input) {
113
- commit();
124
+ commit(true);
125
+ }
126
+ });
127
+
128
+ input.addEventListener("input", function() {
129
+ if(!incomplete()) {
130
+ input.removeAttribute("aria-invalid");
114
131
  }
115
132
  });
116
133
 
117
134
  input.addEventListener("keydown", function(e) {
118
135
  switch(e.key) {
119
136
  case "Enter":
120
- commit();
137
+ commit(false);
121
138
  break;
122
139
  case "Escape":
123
140
  cancel();
@@ -113,4 +113,42 @@ describe("a time column's cell editor", () => {
113
113
  expect(datetime_local_to_time(time_to_datetime_local(EPOCH, "integer"), "integer")).toBe(EPOCH);
114
114
  expect(time_to_datetime_local(EPOCH, "integer")).toBe(date_to_datetime_local(new Date(EPOCH * 1000)));
115
115
  });
116
+
117
+ /* A box with a part of its date cleared answers `value ""`, as an
118
+ * empty one does, and only `validity.badInput` tells them apart.
119
+ * Up to 7.26.46 both were committed as null: one Backspace and
120
+ * Enter erased the stored time. */
121
+ function half_typed($input)
122
+ {
123
+ $input.value = "";
124
+ Object.defineProperty($input, "validity", {
125
+ configurable: true,
126
+ value: {badInput: true, valid: false}
127
+ });
128
+ }
129
+
130
+ test("an incomplete date is not committed by Enter: the editor stays open, said invalid", () => {
131
+ const {$input, said} = open_editor(EPOCH, "integer");
132
+ half_typed($input);
133
+ $input.dispatchEvent(key("Enter"));
134
+ expect(said.success).toEqual([]);
135
+ expect(said.cancel).toBe(0);
136
+ expect($input.getAttribute("aria-invalid")).toBe("true");
137
+
138
+ /* Completed, it commits. */
139
+ Object.defineProperty($input, "validity", {configurable: true, value: {badInput: false, valid: true}});
140
+ $input.value = "2026-03-14T10:00:00";
141
+ $input.dispatchEvent({type: "input"});
142
+ expect($input.getAttribute("aria-invalid")).toBe(null);
143
+ $input.dispatchEvent(key("Enter"));
144
+ expect(said.success).toEqual([Math.floor(new Date("2026-03-14T10:00:00").getTime() / 1000)]);
145
+ });
146
+
147
+ test("an incomplete date left by a blur is a cancel: the stored time stays", () => {
148
+ const {$input, said} = open_editor(EPOCH, "integer");
149
+ half_typed($input);
150
+ $input.dispatchEvent({type: "blur", relatedTarget: {}});
151
+ expect(said.success).toEqual([]);
152
+ expect(said.cancel).toBe(1);
153
+ });
116
154
  });
@@ -0,0 +1,118 @@
1
+ /***********************************************************************
2
+ * form_time_field.wiring.test.js
3
+ *
4
+ * The time field of C_YUI_FORM reads and writes a time column as
5
+ * the cell editor of a table does (form_time_value.js): an epoch in
6
+ * SECONDS for an integer column, an ISO text for a string one, and
7
+ * an empty box for a column that holds no time. Up to gobj-ui
8
+ * 7.26.46 the field read every column with parseInt -- an ISO text
9
+ * as 2026 SECONDS, in January 1970 --, wrote the epoch into a string
10
+ * column, and showed a column with no time as January 1970, which a
11
+ * save then wrote back as 0.
12
+ *
13
+ * Copyright (c) 2026, ArtGins.
14
+ * All Rights Reserved.
15
+ ***********************************************************************/
16
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
17
+ import {install_dom_double} from "../test/dom_double.js";
18
+
19
+ install_dom_double();
20
+
21
+ if(typeof globalThis.ResizeObserver === "undefined") {
22
+ globalThis.ResizeObserver = class {
23
+ observe() {
24
+ }
25
+ unobserve() {
26
+ }
27
+ disconnect() {
28
+ }
29
+ };
30
+ }
31
+
32
+ const {
33
+ SDATA_END, gclass_create,
34
+ gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
35
+ gobj_start, gobj_send_event, gobj_read_attr,
36
+ set_log_callback,
37
+ } = await import("@yuneta/gobj-js");
38
+ const {register_c_yui_form} = await import("./c_yui_form.js");
39
+
40
+ const logged = [];
41
+ const saved = [];
42
+ let yuno = null;
43
+
44
+ /* A local wall time and its epoch, whatever the zone of the run. */
45
+ const WALL = "2026-03-14T09:26:53";
46
+ const EPOCH = Math.floor(new Date(WALL).getTime() / 1000);
47
+ const ISO = new Date(EPOCH * 1000).toISOString();
48
+
49
+ const TEMPLATE = {
50
+ as_epoch: {type: "integer", flag: ["writable", "persistent", "time"]},
51
+ as_text: {type: "string", flag: ["writable", "persistent", "time"]},
52
+ no_time: {type: "integer", flag: ["writable", "persistent", "time"]},
53
+ };
54
+
55
+ beforeAll(async () => {
56
+ const i18next = (await import("i18next")).default;
57
+ await i18next.init({lng: "en", resources: {}});
58
+ gobj_start_up(null, null, null, null, null, null, null);
59
+ set_log_callback((level, msg) => {
60
+ logged.push({level: String(level), msg: String(msg)});
61
+ });
62
+ gclass_create("C_TEST_TIME_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
63
+ gclass_create(
64
+ "C_TEST_TIME_APP",
65
+ [["EV_SAVE_RECORD", 0]],
66
+ [["ST_IDLE", [
67
+ ["EV_SAVE_RECORD", (gobj, event, kw) => {
68
+ saved.push(JSON.parse(JSON.stringify(kw)));
69
+ return 0;
70
+ }, null],
71
+ ]]],
72
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
73
+ );
74
+ register_c_yui_form();
75
+ yuno = gobj_create_yuno("form_time_field_yuno", "C_TEST_TIME_HOST", {});
76
+ gobj_start(yuno);
77
+ });
78
+
79
+ beforeEach(() => {
80
+ logged.length = 0;
81
+ saved.length = 0;
82
+ });
83
+
84
+ function errors()
85
+ {
86
+ return logged.filter(l => /error/i.test(l.level) || /ERROR/.test(l.msg));
87
+ }
88
+
89
+ function box(form, name)
90
+ {
91
+ const $container = gobj_read_attr(form, "$container");
92
+ return Array.from($container.querySelectorAll(".yui-form-data-input"))
93
+ .find(($i) => $i.dataset.treedb_name === name);
94
+ }
95
+
96
+ describe("the time field of a form", () => {
97
+ test("shows each column as the cell editor does, and saves it back as it was", () => {
98
+ const app = gobj_create_pure_child("tapp", "C_TEST_TIME_APP", {}, yuno);
99
+ gobj_start(app);
100
+ const form = gobj_create_pure_child("tform", "C_YUI_FORM", {
101
+ template: TEMPLATE,
102
+ record: {as_epoch: EPOCH, as_text: ISO, no_time: null},
103
+ editable: true,
104
+ }, app);
105
+ gobj_start(form);
106
+
107
+ expect(box(form, "as_epoch").value).toBe(WALL);
108
+ expect(box(form, "as_text").value).toBe(WALL);
109
+ expect(box(form, "no_time").value).toBe("");
110
+
111
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
112
+ expect(saved.length).toBe(1);
113
+ expect(saved[0].as_epoch).toBe(EPOCH);
114
+ expect(saved[0].as_text).toBe(ISO);
115
+ expect(saved[0].no_time).toBe(null);
116
+ expect(errors()).toEqual([]);
117
+ });
118
+ });
@@ -66,4 +66,62 @@ function datetime_local_to_epoch(value)
66
66
  return Math.floor(date.getTime() / 1000);
67
67
  }
68
68
 
69
- export {date_to_datetime_local, datetime_local_to_epoch};
69
+ /************************************************************
70
+ * The value of a time column -> a Date, or null when it holds
71
+ * none. A `string` column holds an ISO text, any other an epoch
72
+ * in SECONDS. The form's time field and the cell editor of a
73
+ * table read it here, so the two agree: up to gobj-ui 7.26.46 the
74
+ * field read every column with parseInt -- an ISO text as the
75
+ * year 2026 in SECONDS, in January 1970 -- and showed an empty
76
+ * one as January 1970 too, which a save then wrote back as 0.
77
+ ************************************************************/
78
+ function time_value_to_date(value, real_type)
79
+ {
80
+ if(value === null || value === undefined || value === "") {
81
+ return null;
82
+ }
83
+ let date = (real_type === "string")?
84
+ new Date(String(value)) : new Date(Number(value) * 1000);
85
+ return isNaN(date.getTime())? null : date;
86
+ }
87
+
88
+ /************************************************************
89
+ * An epoch in seconds (null: no time) -> the value of a time
90
+ * column: an ISO text for a `string` column, the epoch for any
91
+ * other. Up to gobj-ui 7.26.46 the field wrote the epoch into a
92
+ * `string` column too.
93
+ ************************************************************/
94
+ function epoch_to_time_value(epoch, real_type)
95
+ {
96
+ if(epoch === null || epoch === undefined) {
97
+ return null;
98
+ }
99
+ if(typeof epoch !== "number" || !Number.isFinite(epoch)) {
100
+ return epoch; // not an epoch: handed on as it came
101
+ }
102
+ if(real_type === "string") {
103
+ return new Date(epoch * 1000).toISOString();
104
+ }
105
+ return epoch;
106
+ }
107
+
108
+ /************************************************************
109
+ * The value of a time column as a table cell shows it: the
110
+ * local clock the editor opens on, "YYYY-MM-DD HH:mm:ss", as
111
+ * fmt_epoch() of yui_time.js writes a timestamp in a table. ""
112
+ * for no time; a value that is not one is shown as it is, so the
113
+ * reader sees what the column holds.
114
+ ************************************************************/
115
+ function time_value_to_text(value, real_type)
116
+ {
117
+ let date = time_value_to_date(value, real_type);
118
+ if(!date) {
119
+ return (value === null || value === undefined)? "" : String(value);
120
+ }
121
+ return date_to_datetime_local(date).replace("T", " ");
122
+ }
123
+
124
+ export {
125
+ date_to_datetime_local, datetime_local_to_epoch,
126
+ time_value_to_date, epoch_to_time_value, time_value_to_text
127
+ };
@@ -1,5 +1,7 @@
1
1
  import {describe, it, expect} from "vitest";
2
- import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
2
+ import {
3
+ date_to_datetime_local, datetime_local_to_epoch, time_value_to_date, epoch_to_time_value, time_value_to_text
4
+ } from "./form_time_value.js";
3
5
 
4
6
  describe("form_time_value", () => {
5
7
 
@@ -20,4 +22,26 @@ describe("form_time_value", () => {
20
22
  expect(date_to_datetime_local(null)).toBe("");
21
23
  expect(date_to_datetime_local(new Date(NaN))).toBe("");
22
24
  });
25
+
26
+ it("a time column is read and written by its type, and no time is null", () => {
27
+ const epoch = 1790000037;
28
+ const iso = new Date(epoch * 1000).toISOString();
29
+ expect(time_value_to_date(epoch, "integer").getTime()).toBe(epoch * 1000);
30
+ expect(time_value_to_date(iso, "string").getTime()).toBe(epoch * 1000);
31
+ expect(time_value_to_date(null, "integer")).toBe(null);
32
+ expect(time_value_to_date("", "string")).toBe(null);
33
+ expect(time_value_to_date("not a time", "string")).toBe(null);
34
+ expect(epoch_to_time_value(epoch, "integer")).toBe(epoch);
35
+ expect(epoch_to_time_value(epoch, "string")).toBe(iso);
36
+ expect(epoch_to_time_value(null, "string")).toBe(null);
37
+ expect(epoch_to_time_value("already text", "string")).toBe("already text");
38
+ });
39
+
40
+ it("a time cell shows the local clock, and what is not a time as it is", () => {
41
+ const wall = "2026-03-14T09:26:53";
42
+ const epoch = Math.floor(new Date(wall).getTime() / 1000);
43
+ expect(time_value_to_text(epoch, "integer")).toBe("2026-03-14 09:26:53");
44
+ expect(time_value_to_text(null, "integer")).toBe("");
45
+ expect(time_value_to_text("garbage", "string")).toBe("garbage");
46
+ });
23
47
  });
@@ -24,12 +24,15 @@
24
24
  * that wrapped to it, did nothing and was prevented -- the
25
25
  * keyboard never got into the dialog.
26
26
  *
27
- * A trap whose panel left the document without being released
28
- * (its owner was torn down with it) is dropped, with its
29
- * listener, the next time the stack is read, and said. Up to
30
- * gobj-ui 7.26.45 it stayed the top: every window opened later
31
- * believed itself under an overlay and took no focus, and a
32
- * live trap under it no longer heard Tab.
27
+ * A trap whose panel is out of the document is not the top:
28
+ * the top is the highest trap whose panel is in it. Up to
29
+ * gobj-ui 7.26.45 a trap left behind by an owner torn down with
30
+ * it stayed the top: every window opened later believed itself
31
+ * under an overlay and took no focus, and a live trap under it
32
+ * no longer heard Tab. 7.26.46 dropped such a trap from the
33
+ * stack, which was for good: a panel that only moved (taken out
34
+ * and put back, its trap never released) lost its trap. It is
35
+ * skipped now, and leaves the stack only by its release().
33
36
  *
34
37
  * No gobj dependency: only gobj-js's logger. The optional
35
38
  * second argument lets callers inject a mock document object
@@ -39,8 +42,6 @@
39
42
  * All Rights Reserved.
40
43
  ***********************************************************************/
41
44
 
42
- import {log_warning} from "@yuneta/gobj-js";
43
-
44
45
  /* Selector matching the elements typically considered focusable.
45
46
  * Kept conservative: items that are explicitly removed from the tab
46
47
  * order (`tabindex="-1"`) are excluded; everything else is in. */
@@ -59,21 +60,20 @@ export const FOCUSABLE_SELECTOR =
59
60
  * topmost trap; the rest short-circuit. */
60
61
  const __trap_stack__ = [];
61
62
 
62
- /* Drop the traps whose panel is no longer in the document. Only a
63
- * panel that SAYS so (isConnected === false) is detached: a stub
64
- * that cannot say is taken as connected. */
65
- function drop_detached_traps()
63
+ /* The top trap whose panel is in the document. One that is not
64
+ * is skipped, not dropped: a panel that only MOVES (taken out and
65
+ * put back) is the top again once it is back. Only a panel that
66
+ * SAYS so (isConnected === false) is out: a stub that cannot say
67
+ * is taken as in. A trap leaves the stack only by its release(). */
68
+ function top_trap()
66
69
  {
67
70
  for(let i = __trap_stack__.length - 1; i >= 0; i--) {
68
71
  let trap = __trap_stack__[i];
69
72
  if(trap.$panel.isConnected !== false) {
70
- continue;
73
+ return trap;
71
74
  }
72
- __trap_stack__.splice(i, 1);
73
- trap.detach();
74
- log_warning("focus trap: its panel left the document without releasing it; " +
75
- "dropped (the overlay's owner was torn down with it open)");
76
75
  }
76
+ return null;
77
77
  }
78
78
 
79
79
 
@@ -126,8 +126,7 @@ export function activate_focus_trap_on($panel, doc)
126
126
  * Earlier-registered listeners fire too (capture phase),
127
127
  * but they short-circuit unless they own the top of the
128
128
  * stack. */
129
- drop_detached_traps();
130
- if(__trap_stack__[__trap_stack__.length - 1] !== trap) {
129
+ if(top_trap() !== trap) {
131
130
  return;
132
131
  }
133
132
  let nodes = focusables_of($panel);
@@ -151,9 +150,6 @@ export function activate_focus_trap_on($panel, doc)
151
150
  }
152
151
  };
153
152
  trap.$panel = $panel;
154
- trap.detach = function() {
155
- doc.removeEventListener("keydown", trap, true);
156
- };
157
153
  doc.addEventListener("keydown", trap, true);
158
154
  __trap_stack__.push(trap);
159
155
 
@@ -191,7 +187,6 @@ export function activate_focus_trap_on($panel, doc)
191
187
  ***************************************************************/
192
188
  export function focus_trap_panel()
193
189
  {
194
- drop_detached_traps();
195
- let top = __trap_stack__[__trap_stack__.length - 1];
190
+ let top = top_trap();
196
191
  return top ? top.$panel : null;
197
192
  }