@stll/folio-core 0.42.0 → 0.44.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 (206) hide show
  1. package/dist/ai-edits/headless.js +6 -5
  2. package/dist/ai-edits/index.d.ts +2 -2
  3. package/dist/ai-edits/index.js +2 -2
  4. package/dist/ai-edits/snapshot.js +13 -9
  5. package/dist/compare/content-alignment.js +16 -1
  6. package/dist/compare/inline-atoms.js +1 -1
  7. package/dist/compare/style-resources.js +6 -0
  8. package/dist/compat/eigenpal.d.ts +2 -2
  9. package/dist/controller/layoutPipeline.d.ts +2 -1
  10. package/dist/controller/layoutPipeline.js +5 -2
  11. package/dist/controller/layoutSession.d.ts +2 -1
  12. package/dist/controller/layoutSession.js +1 -0
  13. package/dist/docx/appVersionNormalization.d.ts +0 -18
  14. package/dist/docx/blockContentParser.js +10 -1
  15. package/dist/docx/blockRangeMarkers.d.ts +36 -0
  16. package/dist/docx/blockRangeMarkers.js +59 -0
  17. package/dist/docx/bookmarkParser.d.ts +2 -20
  18. package/dist/docx/bookmarkParser.js +6 -30
  19. package/dist/docx/borderParser.d.ts +13 -0
  20. package/dist/docx/borderParser.js +71 -0
  21. package/dist/docx/builtInStyles.d.ts +165 -0
  22. package/dist/docx/builtInStyles.js +239 -0
  23. package/dist/docx/commentIdNormalization.d.ts +10 -0
  24. package/dist/docx/commentIdNormalization.js +33 -0
  25. package/dist/docx/commentParser.d.ts +2 -1
  26. package/dist/docx/commentParser.js +34 -7
  27. package/dist/docx/commentReferenceNormalization.d.ts +4 -1
  28. package/dist/docx/commentReferenceNormalization.js +23 -14
  29. package/dist/docx/danglingRelationshipReferences.d.ts +15 -0
  30. package/dist/docx/danglingRelationshipReferences.js +30 -0
  31. package/dist/docx/defaultParagraphStyle.d.ts +39 -0
  32. package/dist/docx/defaultParagraphStyle.js +54 -0
  33. package/dist/docx/documentParser.d.ts +2 -1
  34. package/dist/docx/documentParser.js +2 -2
  35. package/dist/docx/drawingUtils.d.ts +8 -1
  36. package/dist/docx/drawingUtils.js +12 -3
  37. package/dist/docx/fieldParser.js +3 -5
  38. package/dist/docx/footnoteParser.d.ts +3 -2
  39. package/dist/docx/footnoteParser.js +19 -2
  40. package/dist/docx/groupDrawingParser.js +1 -1
  41. package/dist/docx/headerFooterRefParser.d.ts +15 -3
  42. package/dist/docx/headerFooterRefParser.js +51 -14
  43. package/dist/docx/headerFooterReferenceNormalization.d.ts +4 -1
  44. package/dist/docx/headerFooterReferenceNormalization.js +5 -1
  45. package/dist/docx/hyperlinkParser.js +11 -15
  46. package/dist/docx/imageParser.d.ts +1 -1
  47. package/dist/docx/imageParser.js +22 -18
  48. package/dist/docx/imageRawXml.js +5 -5
  49. package/dist/docx/markupRangeMarker.d.ts +15 -0
  50. package/dist/docx/markupRangeMarker.js +44 -0
  51. package/dist/docx/noteReferenceStyles.d.ts +29 -0
  52. package/dist/docx/noteReferenceStyles.js +70 -0
  53. package/dist/docx/numberingParser.js +2 -1
  54. package/dist/docx/numberingReference.d.ts +21 -0
  55. package/dist/docx/numberingReference.js +21 -0
  56. package/dist/docx/numberingReferenceNormalization.d.ts +14 -2
  57. package/dist/docx/numberingReferenceNormalization.js +51 -9
  58. package/dist/docx/paraIdRangeNormalization.d.ts +0 -19
  59. package/dist/docx/paragraphParser.js +69 -101
  60. package/dist/docx/paragraphPropertySource.js +1 -0
  61. package/dist/docx/paragraphTraversal.d.ts +37 -1
  62. package/dist/docx/paragraphTraversal.js +84 -1
  63. package/dist/docx/parseContext.d.ts +37 -0
  64. package/dist/docx/parseContext.js +67 -0
  65. package/dist/docx/parseWarningMessage.d.ts +6 -0
  66. package/dist/docx/parseWarningMessage.js +44 -0
  67. package/dist/docx/parser.js +86 -24
  68. package/dist/docx/relsParser.d.ts +28 -11
  69. package/dist/docx/relsParser.js +26 -13
  70. package/dist/docx/revisionIdNormalization.js +81 -7
  71. package/dist/docx/rezip.js +85 -27
  72. package/dist/docx/runConsolidator.js +1 -2
  73. package/dist/docx/runParser.d.ts +8 -1
  74. package/dist/docx/runParser.js +30 -48
  75. package/dist/docx/sectionParser.d.ts +2 -1
  76. package/dist/docx/sectionParser.js +21 -65
  77. package/dist/docx/serializer/borderSerializer.d.ts +1 -2
  78. package/dist/docx/serializer/commentSerializer.js +22 -9
  79. package/dist/docx/serializer/documentSerializer.d.ts +1 -5
  80. package/dist/docx/serializer/documentSerializer.js +6 -16
  81. package/dist/docx/serializer/headerFooterSerializer.js +5 -0
  82. package/dist/docx/serializer/markupRangeAttributes.d.ts +8 -0
  83. package/dist/docx/serializer/markupRangeAttributes.js +24 -0
  84. package/dist/docx/serializer/noteSerializer.js +5 -0
  85. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -5
  86. package/dist/docx/serializer/paragraphSerializer.js +29 -35
  87. package/dist/docx/serializer/runSerializer.js +13 -7
  88. package/dist/docx/serializer/tableSerializer.js +28 -13
  89. package/dist/docx/serializer/textFormattingSerializer.d.ts +2 -3
  90. package/dist/docx/server/build.js +8 -1
  91. package/dist/docx/server/createBilingualDocument.js +15 -22
  92. package/dist/docx/server/extractDocxText.js +3 -4
  93. package/dist/docx/shadingParser.d.ts +6 -0
  94. package/dist/docx/shadingParser.js +32 -0
  95. package/dist/docx/shapeParser.js +3 -3
  96. package/dist/docx/styleParser.js +15 -89
  97. package/dist/docx/styleReferenceResolution.d.ts +36 -0
  98. package/dist/docx/styleReferenceResolution.js +51 -0
  99. package/dist/docx/tableLook.d.ts +57 -0
  100. package/dist/docx/tableLook.js +63 -0
  101. package/dist/docx/tableParser.d.ts +7 -9
  102. package/dist/docx/tableParser.js +64 -110
  103. package/dist/docx/textBoxParser.js +4 -4
  104. package/dist/docx/trackedMoveRangeNormalization.d.ts +3 -1
  105. package/dist/docx/trackedMoveRangeNormalization.js +11 -21
  106. package/dist/docx/transitionalSpelling.d.ts +13 -2
  107. package/dist/docx/transitionalSpelling.js +23 -1
  108. package/dist/docx/verbatimCapture.js +4 -11
  109. package/dist/docx/vmlImageParser.js +2 -2
  110. package/dist/docx/watermarkParser.js +2 -2
  111. package/dist/docx/xmlParser.d.ts +22 -32
  112. package/dist/docx/xmlParser.js +36 -21
  113. package/dist/index.d.ts +2 -2
  114. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +2 -0
  115. package/dist/internal/pageBreakRunSourceDescendantIndex.js +9 -6
  116. package/dist/internal/paragraphFormattingSerialization.d.ts +2 -3
  117. package/dist/internal/paragraphFormattingSerialization.js +26 -6
  118. package/dist/layout-bridge/convert/footnoteLayout.js +2 -7
  119. package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +19 -11
  120. package/dist/layout-bridge/convert/templatePreviewFlow.js +103 -38
  121. package/dist/layout-bridge/convert/toFlowBlocks.js +12 -3
  122. package/dist/layout-engine/index.d.ts +2 -2
  123. package/dist/layout-engine/index.js +2 -2
  124. package/dist/layout-engine/measure/measureBlocks.js +1 -6
  125. package/dist/layout-engine/types.d.ts +8 -2
  126. package/dist/layout-engine/types.js +35 -2
  127. package/dist/markdown/index.js +1 -1
  128. package/dist/markdown/internals.d.ts +6 -1
  129. package/dist/markdown/internals.js +14 -1
  130. package/dist/markdown/renderBlock.js +35 -21
  131. package/dist/markdown/renderParagraph.js +14 -5
  132. package/dist/markdown/renderRuns.js +4 -3
  133. package/dist/markdown/renderTable.js +4 -3
  134. package/dist/markdown/trailers.js +41 -7
  135. package/dist/markdown/types.d.ts +3 -7
  136. package/dist/prosemirror/attrs/index.js +2 -5
  137. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +11 -1
  138. package/dist/prosemirror/bookmarkBoundaryAttrs.js +18 -3
  139. package/dist/prosemirror/commands/index.d.ts +3 -3
  140. package/dist/prosemirror/commands/index.js +2 -2
  141. package/dist/prosemirror/commands/pageBreak.js +12 -1
  142. package/dist/prosemirror/commands/paragraph.d.ts +3 -3
  143. package/dist/prosemirror/commands/paragraph.js +2 -2
  144. package/dist/prosemirror/commentIdAllocator.js +2 -7
  145. package/dist/prosemirror/conversion/fromProseDoc.js +131 -41
  146. package/dist/prosemirror/conversion/toProseDoc.d.ts +1 -14
  147. package/dist/prosemirror/conversion/toProseDoc.js +402 -328
  148. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +14 -1
  149. package/dist/prosemirror/extensions/core/ParagraphExtension.js +11 -6
  150. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -3
  151. package/dist/prosemirror/extensions/features/ListExtension.js +42 -4
  152. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +4 -1
  153. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +6 -2
  154. package/dist/prosemirror/extensions/features/pastedHeadingStyles.d.ts +7 -0
  155. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +74 -0
  156. package/dist/prosemirror/extensions/marks/markUtils.d.ts +11 -3
  157. package/dist/prosemirror/extensions/marks/markUtils.js +98 -19
  158. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +7 -3
  159. package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
  160. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +1 -0
  161. package/dist/prosemirror/extensions/nodes/TableExtension.js +15 -1
  162. package/dist/prosemirror/extensions/types.d.ts +2 -2
  163. package/dist/prosemirror/index.d.ts +3 -3
  164. package/dist/prosemirror/index.js +3 -3
  165. package/dist/prosemirror/insertOperations.d.ts +9 -2
  166. package/dist/prosemirror/insertOperations.js +9 -4
  167. package/dist/prosemirror/listMarker.js +2 -1
  168. package/dist/prosemirror/numberedRefFields.js +2 -1
  169. package/dist/prosemirror/pageBreakRunProjection.d.ts +11 -3
  170. package/dist/prosemirror/pageBreakRunProjection.js +16 -8
  171. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +159 -0
  172. package/dist/prosemirror/paragraphFormattingProvenance.js +106 -0
  173. package/dist/prosemirror/plugins/documentStyles.d.ts +9 -1
  174. package/dist/prosemirror/plugins/documentStyles.js +11 -1
  175. package/dist/prosemirror/plugins/index.d.ts +2 -2
  176. package/dist/prosemirror/plugins/index.js +2 -2
  177. package/dist/prosemirror/plugins/revisionIds.d.ts +11 -2
  178. package/dist/prosemirror/plugins/revisionIds.js +21 -6
  179. package/dist/prosemirror/plugins/templatePreviewValues.d.ts +42 -1
  180. package/dist/prosemirror/plugins/templatePreviewValues.js +217 -14
  181. package/dist/prosemirror/runFormattingReconciliation.js +3 -2
  182. package/dist/prosemirror/runStyleFormatting.d.ts +1 -1
  183. package/dist/prosemirror/schema/nodes.d.ts +31 -0
  184. package/dist/prosemirror/styles/resolvedStyleAttrs.js +4 -1
  185. package/dist/prosemirror/styles/styleResolver.d.ts +9 -0
  186. package/dist/prosemirror/styles/styleResolver.js +15 -6
  187. package/dist/prosemirror/utils/visualLineNavigation.d.ts +22 -2
  188. package/dist/prosemirror/utils/visualLineNavigation.js +80 -63
  189. package/dist/style-engine/styleEngine.d.ts +4 -1
  190. package/dist/style-engine/styleEngine.js +3 -0
  191. package/dist/style-sets/extract.js +35 -11
  192. package/dist/style-sets/stellaStyle.js +46 -39
  193. package/dist/style-sets/styleSetNormalization.d.ts +19 -0
  194. package/dist/style-sets/styleSetNormalization.js +99 -0
  195. package/dist/types/content.d.ts +2 -2
  196. package/dist/utils/createDocument.js +145 -20
  197. package/dist/utils/headingCollector.d.ts +8 -5
  198. package/dist/utils/headingCollector.js +23 -25
  199. package/dist/utils/tableOfContentsStyle.js +9 -2
  200. package/package.json +3 -2
  201. package/dist/docx/textWhitespace.d.ts +0 -4
  202. package/dist/docx/textWhitespace.js +0 -4
  203. package/dist/layout-bridge/engine/tableWidthUtils.d.ts +0 -6
  204. package/dist/layout-bridge/engine/tableWidthUtils.js +0 -25
  205. package/dist/markdown/headings.d.ts +0 -13
  206. package/dist/markdown/headings.js +0 -20
