@taprootio/site-authoring 0.34.1 → 0.36.1

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.
@@ -0,0 +1,250 @@
1
+ // Generated from shared/free-form-columns.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ import registry from "./free-form-section-registry.json" with { type: "json" };
3
+ export const COLUMNS_LIMITS = Object.freeze({ ...registry.columns.limits });
4
+ const rowType = registry.columns.nodeType;
5
+ const regionType = registry.column.nodeType;
6
+ const sectionType = registry.section.nodeType;
7
+ const excludedTypes = new Set(registry.column.excludedNodeTypes);
8
+ const maximumPathLength = 256;
9
+ const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
10
+ const structural = (node) => node.type === rowType || node.type === regionType;
11
+ const content = (node) => Array.isArray(node.content) ? node.content : [];
12
+ const childPath = (path, index) => `${path}.content[${index}]`.slice(0, maximumPathLength);
13
+ const error = (code, path) => ({ code, field: "Body", path });
14
+ /** Follow document children, never component data, attributes or marks. Cache only immutable nodes. */
15
+ export function containsColumns(body, cache) {
16
+ if (!object(body))
17
+ return false;
18
+ const seen = new WeakSet();
19
+ const stack = [{ node: body, index: -1 }];
20
+ while (stack.length > 0) {
21
+ const frame = stack[stack.length - 1];
22
+ if (frame.index === -1) {
23
+ const known = cache?.get(frame.node);
24
+ if (known === true || structural(frame.node)) {
25
+ for (const ancestor of stack)
26
+ cache?.set(ancestor.node, true);
27
+ return true;
28
+ }
29
+ if (known === false || seen.has(frame.node)) {
30
+ stack.pop();
31
+ continue;
32
+ }
33
+ seen.add(frame.node);
34
+ frame.index = 0;
35
+ }
36
+ const children = content(frame.node);
37
+ if (frame.index === children.length) {
38
+ cache?.set(frame.node, false);
39
+ stack.pop();
40
+ continue;
41
+ }
42
+ const child = children[frame.index++];
43
+ if (object(child))
44
+ stack.push({ node: child, index: -1 });
45
+ }
46
+ return false;
47
+ }
48
+ /** Existing flow placement is authoritative; adopted fragments remain root-only. */
49
+ export function isColumnEligibleBlock(value) {
50
+ if (!object(value) || typeof value.type !== "string" || excludedTypes.has(value.type))
51
+ return false;
52
+ if (value.type === "componentBlock") {
53
+ const target = object(value.attrs) ? value.attrs.componentType : undefined;
54
+ return typeof target === "string" && Object.prototype.hasOwnProperty.call(registry.components, target)
55
+ && registry.components[target].rootPlacement
56
+ === registry.column.eligibleComponentRootPlacement;
57
+ }
58
+ return Object.prototype.hasOwnProperty.call(registry.rootNodes, value.type)
59
+ && registry.rootNodes[value.type].placement
60
+ === registry.column.eligibleRootNodePlacement;
61
+ }
62
+ function readAttributes(node) {
63
+ if (node.attrs !== undefined && !object(node.attrs))
64
+ return undefined;
65
+ const attrs = object(node.attrs) ? node.attrs : {};
66
+ if (Object.keys(attrs).some(key => !Object.prototype.hasOwnProperty.call(registry.columns.attrs, key))) {
67
+ return undefined;
68
+ }
69
+ const count = attrs.count === undefined ? registry.columns.attrs.count.default : attrs.count;
70
+ const ratio = attrs.ratio === undefined ? registry.columns.attrs.ratio.default : attrs.ratio;
71
+ if (typeof count !== "number" || !Number.isInteger(count) || !registry.columns.attrs.count.values.includes(count)) {
72
+ return undefined;
73
+ }
74
+ if (typeof ratio !== "string" || !registry.columns.attrs.ratio.values.includes(ratio))
75
+ return undefined;
76
+ if (count === 3 && ratio !== registry.columns.threeColumnRatio)
77
+ return undefined;
78
+ return { count: count, ratio: ratio };
79
+ }
80
+ /** Use after structural validation; omission and explicit defaults have identical meaning. */
81
+ export function columnsAttributes(node) {
82
+ return object(node) && node.type === rowType ? readAttributes(node) : undefined;
83
+ }
84
+ function closed(node, definition) {
85
+ return Object.keys(node).every(key => definition.nodeKeys.includes(key))
86
+ && definition.requiredNodeKeys.every(key => Object.prototype.hasOwnProperty.call(node, key));
87
+ }
88
+ /** Cursor frames keep memory proportional to depth, including very wide old documents. */
89
+ function* semanticNodes(body) {
90
+ const stack = [{
91
+ node: body,
92
+ path: "Body",
93
+ depth: 0,
94
+ insideRegion: false,
95
+ index: -1,
96
+ }];
97
+ while (stack.length > 0) {
98
+ const frame = stack[stack.length - 1];
99
+ if (frame.index === -1) {
100
+ frame.index = 0;
101
+ yield frame;
102
+ }
103
+ const children = content(frame.node);
104
+ if (frame.index === children.length) {
105
+ stack.pop();
106
+ continue;
107
+ }
108
+ const index = frame.index++;
109
+ const child = children[index];
110
+ if (object(child)) {
111
+ stack.push({
112
+ node: child,
113
+ path: childPath(frame.path, index),
114
+ depth: frame.depth + 1,
115
+ parentType: frame.node.type,
116
+ insideRegion: frame.insideRegion || frame.node.type === regionType,
117
+ index: -1,
118
+ });
119
+ }
120
+ }
121
+ }
122
+ function* containers(value) {
123
+ if (Array.isArray(value)) {
124
+ for (const child of value)
125
+ if (child !== null && typeof child === "object")
126
+ yield child;
127
+ }
128
+ else {
129
+ for (const key in value) {
130
+ if (!Object.prototype.hasOwnProperty.call(value, key))
131
+ continue;
132
+ const child = value[key];
133
+ if (child !== null && typeof child === "object")
134
+ yield child;
135
+ }
136
+ }
137
+ }
138
+ function containerDepthExceeded(body) {
139
+ const stack = [containers(body)];
140
+ while (stack.length > 0) {
141
+ const next = stack[stack.length - 1].next();
142
+ if (next.done)
143
+ stack.pop();
144
+ else {
145
+ if (stack.length === COLUMNS_LIMITS.jsonContainerDepth)
146
+ return true;
147
+ stack.push(containers(next.value));
148
+ }
149
+ }
150
+ return false;
151
+ }
152
+ /** Validate only the new structural contract. Existing body/content policies retain their ownership. */
153
+ export function validateColumnsBody(body, options = {}) {
154
+ if (!containsColumns(body, options.presenceCache))
155
+ return { hasColumns: false, errors: [] };
156
+ const refuse = (code, path = "Body") => ({
157
+ hasColumns: true,
158
+ errors: [error(code, path)],
159
+ });
160
+ if (options.allowColumns === false)
161
+ return refuse("columns.not_allowed");
162
+ if (!object(body) || body.type !== "doc" || !Array.isArray(body.content))
163
+ return refuse("columns.document");
164
+ let nodes = 0;
165
+ for (const visit of semanticNodes(body)) {
166
+ const { node, path, depth, parentType, insideRegion } = visit;
167
+ if (++nodes > COLUMNS_LIMITS.nodesPerDocument)
168
+ return refuse("columns.node_count", path);
169
+ if (depth > COLUMNS_LIMITS.nodeDepth)
170
+ return refuse("columns.node_depth", path);
171
+ if (insideRegion && (typeof node.type === "string" && excludedTypes.has(node.type)
172
+ || node.type === "componentBlock" && !isColumnEligibleBlock(node))) {
173
+ return refuse("columns.region_block", path);
174
+ }
175
+ if (node.type === rowType) {
176
+ if (depth !== 2 || parentType !== sectionType)
177
+ return refuse("columns.placement", path);
178
+ if (!closed(node, registry.columns) || !Array.isArray(node.content))
179
+ return refuse("columns.shape", path);
180
+ const attrs = readAttributes(node);
181
+ if (!attrs)
182
+ return refuse("columns.attributes", path);
183
+ if (node.content.length !== attrs.count || node.content.some(child => !object(child) || child.type !== regionType)) {
184
+ return refuse("columns.regions", path);
185
+ }
186
+ }
187
+ else if (node.type === regionType) {
188
+ if (parentType !== rowType)
189
+ return refuse("columns.region_placement", path);
190
+ if (!closed(node, registry.column) || !Array.isArray(node.content))
191
+ return refuse("columns.region_shape", path);
192
+ if (node.content.length < registry.column.minimumChildren || node.content.length > COLUMNS_LIMITS.blocksPerRegion) {
193
+ return refuse("columns.region_blocks", path);
194
+ }
195
+ const invalid = node.content.findIndex(child => !isColumnEligibleBlock(child));
196
+ if (invalid !== -1)
197
+ return refuse("columns.region_block", childPath(path, invalid));
198
+ }
199
+ else if (node.type === sectionType && depth === 1) {
200
+ const children = content(node);
201
+ if (children.length > COLUMNS_LIMITS.nodesPerDocument - nodes)
202
+ return refuse("columns.node_count", path);
203
+ let rows = 0;
204
+ let invalid = -1;
205
+ for (let index = 0; index < children.length; index++) {
206
+ const child = children[index];
207
+ if (object(child) && child.type === rowType)
208
+ rows++;
209
+ else if (invalid === -1 && !isColumnEligibleBlock(child))
210
+ invalid = index;
211
+ }
212
+ if (rows > COLUMNS_LIMITS.rowsPerSection)
213
+ return refuse("columns.section_rows", path);
214
+ if (invalid !== -1)
215
+ return refuse("columns.section_block", childPath(path, invalid));
216
+ }
217
+ }
218
+ // Count attribute/config containers too, without serializing text or imposing a byte quota.
219
+ if (containerDepthExceeded(body))
220
+ return refuse("columns.container_depth");
221
+ return { hasColumns: true, errors: [] };
222
+ }
223
+ /** Validate once, then path-copy only nodes changed by structural default omission. */
224
+ export function normalizeColumnsBody(body, options = {}) {
225
+ const result = validateColumnsBody(body, options);
226
+ if (!result.hasColumns || result.errors.length > 0)
227
+ return { ...result, body };
228
+ const rewrite = (node) => {
229
+ const children = content(node);
230
+ const rewritten = children.map(child => object(child) ? rewrite(child) : child);
231
+ const changedChildren = rewritten.some((child, index) => child !== children[index]);
232
+ let copy = changedChildren ? { ...node, content: rewritten } : node;
233
+ if (node.type === rowType && object(node.attrs)) {
234
+ const attrs = { ...node.attrs };
235
+ if (attrs.count === registry.columns.attrs.count.default)
236
+ delete attrs.count;
237
+ if (attrs.ratio === registry.columns.attrs.ratio.default)
238
+ delete attrs.ratio;
239
+ if (Object.keys(attrs).length !== Object.keys(node.attrs).length || Object.keys(attrs).length === 0) {
240
+ copy = { ...copy };
241
+ if (Object.keys(attrs).length === 0)
242
+ delete copy.attrs;
243
+ else
244
+ copy.attrs = attrs;
245
+ }
246
+ }
247
+ return copy;
248
+ };
249
+ return { ...result, body: rewrite(body) };
250
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": 16,
2
+ "version": 17,
3
3
 
4
4
  "imageDescription": {
5
5
  "fields": {
@@ -353,6 +353,49 @@
353
353
  }
354
354
  }
355
355
  },
