@vectoriox/iox-ui 5.128.1 → 5.129.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 {
@@ -64,6 +70,9 @@ export enum PlaceholderKind {
64
70
  /** L2 (`proof.stat-row`): a number the studio stands behind ("12 years", "300 clients") — a fact, its label shown
65
71
  * meanwhile ("Number"), never a number written for it. */
66
72
  Stat = 'stat',
73
+ /** AW1: a stamped legal page's text — what belongs there ("Your privacy policy: …"), never a word of policy. Its page
74
+ * holds Publish while it shows the label (`auditSite`, `legal-page-placeholder`, by the page's kind). */
75
+ Policy = 'policy',
67
76
  }
68
77
 
69
78
  /** The placeholders a page cannot be published with unfilled (W4's gate): a fact, a price, a number, the studio's own
@@ -132,6 +141,9 @@ export interface ComposeContext {
132
141
  photoShape?: (photoId: string) => `${LayoutPhotoShape}` | undefined;
133
142
  /** The tier the plan was made at (its generation's stored tier, AW-D23) — absent = Basic: at most two composed pages. */
134
143
  tier?: `${GenerationTier}`;
144
+ /** AW1: what the studio holds that decides its legal pages and banner (country, trackers, its own legal pages, its
145
+ * routes, a banner it keeps). Absent = only what the plan and the composed pages say (no tracker, no country). */
146
+ legal?: LegalContext;
135
147
  }
136
148
 
137
149
  /** Where a composed layout's photos are, as the server keeps them and the screens read them (M8 gate 2): id → address. */
@@ -142,8 +154,8 @@ export interface LayoutPhotoAddress {
142
154
  }
143
155
 
144
156
  /** 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 } : {};
157
+ export function composeContextOf(year: number, photos?: Readonly<Record<string, LayoutPhotoAddress>>, tier?: `${GenerationTier}`, legal?: LegalContext | null): ComposeContext {
158
+ const tiered = { ...(tier ? { tier } : {}), ...(legal ? { legal } : {}) };
147
159
  if (!photos) return { year, ...tiered };
148
160
  return {
149
161
  year,
@@ -164,7 +176,7 @@ export interface ComposedPage {
164
176
  locale: `${SiteLocale}`;
165
177
  /** DS3: every page the wizard creates follows the look (page-bg / text / font-body). M8 gate 2: a composed page names
166
178
  * 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}` };
179
+ pageSettings: { designSystem: true; layoutSource?: { pageKey: string; runId?: string }; opening?: `${ColorScheme}`; legal?: `${LegalKind}` };
168
180
  /** M1-6c: the page's search-result words — written (a static page) or bound to the route item (a template page),
169
181
  * in the seo-core document shape the shared `resolveSeo` reads. */
170
182
  seo: SeoRawDoc;
@@ -682,12 +694,14 @@ function composeForm(node: SerializedNode, pn: PatternNode, id: string, ctx: Ctx
682
694
  stampPresetForm(node, presetId, id, ctx.owner);
683
695
  }
684
696
 
