@stll/folio-core 0.75.0 → 0.77.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 (143) hide show
  1. package/dist/ai-edits/headless.d.ts +8 -5
  2. package/dist/ai-edits/headless.js +49 -26
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +13 -3
  5. package/dist/ai-edits/read.js +33 -4
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/ai-edits/types.d.ts +9 -4
  8. package/dist/canonical/batchCommentReferences.js +2 -1
  9. package/dist/canonical/canonicalBatchReview.js +5 -8
  10. package/dist/canonical/canonicalComments.js +8 -2
  11. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  12. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  13. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  14. package/dist/canonical/canonicalInlineProjection.js +2 -2
  15. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  16. package/dist/canonical/canonicalPublicOperations.js +214 -107
  17. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  18. package/dist/canonical/canonicalSeedContent.js +28 -15
  19. package/dist/canonical/canonicalSession.d.ts +22 -12
  20. package/dist/canonical/canonicalSession.js +181 -187
  21. package/dist/controller/canonicalClipboard.d.ts +3 -2
  22. package/dist/controller/canonicalClipboard.js +377 -58
  23. package/dist/controller/canonicalComposition.js +67 -14
  24. package/dist/controller/canonicalContentControlValue.js +7 -7
  25. package/dist/controller/canonicalReview.d.ts +21 -0
  26. package/dist/controller/canonicalReview.js +44 -9
  27. package/dist/controller/canonicalStoryEditor.js +2 -0
  28. package/dist/controller/canonicalStructure.d.ts +1 -2
  29. package/dist/controller/canonicalStructure.js +51 -24
  30. package/dist/controller/fontReadiness.js +50 -23
  31. package/dist/controller/hiddenEditorManager.js +7 -20
  32. package/dist/docx/bulletMarkers.d.ts +8 -0
  33. package/dist/docx/bulletMarkers.js +9 -1
  34. package/dist/docx/canonicalSessionInput.js +25 -11
  35. package/dist/docx/ensureParaIds.d.ts +31 -0
  36. package/dist/docx/ensureParaIds.js +57 -32
  37. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  38. package/dist/docx/ensureUniqueControlIds.js +47 -29
  39. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  40. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  41. package/dist/docx/importedIdCollisions.js +29 -4
  42. package/dist/docx/server/templatePlan/apply.js +108 -9
  43. package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
  44. package/dist/docx/server/templatePlan/blocks.js +281 -14
  45. package/dist/docx/server/templatePlan/builders.d.ts +22 -1
  46. package/dist/docx/server/templatePlan/builders.js +37 -3
  47. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  48. package/dist/docx/server/templatePlan/effects.js +188 -0
  49. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  50. package/dist/docx/server/templatePlan/emit.js +152 -8
  51. package/dist/docx/server/templatePlan/inspect.js +21 -1
  52. package/dist/docx/server/templatePlan/labels.js +16 -1
  53. package/dist/docx/server/templatePlan/plan.d.ts +35 -3
  54. package/dist/docx/server/templatePlan/plan.js +197 -20
  55. package/dist/docx/server/templatePlan/planShape.js +58 -22
  56. package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
  57. package/dist/docx/server/templatePlan/revisions.js +681 -0
  58. package/dist/docx/server/templatePlan/story.d.ts +61 -2
  59. package/dist/docx/server/templatePlan/story.js +175 -13
  60. package/dist/docx/server/templatePlan/types.d.ts +313 -1
  61. package/dist/docx/server/templatePlan/verify.js +175 -12
  62. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  63. package/dist/docx/server/templatePlan/xml.js +4 -1
  64. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  65. package/dist/docx/tableGridXml.d.ts +3 -7
  66. package/dist/docx/tableGridXml.js +5 -13
  67. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  68. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  69. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  70. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  71. package/dist/prosemirror/canonicalTableCommands.js +1 -3
  72. package/dist/prosemirror/commands/comments.d.ts +6 -234
  73. package/dist/prosemirror/commands/comments.js +5 -2464
  74. package/dist/prosemirror/commands/index.d.ts +4 -2
  75. package/dist/prosemirror/commands/index.js +4 -2
  76. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  77. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  78. package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
  79. package/dist/prosemirror/conversion/toProseDoc.js +31 -14
  80. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  81. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  82. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  83. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  84. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  85. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  86. package/dist/prosemirror/markupViewNotes.js +24 -27
  87. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  88. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  89. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  90. package/dist/prosemirror/markupViewProjection.js +90 -17
  91. package/dist/prosemirror/paraIds.d.ts +1 -14
  92. package/dist/prosemirror/paraIds.js +1 -14
  93. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  94. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  95. package/dist/prosemirror/projectionReview.d.ts +49 -0
  96. package/dist/prosemirror/projectionReview.js +292 -0
  97. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  98. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  99. package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
  100. package/dist/prosemirror/replacedAnnotations.js +11 -203
  101. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  102. package/dist/prosemirror/revisionCarriers.js +15 -1
  103. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  104. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  105. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  106. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  107. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  108. package/dist/prosemirror/styles/styleResolver.js +4 -1
  109. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  110. package/dist/prosemirror/suggestionQueries.js +320 -0
  111. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  112. package/dist/prosemirror/tableGridMutation.js +1 -78
  113. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  114. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  115. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  116. package/dist/server.d.ts +2 -2
  117. package/dist/types/canonicalCapabilities.d.ts +4 -35
  118. package/dist/types/canonicalCapabilities.js +4 -33
  119. package/package.json +2 -2
  120. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  121. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
  122. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  123. package/dist/internal/revisionResolutionEdits.js +0 -18
  124. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  125. package/dist/internal/revisionResolutionInline.js +0 -302
  126. package/dist/internal/revisionResolutionStep.d.ts +0 -32
  127. package/dist/internal/revisionResolutionStep.js +0 -282
  128. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  129. package/dist/internal/revisionResolutionTracking.js +0 -124
  130. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  131. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  132. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  133. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  134. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  135. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  136. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
  137. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
  138. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  139. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  140. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  141. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  142. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  143. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -1,8 +1,9 @@
