@vectoriox/iox-ui 5.98.0 → 5.100.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.
Files changed (43) hide show
  1. package/actions-core/index.d.ts +7 -4
  2. package/composite-core/index.d.ts +222 -2
  3. package/design-core/index.d.ts +334 -1
  4. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +16 -7
  5. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +948 -256
  7. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs +416 -1
  9. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-forms-core.mjs +3 -24
  11. package/fesm2022/vectoriox-iox-ui-forms-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +23 -13
  13. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  14. package/fesm2022/vectoriox-iox-ui-identity-core.mjs +633 -0
  15. package/fesm2022/vectoriox-iox-ui-identity-core.mjs.map +1 -0
  16. package/fesm2022/vectoriox-iox-ui.mjs +2 -59
  17. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  18. package/forms-core/index.d.ts +2 -23
  19. package/generation-core/index.d.ts +3 -1
  20. package/identity-core/index.d.ts +426 -0
  21. package/identity-core/package.json +3 -0
  22. package/index.d.ts +0 -1
  23. package/package.json +5 -1
  24. package/src/actions-core/action.model.ts +1 -1
  25. package/src/actions-core/element-actions.ts +16 -6
  26. package/src/composite-core/account-runtime.ts +428 -0
  27. package/src/composite-core/account.ts +281 -0
  28. package/src/composite-core/public-api.ts +2 -0
  29. package/src/composite-core/recipe-parts.ts +48 -0
  30. package/src/composite-core/shop.ts +6 -26
  31. package/src/design-core/field-classes.ts +65 -0
  32. package/src/design-core/flavor-spec.generated.ts +346 -0
  33. package/src/design-core/public-api.ts +1 -0
  34. package/src/forms-core/field-markup.ts +2 -22
  35. package/src/generation-core/compose-site.ts +19 -9
  36. package/src/generation-core/nav-shape.ts +4 -4
  37. package/src/identity-core/guards.ts +87 -0
  38. package/src/identity-core/public-api.ts +14 -0
  39. package/src/identity-core/sign-in.ts +223 -0
  40. package/src/identity-core/site-auth-transport.ts +134 -0
  41. package/src/identity-core/site-auth.ts +182 -0
  42. package/src/identity-core/words.ts +194 -0
  43. package/styles/iox-design.css +38 -0
