@yuneta/gobj-ui 7.26.14 → 7.26.15
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 +45 -3
- package/dist/gobj-ui.es.js +45 -3
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +41 -1
- package/src/c_yui_shell.js +100 -6
- package/src/data_as_text.wiring.test.js +27 -5
- package/src/overlay_marker_after_back.wiring.test.js +190 -2
- package/src/window_veto_back.wiring.test.js +6 -2
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -979,6 +979,7 @@ var PRIVATE_DATA$22 = {
|
|
|
979
979
|
restore_hash: "",
|
|
980
980
|
skip_hash: "",
|
|
981
981
|
deferred_route: "",
|
|
982
|
+
deferred_timer: null,
|
|
982
983
|
popstate_handler: null,
|
|
983
984
|
avatar_provider: null,
|
|
984
985
|
avatar_nodes: [],
|
|
@@ -1086,8 +1087,9 @@ function mt_start$20(gobj) {
|
|
|
1086
1087
|
if (top.marker_pending || top.no_marker) return;
|
|
1087
1088
|
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1088
1089
|
let st = ev && ev.state;
|
|
1089
|
-
if (st
|
|
1090
|
-
if (st
|
|
1090
|
+
if (!st) return;
|
|
1091
|
+
if (st.__yui_overlay__ === top.id) return;
|
|
1092
|
+
if (st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
|
|
1091
1093
|
p.overlay_stack.pop();
|
|
1092
1094
|
try {
|
|
1093
1095
|
top.close();
|
|
@@ -1147,6 +1149,7 @@ 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);
|
|
1150
1153
|
if (priv.keydown_handler) {
|
|
1151
1154
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1152
1155
|
priv.keydown_handler = null;
|
|
@@ -2556,6 +2559,11 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2556
2559
|
function push_overlay_marker(gobj, entry) {
|
|
2557
2560
|
let priv = gobj.priv;
|
|
2558
2561
|
entry.below_hash = window.location.hash;
|
|
2562
|
+
if (window.history.state === null) try {
|
|
2563
|
+
window.history.replaceState({ __yui_below__: entry.id }, "");
|
|
2564
|
+
} catch (e) {
|
|
2565
|
+
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2566
|
+
}
|
|
2559
2567
|
try {
|
|
2560
2568
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2561
2569
|
} catch (e) {
|
|
@@ -2572,6 +2580,35 @@ function drop_expected_pops(gobj) {
|
|
|
2572
2580
|
(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
2581
|
priv.expected_pops = 0;
|
|
2574
2582
|
priv.expected_pop_hash = "";
|
|
2583
|
+
clear_deferred_timer(gobj);
|
|
2584
|
+
if (priv.deferred_route) {
|
|
2585
|
+
(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}'`);
|
|
2586
|
+
priv.deferred_route = "";
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2590
|
+
function defer_route(gobj, route) {
|
|
2591
|
+
let priv = gobj.priv;
|
|
2592
|
+
if (priv.deferred_route && priv.deferred_route !== route) (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() of ours is replaced by '${route}'`);
|
|
2593
|
+
priv.deferred_route = route;
|
|
2594
|
+
if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
|
|
2595
|
+
let p = gobj.priv;
|
|
2596
|
+
if (!p) return;
|
|
2597
|
+
p.deferred_timer = null;
|
|
2598
|
+
if (p.expected_pops === 0) return;
|
|
2599
|
+
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
|
|
2600
|
+
p.expected_pops = 0;
|
|
2601
|
+
p.expected_pop_hash = "";
|
|
2602
|
+
p.restore_hash = "";
|
|
2603
|
+
push_pending_markers(gobj);
|
|
2604
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
2605
|
+
}
|
|
2606
|
+
function clear_deferred_timer(gobj) {
|
|
2607
|
+
let priv = gobj.priv;
|
|
2608
|
+
if (priv.deferred_timer) {
|
|
2609
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2610
|
+
priv.deferred_timer = null;
|
|
2611
|
+
}
|
|
2575
2612
|
}
|
|
2576
2613
|
function push_pending_markers(gobj) {
|
|
2577
2614
|
let priv = gobj.priv;
|
|
@@ -2582,6 +2619,7 @@ function push_pending_markers(gobj) {
|
|
|
2582
2619
|
entry.hash = window.location.hash;
|
|
2583
2620
|
push_overlay_marker(gobj, entry);
|
|
2584
2621
|
}
|
|
2622
|
+
clear_deferred_timer(gobj);
|
|
2585
2623
|
if (priv.deferred_route) {
|
|
2586
2624
|
let route = priv.deferred_route;
|
|
2587
2625
|
priv.deferred_route = "";
|
|
@@ -2710,6 +2748,10 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2710
2748
|
}
|
|
2711
2749
|
route = remembered_position(gobj, route);
|
|
2712
2750
|
if ((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
2751
|
+
if (gobj.priv.expected_pops > 0) {
|
|
2752
|
+
defer_route(gobj, route);
|
|
2753
|
+
return 0;
|
|
2754
|
+
}
|
|
2713
2755
|
let target_hash = route_to_hash(route);
|
|
2714
2756
|
if (window.location.hash !== target_hash) window.location.hash = target_hash;
|
|
2715
2757
|
else navigate_to(gobj, route);
|
|
@@ -2951,7 +2993,7 @@ function yui_shell_navigate(shell_gobj, route, opts) {
|
|
|
2951
2993
|
if (!(opts && opts.replace) && (0, _yuneta_gobj_js.gobj_read_attr)(shell_gobj, "use_hash")) {
|
|
2952
2994
|
let priv = shell_gobj.priv;
|
|
2953
2995
|
if (priv && priv.expected_pops > 0) {
|
|
2954
|
-
|
|
2996
|
+
defer_route(shell_gobj, route);
|
|
2955
2997
|
return;
|
|
2956
2998
|
}
|
|
2957
2999
|
let target_hash = route_to_hash(route);
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -974,6 +974,7 @@ var PRIVATE_DATA$22 = {
|
|
|
974
974
|
restore_hash: "",
|
|
975
975
|
skip_hash: "",
|
|
976
976
|
deferred_route: "",
|
|
977
|
+
deferred_timer: null,
|
|
977
978
|
popstate_handler: null,
|
|
978
979
|
avatar_provider: null,
|
|
979
980
|
avatar_nodes: [],
|
|
@@ -1081,8 +1082,9 @@ function mt_start$20(gobj) {
|
|
|
1081
1082
|
if (top.marker_pending || top.no_marker) return;
|
|
1082
1083
|
if (window.location.hash !== top.hash && window.location.hash !== top.below_hash) return;
|
|
1083
1084
|
let st = ev && ev.state;
|
|
1084
|
-
if (st
|
|
1085
|
-
if (st
|
|
1085
|
+
if (!st) return;
|
|
1086
|
+
if (st.__yui_overlay__ === top.id) return;
|
|
1087
|
+
if (st.__yui_overlay__ > top.id && !p.overlay_stack.some((e) => e.id === st.__yui_overlay__)) return;
|
|
1086
1088
|
p.overlay_stack.pop();
|
|
1087
1089
|
try {
|
|
1088
1090
|
top.close();
|
|
@@ -1142,6 +1144,7 @@ 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);
|
|
1145
1148
|
if (priv.keydown_handler) {
|
|
1146
1149
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
1147
1150
|
priv.keydown_handler = null;
|
|
@@ -2551,6 +2554,11 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2551
2554
|
function push_overlay_marker(gobj, entry) {
|
|
2552
2555
|
let priv = gobj.priv;
|
|
2553
2556
|
entry.below_hash = window.location.hash;
|
|
2557
|
+
if (window.history.state === null) try {
|
|
2558
|
+
window.history.replaceState({ __yui_below__: entry.id }, "");
|
|
2559
|
+
} catch (e) {
|
|
2560
|
+
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2561
|
+
}
|
|
2554
2562
|
try {
|
|
2555
2563
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2556
2564
|
} catch (e) {
|
|
@@ -2567,6 +2575,35 @@ function drop_expected_pops(gobj) {
|
|
|
2567
2575
|
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
2576
|
priv.expected_pops = 0;
|
|
2569
2577
|
priv.expected_pop_hash = "";
|
|
2578
|
+
clear_deferred_timer(gobj);
|
|
2579
|
+
if (priv.deferred_route) {
|
|
2580
|
+
log_warning(`C_YUI_SHELL: route '${priv.deferred_route}' waited for that back() and is dropped: the history moved on to '${window.location.hash}'`);
|
|
2581
|
+
priv.deferred_route = "";
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2585
|
+
function defer_route(gobj, route) {
|
|
2586
|
+
let priv = gobj.priv;
|
|
2587
|
+
if (priv.deferred_route && priv.deferred_route !== route) log_warning(`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() of ours is replaced by '${route}'`);
|
|
2588
|
+
priv.deferred_route = route;
|
|
2589
|
+
if (!priv.deferred_timer) priv.deferred_timer = window.setTimeout(() => {
|
|
2590
|
+
let p = gobj.priv;
|
|
2591
|
+
if (!p) return;
|
|
2592
|
+
p.deferred_timer = null;
|
|
2593
|
+
if (p.expected_pops === 0) return;
|
|
2594
|
+
log_warning(`C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
|
|
2595
|
+
p.expected_pops = 0;
|
|
2596
|
+
p.expected_pop_hash = "";
|
|
2597
|
+
p.restore_hash = "";
|
|
2598
|
+
push_pending_markers(gobj);
|
|
2599
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
2600
|
+
}
|
|
2601
|
+
function clear_deferred_timer(gobj) {
|
|
2602
|
+
let priv = gobj.priv;
|
|
2603
|
+
if (priv.deferred_timer) {
|
|
2604
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2605
|
+
priv.deferred_timer = null;
|
|
2606
|
+
}
|
|
2570
2607
|
}
|
|
2571
2608
|
function push_pending_markers(gobj) {
|
|
2572
2609
|
let priv = gobj.priv;
|
|
@@ -2577,6 +2614,7 @@ function push_pending_markers(gobj) {
|
|
|
2577
2614
|
entry.hash = window.location.hash;
|
|
2578
2615
|
push_overlay_marker(gobj, entry);
|
|
2579
2616
|
}
|
|
2617
|
+
clear_deferred_timer(gobj);
|
|
2580
2618
|
if (priv.deferred_route) {
|
|
2581
2619
|
let route = priv.deferred_route;
|
|
2582
2620
|
priv.deferred_route = "";
|
|
@@ -2705,6 +2743,10 @@ function ac_nav_clicked(gobj, event, kw, src) {
|
|
|
2705
2743
|
}
|
|
2706
2744
|
route = remembered_position(gobj, route);
|
|
2707
2745
|
if (gobj_read_attr(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
2746
|
+
if (gobj.priv.expected_pops > 0) {
|
|
2747
|
+
defer_route(gobj, route);
|
|
2748
|
+
return 0;
|
|
2749
|
+
}
|
|
2708
2750
|
let target_hash = route_to_hash(route);
|
|
2709
2751
|
if (window.location.hash !== target_hash) window.location.hash = target_hash;
|
|
2710
2752
|
else navigate_to(gobj, route);
|
|
@@ -2946,7 +2988,7 @@ function yui_shell_navigate(shell_gobj, route, opts) {
|
|
|
2946
2988
|
if (!(opts && opts.replace) && gobj_read_attr(shell_gobj, "use_hash")) {
|
|
2947
2989
|
let priv = shell_gobj.priv;
|
|
2948
2990
|
if (priv && priv.expected_pops > 0) {
|
|
2949
|
-
|
|
2991
|
+
defer_route(shell_gobj, route);
|
|
2950
2992
|
return;
|
|
2951
2993
|
}
|
|
2952
2994
|
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,39 @@ 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 keeps the receiver's head and is no longer static: a
|
|
113
|
+
* receiver that carries data stays BUILT markup through them, and so
|
|
114
|
+
* does a static one whose replacement is data
|
|
115
|
+
* ('<b>NAME</b>'.replace('NAME', name)). */
|
|
116
|
+
function replaced(method, head, args)
|
|
117
|
+
{
|
|
118
|
+
if(head.complete && args.length === 2) {
|
|
119
|
+
let pattern = null;
|
|
120
|
+
if(args[0].type === "Literal" && args[0].regex) {
|
|
121
|
+
try {
|
|
122
|
+
pattern = new RegExp(args[0].regex.pattern, args[0].regex.flags);
|
|
123
|
+
} catch(e) {
|
|
124
|
+
pattern = null;
|
|
125
|
+
}
|
|
126
|
+
} else if(is_string_literal(args[0])) {
|
|
127
|
+
pattern = args[0].value;
|
|
128
|
+
}
|
|
129
|
+
let replacement = leading(args[1]);
|
|
130
|
+
if(pattern !== null && replacement && replacement.complete) {
|
|
131
|
+
try {
|
|
132
|
+
return {text: String.prototype[method].call(head.text, pattern, replacement.text),
|
|
133
|
+
complete: true};
|
|
134
|
+
} catch(e) {
|
|
135
|
+
/* replaceAll() with a regex that is not global throws:
|
|
136
|
+
* so does the code, the check need not know what it gives. */
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return {text: head.text, complete: false};
|
|
141
|
+
}
|
|
142
|
+
|
|
110
143
|
function concat_parts(parts)
|
|
111
144
|
{
|
|
112
145
|
/* parts: [{text, complete}] in order. The leading text runs while
|
|
@@ -191,6 +224,13 @@ function leading(n)
|
|
|
191
224
|
});
|
|
192
225
|
return concat_parts(parts);
|
|
193
226
|
}
|
|
227
|
+
if(method === "replace" || method === "replaceAll") {
|
|
228
|
+
let head = leading(receiver);
|
|
229
|
+
if(head === null) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return replaced(method, head, n.arguments);
|
|
233
|
+
}
|
|
194
234
|
if(HEAD_KEEPING_METHODS.has(method)) {
|
|
195
235
|
let head = leading(receiver);
|
|
196
236
|
if(head === null) {
|
package/src/c_yui_shell.js
CHANGED
|
@@ -180,6 +180,9 @@ let PRIVATE_DATA = {
|
|
|
180
180
|
* flight: it is navigated once the back() is over, or the traversal
|
|
181
181
|
* would run from it and undo it. */
|
|
182
182
|
deferred_route: "",
|
|
183
|
+
/* Bounds the wait for that back(): one that never lands must not
|
|
184
|
+
* hold every later navigation for ever. */
|
|
185
|
+
deferred_timer: null,
|
|
183
186
|
popstate_handler: null,
|
|
184
187
|
/* Avatar item support — every toolbar item with type:"avatar"
|
|
185
188
|
* registers its <span> here so refresh_avatars() can repaint
|
|
@@ -430,14 +433,25 @@ function mt_start(gobj)
|
|
|
430
433
|
* overlay's marker) closes the top overlay: strict
|
|
431
434
|
* LIFO. */
|
|
432
435
|
let st = ev && ev.state;
|
|
433
|
-
if(st
|
|
436
|
+
if(!st) {
|
|
437
|
+
/* An entry with no state is a FRESH one: a push (a
|
|
438
|
+
* link, `location.hash = ...`) fires popstate too, and a
|
|
439
|
+
* link to the hash the panel was opened on is not a
|
|
440
|
+
* Back. A step off a marker lands on the entry under it,
|
|
441
|
+
* which push_overlay_marker() stamped, or on a lower
|
|
442
|
+
* overlay's marker. */
|
|
434
443
|
return;
|
|
435
444
|
}
|
|
436
|
-
if(st
|
|
445
|
+
if(st.__yui_overlay__ === top.id) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if(st.__yui_overlay__ > top.id &&
|
|
437
449
|
!p.overlay_stack.some(e => e.id === st.__yui_overlay__)) {
|
|
438
|
-
/* A dead marker NEWER than the top:
|
|
439
|
-
*
|
|
440
|
-
*
|
|
450
|
+
/* A dead marker NEWER than the top: Forward reaches it
|
|
451
|
+
* (an overlay closed by its button above this one), and
|
|
452
|
+
* so does a Back onto the marker of an overlay a
|
|
453
|
+
* navigation drained under a panel that stayed. It is
|
|
454
|
+
* not a step off the top's marker. */
|
|
441
455
|
return;
|
|
442
456
|
}
|
|
443
457
|
p.overlay_stack.pop();
|
|
@@ -542,6 +556,7 @@ function mt_stop(gobj)
|
|
|
542
556
|
priv.restore_hash = "";
|
|
543
557
|
priv.skip_hash = "";
|
|
544
558
|
priv.deferred_route = "";
|
|
559
|
+
clear_deferred_timer(gobj);
|
|
545
560
|
if(priv.keydown_handler) {
|
|
546
561
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
547
562
|
priv.keydown_handler = null;
|
|
@@ -2781,6 +2796,19 @@ function push_overlay_marker(gobj, entry)
|
|
|
2781
2796
|
* marker lands there -- even after a replace-navigation rewrote the
|
|
2782
2797
|
* marker's own hash (retag_overlay_hash()). */
|
|
2783
2798
|
entry.below_hash = window.location.hash;
|
|
2799
|
+
/* Stamp the entry under the marker: a step off the marker lands on
|
|
2800
|
+
* it, and a push (a link, `location.hash = ...`) lands on a fresh
|
|
2801
|
+
* entry with no state -- both fire popstate, on the same hash when
|
|
2802
|
+
* the link points where the overlay was opened, and the state is
|
|
2803
|
+
* the only thing that tells them apart. An entry with a state of
|
|
2804
|
+
* its own (a lower marker, an app's) keeps it. */
|
|
2805
|
+
if(window.history.state === null) {
|
|
2806
|
+
try {
|
|
2807
|
+
window.history.replaceState({ __yui_below__: entry.id }, "");
|
|
2808
|
+
} catch(e) {
|
|
2809
|
+
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2784
2812
|
try {
|
|
2785
2813
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2786
2814
|
} catch(e) {
|
|
@@ -2812,10 +2840,68 @@ function drop_expected_pops(gobj)
|
|
|
2812
2840
|
);
|
|
2813
2841
|
priv.expected_pops = 0;
|
|
2814
2842
|
priv.expected_pop_hash = "";
|
|
2843
|
+
clear_deferred_timer(gobj);
|
|
2844
|
+
if(priv.deferred_route) {
|
|
2845
|
+
/* The history moved on under it (a link, a Back): that move is
|
|
2846
|
+
* the newer one, and running the route after it would undo it. */
|
|
2847
|
+
log_warning(
|
|
2848
|
+
`C_YUI_SHELL: route '${priv.deferred_route}' waited for that ` +
|
|
2849
|
+
`back() and is dropped: the history moved on to '${window.location.hash}'`
|
|
2850
|
+
);
|
|
2851
|
+
priv.deferred_route = "";
|
|
2852
|
+
}
|
|
2815
2853
|
/* The caller pushes the waiting markers, once it has handled the
|
|
2816
2854
|
* traversal that told it. */
|
|
2817
2855
|
}
|
|
2818
2856
|
|
|
2857
|
+
/* A route pushed while a back() of ours is in flight waits for it to
|
|
2858
|
+
* land (push_pending_markers() navigates it), and a newer one takes
|
|
2859
|
+
* its place, said out loud. The wait is bounded: a back() that never
|
|
2860
|
+
* lands, with nothing else moving the history to say so, would hold
|
|
2861
|
+
* every later navigation. */
|
|
2862
|
+
const DEFERRED_ROUTE_WAIT_MS = 1000;
|
|
2863
|
+
|
|
2864
|
+
function defer_route(gobj, route)
|
|
2865
|
+
{
|
|
2866
|
+
let priv = gobj.priv;
|
|
2867
|
+
if(priv.deferred_route && priv.deferred_route !== route) {
|
|
2868
|
+
log_warning(
|
|
2869
|
+
`C_YUI_SHELL: route '${priv.deferred_route}' waiting for a back() ` +
|
|
2870
|
+
`of ours is replaced by '${route}'`
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
priv.deferred_route = route;
|
|
2874
|
+
if(!priv.deferred_timer) {
|
|
2875
|
+
priv.deferred_timer = window.setTimeout(() => {
|
|
2876
|
+
let p = gobj.priv;
|
|
2877
|
+
if(!p) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
p.deferred_timer = null;
|
|
2881
|
+
if(p.expected_pops === 0) {
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
log_warning(
|
|
2885
|
+
`C_YUI_SHELL: ${p.expected_pops} history.back() of ours did not ` +
|
|
2886
|
+
`land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
|
|
2887
|
+
);
|
|
2888
|
+
p.expected_pops = 0;
|
|
2889
|
+
p.expected_pop_hash = "";
|
|
2890
|
+
p.restore_hash = "";
|
|
2891
|
+
push_pending_markers(gobj); // and navigates the deferred route
|
|
2892
|
+
}, DEFERRED_ROUTE_WAIT_MS);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
function clear_deferred_timer(gobj)
|
|
2897
|
+
{
|
|
2898
|
+
let priv = gobj.priv;
|
|
2899
|
+
if(priv.deferred_timer) {
|
|
2900
|
+
window.clearTimeout(priv.deferred_timer);
|
|
2901
|
+
priv.deferred_timer = null;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2819
2905
|
/* The history.back() calls of ours have all landed: push the markers of
|
|
2820
2906
|
* the overlays registered meanwhile, in their order. One closed in the
|
|
2821
2907
|
* meantime (dismissed, drained, or no longer on the stack) has none. */
|
|
@@ -2833,6 +2919,7 @@ function push_pending_markers(gobj)
|
|
|
2833
2919
|
entry.hash = window.location.hash;
|
|
2834
2920
|
push_overlay_marker(gobj, entry); // Error already logged
|
|
2835
2921
|
}
|
|
2922
|
+
clear_deferred_timer(gobj);
|
|
2836
2923
|
if(priv.deferred_route) {
|
|
2837
2924
|
let route = priv.deferred_route;
|
|
2838
2925
|
priv.deferred_route = "";
|
|
@@ -3110,6 +3197,13 @@ function ac_nav_clicked(gobj, event, kw, src)
|
|
|
3110
3197
|
* Exception: URL-restoring action routes skip the push — see
|
|
3111
3198
|
* route_restores_url. */
|
|
3112
3199
|
if(gobj_read_attr(gobj, "use_hash") && !route_restores_url(gobj, route)) {
|
|
3200
|
+
if(gobj.priv.expected_pops > 0) {
|
|
3201
|
+
/* A back() of ours is in flight (an overlay closed in this
|
|
3202
|
+
* same turn): a push now would be undone by it, as in
|
|
3203
|
+
* yui_shell_navigate(). */
|
|
3204
|
+
defer_route(gobj, route);
|
|
3205
|
+
return 0;
|
|
3206
|
+
}
|
|
3113
3207
|
let target_hash = route_to_hash(route);
|
|
3114
3208
|
if(window.location.hash !== target_hash) {
|
|
3115
3209
|
window.location.hash = target_hash; /* fires hashchange */
|
|
@@ -3706,7 +3800,7 @@ function yui_shell_navigate(shell_gobj, route, opts)
|
|
|
3706
3800
|
* navigates): a push now lands BEFORE the traversal, which
|
|
3707
3801
|
* then runs from it and undoes it (and in Firefox lands on
|
|
3708
3802
|
* the closed overlay's marker). Navigate once it is over. */
|
|
3709
|
-
|
|
3803
|
+
defer_route(shell_gobj, route);
|
|
3710
3804
|
return;
|
|
3711
3805
|
}
|
|
3712
3806
|
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).toEqual({__yui_below__: 1}); // 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
|
|
|
@@ -656,3 +656,191 @@ 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
|
+
});
|
|
@@ -69,10 +69,14 @@ function errors()
|
|
|
69
69
|
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/* A Back off a marker lands on the entry under it, which the shell
|
|
73
|
+
* stamped when it pushed the marker: a landing with NO state is a push
|
|
74
|
+
* (a link), not a Back. */
|
|
72
75
|
function press_back()
|
|
73
76
|
{
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
const ev = new Event("popstate");
|
|
78
|
+
ev.state = {__yui_below__: 0};
|
|
79
|
+
window.dispatchEvent(ev);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
describe("a floating window that vetoes its close", () => {
|