@yuneta/gobj-ui 7.32.8 → 7.32.10

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 CHANGED
@@ -919,8 +919,25 @@ Two layout facts the browser taught this component, both worth keeping:
919
919
  (`7.21.0` forwarded it and broke exactly that way); a host that wants node
920
920
  clicks mounts `C_YUI_JSON_GRAPH` itself.
921
921
  - Internal (DOM → FSM): `EV_TOGGLE_NODE`, `EV_EXPAND_COLLAPSED`, `EV_SEARCH`,
922
- `EV_EXPAND_ALL`, `EV_COLLAPSE_ALL`, `EV_COPY_ALL`. Every kw carries only a
923
- `path` string — never a DOM node or gobj.
922
+ `EV_EXPAND_ALL`, `EV_COLLAPSE_ALL`, `EV_EXPAND_LEVEL`, `EV_COLLAPSE_LEVEL`,
923
+ `EV_COPY_ALL`. Every kw carries only a `path` string — never a DOM node or
924
+ gobj.
925
+ - The tree folds by level too (7.32.10+). Beside "expand loaded" and
926
+ "collapse all", a stepper of two buttons works on one level of the whole
927
+ tree, with the tree-box icons of the icon rule (`yi-square-minus`,
928
+ `yi-square-plus`). A level is the depth of a row: 0 for an entry of the
929
+ root.
930
+ - `EV_EXPAND_LEVEL` (`+`) opens every loaded container of the shallowest
931
+ level that still has one closed. From a closed document, one press shows
932
+ the fields of each entry, with their own containers closed.
933
+ - `EV_COLLAPSE_LEVEL` (`-`) closes every container at the deepest level
934
+ open in sight, and every container under it.
935
+ - A `__collapsed__` sentinel is not opened by `+`: it opens through the
936
+ backend, as with "expand loaded".
937
+
938
+ The keys are `expand one level` and `collapse one level`, the same as the
939
+ stepper of the treedb graph. An app that mounts the viewer defines them in
940
+ every locale. The stepper hides with the tree, like the search box.
924
941
  - i18n keys the switch needs: `tree view`, `text view`, `graph view`,
925
942
  `text truncated; collapse some branches`. All spelled out inside `t()` in
926
943
  `view_label()` — never `t(VIEWS[i].key)`, which no `validate-locales` can
@@ -4534,9 +4551,12 @@ text is in the yunetas `CLAUDE.md` ("JS GUI conventions"); in short:
4534
4551
  define the keys of every module that it imports, and `yui_toolbar.js`
4535
4552
  carries the keys of the scroll arrows.
4536
4553
 
4537
- The app bar, the icon bar and the cards are other bands, with their own
4538
- bigger icons. The close mark of a tab is no icon of the tab and keeps the
4539
- size of its text. Up to 7.32.6 a tab and a menu entry took the size of
4554
+ The title bar of a `C_YUI_WINDOW` takes it too: its icon, and the
4555
+ minimize, maximize and close glyphs, drawn in a box of that size. So does
4556
+ the header of a dialog of the shell (its back arrow and its close), which
4557
+ is the phone's face of a window (7.32.9+). The app bar, the icon bar, the
4558
+ cards and the dock of windows are other bands, with their own sizes. The
4559
+ close mark of a tab is no icon of the tab and keeps the size of its text. Up to 7.32.6 a tab and a menu entry took the size of
4540
4560
  their text, 16px. Under a toolbar of 20px their icons looked smaller.
4541
4561
  - **Bulma helpers carry `!important`** (`.is-hidden`, `.is-flex`): toggle
4542
4562
  `is-hidden`, or use `style.setProperty('display', 'none', 'important')`.
