@yuneta/gobj-ui 7.26.41 → 7.26.43

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.
Files changed (66) hide show
  1. package/README.md +510 -78
  2. package/dist/gobj-ui.cjs.js +1120 -326
  3. package/dist/gobj-ui.es.js +1120 -326
  4. package/package.json +1 -1
  5. package/scripts/validate-locales.mjs +971 -177
  6. package/src/c_g6_nodes_tree.js +3 -2
  7. package/src/c_yui_form.js +261 -154
  8. package/src/c_yui_fsm_graph.js +3 -2
  9. package/src/c_yui_gobj_tree_js.js +3 -2
  10. package/src/c_yui_json_graph.js +3 -2
  11. package/src/c_yui_nav.js +43 -28
  12. package/src/c_yui_node.js +51 -7
  13. package/src/c_yui_schema_editor.css +16 -0
  14. package/src/c_yui_schema_editor.js +110 -20
  15. package/src/c_yui_shell.css +4 -1
  16. package/src/c_yui_shell.js +227 -61
  17. package/src/c_yui_treedb_schema.js +3 -2
  18. package/src/c_yui_window.js +373 -62
  19. package/src/c_yui_window_manager.js +80 -8
  20. package/src/escape_taken.js +58 -0
  21. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  22. package/src/form_json_editor_names.js +3 -1
  23. package/src/form_json_editor_names.wiring.test.js +8 -4
  24. package/src/form_json_expand.wiring.test.js +6 -3
  25. package/src/form_json_field.wiring.test.js +8 -4
  26. package/src/form_label_i18n.wiring.test.js +10 -5
  27. package/src/form_table_edits_ask.wiring.test.js +18 -8
  28. package/src/form_table_rearm.wiring.test.js +13 -5
  29. package/src/form_table_rows.wiring.test.js +489 -0
  30. package/src/form_table_validator.wiring.test.js +8 -4
  31. package/src/form_template_field.wiring.test.js +6 -3
  32. package/src/g6_canvas_tab_order.css +29 -0
  33. package/src/g6_canvas_tab_order.js +41 -9
  34. package/src/g6_canvas_tab_order.wiring.test.js +107 -1
  35. package/src/g6_long_press_clock.test.js +8 -3
  36. package/src/i18n_key_functions.js +81 -27
  37. package/src/i18n_key_functions.test.js +402 -4
  38. package/src/modal_guard_back.wiring.test.js +188 -0
  39. package/src/named_controls.wiring.test.js +323 -19
  40. package/src/nav_cards_helpers.js +9 -4
  41. package/src/nav_item_badge.wiring.test.js +163 -15
  42. package/src/node_nav_events.wiring.test.js +93 -1
  43. package/src/route_map_model.js +59 -10
  44. package/src/route_map_model.test.js +90 -0
  45. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  46. package/src/schema_editor_openers.wiring.test.js +283 -0
  47. package/src/shell_dialog_names.wiring.test.js +149 -0
  48. package/src/shell_escape_taken.wiring.test.js +142 -0
  49. package/src/shell_focus_trap.js +30 -2
  50. package/src/shell_focus_trap.test.js +90 -6
  51. package/src/shell_modals.js +113 -22
  52. package/src/shell_route_map.js +15 -3
  53. package/src/shell_section_index.js +3 -1
  54. package/src/table_editor_name.wiring.test.js +10 -5
  55. package/src/treedb_column_title.wiring.test.js +8 -4
  56. package/src/treedb_graph_writes.wiring.test.js +6 -3
  57. package/src/treedb_json_drill.wiring.test.js +6 -3
  58. package/src/uplot_add_serie.test.js +6 -3
  59. package/src/uplot_ink.test.js +8 -4
  60. package/src/window_dialog.wiring.test.js +486 -0
  61. package/src/window_dock_band.wiring.test.js +189 -0
  62. package/src/window_layer.wiring.test.js +114 -0
  63. package/src/window_rect_rounding.wiring.test.js +121 -0
  64. package/src/yui_gclass_view.js +16 -1
  65. package/src/yui_tabulator_i18n.js +31 -1
  66. package/src/yui_tabulator_i18n.test.js +46 -0
