@yuneta/gobj-ui 7.26.41 → 7.26.42
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 +304 -63
- package/dist/gobj-ui.cjs.js +352 -135
- package/dist/gobj-ui.es.js +352 -135
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +644 -142
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +61 -17
- package/src/c_yui_shell.js +199 -59
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window_manager.js +6 -6
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/i18n_key_functions.js +41 -25
- package/src/i18n_key_functions.test.js +178 -2
- package/src/modal_guard_back.wiring.test.js +135 -0
- package/src/named_controls.wiring.test.js +270 -6
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_modals.js +24 -4
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/window_layer.wiring.test.js +114 -0
- package/src/yui_gclass_view.js +16 -1
package/README.md
CHANGED
|
@@ -114,6 +114,20 @@ Published as `@yuneta/gobj-ui`. Built on top of [`@yuneta/gobj-js`](https://gith
|
|
|
114
114
|
> entry closed the invisible one. Its Back entry goes with the shell that held
|
|
115
115
|
> it: after a re-login Back no longer closes it, its ✕ does.
|
|
116
116
|
>
|
|
117
|
+
> **A gclass viewer goes where the window it was opened from goes.** Opened
|
|
118
|
+
> from a window that hangs where the shell puts every window -- its window
|
|
119
|
+
> layer, the body while there is none -- it takes that place as its opener
|
|
120
|
+
> does, and follows the shell with it. Up to 7.26.41 it was given that element
|
|
121
|
+
> by name, as a `$parent`, which is a choice of its host: opened from the
|
|
122
|
+
> developer window between a logout and the next login, it stayed in the body
|
|
123
|
+
> after the login, above the new shell's dialogs. Opened from a window its host
|
|
124
|
+
> placed elsewhere, it hangs beside that window, there for good, as before.
|
|
125
|
+
>
|
|
126
|
+
> **With two shells alive** (no app has two), destroying the LAST one gives its
|
|
127
|
+
> windows to the one that remains: `yui_shell_of()` falls back to the last
|
|
128
|
+
> shell still alive. Up to 7.26.41 the fallback went empty, and they went to
|
|
129
|
+
> the body, above the dialogs of the shell that remained.
|
|
130
|
+
>
|
|
117
131
|
> **The dock** (`C_YUI_WINDOW_MANAGER`, floating) lives in the shell's popup
|
|
118
132
|
> layer, at the top of it: above every window, below the dialogs and the
|
|
119
133
|
> toasts. It was `document.body` at z-index 1000000, above the whole shell --
|
|
@@ -131,7 +145,7 @@ consumers. They are independent snapshots (no shared git ancestry):
|
|
|
131
145
|
|
|
132
146
|
| Line | Branch | Latest tag | Layout | Consumed by | How | Status |
|
|
133
147
|
|------|--------|------------|--------|-------------|-----|--------|
|
|
134
|
-
| **v2** | `main` | `7.26.x` | `src/` subdir | **gui_agent**, **gui_treedb**, **wattyzer**, the **yunovatios** GUIs, **estadodelaire** (since 2026-10-13) | published npm `@yuneta/gobj-ui` (dist-tag `latest`) | active development |
|
|
148
|
+
| **v2** | `main` | `7.26.x` | `src/` subdir | **gui_agent**, **gui_treedb**, **wattyzer**, the **yunovatios** GUIs, **yunomusica**, **estadodelaire** (since 2026-10-13) | published npm `@yuneta/gobj-ui` (dist-tag `latest`) | active development |
|
|
135
149
|
| **v1** | `v1` | `1.0.4` | `src/` subdir | **hidraulia** | published npm `@yuneta/gobj-ui@^1.0.4` (dist-tag `legacy`) | frozen, maintenance-only |
|
|
136
150
|
|
|
137
151
|
- **v2 / `main`** is the active development line: the declarative shell
|
|
@@ -211,6 +225,19 @@ toggles it closed. The tree model is `yui_shell_nav_map()` /
|
|
|
211
225
|
protocols (`yui_shell_set_sub_routes`, `yui_shell_register_event_handler`)
|
|
212
226
|
live in [`ROUTING.md`](ROUTING.md).
|
|
213
227
|
|
|
228
|
+
**A row says the name its control says** -- one rule names an item
|
|
229
|
+
everywhere. A menu entry (a submenu entry, a runtime tab) is labelled as the
|
|
230
|
+
nav names it: its `name`, else its `aria_label`, else its id. A toolbar item
|
|
231
|
+
and a row of its dropdown as the toolbar names them: `aria_label` first, then
|
|
232
|
+
`name`, then the library's own key for an avatar (`user menu`) or a
|
|
233
|
+
connection dot (`backend connection`), else the id. All of them are KEYS, and
|
|
234
|
+
change language with the map. Two labels are not: the id of another menu (a
|
|
235
|
+
menu declares no name, so its group row shows its id as DATA) and a route (a
|
|
236
|
+
row that no item names has no label; its route is in its own column, and is
|
|
237
|
+
its link's name as data). The root row is the brand's `wordmark`: it names
|
|
238
|
+
the APP, where the brand button's `aria_label` says what pressing it does. Up
|
|
239
|
+
to `7.26.41` a row was labelled `name || wordmark || id || route`.
|
|
240
|
+
|
|
214
241
|
### C_YUI_NODE — navigation as a tree of gobjs (prototype)
|
|
215
242
|
|
|
216
243
|
`C_YUI_SHELL`'s menu tree is **two levels** (a primary item and its
|
|
@@ -1584,9 +1611,39 @@ the shared `keep_canvas_tab_order()` (`src/g6_canvas_tab_order.js`) right after
|
|
|
1584
1611
|
import {keep_canvas_tab_order} from "./g6_canvas_tab_order.js";
|
|
1585
1612
|
|
|
1586
1613
|
const graph = priv.graph = new Graph({container: priv.$container /* ... */});
|
|
1587
|
-
keep_canvas_tab_order(gobj, graph); // main canvas 0, the other layers -1
|
|
1614
|
+
keep_canvas_tab_order(gobj, graph, "treedb graph"); // main canvas 0, named; the other layers -1
|
|
1615
|
+
```
|
|
1616
|
+
|
|
1617
|
+
**The main canvas is a control, and it is NAMED** for the graph it draws: a
|
|
1618
|
+
`title` and an `aria-label` through `t()`, each with its key
|
|
1619
|
+
(`data-i18n-title`, `data-i18n-aria-label`), so a language switch reaches them
|
|
1620
|
+
as it reaches any control, and `role="region"` -- the role maplibre gives its
|
|
1621
|
+
own canvas, because ARIA forbids a name on an element with no role. Each view
|
|
1622
|
+
passes its key: `C_G6_NODES_TREE` **`treedb graph`**, `C_YUI_JSON_GRAPH`
|
|
1623
|
+
**`json graph`**, `C_YUI_GOBJ_TREE_JS` **`gobj tree graph`**,
|
|
1624
|
+
`C_YUI_FSM_GRAPH` **`fsm graph`**, `C_YUI_TREEDB_SCHEMA` **`schema graph`** --
|
|
1625
|
+
keys an app that mounts the view has in its locales. From `7.26.28` to
|
|
1626
|
+
`7.26.41` Tab landed on the canvas and a reader announced nothing.
|
|
1627
|
+
|
|
1628
|
+
**And the focused canvas can be SEEN.** G6 writes `outline: none` on its
|
|
1629
|
+
canvases, inline, so a keyboard that Tabbed onto the graph had no sign of
|
|
1630
|
+
where it was. The main canvas takes the logical class `G6_MAIN_CANVAS`, and
|
|
1631
|
+
`src/g6_canvas_tab_order.css` -- imported by the module, so it comes with every
|
|
1632
|
+
view -- draws the library's focus ring on it, `!important` because only that
|
|
1633
|
+
reaches an inline style:
|
|
1634
|
+
|
|
1635
|
+
```css
|
|
1636
|
+
.G6_MAIN_CANVAS:focus-visible {
|
|
1637
|
+
outline: 2px solid var(--bulma-link-on-scheme, var(--bulma-link, #485fc7)) !important;
|
|
1638
|
+
outline-offset: -2px !important;
|
|
1639
|
+
}
|
|
1588
1640
|
```
|
|
1589
1641
|
|
|
1642
|
+
`:focus-visible`, so a press of the pointer draws no ring (nor the focus a view
|
|
1643
|
+
gives the canvas on a press); the link colour as INK, legible on both schemes
|
|
1644
|
+
(see "Colour" below); inset, so a container that clips the graph does not clip
|
|
1645
|
+
the ring; no transition.
|
|
1646
|
+
|
|
1590
1647
|
The buttons of the graph are buttons for the keyboard too: the items of both
|
|
1591
1648
|
toolbars, the round buttons beside a selection — the gear and the trash of a
|
|
1592
1649
|
node or an edge, the link and the gear of a port — and the ✕ of a node's
|
|
@@ -2491,8 +2548,8 @@ What the screens offer:
|
|
|
2491
2548
|
|
|
2492
2549
|
| Screen | What it is for |
|
|
2493
2550
|
|--------|----------------|
|
|
2494
|
-
| treedbs | one card per treedb, with its topic count and its `schema_version` beside the `c_schema_version` it was projected from |
|
|
2495
|
-
| topics | the topics of one treedb in schema order: pkey, column count, version, system flag |
|
|
2551
|
+
| treedbs | one card per treedb, with its topic count and its `schema_version` beside the `c_schema_version` it was projected from. A card is a control: named by its treedb (a `title` and an `aria-label`), its counts its description, opened by a click, Enter or Space |
|
|
2552
|
+
| topics | the topics of one treedb in schema order: pkey, column count, version, system flag. A row is a row of the TABLE: the topic's name is the button that opens it (a key presses it), and a click anywhere in the row opens it too. Up to 7.26.41 the row was a `<tr role=button>` with no name, which a reader hears as a button with no cells |
|
|
2496
2553
|
| columns | the heart. Rows in `order`, **draggable** — `order` is a field, so a drop writes the rows whose place actually changed, two or three and not forty |
|
|
2497
2554
|
| diagram | the treedb **drawn from the records being edited**, through `C_YUI_TREEDB_SCHEMA` |
|
|
2498
2555
|
|
|
@@ -3263,9 +3320,32 @@ is not even in the tree. So:
|
|
|
3263
3320
|
`yui_shell_set_toolbar_item_badge()` say it when the text a reader would see
|
|
3264
3321
|
CHANGES and is not empty: the same count is no news, a count going away is
|
|
3265
3322
|
not either, one coming back is. A menu entry drawn by three navs is said
|
|
3266
|
-
once. The
|
|
3323
|
+
once. The name is the one its control says: a menu entry's `name`, else its
|
|
3324
|
+
`aria_label`, else its id (up to `7.26.41` an entry with only an
|
|
3325
|
+
`aria_label` was said by its id); a toolbar item's own key, `aria_label`
|
|
3326
|
+
first. The phrase is a key of its own, `"{{name}}, {{n}}"`, so a language
|
|
3267
3327
|
orders and punctuates it its way; it goes through the translator the app gave
|
|
3268
|
-
the shell (`yui_shell_set_translator`)
|
|
3328
|
+
the shell (`yui_shell_set_translator`), and it is TEXT: the name is not
|
|
3329
|
+
escaped for HTML (i18next escapes an interpolated value by default, and a
|
|
3330
|
+
name such as *"Événements d'alarme"* was read *"d'alarme"*).
|
|
3331
|
+
- **Every change of one turn of the loop is said, in ONE message**: a line of
|
|
3332
|
+
the region each (`.SHELL_BADGE_NEWS`), in the order they came. A reader
|
|
3333
|
+
hears the region as it stands when the turn is over, and up to `7.26.41`
|
|
3334
|
+
each change replaced its text -- so of two changes in one action only the
|
|
3335
|
+
second was ever said (the toolbar's count and a menu entry's, updated
|
|
3336
|
+
together by the same feed: exactly what the test-app's *alerts* button
|
|
3337
|
+
does). A badge that moves twice in the turn says its last count; one whose
|
|
3338
|
+
count goes away in the turn it came is not said at all (the badge shows
|
|
3339
|
+
nothing); two controls of one name with one count say it once. The next
|
|
3340
|
+
turn starts a message of its own: the shell posts itself
|
|
3341
|
+
`EV_CLOSE_BADGE_NEWS` on the first change of a turn, which closes it on the
|
|
3342
|
+
next one -- a deferral through the machine, not a time.
|
|
3343
|
+
|
|
3344
|
+
```js
|
|
3345
|
+
/* One action: both are said -- "Alerts, 3" and "Modals, 3" */
|
|
3346
|
+
yui_shell_set_toolbar_item_badge(shell, "alerts", 3);
|
|
3347
|
+
yui_shell_set_nav_item_badge(shell, "modals", 3);
|
|
3348
|
+
```
|
|
3269
3349
|
|
|
3270
3350
|
Up to `7.26.34` the badge was its own `role="status"`: it said *"3"* with no
|
|
3271
3351
|
word of what has three, it was `hidden` while empty -- so the first count was
|
|
@@ -3325,13 +3405,35 @@ keeps working afterwards. With no guard a modal closes exactly as it always
|
|
|
3325
3405
|
did, and the returned `close()` always closes **unconditionally** — the veto is
|
|
3326
3406
|
for the user's dismiss, not for the code's.
|
|
3327
3407
|
|
|
3328
|
-
**A guard that ASKS returns the question's promise** (7.26.38+). It
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3408
|
+
**A guard that ASKS returns the question's promise** (7.26.38+). It tells the
|
|
3409
|
+
modal when the question is over: a browser Back that asked gets its history
|
|
3410
|
+
entry back THEN, below nothing. Opening the question and returning `false` put
|
|
3411
|
+
the entry back at once, above the question's own -- so the next Back, the one
|
|
3412
|
+
meant for the question, reached the modal, which asked again, and on a phone
|
|
3413
|
+
(where Back is a gesture) every Back stacked one more question.
|
|
3414
|
+
|
|
3415
|
+
**What the promise SETTLES with is the answer.** `true` closes the modal, as a
|
|
3416
|
+
`true` returned at once does; anything else -- `false`, `undefined` (what a
|
|
3417
|
+
`.then()` that returns nothing settles with), a string, a rejection (logged as
|
|
3418
|
+
a warning) -- is the veto, and a Back that asked gets its entry back when it
|
|
3419
|
+
settles. A `true` that comes after the guard closed the modal itself closes
|
|
3420
|
+
nothing twice. Up to `7.26.41` any promise was a veto, so an `async` guard --
|
|
3421
|
+
which always answers a promise -- left a modal that nobody could close:
|
|
3422
|
+
|
|
3423
|
+
```js
|
|
3424
|
+
/* An async guard: true closes, false keeps it up */
|
|
3425
|
+
before_close: async () => {
|
|
3426
|
+
const kw = {};
|
|
3427
|
+
gobj_send_event(form, "EV_WINDOW_TO_CLOSE", kw, gobj);
|
|
3428
|
+
if(!kw.abort_close) {
|
|
3429
|
+
return true;
|
|
3430
|
+
}
|
|
3431
|
+
return yui_shell_confirm_yesno(shell, "all changes will be lost", {t}); // true on "yes"
|
|
3432
|
+
},
|
|
3433
|
+
```
|
|
3434
|
+
|
|
3435
|
+
The guard below closes the modal itself on "yes", through an event, and its
|
|
3436
|
+
`.then()` returns nothing: a veto in both cases, as before.
|
|
3335
3437
|
|
|
3336
3438
|
```js
|
|
3337
3439
|
const sheet = yui_shell_show_modal(shell, $body, {
|
|
@@ -4000,6 +4102,57 @@ declaration is a literal when it is the endonym of one of the app's locales
|
|
|
4000
4102
|
(the `name` its catalog exports: `"中文"`, `"español"`); any other lower-case
|
|
4001
4103
|
text is a key, `"configuración"` included.
|
|
4002
4104
|
|
|
4105
|
+
The keys of the shell declaration are the `name`, `aria_label` and `tooltip`
|
|
4106
|
+
of every item, the `label` of a node and the `title` / `subtitle` of a route
|
|
4107
|
+
-- and (since `7.26.42`) the `id` of an item or a node that the library NAMES
|
|
4108
|
+
by it, because the item has no `name` (a node, no `label`):
|
|
4109
|
+
|
|
4110
|
+
- a menu item (of `menu.<id>.items` or of a `submenu.items`) with neither a
|
|
4111
|
+
`name` nor an `aria_label`: `C_YUI_NAV` names it `name || aria_label || id`
|
|
4112
|
+
in every layout;
|
|
4113
|
+
- a menu item with no `name` in a breadcrumb that shows its labels (the text
|
|
4114
|
+
of the crumb is `name || id`), or that opens a section index (its landing is
|
|
4115
|
+
labelled `name || id`);
|
|
4116
|
+
- a toolbar item, the menu of a toolbar dropdown, or an entry of one, with
|
|
4117
|
+
neither an `aria_label` nor a `name`: the shell names them
|
|
4118
|
+
`aria_label || name || id` (an avatar's menu is the library's "user menu");
|
|
4119
|
+
- a row the SITE MAP draws, labelled as its control is named: the rows of the
|
|
4120
|
+
dropdown action of a menu entry with no submenu (`name || aria_label ||
|
|
4121
|
+
id`), and every row under a toolbar item that is not the brand, at every
|
|
4122
|
+
level, an entry with no `action` included (`aria_label || name || id`);
|
|
4123
|
+
- a node of a `C_YUI_NODE` tree with no `label`. The tree is declared as
|
|
4124
|
+
`{"gclass": "C_YUI_NODE", "kw": {...}}` (a menu item's `target`, a route's):
|
|
4125
|
+
its root is the `kw` (its id is `node_id`), and the nodes below it are the
|
|
4126
|
+
specs of `children` (`id`). The library names a node `label || id`, as a
|
|
4127
|
+
key: its item in the navs of its parent, the label of its own navs, its
|
|
4128
|
+
crumb in a path, its node in the site map. A root with no children and no
|
|
4129
|
+
path draws no label.
|
|
4130
|
+
|
|
4131
|
+
Up to `7.26.41` such a menu or toolbar item was named by its raw id, with no
|
|
4132
|
+
key, and the validator read the `label` of a node but not the id that stands
|
|
4133
|
+
in for a missing one. A decorative item (`"type": "header"` or `"divider"`)
|
|
4134
|
+
is named by none of this.
|
|
4135
|
+
|
|
4136
|
+
```json
|
|
4137
|
+
"items": [
|
|
4138
|
+
{"id": "alarms", "icon": "yi-bell", "route": "/alarms"},
|
|
4139
|
+
{"id": "search", "aria_label": "search the site", "icon": "yi-search", "route": "/search"}
|
|
4140
|
+
]
|
|
4141
|
+
```
|
|
4142
|
+
|
|
4143
|
+
The first item asks the locales for "alarms"; the second one for
|
|
4144
|
+
"search the site", and not for "search".
|
|
4145
|
+
|
|
4146
|
+
```json
|
|
4147
|
+
"target": {"gclass": "C_YUI_NODE", "kw": {"node_id": "admin", "base_route": "/admin", "children": [
|
|
4148
|
+
{"id": "accounts", "content": {"gclass": "C_ACCOUNTS"}},
|
|
4149
|
+
{"id": "db", "label": "database", "content": {"gclass": "C_DB_VIEW"}}
|
|
4150
|
+
]}}
|
|
4151
|
+
```
|
|
4152
|
+
|
|
4153
|
+
This tree asks for "admin" (a root with children and no `label`), for
|
|
4154
|
+
"accounts", and for "database" -- not for "db".
|
|
4155
|
+
|
|
4003
4156
|
**The source is PARSED, never run** (since `7.26.28`, with `acorn`, a
|
|
4004
4157
|
dependency of this package since `7.26.29`: an app need not declare it). A
|
|
4005
4158
|
LOCALE is not a source: it is parsed, and then imported, so its top-level code
|
|
@@ -4018,16 +4171,25 @@ call of t()?" (since `7.26.32`; up to `7.26.31` it was a call NAMED `t` or
|
|
|
4018
4171
|
`const {t: tt} = i18next`, a parameter `{t: tt}`), a re-export of a module the
|
|
4019
4172
|
reader reads --, called as `t(k)`, `t?.(k)`, `t.call(x, k)` or
|
|
4020
4173
|
`t.apply(x, [k])`. An ARRAY given to it is i18next's list of fallback keys, and
|
|
4021
|
-
each one is a key: `t([specific, "generic"])` asks for "generic".
|
|
4174
|
+
each one is a key: `t([specific, "generic"])` asks for "generic". A `.bind()`
|
|
4175
|
+
that binds a KEY makes a translator whose calls hand i18next its options or its
|
|
4176
|
+
default value: `const tk = t.bind(null, "save"); tk({count: 2})` (since
|
|
4177
|
+
`7.26.42`; up to `7.26.41` what `tk()` was handed was asked for as a key). The
|
|
4178
|
+
key it binds is not read (below). The places,
|
|
4022
4179
|
since `7.26.32`, also include `el.dataset.i18nTitle = k` (`dataset.i18nX` IS
|
|
4023
4180
|
the attribute `data-i18n-x`), and an attribute or property NAMED by a const:
|
|
4024
4181
|
`el.setAttribute(ATTR, k)`, `{[ATTR]: k}`, `x[ATTR] = k`, with `const ATTR =
|
|
4025
4182
|
"data-i18n-title"`; and since `7.26.35` `el.setAttributeNS(ns, ATTR, k)`, and a
|
|
4026
|
-
translator handed as a CALLBACK:
|
|
4027
|
-
|
|
4028
|
-
- `
|
|
4029
|
-
`some`, `every`
|
|
4030
|
-
|
|
4183
|
+
translator handed as a CALLBACK -- in these forms, and no other:
|
|
4184
|
+
|
|
4185
|
+
- the methods `map`, `flatMap`, `forEach`, `filter`, `find`, `findIndex`,
|
|
4186
|
+
`findLast`, `findLastIndex`, `some`, `every` (`findIndex` and
|
|
4187
|
+
`findLastIndex` since `7.26.42`), called on the array -- `keys.map(t)`,
|
|
4188
|
+
`keys?.map(t)`, `keys["map"](t)` -- or (since `7.26.42`) by `.call()` /
|
|
4189
|
+
`.apply()` of the method, `Array.prototype.map.call(keys, t)`,
|
|
4190
|
+
`[].forEach.apply(keys, [t])`; and `Array.from(keys, t)`,
|
|
4191
|
+
`Array.fromAsync(keys, t)`: each ELEMENT is a key, read like any other -- a
|
|
4192
|
+
const array, a published list, an import of one are followed;
|
|
4031
4193
|
- `promise.then(t)`, `.catch(t)`: what the promise settles with is a key no
|
|
4032
4194
|
source writes.
|
|
4033
4195
|
|
|
@@ -4037,7 +4199,11 @@ and any promise, fails unless the call is marked
|
|
|
4037
4199
|
`load().then(/* i18n: data */ t)`). A translator handed to a FUNCTION is not
|
|
4038
4200
|
one of these: `{t: t}`, `yui_tabulator_lang(t)`, `refresh_language($el, t)` --
|
|
4039
4201
|
it is how gobj-ui receives one, and the function calls it with keys of its
|
|
4040
|
-
own.
|
|
4202
|
+
own. Neither is one handed to any other method (`keys.reduce(t)`,
|
|
4203
|
+
`keys.sort(t)`), to an alias of one of those methods (`const map =
|
|
4204
|
+
Array.prototype.map; map.call(keys, t)`), through `Reflect.apply()`, or with a
|
|
4205
|
+
key bound (`keys.map(t.bind(null, k))`: each element goes to i18next as
|
|
4206
|
+
options). What is followed:
|
|
4041
4207
|
|
|
4042
4208
|
- a string literal, a template with no `${}`, and every branch of `?:`, `||`
|
|
4043
4209
|
and `??` (the right one of `&&`), so
|
|
@@ -4054,9 +4220,11 @@ own. What is followed:
|
|
|
4054
4220
|
computed one, `NOTES[verdict]`, every value the object holds; also of a
|
|
4055
4221
|
COPY of one (since `7.26.32`): `{...BASE, title: "t"}`,
|
|
4056
4222
|
`Object.assign({}, BASE)`;
|
|
4057
|
-
- the element of a const array literal that a
|
|
4058
|
-
|
|
4059
|
-
|
|
4223
|
+
- the element of a const array literal that a `for...of` walks, or that the
|
|
4224
|
+
first parameter of a callback of one of the methods above receives (in the
|
|
4225
|
+
same forms, and since `7.26.42` also the callback of `Array.from(ROWS, cb)`,
|
|
4226
|
+
of `.findIndex()` and of `Array.prototype.forEach.call(ROWS, cb)`), and what a
|
|
4227
|
+
destructuring reads from it (`for(const {key} of ROWS)`);
|
|
4060
4228
|
- `String(x)`, and a template that is only `${x}`, as `x` (since `7.26.29`);
|
|
4061
4229
|
- a parameter, however it is read (since `7.26.32`): `opts.title`,
|
|
4062
4230
|
`opts?.title`, `arguments[1]`, `rest[0]` of a rest parameter, a destructuring
|
|
@@ -4097,11 +4265,11 @@ fails the build, because its keys would go unchecked.
|
|
|
4097
4265
|
**An UNMARKED `let` that is only ever given literals IS followed** (since
|
|
4098
4266
|
`7.26.35`), where `t()`, an `i18n` / `code` value or a `data-i18n*` attribute
|
|
4099
4267
|
reads a key: when every value it is given in its scope -- its initializer, every
|
|
4100
|
-
`=`, `||=`, `??=`,
|
|
4101
|
-
|
|
4102
|
-
`?:` / `||` / `??` of those (the
|
|
4103
|
-
|
|
4104
|
-
it
|
|
4268
|
+
`=`, `||=`, `??=`, `&&=`, the value of a `var` of it declared again -- is
|
|
4269
|
+
WRITTEN as a string literal, a const bound to one (of the module, or imported),
|
|
4270
|
+
`null` / `undefined`, another such `let`, or a `?:` / `||` / `??` of those (the
|
|
4271
|
+
right one of `&&`), the variable can only ever hold those literals, and EVERY
|
|
4272
|
+
literal it is given in its scope is a key asked for.
|
|
4105
4273
|
|
|
4106
4274
|
```js
|
|
4107
4275
|
let state_key = (st === "ST_MONITORING")? "monitor monitoring" : "monitor disconnected";
|
|
@@ -4112,13 +4280,62 @@ $state.setAttribute("data-i18n", state_key); // asks for all three
|
|
|
4112
4280
|
$state.textContent = t(state_key);
|
|
4113
4281
|
```
|
|
4114
4282
|
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4283
|
+
The rule reads the WRITES, not the order in which they run: it is
|
|
4284
|
+
flow-insensitive, by design. A literal that an `if` keeps away from the place
|
|
4285
|
+
that reads the key is asked for, and so is a literal that is overwritten
|
|
4286
|
+
before the read. So a SENTINEL that is no key fails the build, as a missing
|
|
4287
|
+
key. `7.26.35` said that the rule was exact and failed nothing new. That was
|
|
4288
|
+
not true: it asks for every literal whatever the flow, and up to `7.26.41` it
|
|
4289
|
+
also missed some writes (below).
|
|
4290
|
+
|
|
4291
|
+
```js
|
|
4292
|
+
let key = "-"; // asks for "-" too: the `if` below does not hide it
|
|
4293
|
+
if(saving) {
|
|
4294
|
+
key = "save";
|
|
4295
|
+
}
|
|
4296
|
+
if(key !== "-") {
|
|
4297
|
+
t(key); // fails: "-" is defined in no locale
|
|
4298
|
+
}
|
|
4299
|
+
```
|
|
4300
|
+
|
|
4301
|
+
Write a sentinel as `null`, which is never asked for. Or give the key its own
|
|
4302
|
+
`const`:
|
|
4303
|
+
|
|
4304
|
+
```js
|
|
4305
|
+
let key = null; // a sentinel that is never asked for
|
|
4306
|
+
if(saving) {
|
|
4307
|
+
key = "save";
|
|
4308
|
+
}
|
|
4309
|
+
if(key) {
|
|
4310
|
+
t(key); // asks for "save"
|
|
4311
|
+
}
|
|
4312
|
+
```
|
|
4313
|
+
|
|
4314
|
+
```js
|
|
4315
|
+
const key = saving? "save" : null; // asks for "save"
|
|
4316
|
+
if(key) {
|
|
4317
|
+
t(key);
|
|
4318
|
+
}
|
|
4319
|
+
```
|
|
4320
|
+
|
|
4321
|
+
**EVERY write to the variable counts** (since `7.26.42`). A write whose value
|
|
4322
|
+
the reader does not read makes the variable not followed, and it stays
|
|
4323
|
+
invisible: a property of a table (`let m = MONTHS[i]`: the reader would read
|
|
4324
|
+
every value of the table, which is enough for a marker that names lists, and
|
|
4325
|
+
too much to ask the locales for), a call (`let k = busy_key(gobj)`), a
|
|
4326
|
+
parameter, data, a `+=` or `++`, a destructuring (`[k, x] = pair`,
|
|
4327
|
+
`({k} = row)`, `var [k] = pair`), a `for...of` / `for...in` head that writes
|
|
4328
|
+
it -- the variable itself (`for(k of rows)`), a destructuring of it
|
|
4329
|
+
(`for([k, label] of rows)`, `for({k} of rows)`, `for([k] in obj)`), or a `var`
|
|
4330
|
+
of it declared again there (`for(var k of rows)`) --, and a direct `eval()` in
|
|
4331
|
+
its scope. A `var` declared again anywhere in its function or module (a block,
|
|
4332
|
+
a `for(;;)` init, a `switch` case) gives it the value it is declared with. Up
|
|
4333
|
+
to `7.26.41` the loop heads that destructure or declare a `var` did not count,
|
|
4334
|
+
and a module `var` declared again outside the top level was not seen:
|
|
4335
|
+
`let key = "-"; for([key, label] of rows) el.setAttribute("data-i18n", key)`
|
|
4336
|
+
asked for "-", and failed. At a key position of a key function nothing
|
|
4337
|
+
changes: a `let` there is still a violation of the rule per call (below),
|
|
4338
|
+
which wants a const or a marker.
|
|
4122
4339
|
|
|
4123
4340
|
**A key handed to a FUNCTION is read where it is handed.**
|
|
4124
4341
|
`yui_shell_show_error(shell, "some records were gone before the delete")` asks
|
|
@@ -4163,8 +4380,10 @@ variable: `$box` says nothing. The exported ones an app calls:
|
|
|
4163
4380
|
`no_label`), `yui_selection_bar` (each action's `label`), `yui_asset_missing`
|
|
4164
4381
|
/ `yui_asset_element` (`key`), `hook_cell_spec` (the title key),
|
|
4165
4382
|
`period_name` (a granularity id), `card_descriptor` / `cards_grid_descriptor`
|
|
4166
|
-
(a nav item's `name`, `tooltip`, `aria_label
|
|
4167
|
-
|
|
4383
|
+
(a nav item's `name`, `tooltip`, `aria_label`, and its `id`: the key of an
|
|
4384
|
+
item with no `name`), `keep_canvas_tab_order` / `set_canvas_tab_order` (the
|
|
4385
|
+
name of a graph's main canvas) and `open_gclass_view` (the gclass name, which
|
|
4386
|
+
titles it).
|
|
4168
4387
|
|
|
4169
4388
|
**Every function that forwards a key is in the table, and a test finds them**
|
|
4170
4389
|
(since `7.26.29`: up to `7.26.28` the table lacked 39 of them, and 6 entries
|
|
@@ -4402,10 +4621,10 @@ GIVEN, in the scope that declares it -- its initializer and every `=` (`||=`,
|
|
|
4402
4621
|
`??=`, `&&=` too) -- and reads each value like any other. Each literal it finds
|
|
4403
4622
|
is a key the locales are asked for and, under a list marker, must be in the
|
|
4404
4623
|
lists it names. A write it cannot read (`+=`, `++`, a destructuring, a
|
|
4405
|
-
`for...of`
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
fails:
|
|
4624
|
+
`for...of` / `for...in` head that writes it, a direct `eval()`: every write of
|
|
4625
|
+
the list above) keeps the variable unknown; a parameter or another variable of
|
|
4626
|
+
the same name is not a write to it. And a variable that is given nothing but
|
|
4627
|
+
literals is a const that was not written as one, so it fails:
|
|
4409
4628
|
|
|
4410
4629
|
```js
|
|
4411
4630
|
let key = maximized ? "restore" : "maximize";
|
|
@@ -4415,9 +4634,10 @@ t(/* i18n: C_YUI_WINDOW_I18N_KEYS */ key);
|
|
|
4415
4634
|
```
|
|
4416
4635
|
|
|
4417
4636
|
The rule is the same under `i18n: data`: the literals of a marked variable are
|
|
4418
|
-
read, and one that holds nothing else fails. (Unmarked, such a variable
|
|
4419
|
-
|
|
4420
|
-
is
|
|
4637
|
+
read, and one that holds nothing else fails. (Unmarked, such a variable is no
|
|
4638
|
+
violation of its own: since `7.26.35` its literals are asked for, above --
|
|
4639
|
+
every one of them, so a literal that is no key fails as a missing key. The
|
|
4640
|
+
marker is what makes it a claim to check.)
|
|
4421
4641
|
|
|
4422
4642
|
**A `let` that holds a TABLE is held the same way** (since the same round:
|
|
4423
4643
|
up to then a marked member of one passed unread). When what is marked is read
|
|
@@ -4502,10 +4722,7 @@ unmarked `tr()` failed with *"cannot follow"*, whose advice was the marker that
|
|
|
4502
4722
|
then let it pass), and (since `7.26.35`) a string BUILT from one: a
|
|
4503
4723
|
concatenation or a template holding one (`t("k") + ":"`, `` `${t("k")}:` ``),
|
|
4504
4724
|
a method called on one (`t("k").toUpperCase()`, `[t("a"), name].join(" ")`);
|
|
4505
|
-
DOM built with one (`createElement2(["p", {}, t("k")])`) is DOM.
|
|
4506
|
-
excuses such a text anywhere a key is read -- `t(/* i18n: data */ t("k") +
|
|
4507
|
-
"!")` and `{i18n: /* i18n: data */ t("k").trim()}` fail too, with *"hand the
|
|
4508
|
-
key, not t(key)"*:
|
|
4725
|
+
DOM built with one (`createElement2(["p", {}, t("k")])`) is DOM.
|
|
4509
4726
|
|
|
4510
4727
|
```js
|
|
4511
4728
|
yui_install_ask_once(shell, {t: t, message: t("install this app")}); // fails
|
|
@@ -4518,6 +4735,21 @@ src/c_app.js:734 (call at line 732): yui_install_ask_once() [1.message] is given
|
|
|
4518
4735
|
it never changes language, and no marker excuses it): hand the key, not t(key)
|
|
4519
4736
|
```
|
|
4520
4737
|
|
|
4738
|
+
Such a text fails EVERYWHERE a key is read, marked or not: given to `t()`
|
|
4739
|
+
(`t(t("k") + "!")`), to an `i18n` / `code` / `data-i18n*` value
|
|
4740
|
+
(`{i18n: t("k").trim()}`, `el.dataset.i18nTitle = t("k")`), or to a
|
|
4741
|
+
`data-i18n*` attribute (`el.setAttribute("data-i18n-title", t("k"))`), and
|
|
4742
|
+
through a `const` that holds one. The place keeps the translation as its key,
|
|
4743
|
+
so it never changes language. Up to `7.26.41` only a MARKED one failed there:
|
|
4744
|
+
`{i18n: t("k")}` passed, and `{i18n: /* i18n: data */ t("k")}` failed. No
|
|
4745
|
+
consumer had one.
|
|
4746
|
+
|
|
4747
|
+
```
|
|
4748
|
+
src/main.js:2: `t("saved")` is a TRANSLATED text given to a property that holds a key (i18n, code,
|
|
4749
|
+
data-i18n*): the translation is kept as its key and never changes language: hand the key, not t(key)
|
|
4750
|
+
src/main.js:8: `t("saved")` is a TRANSLATED text given to a data-i18n* attribute (read at line 9): ...
|
|
4751
|
+
```
|
|
4752
|
+
|
|
4521
4753
|
In an app, what a wrapper of its own hands on is marked where it hands it:
|
|
4522
4754
|
`/* i18n: data */` when it is data (a backend's comment, a key built from a
|
|
4523
4755
|
name, the DOM its callers built). When its callers give it the module's own
|
|
@@ -4589,7 +4821,8 @@ reading the page in another language:
|
|
|
4589
4821
|
|
|
4590
4822
|
- a key handed to a translator, an `i18n` or a `data-i18n*` value by an
|
|
4591
4823
|
UNMARKED `let` given anything but literals (a property of a table, a call, a
|
|
4592
|
-
parameter, data, a
|
|
4824
|
+
parameter, data, a `+=`, a destructuring, a loop head that writes it: one
|
|
4825
|
+
only ever given literals is followed, above), a
|
|
4593
4826
|
call the reader does not follow (a recursion, one whose returns mix keys and
|
|
4594
4827
|
data, a function of a package) or a computed string:
|
|
4595
4828
|
a translator is not a key function, and only the positions of
|
|
@@ -4603,14 +4836,19 @@ reading the page in another language:
|
|
|
4603
4836
|
through what is no name of it: `(0, t)(k)`, `[t][0](k)`,
|
|
4604
4837
|
`Reflect.apply(t, x, [k])`, `Function.prototype.call.call(t, x, k)`;
|
|
4605
4838
|
- a key BOUND with the translator, `t.bind(null, k)` (`.bind()` is read as an
|
|
4606
|
-
alias of the translator, and the key it binds is not read
|
|
4839
|
+
alias of the translator, and the key it binds is not read; what a call of
|
|
4840
|
+
it is handed is i18next's options or default value, and since `7.26.42` it
|
|
4841
|
+
is not read as a key either);
|
|
4607
4842
|
- a translator handed to a FUNCTION (`{t: t}`, `yui_tabulator_lang(t)`,
|
|
4608
|
-
`run(t)`)
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4843
|
+
`run(t)`) or to any method but those listed above (`keys.reduce(t)`,
|
|
4844
|
+
`keys.sort(t)`, an alias of a method, `Reflect.apply()`): only those
|
|
4845
|
+
methods, in those forms, and `.then()` / `.catch()` are read as calling it
|
|
4846
|
+
with what they walk or settle with;
|
|
4847
|
+
- a translated text held in a `let`, marked or not (`let label = t(k);` ...
|
|
4848
|
+
`label`): the reader reads the literals of a `let`, not its translations;
|
|
4849
|
+
and one returned by a function (`{i18n: label_of(k)}`, `label_of` returning
|
|
4850
|
+
`t(k)`). A translated text written where the key is read fails, marked or
|
|
4851
|
+
not, and so does one a `const` holds (below);
|
|
4614
4852
|
- a key function reached through a parameter (`apply(fn)` calling
|
|
4615
4853
|
`fn(shell, "k")`), a `let` given more than one function, a map in a `let`,
|
|
4616
4854
|
a computed member (`API[name](...)`), or `.apply()` of an array the source
|
|
@@ -4653,14 +4891,17 @@ reading the page in another language:
|
|
|
4653
4891
|
`var`, or mutated (also through an alias or a namespace member);
|
|
4654
4892
|
- a marker that is wrong (above): a `data` marker on what the reader follows
|
|
4655
4893
|
to keys, or on what would hide a key (a call mixing keys and data, an array
|
|
4656
|
-
of string literals),
|
|
4657
|
-
|
|
4658
|
-
|
|
4894
|
+
of string literals), a list marker on a template whose shape no key of the
|
|
4895
|
+
list has -- or whose every key of that shape a narrower marked template
|
|
4896
|
+
builds;
|
|
4897
|
+
- a TRANSLATED text where a key is read, marked or not: given to `t()`, to an
|
|
4898
|
+
`i18n` / `code` / `data-i18n*` value or to a `data-i18n*` attribute (since
|
|
4899
|
+
`7.26.42`; up to `7.26.41` only a marked one failed), or to a key position
|
|
4900
|
+
of a key function (the rule per call, above);
|
|
4659
4901
|
- a key position of a key function, in the app's own code, given what the
|
|
4660
|
-
reader cannot follow and unmarked
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
`.catch()`, unmarked.
|
|
4902
|
+
reader cannot follow and unmarked (the rule per call, above); and so a
|
|
4903
|
+
translator handed as a callback to one of the methods above over an array
|
|
4904
|
+
the reader cannot follow, or to `.then()` / `.catch()`, unmarked.
|
|
4664
4905
|
|
|
4665
4906
|
Up to `7.26.27` the locale cases were "skipped" with an OK: one language less
|
|
4666
4907
|
validated, and nobody told. A file of the locales directory with a locale's
|