@yuneta/gobj-ui 7.26.39 → 7.26.41
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 +37 -2
- package/dist/gobj-ui.cjs.js +135 -75
- package/dist/gobj-ui.es.js +135 -75
- package/package.json +1 -1
- package/src/c_yui_form.js +80 -68
- package/src/c_yui_uplot.js +8 -58
- package/src/form_table_edits_ask.wiring.test.js +398 -0
- package/src/form_table_rearm.wiring.test.js +9 -7
- package/src/uplot_ink.test.js +105 -0
- package/src/yui_tabulator_i18n.js +21 -1
- package/src/yui_tabulator_i18n.test.js +39 -0
- package/src/yui_text.js +10 -0
- package/src/yui_text.test.js +13 -0
- package/src/yui_uplot_ink.js +94 -0
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
yui_tabulator_name_filters,
|
|
16
16
|
yui_tabulator_name_row_selects,
|
|
17
17
|
yui_tabulator_name_editor,
|
|
18
|
+
yui_tabulator_relocalize,
|
|
18
19
|
} from "./yui_tabulator_i18n.js";
|
|
19
20
|
|
|
20
21
|
/* An element double: attributes, and the one child a selector finds. */
|
|
@@ -125,3 +126,41 @@ describe("yui_tabulator_name_editor", () => {
|
|
|
125
126
|
expect(def.editorParams({})).toEqual({a: 1});
|
|
126
127
|
});
|
|
127
128
|
});
|
|
129
|
+
|
|
130
|
+
describe("yui_tabulator_relocalize", () => {
|
|
131
|
+
/* A table double: what the localize module is given, and the
|
|
132
|
+
* locale it is set to. */
|
|
133
|
+
function table()
|
|
134
|
+
{
|
|
135
|
+
const installed = {};
|
|
136
|
+
const tb = {
|
|
137
|
+
options: {},
|
|
138
|
+
installed,
|
|
139
|
+
locale: null,
|
|
140
|
+
modules: {localize: {installLang: (name, strings) => {
|
|
141
|
+
installed[name] = strings;
|
|
142
|
+
}}},
|
|
143
|
+
setLocale: (name) => {
|
|
144
|
+
tb.locale = name;
|
|
145
|
+
},
|
|
146
|
+
getColumns: () => [],
|
|
147
|
+
element: element(null),
|
|
148
|
+
};
|
|
149
|
+
return tb;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
it("hands the column titles to the locale, where Tabulator binds them", () => {
|
|
153
|
+
const tb = table();
|
|
154
|
+
yui_tabulator_relocalize(tb, t, {device_id: "Id dispositivo", value: "Valor"});
|
|
155
|
+
expect(tb.locale).toBeTruthy();
|
|
156
|
+
expect(tb.installed[tb.locale].columns).toEqual(
|
|
157
|
+
{device_id: "Id dispositivo", value: "Valor"});
|
|
158
|
+
expect(tb.installed[tb.locale].pagination).toBeTruthy();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("without titles, the locale carries none, as before", () => {
|
|
162
|
+
const tb = table();
|
|
163
|
+
yui_tabulator_relocalize(tb, t);
|
|
164
|
+
expect(tb.installed[tb.locale].columns).toBe(undefined);
|
|
165
|
+
});
|
|
166
|
+
});
|
package/src/yui_text.js
CHANGED
|
@@ -36,9 +36,19 @@ export function text_node(value)
|
|
|
36
36
|
* Tabulator puts a STRING title in with innerHTML, so a title taken
|
|
37
37
|
* from a schema (`header`, which the schema editor writes) is markup
|
|
38
38
|
* unless the column carries a formatter that returns a Node.
|
|
39
|
+
*
|
|
40
|
+
* And it APPENDS that Node to the title's holder, which it never
|
|
41
|
+
* empties -- while it runs the formatter again on every setLocale()
|
|
42
|
+
* (yui_tabulator_relocalize()). Until 7.26.40 each change of language
|
|
43
|
+
* added one more copy of every title ("Id dispositivoId dispositivo").
|
|
44
|
+
* The holder (the mock cell's element) is emptied first.
|
|
39
45
|
************************************************************/
|
|
40
46
|
export function text_title_formatter(cell)
|
|
41
47
|
{
|
|
48
|
+
const $holder = (typeof cell.getElement === "function")? cell.getElement() : null;
|
|
49
|
+
if($holder) {
|
|
50
|
+
$holder.textContent = "";
|
|
51
|
+
}
|
|
42
52
|
return text_node(cell.getValue());
|
|
43
53
|
}
|
|
44
54
|
|
package/src/yui_text.test.js
CHANGED
|
@@ -48,6 +48,19 @@ describe("text_node()", () => {
|
|
|
48
48
|
expect($title.textContent).toBe(EVIL);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
test("a title formatted again (every setLocale) is not appended to the old one", () => {
|
|
52
|
+
/* What Tabulator does: it appends the Node into the title's
|
|
53
|
+
* holder, and on a change of locale runs the formatter again
|
|
54
|
+
* on the same holder. */
|
|
55
|
+
const $holder = document.createElement("div");
|
|
56
|
+
const cell = (title) => ({getValue: () => title, getElement: () => $holder});
|
|
57
|
+
$holder.appendChild(text_title_formatter(cell("Id dispositivo")));
|
|
58
|
+
$holder.appendChild(text_title_formatter(cell("Device id")));
|
|
59
|
+
$holder.appendChild(text_title_formatter(cell("Id dispositivo")));
|
|
60
|
+
expect($holder.textContent).toBe("Id dispositivo");
|
|
61
|
+
expect($holder.childNodes.length).toBe(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
51
64
|
test("the accordion nav shows a section named by a backend as text", async () => {
|
|
52
65
|
const i18next = (await import("i18next")).default;
|
|
53
66
|
await i18next.init({lng: "en", resources: {}});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_uplot_ink.js
|
|
3
|
+
*
|
|
4
|
+
* The ink of a uPlot chart, on both schemes, and its palette.
|
|
5
|
+
*
|
|
6
|
+
* uPlot is built for a white page: its axis labels are `#000`
|
|
7
|
+
* and its grid `rgba(0,0,0,0.07)`, which on the dark scheme are
|
|
8
|
+
* 1.16:1 and 1.04 -- an axis nobody can read and a grid that is
|
|
9
|
+
* not there. The inks here are handed to uPlot as FUNCTIONS: it
|
|
10
|
+
* calls them when it draws, so the value can never be stale --
|
|
11
|
+
* what goes stale is the canvas, and a change of the theme has to
|
|
12
|
+
* ask for a redraw (yui_watch_theme() turns it into an event).
|
|
13
|
+
*
|
|
14
|
+
* uPlot ALWAYS draws a Y axis: its setDefaults() makes axes[1]
|
|
15
|
+
* whether it was given or not, with its own black. So the axes are
|
|
16
|
+
* padded to two before they are inked. C_YUI_UPLOT's default is
|
|
17
|
+
* `[{}]`, the X axis alone, and until 7.26.40 every chart of the
|
|
18
|
+
* library had a Y axis whose values could not be read in the dark.
|
|
19
|
+
*
|
|
20
|
+
* C_YUI_UPLOT uses it, and so can an app that builds a uPlot of its
|
|
21
|
+
* own:
|
|
22
|
+
*
|
|
23
|
+
* import {yui_uplot_axes} from "@yuneta/gobj-ui/src/yui_uplot_ink.js";
|
|
24
|
+
*
|
|
25
|
+
* const chart = new uPlot({
|
|
26
|
+
* width: 600, height: 300,
|
|
27
|
+
* series: [{}, {label: "temperature"}],
|
|
28
|
+
* axes: yui_uplot_axes([{}]), // X and Y, with the ink of the theme
|
|
29
|
+
* }, data, $el);
|
|
30
|
+
*
|
|
31
|
+
* The palette is six colours that clear 3:1 on BOTH grounds
|
|
32
|
+
* (worst 3.39 on white, 3.71 on near-black), ordered so the first
|
|
33
|
+
* two are the pair that survives colour blindness -- blue and
|
|
34
|
+
* orange, never red and green as the opening pair.
|
|
35
|
+
*
|
|
36
|
+
* Copyright (c) 2026, ArtGins.
|
|
37
|
+
* All Rights Reserved.
|
|
38
|
+
***********************************************************************/
|
|
39
|
+
import {yui_is_dark} from "./yui_theme.js";
|
|
40
|
+
|
|
41
|
+
/************************************************************
|
|
42
|
+
* The ink of the labels of an axis.
|
|
43
|
+
************************************************************/
|
|
44
|
+
function yui_uplot_axis_ink()
|
|
45
|
+
{
|
|
46
|
+
return yui_is_dark()? "#c7cdd8" : "#2e333d";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/************************************************************
|
|
50
|
+
* The ink of the grid and of the ticks.
|
|
51
|
+
************************************************************/
|
|
52
|
+
function yui_uplot_grid_ink()
|
|
53
|
+
{
|
|
54
|
+
return yui_is_dark()? "rgba(199,205,216,0.16)" : "rgba(46,51,61,0.12)";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const YUI_UPLOT_PALETTE = [
|
|
58
|
+
{stroke: "#2f6fd0", fill: "rgba(47,111,208,0.10)"}, /* 4.88 / 3.71 */
|
|
59
|
+
{stroke: "#b8620a", fill: "rgba(184,98,10,0.10)"}, /* 4.38 / 4.13 */
|
|
60
|
+
{stroke: "#2f8f4e", fill: "rgba(47,143,78,0.10)"}, /* 4.07 / 4.45 */
|
|
61
|
+
{stroke: "#8b5cf6", fill: "rgba(139,92,246,0.10)"}, /* 4.23 / 4.28 */
|
|
62
|
+
{stroke: "#0e9aa7", fill: "rgba(14,154,167,0.10)"}, /* 3.39 / 5.35 */
|
|
63
|
+
{stroke: "#d1344b", fill: "rgba(209,52,75,0.10)"}, /* 4.88 / 3.71 */
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/************************************************************
|
|
67
|
+
* The axes the host asked for -- at least the X and the Y,
|
|
68
|
+
* the two uPlot always draws -- with the ink it did not ask
|
|
69
|
+
* about. A stroke, a grid or a ticks the host gave is kept.
|
|
70
|
+
* Answers new objects: the host's are not touched.
|
|
71
|
+
************************************************************/
|
|
72
|
+
function yui_uplot_axes(axes)
|
|
73
|
+
{
|
|
74
|
+
let list = Array.isArray(axes)? axes.slice() : [axes || {}];
|
|
75
|
+
while(list.length < 2) {
|
|
76
|
+
list.push({});
|
|
77
|
+
}
|
|
78
|
+
return list.map((ax) => {
|
|
79
|
+
let a = Object.assign({}, ax || {});
|
|
80
|
+
if(a.stroke === undefined) {
|
|
81
|
+
a.stroke = yui_uplot_axis_ink;
|
|
82
|
+
}
|
|
83
|
+
a.grid = Object.assign({stroke: yui_uplot_grid_ink}, a.grid || {});
|
|
84
|
+
a.ticks = Object.assign({stroke: yui_uplot_grid_ink}, a.ticks || {});
|
|
85
|
+
return a;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
yui_uplot_axes,
|
|
91
|
+
yui_uplot_axis_ink,
|
|
92
|
+
yui_uplot_grid_ink,
|
|
93
|
+
YUI_UPLOT_PALETTE,
|
|
94
|
+
};
|