1
1
  import { isNumberingReference } from "../../numberingReference.js";
2
2
  import { parseSettings } from "../../settingsParser.js";
3
3
  import { validateDocxConformance } from "../validateDocxConformance.js";
4
- import { analyzeDocument } from "./blocks.js";
4
+ import { analyzeDocument, analyzeKeptForm, analyzeSource, viewOf } from "./blocks.js";
5
5
  import { applyRefCaseFormat, fieldBookmarkOf, keepsShiftReturnSpacing, refCaseFormat } from "./builders.js";
6
+ import { countEffects, findInvisibleEffects } from "./effects.js";
6
7
  import { linkAddress, linkAddressKey, templateCharacterStyles } from "./emit.js";
7
8
  import { emphasisSignature, readDirectEmphasis, signatureHighlight, signatureWithoutHighlight } from "./emphasis.js";
8
9
  import { partFields, readHeaderFooterParts } from "./inspect.js";
@@ -10,8 +11,9 @@ import { styleNumbering } from "./labels.js";
10
11
  import { guarded, readPartText } from "./package.js";
11
12
  import { hyperlinkFieldLink, paragraphPieces, piecesContent, resolvePlan, segmentPieces } from "./plan.js";
12
13
  import { objectFingerprint, objectTargets, readStoryResources, relationshipIdsOf } from "./resources.js";
13
- import { createStoryState, endStory, readParagraph, toggleOf, walkBlocks } from "./story.js";
14
- import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren, wName, walkElements } from "./xml.js";
14
+ import { tableRowRevisions } from "./revisions.js";
15
+ import { createStoryState, endStory, isSelfNumberingField, readParagraph, toggleOf, walkBlocks } from "./story.js";
16
+ import { integerOrNull, isW, rangeOf, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren, wName, walkElements } from "./xml.js";
15
17
  import { Result } from "better-result";
16
18
  // src/docx/server/templatePlan/verify.ts
17
19
  /**
@@ -46,14 +48,32 @@ const emptyContent = () => ({
46
48
  links: [],
47
49
  marks: []
48
50
  });
49
- const appendUnit = (content, { kind, text, signature, link, element, origin }, resources) => {
51
+ /**
52
+ * A kept tracked change as marks of a content: an insertion marks every
53
+ * unit of its text (or its place, for content without text), a deletion its
54
+ * place and what was deleted, a paragraph mark its place; each with its
55
+ * author and date. Two contents
56
+ * that read the same then show the same changes by the same hands.
57
+ */
58
+ const revisionMarks = ({ kind, author, date, deleted, mark, within }, at, length) => {
59
+ const by = `${author}:${date ?? ""}`;
60
+ if (kind === "del") {
61
+ const inside = within === void 0 ? "" : `:in:${within.author}:${within.date ?? ""}`;
62
+ return [`${at}:del:${by}:${deleted ?? ""}${inside}`];
63
+ }
64
+ if (mark === true) return [`${at}:mark:${by}`];
65
+ return Array.from({ length: Math.max(length, 1) }, (_unused, offset) => `${at + offset}:ins:${by}`);
66
+ };
67
+ const appendUnit = (content, { kind, text, signature, link, element, instruction, revision, origin }, resources) => {
50
68
  content.text += text;
51
69
  for (let unit = 0; unit < text.length; unit += 1) {
52
70
  content.signatures.push(signature);
53
71
  content.links.push(link);
54
72
  }
55
73
  const at = content.text.length - text.length;
74
+ if (revision !== null) content.marks.push(...revisionMarks(revision, at, text.length));
56
75
  if (kind === "pageBreak") content.marks.push(`${at}:break:${wAttr(element, "type") ?? "page"}`);
76
+ else if (kind === "selfNumber") content.marks.push(`${at}:number:${instruction ?? ""}`);
57
77
  else if (kind === "object" && element !== null) content.marks.push(`${at}:object:${objectFingerprint(element)}:${objectTargets(element, origin, resources).join(",")}`);
58
78
  };
59
79
  /** A paragraph break inside a note. */
@@ -70,6 +90,8 @@ const expectedContent = (pieces, resources, content = emptyContent()) => {
70
90
  signature: piece.signature,
71
91
  link: linkAddressKey(linkAddress(piece.link, resources.relationships[piece.origin])),
72
92
  element: piece.atom?.element ?? null,
93
+ instruction: piece.atom?.instruction ?? null,
94
+ revision: piece.atom?.revision ?? null,
73
95
  origin: piece.origin
74
96
  }, resources);
75
97
  return content;
@@ -95,6 +117,8 @@ const outputContent = ({ read, origin, resources, styles, content = emptyContent
95
117
  signature: styleId === null || styleId === expectedStyle ? stated : `${stated};rStyle=${styleId}`,
96
118
  link,
97
119
  element: atom.element,
120
+ instruction: atom.instruction ?? null,
121
+ revision: atom.revision ?? null,
98
122
  origin
99
123
  }, resources);
100
124
  }
@@ -198,22 +222,57 @@ const CONFORMANCE_RANK = {
198
222
  invalid: 0
199
223
  };
200
224
  const NUMBER_SWITCH = /\\[nrw]\b/u;
