@stll/folio-core 0.72.0 → 0.74.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 (244) hide show
  1. package/README.md +12 -6
  2. package/dist/ai-edits/applyTypes.d.ts +85 -0
  3. package/dist/ai-edits/applyTypes.js +24 -0
  4. package/dist/ai-edits/clean-text.d.ts +7 -1
  5. package/dist/ai-edits/clean-text.js +23 -2
  6. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  7. package/dist/ai-edits/headless.d.ts +29 -147
  8. package/dist/ai-edits/headless.js +215 -1639
  9. package/dist/ai-edits/index.d.ts +3 -3
  10. package/dist/ai-edits/index.js +2 -3
  11. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  12. package/dist/ai-edits/pending-suggestions.js +183 -90
  13. package/dist/ai-edits/pendingJoin.js +6 -1
  14. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  15. package/dist/ai-edits/snapshot.js +9 -4
  16. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  17. package/dist/ai-edits/table-cell-mutations.js +2 -2
  18. package/dist/ai-edits/table-geometry.d.ts +1 -1
  19. package/dist/ai-edits/table-geometry.js +1 -1
  20. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  21. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  22. package/dist/ai-edits/tableNodes.d.ts +38 -0
  23. package/dist/ai-edits/tableNodes.js +86 -0
  24. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  25. package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
  26. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  27. package/dist/canonical/batchCommentReferences.js +1 -0
  28. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  29. package/dist/canonical/canonicalInlineGaps.js +118 -0
  30. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  31. package/dist/canonical/canonicalInlineProjection.js +5 -27
  32. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  33. package/dist/canonical/canonicalPublicOperations.js +282 -75
  34. package/dist/canonical/canonicalSelection.js +1 -1
  35. package/dist/canonical/canonicalSession.d.ts +9 -1
  36. package/dist/canonical/canonicalSession.js +106 -33
  37. package/dist/compare/compare.d.ts +1 -1
  38. package/dist/compare/inline-atoms-model.d.ts +1 -1
  39. package/dist/compare/inline-atoms.d.ts +2 -2
  40. package/dist/compare/inline-provenance-model.d.ts +1 -1
  41. package/dist/compare/inline-provenance.d.ts +2 -2
  42. package/dist/compat/eigenpal.d.ts +3 -3
  43. package/dist/compat/eigenpal.js +2 -3
  44. package/dist/controller/autocompleteSuggestion.js +1 -1
  45. package/dist/controller/canonicalClipboard.d.ts +13 -3
  46. package/dist/controller/canonicalClipboard.js +186 -50
  47. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  48. package/dist/controller/canonicalClipboardResources.js +22 -2
  49. package/dist/controller/canonicalComposition.js +1 -1
  50. package/dist/controller/canonicalInput.js +1 -1
  51. package/dist/controller/canonicalPresence.js +1 -1
  52. package/dist/controller/canonicalReview.d.ts +1 -1
  53. package/dist/controller/canonicalReview.js +1 -1
  54. package/dist/controller/canonicalRoomAuthority.js +1 -1
  55. package/dist/controller/canonicalRoomWire.js +1 -1
  56. package/dist/controller/canonicalStructure.js +1 -1
  57. package/dist/controller/canonicalTabRoom.js +1 -1
  58. package/dist/controller/canonicalWatermark.d.ts +10 -0
  59. package/dist/controller/canonicalWatermark.js +37 -0
  60. package/dist/controller/canonicalYjsRoom.js +1 -1
  61. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  62. package/dist/controller/hiddenEditorApi.js +2 -17
  63. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  64. package/dist/controller/hiddenEditorManager.js +79 -23
  65. package/dist/document-operations.d.ts +1 -14
  66. package/dist/document-operations.js +1 -278
  67. package/dist/docx/canonicalSave.d.ts +1 -1
  68. package/dist/docx/canonicalSave.js +1 -1
  69. package/dist/docx/canonicalSessionInput.js +1 -1
  70. package/dist/docx/containerChildren.js +1 -1
  71. package/dist/docx/createDocx.d.ts +4 -0
  72. package/dist/docx/createDocx.js +6 -0
  73. package/dist/docx/paragraphParser.js +2 -2
  74. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  75. package/dist/docx/parser.js +1 -1
  76. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  77. package/dist/docx/reviewResolutionProvenance.js +31 -8
  78. package/dist/docx/revisionIdNormalization.js +30 -7
  79. package/dist/docx/rezip.d.ts +1 -1
  80. package/dist/docx/rezip.js +1 -1
  81. package/dist/docx/serializer/tableSerializer.js +4 -36
  82. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  83. package/dist/docx/server/templatePlan/apply.js +658 -0
  84. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  85. package/dist/docx/server/templatePlan/blocks.js +355 -0
  86. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  87. package/dist/docx/server/templatePlan/builders.js +237 -0
  88. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  89. package/dist/docx/server/templatePlan/emit.js +466 -0
  90. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  91. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  92. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  93. package/dist/docx/server/templatePlan/inspect.js +230 -0
  94. package/dist/docx/server/templatePlan/labels.d.ts +45 -0
  95. package/dist/docx/server/templatePlan/labels.js +155 -0
  96. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  97. package/dist/docx/server/templatePlan/package.js +99 -0
  98. package/dist/docx/server/templatePlan/plan.d.ts +145 -0
  99. package/dist/docx/server/templatePlan/plan.js +875 -0
  100. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  101. package/dist/docx/server/templatePlan/planShape.js +180 -0
  102. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  103. package/dist/docx/server/templatePlan/resources.js +136 -0
  104. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  105. package/dist/docx/server/templatePlan/story.js +440 -0
  106. package/dist/docx/server/templatePlan/types.d.ts +442 -0
  107. package/dist/docx/server/templatePlan/types.js +29 -0
  108. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  109. package/dist/docx/server/templatePlan/verify.js +976 -0
  110. package/dist/docx/server/templatePlan/xml.d.ts +74 -0
  111. package/dist/docx/server/templatePlan/xml.js +125 -0
  112. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  113. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  114. package/dist/docx/structuralXmlPatch.js +9 -1
  115. package/dist/docx/tableGridXml.d.ts +30 -0
  116. package/dist/docx/tableGridXml.js +54 -0
  117. package/dist/docx/tableParser.js +7 -0
  118. package/dist/i18n/loadMessages.d.ts +5 -0
  119. package/dist/i18n/loadMessages.js +46 -0
  120. package/dist/i18n/locales.d.ts +3 -0
  121. package/dist/i18n/locales.js +17 -0
  122. package/dist/i18n/messages.d.ts +3 -2
  123. package/dist/i18n/messages.js +4 -16
  124. package/dist/index.d.ts +3 -3
  125. package/dist/index.js +2 -3
  126. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  127. package/dist/internal/clipboardTransformPlugin.js +13 -0
  128. package/dist/internal/extensionRuntime.d.ts +7 -0
  129. package/dist/internal/extensionRuntime.js +28 -0
  130. package/dist/internal/starterKitExtensions.d.ts +20 -0
  131. package/dist/internal/starterKitExtensions.js +123 -0
  132. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  133. package/dist/managers/ContextMenuManager.js +2 -1
  134. package/dist/managers/editorShortcuts.d.ts +1 -1
  135. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  136. package/dist/prosemirror/attrs/index.js +1 -1
  137. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  138. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  139. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  140. package/dist/prosemirror/canonicalTableCommands.js +3 -3
  141. package/dist/prosemirror/commands/comments.js +4 -4
  142. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  143. package/dist/prosemirror/commands/contentControls.js +1 -1
  144. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  145. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  146. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  147. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  148. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  149. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  150. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  151. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  152. package/dist/prosemirror/commentRecords.d.ts +1 -1
  153. package/dist/prosemirror/commentRecords.js +2 -2
  154. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  155. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  156. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  157. package/dist/prosemirror/conversion/index.d.ts +2 -2
  158. package/dist/prosemirror/conversion/index.js +2 -2
  159. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  160. package/dist/prosemirror/documentStructureCounts.js +76 -0
  161. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  162. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  163. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  164. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  165. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  166. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  167. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  168. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  169. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  170. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  171. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  172. package/dist/prosemirror/extensions/index.d.ts +2 -1
  173. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  174. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  175. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  176. package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
  177. package/dist/prosemirror/extensions/types.d.ts +1 -1
  178. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  179. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  180. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  181. package/dist/prosemirror/index.d.ts +3 -3
  182. package/dist/prosemirror/index.js +3 -3
  183. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  184. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  185. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  186. package/dist/prosemirror/listNumbering.d.ts +1 -1
  187. package/dist/prosemirror/listNumbering.js +1 -1
  188. package/dist/prosemirror/lockedControls.d.ts +1 -1
  189. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  190. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  191. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  192. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  193. package/dist/prosemirror/noteReferenceReview.js +2 -243
  194. package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
  195. package/dist/prosemirror/paraIds.js +152 -0
  196. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  197. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  198. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  199. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  200. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  201. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  202. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  203. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  204. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  205. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  206. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  207. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  208. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  209. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  210. package/dist/prosemirror/replacedAnnotations.js +17 -2
  211. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  212. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  213. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  214. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  215. package/dist/prosemirror/selectionBounds.js +22 -0
  216. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  217. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  218. package/dist/prosemirror/suggestionCommands.js +31 -0
  219. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  220. package/dist/prosemirror/tableCellPaste.js +1 -1
  221. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  222. package/dist/prosemirror/tableRunIn.js +1 -1
  223. package/dist/prosemirror/textInput.d.ts +1 -1
  224. package/dist/prosemirror/textInput.js +1 -1
  225. package/dist/server.d.ts +7 -2
  226. package/dist/server.js +6 -1
  227. package/dist/types/canonicalCapabilities.d.ts +13 -92
  228. package/dist/types/canonicalCapabilities.js +11 -85
  229. package/package.json +4 -4
  230. package/dist/ai-edits/apply.d.ts +0 -202
  231. package/dist/ai-edits/apply.js +0 -6759
  232. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  233. package/dist/ai-edits/note-story-inventory.js +0 -10
  234. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  235. package/dist/ai-edits/revisionStretches.js +0 -147
  236. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
  237. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
  238. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
  239. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
  240. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
  241. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  242. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  243. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  244. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -13,11 +13,11 @@ import { readModel } from "../types/documentModel.js";
