@yuneta/gobj-ui 7.26.5 → 7.26.7
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 +141 -25
- package/dist/gobj-ui.cjs.js +1358 -429
- package/dist/gobj-ui.es.js +1349 -430
- package/index.js +18 -2
- package/package.json +2 -2
- package/src/c_g6_nodes_tree.js +41 -0
- package/src/c_yui_form.js +287 -91
- package/src/c_yui_gclass.js +6 -2
- package/src/c_yui_gobj_tree_js.js +15 -4
- package/src/c_yui_json_graph.js +40 -13
- package/src/c_yui_map.js +115 -75
- package/src/c_yui_nav.js +53 -14
- package/src/c_yui_pager.js +14 -9
- package/src/c_yui_period.js +16 -6
- package/src/c_yui_shell.js +116 -30
- package/src/c_yui_treedb_topic_with_form.js +111 -46
- package/src/c_yui_treedb_topics.js +77 -7
- package/src/c_yui_uplot.js +1 -1
- package/src/c_yui_window.js +70 -24
- package/src/c_yui_window_manager.js +7 -3
- package/src/c_yui_wizard.js +23 -8
- package/src/delete_impact.js +5 -3
- package/src/form_json_field.js +116 -0
- package/src/form_json_field.test.js +43 -0
- package/src/form_json_field.wiring.test.js +137 -0
- package/src/lib_icons.js +395 -0
- package/src/lib_icons.test.js +214 -0
- package/src/schema_to_c.js +17 -1
- package/src/schema_to_c.test.js +7 -0
- package/src/shell_route_map.js +6 -0
- package/src/treedb_topics_transport.wiring.test.js +9 -1
- package/src/window_veto_back.wiring.test.js +101 -0
- package/src/wizard_chrome.wiring.test.js +87 -0
- package/src/yui_dev.js +10 -3
- package/src/yui_icons.css +20 -0
- package/src/yui_table_filter_clear.js +44 -44
- package/vite-plugin-yuneta-html.js +28 -6
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* lib_icons.test.js
|
|
3
|
+
*
|
|
4
|
+
* Unit tests for the user icons of lib_icons: the svg rebuilt from
|
|
5
|
+
* its shapes, the mask url, and the registry that turns the nodes
|
|
6
|
+
* of __icons__ into `yi-u-<id>` rules.
|
|
7
|
+
*
|
|
8
|
+
* The suite runs in node, with no DOMParser: the sanitizer is
|
|
9
|
+
* tested on its PARSED half (rebuild_svg_from_shapes) with trees
|
|
10
|
+
* built here, and the registry gets a DOMParser double that hands
|
|
11
|
+
* those same trees back.
|
|
12
|
+
* Run with: npm test
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {test, expect, beforeAll} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double();
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
rebuild_svg_from_shapes,
|
|
24
|
+
svg_mask_url,
|
|
25
|
+
yui_user_icon_class,
|
|
26
|
+
yui_icons_is_svg_field,
|
|
27
|
+
yui_icons_set_user,
|
|
28
|
+
yui_icons_put_user,
|
|
29
|
+
yui_icons_remove_user,
|
|
30
|
+
yui_icons_list,
|
|
31
|
+
USER_ICON_PREFIX,
|
|
32
|
+
ICONS_TOPIC,
|
|
33
|
+
} = await import("./lib_icons.js");
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
* An element as rebuild_svg_from_shapes() reads it: a DOM element has
|
|
37
|
+
* more, and these are the only parts it touches.
|
|
38
|
+
*/
|
|
39
|
+
function el(name, attrs, children)
|
|
40
|
+
{
|
|
41
|
+
attrs = attrs || {};
|
|
42
|
+
return {
|
|
43
|
+
localName: name,
|
|
44
|
+
attributes: Object.entries(attrs).map(([k, v]) => {
|
|
45
|
+
let i = k.indexOf(":");
|
|
46
|
+
return {
|
|
47
|
+
name: k,
|
|
48
|
+
localName: i >= 0? k.substring(i + 1) : k,
|
|
49
|
+
prefix: i >= 0? k.substring(0, i) : null,
|
|
50
|
+
value: v
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
children: children || [],
|
|
54
|
+
getAttribute(n) {
|
|
55
|
+
return Object.prototype.hasOwnProperty.call(attrs, n)? attrs[n] : null;
|
|
56
|
+
},
|
|
57
|
+
getElementsByTagName() {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const BOLT = el("svg", {xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24"}, [
|
|
64
|
+
el("path", {d: "M13 2L3 14h9l-1 8 10-12h-9l1-8z"})
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
test("a plain icon comes back as its shapes, in a clean svg", () => {
|
|
68
|
+
let r = rebuild_svg_from_shapes(BOLT);
|
|
69
|
+
expect(r.error).toBeUndefined();
|
|
70
|
+
expect(r.svg).toBe(
|
|
71
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">' +
|
|
72
|
+
'<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"></path></svg>'
|
|
73
|
+
);
|
|
74
|
+
expect(r.dropped).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
* What a hostile svg carries is LEFT OUT and named, never copied: it is
|
|
79
|
+
* written by whoever can write a node and drawn on every page.
|
|
80
|
+
*/
|
|
81
|
+
test("script, foreignObject, image, use and handlers are dropped", () => {
|
|
82
|
+
let svg = el("svg", {viewBox: "0 0 10 10", onload: "alert(1)"}, [
|
|
83
|
+
el("script", {}, []),
|
|
84
|
+
el("foreignObject", {}, [el("div")]),
|
|
85
|
+
el("image", {"xlink:href": "http://x/y.png"}),
|
|
86
|
+
el("use", {href: "#a"}),
|
|
87
|
+
el("path", {d: "M0 0h10v10z", onclick: "alert(2)", "xlink:href": "javascript:alert(3)"})
|
|
88
|
+
]);
|
|
89
|
+
let r = rebuild_svg_from_shapes(svg);
|
|
90
|
+
expect(r.svg).toBe(
|
|
91
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">' +
|
|
92
|
+
'<path d="M0 0h10v10z"></path></svg>'
|
|
93
|
+
);
|
|
94
|
+
expect(r.dropped).toEqual(expect.arrayContaining([
|
|
95
|
+
"script", "foreignObject", "image", "use", "@onclick", "@xlink:href", "@onload"
|
|
96
|
+
]));
|
|
97
|
+
expect(r.svg).not.toMatch(/alert|script|href/);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a value that is a url, or could close its quote, is dropped", () => {
|
|
101
|
+
let svg = el("svg", {viewBox: "0 0 10 10"}, [
|
|
102
|
+
el("rect", {x: "0", y: "0", width: "10", height: "10",
|
|
103
|
+
fill: "url(#grad)", stroke: '"/><script>'})
|
|
104
|
+
]);
|
|
105
|
+
let r = rebuild_svg_from_shapes(svg);
|
|
106
|
+
expect(r.svg).toBe(
|
|
107
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">' +
|
|
108
|
+
'<rect x="0" y="0" width="10" height="10"></rect></svg>'
|
|
109
|
+
);
|
|
110
|
+
expect(r.dropped).toEqual(expect.arrayContaining(["@fill", "@stroke"]));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("an icon drawn with strokes keeps the root's stroke and fill", () => {
|
|
114
|
+
let svg = el("svg", {viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
|
|
115
|
+
"stroke-width": "2", "stroke-linecap": "round"}, [
|
|
116
|
+
el("g", {}, [el("line", {x1: "1", y1: "1", x2: "23", y2: "23"})])
|
|
117
|
+
]);
|
|
118
|
+
let r = rebuild_svg_from_shapes(svg);
|
|
119
|
+
expect(r.svg).toBe(
|
|
120
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" ' +
|
|
121
|
+
'stroke="currentColor" stroke-width="2" stroke-linecap="round">' +
|
|
122
|
+
'<g><line x1="1" y1="1" x2="23" y2="23"></line></g></svg>'
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("the box comes from width and height when there is no viewBox", () => {
|
|
127
|
+
let svg = el("svg", {width: "32", height: "16"}, [el("circle", {cx: "8", cy: "8", r: "8"})]);
|
|
128
|
+
expect(rebuild_svg_from_shapes(svg).svg).toMatch(/viewBox="0 0 32 16"/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("what cannot be drawn is refused, saying why", () => {
|
|
132
|
+
expect(rebuild_svg_from_shapes(el("svg", {}, [el("path", {d: "M0 0"})])).error)
|
|
133
|
+
.toBe("svg without size");
|
|
134
|
+
expect(rebuild_svg_from_shapes(el("svg", {viewBox: "0 0 1 1"}, [el("g")])).error)
|
|
135
|
+
.toBe("svg without shapes");
|
|
136
|
+
expect(rebuild_svg_from_shapes(el("html")).error).toBe("not an svg document");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* The mask url is written into a stylesheet: nothing in it may end the
|
|
141
|
+
* string or the url.
|
|
142
|
+
*/
|
|
143
|
+
test("the mask url encodes what could end it", () => {
|
|
144
|
+
let url = svg_mask_url('<svg a="1">)</svg>\n');
|
|
145
|
+
expect(url.startsWith('url("data:image/svg+xml,')).toBe(true);
|
|
146
|
+
expect(url.endsWith('")')).toBe(true);
|
|
147
|
+
let body = url.slice('url("'.length, -'")'.length);
|
|
148
|
+
expect(body).not.toMatch(/["\n\\]/);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("a user icon lives in its own namespace", () => {
|
|
152
|
+
expect(USER_ICON_PREFIX).toBe("yi-u-");
|
|
153
|
+
expect(yui_user_icon_class("transformer")).toBe("yi-u-transformer");
|
|
154
|
+
expect(yui_icons_is_svg_field(ICONS_TOPIC, "svg")).toBe(true);
|
|
155
|
+
expect(yui_icons_is_svg_field("device_types", "svg")).toBe(false);
|
|
156
|
+
expect(yui_icons_is_svg_field(ICONS_TOPIC, "id")).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
* The registry. Its DOMParser is a double that answers with the trees
|
|
161
|
+
* above, keyed by the text it is given.
|
|
162
|
+
*/
|
|
163
|
+
const TREES = {
|
|
164
|
+
"bolt": BOLT,
|
|
165
|
+
"box": el("svg", {viewBox: "0 0 2 2"}, [el("rect", {width: "2", height: "2"})]),
|
|
166
|
+
"empty": el("svg", {viewBox: "0 0 2 2"}, [])
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
beforeAll(() => {
|
|
170
|
+
globalThis.DOMParser = class {
|
|
171
|
+
parseFromString(text) {
|
|
172
|
+
return {documentElement: TREES[text] || el("parsererror")};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
function user_css()
|
|
178
|
+
{
|
|
179
|
+
let style = document.getElementById("yui-user-icons");
|
|
180
|
+
return style? style.textContent : "";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
test("the nodes of __icons__ become yi-u- rules, the bad ones left out", () => {
|
|
184
|
+
let n = yui_icons_set_user([
|
|
185
|
+
{id: "bolt", svg: "bolt"},
|
|
186
|
+
{id: "box", svg: "box"},
|
|
187
|
+
{id: "Bad Name", svg: "box"},
|
|
188
|
+
{id: "nothing", svg: "empty"},
|
|
189
|
+
{id: "junk", svg: "<not svg"}
|
|
190
|
+
]);
|
|
191
|
+
expect(n).toBe(2);
|
|
192
|
+
let css = user_css();
|
|
193
|
+
expect(css).toMatch(/\.yi-u-bolt::before \{/);
|
|
194
|
+
expect(css).toMatch(/\.yi-u-box::before \{/);
|
|
195
|
+
expect(css).not.toMatch(/nothing|junk|Bad/);
|
|
196
|
+
|
|
197
|
+
let users = yui_icons_list().filter(icon => icon.user).map(icon => icon.name);
|
|
198
|
+
expect(users).toEqual(["yi-u-bolt", "yi-u-box"]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("a write puts or takes away one icon", () => {
|
|
202
|
+
yui_icons_set_user([{id: "bolt", svg: "bolt"}]);
|
|
203
|
+
|
|
204
|
+
expect(yui_icons_put_user({id: "box", svg: "box"})).toBe(true);
|
|
205
|
+
expect(user_css()).toMatch(/\.yi-u-box::before/);
|
|
206
|
+
|
|
207
|
+
/* An update that broke the drawing takes the old one away. */
|
|
208
|
+
expect(yui_icons_put_user({id: "box", svg: "empty"})).toBe(false);
|
|
209
|
+
expect(user_css()).not.toMatch(/\.yi-u-box::before/);
|
|
210
|
+
|
|
211
|
+
yui_icons_remove_user("bolt");
|
|
212
|
+
expect(user_css()).toBe("");
|
|
213
|
+
expect(yui_icons_list().filter(icon => icon.user)).toEqual([]);
|
|
214
|
+
});
|
package/src/schema_to_c.js
CHANGED
|
@@ -267,7 +267,23 @@ function c_text(text)
|
|
|
267
267
|
return text
|
|
268
268
|
.replace(/\\/g, JSON_BACKSLASH)
|
|
269
269
|
.replace(/"/g, JSON_DQUOTE)
|
|
270
|
-
.replace(/'/g, JSON_QUOTE)
|
|
270
|
+
.replace(/'/g, JSON_QUOTE)
|
|
271
|
+
.replace(/[\u0000-\u001f\u007f]/g, json_control);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* A control character (a newline in a description) cannot stand as
|
|
275
|
+
* itself in either layer: a raw newline ends the C literal's line,
|
|
276
|
+
* and JSON refuses any control character inside a string. It is
|
|
277
|
+
* written as its JSON escape, with the backslash doubled for C. */
|
|
278
|
+
const JSON_SHORT_ESCAPES = {"\n": "n", "\r": "r", "\t": "t", "\b": "b", "\f": "f"};
|
|
279
|
+
|
|
280
|
+
function json_control(ch)
|
|
281
|
+
{
|
|
282
|
+
let short = JSON_SHORT_ESCAPES[ch];
|
|
283
|
+
if(short) {
|
|
284
|
+
return C_BACKSLASH + short;
|
|
285
|
+
}
|
|
286
|
+
return C_BACKSLASH + "u" + ch.charCodeAt(0).toString(16).padStart(4, "0");
|
|
271
287
|
}
|
|
272
288
|
|
|
273
289
|
/***************************************************************
|
package/src/schema_to_c.test.js
CHANGED
|
@@ -228,6 +228,13 @@ describe("the characters that cannot be written as themselves", () => {
|
|
|
228
228
|
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe("a\\b");
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
+
test("a newline, a tab and another control character survive both layers", () => {
|
|
232
|
+
const header = "line one\nline\ttwo\r\u0001";
|
|
233
|
+
const src = with_header(header);
|
|
234
|
+
expect(src.split("\n").every((line) => !line.includes("line two"))).toBe(true);
|
|
235
|
+
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe(header);
|
|
236
|
+
});
|
|
237
|
+
|
|
231
238
|
test("all three at once", () => {
|
|
232
239
|
const header = 'a\\b "c" d\'e';
|
|
233
240
|
expect(load_like_the_yuno(with_header(header)).topics[0].cols.id.header)
|
package/src/shell_route_map.js
CHANGED
|
@@ -249,6 +249,8 @@ function build_body(shell, t)
|
|
|
249
249
|
["input", {class: "input is-small ROUTEMAP_SEARCH", type: "text",
|
|
250
250
|
placeholder: t("filter", {defaultValue: "Filter…"}),
|
|
251
251
|
"data-i18n-placeholder": "filter",
|
|
252
|
+
title: t("filter", {defaultValue: "Filter"}),
|
|
253
|
+
"data-i18n-title": "filter",
|
|
252
254
|
"aria-label": t("filter", {defaultValue: "Filter"}),
|
|
253
255
|
"data-i18n-aria-label": "filter"}]
|
|
254
256
|
);
|
|
@@ -334,6 +336,10 @@ function build_body(shell, t)
|
|
|
334
336
|
$tree,
|
|
335
337
|
["div", {class: "ROUTEMAP_ACTIONS"}, [
|
|
336
338
|
["button", {class: "button is-small ROUTEMAP_PRINT",
|
|
339
|
+
title: t("print", {defaultValue: "Print"}),
|
|
340
|
+
"data-i18n-title": "print",
|
|
341
|
+
"aria-label": t("print", {defaultValue: "Print"}),
|
|
342
|
+
"data-i18n-aria-label": "print",
|
|
337
343
|
i18n: "print"}, t("print", {defaultValue: "Print"})]
|
|
338
344
|
]]
|
|
339
345
|
]]
|
|
@@ -38,7 +38,7 @@ const {
|
|
|
38
38
|
gobj_change_state, gobj_current_state,
|
|
39
39
|
set_log_callback,
|
|
40
40
|
} = gobj_js;
|
|
41
|
-
const {register_c_yui_shell, yui_shell_set_connection_state} = await import("./c_yui_shell.js");
|
|
41
|
+
const {register_c_yui_shell, yui_shell_set_connection_state, yui_shell_icons_changed} = await import("./c_yui_shell.js");
|
|
42
42
|
const {register_c_yui_treedb_topics} = await import("./c_yui_treedb_topics.js");
|
|
43
43
|
|
|
44
44
|
const logged = [];
|
|
@@ -255,6 +255,14 @@ describe("a Save in flight when the backend drops", () => {
|
|
|
255
255
|
expect(errors()).toEqual([]);
|
|
256
256
|
});
|
|
257
257
|
|
|
258
|
+
test("nor EV_ICONS_CHANGED, which 7.26.6 added to the shell", () => {
|
|
259
|
+
/* An app hosting a treedb view heard it on every load of
|
|
260
|
+
* `__icons__` and answered "Event NOT DEFINED in state". */
|
|
261
|
+
const {shell} = build("t4b");
|
|
262
|
+
yui_shell_icons_changed(shell);
|
|
263
|
+
expect(errors()).toEqual([]);
|
|
264
|
+
});
|
|
265
|
+
|
|
258
266
|
test("an answer from the backend settles its own form only", () => {
|
|
259
267
|
const {shell, topics, forms} = build("t5");
|
|
260
268
|
yui_shell_set_connection_state(shell, true);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* window_veto_back.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A floating C_YUI_WINDOW registers an entry in the shell's
|
|
5
|
+
* overlay history, so the browser Back closes it. The shell takes
|
|
6
|
+
* that entry off its stack BEFORE it calls the close; when a
|
|
7
|
+
* subscriber vetoed the close (EV_WINDOW_TO_CLOSE + abort_close),
|
|
8
|
+
* the window stayed up with no entry: the next Back did not close
|
|
9
|
+
* it, and a route change left it floating over the next view.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
15
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
16
|
+
|
|
17
|
+
install_dom_double();
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
SDATA_END, gclass_create,
|
|
21
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
22
|
+
gobj_start, gobj_read_attr, gobj_is_destroying,
|
|
23
|
+
set_log_callback,
|
|
24
|
+
} = await import("@yuneta/gobj-js");
|
|
25
|
+
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
26
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
27
|
+
|
|
28
|
+
const logged = [];
|
|
29
|
+
let veto = true;
|
|
30
|
+
let yuno = null;
|
|
31
|
+
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
const i18next = (await import("i18next")).default;
|
|
34
|
+
await i18next.init({lng: "en", resources: {}});
|
|
35
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
36
|
+
set_log_callback((level, msg) => {
|
|
37
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
38
|
+
});
|
|
39
|
+
gclass_create("C_TEST_VETO_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
40
|
+
gclass_create(
|
|
41
|
+
"C_TEST_VETO_APP",
|
|
42
|
+
[["EV_WINDOW_TO_CLOSE", 0]],
|
|
43
|
+
[["ST_IDLE", [
|
|
44
|
+
["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
|
|
45
|
+
kw.abort_close = veto;
|
|
46
|
+
return 0;
|
|
47
|
+
}, null]
|
|
48
|
+
]]],
|
|
49
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
50
|
+
);
|
|
51
|
+
register_c_yui_shell();
|
|
52
|
+
register_c_yui_window();
|
|
53
|
+
yuno = gobj_create_yuno("veto_yuno", "C_TEST_VETO_HOST", {});
|
|
54
|
+
gobj_start(yuno);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
logged.length = 0;
|
|
59
|
+
veto = true;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function errors()
|
|
63
|
+
{
|
|
64
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function press_back()
|
|
68
|
+
{
|
|
69
|
+
window.history.state = null;
|
|
70
|
+
window.dispatchEvent(new Event("popstate", {state: null}));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe("a floating window that vetoes its close", () => {
|
|
74
|
+
test("keeps a Back entry, and closes on the Back after the veto is lifted", () => {
|
|
75
|
+
const app = gobj_create("vapp", "C_TEST_VETO_APP", {}, yuno);
|
|
76
|
+
gobj_start(app);
|
|
77
|
+
const shell = gobj_create("vshell", "C_YUI_SHELL",
|
|
78
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
79
|
+
gobj_start(shell);
|
|
80
|
+
logged.length = 0; /* the shell's own start: no route table here */
|
|
81
|
+
|
|
82
|
+
const win = gobj_create_service("vwin", "C_YUI_WINDOW",
|
|
83
|
+
{subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
|
|
84
|
+
gobj_start(win);
|
|
85
|
+
const first = gobj_read_attr(win, "back_overlay");
|
|
86
|
+
expect(first).toBeTruthy();
|
|
87
|
+
|
|
88
|
+
press_back();
|
|
89
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
90
|
+
const second = gobj_read_attr(win, "back_overlay");
|
|
91
|
+
expect(second).toBeTruthy();
|
|
92
|
+
expect(second).not.toBe(first);
|
|
93
|
+
expect(shell.priv.overlay_stack).toEqual([second]);
|
|
94
|
+
|
|
95
|
+
veto = false;
|
|
96
|
+
press_back();
|
|
97
|
+
expect(gobj_is_destroying(win)).toBe(true);
|
|
98
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
99
|
+
expect(errors()).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* wizard_chrome.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_WIZARD's chrome (title, primary button) is rewritten on
|
|
5
|
+
* every step change, after the host's one-time refresh_language().
|
|
6
|
+
* It stamped a bare `i18n` attribute (which refresh_language does
|
|
7
|
+
* not read) and put the raw key in the text: the title never went
|
|
8
|
+
* through t(), and on the last step the button read `confirm`
|
|
9
|
+
* while its `data-i18n` still said `next`, so a language switch
|
|
10
|
+
* relabelled it "Next".
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2026, ArtGins.
|
|
13
|
+
* All Rights Reserved.
|
|
14
|
+
***********************************************************************/
|
|
15
|
+
import {describe, test, expect, beforeAll} from "vitest";
|
|
16
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
17
|
+
|
|
18
|
+
install_dom_double();
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
SDATA_END, gclass_create,
|
|
22
|
+
gobj_start_up, gobj_create_yuno, gobj_create,
|
|
23
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
24
|
+
} = await import("@yuneta/gobj-js");
|
|
25
|
+
const {register_c_yui_wizard} = await import("./c_yui_wizard.js");
|
|
26
|
+
|
|
27
|
+
let yuno = null;
|
|
28
|
+
let i18next = null;
|
|
29
|
+
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
i18next = (await import("i18next")).default;
|
|
32
|
+
await i18next.init({lng: "en", resources: {
|
|
33
|
+
en: {translation: {"step one": "Step one", "next": "Next", "confirm": "Confirm"}},
|
|
34
|
+
es: {translation: {"step one": "Paso uno", "next": "Siguiente", "confirm": "Confirmar"}},
|
|
35
|
+
}});
|
|
36
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
37
|
+
gclass_create("C_TEST_WIZ_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
38
|
+
gclass_create(
|
|
39
|
+
"C_TEST_WIZ_APP",
|
|
40
|
+
[["EV_STEP_SHOWN", 0], ["EV_WIZARD_DONE", 0]],
|
|
41
|
+
[["ST_IDLE", [
|
|
42
|
+
["EV_STEP_SHOWN", () => 0, null],
|
|
43
|
+
["EV_WIZARD_DONE", () => 0, null],
|
|
44
|
+
]]],
|
|
45
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
46
|
+
);
|
|
47
|
+
register_c_yui_wizard();
|
|
48
|
+
yuno = gobj_create_yuno("wizard_yuno", "C_TEST_WIZ_HOST", {});
|
|
49
|
+
gobj_start(yuno);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("C_YUI_WIZARD chrome", () => {
|
|
53
|
+
test("title and primary label are translated and keep their key", async () => {
|
|
54
|
+
const app = gobj_create("wapp", "C_TEST_WIZ_APP", {}, yuno);
|
|
55
|
+
const wiz = gobj_create("wiz", "C_YUI_WIZARD", {linear: false}, app);
|
|
56
|
+
gobj_send_event(wiz, "EV_SET_STEPS", {steps: [
|
|
57
|
+
{id: "a", title: "step one", content: ["div", {}, "A"]},
|
|
58
|
+
{id: "b", title: "step one", content: ["div", {}, "B"]},
|
|
59
|
+
]}, app);
|
|
60
|
+
|
|
61
|
+
const $c = gobj_read_attr(wiz, "$container");
|
|
62
|
+
const $title = $c.querySelector(".yui-wizard-title");
|
|
63
|
+
const $primary = $c.querySelector(".yui-wizard-primary");
|
|
64
|
+
const $plabel = $c.querySelector(".yui-wizard-primary-label");
|
|
65
|
+
|
|
66
|
+
expect($title.textContent).toBe("Step one");
|
|
67
|
+
expect($title.getAttribute("data-i18n")).toBe("step one");
|
|
68
|
+
expect($plabel.textContent).toBe("Next");
|
|
69
|
+
|
|
70
|
+
gobj_send_event(wiz, "EV_NEXT", {}, app);
|
|
71
|
+
expect($plabel.textContent).toBe("Confirm");
|
|
72
|
+
expect($plabel.getAttribute("data-i18n")).toBe("confirm");
|
|
73
|
+
expect($primary.getAttribute("aria-label")).toBe("Confirm");
|
|
74
|
+
expect($primary.getAttribute("data-i18n-aria-label")).toBe("confirm");
|
|
75
|
+
expect($primary.getAttribute("data-i18n-title")).toBe("confirm");
|
|
76
|
+
|
|
77
|
+
/* What refresh_language() reads on a language switch: the key of
|
|
78
|
+
* the CURRENT label, not the one the button was built with. */
|
|
79
|
+
await i18next.changeLanguage("es");
|
|
80
|
+
try {
|
|
81
|
+
expect(i18next.t($plabel.getAttribute("data-i18n"))).toBe("Confirmar");
|
|
82
|
+
expect(i18next.t($title.getAttribute("data-i18n"))).toBe("Paso uno");
|
|
83
|
+
} finally {
|
|
84
|
+
await i18next.changeLanguage("en");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
package/src/yui_dev.js
CHANGED
|
@@ -852,15 +852,21 @@ function full_sections(payload)
|
|
|
852
852
|
let out = {};
|
|
853
853
|
for(let k of Object.keys(payload)) {
|
|
854
854
|
if(k === "schema") {
|
|
855
|
-
if(show_schema) {
|
|
855
|
+
if(show_schema) {
|
|
856
|
+
out[k] = payload[k];
|
|
857
|
+
}
|
|
856
858
|
continue;
|
|
857
859
|
}
|
|
858
860
|
if(k === "data") {
|
|
859
|
-
if(show_data) {
|
|
861
|
+
if(show_data) {
|
|
862
|
+
out[k] = payload[k];
|
|
863
|
+
}
|
|
860
864
|
continue;
|
|
861
865
|
}
|
|
862
866
|
if(/^__.*__$/.test(k)) {
|
|
863
|
-
if(show_meta) {
|
|
867
|
+
if(show_meta) {
|
|
868
|
+
out[k] = payload[k];
|
|
869
|
+
}
|
|
864
870
|
continue;
|
|
865
871
|
}
|
|
866
872
|
out[k] = payload[k];
|
|
@@ -1665,6 +1671,7 @@ function build_control_bar()
|
|
|
1665
1671
|
let mk_dir = (dir, glyph, key, title) => ['button', {
|
|
1666
1672
|
class: 'YDEV_CHIP s-' + dir, 'data-dir': key, type: 'button',
|
|
1667
1673
|
title: t(title), 'data-i18n-title': title,
|
|
1674
|
+
'aria-label': t(title), 'data-i18n-aria-label': title,
|
|
1668
1675
|
}, glyph, {
|
|
1669
1676
|
click: (ev) => {
|
|
1670
1677
|
ev.stopPropagation();
|
package/src/yui_icons.css
CHANGED
|
@@ -459,3 +459,23 @@
|
|
|
459
459
|
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M0 80C0 53.5 21.5 32 48 32l96 0c26.5 0 48 21.5 48 48l0 16 128 0 0-16c0-26.5 21.5-48 48-48l96 0c26.5 0 48 21.5 48 48l0 96c0 26.5-21.5 48-48 48l-96 0c-26.5 0-48-21.5-48-48l0-16-128 0 0 16c0 7.3-1.7 14.3-4.6 20.5l68.6 91.5 80 0c26.5 0 48 21.5 48 48l0 96c0 26.5-21.5 48-48 48l-96 0c-26.5 0-48-21.5-48-48l0-96c0-7.3 1.7-14.3 4.6-20.5L128 224 48 224c-26.5 0-48-21.5-48-48L0 80z'/%3E%3C/svg%3E");
|
|
460
460
|
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M0 80C0 53.5 21.5 32 48 32l96 0c26.5 0 48 21.5 48 48l0 16 128 0 0-16c0-26.5 21.5-48 48-48l96 0c26.5 0 48 21.5 48 48l0 96c0 26.5-21.5 48-48 48l-96 0c-26.5 0-48-21.5-48-48l0-16-128 0 0 16c0 7.3-1.7 14.3-4.6 20.5l68.6 91.5 80 0c26.5 0 48 21.5 48 48l0 96c0 26.5-21.5 48-48 48l-96 0c-26.5 0-48-21.5-48-48l0-96c0-7.3 1.7-14.3 4.6-20.5L128 224 48 224c-26.5 0-48-21.5-48-48L0 80z'/%3E%3C/svg%3E");
|
|
461
461
|
}
|
|
462
|
+
|
|
463
|
+
/*
|
|
464
|
+
* A user icon drawn straight from its svg, before (or without) being
|
|
465
|
+
* registered as a class -- the preview of the form, the cells of
|
|
466
|
+
* __icons__ (lib_icons.js: yui_svg_icon_element). The same box as a
|
|
467
|
+
* yi- icon; the mask is set inline.
|
|
468
|
+
*/
|
|
469
|
+
.USER_ICON_PREVIEW {
|
|
470
|
+
display: inline-block;
|
|
471
|
+
width: 1em;
|
|
472
|
+
height: 1em;
|
|
473
|
+
background-color: currentColor;
|
|
474
|
+
-webkit-mask-repeat: no-repeat;
|
|
475
|
+
mask-repeat: no-repeat;
|
|
476
|
+
-webkit-mask-position: center;
|
|
477
|
+
mask-position: center;
|
|
478
|
+
-webkit-mask-size: contain;
|
|
479
|
+
mask-size: contain;
|
|
480
|
+
vertical-align: -0.125em;
|
|
481
|
+
}
|