@vectoriox/iox-ui 5.96.2 → 5.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/commerce-core/index.d.ts +274 -2
  2. package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +312 -1
  3. package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
  4. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +2 -8
  5. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1114 -223
  7. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +115 -42
  9. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  10. package/generation-core/index.d.ts +515 -17
  11. package/harness-core/index.d.ts +66 -6
  12. package/package.json +1 -1
  13. package/src/commerce-core/public-api.ts +2 -0
  14. package/src/commerce-core/shipping.ts +22 -0
  15. package/src/commerce-core/site-checkout.ts +406 -0
  16. package/src/commerce-core/variants.ts +20 -0
  17. package/src/composite-core/shop-runtime.ts +2 -8
  18. package/src/generation-core/audit-site.ts +8 -0
  19. package/src/generation-core/compose-site.ts +130 -4
  20. package/src/generation-core/nav-shape.ts +4 -2
  21. package/src/generation-core/patterns.ts +25 -1
  22. package/src/generation-core/pictures.ts +1 -1
  23. package/src/generation-core/plan-derived.ts +10 -5
  24. package/src/generation-core/plan-edits.ts +8 -7
  25. package/src/generation-core/plan-wire.ts +59 -10
  26. package/src/generation-core/plan-words.ts +18 -1
  27. package/src/generation-core/public-api.ts +1 -0
  28. package/src/generation-core/shop-plan.ts +165 -0
  29. package/src/generation-core/showcase.ts +29 -4
  30. package/src/generation-core/site-build-run.ts +25 -0
  31. package/src/generation-core/site-plan.model.ts +49 -1
  32. package/src/generation-core/site-spec.generated.ts +330 -2
  33. package/src/generation-core/stock-photos.ts +19 -2
  34. package/src/generation-core/validate-site-plan.ts +146 -8
  35. package/src/harness-core/business-types.ts +13 -0
  36. package/src/harness-core/harness-spec.generated.ts +69 -39
  37. package/src/harness-core/needs.ts +30 -1
  38. package/src/harness-core/site-reading.ts +8 -2
@@ -9,15 +9,17 @@ import {
9
9
  AccordionAutoBinds, CompositeNodeSpec, findByRole, LIGHTBOX_LABEL, SLIDE_TO_ROW, SLIDE_TYPE, buildTabsRecipe, tabLabelNodeOf,
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
- setHeaderBehaviour,
12
+ setHeaderBehaviour, SHOP_RECIPES, ShopRecipe, ShopRole, bindShopPart, ShopBindTarget,
13
13
  } from '@vectoriox/iox-ui/composite-core';
14
14
 
15
15
  import { EntranceMark, EntrancePart, planEntrances } from './entrances';
16
16
  import { filmOfPlan } from './film';
17
17
  import { NODE_BASELINES } from './node-baselines.generated';
18
18
  import {
19
- BindScope, CardBindTarget, parsePatternPath, PatternDirective, PatternNode, PatternOpens, PatternPlaceholder, PatternRecipe, PatternTrack, SitePattern, patternById,
19
+ BindScope, CardBindTarget, parsePatternPath, PatternDirective, PatternGlobalPosition, PatternNode, PatternOpens, PatternPlaceholder, PatternRecipe, PatternTrack,
20
+ PriceBindTarget, SitePattern, patternById,
20
21
  } from './patterns';
22
+ import { planSells, shopCategoriesOf, shopContentType, variantNamesOf } from './shop-plan';
21
23
  import { recipeListBinds } from './recipe-fields';
22
24
  import { assertStyleSlots, ComposeError, createSerializedNode, SerializedBinding, SerializedNode, setStyleProps, walkSerialized } from './serialized-node';