13
13
  import { bytesToDataUrl } from "../utils/base64.js";
14
14
  import { base64ToBytes } from "../utils/textEncoding.js";
15
15
  import { flattenClipboardStyleReferences, importClipboardStyles } from "./canonicalClipboardResources.js";
16
- import { Result } from "better-result";
16
+ import { Result, panic } from "better-result";
17
17
  import { NUMBER_FORMATS, paragraphNumberingReference, relationshipIdOf } from "@stll/docx-core/model";
18
- import { Fragment, Slice } from "prosemirror-model";
19
- import { CellSelection } from "prosemirror-tables";
20
18
  import { packageResourcesOpOf } from "@stll/docx-core/ops";
19
+ import { CellSelection } from "prosemirror-tables";
20
+ import { Fragment, Slice } from "prosemirror-model";
21
21
  // src/controller/canonicalClipboard.ts
22
22
  const refuse = (message) => Result.err(new CanonicalSessionError({
23
23
  ground: { gap: CANONICAL_GAP.dispatch },
@@ -42,6 +42,61 @@ const unplacedBlockGround = (slice) => {
42
42
  });
43
43
  return { gap: table ? CANONICAL_GAP.trackedTableStructure : CANONICAL_GAP.storyContentProjection };
44
44
  };
45
+ /**
46
+ * A pasted block's paragraphs in document order, a table's cell paragraphs
47
+ * among them, each with the place it fills; undefined when a cell holds a
48
+ * block other than a paragraph or a table.
49
+ */
50
+ const clipboardParagraphs = (block, replace = () => {}) => {
51
+ if (block.type === "paragraph") return [{
52
+ paragraph: block,
53
+ replace
54
+ }];
55
+ const places = [];
56
+ for (const row of block.rows) for (const cell of row.cells) for (const [index, inner] of cell.content.entries()) {
57
+ if (inner.type !== "paragraph" && inner.type !== "table") return void 0;
58
+ const found = clipboardParagraphs(inner, (next) => {
59
+ cell.content[index] = next;
60
+ });
61
+ if (found === void 0) return void 0;
62
+ places.push(...found);
63
+ }
64
+ return places;
65
+ };
66
+ /**
67
+ * A table's verbatim captures describe the markup it was read from; a pasted
68
+ * copy is new content the serializer writes from its model.
69
+ */
70
+ /** Every table among the blocks, those nested in cells included. */
71
+ const clipboardTables = (blocks) => blocks.flatMap((block) => block.type === "table" ? [block, ...clipboardTables(block.rows.flatMap((row) => row.cells.flatMap((cell) => cell.content.filter((inner) => inner.type === "paragraph" || inner.type === "table"))))] : []);
72
+ const withoutTableCaptures = (table) => {
73
+ if (table.formatting !== void 0) {
74
+ delete table.formatting.sourceXml;
75
+ delete table.formatting.gridSourceXml;
76
+ }
77
+ for (const row of table.rows) {
78
+ if (row.formatting !== void 0) delete row.formatting.sourceXml;
79
+ for (const cell of row.cells) {
80
+ if (cell.formatting !== void 0) delete cell.formatting.sourceXml;
81
+ for (const inner of cell.content) if (inner.type === "table") withoutTableCaptures(inner);
82
+ }
83
+ }
84
+ };
85
+ /** A pasted block's own copy, each paragraph keeping its indentation provenance. */
86
+ const cloneClipboardBlock = (block) => {
87
+ const clone = structuredClone(block);
88
+ if (clone.type === "table") withoutTableCaptures(clone);
89
+ const sources = clipboardParagraphs(block) ?? [];
90
+ const targets = clipboardParagraphs(clone) ?? [];
91
+ for (const [index, { paragraph: target }] of targets.entries()) {
92
+ const source = sources[index]?.paragraph;
93
+ if (source !== void 0) copyParagraphIndentationProjection({
94
+ target,
95
+ source
96
+ });
97
+ }
98
+ return clone;
99
+ };
45
100
  const IMAGE_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
46
101
  const HYPERLINK_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
47
102
  const MAX_CLIPBOARD_IMAGE_BYTES = 16777216;
@@ -196,21 +251,36 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
196
251
  numIds: nums
197
252
  });