@@ -0,0 +1,281 @@
1
+ import { roleClass } from '@vectoriox/iox-ui/design-core';
2
+ import { CUSTOMER_SLOT, EMAIL_CODE_TTL_MINUTES, SignInLanguage, signInLanguage, SignInWord, signInWord } from '@vectoriox/iox-ui/identity-core';
3
+
4
+ import { CompositeNode, CompositeNodeFactory, writeProp } from './composite-node';
5
+ import { bindSlot, COLUMN, onClick, recipeButton, recipeIcon, recipePart, recipeText, ROW, WORDS, ZERO } from './recipe-parts';
6
+
7
+ /**
8
+ * THE ACCOUNT PARTS (commerce E3a, C-D5/C-D6 — commerce board 12). Recipes of ordinary builder nodes with roles, like the
9
+ * shop parts, run by ONE DOM runtime (`account-runtime.ts`) over the host's `SiteAuthTransport` — the same on the builder
10
+ * canvas (simulated) and the live site. Buying never needs an account (C-D4): every part is optional.
11
+ *
12
+ * Account entry Container account › ButtonBlock account.entry (`account-button`)
13
+ * › Icon · Text account.sign-in-label "Sign in"
14
+ * · Container account.avatar (`account-avatar`) › Text $customer.initial · Text account.name $customer.name
15
+ * · Popover account.menu › Text account.menu-greeting · ButtonBlock account.orders (a link to the
16
+ * account page) · ButtonBlock account.sign-out (signOut)
17
+ * Sign-in dialog Dialog account.sign-in › head (Heading account.title · Close) · Text account.why
18
+ * · ButtonBlock account.google "Continue with Google" · Text account.provider-error · Text account.or
19
+ * · Container account.email-step › Field account.email · ButtonBlock account.send-code
20
+ * · Container account.code-step › Text account.code-sent · Field account.code · ButtonBlock account.verify
21
+ * · row (Text account.code-valid · Send again · Use another email)
22
+ * · Text account.dialog-error
23
+ *
24
+ * Words are the recipe's in English (board 12); the runtime writes the visitor's language over the ones it owns
25
+ * (the code-sent line, refusals) and a studio edits the rest like any Text.
26
+ */
27
+
28
+ export enum AccountRole {
29
+ Account = 'account',
30
+ Entry = 'account.entry',
31
+ SignInLabel = 'account.sign-in-label',
32
+ Avatar = 'account.avatar',
33
+ Initial = 'account.initial',
34
+ Name = 'account.name',
35
+ Menu = 'account.menu',
36
+ MenuGreeting = 'account.menu-greeting',
37
+ Orders = 'account.orders',
38
+ SignOut = 'account.sign-out',
39
+ SignIn = 'account.sign-in',
40
+ Title = 'account.title',
41
+ Close = 'account.close',
42
+ Why = 'account.why',
43
+ Google = 'account.google',
44
+ ProviderError = 'account.provider-error',
45
+ Or = 'account.or',
46
+ EmailStep = 'account.email-step',
47
+ Email = 'account.email',
48
+ SendCode = 'account.send-code',
49
+ CodeStep = 'account.code-step',
50
+ CodeSent = 'account.code-sent',
51
+ Code = 'account.code',
52
+ Verify = 'account.verify',
53
+ CodeValid = 'account.code-valid',
54
+ SendAgain = 'account.send-again',
55
+ OtherEmail = 'account.other-email',
56
+ DialogError = 'account.dialog-error',
57
+ }
58
+
59
+ export const ACCOUNT_ROLES: ReadonlySet<string> = new Set(Object.values(AccountRole));
60
+
61
+ export function isAccountRole(role: string | null | undefined): boolean {
62
+ return !!role && ACCOUNT_ROLES.has(role);
63
+ }
64
+
65
+ /** The CSS selector of an account role (`.iox-role-account-entry`). */
66
+ export function accountSelector(role: AccountRole): string {
67
+ return `.${roleClass(role)}`;
68
+ }
69
+
70
+ /** On the account root and the dialog: the buyer is signed in (the shared CSS swaps "Sign in" for the initial). */
71
+ export const SIGNED_IN_ATTRIBUTE = 'data-iox-signed-in';
72
+ /** On the sign-in dialog: `email` (asking for an email) or `code` (asking for the code just sent). */
73
+ export const SIGN_IN_STEP_ATTRIBUTE = 'data-iox-sign-in-step';
74
+ /** On a part the runtime has no words for right now (an empty error line). */
75
+ export const ACCOUNT_HIDDEN_ATTRIBUTE = 'data-iox-account-hidden';
76
+ /** The polite live region the account speaks in ("You are signed in."). */
77
+ export const ACCOUNT_LIVE_CLASS = 'iox-account-live';
78
+
79
+ export enum SignInStep {
80
+ Email = 'email',
81
+ Code = 'code',
82
+ }
83
+
84
+ /** The Field names the dialog's two inputs submit under. */
85
+ export enum SignInFieldName {
86
+ Email = 'email',
87
+ Code = 'code',
88
+ }
89
+
90
+ /** The words a fresh recipe shows in `lang` (board 12's sample) — the studio edits them like any Text; the composer
91
+ * stamps them in the site's language. */
92
+ export function accountRecipeWords(lang: string | null | undefined = 'en') {
93
+ const w = (word: SignInWord, fill: Readonly<Record<string, string | number>> = {}) => signInWord(word, lang, fill);
94
+ const name = signInLanguage(lang) === SignInLanguage.He ? 'נועה' : 'Noa';
95
+ return Object.freeze({
96
+ signIn: w(SignInWord.SignIn),
97
+ initial: Array.from(name)[0],
98
+ name,
99
+ greeting: w(SignInWord.Hello, { name }),
100
+ orders: w(SignInWord.YourOrders),
101
+ signOut: w(SignInWord.SignOut),
102
+ title: w(SignInWord.SignIn),
103
+ close: w(SignInWord.Close),
104
+ why: w(SignInWord.Why),
105
+ google: w(SignInWord.ContinueWithGoogle),
106
+ or: w(SignInWord.Or),
107
+ email: w(SignInWord.Email),
108
+ emailPlaceholder: w(SignInWord.EmailPlaceholder),
109
+ sendCode: w(SignInWord.SendCode),
110
+ codeSent: w(SignInWord.CodeSent, { email: 'noa.levi@example.com' }),
111
+ code: w(SignInWord.Code),
112
+ verify: w(SignInWord.Verify),
113
+ codeValid: w(SignInWord.CodeValid, { minutes: EMAIL_CODE_TTL_MINUTES }),
114
+ sendAgain: w(SignInWord.SendAgain),
115
+ otherEmail: w(SignInWord.OtherEmail),
116
+ });
117
+ }
118
+
119
+ export type AccountRecipeWords = ReturnType<typeof accountRecipeWords>;
120
+
121
+ /** The English sample (the palette's — the canvas has no page language yet). */
122
+ export const ACCOUNT_RECIPE_WORDS: AccountRecipeWords = accountRecipeWords('en');
123
+
124
+ export const ACCOUNT_LABELS = Object.freeze({ account: 'Account entry', menu: 'Account menu', signIn: 'Sign-in dialog' });
125
+
126
+ enum Style {
127
+ AccountButton = 'account-button',
128
+ Avatar = 'account-avatar',
129
+ Label = 'button-label',
130
+ Primary = 'button-primary',
131
+ Secondary = 'button-secondary',
132
+ Ghost = 'button-ghost',
133
+ Small = 'small',
134
+ Body = 'body',
135
+ Error = 'sign-in-error',
136
+ Dialog = 'dialog',
137
+ Popover = 'popover',
138
+ Title = 'h3',
139
+ Field = 'field',
140
+ }
141
+
142
+ const PILL = { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 'auto', height: 'auto' };
143
+ const FULL = { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: '100%', height: 'auto' };
144
+ const TEXT_BUTTON = { padding: '4px 4px 4px 4px', width: 'auto', height: 'auto', minHeight: 'auto' };
145
+ /** "Sign in" and the initial share ONE grid cell, so the entry never jumps as the buyer signs in (Emil: in place). */
146
+ const STACKED = { gridColumn: '1', gridRow: '1' };
147
+
148
+ function words(create: CompositeNodeFactory, key: string, role: AccountRole | null, style: Style, text: string, label: string,
149
+ base: Readonly<Record<string, string>> = WORDS, tag = 'p'): CompositeNode {
150
+ return recipeText(create, key, role, style, text, label, base, tag);
151
+ }
152
+
153
+ function labelled(create: CompositeNodeFactory, key: string, role: AccountRole, style: Style, text: string, label: string,
154
+ base: Readonly<Record<string, string>>, labelStyle: Style = Style.Label): CompositeNode {
155
+ const root = recipeButton(create, key, role, style, label, '', base);
156
+ root.children = [words(create, `${key}-label`, null, labelStyle, text, 'Text', WORDS, 'span')];
157
+ return root;
158
+ }
159
+
160
+ function field(create: CompositeNodeFactory, key: string, role: AccountRole, name: SignInFieldName, control: string, label: string,
161
+ placeholder: string): CompositeNode {
162
+ return recipePart(create, key, 'Field', role, Style.Field, { control, label, name, placeholder, required: true }, label,
163
+ { width: '100%', minHeight: 'auto', margin: ZERO });
164
+ }
165
+
166
+ /** The menu a signed-in buyer opens from the account button: hello, their orders, sign out. */
167
+ export function buildAccountMenuRecipe(create: CompositeNodeFactory, lang: string | null = 'en'): CompositeNode {
168
+ const t = accountRecipeWords(lang);
169
+ const menu = recipePart(create, 'account-menu', 'Popover', AccountRole.Menu, Style.Popover, {}, ACCOUNT_LABELS.menu,
170
+ { display: 'flex', flexDirection: 'column', alignItems: 'stretch', width: '220px', height: 'auto', minHeight: 'auto', gap: '4px' });
171
+ writeProp(menu, 'placement', 'below');
172
+ writeProp(menu, 'ariaLabel', t.title);
173
+ const greeting = words(create, 'account-menu-greeting', AccountRole.MenuGreeting, Style.Body, t.greeting, 'Greeting',
174
+ { ...WORDS, margin: '0px 0px 6px 0px', fontWeight: '600' });
175
+ const orders = recipePart(create, 'account-orders', 'ButtonBlock', AccountRole.Orders, Style.Ghost,
176
+ { tag: 'a', linkType: 'external', href: '/account', target: '_self' }, 'Your orders', { ...TEXT_BUTTON, justifyContent: 'flex-start', width: '100%' });
177
+ orders.children = [words(create, 'account-orders-label', null, Style.Label, t.orders, 'Text', WORDS, 'span')];
178
+ const signOut = labelled(create, 'account-sign-out', AccountRole.SignOut, Style.Ghost, t.signOut, 'Sign out',
179
+ { ...TEXT_BUTTON, justifyContent: 'flex-start', width: '100%' });
180
+ onClick(signOut, 'signOut');
181
+ menu.children = [greeting, orders, signOut];
182
+ return menu;
183
+ }
184
+
185
+ /**
186
+ * The header's account entry: "Sign in" while signed out, the buyer's initial and name once signed in ($customer). A
187
+ * press opens the page's sign-in dialog, or — signed in — the menu beside it. The menu is part of the entry.
188
+ */
189
+ export function buildAccountEntryRecipe(create: CompositeNodeFactory, lang: string | null = 'en'): CompositeNode {
190
+ const t = accountRecipeWords(lang);
191
+ const root = recipePart(create, 'account', 'Container', AccountRole.Account, null, {}, ACCOUNT_LABELS.account, { ...ROW, gap: '0px' });
192
+ const entry = recipeButton(create, 'account-entry', AccountRole.Entry, Style.AccountButton, 'Account button', t.signIn,
193
+ { ...PILL, display: 'inline-grid', gridTemplateColumns: 'auto', alignItems: 'center', justifyItems: 'center' });
194
+ const signedOut = recipePart(create, 'account-signed-out', 'Container', null, null, {}, 'Signed out',
195
+ { ...ROW, ...STACKED, gap: '6px' });
196
+ signedOut.children = [
197
+ recipeIcon(create, 'account-icon', 'ph ph-user-circle', '18px'),
198
+ words(create, 'account-sign-in-label', AccountRole.SignInLabel, Style.Label, t.signIn, 'Sign in', WORDS, 'span'),
199
+ ];
200
+ const signedIn = recipePart(create, 'account-signed-in', 'Container', null, null, {}, 'Signed in', { ...ROW, ...STACKED, gap: '8px' });
201
+ const avatar = recipePart(create, 'account-avatar', 'Container', AccountRole.Avatar, Style.Avatar, {}, 'Initial',
202
+ { ...PILL, minHeight: 'var(--iox-account-avatar-size)', padding: ZERO });
203
+ const initial = words(create, 'account-initial', AccountRole.Initial, Style.Label, t.initial, 'Initial',
204
+ { ...WORDS, lineHeight: '1' }, 'span');
205
+ bindSlot(initial, 'content', CUSTOMER_SLOT, 'initial');
206
+ avatar.children = [initial];
207
+ const name = words(create, 'account-name', AccountRole.Name, Style.Label, t.name, 'Name', WORDS, 'span');
208
+ bindSlot(name, 'content', CUSTOMER_SLOT, 'name');
209
+ signedIn.children = [avatar, name];
210
+ entry.children = [signedOut, signedIn];
211
+ root.children = [entry, buildAccountMenuRecipe(create, lang)];
212
+ return root;
213
+ }
214
+
215
+ /** The sign-in dialog (board 12): Google, or an email and the six-digit code sent to it. Never a password. */
216
+ export function buildSignInDialogRecipe(create: CompositeNodeFactory, lang: string | null = 'en'): CompositeNode {
217
+ const t = accountRecipeWords(lang);
218
+ const dialog = recipePart(create, 'sign-in', 'Dialog', AccountRole.SignIn, Style.Dialog, {}, ACCOUNT_LABELS.signIn,
219
+ { width: '400px', maxWidth: '100%', display: 'flex', flexDirection: 'column', gap: '14px' });
220
+ writeProp(dialog, 'placement', 'center');
221
+ writeProp(dialog, 'closeOnBackdrop', true);
222
+ writeProp(dialog, 'showCloseButton', false);
223
+ writeProp(dialog, 'ariaLabel', t.title);
224
+
225
+ const head = recipePart(create, 'sign-in-head', 'Container', null, null, {}, 'Head', { ...ROW, width: '100%', justifyContent: 'space-between', gap: '12px' });
226
+ const title = recipePart(create, 'sign-in-title', 'Heading', AccountRole.Title, Style.Title, { content: t.title, level: 'h2' }, 'Title', WORDS);
227
+ const close = labelled(create, 'sign-in-close', AccountRole.Close, Style.Ghost, t.close, 'Close', TEXT_BUTTON, Style.Small);
228
+ onClick(close, 'closeDialog', dialog.id ?? '');
229
+ head.children = [title, close];
230
+
231
+ const why = words(create, 'sign-in-why', AccountRole.Why, Style.Small, t.why, 'Why sign in');
232
+ const google = recipeButton(create, 'sign-in-google', AccountRole.Google, Style.Secondary, 'Continue with Google', '', { ...FULL, gap: '8px' });
233
+ google.children = [
234
+ recipeIcon(create, 'sign-in-google-icon', 'ph ph-google-logo', '18px'),
235
+ words(create, 'sign-in-google-label', null, Style.Label, t.google, 'Text', WORDS, 'span'),
236
+ ];
237
+ const providerError = words(create, 'sign-in-provider-error', AccountRole.ProviderError, Style.Error, '', 'Google error');
238
+ const or = words(create, 'sign-in-or', AccountRole.Or, Style.Small, t.or, 'Or', { ...WORDS, width: '100%', textAlign: 'center' });
239
+
240
+ const emailStep = recipePart(create, 'sign-in-email-step', 'Container', AccountRole.EmailStep, null, {}, 'Email step', { ...COLUMN, gap: '10px' });
241
+ const sendCode = labelled(create, 'sign-in-send-code', AccountRole.SendCode, Style.Primary, t.sendCode, 'Send me a code', FULL);
242
+ emailStep.children = [
243
+ field(create, 'sign-in-email', AccountRole.Email, SignInFieldName.Email, 'email', t.email, t.emailPlaceholder),
244
+ sendCode,
245
+ ];
246
+
247
+ const codeStep = recipePart(create, 'sign-in-code-step', 'Container', AccountRole.CodeStep, null, {}, 'Code step', { ...COLUMN, gap: '10px' });
248
+ const sent = words(create, 'sign-in-code-sent', AccountRole.CodeSent, Style.Small, t.codeSent, 'Code sent to');
249
+ const verify = labelled(create, 'sign-in-verify', AccountRole.Verify, Style.Primary, t.verify, 'Sign in', FULL);
250
+ const again = recipePart(create, 'sign-in-again', 'Container', null, null, {}, 'Send again', { ...ROW, flexWrap: 'wrap', gap: '4px 12px' });
251
+ again.children = [
252
+ words(create, 'sign-in-code-valid', AccountRole.CodeValid, Style.Small, t.codeValid, 'Valid for', WORDS, 'span'),
253
+ labelled(create, 'sign-in-send-again', AccountRole.SendAgain, Style.Ghost, t.sendAgain, 'Send again', TEXT_BUTTON, Style.Small),
254
+ labelled(create, 'sign-in-other-email', AccountRole.OtherEmail, Style.Ghost, t.otherEmail, 'Use another email', TEXT_BUTTON, Style.Small),
255
+ ];
256
+ codeStep.children = [
257
+ sent,
258
+ field(create, 'sign-in-code', AccountRole.Code, SignInFieldName.Code, 'text', t.code, ''),
259
+ verify,
260
+ again,
261
+ ];
262
+ const dialogError = words(create, 'sign-in-dialog-error', AccountRole.DialogError, Style.Error, '', 'Error');
263
+ dialog.children = [head, why, google, providerError, or, emailStep, codeStep, dialogError];
264
+ return dialog;
265
+ }
266
+
267
+ /** The account recipes, by name. */
268
+ export enum AccountRecipe {
269
+ Entry = 'accountEntry',
270
+ Menu = 'accountMenu',
271
+ SignInDialog = 'signInDialog',
272
+ }
273
+
274
+ export const ACCOUNT_RECIPES: Readonly<Record<AccountRecipe, (create: CompositeNodeFactory, lang?: string | null) => CompositeNode>> = Object.freeze({
275
+ [AccountRecipe.Entry]: buildAccountEntryRecipe,
276
+ [AccountRecipe.Menu]: buildAccountMenuRecipe,
277
+ [AccountRecipe.SignInDialog]: buildSignInDialogRecipe,
278
+ });
279
+
280
+ /** The recipe a site holds ONCE, as a global element after the page — every page's entry opens it. */
281
+ export const ACCOUNT_GLOBAL_RECIPES: ReadonlySet<AccountRecipe> = new Set([AccountRecipe.SignInDialog]);
@@ -30,3 +30,5 @@ export * from './marquee-runtime';
30
30
  export * from './scroll-recipes';
