@yuneta/gobj-ui 7.26.15 → 7.26.16

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.
@@ -970,7 +970,6 @@ var PRIVATE_DATA$22 = {
970
970
  keydown_handler: null,
971
971
  escape_stack: [],
972
972
  overlay_stack: [],
973
- overlay_seq: 0,
974
973
  expected_pops: 0,
975
974
  expected_pop_hash: "",
976
975
  pending_markers: [],
@@ -980,6 +979,8 @@ var PRIVATE_DATA$22 = {
980
979
  skip_hash: "",
981
980
  deferred_route: "",
982
981
  deferred_timer: null,
982
+ expected_pop_ids: [],
983
+ given_up: null,
983
984
  popstate_handler: null,
984
985
  avatar_provider: null,
985
986
  avatar_nodes: [],
@@ -1053,6 +1054,7 @@ function mt_start$20(gobj) {
1053
1054
  priv.popstate_handler = (ev) => {
1054
1055
  let p = gobj.priv;
1055
1056
  if (!p) return;
1057
+ note_late_landing(gobj, ev);
1056
1058
  let hash_moved = window.location.hash !== p.last_hash;
1057
1059
  if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
1058
1060
  drop_expected_pops(gobj);
@@ -1087,9 +1089,7 @@ function mt_start$20(gobj) {
1087
1089
  if (top.marker_pending || top.no_marker) return;
1088
1090
  if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
1089
1091
  let st = ev && ev.state;
1090
- if (!st) return;
1091
- if (st.__yui_overlay__ === top.id) return;
1092
- if (st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
1092
+ if (!st || st.__yui_below__ !== top.id) return;
1093
1093
  p.overlay_stack.pop();
1094
1094
  try {
1095
1095
  top.close();
@@ -1150,6 +1150,8 @@ function mt_stop$20(gobj) {
1150
1150
  priv.skip_hash = "";
1151
1151
  priv.deferred_route = "";
1152
1152
  clear_deferred_timer(gobj);
1153
+ priv.expected_pop_ids = [];
1154
+ priv.given_up = null;
1153
1155
  if (priv.keydown_handler) {
1154
1156
  window.removeEventListener("keydown", priv.keydown_handler);
1155
1157
  priv.keydown_handler = null;
@@ -2538,11 +2540,12 @@ function retag_overlay_hash(gobj, st, hash) {
2538
2540
  let entry = priv.overlay_stack.find((e) => e.id === st.__yui_overlay__);
2539
2541
  if (entry) entry.hash = hash;
2540
2542
  }
2543
+ var __overlay_seq__ = Date.now() * 1e3;
2541
2544
  function push_overlay_history(gobj, close, opts) {
2542
2545
  let priv = gobj.priv;
2543
2546
  if (!priv || !priv.overlay_stack || !(0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash")) return null;
2544
2547
  let entry = {
2545
- id: ++priv.overlay_seq,
2548
+ id: ++__overlay_seq__,
2546
2549
  close,
2547
2550
  hash: window.location.hash,
2548
2551
  keep_on_navigate: !!(opts && opts.keep_on_navigate)
@@ -2559,11 +2562,13 @@ function push_overlay_history(gobj, close, opts) {
2559
2562
  function push_overlay_marker(gobj, entry) {
2560
2563
  let priv = gobj.priv;
2561
2564
  entry.below_hash = window.location.hash;
2562
- if (window.history.state === null) try {
2563
- window.history.replaceState({ __yui_below__: entry.id }, "");
2565
+ let below = window.history.state;
2566
+ if (below === null || typeof below === "object" && !Array.isArray(below)) try {
2567
+ window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2564
2568
  } catch (e) {
2565
2569
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2566
2570
  }
2571
+ else (0, _yuneta_gobj_js.log_warning)("C_YUI_SHELL: the entry under an overlay holds a history state that is not an object, it cannot be stamped: Back will not close the overlay");
2567
2572
  try {
2568
2573
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2569
2574
  } catch (e) {
@@ -2580,6 +2585,7 @@ function drop_expected_pops(gobj) {
2580
2585
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land on '${priv.expected_pop_hash}' (now '${window.location.hash}'), dropped`);
2581
2586
  priv.expected_pops = 0;
2582
2587
  priv.expected_pop_hash = "";
2588
+ priv.expected_pop_ids = [];
2583
2589
  clear_deferred_timer(gobj);
2584
2590
  if (priv.deferred_route) {
2585
2591
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: route '${priv.deferred_route}' waited for that back() and is dropped: the history moved on to '${window.location.hash}'`);
@@ -2592,17 +2598,19 @@ function defer_route(gobj, route) {
2592
2598
  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}'`);
2593
2599
  priv.deferred_route = route;
2594
2600
  if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
2595
- let p = gobj.priv;
2596
- if (!p) return;
2597
- p.deferred_timer = null;
2598
- if (p.expected_pops === 0) return;
2599
- (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2600
- p.expected_pops = 0;
2601
- p.expected_pop_hash = "";
2602
- p.restore_hash = "";
2603
- push_pending_markers(gobj);
2601
+ if (!gobj.priv) return;
2602
+ gobj.priv.deferred_timer = null;
2603
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2604
2604
  }, DEFERRED_ROUTE_WAIT_MS);
2605
2605
  }
2606
+ function note_late_landing(gobj, ev) {
2607
+ let priv = gobj.priv;
2608
+ let given_up = priv.given_up;
2609
+ let st = ev && ev.state;
2610
+ if (!given_up || !st) return;
2611
+ priv.given_up = null;
2612
+ 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}'`);
2613
+ }
2606
2614
  function clear_deferred_timer(gobj) {
2607
2615
  let priv = gobj.priv;
2608
2616
  if (priv.deferred_timer) {
@@ -2620,6 +2628,7 @@ function push_pending_markers(gobj) {
2620
2628
  push_overlay_marker(gobj, entry);
2621
2629
  }
2622
2630
  clear_deferred_timer(gobj);
2631
+ if (priv.expected_pops === 0) priv.expected_pop_ids = [];
2623
2632
  if (priv.deferred_route) {
2624
2633
  let route = priv.deferred_route;
2625
2634
  priv.deferred_route = "";
@@ -2637,12 +2646,14 @@ function overlay_dismissed(gobj, entry) {
2637
2646
  let st = window.history.state;
2638
2647
  if (st && st.__yui_overlay__ === entry.id) {
2639
2648
  priv.expected_pops++;
2649
+ priv.expected_pop_ids.push(entry.id);
2640
2650
  priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
2641
2651
  priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
2642
2652
  try {
2643
2653
  window.history.back();
2644
2654
  } catch (e) {
2645
2655
  priv.expected_pops--;
2656
+ priv.expected_pop_ids.pop();
2646
2657
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2647
2658
  }
2648
2659
  }
@@ -2759,6 +2770,27 @@ function ac_nav_clicked(gobj, event, kw, src) {
2759
2770
  return 0;
2760
2771
  }
2761
2772
  /************************************************************
2773
+ * The wait for a back() of ours is over and it has not landed
2774
+ * (defer_route()): give it up, and run the route that waited for it.
2775
+ * If it lands after all, note_late_landing() says so.
2776
+ ************************************************************/
2777
+ function ac_back_wait_timeout(gobj, event, kw, src) {
2778
+ let priv = gobj.priv;
2779
+ if (priv.expected_pops === 0) return 0;
2780
+ (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`);
2781
+ let given_up = {
2782
+ ids: priv.expected_pop_ids.slice(),
2783
+ route: priv.deferred_route
2784
+ };
2785
+ priv.expected_pops = 0;
2786
+ priv.expected_pop_hash = "";
2787
+ priv.expected_pop_ids = [];
2788
+ priv.restore_hash = "";
2789
+ push_pending_markers(gobj);
2790
+ priv.given_up = given_up;
2791
+ return 0;
2792
+ }
2793
+ /************************************************************
2762
2794
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
2763
2795
  * this so the shell can close the drawer through the canonical
2764
2796
  * flow (DOM + focus-trap + escape-stack pop) instead of mutating
@@ -2831,11 +2863,17 @@ function create_gclass$22(gclass_name) {
2831
2863
  "EV_NAV_ITEM_CLOSE",
2832
2864
  ac_nav_item_close,
2833
2865
  null
2866
+ ],
2867
+ [
2868
+ "EV_BACK_WAIT_TIMEOUT",
2869
+ ac_back_wait_timeout,
2870
+ null
2834
2871
  ]
2835
2872
  ]]];
2836
2873
  const event_types = [
2837
2874
  ["EV_NAV_CLICKED", 0],
2838
2875
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
2876
+ ["EV_BACK_WAIT_TIMEOUT", 0],
2839
2877
  ["EV_NAV_ITEM_CLOSE", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT | _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT | _yuneta_gobj_js.event_flag_t.EVF_NO_WARN_SUBS],
2840
2878
  ["EV_ROUTE_REQUESTED", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT | _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT | _yuneta_gobj_js.event_flag_t.EVF_NO_WARN_SUBS],
2841
2879
  ["EV_ROUTE_CHANGED", _yuneta_gobj_js.event_flag_t.EVF_OUTPUT_EVENT | _yuneta_gobj_js.event_flag_t.EVF_PUBLIC_EVENT | _yuneta_gobj_js.event_flag_t.EVF_NO_WARN_SUBS],
@@ -965,7 +965,6 @@ var PRIVATE_DATA$22 = {
965
965
  keydown_handler: null,
966
966
  escape_stack: [],
967
967
  overlay_stack: [],
968
- overlay_seq: 0,
969
968
  expected_pops: 0,
970
969
  expected_pop_hash: "",
971
970
  pending_markers: [],
@@ -975,6 +974,8 @@ var PRIVATE_DATA$22 = {
975
974
  skip_hash: "",
976
975
  deferred_route: "",
977
976
  deferred_timer: null,
977
+ expected_pop_ids: [],
978
+ given_up: null,
978
979
  popstate_handler: null,
979
980
  avatar_provider: null,
980
981
  avatar_nodes: [],
@@ -1048,6 +1049,7 @@ function mt_start$20(gobj) {
1048
1049
  priv.popstate_handler = (ev) => {
1049
1050
  let p = gobj.priv;
1050
1051
  if (!p) return;
1052
+ note_late_landing(gobj, ev);
1051
1053
  let hash_moved = window.location.hash !== p.last_hash;
1052
1054
  if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
1053
1055
  drop_expected_pops(gobj);
@@ -1082,9 +1084,7 @@ function mt_start$20(gobj) {
1082
1084
  if (top.marker_pending || top.no_marker) return;
1083
1085
  if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
1084
1086
  let st = ev && ev.state;
1085
- if (!st) return;
1086
- if (st.__yui_overlay__ === top.id) return;
1087
- if (st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
1087
+ if (!st || st.__yui_below__ !== top.id) return;
1088
1088
  p.overlay_stack.pop();
1089
1089
  try {
1090
1090
  top.close();
@@ -1145,6 +1145,8 @@ function mt_stop$20(gobj) {
1145
1145
  priv.skip_hash = "";
1146
1146
  priv.deferred_route = "";
1147
1147
  clear_deferred_timer(gobj);
1148
+ priv.expected_pop_ids = [];
1149
+ priv.given_up = null;
1148
1150
  if (priv.keydown_handler) {
1149
1151
  window.removeEventListener("keydown", priv.keydown_handler);
1150
1152
  priv.keydown_handler = null;
@@ -2533,11 +2535,12 @@ function retag_overlay_hash(gobj, st, hash) {
2533
2535
  let entry = priv.overlay_stack.find((e) => e.id === st.__yui_overlay__);
2534
2536
  if (entry) entry.hash = hash;
2535
2537
  }
2538
+ var __overlay_seq__ = Date.now() * 1e3;
2536
2539
  function push_overlay_history(gobj, close, opts) {
2537
2540
  let priv = gobj.priv;
2538
2541
  if (!priv || !priv.overlay_stack || !gobj_read_attr(gobj, "use_hash")) return null;
2539
2542
  let entry = {
2540
- id: ++priv.overlay_seq,
2543
+ id: ++__overlay_seq__,
2541
2544
  close,
2542
2545
  hash: window.location.hash,
2543
2546
  keep_on_navigate: !!(opts && opts.keep_on_navigate)
@@ -2554,11 +2557,13 @@ function push_overlay_history(gobj, close, opts) {
2554
2557
  function push_overlay_marker(gobj, entry) {
2555
2558
  let priv = gobj.priv;
2556
2559
  entry.below_hash = window.location.hash;
2557
- if (window.history.state === null) try {
2558
- window.history.replaceState({ __yui_below__: entry.id }, "");
2560
+ let below = window.history.state;
2561
+ if (below === null || typeof below === "object" && !Array.isArray(below)) try {
2562
+ window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2559
2563
  } catch (e) {
2560
2564
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2561
2565
  }
2566
+ else log_warning("C_YUI_SHELL: the entry under an overlay holds a history state that is not an object, it cannot be stamped: Back will not close the overlay");
2562
2567
  try {
2563
2568
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2564
2569
  } catch (e) {
@@ -2575,6 +2580,7 @@ function drop_expected_pops(gobj) {
2575
2580
  log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land on '${priv.expected_pop_hash}' (now '${window.location.hash}'), dropped`);
2576
2581
  priv.expected_pops = 0;
2577
2582
  priv.expected_pop_hash = "";
2583
+ priv.expected_pop_ids = [];
2578
2584
  clear_deferred_timer(gobj);
2579
2585
  if (priv.deferred_route) {
2580
2586
  log_warning(`C_YUI_SHELL: route '${priv.deferred_route}' waited for that back() and is dropped: the history moved on to '${window.location.hash}'`);
@@ -2587,17 +2593,19 @@ function defer_route(gobj, route) {
2587
2593
  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}'`);
2588
2594
  priv.deferred_route = route;
2589
2595
  if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
2590
- let p = gobj.priv;
2591
- if (!p) return;
2592
- p.deferred_timer = null;
2593
- if (p.expected_pops === 0) return;
2594
- log_warning(`C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2595
- p.expected_pops = 0;
2596
- p.expected_pop_hash = "";
2597
- p.restore_hash = "";
2598
- push_pending_markers(gobj);
2596
+ if (!gobj.priv) return;
2597
+ gobj.priv.deferred_timer = null;
2598
+ gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2599
2599
  }, DEFERRED_ROUTE_WAIT_MS);
2600
2600
  }
2601
+ function note_late_landing(gobj, ev) {
2602
+ let priv = gobj.priv;
2603
+ let given_up = priv.given_up;
2604
+ let st = ev && ev.state;
2605
+ if (!given_up || !st) return;
2606
+ priv.given_up = null;
2607
+ 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}'`);
2608
+ }
2601
2609
  function clear_deferred_timer(gobj) {
2602
2610
  let priv = gobj.priv;
2603
2611
  if (priv.deferred_timer) {
@@ -2615,6 +2623,7 @@ function push_pending_markers(gobj) {
2615
2623
  push_overlay_marker(gobj, entry);
2616
2624
  }
2617
2625
  clear_deferred_timer(gobj);
2626
+ if (priv.expected_pops === 0) priv.expected_pop_ids = [];
2618
2627
  if (priv.deferred_route) {
2619
2628
  let route = priv.deferred_route;
2620
2629
  priv.deferred_route = "";
@@ -2632,12 +2641,14 @@ function overlay_dismissed(gobj, entry) {
2632
2641
  let st = window.history.state;
2633
2642
  if (st && st.__yui_overlay__ === entry.id) {
2634
2643
  priv.expected_pops++;
2644
+ priv.expected_pop_ids.push(entry.id);
2635
2645
  priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
2636
2646
  priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
2637
2647
  try {
2638
2648
  window.history.back();
2639
2649
  } catch (e) {
2640
2650
  priv.expected_pops--;
2651
+ priv.expected_pop_ids.pop();
2641
2652
  log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2642
2653
  }
2643
2654
  }
@@ -2754,6 +2765,27 @@ function ac_nav_clicked(gobj, event, kw, src) {
2754
2765
  return 0;
2755
2766
  }
2756
2767
  /************************************************************
2768
+ * The wait for a back() of ours is over and it has not landed
2769
+ * (defer_route()): give it up, and run the route that waited for it.
2770
+ * If it lands after all, note_late_landing() says so.
2771
+ ************************************************************/
2772
+ function ac_back_wait_timeout(gobj, event, kw, src) {
2773
+ let priv = gobj.priv;
2774
+ if (priv.expected_pops === 0) return 0;
2775
+ log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2776
+ let given_up = {
2777
+ ids: priv.expected_pop_ids.slice(),
2778
+ route: priv.deferred_route
2779
+ };
2780
+ priv.expected_pops = 0;
2781
+ priv.expected_pop_hash = "";
2782
+ priv.expected_pop_ids = [];
2783
+ priv.restore_hash = "";
2784
+ push_pending_markers(gobj);
2785
+ priv.given_up = given_up;
2786
+ return 0;
2787
+ }
2788
+ /************************************************************
2757
2789
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
2758
2790
  * this so the shell can close the drawer through the canonical
2759
2791
  * flow (DOM + focus-trap + escape-stack pop) instead of mutating
@@ -2826,11 +2858,17 @@ function create_gclass$22(gclass_name) {
2826
2858
  "EV_NAV_ITEM_CLOSE",
2827
2859
  ac_nav_item_close,
2828
2860
  null
2861
+ ],
2862
+ [
2863
+ "EV_BACK_WAIT_TIMEOUT",
2864
+ ac_back_wait_timeout,
2865
+ null
2829
2866
  ]
2830
2867
  ]]];
2831
2868
  const event_types = [
2832
2869
  ["EV_NAV_CLICKED", 0],
2833
2870
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
2871
+ ["EV_BACK_WAIT_TIMEOUT", 0],
2834
2872
  ["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2835
2873
  ["EV_ROUTE_REQUESTED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2836
2874
  ["EV_ROUTE_CHANGED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.15",
3
+ "version": "7.26.16",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -109,12 +109,16 @@ const PURE_METHODS = new Set([
109
109
 
110
110
  /* replace()/replaceAll() on a receiver that is static and with static
111
111
  * arguments is computed, so a tag stripped away is seen as stripped.
112
- * Anything else keeps the receiver's head and is no longer static: a
112
+ * Anything else is no longer static. Its head is the receiver's -- a
113
113
  * receiver that carries data stays BUILT markup through them, and so
114
114
  * does a static one whose replacement is data
115
- * ('<b>NAME</b>'.replace('NAME', name)). */
115
+ * ('<b>NAME</b>'.replace('NAME', name)) -- unless the REPLACEMENT brings
116
+ * markup: then that is what the result may start with, and with data
117
+ * somewhere it is built markup ('x'.replace('x', `<b>${y}</b>`),
118
+ * ('a' + name).replace('a', '<b>')). */
116
119
  function replaced(method, head, args)
117
120
  {
121
+ let replacement = (args.length === 2)? leading(args[1]) : null;
118
122
  if(head.complete && args.length === 2) {
119
123
  let pattern = null;
120
124
  if(args[0].type === "Literal" && args[0].regex) {
@@ -126,7 +130,6 @@ function replaced(method, head, args)
126
130
  } else if(is_string_literal(args[0])) {
127
131
  pattern = args[0].value;
128
132
  }
129
- let replacement = leading(args[1]);
130
133
  if(pattern !== null && replacement && replacement.complete) {
131
134
  try {
132
135
  return {text: String.prototype[method].call(head.text, pattern, replacement.text),
@@ -137,6 +140,9 @@ function replaced(method, head, args)
137
140
  }
138
141
  }
139
142
  }
143
+ if(replacement && starts_with_markup(replacement.text)) {
144
+ return {text: replacement.text, complete: false};
145
+ }
140
146
  return {text: head.text, complete: false};
141
147
  }
142
148
 
@@ -152,7 +152,6 @@ let PRIVATE_DATA = {
152
152
  * code) retires its history entry via history.back(). Gated on
153
153
  * `use_hash` — see push_overlay_history / overlay_dismissed. */
154
154
  overlay_stack: [],
155
- overlay_seq: 0,
156
155
  /* Count of history.back() calls WE issued to retire a dismissed
157
156
  * overlay; the popstate they trigger is expected and ignored. */
158
157
  expected_pops: 0,
@@ -183,6 +182,10 @@ let PRIVATE_DATA = {
183
182
  /* Bounds the wait for that back(): one that never lands must not
184
183
  * hold every later navigation for ever. */
185
184
  deferred_timer: null,
185
+ /* The overlays whose back() is in flight, and -- once the wait for
186
+ * them is given up -- what to say if one lands after all. */
187
+ expected_pop_ids: [],
188
+ given_up: null,
186
189
  popstate_handler: null,
187
190
  /* Avatar item support — every toolbar item with type:"avatar"
188
191
  * registers its <span> here so refresh_avatars() can repaint
@@ -332,6 +335,7 @@ function mt_start(gobj)
332
335
  if(!p) {
333
336
  return;
334
337
  }
338
+ note_late_landing(gobj, ev);
335
339
  /* A traversal that moved the hash is followed by a
336
340
  * hashchange, QUEUED: it runs after this handler, and it is
337
341
  * the one that navigates (and drains). */
@@ -422,36 +426,22 @@ function mt_start(gobj)
422
426
  * below, on the hash it had.) */
423
427
  return;
424
428
  }
425
- /* Which entry did it land ON? Markers ({__yui_overlay__:
426
- * id}) tag synthetic entries; route entries have a null
427
- * state.
428
- * - Landing ON the top overlay's OWN entry (a Back from a
429
- * subpath entry pushed above it, or an odd
430
- * history.go(n)): the overlay is at its home entry —
431
- * keep it open.
432
- * - Any other landing (the route entry below, or a lower
433
- * overlay's marker) closes the top overlay: strict
434
- * LIFO. */
429
+ /* Which entry did it land ON? Only the entry the top's marker
430
+ * was pushed over steps off it, and push_overlay_marker()
431
+ * stamped that one with the top's id ({__yui_below__: id}).
432
+ * Any other landing keeps the overlay open:
433
+ * - a fresh entry, no state: a push (a link,
434
+ * `location.hash = ...`) fires popstate too;
435
+ * - the top's OWN marker (a Back from an entry pushed above
436
+ * it);
437
+ * - a dead marker (Forward onto an overlay closed by its
438
+ * button, a Back onto one a navigation drained), or a
439
+ * marker of another page load;
440
+ * - an entry stamped for ANOTHER overlay: stamps stay on
441
+ * their entries, and a stale one is not this marker's
442
+ * floor. */
435
443
  let st = ev && ev.state;
436
- if(!st) {
437
- /* An entry with no state is a FRESH one: a push (a
438
- * link, `location.hash = ...`) fires popstate too, and a
439
- * link to the hash the panel was opened on is not a
440
- * Back. A step off a marker lands on the entry under it,
441
- * which push_overlay_marker() stamped, or on a lower
442
- * overlay's marker. */
443
- return;
444
- }
445
- if(st.__yui_overlay__ === top.id) {
446
- return;
447
- }
448
- if(st.__yui_overlay__ > top.id &&
449
- !p.overlay_stack.some(e => e.id === st.__yui_overlay__)) {
450
- /* A dead marker NEWER than the top: Forward reaches it
451
- * (an overlay closed by its button above this one), and
452
- * so does a Back onto the marker of an overlay a
453
- * navigation drained under a panel that stayed. It is
454
- * not a step off the top's marker. */
444
+ if(!st || st.__yui_below__ !== top.id) {
455
445
  return;
456
446
  }
457
447
  p.overlay_stack.pop();
@@ -557,6 +547,8 @@ function mt_stop(gobj)
557
547
  priv.skip_hash = "";
558
548
  priv.deferred_route = "";
559
549
  clear_deferred_timer(gobj);
550
+ priv.expected_pop_ids = [];
551
+ priv.given_up = null;
560
552
  if(priv.keydown_handler) {
561
553
  window.removeEventListener("keydown", priv.keydown_handler);
562
554
  priv.keydown_handler = null;
@@ -2750,6 +2742,13 @@ function retag_overlay_hash(gobj, st, hash)
2750
2742
  }
2751
2743
  }
2752
2744
 
2745
+ /* Overlay ids are unique across page LOADS, not only within one: the
2746
+ * session history keeps the markers and stamps of a load after an F5,
2747
+ * and an id that starts again from 1 matched them (a Back onto an old
2748
+ * marker taken for the new overlay's own, and lost). Started from the
2749
+ * clock, they are above every id of an earlier load. */
2750
+ let __overlay_seq__ = Date.now() * 1000;
2751
+
2753
2752
  function push_overlay_history(gobj, close, opts)
2754
2753
  {
2755
2754
  let priv = gobj.priv;
@@ -2761,7 +2760,7 @@ function push_overlay_history(gobj, close, opts)
2761
2760
  * step OFF this marker from a route traversal; it is NOT the resting
2762
2761
  * route (a `stay` action route parks the URL off it). Kept in sync
2763
2762
  * by the silent replaceState fix-up in navigate_to(). */
2764
- let entry = { id: ++priv.overlay_seq, close: close,
2763
+ let entry = { id: ++__overlay_seq__, close: close,
2765
2764
  hash: window.location.hash,
2766
2765
  /* Read by drain_overlays: a navigation PANEL survives a
2767
2766
  * resting-route change. Dropping it here left the whole
@@ -2796,18 +2795,26 @@ function push_overlay_marker(gobj, entry)
2796
2795
  * marker lands there -- even after a replace-navigation rewrote the
2797
2796
  * marker's own hash (retag_overlay_hash()). */
2798
2797
  entry.below_hash = window.location.hash;
2799
- /* Stamp the entry under the marker: a step off the marker lands on
2800
- * it, and a push (a link, `location.hash = ...`) lands on a fresh
2801
- * entry with no state -- both fire popstate, on the same hash when
2802
- * the link points where the overlay was opened, and the state is
2803
- * the only thing that tells them apart. An entry with a state of
2804
- * its own (a lower marker, an app's) keeps it. */
2805
- if(window.history.state === null) {
2798
+ /* Stamp the entry under the marker with this overlay's id: a step
2799
+ * off the marker lands on it, and nothing else does -- a push (a
2800
+ * link, `location.hash = ...`) lands on a fresh entry with no
2801
+ * state, and both fire popstate, on the same hash when the link
2802
+ * points where the overlay was opened. A state already there (a
2803
+ * lower overlay's marker, an app's own) keeps its keys; the stamp
2804
+ * is added to them, and replaces an older stamp. */
2805
+ let below = window.history.state;
2806
+ if(below === null || (typeof below === "object" && !Array.isArray(below))) {
2806
2807
  try {
2807
- window.history.replaceState({ __yui_below__: entry.id }, "");
2808
+ window.history.replaceState(
2809
+ Object.assign({}, below, { __yui_below__: entry.id }), "");
2808
2810
  } catch(e) {
2809
2811
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2810
2812
  }
2813
+ } else {
2814
+ log_warning(
2815
+ `C_YUI_SHELL: the entry under an overlay holds a history state that ` +
2816
+ `is not an object, it cannot be stamped: Back will not close the overlay`
2817
+ );
2811
2818
  }
2812
2819
  try {
2813
2820
  window.history.pushState({ __yui_overlay__: entry.id }, "");
@@ -2840,6 +2847,7 @@ function drop_expected_pops(gobj)
2840
2847
  );
2841
2848
  priv.expected_pops = 0;
2842
2849
  priv.expected_pop_hash = "";
2850
+ priv.expected_pop_ids = [];
2843
2851
  clear_deferred_timer(gobj);
2844
2852
  if(priv.deferred_route) {
2845
2853
  /* The history moved on under it (a link, a Back): that move is
@@ -2872,27 +2880,41 @@ function defer_route(gobj, route)
2872
2880
  }
2873
2881
  priv.deferred_route = route;
2874
2882
  if(!priv.deferred_timer) {
2883
+ /* The timer only says that the time is up: the giving up is
2884
+ * an action of the FSM (ac_back_wait_timeout). */
2875
2885
  priv.deferred_timer = window.setTimeout(() => {
2876
- let p = gobj.priv;
2877
- if(!p) {
2878
- return;
2879
- }
2880
- p.deferred_timer = null;
2881
- if(p.expected_pops === 0) {
2886
+ if(!gobj.priv) {
2882
2887
  return;
2883
2888
  }
2884
- log_warning(
2885
- `C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not ` +
2886
- `land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
2887
- );
2888
- p.expected_pops = 0;
2889
- p.expected_pop_hash = "";
2890
- p.restore_hash = "";
2891
- push_pending_markers(gobj); // and navigates the deferred route
2889
+ gobj.priv.deferred_timer = null;
2890
+ gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2892
2891
  }, DEFERRED_ROUTE_WAIT_MS);
2893
2892
  }
2894
2893
  }
2895
2894
 
2895
+ /* A back() of ours given up on can still land, late: on the dead marker
2896
+ * of the overlay it was retiring, after the route that waited for it
2897
+ * was pushed -- and its hashchange then moves the reader back off that
2898
+ * route. A Back of the reader's own lands on the same entry, so the
2899
+ * shell cannot tell the two apart; it says so instead of staying quiet. */
2900
+ function note_late_landing(gobj, ev)
2901
+ {
2902
+ let priv = gobj.priv;
2903
+ let given_up = priv.given_up;
2904
+ let st = ev && ev.state;
2905
+ if(!given_up || !st) {
2906
+ return; // a push (the waiting route's own) lands on a fresh entry
2907
+ }
2908
+ priv.given_up = null; // only the first traversal can be that back()
2909
+ if(given_up.ids.includes(st.__yui_overlay__)) {
2910
+ log_warning(
2911
+ `C_YUI_SHELL: a traversal landed on the marker of an overlay whose ` +
2912
+ `history.back() was given up on: if it is that back(), arriving late, ` +
2913
+ `it undoes route '${given_up.route}'`
2914
+ );
2915
+ }
2916
+ }
2917
+
2896
2918
  function clear_deferred_timer(gobj)
2897
2919
  {
2898
2920
  let priv = gobj.priv;
@@ -2920,6 +2942,9 @@ function push_pending_markers(gobj)
2920
2942
  push_overlay_marker(gobj, entry); // Error already logged
2921
2943
  }
2922
2944
  clear_deferred_timer(gobj);
2945
+ if(priv.expected_pops === 0) {
2946
+ priv.expected_pop_ids = [];
2947
+ }
2923
2948
  if(priv.deferred_route) {
2924
2949
  let route = priv.deferred_route;
2925
2950
  priv.deferred_route = "";
@@ -2961,6 +2986,7 @@ function overlay_dismissed(gobj, entry)
2961
2986
  let st = window.history.state;
2962
2987
  if(st && st.__yui_overlay__ === entry.id) {
2963
2988
  priv.expected_pops++;
2989
+ priv.expected_pop_ids.push(entry.id);
2964
2990
  priv.expected_pop_hash = (typeof entry.below_hash === "string")?
2965
2991
  entry.below_hash : window.location.hash;
2966
2992
  /* A position written on the marker by a replace navigation is
@@ -2971,6 +2997,7 @@ function overlay_dismissed(gobj, entry)
2971
2997
  window.history.back();
2972
2998
  } catch(e) {
2973
2999
  priv.expected_pops--;
3000
+ priv.expected_pop_ids.pop();
2974
3001
  log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2975
3002
  }
2976
3003
  }
@@ -3217,6 +3244,31 @@ function ac_nav_clicked(gobj, event, kw, src)
3217
3244
  return 0;
3218
3245
  }
3219
3246
 
3247
+ /************************************************************
3248
+ * The wait for a back() of ours is over and it has not landed
3249
+ * (defer_route()): give it up, and run the route that waited for it.
3250
+ * If it lands after all, note_late_landing() says so.
3251
+ ************************************************************/
3252
+ function ac_back_wait_timeout(gobj, event, kw, src)
3253
+ {
3254
+ let priv = gobj.priv;
3255
+ if(priv.expected_pops === 0) {
3256
+ return 0; // it landed meanwhile: push_pending_markers() ran the route
3257
+ }
3258
+ log_warning(
3259
+ `C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not ` +
3260
+ `land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
3261
+ );
3262
+ let given_up = {ids: priv.expected_pop_ids.slice(), route: priv.deferred_route};
3263
+ priv.expected_pops = 0;
3264
+ priv.expected_pop_hash = "";
3265
+ priv.expected_pop_ids = [];
3266
+ priv.restore_hash = "";
3267
+ push_pending_markers(gobj); // and navigates the deferred route
3268
+ priv.given_up = given_up;
3269
+ return 0;
3270
+ }
3271
+
3220
3272
  /************************************************************
3221
3273
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
3222
3274
  * this so the shell can close the drawer through the canonical
@@ -3468,13 +3520,17 @@ function create_gclass(gclass_name)
3468
3520
  ["EV_DRAWER_CLOSE_REQUESTED", ac_drawer_close_requested, null],
3469
3521
  /* Close 'x' on a closable tab (from a child C_YUI_NAV);
3470
3522
  * re-published for the app. */
3471
- ["EV_NAV_ITEM_CLOSE", ac_nav_item_close, null]
3523
+ ["EV_NAV_ITEM_CLOSE", ac_nav_item_close, null],
3524
+ /* The wait for a history.back() of the shell is over: the
3525
+ * timer of defer_route() says so. */
3526
+ ["EV_BACK_WAIT_TIMEOUT", ac_back_wait_timeout, null]
3472
3527
  ]]
3473
3528
  ];
3474
3529
 
3475
3530
  const event_types = [
3476
3531
  ["EV_NAV_CLICKED", 0],
3477
3532
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
3533
+ ["EV_BACK_WAIT_TIMEOUT", 0],
3478
3534
  ["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT
3479
3535
  |event_flag_t.EVF_PUBLIC_EVENT
3480
3536
  |event_flag_t.EVF_NO_WARN_SUBS],
@@ -357,7 +357,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
357
357
  expect(shell.priv.expected_pops).toBe(0);
358
358
  expect(session.entries.length).toBe(2); // the dead first marker, ahead
359
359
  expect(session.index).toBe(0);
360
- expect(window.history.state).toEqual({__yui_below__: 1}); // stamped, no marker
360
+ expect(window.history.state.__yui_overlay__).toBeUndefined(); // stamped, no marker
361
361
  expect(errors()).toEqual([]);
362
362
  });
363
363
 
@@ -622,7 +622,7 @@ describe("a routed shell, a realistic history (V5)", () => {
622
622
  const b = yui_shell_register_overlay(shell, () => {});
623
623
  yui_shell_overlay_dismissed(shell, b); // its button: back() to A's marker
624
624
  await next_task();
625
- expect(window.history.state).toEqual({__yui_overlay__: a.id});
625
+ expect(window.history.state.__yui_overlay__).toBe(a.id); // stamped for B, which is gone
626
626
 
627
627
  traverse_to(session.index + 1); // Forward, onto B's dead marker
628
628
  expect(closed_a).toBe(0);
@@ -844,3 +844,119 @@ describe("a route waiting for a back() of ours (V6.2)", () => {
844
844
  expect(window.location.hash).toBe("#/home"); // not swallowed
845
845
  });
846
846
  });
847
+
848
+ /*
849
+ * Seventh check of the review (V7).
850
+ */
851
+ describe("only the entry stamped for the top overlay is its floor (V7.1, V7.3)", () => {
852
+ test("Forward onto an entry stamped for another overlay does not close the panel", async () => {
853
+ const app = gobj_create("v7app1", "C_TEST_MARKER_APP", {}, yuno);
854
+ gobj_start(app);
855
+ window.location.hash = "#/home";
856
+ install_history_model();
857
+ const shell = routed_shell("v7shell1", app);
858
+ const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
859
+ let closed_panel = 0;
860
+ let closed_dialog = 0;
861
+ yui_shell_register_overlay(shell, () => { closed_panel++; }, {keep_on_navigate: true});
862
+ link_to("#/other");
863
+ await next_task();
864
+ link_to("#/home"); // L2
865
+ await next_task();
866
+ await next_task();
867
+ yui_shell_register_overlay(shell, () => { closed_dialog++; }); // stamps L2
868
+
869
+ user_back(); // off the dialog's marker
870
+ await next_task();
871
+ expect(closed_dialog).toBe(1);
872
+ expect(closed_panel).toBe(0);
873
+ user_back(); // to #/other
874
+ await next_task();
875
+ await next_task();
876
+ traverse_to(session.index + 1); // Forward onto L2, stamped for the dialog
877
+ await next_task();
878
+ await next_task();
879
+ expect(closed_panel).toBe(0);
880
+ expect(shell.priv.overlay_stack.length).toBe(1);
881
+ expect(shell_warnings()).toEqual([]);
882
+ });
883
+
884
+ test("Forward onto an entry the app pushed with a state of its own does not close the panel", async () => {
885
+ const app = gobj_create("v7app2", "C_TEST_MARKER_APP", {}, yuno);
886
+ gobj_start(app);
887
+ window.location.hash = "#/home";
888
+ install_history_model();
889
+ const shell = routed_shell("v7shell2", app);
890
+ const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
891
+ let closed = 0;
892
+ yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
893
+ window.history.pushState({app: 3}, ""); // the app's own entry, above the marker
894
+
895
+ user_back(); // onto the marker: home
896
+ await next_task();
897
+ expect(closed).toBe(0);
898
+ traverse_to(session.index + 1); // Forward onto {app: 3}
899
+ await next_task();
900
+ expect(closed).toBe(0);
901
+ user_back();
902
+ user_back(); // off the marker: closes it
903
+ await next_task();
904
+ expect(closed).toBe(1);
905
+ });
906
+
907
+ test("after a reload, a marker of the earlier load is not the new overlay's", async () => {
908
+ const app = gobj_create("v7app3", "C_TEST_MARKER_APP", {}, yuno);
909
+ gobj_start(app);
910
+ window.location.hash = "#/home";
911
+ install_history_model();
912
+ /* The session as an F5 leaves it: on a marker of the earlier load,
913
+ * whose overlay id started from 1. */
914
+ session.entries = [
915
+ {state: {__yui_below__: 1}, hash: "#/home"},
916
+ {state: {__yui_overlay__: 1}, hash: "#/home"}
917
+ ];
918
+ session.index = 1;
919
+ const shell = routed_shell("v7shell3", app);
920
+ const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
921
+ let closed = 0;
922
+ const entry = yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
923
+ expect(entry.id).toBeGreaterThan(1);
924
+ expect(session.entries[1].state).toEqual({__yui_overlay__: 1, __yui_below__: entry.id});
925
+
926
+ user_back(); // off the new marker, onto the old one
927
+ await next_task();
928
+ expect(closed).toBe(1);
929
+ user_back(); // the old marker's floor: nothing to close
930
+ await next_task();
931
+ expect(shell_warnings()).toEqual([]);
932
+ });
933
+ });
934
+
935
+ describe("a back() given up on that lands after all (V7.2)", () => {
936
+ test("its late landing is said out loud", async () => {
937
+ const app = gobj_create("v7app4", "C_TEST_MARKER_APP", {}, yuno);
938
+ gobj_start(app);
939
+ window.location.hash = "#/home";
940
+ install_history_model();
941
+ const shell = routed_shell("v7shell4", app);
942
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
943
+ await import("./c_yui_shell.js");
944
+ const entry = yui_shell_register_overlay(shell, () => {});
945
+ let late = null;
946
+ window.history.back = () => { late = () => traverse_to(session.index - 1); };
947
+ links_on_hash_assign();
948
+
949
+ yui_shell_overlay_dismissed(shell, entry);
950
+ yui_shell_navigate(shell, "/prev");
951
+ await new Promise(resolve => setTimeout(resolve, 1100));
952
+ await next_task();
953
+ expect(window.location.hash).toBe("#/prev");
954
+ expect(shell_warnings().filter(m => m.includes("given up")).length).toBe(1);
955
+
956
+ late(); // it lands now, on the dead marker
957
+ await next_task();
958
+ await next_task();
959
+ expect(shell_warnings().filter(m => m.includes("arriving late")).length).toBe(1);
960
+ expect(shell_warnings().some(m => m.includes("undoes route '/prev'"))).toBe(true);
961
+ });
962
+ });
@@ -70,12 +70,14 @@ function errors()
70
70
  }
71
71
 
72
72
  /* A Back off a marker lands on the entry under it, which the shell
73
- * stamped when it pushed the marker: a landing with NO state is a push
74
- * (a link), not a Back. */
75
- function press_back()
73
+ * stamped with the TOP overlay's id when it pushed the marker: a landing
74
+ * with no state is a push (a link), and one with another overlay's stamp
75
+ * is not this marker's floor. */
76
+ function press_back(shell)
76
77
  {
78
+ const stack = shell.priv.overlay_stack;
77
79
  const ev = new Event("popstate");
78
- ev.state = {__yui_below__: 0};
80
+ ev.state = {__yui_below__: stack.length ? stack[stack.length - 1].id : 0};
79
81
  window.dispatchEvent(ev);
80
82
  }
81
83
 
@@ -94,7 +96,7 @@ describe("a floating window that vetoes its close", () => {
94
96
  const first = gobj_read_attr(win, "back_overlay");
95
97
  expect(first).toBeTruthy();
96
98
 
97
- press_back();
99
+ press_back(shell);
98
100
  expect(gobj_is_destroying(win)).toBe(false);
99
101
  const second = gobj_read_attr(win, "back_overlay");
100
102
  expect(second).toBeTruthy();
@@ -102,7 +104,7 @@ describe("a floating window that vetoes its close", () => {
102
104
  expect(shell.priv.overlay_stack).toEqual([second]);
103
105
 
104
106
  veto = false;
105
- press_back();
107
+ press_back(shell);
106
108
  expect(gobj_is_destroying(win)).toBe(true);
107
109
  expect(shell.priv.overlay_stack).toEqual([]);
108
110
  expect(errors()).toEqual([]);
@@ -122,14 +124,14 @@ describe("a floating window that vetoes its close", () => {
122
124
  warning = "unsaved changes";
123
125
 
124
126
  /* Back: the window asks. Only the question is on the stack. */
125
- press_back();
127
+ press_back(shell);
126
128
  expect(gobj_is_destroying(win)).toBe(false);
127
129
  expect(shell.priv.overlay_stack.length).toBe(1);
128
130
  expect(gobj_read_attr(win, "back_overlay")).toBe(null);
129
131
 
130
132
  /* Back again: the question goes; the window takes its entry back
131
133
  * only then, once there is nothing above it. */
132
- press_back();
134
+ press_back(shell);
133
135
  await new Promise(resolve => setTimeout(resolve, 0));
134
136
  expect(gobj_is_destroying(win)).toBe(false);
135
137
  const entry = gobj_read_attr(win, "back_overlay");