@yuneta/gobj-ui 7.32.3 → 7.32.4
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 +7 -3
- package/dist/gobj-ui.cjs.js +37 -1
- package/dist/gobj-ui.es.js +37 -1
- package/package.json +1 -1
- package/src/c_yui_treedb_topic_with_form.js +55 -1
- package/src/treedb_header_filters.wiring.test.js +118 -0
- package/src/yui_table_standard.js +15 -2
- package/src/yui_table_standard.test.js +8 -0
package/README.md
CHANGED
|
@@ -4384,7 +4384,10 @@ yui_table_wire(table, t);
|
|
|
4384
4384
|
`opts.sizes` change them. A size that the sizes do not hold goes first in
|
|
4385
4385
|
the selector. The host gives the table every row. The footer shows the
|
|
4386
4386
|
paginator and the row count. The count is the number of rows that the
|
|
4387
|
-
filters leave, on all pages together.
|
|
4387
|
+
filters leave, on all pages together. With a filter on, it says both
|
|
4388
|
+
numbers: the rows that the filter leaves and the rows that the table holds
|
|
4389
|
+
("12 / 27 rows"). A status line under the table that only counts its rows
|
|
4390
|
+
is then not necessary. The table locale gives its word, so
|
|
4388
4391
|
the word changes language with `yui_tabulator_relocalize()`.
|
|
4389
4392
|
|
|
4390
4393
|
`yui_table_filters(columns)` gives a copy of the columns, each with its
|
|
@@ -4610,8 +4613,9 @@ let $toolbar = yui_toolbar({class: "ACCOUNTS_TOOLBAR"}, [
|
|
|
4610
4613
|
```
|
|
4611
4614
|
|
|
4612
4615
|
`C_YUI_TREEDB_TOPIC_WITH_FORM` obeys the rule with no work from its host
|
|
4613
|
-
since 7.32.
|
|
4614
|
-
its toolbar wrapped into two rows on a phone.
|
|
4616
|
+
since 7.32.4. Up to 7.32.0 it hid the paginator when all the rows fit, and
|
|
4617
|
+
its toolbar wrapped into two rows on a phone. Up to 7.32.3 the columns of a
|
|
4618
|
+
document, a hook, a file and a time had no filter.
|
|
4615
4619
|
|
|
4616
4620
|
How to make sure that a table obeys it: open the DEPLOYED page at 390 px.
|
|
4617
4621
|
Each control of the toolbar is on one line, the paginator
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -62216,8 +62216,39 @@ function create_tabulator(gobj) {
|
|
|
62216
62216
|
if (value === null || value === void 0) return false;
|
|
62217
62217
|
return (typeof value === "string" ? value : JSON.stringify(value)).toLowerCase().includes(String(term).toLowerCase());
|
|
62218
62218
|
}
|
|
62219
|
+
function time_matches(real_type) {
|
|
62220
|
+
return function(term, value) {
|
|
62221
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
62222
|
+
if (!needle) return true;
|
|
62223
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.default.language));
|
|
62224
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
62225
|
+
};
|
|
62226
|
+
}
|
|
62219
62227
|
function apply_header_filter(colDef, field_desc) {
|
|
62220
62228
|
switch (field_desc.type) {
|
|
62229
|
+
case "object":
|
|
62230
|
+
case "dict":
|
|
62231
|
+
case "template":
|
|
62232
|
+
case "array":
|
|
62233
|
+
case "list":
|
|
62234
|
+
case "coordinates":
|
|
62235
|
+
case "blob":
|
|
62236
|
+
case "gbuffer":
|
|
62237
|
+
case "hook":
|
|
62238
|
+
case "file":
|
|
62239
|
+
colDef.headerFilter = "input";
|
|
62240
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
62241
|
+
break;
|
|
62242
|
+
case "now":
|
|
62243
|
+
case "time":
|
|
62244
|
+
colDef.headerFilter = "input";
|
|
62245
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
62246
|
+
break;
|
|
62247
|
+
case "image":
|
|
62248
|
+
case "color":
|
|
62249
|
+
case "icon":
|
|
62250
|
+
colDef.headerFilter = "input";
|
|
62251
|
+
break;
|
|
62221
62252
|
case "boolean":
|
|
62222
62253
|
colDef.headerFilter = "tickCross";
|
|
62223
62254
|
colDef.headerFilterParams = { tristate: true };
|
|
@@ -62468,7 +62499,12 @@ function create_tabulator(gobj) {
|
|
|
62468
62499
|
}
|
|
62469
62500
|
let paged = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "with_remote_paging");
|
|
62470
62501
|
let total = gobj.priv._page_total;
|
|
62471
|
-
if (paged
|
|
62502
|
+
if (!paged) try {
|
|
62503
|
+
total = tabulator.getDataCount();
|
|
62504
|
+
} catch (e) {
|
|
62505
|
+
total = n;
|
|
62506
|
+
}
|
|
62507
|
+
if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows")}`;
|
|
62472
62508
|
else $rc.textContent = `${n} ${(0, i18next.t)("rows")}`;
|
|
62473
62509
|
}
|
|
62474
62510
|
tabulator.on("columnsLoaded", function() {
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -62211,8 +62211,39 @@ function create_tabulator(gobj) {
|
|
|
62211
62211
|
if (value === null || value === void 0) return false;
|
|
62212
62212
|
return (typeof value === "string" ? value : JSON.stringify(value)).toLowerCase().includes(String(term).toLowerCase());
|
|
62213
62213
|
}
|
|
62214
|
+
function time_matches(real_type) {
|
|
62215
|
+
return function(term, value) {
|
|
62216
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
62217
|
+
if (!needle) return true;
|
|
62218
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.language));
|
|
62219
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
62220
|
+
};
|
|
62221
|
+
}
|
|
62214
62222
|
function apply_header_filter(colDef, field_desc) {
|
|
62215
62223
|
switch (field_desc.type) {
|
|
62224
|
+
case "object":
|
|
62225
|
+
case "dict":
|
|
62226
|
+
case "template":
|
|
62227
|
+
case "array":
|
|
62228
|
+
case "list":
|
|
62229
|
+
case "coordinates":
|
|
62230
|
+
case "blob":
|
|
62231
|
+
case "gbuffer":
|
|
62232
|
+
case "hook":
|
|
62233
|
+
case "file":
|
|
62234
|
+
colDef.headerFilter = "input";
|
|
62235
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
62236
|
+
break;
|
|
62237
|
+
case "now":
|
|
62238
|
+
case "time":
|
|
62239
|
+
colDef.headerFilter = "input";
|
|
62240
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
62241
|
+
break;
|
|
62242
|
+
case "image":
|
|
62243
|
+
case "color":
|
|
62244
|
+
case "icon":
|
|
62245
|
+
colDef.headerFilter = "input";
|
|
62246
|
+
break;
|
|
62216
62247
|
case "boolean":
|
|
62217
62248
|
colDef.headerFilter = "tickCross";
|
|
62218
62249
|
colDef.headerFilterParams = { tristate: true };
|
|
@@ -62463,7 +62494,12 @@ function create_tabulator(gobj) {
|
|
|
62463
62494
|
}
|
|
62464
62495
|
let paged = gobj_read_bool_attr(gobj, "with_remote_paging");
|
|
62465
62496
|
let total = gobj.priv._page_total;
|
|
62466
|
-
if (paged
|
|
62497
|
+
if (!paged) try {
|
|
62498
|
+
total = tabulator.getDataCount();
|
|
62499
|
+
} catch (e) {
|
|
62500
|
+
total = n;
|
|
62501
|
+
}
|
|
62502
|
+
if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows")}`;
|
|
62467
62503
|
else $rc.textContent = `${n} ${t("rows")}`;
|
|
62468
62504
|
}
|
|
62469
62505
|
tabulator.on("columnsLoaded", function() {
|
package/package.json
CHANGED
|
@@ -1360,9 +1360,53 @@ function create_tabulator(gobj)
|
|
|
1360
1360
|
return text.toLowerCase().includes(String(term).toLowerCase());
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
|
+
/* A time is filtered by the date the cell SHOWS, in the app's
|
|
1364
|
+
* language: the value is an epoch (or an ISO text), and typing what
|
|
1365
|
+
* one reads found nothing. */
|
|
1366
|
+
function time_matches(real_type)
|
|
1367
|
+
{
|
|
1368
|
+
return function(term, value) {
|
|
1369
|
+
let needle = String(term ?? "").trim().toLowerCase();
|
|
1370
|
+
if(!needle) {
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
let text = time_value_to_text(value, real_type, safe_locale(i18next.language));
|
|
1374
|
+
return String(text || "").toLowerCase().includes(needle);
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1363
1378
|
function apply_header_filter(colDef, field_desc)
|
|
1364
1379
|
{
|
|
1365
1380
|
switch(field_desc.type) {
|
|
1381
|
+
/* A document, a list of links, a file reference: the JSON
|
|
1382
|
+
* text is what is searched, the same reading as an fkey
|
|
1383
|
+
* (every column of data has a filter, gobj-ui README,
|
|
1384
|
+
* "Conventions" -> "A table: a filter on every column, the
|
|
1385
|
+
* paginator always, the toolbar in one row"). */
|
|
1386
|
+
case "object":
|
|
1387
|
+
case "dict":
|
|
1388
|
+
case "template":
|
|
1389
|
+
case "array":
|
|
1390
|
+
case "list":
|
|
1391
|
+
case "coordinates":
|
|
1392
|
+
case "blob":
|
|
1393
|
+
case "gbuffer":
|
|
1394
|
+
case "hook":
|
|
1395
|
+
case "file":
|
|
1396
|
+
colDef.headerFilter = "input";
|
|
1397
|
+
colDef.headerFilterFunc = fkey_matches;
|
|
1398
|
+
break;
|
|
1399
|
+
case "now":
|
|
1400
|
+
case "time":
|
|
1401
|
+
colDef.headerFilter = "input";
|
|
1402
|
+
colDef.headerFilterFunc = time_matches(field_desc.real_type);
|
|
1403
|
+
break;
|
|
1404
|
+
/* The name of an image, a colour, an icon: text. */
|
|
1405
|
+
case "image":
|
|
1406
|
+
case "color":
|
|
1407
|
+
case "icon":
|
|
1408
|
+
colDef.headerFilter = "input";
|
|
1409
|
+
break;
|
|
1366
1410
|
case "boolean":
|
|
1367
1411
|
colDef.headerFilter = "tickCross";
|
|
1368
1412
|
colDef.headerFilterParams = {tristate: true};
|
|
@@ -1842,7 +1886,17 @@ function create_tabulator(gobj)
|
|
|
1842
1886
|
* with 114 would be a lie by omission. Say both. */
|
|
1843
1887
|
let paged = gobj_read_bool_attr(gobj, "with_remote_paging");
|
|
1844
1888
|
let total = gobj.priv._page_total;
|
|
1845
|
-
if(paged
|
|
1889
|
+
if(!paged) {
|
|
1890
|
+
/* With a filter on, both: the rows it leaves of the rows the
|
|
1891
|
+
* table holds -- the same reading as the standard table
|
|
1892
|
+
* (yui_table_standard.js). */
|
|
1893
|
+
try {
|
|
1894
|
+
total = tabulator.getDataCount();
|
|
1895
|
+
} catch(e) {
|
|
1896
|
+
total = n;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
if(typeof total === "number" && total > n) {
|
|
1846
1900
|
$rc.textContent = `${n} / ${total} ${t("rows")}`;
|
|
1847
1901
|
} else {
|
|
1848
1902
|
$rc.textContent = `${n} ${t("rows")}`;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* treedb_header_filters.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* Every column of data of C_YUI_TREEDB_TOPIC_WITH_FORM's table has
|
|
5
|
+
* a header filter (gobj-ui README, "Conventions" -> "A table: a
|
|
6
|
+
* filter on every column, the paginator always, the toolbar in one
|
|
7
|
+
* row"). Up to 7.32.3 a document (dict, list, blob, coordinates), a
|
|
8
|
+
* hook, a file and a time had none. A document is searched as its
|
|
9
|
+
* JSON text, a time as the date the cell shows.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
15
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
16
|
+
|
|
17
|
+
install_dom_double();
|
|
18
|
+
|
|
19
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
20
|
+
globalThis.ResizeObserver = class {
|
|
21
|
+
observe() {
|
|
22
|
+
}
|
|
23
|
+
unobserve() {
|
|
24
|
+
}
|
|
25
|
+
disconnect() {
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const tables = vi.hoisted(() => []);
|
|
31
|
+
vi.mock("tabulator-tables", () => {
|
|
32
|
+
class FakeTabulator {
|
|
33
|
+
constructor($el, settings) {
|
|
34
|
+
this.element = $el;
|
|
35
|
+
this.options = settings;
|
|
36
|
+
tables.push(this);
|
|
37
|
+
return new Proxy(this, {
|
|
38
|
+
get(target, prop) {
|
|
39
|
+
if(prop in target) {
|
|
40
|
+
return target[prop];
|
|
41
|
+
}
|
|
42
|
+
return () => [];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
on() {
|
|
47
|
+
}
|
|
48
|
+
off() {
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
SDATA_END, gclass_create, set_log_callback,
|
|
58
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
|
|
59
|
+
} = await import("@yuneta/gobj-js");
|
|
60
|
+
const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
|
|
61
|
+
|
|
62
|
+
const logged = [];
|
|
63
|
+
let yuno = null;
|
|
64
|
+
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
const i18next = (await import("i18next")).default;
|
|
67
|
+
await i18next.init({lng: "en", resources: {}});
|
|
68
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
69
|
+
set_log_callback((level, msg) => {
|
|
70
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
71
|
+
});
|
|
72
|
+
gclass_create("C_TEST_FILTERS_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
73
|
+
register_c_yui_treedb_topic_with_form();
|
|
74
|
+
yuno = gobj_create_yuno("filters_yuno", "C_TEST_FILTERS_HOST", {});
|
|
75
|
+
gobj_start(yuno);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("the header filters of a treedb topic's table", () => {
|
|
79
|
+
test("a column of every kind of data has one", () => {
|
|
80
|
+
const view = gobj_create_service("filters_view", "C_YUI_TREEDB_TOPIC_WITH_FORM", {
|
|
81
|
+
treedb_name: "treedb_test",
|
|
82
|
+
topic_name: "devices",
|
|
83
|
+
desc: {id: "devices", pkey: "id", cols: [
|
|
84
|
+
{id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
|
|
85
|
+
{id: "settings", header: "settings", type: "dict", flag: ["persistent"]},
|
|
86
|
+
{id: "notes", header: "notes", type: "array", flag: ["persistent"]},
|
|
87
|
+
{id: "props", header: "props", type: "blob", flag: ["persistent"]},
|
|
88
|
+
{id: "enabled", header: "enabled", type: "boolean", flag: ["persistent"]},
|
|
89
|
+
{id: "updated", header: "updated", type: "integer", flag: ["persistent", "time"]}
|
|
90
|
+
]}
|
|
91
|
+
}, yuno);
|
|
92
|
+
gobj_start(view);
|
|
93
|
+
const options = tables[tables.length - 1].options;
|
|
94
|
+
const columns = options.columns;
|
|
95
|
+
const col = (field) => columns.find((c) => c.field === field);
|
|
96
|
+
|
|
97
|
+
for(const field of ["id", "settings", "notes", "props", "updated"]) {
|
|
98
|
+
expect(col(field).headerFilter, field).toBe("input");
|
|
99
|
+
}
|
|
100
|
+
expect(col("enabled").headerFilter).toBe("tickCross");
|
|
101
|
+
|
|
102
|
+
/* A document: its JSON text */
|
|
103
|
+
const doc = col("settings").headerFilterFunc;
|
|
104
|
+
expect(doc("volt", {volts: 230})).toBe(true);
|
|
105
|
+
expect(doc("amp", {volts: 230})).toBe(false);
|
|
106
|
+
|
|
107
|
+
/* A time: the date the cell shows */
|
|
108
|
+
const epoch = Math.floor(new Date("2026-03-14T09:26:53").getTime() / 1000);
|
|
109
|
+
const when = col("updated").headerFilterFunc;
|
|
110
|
+
expect(when("2026", epoch)).toBe(true);
|
|
111
|
+
expect(when("1999", epoch)).toBe(false);
|
|
112
|
+
expect(when("", null)).toBe(true);
|
|
113
|
+
|
|
114
|
+
/* The paginator is drawn always: nothing in the settings hides it */
|
|
115
|
+
expect(options.pagination).toBe(true);
|
|
116
|
+
expect(logged.filter((l) => l.level === "error")).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -69,7 +69,8 @@ const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "but
|
|
|
69
69
|
*
|
|
70
70
|
* Called by Tabulator with `this` = its pagination module, on
|
|
71
71
|
* every page, filter and data change. `total_rows` is the ACTIVE
|
|
72
|
-
* count: the rows the filters leave, all pages together.
|
|
72
|
+
* count: the rows the filters leave, all pages together. With a
|
|
73
|
+
* filter on, the count says both: "12 / 27 rows".
|
|
73
74
|
*
|
|
74
75
|
* The number is data; the word comes from the table's locale
|
|
75
76
|
* (`pagination.counter.rows`, which `yui_tabulator_lang()` fills
|
|
@@ -84,9 +85,21 @@ function rows_counter(page_size, current_row, current_page, total_rows)
|
|
|
84
85
|
let $count = document.createElement("span");
|
|
85
86
|
$count.className = "YUI_TABLE_COUNT";
|
|
86
87
|
|
|
88
|
+
/* With a filter on, both numbers: the rows it leaves of the rows
|
|
89
|
+
* the table holds ("12 / 27"). The status lines the apps kept under
|
|
90
|
+
* their tables said it that way, and this count replaces them. */
|
|
91
|
+
let shown = total_rows || 0;
|
|
92
|
+
let all = shown;
|
|
93
|
+
try {
|
|
94
|
+
if(this && this.table && typeof this.table.getDataCount === "function") {
|
|
95
|
+
all = this.table.getDataCount();
|
|
96
|
+
}
|
|
97
|
+
} catch(e) {
|
|
98
|
+
all = shown;
|
|
99
|
+
}
|
|
87
100
|
let $number = document.createElement("span");
|
|
88
101
|
$number.className = "YUI_TABLE_COUNT_NUMBER";
|
|
89
|
-
$number.textContent =
|
|
102
|
+
$number.textContent = (all > shown) ? `${shown} / ${all}` : String(shown);
|
|
90
103
|
|
|
91
104
|
let $word = document.createElement("span");
|
|
92
105
|
$word.className = "YUI_TABLE_COUNT_WORD";
|
|
@@ -87,6 +87,14 @@ describe("the row count", () => {
|
|
|
87
87
|
expect($el.className).toBe("YUI_TABLE_COUNT");
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
test("with a filter on, the rows it leaves of the rows the table holds", () => {
|
|
91
|
+
let counter = yui_table_paging().paginationCounter;
|
|
92
|
+
let page = page_module("rows");
|
|
93
|
+
page.table.getDataCount = () => 27;
|
|
94
|
+
expect(counter.call(page, 25, 1, 1, 12, 1).textContent).toBe("12 / 27 rows");
|
|
95
|
+
expect(counter.call(page, 25, 1, 1, 27, 2).textContent).toBe("27 rows");
|
|
96
|
+
});
|
|
97
|
+
|
|
90
98
|
test("without a localize module it still counts, in English", () => {
|
|
91
99
|
let counter = yui_table_paging().paginationCounter;
|
|
92
100
|
let $el = counter.call({}, 25, 1, 1, 3, 1);
|