@yuneta/gobj-ui 7.26.46 → 7.26.48

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.
@@ -94,6 +94,11 @@ const GCLASS_NAME = "C_YUI_SHELL";
94
94
  * that remained -- up to 7.26.41. They go to that shell now. */
95
95
  let __live_shells__ = [];
96
96
 
97
+ /* The shell whose overlays are being closed because it stops, while
98
+ * they close: their close paths run inside it (yui_shell_unpark_route
99
+ * reads it). */
100
+ let __retiring_shell__ = null;
101
+
97
102
  /* The gobjs that keep DOM in a shell's layers without being its
98
103
  * children: a C_YUI_WINDOW parented to the app, the dock of
99
104
  * C_YUI_WINDOW_MANAGER. Each is sent EV_SHELL_CHANGED when a shell is
@@ -583,7 +588,7 @@ function mt_stop(gobj)
583
588
  * modals, questions, the toolbar dropdown -- so no focus trap,
584
589
  * document-level listener or escape-stack entry outlives the
585
590
  * shell. */
586
- close_overlays(gobj);
591
+ retire_overlays(gobj);
587
592
  close_toolbar_dropdown(gobj);
588
593
 
589
594
  if(priv.hash_handler) {
@@ -657,7 +662,7 @@ function mt_destroy(gobj)
657
662
  * (it returns early when nothing is open) and prevents a
658
663
  * dangling document mousedown listener / escape-stack entry
659
664
  * when stop is skipped. The other overlays the same way. */
660
- close_overlays(gobj);
665
+ retire_overlays(gobj);
661
666
  close_toolbar_dropdown(gobj);
662
667
 
663
668
  let live_idx = __live_shells__.indexOf(gobj);
@@ -2802,6 +2807,35 @@ function close_overlays(gobj)
2802
2807
  }
2803
2808
  }
2804
2809
 
2810
+ /************************************************************
2811
+ * What a shell that stops does with its overlays: their
2812
+ * history markers are left where they are, and then they are
2813
+ * closed (close_overlays). The overlay stack is emptied FIRST,
2814
+ * so no close -- of an overlay closed here, or of a window
2815
+ * closed later -- retires its marker with a history.back().
2816
+ * Such a back() is asynchronous and a stopped shell no longer
2817
+ * hears where it lands: up to gobj-ui 7.26.46 a logout followed
2818
+ * by a new shell in the same turn had it taken by the new
2819
+ * shell's first window (Chromium stepped back off that window's
2820
+ * marker, Firefox dropped the back()), and the next Back left
2821
+ * the page. A marker left in place is inert, as a drained one
2822
+ * is: a later Back lands on it and is absorbed.
2823
+ ************************************************************/
2824
+ function retire_overlays(gobj)
2825
+ {
2826
+ let priv = gobj.priv;
2827
+ if(priv && priv.overlay_stack) {
2828
+ priv.overlay_stack.splice(0);
2829
+ }
2830
+ let outer = __retiring_shell__;
2831
+ __retiring_shell__ = gobj;
2832
+ try {
2833
+ close_overlays(gobj);
2834
+ } finally {
2835
+ __retiring_shell__ = outer;
2836
+ }
2837
+ }
2838
+
2805
2839
  function pop_escape(gobj, handler)
