@yuneta/gobj-ui 7.26.48 → 7.26.50
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 +133 -31
- package/dist/gobj-ui.cjs.js +288 -14
- package/dist/gobj-ui.es.js +288 -14
- package/package.json +2 -2
- package/scripts/validate-locales.mjs +734 -76
- package/src/c_yui_form.js +63 -5
- package/src/c_yui_gobj_tree_js.js +37 -4
- package/src/c_yui_shell.css +17 -3
- package/src/c_yui_shell.js +311 -0
- package/src/form_table_rows.wiring.test.js +32 -0
- package/src/form_time_cell_editor.js +20 -5
- package/src/form_time_cell_editor.test.js +73 -0
- package/src/form_time_field.wiring.test.js +71 -0
- package/src/gobj_tree_camera.wiring.test.js +185 -0
- package/src/overlay_marker_after_back.wiring.test.js +3 -0
- package/src/shell_focus_trap.js +21 -0
- package/src/shell_focus_trap.test.js +52 -0
- package/src/shell_history_debt.wiring.test.js +456 -0
package/src/c_yui_form.js
CHANGED
|
@@ -241,14 +241,20 @@ function mt_create(gobj)
|
|
|
241
241
|
function mt_writing(gobj, path)
|
|
242
242
|
{
|
|
243
243
|
if(path === "selectable") {
|
|
244
|
-
/* The checkbox column follows it, in every table built
|
|
244
|
+
/* The checkbox column follows it, in every table built; and
|
|
245
|
+
* what was selected goes, or it would stay selected with no
|
|
246
|
+
* box and no click to take it off (the check refuses both). */
|
|
245
247
|
let $container = gobj_read_attr(gobj, "$container");
|
|
246
248
|
if(!$container) {
|
|
247
249
|
return;
|
|
248
250
|
}
|
|
251
|
+
let selectable = gobj_read_bool_attr(gobj, "selectable");
|
|
249
252
|
for(let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) {
|
|
250
253
|
if($table.tabulator) {
|
|
251
254
|
show_row_selection(gobj, $table.tabulator);
|
|
255
|
+
if(!selectable && $table.tabulator.initialized) {
|
|
256
|
+
$table.tabulator.deselectRow();
|
|
257
|
+
}
|
|
252
258
|
}
|
|
253
259
|
}
|
|
254
260
|
}
|
|
@@ -960,7 +966,7 @@ function build_form(gobj)
|
|
|
960
966
|
function build_html_form(gobj, $form, prefix, template)
|
|
961
967
|
{
|
|
962
968
|
Object.entries(template).forEach(([key, value]) => {
|
|
963
|
-
const field_desc =
|
|
969
|
+
const field_desc = form_template_field_desc(key, value);
|
|
964
970
|
/* The drawing of a user icon (`svg` of __icons__): a text area
|
|
965
971
|
* with the icon it draws below it. */
|
|
966
972
|
if(!prefix && yui_icons_is_svg_field(
|
|
@@ -2207,6 +2213,7 @@ function create_coordinates(gobj, attrs)
|
|
|
2207
2213
|
$input.value = `${longitude}, ${latitude}`;
|
|
2208
2214
|
|
|
2209
2215
|
$input.classList.remove('is-danger');
|
|
2216
|
+
$input.removeAttribute('aria-invalid');
|
|
2210
2217
|
let $h = $input.closest('.xcontrol').parentNode.querySelector('.help');
|
|
2211
2218
|
$h.textContent = '';
|
|
2212
2219
|
$h.style.display = 'none';
|
|
@@ -2234,7 +2241,9 @@ function create_coordinates(gobj, attrs)
|
|
|
2234
2241
|
}
|
|
2235
2242
|
|
|
2236
2243
|
$input.classList.add('is-danger');
|
|
2244
|
+
$input.setAttribute('aria-invalid', 'true');
|
|
2237
2245
|
let $h = $input.closest('.xcontrol').parentNode.querySelector('.help');
|
|
2246
|
+
describe_by_help($input, $h);
|
|
2238
2247
|
$h.textContent = errorMsg;
|
|
2239
2248
|
$h.style.display = 'block';
|
|
2240
2249
|
}
|
|
@@ -2590,7 +2599,7 @@ function table_column_titles(template)
|
|
|
2590
2599
|
{
|
|
2591
2600
|
let titles = {};
|
|
2592
2601
|
Object.entries(template || {}).forEach(([key, value]) => {
|
|
2593
|
-
const field_desc =
|
|
2602
|
+
const field_desc = form_template_field_desc(key, value);
|
|
2594
2603
|
titles[field_desc.name] = column_title(field_desc);
|
|
2595
2604
|
});
|
|
2596
2605
|
return titles;
|
|
@@ -2609,7 +2618,7 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2609
2618
|
/*
|
|
2610
2619
|
* Decode the item in template into html item
|
|
2611
2620
|
*/
|
|
2612
|
-
const field_desc =
|
|
2621
|
+
const field_desc = form_template_field_desc(key, value);
|
|
2613
2622
|
|
|
2614
2623
|
let readonly = !field_desc.is_writable;
|
|
2615
2624
|
let validator = [];
|
|
@@ -2919,6 +2928,26 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2919
2928
|
return columns;
|
|
2920
2929
|
}
|
|
2921
2930
|
|
|
2931
|
+
/************************************************************
|
|
2932
|
+
* A field of the template. A dot-token spec that names a
|
|
2933
|
+
* `time` / `now` type and no real type ("time.writable") is
|
|
2934
|
+
* an epoch, as the real type of a treedb time column is
|
|
2935
|
+
* integer: template_get_field_desc() (gobj-js) gives every
|
|
2936
|
+
* spec without one `string`, and a `string` time column is
|
|
2937
|
+
* an ISO text (form_time_value.js). Since gobj-ui 7.26.47
|
|
2938
|
+
* such a field showed its epoch as no time, and a save of
|
|
2939
|
+
* any field wrote null over it.
|
|
2940
|
+
************************************************************/
|
|
2941
|
+
function form_template_field_desc(key, value)
|
|
2942
|
+
{
|
|
2943
|
+
let field_desc = template_get_field_desc(key, value);
|
|
2944
|
+
if(is_string(value) && (field_desc.type === "time" || field_desc.type === "now") &&
|
|
2945
|
+
!value.split(".").includes(field_desc.real_type)) {
|
|
2946
|
+
field_desc.real_type = "integer";
|
|
2947
|
+
}
|
|
2948
|
+
return field_desc;
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2922
2951
|
/************************************************************
|
|
2923
2952
|
* What is wrong with a field, in the APP's language.
|
|
2924
2953
|
*
|
|
@@ -2986,6 +3015,7 @@ function mark_field_validity($input)
|
|
|
2986
3015
|
|
|
2987
3016
|
if(ok) {
|
|
2988
3017
|
$input.classList.remove('is-danger');
|
|
3018
|
+
$input.removeAttribute('aria-invalid');
|
|
2989
3019
|
if($h) {
|
|
2990
3020
|
$h.textContent = '';
|
|
2991
3021
|
$h.removeAttribute('data-i18n');
|
|
@@ -2994,8 +3024,14 @@ function mark_field_validity($input)
|
|
|
2994
3024
|
return true;
|
|
2995
3025
|
}
|
|
2996
3026
|
|
|
3027
|
+
/* The red outline is for the eye; a reader hears `aria-invalid`
|
|
3028
|
+
* and the line under the box (aria-describedby). Up to gobj-ui
|
|
3029
|
+
* 7.26.48 a field Save refused -- a date with a part cleared, an
|
|
3030
|
+
* empty required box -- said so to the eye only. */
|
|
2997
3031
|
$input.classList.add('is-danger');
|
|
3032
|
+
$input.setAttribute('aria-invalid', 'true');
|
|
2998
3033
|
if($h) {
|
|
3034
|
+
describe_by_help($input, $h);
|
|
2999
3035
|
let key = field_validation_key($input);
|
|
3000
3036
|
if(key) {
|
|
3001
3037
|
$h.setAttribute('data-i18n', /* i18n: C_YUI_FORM_I18N_KEYS, FORM_JSON_FIELD_I18N_KEYS */ key);
|
|
@@ -3008,6 +3044,22 @@ function mark_field_validity($input)
|
|
|
3008
3044
|
return false;
|
|
3009
3045
|
}
|
|
3010
3046
|
|
|
3047
|
+
/* The help line under a box describes it: an id for the line, and
|
|
3048
|
+
* the box's aria-describedby names it (kept with what it held). */
|
|
3049
|
+
let __help_seq__ = 0;
|
|
3050
|
+
|
|
3051
|
+
function describe_by_help($input, $h)
|
|
3052
|
+
{
|
|
3053
|
+
if(!$h.id) {
|
|
3054
|
+
$h.id = `yui-form-help-${++__help_seq__}`;
|
|
3055
|
+
}
|
|
3056
|
+
let ids = ($input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
3057
|
+
if(!ids.includes($h.id)) {
|
|
3058
|
+
ids.push($h.id);
|
|
3059
|
+
$input.setAttribute('aria-describedby', ids.join(' '));
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
|
|
3011
3063
|
/************************************************************
|
|
3012
3064
|
*
|
|
3013
3065
|
************************************************************/
|
|
@@ -3307,12 +3359,18 @@ function clear_data(gobj, $form)
|
|
|
3307
3359
|
************************************************************/
|
|
3308
3360
|
function clear_validation(gobj, $form)
|
|
3309
3361
|
{
|
|
3310
|
-
|
|
3362
|
+
/* Every field mark_field_validity() marks: a textarea and a json
|
|
3363
|
+
* editor stayed red after a clear, as they stay `aria-invalid`. */
|
|
3364
|
+
$form.querySelectorAll('input, .yui-form-data-input').forEach($input => {
|
|
3311
3365
|
$input.classList.remove('is-danger');
|
|
3366
|
+
$input.removeAttribute('aria-invalid');
|
|
3312
3367
|
});
|
|
3313
3368
|
|
|
3369
|
+
/* Its key goes too: a language change re-translates every node
|
|
3370
|
+
* that carries one, and wrote the message back into the line. */
|
|
3314
3371
|
$form.querySelectorAll('.help').forEach($input => {
|
|
3315
3372
|
$input.textContent = '';
|
|
3373
|
+
$input.removeAttribute('data-i18n');
|
|
3316
3374
|
$input.style.display = 'none';
|
|
3317
3375
|
});
|
|
3318
3376
|
|
|
@@ -201,12 +201,15 @@ function restore_view_state(gobj)
|
|
|
201
201
|
let done = false;
|
|
202
202
|
priv.restoring = true;
|
|
203
203
|
try {
|
|
204
|
-
|
|
204
|
+
/* A camera saved by an older version can hold nulls (a NaN
|
|
205
|
+
* written as json): what is not a number is not restored. */
|
|
206
|
+
if(Number.isFinite(state.zoom) && state.zoom > 0) {
|
|
205
207
|
graph.zoomTo(state.zoom);
|
|
206
208
|
priv.last_zoom = state.zoom;
|
|
207
209
|
done = true;
|
|
208
210
|
}
|
|
209
|
-
if(Array.isArray(state.position) && state.position.length >= 2
|
|
211
|
+
if(Array.isArray(state.position) && state.position.length >= 2 &&
|
|
212
|
+
Number.isFinite(state.position[0]) && Number.isFinite(state.position[1])) {
|
|
210
213
|
graph.translateTo([state.position[0], state.position[1]]);
|
|
211
214
|
done = true;
|
|
212
215
|
}
|
|
@@ -243,16 +246,46 @@ function save_view_state(gobj)
|
|
|
243
246
|
collapsed: priv.collapse_state || {},
|
|
244
247
|
anchor: (priv.anchor_state === "on")? priv.anchor_name: "",
|
|
245
248
|
};
|
|
249
|
+
let camera = null;
|
|
246
250
|
try {
|
|
247
|
-
|
|
248
|
-
state.position = graph.getPosition();
|
|
251
|
+
camera = camera_of(graph.getZoom(), graph.getPosition());
|
|
249
252
|
} catch(e) {
|
|
250
253
|
/* between renders: keep the rest, the camera is not readable */
|
|
251
254
|
}
|
|
255
|
+
if(!camera) {
|
|
256
|
+
/* Not readable, or not numbers yet (G6 answers NaN before it
|
|
257
|
+
* paints): the camera saved before stays. Written as it came,
|
|
258
|
+
* a NaN was saved as null (it has no json text), and gobj-js
|
|
259
|
+
* 7.26.27 refuses the whole value with an ERROR. */
|
|
260
|
+
let old = load_view_state(gobj);
|
|
261
|
+
camera = old? camera_of(old.zoom, old.position) : null;
|
|
262
|
+
}
|
|
263
|
+
if(camera) {
|
|
264
|
+
state.zoom = camera.zoom;
|
|
265
|
+
state.position = camera.position;
|
|
266
|
+
}
|
|
252
267
|
|
|
253
268
|
kw_set_local_storage_value(view_store_key(gobj), state);
|
|
254
269
|
}
|
|
255
270
|
|
|
271
|
+
/* A camera that can be saved and restored: a zoom above 0 and a
|
|
272
|
+
* position of two finite numbers; null otherwise. */
|
|
273
|
+
function camera_of(zoom, position)
|
|
274
|
+
{
|
|
275
|
+
if(!(Number.isFinite(zoom) && zoom > 0)) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
if(!position || typeof position.length !== "number" || position.length < 2) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
let x = position[0];
|
|
282
|
+
let y = position[1];
|
|
283
|
+
if(!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
return {zoom: zoom, position: [x, y]};
|
|
287
|
+
}
|
|
288
|
+
|
|
256
289
|
function load_view_state(gobj)
|
|
257
290
|
{
|
|
258
291
|
let state = kw_get_local_storage_value(view_store_key(gobj), null, false);
|
package/src/c_yui_shell.css
CHANGED
|
@@ -514,8 +514,6 @@
|
|
|
514
514
|
white-space: nowrap;
|
|
515
515
|
background-color: var(--bulma-danger, #f14668);
|
|
516
516
|
color: var(--bulma-danger-invert, #fff);
|
|
517
|
-
/* Separates the pill from the glyph when they overlap. */
|
|
518
|
-
box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
|
|
519
517
|
pointer-events: none;
|
|
520
518
|
}
|
|
521
519
|
.yui-badge[hidden] {
|
|
@@ -556,14 +554,24 @@
|
|
|
556
554
|
top: -0.35em;
|
|
557
555
|
right: -0.55em;
|
|
558
556
|
font-size: 0.62em;
|
|
557
|
+
/* Separates the dot from the glyph it overlaps. */
|
|
558
|
+
box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
/* Menu item: after the label
|
|
561
|
+
/* Menu item: after the label, a pill of the size of a Bulma tag
|
|
562
|
+
* (as gobj-ui v1 drew it), with no ring: nothing under it to keep
|
|
563
|
+
* apart, and on the colour of an active item a ring of the page's
|
|
564
|
+
* colour read as a dark circle that ate the tone -- red and yellow
|
|
565
|
+
* were hard to tell at that size. Sized in rem, so it is the same
|
|
562
566
|
* pill in every layout whatever the item's own font size. */
|
|
563
567
|
.yui-nav-badge {
|
|
564
568
|
flex: 0 0 auto;
|
|
565
569
|
margin-inline-start: 0.4rem;
|
|
566
570
|
font-size: 0.75rem;
|
|
571
|
+
min-width: 2em;
|
|
572
|
+
height: 2em;
|
|
573
|
+
padding: 0 0.75em;
|
|
574
|
+
font-weight: 400;
|
|
567
575
|
vertical-align: middle;
|
|
568
576
|
}
|
|
569
577
|
/* Where the item already spaces its children (a flex row or column
|
|
@@ -585,6 +593,12 @@
|
|
|
585
593
|
inset-inline-end: -0.55em;
|
|
586
594
|
margin: 0;
|
|
587
595
|
font-size: 0.7rem;
|
|
596
|
+
min-width: 1.15em;
|
|
597
|
+
height: 1.15em;
|
|
598
|
+
padding: 0 0.3em;
|
|
599
|
+
font-weight: 700;
|
|
600
|
+
/* Separates the dot from the glyph it overlaps. */
|
|
601
|
+
box-shadow: 0 0 0 0.12em var(--bulma-scheme-main, #fff);
|
|
588
602
|
}
|
|
589
603
|
|
|
590
604
|
/*============================================================
|
package/src/c_yui_shell.js
CHANGED
|
@@ -99,6 +99,20 @@ let __live_shells__ = [];
|
|
|
99
99
|
* reads it). */
|
|
100
100
|
let __retiring_shell__ = null;
|
|
101
101
|
|
|
102
|
+
/* The session-history entries a stopped shell left behind, by their
|
|
103
|
+
* navigation key (the Navigation API's, which a replaceState keeps):
|
|
104
|
+
* the markers of its overlays and the action entries of its `stay`
|
|
105
|
+
* routes. They are dead -- nothing closes or opens on them any more --
|
|
106
|
+
* and the next shell takes them off with ONE history.go(-n) at its
|
|
107
|
+
* start, heard by its own expected_pops (retire_dead_entries()). A
|
|
108
|
+
* stopped shell moves no history: it would not hear the landing. */
|
|
109
|
+
let __dead_entries__ = new Set();
|
|
110
|
+
|
|
111
|
+
/* A history.back() of a shell that stopped before it landed. Nothing
|
|
112
|
+
* hears it but a passive count; a shell started meanwhile adopts it,
|
|
113
|
+
* so its own markers wait for that landing (adopt_orphan_back()). */
|
|
114
|
+
let __orphan_back__ = null;
|
|
115
|
+
|
|
102
116
|
/* The gobjs that keep DOM in a shell's layers without being its
|
|
103
117
|
* children: a C_YUI_WINDOW parented to the app, the dock of
|
|
104
118
|
* C_YUI_WINDOW_MANAGER. Each is sent EV_SHELL_CHANGED when a shell is
|
|
@@ -238,6 +252,10 @@ let PRIVATE_DATA = {
|
|
|
238
252
|
* them is given up -- what to say if one lands after all. */
|
|
239
253
|
expected_pop_ids: [],
|
|
240
254
|
given_up: null,
|
|
255
|
+
/* The navigation keys of the entries this shell made: its overlay
|
|
256
|
+
* markers and the action entries of its `stay` routes. Dead once
|
|
257
|
+
* it stops (__dead_entries__). */
|
|
258
|
+
own_entries: [],
|
|
241
259
|
popstate_handler: null,
|
|
242
260
|
/* Avatar item support — every toolbar item with type:"avatar"
|
|
243
261
|
* registers its <span> here so refresh_avatars() can repaint
|
|
@@ -446,6 +464,9 @@ function mt_start(gobj)
|
|
|
446
464
|
}
|
|
447
465
|
}
|
|
448
466
|
p.restore_hash = "";
|
|
467
|
+
if(retire_dead_entries(gobj)) {
|
|
468
|
+
return; // the markers wait for that landing too
|
|
469
|
+
}
|
|
449
470
|
push_pending_markers(gobj);
|
|
450
471
|
}
|
|
451
472
|
return;
|
|
@@ -525,6 +546,8 @@ function mt_start(gobj)
|
|
|
525
546
|
}
|
|
526
547
|
};
|
|
527
548
|
window.addEventListener("popstate", priv.popstate_handler);
|
|
549
|
+
keep_dead_entries_across_reload();
|
|
550
|
+
adopt_orphan_back(gobj);
|
|
528
551
|
}
|
|
529
552
|
|
|
530
553
|
/* Global Escape: route to the top handler of the escape stack,
|
|
@@ -572,6 +595,13 @@ function mt_start(gobj)
|
|
|
572
595
|
"shell.stages.<name>.default_route, or navigate via hash"
|
|
573
596
|
);
|
|
574
597
|
}
|
|
598
|
+
|
|
599
|
+
/* After the first route, which reads the URL now (a stop rewrote
|
|
600
|
+
* it in place, yui_shell_unpark_route): the traversal is
|
|
601
|
+
* asynchronous, and the position is put back where it lands. */
|
|
602
|
+
if(priv.popstate_handler) {
|
|
603
|
+
retire_dead_entries(gobj);
|
|
604
|
+
}
|
|
575
605
|
}
|
|
576
606
|
|
|
577
607
|
/***************************************************************
|
|
@@ -590,6 +620,9 @@ function mt_stop(gobj)
|
|
|
590
620
|
* shell. */
|
|
591
621
|
retire_overlays(gobj);
|
|
592
622
|
close_toolbar_dropdown(gobj);
|
|
623
|
+
if(priv.popstate_handler) {
|
|
624
|
+
hand_over_history(gobj);
|
|
625
|
+
}
|
|
593
626
|
|
|
594
627
|
if(priv.hash_handler) {
|
|
595
628
|
window.removeEventListener("hashchange", priv.hash_handler);
|
|
@@ -1613,6 +1646,12 @@ function navigate_to(gobj, route, depth, no_drain)
|
|
|
1613
1646
|
* entry. no_drain: internal fix-up hop, not a
|
|
1614
1647
|
* resting navigation. */
|
|
1615
1648
|
navigate_to(gobj, prev, depth + 1, true);
|
|
1649
|
+
/* The entry rewritten is a resting one now, whatever
|
|
1650
|
+
* it was in an earlier load (a reload on a marker). */
|
|
1651
|
+
let key = current_entry_key();
|
|
1652
|
+
if(key) {
|
|
1653
|
+
__dead_entries__.delete(key);
|
|
1654
|
+
}
|
|
1616
1655
|
let h = route_to_hash(route);
|
|
1617
1656
|
try {
|
|
1618
1657
|
window.history.pushState(null, "", h);
|
|
@@ -1624,6 +1663,11 @@ function navigate_to(gobj, route, depth, no_drain)
|
|
|
1624
1663
|
* hash — the URL stays where the user sees it, and
|
|
1625
1664
|
* nothing was restored, so there is no ordering to
|
|
1626
1665
|
* keep: the event just fires. */
|
|
1666
|
+
/* The action entry, when the URL sits on it: dead
|
|
1667
|
+
* once a stop closes the overlay (hand_over_history). */
|
|
1668
|
+
if(window.location.hash === route_to_hash(route)) {
|
|
1669
|
+
note_own_entry(gobj);
|
|
1670
|
+
}
|
|
1627
1671
|
}
|
|
1628
1672
|
publish_action();
|
|
1629
1673
|
return;
|
|
@@ -2836,6 +2880,265 @@ function retire_overlays(gobj)
|
|
|
2836
2880
|
}
|
|
2837
2881
|
}
|
|
2838
2882
|
|
|
2883
|
+
/************************************************************
|
|
2884
|
+
* The history a shell that stops leaves to the next one.
|
|
2885
|
+
*
|
|
2886
|
+
* Its markers and the action entries of its `stay` routes
|
|
2887
|
+
* are dead now: a Back onto one closes nothing (up to gobj-ui
|
|
2888
|
+
* 7.26.48 they stayed, one more dead Back per overlay and per
|
|
2889
|
+
* logout, accumulating). It cannot take them off itself: a
|
|
2890
|
+
* back() is asynchronous and it no longer hears where it
|
|
2891
|
+
* lands. They go to __dead_entries__, and the next shell takes
|
|
2892
|
+
* them off at its start (retire_dead_entries()). A back() of
|
|
2893
|
+
* its own still in flight goes to __orphan_back__, which a
|
|
2894
|
+
* shell started before it lands adopts.
|
|
2895
|
+
*
|
|
2896
|
+
* A page with no next shell keeps them: with no router on the
|
|
2897
|
+
* page, a Back over the app's own entries changes nothing on
|
|
2898
|
+
* screen anyway, and the next shell retires them all the same.
|
|
2899
|
+
************************************************************/
|
|
2900
|
+
function hand_over_history(gobj)
|
|
2901
|
+
{
|
|
2902
|
+
let priv = gobj.priv;
|
|
2903
|
+
for(let key of priv.own_entries) {
|
|
2904
|
+
__dead_entries__.add(key);
|
|
2905
|
+
}
|
|
2906
|
+
priv.own_entries = [];
|
|
2907
|
+
|
|
2908
|
+
if(priv.expected_pops > 0) {
|
|
2909
|
+
if(__orphan_back__) {
|
|
2910
|
+
drop_orphan_back("another shell stopped with a back() in flight");
|
|
2911
|
+
}
|
|
2912
|
+
let orphan = {
|
|
2913
|
+
pops: priv.expected_pops,
|
|
2914
|
+
hash: priv.expected_pop_hash,
|
|
2915
|
+
restore_hash: priv.restore_hash,
|
|
2916
|
+
ids: priv.expected_pop_ids.slice(),
|
|
2917
|
+
/* A monotonic clock, as given_up's. */
|
|
2918
|
+
since: performance.now(),
|
|
2919
|
+
listener: null
|
|
2920
|
+
};
|
|
2921
|
+
/* Only counts the landing: with no shell to restore a
|
|
2922
|
+
* position on screen, the URL is put back as a shell would. */
|
|
2923
|
+
orphan.listener = () => {
|
|
2924
|
+
orphan.pops--;
|
|
2925
|
+
if(orphan.pops > 0) {
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2928
|
+
if(orphan.restore_hash && window.location.hash !== orphan.restore_hash) {
|
|
2929
|
+
try {
|
|
2930
|
+
window.history.replaceState(window.history.state, "", orphan.restore_hash);
|
|
2931
|
+
} catch(e) {
|
|
2932
|
+
log_warning(`C_YUI_SHELL: restoring '${orphan.restore_hash}' failed: ${e}`);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
drop_orphan_back(null);
|
|
2936
|
+
};
|
|
2937
|
+
window.addEventListener("popstate", orphan.listener);
|
|
2938
|
+
__orphan_back__ = orphan;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
function drop_orphan_back(reason)
|
|
2943
|
+
{
|
|
2944
|
+
let orphan = __orphan_back__;
|
|
2945
|
+
if(!orphan) {
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
__orphan_back__ = null;
|
|
2949
|
+
window.removeEventListener("popstate", orphan.listener);
|
|
2950
|
+
if(reason) {
|
|
2951
|
+
log_warning(`C_YUI_SHELL: a back() of a stopped shell is no longer waited for: ${reason}`);
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
/************************************************************
|
|
2956
|
+
* A shell that starts while a back() of a stopped one is in
|
|
2957
|
+
* flight waits for it as for one of its own: an overlay it
|
|
2958
|
+
* opens meanwhile gets its marker after the landing, and a
|
|
2959
|
+
* route it pushes runs after it. Pushed before, Chromium runs
|
|
2960
|
+
* the traversal from the new entry and Firefox drops it.
|
|
2961
|
+
************************************************************/
|
|
2962
|
+
function adopt_orphan_back(gobj)
|
|
2963
|
+
{
|
|
2964
|
+
let orphan = __orphan_back__;
|
|
2965
|
+
if(!orphan) {
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
if(performance.now() - orphan.since > DEFERRED_ROUTE_WAIT_MS) {
|
|
2969
|
+
drop_orphan_back(`it did not land in ${DEFERRED_ROUTE_WAIT_MS} ms`);
|
|
2970
|
+
return;
|
|
2971
|
+
}
|
|
2972
|
+
__orphan_back__ = null;
|
|
2973
|
+
window.removeEventListener("popstate", orphan.listener);
|
|
2974
|
+
let priv = gobj.priv;
|
|
2975
|
+
priv.expected_pops = orphan.pops;
|
|
2976
|
+
priv.expected_pop_hash = orphan.hash;
|
|
2977
|
+
priv.restore_hash = orphan.restore_hash;
|
|
2978
|
+
priv.expected_pop_ids = orphan.ids;
|
|
2979
|
+
arm_back_wait(gobj);
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
/************************************************************
|
|
2983
|
+
* A reload is a shell going away with its overlays up, and
|
|
2984
|
+
* no stop: the entries it made stay in the session history,
|
|
2985
|
+
* and they are entries of the new document too (a Back onto
|
|
2986
|
+
* one is a popstate, not a load). Their keys are kept in the
|
|
2987
|
+
* tab's sessionStorage when the page goes, and the first
|
|
2988
|
+
* shell of the new document takes them off as a stop's.
|
|
2989
|
+
************************************************************/
|
|
2990
|
+
const DEAD_ENTRIES_STORAGE_KEY = "yui_shell_dead_entries";
|
|
2991
|
+
let __dead_entries_kept__ = false;
|
|
2992
|
+
|
|
2993
|
+
function keep_dead_entries_across_reload()
|
|
2994
|
+
{
|
|
2995
|
+
if(__dead_entries_kept__) {
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
__dead_entries_kept__ = true;
|
|
2999
|
+
let storage = null;
|
|
3000
|
+
try {
|
|
3001
|
+
storage = window.sessionStorage;
|
|
3002
|
+
} catch(e) {
|
|
3003
|
+
log_warning(`C_YUI_SHELL: no sessionStorage, a reload keeps its dead history entries: ${e}`);
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
if(!storage) {
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
let raw = null;
|
|
3010
|
+
try {
|
|
3011
|
+
raw = storage.getItem(DEAD_ENTRIES_STORAGE_KEY);
|
|
3012
|
+
storage.removeItem(DEAD_ENTRIES_STORAGE_KEY);
|
|
3013
|
+
} catch(e) {
|
|
3014
|
+
log_warning(`C_YUI_SHELL: reading the dead history entries of the last load failed: ${e}`);
|
|
3015
|
+
}
|
|
3016
|
+
if(raw) {
|
|
3017
|
+
let keys = null;
|
|
3018
|
+
try {
|
|
3019
|
+
keys = JSON.parse(raw);
|
|
3020
|
+
} catch(e) {
|
|
3021
|
+
log_warning(`C_YUI_SHELL: the dead history entries of the last load are not json: ${e}`);
|
|
3022
|
+
}
|
|
3023
|
+
if(Array.isArray(keys)) {
|
|
3024
|
+
for(let key of keys) {
|
|
3025
|
+
if(typeof key === "string") {
|
|
3026
|
+
__dead_entries__.add(key);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
window.addEventListener("pagehide", () => {
|
|
3032
|
+
let keys = new Set(__dead_entries__);
|
|
3033
|
+
for(let shell of __live_shells__) {
|
|
3034
|
+
for(let key of (shell.priv && shell.priv.own_entries) || []) {
|
|
3035
|
+
keys.add(key);
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
try {
|
|
3039
|
+
if(keys.size > 0) {
|
|
3040
|
+
storage.setItem(DEAD_ENTRIES_STORAGE_KEY, JSON.stringify([...keys]));
|
|
3041
|
+
} else {
|
|
3042
|
+
storage.removeItem(DEAD_ENTRIES_STORAGE_KEY);
|
|
3043
|
+
}
|
|
3044
|
+
} catch(e) {
|
|
3045
|
+
log_warning(`C_YUI_SHELL: keeping the dead history entries for the next load failed: ${e}`);
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/* The key of the current session-history entry, or null without the
|
|
3051
|
+
* Navigation API (then nothing is retired: the dead entries stay, as
|
|
3052
|
+
* up to gobj-ui 7.26.48). */
|
|
3053
|
+
function current_entry_key()
|
|
3054
|
+
{
|
|
3055
|
+
let nav = window.navigation;
|
|
3056
|
+
if(!nav || !nav.currentEntry || typeof nav.entries !== "function") {
|
|
3057
|
+
return null;
|
|
3058
|
+
}
|
|
3059
|
+
return nav.currentEntry.key || null;
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
/* The current entry is this shell's: a marker it pushed, or the entry
|
|
3063
|
+
* of a `stay` route it parked an overlay on. */
|
|
3064
|
+
const OWN_ENTRIES_PRUNE_AT = 64;
|
|
3065
|
+
|
|
3066
|
+
function note_own_entry(gobj)
|
|
3067
|
+
{
|
|
3068
|
+
let priv = gobj.priv;
|
|
3069
|
+
let key = current_entry_key();
|
|
3070
|
+
if(!key || priv.own_entries.includes(key)) {
|
|
3071
|
+
return;
|
|
3072
|
+
}
|
|
3073
|
+
priv.own_entries.push(key);
|
|
3074
|
+
if(priv.own_entries.length > OWN_ENTRIES_PRUNE_AT) {
|
|
3075
|
+
/* Entries cut off by a push are gone for good. */
|
|
3076
|
+
let alive = new Set(window.navigation.entries().map(e => e.key));
|
|
3077
|
+
priv.own_entries = priv.own_entries.filter(k => alive.has(k));
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
/************************************************************
|
|
3082
|
+
* Take off, with ONE history.go(-n), the dead entries a
|
|
3083
|
+
* stopped shell left under the current one (hand_over_history).
|
|
3084
|
+
* The walk stops at the first entry that is not dead, so it
|
|
3085
|
+
* never goes past an entry of the reader's. The traversal is
|
|
3086
|
+
* this shell's own (expected_pops): its overlays' markers and
|
|
3087
|
+
* the routes it pushes wait for the landing, and a position
|
|
3088
|
+
* the URL holds is put back on the entry it lands on, as for
|
|
3089
|
+
* any back() of ours (restore_hash). Returns true when it
|
|
3090
|
+
* went.
|
|
3091
|
+
************************************************************/
|
|
3092
|
+
function retire_dead_entries(gobj)
|
|
3093
|
+
{
|
|
3094
|
+
let priv = gobj.priv;
|
|
3095
|
+
if(__dead_entries__.size === 0 || priv.expected_pops > 0 ||
|
|
3096
|
+
!priv.popstate_handler || !current_entry_key()) {
|
|
3097
|
+
return false;
|
|
3098
|
+
}
|
|
3099
|
+
let nav = window.navigation;
|
|
3100
|
+
let entries = nav.entries();
|
|
3101
|
+
let index = nav.currentEntry.index;
|
|
3102
|
+
let alive = new Set(entries.map(e => e.key));
|
|
3103
|
+
for(let key of __dead_entries__) {
|
|
3104
|
+
if(!alive.has(key)) {
|
|
3105
|
+
__dead_entries__.delete(key);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
let landing = index;
|
|
3109
|
+
while(landing > 0 && __dead_entries__.has(entries[landing].key)) {
|
|
3110
|
+
landing--;
|
|
3111
|
+
}
|
|
3112
|
+
let steps = index - landing;
|
|
3113
|
+
if(steps === 0) {
|
|
3114
|
+
return false;
|
|
3115
|
+
}
|
|
3116
|
+
let landing_hash = "";
|
|
3117
|
+
try {
|
|
3118
|
+
landing_hash = new URL(entries[landing].url).hash;
|
|
3119
|
+
} catch(e) {
|
|
3120
|
+
log_warning(`C_YUI_SHELL: the entry under the dead ones has no url: ${e}`);
|
|
3121
|
+
return false;
|
|
3122
|
+
}
|
|
3123
|
+
for(let i = landing + 1; i <= index; i++) {
|
|
3124
|
+
__dead_entries__.delete(entries[i].key);
|
|
3125
|
+
}
|
|
3126
|
+
priv.expected_pops++;
|
|
3127
|
+
priv.expected_pop_hash = landing_hash;
|
|
3128
|
+
priv.restore_hash = (window.location.hash !== landing_hash)? window.location.hash : "";
|
|
3129
|
+
try {
|
|
3130
|
+
window.history.go(-steps);
|
|
3131
|
+
} catch(e) {
|
|
3132
|
+
priv.expected_pops--;
|
|
3133
|
+
priv.restore_hash = "";
|
|
3134
|
+
log_warning(`C_YUI_SHELL: retiring ${steps} dead history entries failed: ${e}`);
|
|
3135
|
+
return false;
|
|
3136
|
+
}
|
|
3137
|
+
clear_deferred_timer(gobj); // a wait that just ended goes on: bound it again
|
|
3138
|
+
arm_back_wait(gobj);
|
|
3139
|
+
return true;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
2839
3142
|
function pop_escape(gobj, handler)
|
|
2840
3143
|
{
|
|
2841
3144
|
let priv = gobj.priv;
|
|
@@ -3033,6 +3336,7 @@ function push_overlay_marker(gobj, entry)
|
|
|
3033
3336
|
}
|
|
3034
3337
|
try {
|
|
3035
3338
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
3339
|
+
note_own_entry(gobj);
|
|
3036
3340
|
} catch(e) {
|
|
3037
3341
|
/* pushState failed (rare): drop the entry so overlay_dismissed
|
|
3038
3342
|
* won't later history.back() past a real route. */
|
|
@@ -3099,6 +3403,13 @@ function defer_route(gobj, route)
|
|
|
3099
3403
|
);
|
|
3100
3404
|
}
|
|
3101
3405
|
priv.deferred_route = route;
|
|
3406
|
+
arm_back_wait(gobj);
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
/* Bound the wait for a traversal of ours that may never land. */
|
|
3410
|
+
function arm_back_wait(gobj)
|
|
3411
|
+
{
|
|
3412
|
+
let priv = gobj.priv;
|
|
3102
3413
|
if(!priv.deferred_timer) {
|
|
3103
3414
|
/* The timer only says that the time is up: the giving up is
|
|
3104
3415
|
* an action of the FSM (ac_back_wait_timeout). */
|