@vectoriox/iox-ui 5.173.0 → 5.174.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.
@@ -19,6 +19,7 @@ import { footerMixFromWords } from './footer-mix';
19
19
  import { headerMixFromWords } from './header-mix';
20
20
  import { openingMixFromWords } from './opening-mix';
21
21
  import { bodyMixFromWords } from './body-mix';
22
+ import { popupMixFromWords } from './popup-plan';
22
23
  import { patternListGap } from './recipe-fields';
23
24
  import { freeSlotIssues } from './check-free';
24
25
  import { FREE_ELEMENT_STYLES, FREE_HOLDERS, FREE_MOVES, FREE_WORD_TYPES, FreeLayer, FreeNode, FreeNodeType, FreeTrigger } from './free-wire';
@@ -144,6 +145,7 @@ const SHAPE: Readonly<Record<string, ShapeEntry>> = SPEC_SITE_PLAN_SHAPE;
144
145
  const PLAN_KEYS = shapeKeys(SHAPE['plan']);
145
146
  const TEMPLATE_SOURCE_KEYS = shapeKeys(SHAPE['sourceTemplate']);
146
147
  const AI_SOURCE_KEYS = shapeKeys(SHAPE['sourceAi']);
148
+ const IMPORT_SOURCE_KEYS = shapeKeys(SHAPE['sourceImport']);
147
149
  const BUSINESS_KEYS = shapeKeys(SHAPE['business']);
148
150
  const DESIGN_REQUIRED = requiredShapeKeys(SHAPE['design']);
149
151
  const DESIGN_KEYS = shapeKeys(SHAPE['design']);
@@ -154,10 +156,14 @@ const ARRAY_TYPE = 'array';
154
156
  const FIELD_KEYS = shapeKeys(SHAPE['field']);
155
157
  const SLUG_FIELD = 'slug';
156
158
  const SEED_FIXED_KEYS = shapeKeys(SHAPE['seed']);
159
+ /** X4: the seed key naming each real item's old address (`ContentSeedPlan.importedFrom`). */
160
+ const IMPORTED_FROM = 'importedFrom';
157
161
  const CMS_SOURCE_KEYS = shapeKeys(SHAPE['cmsDataSource']);
158
162
  const RELATIVE_SOURCE_KEYS = shapeKeys(SHAPE['relativeDataSource']);
159
163
  const SHOP_SOURCE_KEYS = shapeKeys(SHAPE['shopDataSource']);
160
164
  const SHOP_KEYS = shapeKeys(SHAPE['shop']);
165
+ const POPUP_LINE_KEYS = shapeKeys(SHAPE['popupLines']);
166
+ const STATED_FACT_KEYS = shapeKeys(SHAPE['statedFact']);
161
167
  const SHOP_PRODUCT_KEYS = shapeKeys(SHAPE['shopProduct']);
162
168
  const SHOP_OPTION_KEYS = shapeKeys(SHAPE['shopOption']);
163
169
  const PAGE_KEYS = shapeKeys(SHAPE['page']);
@@ -212,8 +218,11 @@ function validateSource(c: Collector, source: unknown): void {
212
218
  } else if (source['kind'] === SitePlanSourceKind.Ai) {
213
219
  c.keys(source, AI_SOURCE_KEYS, 'source');
214
220
  c.string(source, 'runId', 'source');
221
+ } else if (source['kind'] === SitePlanSourceKind.Import) {
222
+ c.keys(source, IMPORT_SOURCE_KEYS, 'source');
223
+ c.string(source, 'scanId', 'source');
215
224
  } else {
216
- c.add(SitePlanIssueCode.Shape, 'source.kind', `must be "${SitePlanSourceKind.Template}" or "${SitePlanSourceKind.Ai}"`);
225
+ c.add(SitePlanIssueCode.Shape, 'source.kind', `must be one of ${Object.values(SitePlanSourceKind).map(k => `"${k}"`).join(', ')}`);
217
226
  }
218
227
  }
219
228
 
@@ -316,11 +325,20 @@ function validateContentTypes(c: Collector, list: unknown[]): Map<string, Conten
316
325
  if (!isObject(perItem)) c.add(SitePlanIssueCode.Shape, `${path}.seed.perItem`, 'must be an object');