225
+ const tabStopsKey = (tabs) => tabs === null ? null : wChildren(tabs, "tab").map((tab) => `${wAttr(tab, "val") ?? ""}@${String(twipsOrNull(wAttr(tab, "pos")) ?? wAttr(tab, "pos"))}${wAttr(tab, "leader") === null ? "" : `;${wAttr(tab, "leader") ?? ""}`}`).join(",");
226
+ const indentKey = (left, hanging, firstLine) => [
227
+ left,
228
+ hanging,
229
+ firstLine
230
+ ].map((side) => side ?? "").join(":");
231
+ const spacingKey = (before, after) => before === null && after === null ? null : `${before === null ? "" : String(before)}:${after === null ? "" : String(after)}`;
232
+ /** The sides of an indent counted in characters: they override the
233
+ * measured ones, so a paragraph that states one is another paragraph. */
234
+ const CHARACTER_INDENTS = [
235
+ "leftChars",
236
+ "startChars",
237
+ "hangingChars",
238
+ "firstLineChars"
239
+ ];
240
+ const characterIndentKey = (indent) => CHARACTER_INDENTS.flatMap((name) => {
241
+ const value = wAttr(indent, name);
242
+ return value === null ? [] : [`;${name}=${value}`];
243
+ }).join("");
201
244
  const statedProperties = (paragraph) => {
202
245
  const properties = wChild(paragraph, "pPr");
203
246
  const numbering = wChild(properties, "numPr");
247
+ const indent = wChild(properties, "ind");
204
248
  return {
205
249
  styleId: wChildVal(properties, "pStyle"),
206
250
  numId: integerOrNull(wChildVal(numbering, "numId")),
207
251
  ilvl: integerOrNull(wChildVal(numbering, "ilvl")),
208
252
  pageBreakBefore: toggleOf(wChild(properties, "pageBreakBefore")) === true,
253
+ keepNext: toggleOf(wChild(properties, "keepNext")) === true,
254
+ indent: indent === null ? null : `${indentKey(twipsOrNull(wAttr(indent, "left") ?? wAttr(indent, "start")), twipsOrNull(wAttr(indent, "hanging")), twipsOrNull(wAttr(indent, "firstLine")))}${characterIndentKey(indent)}`,
255
+ tabStops: tabStopsKey(wChild(properties, "tabs")),
256
+ alignment: wChildVal(properties, "jc"),
257
+ spacing: spacingKey(twipsOrNull(wAttr(wChild(properties, "spacing"), "before")), twipsOrNull(wAttr(wChild(properties, "spacing"), "after"))),
209
258
  endsSection: wChild(properties, "sectPr") !== null
210
259
  };
211
260
  };
212
- /** Whether a bookmark of `read` holds all of the paragraph's content. */
261
+ /** Whether a kept paragraph states what the template's states. */
262
+ const sameStated = (before, after) => before.styleId === after.styleId && before.pageBreakBefore === after.pageBreakBefore && before.keepNext === after.keepNext && before.indent === after.indent && before.tabStops === after.tabStops && before.alignment === after.alignment && before.spacing === after.spacing && before.endsSection === after.endsSection && before.numId === after.numId && before.ilvl === after.ilvl;
263
+ /**
264
+ * Whether a bookmark of `read` holds all of the paragraph's content. In a
265
+ * reading that keeps tracked changes the paragraph's own content begins
266
+ * behind the last paragraph mark deleted in it (what stands in front is the
267
+ * paragraph the mark ended) and ends in front of a mark somebody inserted.
268
+ */
213
269
  const bookmarkEncloses = (read, name) => {
214
270
  const start = read?.bookmarks.find((bookmark) => bookmark.name === name);
215
271
  const end = start === void 0 ? void 0 : read?.bookmarkEnds.find(({ id }) => id === start.id);
216
- return read !== null && start !== void 0 && end !== void 0 && start.atomIndex === 0 && end.atomIndex === read.atoms.length;
272
+ if (read === null || start === void 0 || end === void 0) return false;
273
+ const own = read.atoms.findLastIndex(({ revision }) => revision?.deleted === "") + 1;
274
+ const marked = read.atoms.at(-1)?.revision?.mark === true ? 1 : 0;
275
+ return start.atomIndex === own && end.atomIndex === read.atoms.length - marked;
217
276
  };
218
277
  const segmentLength = (segment) => piecesContent(segment.kind === "piece" ? [segment.piece] : segment.pieces).text.length;
219
278
  /** The rows and cells of a table, without the ids of what they hold. */