@@ -4340,6 +4340,62 @@ function yui_shell_set_nav_item_badge(shell_gobj, item_id, value, tone) {
4340
4340
  function yui_shell_close_dropdown(shell_gobj) {
4341
4341
  close_toolbar_dropdown(shell_gobj);
4342
4342
  }
4343
+ // src/yui_toolbar_icon.js
4344
+ /***********************************************************************
4345
+ * yui_toolbar_icon.js
4346
+ *
4347
+ * The one size of the glyphs of a row of controls, and the
4348
+ * `<i>` that draws one at it.
4349
+ *
4350
+ * A module of its own, with no key and no CSS, so that a view
4351
+ * can take the size without taking the toolbar widget. In
4352
+ * 7.32.7 C_YUI_NAV imported it from yui_toolbar.js, and every
4353
+ * app that mounts a nav had to define the keys of the toolbar's
4354
+ * scroll arrows ("scroll left", "scroll right"), which
4355
+ * validate-locales reads in every module the app imports.
4356
+ * yui_toolbar.js exports the two names too, as before.
4357
+ *
4358
+ * Copyright (c) 2026, ArtGins.
4359
+ * All Rights Reserved.
4360
+ ***********************************************************************/
4361
+ /************************************************************
4362
+ * ONE size for every glyph of a view's toolbar, in `rem`.
4363
+ *
4364
+ * It lives here because it belongs to the TOOLBAR and not to
4365
+ * any one view: it was born in the graph rows (7.23.86) and the
4366
+ * JSON viewer beside them still drew 16px, which is the same
4367
+ * drift one level up.
4368
+ *
4369
+ * `rem` and not `em` is the whole lesson: `em` is measured
4370
+ * against the button, so one declaration draws three icons --
4371
+ * `1.5em` is 24px in a plain button, 18px in an `is-small`
4372
+ * chip, and a labelled button that declares nothing keeps the
4373
+ * inherited 16px. `rem` is measured against the page, so a
4374
+ * chip deliberately shorter than a button still carries the
4375
+ * same glyph.
4376
+ *
4377
+ * 20px against a row's 16px text: an icon-only button is
4378
+ * legible at half its 40px height, and beside a label the
4379
+ * glyph reads as a marker rather than as a second word. The
4380
+ * app BAR is a different band and keeps its own, bigger size
4381
+ * (`.yui-toolbar-item .icon`, 1.35rem on 44px items).
4382
+ *
4383
+ * It is also the size of the glyphs of the TABS and of the
4384
+ * MENU entries (C_YUI_NAV, the topic tabs of
4385
+ * C_YUI_TREEDB_TOPICS), and of the paginator of a table on a
4386
+ * phone (tabulator.css). Up to 7.32.6 a tab took the 16px of
4387
+ * its text, and right under a toolbar its icons read as
4388
+ * smaller than the toolbar's. The rows of a tab or a menu
4389
+ * entry are 24px of line, so the glyph changes no height.
4390
+ ************************************************************/
4391
+ var YUI_TOOLBAR_ICON_SIZE = "1.25rem";
4392
+ function yui_toolbar_icon(icon_class, extra_style) {
4393
+ return ["i", {
4394
+ class: icon_class,
4395
+ "aria-hidden": "true",
4396
+ style: `font-size:${YUI_TOOLBAR_ICON_SIZE}; line-height:1; color:inherit;` + (extra_style || "")
4397
+ }];
4398
+ }
4343
4399
  // src/shell_modals.js
4344
4400
  /***********************************************************************
4345
4401
  * shell_modals.js
@@ -4582,7 +4638,7 @@ function yui_shell_show_modal(shell, content, opts) {
4582
4638
  "aria-label": (0, i18next.t)("back"),
4583
4639
  "data-i18n-aria-label": "back"
4584
4640
  },
4585
- [["i", { class: "yi-arrow-left" }]]
4641
+ [yui_toolbar_icon("yi-arrow-left")]
4586
4642
  ],
4587
4643
  [
4588
4644
  "span",
@@ -4599,7 +4655,7 @@ function yui_shell_show_modal(shell, content, opts) {
4599
4655
  "aria-label": (0, i18next.t)("close"),
4600
4656
  "data-i18n-aria-label": "close"
4601
4657
  },
4602
- [["i", { class: "yi-xmark" }]]
4658
+ [yui_toolbar_icon("yi-xmark")]
4603
4659
  ]
4604
4660
  ]
4605
4661
  ], [
@@ -5194,7 +5250,7 @@ function ensure_window_style() {
5194
5250
  .yui-window-titlebar-controls { display: flex; align-items: center; gap: 2px; padding-left: 6px; }
5195
5251
  .yui-window-title { white-space: nowrap; }
5196
5252
  .yui-window-title .icon { flex: 0 0 auto; }
5197
- .yui-window-title svg { width: 14px; height: 14px; display: block; }
5253
+ .yui-window-title svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
5198
5254
  /* Separator between the data half and the translated kind half. CSS,
5199
5255
  * not a text node: createElement2 trims text nodes and eats the spaces.
5200
5256
  * Decorative ("/ ''"): the halves NAME the window, and a reader read
@@ -5212,7 +5268,7 @@ function ensure_window_style() {
5212
5268
  }
5213
5269
  .yui-wc:hover { background: var(--bulma-scheme-main-ter); color: var(--bulma-text-strong); }
5214
5270
  .yui-wc.wc-close:hover { background: #e0364a; color: #fff; }
5215
- .yui-wc svg { width: 15px; height: 15px; display: block; }
5271
+ .yui-wc svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
5216
5272
  .yui-window-resize { color: var(--bulma-text-weak); opacity: 0.55; }
5217
5273
  .yui-window-resize:hover { opacity: 1; color: var(--bulma-text); }
5218
5274
  /* A modal window over its backdrop: the backdrop of a Bulma .modal,
@@ -5227,7 +5283,6 @@ function ensure_window_style() {
5227
5283
  .C_YUI_WINDOW.is-mobile-sheet .yui-window-resize { display: none !important; }
5228
5284
  .yui-wc { width: 42px; height: 38px; }
5229
5285
  .yui-wc.wc-max { display: none !important; }
5230
- .yui-wc svg { width: 18px; height: 18px; }
5231
5286
  }
5232
5287
  `;
5233
5288
  let $style = document.createElement("style");
@@ -5280,7 +5335,7 @@ function build_title_node(gobj, id, hidden) {
5280
5335
  else items.push([
5281
5336
  "span",
5282
5337
  { class: "icon" },
5283
- [["i", { class: icon }]]
5338
+ [yui_toolbar_icon(icon)]
5284
5339
  ]);
5285
5340
  }
5286
5341
  if (!(0, _yuneta_gobj_js.empty_string)(prefix)) items.push([
@@ -16557,62 +16612,6 @@ function create_gclass$15(gclass_name) {
16557
16612
  function register_c_yui_uplot() {
16558
16613
  return create_gclass$15(GCLASS_NAME$15);
16559
16614
  }
16560
- // src/yui_toolbar_icon.js
16561
- /***********************************************************************
16562
- * yui_toolbar_icon.js
16563
- *
16564
- * The one size of the glyphs of a row of controls, and the
16565
- * `<i>` that draws one at it.
16566
- *
16567
- * A module of its own, with no key and no CSS, so that a view
16568
- * can take the size without taking the toolbar widget. In
16569
- * 7.32.7 C_YUI_NAV imported it from yui_toolbar.js, and every
16570
- * app that mounts a nav had to define the keys of the toolbar's
16571
- * scroll arrows ("scroll left", "scroll right"), which
16572
- * validate-locales reads in every module the app imports.
16573
- * yui_toolbar.js exports the two names too, as before.
16574
- *
16575
- * Copyright (c) 2026, ArtGins.
16576
- * All Rights Reserved.
16577
- ***********************************************************************/
16578
- /************************************************************
16579
- * ONE size for every glyph of a view's toolbar, in `rem`.
16580
- *
16581
- * It lives here because it belongs to the TOOLBAR and not to
16582
- * any one view: it was born in the graph rows (7.23.86) and the
16583
- * JSON viewer beside them still drew 16px, which is the same
16584
- * drift one level up.
16585
- *
16586
- * `rem` and not `em` is the whole lesson: `em` is measured
16587
- * against the button, so one declaration draws three icons --
16588
- * `1.5em` is 24px in a plain button, 18px in an `is-small`
16589
- * chip, and a labelled button that declares nothing keeps the
16590
- * inherited 16px. `rem` is measured against the page, so a
16591
- * chip deliberately shorter than a button still carries the
16592
- * same glyph.
16593
- *
16594
- * 20px against a row's 16px text: an icon-only button is
16595
- * legible at half its 40px height, and beside a label the
16596
- * glyph reads as a marker rather than as a second word. The
16597
- * app BAR is a different band and keeps its own, bigger size
16598
- * (`.yui-toolbar-item .icon`, 1.35rem on 44px items).
16599
- *
16600
- * It is also the size of the glyphs of the TABS and of the
16601
- * MENU entries (C_YUI_NAV, the topic tabs of
16602
- * C_YUI_TREEDB_TOPICS), and of the paginator of a table on a
16603
- * phone (tabulator.css). Up to 7.32.6 a tab took the 16px of
16604
- * its text, and right under a toolbar its icons read as
16605
- * smaller than the toolbar's. The rows of a tab or a menu
16606
- * entry are 24px of line, so the glyph changes no height.
16607
- ************************************************************/
16608
- var YUI_TOOLBAR_ICON_SIZE = "1.25rem";
16609
- function yui_toolbar_icon(icon_class, extra_style) {
16610
- return ["i", {
16611
- class: icon_class,
16612
- "aria-hidden": "true",
16613
- style: `font-size:${YUI_TOOLBAR_ICON_SIZE}; line-height:1; color:inherit;` + (extra_style || "")
16614
- }];
16615
- }
16616
16615
  // src/yui_toolbar.js
16617
16616
  function yui_toolbar(attrs = {}, items = []) {
16618
16617
  function arrow_button(side, icon, label) {
@@ -46711,6 +46710,8 @@ function build_ui$12(gobj) {
46711
46710
  priv.$search_ctl = $container.querySelector(".JSON_SEARCH_CONTROL");
46712
46711
  priv.$expand_btn = $container.querySelector(".EV_EXPAND_ALL");
46713
46712
  priv.$collapse_btn = $container.querySelector(".EV_COLLAPSE_ALL");
46713
+ priv.$collapse_level_btn = $container.querySelector(".EV_COLLAPSE_LEVEL");
46714
+ priv.$expand_level_btn = $container.querySelector(".EV_EXPAND_LEVEL");
46714
46715
  priv.$graph = $container.querySelector(".JSON_GRAPH");
46715
46716
  priv.$mode_btns = /* @__PURE__ */ new Map();
46716
46717
  VIEWS$1.forEach(function(v) {
@@ -46737,6 +46738,8 @@ function destroy_ui$7(gobj) {
46737
46738
  priv.$search_ctl = null;
46738
46739
  priv.$expand_btn = null;
46739
46740
  priv.$collapse_btn = null;
46741
+ priv.$collapse_level_btn = null;
46742
+ priv.$expand_level_btn = null;
46740
46743
  priv.$mode_btns = null;
46741
46744
  }
46742
46745
  /************************************************************
@@ -46784,7 +46787,7 @@ function make_toolbar$4(gobj) {
46784
46787
  [yui_toolbar_icon("yi-magnifying-glass")]
46785
46788
  ]]
46786
46789
  ]);
46787
- left_items.push(icon_button$1(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"), icon_button$1(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"));
46790
+ left_items.push(icon_button$1(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"), icon_button$1(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"), icon_button$1(gobj, "yi-square-minus", "EV_COLLAPSE_LEVEL", "collapse one level"), icon_button$1(gobj, "yi-square-plus", "EV_EXPAND_LEVEL", "expand one level"));
46788
46791
  attach_clear($search_control, $search_input);
46789
46792
  left_items.push($search_control);
46790
46793
  let right_items = [view_mode_switch$1(gobj), icon_button$1(gobj, "yi-copy", "EV_COPY_ALL", "copy json")];
@@ -46942,7 +46945,9 @@ function apply_view_mode$1(gobj) {
46942
46945
  [
46943
46946
  priv.$search_ctl,
46944
46947
  priv.$expand_btn,
46945
- priv.$collapse_btn
46948
+ priv.$collapse_btn,
46949
+ priv.$collapse_level_btn,
46950
+ priv.$expand_level_btn
46946
46951
  ].forEach(function($el) {
46947
46952
  if ($el) $el.classList.toggle("is-hidden", mode !== "tree");
46948
46953
  });
@@ -47413,6 +47418,70 @@ function collect_loaded_paths(value, segments, out) {
47413
47418
  });
47414
47419
  }
47415
47420
  }
47421
+ /************************************************************
47422
+ * The entries of a container, as [key, value] pairs: the keys
47423
+ * of an object, the indexes of an array (as strings, the way
47424
+ * a path spells them). None for anything else.
47425
+ ************************************************************/
47426
+ function entries_of(value) {
47427
+ let type = json_type(value);
47428
+ if (type === "object") return Object.entries(value);
47429
+ if (type === "array") return value.map((v, i) => [String(i), v]);
47430
+ return [];
47431
+ }
47432
+ /************************************************************
47433
+ * Is it a container the tree can open in place: an object or
47434
+ * an array that is loaded (not a `__collapsed__` sentinel,
47435
+ * which opens through the backend).
47436
+ ************************************************************/
47437
+ function is_open_able(value) {
47438
+ if (is_collapsed(value)) return false;
47439
+ let type = json_type(value);
47440
+ return type === "object" || type === "array";
47441
+ }
47442
+ /************************************************************
47443
+ * The shallowest level that has a loaded container still
47444
+ * closed, -1 when every loaded container is open. A level is
47445
+ * the depth of a row: 0 for an entry of the root.
47446
+ ************************************************************/
47447
+ function first_closed_level(priv, value, segments) {
47448
+ let level = -1;
47449
+ for (let [k, v] of entries_of(value)) {
47450
+ if (!is_open_able(v)) continue;
47451
+ let child = segments.concat(k);
47452
+ let found = priv.expanded.has(seg_join(child)) ? first_closed_level(priv, v, child) : child.length - 1;
47453
+ if (found >= 0 && (level < 0 || found < level)) level = found;
47454
+ }
47455
+ return level;
47456
+ }
47457
+ /************************************************************
47458
+ * The deepest level with a container open in sight (all its
47459
+ * parents open too), -1 when none is. Only what the reader
47460
+ * sees counts: an open container under a closed one is not
47461
+ * on screen, and folding it would change nothing they see.
47462
+ ************************************************************/
47463
+ function deepest_open_level(priv, value, segments) {
47464
+ let level = -1;
47465
+ for (let [k, v] of entries_of(value)) {
47466
+ if (!is_open_able(v)) continue;
47467
+ let child = segments.concat(k);
47468
+ if (!priv.expanded.has(seg_join(child))) continue;
47469
+ level = Math.max(level, child.length - 1, deepest_open_level(priv, v, child));
47470
+ }
47471
+ return level;
47472
+ }
47473
+ /************************************************************
47474
+ * Open every loaded container of the levels up to `level`.
47475
+ ************************************************************/
47476
+ function open_levels_up_to(priv, value, segments, level) {
47477
+ for (let [k, v] of entries_of(value)) {
47478
+ if (!is_open_able(v)) continue;
47479
+ let child = segments.concat(k);
47480
+ if (child.length - 1 > level) continue;
47481
+ priv.expanded.add(seg_join(child));
47482
+ open_levels_up_to(priv, v, child, level);
47483
+ }
47484
+ }
47416
47485
  /***************************
47417
47486
  * Actions
47418
47487
  ***************************/
@@ -47537,6 +47606,36 @@ function ac_collapse_all$1(gobj, event, kw, src) {
47537
47606
  return 0;
47538
47607
  }
47539
47608
  /************************************************************
47609
+ * EV_EXPAND_LEVEL — open the next level: every loaded
47610
+ * container of the shallowest level that still has one closed.
47611
+ * The levels above it are all open already, so the tree shows
47612
+ * one level more. A `__collapsed__` sentinel is not opened: it
47613
+ * asks the backend, as with "expand loaded".
47614
+ ************************************************************/
47615
+ function ac_expand_level(gobj, event, kw, src) {
47616
+ let priv = gobj.priv;
47617
+ if (priv.root === null || priv.root === void 0) return 0;
47618
+ let level = first_closed_level(priv, priv.root, []);
47619
+ if (level < 0) return 0;
47620
+ open_levels_up_to(priv, priv.root, [], level);
47621
+ render_view$1(gobj);
47622
+ return 0;
47623
+ }
47624
+ /************************************************************
47625
+ * EV_COLLAPSE_LEVEL — fold the deepest level open in sight:
47626
+ * every container open at that level or under it is closed,
47627
+ * so the tree shows one level less.
47628
+ ************************************************************/
47629
+ function ac_collapse_level(gobj, event, kw, src) {
47630
+ let priv = gobj.priv;
47631
+ if (priv.root === null || priv.root === void 0) return 0;
47632
+ let level = deepest_open_level(priv, priv.root, []);
47633
+ if (level < 0) return 0;
47634
+ for (let path of Array.from(priv.expanded)) if (seg_split(path).length - 1 >= level) priv.expanded.delete(path);
47635
+ render_view$1(gobj);
47636
+ return 0;
47637
+ }
47638
+ /************************************************************
47540
47639
  * EV_COPY_ALL — copy the working document to the clipboard
47541
47640
  ************************************************************/
47542
47641
  function ac_copy_all$1(gobj, event, kw, src) {
@@ -47730,6 +47829,16 @@ function create_gclass$13(gclass_name) {
47730
47829
  ac_collapse_all$1,
47731
47830
  null
47732
47831
  ],
47832
+ [
47833
+ "EV_EXPAND_LEVEL",
47834
+ ac_expand_level,
47835
+ null
47836
+ ],
47837
+ [
47838
+ "EV_COLLAPSE_LEVEL",
47839
+ ac_collapse_level,
47840
+ null
47841
+ ],
47733
47842
  [
47734
47843
  "EV_COPY_ALL",
47735
47844
  ac_copy_all$1,
@@ -47770,6 +47879,8 @@ function create_gclass$13(gclass_name) {
47770
47879
  ["EV_SEARCH", 0],
47771
47880
  ["EV_EXPAND_ALL", 0],
47772
47881
  ["EV_COLLAPSE_ALL", 0],
47882
+ ["EV_EXPAND_LEVEL", 0],
47883
+ ["EV_COLLAPSE_LEVEL", 0],
47773
47884
  ["EV_COPY_ALL", 0],
47774
47885
  ["EV_SET_VIEW_MODE", 0],
47775
47886
  ["EV_JSON_ITEM_CLICKED", 0],
@@ -4335,6 +4335,62 @@ function yui_shell_set_nav_item_badge(shell_gobj, item_id, value, tone) {
4335
4335
  function yui_shell_close_dropdown(shell_gobj) {
4336
4336
  close_toolbar_dropdown(shell_gobj);
4337
4337
  }
4338
+ // src/yui_toolbar_icon.js
4339
+ /***********************************************************************
4340
+ * yui_toolbar_icon.js
4341
+ *
4342
+ * The one size of the glyphs of a row of controls, and the
4343
+ * `<i>` that draws one at it.
4344
+ *
4345
+ * A module of its own, with no key and no CSS, so that a view
4346
+ * can take the size without taking the toolbar widget. In
4347
+ * 7.32.7 C_YUI_NAV imported it from yui_toolbar.js, and every
4348
+ * app that mounts a nav had to define the keys of the toolbar's
4349
+ * scroll arrows ("scroll left", "scroll right"), which
4350
+ * validate-locales reads in every module the app imports.
4351
+ * yui_toolbar.js exports the two names too, as before.
4352
+ *
4353
+ * Copyright (c) 2026, ArtGins.
4354
+ * All Rights Reserved.
4355
+ ***********************************************************************/
4356
+ /************************************************************
4357
+ * ONE size for every glyph of a view's toolbar, in `rem`.
4358
+ *
4359
+ * It lives here because it belongs to the TOOLBAR and not to
4360
+ * any one view: it was born in the graph rows (7.23.86) and the
4361
+ * JSON viewer beside them still drew 16px, which is the same
4362
+ * drift one level up.
4363
+ *
4364
+ * `rem` and not `em` is the whole lesson: `em` is measured
4365
+ * against the button, so one declaration draws three icons --
4366
+ * `1.5em` is 24px in a plain button, 18px in an `is-small`
4367
+ * chip, and a labelled button that declares nothing keeps the
4368
+ * inherited 16px. `rem` is measured against the page, so a
4369
+ * chip deliberately shorter than a button still carries the
4370
+ * same glyph.
4371
+ *
4372
+ * 20px against a row's 16px text: an icon-only button is
4373
+ * legible at half its 40px height, and beside a label the
4374
+ * glyph reads as a marker rather than as a second word. The
4375
+ * app BAR is a different band and keeps its own, bigger size
4376
+ * (`.yui-toolbar-item .icon`, 1.35rem on 44px items).
4377
+ *
4378
+ * It is also the size of the glyphs of the TABS and of the
4379
+ * MENU entries (C_YUI_NAV, the topic tabs of
4380
+ * C_YUI_TREEDB_TOPICS), and of the paginator of a table on a
4381
+ * phone (tabulator.css). Up to 7.32.6 a tab took the 16px of
4382
+ * its text, and right under a toolbar its icons read as
4383
+ * smaller than the toolbar's. The rows of a tab or a menu
4384
+ * entry are 24px of line, so the glyph changes no height.
4385
+ ************************************************************/
4386
+ var YUI_TOOLBAR_ICON_SIZE = "1.25rem";
4387
+ function yui_toolbar_icon(icon_class, extra_style) {
4388
+ return ["i", {
4389
+ class: icon_class,
4390
+ "aria-hidden": "true",
4391
+ style: `font-size:${YUI_TOOLBAR_ICON_SIZE}; line-height:1; color:inherit;` + (extra_style || "")
4392
+ }];
4393
+ }
4338
4394
  // src/shell_modals.js
4339
4395
  /***********************************************************************
4340
4396
  * shell_modals.js
@@ -4577,7 +4633,7 @@ function yui_shell_show_modal(shell, content, opts) {
4577
4633
  "aria-label": t("back"),
4578
4634
  "data-i18n-aria-label": "back"
4579
4635
  },
4580
- [["i", { class: "yi-arrow-left" }]]
4636
+ [yui_toolbar_icon("yi-arrow-left")]
4581
4637
  ],
4582
4638
  [
4583
4639
  "span",
@@ -4594,7 +4650,7 @@ function yui_shell_show_modal(shell, content, opts) {
4594
4650
  "aria-label": t("close"),
4595
4651
  "data-i18n-aria-label": "close"
4596
4652
  },
4597
- [["i", { class: "yi-xmark" }]]
4653
+ [yui_toolbar_icon("yi-xmark")]
4598
4654
  ]
4599
4655
  ]
4600
4656
  ], [
@@ -5189,7 +5245,7 @@ function ensure_window_style() {
5189
5245
  .yui-window-titlebar-controls { display: flex; align-items: center; gap: 2px; padding-left: 6px; }
5190
5246
  .yui-window-title { white-space: nowrap; }
5191
5247
  .yui-window-title .icon { flex: 0 0 auto; }
5192
- .yui-window-title svg { width: 14px; height: 14px; display: block; }
5248
+ .yui-window-title svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
5193
5249
  /* Separator between the data half and the translated kind half. CSS,
5194
5250
  * not a text node: createElement2 trims text nodes and eats the spaces.
5195
5251
  * Decorative ("/ ''"): the halves NAME the window, and a reader read
@@ -5207,7 +5263,7 @@ function ensure_window_style() {
5207
5263
  }
5208
5264
  .yui-wc:hover { background: var(--bulma-scheme-main-ter); color: var(--bulma-text-strong); }
5209
5265
  .yui-wc.wc-close:hover { background: #e0364a; color: #fff; }
5210
- .yui-wc svg { width: 15px; height: 15px; display: block; }
5266
+ .yui-wc svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
5211
5267
  .yui-window-resize { color: var(--bulma-text-weak); opacity: 0.55; }
5212
5268
  .yui-window-resize:hover { opacity: 1; color: var(--bulma-text); }
5213
5269
  /* A modal window over its backdrop: the backdrop of a Bulma .modal,
@@ -5222,7 +5278,6 @@ function ensure_window_style() {
5222
5278
  .C_YUI_WINDOW.is-mobile-sheet .yui-window-resize { display: none !important; }
5223
5279
  .yui-wc { width: 42px; height: 38px; }
5224
5280
  .yui-wc.wc-max { display: none !important; }
5225
- .yui-wc svg { width: 18px; height: 18px; }
5226
5281
  }
5227
5282
  `;
5228
5283
  let $style = document.createElement("style");
@@ -5275,7 +5330,7 @@ function build_title_node(gobj, id, hidden) {
5275
5330
  else items.push([
5276
5331
  "span",
5277
5332
  { class: "icon" },
5278
- [["i", { class: icon }]]
5333
+ [yui_toolbar_icon(icon)]
5279
5334
  ]);
5280
5335
  }
5281
5336
  if (!empty_string(prefix)) items.push([
@@ -16552,62 +16607,6 @@ function create_gclass$15(gclass_name) {
16552
16607
  function register_c_yui_uplot() {
16553
16608
  return create_gclass$15(GCLASS_NAME$15);
16554
16609
  }
16555
- // src/yui_toolbar_icon.js
16556
- /***********************************************************************
16557
- * yui_toolbar_icon.js
16558
- *
16559
- * The one size of the glyphs of a row of controls, and the
16560
- * `<i>` that draws one at it.
16561
- *
16562
- * A module of its own, with no key and no CSS, so that a view
16563
- * can take the size without taking the toolbar widget. In
16564
- * 7.32.7 C_YUI_NAV imported it from yui_toolbar.js, and every
16565
- * app that mounts a nav had to define the keys of the toolbar's
16566
- * scroll arrows ("scroll left", "scroll right"), which
16567
- * validate-locales reads in every module the app imports.
16568
- * yui_toolbar.js exports the two names too, as before.
16569
- *
16570
- * Copyright (c) 2026, ArtGins.
16571
- * All Rights Reserved.
16572
- ***********************************************************************/
16573
- /************************************************************
16574
- * ONE size for every glyph of a view's toolbar, in `rem`.
16575
- *
16576
- * It lives here because it belongs to the TOOLBAR and not to
16577
- * any one view: it was born in the graph rows (7.23.86) and the
16578
- * JSON viewer beside them still drew 16px, which is the same
16579
- * drift one level up.
16580
- *
16581
- * `rem` and not `em` is the whole lesson: `em` is measured
16582
- * against the button, so one declaration draws three icons --
16583
- * `1.5em` is 24px in a plain button, 18px in an `is-small`
16584
- * chip, and a labelled button that declares nothing keeps the
16585
- * inherited 16px. `rem` is measured against the page, so a
16586
- * chip deliberately shorter than a button still carries the
16587
- * same glyph.
16588
- *
16589
- * 20px against a row's 16px text: an icon-only button is
16590
- * legible at half its 40px height, and beside a label the
16591
- * glyph reads as a marker rather than as a second word. The
16592
- * app BAR is a different band and keeps its own, bigger size
16593
- * (`.yui-toolbar-item .icon`, 1.35rem on 44px items).
16594
- *
16595
- * It is also the size of the glyphs of the TABS and of the
16596
- * MENU entries (C_YUI_NAV, the topic tabs of
16597
- * C_YUI_TREEDB_TOPICS), and of the paginator of a table on a
16598
- * phone (tabulator.css). Up to 7.32.6 a tab took the 16px of
16599
- * its text, and right under a toolbar its icons read as
16600
- * smaller than the toolbar's. The rows of a tab or a menu
16601
- * entry are 24px of line, so the glyph changes no height.
16602
- ************************************************************/
16603
- var YUI_TOOLBAR_ICON_SIZE = "1.25rem";
16604
- function yui_toolbar_icon(icon_class, extra_style) {
16605
- return ["i", {
16606
- class: icon_class,
16607
- "aria-hidden": "true",
16608
- style: `font-size:${YUI_TOOLBAR_ICON_SIZE}; line-height:1; color:inherit;` + (extra_style || "")
16609
- }];
16610
- }
16611
16610
  // src/yui_toolbar.js
16612
16611
  function yui_toolbar(attrs = {}, items = []) {
16613
16612
  function arrow_button(side, icon, label) {
@@ -46706,6 +46705,8 @@ function build_ui$12(gobj) {
46706
46705
  priv.$search_ctl = $container.querySelector(".JSON_SEARCH_CONTROL");
46707
46706
  priv.$expand_btn = $container.querySelector(".EV_EXPAND_ALL");
46708
46707
  priv.$collapse_btn = $container.querySelector(".EV_COLLAPSE_ALL");
46708
+ priv.$collapse_level_btn = $container.querySelector(".EV_COLLAPSE_LEVEL");
46709
+ priv.$expand_level_btn = $container.querySelector(".EV_EXPAND_LEVEL");
46709
46710
  priv.$graph = $container.querySelector(".JSON_GRAPH");
46710
46711
  priv.$mode_btns = /* @__PURE__ */ new Map();
46711
46712
  VIEWS$1.forEach(function(v) {
@@ -46732,6 +46733,8 @@ function destroy_ui$7(gobj) {
46732
46733
  priv.$search_ctl = null;
46733
46734
  priv.$expand_btn = null;
46734
46735
  priv.$collapse_btn = null;
46736
+ priv.$collapse_level_btn = null;
46737
+ priv.$expand_level_btn = null;
46735
46738
  priv.$mode_btns = null;
46736
46739
  }
46737
46740
  /************************************************************
@@ -46779,7 +46782,7 @@ function make_toolbar$4(gobj) {
46779
46782
  [yui_toolbar_icon("yi-magnifying-glass")]
46780
46783
  ]]
46781
46784
  ]);
46782
- left_items.push(icon_button$1(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"), icon_button$1(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"));
46785
+ left_items.push(icon_button$1(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"), icon_button$1(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"), icon_button$1(gobj, "yi-square-minus", "EV_COLLAPSE_LEVEL", "collapse one level"), icon_button$1(gobj, "yi-square-plus", "EV_EXPAND_LEVEL", "expand one level"));
46783
46786
  attach_clear($search_control, $search_input);
46784
46787
  left_items.push($search_control);
46785
46788
  let right_items = [view_mode_switch$1(gobj), icon_button$1(gobj, "yi-copy", "EV_COPY_ALL", "copy json")];
@@ -46937,7 +46940,9 @@ function apply_view_mode$1(gobj) {
46937
46940
  [
46938
46941
  priv.$search_ctl,
46939
46942
  priv.$expand_btn,
46940
- priv.$collapse_btn
46943
+ priv.$collapse_btn,
46944
+ priv.$collapse_level_btn,
46945
+ priv.$expand_level_btn
46941
46946
  ].forEach(function($el) {
46942
46947
  if ($el) $el.classList.toggle("is-hidden", mode !== "tree");
46943
46948
  });
@@ -47408,6 +47413,70 @@ function collect_loaded_paths(value, segments, out) {
47408
47413
  });
47409
47414
  }
47410
47415
  }
47416
+ /************************************************************
47417
+ * The entries of a container, as [key, value] pairs: the keys
47418
+ * of an object, the indexes of an array (as strings, the way
47419
+ * a path spells them). None for anything else.
47420
+ ************************************************************/
47421
+ function entries_of(value) {
47422
+ let type = json_type(value);
47423
+ if (type === "object") return Object.entries(value);
47424
+ if (type === "array") return value.map((v, i) => [String(i), v]);
47425
+ return [];
47426
+ }
47427
+ /************************************************************
47428
+ * Is it a container the tree can open in place: an object or
47429
+ * an array that is loaded (not a `__collapsed__` sentinel,
47430
+ * which opens through the backend).
47431
+ ************************************************************/
47432
+ function is_open_able(value) {
47433
+ if (is_collapsed(value)) return false;
47434
+ let type = json_type(value);
47435
+ return type === "object" || type === "array";
47436
+ }
47437
+ /************************************************************
47438
+ * The shallowest level that has a loaded container still
47439
+ * closed, -1 when every loaded container is open. A level is
47440
+ * the depth of a row: 0 for an entry of the root.
47441
+ ************************************************************/
47442
+ function first_closed_level(priv, value, segments) {
47443
+ let level = -1;
47444
+ for (let [k, v] of entries_of(value)) {
47445
+ if (!is_open_able(v)) continue;
47446
+ let child = segments.concat(k);
47447
+ let found = priv.expanded.has(seg_join(child)) ? first_closed_level(priv, v, child) : child.length - 1;
47448
+ if (found >= 0 && (level < 0 || found < level)) level = found;
47449
+ }
47450
+ return level;
47451
+ }
47452
+ /************************************************************
47453
+ * The deepest level with a container open in sight (all its
47454
+ * parents open too), -1 when none is. Only what the reader
47455
+ * sees counts: an open container under a closed one is not
47456
+ * on screen, and folding it would change nothing they see.
47457
+ ************************************************************/
47458
+ function deepest_open_level(priv, value, segments) {
47459
+ let level = -1;
47460
+ for (let [k, v] of entries_of(value)) {
47461
+ if (!is_open_able(v)) continue;
47462
+ let child = segments.concat(k);
47463
+ if (!priv.expanded.has(seg_join(child))) continue;
47464
+ level = Math.max(level, child.length - 1, deepest_open_level(priv, v, child));
47465
+ }
47466
+ return level;
47467
+ }
47468
+ /************************************************************
47469
+ * Open every loaded container of the levels up to `level`.
47470
+ ************************************************************/
47471
+ function open_levels_up_to(priv, value, segments, level) {
47472
+ for (let [k, v] of entries_of(value)) {
47473
+ if (!is_open_able(v)) continue;
47474
+ let child = segments.concat(k);
47475
+ if (child.length - 1 > level) continue;
47476
+ priv.expanded.add(seg_join(child));
47477
+ open_levels_up_to(priv, v, child, level);
47478
+ }
47479
+ }
47411
47480
  /***************************
47412
47481
  * Actions
47413
47482
  ***************************/
@@ -47532,6 +47601,36 @@ function ac_collapse_all$1(gobj, event, kw, src) {
47532
47601
  return 0;
47533
47602
  }
47534
47603
  /************************************************************
47604
+ * EV_EXPAND_LEVEL — open the next level: every loaded
47605
+ * container of the shallowest level that still has one closed.
47606
+ * The levels above it are all open already, so the tree shows
47607
+ * one level more. A `__collapsed__` sentinel is not opened: it
47608
+ * asks the backend, as with "expand loaded".
47609
+ ************************************************************/
47610
+ function ac_expand_level(gobj, event, kw, src) {
47611
+ let priv = gobj.priv;
47612
+ if (priv.root === null || priv.root === void 0) return 0;
47613
+ let level = first_closed_level(priv, priv.root, []);
47614
+ if (level < 0) return 0;
47615
+ open_levels_up_to(priv, priv.root, [], level);
47616
+ render_view$1(gobj);
47617
+ return 0;
47618
+ }
47619
+ /************************************************************
47620
+ * EV_COLLAPSE_LEVEL — fold the deepest level open in sight:
47621
+ * every container open at that level or under it is closed,
47622
+ * so the tree shows one level less.
47623
+ ************************************************************/
47624
+ function ac_collapse_level(gobj, event, kw, src) {
47625
+ let priv = gobj.priv;
47626
+ if (priv.root === null || priv.root === void 0) return 0;
47627
+ let level = deepest_open_level(priv, priv.root, []);
47628
+ if (level < 0) return 0;
47629
+ for (let path of Array.from(priv.expanded)) if (seg_split(path).length - 1 >= level) priv.expanded.delete(path);
47630
+ render_view$1(gobj);
47631
+ return 0;
47632
+ }
47633
+ /************************************************************
47535
47634
  * EV_COPY_ALL — copy the working document to the clipboard
47536
47635
  ************************************************************/
47537
47636
  function ac_copy_all$1(gobj, event, kw, src) {
@@ -47725,6 +47824,16 @@ function create_gclass$13(gclass_name) {
47725
47824
  ac_collapse_all$1,
47726
47825
  null
47727
47826
  ],
47827
+ [
47828
+ "EV_EXPAND_LEVEL",
47829
+ ac_expand_level,
47830
+ null
47831
+ ],
47832
+ [
47833
+ "EV_COLLAPSE_LEVEL",
47834
+ ac_collapse_level,
47835
+ null
47836
+ ],
47728
47837
  [
47729
47838
  "EV_COPY_ALL",
47730
47839
  ac_copy_all$1,
@@ -47765,6 +47874,8 @@ function create_gclass$13(gclass_name) {
47765
47874
  ["EV_SEARCH", 0],
47766
47875
  ["EV_EXPAND_ALL", 0],
47767
47876
  ["EV_COLLAPSE_ALL", 0],
47877
+ ["EV_EXPAND_LEVEL", 0],
47878
+ ["EV_COLLAPSE_LEVEL", 0],
47768
47879
  ["EV_COPY_ALL", 0],
47769
47880
  ["EV_SET_VIEW_MODE", 0],
47770
47881
  ["EV_JSON_ITEM_CLICKED", 0],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.32.8",
3
+ "version": "7.32.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
package/src/c_yui_json.js CHANGED
@@ -355,6 +355,8 @@ function build_ui(gobj)
355
355
  priv.$search_ctl = $container.querySelector('.JSON_SEARCH_CONTROL');
356
356
  priv.$expand_btn = $container.querySelector('.EV_EXPAND_ALL');
357
357
  priv.$collapse_btn = $container.querySelector('.EV_COLLAPSE_ALL');
358
+ priv.$collapse_level_btn = $container.querySelector('.EV_COLLAPSE_LEVEL');
359
+ priv.$expand_level_btn = $container.querySelector('.EV_EXPAND_LEVEL');
358
360
  priv.$graph = $container.querySelector('.JSON_GRAPH');
359
361
  priv.$mode_btns = new Map();
360
362
  VIEWS.forEach(function(v) {
@@ -388,6 +390,8 @@ function destroy_ui(gobj)
388
390
  priv.$search_ctl = null;
389
391
  priv.$expand_btn = null;
390
392
  priv.$collapse_btn = null;
393
+ priv.$collapse_level_btn = null;
394
+ priv.$expand_level_btn = null;
391
395
  priv.$mode_btns = null;
392
396
  }
393
397
 
@@ -438,7 +442,13 @@ function make_toolbar(gobj)
438
442
  * per-row toggles live in the rows. */
439
443
  left_items.push(
440
444
  icon_button(gobj, "yi-angles-down", "EV_EXPAND_ALL", "expand loaded"),
441
- icon_button(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all")
445
+ icon_button(gobj, "yi-angles-up", "EV_COLLAPSE_ALL", "collapse all"),
446
+ /* The level stepper, beside the pair that does it all at once:
447
+ * `-` folds the deepest level open, `+` opens the next one. The
448
+ * tree boxes of the icon rule (one LEVEL of the whole tree), in
449
+ * the order of the treedb graph's stepper. */
450
+ icon_button(gobj, "yi-square-minus", "EV_COLLAPSE_LEVEL", "collapse one level"),
451
+ icon_button(gobj, "yi-square-plus", "EV_EXPAND_LEVEL", "expand one level")
442
452
  );
443
453
 
444
454
  attach_clear($search_control, $search_input);
@@ -592,7 +602,8 @@ function apply_view_mode(gobj)
592
602
  * worse than an absent one. A <pre> is searched with the browser's
593
603
  * own Ctrl+F, and the graph carries its own controls.
594
604
  */
595
- [priv.$search_ctl, priv.$expand_btn, priv.$collapse_btn].forEach(function($el) {
605
+ [priv.$search_ctl, priv.$expand_btn, priv.$collapse_btn,
606
+ priv.$collapse_level_btn, priv.$expand_level_btn].forEach(function($el) {
596
607
  if($el) {
597
608
  $el.classList.toggle('is-hidden', mode !== "tree");
598
609
  }
@@ -1095,6 +1106,100 @@ function collect_loaded_paths(value, segments, out)
1095
1106
  }
1096
1107
  }
1097
1108
 
1109
+ /************************************************************
1110
+ * The entries of a container, as [key, value] pairs: the keys
1111
+ * of an object, the indexes of an array (as strings, the way
1112
+ * a path spells them). None for anything else.
1113
+ ************************************************************/
1114
+ function entries_of(value)
1115
+ {
1116
+ let type = json_type(value);
1117
+ if(type === "object") {
1118
+ return Object.entries(value);
1119
+ }
1120
+ if(type === "array") {
1121
+ return value.map((v, i) => [String(i), v]);
1122
+ }
1123
+ return [];
1124
+ }
1125
+
1126
+ /************************************************************
1127
+ * Is it a container the tree can open in place: an object or
1128
+ * an array that is loaded (not a `__collapsed__` sentinel,
1129
+ * which opens through the backend).
1130
+ ************************************************************/
1131
+ function is_open_able(value)
1132
+ {
1133
+ if(is_collapsed(value)) {
1134
+ return false;
1135
+ }
1136
+ let type = json_type(value);
1137
+ return type === "object" || type === "array";
1138
+ }
1139
+
1140
+ /************************************************************
1141
+ * The shallowest level that has a loaded container still
1142
+ * closed, -1 when every loaded container is open. A level is
1143
+ * the depth of a row: 0 for an entry of the root.
1144
+ ************************************************************/
1145
+ function first_closed_level(priv, value, segments)
1146
+ {
1147
+ let level = -1;
1148
+ for(let [k, v] of entries_of(value)) {
1149
+ if(!is_open_able(v)) {
1150
+ continue;
1151
+ }
1152
+ let child = segments.concat(k);
1153
+ let found = priv.expanded.has(seg_join(child)) ?
1154
+ first_closed_level(priv, v, child) :
1155
+ child.length - 1;
1156
+ if(found >= 0 && (level < 0 || found < level)) {
1157
+ level = found;
1158
+ }
1159
+ }
1160
+ return level;
1161
+ }
1162
+
1163
+ /************************************************************
1164
+ * The deepest level with a container open in sight (all its
1165
+ * parents open too), -1 when none is. Only what the reader
1166
+ * sees counts: an open container under a closed one is not
1167
+ * on screen, and folding it would change nothing they see.
1168
+ ************************************************************/
1169
+ function deepest_open_level(priv, value, segments)
1170
+ {
1171
+ let level = -1;
1172
+ for(let [k, v] of entries_of(value)) {
1173
+ if(!is_open_able(v)) {
1174
+ continue;
1175
+ }
1176
+ let child = segments.concat(k);
1177
+ if(!priv.expanded.has(seg_join(child))) {
1178
+ continue;
1179
+ }
1180
+ level = Math.max(level, child.length - 1, deepest_open_level(priv, v, child));
1181
+ }
1182
+ return level;
1183
+ }
1184
+
1185
+ /************************************************************
1186
+ * Open every loaded container of the levels up to `level`.
1187
+ ************************************************************/
1188
+ function open_levels_up_to(priv, value, segments, level)
1189
+ {
1190
+ for(let [k, v] of entries_of(value)) {
1191
+ if(!is_open_able(v)) {
1192
+ continue;
1193
+ }
1194
+ let child = segments.concat(k);
1195
+ if(child.length - 1 > level) {
1196
+ continue;
1197
+ }
1198
+ priv.expanded.add(seg_join(child));
1199
+ open_levels_up_to(priv, v, child, level);
1200
+ }
1201
+ }
1202
+
1098
1203
 
1099
1204
 
1100
1205
 
@@ -1274,6 +1379,52 @@ function ac_collapse_all(gobj, event, kw, src)
1274
1379
  return 0;
1275
1380
  }
1276
1381
 
1382
+ /************************************************************
1383
+ * EV_EXPAND_LEVEL — open the next level: every loaded
1384
+ * container of the shallowest level that still has one closed.
1385
+ * The levels above it are all open already, so the tree shows
1386
+ * one level more. A `__collapsed__` sentinel is not opened: it
1387
+ * asks the backend, as with "expand loaded".
1388
+ ************************************************************/
1389
+ function ac_expand_level(gobj, event, kw, src)
1390
+ {
1391
+ let priv = gobj.priv;
1392
+ if(priv.root === null || priv.root === undefined) {
1393
+ return 0;
1394
+ }
1395
+ let level = first_closed_level(priv, priv.root, []);
1396
+ if(level < 0) {
1397
+ return 0; /* every loaded container is open: nothing to step */
1398
+ }
1399
+ open_levels_up_to(priv, priv.root, [], level);
1400
+ render_view(gobj);
1401
+ return 0;
1402
+ }
1403
+
1404
+ /************************************************************
1405
+ * EV_COLLAPSE_LEVEL — fold the deepest level open in sight:
1406
+ * every container open at that level or under it is closed,
1407
+ * so the tree shows one level less.
1408
+ ************************************************************/
1409
+ function ac_collapse_level(gobj, event, kw, src)
1410
+ {
1411
+ let priv = gobj.priv;
1412
+ if(priv.root === null || priv.root === undefined) {
1413
+ return 0;
1414
+ }
1415
+ let level = deepest_open_level(priv, priv.root, []);
1416
+ if(level < 0) {
1417
+ return 0; /* nothing open: nothing to step */
1418
+ }
1419
+ for(let path of Array.from(priv.expanded)) {
1420
+ if(seg_split(path).length - 1 >= level) {
1421
+ priv.expanded.delete(path);
1422
+ }
1423
+ }
1424
+ render_view(gobj);
1425
+ return 0;
1426
+ }
1427
+
1277
1428
  /************************************************************
1278
1429
  * EV_COPY_ALL — copy the working document to the clipboard
1279
1430
  ************************************************************/
@@ -1468,6 +1619,8 @@ function create_gclass(gclass_name)
1468
1619
  ["EV_SEARCH", ac_search, null],
1469
1620
  ["EV_EXPAND_ALL", ac_expand_all, null],
1470
1621
  ["EV_COLLAPSE_ALL", ac_collapse_all, null],
1622
+ ["EV_EXPAND_LEVEL", ac_expand_level, null],
1623
+ ["EV_COLLAPSE_LEVEL", ac_collapse_level, null],
1471
1624
  ["EV_COPY_ALL", ac_copy_all, null],
1472
1625
  ["EV_SET_VIEW_MODE", ac_set_view_mode, null],
1473
1626
  ["EV_LANGUAGE_CHANGED", ac_language_changed, null],
@@ -1489,6 +1642,8 @@ function create_gclass(gclass_name)
1489
1642
  ["EV_SEARCH", 0],
1490
1643
  ["EV_EXPAND_ALL", 0],
1491
1644
  ["EV_COLLAPSE_ALL", 0],
1645
+ ["EV_EXPAND_LEVEL", 0],
1646
+ ["EV_COLLAPSE_LEVEL", 0],
1492
1647
  ["EV_COPY_ALL", 0],
1493
1648
  ["EV_SET_VIEW_MODE", 0],
1494
1649
  ["EV_JSON_ITEM_CLICKED", 0],
@@ -90,6 +90,7 @@ import {escape_is_taken} from "./escape_taken.js";
90
90
 
91
91
  import "./c_yui_window.css";
92
92
  import {text_node} from "./yui_text.js";
93
+ import {yui_toolbar_icon, YUI_TOOLBAR_ICON_SIZE} from "./yui_toolbar_icon.js";
93
94
 
94
95
  /***************************************************************
95
96
  * Constants
@@ -99,7 +100,13 @@ const GCLASS_NAME = "C_YUI_WINDOW";
99
100
  /* Window-control glyphs as inline SVG (currentColor → theme-aware,
100
101
  * pixel-consistent). There is no minimize/restore glyph in the
101
102
  * yui_icons.css mask set, and chrome affordances read better as
102
- * crisp SVG than as content icons. */
103
+ * crisp SVG than as content icons.
104
+ *
105
+ * Each one is drawn in a box of YUI_TOOLBAR_ICON_SIZE, the size of
106
+ * the glyphs of the toolbar right under the title bar (7.32.9). Up to
107
+ * 7.32.8 the box was 15px, and the drawn marks were 7.5px (close),
108
+ * 8.8px (maximize) and 9.4px (minimize) next to toolbar icons of
109
+ * 20px. In a 20px box they are 10, 11.75 and 12.5px. */
103
110
  const WC_MIN = '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="3" y="11" width="10" height="1.6" rx="0.8" fill="currentColor"/></svg>';
104
111
  const WC_MAX = '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="3.3" y="3.3" width="9.4" height="9.4" rx="1.6" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>';
105
112
  const WC_RESTORE = '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="5.2" y="3" width="7.8" height="7.8" rx="1.3" fill="none" stroke="currentColor" stroke-width="1.4"/><rect x="3" y="5.2" width="7.8" height="7.8" rx="1.3" fill="var(--bulma-scheme-main)" stroke="currentColor" stroke-width="1.4"/></svg>';
@@ -420,7 +427,7 @@ function ensure_window_style()
420
427
  .yui-window-titlebar-controls { display: flex; align-items: center; gap: 2px; padding-left: 6px; }
421
428
  .yui-window-title { white-space: nowrap; }
422
429
  .yui-window-title .icon { flex: 0 0 auto; }
423
- .yui-window-title svg { width: 14px; height: 14px; display: block; }
430
+ .yui-window-title svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
424
431
  /* Separator between the data half and the translated kind half. CSS,
425
432
  * not a text node: createElement2 trims text nodes and eats the spaces.
426
433
  * Decorative ("/ ''"): the halves NAME the window, and a reader read
@@ -438,7 +445,7 @@ function ensure_window_style()
438
445
  }
439
446
  .yui-wc:hover { background: var(--bulma-scheme-main-ter); color: var(--bulma-text-strong); }
440
447
  .yui-wc.wc-close:hover { background: #e0364a; color: #fff; }
441
- .yui-wc svg { width: 15px; height: 15px; display: block; }
448
+ .yui-wc svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE}; display: block; }
442
449
  .yui-window-resize { color: var(--bulma-text-weak); opacity: 0.55; }
443
450
  .yui-window-resize:hover { opacity: 1; color: var(--bulma-text); }
444
451
  /* A modal window over its backdrop: the backdrop of a Bulma .modal,
@@ -453,7 +460,6 @@ function ensure_window_style()
453
460
  .C_YUI_WINDOW.is-mobile-sheet .yui-window-resize { display: none !important; }
454
461
  .yui-wc { width: 42px; height: 38px; }
455
462
  .yui-wc.wc-max { display: none !important; }
456
- .yui-wc svg { width: 18px; height: 18px; }
457
463
  }
458
464
  `;
459
465
  let $style = document.createElement('style');
@@ -507,7 +513,9 @@ function build_title_node(gobj, id, hidden)
507
513
  /* The `icon` attr is the app's own: inline svg is markup. */
508
514
  items.push(['span', {class: 'icon'}, html_markup(icon)]);
509
515
  } else {
510
- items.push(['span', {class: 'icon'}, [['i', {class: icon}]]]);
516
+ /* The size of the glyphs of a row of controls, as a tab:
517
+ * up to 7.32.8 it took the 16px of the title. */
518
+ items.push(['span', {class: 'icon'}, [yui_toolbar_icon(icon)]]);
511
519
  }
512
520
  }
513
521
  if(!empty_string(prefix)) {
@@ -0,0 +1,186 @@
1
+ /***********************************************************************
2
+ * json_level_stepper.wiring.test.js
3
+ *
4
+ * The tree of C_YUI_JSON opens and folds one LEVEL at a time
5
+ * (EV_EXPAND_LEVEL / EV_COLLAPSE_LEVEL), beside the pair that does
6
+ * it all at once (EV_EXPAND_ALL / EV_COLLAPSE_ALL):
7
+ *
8
+ * - `+` opens every loaded container of the shallowest level
9
+ * that still has one closed;
10
+ * - `-` folds the deepest level open in sight, and everything
11
+ * under it.
12
+ *
13
+ * Asked for on the json popup of a treedb cell: from a closed
14
+ * document, one press shows the fields of each entry with their
15
+ * own containers still closed.
16
+ *
17
+ * Driven through the real gclass on a document double.
18
+ *
19
+ * Copyright (c) 2026, ArtGins.
20
+ * All Rights Reserved.
21
+ ***********************************************************************/
22
+ import {test, expect, beforeAll, beforeEach} from "vitest";
23
+ import {install_dom_double} from "../test/dom_double.js";
24
+
25
+ install_dom_double();
26
+
27
+ if(!globalThis.ResizeObserver) {
28
+ globalThis.ResizeObserver = class {
29
+ observe() {
30
+ }
31
+ unobserve() {
32
+ }
33
+ disconnect() {
34
+ }
35
+ };
36
+ }
37
+
38
+ const {
39
+ SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
40
+ gobj_create_pure_child, gobj_start, gobj_read_attr, gobj_send_event,
41
+ set_log_callback,
42
+ } = await import("@yuneta/gobj-js");
43
+ const {register_c_yui_json} = await import("./c_yui_json.js");
44
+
45
+ const logged = [];
46
+ let yuno = null;
47
+ let seq = 0;
48
+
49
+ /* The shape of a template_settings cell: entries of fields, some of
50
+ * them containers in turn. */
51
+ const DOC = {
52
+ template_version: {type: "integer", default: 1, flag: ["persistent", "writable"]},
53
+ top_measures: {type: "array", default: ["temperature"], flag: ["persistent", "writable", "enum"]},
54
+ coordinates: {type: "dict", default: {geometry: {type: "Point", coordinates: [0, 0]}}},
55
+ note: "a leaf at the top",
56
+ };
57
+
58
+ beforeAll(async () => {
59
+ const i18next = (await import("i18next")).default;
60
+ await i18next.init({lng: "en", resources: {}});
61
+ gobj_start_up(null, null, null, null, null, null, null);
62
+ set_log_callback((level, msg) => {
63
+ logged.push({level: String(level), msg: String(msg)});
64
+ });
65
+ gclass_create("C_TEST_LEVEL_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
66
+ gclass_create(
67
+ "C_TEST_LEVEL_APP",
68
+ [["EV_EXPAND_PATH", 0]],
69
+ [["ST_IDLE", [["EV_EXPAND_PATH", () => 0, null]]]],
70
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
71
+ );
72
+ register_c_yui_json();
73
+ yuno = gobj_create_yuno("level_yuno", "C_TEST_LEVEL_HOST", {});
74
+ gobj_start(yuno);
75
+ });
76
+
77
+ beforeEach(() => {
78
+ logged.length = 0;
79
+ });
80
+
81
+ function new_viewer(doc)
82
+ {
83
+ const app = gobj_create_pure_child(`level_app_${++seq}`, "C_TEST_LEVEL_APP", {}, yuno);
84
+ gobj_start(app);
85
+ const viewer = gobj_create(`level_json_${seq}`, "C_YUI_JSON", {view_mode: "tree"}, app);
86
+ gobj_start(viewer);
87
+ gobj_send_event(viewer, "EV_SET_JSON", {json: doc}, app);
88
+ return viewer;
89
+ }
90
+
91
+ /* The keys of the container rows on screen that are open */
92
+ function open_keys(viewer)
93
+ {
94
+ const $c = gobj_read_attr(viewer, "$container");
95
+ return Array.from($c.querySelectorAll(".JSON_CONTAINER"))
96
+ .filter(($r) => $r.querySelector(".JSON_TOGGLE").classList.contains("is-open"))
97
+ .map(($r) => $r.querySelector(".JSON_KEY").textContent);
98
+ }
99
+
100
+ /* How many rows the tree shows */
101
+ function row_count(viewer)
102
+ {
103
+ return gobj_read_attr(viewer, "$container").querySelectorAll(".JSON_ROW").length;
104
+ }
105
+
106
+ function step(viewer, event)
107
+ {
108
+ gobj_send_event(viewer, event, {}, viewer);
109
+ }
110
+
111
+ function errors()
112
+ {
113
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
114
+ }
115
+
116
+ test("`+` opens one level at a time, `-` folds the deepest one", () => {
117
+ const v = new_viewer(DOC);
118
+ expect(open_keys(v)).toEqual([]);
119
+ expect(row_count(v)).toBe(4);
120
+
121
+ step(v, "EV_EXPAND_LEVEL");
122
+ expect(open_keys(v)).toEqual(["template_version", "top_measures", "coordinates"]);
123
+
124
+ step(v, "EV_EXPAND_LEVEL");
125
+ expect(open_keys(v)).toEqual(["template_version", "flag", "top_measures", "default", "flag",
126
+ "coordinates", "default"]);
127
+
128
+ step(v, "EV_EXPAND_LEVEL");
129
+ expect(open_keys(v)).toContain("geometry");
130
+
131
+ step(v, "EV_COLLAPSE_LEVEL");
132
+ expect(open_keys(v)).toEqual(["template_version", "flag", "top_measures", "default", "flag",
133
+ "coordinates", "default"]);
134
+
135
+ step(v, "EV_COLLAPSE_LEVEL");
136
+ step(v, "EV_COLLAPSE_LEVEL");
137
+ expect(open_keys(v)).toEqual([]);
138
+ expect(row_count(v)).toBe(4);
139
+ expect(errors()).toEqual([]);
140
+ });
141
+
142
+ test("`+` opens the shallowest level that still has a container closed", () => {
143
+ const v = new_viewer(DOC);
144
+ /* The reader opened one branch by hand, two levels deep. */
145
+ gobj_send_event(v, "EV_TOGGLE_NODE", {path: "coordinates"}, v);
146
+ expect(open_keys(v)).toEqual(["coordinates"]);
147
+
148
+ step(v, "EV_EXPAND_LEVEL");
149
+ expect(open_keys(v)).toEqual(["template_version", "top_measures", "coordinates"]);
150
+ });
151
+
152
+ test("`-` folds what is in sight, not a branch hidden under a closed one", () => {
153
+ const v = new_viewer(DOC);
154
+ step(v, "EV_EXPAND_LEVEL");
155
+ step(v, "EV_EXPAND_LEVEL");
156
+ /* Close `coordinates` by hand: its open `default` is out of sight. */
157
+ gobj_send_event(v, "EV_TOGGLE_NODE", {path: "coordinates"}, v);
158
+
159
+ step(v, "EV_COLLAPSE_LEVEL");
160
+ expect(open_keys(v)).toEqual(["template_version", "top_measures"]);
161
+ });
162
+
163
+ test("a step with nothing to step does nothing, and says no error", () => {
164
+ const v = new_viewer({a: 1, b: "x"});
165
+ step(v, "EV_EXPAND_LEVEL");
166
+ step(v, "EV_COLLAPSE_LEVEL");
167
+ expect(row_count(v)).toBe(2);
168
+ expect(errors()).toEqual([]);
169
+ });
170
+
171
+ test("the stepper is a tree control: it hides with the tree", () => {
172
+ const v = new_viewer(DOC);
173
+ const $c = gobj_read_attr(v, "$container");
174
+ const $minus = $c.querySelector(".EV_COLLAPSE_LEVEL");
175
+ const $plus = $c.querySelector(".EV_EXPAND_LEVEL");
176
+ expect($minus.querySelector("i.yi-square-minus")).not.toBe(null);
177
+ expect($plus.querySelector("i.yi-square-plus")).not.toBe(null);
178
+ expect($minus.getAttribute("aria-label")).toBe("collapse one level");
179
+ expect($plus.getAttribute("data-i18n-aria-label")).toBe("expand one level");
180
+
181
+ gobj_send_event(v, "EV_SET_VIEW_MODE", {mode: "text"}, v);
182
+ expect($minus.classList.contains("is-hidden")).toBe(true);
183
+ expect($plus.classList.contains("is-hidden")).toBe(true);
184
+ gobj_send_event(v, "EV_SET_VIEW_MODE", {mode: "tree"}, v);
185
+ expect($plus.classList.contains("is-hidden")).toBe(false);
186
+ });
@@ -48,6 +48,7 @@ import {
48
48
  yui_shell_overlay_dismissed,
49
49
  } from "./c_yui_shell.js";
50
50
  import {text_node} from "./yui_text.js";
51
+ import {yui_toolbar_icon} from "./yui_toolbar_icon.js";
51
52
 
52
53
 
53
54
  /***************************************************************
@@ -330,14 +331,18 @@ export function yui_shell_show_modal(shell, content, opts)
330
331
  let with_close = !(opts && opts.with_close_button === false);
331
332
  let modal_children;
332
333
  if(dialog) {
334
+ /* Its glyphs are the size of a toolbar's (yui_toolbar_icon):
335
+ * a dialog is the phone's face of a window, whose bar draws
336
+ * them so too (7.32.9). Up to 7.32.8 they took the 16px of
337
+ * the title. */
333
338
  let header = ["div", {class: "MODAL_HEADER yui-dialog-header"}, [
334
339
  ["button", {class: "MODAL_BACK yui-dialog-back", type: "button", title: t("back"), "data-i18n-title": "back",
335
340
  "aria-label": t("back"), "data-i18n-aria-label": "back"},
336
- [["i", {class: "yi-arrow-left"}]]],
341
+ [yui_toolbar_icon("yi-arrow-left")]],
337
342
  ["span", {class: "MODAL_TITLE yui-dialog-title"}, title_halves],
338
343
  ["button", {class: "MODAL_CLOSE yui-dialog-x", type: "button", title: t("close"), "data-i18n-title": "close",
339
344
  "aria-label": t("close"), "data-i18n-aria-label": "close"},
340
- [["i", {class: "yi-xmark"}]]],
345
+ [yui_toolbar_icon("yi-xmark")]],
341
346
  ]];
342
347
  let body = ["div", {class: "MODAL_BODY yui-dialog-body"}, inner ? [inner] : []];
343
348
  modal_children = [
@@ -0,0 +1,84 @@
1
+ /***********************************************************************
2
+ * window_icon_size.wiring.test.js
3
+ *
4
+ * The glyphs of a window's title bar and of a dialog's header are
5
+ * the size of a toolbar's: YUI_TOOLBAR_ICON_SIZE (yui_toolbar_icon.js).
6
+ * A json cell of a treedb table opens in a C_YUI_WINDOW on a
7
+ * desktop and in a dialog of the shell on a phone, and a toolbar of
8
+ * 20px sits right under either header.
9
+ *
10
+ * Up to 7.32.8 the title icon took the 16px of the title, the
11
+ * minimize / maximize / close glyphs were drawn in a box of 15px
12
+ * (marks of 7.5 to 9.4px), and the back arrow and the close of a
13
+ * dialog took the 16px of its title.
14
+ *
15
+ * Driven through the real gclasses on a document double.
16
+ *
17
+ * Copyright (c) 2026, ArtGins.
18
+ * All Rights Reserved.
19
+ ***********************************************************************/
20
+ import {test, expect, beforeAll} from "vitest";
21
+ import {install_dom_double} from "../test/dom_double.js";
22
+
23
+ install_dom_double();
24
+
25
+ const {
26
+ SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
27
+ gobj_create_service, gobj_start, gobj_read_attr,
28
+ } = await import("@yuneta/gobj-js");
29
+ const {register_c_yui_window} = await import("./c_yui_window.js");
30
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
31
+ const {yui_shell_show_modal} = await import("./shell_modals.js");
32
+ const {YUI_TOOLBAR_ICON_SIZE} = await import("./yui_toolbar_icon.js");
33
+
34
+ let yuno = null;
35
+ let shell = null;
36
+
37
+ beforeAll(async () => {
38
+ const i18next = (await import("i18next")).default;
39
+ await i18next.init({lng: "en", resources: {}});
40
+ gobj_start_up(null, null, null, null, null, null, null);
41
+ gclass_create("C_TEST_WIN_ICON_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
42
+ register_c_yui_window();
43
+ register_c_yui_shell();
44
+ yuno = gobj_create_yuno("win_icon_yuno", "C_TEST_WIN_ICON_HOST", {});
45
+ gobj_start(yuno);
46
+ shell = gobj_create("win_icon_shell", "C_YUI_SHELL",
47
+ {config: {shell: {}}, default_route: "/home"}, yuno);
48
+ gobj_start(shell);
49
+ });
50
+
51
+ /* The font size a glyph carries in its own style */
52
+ function size_of($i)
53
+ {
54
+ const m = /font-size:\s*([^;]+)/.exec(($i && $i.style.cssText) || "");
55
+ return m ? m[1].trim() : "";
56
+ }
57
+
58
+ test("the icon of a window's title is the size of a toolbar's", () => {
59
+ const w = gobj_create_service("win_icon_w", "C_YUI_WINDOW",
60
+ {title: "keys", title_prefix: "raw_events", icon: "yi-code",
61
+ body: ["div", {}, "w"]}, yuno);
62
+ gobj_start(w);
63
+ const $w = gobj_read_attr(w, "$container");
64
+ const $i = $w.querySelector(".WINDOW_TITLE .icon i.yi-code");
65
+ expect(size_of($i)).toBe(YUI_TOOLBAR_ICON_SIZE);
66
+ expect($i.getAttribute("aria-hidden")).toBe("true");
67
+ });
68
+
69
+ test("the glyphs of minimize, maximize and close are drawn in a box of that size", () => {
70
+ const css = document.getElementById("yui-window-style").textContent;
71
+ expect(css).toContain(`.yui-wc svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE};`);
72
+ expect(css).toContain(`.yui-window-title svg { width: ${YUI_TOOLBAR_ICON_SIZE}; height: ${YUI_TOOLBAR_ICON_SIZE};`);
73
+ /* One size on a phone too: the buttons grow there, not the glyphs. */
74
+ expect(css).not.toMatch(/\.yui-wc svg \{ width: \d+px/);
75
+ });
76
+
77
+ test("the back arrow and the close of a dialog are the size of a toolbar's", () => {
78
+ const handle = yui_shell_show_modal(shell, document.createElement("div"),
79
+ {dialog: true, title: "keys", logical_class: "ICON_SIZE_SHEET"});
80
+ const $modal = document.querySelector(".ICON_SIZE_SHEET");
81
+ expect(size_of($modal.querySelector(".MODAL_BACK i.yi-arrow-left"))).toBe(YUI_TOOLBAR_ICON_SIZE);
82
+ expect(size_of($modal.querySelector(".MODAL_CLOSE i.yi-xmark"))).toBe(YUI_TOOLBAR_ICON_SIZE);
83
+ handle.close();
84
+ });