31
31
  export * from './shop';
32
32
  export * from './shop-runtime';
33
+ export * from './account';
34
+ export * from './account-runtime';
@@ -0,0 +1,48 @@
1
+ import { CompositeNode, CompositeNodeFactory, makeCompositePart } from './composite-node';
2
+
3
+ /**
4
+ * The small builders the commerce recipes share (shop.ts — E1c, account.ts — E3a): a part, its words, an icon, a button,
5
+ * a click that runs one action, a binding to a context slot. Internal to composite-core — not part of its public API.
6
+ */
7
+
8
+ export const ZERO = '0px 0px 0px 0px';
9
+ /** Words that take their own size (a recipe never stamps a Text's 10px or a box's 200px — W1.1 `BASELINE_ROLES`). */
10
+ export const WORDS: Readonly<Record<string, string>> = { width: 'auto', minHeight: 'auto', padding: ZERO, margin: ZERO };
11
+ export const ROW = { display: 'flex', flexDirection: 'row', alignItems: 'center', width: 'auto', height: 'auto', minHeight: 'auto', padding: ZERO };
12
+ export const COLUMN = { display: 'flex', flexDirection: 'column', alignItems: 'stretch', width: '100%', height: 'auto', minHeight: 'auto', padding: ZERO };
13
+
14
+ interface Wired { interactions?: unknown[]; bindings?: unknown[] }
15
+
16
+ /** A click on `node` runs one action (`target` '' = the runtime finds its own). */
17
+ export function onClick(node: CompositeNode, type: string, target = ''): void {
18
+ (node as Wired).interactions = [{
19
+ id: `${node.id ?? 'node'}-click`, trigger: 'click',
20
+ actions: [{ type, target, duration: 0, delay: 0, easing: 'ease' }],
21
+ }];
22
+ }
23
+
24
+ /** Bind `prop` to a context slot path, through the money pipe when asked. */
25
+ export function bindSlot(node: CompositeNode, prop: string, source: string, path: string, money = false): void {
26
+ const bindings = ((node as Wired).bindings ?? []).filter(b => (b as { prop?: string }).prop !== prop);
27
+ bindings.push({ prop, source, path, ...(money ? { pipes: [{ name: 'money', args: [] }] } : {}) });
28
+ (node as Wired).bindings = bindings;
29
+ }
30
+
31
+ export function recipePart(create: CompositeNodeFactory, key: string, type: string, role: string | null, style: string | null,
32
+ props: Record<string, unknown>, label: string, base?: Readonly<Record<string, string>>): CompositeNode {
33
+ return makeCompositePart(create, { key, type, props, elementStyle: style ?? undefined }, role, label, base);
34
+ }
35
+
36
+ export function recipeText(create: CompositeNodeFactory, key: string, role: string | null, style: string, words: string, label: string,
37
+ base: Readonly<Record<string, string>> = WORDS, tag = 'p'): CompositeNode {
38
+ return recipePart(create, key, 'Text', role, style, { content: words, tag }, label, base);
39
+ }
40
+
41
+ export function recipeIcon(create: CompositeNodeFactory, key: string, iconClass: string, size = '18px'): CompositeNode {
42
+ return recipePart(create, key, 'Icon', null, 'icon', { iconClass }, 'Icon', { fontSize: size, color: 'inherit' });
43
+ }
44
+
45
+ export function recipeButton(create: CompositeNodeFactory, key: string, role: string, style: string, label: string, ariaLabel = '',
46
+ base: Readonly<Record<string, string>> = {}): CompositeNode {
47
+ return recipePart(create, key, 'ButtonBlock', role, style, { tag: 'button', type: 'button', ...(ariaLabel ? { ariaLabel } : {}) }, label, base);
48
+ }
@@ -2,7 +2,8 @@ import { ShopWord, shopWord } from '@vectoriox/iox-ui/commerce-core';
2
2
  import type { ProductOption } from '@vectoriox/iox-ui/commerce-core';
