@yuneta/gobj-ui 7.26.15 → 7.26.17

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,14 @@ 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
+ let plain = below !== null && typeof below === "object" && (Object.getPrototypeOf(below) === Object.prototype || Object.getPrototypeOf(below) === null);
2567
+ if (below === null || plain) try {
2568
+ window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2564
2569
  } catch (e) {
2565
2570
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2566
2571
  }
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");
2567
2573
  try {
2568
2574
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2569
2575
  } catch (e) {
@@ -2580,6 +2586,7 @@ function drop_expected_pops(gobj) {
2580
2586
  (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
2587
  priv.expected_pops = 0;
2582
2588
  priv.expected_pop_hash = "";
2589
+ priv.expected_pop_ids = [];
2583
2590
  clear_deferred_timer(gobj);
2584
2591
  if (priv.deferred_route) {
2585
2592
  (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 +2599,19 @@ function defer_route(gobj, route) {
2592
2599
  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
2600
  priv.deferred_route = route;
2594
2601
  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);
2602
+ if (!gobj.priv) return;
2603
+ gobj.priv.deferred_timer = null;
2604
+ (0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2604
2605
  }, DEFERRED_ROUTE_WAIT_MS);
2605
2606
  }
2607
+ function note_late_landing(gobj, ev) {
2608
+ let priv = gobj.priv;
2609
+ let given_up = priv.given_up;
2610
+ let st = ev && ev.state;
2611
+ if (!given_up || !st) return;
2612
+ priv.given_up = null;
2613
+ 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}'`);
2614
+ }
2606
2615
  function clear_deferred_timer(gobj) {
2607
2616
  let priv = gobj.priv;
2608
2617
  if (priv.deferred_timer) {
@@ -2613,18 +2622,21 @@ function clear_deferred_timer(gobj) {
2613
2622
  function push_pending_markers(gobj) {
2614
2623
  let priv = gobj.priv;
2615
2624
  let pending = priv.pending_markers.splice(0);
2625
+ let pushed = [];
2616
2626
  for (let entry of pending) {
2617
2627
  entry.marker_pending = false;
2618
2628
  if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
2619
2629
  entry.hash = window.location.hash;
2620
- push_overlay_marker(gobj, entry);
2630
+ if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
2621
2631
  }
2622
2632
  clear_deferred_timer(gobj);
2633
+ if (priv.expected_pops === 0) priv.expected_pop_ids = [];
2623
2634
  if (priv.deferred_route) {
2624
2635
  let route = priv.deferred_route;
2625
2636
  priv.deferred_route = "";
2626
2637
  yui_shell_navigate(gobj, route);
2627
2638
  }
2639
+ return pushed;
2628
2640
  }
2629
2641
  function overlay_dismissed(gobj, entry) {
2630
2642
  let priv = gobj.priv;
@@ -2637,12 +2649,14 @@ function overlay_dismissed(gobj, entry) {
2637
2649
  let st = window.history.state;
2638
2650
  if (st && st.__yui_overlay__ === entry.id) {
2639
2651
  priv.expected_pops++;
2652
+ priv.expected_pop_ids.push(entry.id);
2640
2653
  priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
2641
2654
  priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
2642
2655
  try {
2643
2656
  window.history.back();
2644
2657
  } catch (e) {
2645
2658
  priv.expected_pops--;
2659
+ priv.expected_pop_ids.pop();
2646
2660
  (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2647
2661
  }
2648
2662
  }
@@ -2759,6 +2773,28 @@ function ac_nav_clicked(gobj, event, kw, src) {
2759
2773
  return 0;
2760
2774
  }
2761
2775
  /************************************************************
2776
+ * The wait for a back() of ours is over and it has not landed
2777
+ * (defer_route()): give it up, and run the route that waited for it.
2778
+ * If it lands after all, note_late_landing() says so.
2779
+ ************************************************************/
2780
+ function ac_back_wait_timeout(gobj, event, kw, src) {
2781
+ let priv = gobj.priv;
2782
+ if (priv.expected_pops === 0) return 0;
2783
+ (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
+ let given_up = {
2785
+ ids: priv.expected_pop_ids.slice(),
2786
+ route: priv.deferred_route
2787
+ };
2788
+ priv.expected_pops = 0;
2789
+ priv.expected_pop_hash = "";
2790
+ priv.expected_pop_ids = [];
2791
+ priv.restore_hash = "";
2792
+ let pushed = push_pending_markers(gobj);
2793
+ given_up.ids.push(...pushed);
2794
+ priv.given_up = given_up;
2795
+ return 0;
2796
+ }
2797
+ /************************************************************
2762
2798
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
2763
2799
  * this so the shell can close the drawer through the canonical
2764
2800
  * flow (DOM + focus-trap + escape-stack pop) instead of mutating
@@ -2831,11 +2867,17 @@ function create_gclass$22(gclass_name) {
2831
2867
  "EV_NAV_ITEM_CLOSE",
2832
2868
  ac_nav_item_close,
2833
2869
  null
2870
+ ],
2871
+ [
2872
+ "EV_BACK_WAIT_TIMEOUT",
2873
+ ac_back_wait_timeout,
2874
+ null
2834
2875
  ]
2835
2876
  ]]];
2836
2877
  const event_types = [
2837
2878
  ["EV_NAV_CLICKED", 0],
2838
2879
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
2880
+ ["EV_BACK_WAIT_TIMEOUT", 0],
2839
2881
  ["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
2882
  ["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
2883
  ["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,14 @@ 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
+ let plain = below !== null && typeof below === "object" && (Object.getPrototypeOf(below) === Object.prototype || Object.getPrototypeOf(below) === null);
2562
+ if (below === null || plain) try {
2563
+ window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
2559
2564
  } catch (e) {
2560
2565
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2561
2566
  }
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");
2562
2568
  try {
2563
2569
  window.history.pushState({ __yui_overlay__: entry.id }, "");
2564
2570
  } catch (e) {
@@ -2575,6 +2581,7 @@ function drop_expected_pops(gobj) {
2575
2581
  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
2582
  priv.expected_pops = 0;
2577
2583
  priv.expected_pop_hash = "";
2584
+ priv.expected_pop_ids = [];
2578
2585
  clear_deferred_timer(gobj);
2579
2586
  if (priv.deferred_route) {
2580
2587
  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 +2594,19 @@ function defer_route(gobj, route) {
2587
2594
  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
2595
  priv.deferred_route = route;
2589
2596
  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);
2597
+ if (!gobj.priv) return;
2598
+ gobj.priv.deferred_timer = null;
2599
+ gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2599
2600
  }, DEFERRED_ROUTE_WAIT_MS);
2600
2601
  }
2602
+ function note_late_landing(gobj, ev) {
2603
+ let priv = gobj.priv;
2604
+ let given_up = priv.given_up;
2605
+ let st = ev && ev.state;
2606
+ if (!given_up || !st) return;
2607
+ priv.given_up = null;
2608
+ 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}'`);
2609
+ }
2601
2610
  function clear_deferred_timer(gobj) {
2602
2611
  let priv = gobj.priv;
2603
2612
  if (priv.deferred_timer) {
@@ -2608,18 +2617,21 @@ function clear_deferred_timer(gobj) {
2608
2617
  function push_pending_markers(gobj) {
2609
2618
  let priv = gobj.priv;
2610
2619
  let pending = priv.pending_markers.splice(0);
2620
+ let pushed = [];
2611
2621
  for (let entry of pending) {
2612
2622
  entry.marker_pending = false;
2613
2623
  if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
2614
2624
  entry.hash = window.location.hash;
2615
- push_overlay_marker(gobj, entry);
2625
+ if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
2616
2626
  }
2617
2627
  clear_deferred_timer(gobj);
2628
+ if (priv.expected_pops === 0) priv.expected_pop_ids = [];
2618
2629
  if (priv.deferred_route) {
2619
2630
  let route = priv.deferred_route;
2620
2631
  priv.deferred_route = "";
2621
2632
  yui_shell_navigate(gobj, route);
2622
2633
  }
2634
+ return pushed;
2623
2635
  }
2624
2636
  function overlay_dismissed(gobj, entry) {
2625
2637
  let priv = gobj.priv;
@@ -2632,12 +2644,14 @@ function overlay_dismissed(gobj, entry) {
2632
2644
  let st = window.history.state;
2633
2645
  if (st && st.__yui_overlay__ === entry.id) {
2634
2646
  priv.expected_pops++;
2647
+ priv.expected_pop_ids.push(entry.id);
2635
2648
  priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
2636
2649
  priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
2637
2650
  try {
2638
2651
  window.history.back();
2639
2652
  } catch (e) {
2640
2653
  priv.expected_pops--;
2654
+ priv.expected_pop_ids.pop();
2641
2655
  log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2642
2656
  }
2643
2657
  }
@@ -2754,6 +2768,28 @@ function ac_nav_clicked(gobj, event, kw, src) {
2754
2768
  return 0;
2755
2769
  }
2756
2770
  /************************************************************
2771
+ * The wait for a back() of ours is over and it has not landed
2772
+ * (defer_route()): give it up, and run the route that waited for it.
2773
+ * If it lands after all, note_late_landing() says so.
2774
+ ************************************************************/
2775
+ function ac_back_wait_timeout(gobj, event, kw, src) {
2776
+ let priv = gobj.priv;
2777
+ if (priv.expected_pops === 0) return 0;
2778
+ log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
2779
+ let given_up = {
2780
+ ids: priv.expected_pop_ids.slice(),
2781
+ route: priv.deferred_route
2782
+ };
2783
+ priv.expected_pops = 0;
2784
+ priv.expected_pop_hash = "";
2785
+ priv.expected_pop_ids = [];
2786
+ priv.restore_hash = "";
2787
+ let pushed = push_pending_markers(gobj);
2788
+ given_up.ids.push(...pushed);
2789
+ priv.given_up = given_up;
2790
+ return 0;
2791
+ }
2792
+ /************************************************************
2757
2793
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
2758
2794
  * this so the shell can close the drawer through the canonical
2759
2795
  * flow (DOM + focus-trap + escape-stack pop) instead of mutating
@@ -2826,11 +2862,17 @@ function create_gclass$22(gclass_name) {
2826
2862
  "EV_NAV_ITEM_CLOSE",
2827
2863
  ac_nav_item_close,
2828
2864
  null
2865
+ ],
2866
+ [
2867
+ "EV_BACK_WAIT_TIMEOUT",
2868
+ ac_back_wait_timeout,
2869
+ null
2829
2870
  ]
2830
2871
  ]]];
2831
2872
  const event_types = [
2832
2873
  ["EV_NAV_CLICKED", 0],
2833
2874
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
2875
+ ["EV_BACK_WAIT_TIMEOUT", 0],
2834
2876
  ["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2835
2877
  ["EV_ROUTE_REQUESTED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
2836
2878
  ["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.17",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -34,8 +34,10 @@
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; markup given to innerHTML, or to a widget (Tabulator,
38
- * G6), which are other sinks. set_strings_are_text(true) logs, once
37
+ * literal; a replace() whose replacement is a function or whose
38
+ * pattern is a variable, and a method called on a function result
39
+ * (String(x).replace(...)); markup given to innerHTML, or to a
40
+ * widget (Tabulator, G6), which are other sinks. set_strings_are_text(true) logs, once
39
41
  * at run time, every string that reaches createElement2() starting
40
42
  * with '<': that is the other half of the check.
41
43
  *
@@ -107,35 +109,82 @@ const PURE_METHODS = new Set([
107
109
  "toLowerCase", "toUpperCase"
108
110
  ]);
109
111
 
110
- /* replace()/replaceAll() on a receiver that is static and with static
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
113
- * receiver that carries data stays BUILT markup through them, and so
114
- * does a static one whose replacement is data
115
- * ('<b>NAME</b>'.replace('NAME', name)). */
112
+ /* replace()/replaceAll(). A receiver that is static, with a static
113
+ * pattern and a static replacement, is computed, so a tag stripped away
114
+ * is seen as stripped. Otherwise the result is no longer static, and its
115
+ * head is what is known to come BEFORE the first match: the receiver's
116
+ * text up to it, then the replacement's head
117
+ * ('<b>NAME</b>'.replace('NAME', name) is '<b>' + data: built;
118
+ * 'abc'.replace('abc', '<i>' + y) is '<i>' + data: built). Where the
119
+ * first match is decides it, so the replacement is the head only when the
120
+ * pattern can match at 0: ('z' + name).replace('a', '<b>') starts with
121
+ * 'z', and 'abc'.replace('x', '<i>' + y) is 'abc'.
122
+ * Not seen: a replacement that is a function, a pattern in a variable. */
123
+ function static_pattern(arg)
124
+ {
125
+ if(arg.type === "Literal" && arg.regex) {
126
+ try {
127
+ return new RegExp(arg.regex.pattern, arg.regex.flags);
128
+ } catch(e) {
129
+ return null;
130
+ }
131
+ }
132
+ if(is_string_literal(arg)) {
133
+ return arg.value;
134
+ }
135
+ return null;
136
+ }
137
+
138
+ function first_match(text, pattern)
139
+ {
140
+ if(typeof pattern === "string") {
141
+ return text.indexOf(pattern);
142
+ }
143
+ try {
144
+ const re = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
145
+ const m = re.exec(text);
146
+ return m ? m.index : -1;
147
+ } catch(e) {
148
+ return -1;
149
+ }
150
+ }
151
+
116
152
  function replaced(method, head, args)
117
153
  {
118
- if(head.complete && args.length === 2) {
119
- let pattern = null;
120
- if(args[0].type === "Literal" && args[0].regex) {
121
- try {
122
- pattern = new RegExp(args[0].regex.pattern, args[0].regex.flags);
123
- } catch(e) {
124
- pattern = null;
125
- }
126
- } else if(is_string_literal(args[0])) {
127
- pattern = args[0].value;
154
+ if(args.length !== 2) {
155
+ return {text: head.text, complete: false};
156
+ }
157
+ const pattern = static_pattern(args[0]);
158
+ const replacement = leading(args[1]);
159
+ if(pattern === null) {
160
+ return {text: head.text, complete: false};
161
+ }
162
+ if(head.complete && replacement && replacement.complete) {
163
+ try {
164
+ return {text: String.prototype[method].call(head.text, pattern, replacement.text),
165
+ complete: true};
166
+ } catch(e) {
167
+ /* replaceAll() with a regex that is not global throws: so
168
+ * does the code, the check need not know what it gives. */
169
+ return {text: head.text, complete: false};
128
170
  }
129
- let replacement = leading(args[1]);
130
- if(pattern !== null && replacement && replacement.complete) {
131
- try {
132
- return {text: String.prototype[method].call(head.text, pattern, replacement.text),
133
- complete: true};
134
- } catch(e) {
135
- /* replaceAll() with a regex that is not global throws:
136
- * so does the code, the check need not know what it gives. */
137
- }
171
+ }
172
+ const rep_head = replacement ? replacement.text : "";
173
+ const idx = first_match(head.text, pattern);
174
+ if(idx >= 0) {
175
+ return {text: head.text.slice(0, idx) + rep_head, complete: false};
176
+ }
177
+ if(head.complete) {
178
+ return {text: head.text, complete: true}; // no match: the receiver as it is
179
+ }
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};
138
186
  }
187
+ return {text: head.text.slice(0, keep), complete: false};
139
188
  }
140
189
  return {text: head.text, complete: false};
141
190
  }
@@ -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,31 @@ 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
+ /* 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. */
2808
+ let plain = below !== null && typeof below === "object" &&
2809
+ (Object.getPrototypeOf(below) === Object.prototype ||
2810
+ Object.getPrototypeOf(below) === null);
2811
+ if(below === null || plain) {
2806
2812
  try {
2807
- window.history.replaceState({ __yui_below__: entry.id }, "");
2813
+ window.history.replaceState(
2814
+ Object.assign({}, below, { __yui_below__: entry.id }), "");
2808
2815
  } catch(e) {
2809
2816
  log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
2810
2817
  }
2818
+ } else {
2819
+ log_warning(
2820
+ `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`
2822
+ );
2811
2823
  }
2812
2824
  try {
2813
2825
  window.history.pushState({ __yui_overlay__: entry.id }, "");
@@ -2840,6 +2852,7 @@ function drop_expected_pops(gobj)
2840
2852
  );
2841
2853
  priv.expected_pops = 0;
2842
2854
  priv.expected_pop_hash = "";
2855
+ priv.expected_pop_ids = [];
2843
2856
  clear_deferred_timer(gobj);
2844
2857
  if(priv.deferred_route) {
2845
2858
  /* The history moved on under it (a link, a Back): that move is
@@ -2872,27 +2885,41 @@ function defer_route(gobj, route)
2872
2885
  }
2873
2886
  priv.deferred_route = route;
2874
2887
  if(!priv.deferred_timer) {
2888
+ /* The timer only says that the time is up: the giving up is
2889
+ * an action of the FSM (ac_back_wait_timeout). */
2875
2890
  priv.deferred_timer = window.setTimeout(() => {
2876
- let p = gobj.priv;
2877
- if(!p) {
2891
+ if(!gobj.priv) {
2878
2892
  return;
2879
2893
  }
2880
- p.deferred_timer = null;
2881
- if(p.expected_pops === 0) {
2882
- return;
2883
- }
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
2894
+ gobj.priv.deferred_timer = null;
2895
+ gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
2892
2896
  }, DEFERRED_ROUTE_WAIT_MS);
2893
2897
  }
2894
2898
  }
2895
2899
 
2900
+ /* A back() of ours given up on can still land, late: on the dead marker
2901
+ * of the overlay it was retiring, after the route that waited for it
2902
+ * was pushed -- and its hashchange then moves the reader back off that
2903
+ * route. A Back of the reader's own lands on the same entry, so the
2904
+ * shell cannot tell the two apart; it says so instead of staying quiet. */
2905
+ function note_late_landing(gobj, ev)
2906
+ {
2907
+ let priv = gobj.priv;
2908
+ let given_up = priv.given_up;
2909
+ let st = ev && ev.state;
2910
+ if(!given_up || !st) {
2911
+ return; // a push (the waiting route's own) lands on a fresh entry
2912
+ }
2913
+ priv.given_up = null; // only the first traversal can be that back()
2914
+ if(given_up.ids.includes(st.__yui_overlay__)) {
2915
+ log_warning(
2916
+ `C_YUI_SHELL: a traversal landed on the marker of an overlay whose ` +
2917
+ `history.back() was given up on: if it is that back(), arriving late, ` +
2918
+ `it undoes route '${given_up.route}'`
2919
+ );
2920
+ }
2921
+ }
2922
+
2896
2923
  function clear_deferred_timer(gobj)
2897
2924
  {
2898
2925
  let priv = gobj.priv;
@@ -2909,6 +2936,7 @@ function push_pending_markers(gobj)
2909
2936
  {
2910
2937
  let priv = gobj.priv;
2911
2938
  let pending = priv.pending_markers.splice(0);
2939
+ let pushed = [];
2912
2940
  for(let entry of pending) {
2913
2941
  entry.marker_pending = false;
2914
2942
  if(entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) {
@@ -2917,14 +2945,21 @@ function push_pending_markers(gobj)
2917
2945
  /* The traversal was same-hash, but a route may have moved
2918
2946
  * meanwhile: the marker lives on the hash it is pushed on. */
2919
2947
  entry.hash = window.location.hash;
2920
- push_overlay_marker(gobj, entry); // Error already logged
2948
+ if(push_overlay_marker(gobj, entry)) {
2949
+ pushed.push(entry.id);
2950
+ }
2951
+ // else: Error already logged
2921
2952
  }
2922
2953
  clear_deferred_timer(gobj);
2954
+ if(priv.expected_pops === 0) {
2955
+ priv.expected_pop_ids = [];
2956
+ }
2923
2957
  if(priv.deferred_route) {
2924
2958
  let route = priv.deferred_route;
2925
2959
  priv.deferred_route = "";
2926
2960
  yui_shell_navigate(gobj, route);
2927
2961
  }
2962
+ return pushed; // the ids of the markers it pushed, in order
2928
2963
  }
2929
2964
 
2930
2965
  function overlay_dismissed(gobj, entry)
@@ -2961,6 +2996,7 @@ function overlay_dismissed(gobj, entry)
2961
2996
  let st = window.history.state;
2962
2997
  if(st && st.__yui_overlay__ === entry.id) {
2963
2998
  priv.expected_pops++;
2999
+ priv.expected_pop_ids.push(entry.id);
2964
3000
  priv.expected_pop_hash = (typeof entry.below_hash === "string")?
2965
3001
  entry.below_hash : window.location.hash;
2966
3002
  /* A position written on the marker by a replace navigation is
@@ -2971,6 +3007,7 @@ function overlay_dismissed(gobj, entry)
2971
3007
  window.history.back();
2972
3008
  } catch(e) {
2973
3009
  priv.expected_pops--;
3010
+ priv.expected_pop_ids.pop();
2974
3011
  log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
2975
3012
  }
2976
3013
  }
@@ -3217,6 +3254,36 @@ function ac_nav_clicked(gobj, event, kw, src)
3217
3254
  return 0;
3218
3255
  }
3219
3256
 
3257
+ /************************************************************
3258
+ * The wait for a back() of ours is over and it has not landed
3259
+ * (defer_route()): give it up, and run the route that waited for it.
3260
+ * If it lands after all, note_late_landing() says so.
3261
+ ************************************************************/
3262
+ function ac_back_wait_timeout(gobj, event, kw, src)
3263
+ {
3264
+ let priv = gobj.priv;
3265
+ if(priv.expected_pops === 0) {
3266
+ return 0; // it landed meanwhile: push_pending_markers() ran the route
3267
+ }
3268
+ log_warning(
3269
+ `C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not ` +
3270
+ `land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
3271
+ );
3272
+ let given_up = {ids: priv.expected_pop_ids.slice(), route: priv.deferred_route};
3273
+ priv.expected_pops = 0;
3274
+ priv.expected_pop_hash = "";
3275
+ priv.expected_pop_ids = [];
3276
+ priv.restore_hash = "";
3277
+ /* The markers of the overlays opened during the wait go on top of
3278
+ * the dead one, before the route: a late back() steps back one entry
3279
+ * from the route and lands on the highest of them, not on the dead
3280
+ * marker -- they are its landing too. */
3281
+ let pushed = push_pending_markers(gobj); // and navigates the deferred route
3282
+ given_up.ids.push(...pushed);
3283
+ priv.given_up = given_up;
3284
+ return 0;
3285
+ }
3286
+
3220
3287
  /************************************************************
3221
3288
  * Drawer backdrop click on a C_YUI_NAV child: the nav publishes
3222
3289
  * this so the shell can close the drawer through the canonical
@@ -3468,13 +3535,17 @@ function create_gclass(gclass_name)
3468
3535
  ["EV_DRAWER_CLOSE_REQUESTED", ac_drawer_close_requested, null],
3469
3536
  /* Close 'x' on a closable tab (from a child C_YUI_NAV);
3470
3537
  * re-published for the app. */
3471
- ["EV_NAV_ITEM_CLOSE", ac_nav_item_close, null]
3538
+ ["EV_NAV_ITEM_CLOSE", ac_nav_item_close, null],
3539
+ /* The wait for a history.back() of the shell is over: the
3540
+ * timer of defer_route() says so. */
3541
+ ["EV_BACK_WAIT_TIMEOUT", ac_back_wait_timeout, null]
3472
3542
  ]]
3473
3543
  ];
3474
3544
 
3475
3545
  const event_types = [
3476
3546
  ["EV_NAV_CLICKED", 0],
3477
3547
  ["EV_DRAWER_CLOSE_REQUESTED", 0],
3548
+ ["EV_BACK_WAIT_TIMEOUT", 0],
3478
3549
  ["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT
3479
3550
  |event_flag_t.EVF_PUBLIC_EVENT
3480
3551
  |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).toEqual({__yui_below__: first.id}); // 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).toEqual({__yui_overlay__: a.id, __yui_below__: b.id});
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,164 @@ 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
+ });
963
+
964
+ describe("V8: the edges of the stamp and of the late landing", () => {
965
+ test("a late back() lands on the marker of an overlay opened during the wait: said too", async () => {
966
+ const app = gobj_create("v8app1", "C_TEST_MARKER_APP", {}, yuno);
967
+ gobj_start(app);
968
+ window.location.hash = "#/home";
969
+ install_history_model();
970
+ const shell = routed_shell("v8shell1", app);
971
+ const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
972
+ await import("./c_yui_shell.js");
973
+ const x = yui_shell_register_overlay(shell, () => {});
974
+ let late = null;
975
+ window.history.back = () => { late = () => traverse_to(session.index - 1); };
976
+ links_on_hash_assign();
977
+
978
+ yui_shell_overlay_dismissed(shell, x);
979
+ yui_shell_navigate(shell, "/prev");
980
+ const y = yui_shell_register_overlay(shell, () => {}, {keep_on_navigate: true});
981
+ expect(y.marker_pending).toBe(true);
982
+ await new Promise(resolve => setTimeout(resolve, 1100));
983
+ await next_task();
984
+ expect(window.location.hash).toBe("#/prev");
985
+
986
+ late(); // from #/prev onto Y's marker
987
+ await next_task();
988
+ await next_task();
989
+ expect(window.history.state.__yui_overlay__).toBe(y.id);
990
+ expect(shell_warnings().filter(m => m.includes("arriving late")).length).toBe(1);
991
+ });
992
+
993
+ test("a state that is not a plain object is not stamped over, and says so", async () => {
994
+ const app = gobj_create("v8app2", "C_TEST_MARKER_APP", {}, yuno);
995
+ gobj_start(app);
996
+ window.location.hash = "#/home";
997
+ install_history_model();
998
+ const shell = routed_shell("v8shell2", app);
999
+ const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
1000
+ const app_state = new Map([["k", 1]]);
1001
+ window.history.replaceState(app_state, "");
1002
+ logged.length = 0;
1003
+ yui_shell_register_overlay(shell, () => {});
1004
+ expect(session.entries[0].state).toBe(app_state);
1005
+ expect(shell_warnings().filter(m => m.includes("not a plain object")).length).toBe(1);
1006
+ });
1007
+ });
@@ -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");