@yuneta/gobj-ui 7.26.16 → 7.26.18
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
CHANGED
|
@@ -2563,12 +2563,19 @@ function push_overlay_marker(gobj, entry) {
|
|
|
2563
2563
|
let priv = gobj.priv;
|
|
2564
2564
|
entry.below_hash = window.location.hash;
|
|
2565
2565
|
let below = window.history.state;
|
|
2566
|
-
|
|
2566
|
+
let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
|
|
2567
|
+
let stamped = false;
|
|
2568
|
+
if (below === null || plain) try {
|
|
2567
2569
|
window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2570
|
+
stamped = true;
|
|
2568
2571
|
} catch (e) {
|
|
2569
2572
|
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2570
2573
|
}
|
|
2571
|
-
else (0, _yuneta_gobj_js.log_warning)("C_YUI_SHELL: the entry under an overlay holds a history state that is not
|
|
2574
|
+
else (0, _yuneta_gobj_js.log_warning)("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: Back will not close the overlay");
|
|
2575
|
+
if (!stamped) {
|
|
2576
|
+
entry.no_marker = true;
|
|
2577
|
+
return true;
|
|
2578
|
+
}
|
|
2572
2579
|
try {
|
|
2573
2580
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2574
2581
|
} catch (e) {
|
|
@@ -2593,6 +2600,7 @@ function drop_expected_pops(gobj) {
|
|
|
2593
2600
|
}
|
|
2594
2601
|
}
|
|
2595
2602
|
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2603
|
+
var LATE_LANDING_WINDOW_MS = 5e3;
|
|
2596
2604
|
function defer_route(gobj, route) {
|
|
2597
2605
|
let priv = gobj.priv;
|
|
2598
2606
|
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}'`);
|
|
@@ -2607,6 +2615,10 @@ function note_late_landing(gobj, ev) {
|
|
|
2607
2615
|
let priv = gobj.priv;
|
|
2608
2616
|
let given_up = priv.given_up;
|
|
2609
2617
|
let st = ev && ev.state;
|
|
2618
|
+
if (given_up && Date.now() > given_up.until) {
|
|
2619
|
+
priv.given_up = null;
|
|
2620
|
+
return;
|
|
2621
|
+
}
|
|
2610
2622
|
if (!given_up || !st) return;
|
|
2611
2623
|
priv.given_up = null;
|
|
2612
2624
|
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}'`);
|
|
@@ -2621,11 +2633,12 @@ function clear_deferred_timer(gobj) {
|
|
|
2621
2633
|
function push_pending_markers(gobj) {
|
|
2622
2634
|
let priv = gobj.priv;
|
|
2623
2635
|
let pending = priv.pending_markers.splice(0);
|
|
2636
|
+
let pushed = [];
|
|
2624
2637
|
for (let entry of pending) {
|
|
2625
2638
|
entry.marker_pending = false;
|
|
2626
2639
|
if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
|
|
2627
2640
|
entry.hash = window.location.hash;
|
|
2628
|
-
push_overlay_marker(gobj, entry);
|
|
2641
|
+
if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
|
|
2629
2642
|
}
|
|
2630
2643
|
clear_deferred_timer(gobj);
|
|
2631
2644
|
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
@@ -2634,6 +2647,7 @@ function push_pending_markers(gobj) {
|
|
|
2634
2647
|
priv.deferred_route = "";
|
|
2635
2648
|
yui_shell_navigate(gobj, route);
|
|
2636
2649
|
}
|
|
2650
|
+
return pushed;
|
|
2637
2651
|
}
|
|
2638
2652
|
function overlay_dismissed(gobj, entry) {
|
|
2639
2653
|
let priv = gobj.priv;
|
|
@@ -2780,13 +2794,15 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
|
|
|
2780
2794
|
(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
2795
|
let given_up = {
|
|
2782
2796
|
ids: priv.expected_pop_ids.slice(),
|
|
2783
|
-
route: priv.deferred_route
|
|
2797
|
+
route: priv.deferred_route,
|
|
2798
|
+
until: Date.now() + LATE_LANDING_WINDOW_MS
|
|
2784
2799
|
};
|
|
2785
2800
|
priv.expected_pops = 0;
|
|
2786
2801
|
priv.expected_pop_hash = "";
|
|
2787
2802
|
priv.expected_pop_ids = [];
|
|
2788
2803
|
priv.restore_hash = "";
|
|
2789
|
-
push_pending_markers(gobj);
|
|
2804
|
+
let pushed = push_pending_markers(gobj);
|
|
2805
|
+
given_up.ids.push(...pushed);
|
|
2790
2806
|
priv.given_up = given_up;
|
|
2791
2807
|
return 0;
|
|
2792
2808
|
}
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -2558,12 +2558,19 @@ function push_overlay_marker(gobj, entry) {
|
|
|
2558
2558
|
let priv = gobj.priv;
|
|
2559
2559
|
entry.below_hash = window.location.hash;
|
|
2560
2560
|
let below = window.history.state;
|
|
2561
|
-
|
|
2561
|
+
let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
|
|
2562
|
+
let stamped = false;
|
|
2563
|
+
if (below === null || plain) try {
|
|
2562
2564
|
window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2565
|
+
stamped = true;
|
|
2563
2566
|
} catch (e) {
|
|
2564
2567
|
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2565
2568
|
}
|
|
2566
|
-
else log_warning("C_YUI_SHELL: the entry under an overlay holds a history state that is not
|
|
2569
|
+
else log_warning("C_YUI_SHELL: the entry under an overlay holds a history state that is not a plain object, it cannot be stamped: Back will not close the overlay");
|
|
2570
|
+
if (!stamped) {
|
|
2571
|
+
entry.no_marker = true;
|
|
2572
|
+
return true;
|
|
2573
|
+
}
|
|
2567
2574
|
try {
|
|
2568
2575
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2569
2576
|
} catch (e) {
|
|
@@ -2588,6 +2595,7 @@ function drop_expected_pops(gobj) {
|
|
|
2588
2595
|
}
|
|
2589
2596
|
}
|
|
2590
2597
|
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2598
|
+
var LATE_LANDING_WINDOW_MS = 5e3;
|
|
2591
2599
|
function defer_route(gobj, route) {
|
|
2592
2600
|
let priv = gobj.priv;
|
|
2593
2601
|
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}'`);
|
|
@@ -2602,6 +2610,10 @@ function note_late_landing(gobj, ev) {
|
|
|
2602
2610
|
let priv = gobj.priv;
|
|
2603
2611
|
let given_up = priv.given_up;
|
|
2604
2612
|
let st = ev && ev.state;
|
|
2613
|
+
if (given_up && Date.now() > given_up.until) {
|
|
2614
|
+
priv.given_up = null;
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2605
2617
|
if (!given_up || !st) return;
|
|
2606
2618
|
priv.given_up = null;
|
|
2607
2619
|
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}'`);
|
|
@@ -2616,11 +2628,12 @@ function clear_deferred_timer(gobj) {
|
|
|
2616
2628
|
function push_pending_markers(gobj) {
|
|
2617
2629
|
let priv = gobj.priv;
|
|
2618
2630
|
let pending = priv.pending_markers.splice(0);
|
|
2631
|
+
let pushed = [];
|
|
2619
2632
|
for (let entry of pending) {
|
|
2620
2633
|
entry.marker_pending = false;
|
|
2621
2634
|
if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
|
|
2622
2635
|
entry.hash = window.location.hash;
|
|
2623
|
-
push_overlay_marker(gobj, entry);
|
|
2636
|
+
if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
|
|
2624
2637
|
}
|
|
2625
2638
|
clear_deferred_timer(gobj);
|
|
2626
2639
|
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
@@ -2629,6 +2642,7 @@ function push_pending_markers(gobj) {
|
|
|
2629
2642
|
priv.deferred_route = "";
|
|
2630
2643
|
yui_shell_navigate(gobj, route);
|
|
2631
2644
|
}
|
|
2645
|
+
return pushed;
|
|
2632
2646
|
}
|
|
2633
2647
|
function overlay_dismissed(gobj, entry) {
|
|
2634
2648
|
let priv = gobj.priv;
|
|
@@ -2775,13 +2789,15 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
|
|
|
2775
2789
|
log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
|
|
2776
2790
|
let given_up = {
|
|
2777
2791
|
ids: priv.expected_pop_ids.slice(),
|
|
2778
|
-
route: priv.deferred_route
|
|
2792
|
+
route: priv.deferred_route,
|
|
2793
|
+
until: Date.now() + LATE_LANDING_WINDOW_MS
|
|
2779
2794
|
};
|
|
2780
2795
|
priv.expected_pops = 0;
|
|
2781
2796
|
priv.expected_pop_hash = "";
|
|
2782
2797
|
priv.expected_pop_ids = [];
|
|
2783
2798
|
priv.restore_hash = "";
|
|
2784
|
-
push_pending_markers(gobj);
|
|
2799
|
+
let pushed = push_pending_markers(gobj);
|
|
2800
|
+
given_up.ids.push(...pushed);
|
|
2785
2801
|
priv.given_up = given_up;
|
|
2786
2802
|
return 0;
|
|
2787
2803
|
}
|
package/package.json
CHANGED
|
@@ -34,8 +34,11 @@
|
|
|
34
34
|
* string (its type is not known before running); a description
|
|
35
35
|
* built piece by piece (push() into an array that is later the
|
|
36
36
|
* content); a computed tag with an attrs slot that is not an object
|
|
37
|
-
* literal;
|
|
38
|
-
*
|
|
37
|
+
* literal; a replace() whose replacement is a function, whose
|
|
38
|
+
* pattern is a variable, or whose replacement starts with a special
|
|
39
|
+
* pattern ('$`<i>', '$1'), and a method called on a function result
|
|
40
|
+
* (String(x).replace(...)); markup given to innerHTML, or to a
|
|
41
|
+
* widget (Tabulator, G6), which are other sinks. set_strings_are_text(true) logs, once
|
|
39
42
|
* at run time, every string that reaches createElement2() starting
|
|
40
43
|
* with '<': that is the other half of the check.
|
|
41
44
|
*
|
|
@@ -107,43 +110,102 @@ const PURE_METHODS = new Set([
|
|
|
107
110
|
"toLowerCase", "toUpperCase"
|
|
108
111
|
]);
|
|
109
112
|
|
|
110
|
-
/* replace()/replaceAll()
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* ('<b>NAME</b>'.replace('NAME', name)
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* ('
|
|
113
|
+
/* replace()/replaceAll(). A receiver that is static, with a static
|
|
114
|
+
* pattern and a static replacement, is computed, so a tag stripped away
|
|
115
|
+
* is seen as stripped. Otherwise the result is no longer static, and its
|
|
116
|
+
* head is what is known to come BEFORE the first match: the receiver's
|
|
117
|
+
* text up to it, then the replacement's head
|
|
118
|
+
* ('<b>NAME</b>'.replace('NAME', name) is '<b>' + data: built;
|
|
119
|
+
* 'abc'.replace('abc', '<i>' + y) is '<i>' + data: built). Where the
|
|
120
|
+
* first match is decides it, so the replacement is the head only when the
|
|
121
|
+
* pattern can match at 0: ('z' + name).replace('a', '<b>') starts with
|
|
122
|
+
* 'z', and 'abc'.replace('x', '<i>' + y) is 'abc'.
|
|
123
|
+
* Not seen: a replacement that is a function, a pattern in a variable. */
|
|
124
|
+
function static_pattern(arg)
|
|
125
|
+
{
|
|
126
|
+
if(arg.type === "Literal" && arg.regex) {
|
|
127
|
+
try {
|
|
128
|
+
return new RegExp(arg.regex.pattern, arg.regex.flags);
|
|
129
|
+
} catch(e) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if(is_string_literal(arg)) {
|
|
134
|
+
return arg.value;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function first_match(text, pattern)
|
|
140
|
+
{
|
|
141
|
+
if(typeof pattern === "string") {
|
|
142
|
+
return text.indexOf(pattern);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const re = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
146
|
+
const m = re.exec(text);
|
|
147
|
+
return m ? m.index : -1;
|
|
148
|
+
} catch(e) {
|
|
149
|
+
return -1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
119
153
|
function replaced(method, head, args)
|
|
120
154
|
{
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
155
|
+
if(args.length !== 2) {
|
|
156
|
+
return {text: head.text, complete: false};
|
|
157
|
+
}
|
|
158
|
+
const pattern = static_pattern(args[0]);
|
|
159
|
+
const replacement = leading(args[1]);
|
|
160
|
+
if(pattern === null) {
|
|
161
|
+
return {text: head.text, complete: false};
|
|
162
|
+
}
|
|
163
|
+
if(head.complete && replacement && replacement.complete) {
|
|
164
|
+
try {
|
|
165
|
+
return {text: String.prototype[method].call(head.text, pattern, replacement.text),
|
|
166
|
+
complete: true};
|
|
167
|
+
} catch(e) {
|
|
168
|
+
/* replaceAll() with a regex that is not global throws: so
|
|
169
|
+
* does the code, the check need not know what it gives. */
|
|
170
|
+
return {text: head.text, complete: false};
|
|
132
171
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
172
|
+
}
|
|
173
|
+
/* What the replacement is known to start with. A `$` in it is a
|
|
174
|
+
* special pattern ($&, $`, $', $1...): what it expands to is only
|
|
175
|
+
* known at run time, so the known head stops there. */
|
|
176
|
+
let rep_head = replacement ? replacement.text : "";
|
|
177
|
+
if(rep_head.includes("$")) {
|
|
178
|
+
rep_head = rep_head.slice(0, rep_head.indexOf("$"));
|
|
179
|
+
}
|
|
180
|
+
if(!head.complete && typeof pattern !== "string") {
|
|
181
|
+
/* A regex on a receiver that carries data: alternatives and
|
|
182
|
+
* lookaheads can make the data match before anything the known
|
|
183
|
+
* text says, so no position is computed. Markup in the
|
|
184
|
+
* replacement may be the head (the conservative reading); if not,
|
|
185
|
+
* the receiver's head stands. */
|
|
186
|
+
if(starts_with_markup(rep_head)) {
|
|
187
|
+
return {text: rep_head, complete: false};
|
|
141
188
|
}
|
|
189
|
+
return {text: head.text, complete: false};
|
|
190
|
+
}
|
|
191
|
+
const idx = first_match(head.text, pattern);
|
|
192
|
+
if(idx >= 0) {
|
|
193
|
+
return {text: head.text.slice(0, idx) + rep_head, complete: false};
|
|
194
|
+
}
|
|
195
|
+
if(head.complete) {
|
|
196
|
+
return {text: head.text, complete: true}; // no match: the receiver as it is
|
|
197
|
+
}
|
|
198
|
+
/* A string pattern with no match in the known text: the first match
|
|
199
|
+
* starts in the data, or straddles the end of the known text -- only
|
|
200
|
+
* where what is left of the known text is a prefix of the pattern. */
|
|
201
|
+
let keep = Math.max(0, head.text.length - pattern.length + 1);
|
|
202
|
+
while(keep < head.text.length && !pattern.startsWith(head.text.slice(keep))) {
|
|
203
|
+
keep++;
|
|
142
204
|
}
|
|
143
|
-
if(
|
|
144
|
-
return {text:
|
|
205
|
+
if(keep === 0) {
|
|
206
|
+
return {text: rep_head, complete: false};
|
|
145
207
|
}
|
|
146
|
-
return {text: head.text, complete: false};
|
|
208
|
+
return {text: head.text.slice(0, keep), complete: false};
|
|
147
209
|
}
|
|
148
210
|
|
|
149
211
|
function concat_parts(parts)
|
package/src/c_yui_shell.js
CHANGED
|
@@ -2803,19 +2803,33 @@ function push_overlay_marker(gobj, entry)
|
|
|
2803
2803
|
* lower overlay's marker, an app's own) keeps its keys; the stamp
|
|
2804
2804
|
* is added to them, and replaces an older stamp. */
|
|
2805
2805
|
let below = window.history.state;
|
|
2806
|
-
|
|
2806
|
+
/* A PLAIN object only: a Map or a Date is an object too (the state
|
|
2807
|
+
* is a structured clone, so a plain object comes back with
|
|
2808
|
+
* Object.prototype), and Object.assign() copies none of it. */
|
|
2809
|
+
let plain = below !== null && typeof below === "object" &&
|
|
2810
|
+
Object.getPrototypeOf(below) === Object.prototype;
|
|
2811
|
+
let stamped = false;
|
|
2812
|
+
if(below === null || plain) {
|
|
2807
2813
|
try {
|
|
2808
2814
|
window.history.replaceState(
|
|
2809
2815
|
Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2816
|
+
stamped = true;
|
|
2810
2817
|
} catch(e) {
|
|
2811
2818
|
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2812
2819
|
}
|
|
2813
2820
|
} else {
|
|
2814
2821
|
log_warning(
|
|
2815
2822
|
`C_YUI_SHELL: the entry under an overlay holds a history state that ` +
|
|
2816
|
-
`is not
|
|
2823
|
+
`is not a plain object, it cannot be stamped: Back will not close the overlay`
|
|
2817
2824
|
);
|
|
2818
2825
|
}
|
|
2826
|
+
if(!stamped) {
|
|
2827
|
+
/* With no stamp under it, no Back can step off its marker: a
|
|
2828
|
+
* marker would only swallow one Back of the reader's. The overlay
|
|
2829
|
+
* goes without one, and closes by its own controls. */
|
|
2830
|
+
entry.no_marker = true;
|
|
2831
|
+
return true;
|
|
2832
|
+
}
|
|
2819
2833
|
try {
|
|
2820
2834
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2821
2835
|
} catch(e) {
|
|
@@ -2869,6 +2883,11 @@ function drop_expected_pops(gobj)
|
|
|
2869
2883
|
* every later navigation. */
|
|
2870
2884
|
const DEFERRED_ROUTE_WAIT_MS = 1000;
|
|
2871
2885
|
|
|
2886
|
+
/* How long after giving up a landing on one of those markers is still
|
|
2887
|
+
* said to be, perhaps, the late back(): after that it is a Back of the
|
|
2888
|
+
* reader's, and saying otherwise is a false alarm. */
|
|
2889
|
+
const LATE_LANDING_WINDOW_MS = 5000;
|
|
2890
|
+
|
|
2872
2891
|
function defer_route(gobj, route)
|
|
2873
2892
|
{
|
|
2874
2893
|
let priv = gobj.priv;
|
|
@@ -2902,6 +2921,10 @@ function note_late_landing(gobj, ev)
|
|
|
2902
2921
|
let priv = gobj.priv;
|
|
2903
2922
|
let given_up = priv.given_up;
|
|
2904
2923
|
let st = ev && ev.state;
|
|
2924
|
+
if(given_up && Date.now() > given_up.until) {
|
|
2925
|
+
priv.given_up = null; // too late to be that back(): a Back of the reader's
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2905
2928
|
if(!given_up || !st) {
|
|
2906
2929
|
return; // a push (the waiting route's own) lands on a fresh entry
|
|
2907
2930
|
}
|
|
@@ -2931,6 +2954,7 @@ function push_pending_markers(gobj)
|
|
|
2931
2954
|
{
|
|
2932
2955
|
let priv = gobj.priv;
|
|
2933
2956
|
let pending = priv.pending_markers.splice(0);
|
|
2957
|
+
let pushed = [];
|
|
2934
2958
|
for(let entry of pending) {
|
|
2935
2959
|
entry.marker_pending = false;
|
|
2936
2960
|
if(entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) {
|
|
@@ -2939,7 +2963,10 @@ function push_pending_markers(gobj)
|
|
|
2939
2963
|
/* The traversal was same-hash, but a route may have moved
|
|
2940
2964
|
* meanwhile: the marker lives on the hash it is pushed on. */
|
|
2941
2965
|
entry.hash = window.location.hash;
|
|
2942
|
-
push_overlay_marker(gobj, entry)
|
|
2966
|
+
if(push_overlay_marker(gobj, entry) && !entry.no_marker) {
|
|
2967
|
+
pushed.push(entry.id);
|
|
2968
|
+
}
|
|
2969
|
+
// else: Error already logged
|
|
2943
2970
|
}
|
|
2944
2971
|
clear_deferred_timer(gobj);
|
|
2945
2972
|
if(priv.expected_pops === 0) {
|
|
@@ -2950,6 +2977,7 @@ function push_pending_markers(gobj)
|
|
|
2950
2977
|
priv.deferred_route = "";
|
|
2951
2978
|
yui_shell_navigate(gobj, route);
|
|
2952
2979
|
}
|
|
2980
|
+
return pushed; // the ids of the markers it pushed, in order
|
|
2953
2981
|
}
|
|
2954
2982
|
|
|
2955
2983
|
function overlay_dismissed(gobj, entry)
|
|
@@ -3259,12 +3287,21 @@ function ac_back_wait_timeout(gobj, event, kw, src)
|
|
|
3259
3287
|
`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not ` +
|
|
3260
3288
|
`land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
|
|
3261
3289
|
);
|
|
3262
|
-
let given_up = {
|
|
3290
|
+
let given_up = {
|
|
3291
|
+
ids: priv.expected_pop_ids.slice(),
|
|
3292
|
+
route: priv.deferred_route,
|
|
3293
|
+
until: Date.now() + LATE_LANDING_WINDOW_MS
|
|
3294
|
+
};
|
|
3263
3295
|
priv.expected_pops = 0;
|
|
3264
3296
|
priv.expected_pop_hash = "";
|
|
3265
3297
|
priv.expected_pop_ids = [];
|
|
3266
3298
|
priv.restore_hash = "";
|
|
3267
|
-
|
|
3299
|
+
/* The markers of the overlays opened during the wait go on top of
|
|
3300
|
+
* the dead one, before the route: a late back() steps back one entry
|
|
3301
|
+
* from the route and lands on the highest of them, not on the dead
|
|
3302
|
+
* marker -- they are its landing too. */
|
|
3303
|
+
let pushed = push_pending_markers(gobj); // and navigates the deferred route
|
|
3304
|
+
given_up.ids.push(...pushed);
|
|
3268
3305
|
priv.given_up = given_up;
|
|
3269
3306
|
return 0;
|
|
3270
3307
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Copyright (c) 2026, ArtGins.
|
|
20
20
|
* All Rights Reserved.
|
|
21
21
|
***********************************************************************/
|
|
22
|
-
import {describe, test, expect, beforeAll, beforeEach, afterEach} from "vitest";
|
|
22
|
+
import {describe, test, expect, beforeAll, beforeEach, afterEach, vi} from "vitest";
|
|
23
23
|
import {install_dom_double} from "../test/dom_double.js";
|
|
24
24
|
|
|
25
25
|
install_dom_double();
|
|
@@ -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__: first.id}); // stamped, no marker
|
|
361
361
|
expect(errors()).toEqual([]);
|
|
362
362
|
});
|
|
363
363
|
|
|
@@ -622,7 +622,7 @@ describe("a routed shell, a realistic history (V5)", () => {
|
|
|
622
622
|
const b = yui_shell_register_overlay(shell, () => {});
|
|
623
623
|
yui_shell_overlay_dismissed(shell, b); // its button: back() to A's marker
|
|
624
624
|
await next_task();
|
|
625
|
-
expect(window.history.state
|
|
625
|
+
expect(window.history.state).toEqual({__yui_overlay__: a.id, __yui_below__: b.id});
|
|
626
626
|
|
|
627
627
|
traverse_to(session.index + 1); // Forward, onto B's dead marker
|
|
628
628
|
expect(closed_a).toBe(0);
|
|
@@ -960,3 +960,85 @@ describe("a back() given up on that lands after all (V7.2)", () => {
|
|
|
960
960
|
expect(shell_warnings().some(m => m.includes("undoes route '/prev'"))).toBe(true);
|
|
961
961
|
});
|
|
962
962
|
});
|
|
963
|
+
|
|
964
|
+
describe("V8: the edges of the stamp and of the late landing", () => {
|
|
965
|
+
test("a late back() lands on the marker of an overlay opened during the wait: said too", async () => {
|
|
966
|
+
const app = gobj_create("v8app1", "C_TEST_MARKER_APP", {}, yuno);
|
|
967
|
+
gobj_start(app);
|
|
968
|
+
window.location.hash = "#/home";
|
|
969
|
+
install_history_model();
|
|
970
|
+
const shell = routed_shell("v8shell1", app);
|
|
971
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
972
|
+
await import("./c_yui_shell.js");
|
|
973
|
+
const x = yui_shell_register_overlay(shell, () => {});
|
|
974
|
+
let late = null;
|
|
975
|
+
window.history.back = () => { late = () => traverse_to(session.index - 1); };
|
|
976
|
+
links_on_hash_assign();
|
|
977
|
+
|
|
978
|
+
yui_shell_overlay_dismissed(shell, x);
|
|
979
|
+
yui_shell_navigate(shell, "/prev");
|
|
980
|
+
const y = yui_shell_register_overlay(shell, () => {}, {keep_on_navigate: true});
|
|
981
|
+
expect(y.marker_pending).toBe(true);
|
|
982
|
+
await new Promise(resolve => setTimeout(resolve, 1100));
|
|
983
|
+
await next_task();
|
|
984
|
+
expect(window.location.hash).toBe("#/prev");
|
|
985
|
+
|
|
986
|
+
late(); // from #/prev onto Y's marker
|
|
987
|
+
await next_task();
|
|
988
|
+
await next_task();
|
|
989
|
+
expect(window.history.state.__yui_overlay__).toBe(y.id);
|
|
990
|
+
expect(shell_warnings().filter(m => m.includes("arriving late")).length).toBe(1);
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
test("a state that is not a plain object is not stamped over, and says so", async () => {
|
|
994
|
+
const app = gobj_create("v8app2", "C_TEST_MARKER_APP", {}, yuno);
|
|
995
|
+
gobj_start(app);
|
|
996
|
+
window.location.hash = "#/home";
|
|
997
|
+
install_history_model();
|
|
998
|
+
const shell = routed_shell("v8shell2", app);
|
|
999
|
+
const {yui_shell_register_overlay} = await import("./c_yui_shell.js");
|
|
1000
|
+
const app_state = new Map([["k", 1]]);
|
|
1001
|
+
window.history.replaceState(app_state, "");
|
|
1002
|
+
logged.length = 0;
|
|
1003
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
1004
|
+
expect(session.entries[0].state).toBe(app_state);
|
|
1005
|
+
expect(shell_warnings().filter(m => m.includes("not a plain object")).length).toBe(1);
|
|
1006
|
+
/* V9.3: no marker, so no Back of the reader's is spent on it. */
|
|
1007
|
+
expect(entry.no_marker).toBe(true);
|
|
1008
|
+
expect(session.entries.length).toBe(1);
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
describe("V9: the warning of a late back() has a window", () => {
|
|
1013
|
+
test("a landing on the dead marker long after giving up is the reader's Back: no warning", async () => {
|
|
1014
|
+
const app = gobj_create("v9app1", "C_TEST_MARKER_APP", {}, yuno);
|
|
1015
|
+
gobj_start(app);
|
|
1016
|
+
window.location.hash = "#/home";
|
|
1017
|
+
install_history_model();
|
|
1018
|
+
const shell = routed_shell("v9shell1", app);
|
|
1019
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed, yui_shell_navigate} =
|
|
1020
|
+
await import("./c_yui_shell.js");
|
|
1021
|
+
const x = yui_shell_register_overlay(shell, () => {});
|
|
1022
|
+
let late = null;
|
|
1023
|
+
window.history.back = () => { late = () => traverse_to(session.index - 1); };
|
|
1024
|
+
links_on_hash_assign();
|
|
1025
|
+
|
|
1026
|
+
yui_shell_overlay_dismissed(shell, x);
|
|
1027
|
+
yui_shell_navigate(shell, "/prev");
|
|
1028
|
+
await new Promise(resolve => setTimeout(resolve, 1100));
|
|
1029
|
+
await next_task();
|
|
1030
|
+
expect(shell_warnings().filter(m => m.includes("given up")).length).toBe(1);
|
|
1031
|
+
|
|
1032
|
+
const now = Date.now();
|
|
1033
|
+
const spy = vi.spyOn(Date, "now").mockImplementation(() => now + 6000);
|
|
1034
|
+
try {
|
|
1035
|
+
late(); // the reader's Back, 6 s later
|
|
1036
|
+
await next_task();
|
|
1037
|
+
await next_task();
|
|
1038
|
+
} finally {
|
|
1039
|
+
spy.mockRestore();
|
|
1040
|
+
}
|
|
1041
|
+
expect(shell_warnings().filter(m => m.includes("arriving late")).length).toBe(0);
|
|
1042
|
+
expect(shell.priv.given_up).toBe(null);
|
|
1043
|
+
});
|
|
1044
|
+
});
|