@vectoriox/iox-ui 5.149.0 → 5.150.0
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/fesm2022/vectoriox-iox-ui-generation-core.mjs +337 -85
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +74 -8
- package/package.json +1 -1
- package/src/generation-core/audit-site.ts +55 -40
- package/src/generation-core/audit-words.ts +294 -0
- package/src/generation-core/compose-site.ts +5 -2
- package/src/generation-core/nav-shape.ts +37 -31
- package/src/generation-core/public-api.ts +1 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { CHECKOUT_GATE_RULES, CommerceLabel, labelIn } from '@vectoriox/iox-ui/commerce-core';
|
|
2
|
+
|
|
3
|
+
import type { SiteFinding, SiteFindingCode } from './audit-site';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What the site audit SAYS, in the admin's language (vectoriox/iox-ui#109). Every finding code has ONE entry here:
|
|
7
|
+
* its sentence in English and Hebrew (the commerce-core `CommerceLabel` shape — the core carries both, a string-rendered
|
|
8
|
+
* screen and iox-cms have no translation service), the variants a code has (which mode, why a statement is owed), and
|
|
9
|
+
* how its repeats are grouped with the sentence a group is said in. `auditSite` writes a finding's English `message` from
|
|
10
|
+
* this table and the values it names (`SiteFinding.params`), so the server's words and a screen's are one source.
|
|
11
|
+
*
|
|
12
|
+
* Only TYPES are imported from `audit-site` (the codes are written as their string values) — audit-site imports this
|
|
13
|
+
* file at runtime, and a value import back would be a module cycle.
|
|
14
|
+
*/
|
|
15
|
+
export type FindingSentence = CommerceLabel;
|
|
16
|
+
|
|
17
|
+
/** How a code's repeats become one row on a screen. */
|
|
18
|
+
export enum FindingGrouping {
|
|
19
|
+
/** One row per page (or global): "12 boxes wait for a picture" on Home, another for About. */
|
|
20
|
+
Page = 'page',
|
|
21
|
+
/** One row for the site: "15 sample items", "6 pages have no description for search results". */
|
|
22
|
+
Site = 'site',
|
|
23
|
+
/** Never grouped: each finding names something different (a fact, a product with its own page, a connector). */
|
|
24
|
+
Never = 'never',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface FindingWords {
|
|
28
|
+
/** The sentence for one finding — or one per variant (`params.variant`). `{name}` is replaced by `params.name`. */
|
|
29
|
+
readonly one: FindingSentence | Readonly<Record<string, FindingSentence>>;
|
|
30
|
+
/** The sentence for a group of `{n}` (absent: never grouped). */
|
|
31
|
+
readonly many?: FindingSentence;
|
|
32
|
+
readonly group: FindingGrouping;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const S = (en: string, he: string): FindingSentence => ({ en, he });
|
|
36
|
+
|
|
37
|
+
/** Every code's words. Typed by the codes' values, so a new code without words does not compile. */
|
|
38
|
+
export const SITE_FINDING_WORDS: Readonly<Record<`${SiteFindingCode}`, FindingWords>> = {
|
|
39
|
+
'no-header': {
|
|
40
|
+
one: S('The site has no header, so visitors have no menu to move around with.', 'לאתר אין כותרת עליונה, ולכן אין למבקרים תפריט לנווט בו.'),
|
|
41
|
+
group: FindingGrouping.Never,
|
|
42
|
+
},
|
|
43
|
+
'no-phone-menu': {
|
|
44
|
+
one: S('The header has no phone menu — on a phone its links are hard to reach.', 'לכותרת העליונה אין תפריט לטלפון — בטלפון קשה להגיע לקישורים שלה.'),
|
|
45
|
+
group: FindingGrouping.Never,
|
|
46
|
+
},
|
|
47
|
+
'form-without-id': {
|
|
48
|
+
one: S('A form has no id, so what visitors send is never stored.', 'לטופס אין מזהה, ולכן מה שמבקרים שולחים לא נשמר.'),
|
|
49
|
+
many: S('{n} forms have no id, so what visitors send is never stored.', '{n} טפסים בלי מזהה, ולכן מה שמבקרים שולחים בהם לא נשמר.'),
|
|
50
|
+
group: FindingGrouping.Page,
|
|
51
|
+
},
|
|
52
|
+
'empty-channel': {
|
|
53
|
+
one: S('A form\'s second way to reach you has no number or address yet — visitors do not see it until you fill it in.',
|
|
54
|
+
'לדרך הנוספת ליצור איתכם קשר בטופס עדיין אין מספר או כתובת — המבקרים לא יראו אותה עד שתמלאו אותה.'),
|
|
55
|
+
many: S('{n} forms\' second way to reach you has no number or address yet — visitors do not see it until you fill it in.',
|
|
56
|
+
'ב-{n} טפסים לדרך הנוספת ליצור איתכם קשר עדיין אין מספר או כתובת — המבקרים לא יראו אותה עד שתמלאו אותה.'),
|
|
57
|
+
group: FindingGrouping.Page,
|
|
58
|
+
},
|
|
59
|
+
'email-needs-mailer': {
|
|
60
|
+
one: S('A form emails what visitors send, but Email is not connected — it is stored and never sent.',
|
|
61
|
+
'טופס שולח במייל את מה שמבקרים שולחים, אבל המייל לא מחובר — ההודעות נשמרות ולא נשלחות.'),
|
|
62
|
+
many: S('{n} forms email what visitors send, but Email is not connected — it is stored and never sent.',
|
|
63
|
+
'{n} טפסים שולחים במייל את מה שמבקרים שולחים, אבל המייל לא מחובר — ההודעות נשמרות ולא נשלחות.'),
|
|
64
|
+
group: FindingGrouping.Site,
|
|
65
|
+
},
|
|
66
|
+
'tracker-without-banner': {
|
|
67
|
+
one: S('{trackers} is connected, but the site has no cookie banner — it stays off for every visitor.',
|
|
68
|
+
'{trackers} מחובר, אבל באתר אין באנר עוגיות — הוא כבוי לכל המבקרים.'),
|
|
69
|
+
group: FindingGrouping.Never,
|
|
70
|
+
},
|
|
71
|
+
'no-title': {
|
|
72
|
+
one: S('"{name}" has no title for search results.', 'לעמוד "{name}" אין כותרת לתוצאות החיפוש.'),
|
|
73
|
+
many: S('{n} pages have no title for search results.', '{n} עמודים בלי כותרת לתוצאות החיפוש.'),
|
|
74
|
+
group: FindingGrouping.Site,
|
|
75
|
+
},
|
|
76
|
+
'no-description': {
|
|
77
|
+
one: S('"{name}" has no description for search results.', 'לעמוד "{name}" אין תיאור לתוצאות החיפוש.'),
|
|
78
|
+
many: S('{n} pages have no description for search results.', '{n} עמודים בלי תיאור לתוצאות החיפוש.'),
|
|
79
|
+
group: FindingGrouping.Site,
|
|
80
|
+
},
|
|
81
|
+
'unfilled-fact': {
|
|
82
|
+
one: S('"{text}" is still blank — fill it in before the site goes live.', '"{text}" עדיין ריק — מלאו אותו לפני שהאתר עולה לאוויר.'),
|
|
83
|
+
group: FindingGrouping.Never,
|
|
84
|
+
},
|
|
85
|
+
'contact-missing': {
|
|
86
|
+
one: S('"{text}" is not on the site yet — visitors do not see that line until you fill it in.',
|
|
87
|
+
'"{text}" עוד לא באתר — המבקרים לא יראו את השורה הזו עד שתמלאו אותה.'),
|
|
88
|
+
group: FindingGrouping.Never,
|
|
89
|
+
},
|
|
90
|
+
'copy-placeholder': {
|
|
91
|
+
one: S('Some words are still the template\'s.', 'חלק מהמילים עדיין של התבנית.'),
|
|
92
|
+
many: S('{n} places still hold the template\'s words.', 'ב-{n} מקומות עדיין מופיעות המילים של התבנית.'),
|
|
93
|
+
group: FindingGrouping.Page,
|
|
94
|
+
},
|
|
95
|
+
'sample-items': {
|
|
96
|
+
one: S('"{name}" is a sample — replace or remove it.', '"{name}" הוא פריט לדוגמה — החליפו או הסירו אותו.'),
|
|
97
|
+
many: S('{n} sample items — replace them with yours or remove them.', '{n} פריטים לדוגמה — החליפו אותם בשלכם או הסירו אותם.'),
|
|
98
|
+
group: FindingGrouping.Site,
|
|
99
|
+
},
|
|
100
|
+
// Each sample product is fixed on its own page (the screen links to it), so they are never one row.
|
|
101
|
+
'sample-price': {
|
|
102
|
+
one: S('"{name}" has no price yet — set yours, or remove the sample.', 'ל-"{name}" עדיין אין מחיר — קבעו מחיר או הסירו את הדוגמה.'),
|
|
103
|
+
group: FindingGrouping.Never,
|
|
104
|
+
},
|
|
105
|
+
'sample-stock': {
|
|
106
|
+
one: S('"{name}" has no stock yet — say how many you have, or remove the sample.', 'ל-"{name}" עדיין אין מלאי — כתבו כמה יש לכם, או הסירו את הדוגמה.'),
|
|
107
|
+
group: FindingGrouping.Never,
|
|
108
|
+
},
|
|
109
|
+
// A store fact's words are the checkout gate's rule label (commerce-core) — `findingSentence` reads them by `fact`.
|
|
110
|
+
'store-fact': { one: S('A fact the checkout needs is missing.', 'חסר פרט שהקופה צריכה.'), group: FindingGrouping.Never },
|
|
111
|
+
'store-contact': { one: S('A contact detail the checkout needs is missing.', 'חסר פרט קשר שהקופה צריכה.'), group: FindingGrouping.Never },
|
|
112
|
+
'stock-photo': {
|
|
113
|
+
one: S('A stock photo stands in for one of yours.', 'תמונה מהמאגר עומדת במקום תמונה שלכם.'),
|
|
114
|
+
many: S('{n} stock photos stand in for yours.', '{n} תמונות מהמאגר עומדות במקום התמונות שלכם.'),
|
|
115
|
+
group: FindingGrouping.Page,
|
|
116
|
+
},
|
|
117
|
+
'made-picture': {
|
|
118
|
+
one: S('A picture made with AI stands in for one of yours.', 'תמונה שנוצרה ב-AI עומדת במקום תמונה שלכם.'),
|
|
119
|
+
many: S('{n} pictures made with AI stand in for yours.', '{n} תמונות שנוצרו ב-AI עומדות במקום התמונות שלכם.'),
|
|
120
|
+
group: FindingGrouping.Page,
|
|
121
|
+
},
|
|
122
|
+
'picture-missing': {
|
|
123
|
+
one: {
|
|
124
|
+
made: S('A picture could not be made for this spot — add one of yours.', 'לא הצלחנו ליצור תמונה למקום הזה — הוסיפו תמונה שלכם.'),
|
|
125
|
+
box: S('A box on this page waits for a picture — add one of yours.', 'תיבה בעמוד הזה מחכה לתמונה — הוסיפו תמונה שלכם.'),
|
|
126
|
+
},
|
|
127
|
+
many: S('{n} boxes wait for a picture — add yours.', '{n} תיבות מחכות לתמונה — הוסיפו תמונות שלכם.'),
|
|
128
|
+
group: FindingGrouping.Page,
|
|
129
|
+
},
|
|
130
|
+
'no-privacy-page': {
|
|
131
|
+
one: S('A form asks for personal details, and the site has no privacy page saying what you do with them.',
|
|
132
|
+
'טופס מבקש פרטים אישיים, ואין באתר עמוד פרטיות שמסביר מה אתם עושים איתם.'),
|
|
133
|
+
group: FindingGrouping.Never,
|
|
134
|
+
},
|
|
135
|
+
'legal-page-placeholder': {
|
|
136
|
+
one: S('"{name}" still says what belongs there — only you can write it.', 'בעמוד "{name}" עדיין כתוב רק מה צריך להופיע בו — רק אתם יכולים לכתוב אותו.'),
|
|
137
|
+
group: FindingGrouping.Never,
|
|
138
|
+
},
|
|
139
|
+
'no-accessibility-statement': {
|
|
140
|
+
one: {
|
|
141
|
+
israel: S('The site has no accessibility statement — Israel requires one. Add a page for it and write what is accessible and who to contact.',
|
|
142
|
+
'אין באתר הצהרת נגישות — החוק בישראל מחייב אותה. הוסיפו לה עמוד וכתבו מה נגיש ולמי לפנות.'),
|
|
143
|
+
hebrew: S('The site has no accessibility statement — a Hebrew site is expected to carry one. Add a page for it and write what is accessible and who to contact.',
|
|
144
|
+
'אין באתר הצהרת נגישות — מאתר בעברית מצופה שתהיה בו. הוסיפו לה עמוד וכתבו מה נגיש ולמי לפנות.'),
|
|
145
|
+
},
|
|
146
|
+
group: FindingGrouping.Never,
|
|
147
|
+
},
|
|
148
|
+
'accessibility-statement-advised': {
|
|
149
|
+
one: {
|
|
150
|
+
israel: S('The site has no accessibility statement — Israel requires one. Add a page for it.', 'אין באתר הצהרת נגישות — החוק בישראל מחייב אותה. הוסיפו לה עמוד.'),
|
|
151
|
+
hebrew: S('The site has no accessibility statement — a Hebrew site is expected to carry one. Add a page for it.', 'אין באתר הצהרת נגישות — מאתר בעברית מצופה שתהיה בו. הוסיפו לה עמוד.'),
|
|
152
|
+
},
|
|
153
|
+
group: FindingGrouping.Never,
|
|
154
|
+
},
|
|
155
|
+
'consent-reject-weaker': {
|
|
156
|
+
one: {
|
|
157
|
+
missing: S('The cookie banner has no Reject beside Accept — refusing must be as easy as accepting.',
|
|
158
|
+
'בבאנר העוגיות אין "דחייה" לצד "אישור" — לסרב צריך להיות קל כמו להסכים.'),
|
|
159
|
+
weaker: S('The cookie banner\'s Reject is weaker than its Accept — make it the same kind of button, on the same row.',
|
|
160
|
+
'"דחייה" בבאנר העוגיות חלשה מ"אישור" — הפכו אותה לאותו סוג כפתור, באותה שורה.'),
|
|
161
|
+
},
|
|
162
|
+
group: FindingGrouping.Never,
|
|
163
|
+
},
|
|
164
|
+
'no-cookie-settings': {
|
|
165
|
+
one: S('Nothing on the site reopens the cookie choice — add Cookie settings to the footer so visitors can change their mind.',
|
|
166
|
+
'שום דבר באתר לא פותח מחדש את בחירת העוגיות — הוסיפו "הגדרות עוגיות" לכותרת התחתונה כדי שמבקרים יוכלו לשנות את דעתם.'),
|
|
167
|
+
group: FindingGrouping.Never,
|
|
168
|
+
},
|
|
169
|
+
'low-contrast': {
|
|
170
|
+
one: {
|
|
171
|
+
light: S('{count} text and background pair(s) are hard to read in light mode.', '{count} צירופים של טקסט ורקע קשים לקריאה במצב בהיר.'),
|
|
172
|
+
dark: S('{count} text and background pair(s) are hard to read in dark mode.', '{count} צירופים של טקסט ורקע קשים לקריאה במצב כהה.'),
|
|
173
|
+
},
|
|
174
|
+
group: FindingGrouping.Never,
|
|
175
|
+
},
|
|
176
|
+
'heading-order': {
|
|
177
|
+
one: {
|
|
178
|
+
skip: S('A heading on "{name}" skips a level (h{from} → h{to}).', 'כותרת בעמוד "{name}" מדלגת על רמה (מ-h{from} ל-h{to}).'),
|
|
179
|
+
h1: S('"{name}" has {count} main headings (h1); one is clearer.', 'בעמוד "{name}" יש {count} כותרות ראשיות (h1); אחת ברורה יותר.'),
|
|
180
|
+
},
|
|
181
|
+
many: S('{n} headings on this page are out of order.', '{n} כותרות בעמוד הזה לא בסדר הנכון.'),
|
|
182
|
+
group: FindingGrouping.Page,
|
|
183
|
+
},
|
|
184
|
+
'image-without-alt': {
|
|
185
|
+
one: S('A picture has no description for people who cannot see it.', 'לתמונה אין תיאור לאנשים שלא יכולים לראות אותה.'),
|
|
186
|
+
many: S('{n} pictures have no description for people who cannot see them.', '{n} תמונות בלי תיאור לאנשים שלא יכולים לראות אותן.'),
|
|
187
|
+
group: FindingGrouping.Page,
|
|
188
|
+
},
|
|
189
|
+
'literal-colour': {
|
|
190
|
+
one: S('An element paints a fixed colour, so a new look will not reach it.', 'רכיב צבוע בצבע קבוע, ולכן מראה חדש לא יגיע אליו.'),
|
|
191
|
+
many: S('{n} elements paint a fixed colour, so a new look will not reach them.', '{n} רכיבים צבועים בצבע קבוע, ולכן מראה חדש לא יגיע אליהם.'),
|
|
192
|
+
group: FindingGrouping.Page,
|
|
193
|
+
},
|
|
194
|
+
'dead-link': {
|
|
195
|
+
one: {
|
|
196
|
+
route: S('"{label}" links to {route}, which is not a page of the site.', '"{label}" מקשר אל {route}, שאינו עמוד באתר.'),
|
|
197
|
+
unlinked: S('"{label}" links to no page.', '"{label}" לא מקשר לשום עמוד.'),
|
|
198
|
+
action: S('"{label}" goes to a page the site does not have.', '"{label}" מוביל לעמוד שאין באתר.'),
|
|
199
|
+
},
|
|
200
|
+
many: S('{n} links on this page go to pages the site does not have.', '{n} קישורים בעמוד הזה מובילים לעמודים שאין באתר.'),
|
|
201
|
+
group: FindingGrouping.Page,
|
|
202
|
+
},
|
|
203
|
+
'dead-dialog-target': {
|
|
204
|
+
one: S('"{label}" opens something that is no longer on the site.', '"{label}" פותח משהו שכבר לא נמצא באתר.'),
|
|
205
|
+
many: S('{n} buttons on this page open something that is no longer on the site.', '{n} כפתורים בעמוד הזה פותחים משהו שכבר לא נמצא באתר.'),
|
|
206
|
+
group: FindingGrouping.Page,
|
|
207
|
+
},
|
|
208
|
+
'action-needs-connector': {
|
|
209
|
+
one: S('"{label}" needs {connector} connected.', '"{label}" צריך ש-{connector} יהיה מחובר.'),
|
|
210
|
+
group: FindingGrouping.Never,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/** The values a finding's sentence names (a page's or an item's name, a count, a route…), and its variant. */
|
|
215
|
+
export type FindingParams = Readonly<Record<string, string | number>>;
|
|
216
|
+
|
|
217
|
+
const PLACEHOLDER = /\{(\w+)\}/g;
|
|
218
|
+
|
|
219
|
+
function sentenceOf(words: FindingWords, variant: string | number | undefined): FindingSentence | null {
|
|
220
|
+
const one = words.one as Record<string, unknown>;
|
|
221
|
+
if (typeof one['en'] === 'string') return words.one as FindingSentence;
|
|
222
|
+
return (variant !== undefined ? (one[String(variant)] as FindingSentence | undefined) : undefined) ?? null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** A sentence with its values — or null when one it names is missing (an older finding, written without `params`). */
|
|
226
|
+
function fill(text: string, params: FindingParams): string | null {
|
|
227
|
+
let missing = false;
|
|
228
|
+
const out = text.replace(PLACEHOLDER, (_, key: string) => {
|
|
229
|
+
const v = params[key];
|
|
230
|
+
if (v === undefined || v === null) { missing = true; return ''; }
|
|
231
|
+
return String(v);
|
|
232
|
+
});
|
|
233
|
+
return missing ? null : out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The English sentence `auditSite` stores as a finding's `message` (one source with the screens' words). */
|
|
237
|
+
export function findingMessageOf(code: `${SiteFindingCode}`, params: FindingParams = {}): string {
|
|
238
|
+
const sentence = sentenceOf(SITE_FINDING_WORDS[code], params['variant']);
|
|
239
|
+
return (sentence && fill(sentence.en, params)) ?? code;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* One finding in the admin's language: a store fact is the checkout gate's rule label (commerce-core), every other code
|
|
244
|
+
* its sentence here with the finding's values. A finding that carries no values (written by an older server) keeps the
|
|
245
|
+
* server's own words.
|
|
246
|
+
*/
|
|
247
|
+
export function findingSentence(f: Pick<SiteFinding, 'code' | 'message' | 'fact' | 'params'>, lang: string | null | undefined): string {
|
|
248
|
+
if (f.fact) {
|
|
249
|
+
const rule = CHECKOUT_GATE_RULES.find(r => r.code === f.fact);
|
|
250
|
+
if (rule) return labelIn(rule.label, lang);
|
|
251
|
+
}
|
|
252
|
+
const words = SITE_FINDING_WORDS[f.code as `${SiteFindingCode}`];
|
|
253
|
+
const sentence = words ? sentenceOf(words, f.params?.['variant']) : null;
|
|
254
|
+
return (sentence && fill(labelIn(sentence, lang), f.params ?? {})) ?? f.message;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Findings of one kind said as one row. */
|
|
258
|
+
export interface SiteFindingGroup {
|
|
259
|
+
/** Stable for a screen's list: the code and where the group is. */
|
|
260
|
+
key: string;
|
|
261
|
+
code: SiteFindingCode;
|
|
262
|
+
findings: SiteFinding[];
|
|
263
|
+
/** The first finding — where "Show me" goes, and its page / global. */
|
|
264
|
+
first: SiteFinding;
|
|
265
|
+
count: number;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function groupKey(f: SiteFinding, i: number): string {
|
|
269
|
+
const grouping = SITE_FINDING_WORDS[f.code as `${SiteFindingCode}`]?.group ?? FindingGrouping.Never;
|
|
270
|
+
switch (grouping) {
|
|
271
|
+
case FindingGrouping.Site: return `${f.code}`;
|
|
272
|
+
case FindingGrouping.Page: return `${f.code}:${f.pageId ?? `global:${f.owner ?? ''}`}`;
|
|
273
|
+
default: return `${f.code}:${f.fact ?? f.legal ?? f.nodeId ?? f.pageId ?? i}`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Repeated findings of one kind as one row each (per page, per site, or never — `SITE_FINDING_WORDS[code].group`),
|
|
278
|
+
* in the order the first of each appears. */
|
|
279
|
+
export function groupSiteFindings(findings: ReadonlyArray<SiteFinding>): SiteFindingGroup[] {
|
|
280
|
+
const groups = new Map<string, SiteFinding[]>();
|
|
281
|
+
findings.forEach((f, i) => {
|
|
282
|
+
const key = groupKey(f, i);
|
|
283
|
+
const g = groups.get(key);
|
|
284
|
+
if (g) g.push(f); else groups.set(key, [f]);
|
|
285
|
+
});
|
|
286
|
+
return [...groups.entries()].map(([key, list]) => ({ key, code: list[0].code, findings: list, first: list[0], count: list.length }));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** A group in the admin's language: its one finding's sentence, or the code's sentence for `{n}` of them. */
|
|
290
|
+
export function groupSentence(g: Pick<SiteFindingGroup, 'first' | 'count'>, lang: string | null | undefined): string {
|
|
291
|
+
const many = SITE_FINDING_WORDS[g.first.code as `${SiteFindingCode}`]?.many;
|
|
292
|
+
if (g.count < 2 || !many) return findingSentence(g.first, lang);
|
|
293
|
+
return fill(labelIn(many, lang), { n: g.count }) ?? findingSentence(g.first, lang);
|
|
294
|
+
}
|
|
@@ -2008,12 +2008,15 @@ export function planHeader(plan: SitePlan): { recipe: HeaderRecipe; context: Hea
|
|
|
2008
2008
|
/** The phone-menu options a header recipe asks for: its menu at every width and on its side (none for the defaults, so a
|
|
2009
2009
|
* stored header's edit is the one it always was). */
|
|
2010
2010
|
function headerShapeOptions(recipe: HeaderRecipe | null, locale?: string): { everyWidth?: boolean; menuSide?: MenuSide; look?: Partial<MenuLook>; locale?: string } {
|
|
2011
|
-
|
|
2011
|
+
// vectoriox/iox-ui#100: the menu's words (and the names its parts are heard by) are the site's language — English
|
|
2012
|
+
// words are the table's English, so an English header composes as it always did (R-H4).
|
|
2013
|
+
const words = locale ? { locale } : {};
|
|
2014
|
+
if (!recipe) return words;
|
|
2012
2015
|
// HI2a: the menu's look, only what differs from today's menu (a stored header composes as it always did — R-H4).
|
|
2013
2016
|
const look = Object.fromEntries(Object.entries(recipe.menu).filter(([k, v]) => DEFAULT_MENU_LOOK[k as keyof MenuLook] !== v)) as Partial<MenuLook>;
|
|
2014
2017
|
return {
|
|
2015
2018
|
...(recipe.everyWidth ? { everyWidth: true } : {}), ...(recipe.menuSide === MenuSide.Start ? { menuSide: MenuSide.Start } : {}),
|
|
2016
|
-
...(Object.keys(look).length ? { look
|
|
2019
|
+
...(Object.keys(look).length ? { look } : {}), ...words,
|
|
2017
2020
|
};
|
|
2018
2021
|
}
|
|
2019
2022
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AccountRole, ShopRole } from '@vectoriox/iox-ui/composite-core';
|
|
2
|
+
import { commerceLanguage } from '@vectoriox/iox-ui/commerce-core';
|
|
2
3
|
import { LinkType, MenuButtonKind, menuButtonOf, menuButtonProps, menuDialogProps, MenuLook, MenuTrait } from '@vectoriox/iox-ui/design-core';
|
|
3
4
|
|
|
4
5
|
import { PatternGlobalPosition } from './patterns';
|
|
@@ -94,7 +95,7 @@ export interface NavShapeOptions {
|
|
|
94
95
|
* traits on the drawer, the menu button and the drawer's Close; a default writes nothing (R-H4). Absent: the parts
|
|
95
96
|
* keep what they have. */
|
|
96
97
|
look?: Partial<MenuLook>;
|
|
97
|
-
/** The site's language, for the words
|
|
98
|
+
/** The site's language, for the words the menu's parts show and are named by (`menuWords`). Default English. */
|
|
98
99
|
locale?: string;
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -134,15 +135,18 @@ export const NAV_SHAPE_COPY = {
|
|
|
134
135
|
home: 'Home',
|
|
135
136
|
} as const;
|
|
136
137
|
|
|
137
|
-
/** The words
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
/** The words the menu's parts say, in the site's language — a `word` menu button's visible Menu ⇄ Close (HI2a) and the
|
|
139
|
+
* names a screen reader hears (the menu button, the drawer, its Close, the bar's More, the drawer's Home link). A site
|
|
140
|
+
* in a language the table does not hold speaks English, as it always did (vectoriox/iox-ui#100). */
|
|
141
|
+
export interface MenuWords { menu: string; close: string; closeMenu: string; more: string; home: string }
|
|
142
|
+
|
|
143
|
+
const MENU_WORDS: Readonly<Record<string, MenuWords>> = {
|
|
144
|
+
en: { ...NAV_SHAPE_COPY },
|
|
145
|
+
he: { menu: 'תפריט', close: 'סגירה', closeMenu: 'סגירת התפריט', more: 'עוד', home: 'בית' },
|
|
142
146
|
};
|
|
143
147
|
|
|
144
|
-
export function menuWords(locale: string | undefined):
|
|
145
|
-
return MENU_WORDS[locale
|
|
148
|
+
export function menuWords(locale: string | undefined): MenuWords {
|
|
149
|
+
return MENU_WORDS[commerceLanguage(locale)] ?? MENU_WORDS['en'];
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/** The layer names of the parts (R2: the tree, the breadcrumb and the toolbar read them). */
|
|
@@ -397,8 +401,8 @@ function labelText(kit: Kit, suffix: string, words: string): SerializedNode {
|
|
|
397
401
|
// lines makes the row taller, and two centred buttons in rows of different heights part (iox-ui#60).
|
|
398
402
|
const MENU_BUTTON_LAY = { width: '48px', height: '48px', alignItems: 'center', justifyContent: 'center', alignSelf: 'flex-start', flexShrink: '0' };
|
|
399
403
|
|
|
400
|
-
function menuButton(kit: Kit, drawerId: string, at: string): SerializedNode {
|
|
401
|
-
const btn = part(kit, 'menu', BUTTON, { tag: 'button', ariaLabel:
|
|
404
|
+
function menuButton(kit: Kit, drawerId: string, at: string, words: MenuWords): SerializedNode {
|
|
405
|
+
const btn = part(kit, 'menu', BUTTON, { tag: 'button', ariaLabel: words.menu }, 'button-ghost', NavRole.MenuButton, { ...MENU_BUTTON_LAY });
|
|
402
406
|
btn.children = [iconNode(kit, 'menu-icon', MENU_ICON)];
|
|
403
407
|
btn.interactions = [clickTo(kit, 'menu', NavDialogAction.Toggle, drawerId)];
|
|
404
408
|
phoneOnly(btn, at, MENU_DISPLAY);
|
|
@@ -409,14 +413,14 @@ function pageLink(kit: Kit, suffix: string, page: NavPage, role: NavRole, lay: R
|
|
|
409
413
|
return part(kit, suffix, LINK, { label: page.label, linkType: LinkType.Page, pageRoute: page.route }, 'link', role, lay);
|
|
410
414
|
}
|
|
411
415
|
|
|
412
|
-
function drawer(kit: Kit, root: SerializedNode, pages: NavPage[], at: string): SerializedNode {
|
|
416
|
+
function drawer(kit: Kit, root: SerializedNode, pages: NavPage[], at: string, words: MenuWords): SerializedNode {
|
|
413
417
|
const dr = part(kit, 'drawer', DIALOG, {
|
|
414
|
-
placement: 'end', closeOnBackdrop: true, showCloseButton: false, ariaLabel:
|
|
418
|
+
placement: 'end', closeOnBackdrop: true, showCloseButton: false, ariaLabel: words.menu, closeAbove: at,
|
|
415
419
|
}, 'dialog', NavRole.Drawer, { width: '86vw', maxWidth: '360px', display: 'flex', flexDirection: 'column', gap: '20px' });
|
|
416
420
|
const brandWords = textOf(find([root], NavRole.Brand) ?? root) || NAV_PART_LABELS[NavRole.Root];
|
|
417
421
|
const head = part(kit, 'drawer-head', CONTAINER, {}, 'box', NavRole.DrawerHead,
|
|
418
422
|
{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '12px' });
|
|
419
|
-
const close = part(kit, 'drawer-close', BUTTON, { tag: 'button', ariaLabel:
|
|
423
|
+
const close = part(kit, 'drawer-close', BUTTON, { tag: 'button', ariaLabel: words.closeMenu }, 'button-ghost', NavRole.DrawerClose, { ...MENU_BUTTON_LAY });
|
|
420
424
|
close.children = [iconNode(kit, 'drawer-close-icon', CLOSE_ICON)];
|
|
421
425
|
close.interactions = [clickTo(kit, 'drawer-close', NavDialogAction.Close, dr.id)];
|
|
422
426
|
head.children = [part(kit, 'drawer-brand', HEADING, { content: brandWords, level: 'h3' }, 'h3'), close];
|
|
@@ -426,7 +430,7 @@ function drawer(kit: Kit, root: SerializedNode, pages: NavPage[], at: string): S
|
|
|
426
430
|
// beat one inherited from the list). The links rest at the body weight and the CURRENT page reads by its ink and
|
|
427
431
|
// weight (no line since 2026-11-22) — the shared CSS keys that on the list's role (iox-design.css), so no Link holds
|
|
428
432
|
// a literal over its element style.
|
|
429
|
-
list.children = withHome(root, pages).map((p, i) => pageLink(kit, `drawer-link-${i}`, p, NavRole.DrawerLink,
|
|
433
|
+
list.children = withHome(root, pages, words).map((p, i) => pageLink(kit, `drawer-link-${i}`, p, NavRole.DrawerLink,
|
|
430
434
|
{ display: 'flex', alignItems: 'center', minHeight: '48px', fontSize: 'var(--iox-size-lead)' }));
|
|
431
435
|
dr.children = [head, list];
|
|
432
436
|
const cta = find([root], NavRole.Cta);
|
|
@@ -510,35 +514,35 @@ const BAR_ITEM_LAY = {
|
|
|
510
514
|
flexGrow: '1', flexShrink: '1', flexBasis: '0px', minWidth: '0px', minHeight: '52px', padding: '4px 2px', textDecoration: 'none',
|
|
511
515
|
};
|
|
512
516
|
|
|
513
|
-
function moreItem(kit: Kit, drawerId: string): SerializedNode {
|
|
517
|
+
function moreItem(kit: Kit, drawerId: string, words: MenuWords): SerializedNode {
|
|
514
518
|
const more = part(kit, 'bar-more', BUTTON, { tag: 'button' }, 'bottom-bar-item', NavRole.More, BAR_ITEM_LAY);
|
|
515
|
-
more.children = [iconNode(kit, 'bar-more-icon', MORE_ICON), labelText(kit, 'bar-more-label',
|
|
519
|
+
more.children = [iconNode(kit, 'bar-more-icon', MORE_ICON), labelText(kit, 'bar-more-label', words.more)];
|
|
516
520
|
more.interactions = [clickTo(kit, 'bar-more', NavDialogAction.Toggle, drawerId)];
|
|
517
521
|
return more;
|
|
518
522
|
}
|
|
519
523
|
|
|
520
524
|
/** Home first, then the header's pages: the header reaches Home through its brand, a phone menu names it. */
|
|
521
|
-
function withHome(root: SerializedNode, pages: NavPage[]): NavPage[] {
|
|
525
|
+
function withHome(root: SerializedNode, pages: NavPage[], words: MenuWords): NavPage[] {
|
|
522
526
|
const brand = find([root], NavRole.Brand);
|
|
523
527
|
const home = brand && isPageLink(brand) && prop(brand, 'pageRoute') === HOME_ROUTE && !pages.some(p => p.route === HOME_ROUTE)
|
|
524
|
-
? [{ label:
|
|
528
|
+
? [{ label: words.home, route: HOME_ROUTE }] : [];
|
|
525
529
|
return [...home, ...pages];
|
|
526
530
|
}
|
|
527
531
|
|
|
528
532
|
/** The bar's pages: Home first (a bottom bar's customary first stop), capped. */
|
|
529
|
-
function barPages(root: SerializedNode, pages: NavPage[], count: number): NavPage[] {
|
|
530
|
-
return withHome(root, pages).slice(0, count);
|
|
533
|
+
function barPages(root: SerializedNode, pages: NavPage[], count: number, words: MenuWords): NavPage[] {
|
|
534
|
+
return withHome(root, pages, words).slice(0, count);
|
|
531
535
|
}
|
|
532
536
|
|
|
533
|
-
function bar(kit: Kit, root: SerializedNode, pages: NavPage[], shape: NavShape, count: number, drawerId: string | null, at: string): SerializedNode {
|
|
537
|
+
function bar(kit: Kit, root: SerializedNode, pages: NavPage[], shape: NavShape, count: number, drawerId: string | null, at: string, words: MenuWords): SerializedNode {
|
|
534
538
|
// The node IS fixed (not only its element style): the builder canvas forces a node's own `position`
|
|
535
539
|
// with !important, so a stored `static` default would pin the bar into the flow there.
|
|
536
540
|
const b = part(kit, 'bar', CONTAINER, { htmlTag: 'nav' }, 'bottom-bar', NavRole.Bar,
|
|
537
541
|
{ position: 'fixed', justifyContent: 'space-around', alignItems: 'stretch', gap: '4px', padding: '6px 8px', width: 'auto' });
|
|
538
542
|
phoneOnly(b, at, 'flex');
|
|
539
543
|
const itemCount = shape === NavShape.Both ? count - 1 : count;
|
|
540
|
-
b.children = barPages(root, pages, itemCount).map((p, i) => barItem(kit, i, p));
|
|
541
|
-
if (shape === NavShape.Both && drawerId) b.children.push(moreItem(kit, drawerId));
|
|
544
|
+
b.children = barPages(root, pages, itemCount, words).map((p, i) => barItem(kit, i, p));
|
|
545
|
+
if (shape === NavShape.Both && drawerId) b.children.push(moreItem(kit, drawerId, words));
|
|
542
546
|
b.isGlobal = true;
|
|
543
547
|
b.globalPosition = PatternGlobalPosition.After;
|
|
544
548
|
return b;
|
|
@@ -651,6 +655,7 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
|
|
|
651
655
|
const everyWidth = shape === NavShape.Drawer && (options.everyWidth ?? wasEveryWidth);
|
|
652
656
|
if (options.everyWidth && shape !== NavShape.Drawer) throw new NavShapeError('only a drawer menu shows at every width');
|
|
653
657
|
const kit = makeKit(out, root.id, options.newId);
|
|
658
|
+
const words = menuWords(options.locale);
|
|
654
659
|
|
|
655
660
|
adoptRoles(root);
|
|
656
661
|
const { pages } = phoneMenuPages(root, options.pages);
|
|
@@ -663,7 +668,7 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
|
|
|
663
668
|
const topIndex = out.findIndex(g => g.role === NavRole.Drawer);
|
|
664
669
|
if (!dr && topIndex >= 0) dr = out.splice(topIndex, 1)[0];
|
|
665
670
|
if (dr) { delete dr.isGlobal; delete dr.globalPosition; }
|
|
666
|
-
if (wantDrawer && !dr) dr = drawer(kit, root, pages, at);
|
|
671
|
+
if (wantDrawer && !dr) dr = drawer(kit, root, pages, at, words);
|
|
667
672
|
if (!wantDrawer) dr = null;
|
|
668
673
|
// A drawer reached at every width never closes itself above a breakpoint.
|
|
669
674
|
if (dr) dr.props = { ...dr.props, closeAbove: everyWidth ? '' : at };
|
|
@@ -672,7 +677,7 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
|
|
|
672
677
|
if (options.menuSide !== undefined && !(Object.values(MenuSide) as string[]).includes(options.menuSide)) throw new NavShapeError(`a menu button cannot sit at "${options.menuSide}"`);
|
|
673
678
|
const was = menuPlace(root);
|
|
674
679
|
const existingMenu = removeRole(root, NavRole.MenuButton);
|
|
675
|
-
const menu = wantMenuButton ? (existingMenu ? asToggle(existingMenu) : menuButton(kit, dr!.id, at)) : null;
|
|
680
|
+
const menu = wantMenuButton ? (existingMenu ? asToggle(existingMenu) : menuButton(kit, dr!.id, at, words)) : null;
|
|
676
681
|
|
|
677
682
|
for (const p of phoneHiddenParts(root)) {
|
|
678
683
|
if (everyWidth && !KEPT_AT_EVERY_WIDTH.has(roleOf(p))) { displayEverywhere(p, NONE); continue; }
|
|
@@ -713,7 +718,7 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
|
|
|
713
718
|
let more: SerializedNode | null = null;
|
|
714
719
|
if (wantBar) {
|
|
715
720
|
const count = clampBarCount(options.barItems, shape);
|
|
716
|
-
if (!b) b = bar(kit, root, pages, shape, count, dr?.id ?? null, at);
|
|
721
|
+
if (!b) b = bar(kit, root, pages, shape, count, dr?.id ?? null, at, words);
|
|
717
722
|
else {
|
|
718
723
|
moveDisplayOverride(b, at);
|
|
719
724
|
more = (b.children ?? []).find(c => c.role === NavRole.More) ?? null;
|
|
@@ -721,11 +726,11 @@ export function planNavShape(globals: ReadonlyArray<SerializedNode>, shape: NavS
|
|
|
721
726
|
if (options.barItems !== undefined) {
|
|
722
727
|
const items = b.children;
|
|
723
728
|
const want = shape === NavShape.Both ? count - 1 : count;
|
|
724
|
-
const extra = barPages(root, pages, BAR_ITEMS_MAX).filter(p => !items.some(c => prop(c, 'pageRoute') === p.route));
|
|
729
|
+
const extra = barPages(root, pages, BAR_ITEMS_MAX, words).filter(p => !items.some(c => prop(c, 'pageRoute') === p.route));
|
|
725
730
|
while (items.length > want) items.pop();
|
|
726
731
|
while (items.length < want && extra.length) items.push(barItem(kit, items.length, extra.shift()!));
|
|
727
732
|
}
|
|
728
|
-
if (shape === NavShape.Both && dr) b.children.push(retarget(more ?? moreItem(kit, dr.id), dr.id));
|
|
733
|
+
if (shape === NavShape.Both && dr) b.children.push(retarget(more ?? moreItem(kit, dr.id, words), dr.id));
|
|
729
734
|
}
|
|
730
735
|
out.push(b);
|
|
731
736
|
}
|
|
@@ -776,7 +781,7 @@ export interface AddBarItemResult {
|
|
|
776
781
|
* The bar's Items list "Add item" (board 2): one more item, before More — the next navigation page the
|
|
777
782
|
* bar does not link to yet (Home when every page is there). Refused at five (Q2). Input not mutated.
|
|
778
783
|
*/
|
|
779
|
-
export function addBarItem(globals: ReadonlyArray<SerializedNode>, options: Pick<NavShapeOptions, 'newId' | 'pages'> = {}): AddBarItemResult {
|
|
784
|
+
export function addBarItem(globals: ReadonlyArray<SerializedNode>, options: Pick<NavShapeOptions, 'newId' | 'pages' | 'locale'> = {}): AddBarItemResult {
|
|
780
785
|
const out = clone(globals) as SerializedNode[];
|
|
781
786
|
const root = findNavRoot(out);
|
|
782
787
|
const b = find(out, NavRole.Bar);
|
|
@@ -784,8 +789,9 @@ export function addBarItem(globals: ReadonlyArray<SerializedNode>, options: Pick
|
|
|
784
789
|
const kids = b.children ?? (b.children = []);
|
|
785
790
|
if (kids.length >= BAR_ITEMS_MAX) return { globals: out, added: false };
|
|
786
791
|
const linked = new Set(kids.filter(c => c.role === NavRole.BarItem).map(c => prop(c, 'pageRoute')));
|
|
787
|
-
const
|
|
788
|
-
|
|
792
|
+
const words = menuWords(options.locale);
|
|
793
|
+
const page = barPages(root, phoneMenuPages(root, options.pages).pages, BAR_ITEMS_MAX + 1, words).find(p => !linked.has(p.route))
|
|
794
|
+
?? { label: words.home, route: HOME_ROUTE };
|
|
789
795
|
const item = barItem(makeKit(out, root.id, options.newId), kids.length, page);
|
|
790
796
|
const more = kids.findIndex(c => c.role === NavRole.More);
|
|
791
797
|
if (more >= 0) kids.splice(more, 0, item); else kids.push(item);
|