198
253
  };
199
- /** Imported comments and notes require copying their source story parts. */
200
- const canonicalClipboardStoryPartRefusal = (paragraph) => {
201
- let requiresStory = false;
202
- visitInlineContentSlots(paragraph, ({ item }) => {
203
- if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") requiresStory = true;
204
- });
205
- visitParagraphRuns(paragraph, (run) => {
206
- if (run.content.some((item) => item.type === "footnoteRef" || item.type === "endnoteRef")) requiresStory = true;
207
- });
208
- if (!requiresStory) return void 0;
209
- return new CanonicalSessionError({
254
+ /**
255
+ * The notes and comments the clipboard's references and markers name, read
256
+ * from the document they were copied from; the paste copies each under a
257
+ * fresh id. Without that document the ids could name the destination's own
258
+ * notes and comments, so the paste refuses.
259
+ */
260
+ const clipboardAnnotations = ({ paragraphs, source }) => {
261
+ const comments = /* @__PURE__ */ new Set();
262
+ const notes = /* @__PURE__ */ new Set();
263
+ for (const paragraph of paragraphs) {
264
+ visitInlineContentSlots(paragraph, ({ item }) => {
265
+ if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") comments.add(item.id);
266
+ });
267
+ visitParagraphRuns(paragraph, (run) => {
268
+ for (const item of run.content) if (item.type === "footnoteRef" || item.type === "endnoteRef") notes.add(`${item.type === "footnoteRef" ? "footnote" : "endnote"}:${String(item.id)}`);
269
+ });
270
+ }
271
+ if (comments.size === 0 && notes.size === 0) return Result.ok(void 0);
272
+ const refusal = (message) => Result.err(new CanonicalSessionError({
210
273
  ground: { gap: CANONICAL_GAP.storyContentProjection },
211
274
  reason: "refused",
212
- message: "Clipboard comments and note references require importing their source story parts."
213
- });
275
+ message
276
+ }));
277
+ if (source === void 0) return refusal("Clipboard comments and note references require the document they were copied from.");
278
+ const annotations = {
279
+ notes: [...source.package.footnotes ?? [], ...source.package.endnotes ?? []].filter(({ type, id }) => notes.has(`${type}:${String(id)}`)),
280
+ comments: (source.package.document.comments ?? []).filter(({ id }) => comments.has(id))
281
+ };
282
+ if (annotations.notes.length !== notes.size || annotations.comments.length !== comments.size) return refusal("A clipboard comment or note reference names none in the document it was copied from.");
283
+ return Result.ok(annotations);
214
284
  };
215
285
  const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
216
286
  if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
@@ -222,13 +292,14 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
222
292
  if (slice.openStart > 1 || slice.openEnd > 1) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and nested block containers require canonical table editing.");
223
293
  const paragraphType = state.schema.nodes["paragraph"];
224
294
  if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.");
295
+ const tableType = state.schema.nodes["table"];
225
296
  let inline = true;
226
- let paragraphsOnly = true;
297
+ let blocksOnly = true;
227
298
  slice.content.forEach((node) => {
228
299
  inline &&= node.isInline;
229
- paragraphsOnly &&= node.type === paragraphType;
300
+ blocksOnly &&= node.type === paragraphType || node.type === tableType;
230
301
  });
231
- if (!inline && !paragraphsOnly) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and embedded blocks require canonical table editing.");
302
+ if (!inline && !blocksOnly) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and embedded blocks require canonical table editing.");
232
303
  const importedSlice = inline ? new Slice(Fragment.from(paragraphType.create(null, slice.content)), 1, 1) : slice;
233
304
  const converted = Result.try({
234
305
  try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
@@ -239,17 +310,20 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
239
310
  })
240
311
  });