@@ -224,10 +283,20 @@ const tableShape = (block) => JSON.stringify((block.block.cells ?? []).map(({ ro
224
283
  ]));
225
284
  /** Read `output` back and report how it compares with the resolved plan. */
226
285
  const reportTemplatePlanOutput = async ({ source, template, output, plan, resolved, options }) => {
227
- const analyzedOutput = await analyzeDocument(output);
286
+ const keepsRevisions = source.manifest.trackedChangesKept !== void 0;
287
+ const analyzedOutput = keepsRevisions ? await analyzeKeptForm(output) : await analyzeDocument(output);
228
288
  if (Result.isError(analyzedOutput)) return analyzedOutput;
229
289
  const out = analyzedOutput.value;
230
290
  const issues = [];
291
+ const leftUntagged = out.story.state.formattingRevisions + out.story.state.untaggedRevisions + out.footnotes.state.formattingRevisions + out.footnotes.state.untaggedRevisions + out.endnotes.state.formattingRevisions + out.endnotes.state.untaggedRevisions;
292
+ if (keepsRevisions && leftUntagged > 0) issues.push({
293
+ code: "revision-left",
294
+ message: `The output holds ${String(leftUntagged)} tracked change(s) the source's kept changes do not account for.`
295
+ });
296
+ if (source.manifest.trackedChangesResolved !== void 0 && out.manifest.trackedChanges > 0) issues.push({
297
+ code: "revision-left",
298
+ message: `The output holds ${String(out.manifest.trackedChanges)} tracked change(s).`
299
+ });
231
300
  const warnings = [...source.manifest.warnings.map((warning) => `Source: ${warning}`), ...out.story.warnings];
232
301
  const sourceResourcesRead = await readStoryResources(source);
233
302
  if (Result.isError(sourceResourcesRead)) return sourceResourcesRead;
@@ -243,16 +312,26 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
243
312
  for (const item of resolved.items) if (item.kind === "slot") slotBlocks.set(item.paragraph, item.templateBlock);
244
313
  for (const slot of resolved.nestedSlots) slotBlocks.set(slot.paragraph, slot.templateBlock);
245
314
  const slottedTemplateBlocks = new Set(slotBlocks.values());
315
+ const emptiedTemplateBlocks = new Set(resolved.emptied);
316
+ const { emptiedContents } = resolved;
246
317
  const plannedProperties = (paragraph) => {
247
318
  const slot = slotBlocks.get(paragraph);
248
319
  if (slot !== void 0) return statedProperties(slot.element);
249
- const { styleId, numbering, pageBreakBefore } = paragraph;
320
+ const { styleId, numbering, pageBreakBefore, keepNext, alignment } = paragraph;
321
+ const spacing = paragraph.spacing === null ? null : spacingKey(paragraph.spacing.before ?? null, paragraph.spacing.after ?? null);
250
322
  const endsSection = paragraph.endsSection !== null;
323
+ const indent = paragraph.indent === null ? null : indentKey(paragraph.indent.left, paragraph.indent.hanging, paragraph.indent.firstLine);
324
+ const tabStops = paragraph.tabStops === null ? null : paragraph.tabStops.map((stop) => `left@${String(stop)}`).join(",");
251
325
  if (numbering.kind === "direct") return {
252
326
  styleId,
253
327
  numId: numbering.numId,
254
328
  ilvl: numbering.ilvl,
255
329
  pageBreakBefore,
330
+ keepNext,
331
+ indent,
332
+ tabStops,
333
+ alignment,
334
+ spacing,
256
335
  endsSection
257
336
  };
258
337
  return {
@@ -260,6 +339,11 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
260
339
  numId: numbering.kind === "none" && styleNumbering(styleId ?? template.defaultStyleId, template.styles, template.numbering)?.kind === "reference" ? 0 : null,
261
340
  ilvl: null,
262
341
  pageBreakBefore,
342
+ keepNext,
343
+ indent,
344
+ tabStops,
345
+ alignment,
346
+ spacing,
263
347
  endsSection
264
348
  };
265
349
  };
@@ -279,6 +363,11 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
279
363
  message: planned.pageBreakBefore ? `Block ${blockId} does not start the new page the plan gives it.` : `Block ${blockId} starts a new page the plan does not give it.`,
280
364
  blockId
281
365
  });
366
+ if (stated.keepNext !== planned.keepNext || stated.indent !== planned.indent || stated.tabStops !== planned.tabStops || stated.alignment !== planned.alignment || stated.spacing !== planned.spacing) issues.push({
367
+ code: "paragraph-format-mismatch",
368
+ message: `Block ${blockId} does not carry the keep-with-next, the indent, the tab stops, the alignment or the spacing the plan gives it.`,
369
+ blockId
370
+ });
282
371
  if (stated.endsSection !== planned.endsSection) issues.push({
283
372
  code: "section-mismatch",
284
373
  message: planned.endsSection ? `Block ${blockId} does not end the section the plan gives it.` : `Block ${blockId} ends a section the plan does not give it.`,
@@ -305,6 +394,10 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
305
394
  const mapTable = (cells, sourceTable, outputTable) => {
306
395
  const tableId = sourceTable.block.id;
307
396
  tableOutputs.set(tableId, outputTable.block.id);
397
+ if (!sameList(tableRowRevisions(sourceTable.element), tableRowRevisions(outputTable.element))) {
398
+ missing(`Source table ${tableId} does not keep its inserted and deleted rows.`);
399
+ return;
400
+ }
308
401
  const sourceCells = sourceTable.block.cells ?? [];
309
402
  const outputCells = outputTable.block.cells ?? [];
310
403
  if (sourceCells.length !== outputCells.length || sourceCells.some(({ row, col }, index) => outputCells[index]?.row !== row || outputCells[index]?.col !== col)) {
@@ -346,8 +439,11 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
346
439
  const outputParagraph = outputNested[index];
347
440
  if (outputParagraph === void 0 || templateParagraph.read === null || outputParagraph.read === null) return false;
348
441
  if (slottedTemplateBlocks.has(templateParagraph)) return true;
442
+ if (emptiedTemplateBlocks.has(templateParagraph)) return outputParagraph.read.text === "" && outputParagraph.read.inlineObjects === 0;
349
443
  const before = statedProperties(templateParagraph.element);
350
444
  const after = statedProperties(outputParagraph.element);
445
+ const textKept = emptiedContents.get(templateParagraph);
446
+ if (textKept !== void 0) return sameStated(before, after) && outputParagraph.read.text === templateParagraph.read.text.slice(0, textKept);
351
447
  const was = outputContent({
352
448
  read: templateParagraph.read,
353
449
  origin: "document",
@@ -360,7 +456,7 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
360
456
  resources: outputResources,
361
457
  styles: characterStyles
362
458
  });
363
- return before.styleId === after.styleId && before.pageBreakBefore === after.pageBreakBefore && before.endsSection === after.endsSection && before.numId === after.numId && before.ilvl === after.ilvl && sameReading(was, is) && sameList(was.signatures, is.signatures);
459
+ return sameStated(before, after) && sameReading(was, is) && sameList(was.signatures, is.signatures);
364
460
  }))) issues.push({
365
461
  code: "template-mismatch",
366
462
  message: `Template block ${item.block.block.id} does not read as the template has it.`,
@@ -631,6 +727,18 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
631
727
  lvlText: patch.lvlText
632
728
  };
633
729
  for (const [name, value] of Object.entries(planned)) if (value !== void 0 && wChildVal(level, name) !== value) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} does not carry the planned ${name}.`);
730
+ const fonts = wChild(wChild(level, "rPr"), "rFonts");
731
+ if (patch.font !== void 0 && ([
732
+ "ascii",
733
+ "hAnsi",
734
+ "eastAsia",
735
+ "cs"
736
+ ].some((name) => wAttr(fonts, name) !== patch.font) || [
737
+ "asciiTheme",
738
+ "hAnsiTheme",
739
+ "eastAsiaTheme",
740
+ "cstheme"
741
+ ].some((name) => wAttr(fonts, name) !== null))) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} is not set in the planned face.`);
634
742
  const indent = wChild(wChild(level, "pPr"), "ind");
