@yuneta/gobj-ui 7.32.6 → 7.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.32.6",
3
+ "version": "7.32.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
package/src/c_yui_nav.js CHANGED
@@ -111,6 +111,7 @@ import {
111
111
  import {text_node} from "./yui_text.js";
112
112
  import {css_string} from "./yui_selector.js";
113
113
  import {badge_node, badge_tone, paint_badge, name_control_with_badge} from "./yui_badge.js";
114
+ import {yui_toolbar_icon} from "./yui_toolbar.js";
114
115
 
115
116
  /***************************************************************
116
117
  * Constants
@@ -444,7 +445,7 @@ function render_tabs(gobj, items)
444
445
  let pinned = !empty_string(it.icon) && !has_label;
445
446
  let badge_el = item_badge_node(gobj, it, pinned);
446
447
  if(!empty_string(it.icon)) {
447
- children.push(icon_span(it.icon, "icon is-small", pinned ? badge_el : null));
448
+ children.push(icon_span(it.icon, "icon", pinned ? badge_el : null, true));
448
449
  }
449
450
  if(has_label) {
450
451
  children.push(["span", {i18n: it.name}, text_node(it.name)]);
@@ -598,8 +599,7 @@ function render_backbar(gobj)
598
599
  return createElement2(
599
600
  ["div", {},
600
601
  ["a", a_attrs, [
601
- ["span", {class: "icon is-small"},
602
- ["i", {class: "yi-arrow-left", "aria-hidden": "true"}]],
602
+ icon_span("yi-arrow-left", "icon", null, true),
603
603
  ["span", label_attrs, text_node(label)]
604
604
  ]]
605
605
  ]
@@ -772,7 +772,7 @@ function item_li(gobj, it, opts)
772
772
  let pinned = !empty_string(it.icon) && (is_stacked || !label_el);
773
773
  let badge_el = item_badge_node(gobj, it, pinned);
774
774
  let icon_el = !empty_string(it.icon)
775
- ? icon_span(it.icon, "icon", pinned ? badge_el : null)
775
+ ? icon_span(it.icon, "icon", pinned ? badge_el : null, true)
776
776
  : null;
777
777
 
778
778
  let a_class = "yui-nav-item";
@@ -927,10 +927,16 @@ function item_badge_node(gobj, it, pinned)
927
927
 
928
928
  /************************************************************
929
929
  * An item's icon, with its badge on the corner when given one.
930
+ * `row_glyph`: the glyph of a tab or a menu entry, at the one
931
+ * size of the toolbars (yui_toolbar_icon). Without it the
932
+ * glyph takes the size the layout gives it (the icon bar, the
933
+ * cards).
930
934
  ************************************************************/
931
- function icon_span(icon, classes, badge_el)
935
+ function icon_span(icon, classes, badge_el, row_glyph)
932
936
  {
933
- let glyph = ["i", {class: icon, "aria-hidden": "true"}];
937
+ let glyph = row_glyph ?
938
+ yui_toolbar_icon(icon) :
939
+ ["i", {class: icon, "aria-hidden": "true"}];
934
940
  if(!badge_el) {
935
941
  return ["span", {class: classes}, glyph];
936
942
  }
@@ -616,9 +616,7 @@ function add_tab(gobj, gobj2, id, text, icon)
616
616
  if(icon) {
617
617
  $a.appendChild(
618
618
  createElement2(
619
- ['span', {class: 'icon is-small is-hidden-mobile'},
620
- ['i', {class: `${icon}`, 'aria-hidden': 'true'}]
621
- ]
619
+ ['span', {class: 'icon is-hidden-mobile'}, [yui_toolbar_icon(icon)]]
622
620
  )
623
621
  );
624
622
  }
@@ -0,0 +1,94 @@
1
+ /***********************************************************************
2
+ * nav_icon_size.wiring.test.js
3
+ *
4
+ * The glyph of a tab and of a menu entry of C_YUI_NAV is the size
5
+ * of the glyphs of a toolbar: YUI_TOOLBAR_ICON_SIZE (yui_toolbar.js).
6
+ * Up to 7.32.6 a tab and a menu entry took the 16px of their text,
7
+ * and right under a toolbar of 20px their icons read as smaller.
8
+ * The icon bar and the cards are other bands: they keep their own
9
+ * size. The close mark of a tab is no icon of the tab: it keeps
10
+ * its own size too.
11
+ *
12
+ * Driven through the real gclass on a document double.
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
+ SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
24
+ gobj_read_attr,
25
+ } = await import("@yuneta/gobj-js");
26
+ const {register_c_yui_nav} = await import("./c_yui_nav.js");
27
+ const {YUI_TOOLBAR_ICON_SIZE} = await import("./yui_toolbar.js");
28
+
29
+ let yuno = null;
30
+ let seq = 0;
31
+
32
+ beforeAll(async () => {
33
+ const i18next = (await import("i18next")).default;
34
+ await i18next.init({lng: "en", resources: {en: {translation: {}}}});
35
+ gobj_start_up(null, null, null, null, null, null, null);
36
+ gclass_create("C_TEST_NAV_ICON_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
37
+ register_c_yui_nav();
38
+ yuno = gobj_create_yuno("nav_icon_size_yuno", "C_TEST_NAV_ICON_HOST", {});
39
+ });
40
+
41
+ const ITEMS = [
42
+ {id: "topics", name: "topics", route: "/topics", icon: "yi-table", closable: true},
43
+ {id: "graphs", name: "graphs", route: "/graphs", icon: "yi-hexagon-nodes", badge: 2},
44
+ ];
45
+
46
+ /* The container of a new C_YUI_NAV of this layout */
47
+ function nav_container(kw)
48
+ {
49
+ const nav = gobj_create(`nav_icon_${++seq}`, "C_YUI_NAV",
50
+ Object.assign({menu_items: ITEMS}, kw), yuno);
51
+ return gobj_read_attr(nav, "$container");
52
+ }
53
+
54
+ /* The font size each glyph of the items carries in its own style */
55
+ function glyph_sizes($container, selector)
56
+ {
57
+ return $container.querySelectorAll(selector).map(($i) => {
58
+ const m = /font-size:\s*([^;]+)/.exec($i.style.cssText || "");
59
+ return m ? m[1].trim() : "";
60
+ });
61
+ }
62
+
63
+ test("a tab's glyph is the size of a toolbar's", () => {
64
+ const $c = nav_container({layout: "tabs"});
65
+ expect(glyph_sizes($c, "i.yi-table")).toEqual([YUI_TOOLBAR_ICON_SIZE]);
66
+ expect(glyph_sizes($c, "i.yi-hexagon-nodes")).toEqual([YUI_TOOLBAR_ICON_SIZE]);
67
+ });
68
+
69
+ test("the close mark of a tab keeps its own size", () => {
70
+ const $c = nav_container({layout: "tabs"});
71
+ expect(glyph_sizes($c, "i.yi-xmark")).toEqual([""]);
72
+ });
73
+
74
+ test("a menu entry's glyph is the size of a toolbar's", () => {
75
+ const $c = nav_container({layout: "vertical"});
76
+ expect(glyph_sizes($c, "i.yi-table")).toEqual([YUI_TOOLBAR_ICON_SIZE]);
77
+ expect(glyph_sizes($c, "i.yi-hexagon-nodes")).toEqual([YUI_TOOLBAR_ICON_SIZE]);
78
+ });
79
+
80
+ test("the back arrow of a backbar is the size of a toolbar's", () => {
81
+ const $c = nav_container({layout: "backbar", back_route: "/home"});
82
+ expect(glyph_sizes($c, "i.yi-arrow-left")).toEqual([YUI_TOOLBAR_ICON_SIZE]);
83
+ });
84
+
85
+ test("the icon bar keeps its own size", () => {
86
+ const $c = nav_container({layout: "icon-bar"});
87
+ expect(glyph_sizes($c, "i.yi-table")).toEqual([""]);
88
+ });
89
+
90
+ test("the glyph is decoration: the control carries the name", () => {
91
+ const $c = nav_container({layout: "tabs"});
92
+ const $i = $c.querySelector("i.yi-table");
93
+ expect($i.getAttribute("aria-hidden")).toBe("true");
94
+ });
@@ -1,54 +1,110 @@
1
1
  /***********************************************************************
2
2
  * tabulator_css.test.js
3
3
  *
4
- * The paginator on a narrow screen (tabulator.css): its icons are
5
- * the size of the icons of a view's toolbar, and each step button
6
- * reads its mask from a property that yui_icons.css defines.
4
+ * The stylesheet of the tables: an editor fills its cell only when
5
+ * it is a box to TYPE in. A checkbox or a radio given width and
6
+ * height 100% is drawn as a square the size of the cell (the
7
+ * tickCross editor of an app's "validated" opened as a huge
8
+ * empty box on a phone, gobj-ui 7.26.36).
9
+ *
10
+ * And the paginator on a narrow screen: its icons are the size of
11
+ * the icons of a view's toolbar, and each step button reads its
12
+ * mask from a property that yui_icons.css defines (7.32.6).
13
+ *
14
+ * Read as text, as the window layer's invariants are: jsdom applies
15
+ * no stylesheet.
7
16
  *
8
17
  * Copyright (c) 2026, ArtGins.
9
18
  * All Rights Reserved.
10
19
  ***********************************************************************/
11
- import {test, expect} from "vitest";
12
- import fs from "node:fs";
20
+ import {describe, test, expect} from "vitest";
21
+ import {readFileSync} from "node:fs";
22
+ import {dirname, join} from "node:path";
23
+ import {fileURLToPath} from "node:url";
13
24
  import {install_dom_double} from "../test/dom_double.js";
14
25
 
15
26
  install_dom_double();
16
27
 
17
28
  const {YUI_TOOLBAR_ICON_SIZE} = await import("./yui_toolbar.js");
18
29
 
19
- const CSS = fs.readFileSync(new URL("./tabulator.css", import.meta.url), "utf8");
20
- const ICONS = fs.readFileSync(new URL("./yui_icons.css", import.meta.url), "utf8");
30
+ const ICONS = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "yui_icons.css"), "utf8");
21
31
 
