@yuneta/gobj-ui 7.26.11 → 7.26.12
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 +14 -8
- package/dist/gobj-ui.cjs.js +34 -13
- package/dist/gobj-ui.es.js +34 -13
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +122 -28
- package/src/c_g6_nodes_tree.js +23 -6
- package/src/c_yui_gclass.js +2 -2
- package/src/c_yui_shell.js +33 -5
- package/src/c_yui_treedb_graph.js +2 -1
- package/src/gclass_head_text.wiring.test.js +63 -0
- package/src/overlay_marker_after_back.wiring.test.js +103 -13
package/README.md
CHANGED
|
@@ -3350,16 +3350,22 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
|
|
|
3350
3350
|
must declare as a devDependency (npm does not install a dependency's
|
|
3351
3351
|
devDependencies). It lists a markup string literal in a description
|
|
3352
3352
|
(`literal`, wrap it in `html_markup()`), markup built with values
|
|
3353
|
-
(`built`: a template, a `+`
|
|
3354
|
-
`
|
|
3353
|
+
(`built`: a template, `String.raw`, a `+` chain, `.concat()`, a
|
|
3354
|
+
`[...].join()`, or a string method such as `.trim()` over one of those,
|
|
3355
|
+
whose STATIC head starts with `<` — empty pieces before it are skipped;
|
|
3356
|
+
build the element with `createElement2()` and pass the value as text),
|
|
3357
|
+
a markup string in a list
|
|
3355
3358
|
of children (`in-list`, which is text since gobj-js 7.26.2) and a list of
|
|
3356
3359
|
children whose first item is a markup string (`list-head`: such a list is
|
|
3357
|
-
read as one description). A ternary
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
the
|
|
3360
|
+
read as one description). A ternary, `||`/`&&`/`??` and a comma
|
|
3361
|
+
sequence (its last item) are checked branch by branch; a tag is matched
|
|
3362
|
+
in any case. It CANNOT see: a variable or a function result that holds
|
|
3363
|
+
a string (a helper that returns markup); a template whose head is an
|
|
3364
|
+
expression that is not a static string (`` `${prefix}<b>` ``); a
|
|
3365
|
+
description built piece by piece (`push()` into the content list); a
|
|
3366
|
+
computed tag with an attrs slot that is not an object literal; markup
|
|
3367
|
+
given to `innerHTML` or to a widget (Tabulator, G6). Step 3 is the check
|
|
3368
|
+
for those. A path that does not exist exits with 2 and a message.
|
|
3363
3369
|
2. Call `set_strings_are_text(true)` before the first `createElement2()`.
|
|
3364
3370
|
3. Walk the app and read the console: each string that starts with `<` is
|
|
3365
3371
|
logged once (*"use html_markup() if it is markup"*). A logged string is
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -1023,15 +1023,29 @@ function mt_start$20(gobj) {
|
|
|
1023
1023
|
if ((0, _yuneta_gobj_js.gobj_read_attr)(gobj, "use_hash")) {
|
|
1024
1024
|
priv.hash_handler = () => {
|
|
1025
1025
|
let p = gobj.priv;
|
|
1026
|
-
|
|
1026
|
+
let dropped = false;
|
|
1027
|
+
if (p && p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1028
|
+
drop_expected_pops(gobj);
|
|
1029
|
+
dropped = true;
|
|
1030
|
+
}
|
|
1027
1031
|
let route = hash_to_route(window.location.hash);
|
|
1028
1032
|
if (!(0, _yuneta_gobj_js.empty_string)(route)) navigate_to(gobj, route);
|
|
1033
|
+
if (dropped) push_pending_markers(gobj);
|
|
1029
1034
|
};
|
|
1030
1035
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
1031
1036
|
priv.popstate_handler = (ev) => {
|
|
1032
1037
|
let p = gobj.priv;
|
|
1033
1038
|
if (!p) return;
|
|
1034
|
-
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash)
|
|
1039
|
+
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1040
|
+
drop_expected_pops(gobj);
|
|
1041
|
+
on_traversal(ev);
|
|
1042
|
+
push_pending_markers(gobj);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
on_traversal(ev);
|
|
1046
|
+
};
|
|
1047
|
+
let on_traversal = (ev) => {
|
|
1048
|
+
let p = gobj.priv;
|
|
1035
1049
|
if (p.expected_pops > 0) {
|
|
1036
1050
|
p.expected_pops--;
|
|
1037
1051
|
if (p.expected_pops === 0) push_pending_markers(gobj);
|
|
@@ -1039,6 +1053,7 @@ function mt_start$20(gobj) {
|
|
|
1039
1053
|
}
|
|
1040
1054
|
if (p.overlay_stack.length === 0) return;
|
|
1041
1055
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
1056
|
+
if (top.marker_pending) return;
|
|
1042
1057
|
if (window.location.hash !== top.hash) return;
|
|
1043
1058
|
let st = ev && ev.state;
|
|
1044
1059
|
if (st && st.__yui_overlay__ === top.id) return;
|
|
@@ -2493,6 +2508,7 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2493
2508
|
}
|
|
2494
2509
|
function push_overlay_marker(gobj, entry) {
|
|
2495
2510
|
let priv = gobj.priv;
|
|
2511
|
+
entry.below_hash = window.location.hash;
|
|
2496
2512
|
try {
|
|
2497
2513
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2498
2514
|
} catch (e) {
|
|
@@ -2509,7 +2525,6 @@ function drop_expected_pops(gobj) {
|
|
|
2509
2525
|
(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`);
|
|
2510
2526
|
priv.expected_pops = 0;
|
|
2511
2527
|
priv.expected_pop_hash = "";
|
|
2512
|
-
push_pending_markers(gobj);
|
|
2513
2528
|
}
|
|
2514
2529
|
function push_pending_markers(gobj) {
|
|
2515
2530
|
let priv = gobj.priv;
|
|
@@ -2532,7 +2547,7 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2532
2547
|
let st = window.history.state;
|
|
2533
2548
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2534
2549
|
priv.expected_pops++;
|
|
2535
|
-
priv.expected_pop_hash = window.location.hash;
|
|
2550
|
+
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2536
2551
|
try {
|
|
2537
2552
|
window.history.back();
|
|
2538
2553
|
} catch (e) {
|
|
@@ -19057,7 +19072,7 @@ function build_head(gobj, model) {
|
|
|
19057
19072
|
let items = [[
|
|
19058
19073
|
"span",
|
|
19059
19074
|
{ class: "GCLASS_NAME" },
|
|
19060
|
-
model.id || (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "gclass_name") || "?"
|
|
19075
|
+
text_node(model.id || (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "gclass_name") || "?")
|
|
19061
19076
|
]];
|
|
19062
19077
|
if (model.instances !== null) items.push([
|
|
19063
19078
|
"span",
|
|
@@ -19088,7 +19103,7 @@ function build_head(gobj, model) {
|
|
|
19088
19103
|
title: (0, i18next.t)("current state"),
|
|
19089
19104
|
"data-i18n-title": "current state"
|
|
19090
19105
|
},
|
|
19091
|
-
current
|
|
19106
|
+
text_node(current)
|
|
19092
19107
|
]);
|
|
19093
19108
|
return [
|
|
19094
19109
|
"div",
|
|
@@ -60619,14 +60634,14 @@ var YuiToolbar = class extends _antv_g6.Toolbar {
|
|
|
60619
60634
|
async getDOMContent() {
|
|
60620
60635
|
return (await this.options.getItems()).map((item) => {
|
|
60621
60636
|
if (item.separator) return `<div class="g6-toolbar-sep" aria-hidden="true"></div>`;
|
|
60622
|
-
const extra_class = item.className ? ` ${item.className}` : "";
|
|
60623
|
-
const title = item.title ?? "";
|
|
60624
|
-
if (item.readout) return `<div class="g6-toolbar-readout${extra_class}" title="${title}" aria-label="${title}">${item.text ?? ""}</div>`;
|
|
60637
|
+
const extra_class = item.className ? ` ${(0, _yuneta_gobj_js.escapeHtml)(String(item.className))}` : "";
|
|
60638
|
+
const title = (0, _yuneta_gobj_js.escapeHtml)(String(item.title ?? ""));
|
|
60639
|
+
if (item.readout) return `<div class="g6-toolbar-readout${extra_class}" title="${title}" aria-label="${title}">${(0, _yuneta_gobj_js.escapeHtml)(String(item.text ?? ""))}</div>`;
|
|
60625
60640
|
const disabled = item.disabled ? " disabled" : "";
|
|
60626
60641
|
const is_text = item.text !== void 0;
|
|
60627
60642
|
const kind_class = is_text ? " g6-toolbar-item-text" : "";
|
|
60628
|
-
const body = is_text ? `<span class="g6-toolbar-text">${(0, _yuneta_gobj_js.escapeHtml)(String(item.text))}</span>` : `<svg aria-hidden="true" focusable="false"><use xlink:href="#${item.id}"></use></svg>`;
|
|
60629
|
-
return `<div class="g6-toolbar-item${kind_class}${extra_class}" value="${item.value}" title="${title}" aria-label="${title}"${disabled}>${body}</div>`;
|
|
60643
|
+
const body = is_text ? `<span class="g6-toolbar-text">${(0, _yuneta_gobj_js.escapeHtml)(String(item.text))}</span>` : `<svg aria-hidden="true" focusable="false"><use xlink:href="#${(0, _yuneta_gobj_js.escapeHtml)(String(item.id))}"></use></svg>`;
|
|
60644
|
+
return `<div class="g6-toolbar-item${kind_class}${extra_class}" value="${(0, _yuneta_gobj_js.escapeHtml)(String(item.value))}" title="${title}" aria-label="${title}"${disabled}>${body}</div>`;
|
|
60630
60645
|
}).join("");
|
|
60631
60646
|
}
|
|
60632
60647
|
};
|
|
@@ -61856,14 +61871,20 @@ function topic_defaults_of(gobj, topic_name) {
|
|
|
61856
61871
|
* refused value logs, and the node wears the topic's colour.
|
|
61857
61872
|
************************************************************/
|
|
61858
61873
|
var refused_colors_logged = /* @__PURE__ */ new Set();
|
|
61874
|
+
var REFUSED_COLORS_LOG_MAX = 200;
|
|
61875
|
+
var refused_colors_capped = false;
|
|
61859
61876
|
function data_color(gobj, value) {
|
|
61860
61877
|
if (value === void 0 || value === null || value === "") return null;
|
|
61861
61878
|
let color = css_color_or_null(value);
|
|
61862
61879
|
if (!color) {
|
|
61863
61880
|
let key = `${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}\u0000${String(value)}`;
|
|
61864
|
-
if (
|
|
61881
|
+
if (refused_colors_logged.has(key)) return color;
|
|
61882
|
+
if (refused_colors_logged.size < REFUSED_COLORS_LOG_MAX) {
|
|
61865
61883
|
refused_colors_logged.add(key);
|
|
61866
61884
|
(0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: colour refused, not a css colour: ${JSON.stringify(value)}`);
|
|
61885
|
+
} else if (!refused_colors_capped) {
|
|
61886
|
+
refused_colors_capped = true;
|
|
61887
|
+
(0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: ${REFUSED_COLORS_LOG_MAX} refused colours logged; further refused colours are not logged`);
|
|
61867
61888
|
}
|
|
61868
61889
|
}
|
|
61869
61890
|
return color;
|
|
@@ -70844,7 +70865,7 @@ function refresh_legend(gobj) {
|
|
|
70844
70865
|
class: "GRAPH_LEGEND_NAME",
|
|
70845
70866
|
style: (is_main ? LEGEND_MAIN_NAME_STYLE : LEGEND_NAME_STYLE) + (hidden ? " text-decoration:line-through; opacity:.6;" : "")
|
|
70846
70867
|
},
|
|
70847
|
-
topic_name
|
|
70868
|
+
text_node(topic_name)
|
|
70848
70869
|
], [
|
|
70849
70870
|
"span",
|
|
70850
70871
|
{
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -1018,15 +1018,29 @@ function mt_start$20(gobj) {
|
|
|
1018
1018
|
if (gobj_read_attr(gobj, "use_hash")) {
|
|
1019
1019
|
priv.hash_handler = () => {
|
|
1020
1020
|
let p = gobj.priv;
|
|
1021
|
-
|
|
1021
|
+
let dropped = false;
|
|
1022
|
+
if (p && p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1023
|
+
drop_expected_pops(gobj);
|
|
1024
|
+
dropped = true;
|
|
1025
|
+
}
|
|
1022
1026
|
let route = hash_to_route(window.location.hash);
|
|
1023
1027
|
if (!empty_string(route)) navigate_to(gobj, route);
|
|
1028
|
+
if (dropped) push_pending_markers(gobj);
|
|
1024
1029
|
};
|
|
1025
1030
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
1026
1031
|
priv.popstate_handler = (ev) => {
|
|
1027
1032
|
let p = gobj.priv;
|
|
1028
1033
|
if (!p) return;
|
|
1029
|
-
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash)
|
|
1034
|
+
if (p.expected_pops > 0 && window.location.hash !== p.expected_pop_hash) {
|
|
1035
|
+
drop_expected_pops(gobj);
|
|
1036
|
+
on_traversal(ev);
|
|
1037
|
+
push_pending_markers(gobj);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
on_traversal(ev);
|
|
1041
|
+
};
|
|
1042
|
+
let on_traversal = (ev) => {
|
|
1043
|
+
let p = gobj.priv;
|
|
1030
1044
|
if (p.expected_pops > 0) {
|
|
1031
1045
|
p.expected_pops--;
|
|
1032
1046
|
if (p.expected_pops === 0) push_pending_markers(gobj);
|
|
@@ -1034,6 +1048,7 @@ function mt_start$20(gobj) {
|
|
|
1034
1048
|
}
|
|
1035
1049
|
if (p.overlay_stack.length === 0) return;
|
|
1036
1050
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
1051
|
+
if (top.marker_pending) return;
|
|
1037
1052
|
if (window.location.hash !== top.hash) return;
|
|
1038
1053
|
let st = ev && ev.state;
|
|
1039
1054
|
if (st && st.__yui_overlay__ === top.id) return;
|
|
@@ -2488,6 +2503,7 @@ function push_overlay_history(gobj, close, opts) {
|
|
|
2488
2503
|
}
|
|
2489
2504
|
function push_overlay_marker(gobj, entry) {
|
|
2490
2505
|
let priv = gobj.priv;
|
|
2506
|
+
entry.below_hash = window.location.hash;
|
|
2491
2507
|
try {
|
|
2492
2508
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2493
2509
|
} catch (e) {
|
|
@@ -2504,7 +2520,6 @@ function drop_expected_pops(gobj) {
|
|
|
2504
2520
|
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`);
|
|
2505
2521
|
priv.expected_pops = 0;
|
|
2506
2522
|
priv.expected_pop_hash = "";
|
|
2507
|
-
push_pending_markers(gobj);
|
|
2508
2523
|
}
|
|
2509
2524
|
function push_pending_markers(gobj) {
|
|
2510
2525
|
let priv = gobj.priv;
|
|
@@ -2527,7 +2542,7 @@ function overlay_dismissed(gobj, entry) {
|
|
|
2527
2542
|
let st = window.history.state;
|
|
2528
2543
|
if (st && st.__yui_overlay__ === entry.id) {
|
|
2529
2544
|
priv.expected_pops++;
|
|
2530
|
-
priv.expected_pop_hash = window.location.hash;
|
|
2545
|
+
priv.expected_pop_hash = typeof entry.below_hash === "string" ? entry.below_hash : window.location.hash;
|
|
2531
2546
|
try {
|
|
2532
2547
|
window.history.back();
|
|
2533
2548
|
} catch (e) {
|
|
@@ -19052,7 +19067,7 @@ function build_head(gobj, model) {
|
|
|
19052
19067
|
let items = [[
|
|
19053
19068
|
"span",
|
|
19054
19069
|
{ class: "GCLASS_NAME" },
|
|
19055
|
-
model.id || gobj_read_str_attr(gobj, "gclass_name") || "?"
|
|
19070
|
+
text_node(model.id || gobj_read_str_attr(gobj, "gclass_name") || "?")
|
|
19056
19071
|
]];
|
|
19057
19072
|
if (model.instances !== null) items.push([
|
|
19058
19073
|
"span",
|
|
@@ -19083,7 +19098,7 @@ function build_head(gobj, model) {
|
|
|
19083
19098
|
title: t("current state"),
|
|
19084
19099
|
"data-i18n-title": "current state"
|
|
19085
19100
|
},
|
|
19086
|
-
current
|
|
19101
|
+
text_node(current)
|
|
19087
19102
|
]);
|
|
19088
19103
|
return [
|
|
19089
19104
|
"div",
|
|
@@ -60614,14 +60629,14 @@ var YuiToolbar = class extends Toolbar {
|
|
|
60614
60629
|
async getDOMContent() {
|
|
60615
60630
|
return (await this.options.getItems()).map((item) => {
|
|
60616
60631
|
if (item.separator) return `<div class="g6-toolbar-sep" aria-hidden="true"></div>`;
|
|
60617
|
-
const extra_class = item.className ? ` ${item.className}` : "";
|
|
60618
|
-
const title = item.title ?? "";
|
|
60619
|
-
if (item.readout) return `<div class="g6-toolbar-readout${extra_class}" title="${title}" aria-label="${title}">${item.text ?? ""}</div>`;
|
|
60632
|
+
const extra_class = item.className ? ` ${escapeHtml(String(item.className))}` : "";
|
|
60633
|
+
const title = escapeHtml(String(item.title ?? ""));
|
|
60634
|
+
if (item.readout) return `<div class="g6-toolbar-readout${extra_class}" title="${title}" aria-label="${title}">${escapeHtml(String(item.text ?? ""))}</div>`;
|
|
60620
60635
|
const disabled = item.disabled ? " disabled" : "";
|
|
60621
60636
|
const is_text = item.text !== void 0;
|
|
60622
60637
|
const kind_class = is_text ? " g6-toolbar-item-text" : "";
|
|
60623
|
-
const body = is_text ? `<span class="g6-toolbar-text">${escapeHtml(String(item.text))}</span>` : `<svg aria-hidden="true" focusable="false"><use xlink:href="#${item.id}"></use></svg>`;
|
|
60624
|
-
return `<div class="g6-toolbar-item${kind_class}${extra_class}" value="${item.value}" title="${title}" aria-label="${title}"${disabled}>${body}</div>`;
|
|
60638
|
+
const body = is_text ? `<span class="g6-toolbar-text">${escapeHtml(String(item.text))}</span>` : `<svg aria-hidden="true" focusable="false"><use xlink:href="#${escapeHtml(String(item.id))}"></use></svg>`;
|
|
60639
|
+
return `<div class="g6-toolbar-item${kind_class}${extra_class}" value="${escapeHtml(String(item.value))}" title="${title}" aria-label="${title}"${disabled}>${body}</div>`;
|
|
60625
60640
|
}).join("");
|
|
60626
60641
|
}
|
|
60627
60642
|
};
|
|
@@ -61851,14 +61866,20 @@ function topic_defaults_of(gobj, topic_name) {
|
|
|
61851
61866
|
* refused value logs, and the node wears the topic's colour.
|
|
61852
61867
|
************************************************************/
|
|
61853
61868
|
var refused_colors_logged = /* @__PURE__ */ new Set();
|
|
61869
|
+
var REFUSED_COLORS_LOG_MAX = 200;
|
|
61870
|
+
var refused_colors_capped = false;
|
|
61854
61871
|
function data_color(gobj, value) {
|
|
61855
61872
|
if (value === void 0 || value === null || value === "") return null;
|
|
61856
61873
|
let color = css_color_or_null(value);
|
|
61857
61874
|
if (!color) {
|
|
61858
61875
|
let key = `${gobj_short_name(gobj)}\u0000${String(value)}`;
|
|
61859
|
-
if (
|
|
61876
|
+
if (refused_colors_logged.has(key)) return color;
|
|
61877
|
+
if (refused_colors_logged.size < REFUSED_COLORS_LOG_MAX) {
|
|
61860
61878
|
refused_colors_logged.add(key);
|
|
61861
61879
|
log_warning(`${gobj_short_name(gobj)}: colour refused, not a css colour: ${JSON.stringify(value)}`);
|
|
61880
|
+
} else if (!refused_colors_capped) {
|
|
61881
|
+
refused_colors_capped = true;
|
|
61882
|
+
log_warning(`${gobj_short_name(gobj)}: ${REFUSED_COLORS_LOG_MAX} refused colours logged; further refused colours are not logged`);
|
|
61862
61883
|
}
|
|
61863
61884
|
}
|
|
61864
61885
|
return color;
|
|
@@ -70839,7 +70860,7 @@ function refresh_legend(gobj) {
|
|
|
70839
70860
|
class: "GRAPH_LEGEND_NAME",
|
|
70840
70861
|
style: (is_main ? LEGEND_MAIN_NAME_STYLE : LEGEND_NAME_STYLE) + (hidden ? " text-decoration:line-through; opacity:.6;" : "")
|
|
70841
70862
|
},
|
|
70842
|
-
topic_name
|
|
70863
|
+
text_node(topic_name)
|
|
70843
70864
|
], [
|
|
70844
70865
|
"span",
|
|
70845
70866
|
{
|
package/package.json
CHANGED
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
* All Rights Reserved.
|
|
48
48
|
***********************************************************************/
|
|
49
49
|
import {readFileSync, readdirSync, statSync, realpathSync} from "node:fs";
|
|
50
|
-
import {join, relative} from "node:path";
|
|
50
|
+
import {join, relative, resolve} from "node:path";
|
|
51
51
|
import {fileURLToPath} from "node:url";
|
|
52
52
|
import {parse} from "acorn";
|
|
53
53
|
|
|
54
|
-
const TAG_RE = /^[a-z][a-z0-9-]
|
|
54
|
+
const TAG_RE = /^[a-z][a-z0-9-]*$/i;
|
|
55
55
|
const SKIP_DIRS = new Set(["node_modules", "dist", ".git", "build", "_build"]);
|
|
56
56
|
|
|
57
57
|
function list_files(path, out)
|
|
@@ -91,37 +91,119 @@ function starts_with_markup(s)
|
|
|
91
91
|
return typeof s === "string" && s.trim().startsWith("<");
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/*
|
|
95
|
-
*
|
|
96
|
-
|
|
94
|
+
/* String methods that keep the head of their receiver (a markup head
|
|
95
|
+
* stays a markup head through them). */
|
|
96
|
+
const HEAD_KEEPING_METHODS = new Set([
|
|
97
|
+
"trim", "trimStart", "trimEnd", "toString", "valueOf", "normalize",
|
|
98
|
+
"toLowerCase", "toUpperCase", "replace", "replaceAll", "padEnd", "concat"
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
function concat_parts(parts)
|
|
97
102
|
{
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
/* parts: [{text, complete}] in order. The leading text runs while
|
|
104
|
+
* the parts are static. */
|
|
105
|
+
let text = "";
|
|
106
|
+
for(const p of parts) {
|
|
107
|
+
if(p === null) {
|
|
108
|
+
return {text, complete: false};
|
|
109
|
+
}
|
|
110
|
+
text += p.text;
|
|
111
|
+
if(!p.complete) {
|
|
112
|
+
return {text, complete: false};
|
|
113
|
+
}
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
return {text, complete: true};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function template_parts(quasis, expressions, raw)
|
|
119
|
+
{
|
|
120
|
+
let parts = [];
|
|
121
|
+
for(let i = 0; i < quasis.length; i++) {
|
|
122
|
+
let q = quasis[i].value;
|
|
123
|
+
parts.push({text: raw ? q.raw : (q.cooked ?? ""), complete: true});
|
|
124
|
+
if(i < expressions.length) {
|
|
125
|
+
parts.push(leading(expressions[i]));
|
|
107
126
|
}
|
|
108
|
-
return built_markup(head);
|
|
109
127
|
}
|
|
110
|
-
|
|
111
|
-
|
|
128
|
+
return parts;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* The text an expression STARTS with, as far as it is static:
|
|
132
|
+
* {text, complete} (complete: the whole value is static), or null when
|
|
133
|
+
* it starts with something the check cannot see. */
|
|
134
|
+
function leading(n)
|
|
135
|
+
{
|
|
136
|
+
if(!n) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if(is_string_literal(n)) {
|
|
140
|
+
return {text: n.value, complete: true};
|
|
141
|
+
}
|
|
142
|
+
if(n.type === "TemplateLiteral") {
|
|
143
|
+
return concat_parts(template_parts(n.quasis, n.expressions, false));
|
|
144
|
+
}
|
|
145
|
+
if(n.type === "TaggedTemplateExpression") {
|
|
146
|
+
let tag = n.tag;
|
|
147
|
+
if(tag.type === "MemberExpression" && !tag.computed &&
|
|
148
|
+
tag.object.type === "Identifier" && tag.object.name === "String" &&
|
|
149
|
+
tag.property.name === "raw") {
|
|
150
|
+
return concat_parts(template_parts(n.quasi.quasis, n.quasi.expressions, true));
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
112
153
|
}
|
|
113
154
|
if(n.type === "BinaryExpression" && n.operator === "+") {
|
|
114
|
-
let
|
|
115
|
-
|
|
116
|
-
|
|
155
|
+
let operands = [];
|
|
156
|
+
let flatten = (e) => {
|
|
157
|
+
if(e.type === "BinaryExpression" && e.operator === "+") {
|
|
158
|
+
flatten(e.left);
|
|
159
|
+
flatten(e.right);
|
|
160
|
+
} else {
|
|
161
|
+
operands.push(e);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
flatten(n);
|
|
165
|
+
return concat_parts(operands.map(leading));
|
|
166
|
+
}
|
|
167
|
+
if(n.type === "SequenceExpression") {
|
|
168
|
+
return leading(n.expressions[n.expressions.length - 1]);
|
|
169
|
+
}
|
|
170
|
+
if(n.type === "CallExpression" && n.callee.type === "MemberExpression" &&
|
|
171
|
+
!n.callee.computed) {
|
|
172
|
+
let method = n.callee.property.name;
|
|
173
|
+
let receiver = n.callee.object;
|
|
174
|
+
if(method === "join" && receiver.type === "ArrayExpression") {
|
|
175
|
+
let sep = n.arguments.length ? leading(n.arguments[0]) : {text: ",", complete: true};
|
|
176
|
+
let parts = [];
|
|
177
|
+
receiver.elements.forEach((el, k) => {
|
|
178
|
+
if(k > 0) {
|
|
179
|
+
parts.push(sep);
|
|
180
|
+
}
|
|
181
|
+
parts.push(leading(el));
|
|
182
|
+
});
|
|
183
|
+
return concat_parts(parts);
|
|
117
184
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
185
|
+
if(HEAD_KEEPING_METHODS.has(method)) {
|
|
186
|
+
let head = leading(receiver);
|
|
187
|
+
if(head === null) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
if(method === "concat") {
|
|
191
|
+
return concat_parts([head, ...n.arguments.map(leading)]);
|
|
192
|
+
}
|
|
193
|
+
/* The head is kept; the whole is no longer known to be static. */
|
|
194
|
+
return {text: head.text, complete: false};
|
|
121
195
|
}
|
|
122
|
-
return
|
|
196
|
+
return null;
|
|
123
197
|
}
|
|
124
|
-
return
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* Markup BUILT with values: its static head starts with '<' and it is
|
|
202
|
+
* not static as a whole. */
|
|
203
|
+
function built_markup(n)
|
|
204
|
+
{
|
|
205
|
+
let head = leading(n);
|
|
206
|
+
return !!head && !head.complete && starts_with_markup(head.text);
|
|
125
207
|
}
|
|
126
208
|
|
|
127
209
|
/* [tag, attrs, content, events?]: a tag and an attrs slot. A literal
|
|
@@ -192,8 +274,12 @@ function check_content(n, findings, file, src, where)
|
|
|
192
274
|
check_content(n.right, findings, file, src, where);
|
|
193
275
|
return;
|
|
194
276
|
}
|
|
195
|
-
|
|
196
|
-
|
|
277
|
+
if(n.type === "SequenceExpression") {
|
|
278
|
+
check_content(n.expressions[n.expressions.length - 1], findings, file, src, where);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
let head = leading(n);
|
|
282
|
+
if(head && head.complete && starts_with_markup(head.text)) {
|
|
197
283
|
findings.push({file, line: n.loc.start.line, rule: where === "list" ? "in-list" : "literal",
|
|
198
284
|
text: src.slice(n.start, Math.min(n.end, n.start + 90))});
|
|
199
285
|
return;
|
|
@@ -223,7 +309,8 @@ function check_file(file, root)
|
|
|
223
309
|
}
|
|
224
310
|
let content = n.elements[2];
|
|
225
311
|
if(content && content.type === "ArrayExpression" && content.elements.length > 0) {
|
|
226
|
-
let
|
|
312
|
+
let lead = leading(content.elements[0]);
|
|
313
|
+
let head = (lead && lead.complete)? lead.text : null;
|
|
227
314
|
if(head !== null && starts_with_markup(head)) {
|
|
228
315
|
/* createElement2() reads a list that starts with a string
|
|
229
316
|
* as ONE description: '<b>' would be its tag. */
|
|
@@ -256,7 +343,14 @@ function main()
|
|
|
256
343
|
const targets = process.argv.slice(2).length ? process.argv.slice(2) : ["src"];
|
|
257
344
|
let files = [];
|
|
258
345
|
for(const t of targets) {
|
|
259
|
-
|
|
346
|
+
const path = resolve(root, t); // an absolute path stays absolute
|
|
347
|
+
try {
|
|
348
|
+
statSync(path);
|
|
349
|
+
} catch(e) {
|
|
350
|
+
console.error(`check-markup-strings: no such file or directory: ${t}`);
|
|
351
|
+
process.exit(2);
|
|
352
|
+
}
|
|
353
|
+
list_files(path, files);
|
|
260
354
|
}
|
|
261
355
|
|
|
262
356
|
let all = [];
|
package/src/c_g6_nodes_tree.js
CHANGED
|
@@ -213,14 +213,17 @@ class YuiToolbar extends Toolbar
|
|
|
213
213
|
return `<div class="g6-toolbar-sep" aria-hidden="true"></div>`;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
/* Everything that goes into this markup is escaped, the
|
|
217
|
+
* read-out branch too: its text, title and value are values
|
|
218
|
+
* (a zoom figure, a translated title), never markup. */
|
|
219
|
+
const extra_class = item.className ? ` ${escapeHtml(String(item.className))}` : '';
|
|
220
|
+
const title = escapeHtml(String(item.title ?? ''));
|
|
218
221
|
|
|
219
222
|
if(item.readout) {
|
|
220
223
|
return (
|
|
221
224
|
`<div class="g6-toolbar-readout${extra_class}"` +
|
|
222
225
|
` title="${title}" aria-label="${title}">` +
|
|
223
|
-
`${item.text ?? ''}` +
|
|
226
|
+
`${escapeHtml(String(item.text ?? ''))}` +
|
|
224
227
|
`</div>`
|
|
225
228
|
);
|
|
226
229
|
}
|
|
@@ -231,12 +234,12 @@ class YuiToolbar extends Toolbar
|
|
|
231
234
|
const body = is_text
|
|
232
235
|
? `<span class="g6-toolbar-text">${escapeHtml(String(item.text))}</span>`
|
|
233
236
|
: `<svg aria-hidden="true" focusable="false">` +
|
|
234
|
-
`<use xlink:href="#${item.id}"></use>` +
|
|
237
|
+
`<use xlink:href="#${escapeHtml(String(item.id))}"></use>` +
|
|
235
238
|
`</svg>`;
|
|
236
239
|
|
|
237
240
|
return (
|
|
238
241
|
`<div class="g6-toolbar-item${kind_class}${extra_class}"` +
|
|
239
|
-
` value="${item.value}" title="${title}"` +
|
|
242
|
+
` value="${escapeHtml(String(item.value))}" title="${title}"` +
|
|
240
243
|
` aria-label="${title}"${disabled}>` +
|
|
241
244
|
`${body}` +
|
|
242
245
|
`</div>`
|
|
@@ -2302,6 +2305,8 @@ function topic_defaults_of(gobj, topic_name)
|
|
|
2302
2305
|
* refused value logs, and the node wears the topic's colour.
|
|
2303
2306
|
************************************************************/
|
|
2304
2307
|
const refused_colors_logged = new Set(); // once per (gobj, value): every repaint asks again
|
|
2308
|
+
const REFUSED_COLORS_LOG_MAX = 200;
|
|
2309
|
+
let refused_colors_capped = false;
|
|
2305
2310
|
|
|
2306
2311
|
function data_color(gobj, value)
|
|
2307
2312
|
{
|
|
@@ -2311,9 +2316,21 @@ function data_color(gobj, value)
|
|
|
2311
2316
|
let color = css_color_or_null(value);
|
|
2312
2317
|
if(!color) {
|
|
2313
2318
|
let key = `${gobj_short_name(gobj)}\u0000${String(value)}`;
|
|
2314
|
-
if(
|
|
2319
|
+
if(refused_colors_logged.has(key)) {
|
|
2320
|
+
return color;
|
|
2321
|
+
}
|
|
2322
|
+
if(refused_colors_logged.size < REFUSED_COLORS_LOG_MAX) {
|
|
2315
2323
|
refused_colors_logged.add(key);
|
|
2316
2324
|
log_warning(`${gobj_short_name(gobj)}: colour refused, not a css colour: ${JSON.stringify(value)}`);
|
|
2325
|
+
} else if(!refused_colors_capped) {
|
|
2326
|
+
/* Bounded, but not silent: say once that the rest go unlogged.
|
|
2327
|
+
* An LRU would log again and again on every repaint of a
|
|
2328
|
+
* graph with more refused colours than it holds. */
|
|
2329
|
+
refused_colors_capped = true;
|
|
2330
|
+
log_warning(
|
|
2331
|
+
`${gobj_short_name(gobj)}: ${REFUSED_COLORS_LOG_MAX} refused colours ` +
|
|
2332
|
+
`logged; further refused colours are not logged`
|
|
2333
|
+
);
|
|
2317
2334
|
}
|
|
2318
2335
|
}
|
|
2319
2336
|
return color;
|
package/src/c_yui_gclass.js
CHANGED
|
@@ -556,7 +556,7 @@ function build_head(gobj, model)
|
|
|
556
556
|
{
|
|
557
557
|
let items = [
|
|
558
558
|
['span', {class: 'GCLASS_NAME'},
|
|
559
|
-
model.id || gobj_read_str_attr(gobj, "gclass_name") || "?"]
|
|
559
|
+
text_node(model.id || gobj_read_str_attr(gobj, "gclass_name") || "?")]
|
|
560
560
|
];
|
|
561
561
|
|
|
562
562
|
if(model.instances !== null) {
|
|
@@ -577,7 +577,7 @@ function build_head(gobj, model)
|
|
|
577
577
|
items.push(
|
|
578
578
|
['span', {class: 'GCLASS_CHIP GCLASS_CURRENT',
|
|
579
579
|
title: t("current state"),
|
|
580
|
-
'data-i18n-title': 'current state'}, current]);
|
|
580
|
+
'data-i18n-title': 'current state'}, text_node(current)]);
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
return ['div', {class: 'GCLASS_HEAD'}, items];
|
package/src/c_yui_shell.js
CHANGED
|
@@ -267,14 +267,21 @@ function mt_start(gobj)
|
|
|
267
267
|
if(gobj_read_attr(gobj, "use_hash")) {
|
|
268
268
|
priv.hash_handler = () => {
|
|
269
269
|
let p = gobj.priv;
|
|
270
|
+
let dropped = false;
|
|
270
271
|
if(p && p.expected_pops > 0 &&
|
|
271
272
|
window.location.hash !== p.expected_pop_hash) {
|
|
272
273
|
drop_expected_pops(gobj); // a back() of ours never landed
|
|
274
|
+
dropped = true;
|
|
273
275
|
}
|
|
274
276
|
let route = hash_to_route(window.location.hash);
|
|
275
277
|
if(!empty_string(route)) {
|
|
276
278
|
navigate_to(gobj, route);
|
|
277
279
|
}
|
|
280
|
+
if(dropped) {
|
|
281
|
+
/* After the navigation: an overlay it drained gets no
|
|
282
|
+
* marker, a kept one gets it on the hash it now lives on. */
|
|
283
|
+
push_pending_markers(gobj);
|
|
284
|
+
}
|
|
278
285
|
};
|
|
279
286
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
280
287
|
|
|
@@ -291,9 +298,20 @@ function mt_start(gobj)
|
|
|
291
298
|
if(p.expected_pops > 0 &&
|
|
292
299
|
window.location.hash !== p.expected_pop_hash) {
|
|
293
300
|
/* Not the landing of ours: it was dropped. Whatever
|
|
294
|
-
* this traversal is, it is handled
|
|
301
|
+
* this traversal is, it is handled as any other, and
|
|
302
|
+
* the overlays that waited get their markers AFTER it:
|
|
303
|
+
* pushed first, the waiting top had a marker the
|
|
304
|
+
* traversal then took as "stepped off" -- it was closed
|
|
305
|
+
* and its marker left orphaned. */
|
|
295
306
|
drop_expected_pops(gobj);
|
|
307
|
+
on_traversal(ev);
|
|
308
|
+
push_pending_markers(gobj);
|
|
309
|
+
return;
|
|
296
310
|
}
|
|
311
|
+
on_traversal(ev);
|
|
312
|
+
};
|
|
313
|
+
let on_traversal = (ev) => {
|
|
314
|
+
let p = gobj.priv;
|
|
297
315
|
if(p.expected_pops > 0) {
|
|
298
316
|
/* A history.back() we issued to retire a dismissed
|
|
299
317
|
* overlay — the teardown already happened. */
|
|
@@ -307,6 +325,10 @@ function mt_start(gobj)
|
|
|
307
325
|
return;
|
|
308
326
|
}
|
|
309
327
|
let top = p.overlay_stack[p.overlay_stack.length - 1];
|
|
328
|
+
if(top.marker_pending) {
|
|
329
|
+
/* It has no marker yet: no traversal can step off it. */
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
310
332
|
/* Did this traversal step OFF the top overlay's marker?
|
|
311
333
|
* That is the only landing that closes it, and the marker's
|
|
312
334
|
* OWN hash is what says so: pushState() with no URL keeps
|
|
@@ -2652,6 +2674,10 @@ function push_overlay_history(gobj, close, opts)
|
|
|
2652
2674
|
function push_overlay_marker(gobj, entry)
|
|
2653
2675
|
{
|
|
2654
2676
|
let priv = gobj.priv;
|
|
2677
|
+
/* The entry UNDER the marker is on this hash, and a back() off the
|
|
2678
|
+
* marker lands there -- even after a replace-navigation rewrote the
|
|
2679
|
+
* marker's own hash (retag_overlay_hash()). */
|
|
2680
|
+
entry.below_hash = window.location.hash;
|
|
2655
2681
|
try {
|
|
2656
2682
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2657
2683
|
} catch(e) {
|
|
@@ -2669,8 +2695,8 @@ function push_overlay_marker(gobj, entry)
|
|
|
2669
2695
|
|
|
2670
2696
|
/* A history.back() of ours that the browser dropped: nothing will land
|
|
2671
2697
|
* for it, so it must not wait for a landing and swallow the reader's
|
|
2672
|
-
* next Back. The overlays that waited for it get their markers
|
|
2673
|
-
* the
|
|
2698
|
+
* next Back. The overlays that waited for it get their markers from the
|
|
2699
|
+
* caller (push_pending_markers()), after the traversal is handled. */
|
|
2674
2700
|
function drop_expected_pops(gobj)
|
|
2675
2701
|
{
|
|
2676
2702
|
let priv = gobj.priv;
|
|
@@ -2683,7 +2709,8 @@ function drop_expected_pops(gobj)
|
|
|
2683
2709
|
);
|
|
2684
2710
|
priv.expected_pops = 0;
|
|
2685
2711
|
priv.expected_pop_hash = "";
|
|
2686
|
-
|
|
2712
|
+
/* The caller pushes the waiting markers, once it has handled the
|
|
2713
|
+
* traversal that told it. */
|
|
2687
2714
|
}
|
|
2688
2715
|
|
|
2689
2716
|
/* The history.back() calls of ours have all landed: push the markers of
|
|
@@ -2739,7 +2766,8 @@ function overlay_dismissed(gobj, entry)
|
|
|
2739
2766
|
let st = window.history.state;
|
|
2740
2767
|
if(st && st.__yui_overlay__ === entry.id) {
|
|
2741
2768
|
priv.expected_pops++;
|
|
2742
|
-
priv.expected_pop_hash =
|
|
2769
|
+
priv.expected_pop_hash = (typeof entry.below_hash === "string")?
|
|
2770
|
+
entry.below_hash : window.location.hash;
|
|
2743
2771
|
try {
|
|
2744
2772
|
window.history.back();
|
|
2745
2773
|
} catch(e) {
|
|
@@ -81,6 +81,7 @@ import {
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
import {attach_clear, refresh_clear} from "./yui_inputs.js";
|
|
84
|
+
import {text_node} from "./yui_text.js";
|
|
84
85
|
import {register_c_g6_nodes_tree} from "./c_g6_nodes_tree.js";
|
|
85
86
|
import {yui_toolbar, yui_toolbar_icon, YUI_TOOLBAR_ICON_SIZE} from "./yui_toolbar.js";
|
|
86
87
|
import {
|
|
@@ -3084,7 +3085,7 @@ function refresh_legend(gobj)
|
|
|
3084
3085
|
['span', {class: 'GRAPH_LEGEND_NAME',
|
|
3085
3086
|
style: (is_main? LEGEND_MAIN_NAME_STYLE : LEGEND_NAME_STYLE) +
|
|
3086
3087
|
(hidden? ' text-decoration:line-through; opacity:.6;' : '')},
|
|
3087
|
-
topic_name],
|
|
3088
|
+
text_node(topic_name)], // schema data, never markup
|
|
3088
3089
|
['span', {class: 'GRAPH_LEGEND_COUNT',
|
|
3089
3090
|
style: LEGEND_COUNT_STYLE},
|
|
3090
3091
|
hidden? `${entry.total}` : `${entry.visible}/${entry.total}`]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* gclass_head_text.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The header of C_YUI_GCLASS shows what a REMOTE description says:
|
|
5
|
+
* the gclass name and the instance's current state are data, so
|
|
6
|
+
* they are text, never markup (REV-CLOUD V4.2).
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2026, ArtGins.
|
|
9
|
+
* All Rights Reserved.
|
|
10
|
+
***********************************************************************/
|
|
11
|
+
import {describe, test, expect, beforeAll} from "vitest";
|
|
12
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
13
|
+
|
|
14
|
+
install_dom_double();
|
|
15
|
+
|
|
16
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
17
|
+
globalThis.ResizeObserver = class {
|
|
18
|
+
observe() {
|
|
19
|
+
}
|
|
20
|
+
unobserve() {
|
|
21
|
+
}
|
|
22
|
+
disconnect() {
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SDATA_END, gclass_create,
|
|
29
|
+
gobj_start_up, gobj_create_yuno, gobj_create,
|
|
30
|
+
gobj_start, gobj_read_attr,
|
|
31
|
+
set_log_callback,
|
|
32
|
+
} = await import("@yuneta/gobj-js");
|
|
33
|
+
const {register_c_yui_gclass} = await import("./c_yui_gclass.js");
|
|
34
|
+
|
|
35
|
+
const EVIL = '<img src=x onerror="window.__pwned=1">';
|
|
36
|
+
let yuno = null;
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
const i18next = (await import("i18next")).default;
|
|
40
|
+
await i18next.init({lng: "en", resources: {}});
|
|
41
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
42
|
+
set_log_callback(() => {});
|
|
43
|
+
gclass_create("C_TEST_GCLASS_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
44
|
+
register_c_yui_gclass();
|
|
45
|
+
yuno = gobj_create_yuno("gclass_head_yuno", "C_TEST_GCLASS_HOST", {});
|
|
46
|
+
gobj_start(yuno);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("C_YUI_GCLASS header", () => {
|
|
50
|
+
test("the gclass name and the current state are text", () => {
|
|
51
|
+
const view = gobj_create("gclass_head", "C_YUI_GCLASS", {
|
|
52
|
+
description: {id: EVIL, gcflag: [], attrs: [], commands: [],
|
|
53
|
+
gclass_methods: [], internal_methods: [],
|
|
54
|
+
FSM: {events: [], states: {}}},
|
|
55
|
+
current_state: EVIL,
|
|
56
|
+
}, yuno);
|
|
57
|
+
gobj_start(view);
|
|
58
|
+
const $c = gobj_read_attr(view, "$container");
|
|
59
|
+
expect($c.querySelector(".GCLASS_NAME").textContent).toBe(EVIL);
|
|
60
|
+
expect($c.querySelector(".GCLASS_CURRENT").textContent).toBe(EVIL);
|
|
61
|
+
expect($c.querySelector("img")).toBe(null);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -38,12 +38,20 @@ let veto = true;
|
|
|
38
38
|
let warning = null;
|
|
39
39
|
let yuno = null;
|
|
40
40
|
|
|
41
|
-
/* The session history of one tab.
|
|
42
|
-
|
|
41
|
+
/* The session history of one tab. Each entry carries its hash, as a
|
|
42
|
+
* browser's does: a traversal lands on the entry's hash, and fires a
|
|
43
|
+
* hashchange after the popstate when that hash is not the one it left. */
|
|
44
|
+
const session = {entries: [{state: null, hash: ""}], index: 0};
|
|
45
|
+
|
|
46
|
+
function url_hash(url)
|
|
47
|
+
{
|
|
48
|
+
return (typeof url === "string" && url.includes("#"))?
|
|
49
|
+
url.slice(url.indexOf("#")) : null;
|
|
50
|
+
}
|
|
43
51
|
|
|
44
52
|
function install_history_model()
|
|
45
53
|
{
|
|
46
|
-
session.entries = [{state: null}];
|
|
54
|
+
session.entries = [{state: null, hash: window.location.hash}];
|
|
47
55
|
session.index = 0;
|
|
48
56
|
window.history = {
|
|
49
57
|
get state() {
|
|
@@ -52,19 +60,26 @@ function install_history_model()
|
|
|
52
60
|
get length() {
|
|
53
61
|
return session.entries.length;
|
|
54
62
|
},
|
|
55
|
-
pushState(state) {
|
|
63
|
+
pushState(state, title, url) {
|
|
64
|
+
const h = url_hash(url);
|
|
65
|
+
if(h !== null) {
|
|
66
|
+
window.location.hash = h;
|
|
67
|
+
}
|
|
56
68
|
session.entries.splice(session.index + 1);
|
|
57
|
-
session.entries.push({state: state});
|
|
69
|
+
session.entries.push({state: state, hash: window.location.hash});
|
|
58
70
|
session.index++;
|
|
59
71
|
},
|
|
60
|
-
replaceState(state) {
|
|
61
|
-
|
|
72
|
+
replaceState(state, title, url) {
|
|
73
|
+
const h = url_hash(url);
|
|
74
|
+
if(h !== null) {
|
|
75
|
+
window.location.hash = h;
|
|
76
|
+
}
|
|
77
|
+
session.entries[session.index] = {state: state, hash: window.location.hash};
|
|
62
78
|
},
|
|
63
79
|
back() {
|
|
64
80
|
setTimeout(() => {
|
|
65
81
|
if(session.index > 0) {
|
|
66
|
-
session.index
|
|
67
|
-
fire_popstate();
|
|
82
|
+
traverse_to(session.index - 1);
|
|
68
83
|
}
|
|
69
84
|
}, 0);
|
|
70
85
|
},
|
|
@@ -82,11 +97,21 @@ function fire_popstate()
|
|
|
82
97
|
window.dispatchEvent(ev);
|
|
83
98
|
}
|
|
84
99
|
|
|
100
|
+
function traverse_to(index)
|
|
101
|
+
{
|
|
102
|
+
const left = window.location.hash;
|
|
103
|
+
session.index = index;
|
|
104
|
+
window.location.hash = session.entries[index].hash;
|
|
105
|
+
fire_popstate();
|
|
106
|
+
if(window.location.hash !== left) {
|
|
107
|
+
window.dispatchEvent(new Event("hashchange"));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
85
111
|
/* The user's Back: the browser's own traversal. */
|
|
86
112
|
function user_back()
|
|
87
113
|
{
|
|
88
|
-
session.index
|
|
89
|
-
fire_popstate();
|
|
114
|
+
traverse_to(session.index - 1);
|
|
90
115
|
}
|
|
91
116
|
|
|
92
117
|
function next_task()
|
|
@@ -256,8 +281,9 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
256
281
|
{keep_on_navigate: true});
|
|
257
282
|
expect(second.marker_pending).toBe(true);
|
|
258
283
|
|
|
259
|
-
/* A navigation: the hash moves,
|
|
260
|
-
|
|
284
|
+
/* A navigation: the hash moves (a new entry, as a link does), our
|
|
285
|
+
* back() will never land. */
|
|
286
|
+
window.history.pushState(null, "", "#/other");
|
|
261
287
|
window.dispatchEvent(new Event("hashchange"));
|
|
262
288
|
expect(shell.priv.expected_pops).toBe(0);
|
|
263
289
|
expect(second.marker_pending).toBe(false);
|
|
@@ -288,4 +314,68 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
288
314
|
expect(shell.priv.expected_pops).toBe(0);
|
|
289
315
|
expect(shell.priv.pending_markers).toEqual([]);
|
|
290
316
|
});
|
|
317
|
+
|
|
318
|
+
test("a dropped back() and a Back to another hash: the waiting overlay is not closed, no orphan marker", async () => {
|
|
319
|
+
const app = gobj_create("mapp6", "C_TEST_MARKER_APP", {}, yuno);
|
|
320
|
+
gobj_start(app);
|
|
321
|
+
const shell = gobj_create("mshell6", "C_YUI_SHELL",
|
|
322
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
323
|
+
gobj_start(shell);
|
|
324
|
+
window.location.hash = "#/prev";
|
|
325
|
+
install_history_model();
|
|
326
|
+
window.history.pushState(null, "", "#/home"); // a route entry
|
|
327
|
+
|
|
328
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
329
|
+
await import("./c_yui_shell.js");
|
|
330
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
331
|
+
window.history.back = () => {}; // the browser drops it
|
|
332
|
+
yui_shell_overlay_dismissed(shell, first);
|
|
333
|
+
expect(shell.priv.expected_pops).toBe(1);
|
|
334
|
+
let closed = 0;
|
|
335
|
+
const second = yui_shell_register_overlay(shell, () => { closed++; },
|
|
336
|
+
{keep_on_navigate: true});
|
|
337
|
+
expect(second.marker_pending).toBe(true);
|
|
338
|
+
|
|
339
|
+
/* The reader goes back two entries at once (a long press on Back,
|
|
340
|
+
* history.go(-2)): from the dead marker straight to #/prev, a hash
|
|
341
|
+
* that is not the landing ours expected. */
|
|
342
|
+
traverse_to(0);
|
|
343
|
+
expect(window.location.hash).toBe("#/prev");
|
|
344
|
+
expect(closed).toBe(0);
|
|
345
|
+
expect(shell.priv.overlay_stack).toEqual([second]);
|
|
346
|
+
expect(second.marker_pending).toBe(false);
|
|
347
|
+
expect(window.history.state).toEqual({__yui_overlay__: second.id});
|
|
348
|
+
expect(second.hash).toBe("#/prev");
|
|
349
|
+
|
|
350
|
+
/* And its marker is a real one: the next Back closes it. */
|
|
351
|
+
user_back();
|
|
352
|
+
expect(closed).toBe(1);
|
|
353
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("a button close after a replace navigation lands where expected, without a 'dropped' warning", async () => {
|
|
357
|
+
const app = gobj_create("mapp7", "C_TEST_MARKER_APP", {}, yuno);
|
|
358
|
+
gobj_start(app);
|
|
359
|
+
const shell = gobj_create("mshell7", "C_YUI_SHELL",
|
|
360
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
361
|
+
gobj_start(shell);
|
|
362
|
+
window.location.hash = "#/home";
|
|
363
|
+
install_history_model();
|
|
364
|
+
|
|
365
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
366
|
+
await import("./c_yui_shell.js");
|
|
367
|
+
const entry = yui_shell_register_overlay(shell, () => {}, {keep_on_navigate: true});
|
|
368
|
+
/* The view under it writes its position into the URL with replace:
|
|
369
|
+
* the marker's own entry moves to another hash. */
|
|
370
|
+
window.history.replaceState(window.history.state, "", "#/home/pos");
|
|
371
|
+
logged.length = 0;
|
|
372
|
+
|
|
373
|
+
yui_shell_overlay_dismissed(shell, entry); // the close button
|
|
374
|
+
await next_task();
|
|
375
|
+
await next_task();
|
|
376
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
377
|
+
expect(window.location.hash).toBe("#/home");
|
|
378
|
+
expect(logged.some((l) => l.msg.includes("did not land"))).toBe(false);
|
|
379
|
+
});
|
|
291
380
|
});
|
|
381
|
+
|