241
312
  if (converted.isErr()) return converted;
242
- const paragraphs = [];
313
+ const blocks = [];
243
314
  for (const block of converted.value) {
244
- if (block.type !== "paragraph") return refuseUnder(unplacedBlockGround(slice), "The clipboard contains an unsupported block.");
245
- const paragraph = structuredClone(block);
246
- copyParagraphIndentationProjection({
247
- target: paragraph,
248
- source: block
249
- });
250
- paragraphs.push(paragraph);
315
+ if (block.type !== "paragraph" && block.type !== "table" || clipboardParagraphs(block) === void 0) return refuseUnder(unplacedBlockGround(slice), "The clipboard contains an unsupported block.");
316
+ blocks.push(cloneClipboardBlock(block));
317
+ }
318
+ const places = blocks.flatMap((block, index) => clipboardParagraphs(block, (next) => {
319
+ blocks[index] = next;
320
+ }) ?? []);
321
+ const paragraphs = places.map(({ paragraph }) => paragraph);
322
+ const tables = clipboardTables(blocks);
323
+ if (moveTarget === void 0 && (plain || sourceDocument === void 0)) {
324
+ flattenClipboardStyleReferences(paragraphs);
325
+ for (const table of tables) delete table.formatting?.styleId;
251
326
  }
252
- if (moveTarget === void 0 && (plain || sourceDocument === void 0)) flattenClipboardStyleReferences(paragraphs);
253
327
  const overCells = state.selection instanceof CellSelection && pasteTarget === void 0 && moveSource === void 0 && moveTarget === void 0;
254
328
  if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.");
255
329
  const selectionRange = overCells ? {
@@ -260,6 +334,39 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
260
334
  if (from.isErr()) return from;
261
335
  const to = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
262
336
  if (to.isErr()) return to;
337
+ const named = moveTarget === void 0 ? clipboardAnnotations({
338
+ paragraphs,
339
+ source: sourceDocument
340
+ }) : Result.ok(void 0);
341
+ if (named.isErr()) return named;
342
+ const annotations = named.value === void 0 ? void 0 : {
343
+ notes: structuredClone([...named.value.notes]),
344
+ comments: structuredClone([...named.value.comments])
345
+ };
346
+ const annotationBodies = [];
347
+ for (const note of annotations?.notes ?? []) for (const [index, block] of note.content.entries()) if (block.type === "paragraph") annotationBodies.push({
348
+ paragraph: block,
349
+ replace: (next) => {
350
+ note.content[index] = next;
351
+ }
352
+ });
353
+ for (const comment of annotations?.comments ?? []) for (const [index, paragraph] of comment.content.entries()) annotationBodies.push({
354
+ paragraph,
355
+ replace: (next) => {
356
+ comment.content[index] = next;
357
+ }
358
+ });
359
+ const annotationParagraphs = annotationBodies.map(({ paragraph }) => paragraph);
360
+ for (const paragraph of annotationParagraphs) {
361
+ let related = false;
362
+ visitInlineContentSlots(paragraph, ({ item }) => {
363
+ if (item.type === "hyperlink" && item.anchor === void 0) related = true;
364
+ });
365
+ visitParagraphRuns(paragraph, (run) => {
366
+ if (run.content.some((child) => child.type === "drawing")) related = true;
367
+ });
368
+ if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.");
369
+ }
263
370
  const destination = readModel(session.document);
264
371
  let styles = destination.package.styles;
265
372
  let styleIds;
@@ -268,19 +375,31 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
268
375
  const importedStyles = importClipboardStyles({
269
376
  destination,
270
377
  source: sourceDocument,
271
- paragraphs
378
+ paragraphs,
379
+ annotationParagraphs,
380
+ tableStyleIds: tables.flatMap(({ formatting }) => formatting?.styleId === void 0 ? [] : [formatting.styleId])
272
381
  });
273
382
  if (importedStyles.isErr()) return refuse(importedStyles.error.message);
274
383
  styles = importedStyles.value.styles;
275
- paragraphs.splice(0, paragraphs.length, ...importedStyles.value.paragraphs);
384
+ for (const [index, place] of places.entries()) {
385
+ const imported = importedStyles.value.paragraphs[index] ?? panic("An imported clipboard paragraph is missing.");
386
+ place.replace(imported);
387
+ paragraphs[index] = imported;
388
+ }
389
+ for (const [offset, body] of annotationBodies.entries()) {
390
+ const imported = importedStyles.value.annotationParagraphs[offset] ?? panic("An imported copied note or comment paragraph is missing.");
391
+ body.replace(imported);
392
+ annotationParagraphs[offset] = imported;
393
+ }
276
394
  styleIds = importedStyles.value.styleIds;
277
395
  extraIds = importedStyles.value.numberingIds;
396
+ for (const { formatting } of tables) if (formatting?.styleId !== void 0) formatting.styleId = importedStyles.value.styleIds.get(formatting.styleId) ?? panic("An imported table style has no destination identity.");
278
397
  }
