@stll/folio-core 0.67.0 → 0.68.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 (251) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +104 -34
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/note-references.d.ts +6 -0
  7. package/dist/ai-edits/note-references.js +7 -1
  8. package/dist/ai-edits/read.d.ts +19 -0
  9. package/dist/ai-edits/snapshot.d.ts +6 -0
  10. package/dist/ai-edits/snapshot.js +8 -3
  11. package/dist/ai-edits/types.d.ts +9 -1
  12. package/dist/ai-suggestions/apply.js +13 -4
  13. package/dist/compare/compare.js +2 -1
  14. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  15. package/dist/compare/inserted-resource-snapshot.js +7 -3
  16. package/dist/controller/canonicalClipboard.js +29 -12
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  19. package/dist/controller/canonicalInlineProjection.js +192 -28
  20. package/dist/controller/canonicalInput.d.ts +2 -1
  21. package/dist/controller/canonicalInput.js +28 -1
  22. package/dist/controller/canonicalListRendering.d.ts +2 -1
  23. package/dist/controller/canonicalListRendering.js +1 -1
  24. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  25. package/dist/controller/canonicalLockGuard.js +88 -0
  26. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  27. package/dist/controller/canonicalPublicOperations.js +274 -20
  28. package/dist/controller/canonicalSession.d.ts +87 -7
  29. package/dist/controller/canonicalSession.js +327 -73
  30. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  31. package/dist/controller/canonicalStoryEditor.js +4 -3
  32. package/dist/controller/canonicalStructure.d.ts +2 -1
  33. package/dist/controller/canonicalStructure.js +129 -7
  34. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  35. package/dist/controller/contentControlWidgetController.js +13 -1
  36. package/dist/controller/folioEditor.js +1 -0
  37. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  38. package/dist/controller/headerFooterEditorManager.js +5 -5
  39. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  40. package/dist/controller/hiddenEditorApi.js +1 -0
  41. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  42. package/dist/controller/hiddenEditorManager.js +91 -37
  43. package/dist/controller/layoutPipeline.js +48 -15
  44. package/dist/controller/noteEditorManager.d.ts +2 -2
  45. package/dist/controller/noteEditorManager.js +5 -5
  46. package/dist/display-list/build/pageFurniture.js +41 -19
  47. package/dist/display-list/build/tablePrimitives.js +23 -4
  48. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  49. package/dist/document-operations.d.ts +8 -0
  50. package/dist/document-operations.js +4 -3
  51. package/dist/docx/blockContentParser.d.ts +7 -3
  52. package/dist/docx/blockContentParser.js +2 -3
  53. package/dist/docx/blockPlainText.js +2 -0
  54. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  55. package/dist/docx/bookmarkRangeJoin.js +43 -0
  56. package/dist/docx/canonicalSave.js +5 -1
  57. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  58. package/dist/docx/canonicalSessionInput.js +7 -2
  59. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  60. package/dist/docx/commentAnchorIndex.js +39 -11
  61. package/dist/docx/commentRangeIntegrity.js +30 -24
  62. package/dist/docx/commentRangeJoin.d.ts +4 -0
  63. package/dist/docx/commentRangeJoin.js +26 -12
  64. package/dist/docx/commentReferenceCompletion.js +5 -4
  65. package/dist/docx/commentReferenceNormalization.js +40 -18
  66. package/dist/docx/compatibility.js +9 -2
  67. package/dist/docx/containerChildren.js +22 -1
  68. package/dist/docx/encryption/compoundFile.js +9 -1
  69. package/dist/docx/encryption/encryptionInfo.js +16 -2
  70. package/dist/docx/ensureParaIds.js +46 -7
  71. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  72. package/dist/docx/ensureUniqueControlIds.js +110 -0
  73. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  74. package/dist/docx/headerFooterVerbatim.js +13 -2
  75. package/dist/docx/hostCommentThreads.d.ts +17 -0
  76. package/dist/docx/hostCommentThreads.js +49 -0
  77. package/dist/docx/hyperlinkParser.js +9 -2
  78. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  79. package/dist/docx/inlineWrapperContent.js +9 -2
  80. package/dist/docx/listMarkerComputation.d.ts +35 -1
  81. package/dist/docx/listMarkerComputation.js +39 -1
  82. package/dist/docx/listModelNormalization.d.ts +44 -1
  83. package/dist/docx/listModelNormalization.js +227 -96
  84. package/dist/docx/markupRangeMarker.d.ts +14 -0
  85. package/dist/docx/markupRangeMarker.js +15 -1
  86. package/dist/docx/metadataPrivacy.js +43 -22
  87. package/dist/docx/normalizeBaseDirection.js +3 -1
  88. package/dist/docx/paragraphParser.js +159 -48
  89. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  90. package/dist/docx/paragraphPropertySource.js +22 -1
  91. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  92. package/dist/docx/paragraphTraversal.js +2 -0
  93. package/dist/docx/parseWarningMessage.js +2 -1
  94. package/dist/docx/parser.js +6 -0
  95. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  96. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  97. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  98. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  99. package/dist/docx/reviewResolutionProvenance.js +110 -25
  100. package/dist/docx/rezip.d.ts +6 -0
  101. package/dist/docx/rezip.js +38 -21
  102. package/dist/docx/selectiveSave.js +6 -10
  103. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  104. package/dist/docx/selectiveXmlPatch.js +11 -7
  105. package/dist/docx/serializer/documentSerializer.js +3 -1
  106. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  107. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  108. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  109. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  110. package/dist/docx/serializer/noteSerializer.js +23 -16
  111. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  112. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  113. package/dist/docx/serializer/runSerializer.js +2 -2
  114. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  115. package/dist/docx/serializer/tableSerializer.js +4 -2
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  117. package/dist/docx/server/createBilingualDocument.js +27 -5
  118. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  119. package/dist/docx/sessionListPruning.d.ts +2 -0
  120. package/dist/docx/sessionListPruning.js +50 -0
  121. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  122. package/dist/docx/splitRevisionPieces.js +14 -0
  123. package/dist/docx/storyBlockReplay.js +4 -0
  124. package/dist/docx/structuralXmlPatch.js +19 -7
  125. package/dist/docx/tableParser.d.ts +6 -2
  126. package/dist/docx/tableParser.js +2 -3
  127. package/dist/docx/textBoxContentParser.d.ts +11 -0
  128. package/dist/docx/textBoxContentParser.js +51 -0
  129. package/dist/docx/textBoxParser.d.ts +0 -5
  130. package/dist/docx/textBoxParser.js +1 -23
  131. package/dist/docx/verticalMergeProjection.js +1 -1
  132. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  133. package/dist/fonts/fontsourceFaces.js +1 -7
  134. package/dist/i18n/messages/ar.gen.js +2 -0
  135. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  136. package/dist/i18n/messages/catalogs.gen.js +34 -0
  137. package/dist/i18n/messages/cs.gen.js +2 -0
  138. package/dist/i18n/messages/de.gen.js +2 -0
  139. package/dist/i18n/messages/en.gen.js +2 -0
  140. package/dist/i18n/messages/es.gen.js +2 -0
  141. package/dist/i18n/messages/et.gen.js +2 -0
  142. package/dist/i18n/messages/fr.gen.js +2 -0
  143. package/dist/i18n/messages/he.gen.js +2 -0
  144. package/dist/i18n/messages/hi.gen.js +2 -0
  145. package/dist/i18n/messages/hu.gen.js +2 -0
  146. package/dist/i18n/messages/lt.gen.js +2 -0
  147. package/dist/i18n/messages/lv.gen.js +2 -0
  148. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  149. package/dist/i18n/messages/pl.gen.js +2 -0
  150. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  151. package/dist/i18n/messages/sk.gen.js +2 -0
  152. package/dist/i18n/messages/tr.gen.js +2 -0
  153. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  154. package/dist/internal/acceptedBlockProjection.js +2 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  156. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  157. package/dist/internal/revisionResolutionInline.js +1 -2
  158. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  159. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  160. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  161. package/dist/layout-bridge/engine/hitTest.js +9 -10
  162. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  163. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  164. package/dist/layout-engine/footnoteContinuation.js +210 -0
  165. package/dist/layout-engine/index.d.ts +2 -2
  166. package/dist/layout-engine/index.js +7 -2
  167. package/dist/layout-engine/measure/cache.js +10 -5
  168. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  169. package/dist/layout-engine/tableLayout.js +29 -5
  170. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  171. package/dist/layout-engine/tableRowBreak.js +43 -1
  172. package/dist/layout-engine/types.d.ts +36 -1
  173. package/dist/layout-painter/renderPage.d.ts +4 -4
  174. package/dist/layout-painter/renderPage.js +46 -17
  175. package/dist/layout-painter/renderTable.js +7 -4
  176. package/dist/managers/AutoSaveManager.d.ts +5 -1
  177. package/dist/managers/FindReplaceManager.js +3 -10
  178. package/dist/markdown/escape.d.ts +20 -1
  179. package/dist/markdown/escape.js +43 -1
  180. package/dist/markdown/renderBlock.js +4 -1
  181. package/dist/markdown/renderParagraph.js +13 -27
  182. package/dist/markdown/renderTable.js +6 -2
  183. package/dist/markdown/trailers.js +1 -0
  184. package/dist/pdf/images.d.ts +17 -1
  185. package/dist/pdf/images.js +22 -4
  186. package/dist/pdf/writePdf.js +4 -2
  187. package/dist/prosemirror/attrs/index.js +1 -0
  188. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  189. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  190. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  191. package/dist/prosemirror/commands/comments.d.ts +25 -0
  192. package/dist/prosemirror/commands/comments.js +102 -11
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +1 -1
  195. package/dist/prosemirror/commentIdAllocator.js +2 -2
  196. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  197. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  198. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  199. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  200. package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
  201. package/dist/prosemirror/conversion/index.d.ts +1 -1
  202. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  203. package/dist/prosemirror/conversion/toProseDoc.js +319 -51
  204. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  205. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  206. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  207. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  208. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  209. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  210. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  211. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  212. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  213. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  214. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  215. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  216. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  217. package/dist/prosemirror/index.d.ts +2 -2
  218. package/dist/prosemirror/listLabels.js +3 -2
  219. package/dist/prosemirror/listNumbering.d.ts +6 -0
  220. package/dist/prosemirror/listNumbering.js +12 -9
  221. package/dist/prosemirror/lockedControls.d.ts +13 -0
  222. package/dist/prosemirror/lockedControls.js +106 -0
  223. package/dist/prosemirror/markupViewProjection.js +1 -1
  224. package/dist/prosemirror/noteReferenceReview.js +2 -2
  225. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  226. package/dist/prosemirror/plugins/suggestionMode.js +20 -9
  227. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  228. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  229. package/dist/prosemirror/replacedAnnotations.js +1 -0
  230. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  231. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  232. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  233. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  234. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  235. package/dist/prosemirror/runStyleFormatting.js +16 -13
  236. package/dist/prosemirror/schema/marks.d.ts +6 -0
  237. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  238. package/dist/prosemirror/validation.js +1 -0
  239. package/dist/redline.js +23 -9
  240. package/dist/server.d.ts +2 -2
  241. package/dist/style-sets/extract.js +2 -2
  242. package/dist/types/canonicalCapabilities.d.ts +29 -8
  243. package/dist/types/canonicalCapabilities.js +13 -9
  244. package/dist/utils/cssString.d.ts +7 -0
  245. package/dist/utils/cssString.js +9 -0
  246. package/dist/utils/fontResolver.js +4 -1
  247. package/dist/utils/replaceText.d.ts +11 -0
  248. package/dist/utils/replaceText.js +39 -7
  249. package/dist/version-comparison.d.ts +9 -1
  250. package/dist/version-comparison.js +11 -5
  251. package/package.json +2 -2
