@stll/folio-core 0.67.0 → 0.69.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 (350) 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 +106 -36
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  7. package/dist/ai-edits/newListNumbering.js +24 -1
  8. package/dist/ai-edits/note-references.d.ts +6 -0
  9. package/dist/ai-edits/note-references.js +7 -1
  10. package/dist/ai-edits/pending-suggestions.js +2 -2
  11. package/dist/ai-edits/read.d.ts +19 -0
  12. package/dist/ai-edits/snapshot.d.ts +6 -0
  13. package/dist/ai-edits/snapshot.js +8 -3
  14. package/dist/ai-edits/types.d.ts +9 -1
  15. package/dist/ai-suggestions/apply.js +13 -4
  16. package/dist/compare/compare.js +2 -1
  17. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  18. package/dist/compare/inserted-resource-snapshot.js +7 -3
  19. package/dist/controller/canonicalClipboard.js +31 -14
  20. package/dist/controller/canonicalComposition.js +35 -6
  21. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  22. package/dist/controller/canonicalInlineProjection.js +192 -28
  23. package/dist/controller/canonicalInput.d.ts +2 -1
  24. package/dist/controller/canonicalInput.js +32 -7
  25. package/dist/controller/canonicalListRendering.d.ts +2 -1
  26. package/dist/controller/canonicalListRendering.js +1 -1
  27. package/dist/controller/canonicalLockGuard.d.ts +23 -0
  28. package/dist/controller/canonicalLockGuard.js +133 -0
  29. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  30. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  31. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  32. package/dist/controller/canonicalPublicOperations.js +676 -46
  33. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  34. package/dist/controller/canonicalSeedContent.js +131 -0
  35. package/dist/controller/canonicalSession.d.ts +133 -21
  36. package/dist/controller/canonicalSession.js +738 -205
  37. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  38. package/dist/controller/canonicalSourceNormalization.js +148 -0
  39. package/dist/controller/canonicalStoryEditor.d.ts +4 -3
  40. package/dist/controller/canonicalStoryEditor.js +20 -15
  41. package/dist/controller/canonicalStructure.d.ts +2 -1
  42. package/dist/controller/canonicalStructure.js +129 -7
  43. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  44. package/dist/controller/contentControlWidgetController.js +13 -1
  45. package/dist/controller/folioEditor.js +4 -0
  46. package/dist/controller/headerFooterEditorManager.d.ts +7 -2
  47. package/dist/controller/headerFooterEditorManager.js +11 -6
  48. package/dist/controller/hiddenEditorApi.d.ts +17 -2
  49. package/dist/controller/hiddenEditorApi.js +4 -0
  50. package/dist/controller/hiddenEditorManager.d.ts +11 -3
  51. package/dist/controller/hiddenEditorManager.js +157 -48
  52. package/dist/controller/layoutPipeline.js +50 -16
  53. package/dist/controller/layoutSession.d.ts +3 -0
  54. package/dist/controller/layoutSession.js +3 -1
  55. package/dist/controller/noteEditorManager.d.ts +7 -2
  56. package/dist/controller/noteEditorManager.js +11 -6
  57. package/dist/display-list/build/pageFurniture.js +41 -19
  58. package/dist/display-list/build/tablePrimitives.js +23 -4
  59. package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
  60. package/dist/document-operations.d.ts +9 -1
  61. package/dist/document-operations.js +4 -3
  62. package/dist/docx/blockContentParser.d.ts +7 -3
  63. package/dist/docx/blockContentParser.js +2 -3
  64. package/dist/docx/blockPlainText.js +2 -0
  65. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  66. package/dist/docx/bookmarkRangeJoin.js +43 -0
  67. package/dist/docx/canonicalSave.js +11 -2
  68. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  69. package/dist/docx/canonicalSessionInput.js +7 -2
  70. package/dist/docx/commentAnchorIndex.d.ts +40 -5
  71. package/dist/docx/commentAnchorIndex.js +94 -12
  72. package/dist/docx/commentRangeIntegrity.js +30 -24
  73. package/dist/docx/commentRangeJoin.d.ts +4 -0
  74. package/dist/docx/commentRangeJoin.js +26 -12
  75. package/dist/docx/commentReferenceCompletion.js +5 -4
  76. package/dist/docx/commentReferenceNormalization.js +40 -18
  77. package/dist/docx/compatibility.js +9 -2
  78. package/dist/docx/containerChildren.js +22 -1
  79. package/dist/docx/contentTypeRegistry.js +1 -1
  80. package/dist/docx/encryption/compoundFile.js +9 -1
  81. package/dist/docx/encryption/encryptionInfo.js +16 -2
  82. package/dist/docx/ensureParaIds.js +46 -7
  83. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  84. package/dist/docx/ensureUniqueControlIds.js +110 -0
  85. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  86. package/dist/docx/headerFooterVerbatim.js +13 -2
  87. package/dist/docx/hostCommentThreads.d.ts +27 -0
  88. package/dist/docx/hostCommentThreads.js +72 -0
  89. package/dist/docx/hyperlinkParser.js +9 -2
  90. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  91. package/dist/docx/inlineWrapperContent.js +9 -2
  92. package/dist/docx/listMarkerComputation.d.ts +35 -1
  93. package/dist/docx/listMarkerComputation.js +39 -1
  94. package/dist/docx/listModelNormalization.d.ts +44 -1
  95. package/dist/docx/listModelNormalization.js +226 -96
  96. package/dist/docx/listNumberingInstances.d.ts +1 -1
  97. package/dist/docx/listNumberingInstances.js +2 -2
  98. package/dist/docx/markupRangeMarker.d.ts +14 -0
  99. package/dist/docx/markupRangeMarker.js +15 -1
  100. package/dist/docx/metadataPrivacy.js +43 -22
  101. package/dist/docx/normalizeBaseDirection.js +3 -1
  102. package/dist/docx/numberingIds.d.ts +6 -0
  103. package/dist/docx/numberingIds.js +6 -1
  104. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  105. package/dist/docx/numberingReferenceNormalization.js +12 -2
  106. package/dist/docx/paragraphParser.js +159 -48
  107. package/dist/docx/paragraphPropertySource.d.ts +29 -0
  108. package/dist/docx/paragraphPropertySource.js +106 -16
  109. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  110. package/dist/docx/paragraphTraversal.js +2 -0
  111. package/dist/docx/parseWarningMessage.js +2 -1
  112. package/dist/docx/parser.js +8 -0
  113. package/dist/docx/removeHeaderFooterParts.js +1 -1
  114. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  115. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  116. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  117. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  118. package/dist/docx/reviewResolutionProvenance.js +171 -33
  119. package/dist/docx/rezip.d.ts +6 -0
  120. package/dist/docx/rezip.js +38 -21
  121. package/dist/docx/selectiveSave.js +6 -10
  122. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  123. package/dist/docx/selectiveXmlPatch.js +11 -7
  124. package/dist/docx/serializer/documentSerializer.js +5 -2
  125. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  126. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  127. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  128. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  129. package/dist/docx/serializer/noteSerializer.js +23 -16
  130. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  131. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  132. package/dist/docx/serializer/partNamespaces.js +1 -1
  133. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  134. package/dist/docx/serializer/runSerializer.js +2 -2
  135. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  136. package/dist/docx/serializer/tableSerializer.js +4 -2
  137. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  138. package/dist/docx/server/build.d.ts +1 -1
  139. package/dist/docx/server/createBilingualDocument.js +27 -5
  140. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  141. package/dist/docx/sessionListPruning.d.ts +2 -0
  142. package/dist/docx/sessionListPruning.js +50 -0
  143. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  144. package/dist/docx/splitRevisionPieces.js +14 -0
  145. package/dist/docx/storyBlockReplay.js +19 -2
  146. package/dist/docx/structuralXmlPatch.js +44 -11
  147. package/dist/docx/tableParser.d.ts +6 -2
  148. package/dist/docx/tableParser.js +2 -3
  149. package/dist/docx/textBoxContentParser.d.ts +11 -0
  150. package/dist/docx/textBoxContentParser.js +51 -0
  151. package/dist/docx/textBoxParser.d.ts +0 -5
  152. package/dist/docx/textBoxParser.js +1 -23
  153. package/dist/docx/verticalMergeProjection.js +1 -1
  154. package/dist/docx/xmlParser.d.ts +1 -1
  155. package/dist/docx/xmlParser.js +2 -3
  156. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  157. package/dist/fonts/fontsourceFaces.js +1 -7
  158. package/dist/i18n/messages/ar.gen.js +3 -0
  159. package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
  160. package/dist/i18n/messages/catalogs.gen.js +51 -0
  161. package/dist/i18n/messages/cs.gen.js +3 -0
  162. package/dist/i18n/messages/de.gen.js +3 -0
  163. package/dist/i18n/messages/en.gen.js +3 -0
  164. package/dist/i18n/messages/es.gen.js +3 -0
  165. package/dist/i18n/messages/et.gen.js +3 -0
  166. package/dist/i18n/messages/fr.gen.js +3 -0
  167. package/dist/i18n/messages/he.gen.js +3 -0
  168. package/dist/i18n/messages/hi.gen.js +3 -0
  169. package/dist/i18n/messages/hu.gen.js +3 -0
  170. package/dist/i18n/messages/lt.gen.js +3 -0
  171. package/dist/i18n/messages/lv.gen.js +3 -0
  172. package/dist/i18n/messages/messages.gen.d.ts +3 -0
  173. package/dist/i18n/messages/pl.gen.js +3 -0
  174. package/dist/i18n/messages/pt-BR.gen.js +3 -0
  175. package/dist/i18n/messages/sk.gen.js +3 -0
  176. package/dist/i18n/messages/tr.gen.js +3 -0
  177. package/dist/i18n/messages/zh-CN.gen.js +3 -0
  178. package/dist/internal/acceptedBlockProjection.js +2 -0
  179. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  180. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  181. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  182. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  183. package/dist/internal/revisionResolutionInline.js +1 -2
  184. package/dist/internal/subtreeHolds.d.ts +12 -0
  185. package/dist/internal/subtreeHolds.js +25 -0
  186. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  187. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  188. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  189. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  190. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  191. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  192. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  193. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  194. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  195. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  196. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  197. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  198. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  199. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  200. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  201. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  202. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  203. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  204. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  205. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  206. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  207. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  208. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  209. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  210. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  211. package/dist/layout-bridge/engine/hitTest.js +9 -10
  212. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  213. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  214. package/dist/layout-bridge/tableInsertHover.js +2 -1
  215. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  216. package/dist/layout-engine/footnoteContinuation.js +210 -0
  217. package/dist/layout-engine/index.d.ts +2 -2
  218. package/dist/layout-engine/index.js +7 -2
  219. package/dist/layout-engine/measure/cache.d.ts +2 -0
  220. package/dist/layout-engine/measure/cache.js +16 -6
  221. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  222. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  223. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  224. package/dist/layout-engine/tableLayout.js +29 -5
  225. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  226. package/dist/layout-engine/tableRowBreak.js +43 -1
  227. package/dist/layout-engine/types.d.ts +42 -1
  228. package/dist/layout-painter/imageLayout.js +2 -1
  229. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  230. package/dist/layout-painter/pageShellStyles.js +32 -0
  231. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  232. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  233. package/dist/layout-painter/renderFragment.js +4 -6
  234. package/dist/layout-painter/renderImage.js +2 -2
  235. package/dist/layout-painter/renderPage.d.ts +4 -4
  236. package/dist/layout-painter/renderPage.js +54 -46
  237. package/dist/layout-painter/renderParagraph.js +3 -3
  238. package/dist/layout-painter/renderTable.js +16 -16
  239. package/dist/layout-painter/renderTextBox.js +2 -2
  240. package/dist/layout-painter/sdtBoundary.js +3 -2
  241. package/dist/managers/AutoSaveManager.d.ts +5 -1
  242. package/dist/managers/FindReplaceManager.js +3 -10
  243. package/dist/markdown/escape.d.ts +20 -1
  244. package/dist/markdown/escape.js +43 -1
  245. package/dist/markdown/renderBlock.js +4 -1
  246. package/dist/markdown/renderParagraph.js +13 -27
  247. package/dist/markdown/renderTable.js +6 -2
  248. package/dist/markdown/trailers.js +1 -0
  249. package/dist/paged-layout/blockGeometry.js +3 -2
  250. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  251. package/dist/paged-layout/editorScrollRoot.js +10 -1
  252. package/dist/paged-layout/rangeProjection.js +5 -4
  253. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  254. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  255. package/dist/paged-layout/selectionViewportRect.js +8 -2
  256. package/dist/pdf/images.d.ts +17 -1
  257. package/dist/pdf/images.js +22 -4
  258. package/dist/pdf/writePdf.js +4 -2
  259. package/dist/prosemirror/attrs/index.js +2 -0
  260. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  261. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  262. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  263. package/dist/prosemirror/commands/comments.d.ts +30 -2
  264. package/dist/prosemirror/commands/comments.js +189 -18
  265. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  266. package/dist/prosemirror/commands/index.d.ts +1 -1
  267. package/dist/prosemirror/commentIdAllocator.js +2 -2
  268. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  269. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  270. package/dist/prosemirror/commentRecords.d.ts +137 -0
  271. package/dist/prosemirror/commentRecords.js +400 -0
  272. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  273. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  274. package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
  275. package/dist/prosemirror/conversion/index.d.ts +2 -2
  276. package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
  277. package/dist/prosemirror/conversion/toProseDoc.js +432 -76
  278. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  279. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  280. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  281. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  282. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  283. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
  284. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  285. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  286. package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
  287. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  288. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  289. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  290. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  291. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  292. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  293. package/dist/prosemirror/index.d.ts +3 -3
  294. package/dist/prosemirror/listLabels.js +3 -2
  295. package/dist/prosemirror/listNumbering.d.ts +6 -0
  296. package/dist/prosemirror/listNumbering.js +12 -9
  297. package/dist/prosemirror/lockedControls.d.ts +13 -0
  298. package/dist/prosemirror/lockedControls.js +106 -0
  299. package/dist/prosemirror/markupViewProjection.js +1 -1
  300. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  301. package/dist/prosemirror/nativeSelection.js +74 -0
  302. package/dist/prosemirror/noteReferenceReview.js +2 -2
  303. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  304. package/dist/prosemirror/numberedRefFields.js +16 -5
  305. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  306. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  307. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  308. package/dist/prosemirror/plugins/documentNumbering.js +37 -15
  309. package/dist/prosemirror/plugins/suggestionMode.js +33 -10
  310. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  311. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  312. package/dist/prosemirror/replacedAnnotations.js +1 -0
  313. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  314. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  315. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  316. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  317. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  318. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  319. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  320. package/dist/prosemirror/runStyleFormatting.js +16 -13
  321. package/dist/prosemirror/schema/marks.d.ts +13 -1
  322. package/dist/prosemirror/storyListNumbering.js +7 -2
  323. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  324. package/dist/prosemirror/tableResize.d.ts +10 -9
  325. package/dist/prosemirror/tableResize.js +60 -49
  326. package/dist/prosemirror/textInput.d.ts +30 -1
  327. package/dist/prosemirror/textInput.js +144 -17
  328. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  329. package/dist/prosemirror/validation.d.ts +19 -0
  330. package/dist/prosemirror/validation.js +79 -5
  331. package/dist/redline.js +23 -9
  332. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  333. package/dist/render-dom/RenderedDomContext.js +7 -6
  334. package/dist/server.d.ts +2 -2
  335. package/dist/style-sets/extract.js +2 -2
  336. package/dist/types/canonicalCapabilities.d.ts +38 -16
  337. package/dist/types/canonicalCapabilities.js +21 -18
  338. package/dist/utils/cssString.d.ts +7 -0
  339. package/dist/utils/cssString.js +9 -0
  340. package/dist/utils/findMatchView.js +4 -3
  341. package/dist/utils/fontResolver.js +4 -1
  342. package/dist/utils/formatToStyle.d.ts +1 -1
  343. package/dist/utils/mergeDocumentContent.js +2 -2
  344. package/dist/utils/paintedPositions.d.ts +60 -0
  345. package/dist/utils/paintedPositions.js +101 -0
  346. package/dist/utils/replaceText.d.ts +11 -0
  347. package/dist/utils/replaceText.js +39 -7
  348. package/dist/version-comparison.d.ts +9 -1
  349. package/dist/version-comparison.js +11 -5
  350. package/package.json +2 -3
