@vectoriox/iox-ui 5.120.0 → 5.121.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.
@@ -1,4 +1,4 @@
1
- import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized, AdjustKind, AdjustAxis, adjustStepOf, ADJUST_STEPS, NODE_BASELINES, adjustStyleProps, ADJUST_AXIS_LABELS, adjustStepLabel } from '@vectoriox/iox-ui/generation-core';
1
+ import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized, AdjustKind, AdjustAxis, adjustStepOf, ADJUST_STEPS, NODE_BASELINES, adjustStyleProps, ADJUST_AXIS_LABELS, adjustStepLabel, patternById, composeSection } from '@vectoriox/iox-ui/generation-core';
2
2
  import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle } from '@vectoriox/iox-ui/design-core';
3
3
 
4
4
  /**
@@ -94,10 +94,10 @@ const spec = (s) => ({
94
94
  });
95
95
  const SURFACES = {
96
96
  // S1 offers only the families the server answers (the route can never pick one it cannot): Words first (AI2a);
97
- // Style, Sections and Look & motion join as each slice ships (ai-assist-plan §6, AI2).
97
+ // Look & motion joins when its slice ships (ai-assist-plan §6, AI2e).
98
98
  [AssistSurface.BuilderPage]: spec({
99
99
  surface: AssistSurface.BuilderPage,
100
- families: [EditFamily.Words, EditFamily.Style],
100
+ families: [EditFamily.Words, EditFamily.Style, EditFamily.Sections],
101
101
  commit: CommitKind.BuilderStep,
102
102
  steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
103
103
  permissions: [AssistPermission.PageUpdate],
@@ -1218,16 +1218,16 @@ function styleJsonSchema(looks) {
1218
1218
  assertAssistBudget('style', [part]);
1219
1219
  return { parts: [part], handles: [[...new Set([...styled, ...schemed, ...sized].map(([h]) => h))]] };
1220
1220
  }
1221
- const listOf = (answer, key) => {
1221
+ const listOf$1 = (answer, key) => {
1222
1222
  const list = answer && typeof answer === 'object' ? answer[key] : undefined;
1223
1223
  return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
1224
1224
  };
1225
1225
  /** The answer → the edits it makes. */
