@vectoriox/iox-ui 5.171.0 → 5.172.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "5.171.0",
3
+ "version": "5.172.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -1,4 +1,4 @@
1
- import { CompositeNode, CompositeNodeFactory, writeProp } from './composite-node';
1
+ import { CompositeNode, CompositeNodeFactory, findByRole, readProp, removeFromComposite, writeProp, writeStyles } from './composite-node';
2
2
  import { COLUMN, recipeLang, recipePart, recipeText, ROW, WORDS, ZERO } from './recipe-parts';
3
3
 
4
4
  /**
@@ -178,8 +178,14 @@ export const POPUP_KIND_ARRIVAL: Readonly<Record<PopupKind, { screens?: number;
178
178
 
179
179
  /** The recipe's OWN words — mechanism microcopy, in the site's language. The rest is the owner's. */
180
180
  const POPUP_WORDS = {
181
- en: { close: 'Close', send: 'Send', label: { [PopupKind.Announcement]: 'Announcement', [PopupKind.Offer]: 'Offer', [PopupKind.Newsletter]: 'Newsletter' } },
182
- he: { close: 'סגירה', send: 'שליחה', label: { [PopupKind.Announcement]: 'הודעה', [PopupKind.Offer]: 'הצעה', [PopupKind.Newsletter]: 'ניוזלטר' } },
181
+ en: {
182
+ close: 'Close', send: 'Send', label: { [PopupKind.Announcement]: 'Announcement', [PopupKind.Offer]: 'Offer', [PopupKind.Newsletter]: 'Newsletter' },
183
+ layers: { popup: 'Popup', picture: 'Picture', words: 'Words', dates: 'Dates', title: 'Title', action: 'Action' },
184
+ },
185
+ he: {
186
+ close: 'סגירה', send: 'שליחה', label: { [PopupKind.Announcement]: 'הודעה', [PopupKind.Offer]: 'הצעה', [PopupKind.Newsletter]: 'ניוזלטר' },
187
+ layers: { popup: 'חלון קופץ', picture: 'תמונה', words: 'מילים', dates: 'תאריכים', title: 'כותרת', action: 'פעולה' },
188
+ },
183
189
  } as const;
184
190
 
185
191
  export type PopupWords = (typeof POPUP_WORDS)['en'] | (typeof POPUP_WORDS)['he'];