23
25
  import { SitePlanSourceKind, ContentFieldControl, ContentFieldPlan,
@@ -25,7 +27,7 @@ import { SitePlanSourceKind, ContentFieldControl, ContentFieldPlan,
25
27
  PlanDataSourceType, RelativeOp, roleField, SiteLocale, SitePlan, SitePlanSource, SITE_FACT_LABELS, SiteBusiness,
26
28
  } from './site-plan.model';
27
29
  import { assertValidSitePlan, nextSourceOf, routeParams } from './validate-site-plan';
28
- import { NavShape, planNavShape } from './nav-shape';
30
+ import { NavRole, NavShape, planNavShape } from './nav-shape';
29
31
  import { composeLayout, LayoutColourMode, layoutBandScheme } from './compose-layout';
30
32
  import { LayoutGalleryList, LayoutPage, LayoutPhotoShape, LayoutPhotoSource, LayoutSite, parseLayoutPhotoId } from './layout-language';
31
33
  import { layoutMotionOf, layoutPresetOf } from './layout-look';
@@ -190,6 +192,31 @@ export interface ComposedSite {
190
192
  routes: ComposedRoute[];
191
193
  placeholders: ComposedPlaceholder[];
192
194
  issues: ComposeIssue[];
195
+ /** Commerce C-D21: what the build writes into the studio's SHOP (never a content type) — null when it sells nothing. */
196
+ shop: ComposedShop | null;
197
+ }
198
+
199
+ /** A sample product as the build writes it through the shop's own write path (its slug made there, from its title). */
200
+ export interface ComposedProduct {
201
+ title: string;
202
+ /** The category's label (the build writes the categories first and links each product to its own). */
203
+ category: string;
204
+ description: string;
205
+ options: Array<{ name: string; values: string[] }>;
206
+ /** Whether it varies, and its variants by name (one per combination; sold, no price, no stock — the owner's). */
207
+ productVariants: boolean;
208
+ variants: Array<{ name: string; enable: true }>;
209
+ /** Never a number (shop-aware §3i, T4): the price is the owner's — a sample's blocks Publish until it is set. */
210
+ pricing: { price: null; compareat: null };
211
+ /** Its picture, once the build placed one (a stock photo, the owner's, a made one) — absent until then. */
212
+ mainImage?: string;
213
+ isSample: true;
214
+ isPublished: true;
215
+ }
216
+
217
+ export interface ComposedShop {
218
+ categories: Array<{ label: string }>;
219
+ products: ComposedProduct[];
193
220
  }
194
221
 
195
222
  /** `{sampleImage:k}` — a bundled abstract sample image, never a stock photo (plan §6b). */
@@ -413,7 +440,7 @@ function detailLinkOf(scope: string, repeater: RepeaterScope | null, ctx: Ctx, n
413
440
  const type = typeSource ? contentTypeOfSource(typeSource, ctx.plan) : undefined;
414
441
  const page = type ? ctx.plan.pages.find(p => p.template === type.name && !!p.routeSource) : undefined;
415
442
  const byRoute = page ? ctx.plan.dataSources.find(d => d.alias === page.routeSource) : undefined;
416
- const filter = byRoute && byRoute.type === PlanDataSourceType.Cms ? byRoute.filterByRouteParam : undefined;
443
+ const filter = byRoute && byRoute.type !== PlanDataSourceType.Relative ? byRoute.filterByRouteParam : undefined;
417
444
  const [param] = page ? routeParams(page.route) : [];
418
445
  if (!page || !filter || !param) return null;
419
446
  return { route: page.route, param, binding: resolveScoped(`${scope}.${filter.field}`, repeater, ctx, nodeId) };
@@ -434,6 +461,7 @@ export function contentTypeOfSource(alias: string, plan: SitePlan): ContentTypeP
434
461
  const ds = plan.dataSources.find(d => d.alias === alias);
435
462
  if (!ds) return undefined;
436
463
  if (ds.type === PlanDataSourceType.Relative) return contentTypeOfSource(ds.within, plan);
464
+ if (ds.type === PlanDataSourceType.Shop) return shopContentType(ds.resource);
437
465
  return plan.contentTypes.find(t => t.name === ds.contentType);
438
466
  }
439
467
 
@@ -752,6 +780,11 @@ function composeNode(given: PatternNode, id: string, repeater: RepeaterScope | n
752
780
  throw new ComposeError(`${id}: "alt" belongs on a bound Image`);
753
781
  }
754
782
 
783
+ if (pn.limit !== undefined) {
784
+ if (type !== REPEATER) throw new ComposeError(`${id}: "limit" belongs on a Repeater`);
785
+ setProp(node, 'limit', pn.limit);
786
+ }
787
+
755
788
  // Layout.
756
789
  applyLayout(node, pn);
757
790
  if (pn.shownWhen) hideUntilOn(node, pn, ctx);
@@ -834,6 +867,7 @@ const CARD_BINDS: Readonly<Record<CardBindTarget, { role: CardRole; prop: string
834
867
  * through its title (`href` + `param`, the stretched link). Ids derive from the recipe's keys.
835
868
  */
836
869
  function composeRecipe(pn: PatternNode, id: string, repeater: RepeaterScope | null, ctx: Ctx): SerializedNode {
870
+ if (SHOP_PATTERN_RECIPES.has(pn.recipe as PatternRecipe)) return composeShopRecipe(pn, id, repeater, ctx);
837
871
  if (pn.recipe === PatternRecipe.Accordion) return composeAccordion(pn, id, ctx);
838
872
  if (pn.recipe === PatternRecipe.Tabs) return composeTabs(pn, id, ctx);
839
873
  if (pn.recipe === PatternRecipe.Carousel) return composeCarousel(pn, id, ctx);
@@ -1040,6 +1074,90 @@ function composeTabs(pn: PatternNode, id: string, ctx: Ctx): SerializedNode {
1040
1074
  }
1041
1075
 
1042
1076
  /** A recipe's node factory for this composer: ids derive from the recipe's keys (`<id>-<key>`, the root `<id>`). */
1077
+ /** Commerce G1: a pattern's shop recipes, each E1c's `SHOP_RECIPES` entry and the key its root is built with. */
1078
+ const SHOP_PATTERN_RECIPES: ReadonlyMap<PatternRecipe, { recipe: ShopRecipe; rootKey: string }> = new Map([
1079
+ [PatternRecipe.Price, { recipe: ShopRecipe.Price, rootKey: 'price' }],
1080
+ [PatternRecipe.Variants, { recipe: ShopRecipe.Variants, rootKey: 'variants' }],
1081
+ [PatternRecipe.Quantity, { recipe: ShopRecipe.Quantity, rootKey: 'quantity' }],
1082
+ [PatternRecipe.Add, { recipe: ShopRecipe.Add, rootKey: 'add' }],
1083
+ [PatternRecipe.BuyNow, { recipe: ShopRecipe.BuyNow, rootKey: 'buy-now' }],
1084
+ ]);
1085
+
1086
+ const PRICE_BINDS: Readonly<Record<PriceBindTarget, ShopBindTarget>> = {
1087
+ [PriceBindTarget.Price]: ShopBindTarget.Price,
1088
+ [PriceBindTarget.CompareAt]: ShopBindTarget.CompareAt,
1089
+ };
1090
+
1091
+ /** E1c's root keys of the recipes a site holds outside its sections — the header's bag and the one cart drawer. */
1092
+ const CART_BUTTON_KEY = 'cart-button';
1093
+ const CART_DRAWER_KEY = 'cart-drawer';
1094
+ /** The ids the composer gives them (the header's bag; the drawer, a global after the page). */
1095
+ export const SHOP_CART_BUTTON_ID = 'header-cart';
1096
+ export const SHOP_CART_DRAWER_ID = 'cart';
1097
+
1098
+ /**
1099
+ * Commerce G1: a shop part stamped whole from E1c's recipe (`SHOP_RECIPES`) — the product page's own reading the page's
1100
+ * product (`$variant`, the runtime's), a list's price re-bound to its ROW (`binds`: `item.@price` → `pricing.price`,
1101
+ * through `bindShopPart`, the money pipe kept). A compare-at the row's type cannot show is left out. Never an entrance.
1102
+ */
1103
+ function composeShopRecipe(pn: PatternNode, id: string, repeater: RepeaterScope | null, ctx: Ctx): SerializedNode {
1104
+ const spec = SHOP_PATTERN_RECIPES.get(pn.recipe as PatternRecipe)!;
1105
+ const root = SHOP_RECIPES[spec.recipe](recipeFactory(id, spec.rootKey)) as SerializedNode;
1106
+ if (root.id !== id) throw new ComposeError(`${id}: the ${pn.recipe} recipe's root is not "${spec.rootKey}"`);
1107
+ for (const [key, path] of Object.entries(pn.binds ?? {})) {
1108
+ const target = PRICE_BINDS[key as PriceBindTarget];
1109
+ if (spec.recipe !== ShopRecipe.Price || !target) throw new ComposeError(`${id}: a ${pn.recipe} cannot bind "${key}"`);
1110
+ const scoped = resolveScopedPath(path, repeater, ctx, id);
1111
+ if (scoped) {
1112
+ bindShopPart(root as CompositeNode, target, scoped.source, scoped.path);
1113
+ continue;
1114
+ }
1115
+ if (target === ShopBindTarget.Price) throw new ComposeError(`${id}: a price cannot be left out`);
1116
+ root.children = (root.children ?? []).filter(c => c.role !== ShopRole.PriceCompare);
1117
+ }
1118
+ if (pn.lay) setStyleProps(root, pn.lay);
1119
+ return root;
1120
+ }
1121
+
1122
+ /**
1123
+ * Commerce G1 (C-D21): a selling site is a whole store on every page — the header holds the bag (before the menu
1124
+ * button; the brand takes the row's free space, so the bag sits at the end on every width, either direction), and the
1125
+ * site holds the ONE cart drawer as a global after the page (`SHOP_GLOBAL_RECIPES`), which every bag opens. Check out
1126
+ * is the drawer's own (the fixed checkout). Pure: new globals.
1127
+ */
1128
+ function withStore(globals: SerializedNode[]): SerializedNode[] {
1129
+ const out = [...globals];
1130
+ const header = out.find(g => g.id === GlobalSlot.Header);
1131
+ if (header) {
1132
+ const kids = header.children ?? (header.children = []);
1133
+ const bag = SHOP_RECIPES[ShopRecipe.CartButton](recipeFactory(SHOP_CART_BUTTON_ID, CART_BUTTON_KEY)) as SerializedNode;
1134
+ const menu = kids.findIndex(k => k.role === NavRole.MenuButton);
1135
+ kids.splice(menu >= 0 ? menu : kids.length, 0, bag);
1136
+ const brand = kids.find(k => k.role === NavRole.Brand);
1137
+ if (brand) setStyleProps(brand, { flexGrow: '1' });
1138
+ }
1139
+ const drawer = SHOP_RECIPES[ShopRecipe.CartDrawer](recipeFactory(SHOP_CART_DRAWER_ID, CART_DRAWER_KEY)) as SerializedNode;
1140
+ drawer.isGlobal = true;
1141
+ drawer.globalPosition = PatternGlobalPosition.After;
1142
+ out.push(drawer);
1143
+ return out;
1144
+ }
1145
+
1146
+ /** The plan's products as the build writes them — samples, published, each with no price (the owner's to set). */
1147
+ function composeShop(plan: SitePlan): ComposedShop | null {
1148
+ if (!planSells(plan) || !plan.shop) return null;
1149
+ return {
1150
+ categories: shopCategoriesOf(plan.shop.products).map(label => ({ label })),
1151
+ products: plan.shop.products.map(p => ({
1152
+ title: p.name.trim(), category: p.category.trim(), description: p.description.trim(),
1153
+ options: p.options.map(o => ({ name: o.name.trim(), values: o.values.map(v => v.trim()) })),
1154
+ productVariants: variantNamesOf(p.options).length > 0,
1155
+ variants: variantNamesOf(p.options.map(o => ({ values: o.values.map(v => v.trim()) }))).map(name => ({ name, enable: true as const })),
1156
+ pricing: { price: null, compareat: null }, isSample: true, isPublished: true,
1157
+ })),
1158
+ };
1159
+ }
1160
+
1043
1161
  function recipeFactory(id: string, rootKey: string): (spec: CompositeNodeSpec) => CompositeNode {
1044
1162
  return spec => create(spec.key === rootKey ? id : `${id}-${spec.key}`, spec.type, { ...(spec.props ?? {}) }, spec.elementStyle ?? null) as CompositeNode;
1045
1163
  }
@@ -1181,6 +1299,12 @@ function composeDataSource(ds: DataSourcePlan): ComposedDataSource {
1181
1299
  if (ds.filterByRouteParam) cms['filterByRouteParam'] = { ...ds.filterByRouteParam };
1182
1300
  return { id, alias: ds.alias, type: PlanDataSourceType.Cms, mode: ds.mode, request: { cms } };
1183
1301
  }
1302
+ if (ds.type === PlanDataSourceType.Shop) {
1303
+ const shop: Record<string, unknown> = { contentType: ds.resource };
1304
+ if (ds.limit !== undefined) shop['limit'] = ds.limit;
1305
+ if (ds.filterByRouteParam) shop['filterByRouteParam'] = { ...ds.filterByRouteParam };
1306
+ return { id, alias: ds.alias, type: PlanDataSourceType.Shop, mode: ds.mode, request: { shop } };
1307
+ }
1184
1308
  const pick = ds.op === RelativeOp.SiblingsNext ? 'next' : 'prev';
1185
1309
  return {
1186
1310
  id, alias: ds.alias, type: PlanDataSourceType.Relative, mode: PlanDataSourceMode.Single,
@@ -1357,6 +1481,7 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1357
1481
  const root = header ? globals.find(g => g.id === slot) : null;
1358
1482
  if (header && root) setHeaderBehaviour(root as unknown as CompositeNode, header.behaviour, header.edge ?? null);
1359
1483
  }
1484
+ if (planSells(plan)) globals = withStore(globals);
1360
1485
 
1361
1486
  return {
1362
1487
  source: clone(plan.source),
@@ -1370,6 +1495,7 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1370
1495
  routes: plan.pages.map(p => ({ key: p.key, path: p.route, isHome: p.isHome === true })),
1371
1496
  placeholders,
1372
1497
  issues,
1498
+ shop: composeShop(plan),
1373
1499
  };
1374
1500
  }
1375
1501
 
@@ -1,3 +1,4 @@
1
+ import { ShopRole } from '@vectoriox/iox-ui/composite-core';
1
2
  import { LinkType } from '@vectoriox/iox-ui/design-core';
2
3
 
3
4
  import { PatternGlobalPosition } from './patterns';
@@ -433,9 +434,10 @@ function removeRole(node: SerializedNode, role: NavRole): SerializedNode | null
433
434
  return removed;
434
435
  }
435
436
 
436
- /** The root's own parts that hide at the phone width: everything but the brand, the menu button and the drawer. */
437
+ /** The root's own parts that hide at the phone width: everything but the brand, the menu button, the drawer and a
438
+ * store's bag (commerce G1 — a phone visitor reaches the cart from every page). */
437
439
  function phoneHiddenParts(root: SerializedNode): SerializedNode[] {
438
- const keep = new Set<string | undefined>([NavRole.Brand, NavRole.MenuButton, NavRole.Drawer]);
440
+ const keep = new Set<string | undefined>([NavRole.Brand, NavRole.MenuButton, NavRole.Drawer, ShopRole.CartButton]);
439
441
  return (root.children ?? []).filter((c, i) => !keep.has(roleOf(c)) && !(i === 0 && !c.role && c.type === LINKED));
440
442
  }
441
443
 
@@ -97,6 +97,8 @@ export interface PatternNode {
97
97
  readonly phoneTracks?: ReadonlyArray<PatternTrack>;
98
98
  /** SC6b: the Video a film pattern plays the owner's film in (its `frames`). */
99
99
  readonly film?: boolean;
100
+ /** Commerce G1: a Repeater shows at most this many rows of its source (`commerce.featured`: the newest one). */
101
+ readonly limit?: number;
100
102
  }
101
103
 
102
104
  /**
@@ -126,6 +128,19 @@ export enum PatternRecipe {
126
128
  Carousel = 'carousel',
127
129
  /** CC3: the Lightbox — a Dialog holding a Slider over the node's `src` (the gallery's own source). */
128
130
  Lightbox = 'lightbox',
131
+ /** Commerce G1 (E1c `SHOP_RECIPES`): the product's price — its own on a product page (`$variant`), the row's in a
132
+ * list (`binds`: `price`, `compareAt`). */
133
+ Price = 'price',
134
+ Variants = 'variants',
135
+ Quantity = 'quantity',
136
+ Add = 'add',
137
+ BuyNow = 'buyNow',
138
+ }
139
+
140
+ /** A price recipe's `binds` keys → the part each binds (E1c `ShopBindTarget`). */
141
+ export enum PriceBindTarget {
142
+ Price = 'price',
143
+ CompareAt = 'compareAt',
129
144
  }