356
+ "columns": {
357
+ "nodeType": "columns",
358
+ "label": "Columns",
359
+ "help": "Place two or three ordered editable regions beside one another inside a section; narrow layouts stack in reading order.",
360
+ "closed": true,
361
+ "nodeKeys": ["type", "attrs", "content"],
362
+ "requiredNodeKeys": ["type", "content"],
363
+ "attrs": {
364
+ "count": {
365
+ "type": "integer",
366
+ "required": false,
367
+ "default": 2,
368
+ "values": [2, 3]
369
+ },
370
+ "ratio": {
371
+ "type": "enum",
372
+ "required": false,
373
+ "default": "equal",
374
+ "values": ["equal", "40-60", "60-40"]
375
+ }
376
+ },
377
+ "threeColumnRatio": "equal",
378
+ "placement": { "parent": "section", "parentAtRoot": true },
379
+ "children": { "nodeType": "column", "countAttribute": "count" },
380
+ "limits": {
381
+ "rowsPerSection": 8,
382
+ "blocksPerRegion": 64,
383
+ "nodesPerDocument": 10000,
384
+ "nodeDepth": 16,
385
+ "jsonContainerDepth": 36
386
+ }
387
+ },
388
+ "column": {
389
+ "nodeType": "column",
390
+ "closed": true,
391
+ "nodeKeys": ["type", "content"],
392
+ "requiredNodeKeys": ["type", "content"],
393
+ "minimumChildren": 1,
394
+ "placement": { "parent": "columns" },
395
+ "eligibleRootNodePlacement": "flow",
396
+ "eligibleComponentRootPlacement": "flow",
397
+ "excludedNodeTypes": ["section", "columns", "column", "integrationFragment"]
398
+ },
356
399
  "table": {
357
400
  "nodeTypes": {
358
401
  "table": "table",
@@ -417,6 +460,7 @@
417
460
  "placement": {
418
461
  "root": true,
419
462
  "section": true,
463
+ "column": true,
420
464
  "measure": "wide"
421
465
  }
422
466
  },
@@ -470,6 +514,7 @@
470
514
  "placement": {
471
515
  "root": true,
472
516
  "section": true,
517
+ "column": true,
473
518
  "measure": "wide"
474
519
  }
475
520
  },