685
- /** A preset's name, stable form id and children on a Form node — the ONE stamping `composeSite` and `composeLayout` share. */
697
+ /** 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
698
  function stampPresetForm(node: SerializedNode, presetId: string, id: string, owner: string): void {
687
699
  const preset = formPresetById(presetId);
688
700
  if (!preset) throw new ComposeError(`${id}: no form preset "${presetId}" in forms-core`);
689
701
  setProp(node, 'name', preset.formName);
690
702
  setProp(node, 'formId', `${preset.id}-${stableHash(`${owner}/${id}`)}`);
703
+ const actions = presetFormActions(preset);
704
+ if (actions) setProp(node, 'actions', actions);
691
705
  node.children = presetChildren(preset, id);
692
706
  }
693
707
 
@@ -1579,6 +1593,10 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1579
1593
  if (pattern.header && root) setHeaderBehaviour(root as unknown as CompositeNode, pattern.header.behaviour, pattern.header.edge ?? null);
1580
1594
  }
1581
1595
  if (planSells(plan)) globals = withStore(globals, plan.locale ?? DEFAULT_SITE_LOCALE);
1596
+ // AW1: the law, derived from facts and never asked — the legal pages, the banner when a tracker is connected, the
1597
+ // footer's legal row and the line beside every form that asks for personal details.
1598
+ const legal = composeLegal(plan, context.legal ?? {}, pages, globals, footer.mix.arrange, placeholders);
1599
+ globals = legal.globals;
1582
1600
 
1583
1601
  return {
1584
1602
  source: clone(plan.source),
@@ -1587,15 +1605,179 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1587
1605
  schemas: clone(plan.contentTypes) as ContentTypePlan[],
1588
1606
  items: Object.fromEntries(plan.contentTypes.map(t => [t.name, composeItems(t, plan.source.kind === SitePlanSourceKind.Ai)])),
1589
1607
  dataSources: plan.dataSources.map(composeDataSource),
1590
- pages,
1608
+ pages: [...pages, ...legal.pages],
1591
1609
  globals,
1592
- routes: plan.pages.map(p => ({ key: p.key, path: p.route, isHome: p.isHome === true })),
1610
+ 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
1611
  placeholders,
1594
1612
  issues,
1595
1613
  shop: composeShop(plan),
1596
1614
  };
1597
1615
  }
1598
1616
 
1617
+ // ── AW1: the law (award-ingredients-plan §4) ──────────────────────────────────────────────────────────────────────
1618
+
1619
+ const LINK = 'Link';
1620
+ const HEADING = 'Heading';
1621
+ const SECTION = 'Section';
1622
+ const CONTAINER = 'Container';
1623
+ /** Inline words: the legal line reads as one sentence, its links inside it. */
1624
+ const INLINE = { display: 'inline', width: 'auto', minHeight: 'auto', padding: '0px 0px 0px 0px', margin: '0px 0px 0px 0px' };
1625
+
1626
+ /** The facts the law is decided by: the composed site's forms, what it sells, its language and the studio's country and trackers. */
1627
+ export function legalFactsOf(plan: SitePlan, context: LegalContext, nodes: ReadonlyArray<SerializedNode>): LegalFacts {
1628
+ const sells = planSells(plan);
1629
+ return {
1630
+ ...formLegalFacts(nodes),
1631
+ [LegalFact.Tracker]: (context.trackers?.length ?? 0) > 0,
1632
+ [LegalFact.Sells]: sells,
1633
+ // The shop ships what it sells (commerce shipping, C-D9) — no product is digital yet.
1634
+ [LegalFact.PhysicalGoods]: sells,
1635
+ [LegalFact.Hebrew]: (plan.locale ?? DEFAULT_SITE_LOCALE) === SiteLocale.He,
1636
+ ...countryLegalFacts(context.country),
1637
+ };
1638
+ }
1639
+
1640
+ /** A stamped legal page: its title and the placeholder that says what belongs there — never a word of policy (D-C7). */
1641
+ function composeLegalPage(kind: LegalKind, key: string, route: string, plan: SitePlan, placeholders: ComposedPlaceholder[]): ComposedPage {
1642
+ const locale = plan.locale ?? DEFAULT_SITE_LOCALE;
1643
+ const title = legalTitle(kind, locale);
1644
+ const label = legalLabel(kind, locale);
1645
+ const section = create(key, SECTION, {}, 'section');
1646
+ section.label = 'Legal page';
1647
+ const column = create(`${key}-0`, CONTAINER, {}, 'box');
1648
+ setStyleProps(column, { display: 'flex', flexDirection: 'column', gap: '18px', maxWidth: '720px', width: '100%', margin: '0px auto 0px auto' });
1649
+ const heading = create(`${key}-0-0`, HEADING, { content: title, level: 'h1' }, 'h1');
1650
+ const text = create(`${key}-0-1`, TEXT, { content: label }, 'body');
1651
+ column.children = [heading, text];
1652
+ section.children = [column];
1653
+ placeholders.push({ nodeId: text.id, owner: key, kind: PlaceholderKind.Policy, text: label });
1654
+ const page: PagePlan = { key, name: title, route, sections: [] };
1655
+ return {
1656
+ key, name: title, route: { path: route }, isHome: false, status: STATUS_DRAFT, locale,
1657
+ pageSettings: { designSystem: true, [LEGAL_PAGE_SETTING]: kind } as ComposedPage['pageSettings'],
1658
+ seo: composePageSeo(page, plan), layout: [section],
1659
+ };
1660
+ }
1661
+
1662
+ /** A link to a legal page, worn as the look's link. */
1663
+ function legalLink(id: string, kind: LegalKind, route: string, locale: string, base: Readonly<Record<string, string>> = {}): SerializedNode {
1664
+ const link = create(id, LINK, { label: legalTitle(kind, locale) }, 'link');
1665
+ writePageLink(link, route);
1666
+ setStyleProps(link, { width: 'auto', minHeight: 'auto', ...base });
1667
+ return link;
1668
+ }
1669
+
1670
+ /** The footer's legal row (CONSENT `reopen.footer`, FOOTER `holds.legal`): every legal page, then Cookie settings. */
1671
+ function legalRow(routes: ReadonlyMap<LegalKind, string>, settings: SerializedNode | null, arrange: string, locale: string): SerializedNode | null {
1672
+ if (!routes.size && !settings) return null;
1673
+ const row = create(FOOTER_LEGAL_ROLE.replace('.', '-'), CONTAINER, {}, 'box');
1674
+ row.role = FOOTER_LEGAL_ROLE;
1675
+ row.label = 'Legal';
1676
+ setStyleProps(row, {
1677
+ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '8px 20px', width: '100%', minHeight: 'auto',
1678
+ justifyContent: arrange === FooterArrange.Centred ? 'center' : 'flex-start',
1679
+ });
1680
+ row.children = [...[...routes].map(([kind, route]) => legalLink(`${row.id}-${kind}`, kind, route, locale)), ...(settings ? [settings] : [])];
1681
+ return row;
1682
+ }
1683
+
1684
+ /** The legal line beside a form (AW-D15): the owner's words to edit, its links to the site's terms and privacy pages. */
1685
+ function formLegalLine(form: SerializedNode, routes: ReadonlyMap<LegalKind, string>, locale: string): SerializedNode | null {
1686
+ if (!routes.has(LegalKind.Privacy)) return null;
1687
+ const id = `${form.id}-legal`;
1688
+ const line = create(id, CONTAINER, {}, 'box');
1689
+ line.role = FORM_LEGAL_ROLE;
1690
+ line.label = 'Legal line';
1691
+ setStyleProps(line, { display: 'block', width: '100%', minHeight: 'auto' });
1692
+ line.children = legalFormLine(locale, routes.has(LegalKind.Terms)).map((part, i) => ('kind' in part
1693
+ ? legalLink(`${id}-${i}`, part.kind, routes.get(part.kind)!, locale, INLINE)
1694
+ : (() => {
1695
+ const words = create(`${id}-${i}`, TEXT, { content: part.text, tag: 'span' }, 'small');
1696
+ setStyleProps(words, INLINE);
1697
+ return words;
1698
+ })()));
1699
+ return line;
1700
+ }
1701
+
1702
+ /** Put the legal line after a form's fields and buttons — before its success and error blocks. */
1703
+ function withFormLine(form: SerializedNode, line: SerializedNode): void {
1704
+ const kids = form.children ?? (form.children = []);
1705
+ const at = kids.findIndex(k => k.type === FORM_SUCCESS || k.type === FORM_ERROR);
1706
+ kids.splice(at >= 0 ? at : kids.length, 0, line);
1707
+ }
1708
+
1709
+ /** The categories the trackers need a yes for, each once (Necessary never). */
1710
+ function trackerCategories(context: LegalContext): ConsentCategory[] {
1711
+ const out: ConsentCategory[] = [];
1712
+ for (const t of context.trackers ?? []) {
1713
+ const c = t.category as ConsentCategory;
1714
+ if (c !== ConsentCategory.Necessary && !out.includes(c)) out.push(c);
1715
+ }
1716
+ return out;
1717
+ }
1718
+
1719
+ /**
1720
+ * AW1 (C5): the law a site's facts call for — stamped, never asked. Each legal kind the facts need (`legalKindsFor`) is
1721
+ * the studio's own page when it has one (linked, never stamped again), else an empty flagged page on a free route; the
1722
+ * cookie banner and its preferences are stamped as globals when a tracker is connected (unless the studio keeps its
1723
+ * own); every footer gets the legal row (+ Cookie settings), every form that asks for personal details the legal line.
1724
+ * Pure: new globals, the stamped pages; forms and the footer gain their nodes in place.
1725
+ */
1726
+ function composeLegal(plan: SitePlan, context: LegalContext, pages: ReadonlyArray<ComposedPage>, globals: SerializedNode[], footerArrange: string,
1727
+ placeholders: ComposedPlaceholder[]): { pages: ComposedPage[]; globals: SerializedNode[] } {
1728
+ const locale = plan.locale ?? DEFAULT_SITE_LOCALE;
1729
+ const nodes = [...pages.flatMap(p => p.layout), ...globals];
1730
+ const kinds = legalKindsFor(legalFactsOf(plan, context, nodes));
1731
+ const taken = new Set<string>([...plan.pages.map(p => p.route), ...(context.takenRoutes ?? [])]);
1732
+ const keys = new Set(plan.pages.map(p => p.key));
1733
+ const routes = new Map<LegalKind, string>();
1734
+ const stamped: ComposedPage[] = [];
1735
+ for (const kind of kinds) {
1736
+ const own = context.existing?.[kind];
1737
+ if (own) { routes.set(kind, own); continue; }
1738
+ const route = legalRoute(kind, taken);
1739
+ taken.add(route);
1740
+ let key = `legal-${kind}`;
1741
+ for (let n = 2; keys.has(key); n++) key = `legal-${kind}-${n}`;
1742
+ keys.add(key);
1743
+ routes.set(kind, route);
1744
+ stamped.push(composeLegalPage(kind, key, route, plan, placeholders));
1745
+ }
1746
+
1747
+ const out = [...globals];
1748
+ let settings: SerializedNode | null = null;
1749
+ const categories = trackerCategories(context);
1750
+ if (context.trackers?.length) {
1751
+ const privacy = routes.get(LegalKind.Privacy);
1752
+ const consent = buildConsentRecipe(spec => create(spec.key, spec.type, { ...(spec.props ?? {}) }, spec.elementStyle ?? null) as CompositeNode, {
1753
+ lang: locale, categories, privacyRoute: privacy ?? null, privacyLabel: privacy ? legalTitle(LegalKind.Privacy, locale) : undefined,
1754
+ });
1755
+ settings = consent.settings as SerializedNode;
1756
+ if (context.keptPreferences) {
1757
+ // The studio keeps its own banner: the footer's Cookie settings opens ITS preferences, and no second banner.
1758
+ for (const ix of settings.interactions ?? []) for (const a of (ix as { actions?: Array<{ type?: string; target?: string }> }).actions ?? []) {
1759
+ if (a.type === ConsentActionType.OpenPreferences) a.target = context.keptPreferences;
1760
+ }
1761
+ } else {
1762
+ for (const root of [consent.banner, consent.preferences] as SerializedNode[]) {
1763
+ root.isGlobal = true;
1764
+ root.globalPosition = PatternGlobalPosition.After;
1765
+ out.push(root);
1766
+ }
1767
+ }
1768
+ }
1769
+ const footer = out.find(g => g.id === GlobalSlot.Footer);
1770
+ const row = footer ? legalRow(routes, settings, footerArrange, locale) : null;
1771
+ if (footer && row) (footer.children ?? (footer.children = [])).push(row);
1772
+
1773
+ walkSerialized([...pages.flatMap(p => p.layout), ...out, ...stamped.flatMap(p => p.layout)], n => {
1774
+ if (n.type !== FORM || !formAsksPersonalData(n)) return;
1775
+ const line = formLegalLine(n, routes, locale);
1776
+ if (line) withFormLine(n, line);
1777
+ });
1778
+ return { pages: stamped, globals: out };
1779
+ }
1780
+
1599
1781
  /** A plan's header (HI1): its mix as the product draws it, checked against the site, and the recipe to stamp — with what
1600
1782
  * was mended or drawn as something else, in words. */