279
398
  const sourceNumbering = sourceDocument?.package.numbering ?? completeNumberingForDoc(void 0, state.schema.topNodeType.create(null, importedSlice.content));
280
399
  const importedNumbering = importNumbering({
281
400
  destination: destination.package.numbering,
282
401
  source: sourceNumbering,
283
- paragraphs,
402
+ paragraphs: [...paragraphs, ...annotationParagraphs],
284
403
  mode: moveTarget === void 0 ? "copy" : "move",
285
404
  sourceKind: sourceDocument === void 0 ? "normalizedSlice" : "package",
286
405
  ...extraIds === void 0 ? {} : { extraIds },
@@ -360,8 +479,6 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
360
479
  };
361
480
  for (const paragraph of paragraphs) {
362
481
  if (moveTarget === void 0) {
363
- const storyPartRefusal = canonicalClipboardStoryPartRefusal(paragraph);
364
- if (storyPartRefusal !== void 0) return Result.err(storyPartRefusal);
365
482
  const links = [];
366
483
  visitInlineContentSlots(paragraph, ({ item }) => {
367
484
  if (item.type === "hyperlink") links.push(item);
@@ -492,42 +609,61 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
492
609
  }
493
610
  const openStart = importedSlice.openStart === 0 ? 0 : 1;
494
611
  const openEnd = importedSlice.openEnd === 0 ? 0 : 1;
495
- if (from.value === void 0 || to.value === void 0) return session.prepareCellSelectionStructure(state, (at) => ({
496
- type: "replaceFragment",
612
+ const topParagraphs = blocks.filter((block) => block.type === "paragraph");
613
+ const pasted = (range) => {
614
+ if (annotations !== void 0) return {
615
+ type: "pasteBlocks",
616
+ ...range,
617
+ blocks,
618
+ openStart,
619
+ openEnd,
620
+ annotations
621
+ };
622
+ if (topParagraphs.length === blocks.length) return {
623
+ type: "replaceFragment",
624
+ ...range,
625
+ paragraphs: topParagraphs,
626
+ openStart,
627
+ openEnd
628
+ };
629
+ return {
630
+ type: "pasteBlocks",
631
+ ...range,
632
+ blocks,
633
+ openStart,
634
+ openEnd
635
+ };
636
+ };
637
+ if (from.value === void 0 || to.value === void 0) return session.prepareCellSelectionStructure(state, (at) => pasted({
497
638
  from: at,
498
- to: at,
499
- paragraphs,
500
- openStart,
501
- openEnd
639
+ to: at
502
640
  }), {
503
641
  resourceOps,
504
642
  semantic: "paste"
505
643
  });
506
- const fragment = {
644
+ const range = {
507
645
  from: from.value,
508
- to: to.value,
509
- paragraphs,
510
- openStart,
511
- openEnd
646
+ to: to.value
512
647
  };
513
648
  if (moveTarget === void 0) return session.prepareIntents(state, {
514
- intents: [{
515
- type: "replaceFragment",
516
- ...fragment
517
- }],
649
+ intents: [pasted(range)],
518
650
  resourceOps,
519
651
  semantic: "paste"
520
652
  });
653
+ if (topParagraphs.length !== blocks.length) return refuseUnder({ gap: CANONICAL_GAP.trackedTableStructure }, "Moving a table by dragging requires a table move operation.");
521
654
  const target = session.projection.addressAt(moveTarget);
522
655
  if (target.isErr()) return target;
523
656
  return session.prepareIntents(state, {
524
657
  intents: [{
525
658
  type: "moveFragment",
526
659
  target: target.value,
527
- ...fragment
660
+ ...range,
661
+ paragraphs: topParagraphs,
662
+ openStart,
663
+ openEnd
528
664
  }],
529
665
  resourceOps,
530
666
  semantic: "paste"
531
667
  });
532
668
  };
533
- export { canonicalClipboardStoryPartRefusal, prepareCanonicalPaste };
669
+ export { clipboardAnnotations, prepareCanonicalPaste };
@@ -7,13 +7,21 @@ type ImportClipboardStylesOptions = {
7
7
  destination: document_d_exports.Document;
8
8
  source: document_d_exports.Document;
9
9
  paragraphs: readonly document_d_exports.Paragraph[];
10
+ /** Styles pasted tables name, imported with their dependencies. */
11
+ tableStyleIds?: readonly string[];
12
+ /**
13
+ * Bodies of copied notes and comments: a style they name that the source
14
+ * does not define (a built-in reference style, say) is left as it is.
15
+ */
16
+ annotationParagraphs?: readonly document_d_exports.Paragraph[];
10
17
  };
11
18
  type ImportedClipboardStyles = {
12
19
  styles: document_d_exports.StyleDefinitions | undefined;
13
20
  paragraphs: document_d_exports.Paragraph[];
21
+ annotationParagraphs: document_d_exports.Paragraph[];
14
22
  styleIds: ReadonlyMap<string, string>;
15
23
  numberingIds: ReadonlySet<number>;
16
24
  };
17
25
  /** Import the transitive style/numbering dependencies of the clipboard, retaining destination defaults. */
18
- export declare const importClipboardStyles: ({ destination, source, paragraphs }: ImportClipboardStylesOptions) => Result<ImportedClipboardStyles, DocumentOpRefusal>;
26
+ export declare const importClipboardStyles: ({ destination, source, paragraphs, tableStyleIds, annotationParagraphs }: ImportClipboardStylesOptions) => Result<ImportedClipboardStyles, DocumentOpRefusal>;
19
27
  export {};
@@ -267,12 +267,13 @@ const materializeClipboardDefaults = ({ source, destination, paragraphs }) => {
267
267
  return unavailable === void 0 ? Result.ok(void 0) : refused(unavailable);
268
268
  };
269
269
  /** Import the transitive style/numbering dependencies of the clipboard, retaining destination defaults. */
270
- const importClipboardStyles = ({ destination, source, paragraphs }) => {
270
+ const importClipboardStyles = ({ destination, source, paragraphs, tableStyleIds = [], annotationParagraphs = [] }) => {
271
271
  const clonedParagraphs = structuredClone([...paragraphs]);
272
+ const clonedAnnotations = structuredClone([...annotationParagraphs]);
272
273
  const materialized = materializeClipboardDefaults({
273
274
  source,
274
275
  destination,
275
- paragraphs: clonedParagraphs
276
+ paragraphs: [...clonedParagraphs, ...clonedAnnotations]
276
277
  });
277
278
  if (materialized.isErr()) return materialized;
278
279
  const sourceStyles = /* @__PURE__ */ new Map();
@@ -295,6 +296,12 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
295
296
  }
296
297
  };
297
298
  for (const paragraph of clonedParagraphs) visitReferences(paragraph, selectReferences);
299
+ for (const styleId of tableStyleIds) selectReferences("styleId", styleId, {});
300
+ const selectDefinedReferences = (key, value, owner) => {
301
+ if (STYLE_REFERENCE_FIELDS.has(key) && typeof value === "string" && !sourceStyles.has(value)) return;
302
+ selectReferences(key, value, owner);
303
+ };
304
+ for (const paragraph of clonedAnnotations) visitReferences(paragraph, selectDefinedReferences);
298
305
  const sourceNums = source.package.numbering?.nums ?? [];
299
306
  const sourceAbstracts = source.package.numbering?.abstractNums ?? [];
300
307
  const nums = new Map(sourceNums.map((num) => [num.numId, num]));
@@ -372,6 +379,18 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
372
379
  });
373
380
  if (lowered.isErr()) return lowered;
374
381
  }
382
+ const remapDefined = (key, value, owner) => {
383
+ if (STYLE_REFERENCE_FIELDS.has(key) && typeof value === "string" && !styleIds.has(value)) return;
384
+ remap(key, value, owner);
385
+ };
386
+ for (const paragraph of clonedAnnotations) {
387
+ visitReferences(paragraph, remapDefined);
388
+ const lowered = lowerSourceTheme({
389
+ value: paragraph,
390
+ source
391
+ });
392
+ if (lowered.isErr()) return lowered;
393
+ }
375
394
  const prior = destination.package.styles;
376
395
  const styles = importedStyles.length === 0 ? prior : {
377
396
  ...prior,
@@ -380,6 +399,7 @@ const importClipboardStyles = ({ destination, source, paragraphs }) => {
380
399
  return Result.ok({
381
400
  styles,
382
401
  paragraphs: clonedParagraphs,
402
+ annotationParagraphs: clonedAnnotations,
383
403
  styleIds,
384
404
  numberingIds
385
405
  });
@@ -3,8 +3,8 @@ import { CanonicalSessionError } from "../canonical/canonicalSession.js";
3
3
  import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
4
4
  import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
5
5
  import { Result } from "better-result";
6
- import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
7
6
  import { EditorState, TextSelection } from "prosemirror-state";
7
+ import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
8
8
  // src/controller/canonicalComposition.ts
9
9
  /** A composition over content the session cannot project, restored. */
10
10
  const UNSUPPORTED_COMPOSITION = { gap: CANONICAL_GAP.storyContentProjection };
@@ -2,9 +2,9 @@ import { deletionRange, isCanonicalJoinBoundary, measuredDeletionRange } from ".
2
2
  import { textCaretOf } from "../prosemirror/nativeSelection.js";
3
3
  import { getEditorInputTargetRange, handleEditorBeforeInput } from "../prosemirror/textInput.js";
4
4
  import { createCanonicalComposition } from "./canonicalComposition.js";
5
+ import { Selection, TextSelection } from "prosemirror-state";
5
6
  import { CellSelection } from "prosemirror-tables";
6
7
  import { ReplaceStep } from "prosemirror-transform";
7
- import { Selection, TextSelection } from "prosemirror-state";
8
8
  // src/controller/canonicalInput.ts
9
9
  /** Deletions whose extent the browser measures: by word or by line. */
10
10
  const WORD_AND_LINE_DELETIONS = /* @__PURE__ */ new Set([
@@ -1,6 +1,6 @@
1
1
  import { remapSelection } from "../canonical/canonicalRemoteHistory.js";
2
- import { OP_STORIES } from "@stll/docx-core/ops";
3
2
  import * as v from "valibot";
3
+ import { OP_STORIES } from "@stll/docx-core/ops";
4
4
  // src/controller/canonicalPresence.ts
5
5
  const COUNT = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
6
6
  const STORY = v.union([
@@ -5,6 +5,6 @@ type ResolveCanonicalReviewRangeOptions = {
5
5
  to: number;
6
6
  resolution: "accept" | "reject";
7
7
  };
8
- /** Null delegates to the legacy session's ProseMirror review commands. */
8
+ /** Null when the editor holds no canonical session, which leaves the review as it is. */
9
9
  export declare const resolveCanonicalReviewRange: ({ editor, from, to, resolution }: ResolveCanonicalReviewRangeOptions) => boolean | null;
10
10
  export {};
@@ -1,7 +1,7 @@
1
1
  import { getTrackedChangeGroupIdsFromDoc, getTrackedChangesFromDoc } from "../ai-edits/read.js";
2
2
  import { findAIEditRevisionRange } from "../prosemirror/commands/comments.js";
3
3
  // src/controller/canonicalReview.ts
4
- /** Null delegates to the legacy session's ProseMirror review commands. */
4
+ /** Null when the editor holds no canonical session, which leaves the review as it is. */
5
5
  const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
6
6
  if (!editor?.getCanonicalDocument()) return null;
7
7
  const state = editor.getState();
@@ -1,6 +1,6 @@
1
1
  import { Result, TaggedError } from "better-result";
2
- import { DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_SCHEMA_VERSION, ID_LEASE_KINDS, createSequencer, validateSequencedBatch } from "@stll/docx-core/ops";
3
2
  import * as v from "valibot";
3
+ import { DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_SCHEMA_VERSION, ID_LEASE_KINDS, createSequencer, validateSequencedBatch } from "@stll/docx-core/ops";
4
4
  // src/controller/canonicalRoomAuthority.ts
5
5
  const CanonicalRoomAuthorityErrorBase = TaggedError("CanonicalRoomAuthorityError");
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { Result } from "better-result";
2
- import { BATCH_REJECTION_REASONS, BatchRejection, DOCUMENT_OP_TYPES, EXCLUSIVE_PARTS, ID_LEASE_KINDS, ID_LEASE_REFUSAL_REASONS, IdLeaseRefusal } from "@stll/docx-core/ops";
3
2
  import * as v from "valibot";
3
+ import { BATCH_REJECTION_REASONS, BatchRejection, DOCUMENT_OP_TYPES, EXCLUSIVE_PARTS, ID_LEASE_KINDS, ID_LEASE_REFUSAL_REASONS, IdLeaseRefusal } from "@stll/docx-core/ops";
4
4
  // src/controller/canonicalRoomWire.ts
5
5
  const LEASE_KINDS = v.picklist(Object.values(ID_LEASE_KINDS));
6
6
  const REVISION = v.pipe(v.number(), v.integer(), v.minValue(0));
@@ -16,8 +16,8 @@ import { itemBefore } from "../utils/listItems.js";
16
16
  import { prepareContentControlValue } from "./canonicalContentControlValue.js";
17
17
  import { Result, panic } from "better-result";
18
18
  import { NO_PARAGRAPH_NUMBERING, headingOutlineLevel, paragraphNumberingReference, resolveParagraphNumbering } from "@stll/docx-core/model";
19
- import { CellSelection } from "prosemirror-tables";
20
19
  import { DOCUMENT_OP_TYPES, OP_STORIES, editorParagraphGroups, editorPositionAtPhysicalPosition, physicalPositionAtEditorOffset } from "@stll/docx-core/ops";
20
+ import { CellSelection } from "prosemirror-tables";
21
21
  // src/controller/canonicalStructure.ts
22
22
  const DEFAULT_TOC_PAGE_WIDTH_TWIPS = 12240;
23
23
  const DEFAULT_TOC_MARGIN_TWIPS = 1440;
@@ -2,8 +2,8 @@ import { parseCanonicalPresence } from "./canonicalPresence.js";
2
2
  import { restoreCanonicalRoomAuthority } from "./canonicalRoomAuthority.js";
3
3
  import { UNAVAILABLE_LEASE_ANSWER, decodeLeaseGrant, decodeLeaseRenewal, decodeRoomSubmission, encodeLeaseGrant, encodeLeaseRenewal, encodeRoomSubmission } from "./canonicalRoomWire.js";
4
4
  import { Result, TaggedError } from "better-result";
5
- import { ID_LEASE_KINDS, validateDocumentBatch, validateSequencedBatch } from "@stll/docx-core/ops";
6
5
  import * as v from "valibot";
6
+ import { ID_LEASE_KINDS, validateDocumentBatch, validateSequencedBatch } from "@stll/docx-core/ops";
7
7
  // src/controller/canonicalTabRoom.ts
8
8
  /** BroadcastChannel and the Web Locks API, as a browser tab has them. */
9
9
  const browserTabEnvironment = () => ({
@@ -0,0 +1,10 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { DocumentOp } from "@stll/docx-core/ops";
3
+ /**
4
+ * The canonical operation that sets (or clears) the document's watermark: the
5
+ * header parts and section references {@link setDocumentWatermark} changes,
6
+ * stale-checked against `doc`, so the edit journals and undoes like any other.
7
+ * A header it creates holds one empty paragraph with a fresh id, as every
8
+ * canonical story does.
9
+ */
10
+ export declare const watermarkOperations: (doc: document_d_exports.Document, watermark: document_d_exports.Watermark | undefined) => DocumentOp[];
@@ -0,0 +1,37 @@
1
+ import { withCanonicalParagraphIds } from "../canonical/canonicalOperations.js";
2
+ import { setDocumentWatermark } from "../watermark/index.js";
3
+ import { storyPartsOpOf } from "@stll/docx-core/ops";
4
+ // src/controller/canonicalWatermark.ts
5
+ /**
6
+ * The canonical operation that sets (or clears) the document's watermark: the
7
+ * header parts and section references {@link setDocumentWatermark} changes,
8
+ * stale-checked against `doc`, so the edit journals and undoes like any other.
9
+ * A header it creates holds one empty paragraph with a fresh id, as every
10
+ * canonical story does.
11
+ */
12
+ const watermarkOperations = (doc, watermark) => {
13
+ const marked = setDocumentWatermark(doc, watermark);
14
+ const headers = new Map(marked.package.headers);
15
+ const after = {
16
+ ...marked,
17
+ package: {
18
+ ...marked.package,
19
+ headers
20
+ }
21
+ };
22
+ for (const [rId, header] of headers) {
23
+ if (header.content.length > 0) continue;
24
+ headers.set(rId, {
25
+ ...header,
26
+ content: withCanonicalParagraphIds([{
27
+ type: "paragraph",
28
+ content: []
29
+ }], after)
30
+ });
31
+ }
32
+ return [storyPartsOpOf({
33
+ before: doc,
34
+ after
35
+ })];
36
+ };
37
+ export { watermarkOperations };
@@ -2,8 +2,8 @@ import { itemBefore } from "../utils/listItems.js";
2
2
  import { decodeRoomRecord, restoreCanonicalRoomAuthority } from "./canonicalRoomAuthority.js";
3
3
  import { UNAVAILABLE_LEASE_ANSWER, decodeLeaseGrant, decodeLeaseRenewal, decodeRoomSubmission, encodeLeaseGrant, encodeLeaseRenewal, encodeRoomSubmission, toWireJson } from "./canonicalRoomWire.js";
4
4
  import { Result, TaggedError } from "better-result";
5
- import { ID_LEASE_KINDS, validateDocumentBatch } from "@stll/docx-core/ops";
6
5
  import * as v from "valibot";
6
+ import { ID_LEASE_KINDS, validateDocumentBatch } from "@stll/docx-core/ops";
7
7
  // src/controller/canonicalYjsRoom.ts
8
8
  /** The Yjs client id the authority writes the journal under, unless the host picks another. */
9
9
  const CANONICAL_YJS_AUTHORITY = 1179601993;
@@ -20,8 +20,8 @@ import { FolioDocxSerializationPath } from "../types/docxSerialization.js";
20
20
  import { FolioFieldInsertion } from "../types/fields.js";
21
21
  import { AnonymizationHighlightsView } from "./anonymizationHighlights.js";
22
22
  import { createCanonicalInputBoundary } from "./canonicalInput.js";
23
- import { Node } from "prosemirror-model";
24
23
  import { Command, EditorState, Transaction } from "prosemirror-state";
24
+ import { Node } from "prosemirror-model";
25
25
  import { DocumentOp, FormattingPatch, OpStory, TextPosition } from "@stll/docx-core/ops";
26
26
  import { EditorView } from "prosemirror-view";
27
27
  /** The inline suggestion, and what painting it needs. */
@@ -1,11 +1,9 @@
1
1
  import { cloneDocumentWithParagraphPropertySources } from "../docx/paragraphPropertySource.js";
2
- import { fromProseDoc } from "../prosemirror/conversion/fromProseDoc.js";
3
- import { readModel } from "../types/documentModel.js";
4
2
  import { NO_ANONYMIZATION_HIGHLIGHTS } from "./anonymizationHighlights.js";
5
3
  import { IDLE_AUTOCOMPLETE } from "./autocompleteSuggestion.js";
6
4
  import { legacyEditorPositionAt } from "./textPositionLookup.js";
7
- import { CellSelection } from "prosemirror-tables";
8
5
  import { NodeSelection, Selection, TextSelection } from "prosemirror-state";
6
+ import { CellSelection } from "prosemirror-tables";
9
7
  import { redo, undo } from "prosemirror-history";
10
8
  // src/controller/hiddenEditorApi.ts
11
9
  /** No editor: nothing to suggest in. */
@@ -30,13 +28,6 @@ const delegateAutocomplete = (current) => ({
30
28
  get: () => current().get(),
31
29
  canTrigger: () => current().canTrigger()
32
30
  });
33
- /**
34
- * Convert PM state to Document
35
- */
36
- const stateToDocument = (state, originalDoc) => {
37
- if (!originalDoc) return null;
38
- return fromProseDoc(state.doc, readModel(originalDoc), { stylesheetSource: { type: "package" } });
39
- };
40
31
  const createHiddenEditorApi = (deps) => {
41
32
  const dispatchTr = (view, tr) => {
42
33
  if (!deps.isDestroying()) view.dispatch(tr);
@@ -82,13 +73,7 @@ const createHiddenEditorApi = (deps) => {
82
73
  getAnonymizationHighlights: () => deps.getAnonymizationHighlights?.() ?? NO_ANONYMIZATION_HIGHLIGHTS,
83
74
  insertField: (field) => deps.insertField?.(field) ?? false,
84
75
  autocomplete: deps.autocomplete ?? NO_AUTOCOMPLETE,
85
- getDocument: () => {
86
- const canonical = deps.getCanonicalDocument?.();
87
- if (canonical) return canonical;
88
- const view = deps.getView();
89
- if (!view) return null;
90
- return stateToDocument(view.state, deps.getDocumentContext());
91
- },
76
+ getDocument: () => deps.getCanonicalDocument?.() ?? deps.getDocumentContext(),
92
77
  updateCanonicalInputLifecycle: (action) => deps.canonicalOperations?.updateCanonicalInputLifecycle(action) ?? false,
93
78
  applyCanonicalStoryHistory: (options) => deps.canonicalOperations?.applyCanonicalStoryHistory(options) ?? false,
94
79
  applyCanonicalComment: (request) => deps.canonicalOperations?.applyCanonicalComment(request) ?? null,
@@ -2,7 +2,7 @@ import { CanonicalHistoryDrop, CanonicalHistoryEffect } from "../canonical/canon
2
2
  import { HiddenEditorStateReason } from "../layout-engine/layoutInstrumentation.js";
3
3
  import { EditorMode } from "../managers/EditorModeManager.js";
4
4
  import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js";
5
- import { HistoryShortcutOwner } from "../prosemirror/extensions/core/HistoryExtension.js";
5
+ import { HistoryShortcutOwner } from "../prosemirror/extensions/core/historyCommands.js";
6
6
  import { FolioAnonymizationTerm } from "../types/anonymization.js";
7
7
  import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
8
8
  import { document_d_exports } from "../types/document.js";
@@ -25,8 +25,9 @@ export type HiddenProseMirrorRemoteSelection = RemoteSelection;
25
25
  /**
26
26
  * Create ProseMirror state from document
27
27
  *
28
- * When an ExtensionManager is provided, it supplies the schema and plugins.
29
- * Otherwise falls back to the default singleton schema with no extension plugins.
28
+ * When an ExtensionManager is provided, it supplies the schema. The state
29
+ * paints the document before the canonical session's state replaces it, so it
30
+ * carries none of the extensions' editing plugins.
30
31
  */
31
32
  export type CreateHiddenEditorStateOptions = {
32
33
  /** The model; the editor state is built from it through `readModel`. */