@yuneta/gobj-ui 7.26.42 → 7.26.43
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 +227 -36
- package/dist/gobj-ui.cjs.js +768 -191
- package/dist/gobj-ui.es.js +768 -191
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +355 -63
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.js +49 -3
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +28 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +74 -2
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +63 -25
- package/src/i18n_key_functions.test.js +230 -8
- package/src/modal_guard_back.wiring.test.js +53 -0
- package/src/named_controls.wiring.test.js +53 -13
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +90 -19
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_tabulator_i18n.js +31 -1
- package/src/yui_tabulator_i18n.test.js +46 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* window_rect_rounding.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A C_YUI_WINDOW with auto_save_size_and_position keeps its x, y,
|
|
5
|
+
* width and height (DTP_INTEGER) in localStorage. They came from
|
|
6
|
+
* getBoundingClientRect(), which answers fractions of a pixel under
|
|
7
|
+
* a zoom or a device pixel ratio: a fraction was saved, and written
|
|
8
|
+
* back into the integer attrs. They are whole pixels now, when they
|
|
9
|
+
* are saved (a move, a resize) and when they are restored -- an
|
|
10
|
+
* entry saved before with fractions still restores, rounded. (A
|
|
11
|
+
* value is read as its attribute's type, as the C kernel reads it:
|
|
12
|
+
* 2.5 to an integer is refused.)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {describe, test, expect, beforeAll} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double();
|
|
21
|
+
|
|
22
|
+
if(typeof globalThis.matchMedia === "undefined") {
|
|
23
|
+
globalThis.matchMedia = () => ({matches: false, addEventListener() {}, removeEventListener() {}});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
SDATA_END, gclass_create,
|
|
28
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service,
|
|
29
|
+
gobj_start, gobj_read_attr,
|
|
30
|
+
set_log_callback,
|
|
31
|
+
} = await import("@yuneta/gobj-js");
|
|
32
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
33
|
+
|
|
34
|
+
const logged = [];
|
|
35
|
+
let yuno = null;
|
|
36
|
+
|
|
37
|
+
const FRACTIONS = {x: 10.3, y: 20.7, width: 400.5, height: 300.2};
|
|
38
|
+
const ROUNDED = {x: 10, y: 21, width: 401, height: 300};
|
|
39
|
+
|
|
40
|
+
beforeAll(async () => {
|
|
41
|
+
const i18next = (await import("i18next")).default;
|
|
42
|
+
await i18next.init({lng: "en", resources: {}});
|
|
43
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
44
|
+
set_log_callback((level, msg) => {
|
|
45
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
46
|
+
});
|
|
47
|
+
gclass_create("C_TEST_RECT_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
48
|
+
register_c_yui_window();
|
|
49
|
+
yuno = gobj_create_yuno("rect_yuno", "C_TEST_RECT_HOST", {});
|
|
50
|
+
gobj_start(yuno);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function errors()
|
|
54
|
+
{
|
|
55
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function saved(name)
|
|
59
|
+
{
|
|
60
|
+
return JSON.parse(window.localStorage.getItem(`${name}-rect`));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function attrs_rect(win)
|
|
64
|
+
{
|
|
65
|
+
return {
|
|
66
|
+
x: gobj_read_attr(win, "x"),
|
|
67
|
+
y: gobj_read_attr(win, "y"),
|
|
68
|
+
width: gobj_read_attr(win, "width"),
|
|
69
|
+
height: gobj_read_attr(win, "height"),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function press(win, selector, at, end)
|
|
74
|
+
{
|
|
75
|
+
const $container = gobj_read_attr(win, "$container");
|
|
76
|
+
$container.getBoundingClientRect = () => ({...FRACTIONS});
|
|
77
|
+
const $el = $container.querySelector(selector);
|
|
78
|
+
$el.dispatchEvent({
|
|
79
|
+
type: "pointerdown", target: $el, offsetX: 0, offsetY: 0, ...at,
|
|
80
|
+
stopPropagation() {}, preventDefault() {},
|
|
81
|
+
});
|
|
82
|
+
document.dispatchEvent({type: "pointerup", ...end, stopPropagation() {}, preventDefault() {}});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("the saved rect of a window is whole pixels", () => {
|
|
86
|
+
test("an entry saved with fractions restores rounded", () => {
|
|
87
|
+
window.localStorage.setItem("rect_old-rect", JSON.stringify({...FRACTIONS}));
|
|
88
|
+
logged.length = 0;
|
|
89
|
+
const win = gobj_create_service("rect_old", "C_YUI_WINDOW", {
|
|
90
|
+
header: "old", body: ["div", {}, "old"], auto_save_size_and_position: true,
|
|
91
|
+
}, yuno);
|
|
92
|
+
gobj_start(win);
|
|
93
|
+
expect(attrs_rect(win)).toEqual(ROUNDED);
|
|
94
|
+
expect(errors()).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a move saves whole pixels, and writes them into the attrs", () => {
|
|
98
|
+
const win = gobj_create_service("rect_move", "C_YUI_WINDOW", {
|
|
99
|
+
header: "move", body: ["div", {}, "move"], auto_save_size_and_position: true,
|
|
100
|
+
}, yuno);
|
|
101
|
+
gobj_start(win);
|
|
102
|
+
logged.length = 0;
|
|
103
|
+
press(win, ".WINDOW_HEADER", {screenX: 0, screenY: 0}, {screenX: 5, screenY: 5});
|
|
104
|
+
expect(saved("rect_move")).toEqual(ROUNDED);
|
|
105
|
+
expect(attrs_rect(win)).toEqual(ROUNDED);
|
|
106
|
+
expect(errors()).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("a resize saves whole pixels, and writes them into the attrs", () => {
|
|
110
|
+
const win = gobj_create_service("rect_resize", "C_YUI_WINDOW", {
|
|
111
|
+
header: "resize", body: ["div", {}, "resize"], auto_save_size_and_position: true,
|
|
112
|
+
showFooter: false, // the resize handle in the body: WINDOW_RESIZE
|
|
113
|
+
}, yuno);
|
|
114
|
+
gobj_start(win);
|
|
115
|
+
logged.length = 0;
|
|
116
|
+
press(win, ".WINDOW_RESIZE", {pageX: 0, pageY: 0}, {pageX: 5, pageY: 5});
|
|
117
|
+
expect(saved("rect_resize")).toEqual(ROUNDED);
|
|
118
|
+
expect(attrs_rect(win)).toEqual(ROUNDED);
|
|
119
|
+
expect(errors()).toEqual([]);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
*
|
|
21
21
|
* yui_tabulator_relocalize(table, t, {device_id: t("device id")});
|
|
22
22
|
*
|
|
23
|
+
* A column GROUP is bound by field too, and Tabulator gives it none:
|
|
24
|
+
* give it one (`{title, field: "sizes", columns: [...]}`, no row reads
|
|
25
|
+
* it) and its title goes in the same object. One without is said.
|
|
26
|
+
*
|
|
23
27
|
* Every key carries an English `defaultValue`, so an app that does not
|
|
24
28
|
* define it renders exactly what Tabulator rendered before — the
|
|
25
29
|
* keys are an OPPORTUNITY to translate, never a requirement.
|
|
@@ -242,6 +246,29 @@ function yui_tabulator_name_editor(column_def, name_of)
|
|
|
242
246
|
};
|
|
243
247
|
}
|
|
244
248
|
|
|
249
|
+
/***************************************************************
|
|
250
|
+
* A column GROUP whose title cannot change language, said.
|
|
251
|
+
*
|
|
252
|
+
* Tabulator binds a column's title to the locale by its `field`, and
|
|
253
|
+
* a group has none: its title stays in the language the table was
|
|
254
|
+
* built in. Given a `field` (no row reads a group's), a group is
|
|
255
|
+
* bound like any other column, and its title goes in `titles`.
|
|
256
|
+
***************************************************************/
|
|
257
|
+
function say_groups_without_field(columns)
|
|
258
|
+
{
|
|
259
|
+
for(let column of columns || []) {
|
|
260
|
+
let def = column.getDefinition() || {};
|
|
261
|
+
if(!Array.isArray(def.columns)) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if(!def.field) {
|
|
265
|
+
log_warning(`yui_tabulator_relocalize: column group '${def.title}' has no field: ` +
|
|
266
|
+
`its title stays in the language it was built in`);
|
|
267
|
+
}
|
|
268
|
+
say_groups_without_field(column.getSubColumns());
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
245
272
|
/***************************************************************
|
|
246
273
|
* yui_tabulator_relocalize() -- see "Put an EXISTING table in the
|
|
247
274
|
* current language" above.
|
|
@@ -251,7 +278,9 @@ function yui_tabulator_name_editor(column_def, name_of)
|
|
|
251
278
|
* (`columns`), where Tabulator binds each column's title: setLocale()
|
|
252
279
|
* draws them again without rebuilding a column -- updateDefinition()
|
|
253
280
|
* re-renders every row, and a row whose formatter builds something (a
|
|
254
|
-
* nested table) builds it anew. A field left out keeps its title.
|
|
281
|
+
* nested table) builds it anew. A field left out keeps its title. A
|
|
282
|
+
* column GROUP is bound only if it has a `field` of its own: one
|
|
283
|
+
* without is said (say_groups_without_field).
|
|
255
284
|
***************************************************************/
|
|
256
285
|
function yui_tabulator_relocalize(table, t, titles)
|
|
257
286
|
{
|
|
@@ -263,6 +292,7 @@ function yui_tabulator_relocalize(table, t, titles)
|
|
|
263
292
|
let strings = tabulator_strings(t);
|
|
264
293
|
if(titles && typeof titles === "object") {
|
|
265
294
|
strings.columns = Object.assign({}, titles);
|
|
295
|
+
say_groups_without_field(table.getColumns(true));
|
|
266
296
|
}
|
|
267
297
|
|
|
268
298
|
/* Tabulator DEEP-CLONES options.langs into its localize module when
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* All Rights Reserved.
|
|
11
11
|
***********************************************************************/
|
|
12
12
|
import {describe, it, expect} from "vitest";
|
|
13
|
+
import {set_log_callback} from "@yuneta/gobj-js";
|
|
13
14
|
|
|
14
15
|
import {
|
|
15
16
|
yui_tabulator_name_filters,
|
|
@@ -163,4 +164,49 @@ describe("yui_tabulator_relocalize", () => {
|
|
|
163
164
|
yui_tabulator_relocalize(tb, t);
|
|
164
165
|
expect(tb.installed[tb.locale].columns).toBe(undefined);
|
|
165
166
|
});
|
|
167
|
+
|
|
168
|
+
/* A column double, a group when it has `columns`. */
|
|
169
|
+
function col(def, subs)
|
|
170
|
+
{
|
|
171
|
+
return {
|
|
172
|
+
getDefinition: () => def,
|
|
173
|
+
getSubColumns: () => subs || [],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Tabulator binds a title to the locale by `field`, and a GROUP has
|
|
178
|
+
* none: its title stayed in the language the table was built in,
|
|
179
|
+
* and nothing said so. A group given a `field` is bound like any
|
|
180
|
+
* other column (checked on Tabulator 6.6 in a browser). */
|
|
181
|
+
it("a column group with no field is said; one with a field is a title like any other", () => {
|
|
182
|
+
const warned = [];
|
|
183
|
+
set_log_callback((level, msg) => {
|
|
184
|
+
if(String(level) === "warning") {
|
|
185
|
+
warned.push(String(msg));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
try {
|
|
189
|
+
const a = col({field: "a", title: "A"});
|
|
190
|
+
const b = col({field: "b", title: "B"});
|
|
191
|
+
const tb = table();
|
|
192
|
+
tb.getColumns = (structured) => structured ?
|
|
193
|
+
[col({field: "x", title: "X"}), col({title: "Sizes", columns: [{}, {}]}, [a, b])] : [];
|
|
194
|
+
yui_tabulator_relocalize(tb, t, {x: "Equis", a: "A es", b: "B es"});
|
|
195
|
+
expect(warned.filter((m) => m.includes("'Sizes'") && m.includes("no field")).length).toBe(1);
|
|
196
|
+
|
|
197
|
+
warned.length = 0;
|
|
198
|
+
const named = table();
|
|
199
|
+
named.getColumns = (structured) => structured ?
|
|
200
|
+
[col({title: "Sizes", field: "sizes", columns: [{}, {}]}, [a, b])] : [];
|
|
201
|
+
yui_tabulator_relocalize(named, t, {sizes: "Tallas", a: "A es", b: "B es"});
|
|
202
|
+
expect(warned).toEqual([]);
|
|
203
|
+
expect(named.installed[named.locale].columns.sizes).toBe("Tallas");
|
|
204
|
+
|
|
205
|
+
/* Without titles nothing is asked of the columns. */
|
|
206
|
+
yui_tabulator_relocalize(tb, t);
|
|
207
|
+
expect(warned).toEqual([]);
|
|
208
|
+
} finally {
|
|
209
|
+
set_log_callback(null);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
166
212
|
});
|