1601
1783
  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
+ }
@@ -61,3 +61,4 @@ export * from './footer-mix';
61
61
  export * from './layout-edits';
62
62
  export * from './adjustments';
63
63
  export * from './site-tree';
64
+ export * from './legal';
@@ -9216,10 +9216,6 @@ export const SPEC_SITE_LAYOUT = {
9216
9216
  "phase": "AW2",
9217
9217
  "drawnAs": "none"
9218
9218
  },
9219
- "reopen.footer": {
9220
- "phase": "AW1",
9221
- "drawnAs": "settings"
9222
- },
9223
9219
  "reopen.pill": {
9224
9220
  "phase": "AW2",
9225
9221
  "drawnAs": "settings"
@@ -9401,12 +9397,12 @@ export const SPEC_SITE_LAYOUT = {
9401
9397
  "how": "the site is in Hebrew"
9402
9398
  },
9403
9399
  "israel": {
9404
- "read": "AW1",
9405
- "how": "the studio's country is Israel (a new fact in the reading)"
9400
+ "read": "built",
9401
+ "how": "the studio's country is Israel (Shop ▸ Settings ▸ country; a shekel studio starts in Israel)"
9406
9402
  },
9407
9403
  "eu-business": {
9408
- "read": "AW1",
9409
- "how": "the business is in a country that asks for an imprint (EU / DACH) — a new fact in the reading"
9404
+ "read": "built",
9405
+ "how": "the studio's country asks for an imprint (`imprintCountries`: the EU, the EEA and Switzerland)"
9410
9406
  },
9411
9407
  "us-business": {
9412
9408
  "read": "deferred",
@@ -9583,6 +9579,43 @@ export const SPEC_SITE_LAYOUT = {
9583
9579
  "en": "By sending, you agree to the {terms} and {privacy}.",
9584
9580
  "he": "בשליחה, את/ה מסכים/ה ל{terms} ול{privacy}."
9585
9581
  },
9582
+ "formLinePrivacy": {
9583
+ "en": "By sending, you agree to the {privacy}.",
9584
+ "he": "בשליחה, את/ה מסכים/ה ל{privacy}."
9585
+ },
9586
+ "imprintCountries": [
9587
+ "AT",
9588
+ "BE",
9589
+ "BG",
9590
+ "HR",
9591
+ "CY",
9592
+ "CZ",
9593
+ "DK",
9594
+ "EE",
9595
+ "FI",
9596
+ "FR",
9597
+ "DE",
9598
+ "GR",
9599
+ "HU",
9600
+ "IE",
9601
+ "IT",
9602
+ "LV",
9603
+ "LT",
9604
+ "LU",
9605
+ "MT",
9606
+ "NL",
9607
+ "PL",
9608
+ "PT",
9609
+ "RO",
9610
+ "SK",
9611
+ "SI",
9612
+ "ES",
9613
+ "SE",
9614
+ "IS",
9615
+ "LI",
9616
+ "NO",
9617
+ "CH"
9618
+ ],
9586
9619
  "rules": {
9587
9620
  "neverWritesPolicy": true,
9588
9621
  "editedPageKept": true,
@@ -279,9 +279,13 @@ export function siteTreeOf(studio: SiteStudio): SiteTree {
279
279
  };
280
280
  }
281
281
  const layout = page.layout ?? [];
282
+ // A page the build made that is not one of its plan's pages (AW1's stamped legal pages) is still the build's:
283
+ // drawn from its layout, Built — or Edited, by the same fingerprints (an edited legal page is kept by Undo).
284
+ const known = !!run && Array.isArray(run.edited);
282
285
  return {
283
286
  ...base, sections: layout.map(handSection), data: handData(layout, studio, label),
284
- maker: source?.runId ? SitePageMaker.Built : SitePageMaker.Owner, items: null,
287
+ maker: !source?.runId ? SitePageMaker.Owner : known && run!.edited!.includes(page._id) ? SitePageMaker.Edited : SitePageMaker.Built,
288
+ ...(run ? { editsKnown: known, builtAt: run.finishedAt ?? null } : {}), items: null,
285
289
  };
286
290
  });
287
291
  const nested = nestSitePages(nodes);