2806
2840
  {
2807
2841
  let priv = gobj.priv;
@@ -4565,12 +4599,47 @@ function yui_shell_overlay_dismissed(shell_gobj, overlay)
4565
4599
  * stranded action entries and RE-FIRES the action, reopening
4566
4600
  * the overlay and hijacking the navigation the user asked
4567
4601
  * for. Only back() while the URL still sits on the route.
4602
+ *
4603
+ * A close that comes from a shell that STOPS (a logout with the
4604
+ * overlay up) does not go back: the URL is rewritten in place,
4605
+ * to the resting route under the overlay. A back() is
4606
+ * asynchronous and the stopped shell would never hear where it
4607
+ * lands -- the overlay's own marker is left in place, so a
4608
+ * single back() landed on the action entry, the URL stayed on
4609
+ * the action route, and a new shell built in the same turn read
4610
+ * it and opened the overlay again (up to gobj-ui 7.26.47).
4568
4611
  ************************************************************/
4569
4612
  function yui_shell_unpark_route(route)
4570
4613
  {
4571
- if(window.location.hash === route_to_hash(normalize_route(route))) {
4572
- window.history.back();
4614
+ let hash = route_to_hash(normalize_route(route));
4615
+ if(window.location.hash !== hash) {
4616
+ return;
4617
+ }
4618
+ let shell = __retiring_shell__;
4619
+ if(shell) {
4620
+ let resting = resting_route_of(shell);
4621
+ try {
4622
+ window.history.replaceState(window.history.state, "", route_to_hash(resting));
4623
+ } catch(e) {
4624
+ log_warning(`C_YUI_SHELL: unparking '${route}' at stop failed: ${e}`);
4625
+ }
4626
+ return;
4573
4627
  }
4628
+ window.history.back();
4629
+ }
4630
+
4631
+ /************************************************************
4632
+ * The resting route a shell shows under its overlays: the
4633
+ * current one (only ever written for a RESTING route), else
4634
+ * the main stage's, else the default.
4635
+ ************************************************************/
4636
+ function resting_route_of(gobj)
4637
+ {
4638
+ let priv = gobj.priv || {};
4639
+ return gobj_read_attr(gobj, "current_route") ||
4640
+ (priv.stages && priv.stages.main && priv.stages.main.active_route) ||
4641
+ gobj_read_attr(gobj, "default_route") ||
4642
+ "/";
4574
4643
  }
4575
4644
 
4576
4645
  /************************************************************
@@ -123,6 +123,7 @@ import {cell_text, hook_cell_spec} from "./table_cell_text.js";
123
123
 
124
124
  import { TabulatorFull as Tabulator } from "tabulator-tables";
125
125
  import {text_node, text_list_item_formatter} from "./yui_text.js";
126
+ import {time_value_to_date} from "./form_time_value.js";
126
127
 
127
128
  /***************************************************************
128
129
  * Constants
@@ -2269,8 +2270,13 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field)
2269
2270
  switch(field_desc.real_type) {
2270
2271
  case "string":
2271
2272
  case "integer":
2272
- value = parseInt(value) || 0;
2273
- value = new Date(value*1000);
2273
+ /* An ISO text for a string column (up to 7.26.46 read
2274
+ * with parseInt, as 2026 seconds), none for no time. */
2275
+ value = time_value_to_date(value, field_desc.real_type);
2276
+ if(!value) {
2277
+ value = "";
2278
+ break;
2279
+ }
2274
2280
 
2275
2281
  const rawLocale = navigator.language;
2276
2282
  // Playwright Firefox without locale config and some embedded
@@ -776,7 +776,8 @@ function build_ui(gobj)
776
776
  let key = `${gobj_name(gobj)}-rect`;
777
777
  let stored = kw_get_local_storage_value(key);
778
778
  let rect = whole_rect(stored);
779
- if(!rect && stored != null) {
779
+ /* Text that is not json reads as nothing, as no entry does */
780
+ if(!rect && local_storage_holds(key)) {
780
781
  log_warning(`${gobj_short_name(gobj)}: the saved position '${key}' is not a rect of four numbers: ignored`);
781
782
  kw_remove_local_storage_value(key);
782
783
  } else if(rect && (rect.width <= 0 || rect.height <= 0)) {
@@ -1352,6 +1353,19 @@ function min(gobj)
1352
1353
  return rect;
1353
1354
  }
1354
1355
 
1356
+ /************************************************************
1357
+ * Whether localStorage holds anything under `key`, readable
1358
+ * or not.
1359
+ ************************************************************/
1360
+ function local_storage_holds(key)
1361
+ {
1362
+ try {
1363
+ return window.localStorage.getItem(key) !== null;
1364
+ } catch(e) {
1365
+ return false; // no storage: nothing is kept in it either
1366
+ }
1367
+ }
1368
+
1355
1369
  /************************************************************
1356
1370
  * The rect of a window in whole pixels: x, y, width and height
1357
1371
  * are DTP_INTEGER, and getBoundingClientRect() answers fractions
@@ -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
+ });