@yuneta/gobj-ui 7.26.12 → 7.26.13
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/README.md +6 -2
- package/dist/gobj-ui.cjs.js +48 -9
- package/dist/gobj-ui.es.js +48 -9
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +14 -2
- package/src/c_yui_shell.js +98 -11
- package/src/overlay_marker_after_back.wiring.test.js +211 -11
package/README.md
CHANGED
|
@@ -3359,8 +3359,12 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
|
|
|
3359
3359
|
children whose first item is a markup string (`list-head`: such a list is
|
|
3360
3360
|
read as one description). A ternary, `||`/`&&`/`??` and a comma
|
|
3361
3361
|
sequence (its last item) are checked branch by branch; a tag is matched
|
|
3362
|
-
in any case
|
|
3363
|
-
|
|
3362
|
+
in any case; a pure string method over a static string
|
|
3363
|
+
(`'<b>s</b>'.toUpperCase()`) is still a `literal`. `.replace()` /
|
|
3364
|
+
`.replaceAll()` are NOT taken as keeping the head (they can remove it),
|
|
3365
|
+
so their result is not checked. It CANNOT see: a variable or a function
|
|
3366
|
+
result that holds a string (a helper that returns markup); the result of
|
|
3367
|
+
`.replace()`/`.replaceAll()`; a template whose head is an
|
|
3364
3368
|
expression that is not a static string (`` `${prefix}<b>` ``); a
|
|
3365
3369
|
description built piece by piece (`push()` into the content list); a
|
|
3366
3370
|
computed tag with an attrs slot that is not an object literal; markup
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -974,6 +974,10 @@ var PRIVATE_DATA$22 = {
|
|
|
974
974
|
expected_pops: 0,
|
|
975
975
|
expected_pop_hash: "",
|
|
976
976
|
pending_markers: [],
|
|
977
|
+
last_hash: "",
|
|
978
|
+
markers_after_hashchange: false,
|
|
979
|
+
restore_hash: "",
|
|
980
|
+
skip_hash: "",
|
|
977
981
|
popstate_handler: null,
|
|
978
982
|
avatar_provider: null,
|
|
979
983
|
avatar_nodes: [],
|
|
@@ -1021,42 +1025,68 @@ function mt_start$20(gobj) {
|
|
|
1021
1025
|
build_toolbar$1(gobj, config);
|
|
1022
1026
|
preinstantiate_eager_views(gobj);
|
|
1023
1027
|
if ((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash")) {
|
|
1028
|
+
priv.last_hash = window.location.hash;
|
|
1024
1029
|
priv.hash_handler = () => {
|
|
1025
1030
|
let p = gobj.priv;
|
|
1026
|
-
|
|
1027
|
-
|
|
1031
|
+
if (!p) return;
|
|
1032
|
+
let markers_now = p.markers_after_hashchange;
|
|
1033
|
+
p.markers_after_hashchange = false;
|
|
1034
|
+
if (p.skip_hash && window.location.hash === p.skip_hash) {
|
|
1035
|
+
p.skip_hash = "";
|
|
1036
|
+
p.last_hash = window.location.hash;
|
|
1037
|
+
if (markers_now) push_pending_markers(gobj);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
p.skip_hash = "";
|
|
1041
|
+
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1028
1042
|
drop_expected_pops(gobj);
|
|
1029
|
-
|
|
1043
|
+
markers_now = true;
|
|
1030
1044
|
}
|
|
1031
1045
|
let route = hash_to_route(window.location.hash);
|
|
1032
1046
|
if (!(0, _yuneta_gobj_js.empty_string)(route)) navigate_to(gobj, route);
|
|
1033
|
-
|
|
1047
|
+
p.last_hash = window.location.hash;
|
|
1048
|
+
if (markers_now) push_pending_markers(gobj);
|
|
1034
1049
|
};
|
|
1035
1050
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
1036
1051
|
priv.popstate_handler = (ev) => {
|
|
1037
1052
|
let p = gobj.priv;
|
|
1038
1053
|
if (!p) return;
|
|
1054
|
+
let hash_moved = window.location.hash !== p.last_hash;
|
|
1039
1055
|
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1040
1056
|
drop_expected_pops(gobj);
|
|
1041
1057
|
on_traversal(ev);
|
|
1042
|
-
|
|
1058
|
+
if (hash_moved) p.markers_after_hashchange = true;
|
|
1059
|
+
else push_pending_markers(gobj);
|
|
1060
|
+
p.last_hash = window.location.hash;
|
|
1043
1061
|
return;
|
|
1044
1062
|
}
|
|
1045
1063
|
on_traversal(ev);
|
|
1064
|
+
if (!p.skip_hash) p.last_hash = window.location.hash;
|
|
1046
1065
|
};
|
|
1047
1066
|
let on_traversal = (ev) => {
|
|
1048
1067
|
let p = gobj.priv;
|
|
1049
1068
|
if (p.expected_pops > 0) {
|
|
1050
1069
|
p.expected_pops--;
|
|
1051
|
-
if (p.expected_pops === 0)
|
|
1070
|
+
if (p.expected_pops === 0) {
|
|
1071
|
+
if (p.restore_hash && p.restore_hash !== window.location.hash) try {
|
|
1072
|
+
window.history.replaceState(window.history.state, "", p.restore_hash);
|
|
1073
|
+
p.skip_hash = p.restore_hash;
|
|
1074
|
+
p.last_hash = p.restore_hash;
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: restoring '${p.restore_hash}' failed: ${e}`);
|
|
1077
|
+
}
|
|
1078
|
+
p.restore_hash = "";
|
|
1079
|
+
push_pending_markers(gobj);
|
|
1080
|
+
}
|
|
1052
1081
|
return;
|
|
1053
1082
|
}
|
|
1054
1083
|
if (p.overlay_stack.length === 0) return;
|
|
1055
1084
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
1056
|
-
if (top.marker_pending) return;
|
|
1057
|
-
if (window.location.hash !== top.hash) return;
|
|
1085
|
+
if (top.marker_pending || top.no_marker) return;
|
|
1086
|
+
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1058
1087
|
let st = ev && ev.state;
|
|
1059
1088
|
if (st && st.__yui_overlay__ === top.id) return;
|
|
1089
|
+
if (st && st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
|
|
1060
1090
|
p.overlay_stack.pop();
|
|
1061
1091
|
try {
|
|
1062
1092
|
top.close();
|
|
@@ -1098,9 +1128,16 @@ function mt_stop$20(gobj) {
|
|
|
1098
1128
|
window.removeEventListener("popstate", priv.popstate_handler);
|
|
1099
1129
|
priv.popstate_handler = null;
|
|
1100
1130
|
}
|
|
1131
|
+
for (let entry of priv.pending_markers) {
|
|
1132
|
+
entry.marker_pending = false;
|
|
1133
|
+
entry.no_marker = true;
|
|
1134
|
+
}
|
|
1101
1135
|
priv.expected_pops = 0;
|
|
1102
1136
|
priv.expected_pop_hash = "";
|
|
1103
1137
|
priv.pending_markers = [];
|
|
1138
|
+
priv.markers_after_hashchange = false;
|
|
1139
|
+
priv.restore_hash = "";
|
|
1140
|
+
priv.skip_hash = "";
|
|
1104
1141
|
if (priv.keydown_handler) {
|
|
1105
1142
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1106
1143
|
priv.keydown_handler = null;
|
|
@@ -1706,6 +1743,7 @@ function navigate_to(gobj, route, depth, no_drain) {
|
|
|
1706
1743
|
let target_hash = route_to_hash(route);
|
|
1707
1744
|
if (window.location.hash !== target_hash) try {
|
|
1708
1745
|
window.history.replaceState(window.history.state, "", target_hash);
|
|
1746
|
+
priv.last_hash = target_hash;
|
|
1709
1747
|
retag_overlay_hash(gobj, window.history.state, target_hash);
|
|
1710
1748
|
} catch (e) {
|
|
1711
1749
|
window.location.hash = target_hash;
|
|
@@ -2543,11 +2581,12 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2543
2581
|
let idx = priv.overlay_stack.indexOf(entry);
|
|
2544
2582
|
if (idx < 0) return;
|
|
2545
2583
|
priv.overlay_stack.splice(idx, 1);
|
|
2546
|
-
if (entry.marker_pending) return;
|
|
2584
|
+
if (entry.marker_pending || entry.no_marker) return;
|
|
2547
2585
|
let st = window.history.state;
|
|
2548
2586
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2549
2587
|
priv.expected_pops++;
|
|
2550
2588
|
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2589
|
+
priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
|
|
2551
2590
|
try {
|
|
2552
2591
|
window.history.back();
|
|
2553
2592
|
} catch (e) {
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -969,6 +969,10 @@ var PRIVATE_DATA$22 = {
|
|
|
969
969
|
expected_pops: 0,
|
|
970
970
|
expected_pop_hash: "",
|
|
971
971
|
pending_markers: [],
|
|
972
|
+
last_hash: "",
|
|
973
|
+
markers_after_hashchange: false,
|
|
974
|
+
restore_hash: "",
|
|
975
|
+
skip_hash: "",
|
|
972
976
|
popstate_handler: null,
|
|
973
977
|
avatar_provider: null,
|
|
974
978
|
avatar_nodes: [],
|
|
@@ -1016,42 +1020,68 @@ function mt_start$20(gobj) {
|
|
|
1016
1020
|
build_toolbar$1(gobj, config);
|
|
1017
1021
|
preinstantiate_eager_views(gobj);
|
|
1018
1022
|
if (gobj_read_attr(gobj, "use_hash")) {
|
|
1023
|
+
priv.last_hash = window.location.hash;
|
|
1019
1024
|
priv.hash_handler = () => {
|
|
1020
1025
|
let p = gobj.priv;
|
|
1021
|
-
|
|
1022
|
-
|
|
1026
|
+
if (!p) return;
|
|
1027
|
+
let markers_now = p.markers_after_hashchange;
|
|
1028
|
+
p.markers_after_hashchange = false;
|
|
1029
|
+
if (p.skip_hash && window.location.hash === p.skip_hash) {
|
|
1030
|
+
p.skip_hash = "";
|
|
1031
|
+
p.last_hash = window.location.hash;
|
|
1032
|
+
if (markers_now) push_pending_markers(gobj);
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
p.skip_hash = "";
|
|
1036
|
+
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1023
1037
|
drop_expected_pops(gobj);
|
|
1024
|
-
|
|
1038
|
+
markers_now = true;
|
|
1025
1039
|
}
|
|
1026
1040
|
let route = hash_to_route(window.location.hash);
|
|
1027
1041
|
if (!empty_string(route)) navigate_to(gobj, route);
|
|
1028
|
-
|
|
1042
|
+
p.last_hash = window.location.hash;
|
|
1043
|
+
if (markers_now) push_pending_markers(gobj);
|
|
1029
1044
|
};
|
|
1030
1045
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
1031
1046
|
priv.popstate_handler = (ev) => {
|
|
1032
1047
|
let p = gobj.priv;
|
|
1033
1048
|
if (!p) return;
|
|
1049
|
+
let hash_moved = window.location.hash !== p.last_hash;
|
|
1034
1050
|
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1035
1051
|
drop_expected_pops(gobj);
|
|
1036
1052
|
on_traversal(ev);
|
|
1037
|
-
|
|
1053
|
+
if (hash_moved) p.markers_after_hashchange = true;
|
|
1054
|
+
else push_pending_markers(gobj);
|
|
1055
|
+
p.last_hash = window.location.hash;
|
|
1038
1056
|
return;
|
|
1039
1057
|
}
|
|
1040
1058
|
on_traversal(ev);
|
|
1059
|
+
if (!p.skip_hash) p.last_hash = window.location.hash;
|
|
1041
1060
|
};
|
|
1042
1061
|
let on_traversal = (ev) => {
|
|
1043
1062
|
let p = gobj.priv;
|
|
1044
1063
|
if (p.expected_pops > 0) {
|
|
1045
1064
|
p.expected_pops--;
|
|
1046
|
-
if (p.expected_pops === 0)
|
|
1065
|
+
if (p.expected_pops === 0) {
|
|
1066
|
+
if (p.restore_hash && p.restore_hash !== window.location.hash) try {
|
|
1067
|
+
window.history.replaceState(window.history.state, "", p.restore_hash);
|
|
1068
|
+
p.skip_hash = p.restore_hash;
|
|
1069
|
+
p.last_hash = p.restore_hash;
|
|
1070
|
+
} catch (e) {
|
|
1071
|
+
log_warning(`C_YUI_SHELL: restoring '${p.restore_hash}' failed: ${e}`);
|
|
1072
|
+
}
|
|
1073
|
+
p.restore_hash = "";
|
|
1074
|
+
push_pending_markers(gobj);
|
|
1075
|
+
}
|
|
1047
1076
|
return;
|
|
1048
1077
|
}
|
|
1049
1078
|
if (p.overlay_stack.length === 0) return;
|
|
1050
1079
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
1051
|
-
if (top.marker_pending) return;
|
|
1052
|
-
if (window.location.hash !== top.hash) return;
|
|
1080
|
+
if (top.marker_pending || top.no_marker) return;
|
|
1081
|
+
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1053
1082
|
let st = ev && ev.state;
|
|
1054
1083
|
if (st && st.__yui_overlay__ === top.id) return;
|
|
1084
|
+
if (st && st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
|
|
1055
1085
|
p.overlay_stack.pop();
|
|
1056
1086
|
try {
|
|
1057
1087
|
top.close();
|
|
@@ -1093,9 +1123,16 @@ function mt_stop$20(gobj) {
|
|
|
1093
1123
|
window.removeEventListener("popstate", priv.popstate_handler);
|
|
1094
1124
|
priv.popstate_handler = null;
|
|
1095
1125
|
}
|
|
1126
|
+
for (let entry of priv.pending_markers) {
|
|
1127
|
+
entry.marker_pending = false;
|
|
1128
|
+
entry.no_marker = true;
|
|
1129
|
+
}
|
|
1096
1130
|
priv.expected_pops = 0;
|
|
1097
1131
|
priv.expected_pop_hash = "";
|
|
1098
1132
|
priv.pending_markers = [];
|
|
1133
|
+
priv.markers_after_hashchange = false;
|
|
1134
|
+
priv.restore_hash = "";
|
|
1135
|
+
priv.skip_hash = "";
|
|
1099
1136
|
if (priv.keydown_handler) {
|
|
1100
1137
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1101
1138
|
priv.keydown_handler = null;
|
|
@@ -1701,6 +1738,7 @@ function navigate_to(gobj, route, depth, no_drain) {
|
|
|
1701
1738
|
let target_hash = route_to_hash(route);
|
|
1702
1739
|
if (window.location.hash !== target_hash) try {
|
|
1703
1740
|
window.history.replaceState(window.history.state, "", target_hash);
|
|
1741
|
+
priv.last_hash = target_hash;
|
|
1704
1742
|
retag_overlay_hash(gobj, window.history.state, target_hash);
|
|
1705
1743
|
} catch (e) {
|
|
1706
1744
|
window.location.hash = target_hash;
|
|
@@ -2538,11 +2576,12 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2538
2576
|
let idx = priv.overlay_stack.indexOf(entry);
|
|
2539
2577
|
if (idx < 0) return;
|
|
2540
2578
|
priv.overlay_stack.splice(idx, 1);
|
|
2541
|
-
if (entry.marker_pending) return;
|
|
2579
|
+
if (entry.marker_pending || entry.no_marker) return;
|
|
2542
2580
|
let st = window.history.state;
|
|
2543
2581
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2544
2582
|
priv.expected_pops++;
|
|
2545
2583
|
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2584
|
+
priv.restore_hash = window.location.hash !== priv.expected_pop_hash ? window.location.hash : "";
|
|
2546
2585
|
try {
|
|
2547
2586
|
window.history.back();
|
|
2548
2587
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -92,10 +92,19 @@ function starts_with_markup(s)
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/* String methods that keep the head of their receiver (a markup head
|
|
95
|
-
* stays a markup head through them).
|
|
95
|
+
* stays a markup head through them). Not replace()/replaceAll(): they
|
|
96
|
+
* can take the head away ('<b>x</b>'.replace(/<[^>]+>/g, '') is text),
|
|
97
|
+
* so what they give back is not known. */
|
|
96
98
|
const HEAD_KEEPING_METHODS = new Set([
|
|
97
99
|
"trim", "trimStart", "trimEnd", "toString", "valueOf", "normalize",
|
|
98
|
-
"toLowerCase", "toUpperCase", "
|
|
100
|
+
"toLowerCase", "toUpperCase", "padEnd", "concat"
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
/* The ones with no argument that give a static value from a static
|
|
104
|
+
* receiver: '<b>s</b>'.toUpperCase() is a literal, not built markup. */
|
|
105
|
+
const PURE_METHODS = new Set([
|
|
106
|
+
"trim", "trimStart", "trimEnd", "toString", "valueOf", "normalize",
|
|
107
|
+
"toLowerCase", "toUpperCase"
|
|
99
108
|
]);
|
|
100
109
|
|
|
101
110
|
function concat_parts(parts)
|
|
@@ -190,6 +199,9 @@ function leading(n)
|
|
|
190
199
|
if(method === "concat") {
|
|
191
200
|
return concat_parts([head, ...n.arguments.map(leading)]);
|
|
192
201
|
}
|
|
202
|
+
if(head.complete && PURE_METHODS.has(method) && n.arguments.length === 0) {
|
|
203
|
+
return {text: String.prototype[method].call(head.text), complete: true};
|
|
204
|
+
}
|
|
193
205
|
/* The head is kept; the whole is no longer known to be static. */
|
|
194
206
|
return {text: head.text, complete: false};
|
|
195
207
|
}
|
package/src/c_yui_shell.js
CHANGED
|
@@ -164,6 +164,18 @@ let PRIVATE_DATA = {
|
|
|
164
164
|
/* Overlays registered while one of those history.back() calls is
|
|
165
165
|
* still in flight: their marker is pushed once it has landed. */
|
|
166
166
|
pending_markers: [],
|
|
167
|
+
/* The hash the shell last saw, to tell a traversal that moved it
|
|
168
|
+
* (a hashchange is queued behind its popstate) from one that did
|
|
169
|
+
* not. */
|
|
170
|
+
last_hash: "",
|
|
171
|
+
/* The waiting markers are pushed by the queued hashchange, after
|
|
172
|
+
* its navigation, not by the popstate that dropped our back(). */
|
|
173
|
+
markers_after_hashchange: false,
|
|
174
|
+
/* A position (hash) to put back when our back() lands under a
|
|
175
|
+
* marker a replace navigation had moved, and the hashchange of
|
|
176
|
+
* that landing, which must not navigate. */
|
|
177
|
+
restore_hash: "",
|
|
178
|
+
skip_hash: "",
|
|
167
179
|
popstate_handler: null,
|
|
168
180
|
/* Avatar item support — every toolbar item with type:"avatar"
|
|
169
181
|
* registers its <span> here so refresh_avatars() can repaint
|
|
@@ -265,19 +277,37 @@ function mt_start(gobj)
|
|
|
265
277
|
preinstantiate_eager_views(gobj);
|
|
266
278
|
|
|
267
279
|
if(gobj_read_attr(gobj, "use_hash")) {
|
|
280
|
+
priv.last_hash = window.location.hash;
|
|
268
281
|
priv.hash_handler = () => {
|
|
269
282
|
let p = gobj.priv;
|
|
270
|
-
|
|
271
|
-
|
|
283
|
+
if(!p) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let markers_now = p.markers_after_hashchange;
|
|
287
|
+
p.markers_after_hashchange = false;
|
|
288
|
+
if(p.skip_hash && window.location.hash === p.skip_hash) {
|
|
289
|
+
/* The hashchange of an expected landing whose position
|
|
290
|
+
* was put back (see on_traversal): the route did not
|
|
291
|
+
* change, there is nothing to navigate to. */
|
|
292
|
+
p.skip_hash = "";
|
|
293
|
+
p.last_hash = window.location.hash;
|
|
294
|
+
if(markers_now) {
|
|
295
|
+
push_pending_markers(gobj);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
p.skip_hash = "";
|
|
300
|
+
if(p.expected_pops > 0 &&
|
|
272
301
|
window.location.hash !== p.expected_pop_hash) {
|
|
273
302
|
drop_expected_pops(gobj); // a back() of ours never landed
|
|
274
|
-
|
|
303
|
+
markers_now = true;
|
|
275
304
|
}
|
|
276
305
|
let route = hash_to_route(window.location.hash);
|
|
277
306
|
if(!empty_string(route)) {
|
|
278
307
|
navigate_to(gobj, route);
|
|
279
308
|
}
|
|
280
|
-
|
|
309
|
+
p.last_hash = window.location.hash;
|
|
310
|
+
if(markers_now) {
|
|
281
311
|
/* After the navigation: an overlay it drained gets no
|
|
282
312
|
* marker, a kept one gets it on the hash it now lives on. */
|
|
283
313
|
push_pending_markers(gobj);
|
|
@@ -295,6 +325,10 @@ function mt_start(gobj)
|
|
|
295
325
|
if(!p) {
|
|
296
326
|
return;
|
|
297
327
|
}
|
|
328
|
+
/* A traversal that moved the hash is followed by a
|
|
329
|
+
* hashchange, QUEUED: it runs after this handler, and it is
|
|
330
|
+
* the one that navigates (and drains). */
|
|
331
|
+
let hash_moved = window.location.hash !== p.last_hash;
|
|
298
332
|
if(p.expected_pops > 0 &&
|
|
299
333
|
window.location.hash !== p.expected_pop_hash) {
|
|
300
334
|
/* Not the landing of ours: it was dropped. Whatever
|
|
@@ -302,13 +336,24 @@ function mt_start(gobj)
|
|
|
302
336
|
* the overlays that waited get their markers AFTER it:
|
|
303
337
|
* pushed first, the waiting top had a marker the
|
|
304
338
|
* traversal then took as "stepped off" -- it was closed
|
|
305
|
-
* and its marker left orphaned.
|
|
339
|
+
* and its marker left orphaned. When the hash moved,
|
|
340
|
+
* "after it" is after the hashchange's navigation: a
|
|
341
|
+
* marker pushed here for an overlay that navigation then
|
|
342
|
+
* drains is left orphaned too. */
|
|
306
343
|
drop_expected_pops(gobj);
|
|
307
344
|
on_traversal(ev);
|
|
308
|
-
|
|
345
|
+
if(hash_moved) {
|
|
346
|
+
p.markers_after_hashchange = true;
|
|
347
|
+
} else {
|
|
348
|
+
push_pending_markers(gobj);
|
|
349
|
+
}
|
|
350
|
+
p.last_hash = window.location.hash;
|
|
309
351
|
return;
|
|
310
352
|
}
|
|
311
353
|
on_traversal(ev);
|
|
354
|
+
if(!p.skip_hash) {
|
|
355
|
+
p.last_hash = window.location.hash;
|
|
356
|
+
}
|
|
312
357
|
};
|
|
313
358
|
let on_traversal = (ev) => {
|
|
314
359
|
let p = gobj.priv;
|
|
@@ -317,6 +362,21 @@ function mt_start(gobj)
|
|
|
317
362
|
* overlay — the teardown already happened. */
|
|
318
363
|
p.expected_pops--;
|
|
319
364
|
if(p.expected_pops === 0) {
|
|
365
|
+
if(p.restore_hash && p.restore_hash !== window.location.hash) {
|
|
366
|
+
/* The marker had moved to another hash (a replace
|
|
367
|
+
* navigation wrote the view's position on it) and
|
|
368
|
+
* the back() landed on the entry under it, on the
|
|
369
|
+
* old one: put the position back, and let its
|
|
370
|
+
* hashchange pass -- re-navigating would lose it. */
|
|
371
|
+
try {
|
|
372
|
+
window.history.replaceState(window.history.state, "", p.restore_hash);
|
|
373
|
+
p.skip_hash = p.restore_hash;
|
|
374
|
+
p.last_hash = p.restore_hash;
|
|
375
|
+
} catch(e) {
|
|
376
|
+
log_warning(`C_YUI_SHELL: restoring '${p.restore_hash}' failed: ${e}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
p.restore_hash = "";
|
|
320
380
|
push_pending_markers(gobj);
|
|
321
381
|
}
|
|
322
382
|
return;
|
|
@@ -325,8 +385,8 @@ function mt_start(gobj)
|
|
|
325
385
|
return;
|
|
326
386
|
}
|
|
327
387
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
328
|
-
if(top.marker_pending) {
|
|
329
|
-
/* It has no marker yet: no traversal can step off it. */
|
|
388
|
+
if(top.marker_pending || top.no_marker) {
|
|
389
|
+
/* It has no marker (yet): no traversal can step off it. */
|
|
330
390
|
return;
|
|
331
391
|
}
|
|
332
392
|
/* Did this traversal step OFF the top overlay's marker?
|
|
@@ -346,7 +406,13 @@ function mt_start(gobj)
|
|
|
346
406
|
* a `stay` modal's marker legitimately lives on a hash that
|
|
347
407
|
* is NOT the resting one, and matching on the resting route
|
|
348
408
|
* left Back unable to close it. */
|
|
349
|
-
if(window.location.hash !== top.hash
|
|
409
|
+
if(window.location.hash !== top.hash &&
|
|
410
|
+
window.location.hash !== top.below_hash) {
|
|
411
|
+
/* Neither the marker's own hash nor the hash of the
|
|
412
|
+
* entry under it: a route traversal. (Under it: a
|
|
413
|
+
* replace navigation moved the marker's hash after it
|
|
414
|
+
* was pushed, and stepping off it lands on the entry
|
|
415
|
+
* below, on the hash it had.) */
|
|
350
416
|
return;
|
|
351
417
|
}
|
|
352
418
|
/* Which entry did it land ON? Markers ({__yui_overlay__:
|
|
@@ -363,6 +429,13 @@ function mt_start(gobj)
|
|
|
363
429
|
if(st && st.__yui_overlay__ === top.id) {
|
|
364
430
|
return;
|
|
365
431
|
}
|
|
432
|
+
if(st && st.__yui_overlay__ > top.id &&
|
|
433
|
+
!p.overlay_stack.some(e => e.id === st.__yui_overlay__)) {
|
|
434
|
+
/* A dead marker NEWER than the top: only Forward reaches
|
|
435
|
+
* it (an overlay closed by its button above this one).
|
|
436
|
+
* It is not a step off the top's marker. */
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
366
439
|
p.overlay_stack.pop();
|
|
367
440
|
try {
|
|
368
441
|
top.close();
|
|
@@ -436,10 +509,19 @@ function mt_stop(gobj)
|
|
|
436
509
|
window.removeEventListener("popstate", priv.popstate_handler);
|
|
437
510
|
priv.popstate_handler = null;
|
|
438
511
|
}
|
|
439
|
-
/* Nothing listens for the landings any more.
|
|
512
|
+
/* Nothing listens for the landings any more. An overlay that
|
|
513
|
+
* waited for one gets no marker: it says so, so neither a later
|
|
514
|
+
* dismissal retires one nor a traversal waits for it. */
|
|
515
|
+
for(let entry of priv.pending_markers) {
|
|
516
|
+
entry.marker_pending = false;
|
|
517
|
+
entry.no_marker = true;
|
|
518
|
+
}
|
|
440
519
|
priv.expected_pops = 0;
|
|
441
520
|
priv.expected_pop_hash = "";
|
|
442
521
|
priv.pending_markers = [];
|
|
522
|
+
priv.markers_after_hashchange = false;
|
|
523
|
+
priv.restore_hash = "";
|
|
524
|
+
priv.skip_hash = "";
|
|
443
525
|
if(priv.keydown_handler) {
|
|
444
526
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
445
527
|
priv.keydown_handler = null;
|
|
@@ -1553,6 +1635,7 @@ function navigate_to(gobj, route, depth, no_drain)
|
|
|
1553
1635
|
* its Back/dismiss bookkeeping. */
|
|
1554
1636
|
try {
|
|
1555
1637
|
window.history.replaceState(window.history.state, "", target_hash);
|
|
1638
|
+
priv.last_hash = target_hash;
|
|
1556
1639
|
/* This rewrote the hash of the CURRENT entry. When that
|
|
1557
1640
|
* entry is a live marker (a replace-navigation issued
|
|
1558
1641
|
* with an overlay open), its recorded hash just went
|
|
@@ -2748,7 +2831,7 @@ function overlay_dismissed(gobj, entry)
|
|
|
2748
2831
|
return;
|
|
2749
2832
|
}
|
|
2750
2833
|
priv.overlay_stack.splice(idx, 1);
|
|
2751
|
-
if(entry.marker_pending) {
|
|
2834
|
+
if(entry.marker_pending || entry.no_marker) {
|
|
2752
2835
|
/* Its marker was never pushed: there is nothing to retire. */
|
|
2753
2836
|
return;
|
|
2754
2837
|
}
|
|
@@ -2768,6 +2851,10 @@ function overlay_dismissed(gobj, entry)
|
|
|
2768
2851
|
priv.expected_pops++;
|
|
2769
2852
|
priv.expected_pop_hash = (typeof entry.below_hash === "string")?
|
|
2770
2853
|
entry.below_hash : window.location.hash;
|
|
2854
|
+
/* A position written on the marker by a replace navigation is
|
|
2855
|
+
* put back once the back() lands under it (on_traversal). */
|
|
2856
|
+
priv.restore_hash = (window.location.hash !== priv.expected_pop_hash)?
|
|
2857
|
+
window.location.hash : "";
|
|
2771
2858
|
try {
|
|
2772
2859
|
window.history.back();
|
|
2773
2860
|
} catch(e) {
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
* Copyright (c) 2026, ArtGins.
|
|
20
20
|
* All Rights Reserved.
|
|
21
21
|
***********************************************************************/
|
|
22
|
-
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
22
|
+
import {describe, test, expect, beforeAll, beforeEach, afterEach} from "vitest";
|
|
23
23
|
import {install_dom_double} from "../test/dom_double.js";
|
|
24
24
|
|
|
25
25
|
install_dom_double();
|
|
26
26
|
|
|
27
27
|
const {
|
|
28
|
-
SDATA_END, gclass_create,
|
|
28
|
+
SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
|
|
29
29
|
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
30
|
-
gobj_start, gobj_read_attr, gobj_is_destroying,
|
|
30
|
+
gobj_start, gobj_stop, gobj_is_running, gobj_read_attr, gobj_is_destroying,
|
|
31
31
|
set_log_callback,
|
|
32
32
|
} = await import("@yuneta/gobj-js");
|
|
33
33
|
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
@@ -37,6 +37,7 @@ const logged = [];
|
|
|
37
37
|
let veto = true;
|
|
38
38
|
let warning = null;
|
|
39
39
|
let yuno = null;
|
|
40
|
+
const shells = [];
|
|
40
41
|
|
|
41
42
|
/* The session history of one tab. Each entry carries its hash, as a
|
|
42
43
|
* browser's does: a traversal lands on the entry's hash, and fires a
|
|
@@ -97,17 +98,39 @@ function fire_popstate()
|
|
|
97
98
|
window.dispatchEvent(ev);
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/* As a browser does: popstate is fired during the traversal, and a
|
|
102
|
+
* hashchange -- when the fragment moved -- is QUEUED as a task of its own,
|
|
103
|
+
* so it runs after popstate and after whatever popstate's handlers did. */
|
|
104
|
+
function queue_hashchange()
|
|
105
|
+
{
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
window.dispatchEvent(new Event("hashchange"));
|
|
108
|
+
}, 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
function traverse_to(index)
|
|
101
112
|
{
|
|
102
113
|
const left = window.location.hash;
|
|
103
114
|
session.index = index;
|
|
104
115
|
window.location.hash = session.entries[index].hash;
|
|
105
116
|
fire_popstate();
|
|
106
|
-
if(
|
|
107
|
-
|
|
117
|
+
if(session.entries[index].hash !== left) {
|
|
118
|
+
queue_hashchange();
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
121
|
|
|
122
|
+
/* A click on a fragment link: a new entry, then popstate, then the
|
|
123
|
+
* queued hashchange -- what Chromium and Firefox do. */
|
|
124
|
+
function link_to(hash)
|
|
125
|
+
{
|
|
126
|
+
session.entries.splice(session.index + 1);
|
|
127
|
+
session.entries.push({state: null, hash: hash});
|
|
128
|
+
session.index++;
|
|
129
|
+
window.location.hash = hash;
|
|
130
|
+
fire_popstate();
|
|
131
|
+
queue_hashchange();
|
|
132
|
+
}
|
|
133
|
+
|
|
111
134
|
/* The user's Back: the browser's own traversal. */
|
|
112
135
|
function user_back()
|
|
113
136
|
{
|
|
@@ -141,6 +164,18 @@ beforeAll(async () => {
|
|
|
141
164
|
]]],
|
|
142
165
|
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
143
166
|
);
|
|
167
|
+
gclass_create(
|
|
168
|
+
"C_TEST_MARKER_VIEW", [], [["ST_IDLE", []]], {
|
|
169
|
+
mt_create: (gobj) => {
|
|
170
|
+
gobj_write_attr(gobj, "$container",
|
|
171
|
+
document.createElement("div"));
|
|
172
|
+
}
|
|
173
|
+
}, 0, [
|
|
174
|
+
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "view root"),
|
|
175
|
+
SDATA(data_type_t.DTP_POINTER, "subscriber", 0, null, "subscriber"),
|
|
176
|
+
SDATA_END()
|
|
177
|
+
], {}, 0, 0, 0, 0
|
|
178
|
+
);
|
|
144
179
|
register_c_yui_shell();
|
|
145
180
|
register_c_yui_window();
|
|
146
181
|
yuno = gobj_create_yuno("marker_yuno", "C_TEST_MARKER_HOST", {});
|
|
@@ -154,6 +189,50 @@ beforeEach(() => {
|
|
|
154
189
|
install_history_model();
|
|
155
190
|
});
|
|
156
191
|
|
|
192
|
+
|
|
193
|
+
/* A shell WITH a route table, so a change of resting route drains the
|
|
194
|
+
* overlays (navigate_to() -> drain_overlays()), as in an app. */
|
|
195
|
+
function routed_config()
|
|
196
|
+
{
|
|
197
|
+
const target = (route) => ({stage: "main", gclass: "C_TEST_MARKER_VIEW", kw: {}});
|
|
198
|
+
return {
|
|
199
|
+
shell: {
|
|
200
|
+
zones: {center: {host: "stage.main"}},
|
|
201
|
+
stages: {main: {zone: "center", default_route: "/home"}}
|
|
202
|
+
},
|
|
203
|
+
menu: {
|
|
204
|
+
primary: {
|
|
205
|
+
items: [
|
|
206
|
+
{id: "home", route: "/home", target: target("/home")},
|
|
207
|
+
{id: "prev", route: "/prev", target: target("/prev")},
|
|
208
|
+
{id: "other", route: "/other", target: target("/other")}
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function routed_shell(name, app)
|
|
216
|
+
{
|
|
217
|
+
const shell = gobj_create(name, "C_YUI_SHELL",
|
|
218
|
+
{config: routed_config(), subscriber: app}, app);
|
|
219
|
+
gobj_start(shell);
|
|
220
|
+
shells.push(shell);
|
|
221
|
+
return shell;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* A test leaves no shell listening and no queued hashchange behind: the
|
|
225
|
+
* next test's shell would otherwise hear the previous test's traversal. */
|
|
226
|
+
afterEach(async () => {
|
|
227
|
+
await next_task();
|
|
228
|
+
await next_task();
|
|
229
|
+
for(const sh of shells.splice(0)) {
|
|
230
|
+
if(gobj_is_running(sh)) {
|
|
231
|
+
gobj_stop(sh);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
157
236
|
function errors()
|
|
158
237
|
{
|
|
159
238
|
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
@@ -166,6 +245,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
166
245
|
const shell = gobj_create("mshell", "C_YUI_SHELL",
|
|
167
246
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
168
247
|
gobj_start(shell);
|
|
248
|
+
shells.push(shell);
|
|
169
249
|
logged.length = 0; /* the shell's own start: no route table here */
|
|
170
250
|
install_history_model();
|
|
171
251
|
|
|
@@ -213,6 +293,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
213
293
|
const shell = gobj_create("mshell2", "C_YUI_SHELL",
|
|
214
294
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
215
295
|
gobj_start(shell);
|
|
296
|
+
shells.push(shell);
|
|
216
297
|
logged.length = 0;
|
|
217
298
|
install_history_model();
|
|
218
299
|
|
|
@@ -241,6 +322,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
241
322
|
const shell = gobj_create("mshell3", "C_YUI_SHELL",
|
|
242
323
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
243
324
|
gobj_start(shell);
|
|
325
|
+
shells.push(shell);
|
|
244
326
|
logged.length = 0;
|
|
245
327
|
install_history_model();
|
|
246
328
|
|
|
@@ -266,6 +348,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
266
348
|
const shell = gobj_create("mshell4", "C_YUI_SHELL",
|
|
267
349
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
268
350
|
gobj_start(shell);
|
|
351
|
+
shells.push(shell);
|
|
269
352
|
logged.length = 0;
|
|
270
353
|
install_history_model();
|
|
271
354
|
window.location.hash = "#/home";
|
|
@@ -281,10 +364,10 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
281
364
|
{keep_on_navigate: true});
|
|
282
365
|
expect(second.marker_pending).toBe(true);
|
|
283
366
|
|
|
284
|
-
/* A
|
|
285
|
-
* back() will never land. */
|
|
286
|
-
|
|
287
|
-
|
|
367
|
+
/* A click on a link: a new entry, popstate, then the queued
|
|
368
|
+
* hashchange. Our back() will never land. */
|
|
369
|
+
link_to("#/other");
|
|
370
|
+
await next_task();
|
|
288
371
|
expect(shell.priv.expected_pops).toBe(0);
|
|
289
372
|
expect(second.marker_pending).toBe(false);
|
|
290
373
|
expect(window.history.state).toEqual({__yui_overlay__: second.id});
|
|
@@ -302,6 +385,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
302
385
|
const shell = gobj_create("mshell5", "C_YUI_SHELL",
|
|
303
386
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
304
387
|
gobj_start(shell);
|
|
388
|
+
shells.push(shell);
|
|
305
389
|
install_history_model();
|
|
306
390
|
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
307
391
|
await import("./c_yui_shell.js");
|
|
@@ -321,6 +405,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
321
405
|
const shell = gobj_create("mshell6", "C_YUI_SHELL",
|
|
322
406
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
323
407
|
gobj_start(shell);
|
|
408
|
+
shells.push(shell);
|
|
324
409
|
window.location.hash = "#/prev";
|
|
325
410
|
install_history_model();
|
|
326
411
|
window.history.pushState(null, "", "#/home"); // a route entry
|
|
@@ -340,6 +425,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
340
425
|
* history.go(-2)): from the dead marker straight to #/prev, a hash
|
|
341
426
|
* that is not the landing ours expected. */
|
|
342
427
|
traverse_to(0);
|
|
428
|
+
await next_task(); // the queued hashchange
|
|
343
429
|
expect(window.location.hash).toBe("#/prev");
|
|
344
430
|
expect(closed).toBe(0);
|
|
345
431
|
expect(shell.priv.overlay_stack).toEqual([second]);
|
|
@@ -359,6 +445,7 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
359
445
|
const shell = gobj_create("mshell7", "C_YUI_SHELL",
|
|
360
446
|
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
361
447
|
gobj_start(shell);
|
|
448
|
+
shells.push(shell);
|
|
362
449
|
window.location.hash = "#/home";
|
|
363
450
|
install_history_model();
|
|
364
451
|
|
|
@@ -374,8 +461,121 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
374
461
|
await next_task();
|
|
375
462
|
await next_task();
|
|
376
463
|
expect(shell.priv.expected_pops).toBe(0);
|
|
377
|
-
|
|
378
|
-
expect(
|
|
464
|
+
/* Since 7.26.13 the position written with replace is put back. */
|
|
465
|
+
expect(window.location.hash).toBe("#/home/pos");
|
|
466
|
+
expect(logged.filter((l) => l.msg.includes("did not land")).map(l => l.msg)).toEqual([]);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe("a routed shell, a realistic history (V5)", () => {
|
|
471
|
+
test("Back closes a keep_on_navigate panel after a replace navigation", async () => {
|
|
472
|
+
const app = gobj_create("vapp1", "C_TEST_MARKER_APP", {}, yuno);
|
|
473
|
+
gobj_start(app);
|
|
474
|
+
window.location.hash = "#/home";
|
|
475
|
+
install_history_model();
|
|
476
|
+
const shell = routed_shell("vshell1", app);
|
|
477
|
+
const {yui_shell_register_overlay, yui_shell_navigate} = await import("./c_yui_shell.js");
|
|
478
|
+
let closed = 0;
|
|
479
|
+
yui_shell_register_overlay(shell, () => { closed++; }, {keep_on_navigate: true});
|
|
480
|
+
|
|
481
|
+
/* The view under the panel writes its position with replace. */
|
|
482
|
+
yui_shell_navigate(shell, "/home/pos", {replace: true});
|
|
483
|
+
expect(window.location.hash).toBe("#/home/pos");
|
|
484
|
+
|
|
485
|
+
user_back();
|
|
486
|
+
await next_task();
|
|
487
|
+
expect(closed).toBe(1);
|
|
488
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test("a button close after a replace navigation keeps the position", async () => {
|
|
492
|
+
const app = gobj_create("vapp2", "C_TEST_MARKER_APP", {}, yuno);
|
|
493
|
+
gobj_start(app);
|
|
494
|
+
window.location.hash = "#/home";
|
|
495
|
+
install_history_model();
|
|
496
|
+
const shell = routed_shell("vshell2", app);
|
|
497
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
498
|
+
await import("./c_yui_shell.js");
|
|
499
|
+
const entry = yui_shell_register_overlay(shell, () => {}, {keep_on_navigate: true});
|
|
500
|
+
yui_shell_navigate(shell, "/home/pos", {replace: true});
|
|
501
|
+
logged.length = 0;
|
|
502
|
+
|
|
503
|
+
yui_shell_overlay_dismissed(shell, entry); // the close button
|
|
504
|
+
await next_task();
|
|
505
|
+
await next_task();
|
|
506
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
507
|
+
expect(window.location.hash).toBe("#/home/pos");
|
|
508
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/home/pos");
|
|
509
|
+
expect(window.history.state).toBe(null);
|
|
510
|
+
expect(errors()).toEqual([]);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test("a dropped back() and a real link: a drained overlay leaves no orphan marker", async () => {
|
|
514
|
+
const app = gobj_create("vapp3", "C_TEST_MARKER_APP", {}, yuno);
|
|
515
|
+
gobj_start(app);
|
|
516
|
+
window.location.hash = "#/home";
|
|
517
|
+
install_history_model();
|
|
518
|
+
const shell = routed_shell("vshell3", app);
|
|
519
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} = await import("./c_yui_shell.js");
|
|
520
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
521
|
+
window.history.back = () => {}; // the browser drops it
|
|
522
|
+
yui_shell_overlay_dismissed(shell, first);
|
|
523
|
+
let closed = 0;
|
|
524
|
+
const second = yui_shell_register_overlay(shell, () => { closed++; }); // drained by a navigation
|
|
525
|
+
expect(second.marker_pending).toBe(true);
|
|
526
|
+
|
|
527
|
+
link_to("#/other"); // popstate, then the queued hashchange
|
|
528
|
+
await next_task();
|
|
529
|
+
await next_task();
|
|
530
|
+
expect(closed).toBe(1);
|
|
531
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
532
|
+
expect(window.history.state).toBe(null); // no marker of the drained overlay
|
|
533
|
+
expect(session.entries.length).toBe(3); // #/home, the dead first marker, #/other
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
test("Forward onto a dead marker does not close the overlay under it", async () => {
|
|
537
|
+
const app = gobj_create("vapp4", "C_TEST_MARKER_APP", {}, yuno);
|
|
538
|
+
gobj_start(app);
|
|
539
|
+
window.location.hash = "#/home";
|
|
540
|
+
install_history_model();
|
|
541
|
+
const shell = routed_shell("vshell4", app);
|
|
542
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} = await import("./c_yui_shell.js");
|
|
543
|
+
let closed_a = 0;
|
|
544
|
+
const a = yui_shell_register_overlay(shell, () => { closed_a++; });
|
|
545
|
+
const b = yui_shell_register_overlay(shell, () => {});
|
|
546
|
+
yui_shell_overlay_dismissed(shell, b); // its button: back() to A's marker
|
|
547
|
+
await next_task();
|
|
548
|
+
expect(window.history.state).toEqual({__yui_overlay__: a.id});
|
|
549
|
+
|
|
550
|
+
traverse_to(session.index + 1); // Forward, onto B's dead marker
|
|
551
|
+
expect(closed_a).toBe(0);
|
|
552
|
+
expect(shell.priv.overlay_stack).toEqual([a]);
|
|
553
|
+
|
|
554
|
+
user_back(); // back on A's own marker: absorbed
|
|
555
|
+
expect(closed_a).toBe(0);
|
|
556
|
+
user_back(); // off it: closes A
|
|
557
|
+
expect(closed_a).toBe(1);
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test("mt_stop leaves no overlay waiting for a marker that will never come", async () => {
|
|
561
|
+
const app = gobj_create("vapp5", "C_TEST_MARKER_APP", {}, yuno);
|
|
562
|
+
gobj_start(app);
|
|
563
|
+
window.location.hash = "#/home";
|
|
564
|
+
install_history_model();
|
|
565
|
+
const shell = routed_shell("vshell5", app);
|
|
566
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} = await import("./c_yui_shell.js");
|
|
567
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
568
|
+
let backs = 0;
|
|
569
|
+
window.history.back = () => { backs++; };
|
|
570
|
+
yui_shell_overlay_dismissed(shell, first);
|
|
571
|
+
expect(backs).toBe(1);
|
|
572
|
+
const second = yui_shell_register_overlay(shell, () => {});
|
|
573
|
+
expect(second.marker_pending).toBe(true);
|
|
574
|
+
|
|
575
|
+
gobj_stop(shell);
|
|
576
|
+
expect(second.marker_pending).toBe(false);
|
|
577
|
+
yui_shell_overlay_dismissed(shell, second); // it has no marker: nothing to retire
|
|
578
|
+
expect(backs).toBe(1);
|
|
379
579
|
});
|
|
380
580
|
});
|
|
381
581
|
|