@vectoriox/iox-ui 5.202.1 → 5.203.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.
@@ -410,6 +410,9 @@ export enum FooterRepairCode {
410
410
  * `socialMax`, or on no known network: those left out. */
411
411
  SocialWithoutLinks = 'social-without-links',
412
412
  SocialLeftOut = 'social-left-out',
413
+ /** Social links (Doron 2026-11-29, FV-D10 completion): the owner stated their links, so the footer holds them — also when
414
+ * its mix did not ask for the block (a one-line or name-and-action footer keeps them too). */
415
+ SocialStated = 'social-stated',
413
416
  /** FV1b: a visit band before the footer says where and when — the visit block is not said twice. */
414
417
  VisitBeforeTwice = 'visit-before-twice',
415
418
  /** AW12-D6 (H1): a sign-up only where the site has a reason to write (a journal, events, a shop, a kind of business
@@ -560,20 +563,37 @@ function socialAddress(raw: string): URL | null {
560
563
  * owner did not state. An entry may hold several addresses (a stated line, space- or comma-separated). Pure.
561
564
  */
562
565
  export function footerSocialLinks(addresses?: ReadonlyArray<string> | null): { links: FooterSocialLink[]; leftOut: string[] } {
566
+ const { links, leftOut } = recognisedSocialLinks(addresses);
567
+ const max = rule('socialMax');
568
+ return { links: links.slice(0, max), leftOut: [...leftOut, ...links.slice(max).map(l => l.url)] };
569
+ }
570
+
571
+ /** One address as a social link the footer can name — its network by its host, a profile path, written https — or null
572
+ * (no http(s) address, on no network of the table, or a bare host). Pure. */
573
+ export function socialLinkOf(raw: string): FooterSocialLink | null {
574
+ const url = socialAddress(raw);
575
+ const host = url?.hostname.toLowerCase().replace(/^(www|m)\./, '');
576
+ const network = host ? FOOTER_SOCIAL_NETWORKS.find(n => n.hosts.some(h => host === h || host.endsWith(`.${h}`))) : undefined;
577
+ if (!url || !network || url.pathname.replace(/\/+$/, '') === '') return null;
578
+ return { network: network.id, name: network.name, url: url.href };
579
+ }
580
+
581
+ /** `footerSocialLinks` without the footer's `socialMax`: every recognised link, once per network (the first stated wins), in
582
+ * the table's order — what the owner's own list (the wizard, Site settings) holds. Pure. */
583
+ export function recognisedSocialLinks(addresses?: ReadonlyArray<string> | null): { links: FooterSocialLink[]; leftOut: string[] } {
563
584
  const found = new Map<string, FooterSocialLink>();
564
585
  const leftOut: string[] = [];
565
586
  for (const raw of (addresses ?? []).flatMap(a => String(a).split(/[\s,]+/)).filter(Boolean)) {
566
- const url = socialAddress(raw);
567
- const host = url?.hostname.toLowerCase().replace(/^(www|m)\./, '');
568
- const network = host ? FOOTER_SOCIAL_NETWORKS.find(n => n.hosts.some(h => host === h || host.endsWith(`.${h}`))) : undefined;
569
- if (!url || !network || url.pathname.replace(/\/+$/, '') === '' || found.has(network.id)) { leftOut.push(raw); continue; }
570
- found.set(network.id, { network: network.id, name: network.name, url: url.href });
587
+ const link = socialLinkOf(raw);
588
+ if (!link || found.has(link.network)) { leftOut.push(raw); continue; }
589
+ found.set(link.network, link);
571
590
  }
572
- const links = FOOTER_SOCIAL_NETWORKS.map(n => found.get(n.id)).filter((l): l is FooterSocialLink => !!l);
573
- const max = rule('socialMax');
574
- return { links: links.slice(0, max), leftOut: [...leftOut, ...links.slice(max).map(l => l.url)] };
591
+ return { links: FOOTER_SOCIAL_NETWORKS.map(n => found.get(n.id)).filter((l): l is FooterSocialLink => !!l), leftOut };
575
592
  }
576
593
 
594
+ /** True when the owner stated at least one social link the footer can name — the footer then always holds them. */
595
+ export const holdsStatedSocial = (ctx: Pick<FooterContext, 'social'>): boolean => footerSocialLinks(ctx.social).links.length > 0;
596
+
577
597
  /** True when the call word cannot stand on a phone even split over two balanced lines. */
578
598
  function wordTooWide(word: string, ctx: FooterContext): boolean {
579
599
  const halves = word.split(/\s+/);
@@ -641,6 +661,14 @@ export function checkFooter(given: FooterMix, ctx: FooterContext): { mix: Footer
641
661
  let arrange = mix.arrange;
642
662
  let nameStyle = nameStyleOf(mix);
643
663
  let ground = mix.ground;
664
+ // Social links (Doron 2026-11-29, FV-D10 completion): the links the owner stated are always in the footer — whatever the
665
+ // mix asked for, a one-line and a name-and-action footer too. None stated: nothing is drawn (the check below says so).
666
+ const stated = holdsStatedSocial(ctx);
667
+ if (stated && !holds.includes(FooterHold.Social)) {
668
+ say(FooterRepairCode.SocialStated, 'the owner gave their social links: the footer lists them');
669
+ holds = inOrder(FooterIngredient.Holds, [...holds, FooterHold.Social]);
670
+ }
671
+ const keepsSocial = (h: string): boolean => stated && h === FooterHold.Social;
644
672
  const why = ctx.never?.say?.length ? ` — ${(ctx.locale === 'he' && ctx.never.sayHe?.length ? ctx.never.sayHe : ctx.never.say).join(' ')}` : '';
645
673
  if (ctx.never?.closings.includes(closing)) {
646
674
  say(FooterRepairCode.TypeNever, `this kind of business never closes its footer with ${an(closing)}: the call${why}`);
@@ -655,7 +683,7 @@ export function checkFooter(given: FooterMix, ctx: FooterContext): { mix: Footer
655
683
  arrange = FooterArrange.Columns;
656
684
  }
657
685
  if (arrange === FooterArrange.Line) {
658
- const kept = holds.filter(h => (F.rules.lineHolds as ReadonlyArray<string>).includes(h) || BOTTOM_HOLDS.has(h));
686
+ const kept = holds.filter(h => (F.rules.lineHolds as ReadonlyArray<string>).includes(h) || BOTTOM_HOLDS.has(h) || keepsSocial(h));
659
687
  const left = holds.filter(h => !kept.includes(h));
660
688
  if (left.length) say(FooterRepairCode.LineHolds, `a one-line footer holds only ${F.rules.lineHolds.join(' and ')}: ${left.join(' and ')} left out`);
661
689
  holds = kept;
@@ -666,9 +694,9 @@ export function checkFooter(given: FooterMix, ctx: FooterContext): { mix: Footer
666
694
  closing = refused.instead;
667
695
  }
668
696
  if (closing === FooterClosing.NameAndAction) {
669
- const left = holds.filter(h => !END_HOLDS.includes(h));
697
+ const left = holds.filter(h => !END_HOLDS.includes(h) && !keepsSocial(h));
670
698
  if (left.length) say(FooterRepairCode.LeftOut, `a name-and-action footer holds the pages and the legal row: ${left.join(' and ')} left out`);
671
- holds = holds.filter(h => END_HOLDS.includes(h));
699
+ holds = holds.filter(h => END_HOLDS.includes(h) || keepsSocial(h));
672
700
  if (!footerNameFits(ctx)) say(FooterRepairCode.NameTooLong, `"${ctx.name}" is too long to stand across a phone: the action stays, the name is left out`);
673
701
  }
674
702
  if (arrange === FooterArrange.Ruled && partHolds(holds).length + 1 < rule('ruledMinBlocks')) {
@@ -806,7 +834,15 @@ function emailLine(email: string, ctx: FooterContext): PatternNode {
806
834
 
807
835
  /** FV1b `holds.social`: the part's template link once per stated link — the network's name, the owner's address. */
808
836
  function socialPart(ctx: FooterContext): PatternNode {
809
- const links = footerSocialLinks(ctx.social).links;
837
+ return socialLinksPart(ctx.social);
838
+ }
839
+
840
+ /**
841
+ * The owner's stated social links as THE part (`footer.social`: its "Follow" label and one link per network, the contract's
842
+ * template) — the footer's block, and the "follow" row a contact section carries (compose-site), one recipe. Pure.
843
+ */
844
+ export function socialLinksPart(social?: ReadonlyArray<string> | null): PatternNode {
845
+ const links = footerSocialLinks(social).links;
810
846
  const fill = (n: PatternNode): PatternNode => {
811
847
  const template = (n.c ?? []).find(k => k.role === FooterRole.SocialLink);
812
848
  if (template) return { ...n, c: links.map(l => ({ ...template, text: l.name, href: l.url })) };
@@ -815,6 +851,10 @@ function socialPart(ctx: FooterContext): PatternNode {
815
851
  return fill(part(FooterHold.Social));
816
852
  }
817
853
 
854
+ /** The social part's links alone (no label) — a one-line footer's and name-and-action's end block. */
855
+ const socialLinksRow = (ctx: FooterContext): PatternNode[] =>
856
+ (socialPart(ctx).c ?? []).filter(n => n.role === FooterRole.Links).map(n => laid(n, { width: 'auto' }));
857
+
818
858
  /** A block it holds: how to reach the business leaves its city to the visit block when the footer holds both. */
819
859
  function holdPart(hold: string, mix: FooterMix, ctx: FooterContext): PatternNode {
820
860
  if (hold === FooterHold.Social) return socialPart(ctx);
@@ -875,6 +915,7 @@ function bodyOf(mix: FooterMix, ctx: FooterContext): PatternNode[] {
875
915
  const row: PatternNode = { t: 'Container', es: 'box', lay: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', gap: GAP }, c: [
876
916
  laid(part('copyright'), { width: 'auto' }),
877
917
  ...(mix.holds.includes(FooterHold.Pages) ? [part('pageRow')] : []),
918
+ ...(mix.holds.includes(FooterHold.Social) ? socialLinksRow(ctx) : []),
878
919
  ...(mix.holds.includes(FooterHold.Top) ? [part(FooterHold.Top)] : []),
879
920
  ] };
880
921
  return [row];
@@ -923,7 +964,10 @@ function endOf(mix: FooterMix, ctx: FooterContext): PatternNode[] {
923
964
  const end = part('name-and-action');
924
965
  const kids = (end.c ?? []).map(n => {
925
966
  if (n.role === FooterRole.Links) return mix.holds.includes(FooterHold.Pages) ? n : null;
926
- if (n.role === FooterRole.EndBlock) return { ...n, c: [laid(part('copyright'), { textAlign: 'end' }), ...(n.c ?? [])] };
967
+ if (n.role === FooterRole.EndBlock) {
968
+ const social = mix.holds.includes(FooterHold.Social) ? socialLinksRow(ctx) : [];
969
+ return { ...n, c: [laid(part('copyright'), { textAlign: 'end' }), ...social, ...(n.c ?? [])] };
970
+ }
927
971
  return n;
928
972
  }).filter((n): n is PatternNode => !!n);
929
973
  return [{ ...end, c: kids }, ...(footerNameFits(ctx) ? [closingName(ctx, mix)] : [])];
@@ -610,6 +610,8 @@ export interface LayoutSite {
610
610
  sections: LayoutSection[];
611
611
  /** Award §0c CW2: the page's own column word (`LayoutPage.column`); absent = the design's (`ComposeLayoutOptions.design`). */
612
612
  column?: string;
613
+ /** Social links (FV-D10): the owner's stated WhatsApp as a contact form's channel address (`statedWhatsAppHref`). */
614
+ whatsApp?: string;
613
615
  }
614
616
 
615
617
  // ── The tables the composer reads (the prototype renderer v4's values, `code/renderer-round4.src.html`) ──────────────
@@ -99,6 +99,7 @@ export * from './opening-edit';
99
99
  export * from './footer-mix';
100
100
  export * from './footer-sign-up';
101
101
  export * from './footer-free';
102
+ export * from './social-links';
102
103
  export * from './layout-edits';
103
104
  export * from './adjustments';
104
105
  export * from './site-tree';
@@ -9326,6 +9326,16 @@ export const SPEC_SITE_LAYOUT = {
9326
9326
  "wa.me",
9327
9327
  "whatsapp.com"
9328
9328
  ]
9329
+ },
9330
+ {
9331
+ "id": "google",
9332
+ "name": "Google",
9333
+ "hosts": [
9334
+ "g.page",
9335
+ "g.co",
9336
+ "maps.app.goo.gl",
9337
+ "business.google.com"
9338
+ ]
9329
9339
  }
9330
9340
  ],
9331
9341
  "callWords": [
@@ -0,0 +1,177 @@
1
+ import { channelHref, ChannelKind } from '@vectoriox/iox-ui/forms-core';
2
+
3
+ import { FOOTER_SOCIAL_NETWORKS, footerSocialLinks, FooterSocialLink, recognisedSocialLinks, socialLinkOf, socialLinksPart } from './footer-mix';
4
+ import { PatternNode } from './patterns';
5
+ import { FACT_KEYS } from './site-plan.model';
6
+
7
+ /**
8
+ * THE OWNER'S SOCIAL LINKS (footer-v2-plan.md FV-D10, completed 2026-11-29 — Doron: "the website generator completely
9
+ * ignores social networks … they shall be in the contact area or footer"). The owner types them in the wizard (one input per
10
+ * network of the contract's `FOOTER.socialNetworks`) or in Site settings ▸ Socials; a typed address is STATED by definition
11
+ * (harness `statedFacts.social`) — never searched for, completed or guessed. This module is the ONE rule the wizard, Site
12
+ * settings and iox-cms share:
13
+ *
14
+ * - `ownerSocialLink` — what the owner typed under one network, as its https link, or why it is not one;
15
+ * - `socialLinksByNetwork` / `socialLinksList` — several lists (the reading's, the owner's, Site settings') merged, once per
16
+ * network, the first list winning;
17
+ * - `SITE_SOCIAL_FIELDS`, `siteSocialLinks`, `siteSocialPatch` — the Site settings record's fields, read and written;
18
+ * - `statedWhatsAppHref` — a stated WhatsApp link as the contact form's WhatsApp channel (forms-core `channelHref`);
19
+ * - `withFollowRow` — a contact section with the footer's social part ("Follow" and the links) beside its contact facts.
20
+ *
21
+ * Pure and framework-free (iox-cms imports it).
22
+ */
23
+
24
+ /** Why a typed address is not the owner's link on that network — the wizard says it under the input. */
25
+ export enum SocialLinkRefusal {
26
+ /** Not a web address (and, under WhatsApp, not a phone number either). */
27
+ NotAnAddress = 'not-an-address',
28
+ /** A scheme other than https (javascript:, ftp:, mailto: …) — http is written https. */
29
+ NotHttps = 'not-https',
30
+ /** A web address on no network the footer can name. */
31
+ UnknownNetwork = 'unknown-network',
32
+ /** An address of ANOTHER network than the input it was typed in ("facebook.com/x" under Instagram). */
33
+ OtherNetwork = 'other-network',
34
+ /** The network's bare address ("instagram.com") — the owner's own page has a path. */
35
+ NoProfile = 'no-profile',
36
+ }
37
+
38
+ /** What the owner typed under one network: its link, or why not. Empty input: null (nothing stated). */
39
+ export type OwnerSocialLink =
40
+ | { readonly ok: true; readonly link: FooterSocialLink }
41
+ | { readonly ok: false; readonly refusal: SocialLinkRefusal; readonly network?: string };
42
+
43
+ const WHATSAPP = 'whatsapp';
44
+ /** A phone number as typed: digits with the usual separators, an optional leading +. */
45
+ const PHONE = /^\+?[\d\s().-]+$/;
46
+ const SCHEME = /^([a-z][a-z0-9+.-]*):/i;
47
+ const WEB_SCHEMES: ReadonlyArray<string> = ['http', 'https'];
48
+
49
+ /** The network a host belongs to (bare: no `www.` / `m.`), or null. */
50
+ function networkOfHost(host: string): string | null {
51
+ const bare = host.toLowerCase().replace(/^(www|m)\./, '');
52
+ return FOOTER_SOCIAL_NETWORKS.find(n => n.hosts.some(h => bare === h || bare.endsWith(`.${h}`)))?.id ?? null;
53
+ }
54
+
55
+ /**
56
+ * What the owner typed under one network as its https link — or the reason it is none (said under the input). Under
57
+ * WhatsApp a phone number is the address too (`wa.me/<digits>`, forms-core `channelHref`: the digits as typed, with the
58
+ * country code). Pure.
59
+ */
60
+ export function ownerSocialLink(network: string, typed: unknown): OwnerSocialLink | null {
61
+ const raw = typeof typed === 'string' ? typed.trim() : '';
62
+ if (!raw) return null;
63
+ if (network === WHATSAPP && PHONE.test(raw)) {
64
+ const href = channelHref(ChannelKind.WhatsApp, raw);
65
+ const link = href ? socialLinkOf(href) : null;
66
+ return link ? { ok: true, link } : { ok: false, refusal: SocialLinkRefusal.NotAnAddress };
67
+ }
68
+ const scheme = SCHEME.exec(raw)?.[1]?.toLowerCase();
69
+ if (scheme && !WEB_SCHEMES.includes(scheme)) return { ok: false, refusal: SocialLinkRefusal.NotHttps };
70
+ let host: string;
71
+ try {
72
+ host = new URL(scheme && WEB_SCHEMES.includes(scheme) ? raw : `https://${raw}`).hostname;
73
+ } catch {
74
+ return { ok: false, refusal: SocialLinkRefusal.NotAnAddress };
75
+ }
76
+ if (!host.includes('.')) return { ok: false, refusal: SocialLinkRefusal.NotAnAddress };
77
+ const on = networkOfHost(host);
78
+ if (!on) return { ok: false, refusal: SocialLinkRefusal.UnknownNetwork };
79
+ if (on !== network) return { ok: false, refusal: SocialLinkRefusal.OtherNetwork, network: on };
80
+ const link = socialLinkOf(raw);
81
+ return link ? { ok: true, link } : { ok: false, refusal: SocialLinkRefusal.NoProfile };
82
+ }
83
+
84
+ /**
85
+ * Several lists of addresses (each a stated line or a list) as ONE link per network — the FIRST list naming a network wins
86
+ * (pass the owner's own first), in the table's order. Unrecognised addresses are dropped (the footer could not name them
87
+ * either). Pure.
88
+ */
89
+ export function socialLinksByNetwork(...lists: ReadonlyArray<ReadonlyArray<string> | null | undefined>): Partial<Record<string, string>> {
90
+ const out: Partial<Record<string, string>> = {};
91
+ for (const list of lists) {
92
+ for (const link of recognisedSocialLinks(list).links) if (!out[link.network]) out[link.network] = link.url;
93
+ }
94
+ return out;
95
+ }
96
+
97
+ /** `socialLinksByNetwork` as the stated list (`business.social`, `statedFacts.social`): one https address per network, in
98
+ * the table's order. Pure. */
99
+ export function socialLinksList(...lists: ReadonlyArray<ReadonlyArray<string> | null | undefined>): string[] {
100
+ const by = socialLinksByNetwork(...lists);
101
+ return FOOTER_SOCIAL_NETWORKS.map(n => by[n.id]).filter((u): u is string => !!u);
102
+ }
103
+
104
+ /**
105
+ * The Site settings record's field for each network (iox-cms `site` schema; Site settings ▸ Socials). The four older
106
+ * fields keep their names (`linkedIn`, `twitter`); every other network's field is its id. Site settings is the ONE place the
107
+ * links live after a build writes them back (`siteSocialPatch`).
108
+ */
109
+ export const SITE_SOCIAL_FIELDS: Readonly<Record<string, string>> = Object.fromEntries(
110
+ FOOTER_SOCIAL_NETWORKS.map(n => [n.id, ({ linkedin: 'linkedIn', x: 'twitter' } as Readonly<Record<string, string>>)[n.id] ?? n.id]),
111
+ );
112
+
113
+ /** The links a Site settings record holds (a WhatsApp field may hold a phone number), once per network. Pure. */
114
+ export function siteSocialLinks(site: Readonly<Record<string, unknown>> | null | undefined): string[] {
115
+ const typed = FOOTER_SOCIAL_NETWORKS.map(n => {
116
+ const owned = ownerSocialLink(n.id, site?.[SITE_SOCIAL_FIELDS[n.id]]);
117
+ return owned?.ok ? owned.link.url : '';
118
+ });
119
+ return socialLinksList(typed.filter(Boolean));
120
+ }
121
+
122
+ /** The Site settings fields that change when the links are written back — only networks the links name and whose field
123
+ * holds something else (a field is never cleared). Empty: nothing to write. Pure. */
124
+ export function siteSocialPatch(links: ReadonlyArray<string> | null | undefined, site: Readonly<Record<string, unknown>> | null | undefined): Record<string, string> {
125
+ const by = socialLinksByNetwork(links);
126
+ const patch: Record<string, string> = {};
127
+ for (const [network, url] of Object.entries(by)) {
128
+ const field = SITE_SOCIAL_FIELDS[network];
129
+ const held = ownerSocialLink(network, site?.[field]);
130
+ if (url && !(held?.ok && held.link.url === url)) patch[field] = url;
131
+ }
132
+ return patch;
133
+ }
134
+
135
+ /** A stated WhatsApp link (`wa.me/<number>`) as the contact form's WhatsApp channel address (forms-core `channelHref`), or
136
+ * '' — a whatsapp.com page that is no number is no chat. Pure. */
137
+ export function statedWhatsAppHref(social: ReadonlyArray<string> | null | undefined): string {
138
+ const url = socialLinksByNetwork(social)[WHATSAPP];
139
+ if (!url) return '';
140
+ const parsed = new URL(url);
141
+ const number = parsed.hostname.replace(/^www\./, '') === 'wa.me' ? parsed.pathname.slice(1) : parsed.searchParams.get('phone') ?? '';
142
+ return channelHref(ChannelKind.WhatsApp, number);
143
+ }
144
+
145
+ /** The family whose sections carry the "follow" row (the contract's contact patterns). */
146
+ export const FOLLOW_ROW_FAMILY = 'contact';
147
+
148
+ /** Index paths (from the root) of every node that shows a contact fact (`ph: email | phone | city | address | hours`). */
149
+ function factPaths(node: PatternNode, at: number[] = []): number[][] {
150
+ const own = node.ph && (FACT_KEYS as ReadonlyArray<string>).includes(node.ph) ? [at] : [];
151
+ return [...own, ...(node.c ?? []).flatMap((k, i) => factPaths(k, [...at, i]))];
152
+ }
153
+
154
+ /** The longest path every one of `paths` starts with. */
155
+ function commonStart(paths: ReadonlyArray<ReadonlyArray<number>>): number[] {
156
+ const out: number[] = [];
157
+ for (let i = 0; paths.every(p => i < p.length && p[i] === paths[0][i]); i++) out.push(paths[0][i]);
158
+ return out;
159
+ }
160
+
161
+ /**
162
+ * A contact section with the owner's stated social links (Doron 2026-11-29: "in the contact area"): THE footer part
163
+ * (`socialLinksPart` — its "Follow" label and one link per network, the same recipe, no copy) placed in the box that holds
164
+ * the section's contact facts (the details column of `contact.split`, the grid of `contact.simple`), after them; a section
165
+ * with no fact line takes it at the end of its first box. None stated, or nothing the footer can name: the section as it
166
+ * was. Pure — a new node, the input never touched.
167
+ */
168
+ export function withFollowRow(node: PatternNode, social: ReadonlyArray<string> | null | undefined): PatternNode {
169
+ if (!footerSocialLinks(social).links.length) return node;
170
+ const facts = factPaths(node);
171
+ const box = facts.length ? commonStart(facts.map(p => p.slice(0, -1))) : node.c?.[0]?.t === 'Container' ? [0] : null;
172
+ if (!box) return node;
173
+ const place = (n: PatternNode, path: ReadonlyArray<number>): PatternNode => path.length
174
+ ? { ...n, c: (n.c ?? []).map((k, i) => (i === path[0] ? place(k, path.slice(1)) : k)) }
175
+ : { ...n, c: [...(n.c ?? []), socialLinksPart(social)] };
176
+ return place(node, box);
177
+ }