130
145
 
131
146
  /** A recipe node's `binds` keys → the part each binds (Card v2). */
@@ -162,6 +177,9 @@ export interface SitePattern {
162
177
  readonly scene?: boolean;
163
178
  /** SC6b: a Scene that plays the owner's film. Placed by `placeFilm`, never chosen: no manifest or wire lists it. */
164
179
  readonly film?: boolean;
180
+ /** Commerce G1: a store section — it reads the shop (its products, a product's price and variants). Listed only to
181
+ * a business that sells. */
182
+ readonly shop?: boolean;
165
183
  readonly node: PatternNode;
166
184
  }
167
185
 
@@ -347,11 +365,15 @@ export interface PatternManifestEntry {
347
365
  form: boolean;
348
366
  /** SC6: it holds the page as it scrolls — one per page, the home page and at most one other. */
349
367
  scene?: boolean;
368
+ /** Commerce G1: a store section — it binds the shop's sources. */
369
+ shop?: boolean;
350
370
  }
351
371
 
352
372
  export interface PatternManifestOptions {
353
373
  /** The site's How animated: below `SCENE_LEVEL` the Scenes are left out — a model cannot choose what it never sees. */
354
374
  animate?: string | null;
375
+ /** Commerce G1: whether the business sells — when false the store sections are left out; absent, all of them. */
376
+ sells?: boolean;
355
377
  }