@@ -0,0 +1,21 @@
1
+ import { OpStory } from "@stll/docx-core/ops";
2
+ import { BlockContent, Document } from "@stll/docx-core";
3
+ /** A story the session reads in its own form, with the blocks it was read with. */
4
+ type NormalizedStory = {
5
+ story: OpStory;
6
+ source: readonly BlockContent[];
7
+ };
8
+ /** A normalized story, with what it held when the session opened. */
9
+ export type CanonicalSourceRestore = NormalizedStory & {
10
+ opened: string;
11
+ };
12
+ /** The document in the session's own spelling, with every story it changed. */
13
+ export declare const normalizeCanonicalSource: (document: Document) => {
14
+ document: Document;
15
+ normalized: NormalizedStory[];
16
+ };
17
+ /** What each normalized story holds in the document the session opens. */
18
+ export declare const canonicalSourceRestores: (document: Document, normalized: readonly NormalizedStory[]) => CanonicalSourceRestore[];
19
+ /** The document with every story that still holds what it opened with given back as read. */
20
+ export declare const withUneditedSourceRestored: (document: Document, restores: readonly CanonicalSourceRestore[]) => Document;
21
+ export {};
@@ -0,0 +1,148 @@
1
+ import { canonicalJson } from "../utils/canonicalJson.js";
2
+ import { panic } from "better-result";
3
+ import { OP_STORIES, documentStories, findStoryBody, packageParagraphIds, replaceStoryBody, withBodyContent } from "@stll/docx-core/ops";
4
+ // src/controller/canonicalSourceNormalization.ts
5
+ /**
6
+ * Source spellings the canonical session reads in its own form, and gives back
7
+ * as read while their story is unedited.
8
+ *
9
+ * Two spellings carry a meaning the session models another way:
10
+ *
11
+ * - A literal tab character in `w:t`, which a reader shows as a tab: the
12
+ * session's model spells a tab as `w:tab`, so the text is split around it.
13
+ * - A story with no blocks (a header or a footer holding nothing): a story
14
+ * ends with a paragraph, the one a caret goes in, so the session gives it an
15
+ * empty one.
16
+ *
17
+ * Both are the session's model only. Each normalized story keeps the blocks it
18
+ * was read with, and a save of that story while it still holds what the
19
+ * session opened with writes those blocks, so the part keeps its source bytes.
20
+ * A story the user edits saves as edited, in the session's spelling.
21
+ */
22
+ const TAB = " ";
23
+ /** The run content with each literal tab in its text spelled as a tab element. */
24
+ const tabSpelledContent = (content) => {
25
+ const out = [];
26
+ for (const item of content) {
27
+ if (item.type !== "text" || !item.text.includes(TAB)) {
28
+ out.push(item);
29
+ continue;
30
+ }
31
+ item.text.split(TAB).forEach((part, index) => {
32
+ if (index > 0) out.push({ type: "tab" });
33
+ if (part !== "") out.push({
34
+ ...item,
35
+ text: part
36
+ });
37
+ });
38
+ }
39
+ return out;
40
+ };
41
+ const withTabElements = (run) => run.content.some((item) => item.type === "text" && item.text.includes(TAB)) ? {
42
+ ...run,
43
+ content: tabSpelledContent(run.content)
44
+ } : run;
45
+ const isPlainRecord = (value) => {
46
+ const prototype = Object.getPrototypeOf(value);
47
+ return prototype === Object.prototype || prototype === null;
48
+ };
49
+ /**
50
+ * `value` with every run's literal tabs spelled as tab elements, rebuilding
51
+ * only what changes. A run sits at any depth of inline content (inside a
52
+ * revision, a link, a field result, a content control), so the walk goes
53
+ * through every plain record and array and leaves everything else as it is.
54
+ */
55
+ const withRunTabElements = (value) => {
56
+ if (typeof value !== "object" || value === null) return value;
57
+ if (Array.isArray(value)) {
58
+ let changed = false;
59
+ const mapped = value.map((item) => {
60
+ const next = withRunTabElements(item);
61
+ if (next !== item) changed = true;
62
+ return next;
63
+ });
64
+ return changed ? mapped : value;
65
+ }
66
+ if (!isPlainRecord(value)) return value;
67
+ const changes = /* @__PURE__ */ new Map();
68
+ for (const [key, child] of Object.entries(value)) {
69
+ const mapped = withRunTabElements(child);
70
+ if (mapped !== child) changes.set(key, mapped);
71
+ }
72
+ let next = changes.size === 0 ? value : {
73
+ ...value,
74
+ ...Object.fromEntries(changes)
75
+ };
76
+ if (next["type"] === "run" && Array.isArray(next["content"])) next = withTabElements(next);
77
+ return next === value ? value : next;
78
+ };
79
+ /** The first id not in `used`, spelled as eight uppercase hex digits. */
80
+ const freshParaId = (used) => {
81
+ for (let candidate = 1; candidate < 2147483648; candidate += 1) {
82
+ const id = candidate.toString(16).toUpperCase().padStart(8, "0");
83
+ if (!used.has(id)) {
84
+ used.add(id);
85
+ return id;
86
+ }
87
+ }
88
+ return panic("Every paragraph id is in use.");
89
+ };
90
+ const isSeparatorNote = (document, story) => {
91
+ if (story === OP_STORIES.MAIN) return false;
92
+ if (story.kind !== "footnote" && story.kind !== "endnote") return false;
93
+ const note = (story.kind === "footnote" ? document.package.footnotes : document.package.endnotes)?.find(({ id }) => id === story.id);
94
+ return note?.noteType !== void 0 && note.noteType !== "normal";
95
+ };
96
+ /** The document in the session's own spelling, with every story it changed. */
97
+ const normalizeCanonicalSource = (document) => {
98
+ let current = document;
99
+ const normalized = [];
100
+ const used = new Set(packageParagraphIds(document.package).map((id) => id.toUpperCase()));
101
+ for (const story of documentStories(document)) {
102
+ const body = findStoryBody(current, story);
103
+ if (body === void 0) continue;
104
+ let content = withRunTabElements(body.content);
105
+ if (content.length === 0 && !isSeparatorNote(document, story)) content = [{
106
+ type: "paragraph",
107
+ paraId: freshParaId(used),
108
+ content: []
109
+ }];
110
+ if (content === body.content) continue;
111
+ normalized.push({
112
+ story,
113
+ source: body.content
114
+ });
115
+ current = replaceStoryBody({
116
+ document: current,
117
+ story,
118
+ body: withBodyContent(body, [...content])
119
+ });
120
+ }
121
+ return {
122
+ document: current,
123
+ normalized
124
+ };
125
+ };
126
+ /** What each normalized story holds in the document the session opens. */
127
+ const canonicalSourceRestores = (document, normalized) => normalized.flatMap((entry) => {
128
+ const body = findStoryBody(document, entry.story);
129
+ return body === void 0 ? [] : [{
130
+ ...entry,
131
+ opened: canonicalJson(body.content)
132
+ }];
133
+ });
134
+ /** The document with every story that still holds what it opened with given back as read. */
135
+ const withUneditedSourceRestored = (document, restores) => {
136
+ let current = document;
137
+ for (const { story, source, opened } of restores) {
138
+ const body = findStoryBody(current, story);
139
+ if (body === void 0 || canonicalJson(body.content) !== opened) continue;
140
+ current = replaceStoryBody({
141
+ document: current,
142
+ story,
143
+ body: withBodyContent(body, [...source])
144
+ });
145
+ }
146
+ return current;
147
+ };
148
+ export { canonicalSourceRestores, normalizeCanonicalSource, withUneditedSourceRestored };
@@ -1,15 +1,15 @@
1
- import { CanonicalGap } from "../types/canonicalCapabilities.js";
1
+ import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
2
2
  import { HiddenEditorApi } from "./hiddenEditorApi.js";
