@yuneta/gobj-ui 7.26.10 → 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 +27 -7
- package/dist/gobj-ui.cjs.js +132 -66
- package/dist/gobj-ui.es.js +132 -66
- package/package.json +3 -2
- package/scripts/check-markup-strings.mjs +372 -0
- package/src/c_g6_nodes_tree.js +31 -8
- package/src/c_yui_form.js +2 -1
- package/src/c_yui_gclass.js +5 -5
- package/src/c_yui_json.js +1 -1
- package/src/c_yui_schema_editor.js +2 -2
- package/src/c_yui_shell.js +71 -2
- package/src/c_yui_treedb_graph.js +2 -1
- package/src/c_yui_treedb_topic_with_form.js +8 -4
- package/src/c_yui_window.js +2 -1
- package/src/c_yui_window_manager.js +14 -4
- package/src/gclass_head_text.wiring.test.js +63 -0
- package/src/overlay_marker_after_back.wiring.test.js +180 -11
- package/src/window_show.wiring.test.js +48 -0
- package/src/yui_text.js +16 -0
- package/src/yui_text.test.js +13 -1
package/src/c_yui_shell.js
CHANGED
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
} from "./shell_toolbar_helpers.js";
|
|
65
65
|
|
|
66
66
|
import { resolve_route, normalize_route } from "./route_resolver.js";
|
|
67
|
+
import { text_node } from "./yui_text.js";
|
|
67
68
|
import { build_nav_map } from "./route_map_model.js";
|
|
68
69
|
import {
|
|
69
70
|
section_index_target,
|
|
@@ -155,6 +156,11 @@ let PRIVATE_DATA = {
|
|
|
155
156
|
/* Count of history.back() calls WE issued to retire a dismissed
|
|
156
157
|
* overlay; the popstate they trigger is expected and ignored. */
|
|
157
158
|
expected_pops: 0,
|
|
159
|
+
/* The hash those history.back() calls were issued on: a back() of
|
|
160
|
+
* ours steps off a marker and lands on the SAME hash. A landing on
|
|
161
|
+
* another hash means the browser dropped ours (a navigation in the
|
|
162
|
+
* same turn cancels a queued traversal), see drop_expected_pops(). */
|
|
163
|
+
expected_pop_hash: "",
|
|
158
164
|
/* Overlays registered while one of those history.back() calls is
|
|
159
165
|
* still in flight: their marker is pushed once it has landed. */
|
|
160
166
|
pending_markers: [],
|
|
@@ -260,10 +266,22 @@ function mt_start(gobj)
|
|
|
260
266
|
|
|
261
267
|
if(gobj_read_attr(gobj, "use_hash")) {
|
|
262
268
|
priv.hash_handler = () => {
|
|
269
|
+
let p = gobj.priv;
|
|
270
|
+
let dropped = false;
|
|
271
|
+
if(p && p.expected_pops > 0 &&
|
|
272
|
+
window.location.hash !== p.expected_pop_hash) {
|
|
273
|
+
drop_expected_pops(gobj); // a back() of ours never landed
|
|
274
|
+
dropped = true;
|
|
275
|
+
}
|
|
263
276
|
let route = hash_to_route(window.location.hash);
|
|
264
277
|
if(!empty_string(route)) {
|
|
265
278
|
navigate_to(gobj, route);
|
|
266
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
|
+
}
|
|
267
285
|
};
|
|
268
286
|
window.addEventListener("hashchange", priv.hash_handler);
|
|
269
287
|
|
|
@@ -277,6 +295,23 @@ function mt_start(gobj)
|
|
|
277
295
|
if(!p) {
|
|
278
296
|
return;
|
|
279
297
|
}
|
|
298
|
+
if(p.expected_pops > 0 &&
|
|
299
|
+
window.location.hash !== p.expected_pop_hash) {
|
|
300
|
+
/* Not the landing of ours: it was dropped. Whatever
|
|
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. */
|
|
306
|
+
drop_expected_pops(gobj);
|
|
307
|
+
on_traversal(ev);
|
|
308
|
+
push_pending_markers(gobj);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
on_traversal(ev);
|
|
312
|
+
};
|
|
313
|
+
let on_traversal = (ev) => {
|
|
314
|
+
let p = gobj.priv;
|
|
280
315
|
if(p.expected_pops > 0) {
|
|
281
316
|
/* A history.back() we issued to retire a dismissed
|
|
282
317
|
* overlay — the teardown already happened. */
|
|
@@ -290,6 +325,10 @@ function mt_start(gobj)
|
|
|
290
325
|
return;
|
|
291
326
|
}
|
|
292
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
|
+
}
|
|
293
332
|
/* Did this traversal step OFF the top overlay's marker?
|
|
294
333
|
* That is the only landing that closes it, and the marker's
|
|
295
334
|
* OWN hash is what says so: pushState() with no URL keeps
|
|
@@ -397,6 +436,10 @@ function mt_stop(gobj)
|
|
|
397
436
|
window.removeEventListener("popstate", priv.popstate_handler);
|
|
398
437
|
priv.popstate_handler = null;
|
|
399
438
|
}
|
|
439
|
+
/* Nothing listens for the landings any more. */
|
|
440
|
+
priv.expected_pops = 0;
|
|
441
|
+
priv.expected_pop_hash = "";
|
|
442
|
+
priv.pending_markers = [];
|
|
400
443
|
if(priv.keydown_handler) {
|
|
401
444
|
window.removeEventListener("keydown", priv.keydown_handler);
|
|
402
445
|
priv.keydown_handler = null;
|
|
@@ -1787,7 +1830,7 @@ function build_toolbar_action_item(gobj, it)
|
|
|
1787
1830
|
}
|
|
1788
1831
|
if(!empty_string(it.name)) {
|
|
1789
1832
|
children.push(["span", {class: "yui-toolbar-item-label", i18n: it.name},
|
|
1790
|
-
it.name]);
|
|
1833
|
+
text_node(it.name)]);
|
|
1791
1834
|
}
|
|
1792
1835
|
|
|
1793
1836
|
let aria_key = it.aria_label || it.name || it.id || "";
|
|
@@ -2372,7 +2415,7 @@ function build_dropdown_row(gobj, sub, idx)
|
|
|
2372
2415
|
}
|
|
2373
2416
|
if(!empty_string(sub.name)) {
|
|
2374
2417
|
children.push(["span", {class: "yui-toolbar-dropdown-label",
|
|
2375
|
-
i18n: sub.name}, sub.name]);
|
|
2418
|
+
i18n: sub.name}, text_node(sub.name)]);
|
|
2376
2419
|
}
|
|
2377
2420
|
/* Trailing check for the ACTIVE option. The element is always
|
|
2378
2421
|
* rendered and hidden by CSS when not selected, so every row keeps
|
|
@@ -2631,6 +2674,10 @@ function push_overlay_history(gobj, close, opts)
|
|
|
2631
2674
|
function push_overlay_marker(gobj, entry)
|
|
2632
2675
|
{
|
|
2633
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;
|
|
2634
2681
|
try {
|
|
2635
2682
|
window.history.pushState({ __yui_overlay__: entry.id }, "");
|
|
2636
2683
|
} catch(e) {
|
|
@@ -2646,6 +2693,26 @@ function push_overlay_marker(gobj, entry)
|
|
|
2646
2693
|
return true;
|
|
2647
2694
|
}
|
|
2648
2695
|
|
|
2696
|
+
/* A history.back() of ours that the browser dropped: nothing will land
|
|
2697
|
+
* for it, so it must not wait for a landing and swallow the reader's
|
|
2698
|
+
* next Back. The overlays that waited for it get their markers from the
|
|
2699
|
+
* caller (push_pending_markers()), after the traversal is handled. */
|
|
2700
|
+
function drop_expected_pops(gobj)
|
|
2701
|
+
{
|
|
2702
|
+
let priv = gobj.priv;
|
|
2703
|
+
if(!priv || priv.expected_pops === 0) {
|
|
2704
|
+
return;
|
|
2705
|
+
}
|
|
2706
|
+
log_warning(
|
|
2707
|
+
`C_YUI_SHELL: ${priv.expected_pops} history.back() of ours did ` +
|
|
2708
|
+
`not land on '${priv.expected_pop_hash}' (now '${window.location.hash}'), dropped`
|
|
2709
|
+
);
|
|
2710
|
+
priv.expected_pops = 0;
|
|
2711
|
+
priv.expected_pop_hash = "";
|
|
2712
|
+
/* The caller pushes the waiting markers, once it has handled the
|
|
2713
|
+
* traversal that told it. */
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2649
2716
|
/* The history.back() calls of ours have all landed: push the markers of
|
|
2650
2717
|
* the overlays registered meanwhile, in their order. One closed in the
|
|
2651
2718
|
* meantime (dismissed, drained, or no longer on the stack) has none. */
|
|
@@ -2699,6 +2766,8 @@ function overlay_dismissed(gobj, entry)
|
|
|
2699
2766
|
let st = window.history.state;
|
|
2700
2767
|
if(st && st.__yui_overlay__ === entry.id) {
|
|
2701
2768
|
priv.expected_pops++;
|
|
2769
|
+
priv.expected_pop_hash = (typeof entry.below_hash === "string")?
|
|
2770
|
+
entry.below_hash : window.location.hash;
|
|
2702
2771
|
try {
|
|
2703
2772
|
window.history.back();
|
|
2704
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}`]
|
|
@@ -122,7 +122,7 @@ import "./tabulator.css";
|
|
|
122
122
|
import {cell_text, hook_cell_spec} from "./table_cell_text.js";
|
|
123
123
|
|
|
124
124
|
import { TabulatorFull as Tabulator } from "tabulator-tables";
|
|
125
|
-
import {text_node} from "./yui_text.js";
|
|
125
|
+
import {text_node, text_list_item_formatter} from "./yui_text.js";
|
|
126
126
|
|
|
127
127
|
/***************************************************************
|
|
128
128
|
* Constants
|
|
@@ -1288,7 +1288,10 @@ function create_tabulator(gobj)
|
|
|
1288
1288
|
break;
|
|
1289
1289
|
case "enum":
|
|
1290
1290
|
colDef.editor = "list";
|
|
1291
|
-
colDef.editorParams = {
|
|
1291
|
+
colDef.editorParams = {
|
|
1292
|
+
values: field_desc.enum_list || [],
|
|
1293
|
+
itemFormatter: text_list_item_formatter // schema data
|
|
1294
|
+
};
|
|
1292
1295
|
break;
|
|
1293
1296
|
case "integer":
|
|
1294
1297
|
case "real":
|
|
@@ -1339,7 +1342,8 @@ function create_tabulator(gobj)
|
|
|
1339
1342
|
colDef.headerFilter = "list";
|
|
1340
1343
|
colDef.headerFilterParams = {
|
|
1341
1344
|
values: field_desc.enum_list || [],
|
|
1342
|
-
clearable: true
|
|
1345
|
+
clearable: true,
|
|
1346
|
+
itemFormatter: text_list_item_formatter // schema data
|
|
1343
1347
|
};
|
|
1344
1348
|
break;
|
|
1345
1349
|
case "fkey":
|
|
@@ -2080,7 +2084,7 @@ function icon_formatter(cell)
|
|
|
2080
2084
|
return createElement2([
|
|
2081
2085
|
"span",
|
|
2082
2086
|
{class: "ICON_CELL_UNKNOWN is-size-7 yui-text-quiet", title: name},
|
|
2083
|
-
name
|
|
2087
|
+
text_node(name) // data, not markup: it failed the name check
|
|
2084
2088
|
]);
|
|
2085
2089
|
}
|
|
2086
2090
|
|
package/src/c_yui_window.js
CHANGED
|
@@ -335,7 +335,8 @@ function build_default_header(gobj)
|
|
|
335
335
|
let items = [];
|
|
336
336
|
if(!empty_string(icon)) {
|
|
337
337
|
if(icon.charAt(0) === '<') {
|
|
338
|
-
|
|
338
|
+
/* The `icon` attr is the app's own: inline svg is markup. */
|
|
339
|
+
items.push(['span', {class: 'icon'}, html_markup(icon)]);
|
|
339
340
|
} else {
|
|
340
341
|
items.push(['span', {class: 'icon'}, [['i', {class: icon}]]]);
|
|
341
342
|
}
|
|
@@ -339,14 +339,12 @@ function chip_lead(icon)
|
|
|
339
339
|
return ['span', {class: 'yui-dock-dot'}, ''];
|
|
340
340
|
}
|
|
341
341
|
if(icon.charAt(0) === '<') {
|
|
342
|
-
|
|
342
|
+
/* The window's `icon` attr, the app's own: inline svg is markup. */
|
|
343
|
+
return ['span', {class: 'yui-dock-icon'}, html_markup(icon)];
|
|
343
344
|
}
|
|
344
345
|
return ['span', {class: 'yui-dock-icon'}, [['i', {class: icon}]]];
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
/************************************************************
|
|
348
|
-
* Find a registry entry by its window gobj.
|
|
349
|
-
************************************************************/
|
|
350
348
|
/************************************************************
|
|
351
349
|
* The window an event is about. A kw is plain json (the machine
|
|
352
350
|
* trace dumps it), so the window travels in it as its FULL NAME,
|
|
@@ -367,6 +365,15 @@ function window_of(gobj, event, kw, src)
|
|
|
367
365
|
`in its kw: send {window: gobj_full_name(window)} from the window`
|
|
368
366
|
);
|
|
369
367
|
}
|
|
368
|
+
if(w !== src) {
|
|
369
|
+
/* Only the window speaks for itself, in either form. */
|
|
370
|
+
log_error(
|
|
371
|
+
`${gobj_short_name(gobj)}: ${event}: window ` +
|
|
372
|
+
`'${gobj_full_name(w)}' is not the src of the event ` +
|
|
373
|
+
`(${is_gobj(src) ? gobj_full_name(src) : String(src)})`
|
|
374
|
+
);
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
370
377
|
return w;
|
|
371
378
|
}
|
|
372
379
|
if(!is_gobj(src) || gobj_full_name(src) !== w) {
|
|
@@ -379,6 +386,9 @@ function window_of(gobj, event, kw, src)
|
|
|
379
386
|
return src;
|
|
380
387
|
}
|
|
381
388
|
|
|
389
|
+
/************************************************************
|
|
390
|
+
* Find a registry entry by its window gobj.
|
|
391
|
+
************************************************************/
|
|
382
392
|
function find_entry(priv, win)
|
|
383
393
|
{
|
|
384
394
|
for(let e of priv.windows) {
|
|
@@ -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()
|
|
@@ -209,4 +234,148 @@ describe("an overlay registered while a back() of ours is in flight", () => {
|
|
|
209
234
|
expect(window.history.state).toBe(null);
|
|
210
235
|
expect(errors()).toEqual([]);
|
|
211
236
|
});
|
|
237
|
+
|
|
238
|
+
test("a user Back queued after ours is the user's: it closes the next overlay", async () => {
|
|
239
|
+
const app = gobj_create("mapp3", "C_TEST_MARKER_APP", {}, yuno);
|
|
240
|
+
gobj_start(app);
|
|
241
|
+
const shell = gobj_create("mshell3", "C_YUI_SHELL",
|
|
242
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
243
|
+
gobj_start(shell);
|
|
244
|
+
logged.length = 0;
|
|
245
|
+
install_history_model();
|
|
246
|
+
|
|
247
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
248
|
+
await import("./c_yui_shell.js");
|
|
249
|
+
let closed_a = 0;
|
|
250
|
+
const a = yui_shell_register_overlay(shell, () => { closed_a++; });
|
|
251
|
+
const b = yui_shell_register_overlay(shell, () => {});
|
|
252
|
+
expect(session.entries.length).toBe(3);
|
|
253
|
+
yui_shell_overlay_dismissed(shell, b); // our back(), in flight
|
|
254
|
+
await next_task(); // ours lands first...
|
|
255
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
256
|
+
user_back(); // ... then the user's
|
|
257
|
+
expect(closed_a).toBe(1);
|
|
258
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
259
|
+
expect(errors()).toEqual([]);
|
|
260
|
+
expect(a).toBeTruthy();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("a back() of ours that never lands does not swallow the next Back", async () => {
|
|
264
|
+
const app = gobj_create("mapp4", "C_TEST_MARKER_APP", {}, yuno);
|
|
265
|
+
gobj_start(app);
|
|
266
|
+
const shell = gobj_create("mshell4", "C_YUI_SHELL",
|
|
267
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
268
|
+
gobj_start(shell);
|
|
269
|
+
logged.length = 0;
|
|
270
|
+
install_history_model();
|
|
271
|
+
window.location.hash = "#/home";
|
|
272
|
+
|
|
273
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
274
|
+
await import("./c_yui_shell.js");
|
|
275
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
276
|
+
window.history.back = () => {}; // the browser drops it
|
|
277
|
+
yui_shell_overlay_dismissed(shell, first);
|
|
278
|
+
expect(shell.priv.expected_pops).toBe(1);
|
|
279
|
+
let closed = 0;
|
|
280
|
+
const second = yui_shell_register_overlay(shell, () => { closed++; },
|
|
281
|
+
{keep_on_navigate: true});
|
|
282
|
+
expect(second.marker_pending).toBe(true);
|
|
283
|
+
|
|
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");
|
|
287
|
+
window.dispatchEvent(new Event("hashchange"));
|
|
288
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
289
|
+
expect(second.marker_pending).toBe(false);
|
|
290
|
+
expect(window.history.state).toEqual({__yui_overlay__: second.id});
|
|
291
|
+
|
|
292
|
+
/* The next Back is the user's, and it closes the overlay. */
|
|
293
|
+
logged.length = 0;
|
|
294
|
+
user_back();
|
|
295
|
+
expect(closed).toBe(1);
|
|
296
|
+
expect(errors()).toEqual([]);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("mt_stop forgets the landings it can no longer hear", async () => {
|
|
300
|
+
const app = gobj_create("mapp5", "C_TEST_MARKER_APP", {}, yuno);
|
|
301
|
+
gobj_start(app);
|
|
302
|
+
const shell = gobj_create("mshell5", "C_YUI_SHELL",
|
|
303
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
304
|
+
gobj_start(shell);
|
|
305
|
+
install_history_model();
|
|
306
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
307
|
+
await import("./c_yui_shell.js");
|
|
308
|
+
const {gobj_stop} = await import("@yuneta/gobj-js");
|
|
309
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
310
|
+
window.history.back = () => {};
|
|
311
|
+
yui_shell_overlay_dismissed(shell, first);
|
|
312
|
+
yui_shell_register_overlay(shell, () => {});
|
|
313
|
+
gobj_stop(shell);
|
|
314
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
315
|
+
expect(shell.priv.pending_markers).toEqual([]);
|
|
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
|
+
});
|
|
212
380
|
});
|
|
381
|
+
|
|
@@ -127,4 +127,52 @@ describe("EV_SHOW", () => {
|
|
|
127
127
|
set_strings_are_text(false);
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
|
+
|
|
131
|
+
test("only the window speaks for itself: a name or a gobj that is not the src is refused", () => {
|
|
132
|
+
const dock = gobj_create_service("src_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
|
|
133
|
+
gobj_start(dock);
|
|
134
|
+
const w = gobj_create_service("src_w", "C_YUI_WINDOW",
|
|
135
|
+
{header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
|
|
136
|
+
gobj_start(w);
|
|
137
|
+
const other = gobj_create_service("src_other", "C_YUI_WINDOW",
|
|
138
|
+
{header: "o", body: ["div", {}, "o"]}, yuno);
|
|
139
|
+
gobj_start(other);
|
|
140
|
+
const $w = gobj_read_attr(w, "$container");
|
|
141
|
+
const n_windows = dock.priv.windows.length;
|
|
142
|
+
|
|
143
|
+
for(const ev of ["EV_REGISTER_WINDOW", "EV_FOCUS_WINDOW", "EV_UNREGISTER_WINDOW", "EV_MINIMIZE_WINDOW"]) {
|
|
144
|
+
/* w's name, sent by another gobj. */
|
|
145
|
+
logged.length = 0;
|
|
146
|
+
gobj_send_event(dock, ev, {window: gobj_full_name(w)}, other);
|
|
147
|
+
expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
|
|
148
|
+
/* The OLD form (the gobj in the kw), sent by another gobj. */
|
|
149
|
+
logged.length = 0;
|
|
150
|
+
gobj_send_event(dock, ev, {window: w}, other);
|
|
151
|
+
expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
|
|
152
|
+
}
|
|
153
|
+
expect(dock.priv.windows.length).toBe(n_windows); // nothing unregistered
|
|
154
|
+
expect(dock.priv.windows.some((e) => e.gobj === other)).toBe(false); // nothing registered
|
|
155
|
+
expect($w.style.getPropertyValue("display")).toBe(""); // nothing minimized
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("an inline-svg icon is the app's markup, in strict mode too", async () => {
|
|
159
|
+
const {set_strings_are_text} = await import("@yuneta/gobj-js");
|
|
160
|
+
set_strings_are_text(true);
|
|
161
|
+
try {
|
|
162
|
+
logged.length = 0;
|
|
163
|
+
const dock = gobj_create_service("icon_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
|
|
164
|
+
gobj_start(dock);
|
|
165
|
+
const svg = '<svg viewBox="0 0 8 8"><rect width="8" height="8"/></svg>';
|
|
166
|
+
const w = gobj_create_service("icon_w", "C_YUI_WINDOW",
|
|
167
|
+
{title: "w", icon: svg, body: ["div", {}, "w"], manager: dock}, yuno);
|
|
168
|
+
gobj_start(w);
|
|
169
|
+
const $w = gobj_read_attr(w, "$container");
|
|
170
|
+
expect($w.querySelector(".icon svg")).not.toBe(null);
|
|
171
|
+
const $dock = gobj_read_attr(dock, "$container");
|
|
172
|
+
expect($dock.querySelector(".yui-dock-icon svg")).not.toBe(null);
|
|
173
|
+
expect(logged.filter((l) => l.msg.includes("html_markup"))).toEqual([]);
|
|
174
|
+
} finally {
|
|
175
|
+
set_strings_are_text(false);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
130
178
|
});
|
package/src/yui_text.js
CHANGED
|
@@ -41,3 +41,19 @@ export function text_title_formatter(cell)
|
|
|
41
41
|
{
|
|
42
42
|
return text_node(cell.getValue());
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
/************************************************************
|
|
46
|
+
* A Tabulator `itemFormatter` for a `list` editor or header filter
|
|
47
|
+
* that shows each item's label as text.
|
|
48
|
+
*
|
|
49
|
+
* Tabulator appends what an itemFormatter returns only when it is an
|
|
50
|
+
* HTMLElement (a Text node would be innerHTML'd as "[object Text]"),
|
|
51
|
+
* and it puts a bare label in with innerHTML. A label taken from a
|
|
52
|
+
* schema (`enum_list`) is data, so it goes in a span, as text.
|
|
53
|
+
************************************************************/
|
|
54
|
+
export function text_list_item_formatter(label)
|
|
55
|
+
{
|
|
56
|
+
const span = document.createElement("span");
|
|
57
|
+
span.textContent = (label === null || label === undefined) ? "" : String(label);
|
|
58
|
+
return span;
|
|
59
|
+
}
|
package/src/yui_text.test.js
CHANGED
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
|
|
18
18
|
gobj_read_attr, set_log_callback
|
|
19
19
|
} = await import("@yuneta/gobj-js");
|
|
20
|
-
const {text_node, text_title_formatter} = await import("./yui_text.js");
|
|
20
|
+
const {text_node, text_title_formatter, text_list_item_formatter} = await import("./yui_text.js");
|
|
21
21
|
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
22
22
|
const {card_descriptor} = await import("./nav_cards_helpers.js");
|
|
23
23
|
|
|
@@ -65,3 +65,15 @@ describe("text_node()", () => {
|
|
|
65
65
|
expect($c.querySelector(".yui-accordion-head").textContent).toBe(EVIL);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
describe("text_list_item_formatter (Tabulator list editor / header filter)", () => {
|
|
70
|
+
test("returns an ELEMENT (Tabulator appends only an HTMLElement) holding the label as text", () => {
|
|
71
|
+
const EVIL = '<img src=x onerror="window.__pwned=1">';
|
|
72
|
+
const el = text_list_item_formatter(EVIL, EVIL, {}, null);
|
|
73
|
+
expect(el instanceof HTMLElement).toBe(true);
|
|
74
|
+
expect(el.querySelector("img")).toBe(null);
|
|
75
|
+
expect(el.textContent).toBe(EVIL);
|
|
76
|
+
expect(text_list_item_formatter(null).textContent).toBe("");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|