@yuneta/gobj-ui 7.32.10 → 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 +75 -0
- package/dist/gobj-ui.cjs.js +943 -358
- package/dist/gobj-ui.es.js +932 -359
- package/index.js +18 -0
- package/package.json +1 -1
- package/src/c_yui_node.js +47 -9
- package/src/c_yui_preferences.js +282 -0
- package/src/c_yui_shell.js +57 -1
- package/src/i18n_key_functions.js +6 -0
- package/src/preferences.wiring.test.js +159 -0
- package/src/yui_preferences.js +331 -0
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
|