1226
1226
  function decodeStyleAnswers(answers) {
1227
1227
  return answers.flatMap(answer => [
1228
- ...listOf(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
1229
- ...listOf(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
1230
- ...listOf(answer, StyleAnswerKey.Sizes).map(x => ({ handle: String(x['handle'] ?? ''), axis: String(x['axis'] ?? ''), step: String(x['step'] ?? '') })),
1228
+ ...listOf$1(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
1229
+ ...listOf$1(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
1230
+ ...listOf$1(answer, StyleAnswerKey.Sizes).map(x => ({ handle: String(x['handle'] ?? ''), axis: String(x['axis'] ?? ''), step: String(x['step'] ?? '') })),
1231
1231
  ]);
1232
1232
  }
1233
1233
  const isStyleEdit = (e) => typeof e.style === 'string';
@@ -1240,6 +1240,7 @@ var PageChangeOp;
1240
1240
  PageChangeOp["Style"] = "style";
1241
1241
  PageChangeOp["Scheme"] = "scheme";
1242
1242
  PageChangeOp["Size"] = "size";
1243
+ PageChangeOp["Section"] = "section";
1243
1244
  })(PageChangeOp || (PageChangeOp = {}));
1244
1245
  /** The serialized baseline: the type's constructor values, its text colour released as a new node's is (generation-core `createSerializedNode`). */
1245
1246
  const serializedBaselineStyles = type => {
@@ -1351,6 +1352,359 @@ function applyStyleEdits(layout, edits, ctx) {
1351
1352
  return { ok: true, result, changes, issues: [] };
1352
1353
  }
1353
1354
 
1355
+ /**
1356
+ * Surface S1 (the builder, this page), family `sections` (ai-assist-plan AI2d; ai-session-panel-plan `addSection` /
1357
+ * `removeSection` / `moveSection` / `swapPattern`): a section is added, removed, moved or swapped for another — and every
1358
+ * section Ask adds is a library pattern stamped by generation-core's `composeSection`, the SAME recipe the builder palette's
1359
+ * ready-made sections and the composer use (R-H9). The model names a pattern from a closed list and a place by handle;
1360
+ * it never writes a node. The same pure functions run on the server (the check on a copy) and in the builder (the trial).
1361
+ */
1362
+ /**
1363
+ * The library patterns Ask may add or swap to — those `composeSection` stamps on their own with no Site Plan behind
1364
+ * them. Not offered: headers and footers (globals), lists and products (they need a content source — a Pages & data
1365
+ * change), Scenes and the owner's film (the look's motion decides them, and a page holds one).
1366
+ */
1367
+ const ASK_SECTION_PATTERNS = [
1368
+ 'hero.split', 'hero.centered', 'hero.full-bleed-media', 'hero.stacked-editorial',
1369
+ 'proof.logo-strip', 'proof.stat-row', 'proof.testimonial-single',
1370
+ 'feature.triad', 'feature.alternating-rows', 'feature.icon-list', 'feature.tabbed',
1371
+ 'story.long-form', 'story.timeline', 'story.quote-break',
1372
+ 'cta.banner', 'cta.split-form', 'contact.simple', 'faq.accordion', 'pricing.tiers',
1373
+ ];
1374
+ /** Where an added or moved section goes when it is first on the page. */
1375
+ const SECTION_START = 'start';
1376
+ /** The library pattern a section root was stamped from, by its label (the composer names a root by its pattern). */
1377
+ function sectionPatternOf(root) {
1378
+ const label = (root.label ?? '').split(' · ')[0].trim();
1379
+ if (!label)
1380
+ return undefined;
1381
+ return ASK_SECTION_PATTERNS.find(id => patternById(id)?.label === label);
1382
+ }
1383
+ /** The patterns Ask offers, as the model and the owner read them: id → its name ("Hero — words centred"). */
1384
+ function askSectionPatternNames() {
1385
+ return Object.fromEntries(ASK_SECTION_PATTERNS.map(id => [id, patternById(id)?.label ?? id]));
1386
+ }
1387
+ var SectionsAnswerKey;
1388
+ (function (SectionsAnswerKey) {
1389
+ SectionsAnswerKey["Add"] = "add";
1390
+ SectionsAnswerKey["Remove"] = "remove";
1391
+ SectionsAnswerKey["Move"] = "move";
1392
+ SectionsAnswerKey["Swap"] = "swap";
1393
+ SectionsAnswerKey["Note"] = "note";
1394
+ })(SectionsAnswerKey || (SectionsAnswerKey = {}));
1395
+ /**
1396
+ * The strict format of family `sections` — ONE request: `add [{pattern, after}]`, `remove [{handle}]`,
1397
+ * `move [{handle, after}]`, `swap [{handle, pattern}]`, `note`. Handles are enums of the page's sections (the focus's for
1398
+ * what may change), patterns an enum of {@link ASK_SECTION_PATTERNS}. Whether an op makes sense is the check's.
1399
+ */
1400
+ function sectionsJsonSchema(sections) {
1401
+ const all = Object.keys(sections);
1402
+ const focus = all.filter(h => sections[h].focus);
1403
+ const places = [SECTION_START, ...all];
1404
+ const patterns = jsonOneOf([...ASK_SECTION_PATTERNS]);
1405
+ const properties = {
1406
+ [SectionsAnswerKey.Add]: {
1407
+ ...jsonListOf(jsonClosedObject({ pattern: patterns, after: jsonOneOf(places) }, ['pattern', 'after'])),
1408
+ description: 'A new section from the library, placed after a section (or at the start); [] adds none.',
1409
+ },
1410
+ };
1411
+ if (focus.length) {
1412
+ properties[SectionsAnswerKey.Remove] = {
1413
+ ...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus) }, ['handle'])),
1414
+ description: 'A section taken off the page; [] removes none.',
1415
+ };
1416
+ properties[SectionsAnswerKey.Move] = {
1417
+ ...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus), after: jsonOneOf(places) }, ['handle', 'after'])),
1418
+ description: 'A section moved to after another (or to the start); [] moves none.',
1419
+ };
1420
+ properties[SectionsAnswerKey.Swap] = {
1421
+ ...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus), pattern: patterns }, ['handle', 'pattern'])),
1422
+ description: 'A section redrawn as another library section, its words and pictures carried over; [] swaps none.',
1423
+ };
1424
+ }
1425
+ properties[SectionsAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
1426
+ const part = jsonClosedObject(properties, Object.keys(properties));
1427
+ assertAssistBudget('sections', [part]);
1428
+ return { parts: [part], handles: [focus] };
1429
+ }
1430
+ const isSectionEdit = (e) => 'add' in e || 'remove' in e || 'move' in e || 'swap' in e;
1431
+ const listOf = (answer, key) => {
1432
+ const list = answer && typeof answer === 'object' ? answer[key] : undefined;
1433
+ return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
1434
+ };
1435
+ const str = (v) => String(v ?? '');
1436
+ /** The answer → the edits it makes. */
1437
+ function decodeSectionsAnswers(answers) {
1438
+ return answers.flatMap(answer => [
1439
+ ...listOf(answer, SectionsAnswerKey.Swap).map(x => ({ swap: str(x['handle']), pattern: str(x['pattern']) })),
1440
+ ...listOf(answer, SectionsAnswerKey.Remove).map(x => ({ remove: str(x['handle']) })),
1441
+ ...listOf(answer, SectionsAnswerKey.Move).map(x => ({ move: str(x['handle']), after: str(x['after']) })),
1442
+ ...listOf(answer, SectionsAnswerKey.Add).map(x => ({ add: str(x['pattern']), after: str(x['after']) })),
1443
+ ]);
1444
+ }
1445
+ var SectionChangeKind;
1446
+ (function (SectionChangeKind) {
1447
+ SectionChangeKind["Add"] = "add";
1448
+ SectionChangeKind["Remove"] = "remove";
1449
+ SectionChangeKind["Move"] = "move";
1450
+ SectionChangeKind["Swap"] = "swap";
1451
+ })(SectionChangeKind || (SectionChangeKind = {}));
1452
+ /** Why a section cannot be redrawn as another: it holds what a swap would lose (a form, words from content, a Scene). */
1453
+ function swapBlocker(root) {
1454
+ let blocker = null;
1455
+ walkSerialized([root], n => {
1456
+ if (blocker)
1457
+ return;
1458
+ if (n.role === 'scene')
1459
+ blocker = 'it plays as a Scene';
1460
+ else if (n.type === 'Form')
1461
+ blocker = 'it holds a form';
1462
+ else if (n.type === 'Repeater' || (n.bindings ?? []).length)
1463
+ blocker = 'its words come from your content';
1464
+ });
1465
+ return blocker;
1466
+ }
1467
+ /** A section's parts a swap carries over, in reading order, by kind. */
1468
+ var CarryKind;
1469
+ (function (CarryKind) {
1470
+ CarryKind["Eyebrow"] = "eyebrow";
1471
+ CarryKind["Heading"] = "heading";
1472
+ CarryKind["Text"] = "text";
1473
+ CarryKind["Button"] = "button";
1474
+ CarryKind["Image"] = "image";
1475
+ })(CarryKind || (CarryKind = {}));
1476
+ /** A button the owner's words and link travel in — never a tab, a price switch or a cart button (their recipe's own). */
1477
+ const CARRIED_BUTTON_STYLES = new Set(['button-primary', 'button-secondary', 'button-ghost']);
1478
+ /** Words that belong to their recipe, not the owner's copy: a figure ("40+", a price), a badge — left where they are. */
1479
+ const KEPT_TEXT_STYLES = new Set(['price', 'badge-label']);
1480
+ function carryKind(n) {
1481
+ if (n.elementStyle === 'eyebrow' && (n.type === 'Heading' || n.type === 'Text'))
1482
+ return CarryKind.Eyebrow;
1483
+ if (n.type === 'Heading')
1484
+ return CarryKind.Heading;
1485
+ if (n.type === 'Text')
1486
+ return KEPT_TEXT_STYLES.has(n.elementStyle ?? '') ? null : CarryKind.Text;
1487
+ if (n.type === 'Image')
1488
+ return CarryKind.Image;
1489
+ return null;
1490
+ }
1491
+ function carryParts(root) {
1492
+ const out = { eyebrow: [], heading: [], text: [], button: [], image: [] };
1493
+ const visit = (n) => {
1494
+ if (n.type === 'ButtonBlock') {
1495
+ if (CARRIED_BUTTON_STYLES.has(n.elementStyle ?? ''))
1496
+ out.button.push(n);
1497
+ return;
1498
+ }
1499
+ const kind = carryKind(n);
1500
+ if (kind)
1501
+ out[kind].push(n);
1502
+ for (const c of n.children ?? [])
1503
+ visit(c);
1504
+ };
1505
+ for (const c of root.children ?? [])
1506
+ visit(c);
1507
+ return out;
1508
+ }
1509
+ const BUTTON_LINK_PROPS = ['tag', 'linkType', 'href', 'pageRoute', 'url', 'target'];
1510
+ const labelOf = (button) => (button.children ?? []).find(c => c.type === 'Text');
1511
+ /** The owner's words and pictures, placed into the new section part for part (kind by kind, in order); how many found no place. */
1512
+ function carryOver(from, to) {
1513
+ const old = carryParts(from);
1514
+ const fresh = carryParts(to);
1515
+ let notPlaced = 0;
1516
+ for (const kind of Object.values(CarryKind)) {
1517
+ old[kind].forEach((source, i) => {
1518
+ const target = fresh[kind][i];
1519
+ if (!target) {
1520
+ const hasContent = kind === CarryKind.Image ? !!source.props['src'] : true;
1521
+ if (hasContent)
1522
+ notPlaced++;
1523
+ return;
1524
+ }
1525
+ if (kind === CarryKind.Image) {
1526
+ if (!source.props['src'])
1527
+ return;
1528
+ target.props = { ...target.props, src: source.props['src'], alt: source.props['alt'] ?? target.props['alt'] };
1529
+ }
1530
+ else if (kind === CarryKind.Button) {
1531
+ const words = labelOf(source);
1532
+ const into = labelOf(target);
1533
+ if (words && into)
1534
+ into.props = { ...into.props, content: words.props['content'] };
1535
+ const link = Object.fromEntries(BUTTON_LINK_PROPS.filter(k => k in source.props).map(k => [k, source.props[k]]));
1536
+ target.props = { ...target.props, ...link };
1537
+ }
1538
+ else {
1539
+ target.props = { ...target.props, content: source.props['content'] };
1540
+ }
1541
+ });
1542
+ }
1543
+ return notPlaced;
1544
+ }
1545
+ /** A stable id no node of the page holds (nor any of its parts' derived ids, `<id>-0-1`). */
1546
+ function stableIds(layout) {
1547
+ const taken = [];
1548
+ walkSerialized([...layout], n => taken.push(n.id));
1549
+ let n = 0;
1550
+ return () => {
1551
+ let id;
1552
+ do
1553
+ id = `ask-s${++n}`;
1554
+ while (taken.some(t => t === id || t.startsWith(`${id}-`)));
1555
+ taken.push(id);
1556
+ return id;
1557
+ };
1558
+ }
1559
+ const patternName = (id) => patternById(id)?.label ?? id;
1560
+ /**
1561
+ * Family `sections`, applied — the SAME check on the server and in the builder. All or none; never mutates its input.
1562
+ * Swaps redraw in place, then removals, moves and additions, each placed by the ORIGINAL handles. Refused (re-asked once
1563
+ * by the server, never repaired): a handle not on the page or not in the focus, a pattern not offered, a section given two
1564
+ * changes, a place that is the section itself or one removed in the same answer, a swap of a section holding a form,
1565
+ * content-bound words or a Scene.
1566
+ */
1567
+ function applySectionEdits(layout, edits, ctx) {
1568
+ const result = JSON.parse(JSON.stringify(layout));
1569
+ const issues = [];
1570
+ const changes = [];
1571
+ const newId = ctx.newId ?? stableIds(layout);
1572
+ const has = (h) => Object.prototype.hasOwnProperty.call(ctx.sections, h);
1573
+ const refuse = (handle, code, message) => issues.push({ code, handle, message });
1574
+ /** The sections as they stood — what "before" reads, and what a moved, swapped section is placed by. */
1575
+ const original = ctx.sections;
1576
+ /** The kinds of change each section was given: a swap may come with a move; a removal comes alone; no kind twice. */
1577
+ const touched = new Map();
1578
+ const removed = new Set(edits.filter((e) => 'remove' in e).map(e => e.remove));
1579
+ const changeable = (handle, kind) => {
1580
+ if (!has(handle)) {
1581
+ refuse(handle, AssistIssueCode.UnknownHandle, `"${handle}" is not a section of this page`);
1582
+ return null;
1583
+ }
1584
+ const target = ctx.sections[handle];
1585
+ if (!target.focus) {
1586
+ refuse(handle, AssistIssueCode.UnknownHandle, `${target.label} is not in the focus — widen the chip to change it`);
1587
+ return null;
1588
+ }
1589
+ const kinds = touched.get(handle) ?? new Set();
1590
+ if (kinds.has(kind) || (kinds.size && (kind === SectionChangeKind.Remove || kinds.has(SectionChangeKind.Remove)))) {
1591
+ refuse(handle, AssistIssueCode.Duplicate, `${target.label} is given two changes that cannot go together`);
1592
+ return null;
1593
+ }
1594
+ touched.set(handle, kinds.add(kind));
1595
+ return target;
1596
+ };
1597
+ const place = (handle, after) => {
1598
+ if (after === SECTION_START)
1599
+ return true;
1600
+ if (!has(after)) {
1601
+ refuse(handle, AssistIssueCode.UnknownHandle, `"${after}" is not a section of this page`);
1602
+ return false;
1603
+ }
1604
+ if (after === handle) {
1605
+ refuse(handle, AssistIssueCode.NotAnOption, 'a section cannot go after itself');
1606
+ return false;
1607
+ }
1608
+ if (removed.has(after)) {
1609
+ refuse(handle, AssistIssueCode.NotAnOption, `${ctx.sections[after].label} is removed in the same answer — place it after another section`);
1610
+ return false;
1611
+ }
1612
+ return true;
1613
+ };
1614
+ const offered = (handle, pattern) => {
1615
+ if (ASK_SECTION_PATTERNS.includes(pattern))
1616
+ return true;
1617
+ refuse(handle, AssistIssueCode.NotAnOption, `"${pattern}" is not a section Ask can add`);
1618
+ return false;
1619
+ };
1620
+ const indexOf = (id) => result.findIndex(n => n.id === id);
1621
+ const whereLabel = (after) => after === SECTION_START ? 'At the start' : `After ${ctx.sections[after].label}`;
1622
+ /** The handle of the section a section stood after, or the start. */
1623
+ const stoodAfter = (handle) => {
1624
+ const at = layout.findIndex(n => n.id === original[handle].id);
1625
+ const prev = at > 0 ? Object.entries(original).find(([, t]) => t.id === layout[at - 1].id) : undefined;
1626
+ return prev ? prev[0] : SECTION_START;
1627
+ };
1628
+ const standsAfter = (handle) => {
1629
+ const prev = stoodAfter(handle);
1630
+ return prev === SECTION_START ? 'At the start' : `After ${original[prev].label}`;
1631
+ };
1632
+ const insertAfter = (node, after) => {
1633
+ if (after === SECTION_START) {
1634
+ result.unshift(node);
1635
+ return;
1636
+ }
1637
+ const at = indexOf(ctx.sections[after].id);
1638
+ result.splice(at + 1, 0, node);
1639
+ };
1640
+ // Swaps first, in place — so an addition or a move placed after a swapped section lands after its new drawing.
1641
+ for (const edit of edits) {
1642
+ if (!('swap' in edit))
1643
+ continue;
1644
+ const target = changeable(edit.swap, SectionChangeKind.Swap);
1645
+ if (!target || !offered(edit.swap, edit.pattern))
1646
+ continue;
1647
+ const at = indexOf(target.id);
1648
+ const blocker = swapBlocker(result[at]);
1649
+ if (blocker) {
1650
+ refuse(edit.swap, AssistIssueCode.NotAnOption, `${target.label} cannot be redrawn — ${blocker}; add a new section and remove this one instead`);
1651
+ continue;
1652
+ }
1653
+ const section = composeSection(edit.pattern, ctx.input ?? {}, { id: newId() }).section;
1654
+ const notPlaced = carryOver(result[at], section);
1655
+ result[at] = section;
1656
+ // Later places name the section by its ORIGINAL id — it stands where the swapped one stood.
1657
+ ctx = { ...ctx, sections: { ...ctx.sections, [edit.swap]: { ...target, id: section.id } } };
1658
+ changes.push({
1659
+ op: PageChangeOp.Section, kind: SectionChangeKind.Swap, handle: edit.swap, nodeId: section.id, label: target.label,
1660
+ pattern: edit.pattern, before: target.label, after: patternName(edit.pattern), ...(notPlaced ? { notPlaced } : {}),
1661
+ });
1662
+ }
1663
+ for (const edit of edits) {
1664
+ if (!('remove' in edit))
1665
+ continue;
1666
+ const target = changeable(edit.remove, SectionChangeKind.Remove);
1667
+ if (!target)
1668
+ continue;
1669
+ result.splice(indexOf(target.id), 1);
1670
+ changes.push({ op: PageChangeOp.Section, kind: SectionChangeKind.Remove, handle: edit.remove, nodeId: target.id, label: target.label, before: standsAfter(edit.remove), after: 'Removed' });
1671
+ }
1672
+ for (const edit of edits) {
1673
+ if (!('move' in edit))
1674
+ continue;
1675
+ const target = changeable(edit.move, SectionChangeKind.Move);
1676
+ if (!target || !place(edit.move, edit.after))
1677
+ continue;
1678
+ const [node] = result.splice(indexOf(target.id), 1);
1679
+ insertAfter(node, edit.after);
1680
+ if (stoodAfter(edit.move) === edit.after)
1681
+ continue;
1682
+ changes.push({
1683
+ op: PageChangeOp.Section, kind: SectionChangeKind.Move, handle: edit.move, nodeId: target.id, label: target.label,
1684
+ before: standsAfter(edit.move), after: whereLabel(edit.after),
1685
+ });
1686
+ }
1687
+ // Additions in answer order: two after the same section stand in that order.
1688
+ const lastAdded = new Map();
1689
+ for (const edit of edits) {
1690
+ if (!('add' in edit))
1691
+ continue;
1692
+ if (!offered('new', edit.add) || !place('new', edit.after))
1693
+ continue;
1694
+ const section = composeSection(edit.add, ctx.input ?? {}, { id: newId() }).section;
1695
+ const anchor = lastAdded.get(edit.after);
1696
+ if (anchor)
1697
+ result.splice(indexOf(anchor) + 1, 0, section);
1698
+ else
1699
+ insertAfter(section, edit.after);
1700
+ lastAdded.set(edit.after, section.id);
1701
+ changes.push({ op: PageChangeOp.Section, kind: SectionChangeKind.Add, handle: 'new', nodeId: section.id, label: patternName(edit.add), pattern: edit.add, before: '', after: whereLabel(edit.after) });
1702
+ }
1703
+ if (issues.length)
1704
+ return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
1705
+ return { ok: true, result, changes, issues: [] };
1706
+ }
1707
+
1354
1708
  /**
1355
1709
  * Surface S1 (the builder, this page), family `words` (ai-assist-plan §4, ai-session-panel-plan §3b–§3d): the page as
1356
1710
  * the model sees it — sections in order, each a handle (`s0`), the parts that carry words as handles (`s0.heading1`,
@@ -1479,6 +1833,10 @@ function summarizePage(layout, ctx) {
1479
1833
  handle: sectionHandle(index),
1480
1834
  label: sectionLabel(root, index),
1481
1835
  parts: walked.filter(w => w.section === index).map(w => ({ ...w.part, words: clipText(w.part.words, FOCUS_TEXT_CHARS) })),
1836
+ ...(() => {
1837
+ const pattern = sectionPatternOf(root);
1838
+ return pattern ? { pattern } : {};
1839
+ })(),
1482
1840
  ...(() => {
1483
1841
  const looks = walkedLooks.filter(l => l.section === index).map(l => l.look);
1484
1842
  return looks.length ? { looks } : {};
@@ -1531,7 +1889,11 @@ function summarizePage(layout, ctx) {
1531
1889
  : selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
1532
1890
  ...(Object.keys(names.styles).length ? { styleNames: names.styles } : {}),
1533
1891
  ...(Object.keys(names.schemes).length ? { schemeNames: names.schemes } : {}),
1892
+ sectionPatterns: askSectionPatternNames(),
1534
1893
  };
1894
+ const sectionMap = Object.fromEntries(layout.map((root, index) => [sectionHandle(index), {
1895
+ id: root.id, label: sectionLabel(root, index), focus: scope === AssistScope.Page || index === selectedSection,
1896
+ }]));
1535
1897
  return {
1536
1898
  brief: {
1537
1899
  surface: AssistSurface.BuilderPage,
@@ -1545,6 +1907,7 @@ function summarizePage(layout, ctx) {
1545
1907
  focusHandles: focusWalked.filter(w => !w.part.bound).map(w => w.part.handle),
1546
1908
  nodes,
1547
1909
  looks,
1910
+ sections: sectionMap,
1548
1911
  };
1549
1912
  }
1550
1913
  var WordsAnswerKey;
@@ -1739,16 +2102,20 @@ function pageWriteLocale(layout, ctx) {
1739
2102
  }
1740
2103
 
1741
2104
  const isWordEdit = (e) => 'value' in e;
2105
+ const isLookEdit = (e) => !isWordEdit(e) && !isSectionEdit(e) && (isStyleEdit(e) || isSchemeEdit(e) || isSizeEdit(e));
1742
2106
  function applyPageEdits(layout, edits, ctx) {
1743
2107
  const words = applyWordEdits(layout, edits.filter(isWordEdit), {
1744
2108
  handles: ctx.summary.handles, never: ctx.summary.brief.rules.never, sentence: ctx.sentence, words: ctx.words,
1745
2109
  });
1746
- const looks = edits.filter((e) => !isWordEdit(e) && (isStyleEdit(e) || isSchemeEdit(e) || isSizeEdit(e)));
1747
- const style = applyStyleEdits(words.result, looks, { looks: ctx.summary.looks, baseline: ctx.baseline });
1748
- const issues = [...words.issues, ...style.issues];
2110
+ const style = applyStyleEdits(words.result, edits.filter(isLookEdit), { looks: ctx.summary.looks, baseline: ctx.baseline });
2111
+ const sectionEdits = edits.filter(isSectionEdit);
2112
+ const sections = sectionEdits.length
2113
+ ? applySectionEdits(style.result, sectionEdits, { sections: ctx.summary.sections ?? {}, input: ctx.sectionInput, newId: ctx.newId })
2114
+ : { result: style.result, changes: [], issues: [] };
2115
+ const issues = [...words.issues, ...style.issues, ...sections.issues];
1749
2116
  if (issues.length)
1750
2117
  return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
1751
- return { ok: true, result: style.result, changes: [...words.changes, ...style.changes], issues: [] };
2118
+ return { ok: true, result: sections.result, changes: [...words.changes, ...style.changes, ...sections.changes], issues: [] };
1752
2119
  }
1753
2120
 
1754
2121
  /**
@@ -1771,7 +2138,8 @@ const isTerminalTurn = (status) => TERMINAL.has(status);
1771
2138
  const ASSIST_MODEL_AUTO = 'auto';
1772
2139
  const ASSIST_POLL_MS = 750;
1773
2140
  const MAX_SENTENCE_CHARS = 2000;
1774
- const isLookChange = (c) => 'op' in c && (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size);
2141
+ const isLookChange = (c) => 'op' in c
2142
+ && (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size || c.op === PageChangeOp.Section);
1775
2143
  /** A turn's own refusals and failures, beside generation-core's `AiRefusalCode`s (credits, plan, key), which a turn returns as they are. */