635
743
  for (const [name, value] of Object.entries(patch.indent ?? {})) if (twipsOrNull(wAttr(indent, name)) !== value) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} does not carry the planned ${name} indent.`);
636
744
  for (const [stated, other] of [["hanging", "firstLine"], ["firstLine", "hanging"]]) if (patch.indent?.[stated] !== void 0 && wAttr(indent, other) !== null) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} keeps a ${other} indent beside the planned ${stated} one.`);
@@ -779,7 +887,9 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
779
887
  if (bookmark !== null && !bookmarkNames.has(bookmark)) warnings.push(`A kept ${field.kind} field points at the bookmark ${bookmark}, which the output does not hold; its cached text is stale until fields update.`);
780
888
  }
781
889
  const keptToc = templateFields.filter(({ kind }) => kind === "TOC").length;
782
- if (keptToc > 0) warnings.push(`${keptToc} table of contents field(s) keep the template's cached entries until fields update.`);
890
+ const emptiedToc = Math.min(keptToc, resolved.emptiedContents.size);
891
+ if (emptiedToc > 0) warnings.push(`${emptiedToc} table of contents field(s) show no entries until fields update: the template's cached entries were taken out.`);
892
+ if (keptToc > emptiedToc) warnings.push(`${keptToc - emptiedToc} table of contents field(s) keep the template's cached entries until fields update.`);
783
893
  const keptTemplateIds = new Set(resolved.keptTemplateBlocks.map(({ block }) => block.id));
784
894
  const frozenFields = [];
785
895
  if (resolved.freezeKinds.size > 0) {
@@ -791,6 +901,55 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
791
901
  if (Result.isError(templateHeadersAndFooters)) return templateHeadersAndFooters;
792
902
  for (const part of templateHeadersAndFooters.value) frozenFields.push(...countByKind(part.path, frozenIn(partFields(part))));
793
903
  }
904
+ const effectsOf = (path, xml) => {
905
+ const part = path === null || xml === null ? null : readRawPart(path, xml);
906
+ return part === null ? [] : findInvisibleEffects(part);
907
+ };
908
+ const keptRanges = [...resolved.keptTemplateBlocks.map(({ element }) => element), ...resolved.items.flatMap((item) => item.kind === "slot" ? [item.templateBlock.element] : [])].flatMap((element) => {
909
+ const range = rangeOf(element);
910
+ return range === null ? [] : [range];
911
+ });
912
+ const templateHeaderFooterParts = await readHeaderFooterParts(template);
913
+ if (Result.isError(templateHeaderFooterParts)) return templateHeaderFooterParts;
914
+ const effectParts = [
915
+ {
916
+ part: out.pkg.documentPath,
917
+ before: findInvisibleEffects(template.document).filter(({ range }) => keptRanges.some((kept) => range.start >= kept.start && range.end <= kept.end)),
918
+ after: findInvisibleEffects(out.document)
919
+ },
920
+ {
921
+ part: template.numberingPath,
922
+ before: effectsOf(template.numberingPath, template.numberingXml),
923
+ after: effectsOf(out.numberingPath, out.numberingXml)
924
+ },
925
+ {
926
+ part: template.stylesPath,
927
+ before: effectsOf(template.stylesPath, template.stylesXml),
928
+ after: effectsOf(out.stylesPath, out.stylesXml)
929
+ },
930
+ ...templateHeaderFooterParts.value.map((part) => ({
931
+ part: part.path,
932
+ before: findInvisibleEffects(part),
933
+ after: findInvisibleEffects(outputHeadersAndFooters.value.find(({ path }) => path === part.path) ?? part)
934
+ }))
935
+ ];
936
+ const textEffects = {
937
+ removed: [],
938
+ left: []
939
+ };
940
+ for (const { part, before, after } of effectParts) {
941
+ if (part === null) continue;
942
+ const left = countEffects(part, after);
943
+ textEffects.left.push(...left);
944
+ for (const { effect, count } of countEffects(part, before)) {
945
+ const kept = left.find((entry) => entry.effect === effect)?.count ?? 0;
946
+ if (count > kept) textEffects.removed.push({
947
+ part,
948
+ effect,
949
+ count: count - kept
950
+ });
951
+ }
952
+ }
794
953
  const filler = [];
795
954
  const documentText = out.story.order.flatMap(({ read }) => read === null ? [] : [read.text]).join("\n");
