@yuneta/gobj-ui 7.26.17 → 7.26.19

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.
@@ -2563,13 +2563,19 @@ function push_overlay_marker(gobj, entry) {
2563
2563
  let priv = gobj.priv;
2564
2564
  entry.below_hash = window.location.hash;
2565
2565
  let below = window.history.state;
2566
- let plain = below !== null && typeof below === "object" && (Object.getPrototypeOf(below) === Object.prototype || Object.getPrototypeOf(below) === null);
2566
+ let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
2567
+ let stamped = false;
2567
2568
  if (below === null || plain) try {
2568
2569
  window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2570
+ stamped = true;
2569
2571
  } catch (e) {
2570
2572
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2571
2573
  }
2572
- else (0, _yuneta_gobj_js.log_warning)("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: Back will not close the overlay");
2574
+ else (0, _yuneta_gobj_js.log_warning)("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: the overlay gets no history marker, Back will not close it (its own controls do)");
2575
+ if (!stamped) {
2576
+ entry.no_marker = true;
2577
+ return true;
2578
+ }
2573
2579
  try {
2574
2580
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2575
2581
  } catch (e) {
@@ -2594,6 +2600,7 @@ function drop_expected_pops(gobj) {
2594
2600
  }
2595
2601
  }
2596
2602
  var DEFERRED_ROUTE_WAIT_MS = 1e3;
2603
+ var LATE_LANDING_WINDOW_MS = 5e3;
2597
2604
  function defer_route(gobj, route) {
2598
2605
  let priv = gobj.priv;
2599
2606
  if (priv.deferred_route && priv.deferred_route !== route) (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() of ours is replaced by '${route}'`);
@@ -2608,6 +2615,10 @@ function note_late_landing(gobj, ev) {
2608
2615
  let priv = gobj.priv;
2609
2616
  let given_up = priv.given_up;
2610
2617
  let st = ev && ev.state;
2618
+ if (given_up && performance.now() > given_up.until) {
2619
+ priv.given_up = null;
2620
+ return;
2621
+ }
2611
2622
  if (!given_up || !st) return;
2612
2623
  priv.given_up = null;
2613
2624
  if (given_up.ids.includes(st.__yui_overlay__)) (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: a traversal landed on the marker of an overlay whose history.back() was given up on: if it is that back(), arriving late, it undoes route '${given_up.route}'`);
@@ -2627,7 +2638,7 @@ function push_pending_markers(gobj) {
2627
2638
  entry.marker_pending = false;
2628
2639
  if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
2629
2640
  entry.hash = window.location.hash;
2630
- if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
2641
+ if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
2631
2642
  }
2632
2643
  clear_deferred_timer(gobj);
2633
2644
  if (priv.expected_pops === 0) priv.expected_pop_ids = [];
@@ -2783,7 +2794,8 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
2783
2794
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2784
2795
  let given_up = {
2785
2796
  ids: priv.expected_pop_ids.slice(),
2786
- route: priv.deferred_route
2797
+ route: priv.deferred_route,
2798
+ until: performance.now() + LATE_LANDING_WINDOW_MS
2787
2799
  };
2788
2800
  priv.expected_pops = 0;
2789
2801
  priv.expected_pop_hash = "";
@@ -2558,13 +2558,19 @@ function push_overlay_marker(gobj, entry) {
2558
2558
  let priv = gobj.priv;
2559
2559
  entry.below_hash = window.location.hash;
2560
2560
  let below = window.history.state;
2561
- let plain = below !== null && typeof below === "object" && (Object.getPrototypeOf(below) === Object.prototype || Object.getPrototypeOf(below) === null);
2561
+ let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
2562
+ let stamped = false;
2562
2563
  if (below === null || plain) try {
2563
2564
  window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2565
+ stamped = true;
2564
2566
  } catch (e) {
2565
2567
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2566
2568
  }
2567
- else log_warning("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: Back will not close the overlay");
2569
+ else log_warning("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: the overlay gets no history marker, Back will not close it (its own controls do)");
2570
+ if (!stamped) {
2571
+ entry.no_marker = true;
2572
+ return true;
2573
+ }
2568
2574
  try {
2569
2575
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2570
2576
  } catch (e) {
@@ -2589,6 +2595,7 @@ function drop_expected_pops(gobj) {
2589
2595
  }
2590
2596
  }
2591
2597
  var DEFERRED_ROUTE_WAIT_MS = 1e3;
2598
+ var LATE_LANDING_WINDOW_MS = 5e3;
2592
2599
  function defer_route(gobj, route) {
2593
2600
  let priv = gobj.priv;
2594
2601
  if (priv.deferred_route && priv.deferred_route !== route) log_warning(`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() of ours is replaced by '${route}'`);
@@ -2603,6 +2610,10 @@ function note_late_landing(gobj, ev) {
2603
2610
  let priv = gobj.priv;
2604
2611
  let given_up = priv.given_up;
2605
2612
  let st = ev && ev.state;
2613
+ if (given_up && performance.now() > given_up.until) {
2614
+ priv.given_up = null;
2615
+ return;
2616
+ }
2606
2617
  if (!given_up || !st) return;
2607
2618
  priv.given_up = null;
2608
2619
  if (given_up.ids.includes(st.__yui_overlay__)) log_warning(`C_YUI_SHELL: a traversal landed on the marker of an overlay whose history.back() was given up on: if it is that back(), arriving late, it undoes route '${given_up.route}'`);
@@ -2622,7 +2633,7 @@ function push_pending_markers(gobj) {
2622
2633
  entry.marker_pending = false;
2623
2634
  if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
2624
2635
  entry.hash = window.location.hash;
2625
- if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
2636
+ if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
2626
2637
  }
2627
2638
  clear_deferred_timer(gobj);
2628
2639
  if (priv.expected_pops === 0) priv.expected_pop_ids = [];
@@ -2778,7 +2789,8 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
2778
2789
  log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2779
2790
  let given_up = {
2780
2791
  ids: priv.expected_pop_ids.slice(),
2781
- route: priv.deferred_route
2792
+ route: priv.deferred_route,
2793
+ until: performance.now() + LATE_LANDING_WINDOW_MS
2782
2794
  };
2783
2795
  priv.expected_pops = 0;
2784
2796
  priv.expected_pop_hash = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.17",
3
+ "version": "7.26.19",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -34,8 +34,9 @@
34
34
  * string (its type is not known before running); a description
35
35
  * built piece by piece (push() into an array that is later the
36
36
  * content); a computed tag with an attrs slot that is not an object
37
- * literal; a replace() whose replacement is a function or whose
38
- * pattern is a variable, and a method called on a function result
37
+ * literal; a replace() whose replacement is a function, whose
38
+ * pattern is a variable, or whose replacement starts with a special
39
+ * pattern ('$`<i>', '$1'), and a method called on a function result
39
40
  * (String(x).replace(...)); markup given to innerHTML, or to a
40
41
  * widget (Tabulator, G6), which are other sinks. set_strings_are_text(true) logs, once
41
42
  * at run time, every string that reaches createElement2() starting
@@ -118,7 +119,13 @@ const PURE_METHODS = new Set([
118
119
  * 'abc'.replace('abc', '<i>' + y) is '<i>' + data: built). Where the
119
120
  * first match is decides it, so the replacement is the head only when the
120
121
  * pattern can match at 0: ('z' + name).replace('a', '<b>') starts with
121
- * 'z', and 'abc'.replace('x', '<i>' + y) is 'abc'.
122
+ * 'z', and 'abc'.replace('x', '<i>' + y) is 'abc'. With only blank
123
+ * before where it can match, the replacement still heads the content,
124
+ * since createElement2() trims.
125
+ * A regex on a receiver that carries data is not positioned at all:
126
+ * alternatives and lookaheads can make the data match first, so markup
127
+ * in the replacement is taken as the head (the conservative reading).
128
+ * A `$` in the replacement ends what is known of it.
122
129
  * Not seen: a replacement that is a function, a pattern in a variable. */
123
130
  function static_pattern(arg)
124
131
  {
@@ -169,7 +176,24 @@ function replaced(method, head, args)
169
176
  return {text: head.text, complete: false};
170
177
  }
171
178
  }
172
- const rep_head = replacement ? replacement.text : "";
179
+ /* What the replacement is known to start with. A `$` in it is a
180
+ * special pattern ($&, $`, $', $1...): what it expands to is only
181
+ * known at run time, so the known head stops there. */
182
+ let rep_head = replacement ? replacement.text : "";
183
+ if(rep_head.includes("$")) {
184
+ rep_head = rep_head.slice(0, rep_head.indexOf("$"));
185
+ }
186
+ if(!head.complete && typeof pattern !== "string") {
187
+ /* A regex on a receiver that carries data: alternatives and
188
+ * lookaheads can make the data match before anything the known
189
+ * text says, so no position is computed. Markup in the
190
+ * replacement may be the head (the conservative reading); if not,
191
+ * the receiver's head stands. */
192
+ if(starts_with_markup(rep_head)) {
193
+ return {text: rep_head, complete: false};
194
+ }
195
+ return {text: head.text, complete: false};
196
+ }
173
197
  const idx = first_match(head.text, pattern);
174
198
  if(idx >= 0) {
175
199
  return {text: head.text.slice(0, idx) + rep_head, complete: false};
@@ -177,16 +201,19 @@ function replaced(method, head, args)
177
201
  if(head.complete) {
178
202
  return {text: head.text, complete: true}; // no match: the receiver as it is
179
203
  }
180
- if(typeof pattern === "string") {
181
- /* The first match is in the data: no earlier than where the
182
- * pattern could start straddling the known text. */
183
- const keep = Math.max(0, head.text.length - pattern.length + 1);
184
- if(keep === 0) {
185
- return {text: rep_head, complete: false};
186
- }
187
- return {text: head.text.slice(0, keep), complete: false};
204
+ /* A string pattern with no match in the known text: the first match
205
+ * starts in the data, or straddles the end of the known text -- only
206
+ * where what is left of the known text is a prefix of the pattern. */
207
+ let keep = Math.max(0, head.text.length - pattern.length + 1);
208
+ while(keep < head.text.length && !pattern.startsWith(head.text.slice(keep))) {
209
+ keep++;
210
+ }
211
+ /* Only blank before the match: createElement2() trims, so the
212
+ * replacement's head is what starts the content (' <b>' is markup). */
213
+ if(head.text.slice(0, keep).trim() === "") {
214
+ return {text: head.text.slice(0, keep) + rep_head, complete: false};
188
215
  }
189
- return {text: head.text, complete: false};
216
+ return {text: head.text.slice(0, keep), complete: false};
190
217
  }
191
218
 
192
219
  function concat_parts(parts)
@@ -2804,23 +2804,33 @@ function push_overlay_marker(gobj, entry)
2804
2804
  * is added to them, and replaces an older stamp. */
2805
2805
  let below = window.history.state;
2806
2806
  /* A PLAIN object only: a Map or a Date is an object too (the state
2807
- * is a structured clone), and Object.assign() copies none of it. */
2807
+ * is a structured clone, so a plain object comes back with
2808
+ * Object.prototype), and Object.assign() copies none of it. */
2808
2809
  let plain = below !== null && typeof below === "object" &&
2809
- (Object.getPrototypeOf(below) === Object.prototype ||
2810
- Object.getPrototypeOf(below) === null);
2810
+ Object.getPrototypeOf(below) === Object.prototype;
2811
+ let stamped = false;
2811
2812
  if(below === null || plain) {
2812
2813
  try {
2813
2814
  window.history.replaceState(
2814
2815
  Object.assign({}, below, { __yui_below__: entry.id }), "");
2816
+ stamped = true;
2815
2817
  } catch(e) {
2816
2818
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2817
2819
  }
2818
2820
  } else {
2819
2821
  log_warning(
2820
2822
  `C_YUI_SHELL: the entry under an overlay holds a history state that ` +
2821
- `is not a plain object, it cannot be stamped: Back will not close the overlay`
2823
+ `is not a plain object, it cannot be stamped: the overlay gets no ` +
2824
+ `history marker, Back will not close it (its own controls do)`
2822
2825
  );
2823
2826
  }
2827
+ if(!stamped) {
2828
+ /* With no stamp under it, no Back can step off its marker: a
2829
+ * marker would only swallow one Back of the reader's. The overlay
2830
+ * goes without one, and closes by its own controls. */
2831
+ entry.no_marker = true;
2832
+ return true;
2833
+ }
2824
2834
  try {
2825
2835
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2826
2836
  } catch(e) {
@@ -2874,6 +2884,11 @@ function drop_expected_pops(gobj)
2874
2884
  * every later navigation. */
2875
2885
  const DEFERRED_ROUTE_WAIT_MS = 1000;
2876
2886
 
2887
+ /* How long after giving up a landing on one of those markers is still
2888
+ * said to be, perhaps, the late back(): after that it is a Back of the
2889
+ * reader's, and saying otherwise is a false alarm. */
2890
+ const LATE_LANDING_WINDOW_MS = 5000;
2891
+
2877
2892
  function defer_route(gobj, route)
2878
2893
  {
2879
2894
  let priv = gobj.priv;
@@ -2907,6 +2922,10 @@ function note_late_landing(gobj, ev)
2907
2922
  let priv = gobj.priv;
2908
2923
  let given_up = priv.given_up;
2909
2924
  let st = ev && ev.state;
2925
+ if(given_up && performance.now() > given_up.until) {
2926
+ priv.given_up = null; // too late to be that back(): a Back of the reader's
2927
+ return;
2928
+ }
2910
2929
  if(!given_up || !st) {
2911
2930
  return; // a push (the waiting route's own) lands on a fresh entry
2912
2931
  }
@@ -2945,7 +2964,7 @@ function push_pending_markers(gobj)
2945
2964
  /* The traversal was same-hash, but a route may have moved
2946
2965
  * meanwhile: the marker lives on the hash it is pushed on. */
2947
2966
  entry.hash = window.location.hash;
2948
- if(push_overlay_marker(gobj, entry)) {
2967
+ if(push_overlay_marker(gobj, entry) && !entry.no_marker) {
2949
2968
  pushed.push(entry.id);
2950
2969
  }
2951
2970
  // else: Error already logged
@@ -3269,7 +3288,13 @@ function ac_back_wait_timeout(gobj, event, kw, src)
3269
3288
  `C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not ` +
3270
3289
  `land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
3271
3290
  );
3272
- let given_up = {ids: priv.expected_pop_ids.slice(), route: priv.deferred_route};
3291
+ let given_up = {
3292
+ ids: priv.expected_pop_ids.slice(),
3293
+ route: priv.deferred_route,
3294
+ /* A monotonic clock: a wall clock set back holds the window
3295
+ * open, set forward closes it early. */
3296
+ until: performance.now() + LATE_LANDING_WINDOW_MS
3297
+ };
3273
3298
  priv.expected_pops = 0;
3274
3299
  priv.expected_pop_hash = "";
3275
3300
  priv.expected_pop_ids = [];
@@ -19,7 +19,7 @@
19
19
  * Copyright (c) 2026, ArtGins.
20
20
  * All Rights Reserved.
21
21
  ***********************************************************************/
22
- import {describe, test, expect, beforeAll, beforeEach, afterEach} from "vitest";
22
+ import {describe, test, expect, beforeAll, beforeEach, afterEach, vi} from "vitest";
23
23
  import {install_dom_double} from "../test/dom_double.js";
24
24
 
25
25
  install_dom_double();
@@ -1000,8 +1000,45 @@ describe("V8: the edges of the stamp and of the late landing", () => {
1000
1000
  const app_state = new Map([["k", 1]]);
1001
1001
  window.history.replaceState(app_state, "");
1002
1002
  logged.length = 0;
1003
- yui_shell_register_overlay(shell, () => {});
1003
+ const entry = yui_shell_register_overlay(shell, () => {});
1004
1004
  expect(session.entries[0].state).toBe(app_state);
1005
1005
  expect(shell_warnings().filter(m => m.includes("not a plain object")).length).toBe(1);
1006
+ /* V9.3: no marker, so no Back of the reader's is spent on it. */
1007
+ expect(entry.no_marker).toBe(true);
1008
+ expect(session.entries.length).toBe(1);
1009
+ });
1010
+ });
1011
+
1012
+ describe("V9: the warning of a late back() has a window", () => {
1013
+ test("a landing on the dead marker long after giving up is the reader's Back: no warning", async () => {
1014
+ const app = gobj_create("v9app1", "C_TEST_MARKER_APP", {}, yuno);
1015
+ gobj_start(app);
1016
+ window.location.hash = "#/home";
1017
+ install_history_model();
1018
+ const shell = routed_shell("v9shell1", app);
1019
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
1020
+ await import("./c_yui_shell.js");
1021
+ const x = yui_shell_register_overlay(shell, () => {});
1022
+ let late = null;
1023
+ window.history.back = () => { late = () => traverse_to(session.index - 1); };
1024
+ links_on_hash_assign();
1025
+
1026
+ yui_shell_overlay_dismissed(shell, x);
1027
+ yui_shell_navigate(shell, "/prev");
1028
+ await new Promise(resolve => setTimeout(resolve, 1100));
1029
+ await next_task();
1030
+ expect(shell_warnings().filter(m => m.includes("given up")).length).toBe(1);
1031
+
1032
+ const now = performance.now();
1033
+ const spy = vi.spyOn(performance, "now").mockImplementation(() => now + 6000);
1034
+ try {
1035
+ late(); // the reader's Back, 6 s later
1036
+ await next_task();
1037
+ await next_task();
1038
+ } finally {
1039
+ spy.mockRestore();
1040
+ }
1041
+ expect(shell_warnings().filter(m => m.includes("arriving late")).length).toBe(0);
1042
+ expect(shell.priv.given_up).toBe(null);
1006
1043
  });
1007
1044
  });