3
3
  import { roleClass } from '@vectoriox/iox-ui/design-core';
4
4
 
5
- import { CompositeNode, CompositeNodeFactory, findByRole, makeCompositePart, writeProp } from './composite-node';
5
+ import { CompositeNode, CompositeNodeFactory, findByRole, writeProp } from './composite-node';
6
+ import { bindSlot, COLUMN, onClick, recipeButton, recipeIcon, recipePart, recipeText, ROW, WORDS, ZERO } from './recipe-parts';
6
7
 
7
8
  /**
8
9
  * THE SHOP PARTS (commerce E1c, C-D16 — commerce board 10). Not components: recipes of ordinary builder nodes, each part
@@ -232,47 +233,26 @@ export const SHOP_LABELS = Object.freeze({
232
233
  price: 'Price', variants: 'Options', quantity: 'Quantity', add: 'Add to cart', buyNow: 'Buy now', cartButton: 'Cart button', cartDrawer: 'Cart drawer',
233
234
  });
234
235
 
235
- const ZERO = '0px 0px 0px 0px';
236
- const WORDS: Readonly<Record<string, string>> = { width: 'auto', minHeight: 'auto', padding: ZERO, margin: ZERO };
237
- const ROW = { display: 'flex', flexDirection: 'row', alignItems: 'center', width: 'auto', height: 'auto', minHeight: 'auto', padding: ZERO };
238
- const COLUMN = { display: 'flex', flexDirection: 'column', alignItems: 'stretch', width: '100%', height: 'auto', minHeight: 'auto', padding: ZERO };
239
236
  /** "Add to cart" and "Added ✓" share ONE grid cell, so the button never changes width as they swap (Emil: in place). */