@@ -24,7 +24,7 @@ const {
24
24
  SDATA, SDATA_END, data_type_t, gclass_create, gobj_write_attr,
25
25
  gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop,
26
26
  gobj_destroy, gobj_is_running, gobj_read_attr, gobj_send_event,
27
- set_log_callback,
27
+ gobj_has_event, gobj_posted_events_size, set_log_callback,
28
28
  } = await import("@yuneta/gobj-js");
29
29
  const {
30
30
  register_c_yui_shell,
@@ -241,6 +241,36 @@ function said(shell)
241
241
  return root(shell).querySelector(".SHELL_BADGE_STATUS").textContent;
242
242
  }
243
243
 
244
+ /* What the live region holds, one entry per change it says: a line
245
+ * each (an element child), or the bare text up to 7.26.41. */
246
+ function said_lines(shell)
247
+ {
248
+ const $status = root(shell).querySelector(".SHELL_BADGE_STATUS");
249
+ if($status.children.length > 0) {
250
+ return Array.from($status.children).map(($line) => $line.textContent);
251
+ }
252
+ return $status.textContent ? [$status.textContent] : [];
253
+ }
254
+
255
+ /* The turn of the loop is over: what was posted in it is delivered
256
+ * (gobj_post_event() drains on setTimeout(0), queued before this). */
257
+ function next_turn()
258
+ {
259
+ return new Promise((resolve) => setTimeout(resolve, 0));
260
+ }
261
+
262
+ /* Every write of the region's content, as the texts it held after it. */
263
+ function spy_writes($status)
264
+ {
265
+ const writes = [];
266
+ const real = $status.replaceChildren;
267
+ $status.replaceChildren = function(...nodes) {
268
+ real.apply(this, nodes);
269
+ writes.push(Array.from(this.children).map(($line) => $line.textContent));
270
+ };
271
+ return writes;
272
+ }
273
+
244
274
 