317
326
  else for (const [field, list] of Object.entries(perItem)) {
318
327
  const at = `${path}.seed.perItem.${field}`;
328
+ // An array field's value is a list of strings (X4: an imported item's pictures); any other field's, a string.
329
+ const listField = fieldTypes.get(field) === ARRAY_TYPE;
330
+ const fits = (v: unknown) => listField ? Array.isArray(v) && v.every(w => typeof w === 'string') : typeof v === 'string';
319
331
  if (!fieldSet.has(field)) c.add(SitePlanIssueCode.UnknownField, at, `"${field}" is not a field of ${name}`);
320
- else if (!Array.isArray(list) || list.length !== seed['count'] || list.some(v => typeof v !== 'string')) c.add(SitePlanIssueCode.Shape, at, `must be ${String(seed['count'])} strings, one per sample`);
332
+ else if (!Array.isArray(list) || list.length !== seed['count'] || !list.every(fits)) c.add(SitePlanIssueCode.Shape, at, `must be ${String(seed['count'])} ${listField ? 'lists of strings' : 'strings'}, one per sample`);
321
333
  else if (field === SLUG_FIELD && new Set(list).size !== list.length) c.add(SitePlanIssueCode.Shape, at, 'each sample needs its own slug');
322
334
  }
323
335
  }
336
+ const from = seed[IMPORTED_FROM];
337
+ if (from !== undefined) {
338
+ const at = `${path}.seed.${IMPORTED_FROM}`;
339
+ if (seed['sample'] !== false) c.add(SitePlanIssueCode.Shape, at, 'only real items were read from a site — a sample never was');
340
+ else if (!Array.isArray(from) || from.length !== seed['count'] || !from.every(isNonEmptyString)) c.add(SitePlanIssueCode.Shape, at, `must be ${String(seed['count'])} addresses, one per item`);
341
+ }
324
342
  for (const key of Object.keys(seed)) {
325
343
  if (!SEED_FIXED_KEYS.includes(key) && !fieldSet.has(key)) c.add(SitePlanIssueCode.UnknownField, `${path}.seed.${key}`, `"${key}" is not a field of ${name}`);
326
344
  }
@@ -525,7 +543,10 @@ function validateProductReach(c: Collector, plan: Record<string, unknown>, pages
525
543
  }
526
544
  }
527
545
 