240
237
  const STACKED = { gridColumn: '1', gridRow: '1', ...WORDS };
241
238
 
242
- interface WithInteractions { interactions?: unknown[]; bindings?: unknown[] }
243
-
244
- /** A click on `node` runs one action (`target` '' = the runtime finds its own: the page's product, the page's drawer). */
245
- function onClick(node: CompositeNode, type: string, target = ''): void {
246
- (node as WithInteractions).interactions = [{
247
- id: `${node.id ?? 'node'}-click`, trigger: 'click',
248
- actions: [{ type, target, duration: 0, delay: 0, easing: 'ease' }],
249
- }];
250
- }
251
-
252
- /** Bind `prop` to a shop slot path, through the money pipe when asked. */
253
- function bindSlot(node: CompositeNode, prop: string, source: string, path: string, money = false): void {
254
- const bindings = ((node as WithInteractions).bindings ?? []).filter(b => (b as { prop?: string }).prop !== prop);
255
- bindings.push({ prop, source, path, ...(money ? { pipes: [{ name: 'money', args: [] }] } : {}) });
256
- (node as WithInteractions).bindings = bindings;
257
- }
258
-
259
239
  function part(create: CompositeNodeFactory, key: string, type: Type, role: ShopRole | null, style: Style | null,
260
240
  props: Record<string, unknown>, label: string, base?: Readonly<Record<string, string>>): CompositeNode {
261
- return makeCompositePart(create, { key, type, props, elementStyle: style ?? undefined }, role, label, base);
241
+ return recipePart(create, key, type, role, style, props, label, base);
262
242
  }
