@yuneta/gobj-ui 7.26.49 → 7.26.51

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/src/c_yui_form.js CHANGED
@@ -3187,7 +3187,19 @@ function get_form_values(gobj, $form)
3187
3187
  case "input":
3188
3188
  switch(input_type) {
3189
3189
  case "datetime-local":
3190
- value = datetime_local_to_epoch($input.value);
3190
+ /* A box still showing what it was filled with
3191
+ * gives back the value it was filled from: read
3192
+ * as a wall time, an instant in the SECOND pass
3193
+ * of the hour the clocks go back is the first
3194
+ * one, and up to gobj-ui 7.26.50 a save with the
3195
+ * field untouched wrote it -3600 s
3196
+ * (form_time_value.js). */
3197
+ if($input.yui_time_kept &&
3198
+ $input.value === $input.yui_time_kept.shown) {
3199
+ value = $input.yui_time_kept.value;
3200
+ } else {
3201
+ value = datetime_local_to_epoch($input.value);
3202
+ }
3191
3203
  break;
3192
3204
  default:
3193
3205
  value = getInputValue($input);
@@ -3306,6 +3318,7 @@ function clear_data(gobj, $form)
3306
3318
 
3307
3319
  } else if($input.type === 'datetime-local') { /* time */
3308
3320
  $input.value = null;
3321
+ $input.yui_time_kept = null;
3309
3322
 
3310
3323
  } else if($input.type === 'color') {
3311
3324
  /* A colour input holds a colour: the "" a null is written
@@ -3443,6 +3456,7 @@ function set_form_values(gobj, template, $form, record)
3443
3456
  value = field_desc.default_value;
3444
3457
  modified = true;
3445
3458
  }
3459
+ let stored = (value === undefined)? null : value;
3446
3460
  value = treedb_value_2_form_value(gobj, field_desc, value);
3447
3461
  if(value === undefined) {
3448
3462
  /* DOM 'value' setters stringify undefined as "undefined";
@@ -3466,8 +3480,12 @@ function set_form_values(gobj, template, $form, record)
3466
3480
  case "input":
3467
3481
  switch(input_type) {
3468
3482
  case "datetime-local":
3469
- /* value is a Date (see treedb_value_2_form_value) */
3483
+ /* value is a Date (see treedb_value_2_form_value).
3484
+ * The text kept is the one READ BACK: the browser
3485
+ * drops seconds of :00, so the text written never
3486
+ * matches it (get_form_values). */
3470
3487
  $input.value = date_to_datetime_local(value);
3488
+ $input.yui_time_kept = {value: stored, shown: $input.value};
3471
3489
  break;
3472
3490
  case "color":
3473
3491
  $input.value = convertColor(value);
@@ -514,8 +514,6 @@
514
514
  white-space: nowrap;
515
515
  background-color: var(--bulma-danger, #f14668);
516
516
  color: var(--bulma-danger-invert, #fff);
517
- /* Separates the pill from the glyph when they overlap. */
518
- box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
519
517
  pointer-events: none;
520
518
  }
521
519
  .yui-badge[hidden] {
@@ -556,14 +554,24 @@
556
554
  top: -0.35em;
557
555
  right: -0.55em;
558
556
  font-size: 0.62em;
557
+ /* Separates the dot from the glyph it overlaps. */
558
+ box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
559
559
  }
560
560
 
561
- /* Menu item: after the label. Sized in rem, so it is the same
561
+ /* Menu item: after the label, a pill of the size of a Bulma tag
562
+ * (as gobj-ui v1 drew it), with no ring: nothing under it to keep
563
+ * apart, and on the colour of an active item a ring of the page's
564
+ * colour read as a dark circle that ate the tone -- red and yellow
565
+ * were hard to tell at that size. Sized in rem, so it is the same
562
566
  * pill in every layout whatever the item's own font size. */
563
567
  .yui-nav-badge {
564
568
  flex: 0 0 auto;
565
569
  margin-inline-start: 0.4rem;
566
570
  font-size: 0.75rem;
571
+ min-width: 2em;
572
+ height: 2em;
573
+ padding: 0 0.75em;
574
+ font-weight: 400;
567
575
  vertical-align: middle;
568
576
  }
569
577
  /* Where the item already spaces its children (a flex row or column
@@ -585,6 +593,12 @@
585
593
  inset-inline-end: -0.55em;
586
594
  margin: 0;
587
595
  font-size: 0.7rem;
596
+ min-width: 1.15em;
597
+ height: 1.15em;
598
+ padding: 0 0.3em;
599
+ font-weight: 700;
600
+ /* Separates the dot from the glyph it overlaps. */
601
+ box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
588
602
  }
589
603
 
590
604
  /*============================================================
@@ -104,8 +104,11 @@ let __retiring_shell__ = null;
104
104
  * the markers of its overlays and the action entries of its `stay`
105
105
  * routes. They are dead -- nothing closes or opens on them any more --
106
106
  * and the next shell takes them off with ONE history.go(-n) at its
107
- * start, heard by its own expected_pops (retire_dead_entries()). A
108
- * stopped shell moves no history: it would not hear the landing. */
107
+ * start, heard by its own expected_pops, and goes on over them when a
108
+ * Back or Forward of the reader's lands on them (retire_dead_entries()).
109
+ * A key stays here while its entry exists, and leaves when a live shell
110
+ * makes the entry its own again. A stopped shell moves no history: it
111
+ * would not hear the landing. */
109
112
  let __dead_entries__ = new Set();
110
113
 
111
114
  /* A history.back() of a shell that stopped before it landed. Nothing
@@ -256,6 +259,11 @@ let PRIVATE_DATA = {
256
259
  * markers and the action entries of its `stay` routes. Dead once
257
260
  * it stops (__dead_entries__). */
258
261
  own_entries: [],
262
+ /* The index of the entry a traversal comes FROM, told by the
263
+ * Navigation API's currententrychange before its popstate: which
264
+ * way a reader's traversal goes over dead entries. */
265
+ traverse_from: -1,
266
+ entry_change_handler: null,
259
267
  popstate_handler: null,
260
268
  /* Avatar item support — every toolbar item with type:"avatar"
261
269
  * registers its <span> here so refresh_avatars() can repaint
@@ -412,10 +420,21 @@ function mt_start(gobj)
412
420
  return;
413
421
  }
414
422
  note_late_landing(gobj, ev);
423
+ let from = p.traverse_from;
424
+ p.traverse_from = -1;
415
425
  /* A traversal that moved the hash is followed by a
416
426
  * hashchange, QUEUED: it runs after this handler, and it is
417
427
  * the one that navigates (and drains). */
418
428
  let hash_moved = window.location.hash !== p.last_hash;
429
+ if(p.expected_pops === 0 && from >= 0 &&
430
+ retire_dead_entries(gobj, from, hash_moved)) {
431
+ /* A Back or Forward of the reader's onto dead entries
432
+ * goes on over them: what it lands on is not this one. */
433
+ if(!p.skip_hash) {
434
+ p.last_hash = window.location.hash;
435
+ }
436
+ return;
437
+ }
419
438
  if(p.expected_pops > 0 &&
420
439
  window.location.hash !== p.expected_pop_hash) {
421
440
  /* Not the landing of ours: it was dropped. Whatever
@@ -546,6 +565,18 @@ function mt_start(gobj)
546
565
  }
547
566
  };
548
567
  window.addEventListener("popstate", priv.popstate_handler);
568
+ let nav = window.navigation;
569
+ if(nav && typeof nav.addEventListener === "function") {
570
+ priv.entry_change_handler = (ev) => {
571
+ let p = gobj.priv;
572
+ if(!p) {
573
+ return;
574
+ }
575
+ p.traverse_from = (ev && ev.navigationType === "traverse" && ev.from &&
576
+ typeof ev.from.index === "number")? ev.from.index : -1;
577
+ };
578
+ nav.addEventListener("currententrychange", priv.entry_change_handler);
579
+ }
549
580
  keep_dead_entries_across_reload();
550
581
  adopt_orphan_back(gobj);
551
582
  }
@@ -632,6 +663,14 @@ function mt_stop(gobj)
632
663
  window.removeEventListener("popstate", priv.popstate_handler);
633
664
  priv.popstate_handler = null;
634
665
  }
666
+ if(priv.entry_change_handler) {
667
+ let nav = window.navigation;
668
+ if(nav && typeof nav.removeEventListener === "function") {
669
+ nav.removeEventListener("currententrychange", priv.entry_change_handler);
670
+ }
671
+ priv.entry_change_handler = null;
672
+ }
673
+ priv.traverse_from = -1;
635
674
  /* Nothing listens for the landings any more. An overlay that
636
675
  * waited for one gets no marker: it says so, so neither a later
637
676
  * dismissal retires one nor a traversal waits for it. */
@@ -2895,7 +2934,9 @@ function retire_overlays(gobj)
2895
2934
  *
2896
2935
  * A page with no next shell keeps them: with no router on the
2897
2936
  * page, a Back over the app's own entries changes nothing on
2898
- * screen anyway, and the next shell retires them all the same.
2937
+ * screen anyway, and the next shell retires them all the same --
2938
+ * at its start, or when a traversal of the reader's lands on them
2939
+ * if the reader moved meanwhile.
2899
2940
  ************************************************************/
2900
2941
  function hand_over_history(gobj)
2901
2942
  {
@@ -3070,6 +3111,7 @@ function note_own_entry(gobj)
3070
3111
  if(!key || priv.own_entries.includes(key)) {
3071
3112
  return;
3072
3113
  }
3114
+ __dead_entries__.delete(key);
3073
3115
  priv.own_entries.push(key);
3074
3116
  if(priv.own_entries.length > OWN_ENTRIES_PRUNE_AT) {
3075
3117
  /* Entries cut off by a push are gone for good. */
@@ -3082,16 +3124,34 @@ function note_own_entry(gobj)
3082
3124
  * Take off, with ONE history.go(-n), the dead entries a
3083
3125
  * stopped shell left under the current one (hand_over_history).
3084
3126
  * The walk stops at the first entry that is not dead, so it
3085
- * never goes past an entry of the reader's. The traversal is
3086
- * this shell's own (expected_pops): its overlays' markers and
3087
- * the routes it pushes wait for the landing, and a position
3088
- * the URL holds is put back on the entry it lands on, as for
3089
- * any back() of ours (restore_hash). Returns true when it
3090
- * went.
3127
+ * never goes past an entry of the reader's, and at the first
3128
+ * entry of the current document: a navigation to another page
3129
+ * with replace keeps the entry's key, so a later document can
3130
+ * sit on the key of a dead marker, over the entries of the one
3131
+ * before it (up to gobj-ui 7.26.50 the walk went into them and
3132
+ * that document was loaded again). After a reload every entry
3133
+ * is the new document's, and its dead ones go.
3134
+ *
3135
+ * With `from` (the index a traversal of the reader's came
3136
+ * from), it goes on over the dead entries that traversal landed
3137
+ * on, the way it was going: down to the first live one under
3138
+ * them, or up to the first live one over them -- there is none
3139
+ * when they are the newest, and nothing moves. Dead entries
3140
+ * under an entry of the reader's are taken off that way: the
3141
+ * start of a shell never goes past one.
3142
+ *
3143
+ * The traversal is this shell's own (expected_pops): its
3144
+ * overlays' markers and the routes it pushes wait for the
3145
+ * landing. At the start, a position the URL holds is put back
3146
+ * on the entry it lands on, as for any back() of ours
3147
+ * (restore_hash). The keys stay dead while their entries
3148
+ * exist: a later Back or Forward onto them goes over them too.
3149
+ * Returns true when it went.
3091
3150
  ************************************************************/
3092
- function retire_dead_entries(gobj)
3151
+ function retire_dead_entries(gobj, from, hash_moved)
3093
3152
  {
3094
3153
  let priv = gobj.priv;
3154
+ let reader = (typeof from === "number");
3095
3155
  if(__dead_entries__.size === 0 || priv.expected_pops > 0 ||
3096
3156
  !priv.popstate_handler || !current_entry_key()) {
3097
3157
  return false;
@@ -3105,11 +3165,22 @@ function retire_dead_entries(gobj)
3105
3165
  __dead_entries__.delete(key);
3106
3166
  }
3107
3167
  }
3168
+ if(reader && (from === index || !__dead_entries__.has(entries[index].key))) {
3169
+ return false;
3170
+ }
3171
+ let step = (reader && from < index)? 1 : -1;
3108
3172
  let landing = index;
3109
- while(landing > 0 && __dead_entries__.has(entries[landing].key)) {
3110
- landing--;
3173
+ while(__dead_entries__.has(entries[landing].key)) {
3174
+ let next = landing + step;
3175
+ if(next < 0 || next >= entries.length || !entries[next].sameDocument) {
3176
+ break;
3177
+ }
3178
+ landing = next;
3111
3179
  }
3112
- let steps = index - landing;
3180
+ if(step > 0 && __dead_entries__.has(entries[landing].key)) {
3181
+ return false;
3182
+ }
3183
+ let steps = landing - index;
3113
3184
  if(steps === 0) {
3114
3185
  return false;
3115
3186
  }
@@ -3117,21 +3188,28 @@ function retire_dead_entries(gobj)
3117
3188
  try {
3118
3189
  landing_hash = new URL(entries[landing].url).hash;
3119
3190
  } catch(e) {
3120
- log_warning(`C_YUI_SHELL: the entry under the dead ones has no url: ${e}`);
3191
+ log_warning(`C_YUI_SHELL: the entry past the dead ones has no url: ${e}`);
3121
3192
  return false;
3122
3193
  }
3123
- for(let i = landing + 1; i <= index; i++) {
3124
- __dead_entries__.delete(entries[i].key);
3125
- }
3126
3194
  priv.expected_pops++;
3127
3195
  priv.expected_pop_hash = landing_hash;
3128
- priv.restore_hash = (window.location.hash !== landing_hash)? window.location.hash : "";
3196
+ if(reader) {
3197
+ priv.restore_hash = "";
3198
+ /* The hashchange of the landing on the dead entry is queued
3199
+ * before ours lands, and is not the reader's destination. */
3200
+ if(hash_moved && window.location.hash !== landing_hash) {
3201
+ priv.skip_hash = window.location.hash;
3202
+ }
3203
+ } else {
3204
+ priv.restore_hash = (window.location.hash !== landing_hash)? window.location.hash : "";
3205
+ }
3129
3206
  try {
3130
- window.history.go(-steps);
3207
+ window.history.go(steps);
3131
3208
  } catch(e) {
3132
3209
  priv.expected_pops--;
3133
3210
  priv.restore_hash = "";
3134
- log_warning(`C_YUI_SHELL: retiring ${steps} dead history entries failed: ${e}`);
3211
+ priv.skip_hash = "";
3212
+ log_warning(`C_YUI_SHELL: going over ${Math.abs(steps)} dead history entries failed: ${e}`);
3135
3213
  return false;
3136
3214
  }
3137
3215
  clear_deferred_timer(gobj); // a wait that just ended goes on: bound it again
@@ -3317,6 +3395,11 @@ function push_overlay_marker(gobj, entry)
3317
3395
  window.history.replaceState(
3318
3396
  Object.assign({}, below, { __yui_below__: entry.id }), "");
3319
3397
  stamped = true;
3398
+ /* A Back onto it closes this overlay now. */
3399
+ let key = current_entry_key();
3400
+ if(key) {
3401
+ __dead_entries__.delete(key);
3402
+ }
3320
3403
  } catch(e) {
3321
3404
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
3322
3405
  }
@@ -187,3 +187,130 @@ describe("the time field of a form", () => {
187
187
  expect(errors()).toEqual([]);
188
188
  });
189
189
  });
190
+
191
+ /* Chromium and Firefox write a `datetime-local` value without its
192
+ * seconds when they are :00: "…T02:30:00" reads back "…T02:30". */
193
+ function with_browser_box(fn)
194
+ {
195
+ const create = document.createElement;
196
+ document.createElement = function(tag) {
197
+ const el = create.call(document, tag);
198
+ if(String(tag).toLowerCase() === "input") {
199
+ let raw = "";
200
+ Object.defineProperty(el, "value", {
201
+ configurable: true,
202
+ get: () => raw,
203
+ set: (v) => {
204
+ raw = (v === null || v === undefined)? "" :
205
+ String(v).replace(/^(\d{4}-\d\d-\d\dT\d\d:\d\d):00$/, "$1");
206
+ },
207
+ });
208
+ }
209
+ return el;
210
+ };
211
+ try {
212
+ fn();
213
+ } finally {
214
+ document.createElement = create;
215
+ }
216
+ }
217
+
218
+ function in_madrid(fn)
219
+ {
220
+ const tz = process.env.TZ;
221
+ process.env.TZ = "Europe/Madrid";
222
+ try {
223
+ fn();
224
+ } finally {
225
+ if(tz === undefined) {
226
+ delete process.env.TZ;
227
+ } else {
228
+ process.env.TZ = tz;
229
+ }
230
+ }
231
+ }
232
+
233
+ /* 01:30Z and 00:30Z on 2026-10-25 are both 02:30 in Madrid: the
234
+ * second and the first pass of the hour the clocks go back. A wall
235
+ * time read back is the FIRST one. */
236
+ const SECOND_PASS = Date.UTC(2026, 9, 25, 1, 30, 0) / 1000;
237
+ const FIRST_PASS = SECOND_PASS - 3600;
238
+ const SECOND_PASS_S = Date.UTC(2026, 9, 25, 1, 30, 15) / 1000;
239
+
240
+ describe("a time in the repeated hour of autumn, saved with nothing touched", () => {
241
+ test("goes back as the record had it: integer, string, template spec, with and without seconds", () => {
242
+ in_madrid(() => {
243
+ with_browser_box(() => {
244
+ const app = gobj_create_pure_child("tapp4", "C_TEST_TIME_APP", {}, yuno);
245
+ gobj_start(app);
246
+ const form = gobj_create_pure_child("tform4", "C_YUI_FORM", {
247
+ template: {
248
+ when: {type: "integer", flag: ["writable", "persistent", "time"]},
249
+ when_s: {type: "string", flag: ["writable", "persistent", "time"]},
250
+ bare: "time.writable",
251
+ secs: "time.writable",
252
+ },
253
+ record: {
254
+ when: SECOND_PASS,
255
+ when_s: new Date(SECOND_PASS * 1000).toISOString(),
256
+ bare: SECOND_PASS,
257
+ secs: SECOND_PASS_S,
258
+ },
259
+ editable: true,
260
+ }, app);
261
+ gobj_start(form);
262
+
263
+ expect(box(form, "when").value).toBe("2026-10-25T02:30");
264
+ expect(box(form, "secs").value).toBe("2026-10-25T02:30:15");
265
+ expect(gobj_read_attr(form, "edited")).toBe(false);
266
+
267
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
268
+ expect(saved.length).toBe(1);
269
+ expect(saved[0].when).toBe(SECOND_PASS);
270
+ expect(saved[0].when_s).toBe("2026-10-25T01:30:00.000Z");
271
+ expect(saved[0].bare).toBe(SECOND_PASS);
272
+ expect(saved[0].secs).toBe(SECOND_PASS_S);
273
+ expect(errors()).toEqual([]);
274
+ });
275
+ });
276
+ });
277
+
278
+ test("a box the reader changed is read, and a record loaded after another one is ITS value", () => {
279
+ in_madrid(() => {
280
+ with_browser_box(() => {
281
+ const app = gobj_create_pure_child("tapp5", "C_TEST_TIME_APP", {}, yuno);
282
+ gobj_start(app);
283
+ const form = gobj_create_pure_child("tform5", "C_YUI_FORM", {
284
+ template: {when: "time.writable", other: "time.writable"},
285
+ record: {when: SECOND_PASS, other: SECOND_PASS},
286
+ editable: true,
287
+ }, app);
288
+ gobj_start(form);
289
+
290
+ /* The same wall time, the other instant: the box shows
291
+ * the same text, and the save must be the NEW record's. */
292
+ gobj_send_event(form, "EV_LOAD_RECORD", {when: FIRST_PASS, other: null}, form);
293
+ expect(box(form, "when").value).toBe("2026-10-25T02:30");
294
+ expect(box(form, "other").value).toBe("");
295
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
296
+ expect(saved[0].when).toBe(FIRST_PASS);
297
+ expect(saved[0].other).toBe(null);
298
+
299
+ gobj_send_event(form, "EV_LOAD_RECORD", {when: SECOND_PASS, other: SECOND_PASS}, form);
300
+ box(form, "when").value = "2026-10-25T04:00:00";
301
+ box(form, "other").value = "";
302
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
303
+ expect(saved[1].when).toBe(Date.UTC(2026, 9, 25, 3, 0, 0) / 1000);
304
+ expect(saved[1].other).toBe(null);
305
+
306
+ /* Cleared by the form's own Clear: nothing kept. */
307
+ gobj_send_event(form, "EV_LOAD_RECORD", {when: SECOND_PASS, other: SECOND_PASS}, form);
308
+ gobj_send_event(form, "EV_CLEAR_RECORD", {}, form);
309
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
310
+ expect(saved[2].when).toBe(null);
311
+ expect(saved[2].other).toBe(null);
312
+ expect(errors()).toEqual([]);
313
+ });
314
+ });
315
+ });
316
+ });
@@ -15,8 +15,11 @@
15
15
  * `new Date("YYYY-MM-DDT02:30:00")` answers the EARLIER one
16
16
  * (ECMAScript's "compatible" disambiguation). An epoch in the
17
17
  * SECOND pass of that hour is shown as 02:30 and comes back
18
- * one hour earlier: saving the record -- any field of it --
19
- * moves a writable time column that holds it by -3600 s.
18
+ * one hour earlier. So neither the form's field nor the cell
19
+ * editor reads a box that still shows what it was filled
20
+ * with: they give back the value it was filled from (up to
21
+ * gobj-ui 7.26.48 the cell, and 7.26.50 the field, wrote
22
+ * -3600 s on a save of any field of the record).
20
23
  * - the night the clocks go forward (spring), one hour does not
21
24
  * exist. No epoch is shown in it, so nothing read comes back
22
25
  * wrong; a wall time TYPED in it is moved forward by the
@@ -26,8 +29,8 @@
26
29
  * carry. What is safe: a read-only time column never goes back
27
30
  * (treedb_write_plan.js, col_goes_back_to_treedb), and a time
28
31
  * pkey2 goes back as the record had it, never through this
29
- * widget (instance_keys_of). A writable time column edited or
30
- * merely saved inside the repeated hour is the exposed case.
32
+ * widget (instance_keys_of). A wall time TYPED inside the
33
+ * repeated hour is the exposed case: it is the first pass.
31
34
  *
32
35
  * Copyright (c) 2026, ArtGins.
33
36
  * All Rights Reserved.