528
- function validatePages(c: Collector, list: unknown[], types: Map<string, ContentTypeInfo>, sources: Map<string, SourceInfo>, density: string | null): void {
546
+ /** `moved` (X4): the plan was read from the owner's own site — its slots hold the owner's words moved, never written to a
547
+ * budget, so a long page is never refused for its length. */
548
+ function validatePages(c: Collector, list: unknown[], types: Map<string, ContentTypeInfo>, sources: Map<string, SourceInfo>, density: string | null,
549
+ moved = false): void {
529
550
  const homes: number[] = [];
530
551
  const routes = new Set(list.map(p => (isObject(p) && typeof p['route'] === 'string' ? p['route'] : null)).filter((r): r is string => !!r));
531
552
  list.forEach((raw, i) => {
@@ -586,7 +607,7 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
586
607
  if (!declared.includes(slot)) c.add(SitePlanIssueCode.UnknownSlot, `${sp}.slots.${slot}`, `"${patternId}" has no slot "${slot}" (${declared.join(', ') || 'none'})`);
587
608
  else if (typeof value !== 'string') c.add(SitePlanIssueCode.Shape, `${sp}.slots.${slot}`, 'must be a string');
588
609
  else {
589
- const budget = slotBudget(pattern, slot, density);
610
+ const budget = moved ? null : slotBudget(pattern, slot, density);
590
611
  if (budget !== null && value.length > budget) c.add(SitePlanIssueCode.SlotTooLong, `${sp}.slots.${slot}`, `${value.length} characters — the slot holds ${budget} at the ${density ?? 'regular'} density`);
591
612
  }
592
613
  }
@@ -754,7 +775,8 @@ function validateGlobals(c: Collector, globals: unknown): void {
754
775
  }
755
776
 
756
777
  /** The parts a plan may carry as a mix, and how each reads its words (only the footer until header ingredients HI1). */
757
- const MIX_READERS: Readonly<Record<string, (words: ReadonlyArray<string>) => unknown>> = { header: headerMixFromWords, footer: footerMixFromWords, opening: openingMixFromWords, body: bodyMixFromWords };
778
+ const MIX_READERS: Readonly<Record<string, (words: ReadonlyArray<string>) => unknown>> = { header: headerMixFromWords, footer: footerMixFromWords, opening: openingMixFromWords, body: bodyMixFromWords,
779
+ popup: popupMixFromWords };
758
780
 
759
781
  /** `mixes`: each part's words parse in its table (list ingredients LI5); absent is fine. */
760
782
  function validateMixes(c: Collector, mixes: unknown): void {
@@ -769,6 +791,22 @@ function validateMixes(c: Collector, mixes: unknown): void {
769
791
  }
770
792
  }
771
793
 
794
+ /** Popups PU3: the owner's popup lines — a stated news (its value and the owner's words) and the newsletter tick; absent is fine. */
795
+ function validatePopupLines(c: Collector, lines: unknown): void {
796
+ if (lines === undefined) return;
797
+ if (!isObject(lines)) return c.add(SitePlanIssueCode.Shape, 'popup', 'must be an object');
798
+ c.keys(lines, POPUP_LINE_KEYS, 'popup');
799
+ const news = lines['news'];
800
+ if (news !== undefined) {
801
+ if (!isObject(news)) c.add(SitePlanIssueCode.Shape, 'popup.news', 'must be { value, quote }');
802
+ else {
803
+ c.keys(news, STATED_FACT_KEYS, 'popup.news');
804
+ for (const key of STATED_FACT_KEYS) c.string(news, key, 'popup.news');
805
+ }
806
+ }
807
+ if (lines['newsletter'] !== undefined) c.boolean(lines, 'newsletter', 'popup');
808
+ }
809
+
772
810
  /** Check a Site Plan against the plan shape and the pattern library. Never throws, never repairs. */
773
811
  export function validateSitePlan(plan: unknown, ctx: SitePlanContext = {}): SitePlanValidation {
774
812
  const c = new Collector();
@@ -786,13 +824,15 @@ export function validateSitePlan(plan: unknown, ctx: SitePlanContext = {}): Site
786
824
  const sources = validateDataSources(c, c.array(plan, 'dataSources', ''), types);
787
825
  const sells = validateShop(c, plan, ctx);
788
826
  const design = isObject(plan['design']) ? plan['design'] : {};
789
- validatePages(c, c.array(plan, 'pages', ''), withShopTypes(types, sources), sources, typeof design['density'] === 'string' ? design['density'] : null);
827
+ const moved = isObject(plan['source']) && plan['source']['kind'] === SitePlanSourceKind.Import;
828
+ validatePages(c, c.array(plan, 'pages', ''), withShopTypes(types, sources), sources, typeof design['density'] === 'string' ? design['density'] : null, moved);
790
829
  if (sells) {
791
830
  validateProductPage(c, c.array(plan, 'pages', ''), sources);
792
831
  validateProductReach(c, plan, c.array(plan, 'pages', ''));
793
832
  }
794
833
  validateGlobals(c, plan['globals']);
795
834
  validateMixes(c, plan['mixes']);
835
+ validatePopupLines(c, plan['popup']);
796
836
  validateScenes(c, c.array(plan, 'pages', ''), typeof design['animate'] === 'string' ? design['animate'] : null);
797
837
  validateFilm(c, plan['film'], c.array(plan, 'pages', ''));
798
838
  validateArtDirection(c, plan['artDirection']);
@@ -4712,6 +4712,7 @@ export const SPEC_ANALYSIS_SHAPE = {
4712
4712
  "business": "business",
4713
4713
  "needs": "need[] — what the site needs: the owner's (from: you) and the type's (from: type)",
4714
4714
  "facts": "{ [fact]: factRead } — site.facts keys, only what the prompt states; every quote is words of the prompt",
4715
+ "statedFacts?": "{ [statedFact]: factRead } — harness.statedFacts keys (news), only what the prompt states; never a placeholder and never in missingFacts. On the wire a stated fact is a fact line of the facts list",
4715
4716
  "missingFacts": "string[] — site.facts keys the prompt does not state",
4716
4717
  "voice": "voice",
4717
4718
  "moods": "string[] — ≤ 3 moods",
@@ -7,6 +7,7 @@ import {
7
7
  import { BUSINESS_TYPE_IDS, NEED_IDS, USER_AVOID_IDS, UserAvoidId } from './business-types';
8
8
  import { SPEC_ANALYSIS_SHAPE } from './harness-spec.generated';
9
9
  import { NeedSource, SiteNeed } from './needs';
10
+ import { STATED_FACT_KEYS, STATED_FACTS, StatedFactKey } from './popup-stance';
10
11
 
11
12
  /**
12
13
  * What the reading of a prompt returns (AI plan rev 3 §3d): one of the 30 kinds of business (and the two
@@ -43,6 +44,9 @@ export interface SiteAnalysis {
43
44
  needs: SiteNeed[];
44
45
  facts: Partial<Record<FactKey, FactRead>>;
45
46
  missingFacts: FactKey[];
47
+ /** Popups PU3: what the prompt STATES of the harness's stated facts (`news`) — never a placeholder, never missing;
48
+ * absent = none stated. On the wire a stated fact is a line of `facts`. */
49
+ statedFacts?: Partial<Record<StatedFactKey, FactRead>>;
46
50
  voice: { tone: string; person: `${VoicePerson}`; formality: `${VoiceFormality}`; avoidWords: string[] };
47
51
  moods: MoodId[];
48
52
  avoid: UserAvoidId[];
@@ -152,6 +156,18 @@ export function validateSiteAnalysis(value: unknown, ctx: AnalysisContext): Anal
152
156
  if (quote && !promptWords.includes(normalise(quote))) c.add(AnalysisIssueCode.QuoteNotInPrompt, pathAt(path, 'quote'), 'is not words of the prompt — a fact the prompt does not state is missing, never filled');
153
157
  found.add(key);
154
158
  }
159
+ if (a['statedFacts'] !== undefined) {
160
+ if (!isPlainObject(a['statedFacts'])) c.add(AnalysisIssueCode.Shape, 'statedFacts', 'must be an object');
161
+ else for (const [key, raw] of Object.entries(a['statedFacts'])) {
162
+ const path = `statedFacts.${key}`;
163
+ if (!(STATED_FACT_KEYS as ReadonlyArray<string>).includes(key)) { c.add(AnalysisIssueCode.UnknownFact, path, `"${key}" is not a stated fact (${STATED_FACT_KEYS.join(', ')})`); continue; }
164
+ const fact = c.object(raw, 'factRead', path);
165
+ if (!fact) continue;
166
+ c.string(fact, 'value', path);
167
+ const quote = c.string(fact, 'quote', path);
168
+ if (quote && !promptWords.includes(normalise(quote))) c.add(AnalysisIssueCode.QuoteNotInPrompt, pathAt(path, 'quote'), 'is not words of the prompt — news the prompt does not state does not exist');
169
+ }
170
+ }
155
171
  c.strings(a, 'missingFacts', '').forEach((key, i) => {
156
172
  if (!(FACT_KEYS as ReadonlyArray<string>).includes(key)) c.add(AnalysisIssueCode.UnknownFact, `missingFacts[${i}]`, `"${key}" is not a fact`);
157
173
  else if (found.has(key)) c.add(AnalysisIssueCode.FactFoundAndMissing, `missingFacts[${i}]`, `"${key}" is also in facts`);
@@ -206,20 +222,25 @@ const listOf = jsonListOf;
206
222
  /** An object of `shape`: exactly its keys, its required ones required, each described by the table. */
207
223
  const shaped = (shape: string, properties: Record<string, JsonSchema>): JsonSchema => jsonShapedObject(SHAPE[shape], properties, shape);
208
224
 
225
+ /** Every fact a line may state: the site's facts, then the stated ones (PU3: `news` — only as stated, never missing). */
226
+ const WIRE_FACT_KEYS: ReadonlyArray<string> = [...FACT_KEYS, ...STATED_FACT_KEYS];
227
+ const STATED_KEY = 'statedFacts';
228
+
209
229
  /** A stated fact on the wire: which fact, then the document's `factRead` keys in the table's own words. */
210
230
  const FACT_LINE_SHAPE: ShapeEntry = {
211
- fact: `${FACT_KEYS.map(k => `'${k}'`).join(' | ')} — which fact (site.facts), each at most once`,
231
+ fact: `${WIRE_FACT_KEYS.map(k => `'${k}'`).join(' | ')} — which fact (site.facts), each at most once; `
232
+ + STATED_FACT_KEYS.map(k => `'${k}': ${STATED_FACTS[k].how}`).join('; '),
212
233
  ...SHAPE['factRead'],
213
234
  };
214
235
 
215
- /** The analysis as the wire carries it: `facts` a list of fact lines, described in the table's words. */
216
- const ANALYSIS_WIRE_SHAPE: ShapeEntry = {
236
+ /** The analysis as the wire carries it: `facts` a list of fact lines (the stated facts among them), described in the table's words. */
237
+ const ANALYSIS_WIRE_SHAPE: ShapeEntry = Object.fromEntries(Object.entries({
217
238
  ...SHAPE['analysis'],
218
239
  facts: `factLine[] — ${describeShapeKey(SHAPE['analysis'], 'facts').replace(/^\{ \[fact\]: factRead \} — /, '')}`,
219
- };
240
+ }).filter(([k]) => k.replace(/\?$/, '') !== STATED_KEY));
220
241
 
221
242
  export function siteAnalysisJsonSchema(): JsonSchema {
222
- const factLine = jsonShapedObject(FACT_LINE_SHAPE, { fact: oneOf(FACT_KEYS), value: text(), quote: text() }, 'factLine');
243
+ const factLine = jsonShapedObject(FACT_LINE_SHAPE, { fact: oneOf(WIRE_FACT_KEYS), value: text(), quote: text() }, 'factLine');
223
244
  return jsonShapedObject(ANALYSIS_WIRE_SHAPE, {
224
245
  businessType: oneOf(BUSINESS_TYPE_IDS),
225
246
  alternatives: listOf(oneOf(BUSINESS_TYPE_IDS)),
@@ -245,6 +266,7 @@ export function analysisFromWire(wire: unknown): { analysis: unknown; issues: An
245
266
  if (!isPlainObject(wire)) return { analysis: wire, issues: [] };
246
267
  if (!Array.isArray(wire['facts'])) return { analysis: wire, issues: [{ code: AnalysisIssueCode.Shape, path: 'facts', message: 'must be a list of { fact, value, quote }' }] };
247
268
  const facts: PlainObject = {};
269
+ const stated: PlainObject = {};
248
270
  const issues: AnalysisIssue[] = [];
249
271
  (wire['facts'] as unknown[]).forEach((line, i) => {
250
272
  if (!isPlainObject(line) || typeof line['fact'] !== 'string') {
@@ -252,13 +274,16 @@ export function analysisFromWire(wire: unknown): { analysis: unknown; issues: An
252
274
  return;
253
275
  }
254
276
  const { fact, ...read } = line;
255
- if (fact in facts) issues.push({ code: AnalysisIssueCode.Duplicate, path: `facts[${i}].fact`, message: `"${fact}" is stated twice` });
256
- else facts[fact as string] = read;
277
+ // PU3: a stated fact (news) is the document's `statedFacts`, never a site fact.
278
+ const into = (STATED_FACT_KEYS as ReadonlyArray<string>).includes(fact as string) ? stated : facts;
279
+ if (fact in into) issues.push({ code: AnalysisIssueCode.Duplicate, path: `facts[${i}].fact`, message: `"${fact}" is stated twice` });
280
+ else into[fact as string] = read;
257
281
  });
258
- return { analysis: { ...wire, facts }, issues };
282
+ return { analysis: { ...wire, facts, ...(Object.keys(stated).length ? { [STATED_KEY]: stated } : {}) }, issues };
259
283
  }
260
284
 
261
285
  /** The document → the wire (what a model writes). */
262
286
  export function analysisToWire(analysis: SiteAnalysis): PlainObject {
263
- return { ...analysis, facts: Object.entries(analysis.facts).map(([fact, read]) => ({ fact, ...read })) };
287
+ const { statedFacts, ...rest } = analysis;
288
+ return { ...rest, facts: [...Object.entries(analysis.facts), ...Object.entries(statedFacts ?? {})].map(([fact, read]) => ({ fact, ...read })) };
264
289
  }