263
243
 
264
244
  function text(create: CompositeNodeFactory, key: string, role: ShopRole | null, style: Style, words: string, label: string,
265
245
  base: Readonly<Record<string, string>> = WORDS, tag = 'p'): CompositeNode {
266
- return part(create, key, Type.Text, role, style, { content: words, tag }, label, base);
246
+ return recipeText(create, key, role, style, words, label, base, tag);
267
247
  }
268
248
 
269
249
  function icon(create: CompositeNodeFactory, key: string, iconClass: string, size = '18px'): CompositeNode {
270
- return part(create, key, Type.Icon, null, Style.Icon, { iconClass }, 'Icon', { fontSize: size, color: 'inherit' });
250
+ return recipeIcon(create, key, iconClass, size);
271
251
  }
272
252
 
273
253
  function button(create: CompositeNodeFactory, key: string, role: ShopRole, style: Style, label: string, ariaLabel = '',
274
254
  base: Readonly<Record<string, string>> = {}): CompositeNode {
275
- return part(create, key, Type.ButtonBlock, role, style, { tag: 'button', type: 'button', ...(ariaLabel ? { ariaLabel } : {}) }, label, base);
255
+ return recipeButton(create, key, role, style, label, ariaLabel, base);
276
256
  }
277
257
 
278
258
  /** Price: the variant's price and, when it is higher, its earlier price struck through (board 10). */
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A rendered Field's classes and its error, in design-core because two entries write into a Field: forms-core (the
3
+ * string renderer's markup, the form runtimes) and composite-core (the sign-in dialog). composite-core may not import
4
+ * forms-core (forms-core → actions-core → composite-core would close a cycle), and design-core imports no other entry.
5
+ * forms-core re-exports all three names. Framework-free; the DOM is the caller's element.
6
+ */
7
+
8
+ /** The classes the markup carries — the runtimes and the shared CSS key on these, never on a literal. */
9
+ export enum FieldClass {
10
+ Root = 'iox-field',
11
+ Label = 'iox-field__label',
12
+ LabelHidden = 'iox-field__label--hidden',
13
+ Required = 'iox-field__required',
14
+ Control = 'iox-field__control',
15
+ Help = 'iox-field__help',
16
+ Error = 'iox-field__error',
17
+ Group = 'iox-field__group',
18
+ Option = 'iox-field__option',
19
+ Choices = 'iox-field__choices',
20
+ ChoicesChips = 'iox-field__choices--chips',
21
+ ChoicesList = 'iox-field__choices--list',
22
+ Chips = 'iox-field__chips',
23
+ Chip = 'iox-field__chip',
24
+ ChipInput = 'iox-field__control--chip',
25
+ DateButton = 'iox-field__control--date',
26
+ DateValue = 'iox-field__date-value',
27
+ DateIcon = 'iox-field__date-icon',
28
+ DateInput = 'iox-field__date-input',
29
+ }
30
+
31
+ /** A field's error class on its element (shared CSS keys on it). */
32
+ export const FIELD_INVALID_CLASS = 'iox-invalid';
33
+
34
+ /**
35
+ * Say `text` as a Field's error — or clear it with '' — exactly as `IoxFieldComponent` renders one: the error paragraph
36
+ * (`role=alert`, id `<control id>-error`) at the field's end, `aria-invalid` and `aria-describedby` (help first) on every
37
+ * control, the invalid class on the field. ONE copy for every runtime that writes into a rendered Field (the string-form
38
+ * runtime, the sign-in dialog).
39
+ */
40
+ export function writeFieldError(field: HTMLElement, text: string): void {
41
+ const controls = Array.from(field.querySelectorAll<HTMLElement>(`.${FieldClass.Control}`));
42
+ const id = (controls[0]?.id || `iox-field-${field.getAttribute('data-iox-field') ?? ''}`) + '-error';
43
+ let p = field.querySelector<HTMLElement>(`.${FieldClass.Error}`);
44
+ if (text) {
45
+ if (!p) {
46
+ p = field.ownerDocument.createElement('p');
47
+ p.className = FieldClass.Error;
48
+ p.id = id;
49
+ p.setAttribute('role', 'alert');
50
+ field.appendChild(p);
51
+ }
52
+ p.textContent = text;
53
+ } else {
54
+ p?.remove();
55
+ }
56
+ field.classList.toggle(FIELD_INVALID_CLASS, !!text);
57
+ const helpId = field.querySelector(`.${FieldClass.Help}`)?.id;
58
+ const describedBy = [helpId, text ? id : ''].filter(Boolean).join(' ');
59
+ for (const control of controls) {
60
+ if (text) control.setAttribute('aria-invalid', 'true');
61
+ else control.removeAttribute('aria-invalid');
62
+ if (describedBy) control.setAttribute('aria-describedby', describedBy);
63
+ else control.removeAttribute('aria-describedby');
64
+ }
65
+ }