@stll/folio-core 0.76.0 → 0.78.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 (92) hide show
  1. package/dist/ai-edits/headless.d.ts +6 -4
  2. package/dist/ai-edits/headless.js +32 -15
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +11 -0
  5. package/dist/ai-edits/read.js +24 -1
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/canonical/canonicalBatchReview.js +7 -6
  8. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  9. package/dist/canonical/canonicalInlineProjection.js +2 -2
  10. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  11. package/dist/canonical/canonicalPublicOperations.js +19 -40
  12. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  13. package/dist/canonical/canonicalSeedContent.js +28 -15
  14. package/dist/canonical/canonicalSession.d.ts +22 -12
  15. package/dist/canonical/canonicalSession.js +190 -194
  16. package/dist/compare/inline-provenance.js +8 -1
  17. package/dist/controller/canonicalClipboard.d.ts +2 -1
  18. package/dist/controller/canonicalClipboard.js +312 -47
  19. package/dist/controller/canonicalComposition.js +67 -14
  20. package/dist/controller/canonicalStoryEditor.js +2 -0
  21. package/dist/controller/hiddenEditorManager.js +2 -0
  22. package/dist/docx/importedIdCollisions.js +29 -4
  23. package/dist/docx/paragraphParser.js +1 -1
  24. package/dist/docx/reviewResolutionProvenance.d.ts +2 -0
  25. package/dist/docx/reviewResolutionProvenance.js +22 -2
  26. package/dist/docx/server/templatePlan/apply.js +47 -2
  27. package/dist/docx/server/templatePlan/blocks.d.ts +34 -7
  28. package/dist/docx/server/templatePlan/blocks.js +190 -13
  29. package/dist/docx/server/templatePlan/builders.d.ts +8 -1
  30. package/dist/docx/server/templatePlan/builders.js +21 -5
  31. package/dist/docx/server/templatePlan/emit.d.ts +2 -0
  32. package/dist/docx/server/templatePlan/emit.js +108 -6
  33. package/dist/docx/server/templatePlan/plan.d.ts +26 -1
  34. package/dist/docx/server/templatePlan/plan.js +181 -21
  35. package/dist/docx/server/templatePlan/planShape.js +15 -3
  36. package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
  37. package/dist/docx/server/templatePlan/revisions.js +276 -2
  38. package/dist/docx/server/templatePlan/story.d.ts +58 -1
  39. package/dist/docx/server/templatePlan/story.js +176 -12
  40. package/dist/docx/server/templatePlan/types.d.ts +153 -1
  41. package/dist/docx/server/templatePlan/verify.js +58 -15
  42. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  43. package/dist/docx/tableGridXml.d.ts +3 -7
  44. package/dist/docx/tableGridXml.js +23 -15
  45. package/dist/docx/tableParser.js +3 -1
  46. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  47. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  48. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  49. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  50. package/dist/prosemirror/canonicalTableCommands.js +7 -9
  51. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  52. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  53. package/dist/prosemirror/conversion/toProseDoc.d.ts +8 -0
  54. package/dist/prosemirror/conversion/toProseDoc.js +43 -19
  55. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  56. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  57. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  58. package/dist/prosemirror/markupViewNotes.js +24 -27
  59. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  60. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  61. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  62. package/dist/prosemirror/markupViewProjection.js +90 -17
  63. package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
  64. package/dist/prosemirror/replacedAnnotations.js +11 -194
  65. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  66. package/dist/prosemirror/styles/styleResolver.js +4 -1
  67. package/dist/server.d.ts +2 -2
  68. package/dist/types/canonicalCapabilities.d.ts +3 -10
  69. package/dist/types/canonicalCapabilities.js +3 -10
  70. package/package.json +2 -2
  71. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  72. package/dist/internal/revisionResolutionEdits.js +0 -18
  73. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  74. package/dist/internal/revisionResolutionInline.js +0 -302
  75. package/dist/internal/revisionResolutionStep.d.ts +0 -3
  76. package/dist/internal/revisionResolutionStep.js +0 -113
  77. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  78. package/dist/internal/revisionResolutionTracking.js +0 -124
  79. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  80. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  81. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  82. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  83. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  84. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  85. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
  86. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
  87. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  88. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  89. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  90. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  91. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  92. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -93,6 +93,12 @@ const REF_SWITCH = /^\\[fhnprtw]$/u;
93
93
  /** The general format switch and the letter cases it may name. */
94
94
  const FORMAT_SWITCH = "\\*";
95
95
  const CASE_FORMAT = /^(?:lower|upper|firstcap)$/iu;
96
+ /**
97
+ * What else the general format switch may name: that an update keeps the
98
+ * look of the previous result (ECMA-376 Part 1, 17.16.4.3), so a field
99
+ * set in a face of its own stays so once its result is recalculated.
100
+ */
101
+ const LOOK_FORMAT = /^(?:mergeformat|charformat)$/iu;
96
102
  /** The letter case a REF instruction asks for its result in, or null. */