356
378
 
357
379
  /**
@@ -360,7 +382,8 @@ export interface PatternManifestOptions {
360
382
  */
361
383
  export function patternManifest(density?: string | null, options: PatternManifestOptions = {}): PatternManifestEntry[] {
362
384
  const scenes = !('animate' in options) || options.animate === SCENE_LEVEL;
363
- return Object.entries(SITE_PATTERNS).filter(([, p]) => !p.film && (scenes || !p.scene)).map(([id, p]) => ({
385
+ const store = options.sells !== false;
386
+ return Object.entries(SITE_PATTERNS).filter(([, p]) => !p.film && (scenes || !p.scene) && (store || !p.shop)).map(([id, p]) => ({
364
387
  id, family: p.family, label: p.label, intent: p.intent, ...(p.global ? { global: p.global } : {}),
365
388
  slots: Object.fromEntries(Object.keys(patternSlotBudgets(p)).map(slot => [slot, slotBudget(p, slot, density) as number])),
366
389
  links: patternLinkSlots(p),
@@ -369,6 +392,7 @@ export function patternManifest(density?: string | null, options: PatternManifes
369
392
  optionalParts: patternOptionalParts(p),
370
393
  form: patternHasForm(p),
371
394
  ...(p.scene ? { scene: true } : {}),
395
+ ...(p.shop ? { shop: true } : {}),
372
396
  }));
373
397
  }
374
398
 
@@ -105,7 +105,7 @@ export interface PicturePlanOptions {
105
105
  }
106
106
 
107
107
  /** The ONE list of picture slots a build fills — its composed sections' empty pictures, then its sample items'. */
108
- export function pictureTargets(plan: SitePlan, composed: Pick<ComposedSite, 'pages' | 'placeholders' | 'items'>): StockTarget[] {
108
+ export function pictureTargets(plan: SitePlan, composed: Pick<ComposedSite, 'pages' | 'placeholders' | 'items'> & Partial<Pick<ComposedSite, 'shop'>>): StockTarget[] {
109
109
  return [...stockSlots(plan, composed), ...stockItemSlots(plan, composed)];
110
110
  }
111
111
 
@@ -1,6 +1,7 @@
1
1
  import { BindScope, patternById, patternScopes } from './patterns';
2
2
  import { DataSourcePlan, PlanDataSourceMode, PlanDataSourceType, RelativeOp } from './site-plan.model';
3
3
  import { isNonEmptyString, isPlainObject, PlainObject } from './shape-check';
4
+ import { derivedShopSources } from './shop-plan';
4
5
  import { nextSourceOf } from './validate-site-plan';
5
6
 
6
7
  /**
@@ -75,10 +76,14 @@ export function derivedDataSources(plan: unknown): DataSourcePlan[] {
75
76
  return derived;
76
77
  }
77
78
 
78
- /** `plan` with the data sources its pages need appended (`derivedDataSources`); the same object when it lacks none. */
79
+ /**
80
+ * `plan` with the data sources that follow from it appended: a selling plan's shop sources (`derivedShopSources`, commerce
81
+ * C-D21), then those its pages need (`derivedDataSources`). The same object when it lacks none.
82
+ */
79
83
  export function withDerivedSources<T>(plan: T): T {
80
- const derived = derivedDataSources(plan);
81
- if (!derived.length) return plan;
82
- const own = plan as unknown as PlainObject;
83
- return { ...own, dataSources: [...(own['dataSources'] as unknown[]), ...derived] } as T;
84
+ const shop = derivedShopSources(plan);
85
+ const withShop = shop.length ? { ...(plan as unknown as PlainObject), dataSources: [...((plan as unknown as PlainObject)['dataSources'] as unknown[]), ...shop] } : plan as unknown as PlainObject;
86
+ const derived = derivedDataSources(withShop);
87
+ if (!derived.length) return withShop as unknown as T;
88
+ return { ...withShop, dataSources: [...(withShop['dataSources'] as unknown[]), ...derived] } as T;
84
89
  }
@@ -2,7 +2,7 @@ import {
2
2
  jsonAnyOf, jsonInteger, jsonListOf, jsonOneOf, JsonSchema, jsonShapedObject, jsonText,
3
3
  } from './json-schema';
4
4
  import { patternById, patternOptionalParts, patternSlots, patternTakesBinding } from './patterns';
5
- import { derivedDataSources } from './plan-derived';
5
+ import { withDerivedSources } from './plan-derived';
6
6
  import {
7
7
  contentTypeToWire, dataSourceToWire, expandWireContentType, expandWireDataSource, expandWireField, expandWirePage, expandWireSection, fieldToWire,
8
8
  pageToWire, PLAN_PARTS, PlanPart, PlanWireShapeError, sectionPatternIds, sectionToWire, wireContentTypeJsonSchema, wireDataSourceJsonSchema,
@@ -365,7 +365,7 @@ const APPLY: Readonly<Record<`${PlanEditOp}`, Apply>> = {
365
365
  const at = findPage(d, e.page, c, `${path}.page`);
366
366
  if (at < 0 || !findSection(d, at, e.index, c, `${path}.index`)) return;
367
367
  const source = d.dataSources.find(s => s.alias === e.binding);
368
- if (!source || source.type !== PlanDataSourceType.Cms || source.mode !== PlanDataSourceMode.Query) {
368
+ if (!source || source.type === PlanDataSourceType.Relative || source.mode !== PlanDataSourceMode.Query) {
369
369
  return c.add(PlanEditIssueCode.UnknownDataSource, `${path}.binding`, `no list source "${String(e.binding)}" in the plan`);
370
370
  }
371
371
  setSections(d, at, d.pages[at].sections.map((s, i) => (i === e.index ? { ...s, binding: e.binding } : s)));
@@ -391,7 +391,7 @@ export function recomposeAsks(edits: ReadonlyArray<PlanEdit>): Record<string, st
391
391
  /**
392
392
  * Apply a set of edits to a plan — all of them, or none (any issue refuses the set and returns the plan unchanged). The
393
393
  * sources only removed pages and sections read are dropped with them; sources nothing read before are kept; the sources
394
- * the pages now need and no model writes are derived (`derivedDataSources` — a page edit adding `project.next`, as the
394
+ * the pages now need and no model writes are derived (`withDerivedSources` — a page edit adding `project.next`, as the
395
395
  * plan wire's expansion does, vectoriox/iox-cms#49). The result still has to pass `validateSitePlan`.
396
396
  */
397
397
  export function applyPlanEdits(plan: SitePlan, edits: ReadonlyArray<PlanEdit>): PlanEditResult {
@@ -406,13 +406,14 @@ export function applyPlanEdits(plan: SitePlan, edits: ReadonlyArray<PlanEdit>):
406
406
  const before = withDependencies(aliasesOf(plan.pages), plan.dataSources);
407
407
  const after = withDependencies(aliasesOf(draft.pages), draft.dataSources);
408
408
  const added = new Set(changed.filter(ch => ch.kind === PlanChangeKind.DataSource).map(ch => ch.name));
409
- const dataSources = draft.dataSources.filter(s => after.has(s.alias) || !before.has(s.alias) || added.has(s.alias));
409
+ // A shop source follows from what the business sells, never from which page reads it (commerce G1): it stays.
410
+ const dataSources = draft.dataSources.filter(s => s.type === PlanDataSourceType.Shop || after.has(s.alias) || !before.has(s.alias) || added.has(s.alias));
410
411
  for (const s of draft.dataSources) if (!dataSources.includes(s)) changed.push({ kind: PlanChangeKind.DataSource, action: PlanChangeAction.Removed, name: s.alias });
411
412
  const edited = { ...plan, pages: draft.pages, contentTypes: draft.contentTypes, dataSources };
412
- const derived = derivedDataSources(edited);
413
- for (const s of derived) changed.push({ kind: PlanChangeKind.DataSource, action: PlanChangeAction.Added, name: s.alias });
413
+ const whole = withDerivedSources(edited);
414
+ for (const s of whole.dataSources.slice(dataSources.length)) changed.push({ kind: PlanChangeKind.DataSource, action: PlanChangeAction.Added, name: s.alias });
414
415
 
415
- return { plan: derived.length ? { ...edited, dataSources: [...dataSources, ...derived] } : edited, changed, issues: [] };
416
+ return { plan: whole, changed, issues: [] };
416
417
  }
417
418
 
418
419
  // ── The format a model writes edits in ─────────────────────────────────────────────────────────────────
@@ -4,9 +4,10 @@ import { planFormPresetIds } from '@vectoriox/iox-ui/forms-core';
4
4
  import { describeShapeKey, jsonAnyOf, jsonBoolean, jsonInteger, jsonListOf, jsonOneOf, JsonSchema, jsonShapedObject, jsonText } from './json-schema';
5
5
  import { patternLinkSlots, patternOptionalParts, patternSlots, PatternGlobalPosition, SITE_PATTERNS } from './patterns';
6
6
  import { withDerivedSources } from './plan-derived';
7
+ import { shopCategoriesOf } from './shop-plan';
7
8
  import { ContentFieldControl, FIELD_TYPE_OF_CONTROL,
8
9
  ContentFieldPlan, ContentTypePlan, DataSourcePlan, FactKey, GlobalSlot, PAGE_ARCHETYPES, PagePlan, PageSectionPlan, PlanDataSourceMode, PlanDataSourceType,
9
- RelativeOp, SITE_NEED_IDS, SITE_PLAN_VERSION, SitePlan, SitePlanSource, SiteLocale,
10
+ RelativeOp, ShopProductPlan, SITE_NEED_IDS, SITE_PLAN_VERSION, SitePlan, SitePlanSource, SiteLocale,
10
11
  } from './site-plan.model';
11
12
  import { SPEC_SITE_PLAN_SHAPE } from './site-spec.generated';
12
13
  import { isPlainObject, PlainObject, ShapeEntry, shapeKeys } from './shape-check';
@@ -71,6 +72,9 @@ export enum PlanWireEntry {
71
72
  SlotLink = 'slotLink',
72
73
  Globals = 'globals',
73
74
  Direction = 'direction',
75
+ /** Commerce C-D21: one product the business sells, by name. */
76
+ ShopProduct = 'shopProduct',
77
+ ShopOption = 'shopOption',
74
78
  }
75
79
 
76
80
  type PlanShapeName = keyof typeof SPEC_SITE_PLAN_SHAPE;
@@ -97,7 +101,11 @@ const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, Wir
97
101
  plan: {
98
102
  business: inPart(PlanPart.Structure, key('plan.business')),
99
103
  contentTypes: inPart(PlanPart.Structure, key('plan.contentTypes')),
100
- dataSources: inPart(PlanPart.Structure, { refs: ['plan.dataSources'], text: "dataSource[] — merged by alias into the org library; a per-item page's $siblings.next source (what a section reading the next item needs) is added for you" }),
104
+ dataSources: inPart(PlanPart.Structure, { refs: ['plan.dataSources'], text: "dataSource[] — merged by alias into the org library; a per-item page's $siblings.next source (what a section reading the next item needs) is added for you, and so are the shop's sources when the business sells" }),
105
+ shop: inPart(PlanPart.Structure, {
106
+ refs: ['plan.shop', 'shop.products'],
107
+ text: `shopProduct[] — what the business sells, when it sells (the need "products"): at most 6 sample products by name, each in a category — never a price, stock or a fee. [] = it sells nothing. Its categories, the shop's data sources (the products, the newest, one product by its :slug) and the store's parts are added for you`,
108
+ }),
101
109
  pages: inPart(PlanPart.Pages, key('plan.pages')),
102
110
  globals: inPart(PlanPart.Pages, key('plan.globals')),
103
111
  direction: inPart(PlanPart.Pages, key('plan.direction')),
@@ -141,13 +149,13 @@ const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, Wir
141
149
  each: { refs: ['seed.perItem'], text: 'string[] — one value per sample, in order, when each sample has its own content', none: '[]' },
142
150
  },
143
151
  dataSource: {
144
- alias: { refs: ['cmsDataSource.alias', 'relativeDataSource.alias'] },
145
- type: { refs: ['cmsDataSource.type', 'relativeDataSource.type'], text: "'cms' | 'relative' — which of the keys below are read" },
146
- mode: key('cmsDataSource.mode', "'' (relative)"),
147
- contentType: key('cmsDataSource.contentType', "'' (relative)"),
148
- limit: key('cmsDataSource.limit', '0 (all, or relative)'),
149
- filterField: { refs: ['cmsDataSource.filterByRouteParam'], text: "string — single only: the field that holds the route param's value (e.g. slug)", none: "''" },
150
- routeParam: { refs: ['cmsDataSource.filterByRouteParam'], text: 'string — single only: the route param that picks the item (the :param of its page route)', none: "''" },
152
+ alias: { refs: ['cmsDataSource.alias', 'relativeDataSource.alias', 'shopDataSource.alias'] },
153
+ type: { refs: ['cmsDataSource.type', 'relativeDataSource.type', 'shopDataSource.type'], text: "'cms' | 'relative' | 'shop' — which of the keys below are read ('shop' sources are added for you)" },
154
+ mode: { refs: ['cmsDataSource.mode', 'shopDataSource.mode'], none: "'' (relative)" },
155
+ contentType: { refs: ['cmsDataSource.contentType', 'shopDataSource.resource'], text: "string — a content type of the plan (cms); the shop's list, 'products' or 'categories' (shop)", none: "'' (relative)" },
156
+ limit: { refs: ['cmsDataSource.limit', 'shopDataSource.limit'], none: '0 (all, or relative)' },
157
+ filterField: { refs: ['cmsDataSource.filterByRouteParam', 'shopDataSource.filterByRouteParam'], text: "string — single only: the field that holds the route param's value (e.g. slug)", none: "''" },
158
+ routeParam: { refs: ['cmsDataSource.filterByRouteParam', 'shopDataSource.filterByRouteParam'], text: 'string — single only: the route param that picks the item (the :param of its page route)', none: "''" },
151
159
  of: key('relativeDataSource.of', "'' (cms)"),
152
160
  op: key('relativeDataSource.op', "'' (cms)"),
153
161
  within: key('relativeDataSource.within', "'' (cms)"),
@@ -190,6 +198,16 @@ const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, Wir
190
198
  header: key('globals.header'),
191
199
  footer: key('globals.footer'),
192
200
  },
201
+ shopProduct: {
202
+ name: key('shopProduct.name'),
203
+ category: key('shopProduct.category'),
204
+ description: key('shopProduct.description'),
205
+ options: key('shopProduct.options'),
206
+ },
207
+ shopOption: {
208
+ name: key('shopOption.name'),
209
+ values: key('shopOption.values'),
210
+ },
193
211
  };
194
212
 
195
213
  /** The plan keys the model does not write, and where the expander takes each from. */
@@ -210,6 +228,7 @@ export const PLAN_WIRE_DERIVED: Readonly<Record<string, string>> = {
210
228
  'plan.artDirection': 'the generation, from the business type and the look (M7 — artDirectionFor)',
211
229
  artDirection: 'the generation, from the business type and the look (M7 — artDirectionFor)',
212
230
  'page.layout': 'the layout step: one request per composed page, after the pages (M8 gate 2)',
231
+ 'shop.categories': "the products' own categories, in order (shopCategoriesOf)",
213
232
  layoutPage: 'the layout step: one request per composed page, after the pages (M8 gate 2)',
214
233
  };
215
234
 
@@ -364,8 +383,17 @@ const PLAN_TOP_SCHEMAS: Readonly<Record<string, () => JsonSchema>> = {
364
383
  [GlobalSlot.Footer]: jsonOneOf(globalIds(PatternGlobalPosition.After)),
365
384
  }),
366
385
  direction: () => shaped(PlanWireEntry.Direction, { idea: jsonText(), cliche: jsonText(), flip: jsonText(), rules: jsonListOf(jsonText()) }),
386
+ shop: () => jsonListOf(wireShopProductJsonSchema()),
367
387
  };
368
388
 
389
+ /** Commerce C-D21: one product the business sells, as the structure writes it — never a price, stock or a fee. */
390
+ export function wireShopProductJsonSchema(): JsonSchema {
391
+ return shaped(PlanWireEntry.ShopProduct, {
392
+ name: jsonText(), category: jsonText(), description: jsonText(),
393
+ options: jsonListOf(shaped(PlanWireEntry.ShopOption, { name: jsonText(), values: jsonListOf(jsonText()) })),
394
+ });
395
+ }
396
+
369
397
  /** The plan's top-level shape for one part (its keys only) — what that part's request shows and is built from. */
370
398
  export function planWirePartShape(part: PlanPart): ShapeEntry {
371
399
  return Object.fromEntries(Object.entries(PLAN_WIRE_SHAPE.plan).filter(([k]) => PLAN_PART_KEYS[part].includes(k)));
@@ -450,9 +478,21 @@ export function expandWireDataSource(wire: unknown): DataSourcePlan | unknown {
450
478
  return { ...rest, alias, type, mode, contentType, ...optional('limit', limit, v => v === undefined || v === 0), ...filter };
451
479
  }
452
480
  if (type === PlanDataSourceType.Relative) return { ...rest, alias, type, of, op, within };
481
+ if (type === PlanDataSourceType.Shop) {
482
+ const filter = isNone(filterField) && isNone(routeParam) ? {} : { filterByRouteParam: { field: filterField, routeParam } };
483
+ return { ...rest, alias, type, mode, resource: contentType, ...optional('limit', limit, v => v === undefined || v === 0), ...filter };
484
+ }
453
485
  return wire;
454
486
  }
455
487
 
488
+ /** The structure's products → the plan's `shop`: the products as written, their categories derived; `[]` = it sells nothing. */
489
+ export function expandWireShop(wire: unknown): unknown {
490
+ if (!Array.isArray(wire)) return wire;
491
+ if (!wire.length) return undefined;
492
+ const products = wire.filter(isPlainObject) as unknown as ShopProductPlan[];
493
+ return { categories: products.length === wire.length ? shopCategoriesOf(products) : [], products: wire };
494
+ }
495
+
456
496
  export function expandWireSection(wire: unknown): PageSectionPlan | unknown {
457
497
  if (!isPlainObject(wire)) return wire;
458
498
  const { slots, links, binding, without, form, enter, ...rest } = wire;
@@ -505,9 +545,11 @@ export function expandPlanWire(parts: PlanWireParts, context: PlanWireContext):
505
545
  const odd = written.find(value => !isPlainObject(value));
506
546
  if (odd !== undefined) return odd;
507
547
  const wire: PlainObject = Object.assign({}, ...(written as PlainObject[]));
508
- const { business, contentTypes, dataSources, pages, direction, ...rest } = wire;
548
+ const { business, contentTypes, dataSources, pages, direction, shop, ...rest } = wire;
549
+ const sells = expandWireShop(shop);
509
550
  return withDerivedSources({
510
551
  ...rest,
552
+ ...(sells === undefined ? {} : { shop: sells }),
511
553
  ...(isPlainObject(direction) && direction['idea'] === NONE ? {} : direction === undefined ? {} : { direction }),
512
554
  version: SITE_PLAN_VERSION,
513
555
  source: { ...context.source },
@@ -539,6 +581,12 @@ export function contentTypeToWire(type: ContentTypePlan, options: WireOptions =
539
581
  export function dataSourceToWire(source: DataSourcePlan): PlainObject {
540
582
  const blank = { alias: source.alias, type: source.type, mode: NONE, contentType: NONE, limit: 0, filterField: NONE, routeParam: NONE, of: NONE, op: NONE, within: NONE };
541
583
  if (source.type === PlanDataSourceType.Relative) return { ...blank, of: source.of, op: source.op, within: source.within };
584
+ if (source.type === PlanDataSourceType.Shop) {
585
+ return {
586
+ ...blank, mode: source.mode, contentType: source.resource, limit: source.limit ?? 0,
587
+ filterField: source.filterByRouteParam?.field ?? NONE, routeParam: source.filterByRouteParam?.routeParam ?? NONE,
588
+ };
589
+ }
542
590
  return {
543
591
  ...blank, mode: source.mode, contentType: source.contentType, limit: source.limit ?? 0,
544
592
  filterField: source.filterByRouteParam?.field ?? NONE, routeParam: source.filterByRouteParam?.routeParam ?? NONE,
@@ -569,6 +617,7 @@ const PLAN_TO_WIRE: Readonly<Record<string, (plan: SitePlan) => unknown>> = {
569
617
  pages: plan => plan.pages.map(page => pageToWire(page)),
570
618
  globals: plan => ({ ...plan.globals }),
571
619
  direction: plan => ({ idea: plan.direction?.idea ?? NONE, cliche: plan.direction?.cliche ?? NONE, flip: plan.direction?.flip ?? NONE, rules: [...(plan.direction?.rules ?? [])] }),
620
+ shop: plan => (plan.shop?.products ?? []).map(p => ({ name: p.name, category: p.category, description: p.description, options: p.options.map(o => ({ name: o.name, values: [...o.values] })) })),
572
621
  };
573
622
 
574
623
  /** One part of the plan on the wire: what that part's request would have answered. */
@@ -52,6 +52,16 @@ export function writtenTexts(plan: SitePlan): WrittenText[] {
52
52
  values.forEach((v, k) => add(`contentTypes[${t}].seed.${field}${Array.isArray(value) ? `[${k}]` : ''}`, v));
53
53
  }
54
54
  });
55
+ plan.shop?.products?.forEach((product, i) => {
56
+ const at = `shop.products[${i}]`;
57
+ add(`${at}.name`, product.name);
58
+ add(`${at}.category`, product.category);
59
+ add(`${at}.description`, product.description);
60
+ product.options?.forEach((option, j) => {
61
+ add(`${at}.options[${j}].name`, option.name);
62
+ option.values?.forEach((v, k) => add(`${at}.options[${j}].values[${k}]`, v));
63
+ });
64
+ });
55
65
  return out;
56
66
  }
57
67
 
@@ -69,14 +79,21 @@ export function wordPattern(word: string): RegExp {
69
79
  return new RegExp(`(?<![\\p{L}\\p{N}])${prefix}${w}(?![\\p{L}\\p{N}])`, 'u');
70
80
  }
71
81
 
82
+ const PRICE_SHAPE = { kind: 'price', pattern: /(?:[$€£₪]\s?\d[\d,.]*|\d[\d,.]*\s?(?:[$€£₪]|ש"ח|NIS|USD|EUR|GBP))/gu, key: (m: string) => m.replace(/[^\d]/g, '') };
83
+
72
84
  /** What a fact looks like when a model writes one — each judged against the owner's facts. */
73
85
  const FACT_SHAPES: ReadonlyArray<{ kind: string; pattern: RegExp; key: (match: string) => string }> = [
74
86
  { kind: 'email', pattern: /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+/gu, key: m => m.toLowerCase() },
75
87
  { kind: 'phone', pattern: /\+?\d[\d\s().-]{6,}\d/g, key: m => m.replace(/\D/g, '') },
76
- { kind: 'price', pattern: /(?:[$€£₪]\s?\d[\d,.]*|\d[\d,.]*\s?(?:[$€£₪]|ש"ח|NIS|USD|EUR|GBP))/gu, key: m => m.replace(/[^\d]/g, '') },
88
+ PRICE_SHAPE,
77
89
  { kind: 'time', pattern: /(?<!\d)\d{1,2}[:.]\d{2}(?!\d)/g, key: m => m.replace(/\D/g, '') },
78
90
  ];
79
91
 
92
+ /** Every price written in `text` (commerce C-D21: what a business sells never carries one — the owner sets prices). */
93
+ export function pricesIn(text: string): string[] {
94
+ return (text.match(PRICE_SHAPE.pattern) ?? []).map(m => m.trim());
95
+ }
96
+
80
97
  const MIN_PHONE_DIGITS = 8;
81
98
  /** "2019 – 2024" is two years, not a phone number. */
82
99
  const YEAR_RANGE = /^\s*\d{4}\s*[-–]\s*\d{4}\s*$/;
@@ -29,6 +29,7 @@ export * from './site-build-run';
29
29
  export * from './ai-run';
30
30
  export * from './recipe-fields';
31
31
  export * from './plan-derived';
32
+ export * from './shop-plan';
32
33
  export * from './plan-wire';
33
34
  export * from './strict-schema';
34
35
  export * from './plan-edits';