@yuneta/gobj-ui 7.26.17 → 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,13 +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
|
-
let plain = below !== null && typeof below === "object" &&
|
|
2566
|
+
let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
|
|
2567
|
+
let stamped = false;
|
|
2567
2568
|
if (below === null || plain) try {
|
|
2568
2569
|
window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2570
|
+
stamped = true;
|
|
2569
2571
|
} catch (e) {
|
|
2570
2572
|
(0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2571
2573
|
}
|
|
2572
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
|
+
}
|
|
2573
2579
|
try {
|
|
2574
2580
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2575
2581
|
} catch (e) {
|
|
@@ -2594,6 +2600,7 @@ function drop_expected_pops(gobj) {
|
|
|
2594
2600
|
}
|
|
2595
2601
|
}
|
|
2596
2602
|
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2603
|
+
var LATE_LANDING_WINDOW_MS = 5e3;
|
|
2597
2604
|
function defer_route(gobj, route) {
|
|
2598
2605
|
let priv = gobj.priv;
|
|
2599
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}'`);
|
|
@@ -2608,6 +2615,10 @@ function note_late_landing(gobj, ev) {
|
|
|
2608
2615
|
let priv = gobj.priv;
|
|
2609
2616
|
let given_up = priv.given_up;
|
|
2610
2617
|
let st = ev && ev.state;
|
|
2618
|
+
if (given_up && Date.now() > given_up.until) {
|
|
2619
|
+
priv.given_up = null;
|
|
2620
|
+
return;
|
|
2621
|
+
}
|
|
2611
2622
|
if (!given_up || !st) return;
|
|
2612
2623
|
priv.given_up = null;
|
|
2613
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}'`);
|
|
@@ -2627,7 +2638,7 @@ function push_pending_markers(gobj) {
|
|
|
2627
2638
|
entry.marker_pending = false;
|
|
2628
2639
|
if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
|
|
2629
2640
|
entry.hash = window.location.hash;
|
|
2630
|
-
if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
|
|
2641
|
+
if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
|
|
2631
2642
|
}
|
|
2632
2643
|
clear_deferred_timer(gobj);
|
|
2633
2644
|
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
@@ -2783,7 +2794,8 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
|
|
|
2783
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`);
|
|
2784
2795
|
let given_up = {
|
|
2785
2796
|
ids: priv.expected_pop_ids.slice(),
|
|
2786
|
-
route: priv.deferred_route
|
|
2797
|
+
route: priv.deferred_route,
|
|
2798
|
+
until: Date.now() + LATE_LANDING_WINDOW_MS
|
|
2787
2799
|
};
|
|
2788
2800
|
priv.expected_pops = 0;
|
|
2789
2801
|
priv.expected_pop_hash = "";
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -2558,13 +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
|
-
let plain = below !== null && typeof below === "object" &&
|
|
2561
|
+
let plain = below !== null && typeof below === "object" && Object.getPrototypeOf(below) === Object.prototype;
|
|
2562
|
+
let stamped = false;
|
|
2562
2563
|
if (below === null || plain) try {
|
|
2563
2564
|
window.history.replaceState(Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2565
|
+
stamped = true;
|
|
2564
2566
|
} catch (e) {
|
|
2565
2567
|
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2566
2568
|
}
|
|
2567
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
|
+
}
|
|
2568
2574
|
try {
|
|
2569
2575
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2570
2576
|
} catch (e) {
|
|
@@ -2589,6 +2595,7 @@ function drop_expected_pops(gobj) {
|
|
|
2589
2595
|
}
|
|
2590
2596
|
}
|
|
2591
2597
|
var DEFERRED_ROUTE_WAIT_MS = 1e3;
|
|
2598
|
+
var LATE_LANDING_WINDOW_MS = 5e3;
|
|
2592
2599
|
function defer_route(gobj, route) {
|
|
2593
2600
|
let priv = gobj.priv;
|
|
2594
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}'`);
|
|
@@ -2603,6 +2610,10 @@ function note_late_landing(gobj, ev) {
|
|
|
2603
2610
|
let priv = gobj.priv;
|
|
2604
2611
|
let given_up = priv.given_up;
|
|
2605
2612
|
let st = ev && ev.state;
|
|
2613
|
+
if (given_up && Date.now() > given_up.until) {
|
|
2614
|
+
priv.given_up = null;
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2606
2617
|
if (!given_up || !st) return;
|
|
2607
2618
|
priv.given_up = null;
|
|
2608
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}'`);
|
|
@@ -2622,7 +2633,7 @@ function push_pending_markers(gobj) {
|
|
|
2622
2633
|
entry.marker_pending = false;
|
|
2623
2634
|
if (entry.dismissed || priv.overlay_stack.indexOf(entry) < 0) continue;
|
|
2624
2635
|
entry.hash = window.location.hash;
|
|
2625
|
-
if (push_overlay_marker(gobj, entry)) pushed.push(entry.id);
|
|
2636
|
+
if (push_overlay_marker(gobj, entry) && !entry.no_marker) pushed.push(entry.id);
|
|
2626
2637
|
}
|
|
2627
2638
|
clear_deferred_timer(gobj);
|
|
2628
2639
|
if (priv.expected_pops === 0) priv.expected_pop_ids = [];
|
|
@@ -2778,7 +2789,8 @@ function ac_back_wait_timeout(gobj, event, kw, src) {
|
|
|
2778
2789
|
log_warning(`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`);
|
|
2779
2790
|
let given_up = {
|
|
2780
2791
|
ids: priv.expected_pop_ids.slice(),
|
|
2781
|
-
route: priv.deferred_route
|
|
2792
|
+
route: priv.deferred_route,
|
|
2793
|
+
until: Date.now() + LATE_LANDING_WINDOW_MS
|
|
2782
2794
|
};
|
|
2783
2795
|
priv.expected_pops = 0;
|
|
2784
2796
|
priv.expected_pop_hash = "";
|
package/package.json
CHANGED
|
@@ -34,8 +34,9 @@
|
|
|
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; a replace() whose replacement is a function
|
|
38
|
-
* pattern is a variable,
|
|
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
|
|
39
40
|
* (String(x).replace(...)); markup given to innerHTML, or to a
|
|
40
41
|
* widget (Tabulator, G6), which are other sinks. set_strings_are_text(true) logs, once
|
|
41
42
|
* at run time, every string that reaches createElement2() starting
|
|
@@ -169,7 +170,24 @@ function replaced(method, head, args)
|
|
|
169
170
|
return {text: head.text, complete: false};
|
|
170
171
|
}
|
|
171
172
|
}
|
|
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};
|
|
188
|
+
}
|
|
189
|
+
return {text: head.text, complete: false};
|
|
190
|
+
}
|
|
173
191
|
const idx = first_match(head.text, pattern);
|
|
174
192
|
if(idx >= 0) {
|
|
175
193
|
return {text: head.text.slice(0, idx) + rep_head, complete: false};
|
|
@@ -177,16 +195,17 @@ function replaced(method, head, args)
|
|
|
177
195
|
if(head.complete) {
|
|
178
196
|
return {text: head.text, complete: true}; // no match: the receiver as it is
|
|
179
197
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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++;
|
|
204
|
+
}
|
|
205
|
+
if(keep === 0) {
|
|
206
|
+
return {text: rep_head, complete: false};
|
|
188
207
|
}
|
|
189
|
-
return {text: head.text, complete: false};
|
|
208
|
+
return {text: head.text.slice(0, keep), complete: false};
|
|
190
209
|
}
|
|
191
210
|
|
|
192
211
|
function concat_parts(parts)
|
package/src/c_yui_shell.js
CHANGED
|
@@ -2804,14 +2804,16 @@ function push_overlay_marker(gobj, entry)
|
|
|
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
|
|
2807
|
+
* is a structured clone, so a plain object comes back with
|
|
2808
|
+
* Object.prototype), and Object.assign() copies none of it. */
|
|
2808
2809
|
let plain = below !== null && typeof below === "object" &&
|
|
2809
|
-
|
|
2810
|
-
|
|
2810
|
+
Object.getPrototypeOf(below) === Object.prototype;
|
|
2811
|
+
let stamped = false;
|
|
2811
2812
|
if(below === null || plain) {
|
|
2812
2813
|
try {
|
|
2813
2814
|
window.history.replaceState(
|
|
2814
2815
|
Object.assign({}, below, { __yui_below__: entry.id }), "");
|
|
2816
|
+
stamped = true;
|
|
2815
2817
|
} catch(e) {
|
|
2816
2818
|
log_warning(`C_YUI_SHELL: stamping the entry under an overlay failed: ${e}`);
|
|
2817
2819
|
}
|
|
@@ -2821,6 +2823,13 @@ function push_overlay_marker(gobj, entry)
|
|
|
2821
2823
|
`is not a plain object, it cannot be stamped: Back will not close the overlay`
|
|
2822
2824
|
);
|
|
2823
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
|
+
}
|
|
2824
2833
|
try {
|
|
2825
2834
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2826
2835
|
} catch(e) {
|
|
@@ -2874,6 +2883,11 @@ function drop_expected_pops(gobj)
|
|
|
2874
2883
|
* every later navigation. */
|
|
2875
2884
|
const DEFERRED_ROUTE_WAIT_MS = 1000;
|
|
2876
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
|
+
|
|
2877
2891
|
function defer_route(gobj, route)
|
|
2878
2892
|
{
|
|
2879
2893
|
let priv = gobj.priv;
|
|
@@ -2907,6 +2921,10 @@ function note_late_landing(gobj, ev)
|
|
|
2907
2921
|
let priv = gobj.priv;
|
|
2908
2922
|
let given_up = priv.given_up;
|
|
2909
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
|
+
}
|
|
2910
2928
|
if(!given_up || !st) {
|
|
2911
2929
|
return; // a push (the waiting route's own) lands on a fresh entry
|
|
2912
2930
|
}
|
|
@@ -2945,7 +2963,7 @@ function push_pending_markers(gobj)
|
|
|
2945
2963
|
/* The traversal was same-hash, but a route may have moved
|
|
2946
2964
|
* meanwhile: the marker lives on the hash it is pushed on. */
|
|
2947
2965
|
entry.hash = window.location.hash;
|
|
2948
|
-
if(push_overlay_marker(gobj, entry)) {
|
|
2966
|
+
if(push_overlay_marker(gobj, entry) && !entry.no_marker) {
|
|
2949
2967
|
pushed.push(entry.id);
|
|
2950
2968
|
}
|
|
2951
2969
|
// else: Error already logged
|
|
@@ -3269,7 +3287,11 @@ function ac_back_wait_timeout(gobj, event, kw, src)
|
|
|
3269
3287
|
`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did not ` +
|
|
3270
3288
|
`land in ${DEFERRED_ROUTE_WAIT_MS} ms, given up`
|
|
3271
3289
|
);
|
|
3272
|
-
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
|
+
};
|
|
3273
3295
|
priv.expected_pops = 0;
|
|
3274
3296
|
priv.expected_pop_hash = "";
|
|
3275
3297
|
priv.expected_pop_ids = [];
|
|
@@ -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();
|
|
@@ -1000,8 +1000,45 @@ describe("V8: the edges of the stamp and of the late landing", () => {
|
|
|
1000
1000
|
const app_state = new Map([["k", 1]]);
|
|
1001
1001
|
window.history.replaceState(app_state, "");
|
|
1002
1002
|
logged.length = 0;
|
|
1003
|
-
yui_shell_register_overlay(shell, () => {});
|
|
1003
|
+
const entry = yui_shell_register_overlay(shell, () => {});
|
|
1004
1004
|
expect(session.entries[0].state).toBe(app_state);
|
|
1005
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);
|
|
1006
1043
|
});
|
|
1007
1044
|
});
|