@yuneta/gobj-ui 7.32.9 → 7.32.11

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
@@ -370,6 +370,73 @@ validate and before publishing a release.
370
370
 
371
371
  ## Components
372
372
 
373
+ ### Preferences — `C_YUI_PREFERENCES` and `yui_preferences_setup`
374
+
375
+ Every app has a Preferences page at `/preferences`, and it shows at least
376
+ three rows in one box headed "Appearance" (7.32.11+):
377
+
378
+ | row | options | kept by |
379
+ |---|---|---|
380
+ | Theme | light theme, dark theme | the app (`set_theme`) |
381
+ | Language | the app's languages, each in its own words | the app (`set_language`) |
382
+ | Navigation | stacked strips, back to parent, breadcrumb | the shell (`yui_shell_set_nav_mode`) |
383
+
384
+ The app says once, at start up, how it reads and changes its theme and its
385
+ language, and which boxes it adds under the three rows:
386
+
387
+ ```js
388
+ import {yui_preferences_setup} from "@yuneta/gobj-ui/src/yui_preferences.js";
389
+
390
+ yui_preferences_setup({
391
+ current_theme: current_theme, // () => "light" | "dark"
392
+ set_theme: (v) => app_set_theme(v),
393
+ languages: [{value: "en", text: "English"}, {value: "es", text: "Español"}],
394
+ current_language: current_locale,
395
+ set_language: switch_locale, // the app's i18next
396
+ sections: (gobj) => [], // optional: boxes of the app
397
+ });
398
+ ```
399
+
400
+ Then the page is a route of the app config, with no menu entry (the account
401
+ menu navigates to it). It is a page and not a dialog, so it is linkable and
402
+ survives an F5:
403
+
404
+ ```json
405
+ "routes": {
406
+ "/preferences": {"stage": "main", "gclass": "C_YUI_PREFERENCES",
407
+ "lifecycle": "lazy_destroy"}
408
+ }
409
+ ```
410
+
411
+ Register the gclass with the others (`register_c_yui_preferences()`). The
412
+ navigation needs nothing from the app: every `C_YUI_NODE` tree with no mode
413
+ of its own follows it, and an app with no tree keeps the choice for the day
414
+ it has one.
415
+
416
+ An app whose page has fields with actions of its own (a font size, a buffer)
417
+ keeps its own view and draws the same rows with the parts:
418
+ `yui_pref_header()`, `yui_pref_box(fields)`, `yui_pref_field(label_key,
419
+ control)`, `yui_pref_segment(gobj, event, options, current)` and
420
+ `yui_pref_appearance_fields(gobj)`. Its FSM declares `EV_SET_THEME`,
421
+ `EV_SET_LANGUAGE` and `EV_SET_NAV_MODE` (`{value}`), and each action calls
422
+ `yui_pref_apply(gobj, event, kw)` and draws the page again:
423
+
424
+ ```js
425
+ function ac_set_preference(gobj, event, kw, src)
426
+ {
427
+ let ret = yui_pref_apply(gobj, event, kw);
428
+ render(gobj); // which option is marked is markup
429
+ return ret;
430
+ }
431
+ ```
432
+
433
+ A language is shown and named in its own words, with its `lang`: a reader
434
+ finds their language in the language they read, and an app of ten languages
435
+ needs no key per language name. The keys the page needs are `preferences`,
436
+ `appearance`, `theme`, `language`, `navigation`, `light theme`, `dark theme`,
437
+ `stacked strips`, `back to parent` and `breadcrumb`. `validate-locales` asks
438
+ for them in every app that imports the page.
439
+
373
440
  ### Site map — `yui_shell_show_route_map`
374
441
 
375
442
  Every declarative-shell app can render its WHOLE navigation surface —
@@ -503,6 +570,14 @@ seen*:
503
570
  | `"back"` | only the tip's parent, as a `← parent` | `chrome: {"layout":"backbar"}` everywhere + `chrome_depth: 1` |
504
571
  | `"path"` | the trail as ONE line | `path: {"layout":"breadcrumb"}` on the root + `chrome_depth: 0` |
505
572
 
573
+ **A root with no `nav_mode` of its own follows the reader's choice for the
574
+ whole app** (7.32.11+): `yui_shell_nav_mode(shell)`, the Navigation row of
575
+ the Preferences page, kept in this browser. When the reader changes it,
576
+ `yui_shell_set_nav_mode(shell, mode)` publishes `EV_NAV_MODE_CHANGED`, and
577
+ every root that follows it draws its path again. A root that declares
578
+ `"nav_mode"`, or is given one with `yui_node_set_nav_mode(root, "path")`,
579
+ keeps it. `yui_node_set_nav_mode(root, "")` makes it follow again.
580
+
506
581
  It belongs to the **root** (`yui_node_set_nav_mode(root, "path")`, or
507
582
  `"nav_mode"` in its declaration) and the whole tree reads it from there —
508
583
  ancestors stacking strips while a descendant drew a breadcrumb would be
@@ -919,8 +994,25 @@ Two layout facts the browser taught this component, both worth keeping:
919
994
  (`7.21.0` forwarded it and broke exactly that way); a host that wants node
920
995
  clicks mounts `C_YUI_JSON_GRAPH` itself.
921
996
  - 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.
997
+ `EV_EXPAND_ALL`, `EV_COLLAPSE_ALL`, `EV_EXPAND_LEVEL`, `EV_COLLAPSE_LEVEL`,
998
+ `EV_COPY_ALL`. Every kw carries only a `path` string — never a DOM node or
999
+ gobj.
1000
+ - The tree folds by level too (7.32.10+). Beside "expand loaded" and
1001
+ "collapse all", a stepper of two buttons works on one level of the whole
1002
+ tree, with the tree-box icons of the icon rule (`yi-square-minus`,
1003
+ `yi-square-plus`). A level is the depth of a row: 0 for an entry of the
1004
+ root.
1005
+ - `EV_EXPAND_LEVEL` (`+`) opens every loaded container of the shallowest
1006
+ level that still has one closed. From a closed document, one press shows
1007
+ the fields of each entry, with their own containers closed.
1008
+ - `EV_COLLAPSE_LEVEL` (`-`) closes every container at the deepest level
1009
+ open in sight, and every container under it.
1010
+ - A `__collapsed__` sentinel is not opened by `+`: it opens through the
1011
+ backend, as with "expand loaded".
1012
+
1013
+ The keys are `expand one level` and `collapse one level`, the same as the
1014
+ stepper of the treedb graph. An app that mounts the viewer defines them in
1015
+ every locale. The stepper hides with the tree, like the search box.
924
1016
  - i18n keys the switch needs: `tree view`, `text view`, `graph view`,
925
1017
  `text truncated; collapse some branches`. All spelled out inside `t()` in
926
1018
  `view_label()` — never `t(VIEWS[i].key)`, which no `validate-locales` can