@vectoriox/iox-ui 5.128.1 → 5.130.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.
@@ -2,7 +2,7 @@ import {
2
2
  AnimateId, COLOR_SCHEME_TRAIT, COLOR_SCHEMES, ColorScheme, colorSchemeClass, DEFAULT_MENU_LOOK, DesignChoices, LinkType, MenuLook, resolveDesignChoices, setColorScheme,
3
3
  } from '@vectoriox/iox-ui/design-core';
4
4
  import { SEO_DESCRIPTION_MAX, SEO_TITLE_MAX, SeoRawDoc } from '@vectoriox/iox-ui/seo-core';
5
- import { channelOpensNewTab, FORM_ACTIONS_ROLE, FORM_CHANNEL_ROLE, FormPresetChannel, FormPresetDef, FormPresetField, formPresetById } from '@vectoriox/iox-ui/forms-core';
5
+ import { channelOpensNewTab, FORM_ACTIONS_ROLE, FORM_CHANNEL_ROLE, FormPresetChannel, FormPresetDef, FormPresetField, formPresetById, presetFormActions } from '@vectoriox/iox-ui/forms-core';
6
6
  import {
7
7
  ACCORDION_BIND_PROP, ACCORDION_CONTENT_LIMIT, ACCORDION_WORDS, accordionAnswerOf, accordionItems, accordionQuestionOf, AccordionRole,
8
8
  buildAccordionRecipe, buildCardRecipe, buildCarouselRecipe, buildLightboxRecipe, CardLayout, CardPart, CardRole, CARD_LAYOUTS, CARD_PARTS, CompositeNode,
@@ -10,11 +10,17 @@ import {
10
10
  tabPanelImageOf, tabPanelTextOf, tabsListOf, tabsPanels, tabsPanelsOf, tabsTriggers, TABS_CONTENT_LIMIT, TABS_IMAGE_BIND_PROP, TABS_LABEL_BIND_PROP,
11
11
  TABS_TEXT_BIND_PROP, TABS_WORDS, TabsAutoBinds, BadgeTone, BADGE_TONES, buildSegmentedRecipe, CardWords, ITEM_OPEN_STATE, segmentedOptions,
12
12
  setHeaderBehaviour, SHOP_RECIPES, ShopRecipe, ShopRole, bindShopPart, ShopBindTarget, ACCOUNT_RECIPES, AccountRecipe,
13
+ buildConsentRecipe, ConsentActionType,
13
14
  } from '@vectoriox/iox-ui/composite-core';
15
+ import { ConsentCategory } from '@vectoriox/iox-ui/consent-core';
14
16
 
15
17
  import { EntranceMark, EntrancePart, planEntrances } from './entrances';
16
18
  import { filmOfPlan } from './film';
17
- import { checkFooter, footerMixOfPlan, footerPattern } from './footer-mix';
19
+ import { checkFooter, FooterArrange, footerMixOfPlan, footerPattern } from './footer-mix';
20
+ import {
21
+ countryLegalFacts, FOOTER_LEGAL_ROLE, FORM_LEGAL_ROLE, formAsksPersonalData, formLegalFacts, LEGAL_PAGE_SETTING, LegalContext, LegalFact, LegalFacts,
22
+ legalFormLine, LegalKind, legalKindsFor, legalLabel, legalRoute, legalTitle,
23
+ } from './legal';
18
24
  import { checkHeader, drawnHeaderMix, HeaderContext, headerContextOfPlan, headerMix, HeaderMix, headerRecipe, HeaderRecipe, wornHeaderOfPlan } from './header-mix';
19
25
  import { NODE_BASELINES } from './node-baselines.generated';
20
26
  import {
@@ -24,6 +30,7 @@ import {
24
30
  import { planSells, shopCategoriesOf, shopContentType, variantNamesOf } from './shop-plan';
25
31
  import { recipeListBinds } from './recipe-fields';
26
32
  import { assertStyleSlots, ComposeError, createSerializedNode, SerializedBinding, SerializedNode, setStyleProps, walkSerialized } from './serialized-node';
33
+ import { refreshSectionStamps, stampSection } from './section-stamp';
27
34
  import { SitePlanSourceKind, ContentFieldControl, ContentFieldPlan,
28
35
  ContentRole, ContentTypePlan, DataSourcePlan, DEFAULT_SITE_LOCALE, FactKey, FACT_KEYS, GlobalSlot, isRtlLocale, PagePlan, PageSectionPlan, PlanDataSourceMode,
29
36
  PlanDataSourceType, RelativeOp, roleField, SiteLocale, SitePlan, SitePlanSource, SITE_FACT_LABELS, SiteBusiness, GenerationTier,
@@ -64,6 +71,9 @@ export enum PlaceholderKind {
64
71
  /** L2 (`proof.stat-row`): a number the studio stands behind ("12 years", "300 clients") — a fact, its label shown
65
72
  * meanwhile ("Number"), never a number written for it. */
66
73
  Stat = 'stat',
74
+ /** AW1: a stamped legal page's text — what belongs there ("Your privacy policy: …"), never a word of policy. Its page
75
+ * holds Publish while it shows the label (`auditSite`, `legal-page-placeholder`, by the page's kind). */
76
+ Policy = 'policy',
67
77
  }
68
78
 
69
79
  /** The placeholders a page cannot be published with unfilled (W4's gate): a fact, a price, a number, the studio's own
@@ -132,6 +142,9 @@ export interface ComposeContext {
132
142
  photoShape?: (photoId: string) => `${LayoutPhotoShape}` | undefined;
133
143
  /** The tier the plan was made at (its generation's stored tier, AW-D23) — absent = Basic: at most two composed pages. */
134
144
  tier?: `${GenerationTier}`;
145
+ /** AW1: what the studio holds that decides its legal pages and banner (country, trackers, its own legal pages, its
146
+ * routes, a banner it keeps). Absent = only what the plan and the composed pages say (no tracker, no country). */
147
+ legal?: LegalContext;
135
148
  }
136
149
 
137
150
  /** Where a composed layout's photos are, as the server keeps them and the screens read them (M8 gate 2): id → address. */
@@ -142,8 +155,8 @@ export interface LayoutPhotoAddress {
142
155
  }
143
156
 
144
157
  /** The composer's context for a site whose layouts name photos: the year, and each photo's address, words and shape. */
145
- export function composeContextOf(year: number, photos?: Readonly<Record<string, LayoutPhotoAddress>>, tier?: `${GenerationTier}`): ComposeContext {
146
- const tiered = tier ? { tier } : {};
158
+ export function composeContextOf(year: number, photos?: Readonly<Record<string, LayoutPhotoAddress>>, tier?: `${GenerationTier}`, legal?: LegalContext | null): ComposeContext {
159
+ const tiered = { ...(tier ? { tier } : {}), ...(legal ? { legal } : {}) };
147
160
  if (!photos) return { year, ...tiered };
148
161
  return {
149
162
  year,
@@ -164,7 +177,7 @@ export interface ComposedPage {
164
177
  locale: `${SiteLocale}`;
165
178
  /** DS3: every page the wizard creates follows the look (page-bg / text / font-body). M8 gate 2: a composed page names
166
179
  * the plan page its layout is (`layoutSource`; the build adds its run) — what Design ▸ Re-fit recomposes it from. */
167
- pageSettings: { designSystem: true; layoutSource?: { pageKey: string; runId?: string }; opening?: `${ColorScheme}` };
180
+ pageSettings: { designSystem: true; layoutSource?: { pageKey: string; runId?: string }; opening?: `${ColorScheme}`; legal?: `${LegalKind}` };
168
181
  /** M1-6c: the page's search-result words — written (a static page) or bound to the route item (a template page),
169
182
  * in the seo-core document shape the shared `resolveSeo` reads. */
170
183
  seo: SeoRawDoc;
@@ -682,12 +695,14 @@ function composeForm(node: SerializedNode, pn: PatternNode, id: string, ctx: Ctx
682
695
  stampPresetForm(node, presetId, id, ctx.owner);
683
696
  }
684
697
 
685
- /** A preset's name, stable form id and children on a Form node — the ONE stamping `composeSite` and `composeLayout` share. */
698
+ /** A preset's name, stable form id, after-send steps (iox-cms#84: a contact form emails the owner) and children on a Form node — the ONE stamping `composeSite` and `composeLayout` share. */
686
699
  function stampPresetForm(node: SerializedNode, presetId: string, id: string, owner: string): void {
687
700
  const preset = formPresetById(presetId);
688
701
  if (!preset) throw new ComposeError(`${id}: no form preset "${presetId}" in forms-core`);
689
702
  setProp(node, 'name', preset.formName);
690
703
  setProp(node, 'formId', `${preset.id}-${stableHash(`${owner}/${id}`)}`);
704
+ const actions = presetFormActions(preset);
705
+ if (actions) setProp(node, 'actions', actions);
691
706
  node.children = presetChildren(preset, id);
692
707
  }
693
708
 
@@ -1500,6 +1515,17 @@ function composeLayoutPage(
1500
1515
  return nodes;
1501
1516
  }
1502
1517
 
1518
+ /** M2-1: each section root of a model-laid page says where it came from — a ready-made place its plan section's library
1519
+ * pattern, any other its layout section id (`composeLayout` keeps one root per layout section, in order). */
1520
+ function stampLayoutSections(page: PagePlan, layout: LayoutPage, nodes: SerializedNode[]): SerializedNode[] {
1521
+ if (nodes.length !== layout.sections.length) throw new ComposeError(`${page.key}: ${nodes.length} roots for ${layout.sections.length} layout sections`);
1522
+ return nodes.map((root, i) => {
1523
+ const s = layout.sections[i];
1524
+ const readyMade = s.readyMade ? page.sections[s.readyMade.at]?.pattern : undefined;
1525
+ return stampSection(root, readyMade ? { pattern: readyMade } : { layout: s.id });
1526
+ });
1527
+ }
1528
+
1503
1529
  /**
1504
1530
  * Compose a Site Plan. Throws `SitePlanError` (every issue) when the plan does not validate — the
1505
1531
  * composer never repairs a plan. `context` carries what the composer may not read for itself (the year).
@@ -1524,15 +1550,15 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1524
1550
  return {
1525
1551
  key: page.key, name: page.name, route: { path: page.route }, isHome: page.isHome === true, status: STATUS_DRAFT, locale,
1526
1552
  pageSettings: { designSystem: true, layoutSource: { pageKey: page.key }, ...(opening ? { opening } : {}) }, seo: composePageSeo(page, plan),
1527
- layout: composeLayoutPage(page, page.layout, plan, context, design, placeholders, (section, id) =>
1553
+ layout: stampLayoutSections(page, page.layout, composeLayoutPage(page, page.layout, plan, context, design, placeholders, (section, id) =>
1528
1554
  composePattern(patternById(section.pattern) as SitePattern, id, { ...base, owner: page.key, page, section, nextAlias },
1529
- { level: section.enter ?? design.animate ?? null, rtl })),
1555
+ { level: section.enter ?? design.animate ?? null, rtl }))),
1530
1556
  };
1531
1557
  }
1532
1558
  const layout = page.sections.map((section, i) => {
1533
1559
  const pattern = patternById(section.pattern) as SitePattern;
1534
1560
  const motion: SectionMotion = { level: section.enter ?? design.animate ?? null, rtl };
1535
- return composePattern(pattern, `${page.key}-${i}`, { ...base, owner: page.key, page, section, nextAlias }, motion);
1561
+ return stampSection(composePattern(pattern, `${page.key}-${i}`, { ...base, owner: page.key, page, section, nextAlias }, motion), { pattern: section.pattern });
1536
1562
  });
1537
1563
  const opening = colorSchemeClass(layout[0]?.props?.[COLOR_SCHEME_TRAIT]) ? (layout[0].props[COLOR_SCHEME_TRAIT] as ColorScheme) : null;
1538
1564
  return {
@@ -1579,6 +1605,13 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1579
1605
  if (pattern.header && root) setHeaderBehaviour(root as unknown as CompositeNode, pattern.header.behaviour, pattern.header.edge ?? null);
1580
1606
  }
1581
1607
  if (planSells(plan)) globals = withStore(globals, plan.locale ?? DEFAULT_SITE_LOCALE);
1608
+ // AW1: the law, derived from facts and never asked — the legal pages, the banner when a tracker is connected, the
1609
+ // footer's legal row and the line beside every form that asks for personal details.
1610
+ const legal = composeLegal(plan, context.legal ?? {}, pages, globals, footer.mix.arrange, placeholders);
1611
+ globals = legal.globals;
1612
+ // RD1 (M2-1): the legal line dresses a section's form AFTER it was stamped — re-take the fingerprints, so a built
1613
+ // page reads "as the build left it" (the same rule iox-cms runs after the stock photos).
1614
+ for (const page of pages) refreshSectionStamps(page.layout);
1582
1615
 
1583
1616
  return {
1584
1617
  source: clone(plan.source),
@@ -1587,15 +1620,179 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1587
1620
  schemas: clone(plan.contentTypes) as ContentTypePlan[],
1588
1621
  items: Object.fromEntries(plan.contentTypes.map(t => [t.name, composeItems(t, plan.source.kind === SitePlanSourceKind.Ai)])),
1589
1622
  dataSources: plan.dataSources.map(composeDataSource),
1590
- pages,
1623
+ pages: [...pages, ...legal.pages],
1591
1624
  globals,
1592
- routes: plan.pages.map(p => ({ key: p.key, path: p.route, isHome: p.isHome === true })),
1625
+ routes: [...plan.pages.map(p => ({ key: p.key, path: p.route, isHome: p.isHome === true })), ...legal.pages.map(p => ({ key: p.key, path: p.route.path, isHome: false }))],
1593
1626
  placeholders,
1594
1627
  issues,
1595
1628
  shop: composeShop(plan),
1596
1629
  };
1597
1630
  }
1598
1631
 
1632
+ // ── AW1: the law (award-ingredients-plan §4) ──────────────────────────────────────────────────────────────────────
1633
+
1634
+ const LINK = 'Link';
1635
+ const HEADING = 'Heading';
1636
+ const SECTION = 'Section';
1637
+ const CONTAINER = 'Container';
1638
+ /** Inline words: the legal line reads as one sentence, its links inside it. */
1639
+ const INLINE = { display: 'inline', width: 'auto', minHeight: 'auto', padding: '0px 0px 0px 0px', margin: '0px 0px 0px 0px' };
1640
+
1641
+ /** The facts the law is decided by: the composed site's forms, what it sells, its language and the studio's country and trackers. */
1642
+ export function legalFactsOf(plan: SitePlan, context: LegalContext, nodes: ReadonlyArray<SerializedNode>): LegalFacts {
1643
+ const sells = planSells(plan);
1644
+ return {
1645
+ ...formLegalFacts(nodes),
1646
+ [LegalFact.Tracker]: (context.trackers?.length ?? 0) > 0,
1647
+ [LegalFact.Sells]: sells,
1648
+ // The shop ships what it sells (commerce shipping, C-D9) — no product is digital yet.
1649
+ [LegalFact.PhysicalGoods]: sells,
1650
+ [LegalFact.Hebrew]: (plan.locale ?? DEFAULT_SITE_LOCALE) === SiteLocale.He,
1651
+ ...countryLegalFacts(context.country),
1652
+ };
1653
+ }
1654
+
1655
+ /** A stamped legal page: its title and the placeholder that says what belongs there — never a word of policy (D-C7). */
1656
+ function composeLegalPage(kind: LegalKind, key: string, route: string, plan: SitePlan, placeholders: ComposedPlaceholder[]): ComposedPage {
1657
+ const locale = plan.locale ?? DEFAULT_SITE_LOCALE;
1658
+ const title = legalTitle(kind, locale);
1659
+ const label = legalLabel(kind, locale);
1660
+ const section = create(key, SECTION, {}, 'section');
1661
+ section.label = 'Legal page';
1662
+ const column = create(`${key}-0`, CONTAINER, {}, 'box');
1663
+ setStyleProps(column, { display: 'flex', flexDirection: 'column', gap: '18px', maxWidth: '720px', width: '100%', margin: '0px auto 0px auto' });
1664
+ const heading = create(`${key}-0-0`, HEADING, { content: title, level: 'h1' }, 'h1');
1665
+ const text = create(`${key}-0-1`, TEXT, { content: label }, 'body');
1666
+ column.children = [heading, text];
1667
+ section.children = [column];
1668
+ placeholders.push({ nodeId: text.id, owner: key, kind: PlaceholderKind.Policy, text: label });
1669
+ const page: PagePlan = { key, name: title, route, sections: [] };
1670
+ return {
1671
+ key, name: title, route: { path: route }, isHome: false, status: STATUS_DRAFT, locale,
1672
+ pageSettings: { designSystem: true, [LEGAL_PAGE_SETTING]: kind } as ComposedPage['pageSettings'],
1673
+ seo: composePageSeo(page, plan), layout: [section],
1674
+ };
1675
+ }
1676
+
1677
+ /** A link to a legal page, worn as the look's link. */
1678
+ function legalLink(id: string, kind: LegalKind, route: string, locale: string, base: Readonly<Record<string, string>> = {}): SerializedNode {
1679
+ const link = create(id, LINK, { label: legalTitle(kind, locale) }, 'link');
1680
+ writePageLink(link, route);
1681
+ setStyleProps(link, { width: 'auto', minHeight: 'auto', ...base });
1682
+ return link;
1683
+ }
1684
+
1685
+ /** The footer's legal row (CONSENT `reopen.footer`, FOOTER `holds.legal`): every legal page, then Cookie settings. */
1686
+ function legalRow(routes: ReadonlyMap<LegalKind, string>, settings: SerializedNode | null, arrange: string, locale: string): SerializedNode | null {
1687
+ if (!routes.size && !settings) return null;
1688
+ const row = create(FOOTER_LEGAL_ROLE.replace('.', '-'), CONTAINER, {}, 'box');
1689
+ row.role = FOOTER_LEGAL_ROLE;
1690
+ row.label = 'Legal';
1691
+ setStyleProps(row, {
1692
+ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '8px 20px', width: '100%', minHeight: 'auto',
1693
+ justifyContent: arrange === FooterArrange.Centred ? 'center' : 'flex-start',
1694
+ });
1695
+ row.children = [...[...routes].map(([kind, route]) => legalLink(`${row.id}-${kind}`, kind, route, locale)), ...(settings ? [settings] : [])];
1696
+ return row;
1697
+ }
1698
+
1699
+ /** The legal line beside a form (AW-D15): the owner's words to edit, its links to the site's terms and privacy pages. */
1700
+ function formLegalLine(form: SerializedNode, routes: ReadonlyMap<LegalKind, string>, locale: string): SerializedNode | null {
1701
+ if (!routes.has(LegalKind.Privacy)) return null;
1702
+ const id = `${form.id}-legal`;
1703
+ const line = create(id, CONTAINER, {}, 'box');
1704
+ line.role = FORM_LEGAL_ROLE;
1705
+ line.label = 'Legal line';
1706
+ setStyleProps(line, { display: 'block', width: '100%', minHeight: 'auto' });
1707
+ line.children = legalFormLine(locale, routes.has(LegalKind.Terms)).map((part, i) => ('kind' in part
1708
+ ? legalLink(`${id}-${i}`, part.kind, routes.get(part.kind)!, locale, INLINE)
1709
+ : (() => {
1710
+ const words = create(`${id}-${i}`, TEXT, { content: part.text, tag: 'span' }, 'small');
1711
+ setStyleProps(words, INLINE);
1712
+ return words;
1713
+ })()));
1714
+ return line;
1715
+ }
1716
+
1717
+ /** Put the legal line after a form's fields and buttons — before its success and error blocks. */
1718
+ function withFormLine(form: SerializedNode, line: SerializedNode): void {
1719
+ const kids = form.children ?? (form.children = []);
1720
+ const at = kids.findIndex(k => k.type === FORM_SUCCESS || k.type === FORM_ERROR);
1721
+ kids.splice(at >= 0 ? at : kids.length, 0, line);
1722
+ }
1723
+
1724
+ /** The categories the trackers need a yes for, each once (Necessary never). */
1725
+ function trackerCategories(context: LegalContext): ConsentCategory[] {
1726
+ const out: ConsentCategory[] = [];
1727
+ for (const t of context.trackers ?? []) {
1728
+ const c = t.category as ConsentCategory;
1729
+ if (c !== ConsentCategory.Necessary && !out.includes(c)) out.push(c);
1730
+ }
1731
+ return out;
1732
+ }
1733
+
1734
+ /**
1735
+ * AW1 (C5): the law a site's facts call for — stamped, never asked. Each legal kind the facts need (`legalKindsFor`) is
1736
+ * the studio's own page when it has one (linked, never stamped again), else an empty flagged page on a free route; the
1737
+ * cookie banner and its preferences are stamped as globals when a tracker is connected (unless the studio keeps its
1738
+ * own); every footer gets the legal row (+ Cookie settings), every form that asks for personal details the legal line.
1739
+ * Pure: new globals, the stamped pages; forms and the footer gain their nodes in place.
1740
+ */
1741
+ function composeLegal(plan: SitePlan, context: LegalContext, pages: ReadonlyArray<ComposedPage>, globals: SerializedNode[], footerArrange: string,
1742
+ placeholders: ComposedPlaceholder[]): { pages: ComposedPage[]; globals: SerializedNode[] } {
1743
+ const locale = plan.locale ?? DEFAULT_SITE_LOCALE;
1744
+ const nodes = [...pages.flatMap(p => p.layout), ...globals];
1745
+ const kinds = legalKindsFor(legalFactsOf(plan, context, nodes));
1746
+ const taken = new Set<string>([...plan.pages.map(p => p.route), ...(context.takenRoutes ?? [])]);
1747
+ const keys = new Set(plan.pages.map(p => p.key));
1748
+ const routes = new Map<LegalKind, string>();
1749
+ const stamped: ComposedPage[] = [];
1750
+ for (const kind of kinds) {
1751
+ const own = context.existing?.[kind];
1752
+ if (own) { routes.set(kind, own); continue; }
1753
+ const route = legalRoute(kind, taken);
1754
+ taken.add(route);
1755
+ let key = `legal-${kind}`;
1756
+ for (let n = 2; keys.has(key); n++) key = `legal-${kind}-${n}`;
1757
+ keys.add(key);
1758
+ routes.set(kind, route);
1759
+ stamped.push(composeLegalPage(kind, key, route, plan, placeholders));
1760
+ }
1761
+
1762
+ const out = [...globals];
1763
+ let settings: SerializedNode | null = null;
1764
+ const categories = trackerCategories(context);
1765
+ if (context.trackers?.length) {
1766
+ const privacy = routes.get(LegalKind.Privacy);
1767
+ const consent = buildConsentRecipe(spec => create(spec.key, spec.type, { ...(spec.props ?? {}) }, spec.elementStyle ?? null) as CompositeNode, {
1768
+ lang: locale, categories, privacyRoute: privacy ?? null, privacyLabel: privacy ? legalTitle(LegalKind.Privacy, locale) : undefined,
1769
+ });
1770
+ settings = consent.settings as SerializedNode;
1771
+ if (context.keptPreferences) {
1772
+ // The studio keeps its own banner: the footer's Cookie settings opens ITS preferences, and no second banner.
1773
+ for (const ix of settings.interactions ?? []) for (const a of (ix as { actions?: Array<{ type?: string; target?: string }> }).actions ?? []) {
1774
+ if (a.type === ConsentActionType.OpenPreferences) a.target = context.keptPreferences;
1775
+ }
1776
+ } else {
1777
+ for (const root of [consent.banner, consent.preferences] as SerializedNode[]) {
1778
+ root.isGlobal = true;
1779
+ root.globalPosition = PatternGlobalPosition.After;
1780
+ out.push(root);
1781
+ }
1782
+ }
1783
+ }
1784
+ const footer = out.find(g => g.id === GlobalSlot.Footer);
1785
+ const row = footer ? legalRow(routes, settings, footerArrange, locale) : null;
1786
+ if (footer && row) (footer.children ?? (footer.children = [])).push(row);
1787
+
1788
+ walkSerialized([...pages.flatMap(p => p.layout), ...out, ...stamped.flatMap(p => p.layout)], n => {
1789
+ if (n.type !== FORM || !formAsksPersonalData(n)) return;
1790
+ const line = formLegalLine(n, routes, locale);
1791
+ if (line) withFormLine(n, line);
1792
+ });
1793
+ return { pages: stamped, globals: out };
1794
+ }
1795
+
1599
1796
  /** A plan's header (HI1): its mix as the product draws it, checked against the site, and the recipe to stamp — with what
1600
1797
  * was mended or drawn as something else, in words. */
1601
1798
  export function planHeader(plan: SitePlan): { recipe: HeaderRecipe; context: HeaderContext; said: string[] } {
@@ -0,0 +1,213 @@
1
+ import { ConsentCategory } from '@vectoriox/iox-ui/consent-core';
2
+ import { ControlType, FIELD_NODE_TYPE, FORM_NODE_TYPE } from '@vectoriox/iox-ui/forms-core';
3
+
4
+ import { SerializedNode, walkSerialized } from './serialized-node';
5
+ import { SPEC_SITE_LAYOUT } from './site-spec.generated';
6
+
7
+ /**
8
+ * THE LEGAL PAGES (award-ingredients-plan §4.3, AW1; consent plan C5) — read from ONE table, the contract's
9
+ * `site.layout.legal` (layout.mjs `LEGAL`): which legal page KINDS a site needs follows from facts the site and the
10
+ * studio hold (a form asks for personal details, a tracker is connected, the site sells, books or signs people up, it is
11
+ * in Hebrew, the studio's country), never from a model. A kind is stamped by `composeSite` as an EMPTY, flagged page —
12
+ * a title and a placeholder whose label says what belongs there — and the Publishable gate blocks while it is still the
13
+ * placeholder. IOX never writes a word of policy (D-C7). Pure.
14
+ */
15
+
16
+ const L = SPEC_SITE_LAYOUT.legal;
17
+
18
+ /** The kinds, by the table's ids (held equal to it by legal.spec). */
19
+ export enum LegalKind {
20
+ Privacy = 'privacy',
21
+ Cookies = 'cookies',
22
+ Accessibility = 'accessibility',
23
+ Terms = 'terms',
24
+ TermsOfSale = 'terms-of-sale',
25
+ Returns = 'returns',
26
+ Shipping = 'shipping',
27
+ Imprint = 'imprint',
28
+ DoNotSell = 'do-not-sell',
29
+ }
30
+
31
+ /** The facts that decide a kind, by the table's ids. */
32
+ export enum LegalFact {
33
+ PersonalDataForm = 'personal-data-form',
34
+ Tracker = 'tracker',
35
+ Sells = 'sells',
36
+ PhysicalGoods = 'physical-goods',
37
+ Books = 'books',
38
+ Signups = 'signups',
39
+ Hebrew = 'hebrew',
40
+ Israel = 'israel',
41
+ EuBusiness = 'eu-business',
42
+ UsBusiness = 'us-business',
43
+ }
44
+
45
+ /** Whether a kind holds Publish while it is the placeholder: yes · through the checkout gate · never. */
46
+ export enum LegalBlocks {
47
+ Yes = 'yes',
48
+ Commerce = 'commerce',
49
+ No = 'no',
50
+ }
51
+
52
+ export interface LegalWords {
53
+ readonly en: string;
54
+ readonly he: string;
55
+ }
56
+
57
+ export interface LegalKindRow {
58
+ readonly id: `${LegalKind}`;
59
+ readonly when: ReadonlyArray<`${LegalFact}`>;
60
+ readonly blocks: `${LegalBlocks}`;
61
+ readonly phase: string;
62
+ readonly tier: string;
63
+ readonly title: LegalWords;
64
+ readonly label: LegalWords;
65
+ }
66
+
67
+ /** Every kind, in the table's order. */
68
+ export const LEGAL_KINDS: ReadonlyArray<LegalKindRow> = L.kinds as unknown as ReadonlyArray<LegalKindRow>;
69
+
70
+ /** A deferred kind is never stamped (`do-not-sell`, US only). */
71
+ const DEFERRED = 'deferred';
72
+
73
+ /** Where a page says which legal kind it is: `pageSettings.legal` (free-form, saved with the page). */
74
+ export const LEGAL_PAGE_SETTING = 'legal';
75
+
76
+ /** The role of the legal line beside a form and of a footer's legal row. */
77
+ export const FORM_LEGAL_ROLE = 'form.legal';
78
+ export const FOOTER_LEGAL_ROLE = 'footer.legal';
79
+
80
+ /** ISO 3166-1 alpha-2 for Israel — the accessibility statement's country (Israel's equal-rights regulations, 2013). */
81
+ export const ISRAEL = 'IL';
82
+
83
+ /** The countries whose businesses publish an imprint (the table's `imprintCountries`). */
84
+ export const IMPRINT_COUNTRIES: ReadonlySet<string> = new Set(L.imprintCountries as ReadonlyArray<string>);
85
+
86
+ export function isLegalKind(value: unknown): value is LegalKind {
87
+ return typeof value === 'string' && LEGAL_KINDS.some(k => k.id === value);
88
+ }
89
+
90
+ export function legalKindRow(kind: `${LegalKind}`): LegalKindRow {
91
+ const row = LEGAL_KINDS.find(k => k.id === kind);
92
+ if (!row) throw new Error(`no legal kind "${kind}"`);
93
+ return row;
94
+ }
95
+
96
+ const pick = (words: LegalWords, lang: string | null | undefined): string => (lang === 'he' ? words.he : words.en);
97
+
98
+ /** A kind's page title in the site's language. */
99
+ export function legalTitle(kind: `${LegalKind}`, lang: string | null | undefined): string {
100
+ return pick(legalKindRow(kind).title, lang);
101
+ }
102
+
103
+ /** What belongs on the page, in the site's language — the placeholder it shows until the owner writes it. */
104
+ export function legalLabel(kind: `${LegalKind}`, lang: string | null | undefined): string {
105
+ return pick(legalKindRow(kind).label, lang);
106
+ }
107
+
108
+ /** True when a kind holds Publish while it is the placeholder (yes, or with the checkout's own). */
109
+ export function legalKindBlocks(kind: `${LegalKind}`): boolean {
110
+ return legalKindRow(kind).blocks !== LegalBlocks.No;
111
+ }
112
+
113
+ /** The kind a page says it is (`pageSettings.legal`), or null. */
114
+ export function legalKindOfPage(page: { pageSettings?: Readonly<Record<string, unknown>> | null } | null | undefined): LegalKind | null {
115
+ const kind = page?.pageSettings?.[LEGAL_PAGE_SETTING];
116
+ return isLegalKind(kind) ? kind : null;
117
+ }
118
+
119
+ export type LegalFacts = Readonly<Partial<Record<`${LegalFact}`, boolean>>>;
120
+
121
+ /** The kinds a site with these facts needs, in the table's order (deferred kinds never). */
122
+ export function legalKindsFor(facts: LegalFacts): LegalKind[] {
123
+ return LEGAL_KINDS.filter(k => k.phase !== DEFERRED && k.when.some(f => facts[f] === true)).map(k => k.id as LegalKind);
124
+ }
125
+
126
+ /** The form controls that ask for a personal detail (a name, an email, a phone, words about the person). */
127
+ export const PERSONAL_CONTROLS: ReadonlySet<string> = new Set([ControlType.Email, ControlType.Tel, ControlType.Text, ControlType.Textarea]);
128
+
129
+ /** True when a Form node asks for a personal detail. */
130
+ export function formAsksPersonalData(form: SerializedNode): boolean {
131
+ let personal = false;
132
+ walkSerialized(form.children ?? [], f => {
133
+ if (f.type === FIELD_NODE_TYPE && PERSONAL_CONTROLS.has(String(f.props['control'] ?? ControlType.Text))) personal = true;
134
+ });
135
+ return personal;
136
+ }
137
+
138
+ /** The forms-core presets whose forms are a booking or a sign-up (a Form's `formId` starts with its preset's id). */
139
+ const BOOKING_PRESET = 'booking';
140
+ const SIGNUP_PRESETS: ReadonlySet<string> = new Set(['newsletter']);
141
+ const presetOf = (form: SerializedNode): string => String(form.props['formId'] ?? '').split('-')[0];
142
+
143
+ /** The facts the site's own nodes answer: a personal-data form, a booking form, a sign-up form. */
144
+ export function formLegalFacts(nodes: ReadonlyArray<SerializedNode>): LegalFacts {
145
+ const facts: Partial<Record<`${LegalFact}`, boolean>> = {};
146
+ walkSerialized(nodes, n => {
147
+ if (n.type !== FORM_NODE_TYPE) return;
148
+ if (formAsksPersonalData(n)) facts[LegalFact.PersonalDataForm] = true;
149
+ if (presetOf(n) === BOOKING_PRESET) facts[LegalFact.Books] = true;
150
+ if (SIGNUP_PRESETS.has(presetOf(n))) facts[LegalFact.Signups] = true;
151
+ });
152
+ return facts;
153
+ }
154
+
155
+ /** The studio's country as facts: Israel, or a country that asks for an imprint. Unknown = neither. */
156
+ export function countryLegalFacts(country: string | null | undefined): LegalFacts {
157
+ const c = String(country ?? '').trim().toUpperCase();
158
+ return { [LegalFact.Israel]: c === ISRAEL, [LegalFact.EuBusiness]: IMPRINT_COUNTRIES.has(c) };
159
+ }
160
+
161
+ /** A tracker the studio has connected: its connector type and the consent category it needs a yes for. */
162
+ export interface LegalTracker {
163
+ type: string;
164
+ category: `${ConsentCategory}`;
165
+ }
166
+
167
+ /**
168
+ * What the composer may not know for itself about the law (AW1): the studio's country, the trackers it connected, the
169
+ * legal pages it already has, every route it already holds and the cookie banner it already keeps. Read by the caller
170
+ * (iox-cms reads them at preflight and keeps them on the run, so every step composes the same site).
171
+ */
172
+ export interface LegalContext {
173
+ /** ISO 3166-1 alpha-2 — the studio's country (Shop ▸ Settings; a shekel studio starts in Israel). Absent = unknown. */
174
+ country?: string | null;
175
+ trackers?: ReadonlyArray<LegalTracker>;
176
+ /** The studio's own legal pages, by kind: their route. The build links them and never stamps that kind again. */
177
+ existing?: Readonly<Partial<Record<`${LegalKind}`, string>>>;
178
+ /** Every route the studio already has — a stamped legal page never takes one. */
179
+ takenRoutes?: ReadonlyArray<string>;
180
+ /** The studio keeps its own cookie banner: its preferences dialog's id, which the footer's Cookie settings opens.
181
+ * The build stamps no second banner. */
182
+ keptPreferences?: string | null;
183
+ }
184
+
185
+ /** The route a stamped kind takes: `/<kind>`, else `/legal/<kind>`, else numbered — never one already taken. */
186
+ export function legalRoute(kind: `${LegalKind}`, taken: ReadonlySet<string>): string {
187
+ const tries = [`/${kind}`, `/legal/${kind}`];
188
+ for (const route of tries) if (!taken.has(route)) return route;
189
+ for (let n = 2; ; n++) if (!taken.has(`/legal/${kind}-${n}`)) return `/legal/${kind}-${n}`;
190
+ }
191
+
192
+ /** One piece of the legal line: words, or a link to a kind's page. */
193
+ export type LegalLinePart = { text: string } | { kind: LegalKind.Terms | LegalKind.Privacy };
194
+
195
+ const LINE_KEY = /\{(terms|privacy)\}/g;
196
+
197
+ /**
198
+ * The legal line beside a form (AW-D15) in the site's language, as words and links: "By sending, you agree to the
199
+ * {terms} and {privacy}." — the privacy-only line when the site has no terms page. Spaces stay with the words, so the
200
+ * pieces read as one sentence when drawn inline.
201
+ */
202
+ export function legalFormLine(lang: string | null | undefined, withTerms: boolean): LegalLinePart[] {
203
+ const template = pick((withTerms ? L.formLine : L.formLinePrivacy) as LegalWords, lang);
204
+ const parts: LegalLinePart[] = [];
205
+ let at = 0;
206
+ for (const m of template.matchAll(LINE_KEY)) {
207
+ if (m.index! > at) parts.push({ text: template.slice(at, m.index) });
208
+ parts.push({ kind: m[1] as LegalKind.Terms | LegalKind.Privacy });
209
+ at = m.index! + m[0].length;
210
+ }
211
+ if (at < template.length) parts.push({ text: template.slice(at) });
212
+ return parts;
213
+ }
@@ -17,6 +17,7 @@ export * from './site-plan.model';
17
17
  export * from './patterns';
18
18
  export * from './templates';
19
19
  export * from './serialized-node';
20
+ export * from './section-stamp';
20
21
  export * from './shape-check';
21
22
  export * from './json-schema';
22
23
  export * from './validate-site-plan';
@@ -61,3 +62,4 @@ export * from './footer-mix';
61
62
  export * from './layout-edits';
62
63
  export * from './adjustments';
63
64
  export * from './site-tree';
65
+ export * from './legal';