245
275
  describe("a badge declared in app_config.json", () => {
246
276
  test("renders: after the label in the rail, on the icon in the icon bar", () => {
@@ -684,22 +714,11 @@ describe("a reader gets the count with the name of what it counts", () => {
684
714
  /* "home" has no badge: its first count is a change from nothing */
685
715
  yui_shell_set_nav_item_badge(shell, "home", 1);
686
716
  expect(said(shell)).toBe("Home, 1");
717
+ await next_turn();
687
718
 
688
- const writes = [];
689
- const $status = root(shell).querySelector(".SHELL_BADGE_STATUS");
690
- const real = Object.getOwnPropertyDescriptor(Object.getPrototypeOf($status), "textContent");
691
- Object.defineProperty($status, "textContent", {
692
- get() {
693
- return real.get.call(this);
694
- },
695
- set(v) {
696
- writes.push(v);
697
- real.set.call(this, v);
698
- },
699
- configurable: true
700
- });
719
+ const writes = spy_writes(root(shell).querySelector(".SHELL_BADGE_STATUS"));
701
720
  yui_shell_set_nav_item_badge(shell, "alarms", 3);
702
- expect(writes).toEqual(["Alarms, 3"]);
721
+ expect(writes).toEqual([["Alarms, 3"]]);
703
722
  });
704
723
 
705
724
  test("the same count is no news, a count going away is not either, one coming back is", async () => {
@@ -714,15 +733,21 @@ describe("a reader gets the count with the name of what it counts", () => {
714
733
  yui_shell_set_nav_item_badge(shell, "alarms", 2);
715
734
  expect(said(shell)).toBe("");
716
735
 
736
+ /* Each change in a turn of its own, as a feed of counts sends
737
+ * them: what one turn said stays in the region until the next
738
+ * change is said. */
717
739
  yui_shell_set_nav_item_badge(shell, "alarms", 3);
718
740
  expect(said(shell)).toBe("Alarms, 3");
719
741
  const node = $status.firstChild;
742
+ await next_turn();
720
743
 
721
744
  yui_shell_set_nav_item_badge(shell, "alarms", 3, "danger"); // only the tone
722
745
  expect($status.firstChild).toBe(node);
746
+ await next_turn();
723
747
 
724
748
  yui_shell_set_nav_item_badge(shell, "alarms", 0);
725
749
  expect($status.firstChild).toBe(node); // not said
750
+ await next_turn();
726
751
 
727
752
  yui_shell_set_nav_item_badge(shell, "alarms", 3);
728
753
  expect(said(shell)).toBe("Alarms, 3");
@@ -743,3 +768,126 @@ describe("a reader gets the count with the name of what it counts", () => {
743
768
  expect(errors()).toEqual([]);
744
769
  });
745
770
  });
771
+
772
+ describe("REV-CLOUD V24.5.3: every change is said, as it reads", () => {
773
+ async function english(extra)
774
+ {
775
+ const i18next = (await import("i18next")).default;
776
+ i18next.addResourceBundle("en", "translation", Object.assign(
777
+ {"{{name}}, {{n}}": "{{name}}, {{n}}", "alarms": "Alarms", "home": "Home"},
778
+ extra || {}), true, true);
779
+ return i18next.getFixedT("en");
780
+ }
781
+
782
+ /* The test-app's "alerts" button does exactly this: the toolbar
783
+ * count and a menu entry's, in the same action. Up to 7.26.41 the
784
+ * second overwrote the first in the region before a reader could
785
+ * hear it, so the control pressed was never said. */
786
+ test("two changes in one turn: both said, in ONE message, a line each", async () => {
787
+ const shell = new_shell();
788
+ yui_shell_set_translator(shell, await english());
789
+
790
+ yui_shell_set_toolbar_item_badge(shell, "bell", 7);
791
+ yui_shell_set_nav_item_badge(shell, "home", 1);
792
+ expect(said_lines(shell)).toEqual(["Alarms, 7", "Home, 1"]);
793
+
794
+ /* The next turn starts a message of its own: what the last one
795
+ * said is not said again. */
796
+ await next_turn();
797
+ yui_shell_set_nav_item_badge(shell, "home", 2);
798
+ expect(said_lines(shell)).toEqual(["Home, 2"]);
799
+ expect(errors()).toEqual([]);
800
+ });
801
+
802
+ test("the same badge twice in one turn says its last count", async () => {
803
+ const shell = new_shell();
804
+ yui_shell_set_translator(shell, await english());
805
+
806
+ yui_shell_set_nav_item_badge(shell, "alarms", 3);
807
+ yui_shell_set_toolbar_item_badge(shell, "bell", 6);
808
+ yui_shell_set_nav_item_badge(shell, "alarms", 5);
809
+ expect(said_lines(shell)).toEqual(["Alarms, 5", "Alarms, 6"]);
810
+ });
811
+
812
+ test("a count that goes away in the turn it came is not said: the badge shows nothing", async () => {
813
+ const shell = new_shell();
814
+ yui_shell_set_translator(shell, await english());
815
+
816
+ yui_shell_set_nav_item_badge(shell, "home", 4);
817
+ yui_shell_set_nav_item_badge(shell, "alarms", 3);
818
+ yui_shell_set_nav_item_badge(shell, "alarms", 0);
819
+ expect(said_lines(shell)).toEqual(["Home, 4"]);
820
+
821
+ yui_shell_set_nav_item_badge(shell, "home", 0);
822
+ expect(said_lines(shell)).toEqual([]);
823
+ });
824
+
825
+ test("one turn is closed once, though its message was emptied and opened again", async () => {
826
+ const shell = new_shell();
827
+ yui_shell_set_translator(shell, await english());
828
+
829
+ const before = gobj_posted_events_size();
830
+ yui_shell_set_nav_item_badge(shell, "alarms", 3);
831
+ yui_shell_set_nav_item_badge(shell, "alarms", 0); // the message is empty again
832
+ yui_shell_set_nav_item_badge(shell, "home", 1);
833
+ expect(gobj_posted_events_size() - before).toBe(1);
834
+ expect(said_lines(shell)).toEqual(["Home, 1"]);
835
+
836
+ await next_turn();
837
+ yui_shell_set_nav_item_badge(shell, "alarms", 4);
838
+ expect(said_lines(shell)).toEqual(["Alarms, 4"]);
839
+ expect(errors()).toEqual([]);
840
+ });
841
+
842
+ test("two controls of one name with one count: said once", async () => {
843
+ const shell = new_shell();
844
+ yui_shell_set_translator(shell, await english());
845
+
846
+ /* The bell is named "alarms" too */
847
+ yui_shell_set_toolbar_item_badge(shell, "bell", 9);
848
+ yui_shell_set_nav_item_badge(shell, "alarms", 9);
849
+ expect(said_lines(shell)).toEqual(["Alarms, 9"]);
850
+ });
851
+
852
+ /* i18next escapes an interpolated value for HTML by default, and
853
+ * the message goes to a text node: a reader would have read the
854
+ * entities. */
855
+ test("the message is text, not HTML: a name with an apostrophe or an ampersand reads as written", async () => {
856
+ const shell = new_shell();
857
+ yui_shell_set_translator(shell, await english({"alarms": "Événements d'alarme & co"}));
858
+
859
+ yui_shell_set_nav_item_badge(shell, "alarms", 3);
860
+ expect(said_lines(shell)).toEqual(["Événements d'alarme & co, 3"]);
861
+ });
862
+
863
+ test("the turn is closed through the machine, by an event of the shell", () => {
864
+ const shell = new_shell();
865
+ expect(gobj_has_event(shell, "EV_CLOSE_BADGE_NEWS")).toBe(true);
866
+ /* Nothing to close: a second message is not opened by it. */
867
+ gobj_send_event(shell, "EV_CLOSE_BADGE_NEWS", {}, shell);
868
+ expect(errors()).toEqual([]);
869
+ });
870
+
871
+ /* One rule names an item everywhere: the nav names a menu entry by
872
+ * its `name`, else its `aria_label`, else its id. Up to 7.26.41 the
873
+ * announcement took `name || id`, so an entry that declares only an
874
+ * `aria_label` was said by its id -- one name on the control,
875
+ * another in the region. */
876
+ test("an entry with no `name` is said by the name the nav gives it: its `aria_label`, else its id", async () => {
877
+ const cfg = config();
878
+ cfg.menu.primary.items.push(
879
+ {id: "x9", aria_label: "active alarms", icon: "yi-triangle-exclamation",
880
+ route: "/x9", target: view()},
881
+ {id: "events", icon: "yi-eye", route: "/events", target: view()}
882
+ );
883
+ const shell = new_shell(cfg);
884
+ yui_shell_set_translator(shell, await english({"active alarms": "Active alarms", "events": "Events"}));
885
+
886
+ const $a = zone(shell, "left").querySelector('a[data-item-id="x9"]');
887
+ expect($a.getAttribute("data-i18n-aria-label")).toBe("active alarms");
888
+ yui_shell_set_nav_item_badge(shell, "x9", 3);
889
+ yui_shell_set_nav_item_badge(shell, "events", 5);
890
+ expect(said_lines(shell)).toEqual(["Active alarms, 3", "Events, 5"]);
891
+ expect(errors()).toEqual([]);
892
+ });
893
+ });
@@ -12,6 +12,13 @@
12
12
  * of a root that is off the path landed on ST_OFF, which declared
13
13
  * none of the three.
14
14
  *
15
+ * And a click on the item a node is already showing navigates to the
16
+ * same route in the same turn (no hash change, so no hashchange):
17
+ * the node renders again INSIDE the nav's publication of
18
+ * EV_NAV_CLICKED, and the render destroyed that nav under it (the
19
+ * ERROR "Destroying a gobj while its tree is publishing" of
20
+ * gobj-js 7.26.22). The navs a render leaves go on the next turn.
21
+ *
15
22
  * Driven through the real gclasses (C_YUI_SHELL, C_YUI_NODE,
16
23
  * C_YUI_NAV) on a document double: each event is published by the
17
24
  * real nav the node created.
@@ -31,7 +38,8 @@ const {
31
38
  gobj_current_state, gobj_change_state,
32
39
  set_log_callback,
33
40
  } = await import("@yuneta/gobj-js");
34
- const {register_c_yui_shell} = await import("./c_yui_shell.js");
41
+ const {gobj_is_destroying} = await import("@yuneta/gobj-js");
42
+ const {register_c_yui_shell, yui_shell_navigate} = await import("./c_yui_shell.js");
35
43
  const {register_c_yui_nav} = await import("./c_yui_nav.js");
36
44
  const {register_c_yui_node} = await import("./c_yui_node.js");
37
45
 
@@ -148,3 +156,87 @@ describe("the events of a C_YUI_NAV reach its C_YUI_NODE", () => {
148
156
  expect(closed.map((c) => c.item_id)).toEqual(["b"]);
149
157
  });
150
158
  });
159
+
160
+ describe("the path a node draws is named by the node", () => {
161
+
162
+ /* A root that draws the PATH (`projection.path`), with or without a
163
+ * label, on the path to its child "a" */
164
+ function build_path(kw)
165
+ {
166
+ const name = `n${++seq}`;
167
+ const app = gobj_create(`${name}_app`, "C_TEST_APP", {}, yuno);
168
+ gobj_start(app);
169
+ const shell = gobj_create(`${name}_shell`, "C_YUI_SHELL",
170
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
171
+ gobj_start(shell);
172
+ const tree = gobj_create_pure_child(`${name}_tree`, "C_YUI_NODE", Object.assign({
173
+ node_id: "root",
174
+ base_route: "/tree",
175
+ projection: {index: {layout: "cards"}, path: {layout: "submenu"}},
176
+ children: [{id: "a", label: "A"}, {id: "b", label: "B"}]
177
+ }, kw), shell);
178
+ gobj_start(tree);
179
+ gobj_send_event(tree, "EV_ROUTE_CHANGED", {base: "/tree", subpath: "a"}, shell);
180
+ return tree.priv.navs.find((nav) => gobj_read_attr(nav, "menu_id").startsWith("node.path."));
181
+ }
182
+
183
+ /* A "submenu" heads the nav with its nav_label, else its menu_id, as a
184
+ * KEY: a node with no label read "node.path./tree" there (up to
185
+ * 7.26.42), a key no locale can hold, where every other nav of the
186
+ * node is named `label || node_id` */
187
+ test("by its label, else by its node_id -- never by the menu_id", () => {
188
+ const unlabelled = build_path({});
189
+ expect(unlabelled).toBeTruthy();
190
+ expect(gobj_read_attr(unlabelled, "nav_label")).toBe("root");
191
+ const labelled = build_path({label: "the tree"});
192
+ expect(gobj_read_attr(labelled, "nav_label")).toBe("the tree");
193
+ });
194
+ });
195
+
196
+ describe("the item a node is showing, clicked again", () => {
197
+
198
+ test("renders the node again; the nav that published the click goes on the next turn", async () => {
199
+ const name = `n${++seq}`;
200
+ const shell = gobj_create(`${name}_shell`, "C_YUI_SHELL", {
201
+ config: {
202
+ shell: {
203
+ zones: {center: {host: "stage.main"}},
204
+ stages: {main: {zone: "center", default_route: "/tree"}}
205
+ },
206
+ menu: {primary: {items: [
207
+ {id: "tree", name: "tree", route: "/tree", target: {
208
+ stage: "main", gclass: "C_YUI_NODE", lifecycle: "keep_alive",
209
+ name: `${name}_tree`,
210
+ kw: {
211
+ node_id: "root",
212
+ base_route: "/tree",
213
+ projection: {index: {layout: "tabs"}, chrome: {layout: "tabs"}},
214
+ children: [{id: "a", label: "A"}, {id: "b", label: "B"}]
215
+ }
216
+ }}
217
+ ]}}
218
+ },
219
+ use_hash: false
220
+ }, yuno);
221
+ gobj_start(shell);
222
+ yui_shell_navigate(shell, "/tree/a");
223
+ const tree = shell.priv.stages.main.items["/tree"];
224
+ expect(gobj_current_state(tree)).toBe("ST_CHILD");
225
+ const nav = tree.priv.navs[0];
226
+ expect(nav).toBeTruthy();
227
+ logged.length = 0;
228
+
229
+ /* What the nav's click handler does with the active item. */
230
+ gobj_publish_event(nav, "EV_NAV_CLICKED", {route: "/tree/a", item_id: "a"});
231
+
232
+ expect(gobj_is_destroying(nav)).toBe(false);
233
+ expect(tree.priv.navs.length).toBe(1);
234
+ expect(tree.priv.navs[0]).not.toBe(nav);
235
+ expect(gobj_read_attr(nav, "$container").parentNode).toBeFalsy();
236
+
237
+ await new Promise((resolve) => setTimeout(resolve, 0));
238
+ expect(gobj_is_destroying(nav)).toBe(true);
239
+ expect(gobj_is_destroying(tree.priv.navs[0])).toBe(false);
240
+ expect(errors()).toEqual([]);
241
+ });
242
+ });
@@ -18,13 +18,50 @@
18
18
  * All Rights Reserved.
19
19
  ***********************************************************************/
20
20
 
21
+ /************************************************************
22
+ * The label of a row is the name of its CONTROL: one rule names
23
+ * an item everywhere.
24
+ *
25
+ * - A menu entry, as the nav names it (c_yui_nav.js item_li):
26
+ * its `name`, else its `aria_label`, else its id.
27
+ * - A toolbar item and a row of its dropdown, as the toolbar
28
+ * names them (c_yui_shell.js build_toolbar_*): its
29
+ * `aria_label` first -- the visible `name` of a toolbar
30
+ * button is often a symbol ("ES/EN") --, then its `name`,
31
+ * then, for an avatar or a connection dot, the library's own
32
+ * key, else its id.
33
+ *
34
+ * A route is no key: it has its own column, and an item with
35
+ * none of these has no label. Up to 7.26.41 a row was labelled
36
+ * `name || wordmark || id || route` -- an entry that declares
37
+ * only an `aria_label` had its id here, the language button read
38
+ * "ES/EN" where its control says "toggle language", and a route
39
+ * was asked of the locales as a key.
40
+ ************************************************************/
41
+ function menu_item_label(it)
42
+ {
43
+ return it.name || it.aria_label || it.id || "";
44
+ }
45
+
46
+ function toolbar_item_label(it)
47
+ {
48
+ let fallback = it.id || "";
49
+ if(it.type === "avatar") {
50
+ fallback = "user menu";
51
+ } else if(it.type === "connection") {
52
+ fallback = "backend connection";
53
+ }
54
+ return it.aria_label || it.name || fallback;
55
+ }
56
+
21
57
  /************************************************************
22
58
  * One node of the nav map from a declared config item, in
23
59
  * DECLARATION ORDER (never sorted). Recurses into static submenus
24
60
  * and toolbar dropdowns, and merges the LIVE dynamic submenu tabs
25
61
  * (added at runtime via yui_shell_set_submenu) by parent id.
62
+ * `label_of` names it: menu_item_label() or toolbar_item_label().
26
63
  ************************************************************/
27
- function nav_node_from_item(it, index)
64
+ function nav_node_from_item(it, index, label_of)
28
65
  {
29
66
  if(!it || it.type === "divider" || it.type === "header") {
30
67
  return null;
@@ -45,7 +82,7 @@ function nav_node_from_item(it, index)
45
82
  }
46
83
  let node = {
47
84
  id: it.id || "",
48
- label: it.name || it.wordmark || it.id || route || "",
85
+ label: label_of(it),
49
86
  icon: it.icon || "",
50
87
  route: route,
51
88
  event: event,
@@ -62,7 +99,7 @@ function nav_node_from_item(it, index)
62
99
  action.items : null);
63
100
  if(sub_items) {
64
101
  for(let s of sub_items) {
65
- let n = nav_node_from_item(s, index);
102
+ let n = nav_node_from_item(s, index, label_of);
66
103
  if(n) {
67
104
  node.children.push(n);
68
105
  }
@@ -79,7 +116,8 @@ function nav_node_from_item(it, index)
79
116
  !node.children.some((c) => c.route === r)) {
80
117
  node.children.push({
81
118
  id: (e.item && e.item.id) || "",
82
- label: (e.item && e.item.name) || r,
119
+ /* A runtime tab is an entry of a nav */
120
+ label: e.item ? menu_item_label(e.item) : "",
83
121
  icon: (e.item && e.item.icon) || "",
84
122
  route: r,
85
123
  event: "",
@@ -231,7 +269,10 @@ function mark_current(groups, current_route)
231
269
  *
232
270
  * - `nav` walks EVERY declared menu in declaration order: the
233
271
  * `primary` menu contributes its items flat (the common case);
234
- * any other menu contributes a group node labelled by its key.
272
+ * any other menu contributes a group node labelled by its key,
273
+ * as data (`data_label: true`).
274
+ * - a node is labelled as its control is named (menu_item_label(),
275
+ * toolbar_item_label()); a node no item names has label "".
235
276
  * - `other` lists the routes declared only in the route table
236
277
  * (config.shell.routes) that no rendered node covers — root "/",
237
278
  * URL-only action routes, toolbar-less forms. Brand-covered
@@ -260,13 +301,16 @@ function build_nav_map(input)
260
301
  for(let it of tb) {
261
302
  if(it && it.type === "brand") {
262
303
  let a = it.action || {};
304
+ /* The ROOT of the map is the app, and the wordmark is its
305
+ * name -- not the brand BUTTON's `aria_label`, which says
306
+ * what pressing it does ("go to home"). */
263
307
  brand = {
264
308
  label: it.wordmark || it.alt || it.id || "",
265
309
  route: it.route || (a.type === "navigate" ? a.route : "") || ""
266
310
  };
267
311
  continue;
268
312
  }
269
- let n = nav_node_from_item(it, index);
313
+ let n = nav_node_from_item(it, index, toolbar_item_label);
270
314
  if(n) {
271
315
  toolbar.push(n);
272
316
  }
@@ -284,7 +328,7 @@ function build_nav_map(input)
284
328
  }
285
329
  let nodes = [];
286
330
  for(let it of m.items) {
287
- let n = nav_node_from_item(it, index);
331
+ let n = nav_node_from_item(it, index, menu_item_label);
288
332
  if(n) {
289
333
  nodes.push(n);
290
334
  }
@@ -292,9 +336,12 @@ function build_nav_map(input)
292
336
  if(menu_id === "primary") {
293
337
  nav = nav.concat(nodes);
294
338
  } else if(nodes.length) {
339
+ /* A menu declares no name: its id is what the map can show,
340
+ * and an id is DATA (`data_label`), drawn as it is and never
341
+ * asked of the locales -- as a route is not. */
295
342
  nav.push({
296
- id: menu_id, label: menu_id, icon: "", route: "", event: "",
297
- gclass: "", kind: "group", children: nodes
343
+ id: menu_id, label: menu_id, data_label: true, icon: "", route: "",
344
+ event: "", gclass: "", kind: "group", children: nodes
298
345
  });
299
346
  }
300
347
  }
@@ -336,7 +383,9 @@ function build_nav_map(input)
336
383
  let tgt = (e && e.target) || null;
337
384
  other.push({
338
385
  id: (e && e.item && e.item.id) || "",
339
- label: (e && e.item && (e.item.name || e.item.id)) || r,
386
+ /* A route is no key: one no item names has no label, and
387
+ * its route is in its own column. */
388
+ label: (e && e.item) ? menu_item_label(e.item) : "",
340
389
  icon: (e && e.item && e.item.icon) || "",
341
390
  route: r,
342
391
  event: (tgt && tgt.kind === "action" && tgt.event) || "",
@@ -277,3 +277,93 @@ test("'you are here' lands on the owner, never on a reference", () => {
277
277
  expect(map.nav.find((n) => n.route === "/cards").current).toBe(true);
278
278
  expect(map.toolbar[0].children[0].current).toBeUndefined();
279
279
  });
280
+
281
+
282
+ /***************************************************************
283
+ * one rule names an item everywhere (REV-CLOUD V24.5.4)
284
+ *
285
+ * A row of the map is labelled as its CONTROL is named: a menu
286
+ * entry as the nav names it (c_yui_nav.js: `name`, else
287
+ * `aria_label`, else id), a toolbar item and a row of its menu as
288
+ * the toolbar does (c_yui_shell.js: `aria_label` first). Up to
289
+ * 7.26.41 it was `name || wordmark || id || route`: an entry that
290
+ * declares only an `aria_label` had its id in the map, the lang
291
+ * button read "ES/EN" where its control says "toggle language",
292
+ * and a route -- which is no key -- was a label asked of the
293
+ * locales.
294
+ ***************************************************************/
295
+ describe("a row of the map is labelled as its control is named", () => {
296
+ function map_of(config, index)
297
+ {
298
+ return build_nav_map({config: config, item_index: index || {}});
299
+ }
300
+ const by_id = (nodes, id) => nodes.find((n) => n.id === id);
301
+
302
+ test("a menu entry: its `name`, else its `aria_label`, else its id -- never its route", () => {
303
+ const m = map_of({menu: {primary: {items: [
304
+ {id: "home", name: "home", aria_label: "go home", route: "/home"},
305
+ {id: "x9", aria_label: "active alarms", route: "/x9"},
306
+ {id: "events", route: "/events"},
307
+ {route: "/anonymous"},
308
+ ]}}});
309
+ expect(m.nav.map((n) => n.label)).toEqual(["home", "active alarms", "events", ""]);
310
+ expect(m.nav[3].route).toBe("/anonymous"); // the route has its own column
311
+ });
312
+
313
+ test("a submenu entry and a runtime tab: the same rule", () => {
314
+ const parent = {id: "devices", name: "devices", route: "/devices", submenu: {items: [
315
+ {id: "list", aria_label: "device list", route: "/devices/list"}
316
+ ]}};
317
+ const m = map_of({menu: {primary: {items: [parent]}}}, {
318
+ "/devices/tab1": {item: {id: "tab1", aria_label: "first device"},
319
+ parent_item: parent, target: {gclass: "C_DEV"}},
320
+ "/devices/tab2": {item: {id: "tab2"}, parent_item: parent, target: {gclass: "C_DEV"}}
321
+ });
322
+ expect(m.nav[0].children.map((n) => n.label))
323
+ .toEqual(["device list", "first device", "tab2"]);
324
+ });
325
+
326
+ test("a toolbar item and a row of its menu: as the toolbar names them, `aria_label` first", () => {
327
+ const m = map_of({toolbar: {items: [
328
+ {id: "lang", name: "ES/EN", aria_label: "toggle language",
329
+ action: {type: "event", event: "EV_LANG"}},
330
+ {id: "help", icon: "yi-circle-question", action: {type: "event", event: "EV_HELP"}},
331
+ {id: "user", type: "avatar", action: {type: "dropdown", items: [
332
+ {id: "logout", action: {type: "event", event: "EV_LOGOUT"}},
333
+ {id: "prefs", name: "preferences", action: {type: "event", event: "EV_PREFS"}}
334
+ ]}},
335
+ {id: "conn", type: "connection"}
336
+ ]}});
337
+ expect(m.toolbar.map((n) => n.label))
338
+ .toEqual(["toggle language", "help", "user menu", "backend connection"]);
339
+ expect(by_id(m.toolbar, "user").children.map((n) => n.label)).toEqual(["logout", "preferences"]);
340
+ });
341
+
342
+ test("a route of the route table no item points at: no label, its route in its column", () => {
343
+ const m = map_of({menu: {primary: {items: []}}}, {
344
+ "/hidden": {item: null, target: {gclass: "C_HIDDEN"}},
345
+ "/kept": {item: {id: "kept", aria_label: "kept route"}, target: {gclass: "C_KEPT"}}
346
+ });
347
+ expect(m.other.map((n) => [n.route, n.label]))
348
+ .toEqual([["/hidden", ""], ["/kept", "kept route"]]);
349
+ });
350
+
351
+ test("the brand, the ROOT of the map, keeps its wordmark: it names the app", () => {
352
+ const m = map_of({toolbar: {items: [
353
+ {type: "brand", id: "brand", wordmark: "demo", aria_label: "go to home",
354
+ action: {type: "navigate", route: "/"}}
355
+ ]}});
356
+ expect(m.brand.label).toBe("demo");
357
+ });
358
+
359
+ test("another menu is a group labelled by its id, as DATA: a menu declares no name", () => {
360
+ const m = map_of({menu: {
361
+ primary: {items: [{id: "a", name: "a", route: "/a"}]},
362
+ quick: {items: [{id: "b", name: "b", route: "/b"}]}
363
+ }});
364
+ const quick = by_id(m.nav, "quick");
365
+ expect(quick.kind).toBe("group");
366
+ expect(quick.label).toBe("quick");
367
+ expect(quick.data_label).toBe(true);
368
+ });
369
+ });