97
103
  const refCaseFormat = (instruction) => {
98
104
  const name = /\\\*\s*(?<name>lower|upper|firstcap)\b/iu.exec(instruction)?.groups?.["name"]?.toLowerCase();
@@ -118,16 +124,20 @@ const applyRefCaseFormat = (text, format) => {
118
124
  /**
119
125
  * The field code of a REF to `bookmark` with `switches` (`\n \t \h`,
120
126
  * `\n \* lower \h`). Null when the switches hold anything but
121
- * single-letter switches and one letter-case format.
127
+ * single-letter switches, one letter-case format and one format that
128
+ * keeps the result's look.
122
129
  */
123
130
  const refFieldInstruction = (bookmark, switches) => {
124
131
  const parts = switches.trim().split(/\s+/u).filter(Boolean);
125
- let formats = 0;
132
+ let cases = 0;
133
+ let looks = 0;
126
134
  for (const [index, part] of parts.entries()) {
127
135
  const afterFormat = parts[index - 1] === FORMAT_SWITCH;
128
136
  if (part === FORMAT_SWITCH) {
129
- formats += 1;
130
- if (formats > 1 || !CASE_FORMAT.test(parts[index + 1] ?? "")) return null;
137
+ const format = parts[index + 1] ?? "";
138
+ cases += CASE_FORMAT.test(format) ? 1 : 0;
139
+ looks += LOOK_FORMAT.test(format) ? 1 : 0;
140
+ if (cases > 1 || looks > 1 || !(CASE_FORMAT.test(format) || LOOK_FORMAT.test(format))) return null;
131
141
  } else if (!afterFormat && !REF_SWITCH.test(part)) return null;
132
142
  }
133
143
  return ` REF ${bookmark} ${parts.join(" ")}${parts.length === 0 ? "" : " "}`;
@@ -139,6 +149,12 @@ const fieldBookmarkOf = (instruction) => /^\s*(?:REF|PAGEREF|NOTEREF)\s+"?(?<nam
139
149
  * place in the schema's child order. Null when the part is not a settings part.
140
150
  */
141
151
  const setUpdateFieldsOnOpen = (settingsXml, enabled) => updateSettingsOnOffChild(settingsXml, "updateFields", enabled ? true : void 0);
152
+ /**
153
+ * `settingsXml` without `w:trackRevisions`: a document that carries tracked
154
+ * changes of its source records no new ones until its reader switches
155
+ * tracking on. Null when the part is not a settings part.
156
+ */
157
+ const setTrackingOff = (settingsXml) => updateSettingsOnOffChild(settingsXml, "trackRevisions", void 0);
142
158
  const SHIFT_RETURN = "doNotExpandShiftReturn";
143
159
  /** The children of `w:compat` the schema orders in front of the setting. */
144
160
  const COMPAT_BEFORE_SHIFT_RETURN = /* @__PURE__ */ new Set([
@@ -453,4 +469,4 @@ const freezeFields = (part, kinds) => {
453
469
  }))
454
470
  };
455
471
  };
456
- export { applyRefCaseFormat, bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, inheritedReferencesXml, keepsShiftReturnSpacing, mintRefBookmarkName, refCaseFormat, refFieldInstruction, sectionPropertiesXml, setKeepShiftReturnSpacing, setUpdateFieldsOnOpen, withoutContained, wrapParagraphContentInBookmark };
472
+ export { applyRefCaseFormat, bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, inheritedReferencesXml, keepsShiftReturnSpacing, mintRefBookmarkName, refCaseFormat, refFieldInstruction, sectionPropertiesXml, setKeepShiftReturnSpacing, setTrackingOff, setUpdateFieldsOnOpen, withoutContained, wrapParagraphContentInBookmark };
@@ -55,6 +55,8 @@ export type EmitShared = {
55
55
  /** Register a media part of the output and return its absolute target. */
56
56
  addMedia: (sourcePath: string, media: SourceMedia) => string;
57
57
  nextDrawingId: () => number;
58
+ /** A fresh id for a tracked change the output carries. */
59
+ nextRevisionId: () => number;
58
60
  };
59
61
  export type EmitContext = EmitShared & {
60
62
  prefixes: PartPrefixes;
@@ -5,6 +5,7 @@ import { appendToXmlRoot } from "../../xmlRootInsertion.js";
5
5
  import { bookmarkEndXml, bookmarkStartXml, complexFieldXml, wrapParagraphContentInBookmark } from "./builders.js";
6
6
  import { runPropertiesXml } from "./emphasis.js";
7
7
  import { paragraphPieces } from "./plan.js";
8
+ import { deletedRowMarkOf, insertedRowMarkOf, keptDeletedRowOf, rowTextOf } from "./revisions.js";
8
9
  import { TemplatePlanError } from "./types.js";
9
10
  import { MATH_NAMESPACE, elementChildren, escapeXmlAttribute, escapeXmlText, wAttr, wChild, wChildren, wName } from "./xml.js";
10
11
  import { Result, panic } from "better-result";
@@ -189,7 +190,55 @@ const wSubtreeXml = (element, prefix) => {
189
190
  const open = `<${prefix}:${name}${wAttributesXml(element, prefix)}`;
190
191
  return children === "" ? `${open}/>` : `${open}>${children}</${prefix}:${name}>`;
191
192
  };
193
+ /**
194
+ * What stands in a paragraph's runs for a deleted paragraph mark until the
195
+ * paragraph is written: the attributes of the mark between two of these. No
196
+ * run holds the character (XML text cannot).
197
+ */
198
+ const MARK_SPLIT = "\0";
199
+ /** The inserted mark of a paragraph's last piece, when it has one. */
200
+ const insertedMarkOf = (segments) => {
201
+ const last = segments.at(-1);
202
+ const revision = (last === void 0 || last.kind === "piece" ? [last?.piece] : last.pieces).at(-1)?.atom?.revision;
203
+ return revision?.mark === true ? revision : void 0;
204
+ };
205
+ /** The attributes a kept tracked change is written with: its own author and
206
+ * date, and an id of the output's. */
207
+ const revisionAttributesXml = ({ author, date }, { prefixes: { w }, nextRevisionId }) => ` ${w}:id="${String(nextRevisionId())}" ${w}:author="${escapeXmlAttribute(author)}"${date === null ? "" : ` ${w}:date="${escapeXmlAttribute(date)}"`}`;
208
+ /** Deleted text as the content of a deleted run: tabs and line breaks are
209
+ * elements, the rest is `w:delText`. */
210
+ const deletedContentXml = (deleted, w) => deleted.split(/(\t|\n)/u).map((part) => {
211
+ if (part === " ") return `<${w}:tab/>`;
212
+ if (part === "\n") return `<${w}:br/>`;
213
+ return part === "" ? "" : `<${w}:delText xml:space="preserve">${escapeXmlText(part)}</${w}:delText>`;
214
+ }).join("");
215
+ /**
216
+ * The runs of one piece. A piece of a kept tracked change is written inside
217
+ * its insertion or deletion; a deletion holds the text that was deleted and
218
+ * takes no place in the text around it.
219
+ */
192
220
  const pieceRunXml = (piece, context, linked) => {
221
+ const revision = piece.atom?.revision;
222
+ if (revision === void 0) return plainPieceRunXml(piece, context, linked);
223
+ const { w } = context.prefixes;
224
+ if (revision.mark === true) return Result.ok("");
225
+ const attributes = revisionAttributesXml(revision, context);
226
+ if (revision.deleted === "") return Result.ok(`${MARK_SPLIT}${attributes}${MARK_SPLIT}`);
227
+ if (revision.kind === "del") {
228
+ const deletion = `<${w}:del${attributes}><${w}:r>${runPropertiesXml({
229
+ prefix: w,
230
+ signature: piece.signature,
231
+ rStyle: linked ? context.styles.hyperlink : null,
232
+ escapeAttribute: escapeXmlAttribute
233
+ })}${deletedContentXml(revision.deleted ?? "", w)}</${w}:r></${w}:del>`;
234
+ return Result.ok(revision.within === void 0 ? deletion : `<${w}:ins${revisionAttributesXml({
235
+ kind: "ins",
236
+ ...revision.within
237
+ }, context)}>${deletion}</${w}:ins>`);
238
+ }
239
+ return plainPieceRunXml(piece, context, linked).map((runs) => runs === "" ? "" : `<${w}:ins${attributes}>${runs}</${w}:ins>`);
240
+ };
241
+ const plainPieceRunXml = (piece, context, linked) => {
193
242
  const { w } = context.prefixes;
194
243
  const properties = (rStyle) => runPropertiesXml({
195
244
  prefix: w,
@@ -242,7 +291,7 @@ const mergedPieces = (pieces) => {
242
291
  const merged = [];
243
292
  for (const piece of pieces) {
244
293
  const last = merged.at(-1);
245
- if (last !== void 0 && last.kind === "text" && piece.kind === "text" && last.signature === piece.signature && last.origin === piece.origin && sameLink(last.link, piece.link)) merged[merged.length - 1] = {
294
+ if (last !== void 0 && last.kind === "text" && piece.kind === "text" && last.signature === piece.signature && last.origin === piece.origin && last.atom?.revision === void 0 && piece.atom?.revision === void 0 && sameLink(last.link, piece.link)) merged[merged.length - 1] = {
246
295
  ...last,
247
296
  text: last.text + piece.text
248
297
  };
@@ -343,6 +392,11 @@ const paragraphXml = (emit, context) => {
343
392
  const stops = tabStops.map((stop) => `<${w}:tab ${w}:val="left" ${w}:pos="${String(stop)}"/>`).join("");
344
393
  properties.push(`<${w}:tabs>${stops}</${w}:tabs>`);
345
394
  }
395
+ const { spacing } = emit.paragraph;
396
+ if (spacing !== null) {
397
+ const sides = ["before", "after"].filter((side) => spacing[side] !== void 0).map((side) => ` ${w}:${side}="${String(spacing[side])}"`).join("");
398
+ properties.push(`<${w}:spacing${sides}/>`);
399
+ }
346
400
  if (indent !== null) {
347
401
  const sides = [
348
402
  "left",
@@ -356,8 +410,22 @@ const paragraphXml = (emit, context) => {
356
410
  if (emit.sectionXml !== null) properties.push(emit.sectionXml);
357
411
  const runs = segmentsRunsXml(emit.paragraph.segments, context, emit.instructionOf);
358
412
  if (Result.isError(runs)) return runs;
359
- const xml = `<${w}:p>${properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`}${runs.value}</${w}:p>`;
360
- if (emit.bookmark === void 0) return Result.ok(xml);
413
+ const inserted = insertedMarkOf(emit.paragraph.segments);
414
+ if (inserted !== void 0) {
415
+ const mark = `<${w}:rPr><${w}:ins${revisionAttributesXml(inserted, context)}/></${w}:rPr>`;
416
+ properties.splice(emit.sectionXml === null ? properties.length : properties.length - 1, 0, mark);
417
+ }
418
+ const pPr = properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`;
419
+ const [last = "", ...earlier] = runs.value.split(MARK_SPLIT).toReversed();
420
+ const halves = [];
421
+ const parted = earlier.toReversed();
422
+ for (let at = 0; at + 1 < parted.length; at += 2) {
423
+ const style = styleId === null ? "" : `<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`;
424
+ const list = numbering.kind === "direct" || emit.styleBindsList ? `<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>` : "";
425
+ halves.push(`<${w}:p><${w}:pPr>${style}${list}<${w}:rPr><${w}:del${parted[at + 1] ?? ""}/></${w}:rPr></${w}:pPr>${parted[at] ?? ""}</${w}:p>`);
426
+ }
427
+ const xml = `<${w}:p>${pPr}${last}</${w}:p>`;
428
+ if (emit.bookmark === void 0) return Result.ok(`${halves.join("")}${xml}`);
361
429
  const wrapped = wrapParagraphContentInBookmark({
362
430
  paragraphXml: xml,
363
431
  prefixes: context.prefixes,
@@ -367,7 +435,7 @@ const paragraphXml = (emit, context) => {
367
435
  code: "xml-unreadable",
368
436
  message: "A reference target could not be bookmarked.",
369
437
  blockId: emit.paragraph.parts.at(0)?.block.block.id ?? ""
370
- })) : Result.ok(wrapped);
438
+ })) : Result.ok(`${halves.join("")}${wrapped}`);
371
439
  };
372
440
  const TABLE_LAYOUT_PROPERTIES = ["tblLayout", "tblLook"];
373
441
  const ROW_PROPERTIES = [
@@ -403,6 +471,37 @@ const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
403
471
  const child = wChild(properties, name);
404
472
  return child === null ? "" : wSubtreeXml(child, prefix);
405
473
  }).join("");
474
+ /** The attributes a kept row or mark revision is written with, read off the
475
+ * source's own record. */
476
+ const markAttributesXml = (mark, context) => revisionAttributesXml({
477
+ kind: "del",
478
+ author: wAttr(mark, "author") ?? "",
479
+ date: wAttr(mark, "date")
480
+ }, context);
481
+ /**
482
+ * A row the source records as deleted, written back as one: its cells with
483
+ * their spans, and in each cell its paragraphs' text as deleted text with a
484
+ * deleted paragraph mark. The accepted view has no such row, so no plan
485
+ * places its paragraphs; they take no style of their own.
486
+ */
487
+ const deletedRowXml = (row, keepsBorders, context) => {
488
+ const { w } = context.prefixes;
489
+ const mark = deletedRowMarkOf(row);
490
+ const attributes = () => mark === null ? "" : markAttributesXml(mark, context);
491
+ const deletedParagraphXml = (text) => `<${w}:p><${w}:pPr><${w}:rPr><${w}:del${attributes()}/></${w}:rPr></${w}:pPr>${text === "" ? "" : `<${w}:del${attributes()}><${w}:r>${deletedContentXml(text, w)}</${w}:r></${w}:del>`}</${w}:p>`;
492
+ const cells = [];
493
+ const stack = [...elementChildren(row)].toReversed();
494
+ for (let next = stack.pop(); next !== void 0; next = stack.pop()) if (wName(next) === "tc") {
495
+ const properties = wChild(next, "tcPr");
496
+ const kept = `${keptChildrenXml(properties, CELL_SPAN_PROPERTIES, w)}${keepsBorders ? keptChildrenXml(properties, ["tcBorders"], w) : ""}`;
497
+ const lines = rowTextOf({
498
+ ...row,
499
+ elements: [next]
500
+ }).split("\n");
501
+ cells.push(`<${w}:tc>${kept === "" ? "" : `<${w}:tcPr>${kept}</${w}:tcPr>`}${lines.map(deletedParagraphXml).join("")}</${w}:tc>`);
502
+ } else if (wName(next) !== "trPr") stack.push(...elementChildren(next).toReversed());
503
+ return `<${w}:tr><${w}:trPr><${w}:del${attributes()}/></${w}:trPr>${cells.join("")}</${w}:tr>`;
504
+ };
406
505
  /**
407
506
  * A source table rebuilt: its grid, spans and merges, with every cell
408
507
  * paragraph placed like a body paragraph. Without a template table style the
@@ -459,8 +558,11 @@ const tableXml = ({ table, styleId, paragraphOf }, context) => {
459
558
  const out = [];
460
559
  for (const child of elementChildren(container)) {
461
560
  const name = wName(child);
462
- if (name === "tr") {
463
- const kept = keptChildrenXml(wChild(child, "trPr"), ROW_PROPERTIES, w);
561
+ const deleted = keptDeletedRowOf(child);
562
+ if (deleted !== null) out.push(deletedRowXml(deleted, styleId === null, context));
563
+ else if (name === "tr") {
564
+ const inserted = insertedRowMarkOf(child);
565
+ const kept = `${keptChildrenXml(wChild(child, "trPr"), ROW_PROPERTIES, w)}${inserted === null ? "" : `<${w}:ins${markAttributesXml(inserted, context)}/>`}`;
464
566
  const cells = cellsXml(child);
465
567
  if (Result.isError(cells)) return cells;
466
568
  out.push(`<${w}:tr>${kept === "" ? "" : `<${w}:trPr>${kept}</${w}:trPr>`}${cells.value}</${w}:tr>`);
@@ -9,7 +9,7 @@ import { AnalyzedBlock, AnalyzedDocument } from "./blocks.js";
9
9
  import { BookmarkWrap } from "./builders.js";
10
10
  import { StoryOrigin } from "./resources.js";
11
11
  import { AtomKind, AtomLink, InlineAtom, ParagraphRead, StoryField } from "./story.js";
12
- import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
12
+ import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection, TemplatePlanSpacing } from "./types.js";
13
13
  import { Result } from "better-result";
14
14
  export type ExpectedPiece = {
15
15
  kind: AtomKind;
@@ -53,6 +53,14 @@ export type ResolvedNumbering = {
53
53
  export type ResolvedPart = {
54
54
  block: AnalyzedBlock;
55
55
  strippedPrefix: string;
56
+ /** Drawn shapes fixed to the page the part is written without. */
57
+ droppedPageShapes: number;
58
+ /** The lead a slot dropped off the part and the template paragraph that
59
+ * shows the field, or null. */
60
+ droppedLead: {
61
+ text: string;
62
+ shownByTemplateBlockId: string;
63
+ } | null;
56
64
  /** The automatic label written as text before the part, or null. */
57
65
  labelAsText: string | null;
58
66
  };
@@ -77,6 +85,8 @@ export type ResolvedParagraph = {
77
85
  tabStops: readonly number[] | null;
78
86
  /** The paragraph's own alignment, or null. */
79
87
  alignment: TemplatePlanAlignment | null;
88
+ /** The paragraph's own space in front and behind, or null. */
89
+ spacing: TemplatePlanSpacing | null;
80
90
  /** The section the paragraph is the last of, or null. */
81
91
  endsSection: TemplatePlanSection | null;
82
92
  };
@@ -109,10 +119,21 @@ export type ResolvedSlot = {
109
119
  templateBlock: AnalyzedBlock;
110
120
  paragraph: ResolvedParagraph;
111
121
  };
122
+ /**
123
+ * The run of a paragraph that holds the separator of the field the
124
+ * paragraph begins and leaves open: what follows it is the start of a result
125
+ * that goes on in later paragraphs. A field the paragraph both begins and
126
+ * ends (a page number in front of a table of contents) is not that field.
127
+ * Null when no one field is left open with its result begun, in runs of the
128
+ * paragraph itself.
129
+ */
130
+ export declare const fieldSeparatorRun: (paragraph: XmlElement) => XmlElement | null;
112
131
  export type ResolvedPlan = {
113
132
  items: ResolvedItem[];
114
133
  /** Slots that sit inside a kept template table. */
115
134
  nestedSlots: ResolvedSlot[];
135
+ /** Paragraphs of kept template tables written without their text. */
136
+ emptied: AnalyzedBlock[];
116
137
  /** The output paragraph each placed source block ends up in. */
117
138
  byBlockId: Map<string, ResolvedParagraph>;
118
139
  omitted: Map<string, TemplatePlanOmitReason>;
@@ -128,6 +149,10 @@ export type ResolvedPlan = {
128
149
  }[];
129
150
  freezeKinds: ReadonlySet<string>;
130
151
  keptTemplateBlocks: AnalyzedBlock[];
152
+ /** The paragraphs kept tables of contents begin in, written without the
153
+ * entries they cache: each with the length of the text it keeps in front
154
+ * of the field's result. */
155
+ emptiedContents: Map<AnalyzedBlock, number>;
131
156
  };
132
157
  /**
133
158
  * Whether `label` reads as a manual list label: up to three leading words
@@ -5,8 +5,10 @@ import { bookmarkIdsOf, mintRefBookmarkName, refFieldInstruction } from "./build
5
5
  import { emphasisDeviation, emphasisSignature, paragraphBaseline, readDirectEmphasis, withCharacterStyle, withOverride, withSignatureHighlight } from "./emphasis.js";
6
6
  import { styleNumbering } from "./labels.js";
7
7
  import { PLAN_HIGHLIGHT_COLORS, planShapeIssue } from "./planShape.js";
8
+ import "./revisions.js";
9
+ import { isPageShape } from "./story.js";
8
10
  import { TemplatePlanError } from "./types.js";
9
- import { isW, maxOf, wAttr, wChild, wChildVal, walkElements } from "./xml.js";
11
+ import { elementChildren, isW, maxOf, wAttr, wChild, wChildVal, wName, walkElements } from "./xml.js";
10
12
  import { Result } from "better-result";
11
13
  // src/docx/server/templatePlan/plan.ts
12
14
  /**
@@ -15,6 +17,77 @@ import { Result } from "better-result";
15
17
  * emphasis, derived from the source blocks alone. The writer emits it and the
16
18
  * verifier compares the written package against it.
17
19
  */
20
+ const fieldCharOf = (run) => wName(run) === "r" ? wAttr(wChild(run, "fldChar"), "fldCharType") : null;
21
+ /**
22
+ * The run of a paragraph that holds the separator of the field the
23
+ * paragraph begins and leaves open: what follows it is the start of a result
24
+ * that goes on in later paragraphs. A field the paragraph both begins and
25
+ * ends (a page number in front of a table of contents) is not that field.
26
+ * Null when no one field is left open with its result begun, in runs of the
27
+ * paragraph itself.
28
+ */
29
+ const fieldSeparatorRun = (paragraph) => {
30
+ const open = [];
31
+ for (const child of elementChildren(paragraph)) {
32
+ const mark = fieldCharOf(child);
33
+ if (mark === "begin") open.push({ separator: null });
34
+ else if (mark === "end") open.pop();
35
+ else if (mark === "separate") {
36
+ const top = open.at(-1);
37
+ if (top !== void 0 && top.separator === null) top.separator = child;
38
+ }
39
+ }
40
+ const [left, ...others] = open;
41
+ return left === void 0 || others.length > 0 ? null : left.separator;
42
+ };
43
+ const holdsText = (element) => {
44
+ let text = false;
45
+ walkElements(element, (inner) => {
46
+ text ||= wName(inner) === "t";
47
+ });
48
+ return text;
49
+ };
50
+ /**
51
+ * Whether a paragraph ends the field left open in front of it and holds no
52
+ * more behind that end: the end of the field's result and nothing else. The
53
+ * end is the field's own, the first one that closes no field the paragraph
54
+ * began; text behind it stays, whatever field follows that text.
55
+ */
56
+ const endsOpenField = (paragraph) => {
57
+ const children = elementChildren(paragraph);
58
+ let depth = 0;
59
+ for (const [position, child] of children.entries()) {
60
+ const mark = fieldCharOf(child);
61
+ if (mark === "begin") depth += 1;
62
+ else if (mark === "end") {
63
+ if (depth === 0) return !children.slice(position + 1).some(holdsText);
64
+ depth -= 1;
65
+ }
66
+ }
67
+ return false;
68
+ };
69
+ /**
70
+ * The kept tables of contents that show entries over several paragraphs:
71
+ * the paragraph each begins in, the length of the text that paragraph holds
72
+ * in front of the field's result, and the further paragraphs of its
73
+ * entries. A field that does not begin in runs of its own paragraph, that
74
+ * ends in a paragraph with text behind it, or whose paragraphs are not all
75
+ * kept top-level blocks, is not among them and stays as the template has it.
76
+ */
77
+ const contentsWithEntries = (template, keptIds) => {
78
+ const found = [];
79
+ for (const field of template.story.state.fields) {
80
+ if (field.kind !== "TOC" || !field.closed || field.nestedInCode || field.endParagraphOrdinal <= field.paragraphOrdinal) continue;
81
+ const [first, ...rest] = template.story.paragraphs.slice(field.paragraphOrdinal, field.endParagraphOrdinal + 1);
82
+ const last = rest.at(-1);
83
+ if (first !== void 0 && last !== void 0 && [first, ...rest].every(({ block, parentId }) => parentId === null && keptIds.has(block.id)) && field.resultStart >= 0 && fieldSeparatorRun(first.element) !== null && endsOpenField(last.element)) found.push({
84
+ first,
85
+ textKept: field.resultStart,
86
+ rest
87
+ });
88
+ }
89
+ return found;
90
+ };
18
91
  const refuse = ({ code, message, blockId }) => new TemplatePlanError({
19
92
  code,
20
93
  message,
@@ -196,6 +269,16 @@ const partSegments = ({ block, pieces, strippedLength, strippedBreak, references
196
269
  }));
197
270
  for (const { start, end } of references) if (!boundaries.has(start) || !boundaries.has(end)) return badReference(`Reference span ${start}-${end} in block ${blockId} cuts a character or mark.`);
198
271
  for (const { start, end } of highlights) if (!boundaries.has(start) || !boundaries.has(end)) return badHighlight(`Highlight ${start}-${end} in block ${blockId} cuts a character or mark.`);
272
+ for (const { piece, start, end } of split) {
273
+ if (piece.atom?.revision === void 0) continue;
274
+ if (strippedLength > 0 && start < strippedLength) return Result.err(refuse({
275
+ code: "strip-label-mismatch",
276
+ message: `The label to strip from block ${blockId} holds a tracked change.`,
277
+ blockId
278
+ }));
279
+ const cited = references.find((reference) => start <= reference.end && end >= reference.start);
280
+ if (cited !== void 0) return badReference(`Reference span ${cited.start}-${cited.end} in block ${blockId} holds a tracked change.`);
281
+ }
199
282
  const positioned = [];
200
283
  for (const entry of split) {
201
284
  const empty = entry.start === entry.end;
@@ -368,7 +451,7 @@ const resolvePlan = (source, template, plan) => {
368
451
  message: "The plan was made for another template."
369
452
  }));
370
453
  for (const [name, analyzed] of [["source", source], ["template", template]]) if (analyzed.document.root.namespaceUri !== TRANSITIONAL_WORDPROCESSINGML) return unsupported(`The ${name} is not a Transitional WordprocessingML package.`);
371
- if (source.manifest.trackedChanges > 0) return Result.err(refuse({
454
+ if (source.manifest.trackedChanges > 0 && source.manifest.trackedChangesKept === void 0) return Result.err(refuse({
372
455
  code: "tracked-changes",
373
456
  message: `The source holds ${source.manifest.trackedChanges} tracked change(s); resolve them first.`
374
457
  }));
@@ -469,7 +552,7 @@ const resolvePlan = (source, template, plan) => {
469
552
  placed.add(id);
470
553
  return Result.ok(void 0);
471
554
  };
472
- const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, endsSection }) => {
555
+ const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, spacing, endsSection }) => {
473
556
  const first = parts.at(0);
474
557
  if (first === void 0) return invalid("A plan item names no source block.");
475
558
  const firstId = first.block.block.id;
@@ -488,6 +571,13 @@ const resolvePlan = (source, template, plan) => {
488
571
  const { block, stripLabel, stripLabelBreak } = planned;
489
572
  const { id, text } = block.block;
490
573
  if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
574
+ const endsInInsertedMark = block.read.atoms.some(({ revision }) => revision?.mark === true);
575
+ const holdsDeletedMark = block.read.atoms.some(({ revision }) => revision?.deleted === "");
576
+ if (endsInInsertedMark && index < parts.length - 1 || placement === "slot" && (endsInInsertedMark || holdsDeletedMark)) return Result.err(refuse({
577
+ code: "merge-invalid",
578
+ message: placement === "slot" ? `Block ${id} holds a tracked paragraph mark and cannot fill a paragraph of the template.` : `Block ${id} ends in a tracked paragraph mark and cannot join the next block.`,
579
+ blockId: id
580
+ }));
491
581
  const placedOnce = place(block);
492
582
  if (Result.isError(placedOnce)) return placedOnce;
493
583
  const unread = block.read.unsupported.at(0);
@@ -504,15 +594,32 @@ const resolvePlan = (source, template, plan) => {
504
594
  const blank = stripLabelBreak === true ? LABEL_SPACE_AND_BREAK : LABEL_SPACE;
505
595
  strippedPrefix = text.slice(0, labelEnd + (blank.exec(text.slice(labelEnd))?.[0].length ?? 0));
506
596
  }
597
+ let droppedLead = null;
598
+ if (planned.dropLead !== void 0) {
599
+ const lead = LEADING_SPACE.exec(text)?.[0] ?? "";
600
+ const leadEnd = lead.length + planned.dropLead.text.length;
601
+ const dropped = text.slice(0, leadEnd + (LABEL_SPACE.exec(text.slice(leadEnd))?.[0].length ?? 0));
602
+ if (planned.dropLead.text.trim() === "" || !text.startsWith(planned.dropLead.text, lead.length) || text.slice(dropped.length).trim() === "") return Result.err(refuse({
603
+ code: "strip-label-mismatch",
604
+ message: `Block ${id} does not start with the lead to drop, or holds nothing behind it.`,
605
+ blockId: id
606
+ }));
607
+ droppedLead = {
608
+ text: dropped,
609
+ shownByTemplateBlockId: planned.dropLead.shownByTemplateBlockId
610
+ };
611
+ }
612
+ const every = paragraphPieces({
613
+ read: block.read,
614
+ context: source,
615
+ origin: "document",
616
+ fields: source.story.state.fields
617
+ });
618
+ const kept = planned.dropPageShapes === true ? every.filter(({ kind, atom }) => !(kind === "object" && atom?.element !== null && atom?.element !== void 0 && isPageShape(atom.element))) : every;
507
619
  const part = partSegments({
508
620
  block,
509
- pieces: paragraphPieces({
510
- read: block.read,
511
- context: source,
512
- origin: "document",
513
- fields: source.story.state.fields
514
- }),
515
- strippedLength: strippedPrefix.length,
621
+ pieces: kept,
622
+ strippedLength: droppedLead === null ? strippedPrefix.length : droppedLead.text.length,
516
623
  strippedBreak: stripLabelBreak === true,
517
624
  references: referencesByBlock.get(id) ?? [],
518
625
  highlights: highlightsByBlock.get(id) ?? []
@@ -542,6 +649,8 @@ const resolvePlan = (source, template, plan) => {
542
649
  resolvedParts.push({
543
650
  block,
544
651
  strippedPrefix,
652
+ droppedPageShapes: every.length - kept.length,
653
+ droppedLead,
545
654
  labelAsText: written?.label ?? null
546
655
  });
547
656
  }
@@ -568,6 +677,7 @@ const resolvePlan = (source, template, plan) => {
568
677
  indent: indent ?? null,
569
678
  tabStops: tabStops ?? null,
570
679
  alignment: alignment ?? null,
680
+ spacing: spacing ?? null,
571
681
  endsSection: endsSection ?? null
572
682
  };
573
683
  for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
@@ -584,7 +694,7 @@ const resolvePlan = (source, template, plan) => {
584
694
  };
585
695
  const resolveTable = (block, item, tableOrdinal) => {
586
696
  const { id } = block.block;
587
- if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.stripLabelBreak !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.keepNext !== void 0 || item.indent !== void 0 || item.tabStops !== void 0 || item.alignment !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
697
+ if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.stripLabelBreak !== void 0 || item.labelAsText !== void 0 || item.dropPageShapes !== void 0 || item.pageBreakBefore !== void 0 || item.keepNext !== void 0 || item.indent !== void 0 || item.tabStops !== void 0 || item.alignment !== void 0 || item.spacing !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
588
698
  if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
589
699
  code: "style-unknown",
590
700
  message: `The template has no table style ${item.styleId}.`,
@@ -607,7 +717,8 @@ const resolvePlan = (source, template, plan) => {
607
717
  parts: [{
608
718
  block: nested,
609
719
  stripLabel: override?.stripLabel,
610
- labelAsText: override?.labelAsText === true
720
+ labelAsText: override?.labelAsText === true,
721
+ dropPageShapes: override?.dropPageShapes === true
611
722
  }],
612
723
  separators: [],
613
724
  styleId: override?.styleId ?? item.cellStyleId,
@@ -617,7 +728,8 @@ const resolvePlan = (source, template, plan) => {
617
728
  keepNext: override?.keepNext === true,
618
729
  indent: override?.indent,
619
730
  tabStops: override?.tabStops,
620
- alignment: override?.alignment
731
+ alignment: override?.alignment,
732
+ spacing: override?.spacing
621
733
  });
622
734
  if (Result.isError(paragraph)) return paragraph;
623
735
  cells.set(nested.element, paragraph.value);
@@ -641,6 +753,8 @@ const resolvePlan = (source, template, plan) => {
641
753
  const keptTemplateIds = /* @__PURE__ */ new Set();
642
754
  const slottedTemplateIds = /* @__PURE__ */ new Set();
643
755
  const pendingNestedSlots = [];
756
+ /** The template paragraphs slots name as showing a dropped lead's field. */
757
+ const leadShowers = [];
644
758
  let ordinal = 0;
645
759
  for (let index = 0; index < plan.body.length; index += 1) {
646
760
  const item = plan.body[index];
@@ -686,7 +800,8 @@ const resolvePlan = (source, template, plan) => {
686
800
  block: block.value,
687
801
  stripLabel: item.stripLabel,
688
802
  stripLabelBreak: item.stripLabelBreak === true,
689
- labelAsText: item.labelAsText === true
803
+ labelAsText: item.labelAsText === true,
804
+ dropPageShapes: item.dropPageShapes === true
690
805
  }];
691
806
  const separators = [];
692
807
  let merge = item.mergeNext;
@@ -703,7 +818,7 @@ const resolvePlan = (source, template, plan) => {
703
818
  message: `Block ${next.blockId} does not have the hash the plan pins.`,
704
819
  blockId: next.blockId
705
820
  }));
706
- if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.keepNext !== void 0 || next.indent !== void 0 || next.tabStops !== void 0 || next.alignment !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
821
+ if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.keepNext !== void 0 || next.indent !== void 0 || next.tabStops !== void 0 || next.alignment !== void 0 || next.spacing !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
707
822
  code: "merge-invalid",
708
823
  message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start, a format or a section end of its own.`,
709
824
  blockId: next.blockId
@@ -713,7 +828,8 @@ const resolvePlan = (source, template, plan) => {
713
828
  block: nextBlock.value,
714
829
  stripLabel: next.stripLabel,
715
830
  stripLabelBreak: next.stripLabelBreak === true,
716
- labelAsText: next.labelAsText === true
831
+ labelAsText: next.labelAsText === true,
832
+ dropPageShapes: next.dropPageShapes === true
717
833
  });
718
834
  merge = next.mergeNext;
719
835
  index += 1;
@@ -730,6 +846,7 @@ const resolvePlan = (source, template, plan) => {
730
846
  indent: item.indent,
731
847
  tabStops: item.tabStops,
732
848
  alignment: item.alignment,
849
+ spacing: item.spacing,
733
850
  endsSection: item.endsSection
734
851
  });
735
852
  if (Result.isError(paragraph)) return paragraph;
@@ -752,16 +869,22 @@ const resolvePlan = (source, template, plan) => {
752
869
  blockId: item.templateBlockId
753
870
  }));
754
871
  slottedTemplateIds.add(item.templateBlockId);
872
+ if (item.dropLead !== void 0 && (typeof item.dropLead.text !== "string" || typeof item.dropLead.shownByTemplateBlockId !== "string")) return invalid(`Slot ${item.templateBlockId} names a lead to drop without its text or the paragraph that shows it.`);
755
873
  const parts = [];
756
- for (const id of item.sourceBlockIds) {
874
+ for (const [position, id] of item.sourceBlockIds.entries()) {
757
875
  const block = sourceTopLevel(id);
758
876
  if (Result.isError(block)) return block;
759
877
  parts.push({
760
878
  block: block.value,
761
879
  stripLabel: void 0,
762
- labelAsText: false
880
+ labelAsText: false,
881
+ ...position === 0 && item.dropLead !== void 0 ? { dropLead: item.dropLead } : {}
763
882
  });
764
883
  }
884
+ if (item.dropLead !== void 0) leadShowers.push({
885
+ templateBlockId: item.dropLead.shownByTemplateBlockId,
886
+ slotId: item.templateBlockId
887
+ });
765
888
  const paragraph = resolveParagraph({
766
889
  parts,
767
890
  separators: parts.slice(1).map(() => "lineBreak"),
@@ -793,12 +916,34 @@ const resolvePlan = (source, template, plan) => {
793
916
  }));
794
917
  nestedSlots.push(slot);
795
918
  }
919
+ const emptied = [];
920
+ for (const id of plan.emptyTemplateBlockIds ?? []) {
921
+ const block = template.story.byId.get(id);
922
+ if (block === void 0 || block.read === null || block.parentId === null || !keptTemplateIds.has(block.topLevelId) || slottedTemplateIds.has(id) || emptied.includes(block)) return Result.err(refuse({
923
+ code: "unknown-block",
924
+ message: `Template block ${id} is no paragraph of a kept template table that the plan may empty once.`,
925
+ blockId: id
926
+ }));
927
+ emptied.push(block);
928
+ }
929
+ for (const { templateBlockId, slotId } of leadShowers) {
930
+ const shower = template.story.byId.get(templateBlockId);
931
+ if (shower === void 0 || shower.read === null || shower.block.text.trim() === "" || !keptTemplateIds.has(shower.topLevelId) || slottedTemplateIds.has(templateBlockId) || emptied.includes(shower)) return Result.err(refuse({
932
+ code: "unknown-block",
933
+ message: `Template block ${templateBlockId} is no kept paragraph with text that could show the field of slot ${slotId}.`,
934
+ blockId: templateBlockId
935
+ }));
936
+ }
796
937
  partTables(items);
797
938
  if ((plan.lastSection !== void 0 || items.some((item) => item.kind === "paragraph" && item.paragraph.endsSection !== null)) && wChild(template.body, "sectPr") === null) return invalid("The template has no last section to build the plan's sections from.");
798
939
  const keptPosition = /* @__PURE__ */ new Map();
799
940
  for (const [position, item] of items.entries()) if (item.kind === "template") keptPosition.set(item.block.block.id, position);
800
941
  const templateOrder = template.story.topLevel.map(({ block }) => block.id);
801
- const slots = [...nestedSlots, ...items.flatMap((item) => item.kind === "slot" ? [item] : [])];
942
+ const slots = [
943
+ ...nestedSlots,
944
+ ...items.flatMap((item) => item.kind === "slot" ? [item] : []),
945
+ ...emptied.map((templateBlock) => ({ templateBlock }))
946
+ ];
802
947
  for (const field of template.story.state.fields) {
803
948
  const lastOrdinal = field.closed ? field.endParagraphOrdinal : Number.POSITIVE_INFINITY;
804
949
  if (lastOrdinal === field.paragraphOrdinal) continue;
@@ -823,6 +968,19 @@ const resolvePlan = (source, template, plan) => {
823
968
  blockId: span.at(0) ?? ""
824
969
  }));
825
970
  }
971
+ const emptiedContents = /* @__PURE__ */ new Map();
972
+ for (const { first, textKept, rest } of freezeKinds.includes("TOC") ? [] : contentsWithEntries(template, keptTemplateIds)) {
973
+ emptiedContents.set(first, textKept);
974
+ const gone = new Set(rest);
975
+ for (let position = items.length - 1; position >= 0; position -= 1) {
976
+ const item = items[position];
977
+ if (item?.kind === "template" && gone.has(item.block)) items.splice(position, 1);
978
+ }
979
+ for (let position = keptTemplateBlocks.length - 1; position >= 0; position -= 1) {
980
+ const block = keptTemplateBlocks[position];
981
+ if (block !== void 0 && gone.has(block)) keptTemplateBlocks.splice(position, 1);
982
+ }
983
+ }
826
984
  const omitted = /* @__PURE__ */ new Map();
827
985
  for (const entry of plan.omit) {
828
986
  const block = sourceTopLevel(entry.blockId);
@@ -902,13 +1060,15 @@ const resolvePlan = (source, template, plan) => {
902
1060
  return Result.ok({
903
1061
  items,
904
1062
  nestedSlots,
1063
+ emptied,
905
1064
  byBlockId,
906
1065
  omitted,
907
1066
  mints: [...mints.values()],
908
1067
  bookmarks,
909
1068
  references: resolvedReferences,
910
1069
  freezeKinds: new Set(freezeKinds),
911
- keptTemplateBlocks
1070
+ keptTemplateBlocks,
1071
+ emptiedContents
912
1072
  });
913
1073
  };
914
- export { hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };
1074
+ export { fieldSeparatorRun, hyperlinkFieldLink, isBlankBlock, isManualLabel, paragraphPieces, piecesContent, resolvePlan, segmentPieces };