1776
2144
  var AssistRefusalCode;
1777
2145
  (function (AssistRefusalCode) {
@@ -1919,5 +2287,5 @@ function validateTurnRequest(req) {
1919
2287
  * Generated bundle index. Do not edit.
1920
2288
  */
1921
2289
 
1922
- export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PageChangeOp, PagePartKind, PageSuggestionKind, RouteAnswerKey, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, StyleAnswerKey, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, applyFieldEdits, applyPageEdits, applyStyleEdits, applyWordEdits, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeStyleAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSchemeEdit, isSessionOf, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookNames, memoryLine, namedLocale, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, serializedBaselineStyles, sessionMemory, styleJsonSchema, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
2290
+ export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_SECTION_PATTERNS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PageChangeOp, PagePartKind, PageSuggestionKind, RouteAnswerKey, SECTION_START, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SectionChangeKind, SectionsAnswerKey, StyleAnswerKey, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, applyFieldEdits, applyPageEdits, applySectionEdits, applyStyleEdits, applyWordEdits, askSectionPatternNames, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeSectionsAnswers, decodeStyleAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSchemeEdit, isSectionEdit, isSessionOf, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookNames, memoryLine, namedLocale, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, sectionPatternOf, sectionsJsonSchema, serializedBaselineStyles, sessionMemory, styleJsonSchema, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
1923
2291
  //# sourceMappingURL=vectoriox-iox-ui-assist-core.mjs.map