22
- /* The block of the narrow screen. */
23
- function narrow()
32
+ const CSS = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "tabulator.css"), "utf8")
33
+ .replace(/\/\*[\s\S]*?\*\//g, "");
34
+
35
+ /* Every rule: its selectors, and its body. */
36
+ function rules()
24
37
  {
25
- let start = CSS.indexOf("@media screen and (max-width: 768px) {");
26
- expect(start).toBeGreaterThan(0);
27
- return CSS.slice(start, CSS.indexOf("\n}\n", start));
38
+ const out = [];
39
+ const re = /([^{}]+)\{([^{}]*)\}/g;
40
+ let m;
41
+ while((m = re.exec(CSS)) !== null) {
42
+ out.push({
43
+ selectors: m[1].split(",").map((s) => s.trim()).filter(Boolean),
44
+ body: m[2]
45
+ });
46
+ }
47
+ return out;
28
48
  }
29
49
 
30
- test("the paginator's icons are the size of the toolbar's", () => {
31
- let m = /\[data-page=last\]\)::before \{[^}]*?width: ([\d.]+rem);\s*height: ([\d.]+rem);/.exec(narrow());
32
- expect(m).not.toBeNull();
33
- expect(m[1]).toBe(YUI_TOOLBAR_ICON_SIZE);
34
- expect(m[2]).toBe(YUI_TOOLBAR_ICON_SIZE);
50
+ describe("an editor fills its cell only when it is a box to type in", () => {
51
+ test("no rule sizes a checkbox or a radio of a table to its cell", () => {
52
+ const offenders = [];
53
+ for(const r of rules()) {
54
+ if(!/\b(width|height)\s*:\s*100%/.test(r.body)) {
55
+ continue;
56
+ }
57
+ for(const sel of r.selectors) {
58
+ /* A bare `input` in a cell editor or a header filter reaches
59
+ * a checkbox too, unless the selector leaves it out. */
60
+ if(/\binput\b/.test(sel) && /tabulator/.test(sel) &&
61
+ !(/:not\(\[type=checkbox\]\)/.test(sel) && /:not\(\[type=radio\]\)/.test(sel))) {
62
+ offenders.push(sel);
63
+ }
64
+ }
65
+ }
66
+ expect(offenders).toEqual([]);
67
+ });
68
+
69
+ test("a text input of a cell being edited still fills it", () => {
70
+ const fill = rules().filter((r) => /\bwidth\s*:\s*100%/.test(r.body) &&
71
+ r.selectors.some((s) => /tabulator-editing input:not\(\[type=checkbox\]\)/.test(s)));
72
+ expect(fill.length).toBeGreaterThan(0);
73
+ });
35
74
  });
36
75
 
37
- test("each step has the icon of the period navigator, from yui_icons.css", () => {
38
- const STEPS = {
39
- first: "yi-backward-step",
40
- prev: "yi-chevron-left",
41
- next: "yi-chevron-right",
42
- last: "yi-forward-step"
43
- };
44
- for(const [page, icon] of Object.entries(STEPS)) {
45
- expect(narrow()).toMatch(new RegExp(
46
- `\\[data-page=${page}\\]::before \\{\\s*-webkit-mask-image: var\\(--${icon}\\);` +
47
- `\\s*mask-image: var\\(--${icon}\\);`));
48
- expect(ICONS).toMatch(new RegExp(`\\n {4}--${icon}: url\\(`));
76
+ describe("the paginator on a narrow screen", () => {
77
+ /* The block of the narrow screen. */
78
+ function narrow()
79
+ {
80
+ let start = CSS.indexOf("@media screen and (max-width: 768px) {");
81
+ expect(start).toBeGreaterThan(0);
82
+ return CSS.slice(start, CSS.indexOf("\n}\n", start));
49
83
  }
50
- });
51
84
 
52
- test("the numbered pages keep their number: only the steps lose the word", () => {
53
- expect(narrow()).not.toMatch(/\.tabulator-page\[data-page\]/);
85
+ test("its icons are the size of the toolbar's", () => {
86
+ let m = /\[data-page=last\]\)::before \{[^}]*?width: ([\d.]+rem);\s*height: ([\d.]+rem);/.exec(narrow());
87
+ expect(m).not.toBeNull();
88
+ expect(m[1]).toBe(YUI_TOOLBAR_ICON_SIZE);
89
+ expect(m[2]).toBe(YUI_TOOLBAR_ICON_SIZE);
90
+ });
91
+
92
+ test("each step has the icon of the period navigator, from yui_icons.css", () => {
93
+ const STEPS = {
94
+ first: "yi-backward-step",
95
+ prev: "yi-chevron-left",
96
+ next: "yi-chevron-right",
97
+ last: "yi-forward-step"
98
+ };
99
+ for(const [page, icon] of Object.entries(STEPS)) {
100
+ expect(narrow()).toMatch(new RegExp(
101
+ `\\[data-page=${page}\\]::before \\{\\s*-webkit-mask-image: var\\(--${icon}\\);` +
102
+ `\\s*mask-image: var\\(--${icon}\\);`));
103
+ expect(ICONS).toMatch(new RegExp(`\\n {4}--${icon}: url\\(`));
104
+ }
105
+ });
106
+
107
+ test("the numbered pages keep their number: only the steps lose the word", () => {
108
+ expect(narrow()).not.toMatch(/\.tabulator-page\[data-page\]/);
109
+ });
54
110
  });
@@ -40,14 +40,24 @@ import "./yui_toolbar.css"; // Must be in index.js ?
40
40
  * glyph reads as a marker rather than as a second word. The
41
41
  * app BAR is a different band and keeps its own, bigger size
42
42
  * (`.yui-toolbar-item .icon`, 1.35rem on 44px items).
43
+ *
44
+ * It is also the size of the glyphs of the TABS and of the
45
+ * MENU entries (C_YUI_NAV, the topic tabs of
46
+ * C_YUI_TREEDB_TOPICS), and of the paginator of a table on a
47
+ * phone (tabulator.css). Up to 7.32.6 a tab took the 16px of
48
+ * its text, and right under a toolbar its icons read as
49
+ * smaller than the toolbar's. The rows of a tab or a menu
50
+ * entry are 24px of line, so the glyph changes no height.
43
51
  ************************************************************/
44
52
  const YUI_TOOLBAR_ICON_SIZE = "1.25rem";
45
53
 
46
- /* The `<i>` spec of a toolbar glyph, at that one size. */
54
+ /* The `<i>` spec of a toolbar glyph, at that one size. The
55
+ * glyph is decoration: the control around it carries the name. */
47
56
  function yui_toolbar_icon(icon_class, extra_style)
48
57
  {
49
58
  return ['i', {
50
59
  class: icon_class,
60
+ 'aria-hidden': 'true',
51
61
  style: `font-size:${YUI_TOOLBAR_ICON_SIZE}; line-height:1; color:inherit;` +
52
62
  (extra_style || ''),
53
63
  }];