796
955
  for (const text of options?.fillerStrings ?? []) for (const { part, text: haystack } of [{
@@ -894,6 +1053,7 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
894
1053
  text,
895
1054
  emphasis,
896
1055
  ...part === void 0 || part.strippedPrefix === "" ? {} : { strippedPrefix: part.strippedPrefix },
1056
+ ...part === void 0 || part.droppedLead === null ? {} : { droppedLead: part.droppedLead },
897
1057
  ...labelAsText === null ? {} : { labelAsText },
898
1058
  sourceLabel,
899
1059
  outputLabel
@@ -908,7 +1068,7 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
908
1068
  for (const read of placedReads) {
909
1069
  for (const index of read.fieldIndices) {
910
1070
  const field = source.story.state.fields[index];
911
- if (field !== void 0 && hyperlinkFieldLink(field) === null) droppedFields.set(field.kind, (droppedFields.get(field.kind) ?? 0) + 1);
1071
+ if (field !== void 0 && hyperlinkFieldLink(field) === null && !isSelfNumberingField(field.kind)) droppedFields.set(field.kind, (droppedFields.get(field.kind) ?? 0) + 1);
912
1072
  }
913
1073
  let previous = null;
914
1074
  for (const { link } of read.atoms) {
@@ -946,6 +1106,8 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
946
1106
  sourceSha256: source.manifest.sha256,
947
1107
  templateSha256: template.manifest.sha256,
948
1108
  outputSha256: out.manifest.sha256,
1109
+ ...source.manifest.trackedChangesResolved === void 0 ? {} : { trackedChanges: source.manifest.trackedChangesResolved },
1110
+ ...source.manifest.trackedChangesKept === void 0 ? {} : { trackedChangesKept: source.manifest.trackedChangesKept },
949
1111
  blocks,
950
1112
  counts,
951
1113
  footnotes,
@@ -982,6 +1144,7 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
982
1144
  internalHyperlinks,
983
1145
  sectionBreaks
984
1146
  },
1147
+ textEffects,
985
1148
  updateFields,
986
1149
  conformance: {
987
1150
  status: conformance.status,
@@ -993,7 +1156,7 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
993
1156
  });
994
1157
  };
995
1158
  const verifyUnguarded = async ({ source, template, output, plan, options }) => {
996
- const analyzedSource = await analyzeDocument(source);
1159
+ const analyzedSource = await analyzeSource(source, viewOf(plan));
997
1160
  if (Result.isError(analyzedSource)) return analyzedSource;
998
1161
  const analyzedTemplate = await analyzeDocument(template);
999
1162
  if (Result.isError(analyzedTemplate)) return analyzedTemplate;
@@ -25,6 +25,9 @@ export declare const integerOrNull: (value: string | null) => number | null;
25
25
  * universal measure (`1in`, `2.54cm`), which the schema allows in its place.
26
26
  */
27
27
  export declare const twipsOrNull: (value: string | null) => number | null;
28
+ /** A length in half-points: a plain number, or a universal measure such as
29
+ * `12pt`. */
30
+ export declare const halfPointsOrNull: (value: string | null) => number | null;
28
31
  /** The largest of `values`, or `floor` when none is larger. */
29
32
  export declare const maxOf: (values: Iterable<number>, floor: number) => number;
30
33
  /** A relationship attribute (`r:id`, `r:embed`, ...) by local name. */
@@ -32,6 +32,9 @@ const integerOrNull = (value) => {
32
32
  * universal measure (`1in`, `2.54cm`), which the schema allows in its place.
33
33
  */
34
34
  const twipsOrNull = (value) => integerOrNull(value) ?? (value === null ? null : universalMeasureAs(value.trim(), "twips") ?? null);
35
+ /** A length in half-points: a plain number, or a universal measure such as
36
+ * `12pt`. */
37
+ const halfPointsOrNull = (value) => integerOrNull(value) ?? (value === null ? null : universalMeasureAs(value.trim(), "halfPoints") ?? null);
35
38
  /** The largest of `values`, or `floor` when none is larger. */
36
39
  const maxOf = (values, floor) => {
37
40
  let max = floor;
@@ -122,4 +125,4 @@ const walkElements = (root, visit) => {
122
125
  }
123
126
  }
124
127
  };
125
- export { MARKUP_COMPATIBILITY_NAMESPACE, MATH_NAMESPACE, elementChildren, escapeXmlAttribute, escapeXmlText, innerRangeOf, integerOrNull, isW, maxOf, partPrefixes, prefixFor, rangeOf, readRawPart, relationshipAttr, sliceWithSplices, spliceXml, twipsOrNull, wAttr, wChild, wChildVal, wChildren, wName, walkElements };
128
+ export { MARKUP_COMPATIBILITY_NAMESPACE, MATH_NAMESPACE, elementChildren, escapeXmlAttribute, escapeXmlText, halfPointsOrNull, innerRangeOf, integerOrNull, isW, maxOf, partPrefixes, prefixFor, rangeOf, readRawPart, relationshipAttr, sliceWithSplices, spliceXml, twipsOrNull, wAttr, wChild, wChildVal, wChildren, wName, walkElements };
@@ -1,5 +1,5 @@
1
1
  /** The on/off children of `w:settings` a caller may set without re-serializing the part. */
2
- export type SettingsOnOffChild = "evenAndOddHeaders" | "updateFields";
2
+ export type SettingsOnOffChild = "evenAndOddHeaders" | "trackRevisions" | "updateFields";
3
3
  /**
4
4
  * Set (`true`), clear (`false`) or remove (`undefined`) one on/off child of
5
5
  * `w:settings`, at its place in the schema's child order; the rest of the part
@@ -4,12 +4,7 @@
4
4
  * grid differs from it, so a table without one reads back as it was written.
5
5
  */
6
6
  import { document_d_exports } from "../types/document.js";
7
- /**
8
- * The most grid columns a table declares. Far above what any editor lays out,
9
- * it bounds a grid built from a source's skipped-column
10
- * and span counts, which a file can state at any size.
11
- */
12
- export declare const MAX_GRID_COLUMNS = 4096;
7
+ import { MAX_TABLE_GRID_COLUMNS as MAX_GRID_COLUMNS } from "@stll/docx-core/model";
13
8
  /**
14
9
  * Columns the grid has to declare: the widest row's total of skipped columns
15
10
  * and spans, because a grid narrower than a row leaves cells with no column
@@ -27,4 +22,5 @@ export declare const gridColumnCount: (table: document_d_exports.Table) => numbe
27
22
  * accepts the reviewer's change without saying so. The schema declares it
28
23
  * after every `w:gridCol`, so it is appended.
29
24
  */
30
- export declare const modelTableGrid: (table: document_d_exports.Table) => string;
25
+ export declare const modelTableGrid: (table: document_d_exports.Table) => string;
26
+ export { MAX_GRID_COLUMNS };
@@ -1,25 +1,17 @@
1
1
  import { intAttr } from "./serializer/xmlUtils.js";
2
+ import { MAX_TABLE_GRID_COLUMNS as MAX_GRID_COLUMNS, gridColumnsInRows } from "@stll/docx-core/model";
2
3
  // src/docx/tableGridXml.ts
3
4
  /**
4
- * The most grid columns a table declares. Far above what any editor lays out,
5
- * it bounds a grid built from a source's skipped-column
6
- * and span counts, which a file can state at any size.
5
+ * The `w:tblGrid` a table's model writes when no capture stands in for it.
6
+ * The serializer writes it; the parser keeps a capture only when the source
7
+ * grid differs from it, so a table without one reads back as it was written.
7
8
  */
8
- const MAX_GRID_COLUMNS = 4096;
9
9
  /**
10
10
  * Columns the grid has to declare: the widest row's total of skipped columns
11
11
  * and spans, because a grid narrower than a row leaves cells with no column
12
12
  * to sit in. At most {@link MAX_GRID_COLUMNS}.
13
13
  */
14
- const gridColumnCount = (table) => {
15
- let widest = 0;
16
- for (const row of table.rows) {
17
- let columns = (row.formatting?.gridBefore ?? 0) + (row.formatting?.gridAfter ?? 0);
18
- for (const cell of row.cells) columns += cell.formatting?.gridSpan ?? 1;
19
- widest = Math.max(widest, columns);
20
- }
21
- return Math.min(widest, MAX_GRID_COLUMNS);
22
- };
14
+ const gridColumnCount = (table) => Math.min(gridColumnsInRows(table.rows), MAX_GRID_COLUMNS);
23
15
  /**
24
16
  * Serialize `w:tblGridChange`: the grid a reviewer replaced, from the change's
25
17
  * own record rather than from the bytes it arrived as.
@@ -1,7 +1,9 @@
1
+ import { expectNoteMarkerAttrs } from "../../internal/noteMarkerAttrs.js";
1
2
  import { measureParagraph } from "../../layout-engine/measure/measureParagraph.js";
2
3
  import { getExactTableRowBottomMargins } from "../../layout-engine/measure/tableCellGrid.js";
3
4
  import { layoutTextBoxContent } from "../../layout-engine/measure/textBoxParagraphLayout.js";
4
5
  import { DEFAULT_TEXTBOX_MARGINS, FOOTNOTE_ENTRY_MARGIN_BOTTOM, FOOTNOTE_FALLBACK_LINE_HEIGHT, FOOTNOTE_SEPARATOR_HEIGHT, isFloatingImageRun, resolveTableWidthPx } from "../../layout-engine/types.js";
6
+ import { markupViewSources } from "../../prosemirror/conversion/markupViewSource.js";
5
7
  import { footnoteToProseDoc } from "../../prosemirror/conversion/toProseDoc.js";
6
8
  import { projectStoryMarkupView } from "../../prosemirror/markupViewProjection.js";
7
9
  import { remapMarkupViewBlocks } from "./markupViewFlow.js";
@@ -229,14 +231,38 @@ function convertNoteStoryToFlowBlocks(content, options, referenceMarkText) {
229
231
  if (options.justificationCompatibility) flowOptions.justificationCompatibility = options.justificationCompatibility;
230
232
  if (options.tableIndentCompatibility) flowOptions.tableIndentCompatibility = options.tableIndentCompatibility;
231
233
  if (options.automaticHyphenation) flowOptions.automaticHyphenation = options.automaticHyphenation;
234
+ const markupView = options.markupView ?? "all-markup";
235
+ const kind = noteReferenceKind(pmDoc);
236
+ if (markupView !== "all-markup" && kind !== void 0) {
237
+ const id = 0;
238
+ markupViewSources.set(pmDoc, {
239
+ document: { package: {
240
+ document: { content: [] },
241
+ ...kind === "footnote" ? { footnotes: [{
242
+ type: kind,
243
+ id,
244
+ content
245
+ }] } : { endnotes: [{
246
+ type: kind,
247
+ id,
248
+ content
249
+ }] }
250
+ } },
251
+ story: {
252
+ kind,
253
+ id
254
+ },
255
+ options: proseOptions
256
+ });
257
+ }
232
258
  const projection = projectStoryMarkupView({
233
259
  doc: pmDoc,
234
- markupView: options.markupView ?? "all-markup",
260
+ markupView,
235
261
  styles: options.styles,
236
262
  numbering: options.numbering
237
263
  });
238
264
  const viewDoc = projection.type === "resolved" ? projection.doc : pmDoc;
239
- const hasReferenceMark = containsNoteReferenceMark(viewDoc);
265
+ const hasReferenceMark = (viewDoc === pmDoc ? kind : noteReferenceKind(viewDoc)) !== void 0;
240
266
  if (hasReferenceMark && referenceMarkText !== void 0) flowOptions.noteReferenceMarkText = referenceMarkText;
241
267
  const converted = toFlowBlocks(viewDoc, flowOptions);
242
268
  return {
@@ -244,14 +270,14 @@ function convertNoteStoryToFlowBlocks(content, options, referenceMarkText) {
244
270
  hasReferenceMark
245
271
  };
246
272
  }
247
- function containsNoteReferenceMark(doc) {
248
- let found = false;
273
+ function noteReferenceKind(doc) {
274
+ let kind;
249
275
  doc.descendants((node) => {
250
- if (found) return false;
251
- if (node.type.name === "noteMarker") found = true;
252
- return !found;
276
+ if (kind !== void 0) return false;
277
+ if (node.type.name === "noteMarker") kind = expectNoteMarkerAttrs(node).kind;
278
+ return kind === void 0;
253
279
  });
254
- return found;
280
+ return kind;
255
281
  }
256
282
  /** Restore an authored footnote line that the body-only terminal-table policy collapsed. */
257
283
  function preserveAuthoredFootnoteTerminalParagraph(blocks) {
@@ -0,0 +1,20 @@
1
+ import { EditorState } from "prosemirror-state";
2
+ import { Node } from "prosemirror-model";
3
+ import { RevisionDecision } from "@stll/docx-core/ops";
4
+ import { StepMap } from "prosemirror-transform";
5
+ type CanonicalMarkupDocumentOptions = {
6
+ state: EditorState;
7
+ decision: RevisionDecision;
8
+ };
9
+ type CanonicalMarkupDocument = {
10
+ doc: Node;
11
+ partial: boolean;
12
+ positionMap?: StepMap;
13
+ changeBarRanges?: readonly {
14
+ from: number;
15
+ to: number;
16
+ }[];
17
+ };
18
+ /** Resolve a copy of the authored model and project the selected review view. */
19
+ export declare const canonicalMarkupDocument: ({ state, decision }: CanonicalMarkupDocumentOptions) => CanonicalMarkupDocument;
20
+ export {};
@@ -0,0 +1,73 @@
1
+ import { writableCopy } from "../types/documentModel.js";
2
+ import { proseDocToBlocks } from "./conversion/fromProseDoc.js";
3
+ import { markupViewSources, markupViewStateSources } from "./conversion/markupViewSource.js";
4
+ import { storyConversionOptions } from "./conversion/storyConversionOptions.js";
5
+ import { footnoteToProseDoc, headerFooterToProseDoc, toProseDoc } from "./conversion/toProseDoc.js";
6
+ import { projectDetachedText, projectIndependentMarkup } from "./independentMarkupProjection.js";
7
+ import { getStatedDocumentNumbering } from "./plugins/documentNumbering.js";
8
+ import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
9
+ import { styleResolverSource } from "./styles/styleResolver.js";
10
+ import { OP_STORIES, findStoryBody, resolvedMarkupDocumentView, sameStory } from "@stll/docx-core/ops";
11
+ // src/prosemirror/canonicalMarkupDocument.ts
12
+ const detachedModel = (state) => {
13
+ const numbering = getStatedDocumentNumbering(state);
14
+ const resolver = getDocumentStyleResolver(state);
15
+ const definitions = resolver === null ? void 0 : styleResolverSource(resolver);
16
+ const styles = definitions === void 0 ? void 0 : writableCopy(definitions);
17
+ return { package: {
18
+ document: { content: proseDocToBlocks(state.doc, void 0, styles) },
19
+ ...numbering === null ? {} : { numbering },
20
+ ...styles === void 0 ? {} : { styles }
21
+ } };
22
+ };
23
+ /** Resolve a copy of the authored model and project the selected review view. */
24
+ const canonicalMarkupDocument = ({ state, decision }) => {
25
+ const converted = markupViewStateSources.get(state) ?? markupViewSources.get(state.doc);
26
+ const authoritative = converted?.document;
27
+ if (authoritative === void 0) {
28
+ const detached = projectDetachedText(state.doc, decision);
29
+ if (detached !== void 0) return {
30
+ ...detached,
31
+ partial: false
32
+ };
33
+ }
34
+ const source = authoritative ?? detachedModel(state);
35
+ const resolved = resolvedMarkupDocumentView(source, decision);
36
+ const story = converted?.story ?? OP_STORIES.MAIN;
37
+ const partial = resolved.unresolved.some((unresolved) => sameStory(unresolved, story));
38
+ if (resolved.document === source) return {
39
+ doc: state.doc,
40
+ partial
41
+ };
42
+ if (story === OP_STORIES.MAIN) {
43
+ const projected = resolved.independentInline === void 0 ? void 0 : projectIndependentMarkup({
44
+ doc: state.doc,
45
+ changes: resolved.independentInline
46
+ });
47
+ if (projected !== void 0) return {
48
+ ...projected,
49
+ partial
50
+ };
51
+ const projectedDoc = toProseDoc(resolved.document, converted?.options);
52
+ return {
53
+ doc: authoritative === void 0 ? state.doc.type.create(state.doc.attrs, projectedDoc.content) : projectedDoc,
54
+ partial
55
+ };
56
+ }
57
+ const body = findStoryBody(resolved.document, story);
58
+ if (body === void 0) return {
59
+ doc: state.doc,
60
+ partial: true
61
+ };
62
+ const { styles: storyStyles, theme, numbering: storyNumbering } = resolved.document.package;
63
+ const options = converted?.options ?? storyConversionOptions({
64
+ styles: storyStyles,
65
+ theme,
66
+ numbering: storyNumbering
67
+ });
68
+ return {
69
+ doc: story.kind === "header" || story.kind === "footer" ? headerFooterToProseDoc(body.content, options) : footnoteToProseDoc(body.content, options),
70
+ partial
71
+ };
72
+ };
73
+ export { canonicalMarkupDocument };
@@ -19,7 +19,7 @@ export declare const withCanonicalTableAttributeCommand: (command: Command) => C
19
19
  * command that would change the document has no such description.
20
20
  */
21
21
  export declare const withCanonicalSelectionCommand: (command: Command) => Command;
22
- /** A paragraph of the table's own, outside the given columns, that addresses it. */
22
+ /** A paragraph in a cell with a slot outside the columns being removed. */
23
23
  export declare const tableAnchor: (rect: TableRect, avoid?: {
24
24
  left: number;
25
25
  right: number;
@@ -154,7 +154,7 @@ const withCanonicalSelectionCommand = (command) => withCanonicalCommand(command,
154
154
  }) || transaction === void 0 || transaction.docChanged) return void 0;
155
155
  return [{ type: "selection" }];
156
156
  });
157
- /** A paragraph of the table's own, outside the given columns, that addresses it. */
157
+ /** A paragraph in a cell with a slot outside the columns being removed. */
158
158
  const tableAnchor = (rect, avoid = {
159
159
  left: 0,
160
160
  right: 0
@@ -166,8 +166,6 @@ const tableAnchor = (rect, avoid = {
166
166
  if (offset === void 0) continue;
167
167
  const cell = table.nodeAt(offset);
168
168
  if (cell === null || cell.attrs["_omittedGridSlot"] != null) continue;
169
- const cellRect = map.findCell(offset);
170
- if (cellRect.left < avoid.right && cellRect.right > avoid.left) continue;
171
169
  const at = firstParagraphPosition(cell, tableStart + offset);
172
170
  if (at !== void 0) return at;
173
171
  }