@@ -2,7 +2,7 @@ import { PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./co
2
2
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./commands/formatting.js";
3
3
  import { insertImageFromFile } from "./commands/image.js";
4
4
  import { insertPageBreak } from "./commands/pageBreak.js";
5
- import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, generateTOC, increaseIndent, increaseListLevel, removeList, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, toggleBidi, toggleBulletList, toggleNumberedList } from "./commands/paragraph.js";
5
+ import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, generateTableOfContents, increaseIndent, increaseListLevel, removeList, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, toggleBidi, toggleBulletList, toggleNumberedList } from "./commands/paragraph.js";
6
6
  import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, insertTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap } from "./commands/table.js";
7
7
  import { fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.js";
8
8
  import { createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
@@ -13,11 +13,11 @@ import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensi
13
13
  import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
14
14
  import { getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
15
15
  import { insertPageBreakInView, insertTableInView, insertTableOfContentsInView } from "./insertOperations.js";
16
- import { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver } from "./plugins/documentStyles.js";
16
+ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./plugins/documentStyles.js";
17
17
  import { createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./plugins/selectionTracker.js";
18
18
  import { schema, singletonManager } from "./schema/index.js";
19
19
  import { extractSelectionState } from "./selectionState.js";
20
20
  import { StyleResolver, createStyleResolver } from "./styles/styleResolver.js";
21
21
  import { assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
22
22
  import { TextSelection } from "prosemirror-state";
23
- export { PAINTABLE_MARK_NAMES, StyleResolver, TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTOC, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
23
+ export { PAINTABLE_MARK_NAMES, StyleResolver, TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, assertValidProseMirrorDocument, autoFitContents, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, createDocumentStylesPlugin, createEmptyDoc, createSelectionTrackerPlugin, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, documentStylesKey, ensureParaIdsInState, extractSelectionContext, extractSelectionState, formatProseMirrorDocumentIssues, fromProseDoc, generateTableOfContents, getDocumentBuiltInStyles, getDocumentStyleResolver, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getSelectionContext, getStyleId, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertImageFromFile, insertPageBreak, insertPageBreakInView, insertTable, insertTableInView, insertTableOfContentsInView, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, removeHyperlink, removeList, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, selectionTrackerKey, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, singletonManager, splitCell, toProseDoc, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, updateDocumentContent, validateProseMirrorDocument };
@@ -1,11 +1,18 @@
1
+ import { GenerateTableOfContentsOptions } from "./extensions/core/ParagraphExtension.js";
1
2
  import { insertImageFromFile } from "./commands/image.js";
3
+ import "./commands/index.js";
2
4
  import { EditorView } from "prosemirror-view";
3
5
  //#region src/prosemirror/insertOperations.d.ts
4
6
  /** Insert a `rows × columns` table at the current selection. */
5
7
  declare function insertTableInView(view: EditorView, rows: number, columns: number): boolean;
6
8
  /** Insert a page break at the current selection. */
7
9
  declare function insertPageBreakInView(view: EditorView): boolean;
8
- /** Generate (or refresh) a table of contents from the document's headings. */
9
- declare function insertTableOfContentsInView(view: EditorView): boolean;
10
+ /**
11
+ * Generate (or refresh) a table of contents from the document's headings.
12
+ *
13
+ * `title` is the caller's because this layer has no locale — see
14
+ * {@link GenerateTableOfContentsOptions}.
15
+ */
16
+ declare function insertTableOfContentsInView(view: EditorView, options: GenerateTableOfContentsOptions): boolean;
10
17
  //#endregion
11
18
  export { insertImageFromFile, insertPageBreakInView, insertTableInView, insertTableOfContentsInView };
@@ -1,6 +1,6 @@
1
1
  import { insertImageFromFile } from "./commands/image.js";
2
2
  import { insertPageBreak } from "./commands/pageBreak.js";
3
- import { generateTOC } from "./commands/paragraph.js";
3
+ import { generateTableOfContents } from "./commands/paragraph.js";
4
4
  import { insertTable } from "./commands/table.js";
5
5
  //#region src/prosemirror/insertOperations.ts
6
6
  /** Insert a `rows × columns` table at the current selection. */
@@ -11,9 +11,14 @@ function insertTableInView(view, rows, columns) {
11
11
  function insertPageBreakInView(view) {
12
12
  return insertPageBreak(view.state, view.dispatch);
13
13
  }
14
- /** Generate (or refresh) a table of contents from the document's headings. */
15
- function insertTableOfContentsInView(view) {
16
- return generateTOC(view.state, view.dispatch);
14
+ /**
15
+ * Generate (or refresh) a table of contents from the document's headings.
16
+ *
17
+ * `title` is the caller's because this layer has no locale — see
18
+ * {@link GenerateTableOfContentsOptions}.
19
+ */
20
+ function insertTableOfContentsInView(view, options) {
21
+ return generateTableOfContents(options)(view.state, view.dispatch);
17
22
  }
18
23
  //#endregion
19
24
  export { insertImageFromFile, insertPageBreakInView, insertTableInView, insertTableOfContentsInView };
@@ -1,4 +1,5 @@
1
1
  import { convertBulletToUnicode } from "../docx/bulletMarkers.js";
2
+ import { isNumberingReference } from "../docx/numberingReference.js";
2
3
  import { formatOoxmlCounter } from "../docx/ooxmlCounterFormatter.js";
3
4
  import { LIST_RENDERING_ATTR_KEYS } from "./listRenderingAttrs.js";
4
5
  //#region src/prosemirror/listMarker.ts
@@ -179,7 +180,7 @@ function advanceListMarker(attrs, state) {
179
180
  const level = attrs.numPr?.ilvl ?? 0;
180
181
  if (!Number.isInteger(level) || level < 0 || level > 8) return null;
181
182
  const numId = attrs.numPr?.numId;
182
- if (numId === void 0 || numId === 0) {
183
+ if (!isNumberingReference(numId)) {
183
184
  let marker = null;
184
185
  if (markerTemplate?.includes("%") && !attrs.listIsBullet) {
185
186
  const counters = getLastListCounters(state);
@@ -1,3 +1,4 @@
1
+ import { isNumberingReference } from "../docx/numberingReference.js";
1
2
  import { expectFieldAttrs, expectParagraphAttrs } from "./attrs/index.js";
2
3
  import { expectBookmarkBoundaryAttrs } from "./bookmarkBoundaryAttrs.js";
3
4
  import { advanceVisibleListMarker, createListCounterState, resolveListTemplateWithComponents } from "./listMarker.js";
@@ -79,7 +80,7 @@ function numberTargetForParagraph(node, contextStreams, streams) {
79
80
  }
80
81
  function numberTargetForAdvancedMarker(attrs, resolvedMarker, state, contexts) {
81
82
  const numId = attrs.numPr?.numId;
82
- if (numId === void 0 || numId === 0 || attrs.listIsBullet || attrs.listMarkerHidden || attrs.listNumFmt === "none" || !resolvedMarker) return null;
83
+ if (!isNumberingReference(numId) || attrs.listIsBullet || attrs.listMarkerHidden || attrs.listNumFmt === "none" || !resolvedMarker) return null;
83
84
  const marker = attrs.listMarkerAllCaps ? resolvedMarker.toLocaleUpperCase() : resolvedMarker;
84
85
  const level = attrs.numPr?.ilvl ?? 0;
85
86
  if (!Number.isInteger(level) || level < 0 || level > 8) return null;
@@ -6,7 +6,7 @@ declare const PAGE_BREAK_RUN_PARAGRAPH_PROJECTION_MESSAGES: {
6
6
  readonly borders: "A bordered paragraph containing an explicit page-break run cannot be projected";
7
7
  readonly frame: "A framed paragraph containing an explicit page-break run cannot be projected";
8
8
  readonly outline: "An outline paragraph containing an explicit page-break run cannot be projected";
9
- readonly textBoxAnchor: "A paragraph containing both an explicit page-break run and a text-box anchor cannot be projected";
9
+ readonly textBoxAnchor: "A paragraph whose text-box anchor follows an explicit page-break run cannot be projected";
10
10
  };
11
11
  type PageBreakRunParagraphProjectionReason = keyof typeof PAGE_BREAK_RUN_PARAGRAPH_PROJECTION_MESSAGES;
12
12
  type PageBreakRunParagraphProjectionDisposition = {
@@ -19,10 +19,18 @@ type PageBreakRunParagraphProjectionDisposition = {
19
19
  type PageBreakRunParagraphFeatures = {
20
20
  attrs: ParagraphAttrs;
21
21
  effectiveFrame: document_d_exports.ParagraphFormatting["frame"];
22
- hasTextBoxAnchor: boolean;
22
+ /**
23
+ * A text-box anchor that the paragraph's first page break precedes.
24
+ *
25
+ * Layout splits such a paragraph into fragments at its breaks, and only the
26
+ * first fragment keeps the paragraph's block id, which is what an anchor
27
+ * resolves its host through. An anchor before the first break is therefore
28
+ * projected faithfully; one after it would lose its host.
29
+ */
30
+ textBoxAnchorAfterPageBreak: boolean;
23
31
  };
24
32
  /** Keep source-import and ProseMirror-layout ownership decisions on one predicate. */
25
- declare const pageBreakRunParagraphProjectionDispositionForFeatures: ({ attrs, effectiveFrame, hasTextBoxAnchor }: PageBreakRunParagraphFeatures) => PageBreakRunParagraphProjectionDisposition;
33
+ declare const pageBreakRunParagraphProjectionDispositionForFeatures: ({ attrs, effectiveFrame, textBoxAnchorAfterPageBreak }: PageBreakRunParagraphFeatures) => PageBreakRunParagraphProjectionDisposition;
26
34
  declare const pageBreakRunParagraphProjectionDisposition: (paragraph: Node) => PageBreakRunParagraphProjectionDisposition;
27
35
  //#endregion
28
36
  export { PageBreakRunParagraphProjectionDisposition, PageBreakRunParagraphProjectionReason, pageBreakRunParagraphProjectionDisposition, pageBreakRunParagraphProjectionDispositionForFeatures };
@@ -4,10 +4,10 @@ const PAGE_BREAK_RUN_PARAGRAPH_PROJECTION_MESSAGES = {
4
4
  borders: "A bordered paragraph containing an explicit page-break run cannot be projected",
5
5
  frame: "A framed paragraph containing an explicit page-break run cannot be projected",
6
6
  outline: "An outline paragraph containing an explicit page-break run cannot be projected",
7
- textBoxAnchor: "A paragraph containing both an explicit page-break run and a text-box anchor cannot be projected"
7
+ textBoxAnchor: "A paragraph whose text-box anchor follows an explicit page-break run cannot be projected"
8
8
  };
9
9
  /** Keep source-import and ProseMirror-layout ownership decisions on one predicate. */
10
- const pageBreakRunParagraphProjectionDispositionForFeatures = ({ attrs, effectiveFrame, hasTextBoxAnchor }) => {
10
+ const pageBreakRunParagraphProjectionDispositionForFeatures = ({ attrs, effectiveFrame, textBoxAnchorAfterPageBreak }) => {
11
11
  if (effectiveFrame !== void 0 && effectiveFrame.dropCap !== "drop" && effectiveFrame.dropCap !== "margin") return {
12
12
  status: "unsupported",
13
13
  reason: "frame",
@@ -23,7 +23,7 @@ const pageBreakRunParagraphProjectionDispositionForFeatures = ({ attrs, effectiv
23
23
  reason: "borders",
24
24
  message: PAGE_BREAK_RUN_PARAGRAPH_PROJECTION_MESSAGES.borders
25
25
  };
26
- if (hasTextBoxAnchor) return {
26
+ if (textBoxAnchorAfterPageBreak) return {
27
27
  status: "unsupported",
28
28
  reason: "textBoxAnchor",
29
29
  message: PAGE_BREAK_RUN_PARAGRAPH_PROJECTION_MESSAGES.textBoxAnchor
@@ -32,15 +32,23 @@ const pageBreakRunParagraphProjectionDispositionForFeatures = ({ attrs, effectiv
32
32
  };
33
33
  const pageBreakRunParagraphProjectionDisposition = (paragraph) => {
34
34
  const attrs = expectParagraphAttrs(paragraph);
35
- let hasTextBoxAnchor = false;
36
- paragraph.descendants((descendant) => {
37
- hasTextBoxAnchor ||= descendant.type.name === "textBoxAnchor";
38
- return !hasTextBoxAnchor;
35
+ let firstPageBreakPos;
36
+ let textBoxAnchorAfterPageBreak = false;
37
+ paragraph.descendants((descendant, pos) => {
38
+ if (descendant.type.name === "pageBreakRun") {
39
+ firstPageBreakPos ??= pos;
40
+ return false;
41
+ }
42
+ if (descendant.type.name === "textBoxAnchor" && firstPageBreakPos !== void 0) {
43
+ textBoxAnchorAfterPageBreak = true;
44
+ return false;
45
+ }
46
+ return !textBoxAnchorAfterPageBreak;
39
47
  });
40
48
  return pageBreakRunParagraphProjectionDispositionForFeatures({
41
49
  attrs,
42
50
  effectiveFrame: attrs._originalFormatting?.frame,
43
- hasTextBoxAnchor
51
+ textBoxAnchorAfterPageBreak
44
52
  });
45
53
  };
46
54
  //#endregion
@@ -0,0 +1,159 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { ParagraphAttrs } from "./schema/nodes.js";
3
+ //#region src/prosemirror/paragraphFormattingProvenance.d.ts
4
+ /**
5
+ * How each `w:pPr` field reaches the saved model from paragraph attrs.
6
+ *
7
+ * - `style-resolved-attr`: the named attr holds the effective value, so the
8
+ * write-back filters it against `ParagraphAttrs._resolvedFormatting`.
9
+ * - `direct-provenance`: the field has its own provenance channel and reader
10
+ * (`alignmentFromStyle`, `spacingFromDocDefaults`, `numPrFromStyle`, …).
11
+ * - `derived`: not authored; recomputed from another field on load and save.
12
+ * - `original-only`: no editor attr writes it back; it survives through
13
+ * `ParagraphAttrs._originalFormatting`.
14
+ */
15
+ type ParagraphFieldWriteBack = {
16
+ kind: "style-resolved-attr";
17
+ attr: keyof ParagraphAttrs;
18
+ } | {
19
+ kind: "direct-provenance";
20
+ } | {
21
+ kind: "derived";
22
+ } | {
23
+ kind: "original-only";
24
+ };
25
+ /**
26
+ * Total over `ParagraphFormatting`, so a new `w:pPr` field cannot land without
27
+ * a decision about how a save tells its authored value from its inherited one.
28
+ */
29
+ declare const PARAGRAPH_FORMATTING_WRITE_BACK: {
30
+ readonly alignment: {
31
+ readonly kind: "direct-provenance";
32
+ };
33
+ readonly bidi: {
34
+ readonly kind: "style-resolved-attr";
35
+ readonly attr: "direction";
36
+ };
37
+ readonly kinsoku: {
38
+ readonly kind: "style-resolved-attr";
39
+ readonly attr: "kinsoku";
40
+ };
41
+ readonly overflowPunctuation: {
42
+ readonly kind: "style-resolved-attr";
43
+ readonly attr: "overflowPunctuation";
44
+ };
45
+ readonly spaceBefore: {
46
+ readonly kind: "direct-provenance";
47
+ };
48
+ readonly spaceAfter: {
49
+ readonly kind: "direct-provenance";
50
+ };
51
+ readonly lineSpacing: {
52
+ readonly kind: "direct-provenance";
53
+ };
54
+ readonly lineSpacingRule: {
55
+ readonly kind: "direct-provenance";
56
+ };
57
+ readonly snapToGrid: {
58
+ readonly kind: "style-resolved-attr";
59
+ readonly attr: "snapToGrid";
60
+ };
61
+ readonly beforeAutospacing: {
62
+ readonly kind: "direct-provenance";
63
+ };
64
+ readonly afterAutospacing: {
65
+ readonly kind: "direct-provenance";
66
+ };
67
+ readonly spacingExplicit: {
68
+ readonly kind: "derived";
69
+ };
70
+ readonly indentLeft: {
71
+ readonly kind: "style-resolved-attr";
72
+ readonly attr: "indentLeft";
73
+ };
74
+ readonly indentRight: {
75
+ readonly kind: "style-resolved-attr";
76
+ readonly attr: "indentRight";
77
+ };
78
+ readonly indentFirstLine: {
79
+ readonly kind: "style-resolved-attr";
80
+ readonly attr: "indentFirstLine";
81
+ };
82
+ readonly hangingIndent: {
83
+ readonly kind: "direct-provenance";
84
+ };
85
+ readonly borders: {
86
+ readonly kind: "style-resolved-attr";
87
+ readonly attr: "borders";
88
+ };
89
+ readonly shading: {
90
+ readonly kind: "style-resolved-attr";
91
+ readonly attr: "shading";
92
+ };
93
+ readonly tabs: {
94
+ readonly kind: "style-resolved-attr";
95
+ readonly attr: "tabs";
96
+ };
97
+ readonly keepNext: {
98
+ readonly kind: "original-only";
99
+ };
100
+ readonly keepLines: {
101
+ readonly kind: "original-only";
102
+ };
103
+ readonly widowControl: {
104
+ readonly kind: "style-resolved-attr";
105
+ readonly attr: "widowControl";
106
+ };
107
+ readonly pageBreakBefore: {
108
+ readonly kind: "style-resolved-attr";
109
+ readonly attr: "pageBreakBefore";
110
+ };
111
+ readonly contextualSpacing: {
112
+ readonly kind: "style-resolved-attr";
113
+ readonly attr: "contextualSpacing";
114
+ };
115
+ readonly numPr: {
116
+ readonly kind: "direct-provenance";
117
+ };
118
+ readonly numPrFromStyle: {
119
+ readonly kind: "derived";
120
+ };
121
+ readonly numberingChangeXml: {
122
+ readonly kind: "original-only";
123
+ };
124
+ readonly outlineLevel: {
125
+ readonly kind: "style-resolved-attr";
126
+ readonly attr: "outlineLevel";
127
+ };
128
+ readonly styleId: {
129
+ readonly kind: "direct-provenance";
130
+ };
131
+ readonly frame: {
132
+ readonly kind: "original-only";
133
+ };
134
+ readonly suppressLineNumbers: {
135
+ readonly kind: "original-only";
136
+ };
137
+ readonly suppressAutoHyphens: {
138
+ readonly kind: "style-resolved-attr";
139
+ readonly attr: "suppressAutoHyphens";
140
+ };
141
+ readonly runProperties: {
142
+ readonly kind: "original-only";
143
+ };
144
+ readonly runInWithNext: {
145
+ readonly kind: "original-only";
146
+ };
147
+ };
148
+ type StyleResolvedParagraphField = { [Field in keyof typeof PARAGRAPH_FORMATTING_WRITE_BACK]: (typeof PARAGRAPH_FORMATTING_WRITE_BACK)[Field] extends {
149
+ kind: "style-resolved-attr";
150
+ } ? Field : never; }[keyof typeof PARAGRAPH_FORMATTING_WRITE_BACK];
151
+ declare const STYLE_RESOLVED_PARAGRAPH_FIELDS: StyleResolvedParagraphField[];
152
+ /**
153
+ * The part of a resolved style cascade a save needs to keep out of direct
154
+ * `w:pPr`. Narrowed to the governed fields so an ordinary paragraph, whose
155
+ * cascade supplies only spacing, stores nothing at all.
156
+ */
157
+ declare const styleResolvedParagraphFormatting: (resolved: document_d_exports.ParagraphFormatting | undefined) => document_d_exports.ParagraphFormatting | undefined;
158
+ //#endregion
159
+ export { PARAGRAPH_FORMATTING_WRITE_BACK, ParagraphFieldWriteBack, STYLE_RESOLVED_PARAGRAPH_FIELDS, StyleResolvedParagraphField, styleResolvedParagraphFormatting };
@@ -0,0 +1,106 @@
1
+ //#region src/prosemirror/paragraphFormattingProvenance.ts
2
+ /**
3
+ * Total over `ParagraphFormatting`, so a new `w:pPr` field cannot land without
4
+ * a decision about how a save tells its authored value from its inherited one.
5
+ */
6
+ const PARAGRAPH_FORMATTING_WRITE_BACK = {
7
+ alignment: { kind: "direct-provenance" },
8
+ bidi: {
9
+ kind: "style-resolved-attr",
10
+ attr: "direction"
11
+ },
12
+ kinsoku: {
13
+ kind: "style-resolved-attr",
14
+ attr: "kinsoku"
15
+ },
16
+ overflowPunctuation: {
17
+ kind: "style-resolved-attr",
18
+ attr: "overflowPunctuation"
19
+ },
20
+ spaceBefore: { kind: "direct-provenance" },
21
+ spaceAfter: { kind: "direct-provenance" },
22
+ lineSpacing: { kind: "direct-provenance" },
23
+ lineSpacingRule: { kind: "direct-provenance" },
24
+ snapToGrid: {
25
+ kind: "style-resolved-attr",
26
+ attr: "snapToGrid"
27
+ },
28
+ beforeAutospacing: { kind: "direct-provenance" },
29
+ afterAutospacing: { kind: "direct-provenance" },
30
+ spacingExplicit: { kind: "derived" },
31
+ indentLeft: {
32
+ kind: "style-resolved-attr",
33
+ attr: "indentLeft"
34
+ },
35
+ indentRight: {
36
+ kind: "style-resolved-attr",
37
+ attr: "indentRight"
38
+ },
39
+ indentFirstLine: {
40
+ kind: "style-resolved-attr",
41
+ attr: "indentFirstLine"
42
+ },
43
+ hangingIndent: { kind: "direct-provenance" },
44
+ borders: {
45
+ kind: "style-resolved-attr",
46
+ attr: "borders"
47
+ },
48
+ shading: {
49
+ kind: "style-resolved-attr",
50
+ attr: "shading"
51
+ },
52
+ tabs: {
53
+ kind: "style-resolved-attr",
54
+ attr: "tabs"
55
+ },
56
+ keepNext: { kind: "original-only" },
57
+ keepLines: { kind: "original-only" },
58
+ widowControl: {
59
+ kind: "style-resolved-attr",
60
+ attr: "widowControl"
61
+ },
62
+ pageBreakBefore: {
63
+ kind: "style-resolved-attr",
64
+ attr: "pageBreakBefore"
65
+ },
66
+ contextualSpacing: {
67
+ kind: "style-resolved-attr",
68
+ attr: "contextualSpacing"
69
+ },
70
+ numPr: { kind: "direct-provenance" },
71
+ numPrFromStyle: { kind: "derived" },
72
+ numberingChangeXml: { kind: "original-only" },
73
+ outlineLevel: {
74
+ kind: "style-resolved-attr",
75
+ attr: "outlineLevel"
76
+ },
77
+ styleId: { kind: "direct-provenance" },
78
+ frame: { kind: "original-only" },
79
+ suppressLineNumbers: { kind: "original-only" },
80
+ suppressAutoHyphens: {
81
+ kind: "style-resolved-attr",
82
+ attr: "suppressAutoHyphens"
83
+ },
84
+ runProperties: { kind: "original-only" },
85
+ runInWithNext: { kind: "original-only" }
86
+ };
87
+ const STYLE_RESOLVED_PARAGRAPH_FIELDS = Object.keys(PARAGRAPH_FORMATTING_WRITE_BACK).filter((field) => PARAGRAPH_FORMATTING_WRITE_BACK[field].kind === "style-resolved-attr");
88
+ /**
89
+ * The part of a resolved style cascade a save needs to keep out of direct
90
+ * `w:pPr`. Narrowed to the governed fields so an ordinary paragraph, whose
91
+ * cascade supplies only spacing, stores nothing at all.
92
+ */
93
+ const styleResolvedParagraphFormatting = (resolved) => {
94
+ if (!resolved) return;
95
+ const governed = {};
96
+ let found = false;
97
+ for (const field of STYLE_RESOLVED_PARAGRAPH_FIELDS) {
98
+ const value = resolved[field];
99
+ if (value === void 0) continue;
100
+ Reflect.set(governed, field, value);
101
+ found = true;
102
+ }
103
+ return found ? governed : void 0;
104
+ };
105
+ //#endregion
106
+ export { PARAGRAPH_FORMATTING_WRITE_BACK, STYLE_RESOLVED_PARAGRAPH_FIELDS, styleResolvedParagraphFormatting };
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { BuiltInStyleIndex } from "../../docx/builtInStyles.js";
2
3
  import { StyleResolver } from "../styles/styleResolver.js";
3
4
  import { EditorState, Plugin, PluginKey } from "prosemirror-state";
4
5
  //#region src/prosemirror/plugins/documentStyles.d.ts
@@ -13,7 +14,14 @@ declare const documentStylesKey: PluginKey<StyleResolver | null>;
13
14
  declare function createDocumentStylesPlugin(styles: document_d_exports.StyleDefinitions | StyleResolver | null | undefined): Plugin;
14
15
  /** Read the document's StyleResolver, or null when the plugin isn't installed. */
15
16
  declare function getDocumentStyleResolver(state: EditorState): StyleResolver | null;
17
+ /**
18
+ * Read the document's built-in style index, for the callers that classify
19
+ * paragraphs (heading collection, markdown export, the AI snapshot). Without
20
+ * the plugin every lookup misses, which degrades classification to the
21
+ * paragraph's own outline level rather than to English style ids.
22
+ */
23
+ declare function getDocumentBuiltInStyles(state: EditorState): BuiltInStyleIndex;
16
24
  /** Reconfigure so ProseMirror replaces the keyed plugin's resolver state. */
17
25
  declare const withDocumentStyles: (state: EditorState, styles: document_d_exports.StyleDefinitions | StyleResolver | null | undefined) => EditorState;
18
26
  //#endregion
19
- export { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver, withDocumentStyles };
27
+ export { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver, withDocumentStyles };
@@ -1,3 +1,4 @@
1
+ import { EMPTY_BUILT_IN_STYLE_INDEX } from "../../docx/builtInStyles.js";
1
2
  import { StyleResolver, createStyleResolver } from "../styles/styleResolver.js";
2
3
  import { Plugin, PluginKey } from "prosemirror-state";
3
4
  //#region src/prosemirror/plugins/documentStyles.ts
@@ -42,6 +43,15 @@ function createDocumentStylesPlugin(styles) {
42
43
  function getDocumentStyleResolver(state) {
43
44
  return documentStylesKey.getState(state) ?? null;
44
45
  }
46
+ /**
47
+ * Read the document's built-in style index, for the callers that classify
48
+ * paragraphs (heading collection, markdown export, the AI snapshot). Without
49
+ * the plugin every lookup misses, which degrades classification to the
50
+ * paragraph's own outline level rather than to English style ids.
51
+ */
52
+ function getDocumentBuiltInStyles(state) {
53
+ return getDocumentStyleResolver(state)?.builtInStyles ?? EMPTY_BUILT_IN_STYLE_INDEX;
54
+ }
45
55
  /** Reconfigure so ProseMirror replaces the keyed plugin's resolver state. */
46
56
  const withDocumentStyles = (state, styles) => {
47
57
  const previous = documentStylesKey.get(state);
@@ -49,4 +59,4 @@ const withDocumentStyles = (state, styles) => {
49
59
  return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [...retained, createDocumentStylesPlugin(styles)] });
50
60
  };
51
61
  //#endregion
52
- export { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver, withDocumentStyles };
62
+ export { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver, withDocumentStyles };
@@ -1,3 +1,3 @@
1
1
  import { SelectionChangeCallback, SelectionContext, createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./selectionTracker.js";
2
- import { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver } from "./documentStyles.js";
3
- export { type SelectionChangeCallback, type SelectionContext, createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
2
+ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./documentStyles.js";
3
+ export { type SelectionChangeCallback, type SelectionContext, createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentBuiltInStyles, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
@@ -1,3 +1,3 @@
1
- import { createDocumentStylesPlugin, documentStylesKey, getDocumentStyleResolver } from "./documentStyles.js";
1
+ import { createDocumentStylesPlugin, documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./documentStyles.js";
2
2
  import { createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./selectionTracker.js";
3
- export { createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
3
+ export { createDocumentStylesPlugin, createSelectionTrackerPlugin, documentStylesKey, extractSelectionContext, getDocumentBuiltInStyles, getDocumentStyleResolver, getSelectionContext, selectionTrackerKey };
@@ -14,9 +14,18 @@ declare function mintRevisionId(): number;
14
14
  */
15
15
  declare function seedRevisionIdsAbove(maxId: number): void;
16
16
  /**
17
- * Raise the counter above every revision id already present in `doc`.
17
+ * The highest id in `doc` from any part of the annotation space.
18
+ *
19
+ * A revision, a comment and a bookmark draw their `w:id` from one space, so a
20
+ * counter seeded above its own kind alone still mints over another kind's id.
21
+ * Both allocators seed from this, and the save-time normalization avoids the
22
+ * same space, so the three agree on what is taken.
23
+ */
24
+ declare function maxAnnotationIdInDoc(doc: Node): number;
25
+ /**
26
+ * Raise the counter above every annotation id already present in `doc`.
18
27
  * Called from the suggestion-mode plugin's `state.init`.
19
28
  */
20
29
  declare function seedRevisionIdsFromDoc(doc: Node): void;
21
30
  //#endregion
22
- export { mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
31
+ export { maxAnnotationIdInDoc, mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
@@ -31,16 +31,24 @@ function seedRevisionIdsAbove(maxId) {
31
31
  /** Node attrs that carry a revision id directly (`revisionId` field). */
32
32
  const DIRECT_REVISION_ATTR_KEYS = ["trIns", "trDel"];
33
33
  /**
34
- * Raise the counter above every revision id already present in `doc`.
35
- * Called from the suggestion-mode plugin's `state.init`.
34
+ * The highest id in `doc` from any part of the annotation space.
35
+ *
36
+ * A revision, a comment and a bookmark draw their `w:id` from one space, so a
37
+ * counter seeded above its own kind alone still mints over another kind's id.
38
+ * Both allocators seed from this, and the save-time normalization avoids the
39
+ * same space, so the three agree on what is taken.
36
40
  */
37
- function seedRevisionIdsFromDoc(doc) {
41
+ function maxAnnotationIdInDoc(doc) {
38
42
  let max = 0;
39
43
  const consider = (id) => {
40
44
  if (typeof id === "number" && Number.isInteger(id) && id > max && id <= MAX_REVISION_ID) max = id;
41
45
  };
42
46
  doc.descendants((node) => {
43
- for (const mark of node.marks) consider(mark.attrs["revisionId"]);
47
+ for (const mark of node.marks) {
48
+ consider(mark.attrs["revisionId"]);
49
+ consider(mark.attrs["commentId"]);
50
+ }
51
+ if (node.type.name === "bookmarkBoundary") consider(node.attrs["id"]);
44
52
  const attrs = node.attrs;
45
53
  const pPrMark = attrs["pPrMark"];
46
54
  if (pPrMark?.info) consider(pPrMark.info.id);
@@ -51,7 +59,14 @@ function seedRevisionIdsFromDoc(doc) {
51
59
  const cellMarker = attrs["cellMarker"];
52
60
  if (cellMarker?.info) consider(cellMarker.info.revisionId);
53
61
  });
54
- seedRevisionIdsAbove(max);
62
+ return max;
63
+ }
64
+ /**
65
+ * Raise the counter above every annotation id already present in `doc`.
66
+ * Called from the suggestion-mode plugin's `state.init`.
67
+ */
68
+ function seedRevisionIdsFromDoc(doc) {
69
+ seedRevisionIdsAbove(maxAnnotationIdInDoc(doc));
55
70
  }
56
71
  //#endregion
57
- export { mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };
72
+ export { maxAnnotationIdInDoc, mintRevisionId, seedRevisionIdsAbove, seedRevisionIdsFromDoc };