@@ -214,6 +220,12 @@ export interface PopupRecipeOptions {
214
220
  /** The ONE action: a link to a page of the site, with its words. No route = no action (an announcement may have none). */
215
221
  actionLabel?: string;
216
222
  actionRoute?: string | null;
223
+ /** PU2c (PP-D3): stamp the action link EMPTY — no words, no page — for the author to fill (the builder's palette). Until
224
+ * it names a page it is a dead link, which the Publishable gate blocks; never a page we guessed. */
225
+ emptyAction?: boolean;
226
+ /** PU2c: the language of the LAYER names (the Layers row, the crumb: "חלון קופץ — הצעה") — the admin's, when the palette
227
+ * stamps it. Defaults to `lang`; the visitor's words (the ✕, the Dialog's label) always follow `lang`. */
228
+ labelLang?: string | null;
217
229
  /** The owner's picture (`art: picture`); '' = the DS3 empty-image box ("Add image"). */
218
230
  imageSrc?: string;
219
231
  imageAlt?: string;
@@ -227,6 +239,31 @@ export interface PopupRecipeOptions {
227
239
  newsletterForm?: CompositeNode | null;
228
240
  }
229
241
 
242
+ /** The dialog element style's padding, as the style writes it (design-core `dialog`): a card without a picture wears it. */
243
+ const DIALOG_PAD = 'var(--iox-dialog-pad)';
244
+
245
+ /** The layout the popup's ROOT wears in a form — ONE rule the recipe and a later "Where it sits" change both read. */
246
+ function popupRootLayout(bar: boolean, picture: boolean): Record<string, string> {
247
+ const { padding: _rowPad, ...row } = ROW;
248
+ // The dialog style's padding holds, except around a picture: the picture runs to the card's edge, the words keep the pad.
249
+ if (bar) return { ...row, width: '100%', maxWidth: '100%', gap: '16px' };
250
+ return { ...row, width: picture ? '560px' : '420px', maxWidth: '100%', alignItems: 'stretch', gap: '0px', ...(picture ? { padding: ZERO } : {}) };
251
+ }
252
+
253
+ /** The layout the words' column wears in a form (a bar lays them in one wrapping line). */
254
+ function popupContentLayout(bar: boolean, picture: boolean): Record<string, string> {
255
+ if (bar) return { ...ROW, flexGrow: '1', flexWrap: 'wrap', gap: '4px 16px' };
256
+ return { ...COLUMN, flexGrow: '1', width: 'auto', gap: '8px', ...(picture ? { padding: DIALOG_PAD } : {}) };
257
+ }
258
+
259
+ function popupMedia(create: CompositeNodeFactory, layers: PopupWords['layers'], src = '', alt = ''): CompositeNode {
260
+ const media = recipePart(create, 'popup-media', 'Container', PopupRole.Media, null, {}, layers.picture,
261
+ { ...COLUMN, width: '40%', flexShrink: '0', overflow: 'hidden' });
262
+ media.children = [recipePart(create, 'popup-image', 'Image', null, null, { src, alt }, layers.picture,
263
+ { width: '100%', height: '100%', minHeight: '160px', objectFit: 'cover', margin: ZERO })];
264
+ return media;
265
+ }
266
+
230
267
  /** The popup — ONE root. Pure over the factory: the builder and the composer get the same tree. */
231
268
  export function buildPopupRecipe(create: CompositeNodeFactory, options: PopupRecipeOptions = {}): CompositeNode {
232
269
  const kind = options.kind ?? PopupKind.Offer;
@@ -234,15 +271,13 @@ export function buildPopupRecipe(create: CompositeNodeFactory, options: PopupRec
234
271
  const form = popupFormOf(kind, options.form ?? mix.form);
235
272
  const art = form === PopupForm.Bar ? PopupArt.None : options.art ?? mix.art;
236
273
  const words = popupWords(options.lang);
274
+ const layers = popupWords(options.labelLang ?? options.lang).layers;
275
+ const kindLayer = popupWords(options.labelLang ?? options.lang).label[kind];
237
276
  const title = options.title?.trim() ?? '';
238
277
  const bar = form === PopupForm.Bar;
239
278
 
240
279
  const picture = art === PopupArt.Picture;
241
- // The dialog style's padding holds, except around a picture: the picture runs to the card's edge, the words keep the pad.
242
- const { padding: _rowPad, ...row } = ROW;
243
- const root = recipePart(create, 'popup', 'Dialog', PopupRole.Popup, Style.Dialog, {}, `Popup — ${words.label[kind]}`,
244
- bar ? { ...row, width: '100%', maxWidth: '100%', gap: '16px' }
245
- : { ...row, width: picture ? '560px' : '420px', maxWidth: '100%', alignItems: 'stretch', gap: '0px', ...(picture ? { padding: ZERO } : {}) });
280
+ const root = recipePart(create, 'popup', 'Dialog', PopupRole.Popup, Style.Dialog, {}, `${layers.popup} — ${kindLayer}`, popupRootLayout(bar, picture));
246
281
  writeProp(root, 'placement', 'center'); // the popup's own form places it (iox-design.css), never the placement
247
282
  writeProp(root, 'closeOnBackdrop', true); // centred only: a click on the scrim is a close (remembered)
248
283
  writeProp(root, 'showCloseButton', true);
@@ -253,29 +288,21 @@ export function buildPopupRecipe(create: CompositeNodeFactory, options: PopupRec
253
288
  writeProp(root, PopupTrait.Again, options.again ?? mix.again);
254
289
 
255
290
  const children: CompositeNode[] = [];
256
- if (picture) {
257
- const media = recipePart(create, 'popup-media', 'Container', PopupRole.Media, null, {}, 'Picture',
258
- { ...COLUMN, width: '40%', flexShrink: '0', overflow: 'hidden' });
259
- media.children = [recipePart(create, 'popup-image', 'Image', null, null, { src: options.imageSrc ?? '', alt: options.imageAlt ?? '' }, 'Picture',
260
- { width: '100%', height: '100%', minHeight: '160px', objectFit: 'cover', margin: ZERO })];
261
- children.push(media);
262
- }
263
- const content = recipePart(create, 'popup-content', 'Container', PopupRole.Content, null, {}, 'Words',
264
- bar ? { ...ROW, flexGrow: '1', flexWrap: 'wrap', gap: '4px 16px' }
265
- : { ...COLUMN, flexGrow: '1', width: 'auto', gap: '8px', ...(picture ? { padding: 'var(--iox-dialog-pad)' } : {}) });
291
+ if (picture) children.push(popupMedia(create, layers, options.imageSrc ?? '', options.imageAlt ?? ''));
292
+ const content = recipePart(create, 'popup-content', 'Container', PopupRole.Content, null, {}, layers.words, popupContentLayout(bar, picture));
266
293
  const parts: CompositeNode[] = [];
267
- if (options.eyebrow?.trim()) parts.push(recipeText(create, 'popup-eyebrow', PopupRole.Eyebrow, Style.Eyebrow, options.eyebrow.trim(), 'Dates'));
268
- parts.push(recipePart(create, 'popup-title', 'Heading', PopupRole.Title, Style.Title, { content: title, level: 'h2' }, 'Title', WORDS));
269
- if (options.body?.trim() || !bar) parts.push(recipeText(create, 'popup-body', PopupRole.Body, Style.Body, options.body?.trim() ?? '', 'Words'));
294
+ if (options.eyebrow?.trim()) parts.push(recipeText(create, 'popup-eyebrow', PopupRole.Eyebrow, Style.Eyebrow, options.eyebrow.trim(), layers.dates));
295
+ parts.push(recipePart(create, 'popup-title', 'Heading', PopupRole.Title, Style.Title, { content: title, level: 'h2' }, layers.title, WORDS));
296
+ if (options.body?.trim() || !bar) parts.push(recipeText(create, 'popup-body', PopupRole.Body, Style.Body, options.body?.trim() ?? '', layers.words));
270
297
  if (kind === PopupKind.Newsletter && options.newsletterForm) {
271
298
  const f = options.newsletterForm;
272
299
  f.role = PopupRole.Form;
273
300
  parts.push(f);
274
- } else if (options.actionRoute) {
301
+ } else if (options.actionRoute || options.emptyAction) {
275
302
  // A popup's action is QUIET — never the page's primary button (§6): the look's link (a Link, the consent banner's
276
303
  // privacy link's shape), hugging its words — the column would stretch its box (focus ring, hover) to full width.
277
304
  parts.push(recipePart(create, 'popup-action', 'Link', PopupRole.Action, Style.Link,
278
- { label: options.actionLabel?.trim() ?? '', linkType: 'page', pageRoute: options.actionRoute }, 'Action',
305
+ { label: options.actionLabel?.trim() ?? '', linkType: 'page', pageRoute: options.actionRoute ?? '' }, layers.action,
279
306
  { ...WORDS, alignSelf: 'flex-start' }));
280
307
  }
281
308
  content.children = parts;
@@ -283,3 +310,52 @@ export function buildPopupRecipe(create: CompositeNodeFactory, options: PopupRec
283
310
  root.children = children;
284
311
  return root;
285
312
  }
313
+
314
+ /** What a "Where it sits" change did to the popup's parts. */
315
+ export interface PopupFormChange {
316
+ /** The form the popup now sits in (judged: `centred` only for a newsletter). */
317
+ form: PopupForm;
318
+ /** The picture part a bar dropped, or null. */
319
+ removed: CompositeNode | null;
320
+ /** The picture part a card got back, or null. */
321
+ added: CompositeNode | null;
322
+ }
323
+
324
+ export interface PopupFormOptions {
325
+ /** The language of a re-stamped part's layer name. */
326
+ labelLang?: string | null;
327
+ }
328
+
329
+ /**
330
+ * PU2c — "Where it sits", in ONE edit (the builder applies it as one undo step): the form trait AND the parts that follow
331
+ * it, so a popup re-shaped later is the tree the recipe would stamp in that form. A BAR drops the picture part (one line
332
+ * holds no picture) and lays its words in a row; a CORNER / CENTRED card of a kind that carries a picture (an Offer) gets
333
+ * the picture part back — empty, the DS3 "Add image" box — and lays its words in a column. Its words, form and action are
334
+ * never touched. Mutates `root`; without a factory nothing is stamped back.
335
+ */
336
+ export function setPopupForm(root: CompositeNode, form: PopupForm, create?: CompositeNodeFactory, options: PopupFormOptions = {}): PopupFormChange {
337
+ const kindValue = readProp(root, PopupTrait.Kind);
338
+ const kind = (Object.values(PopupKind) as unknown[]).includes(kindValue) ? kindValue as PopupKind : PopupKind.Offer;
339
+ const judged = popupFormOf(kind, form);
340
+ writeProp(root, PopupTrait.Form, judged);
341
+ const bar = judged === PopupForm.Bar;
342
+ let media = findByRole(root, PopupRole.Media) ?? null;
343
+ let removed: CompositeNode | null = null;
344
+ let added: CompositeNode | null = null;
345
+ if (bar && media) {
346
+ removeFromComposite(root, media);
347
+ removed = media;
348
+ media = null;
349
+ } else if (!bar && !media && create && POPUP_KIND_MIX[kind].art === PopupArt.Picture) {
350
+ media = added = popupMedia(create, popupWords(options.labelLang).layers);
351
+ root.children = [media, ...(root.children ?? [])];
352
+ }
353
+ const picture = !!media;
354
+ // The recipe's layout for the new form, so the tree is the one the recipe stamps in this form: with no picture the card
355
+ // takes back its dialog style's padding (the style writes it as this token reference); '' clears a wrap only the bar wrote
356
+ // (the compiler skips an empty value).
357
+ writeStyles(root, { alignItems: 'center', padding: DIALOG_PAD, ...popupRootLayout(bar, picture) });
358
+ const content = findByRole(root, PopupRole.Content);
359
+ if (content) writeStyles(content, { flexWrap: '', ...popupContentLayout(bar, picture) });
360
+ return { form: judged, removed, added };
361
+ }