@@ -674,6 +719,7 @@
674
719
  "placement": {
675
720
  "root": true,
676
721
  "section": true,
722
+ "column": true,
677
723
  "measure": "wide"
678
724
  }
679
725
  },
@@ -11,6 +11,7 @@ import {
11
11
  normalizeFreeFormSectionBackground,
12
12
  normalizeFreeFormSectionDecoration,
13
13
  } from "./free-form-sections.js";
14
+ import { columnsAttributes, isColumnEligibleBlock, normalizeColumnsBody, validateColumnsBody } from "./free-form-columns.js";
14
15
  import { normalizeInlineFactsItems } from "./inline-facts.js";
15
16
  import { validateDocument } from "./validate-document.js";
16
17
  import {
@@ -59,6 +60,7 @@ const FENCE_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/u;
59
60
  const SECTION_HEADER_RE = /^:::section (\{.*\})$/u;
60
61
  const SECTION_HEADER_LIKE_RE = /^ *:::section(?=\s|\{|$)/u;
61
62
  const SECTION_CLOSE_RE = /^:::$/u;
63
+ const COLUMNS_DIRECTIVE_LIKE_RE = /^ *:::(columns|column|endcolumns|endcolumn)(?=\s|\{|$)/u;
62
64
  const BULLET_RE = /^( *)([-*+])( +|$)(.*)$/u;
63
65
  const ORDERED_RE = /^( *)(\d{1,9})([.)])( +|$)(.*)$/u;
64
66
  const BLOCKQUOTE_RE = /^ {0,3}>/u;
@@ -253,7 +255,8 @@ function isBlockStart(text) {
253
255
  || FOOTNOTE_DEFINITION_RE.test(text)
254
256
  || REFERENCE_DEFINITION_RE.test(text)
255
257
  || SECTION_HEADER_LIKE_RE.test(text)
256
- || SECTION_CLOSE_RE.test(text);
258
+ || SECTION_CLOSE_RE.test(text)
259
+ || COLUMNS_DIRECTIVE_LIKE_RE.test(text);
257
260
  }
258
261
 
259
262
  function guardBlockConstructs(text, line, nextText) {
@@ -316,7 +319,7 @@ async function parseBlocks(lines, context, depth) {
316
319
 
317
320
  const table = tablePrelude(lines, index);
318
321
  if (table) {
319
- if (context.blockPlacement !== "root" && context.blockPlacement !== "section") {
322
+ if (context.blockPlacement !== "root" && context.blockPlacement !== "section" && context.blockPlacement !== "column") {
320
323
  throw fail(
321
324
  CODES.tableShape,
322
325
  "table",
@@ -330,6 +333,16 @@ async function parseBlocks(lines, context, depth) {
330
333
  continue;
331
334
  }
332
335
 
336
+ if (COLUMNS_DIRECTIVE_LIKE_RE.test(text)) {
337
+ if (context.blockPlacement !== "section" || !text.startsWith(":::columns ")) {
338
+ throw fail(CODES.markdownColumns, "columns layout", "A columns layout belongs directly inside a section; its headers and closing markers must match.", line.number);
339
+ }
340
+ const consumed = await consumeColumns(lines, index, context, depth);
341
+ nodes.push(consumed.node);
342
+ index = consumed.next;
343
+ continue;
344
+ }
345
+
333
346
  if (SECTION_HEADER_LIKE_RE.test(text) || SECTION_CLOSE_RE.test(text)) {
334
347
  if (depth !== 0) {
335
348
  throw fail(
@@ -780,6 +793,69 @@ async function consumeSection(lines, start, headerText, context, depth) {
780
793
  );
781
794
  }
782
795
 
796
+ function columnsHeader(text, name, line) {
797
+ const match = new RegExp(`^:::${name} (\\{.*\\})$`, "u").exec(text);
798
+ if (!match) throw fail(CODES.markdownColumns, "columns layout", `Use exactly ':::${name} {JSON object}' without indentation or trailing text.`, line.number);
799
+ let attrs;
800
+ try { attrs = JSON.parse(match[1]); } catch (error) {
801
+ throw fail(CODES.markdownColumns, "columns layout", "A layout header needs a valid JSON object.", line.number, error);
802
+ }
803
+ if (!isPlainObject(attrs) || name === "column" && Object.keys(attrs).length !== 0) {
804
+ throw fail(CODES.markdownColumns, "columns layout", "A region header accepts only an empty JSON object.", line.number);
805
+ }
806
+ return attrs;
807
+ }
808
+
809
+ async function consumeColumns(lines, start, context, depth) {
810
+ const attrs = columnsHeader(expandLeadingTabs(lines[start].text), "columns", lines[start]);
811
+ const layout = columnsAttributes({ type: "columns", attrs });
812
+ if (!layout) throw fail(CODES.markdownColumns, "columns layout", "Choose two or three columns and Equal, Narrow start or Wide start; three columns must be equal.", lines[start].number);
813
+ const regions = [];
814
+ let index = start + 1;
815
+ while (index < lines.length) {
816
+ const line = lines[index];
817
+ const text = expandLeadingTabs(line.text);
818
+ if (isBlank(text)) { index += 1; continue; }
819
+ if (text === ":::endcolumns") {
820
+ if (regions.length !== layout.count) throw fail(CODES.markdownColumns, "columns layout", `This layout needs exactly ${layout.count} non-empty regions.`, line.number);
821
+ return { node: { type: "columns", attrs, content: regions }, next: index + 1 };
822
+ }
823
+ columnsHeader(text, "column", line);
824
+ const regionLine = line;
825
+ const body = [];
826
+ let activeFence;
827
+ let closed = false;
828
+ for (index += 1; index < lines.length; index += 1) {
829
+ const bodyLine = lines[index];
830
+ const bodyText = expandLeadingTabs(bodyLine.text);
831
+ if (activeFence) {
832
+ body.push(bodyLine);
833
+ if (activeFence.test(bodyText)) activeFence = undefined;
834
+ continue;
835
+ }
836
+ const fence = FENCE_RE.exec(bodyText);
837
+ if (fence) {
838
+ activeFence = fenceClosing(fence[2]);
839
+ body.push(bodyLine);
840
+ continue;
841
+ }
842
+ if (bodyText === ":::endcolumn") { closed = true; index += 1; break; }
843
+ if (COLUMNS_DIRECTIVE_LIKE_RE.test(bodyText) || SECTION_HEADER_LIKE_RE.test(bodyText) || SECTION_CLOSE_RE.test(bodyText)) {
844
+ throw fail(CODES.markdownColumns, "columns layout", "Close each region with ':::endcolumn' before another layout marker.", bodyLine.number);
845
+ }
846
+ body.push(bodyLine);
847
+ }
848
+ if (!closed) throw fail(CODES.markdownColumns, "columns layout", "A region was opened but never closed with ':::endcolumn'.", regionLine.number);
849
+ const content = await parseBlocks(body, { ...context, blockPlacement: "column" }, depth + 2);
850
+ if (content.length === 0 || content.some(node => !isColumnEligibleBlock(node))) {
851
+ throw fail(CODES.markdownColumns, "columns layout", "Each region needs ordinary flow blocks; sections and full-width components belong outside it.", regionLine.number);
852
+ }
853
+ regions.push({ type: "column", content });
854
+ if (regions.length > layout.count) throw fail(CODES.markdownColumns, "columns layout", `This layout accepts only ${layout.count} regions.`, regionLine.number);
855
+ }
856
+ throw fail(CODES.markdownColumns, "columns layout", "A layout was opened but never closed with ':::endcolumns'.", lines[start].number);
857
+ }
858
+
783
859
  function stripClosingHashes(title) {
784
860
  const trimmed = title.trimEnd();
785
861
  const closing = /^(.*?)\s+#+$/u.exec(trimmed);
@@ -825,7 +901,7 @@ async function consumeFence(lines, start, fence, context) {
825
901
  };
826
902
  }
827
903
  if (info === INLINE_FACTS_CONTRACT.markdown.fence) {
828
- if (context.blockPlacement !== "root" && context.blockPlacement !== "section") {
904
+ if (context.blockPlacement !== "root" && context.blockPlacement !== "section" && context.blockPlacement !== "column") {
829
905
  throw fail(
830
906
  CODES.markdownInlineFacts,
831
907
  "inline facts",
@@ -1767,6 +1843,10 @@ export async function markdownToProseMirror(markdown, options = {}) {
1767
1843
  "The Markdown source produced an empty page body. A page needs text, an image, a component block, or inline facts.",
1768
1844
  );
1769
1845
  }
1846
+ const columns = validateColumnsBody(document);
1847
+ if (columns.errors.length > 0) {
1848
+ throw fail(CODES.markdownColumns, columns.errors[0].path, "The columns layout has invalid nesting or exceeds its structural limits.");
1849
+ }
1770
1850
  assertConvertedDocument(document);
1771
- return { doc: document };
1851
+ return { doc: normalizeColumnsBody(document).body };
1772
1852
  }
@@ -7,6 +7,7 @@
7
7
  * Keep those publishing copies in sync and covered by parity tests.
8
8
  */
9
9
 
10
+ import { columnsAttributes, isColumnEligibleBlock } from "./free-form-columns.js";
10
11
  import freeFormSectionRegistry from "./free-form-section-registry.json" with { type: "json" };
11
12
  import { imageDescriptionIssues } from "./image-description-validation.js";
12
13
  import { isExternalLink, NEW_TAB_CUE_HTML, relWithNewTabTokens } from "./external-link.js";
@@ -177,7 +178,7 @@ function isTextBlock(type: string): boolean {
177
178
  || type === "tableHeader";
178
179
  }
179
180
 
180
- type RenderPlacement = "root" | "section" | "nested";
181
+ type RenderPlacement = "root" | "section" | "column" | "nested";
181
182
  type RenderOptionsWithLayout = RenderProseMirrorOptions & { fullWidthImages?: boolean };
182
183
 
183
184
  function renderNodes(
@@ -301,7 +302,9 @@ function renderNode(
301
302
  case "horizontalRule":
302
303
  return "<hr>";
303
304
  case "table":
304
- return placement === "root" || placement === "section" ? renderTable(node, options) : "";
305
+ return placement === "root" || placement === "section" || placement === "column"
306
+ ? renderTable(node, options)
307
+ : "";
305
308
  case "taprootImage":
306
309
  return options.nodeRenderers?.taprootImage?.(node, { groupColumns, fullWidth: options.fullWidthImages === true })
307
310
  ?? renderTaprootImage(node, options);
@@ -311,6 +314,10 @@ function renderNode(
311
314
  return options.nodeRenderers?.componentBlock?.(node) ?? renderComponentBlock(node);
312
315
  case "integrationPlacement":
313
316
  return renderIntegrationPlacement(node, options);
317
+ case "columns":
318
+ return placement === "section" ? renderColumns(node, options) : "";
319
+ case "column":
320
+ return "";
314
321
  case "section":
315
322
  return renderSection(
316
323
  node.content ?? [],
@@ -665,7 +672,7 @@ function renderInlineFacts(
665
672
  options: RenderProseMirrorOptions,
666
673
  placement: RenderPlacement,
667
674
  ): string {
668
- if (placement !== "root" && placement !== "section") return "";
675
+ if (placement !== "root" && placement !== "section" && placement !== "column") return "";
669
676
  const facts = normalizeInlineFacts(node);
670
677
  if (!facts) return "";
671
678
  const items = facts.map((fact) => {
@@ -724,6 +731,27 @@ function normalizeInlineFacts(node: ProseMirrorNode): NormalizedInlineFact[] | u
724
731
  return facts;
725
732
  }
726
733
 
734
+ function renderColumns(node: ProseMirrorNode, options: RenderOptionsWithLayout): string {
735
+ const attrs = columnsAttributes(node);
736
+ const regions = node.content;
737
+ if (
738
+ !attrs || !regions || regions.length !== attrs.count
739
+ || regions.some(region =>
740
+ region.type !== "column" || !region.content?.length || region.content.some(block => !isColumnEligibleBlock(block))
741
+ )
742
+ ) return "";
743
+ return renderElement(
744
+ "esp-columns",
745
+ {
746
+ "data-taproot-columns": true,
747
+ ratio: attrs.ratio === "equal" ? undefined : attrs.ratio,
748
+ },
749
+ regions.map(region =>
750
+ renderElement("div", { "data-taproot-column": true }, renderNodes(region.content ?? [], options, "column"))
751
+ ).join(""),
752
+ );
753
+ }
754
+
727
755
  function renderSection(
728
756
  nodes: readonly ProseMirrorNode[],
729
757
  attrs: Record<string, JsonValue | undefined>,
@@ -1,3 +1,4 @@
1
+ import { validateColumnsBody } from "./free-form-columns.js";
1
2
  import { IMAGE_DESCRIPTION_MODES } from "./image-description-validation.js";
2
3
  import { validateComponentBlock } from "./components.js";
3
4
  import {
@@ -431,11 +432,17 @@ const NODE_RULES = Object.freeze({
431
432
  }),
432
433
  section: rule({
433
434
  attrs: SECTION_ATTRS,
434
- children: SECTION_BLOCKS,
435
+ children: Object.freeze([...SECTION_BLOCKS, FREE_FORM_SECTION_REGISTRY.columns.nodeType]),
435
436
  minChildren: FREE_FORM_SECTION_REGISTRY.section.minimumChildren,
436
437
  sectionBackground: true,
437
438
  sectionDecoration: true,
438
439
  }),
440
+ columns: rule({
441
+ attrs: Object.freeze({ count: spec(() => null), ratio: spec(() => null) }),
442
+ children: Object.freeze([FREE_FORM_SECTION_REGISTRY.column.nodeType]),
443
+ minChildren: FREE_FORM_SECTION_REGISTRY.columns.attrs.count.default,
444
+ }),
445
+ column: rule({ children: SECTION_BLOCKS, minChildren: FREE_FORM_SECTION_REGISTRY.column.minimumChildren }),
439
446
  [INLINE_FACTS_CONTRACT.nodeType]: rule({
440
447
  attrs: Object.freeze({
441
448
  items: spec(() => null, {
@@ -1097,6 +1104,12 @@ export function validateDocument(document) {
1097
1104
  return finish(state);
1098
1105
  }
1099
1106
 
1107
+ const structural = validateColumnsBody(document);
1108
+ for (const issue of structural.errors) {
1109
+ report(state, issue.path, issue.code, "This columns layout has invalid structure, placement or size. Use two or three non-empty regions directly inside a section.");
1110
+ }
1111
+ if (structural.errors.length > 0) return finish(state);
1112
+
1100
1113
  checkNodeKeys(document, "", NODE_RULES.doc, false, state);
1101
1114
  checkAttrs(document, "", NODE_RULES.doc, state);
1102
1115
  checkMarks(document, "", NODE_RULES.doc, true, state);
@@ -57,6 +57,8 @@ export const NODE_TYPES = Object.freeze([
57
57
  "integrationPlacement",
58
58
  "integrationFragment",
59
59
  "section",
60
+ freeFormSectionRegistry.columns.nodeType,
61
+ freeFormSectionRegistry.column.nodeType,
60
62
  freeFormSectionRegistry.inlineFacts.nodeType,
61
63
  freeFormSectionRegistry.table.nodeTypes.table,
62
64
  freeFormSectionRegistry.table.nodeTypes.row,
@@ -172,6 +174,7 @@ export const CONTENT_ERROR_CODES = Object.freeze({
172
174
  markdownIndentedCode: "content.markdown_indented_code",
173
175
  markdownUnclosedFence: "content.markdown_unclosed_fence",
174
176
  markdownCodeLanguage: "content.markdown_code_language",
177
+ markdownColumns: "content.markdown_columns",
175
178
  markdownSectionHeader: "content.markdown_section_header",
176
179
  markdownSectionUnclosed: "content.markdown_section_unclosed",
177
180
  markdownSectionNested: "content.markdown_section_nested",
@@ -0,0 +1,47 @@
1
+ // Generated from shared/header-presentation.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ export const HEADER_HEIGHT_MULTIPLIER_LIMITS = Object.freeze({ minimum: 1, maximum: 5, step: 0.1 });
3
+ const STANDARD_HEIGHT = Object.freeze({ tenths: 10, scale: 1, canonical: "" });
4
+ const HEIGHT_MULTIPLIER = /^(?:[1-4](?:\.[0-9])?|5(?:\.0)?)$/u;
5
+ /** Parse the authored string without floating-point remainder or whitespace normalization. */
6
+ export function parseHeaderHeightMultiplier(value) {
7
+ if (value === undefined || value === "")
8
+ return STANDARD_HEIGHT;
9
+ if (typeof value !== "string")
10
+ return null;
11
+ // JavaScript's end anchor also matches before a final newline; require the entire value.
12
+ if (HEIGHT_MULTIPLIER.exec(value)?.[0] !== value)
13
+ return null;
14
+ const whole = value.charCodeAt(0) - 48;
15
+ const fraction = value.length === 3 ? value.charCodeAt(2) - 48 : 0;
16
+ const tenths = whole * 10 + fraction;
17
+ return tenths === 10
18
+ ? STANDARD_HEIGHT
19
+ : Object.freeze({ tenths, scale: tenths / 10, canonical: `${whole}.${fraction}` });
20
+ }
21
+ /** Read old or omitted settings as standard height; writes use the strict parser. */
22
+ export function resolveHeaderHeightMultiplier(value) {
23
+ return parseHeaderHeightMultiplier(value) ?? STANDARD_HEIGHT;
24
+ }
25
+ /** Stored compact assets are delivered only when an expanded brand already exists. */
26
+ export function canUseCompactHeaderLogo(position, multiplier, hasRegularLogo) {
27
+ const height = parseHeaderHeightMultiplier(multiplier);
28
+ return position === "fixed" && hasRegularLogo && height !== null && height.tenths > 10;
29
+ }
30
+ /** Keep each scheme's selected source and reserved ratio together through fallback. */
31
+ export function resolveHeaderLogoPairs(input) {
32
+ const pair = (url = "", aspectRatio = "") => ({ url, aspectRatio: url ? aspectRatio : "" });
33
+ const light = pair(input.lightLogoUrl, input.lightLogoAspectRatio);
34
+ const dark = pair(input.darkLogoUrl, input.darkLogoAspectRatio);
35
+ const profile = pair(input.profileLogoFallbackUrl, input.profileLogoAspectRatio);
36
+ const compactLight = pair(input.lightCompactLogoUrl, input.lightCompactLogoAspectRatio);
37
+ const compactDark = pair(input.darkCompactLogoUrl, input.darkCompactLogoAspectRatio);
38
+ const first = (...pairs) => pairs.find(candidate => candidate.url !== "") ?? pairs[0];
39
+ const resolvedLight = first(light, profile, dark);
40
+ const resolvedDark = first(dark, light, profile);
41
+ return {
42
+ light: resolvedLight,
43
+ dark: resolvedDark,
44
+ lightCompact: first(compactLight, compactDark, resolvedLight),
45
+ darkCompact: first(compactDark, compactLight, resolvedDark),
46
+ };
47
+ }