@@ -49,6 +49,25 @@ export type FolioReviewChange = {
49
49
  */
50
50
  blockId: string | null;
51
51
  };
52
+ /** A tracked change an accept-all or reject-all left pending, and why. */
53
+ export type FolioReviewResolutionSkip = {
54
+ /** The change's revision id, as {@link FolioReviewChange.id}. */
55
+ id: number;
56
+ /**
57
+ * `contentControlLock`: resolving it would change the content of a content
58
+ * control whose `w:lock` is `contentLocked` or `sdtContentLocked`, or remove
59
+ * one whose lock is `sdtLocked` or `sdtContentLocked`.
60
+ */
61
+ reason: "contentControlLock";
62
+ message: string;
63
+ };
64
+ /** What an accept-all or reject-all did. */
65
+ export type FolioReviewResolution = {
66
+ /** The ordinary tracked changes it resolved. */
67
+ resolved: number;
68
+ /** The changes it left pending, each as it was. */
69
+ skipped: FolioReviewResolutionSkip[];
70
+ };
52
71
  /** A comment anchor (the ranged text a comment marks) discovered in the body. */
53
72
  export type FolioCommentAnchor = {
54
73
  commentId: number;
@@ -67,6 +67,12 @@ export declare const isFolioAIContentBlock: ({ text }: Pick<FolioAIBlock, "text"
67
67
  */
68
68
  export declare const trailingBodyBlockId: ({ blocks }: FolioAIEditSnapshot) => string | null;
69
69
  export declare const hashFolioAIBlockText: (text: string) => string;
70
+ /**
71
+ * The identity of a block's text: what a snapshot anchor records, and what an
72
+ * engine compares an anchor or a precondition against. Whitespace runs collapse
73
+ * and the ends trim, so a block reads the same however its spaces were typed.
74
+ */
75
+ export declare const hashFolioAIBlockContent: (text: string) => string;
70
76
  /**
71
77
  * Canonical public projection of the clean view's inline structure.
72
78
  *
@@ -241,6 +241,12 @@ const hashFolioAIBlockText = (text) => {
241
241
  for (const character of text) hash = (hash * 33 + (character.codePointAt(0) ?? 0)) % 2147483647;
242
242
  return `h${hash.toString(36)}`;
243
243
  };
244
+ /**
245
+ * The identity of a block's text: what a snapshot anchor records, and what an
246
+ * engine compares an anchor or a precondition against. Whitespace runs collapse
247
+ * and the ends trim, so a block reads the same however its spaces were typed.
248
+ */
249
+ const hashFolioAIBlockContent = (text) => hashFolioAIBlockText(normalizeFolioAIBlockText(text));
244
250
  const EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARIES = Object.freeze([]);
245
251
  const EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARY_HASH = hashFolioAIBlockText(JSON.stringify(EMPTY_FOLIO_AI_BLOCK_STRUCTURAL_BOUNDARIES));
246
252
  /**
@@ -508,7 +514,7 @@ const createFolioAIEditSnapshotInternal = (doc, styleResolver, noteReferenceLabe
508
514
  const structuralBoundaries = projectFolioAIBlockStructuralBoundaries(cleanBlock);
509
515
  const structuralBoundaryHash = hashFolioAIBlockStructuralBoundaryProjection(structuralBoundaries);
510
516
  const normalizedText = normalizeFolioAIBlockText(text);
511
- const textHash = hashFolioAIBlockText(normalizedText);
517
+ const textHash = hashFolioAIBlockContent(text);
512
518
  hashCounts.set(textHash, (hashCounts.get(textHash) ?? 0) + 1);
513
519
  const paraIdAttr = node.attrs["paraId"];
514
520
  const paraId = typeof paraIdAttr === "string" && paraIdAttr.length > 0 ? paraIdAttr : null;
@@ -715,7 +721,6 @@ const getPreviewRuns = ({ node, nodeFrom, cleanBlock, styleResolver }) => {
715
721
  baseParagraphFormatting: paragraphStyleContext.baseParagraphFormatting,
716
722
  inheritedFormatting: paragraphStyleContext.paragraphFormatting,
717
723
  paragraphMarkFormatting: paragraphStyleContext.paragraphMarkFormatting,
718
- paragraphMarkPrecedesStyle: paragraphStyleContext.paragraphMarkPrecedesStyle,
719
724
  styleResolver
720
725
  });
721
726
  directFormatting = getDirectPreviewRunStyle(child.marks, directTextFormatting, styleResolver);
@@ -894,4 +899,4 @@ const samePreviewRunStyle = (run, style) => run.bold === style.bold && run.itali
894
899
  const isEmptyPreviewRunStyle = ({ bold, italic, underline, strike, fontFamily, fontSizePt, color }) => bold === void 0 && italic === void 0 && underline === void 0 && strike === void 0 && fontFamily === void 0 && fontSizePt === void 0 && color === void 0;
895
900
  const sameDirectFormatting = (left, right) => left === void 0 && isEmptyPreviewRunStyle(right) || left !== void 0 && left.bold === right.bold && left.italic === right.italic && left.underline === right.underline && left.strike === right.strike && left.fontFamily === right.fontFamily && left.fontSizePt === right.fontSizePt && left.color === right.color;
896
901
  const isUnstyledPreviewRun = ({ directFormatting, ...style }) => isEmptyPreviewRunStyle(style) && (directFormatting === void 0 || isEmptyPreviewRunStyle(directFormatting));
897
- export { alignedNoteReferenceLabels, collectNoteReferenceLabels, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isFolioAIContentBlock, isHiddenTableRow, normalizeFolioAIBlockText, numberingReferenceKeysOf, projectFolioAIBlockStructuralBoundaries, relabelFolioAIEditSnapshotNoteReferences, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf, styleResolverOf, trailingBodyBlockId };
902
+ export { alignedNoteReferenceLabels, collectNoteReferenceLabels, createFolioAIEditSnapshot, createFolioAIEditSnapshotWithStyleResolver, createFolioAITextRangeHandle, detachFolioAIEditSnapshotExternalHyperlinks, folioStoryTables, hashFolioAIBlockContent, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isFolioAIContentBlock, isHiddenTableRow, normalizeFolioAIBlockText, numberingReferenceKeysOf, projectFolioAIBlockStructuralBoundaries, relabelFolioAIEditSnapshotNoteReferences, remapFolioAIEditSnapshotNumberingReferences, remapFolioAIEditSnapshotStyleReferences, sourceDocumentOf, storyTablesOf, styleResolverOf, trailingBodyBlockId };
@@ -564,7 +564,15 @@ export type FolioAIResolvedEditOperation = FolioAIEditOperation<FolioContentStat
564
564
  * `unsupportedMode`.
565
565
  */
566
566
  export type FolioAIEditApplyMode = "direct" | "tracked-changes" | "suggested";
567
- export type FolioAIEditSkipReason = "missingBlock" | "changedBlock" | "ambiguousFind" | "missingFind" | "unsupportedBlock" | "unsupportedMode" | "atomicBatchRejected" | "preconditionFailed" | "staleRange" | "emptyOperation" |
567
+ export type FolioAIEditSkipReason =
568
+ /**
569
+ * A content control's `w:lock` forbids the change: it reaches inside a
570
+ * control whose content is locked (`contentLocked`, `sdtContentLocked`), or
571
+ * removes one that may not be removed (`sdtLocked`, `sdtContentLocked`),
572
+ * also by deleting the paragraph or text that holds it. Nothing was
573
+ * applied; `message` names the lock.
574
+ */
575
+ "contentControlLock" | "missingBlock" | "changedBlock" | "ambiguousFind" | "missingFind" | "unsupportedBlock" | "unsupportedMode" | "atomicBatchRejected" | "preconditionFailed" | "staleRange" | "emptyOperation" |
568
576
  /** The paragraph already owns the one `w:pPrChange` OOXML permits. */
569
577
  "pendingParagraphPropertyChange" |
570
578
  /** The affected run already owns the one `w:rPrChange` OOXML permits. */
@@ -27,9 +27,18 @@ function applySuggestions(options) {
27
27
  applied,
28
28
  stale
29
29
  };
30
- resolved.sort((a, b) => b.from - a.from);
30
+ resolved.sort((a, b) => b.from - a.from || b.to - a.to);
31
+ const accepted = [];
32
+ for (const entry of resolved) {
33
+ const following = accepted.at(-1);
34
+ if (following !== void 0 && entry.to > following.from) {
35
+ stale.push(entry.suggestion.id);
36
+ continue;
37
+ }
38
+ accepted.push(entry);
39
+ }
31
40
  const tr = view.state.tr;
32
- if (mode === "direct") for (const { suggestion, from, to } of resolved) {
41
+ if (mode === "direct") for (const { suggestion, from, to } of accepted) {
33
42
  tr.insertText(suggestion.suggestedText, from, to);
34
43
  applied.push(suggestion.id);
35
44
  }
@@ -38,11 +47,11 @@ function applySuggestions(options) {
38
47
  const deletionType = view.state.schema.marks["deletion"];
39
48
  if (!insertionType || !deletionType) return {
40
49
  applied,
41
- stale: [...stale, ...resolved.map((r) => r.suggestion.id)]
50
+ stale: [...stale, ...accepted.map((r) => r.suggestion.id)]
42
51
  };
43
52
  const date = (/* @__PURE__ */ new Date()).toISOString();
44
53
  seedRevisionIdsFromDoc(view.state.doc);
45
- for (const { suggestion, from, to } of resolved) {
54
+ for (const { suggestion, from, to } of accepted) {
46
55
  const attrs = {
47
56
  revisionId: mintRevisionId(),
48
57
  author,
@@ -497,7 +497,8 @@ const COMPARE_SKIP_DISPOSITION = {
497
497
  missingStyle: "fatal",
498
498
  missingNumbering: "fatal",
499
499
  invalidResult: "fatal",
500
- pendingDeletion: "unwritable"
500
+ pendingDeletion: "unwritable",
501
+ contentControlLock: "fatal"
501
502
  };
502
503
  const getCompareSkipDisposition = (reason) => COMPARE_SKIP_DISPOSITION[reason];
503
504
  /**
@@ -1,10 +1,13 @@
1
1
  import { FolioAIBlock, FolioAIEditSnapshot } from "../ai-edits/types.js";
2
+ import { FolioContentAlignmentWorkSession } from "./content-alignment.js";
2
3
  type CreateInsertedResourceProjectionOptions = {
3
4
  base: FolioAIEditSnapshot;
4
5
  revised: FolioAIEditSnapshot;
6
+ /** The comparison's alignment allowance; the projection's work is charged to it. */
7
+ alignmentSession: FolioContentAlignmentWorkSession;
5
8
  };
6
9
  /** Select resource nodes with their identities from the full revised snapshot. */
7
- export declare const createInsertedResourceProjection: ({ base, revised }: CreateInsertedResourceProjectionOptions) => {
10
+ export declare const createInsertedResourceProjection: ({ base, revised, alignmentSession }: CreateInsertedResourceProjectionOptions) => {
8
11
  snapshot: FolioAIEditSnapshot;
9
12
  revisedBlockIds: string[];
10
13
  };
@@ -1,12 +1,16 @@
1
1
  import { createFolioAIEditSnapshotWithStyleResolver, sourceDocumentOf, styleResolverOf } from "../ai-edits/snapshot.js";
2
- import { alignFolioBlocks } from "../version-comparison.js";
2
+ import { alignFolioBlocksInSession } from "../version-comparison.js";
3
3
  import { panic } from "better-result";
4
4
  import { Fragment } from "prosemirror-model";
5
5
  // src/compare/inserted-resource-snapshot.ts
6
6
  /** Select resource nodes with their identities from the full revised snapshot. */
7
- const createInsertedResourceProjection = ({ base, revised }) => {
7
+ const createInsertedResourceProjection = ({ base, revised, alignmentSession }) => {
8
8
  const document = sourceDocumentOf(revised);
9
- const insertions = alignFolioBlocks(base.blocks, revised.blocks).flatMap((event) => {
9
+ const insertions = alignFolioBlocksInSession({
10
+ baseBlocks: base.blocks,
11
+ revisedBlocks: revised.blocks,
12
+ workSession: alignmentSession
13
+ }).flatMap((event) => {
10
14
  if (event.type === "pair" || event.type === "baseOnly") return [];
11
15
  const anchor = revised.anchors[event.block.id] ?? panic("An inserted block lost its source anchor");
12
16
  const node = document.nodeAt(anchor.from) ?? panic("An inserted block lost its source paragraph");
@@ -19,7 +19,7 @@ import { CellSelection } from "prosemirror-tables";
19
19
  import { packageResourcesOpOf } from "@stll/docx-core/ops";
20
20
  // src/controller/canonicalClipboard.ts
21
21
  const refuse = (message) => Result.err(new CanonicalSessionError({
22
- gap: CANONICAL_GAP.dispatch,
22
+ ground: { gap: CANONICAL_GAP.dispatch },
23
23
  message,
24
24
  reason: "refused"
25
25
  }));
@@ -188,7 +188,7 @@ const canonicalClipboardStoryPartRefusal = (paragraph) => {
188
188
  });
189
189
  if (!requiresStory) return void 0;
190
190
  return new CanonicalSessionError({
191
- gap: CANONICAL_GAP.dispatch,
191
+ ground: { gap: CANONICAL_GAP.dispatch },
192
192
  reason: "refused",
193
193
  message: "Clipboard comments and note references require importing their source story parts."
194
194
  });
@@ -196,7 +196,7 @@ const canonicalClipboardStoryPartRefusal = (paragraph) => {
196
196
  const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
197
197
  if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
198
198
  if (slice.content.size === 0) return Result.err(new CanonicalSessionError({
199
- gap: CANONICAL_GAP.dispatch,
199
+ ground: { gap: CANONICAL_GAP.dispatch },
200
200
  message: "The clipboard contains no content.",
201
201
  reason: "noChange"
202
202
  }));
@@ -214,7 +214,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
214
214
  const converted = Result.try({
215
215
  try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
216
216
  catch: (cause) => new CanonicalSessionError({
217
- gap: CANONICAL_GAP.dispatch,
217
+ ground: { gap: CANONICAL_GAP.dispatch },
218
218
  reason: "refused",
219
219
  message: `Clipboard normalization failed: ${cause instanceof Error ? cause.message : String(cause)}`
220
220
  })
@@ -231,11 +231,15 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
231
231
  paragraphs.push(paragraph);
232
232
  }
233
233
  if (moveTarget === void 0 && (plain || sourceDocument === void 0)) flattenClipboardStyleReferences(paragraphs);
234
- if (state.selection instanceof CellSelection) return refuse("Pasting over selected cells requires a per-cell paste operation.");
235
- const selectionRange = canonicalSelectionRange(state);
236
- const from = session.projection.addressAt(pasteTarget ?? moveSource?.from ?? selectionRange.from);
234
+ const overCells = state.selection instanceof CellSelection && pasteTarget === void 0 && moveSource === void 0 && moveTarget === void 0;
235
+ if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.");
236
+ const selectionRange = overCells ? {
237
+ from: state.selection.from,
238
+ to: state.selection.to
239
+ } : canonicalSelectionRange(state);
240
+ const from = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.from ?? selectionRange.from);
237
241
  if (from.isErr()) return from;
238
- const to = session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
242
+ const to = overCells ? Result.ok(void 0) : session.projection.addressAt(pasteTarget ?? moveSource?.to ?? selectionRange.to);
239
243
  if (to.isErr()) return to;
240
244
  let styles = session.document.package.styles;
241
245
  let styleIds;
@@ -304,7 +308,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
304
308
  const parsed = Result.try({
305
309
  try: () => parseXml(xml, OOXML_NAMESPACE_SCOPE),
306
310
  catch: () => new CanonicalSessionError({
307
- gap: CANONICAL_GAP.dispatch,
311
+ ground: { gap: CANONICAL_GAP.dispatch },
308
312
  reason: "refused",
309
313
  message: "The clipboard hyperlink metadata is malformed."
310
314
  })
@@ -412,7 +416,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
412
416
  const decoded = Result.try({
413
417
  try: () => base64ToBytes(payload),
414
418
  catch: () => new CanonicalSessionError({
415
- gap: CANONICAL_GAP.dispatch,
419
+ ground: { gap: CANONICAL_GAP.dispatch },
416
420
  message: "The clipboard image data is malformed.",
417
421
  reason: "refused"
418
422
  })
@@ -466,12 +470,25 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
466
470
  after: imported
467
471
  }));
468
472
  }
473
+ const openStart = importedSlice.openStart === 0 ? 0 : 1;
474
+ const openEnd = importedSlice.openEnd === 0 ? 0 : 1;
475
+ if (from.value === void 0 || to.value === void 0) return session.prepareCellSelectionStructure(state, (at) => ({
476
+ type: "replaceFragment",
477
+ from: at,
478
+ to: at,
479
+ paragraphs,
480
+ openStart,
481
+ openEnd
482
+ }), {
483
+ resourceOps,
484
+ semantic: "paste"
485
+ });
469
486
  const fragment = {
470
487
  from: from.value,
471
488
  to: to.value,
472
489
  paragraphs,
473
- openStart: importedSlice.openStart === 0 ? 0 : 1,
474
- openEnd: importedSlice.openEnd === 0 ? 0 : 1
490
+ openStart,
491
+ openEnd
475
492
  };
476
493
  if (moveTarget === void 0) return session.prepareIntents(state, {
477
494
  intents: [{
@@ -197,7 +197,7 @@ const createCanonicalComposition = (options) => {
197
197
  const applyNative = (view, transaction) => Result.try({
198
198
  try: () => view.state.applyTransaction(transaction),
199
199
  catch: (cause) => new CanonicalSessionError({
200
- gap: CANONICAL_GAP.dispatch,
200
+ ground: { gap: CANONICAL_GAP.dispatch },
201
201
  reason: "refused",
202
202
  message: `Composition projection failed: ${String(cause)}`
203
203
  })
@@ -9,7 +9,7 @@ export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
9
9
  readonly moveFrom: "container";
10
10
  readonly moveTo: "container";
11
11
  readonly inlineWrapper: "container";
12
- readonly inlineSdt: "control";
12
+ readonly inlineSdt: "container";
13
13
  readonly simpleField: "leaf";
14
14
  readonly complexField: "leaf";
15
15
  readonly mathEquation: "leaf";
@@ -34,7 +34,7 @@ export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
34
34
  readonly instrText: "rawField";
35
35
  readonly softHyphen: "leaf";
36
36
  readonly noBreakHyphen: "leaf";
37
- readonly renderedPageBreak: "layout";
37
+ readonly renderedPageBreak: "leaf";
38
38
  readonly preservedXml: "leaf";
39
39
  readonly drawing: "leaf";
40
40
  readonly shape: "leaf";
@@ -58,8 +58,8 @@ export declare const CANONICAL_NATIVE_INLINE_POLICIES: {
58
58
  readonly tab: "unit";
59
59
  readonly textBoxAnchor: "unit";
60
60
  readonly commentReference: "unit";
61
- readonly renderedPageBreak: "refused";
62
- readonly sdt: "refused";
61
+ readonly renderedPageBreak: "markers";
62
+ readonly sdt: "control";
63
63
  };
64
64
  declare const InlineProjectionErrorBase: TaggedErrorClass<"InlineProjectionError">;
65
65
  declare class InlineProjectionError extends InlineProjectionErrorBase<{
@@ -98,20 +98,45 @@ export type CanonicalInlineGap = {
98
98
  position: number;
99
99
  zeroWidthBefore: number;
100
100
  };
101
+ /** The source ordinals one editor position stands for: from `first` to `last`. */
102
+ export type CanonicalSeamExtent = {
103
+ first: number;
104
+ last: number;
105
+ };
101
106
  type InlineProjection = {
102
107
  text: string;
103
108
  boundaries: CanonicalInlineGap[][];
109
+ /** Parallel to `boundaries`: each gap's whole seam. */
110
+ seams: CanonicalSeamExtent[][];
111
+ };
112
+ /** Whether a story holds an id: all a paragraph's projection asks of a story id set. */
113
+ export type StoryIdMembership = Pick<ReadonlySet<number>, "has">;
114
+ /** The story's comments as one paragraph's projection reads them. */
115
+ export type CanonicalInlineCommentContext = {
116
+ rangedIds: StoryIdMembership;
117
+ pointIds: StoryIdMembership;
118
+ /** The comment ranges open where the paragraph starts. */
119
+ openIds: ReadonlySet<number>;
104
120
  };
105
121
  type CanonicalInlineProjectionArgs = {
106
122
  source: document_d_exports.Paragraph;
107
123
  paragraph: Node;
108
- pairedBookmarkIds: ReadonlySet<number>;
109
- commentContext?: {
110
- rangedIds: ReadonlySet<number>;
111
- pointIds: ReadonlySet<number>;
112
- openIds: ReadonlySet<number>;
113
- };
124
+ pairedBookmarkIds: StoryIdMembership;
125
+ commentContext?: CanonicalInlineCommentContext;
114
126
  };
115
127
  /** Bind rendered gaps to the operation owner's source leaf ordinals, including collapsed pairs. */
116
128
  export declare const projectCanonicalInline: ({ source, paragraph, pairedBookmarkIds, commentContext }: CanonicalInlineProjectionArgs) => Result<InlineProjection, InlineProjectionError>;
129
+ /**
130
+ * Paragraph projections kept across projections of a story.
131
+ *
132
+ * A paragraph an edit left keeps its source records, and the block cache
133
+ * keeps its editor node, so its gaps can be reused where the story facts its
134
+ * projection read are the same: the comments open at its start and the
135
+ * comment and bookmark ids it asked about. Gap positions are relative to the
136
+ * paragraph, so a reused projection holds wherever the paragraph now starts.
137
+ */
138
+ export declare class InlineProjectionCache {
139
+ private paragraphs;
140
+ project(args: CanonicalInlineProjectionArgs): Result<InlineProjection, InlineProjectionError>;
141
+ }
117
142
  export {};