@yuneta/gobj-ui 7.26.6 → 7.26.8
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 +74 -25
- package/dist/gobj-ui.cjs.js +967 -377
- package/dist/gobj-ui.es.js +967 -377
- package/index.js +5 -1
- package/package.json +2 -2
- package/src/c_g6_nodes_tree.js +69 -24
- package/src/c_yui_form.js +331 -140
- package/src/c_yui_gclass.js +26 -21
- package/src/c_yui_gobj_tree_js.js +16 -5
- package/src/c_yui_json.js +7 -6
- package/src/c_yui_json_graph.js +42 -14
- package/src/c_yui_json_pad.js +2 -1
- package/src/c_yui_map.js +139 -75
- package/src/c_yui_nav.js +60 -20
- package/src/c_yui_pager.js +14 -9
- package/src/c_yui_period.js +16 -6
- package/src/c_yui_schema_editor.js +3 -2
- package/src/c_yui_shell.js +96 -31
- package/src/c_yui_treedb_topic_with_form.js +50 -56
- package/src/c_yui_treedb_topics.js +8 -7
- package/src/c_yui_uplot.js +1 -1
- package/src/c_yui_window.js +123 -36
- package/src/c_yui_window_manager.js +8 -3
- package/src/c_yui_wizard.js +23 -8
- package/src/delete_impact.js +5 -3
- package/src/form_json_field.js +123 -0
- package/src/form_json_field.test.js +49 -0
- package/src/form_json_field.wiring.test.js +137 -0
- package/src/form_table_rearm.wiring.test.js +158 -0
- package/src/g6_event_kw.js +36 -0
- package/src/nav_cards_helpers.js +2 -1
- package/src/nav_cards_helpers.test.js +7 -3
- package/src/schema_to_c.js +27 -1
- package/src/schema_to_c.test.js +15 -1
- package/src/shell_modals.js +5 -3
- package/src/shell_route_map.js +18 -13
- package/src/treedb_topics_transport.wiring.test.js +35 -1
- package/src/vite_plugin_yuneta_html.test.js +79 -0
- package/src/window_show.wiring.test.js +83 -0
- package/src/window_veto_back.wiring.test.js +136 -0
- package/src/wizard_chrome.wiring.test.js +87 -0
- package/src/yui_dev.js +23 -14
- package/src/yui_frontend_view.js +4 -4
- package/src/yui_gclass_view.js +3 -3
- package/src/yui_table_filter_clear.js +44 -44
- package/src/yui_text.js +31 -0
- package/src/yui_text.test.js +39 -0
- package/vite-plugin-yuneta-html.js +36 -9
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
/***********************************************************************
|
|
2
2
|
* yui_table_filter_clear.js
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* THE ✕ OF A TABULATOR'S HEADER FILTERS.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* A column filter is set by typing and removed by DELETING what
|
|
7
|
+
* was typed, letter by letter, and nothing in the header says it
|
|
8
|
+
* can be removed. With several columns filtered, getting the
|
|
9
|
+
* whole table back is an exercise of memory: which ones did I
|
|
10
|
+
* touch. The ✕ says it and does it.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* THREE DECISIONS THAT ARE NOT OBVIOUS:
|
|
13
13
|
*
|
|
14
|
-
* - **
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
14
|
+
* - **It shows while the filter has content, focused or not.**
|
|
15
|
+
* The opposite of a form's ✕ (`yui_inputs.js`), which appears
|
|
16
|
+
* only on the field being edited so as not to light a cross on
|
|
17
|
+
* every filled field. Here the use case is the reverse: the
|
|
18
|
+
* filter is already set, the focus is elsewhere, and what is
|
|
19
|
+
* wanted is to see it and remove it. Hidden behind the focus it
|
|
20
|
+
* would take two clicks.
|
|
21
21
|
*
|
|
22
|
-
* - **
|
|
23
|
-
* `setHeaderFilterValue(field, "")`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* - **It clears through the API, not by faking keys.**
|
|
23
|
+
* `setHeaderFilterValue(field, "")` is what Tabulator offers,
|
|
24
|
+
* and it keeps the value and the filter consistent. Synthesising
|
|
25
|
+
* an `input` on the `<input>` depends on what that filter's
|
|
26
|
+
* editor listens to, which changes with the column type.
|
|
27
27
|
*
|
|
28
|
-
* - **
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* `querySelector
|
|
34
|
-
*
|
|
28
|
+
* - **The header is walked, the editor is not wrapped.** The
|
|
29
|
+
* columns are built from the topic's schema, so there is no
|
|
30
|
+
* single place to wrap the editor; and the header rebuilds
|
|
31
|
+
* itself when the columns change. The walk is idempotent -- it
|
|
32
|
+
* marks what already has its cross -- and is triggered by a
|
|
33
|
+
* one-pass `querySelector`, so repeating it on every render
|
|
34
|
+
* costs nothing.
|
|
35
35
|
*
|
|
36
36
|
* Copyright (c) 2026, ArtGins.
|
|
37
37
|
* All Rights Reserved.
|
|
@@ -47,9 +47,9 @@ const MARK = "data-yui-filter-clear";
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
/***************************************************************
|
|
50
|
-
*
|
|
50
|
+
* Put (or put back) the ✕ of every header filter of `table`.
|
|
51
51
|
*
|
|
52
|
-
*
|
|
52
|
+
* Idempotent: the ones that already have it are skipped.
|
|
53
53
|
***************************************************************/
|
|
54
54
|
function decorate(table)
|
|
55
55
|
{
|
|
@@ -58,7 +58,7 @@ function decorate(table)
|
|
|
58
58
|
}
|
|
59
59
|
let $pending = table.element.querySelector(`.tabulator-header-filter:not([${MARK}])`);
|
|
60
60
|
if(!$pending) {
|
|
61
|
-
return; /*
|
|
61
|
+
return; /* nothing new in the header */
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
let list = table.element.querySelectorAll(`.tabulator-header-filter:not([${MARK}])`);
|
|
@@ -67,22 +67,22 @@ function decorate(table)
|
|
|
67
67
|
|
|
68
68
|
let $input = $filter.querySelector("input");
|
|
69
69
|
if(!$input) {
|
|
70
|
-
continue; /*
|
|
70
|
+
continue; /* a filter that is not typed: a select, a range */
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/*
|
|
74
|
-
*
|
|
73
|
+
/* The field is read from the `.tabulator-col` holding it, which
|
|
74
|
+
* is what carries it; the `<input>` does not know its column. */
|
|
75
75
|
let $col = $filter.closest(".tabulator-col");
|
|
76
76
|
let field = $col? $col.getAttribute("tabulator-field"): "";
|
|
77
77
|
if(!field) {
|
|
78
|
-
continue; /*
|
|
78
|
+
continue; /* without a field there is nobody to tell to clear */
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
$filter.classList.add("yui-filter-has-clear");
|
|
82
82
|
|
|
83
|
-
/*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
83
|
+
/* The key travels with the button: a `title` set with t() at
|
|
84
|
+
* build time is invisible to refresh_language(), and stays in
|
|
85
|
+
* the language of that moment for ever. */
|
|
86
86
|
let $btn = createElement2(["button", {
|
|
87
87
|
type: "button",
|
|
88
88
|
class: "delete is-small yui-filter-clear",
|
|
@@ -100,7 +100,7 @@ function decorate(table)
|
|
|
100
100
|
$input.addEventListener("input", sync);
|
|
101
101
|
$input.addEventListener("change", sync);
|
|
102
102
|
$btn.addEventListener("click", (event) => {
|
|
103
|
-
event.stopPropagation(); /*
|
|
103
|
+
event.stopPropagation(); /* a press must not sort the column */
|
|
104
104
|
table.setHeaderFilterValue(field, "");
|
|
105
105
|
sync();
|
|
106
106
|
});
|
|
@@ -111,11 +111,11 @@ function decorate(table)
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/***************************************************************
|
|
114
|
-
*
|
|
114
|
+
* Hook the ✕ onto a table already created.
|
|
115
115
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* Called once, with the table built. The hooks cover the two
|
|
117
|
+
* moments the header appears or is rebuilt: when it is built
|
|
118
|
+
* and when the columns change.
|
|
119
119
|
***************************************************************/
|
|
120
120
|
export function yui_table_filter_clear(table)
|
|
121
121
|
{
|
|
@@ -132,9 +132,9 @@ export function yui_table_filter_clear(table)
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/***************************************************************
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
135
|
+
* Go over the state of the ✕s after a change that did not come
|
|
136
|
+
* from the keyboard -- clearing every filter, loading a saved
|
|
137
|
+
* view -- because that fires no `input`.
|
|
138
138
|
***************************************************************/
|
|
139
139
|
export function yui_table_filter_clear_refresh(table)
|
|
140
140
|
{
|
package/src/yui_text.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_text.js
|
|
3
|
+
*
|
|
4
|
+
* DATA as text for createElement2().
|
|
5
|
+
*
|
|
6
|
+
* createElement2() takes a string content that starts with '<' for
|
|
7
|
+
* MARKUP and parses it (that is how a component passes an inline
|
|
8
|
+
* icon). So a value that came from outside -- a backend answer, a
|
|
9
|
+
* treedb node, a name somebody typed, a frame of the traffic -- must
|
|
10
|
+
* never go in as a bare string: "<img src=x onerror=...>" would run.
|
|
11
|
+
* It goes in as a Text node, which is always text.
|
|
12
|
+
*
|
|
13
|
+
* Trimmed like createElement2() trims a string, so the change of
|
|
14
|
+
* form does not change what is shown. A Text node under an
|
|
15
|
+
* `i18n`/`data-i18n` element is still re-translated by
|
|
16
|
+
* refresh_language(), which sets textContent.
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2026, ArtGins.
|
|
19
|
+
* All Rights Reserved.
|
|
20
|
+
***********************************************************************/
|
|
21
|
+
|
|
22
|
+
/************************************************************
|
|
23
|
+
* A Text node with `value` as its text ("" for null/undefined).
|
|
24
|
+
************************************************************/
|
|
25
|
+
export function text_node(value)
|
|
26
|
+
{
|
|
27
|
+
if(value === null || value === undefined) {
|
|
28
|
+
return document.createTextNode("");
|
|
29
|
+
}
|
|
30
|
+
return document.createTextNode(String(value).trim());
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_text.test.js
|
|
3
|
+
*
|
|
4
|
+
* Data goes into createElement2() as a Text node: a string that
|
|
5
|
+
* starts with '<' is parsed as markup there.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2026, ArtGins.
|
|
8
|
+
* All Rights Reserved.
|
|
9
|
+
***********************************************************************/
|
|
10
|
+
import {describe, test, expect} from "vitest";
|
|
11
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
12
|
+
|
|
13
|
+
install_dom_double();
|
|
14
|
+
|
|
15
|
+
const {createElement2} = await import("@yuneta/gobj-js");
|
|
16
|
+
const {text_node} = await import("./yui_text.js");
|
|
17
|
+
const {card_descriptor} = await import("./nav_cards_helpers.js");
|
|
18
|
+
|
|
19
|
+
const EVIL = "<img src=x onerror=alert(1)>";
|
|
20
|
+
|
|
21
|
+
describe("text_node()", () => {
|
|
22
|
+
test("a value that looks like markup stays text", () => {
|
|
23
|
+
const $el = createElement2(["span", {}, text_node(EVIL)]);
|
|
24
|
+
expect($el.querySelector("img")).toBe(null);
|
|
25
|
+
expect($el.textContent).toBe(EVIL);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("trimmed like a string content, and null is empty", () => {
|
|
29
|
+
expect(text_node(" a ").textContent).toBe("a");
|
|
30
|
+
expect(text_node(null).textContent).toBe("");
|
|
31
|
+
expect(text_node(0).textContent).toBe("0");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("a nav card named by a backend (set_submenu) shows its name as text", () => {
|
|
35
|
+
const $card = createElement2(card_descriptor({id: "x", name: EVIL, route: "/x"}, true));
|
|
36
|
+
expect($card.querySelector("img")).toBe(null);
|
|
37
|
+
expect($card.textContent).toContain(EVIL);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -6,17 +6,28 @@
|
|
|
6
6
|
* - <title> from config.title
|
|
7
7
|
* - <meta> tags from config.metadata
|
|
8
8
|
* - Content-Security-Policy from config.csp_connect_src
|
|
9
|
+
* (always emitted: connect-src 'self' alone when the
|
|
10
|
+
* list is missing, with a warning)
|
|
9
11
|
*
|
|
10
12
|
* Usage in vite.config.js (vendored copy):
|
|
11
13
|
* import { yunetaHtmlPlugin } from "./src/gobj-ui/vite-plugin-yuneta-html.js";
|
|
12
14
|
* plugins: [ yunetaHtmlPlugin({ defaultTitle: "My App" }) ]
|
|
13
15
|
*
|
|
14
|
-
* Copyright (c) 2025, ArtGins.
|
|
16
|
+
* Copyright (c) 2025-2026, ArtGins.
|
|
15
17
|
* All Rights Reserved.
|
|
16
18
|
***********************************************************************/
|
|
17
19
|
import fs from "fs";
|
|
18
20
|
import path from "path";
|
|
19
21
|
|
|
22
|
+
/* config.json is build input, but its text lands inside markup. */
|
|
23
|
+
function escape_html(value) {
|
|
24
|
+
return String(value)
|
|
25
|
+
.replace(/&/g, "&")
|
|
26
|
+
.replace(/</g, "<")
|
|
27
|
+
.replace(/>/g, ">")
|
|
28
|
+
.replace(/"/g, """);
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
/**
|
|
21
32
|
* @param {object} [options]
|
|
22
33
|
* @param {string} [options.defaultTitle] - Fallback title if config.json is missing
|
|
@@ -33,13 +44,15 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
33
44
|
const configPath = options.configPath ||
|
|
34
45
|
path.resolve(process.cwd(), "config.json");
|
|
35
46
|
|
|
47
|
+
/* Without a config.json the page still gets its policy
|
|
48
|
+
* (connect-src 'self' only): it used to get none at all. */
|
|
49
|
+
let config = {};
|
|
36
50
|
if (!fs.existsSync(configPath)) {
|
|
37
51
|
console.error("⚠️ config.json not found at", configPath);
|
|
38
|
-
|
|
52
|
+
} else {
|
|
53
|
+
config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
42
|
-
|
|
43
56
|
/*------------------------------------------*
|
|
44
57
|
* Title
|
|
45
58
|
*------------------------------------------*/
|
|
@@ -52,7 +65,7 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
52
65
|
if (config.metadata) {
|
|
53
66
|
for (const [key, value] of Object.entries(config.metadata)) {
|
|
54
67
|
if (value) {
|
|
55
|
-
metadataHtml += ` <meta name="${key}" content="${value}">\n`;
|
|
68
|
+
metadataHtml += ` <meta name="${escape_html(key)}" content="${escape_html(value)}">\n`;
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
}
|
|
@@ -83,10 +96,24 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
83
96
|
* injected style blocks. Don't loosen the script
|
|
84
97
|
* side without a strong reason.
|
|
85
98
|
*------------------------------------------*/
|
|
99
|
+
/* A config with no csp_connect_src used to get NO policy
|
|
100
|
+
* at all, silently. It gets the same policy with
|
|
101
|
+
* connect-src 'self' only, and a warning. */
|
|
86
102
|
let cspHtml = "";
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
103
|
+
{
|
|
104
|
+
let origins = [];
|
|
105
|
+
if (Array.isArray(config.csp_connect_src)) {
|
|
106
|
+
/* Escaped: an origin lands inside the content="..."
|
|
107
|
+
* attribute, where a quote would end it. */
|
|
108
|
+
origins = config.csp_connect_src
|
|
109
|
+
.filter(s => typeof s === "string" && !s.startsWith("_comment"))
|
|
110
|
+
.map(escape_html);
|
|
111
|
+
} else {
|
|
112
|
+
console.warn(
|
|
113
|
+
"⚠️ config.json has no csp_connect_src array: " +
|
|
114
|
+
"the Content-Security-Policy allows connect-src 'self' only"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
90
117
|
|
|
91
118
|
const connectSrc = ["'self'", ...origins].join("\n ");
|
|
92
119
|
|
|
@@ -112,7 +139,7 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
112
139
|
* Apply replacements
|
|
113
140
|
*------------------------------------------*/
|
|
114
141
|
return html
|
|
115
|
-
.replace("<title></title>", `<title>${title}</title>`)
|
|
142
|
+
.replace("<title></title>", `<title>${escape_html(title)}</title>`)
|
|
116
143
|
.replace("<!-- METADATA_PLACEHOLDER -->", metadataHtml)
|
|
117
144
|
.replace("<!-- CSP_PLACEHOLDER -->", cspHtml);
|
|
118
145
|
}
|