@yuneta/gobj-ui 7.26.14 → 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.
- package/dist/gobj-ui.cjs.js +85 -5
- package/dist/gobj-ui.es.js +85 -5
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +47 -1
- package/src/c_yui_shell.js +172 -22
- package/src/data_as_text.wiring.test.js +27 -5
- package/src/overlay_marker_after_back.wiring.test.js +307 -3
- package/src/window_veto_back.wiring.test.js +13 -7
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -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: [],
|
|
@@ -979,6 +978,9 @@ var PRIVATE_DATA$22 = {
|
|
|
979
978
|
restore_hash: "",
|
|
980
979
|
skip_hash: "",
|
|
981
980
|
deferred_route: "",
|
|
981
|
+
deferred_timer: null,
|
|
982
|
+
expected_pop_ids: [],
|
|
983
|
+
given_up: null,
|
|
982
984
|
popstate_handler: null,
|
|
983
985
|
avatar_provider: null,
|
|
984
986
|
avatar_nodes: [],
|
|
@@ -1052,6 +1054,7 @@ function mt_start$20(gobj) {
|
|
|
1052
1054
|
priv.popstate_handler = (ev) => {
|
|
1053
1055
|
let p = gobj.priv;
|
|
1054
1056
|
if (!p) return;
|
|
1057
|
+
note_late_landing(gobj, ev);
|
|
1055
1058
|
let hash_moved = window.location.hash !== p.last_hash;
|
|
1056
1059
|
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1057
1060
|
drop_expected_pops(gobj);
|
|
@@ -1086,8 +1089,7 @@ function mt_start$20(gobj) {
|
|
|
1086
1089
|
if (top.marker_pending || top.no_marker) return;
|
|
1087
1090
|
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1088
1091
|
let st = ev && ev.state;
|
|
1089
|
-
if (st
|
|
1090
|
-
if (st && 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;
|
|
1091
1093
|
p.overlay_stack.pop();
|
|
1092
1094
|
try {
|
|
1093
1095
|
top.close();
|
|
@@ -1147,6 +1149,9 @@ function mt_stop$20(gobj) {
|
|
|
1147
1149
|
priv.restore_hash = "";
|
|
1148
1150
|
priv.skip_hash = "";
|
|
1149
1151
|
priv.deferred_route = "";
|
|
1152
|
+
clear_deferred_timer(gobj);
|
|
1153
|
+
priv.expected_pop_ids = [];
|
|
1154
|
+
priv.given_up = null;
|
|
1150
1155
|
if (priv.keydown_handler) {
|
|
1151
1156
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1152
1157
|
priv.keydown_handler = null;
|
|
@@ -2535,11 +2540,12 @@ function retag_overlay_hash(gobj, st, hash) {
|
|
|
2535
2540
|
let entry = priv.overlay_stack.find((e) => e.id === st.__yui_overlay__);
|
|
2536
2541
|
if (entry) entry.hash = hash;
|
|
2537
2542
|
}
|
|
2543
|
+
var __overlay_seq__ = Date.now() * 1e3;
|
|
2538
2544
|
function push_overlay_history(gobj, close, opts) {
|
|
2539
2545
|
let priv = gobj.priv;
|
|
2540
2546
|
if (!priv || !priv.overlay_stack || !(0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash")) return null;
|
|
2541
2547
|
let entry = {
|
|
2542
|
-
id: ++
|
|
2548
|
+
id: ++__overlay_seq__,
|
|
2543
2549
|
close,
|
|
2544
2550
|
hash: window.location.hash,
|
|
2545
2551
|
keep_on_navigate: !!(opts && opts.keep_on_navigate)
|
|
@@ -2556,6 +2562,13 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2556
2562
|
function push_overlay_marker(gobj, entry) {
|
|
2557
2563
|
let priv = gobj.priv;
|
|
2558
2564
|
entry.below_hash = window.location.hash;
|
|
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 }), "");
|
|
2568
|
+
} catch (e) {
|
|
2569
|
+
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
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");
|
|
2559
2572
|
try {
|
|
2560
2573
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2561
2574
|
} catch (e) {
|
|
@@ -2572,6 +2585,38 @@ function drop_expected_pops(gobj) {
|
|
|
2572
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`);
|
|
2573
2586
|
priv.expected_pops = 0;
|
|
2574
2587
|
priv.expected_pop_hash = "";
|
|
2588
|
+
priv.expected_pop_ids = [];
|
|
2589
|
+
clear_deferred_timer(gobj);
|
|
2590
|
+
if (priv.deferred_route) {
|
|
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
|
+
priv.deferred_route = "";
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2596
|
+
function defer_route(gobj, route) {
|
|
2597
|
+
let priv = gobj.priv;
|
|
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}'`);
|
|
2599
|
+
priv.deferred_route = route;
|
|
2600
|
+
if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
|
|
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
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
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
|
+
}
|
|
2614
|
+
function clear_deferred_timer(gobj) {
|
|
2615
|
+
let priv = gobj.priv;
|
|
2616
|
+
if (priv.deferred_timer) {
|
|
2617
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2618
|
+
priv.deferred_timer = null;
|
|
2619
|
+
}
|
|
2575
2620
|
}
|
|
2576
2621
|
function push_pending_markers(gobj) {
|
|
2577
2622
|
let priv = gobj.priv;
|
|
@@ -2582,6 +2627,8 @@ function push_pending_markers(gobj) {
|
|
|
2582
2627
|
entry.hash = window.location.hash;
|
|
2583
2628
|
push_overlay_marker(gobj, entry);
|
|
2584
2629
|
}
|
|
2630
|
+
clear_deferred_timer(gobj);
|
|
2631
|
+
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
2585
2632
|
if (priv.deferred_route) {
|
|
2586
2633
|
let route = priv.deferred_route;
|
|
2587
2634
|
priv.deferred_route = "";
|
|
@@ -2599,12 +2646,14 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2599
2646
|
let st = window.history.state;
|
|
2600
2647
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2601
2648
|
priv.expected_pops++;
|
|
2649
|
+
priv.expected_pop_ids.push(entry.id);
|
|
2602
2650
|
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2603
2651
|
priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
|
|
2604
2652
|
try {
|
|
2605
2653
|
window.history.back();
|
|
2606
2654
|
} catch (e) {
|
|
2607
2655
|
priv.expected_pops--;
|
|
2656
|
+
priv.expected_pop_ids.pop();
|
|
2608
2657
|
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
|
|
2609
2658
|
}
|
|
2610
2659
|
}
|
|
@@ -2710,6 +2759,10 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2710
2759
|
}
|
|
2711
2760
|
route = remembered_position(gobj, route);
|
|
2712
2761
|
if ((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
2762
|
+
if (gobj.priv.expected_pops > 0) {
|
|
2763
|
+
defer_route(gobj, route);
|
|
2764
|
+
return 0;
|
|
2765
|
+
}
|
|
2713
2766
|
let target_hash = route_to_hash(route);
|
|
2714
2767
|
if (window.location.hash !== target_hash) window.location.hash = target_hash;
|
|
2715
2768
|
else navigate_to(gobj, route);
|
|
@@ -2717,6 +2770,27 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2717
2770
|
return 0;
|
|
2718
2771
|
}
|
|
2719
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
|
+
/************************************************************
|
|
2720
2794
|
* Drawer backdrop click on a C_YUI_NAV child: the nav publishes
|
|
2721
2795
|
* this so the shell can close the drawer through the canonical
|
|
2722
2796
|
* flow (DOM + focus-trap + escape-stack pop) instead of mutating
|
|
@@ -2789,11 +2863,17 @@ function create_gclass$22(gclass_name) {
|
|
|
2789
2863
|
"EV_NAV_ITEM_CLOSE",
|
|
2790
2864
|
ac_nav_item_close,
|
|
2791
2865
|
null
|
|
2866
|
+
],
|
|
2867
|
+
[
|
|
2868
|
+
"EV_BACK_WAIT_TIMEOUT",
|
|
2869
|
+
ac_back_wait_timeout,
|
|
2870
|
+
null
|
|
2792
2871
|
]
|
|
2793
2872
|
]]];
|
|
2794
2873
|
const event_types = [
|
|
2795
2874
|
["EV_NAV_CLICKED", 0],
|
|
2796
2875
|
["EV_DRAWER_CLOSE_REQUESTED", 0],
|
|
2876
|
+
["EV_BACK_WAIT_TIMEOUT", 0],
|
|
2797
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],
|
|
2798
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],
|
|
2799
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],
|
|
@@ -2951,7 +3031,7 @@ function yui_shell_navigate(shell_gobj, route, opts) {
|
|
|
2951
3031
|
if (!(opts && opts.replace) && (0, _yuneta_gobj_js.gobj_read_attr)(shell_gobj, "use_hash")) {
|
|
2952
3032
|
let priv = shell_gobj.priv;
|
|
2953
3033
|
if (priv && priv.expected_pops > 0) {
|
|
2954
|
-
|
|
3034
|
+
defer_route(shell_gobj, route);
|
|
2955
3035
|
return;
|
|
2956
3036
|
}
|
|
2957
3037
|
let target_hash = route_to_hash(route);
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -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: [],
|
|
@@ -974,6 +973,9 @@ var PRIVATE_DATA$22 = {
|
|
|
974
973
|
restore_hash: "",
|
|
975
974
|
skip_hash: "",
|
|
976
975
|
deferred_route: "",
|
|
976
|
+
deferred_timer: null,
|
|
977
|
+
expected_pop_ids: [],
|
|
978
|
+
given_up: null,
|
|
977
979
|
popstate_handler: null,
|
|
978
980
|
avatar_provider: null,
|
|
979
981
|
avatar_nodes: [],
|
|
@@ -1047,6 +1049,7 @@ function mt_start$20(gobj) {
|
|
|
1047
1049
|
priv.popstate_handler = (ev) => {
|
|
1048
1050
|
let p = gobj.priv;
|
|
1049
1051
|
if (!p) return;
|
|
1052
|
+
note_late_landing(gobj, ev);
|
|
1050
1053
|
let hash_moved = window.location.hash !== p.last_hash;
|
|
1051
1054
|
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1052
1055
|
drop_expected_pops(gobj);
|
|
@@ -1081,8 +1084,7 @@ function mt_start$20(gobj) {
|
|
|
1081
1084
|
if (top.marker_pending || top.no_marker) return;
|
|
1082
1085
|
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1083
1086
|
let st = ev && ev.state;
|
|
1084
|
-
if (st
|
|
1085
|
-
if (st && 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;
|
|
1086
1088
|
p.overlay_stack.pop();
|
|
1087
1089
|
try {
|
|
1088
1090
|
top.close();
|
|
@@ -1142,6 +1144,9 @@ function mt_stop$20(gobj) {
|
|
|
1142
1144
|
priv.restore_hash = "";
|
|
1143
1145
|
priv.skip_hash = "";
|
|
1144
1146
|
priv.deferred_route = "";
|
|
1147
|
+
clear_deferred_timer(gobj);
|
|
1148
|
+
priv.expected_pop_ids = [];
|
|
1149
|
+
priv.given_up = null;
|
|
1145
1150
|
if (priv.keydown_handler) {
|
|
1146
1151
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1147
1152
|
priv.keydown_handler = null;
|
|
@@ -2530,11 +2535,12 @@ function retag_overlay_hash(gobj, st, hash) {
|
|
|
2530
2535
|
let entry = priv.overlay_stack.find((e) => e.id === st.__yui_overlay__);
|
|
2531
2536
|
if (entry) entry.hash = hash;
|
|
2532
2537
|
}
|
|
2538
|
+
var __overlay_seq__ = Date.now() * 1e3;
|
|
2533
2539
|
function push_overlay_history(gobj, close, opts) {
|
|
2534
2540
|
let priv = gobj.priv;
|
|
2535
2541
|
if (!priv || !priv.overlay_stack || !gobj_read_attr(gobj, "use_hash")) return null;
|
|
2536
2542
|
let entry = {
|
|
2537
|
-
id: ++
|
|
2543
|
+
id: ++__overlay_seq__,
|
|
2538
2544
|
close,
|
|
2539
2545
|
hash: window.location.hash,
|
|
2540
2546
|
keep_on_navigate: !!(opts && opts.keep_on_navigate)
|
|
@@ -2551,6 +2557,13 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2551
2557
|
function push_overlay_marker(gobj, entry) {
|
|
2552
2558
|
let priv = gobj.priv;
|
|
2553
2559
|
entry.below_hash = window.location.hash;
|
|
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 }), "");
|
|
2563
|
+
} catch (e) {
|
|
2564
|
+
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
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");
|
|
2554
2567
|
try {
|
|
2555
2568
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2556
2569
|
} catch (e) {
|
|
@@ -2567,6 +2580,38 @@ function drop_expected_pops(gobj) {
|
|
|
2567
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`);
|
|
2568
2581
|
priv.expected_pops = 0;
|
|
2569
2582
|
priv.expected_pop_hash = "";
|
|
2583
|
+
priv.expected_pop_ids = [];
|
|
2584
|
+
clear_deferred_timer(gobj);
|
|
2585
|
+
if (priv.deferred_route) {
|
|
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
|
+
priv.deferred_route = "";
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2591
|
+
function defer_route(gobj, route) {
|
|
2592
|
+
let priv = gobj.priv;
|
|
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}'`);
|
|
2594
|
+
priv.deferred_route = route;
|
|
2595
|
+
if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
|
|
2596
|
+
if (!gobj.priv) return;
|
|
2597
|
+
gobj.priv.deferred_timer = null;
|
|
2598
|
+
gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
|
|
2599
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
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
|
+
}
|
|
2609
|
+
function clear_deferred_timer(gobj) {
|
|
2610
|
+
let priv = gobj.priv;
|
|
2611
|
+
if (priv.deferred_timer) {
|
|
2612
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2613
|
+
priv.deferred_timer = null;
|
|
2614
|
+
}
|
|
2570
2615
|
}
|
|
2571
2616
|
function push_pending_markers(gobj) {
|
|
2572
2617
|
let priv = gobj.priv;
|
|
@@ -2577,6 +2622,8 @@ function push_pending_markers(gobj) {
|
|
|
2577
2622
|
entry.hash = window.location.hash;
|
|
2578
2623
|
push_overlay_marker(gobj, entry);
|
|
2579
2624
|
}
|
|
2625
|
+
clear_deferred_timer(gobj);
|
|
2626
|
+
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
2580
2627
|
if (priv.deferred_route) {
|
|
2581
2628
|
let route = priv.deferred_route;
|
|
2582
2629
|
priv.deferred_route = "";
|
|
@@ -2594,12 +2641,14 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2594
2641
|
let st = window.history.state;
|
|
2595
2642
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2596
2643
|
priv.expected_pops++;
|
|
2644
|
+
priv.expected_pop_ids.push(entry.id);
|
|
2597
2645
|
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2598
2646
|
priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
|
|
2599
2647
|
try {
|
|
2600
2648
|
window.history.back();
|
|
2601
2649
|
} catch (e) {
|
|
2602
2650
|
priv.expected_pops--;
|
|
2651
|
+
priv.expected_pop_ids.pop();
|
|
2603
2652
|
log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
|
|
2604
2653
|
}
|
|
2605
2654
|
}
|
|
@@ -2705,6 +2754,10 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2705
2754
|
}
|
|
2706
2755
|
route = remembered_position(gobj, route);
|
|
2707
2756
|
if (gobj_read_attr(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
2757
|
+
if (gobj.priv.expected_pops > 0) {
|
|
2758
|
+
defer_route(gobj, route);
|
|
2759
|
+
return 0;
|
|
2760
|
+
}
|
|
2708
2761
|
let target_hash = route_to_hash(route);
|
|
2709
2762
|
if (window.location.hash !== target_hash) window.location.hash = target_hash;
|
|
2710
2763
|
else navigate_to(gobj, route);
|
|
@@ -2712,6 +2765,27 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2712
2765
|
return 0;
|
|
2713
2766
|
}
|
|
2714
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
|
+
/************************************************************
|
|
2715
2789
|
* Drawer backdrop click on a C_YUI_NAV child: the nav publishes
|
|
2716
2790
|
* this so the shell can close the drawer through the canonical
|
|
2717
2791
|
* flow (DOM + focus-trap + escape-stack pop) instead of mutating
|
|
@@ -2784,11 +2858,17 @@ function create_gclass$22(gclass_name) {
|
|
|
2784
2858
|
"EV_NAV_ITEM_CLOSE",
|
|
2785
2859
|
ac_nav_item_close,
|
|
2786
2860
|
null
|
|
2861
|
+
],
|
|
2862
|
+
[
|
|
2863
|
+
"EV_BACK_WAIT_TIMEOUT",
|
|
2864
|
+
ac_back_wait_timeout,
|
|
2865
|
+
null
|
|
2787
2866
|
]
|
|
2788
2867
|
]]];
|
|
2789
2868
|
const event_types = [
|
|
2790
2869
|
["EV_NAV_CLICKED", 0],
|
|
2791
2870
|
["EV_DRAWER_CLOSE_REQUESTED", 0],
|
|
2871
|
+
["EV_BACK_WAIT_TIMEOUT", 0],
|
|
2792
2872
|
["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
|
|
2793
2873
|
["EV_ROUTE_REQUESTED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
|
|
2794
2874
|
["EV_ROUTE_CHANGED", event_flag_t.EVF_OUTPUT_EVENT | event_flag_t.EVF_PUBLIC_EVENT | event_flag_t.EVF_NO_WARN_SUBS],
|
|
@@ -2946,7 +3026,7 @@ function yui_shell_navigate(shell_gobj, route, opts) {
|
|
|
2946
3026
|
if (!(opts && opts.replace) && gobj_read_attr(shell_gobj, "use_hash")) {
|
|
2947
3027
|
let priv = shell_gobj.priv;
|
|
2948
3028
|
if (priv && priv.expected_pops > 0) {
|
|
2949
|
-
|
|
3029
|
+
defer_route(shell_gobj, route);
|
|
2950
3030
|
return;
|
|
2951
3031
|
}
|
|
2952
3032
|
let target_hash = route_to_hash(route);
|
package/package.json
CHANGED
|
@@ -94,7 +94,7 @@ function starts_with_markup(s)
|
|
|
94
94
|
/* String methods that keep the head of their receiver (a markup head
|
|
95
95
|
* stays a markup head through them). Not replace()/replaceAll(): they
|
|
96
96
|
* can take the head away ('<b>x</b>'.replace(/<[^>]+>/g, '') is text),
|
|
97
|
-
*
|
|
97
|
+
* see replaced(). */
|
|
98
98
|
const HEAD_KEEPING_METHODS = new Set([
|
|
99
99
|
"trim", "trimStart", "trimEnd", "toString", "valueOf", "normalize",
|
|
100
100
|
"toLowerCase", "toUpperCase", "padEnd", "concat"
|
|
@@ -107,6 +107,45 @@ const PURE_METHODS = new Set([
|
|
|
107
107
|
"toLowerCase", "toUpperCase"
|
|
108
108
|
]);
|
|
109
109
|
|
|
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 is no longer static. Its head is the receiver's -- 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)) -- 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>')). */
|
|
119
|
+
function replaced(method, head, args)
|
|
120
|
+
{
|
|
121
|
+
let replacement = (args.length === 2)? leading(args[1]) : null;
|
|
122
|
+
if(head.complete && args.length === 2) {
|
|
123
|
+
let pattern = null;
|
|
124
|
+
if(args[0].type === "Literal" && args[0].regex) {
|
|
125
|
+
try {
|
|
126
|
+
pattern = new RegExp(args[0].regex.pattern, args[0].regex.flags);
|
|
127
|
+
} catch(e) {
|
|
128
|
+
pattern = null;
|
|
129
|
+
}
|
|
130
|
+
} else if(is_string_literal(args[0])) {
|
|
131
|
+
pattern = args[0].value;
|
|
132
|
+
}
|
|
133
|
+
if(pattern !== null && replacement && replacement.complete) {
|
|
134
|
+
try {
|
|
135
|
+
return {text: String.prototype[method].call(head.text, pattern, replacement.text),
|
|
136
|
+
complete: true};
|
|
137
|
+
} catch(e) {
|
|
138
|
+
/* replaceAll() with a regex that is not global throws:
|
|
139
|
+
* so does the code, the check need not know what it gives. */
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if(replacement && starts_with_markup(replacement.text)) {
|
|
144
|
+
return {text: replacement.text, complete: false};
|
|
145
|
+
}
|
|
146
|
+
return {text: head.text, complete: false};
|
|
147
|
+
}
|
|
148
|
+
|
|
110
149
|
function concat_parts(parts)
|
|
111
150
|
{
|
|
112
151
|
/* parts: [{text, complete}] in order. The leading text runs while
|
|
@@ -191,6 +230,13 @@ function leading(n)
|
|
|
191
230
|
});
|
|
192
231
|
return concat_parts(parts);
|
|
193
232
|
}
|
|
233
|
+
if(method === "replace" || method === "replaceAll") {
|
|
234
|
+
let head = leading(receiver);
|
|
235
|
+
if(head === null) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
return replaced(method, head, n.arguments);
|
|
239
|
+
}
|
|
194
240
|
if(HEAD_KEEPING_METHODS.has(method)) {
|
|
195
241
|
let head = leading(receiver);
|
|
196
242
|
if(head === null) {
|
package/src/c_yui_shell.js
CHANGED
|
@@ -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,
|
|
@@ -180,6 +179,13 @@ let PRIVATE_DATA = {
|
|
|
180
179
|
* flight: it is navigated once the back() is over, or the traversal
|
|
181
180
|
* would run from it and undo it. */
|
|
182
181
|
deferred_route: "",
|
|
182
|
+
/* Bounds the wait for that back(): one that never lands must not
|
|
183
|
+
* hold every later navigation for ever. */
|
|
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,
|
|
183
189
|
popstate_handler: null,
|
|
184
190
|
/* Avatar item support — every toolbar item with type:"avatar"
|
|
185
191
|
* registers its <span> here so refresh_avatars() can repaint
|
|
@@ -329,6 +335,7 @@ function mt_start(gobj)
|
|
|
329
335
|
if(!p) {
|
|
330
336
|
return;
|
|
331
337
|
}
|
|
338
|
+
note_late_landing(gobj, ev);
|
|
332
339
|
/* A traversal that moved the hash is followed by a
|
|
333
340
|
* hashchange, QUEUED: it runs after this handler, and it is
|
|
334
341
|
* the one that navigates (and drains). */
|
|
@@ -419,25 +426,22 @@ function mt_start(gobj)
|
|
|
419
426
|
* below, on the hash it had.) */
|
|
420
427
|
return;
|
|
421
428
|
}
|
|
422
|
-
/* Which entry did it land ON?
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
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. */
|
|
432
443
|
let st = ev && ev.state;
|
|
433
|
-
if(st
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if(st && st.__yui_overlay__ > top.id &&
|
|
437
|
-
!p.overlay_stack.some(e => e.id === st.__yui_overlay__)) {
|
|
438
|
-
/* A dead marker NEWER than the top: only Forward reaches
|
|
439
|
-
* it (an overlay closed by its button above this one).
|
|
440
|
-
* It is not a step off the top's marker. */
|
|
444
|
+
if(!st || st.__yui_below__ !== top.id) {
|
|
441
445
|
return;
|
|
442
446
|
}
|
|
443
447
|
p.overlay_stack.pop();
|
|
@@ -542,6 +546,9 @@ function mt_stop(gobj)
|
|
|
542
546
|
priv.restore_hash = "";
|
|
543
547
|
priv.skip_hash = "";
|
|
544
548
|
priv.deferred_route = "";
|
|
549
|
+
clear_deferred_timer(gobj);
|
|
550
|
+
priv.expected_pop_ids = [];
|
|
551
|
+
priv.given_up = null;
|
|
545
552
|
if(priv.keydown_handler) {
|
|
546
553
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
547
554
|
priv.keydown_handler = null;
|
|
@@ -2735,6 +2742,13 @@ function retag_overlay_hash(gobj, st, hash)
|
|
|
2735
2742
|
}
|
|
2736
2743
|
}
|
|
2737
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
|
+
|
|
2738
2752
|
function push_overlay_history(gobj, close, opts)
|
|
2739
2753
|
{
|
|
2740
2754
|
let priv = gobj.priv;
|
|
@@ -2746,7 +2760,7 @@ function push_overlay_history(gobj, close, opts)
|
|
|
2746
2760
|
* step OFF this marker from a route traversal; it is NOT the resting
|
|
2747
2761
|
* route (a `stay` action route parks the URL off it). Kept in sync
|
|
2748
2762
|
* by the silent replaceState fix-up in navigate_to(). */
|
|
2749
|
-
let entry = { id: ++
|
|
2763
|
+
let entry = { id: ++__overlay_seq__, close: close,
|
|
2750
2764
|
hash: window.location.hash,
|
|
2751
2765
|
/* Read by drain_overlays: a navigation PANEL survives a
|
|
2752
2766
|
* resting-route change. Dropping it here left the whole
|
|
@@ -2781,6 +2795,27 @@ function push_overlay_marker(gobj, entry)
|
|
|
2781
2795
|
* marker lands there -- even after a replace-navigation rewrote the
|
|
2782
2796
|
* marker's own hash (retag_overlay_hash()). */
|
|
2783
2797
|
entry.below_hash = window.location.hash;
|
|
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))) {
|
|
2807
|
+
try {
|
|
2808
|
+
window.history.replaceState(
|
|
2809
|
+
Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2810
|
+
} catch(e) {
|
|
2811
|
+
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
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
|
+
);
|
|
2818
|
+
}
|
|
2784
2819
|
try {
|
|
2785
2820
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2786
2821
|
} catch(e) {
|
|
@@ -2812,10 +2847,83 @@ function drop_expected_pops(gobj)
|
|
|
2812
2847
|
);
|
|
2813
2848
|
priv.expected_pops = 0;
|
|
2814
2849
|
priv.expected_pop_hash = "";
|
|
2850
|
+
priv.expected_pop_ids = [];
|
|
2851
|
+
clear_deferred_timer(gobj);
|
|
2852
|
+
if(priv.deferred_route) {
|
|
2853
|
+
/* The history moved on under it (a link, a Back): that move is
|
|
2854
|
+
* the newer one, and running the route after it would undo it. */
|
|
2855
|
+
log_warning(
|
|
2856
|
+
`C_YUI_SHELL: route '${priv.deferred_route}' waited for that ` +
|
|
2857
|
+
`back() and is dropped: the history moved on to '${window.location.hash}'`
|
|
2858
|
+
);
|
|
2859
|
+
priv.deferred_route = "";
|
|
2860
|
+
}
|
|
2815
2861
|
/* The caller pushes the waiting markers, once it has handled the
|
|
2816
2862
|
* traversal that told it. */
|
|
2817
2863
|
}
|
|
2818
2864
|
|
|
2865
|
+
/* A route pushed while a back() of ours is in flight waits for it to
|
|
2866
|
+
* land (push_pending_markers() navigates it), and a newer one takes
|
|
2867
|
+
* its place, said out loud. The wait is bounded: a back() that never
|
|
2868
|
+
* lands, with nothing else moving the history to say so, would hold
|
|
2869
|
+
* every later navigation. */
|
|
2870
|
+
const DEFERRED_ROUTE_WAIT_MS = 1000;
|
|
2871
|
+
|
|
2872
|
+
function defer_route(gobj, route)
|
|
2873
|
+
{
|
|
2874
|
+
let priv = gobj.priv;
|
|
2875
|
+
if(priv.deferred_route && priv.deferred_route !== route) {
|
|
2876
|
+
log_warning(
|
|
2877
|
+
`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() ` +
|
|
2878
|
+
`of ours is replaced by '${route}'`
|
|
2879
|
+
);
|
|
2880
|
+
}
|
|
2881
|
+
priv.deferred_route = route;
|
|
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). */
|
|
2885
|
+
priv.deferred_timer = window.setTimeout(() => {
|
|
2886
|
+
if(!gobj.priv) {
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
gobj.priv.deferred_timer = null;
|
|
2890
|
+
gobj_send_event(gobj, "EV_BACK_WAIT_TIMEOUT", {}, gobj);
|
|
2891
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
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
|
+
|
|
2918
|
+
function clear_deferred_timer(gobj)
|
|
2919
|
+
{
|
|
2920
|
+
let priv = gobj.priv;
|
|
2921
|
+
if(priv.deferred_timer) {
|
|
2922
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2923
|
+
priv.deferred_timer = null;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2819
2927
|
/* The history.back() calls of ours have all landed: push the markers of
|
|
2820
2928
|
* the overlays registered meanwhile, in their order. One closed in the
|
|
2821
2929
|
* meantime (dismissed, drained, or no longer on the stack) has none. */
|
|
@@ -2833,6 +2941,10 @@ function push_pending_markers(gobj)
|
|
|
2833
2941
|
entry.hash = window.location.hash;
|
|
2834
2942
|
push_overlay_marker(gobj, entry); // Error already logged
|
|
2835
2943
|
}
|
|
2944
|
+
clear_deferred_timer(gobj);
|
|
2945
|
+
if(priv.expected_pops === 0) {
|
|
2946
|
+
priv.expected_pop_ids = [];
|
|
2947
|
+
}
|
|
2836
2948
|
if(priv.deferred_route) {
|
|
2837
2949
|
let route = priv.deferred_route;
|
|
2838
2950
|
priv.deferred_route = "";
|
|
@@ -2874,6 +2986,7 @@ function overlay_dismissed(gobj, entry)
|
|
|
2874
2986
|
let st = window.history.state;
|
|
2875
2987
|
if(st && st.__yui_overlay__ === entry.id) {
|
|
2876
2988
|
priv.expected_pops++;
|
|
2989
|
+
priv.expected_pop_ids.push(entry.id);
|
|
2877
2990
|
priv.expected_pop_hash = (typeof entry.below_hash === "string")?
|
|
2878
2991
|
entry.below_hash : window.location.hash;
|
|
2879
2992
|
/* A position written on the marker by a replace navigation is
|
|
@@ -2884,6 +2997,7 @@ function overlay_dismissed(gobj, entry)
|
|
|
2884
2997
|
window.history.back();
|
|
2885
2998
|
} catch(e) {
|
|
2886
2999
|
priv.expected_pops--;
|
|
3000
|
+
priv.expected_pop_ids.pop();
|
|
2887
3001
|
log_warning(`C_YUI_SHELL: overlay history.back() failed: ${e}`);
|
|
2888
3002
|
}
|
|
2889
3003
|
}
|
|
@@ -3110,6 +3224,13 @@ function ac_nav_clicked(gobj, event, kw, src)
|
|
|
3110
3224
|
* Exception: URL-restoring action routes skip the push — see
|
|
3111
3225
|
* route_restores_url. */
|
|
3112
3226
|
if(gobj_read_attr(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
3227
|
+
if(gobj.priv.expected_pops > 0) {
|
|
3228
|
+
/* A back() of ours is in flight (an overlay closed in this
|
|
3229
|
+
* same turn): a push now would be undone by it, as in
|
|
3230
|
+
* yui_shell_navigate(). */
|
|
3231
|
+
defer_route(gobj, route);
|
|
3232
|
+
return 0;
|
|
3233
|
+
}
|
|
3113
3234
|
let target_hash = route_to_hash(route);
|
|
3114
3235
|
if(window.location.hash !== target_hash) {
|
|
3115
3236
|
window.location.hash = target_hash; /* fires hashchange */
|
|
@@ -3123,6 +3244,31 @@ function ac_nav_clicked(gobj, event, kw, src)
|
|
|
3123
3244
|
return 0;
|
|
3124
3245
|
}
|
|
3125
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
|
+
|
|
3126
3272
|
/************************************************************
|
|
3127
3273
|
* Drawer backdrop click on a C_YUI_NAV child: the nav publishes
|
|
3128
3274
|
* this so the shell can close the drawer through the canonical
|
|
@@ -3374,13 +3520,17 @@ function create_gclass(gclass_name)
|
|
|
3374
3520
|
["EV_DRAWER_CLOSE_REQUESTED", ac_drawer_close_requested, null],
|
|
3375
3521
|
/* Close 'x' on a closable tab (from a child C_YUI_NAV);
|
|
3376
3522
|
* re-published for the app. */
|
|
3377
|
-
["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]
|
|
3378
3527
|
]]
|
|
3379
3528
|
];
|
|
3380
3529
|
|
|
3381
3530
|
const event_types = [
|
|
3382
3531
|
["EV_NAV_CLICKED", 0],
|
|
3383
3532
|
["EV_DRAWER_CLOSE_REQUESTED", 0],
|
|
3533
|
+
["EV_BACK_WAIT_TIMEOUT", 0],
|
|
3384
3534
|
["EV_NAV_ITEM_CLOSE", event_flag_t.EVF_OUTPUT_EVENT
|
|
3385
3535
|
|event_flag_t.EVF_PUBLIC_EVENT
|
|
3386
3536
|
|event_flag_t.EVF_NO_WARN_SUBS],
|
|
@@ -3706,7 +3856,7 @@ function yui_shell_navigate(shell_gobj, route, opts)
|
|
|
3706
3856
|
* navigates): a push now lands BEFORE the traversal, which
|
|
3707
3857
|
* then runs from it and undoes it (and in Firefox lands on
|
|
3708
3858
|
* the closed overlay's marker). Navigate once it is over. */
|
|
3709
|
-
|
|
3859
|
+
defer_route(shell_gobj, route);
|
|
3710
3860
|
return;
|
|
3711
3861
|
}
|
|
3712
3862
|
let target_hash = route_to_hash(route);
|
|
@@ -163,12 +163,34 @@ describe("data is text, not markup", () => {
|
|
|
163
163
|
{id: EVIL, value: EVIL, title: EVIL},
|
|
164
164
|
{text: EVIL, value: "v", title: "t"},
|
|
165
165
|
];
|
|
166
|
+
/* The DOM double builds no element out of markup, so the html is
|
|
167
|
+
* read here as a browser would: tags out, entities decoded. What
|
|
168
|
+
* the reader sees and what each attribute holds must be the
|
|
169
|
+
* value itself -- an unescaped value drops out of the text. */
|
|
170
|
+
const decode = (v) => v.replace(/</g, "<").replace(/>/g, ">")
|
|
171
|
+
.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
172
|
+
const visible = (html) => decode(html.replace(/<[^>]*>/g, ""));
|
|
173
|
+
const attr = (html, name) => {
|
|
174
|
+
const m = html.match(new RegExp(` ${name}="([^"]*)"`));
|
|
175
|
+
return m ? decode(m[1]) : null;
|
|
176
|
+
};
|
|
177
|
+
const read = toolbar_item_html(items[0]);
|
|
178
|
+
expect(visible(read)).toBe(EVIL);
|
|
179
|
+
expect(attr(read, "title")).toBe(EVIL);
|
|
180
|
+
expect(attr(read, "aria-label")).toBe(EVIL);
|
|
181
|
+
expect(attr(read, "class")).toBe(`g6-toolbar-readout ${EVIL}`);
|
|
182
|
+
|
|
183
|
+
const icon = toolbar_item_html(items[1]);
|
|
184
|
+
expect(visible(icon)).toBe("");
|
|
185
|
+
expect(attr(icon, "value")).toBe(EVIL);
|
|
186
|
+
expect(attr(icon, "title")).toBe(EVIL);
|
|
187
|
+
expect(attr(icon, "xlink:href")).toBe(`#${EVIL}`);
|
|
188
|
+
|
|
189
|
+
const text = toolbar_item_html(items[2]);
|
|
190
|
+
expect(visible(text)).toBe(EVIL);
|
|
191
|
+
|
|
166
192
|
for(const item of items) {
|
|
167
|
-
|
|
168
|
-
expect(html.includes("<img")).toBe(false);
|
|
169
|
-
const $box = document.createElement("div");
|
|
170
|
-
$box.innerHTML = html;
|
|
171
|
-
expect($box.querySelector("img")).toBe(null);
|
|
193
|
+
expect(toolbar_item_html(item).includes("<img")).toBe(false);
|
|
172
194
|
}
|
|
173
195
|
});
|
|
174
196
|
});
|
|
@@ -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).
|
|
360
|
+
expect(window.history.state.__yui_overlay__).toBeUndefined(); // stamped, no marker
|
|
361
361
|
expect(errors()).toEqual([]);
|
|
362
362
|
});
|
|
363
363
|
|
|
@@ -583,7 +583,7 @@ describe("a routed shell, a realistic history (V5)", () => {
|
|
|
583
583
|
expect(shell.priv.expected_pops).toBe(0);
|
|
584
584
|
expect(window.location.hash).toBe("#/home/pos");
|
|
585
585
|
expect(gobj_read_attr(shell, "current_route")).toBe("/home/pos");
|
|
586
|
-
expect(window.history.state).
|
|
586
|
+
expect(window.history.state).toEqual({__yui_below__: entry.id}); // stamped, no marker
|
|
587
587
|
expect(errors()).toEqual([]);
|
|
588
588
|
});
|
|
589
589
|
|
|
@@ -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).
|
|
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);
|
|
@@ -656,3 +656,307 @@ describe("a routed shell, a realistic history (V5)", () => {
|
|
|
656
656
|
});
|
|
657
657
|
});
|
|
658
658
|
|
|
659
|
+
/*
|
|
660
|
+
* Sixth check of the review (V6).
|
|
661
|
+
*/
|
|
662
|
+
/* The test app declares no route event: what the shell says is what
|
|
663
|
+
* these tests read. */
|
|
664
|
+
function shell_warnings()
|
|
665
|
+
{
|
|
666
|
+
return errors().filter((m) => m.includes("C_YUI_SHELL"));
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
describe("a link is not a Back (V6.1)", () => {
|
|
670
|
+
test("a link back to the hash a kept panel was opened on keeps it open", async () => {
|
|
671
|
+
const app = gobj_create("v6app1", "C_TEST_MARKER_APP", {}, yuno);
|
|
672
|
+
gobj_start(app);
|
|
673
|
+
window.location.hash = "#/home";
|
|
674
|
+
install_history_model();
|
|
675
|
+
const shell = routed_shell("v6shell1", app);
|
|
676
|
+
const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
|
|
677
|
+
let closed = 0;
|
|
678
|
+
yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
|
|
679
|
+
|
|
680
|
+
link_to("#/other");
|
|
681
|
+
await next_task();
|
|
682
|
+
link_to("#/home"); // the panel's own hash
|
|
683
|
+
await next_task();
|
|
684
|
+
await next_task();
|
|
685
|
+
expect(closed).toBe(0);
|
|
686
|
+
expect(shell.priv.overlay_stack.length).toBe(1);
|
|
687
|
+
expect(window.location.hash).toBe("#/home");
|
|
688
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/home");
|
|
689
|
+
expect(shell_warnings()).toEqual([]);
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
test("after a replace navigation, a link to the hash under the marker: URL and view agree", async () => {
|
|
693
|
+
const app = gobj_create("v6app2", "C_TEST_MARKER_APP", {}, yuno);
|
|
694
|
+
gobj_start(app);
|
|
695
|
+
window.location.hash = "#/home";
|
|
696
|
+
install_history_model();
|
|
697
|
+
const shell = routed_shell("v6shell2", app);
|
|
698
|
+
const {yui_shell_register_overlay, yui_shell_navigate} = await import("./c_yui_shell.js");
|
|
699
|
+
let closed = 0;
|
|
700
|
+
yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
|
|
701
|
+
yui_shell_navigate(shell, "/home/pos", {replace: true});
|
|
702
|
+
|
|
703
|
+
link_to("#/other");
|
|
704
|
+
await next_task();
|
|
705
|
+
link_to("#/home"); // the hash of the entry under the marker
|
|
706
|
+
await next_task();
|
|
707
|
+
await next_task();
|
|
708
|
+
expect(closed).toBe(0);
|
|
709
|
+
expect(window.location.hash).toBe("#/home");
|
|
710
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/home");
|
|
711
|
+
expect(shell_warnings()).toEqual([]);
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
test("from the position, a link to the panel's hash is a push; Back walks it, then closes the panel", async () => {
|
|
715
|
+
const app = gobj_create("v6app3", "C_TEST_MARKER_APP", {}, yuno);
|
|
716
|
+
gobj_start(app);
|
|
717
|
+
window.location.hash = "#/home";
|
|
718
|
+
install_history_model();
|
|
719
|
+
const shell = routed_shell("v6shell3", app);
|
|
720
|
+
const {yui_shell_register_overlay, yui_shell_navigate} = await import("./c_yui_shell.js");
|
|
721
|
+
let closed = 0;
|
|
722
|
+
yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
|
|
723
|
+
yui_shell_navigate(shell, "/home/pos", {replace: true});
|
|
724
|
+
|
|
725
|
+
link_to("#/home");
|
|
726
|
+
await next_task();
|
|
727
|
+
await next_task();
|
|
728
|
+
expect(closed).toBe(0);
|
|
729
|
+
expect(window.location.hash).toBe("#/home");
|
|
730
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/home");
|
|
731
|
+
|
|
732
|
+
user_back(); // onto the marker: the panel is home
|
|
733
|
+
await next_task();
|
|
734
|
+
await next_task();
|
|
735
|
+
expect(closed).toBe(0);
|
|
736
|
+
expect(window.location.hash).toBe("#/home/pos");
|
|
737
|
+
|
|
738
|
+
user_back(); // off it: closes the panel
|
|
739
|
+
await next_task();
|
|
740
|
+
await next_task();
|
|
741
|
+
expect(closed).toBe(1);
|
|
742
|
+
expect(window.location.hash).toBe("#/home/pos");
|
|
743
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/home/pos");
|
|
744
|
+
expect(shell_warnings()).toEqual([]);
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
describe("a route waiting for a back() of ours (V6.2)", () => {
|
|
749
|
+
test("a newer route replaces the waiting one, and says so", async () => {
|
|
750
|
+
const app = gobj_create("v6app4", "C_TEST_MARKER_APP", {}, yuno);
|
|
751
|
+
gobj_start(app);
|
|
752
|
+
window.location.hash = "#/home";
|
|
753
|
+
install_history_model();
|
|
754
|
+
const shell = routed_shell("v6shell4", app);
|
|
755
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
756
|
+
await import("./c_yui_shell.js");
|
|
757
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
758
|
+
links_on_hash_assign();
|
|
759
|
+
|
|
760
|
+
yui_shell_overlay_dismissed(shell, entry);
|
|
761
|
+
yui_shell_navigate(shell, "/prev");
|
|
762
|
+
yui_shell_navigate(shell, "/other");
|
|
763
|
+
for(let i = 0; i < 4; i++) {
|
|
764
|
+
await next_task();
|
|
765
|
+
}
|
|
766
|
+
expect(window.location.hash).toBe("#/other");
|
|
767
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/other");
|
|
768
|
+
expect(shell_warnings().filter(m => m.includes("is replaced by '/other'")).length).toBe(1);
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
test("a back() that never lands is given up on, and the waiting route runs", async () => {
|
|
772
|
+
const app = gobj_create("v6app5", "C_TEST_MARKER_APP", {}, yuno);
|
|
773
|
+
gobj_start(app);
|
|
774
|
+
window.location.hash = "#/home";
|
|
775
|
+
install_history_model();
|
|
776
|
+
const shell = routed_shell("v6shell5", app);
|
|
777
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
778
|
+
await import("./c_yui_shell.js");
|
|
779
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
780
|
+
window.history.back = () => {}; // it never lands
|
|
781
|
+
links_on_hash_assign();
|
|
782
|
+
|
|
783
|
+
yui_shell_overlay_dismissed(shell, entry);
|
|
784
|
+
yui_shell_navigate(shell, "/prev");
|
|
785
|
+
await next_task();
|
|
786
|
+
expect(window.location.hash).toBe("#/home"); // still waiting
|
|
787
|
+
await new Promise(resolve => setTimeout(resolve, 1100));
|
|
788
|
+
await next_task();
|
|
789
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
790
|
+
expect(window.location.hash).toBe("#/prev");
|
|
791
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/prev");
|
|
792
|
+
expect(shell_warnings().filter(m => m.includes("given up")).length).toBe(1);
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
test("a user's link while a route waits: the link wins, the route is dropped out loud", async () => {
|
|
796
|
+
const app = gobj_create("v6app6", "C_TEST_MARKER_APP", {}, yuno);
|
|
797
|
+
gobj_start(app);
|
|
798
|
+
window.location.hash = "#/home";
|
|
799
|
+
install_history_model();
|
|
800
|
+
const shell = routed_shell("v6shell6", app);
|
|
801
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
802
|
+
await import("./c_yui_shell.js");
|
|
803
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
804
|
+
window.history.back = () => {}; // the link cancels the traversal
|
|
805
|
+
|
|
806
|
+
yui_shell_overlay_dismissed(shell, entry);
|
|
807
|
+
yui_shell_navigate(shell, "/prev");
|
|
808
|
+
link_to("#/other");
|
|
809
|
+
for(let i = 0; i < 4; i++) {
|
|
810
|
+
await next_task();
|
|
811
|
+
}
|
|
812
|
+
expect(window.location.hash).toBe("#/other");
|
|
813
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/other");
|
|
814
|
+
expect(shell.priv.deferred_route).toBe("");
|
|
815
|
+
expect(shell_warnings().filter(m => m.includes("'/prev' waited for that back() and is dropped")).length).toBe(1);
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
test("a menu click in the same turn as a close waits for the back() too", async () => {
|
|
819
|
+
const app = gobj_create("v6app7", "C_TEST_MARKER_APP", {}, yuno);
|
|
820
|
+
gobj_start(app);
|
|
821
|
+
window.location.hash = "#/home";
|
|
822
|
+
install_history_model();
|
|
823
|
+
const shell = routed_shell("v6shell7", app);
|
|
824
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} = await import("./c_yui_shell.js");
|
|
825
|
+
const {gobj_send_event} = await import("@yuneta/gobj-js");
|
|
826
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
827
|
+
await next_task();
|
|
828
|
+
links_on_hash_assign();
|
|
829
|
+
|
|
830
|
+
yui_shell_overlay_dismissed(shell, entry);
|
|
831
|
+
gobj_send_event(shell, "EV_NAV_CLICKED", {route: "/prev"}, app);
|
|
832
|
+
for(let i = 0; i < 4; i++) {
|
|
833
|
+
await next_task();
|
|
834
|
+
}
|
|
835
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
836
|
+
expect(window.location.hash).toBe("#/prev");
|
|
837
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/prev");
|
|
838
|
+
expect(window.history.state).toBe(null); // the pushed entry, no marker
|
|
839
|
+
expect(shell_warnings()).toEqual([]);
|
|
840
|
+
|
|
841
|
+
user_back();
|
|
842
|
+
await next_task();
|
|
843
|
+
await next_task();
|
|
844
|
+
expect(window.location.hash).toBe("#/home"); // not swallowed
|
|
845
|
+
});
|
|
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
|
+
});
|
|
@@ -69,10 +69,16 @@ function errors()
|
|
|
69
69
|
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
/* A Back off a marker lands on the entry under it, which the shell
|
|
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)
|
|
73
77
|
{
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
const stack = shell.priv.overlay_stack;
|
|
79
|
+
const ev = new Event("popstate");
|
|
80
|
+
ev.state = {__yui_below__: stack.length ? stack[stack.length - 1].id : 0};
|
|
81
|
+
window.dispatchEvent(ev);
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
describe("a floating window that vetoes its close", () => {
|
|
@@ -90,7 +96,7 @@ describe("a floating window that vetoes its close", () => {
|
|
|
90
96
|
const first = gobj_read_attr(win, "back_overlay");
|
|
91
97
|
expect(first).toBeTruthy();
|
|
92
98
|
|
|
93
|
-
press_back();
|
|
99
|
+
press_back(shell);
|
|
94
100
|
expect(gobj_is_destroying(win)).toBe(false);
|
|
95
101
|
const second = gobj_read_attr(win, "back_overlay");
|
|
96
102
|
expect(second).toBeTruthy();
|
|
@@ -98,7 +104,7 @@ describe("a floating window that vetoes its close", () => {
|
|
|
98
104
|
expect(shell.priv.overlay_stack).toEqual([second]);
|
|
99
105
|
|
|
100
106
|
veto = false;
|
|
101
|
-
press_back();
|
|
107
|
+
press_back(shell);
|
|
102
108
|
expect(gobj_is_destroying(win)).toBe(true);
|
|
103
109
|
expect(shell.priv.overlay_stack).toEqual([]);
|
|
104
110
|
expect(errors()).toEqual([]);
|
|
@@ -118,14 +124,14 @@ describe("a floating window that vetoes its close", () => {
|
|
|
118
124
|
warning = "unsaved changes";
|
|
119
125
|
|
|
120
126
|
/* Back: the window asks. Only the question is on the stack. */
|
|
121
|
-
press_back();
|
|
127
|
+
press_back(shell);
|
|
122
128
|
expect(gobj_is_destroying(win)).toBe(false);
|
|
123
129
|
expect(shell.priv.overlay_stack.length).toBe(1);
|
|
124
130
|
expect(gobj_read_attr(win, "back_overlay")).toBe(null);
|
|
125
131
|
|
|
126
132
|
/* Back again: the question goes; the window takes its entry back
|
|
127
133
|
* only then, once there is nothing above it. */
|
|
128
|
-
press_back();
|
|
134
|
+
press_back(shell);
|
|
129
135
|
await new Promise(resolve => setTimeout(resolve, 0));
|
|
130
136
|
expect(gobj_is_destroying(win)).toBe(false);
|
|
131
137
|
const entry = gobj_read_attr(win, "back_overlay");
|