3
3
  import { Transaction } from "prosemirror-state";
4
- import { EditorView } from "prosemirror-view";
5
4
  import { OpStory } from "@stll/docx-core/ops";
5
+ import { EditorView } from "prosemirror-view";
6
6
  type CanonicalStoryEditorOptions = {
7
7
  story: OpStory;
8
8
  getView: () => EditorView;
9
9
  getApi: () => HiddenEditorApi | null;
10
10
  enabled: () => boolean;
11
11
  onSelectionChange: () => void;
12
- onRefusal: ((reason: string, gap: CanonicalGap) => void) | undefined;
12
+ onRefusal: ((reason: string, ground: CanonicalRefusalGround) => void) | undefined;
13
13
  };
14
14
  /** Secondary views compile classified native input into the shared Document journal. */
15
15
  export declare const createCanonicalStoryEditor: ({ story, getView, getApi, enabled, onRefusal, onSelectionChange }: CanonicalStoryEditorOptions) => {
@@ -17,6 +17,7 @@ export declare const createCanonicalStoryEditor: ({ story, getView, getApi, enab
17
17
  props: {
18
18
  handleKeyDown: (view: EditorView, event: KeyboardEvent) => boolean;
19
19
  handleTextInput: (view: EditorView, from: number, to: number, text: string) => boolean;
20
+ handleKeyPress: (view: EditorView, event: KeyboardEvent) => boolean;
20
21
  handleDOMEvents: {
21
22
  keydown: (view: EditorView, event: KeyboardEvent) => boolean;
22
23
  keyup: (view: EditorView, event: KeyboardEvent) => boolean;
@@ -1,16 +1,16 @@
1
+ import { adoptNativeSelection, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
1
2
  import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
2
3
  import { createCanonicalInputBoundary } from "./canonicalInput.js";
3
4
  import { CanonicalSessionError } from "./canonicalSession.js";
4
- import { AllSelection, TextSelection } from "prosemirror-state";
5
5
  // src/controller/canonicalStoryEditor.ts
6
6
  /** Secondary views compile classified native input into the shared Document journal. */
7
7
  const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal, onSelectionChange }) => {
8
8
  const refuse = (reason) => {
9
- const gap = CANONICAL_GAP.dispatch;
9
+ const ground = { gap: CANONICAL_GAP.dispatch };
10
10
  const message = reason;
11
- if (onRefusal) onRefusal(message, gap);
11
+ if (onRefusal) onRefusal(message, ground);
12
12
  else throw new CanonicalSessionError({
13
- gap,
13
+ ground,
14
14
  message,
15
15
  reason: "refused"
16
16
  });
@@ -26,15 +26,7 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
26
26
  return accepted;
27
27
  };
28
28
  const syncNativeSelection = (view) => {
29
- if (boundary.isComposing || view.composing) return;
30
- const selection = view.dom.ownerDocument.getSelection();
31
- if (!selection?.anchorNode || !selection.focusNode || !view.dom.contains(selection.anchorNode) || !view.dom.contains(selection.focusNode)) return;
32
- const anchor = view.posAtDOM(selection.anchorNode, selection.anchorOffset);
33
- const head = view.posAtDOM(selection.focusNode, selection.focusOffset);
34
- if (view.state.selection instanceof AllSelection && Math.min(anchor, head) === 0 && Math.max(anchor, head) === view.state.doc.content.size) return;
35
- if (anchor === view.state.selection.anchor && head === view.state.selection.head) return;
36
- if (!view.state.doc.resolve(anchor).parent.inlineContent || !view.state.doc.resolve(head).parent.inlineContent) return;
37
- view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, anchor, head)));
29
+ if (!boundary.isComposing) adoptNativeSelection(view);
38
30
  };
39
31
  const boundary = createCanonicalInputBoundary({
40
32
  breakUndoGroup: () => {
@@ -60,6 +52,10 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
60
52
  dispatch: (transaction) => {
61
53
  if (!enabled()) return false;
62
54
  const view = getView();
55
+ getApi()?.noteCanonicalStoryView({
56
+ story,
57
+ view
58
+ });
63
59
  if (transaction.docChanged) {
64
60
  if (boundary.acceptComposition(view, transaction)) return true;
65
61
  if (!boundary.commitNativeProposal(view, transaction)) boundary.refuseNativeMutation(view);
@@ -80,8 +76,13 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
80
76
  props: {
81
77
  handleKeyDown: (view, event) => enabled() && boundary.handleKeyDown(view, event),
82
78
  handleTextInput: (view, from, to, text) => enabled() && boundary.handleTextInput(view, from, to, text),
79
+ handleKeyPress: (view, event) => enabled() && boundary.handleKeyPress(view, event),
83
80
  handleDOMEvents: {
84
- keydown: (view, event) => enabled() && boundary.handleDOMEvents.keydown(view, event),
81
+ keydown: (view, event) => {
82
+ if (!enabled()) return false;
83
+ if (!isCompositionKeyDown(event)) syncNativeSelection(view);
84
+ return boundary.handleDOMEvents.keydown(view, event);
85
+ },
85
86
  keyup: (view, event) => {
86
87
  if (enabled() && /^(?:Arrow|Home$|End$|Page)/u.test(event.key)) syncNativeSelection(view);
87
88
  return false;
@@ -90,7 +91,11 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal
90
91
  if (enabled()) syncNativeSelection(view);
91
92
  return false;
92
93
  },
93
- beforeinput: (view, event) => enabled() && boundary.handleDOMEvents.beforeinput(view, event),
94
+ beforeinput: (view, event) => {
95
+ if (!enabled()) return false;
96
+ if (!event.isComposing) syncNativeSelection(view);
97
+ return boundary.handleDOMEvents.beforeinput(view, event);
98
+ },
94
99
  mousedown: (view) => enabled() && boundary.handleDOMEvents.mousedown(view),
95
100
  compositionstart: (view) => enabled() && boundary.handleDOMEvents.compositionstart(view),
96
101
  compositionend: (view, event) => enabled() && boundary.handleDOMEvents.compositionend(view, event),
@@ -1,7 +1,8 @@
1
- import { CanonicalCommit, CanonicalSession, CanonicalSessionError } from "./canonicalSession.js";
2
1
  import { CanonicalCommandIntent } from "../prosemirror/canonicalCommands.js";
2
+ import { CanonicalCommit, CanonicalSession, CanonicalSessionError } from "./canonicalSession.js";
3
3
  import { EditorState } from "prosemirror-state";
4
4
  import { Result } from "better-result";
5
+ export declare const CELL_SELECTION_PLACEMENT_REFUSAL = "A note or table of contents goes at a caret, not over selected cells.";
5
6
  /** Toolbar meanings enter the same operation journal as native input. */
6
7
  export declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState, commands: readonly CanonicalCommandIntent[]) => Result<CanonicalCommit, CanonicalSessionError>;
7
8
  type CanonicalAutoformatInput = {
@@ -2,13 +2,16 @@ import { BUILT_IN_STYLE_NAME, createBuiltInStyleIndex } from "../docx/builtInSty
2
2
  import { createNote } from "../docx/noteReferenceMark.js";
3
3
  import { getCachedNumberingMap, numberingLevelUsesBulletMarker } from "../docx/numberingParser.js";
4
4
  import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySource.js";
5
+ import { visitDocxParagraphs } from "../docx/paragraphTraversal.js";
5
6
  import { listRequestsForMarker } from "../prosemirror/listAutoformatMarkers.js";
7
+ import { unusedListInstanceFor } from "../prosemirror/listNumbering.js";
6
8
  import { effectiveParagraphNumbering, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
7
9
  import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
8
10
  import { collectHeadings } from "../utils/headingCollector.js";
9
11
  import { CanonicalSessionError } from "./canonicalSession.js";
10
12
  import { Result, panic } from "better-result";
11
13
  import { headingOutlineLevel, paragraphNumberingReference } from "@stll/docx-core/model";
14
+ import { CellSelection } from "prosemirror-tables";
12
15
  import { DOCUMENT_OP_TYPES, OP_STORIES, editorParagraphGroups, editorPositionAtPhysicalPosition, physicalPositionAtEditorOffset } from "@stll/docx-core/ops";
13
16
  // src/controller/canonicalStructure.ts
14
17
  const DEFAULT_TOC_PAGE_WIDTH_TWIPS = 12240;
@@ -23,13 +26,14 @@ const currentSectionEndpoint = (paragraph) => {
23
26
  if (Object.hasOwn(paragraph, "sectionProperties")) return { type: "undefined" };
24
27
  return { type: "omitted" };
25
28
  };
29
+ const CELL_SELECTION_PLACEMENT_REFUSAL = "A note or table of contents goes at a caret, not over selected cells.";
26
30
  const refuse = (message) => Result.err(new CanonicalSessionError({
27
- gap: CANONICAL_GAP.commands,
31
+ ground: { gap: CANONICAL_GAP.commands },
28
32
  message,
29
33
  reason: "refused"
30
34
  }));
31
35
  const noChange = (message) => Result.err(new CanonicalSessionError({
32
- gap: CANONICAL_GAP.commands,
36
+ ground: { gap: CANONICAL_GAP.commands },
33
37
  message,
34
38
  reason: "noChange"
35
39
  }));
@@ -51,7 +55,7 @@ const effectiveNumbering = (paragraph) => effectiveParagraphNumbering(paragraphN
51
55
  numPr: paragraph?.formatting?.numPr,
52
56
  numPrFromStyle: paragraph?.formatting?.numPrFromStyle
53
57
  }));
54
- /** List structure is local to the block container that owns each paragraph. */
58
+ /** Each selected paragraph with the block container that owns it. A list may run through several containers, such as table cells, as the editor applies it. */
55
59
  const paragraphPositions = (session, paragraphs) => {
56
60
  if (paragraphs.length === 0) return noChange("List changes require a paragraph selection.");
57
61
  const positions = [];
@@ -66,10 +70,38 @@ const paragraphPositions = (session, paragraphs) => {
66
70
  paragraph
67
71
  });
68
72
  }
69
- const container = positions.at(0)?.container;
70
- if (positions.some((position) => position.container !== container)) return refuse("A list command cannot span multiple block containers.");
71
73
  return Result.ok(positions);
72
74
  };
75
+ /** Content a paragraph keeps no trace of once its pending changes are accepted. */
76
+ const GONE_ON_ACCEPT = /* @__PURE__ */ new Set([
77
+ "deletion",
78
+ "moveFrom",
79
+ "bookmarkStart",
80
+ "bookmarkEnd",
81
+ "commentRangeStart",
82
+ "commentRangeEnd",
83
+ "moveFromRangeStart",
84
+ "moveFromRangeEnd",
85
+ "moveToRangeStart",
86
+ "moveToRangeEnd"
87
+ ]);
88
+ /** A paragraph accepting removes: its mark and every character are going. */
89
+ const goesOnAccept = (paragraph) => (paragraph.pPrMark?.kind === "del" || paragraph.pPrMark?.kind === "moveFrom") && paragraph.content.every(({ type }) => GONE_ON_ACCEPT.has(type));
90
+ /**
91
+ * Every list instance a paragraph of the main story refers to once its pending
92
+ * changes are accepted: directly, through its style, or in a pending property
93
+ * change. A paragraph on its way out refers to nothing, so typing a list
94
+ * marker over a struck list takes the instance editing would.
95
+ */
96
+ const referencedNumIds = (document) => {
97
+ const referenced = /* @__PURE__ */ new Set();
98
+ visitDocxParagraphs({ documentBody: document.package.document }, (paragraph) => {
99
+ if (goesOnAccept(paragraph)) return;
100
+ for (const numPr of [paragraph.formatting?.numPr, paragraph.formatting?.numPrFromStyle]) if (numPr?.kind === "reference") referenced.add(numPr.numId);
101
+ for (const change of paragraph.propertyChanges ?? []) if (change.previousFormatting?.numPr?.kind === "reference") referenced.add(change.previousFormatting.numPr.numId);
102
+ });
103
+ return referenced;
104
+ };
73
105
  const numberingIntent = (session, positions, request) => {
74
106
  const definitions = session.document.package.numbering;
75
107
  const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
@@ -77,7 +109,7 @@ const numberingIntent = (session, positions, request) => {
77
109
  const first = positions.at(0)?.index ?? 0;
78
110
  const last = positions.at(-1)?.index ?? first;
79
111
  const neighbor = [first > 0 ? container.at(first - 1) : void 0, container.at(last + 1)].find((item) => {
80
- if (item?.type !== "paragraph" || item.formatting?.numPr?.kind !== "reference" || item.formatting.numPrFromStyle !== void 0) return false;
112
+ if (item?.type !== "paragraph" || goesOnAccept(item) || item.formatting?.numPr?.kind !== "reference" || item.formatting.numPrFromStyle !== void 0) return false;
81
113
  const level = map?.getLevel(item.formatting.numPr.numId, item.formatting.numPr.ilvl ?? 0);
82
114
  if (level == null || numberingLevelUsesBulletMarker(level) !== (request.kind === "bullet")) return false;
83
115
  return request.format === void 0 || level.numFmt === request.format.numFmt && level.lvlText === request.format.lvlText;
@@ -85,6 +117,7 @@ const numberingIntent = (session, positions, request) => {
85
117
  let numId;
86
118
  let ilvl = 0;
87
119
  let target;
120
+ const unused = map === void 0 ? void 0 : unusedListInstanceFor(map, referencedNumIds(session.document), request);
88
121
  if (neighbor?.type === "paragraph" && neighbor.formatting?.numPr?.kind === "reference") {
89
122
  numId = neighbor.formatting.numPr.numId;
90
123
  ilvl = neighbor.formatting.numPr.ilvl ?? 0;
@@ -92,6 +125,12 @@ const numberingIntent = (session, positions, request) => {
92
125
  type: "existing",
93
126
  numId
94
127
  };
128
+ } else if (unused !== void 0) {
129
+ numId = unused;
130
+ target = {
131
+ type: "existing",
132
+ numId
133
+ };
95
134
  } else {
96
135
  numId = Math.max(0, ...definitions?.nums.map((num) => num.numId) ?? []) + 1;
97
136
  const abstractNumId = Math.max(-1, ...definitions?.abstractNums.map((num) => num.abstractNumId) ?? []) + 1;
@@ -135,6 +174,7 @@ const numberingIntent = (session, positions, request) => {
135
174
  };
136
175
  /** Toolbar meanings enter the same operation journal as native input. */
137
176
  const prepareCanonicalCommands = (session, state, commands) => {
177
+ if (state.selection instanceof CellSelection && commands.some(({ type }) => type === "generateTOC" || type === "insertNote" || type === "deleteNote")) return refuse(CELL_SELECTION_PLACEMENT_REFUSAL);
138
178
  const intents = [];
139
179
  const sectionCommands = commands.filter((command) => command.type === "setSectionBreak" || command.type === "removeSectionBreak");
140
180
  if (sectionCommands.length > 0) {
@@ -248,6 +288,88 @@ const prepareCanonicalCommands = (session, state, commands) => {
248
288
  });
249
289
  break;
250
290
  }
291
+ case "formatTable":
292
+ for (const target of command.targets) {
293
+ const at = session.projection.addressAt(target.at);
294
+ if (at.isErr()) return at;
295
+ const address = {
296
+ story: at.value.story,
297
+ blockId: at.value.blockId
298
+ };
299
+ switch (target.scope) {
300
+ case "table":
301
+ intents.push({
302
+ type: "table",
303
+ operation: {
304
+ type: DOCUMENT_OP_TYPES.SET_TABLE_PROPS,
305
+ ...address,
306
+ patch: target.patch
307
+ }
308
+ });
309
+ break;
310
+ case "row":
311
+ intents.push({
312
+ type: "table",
313
+ operation: {
314
+ type: DOCUMENT_OP_TYPES.SET_ROW_PROPS,
315
+ ...address,
316
+ patch: target.patch
317
+ }
318
+ });
319
+ break;
320
+ case "cell":
321
+ intents.push({
322
+ type: "table",
323
+ operation: {
324
+ type: DOCUMENT_OP_TYPES.SET_CELL_PROPS,
325
+ ...address,
326
+ patch: target.patch
327
+ }
328
+ });
329
+ break;
330
+ default: return target;
331
+ }
332
+ }
333
+ break;
334
+ case "editTableBlock": {
335
+ const at = session.projection.addressAt(command.at);
336
+ if (at.isErr()) return at;
337
+ intents.push({
338
+ type: "tableBlock",
339
+ operation: {
340
+ ...command.edit,
341
+ story: at.value.story,
342
+ blockId: at.value.blockId
343
+ }
344
+ });
345
+ break;
346
+ }
347
+ case "editTableRow": {
348
+ const at = session.projection.addressAt(command.at);
349
+ if (at.isErr()) return at;
350
+ intents.push({
351
+ type: "tableRow",
352
+ operation: {
353
+ ...command.edit,
354
+ story: at.value.story,
355
+ blockId: at.value.blockId
356
+ }
357
+ });
358
+ break;
359
+ }
360
+ case "editTable": {
361
+ const at = session.projection.addressAt(command.at);
362
+ if (at.isErr()) return at;
363
+ intents.push({
364
+ type: "table",
365
+ operation: {
366
+ ...command.edit,
367
+ story: at.value.story,
368
+ blockId: at.value.blockId
369
+ }
370
+ });
371
+ break;
372
+ }
251
373
  case "insertBreak": {
252
374
  const from = session.projection.addressAt(command.from);
253
375
  if (from.isErr()) return from;
@@ -473,4 +595,4 @@ const prepareCanonicalAutoformat = (session, state, { from, to, text }) => {
473
595
  text: ""
474
596
  }, paragraphIntent] });
475
597
  };
476
- export { prepareCanonicalAutoformat, prepareCanonicalCommands };
598
+ export { CELL_SELECTION_PLACEMENT_REFUSAL, prepareCanonicalAutoformat, prepareCanonicalCommands };
@@ -27,6 +27,11 @@ export type ContentControlWidgetControllerOptions = {
27
27
  kind: "refused";
28
28
  }>) => void) | undefined;
29
29
  };
30
+ /**
31
+ * The picker's choices: one per stored value, the first item that has it. A
32
+ * pick is applied by value, and the value names its first item, so a later
33
+ * item sharing that value would show one label and write another.
34
+ */
30
35
  export declare const parseContentControlListItems: (raw: string | undefined) => ContentControlListItem[];
31
36
  export declare class ContentControlWidgetController extends Subscribable<ContentControlWidgetSnapshot> {
32
37
  private readonly options;
@@ -8,6 +8,11 @@ const isListItem = (value) => {
8
8
  if (!("displayText" in value) || !("value" in value)) return false;
9
9
  return typeof value.displayText === "string" && typeof value.value === "string";
10
10
  };
11
+ /**
12
+ * The picker's choices: one per stored value, the first item that has it. A
13
+ * pick is applied by value, and the value names its first item, so a later
14
+ * item sharing that value would show one label and write another.
15
+ */
11
16
  const parseContentControlListItems = (raw) => {
12
17
  if (!raw) return [];
13
18
  let parsed;
@@ -17,7 +22,14 @@ const parseContentControlListItems = (raw) => {
17
22
  return [];
18
23
  }
19
24
  if (!Array.isArray(parsed)) return [];
20
- return parsed.filter(isListItem);
25
+ const values = /* @__PURE__ */ new Set();
26
+ const items = [];
27
+ for (const item of parsed) {
28
+ if (!isListItem(item) || values.has(item.value)) continue;
29
+ values.add(item.value);
30
+ items.push(item);
31
+ }
32
+ return items;
21
33
  };
22
34
  const pickerPosition = (event) => {
23
35
  const rect = event.anchor.getBoundingClientRect();
@@ -29,6 +29,9 @@ const createFolioEditor = (deps) => {
29
29
  getCanonicalStorySelection: (story) => deps.getEditorApi()?.getCanonicalStorySelection(story) ?? null,
30
30
  getCanonicalStoryProjection: (story) => deps.getEditorApi()?.getCanonicalStoryProjection(story) ?? null,
31
31
  replaceCanonicalStoryText: (options) => deps.getEditorApi()?.replaceCanonicalStoryText(options) ?? false,
32
+ noteCanonicalStoryView: (options) => {
33
+ deps.getEditorApi()?.noteCanonicalStoryView(options);
34
+ },
32
35
  isCanonicalSaveCurrent: (version) => deps.getEditorApi()?.isCanonicalSaveCurrent(version) ?? false,
33
36
  captureCanonicalSave: () => deps.getEditorApi()?.captureCanonicalSave() ?? null,
34
37
  applyCanonicalDocumentOperations: (options) => deps.getEditorApi()?.applyCanonicalDocumentOperations(options) ?? null,
@@ -38,6 +41,7 @@ const createFolioEditor = (deps) => {
38
41
  getCanonicalDocument: () => deps.getEditorApi()?.getCanonicalDocument() ?? null,
39
42
  setCanonicalMode: (mode) => deps.getEditorApi()?.setCanonicalMode(mode) ?? false,
40
43
  resolveCanonicalRevisions: (revisionIds, resolution) => deps.getEditorApi()?.resolveCanonicalRevisions(revisionIds, resolution) ?? false,
44
+ resolveCanonicalSuggestion: (suggestionId, resolution, author) => deps.getEditorApi()?.resolveCanonicalSuggestion(suggestionId, resolution, author) ?? false,
41
45
  focus: () => deps.getEditorApi()?.focus(),
42
46
  blur: () => deps.getEditorApi()?.blur(),
43
47
  isFocused: () => deps.getEditorApi()?.isFocused() ?? false,
@@ -1,5 +1,5 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { CanonicalGap } from "../types/canonicalCapabilities.js";
2
+ import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
3
3
  import { HiddenEditorApi } from "./hiddenEditorApi.js";
4
4
  import { DirectEditorProps, EditorView } from "prosemirror-view";
5
5
  export type HeaderFooterPartKind = "header" | "footer";
@@ -19,8 +19,13 @@ export type HeaderFooterEditorManagerDeps = {
19
19
  getDocument: () => document_d_exports.Document | null;
20
20
  getReadOnly?: (() => boolean) | undefined;
21
21
  getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
22
+ /**
23
+ * The canonical session's own document, read without a copy (see
24
+ * `HiddenEditorManager.readCanonicalDocument`); null outside a session.
25
+ */
26
+ readCanonicalDocument: () => document_d_exports.Document | null;
22
27
  getExperimentalSession?: (() => "canonical" | undefined) | undefined;
23
- onSessionRefusal?: ((reason: string, gap: CanonicalGap, error?: Error) => void) | undefined;
28
+ onSessionRefusal?: ((reason: string, ground: CanonicalRefusalGround, error?: Error) => void) | undefined;
24
29
  getHost: () => HTMLElement | null;
25
30
  getStyles: () => document_d_exports.StyleDefinitions | null | undefined;
26
31
  getTheme: () => document_d_exports.Theme | null | undefined;
@@ -6,6 +6,7 @@ import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js"
6
6
  import { createStarterKit } from "../prosemirror/extensions/StarterKit.js";
7
7
  import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
8
8
  import { ensureParaIdsInState } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
9
+ import { createNativeSelectionRefreshPlugin } from "../prosemirror/nativeSelection.js";
9
10
  import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
10
11
  import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
11
12
  import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
@@ -39,9 +40,9 @@ const buildInitialState = (headerFooter, styles, theme, numbering, manager) => {
39
40
  doc: document,
40
41
  schema,
41
42
  plugins: [
43
+ createDocumentNumberingPlugin(numbering),
42
44
  ...manager.getPlugins(),
43
- createDocumentStylesPlugin(styles),
44
- createDocumentNumberingPlugin(numbering)
45
+ createDocumentStylesPlugin(styles)
45
46
  ]
46
47
  })));
47
48
  };
@@ -80,7 +81,7 @@ const createHeaderFooterEditorManager = (deps) => {
80
81
  for (const part of mounted.values()) destroyMounted(part);
81
82
  mounted.clear();
82
83
  };
83
- const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.getCanonicalApi?.()?.getCanonicalDocument() ?? null : deps.getDocument();
84
+ const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.readCanonicalDocument() : deps.getDocument();
84
85
  const sync = () => {
85
86
  const host = deps.getHost();
86
87
  if (!host) return;
@@ -184,7 +185,11 @@ const createHeaderFooterEditorManager = (deps) => {
184
185
  editable: () => !(deps.getReadOnly?.() ?? false),
185
186
  state: canonicalProjection ? EditorState.create({
186
187
  doc: canonicalProjection,
187
- plugins: [createDocumentStyleContextPlugin(styles), createDocumentNumberingPlugin(numbering)]
188
+ plugins: [
189
+ createDocumentNumberingPlugin(numbering),
190
+ createDocumentStyleContextPlugin(styles),
191
+ createNativeSelectionRefreshPlugin()
192
+ ]
188
193
  }) : buildInitialState(headerFooter, styles, theme, numbering, manager),
189
194
  dispatchTransaction(transaction) {
190
195
  if ((deps.getReadOnly?.() ?? false) && transaction.docChanged) return;
@@ -192,7 +197,7 @@ const createHeaderFooterEditorManager = (deps) => {
192
197
  const nextState = view.state.apply(transaction);
193
198
  const docChanged = !nextState.doc.eq(view.state.doc);
194
199
  const noteIssue = noteReferenceTransactionIssue(transaction);
195
- if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, CANONICAL_GAP.dispatch, noteIssue);
200
+ if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
196
201
  view.updateState(nextState);
197
202
  const mountedPart = mounted.get(part.rId);
198
203
  if (mountedPart && docChanged) mountedPart.dirty = true;
@@ -232,7 +237,7 @@ const createHeaderFooterEditorManager = (deps) => {
232
237
  const canonical = deps.getCanonicalApi?.()?.getCanonicalDocument();
233
238
  if (canonical) return canonical;
234
239
  throw new CanonicalSessionError({
235
- gap: CANONICAL_GAP.authorityRouting,
240
+ ground: { gap: CANONICAL_GAP.authorityRouting },
236
241
  reason: "refused",
237
242
  message: "Canonical story snapshot is unavailable."
238
243
  });