@stll/folio-core 0.75.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/ai-edits/headless.d.ts +8 -5
  2. package/dist/ai-edits/headless.js +49 -26
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +13 -3
  5. package/dist/ai-edits/read.js +33 -4
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/ai-edits/types.d.ts +9 -4
  8. package/dist/canonical/batchCommentReferences.js +2 -1
  9. package/dist/canonical/canonicalBatchReview.js +5 -8
  10. package/dist/canonical/canonicalComments.js +8 -2
  11. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  12. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  13. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  14. package/dist/canonical/canonicalInlineProjection.js +2 -2
  15. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  16. package/dist/canonical/canonicalPublicOperations.js +214 -107
  17. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  18. package/dist/canonical/canonicalSeedContent.js +28 -15
  19. package/dist/canonical/canonicalSession.d.ts +22 -12
  20. package/dist/canonical/canonicalSession.js +181 -187
  21. package/dist/controller/canonicalClipboard.d.ts +3 -2
  22. package/dist/controller/canonicalClipboard.js +377 -58
  23. package/dist/controller/canonicalComposition.js +67 -14
  24. package/dist/controller/canonicalContentControlValue.js +7 -7
  25. package/dist/controller/canonicalReview.d.ts +21 -0
  26. package/dist/controller/canonicalReview.js +44 -9
  27. package/dist/controller/canonicalStoryEditor.js +2 -0
  28. package/dist/controller/canonicalStructure.d.ts +1 -2
  29. package/dist/controller/canonicalStructure.js +51 -24
  30. package/dist/controller/fontReadiness.js +50 -23
  31. package/dist/controller/hiddenEditorManager.js +7 -20
  32. package/dist/docx/bulletMarkers.d.ts +8 -0
  33. package/dist/docx/bulletMarkers.js +9 -1
  34. package/dist/docx/canonicalSessionInput.js +25 -11
  35. package/dist/docx/ensureParaIds.d.ts +31 -0
  36. package/dist/docx/ensureParaIds.js +57 -32
  37. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  38. package/dist/docx/ensureUniqueControlIds.js +47 -29
  39. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  40. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  41. package/dist/docx/importedIdCollisions.js +29 -4
  42. package/dist/docx/server/templatePlan/apply.js +108 -9
  43. package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
  44. package/dist/docx/server/templatePlan/blocks.js +281 -14
  45. package/dist/docx/server/templatePlan/builders.d.ts +22 -1
  46. package/dist/docx/server/templatePlan/builders.js +37 -3
  47. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  48. package/dist/docx/server/templatePlan/effects.js +188 -0
  49. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  50. package/dist/docx/server/templatePlan/emit.js +152 -8
  51. package/dist/docx/server/templatePlan/inspect.js +21 -1
  52. package/dist/docx/server/templatePlan/labels.js +16 -1
  53. package/dist/docx/server/templatePlan/plan.d.ts +35 -3
  54. package/dist/docx/server/templatePlan/plan.js +197 -20
  55. package/dist/docx/server/templatePlan/planShape.js +58 -22
  56. package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
  57. package/dist/docx/server/templatePlan/revisions.js +681 -0
  58. package/dist/docx/server/templatePlan/story.d.ts +61 -2
  59. package/dist/docx/server/templatePlan/story.js +175 -13
  60. package/dist/docx/server/templatePlan/types.d.ts +313 -1
  61. package/dist/docx/server/templatePlan/verify.js +175 -12
  62. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  63. package/dist/docx/server/templatePlan/xml.js +4 -1
  64. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  65. package/dist/docx/tableGridXml.d.ts +3 -7
  66. package/dist/docx/tableGridXml.js +5 -13
  67. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  68. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  69. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  70. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  71. package/dist/prosemirror/canonicalTableCommands.js +1 -3
  72. package/dist/prosemirror/commands/comments.d.ts +6 -234
  73. package/dist/prosemirror/commands/comments.js +5 -2464
  74. package/dist/prosemirror/commands/index.d.ts +4 -2
  75. package/dist/prosemirror/commands/index.js +4 -2
  76. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  77. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  78. package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
  79. package/dist/prosemirror/conversion/toProseDoc.js +31 -14
  80. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  81. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  82. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  83. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  84. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  85. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  86. package/dist/prosemirror/markupViewNotes.js +24 -27
  87. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  88. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  89. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  90. package/dist/prosemirror/markupViewProjection.js +90 -17
  91. package/dist/prosemirror/paraIds.d.ts +1 -14
  92. package/dist/prosemirror/paraIds.js +1 -14
  93. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  94. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  95. package/dist/prosemirror/projectionReview.d.ts +49 -0
  96. package/dist/prosemirror/projectionReview.js +292 -0
  97. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  98. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  99. package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
  100. package/dist/prosemirror/replacedAnnotations.js +11 -203
  101. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  102. package/dist/prosemirror/revisionCarriers.js +15 -1
  103. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  104. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  105. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  106. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  107. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  108. package/dist/prosemirror/styles/styleResolver.js +4 -1
  109. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  110. package/dist/prosemirror/suggestionQueries.js +320 -0
  111. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  112. package/dist/prosemirror/tableGridMutation.js +1 -78
  113. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  114. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  115. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  116. package/dist/server.d.ts +2 -2
  117. package/dist/types/canonicalCapabilities.d.ts +4 -35
  118. package/dist/types/canonicalCapabilities.js +4 -33
  119. package/package.json +2 -2
  120. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  121. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
  122. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  123. package/dist/internal/revisionResolutionEdits.js +0 -18
  124. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  125. package/dist/internal/revisionResolutionInline.js +0 -302
  126. package/dist/internal/revisionResolutionStep.d.ts +0 -32
  127. package/dist/internal/revisionResolutionStep.js +0 -282
  128. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  129. package/dist/internal/revisionResolutionTracking.js +0 -124
  130. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  131. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  132. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  133. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  134. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  135. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  136. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
  137. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
  138. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  139. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  140. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  141. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  142. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  143. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -8,11 +8,13 @@ import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
8
8
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
9
9
  import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
10
10
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
11
- import { AcceptSuggestionOptions, FolioSuggestion, SuggestionAppliedAs, SuggestionKind, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
11
+ import { addCommentMark, findNextChange, findPreviousChange, removeCommentMark } from "../projectionReview.js";
12
+ import { findAIEditRevisionRange } from "../revisionRangeQueries.js";
13
+ import { FolioSuggestion, SuggestionAppliedAs, SuggestionKind, findSuggestionRange, getSuggestions } from "../suggestionQueries.js";
12
14
  import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
13
15
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
14
16
  import { insertPageBreak } from "./pageBreak.js";
15
17
  import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, continueNumbering, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, increaseIndent, increaseListLevel, oneAndHalfSpacing, removeList, removeTabStop, restartNumbering, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setNumberingValue, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList } from "./paragraph.js";
16
18
  import { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting } from "./pastePlainText.js";
17
19
  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 "./table.js";
18
- export { type AcceptSuggestionOptions, type BorderPreset, CLIPBOARD_READ_ERROR_EVENT, type CapturedTextFormatting, type FolioSuggestion, type GenerateTableOfContentsOptions, PAINTABLE_MARK_NAMES, type ResolvedStyleAttrs, type SuggestionAppliedAs, type SuggestionKind, type TableBorderPreset, type TableContextInfo, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, continueNumbering, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, restartNumbering, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setNumberingValue, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
20
+ export { type BorderPreset, CLIPBOARD_READ_ERROR_EVENT, type CapturedTextFormatting, type FolioSuggestion, type GenerateTableOfContentsOptions, PAINTABLE_MARK_NAMES, type ResolvedStyleAttrs, type SuggestionAppliedAs, type SuggestionKind, type TableBorderPreset, type TableContextInfo, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, continueNumbering, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, restartNumbering, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setNumberingValue, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
@@ -3,11 +3,13 @@ import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
3
3
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
4
4
  import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
5
5
  import { getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
6
- import { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
6
+ import { addCommentMark, findNextChange, findPreviousChange, removeCommentMark } from "../projectionReview.js";
7
+ import { findAIEditRevisionRange } from "../revisionRangeQueries.js";
8
+ import { findSuggestionRange, getSuggestions } from "../suggestionQueries.js";
7
9
  import { PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
8
10
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
9
11
  import { insertPageBreak } from "./pageBreak.js";
10
12
  import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, continueNumbering, decreaseIndent, decreaseListLevel, doubleSpacing, generateTableOfContents, increaseIndent, increaseListLevel, oneAndHalfSpacing, removeList, removeTabStop, restartNumbering, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setNumberingValue, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList } from "./paragraph.js";
11
13
  import { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting } from "./pastePlainText.js";
12
14
  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 "./table.js";
13
- export { CLIPBOARD_READ_ERROR_EVENT, PAINTABLE_MARK_NAMES, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, continueNumbering, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, restartNumbering, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setNumberingValue, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
15
+ export { CLIPBOARD_READ_ERROR_EVENT, PAINTABLE_MARK_NAMES, addColumnLeft, addColumnRight, addCommentMark, addRowAbove, addRowBelow, addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, buildPlainTextSlice, captureFormatMarks, clearFontFamily, clearFontSize, clearFormatting, clearHighlight, clearStyle, clearTextColor, continueNumbering, createRemoveMarkCommand, createSetMarkCommand, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, doubleSpacing, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, generateTableOfContents, getHyperlinkAttrs, getListInfo, getMarkAttr, getParagraphAlignment, getParagraphBidi, getSelectedText, getStyleId, getSuggestions, getTableContext, increaseIndent, increaseListLevel, insertHyperlink, insertPageBreak, insertTable, isHyperlinkActive, isInList, isInTableCell as isInTable, isMarkActive, mergeCells, oneAndHalfSpacing, pasteWithoutFormatting, removeCommentMark, removeHyperlink, removeList, removeTabStop, removeTableBorders, restartNumbering, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setHyperlink, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setNumberingValue, setOutsideTableBorders, setRowHeight, setRtl, setSpaceAfter, setSpaceBefore, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, setTextColor, setUnderlineStyle, singleSpacing, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline };
@@ -0,0 +1,17 @@
1
+ import { document_d_exports } from "../../types/document.js";
2
+ import { ToProseDocOptions } from "./toProseDoc.js";
3
+ import { EditorState } from "prosemirror-state";
4
+ import { Node } from "prosemirror-model";
5
+ import { OpStory } from "@stll/docx-core/ops";
6
+ type MarkupViewSource = {
7
+ document: document_d_exports.Document;
8
+ story?: OpStory;
9
+ options?: ToProseDocOptions;
10
+ };
11
+ /** The model used to convert a story, keyed by the exact PM snapshot. */
12
+ export declare const markupViewSources: WeakMap<Node, MarkupViewSource>;
13
+ /** Two states can share a PM node while publishing different model snapshots. */
14
+ export declare const markupViewStateSources: WeakMap<EditorState, MarkupViewSource>;
15
+ /** Carry the published model through a transaction that preserves the story. */
16
+ export declare const retainMarkupViewSource: (before: EditorState, after: EditorState) => void;
17
+ export {};
@@ -0,0 +1,11 @@
1
+ // src/prosemirror/conversion/markupViewSource.ts
2
+ /** The model used to convert a story, keyed by the exact PM snapshot. */
3
+ const markupViewSources = /* @__PURE__ */ new WeakMap();
4
+ /** Two states can share a PM node while publishing different model snapshots. */
5
+ const markupViewStateSources = /* @__PURE__ */ new WeakMap();
6
+ /** Carry the published model through a transaction that preserves the story. */
7
+ const retainMarkupViewSource = (before, after) => {
8
+ const source = markupViewStateSources.get(before) ?? markupViewSources.get(before.doc);
9
+ if (source !== void 0) markupViewStateSources.set(after, source);
10
+ };
11
+ export { markupViewSources, markupViewStateSources, retainMarkupViewSource };
@@ -81,6 +81,7 @@ declare const CONVERSION_CONTEXT_DEPENDENCY: {
81
81
  readonly warnPageBreakProjection: "package";
82
82
  readonly createMark: "package";
83
83
  readonly nextTextBoxGroupId: "story";
84
+ readonly placedTextBoxGroup: "story";
84
85
  readonly nextHyperlinkInstanceIndex: "story";
85
86
  readonly nextNoteReferenceOccurrenceId: "story";
86
87
  readonly pairedBookmarkIds: "story";
@@ -172,6 +173,8 @@ type TableConversionContext = {
172
173
  numbering: NumberingMap | undefined;
173
174
  theme: DeepReadonly<document_d_exports.Theme> | null | undefined;
174
175
  nextTextBoxGroupId: () => string;
176
+ /** Told when a paragraph puts the group id it drew on what it converts. */
177
+ placedTextBoxGroup?: () => void;
175
178
  nextHyperlinkInstanceIndex: HyperlinkInstanceIndexAllocator;
176
179
  nextNoteReferenceOccurrenceId: () => string;
177
180
  pairedBookmarkIds: IdMembership;
@@ -64,6 +64,7 @@ import { assertValidProseMirrorDocument, assertValidProseMirrorDocumentKeeping }
64
64
  import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
65
65
  import { HYPHEN_ELEMENT_MARK_NAME, HYPHEN_TEXT_CARRIERS } from "./hyphenTextCarriers.js";
66
66
  import { createMarkInterner } from "./markInterner.js";
67
+ import { markupViewSources } from "./markupViewSource.js";
67
68
  import { hasSinkChildren } from "./preservedSinkCarriers.js";
68
69
  import { sdtAttrsFromProperties } from "./sdtAttrs.js";
69
70
  import { panic } from "better-result";
@@ -428,7 +429,8 @@ var ProjectionBlockCache = class {
428
429
  const context = this.context ?? panic("A block cache converts after its package context");
429
430
  const textBoxGroups = {
430
431
  start: state.textBoxGroups.value,
431
- taken: 0
432
+ taken: 0,
433
+ used: false
432
434
  };
433
435
  const hyperlinks = {
434
436
  start: state.hyperlinks.value,
@@ -446,6 +448,9 @@ var ProjectionBlockCache = class {
446
448
  textBoxGroups.taken += 1;
447
449
  return `${this.salt}:${state.textBoxGroups.value++}`;
448
450
  },
451
+ placedTextBoxGroup: () => {
452
+ textBoxGroups.used = true;
453
+ },
449
454
  nextHyperlinkInstanceIndex: () => {
450
455
  hyperlinks.taken += 1;
451
456
  return state.hyperlinks.value++;
@@ -467,12 +472,8 @@ var ProjectionBlockCache = class {
467
472
  createMark: context.createMark,
468
473
  ...story
469
474
  });
470
- const saltMark = `"${this.salt}:`;
471
475
  const reads = {
472
- textBoxGroups: {
473
- ...textBoxGroups,
474
- used: nodes.some((node) => JSON.stringify(node.toJSON()).includes(saltMark))
475
- },
476
+ textBoxGroups: { ...textBoxGroups },
476
477
  hyperlinks,
477
478
  noteOccurrences,
478
479
  pairedBookmarkIds: setReadsOf(pairedBookmarkIds),
@@ -594,6 +595,15 @@ function toProseDoc(document, options) {
594
595
  const invalid = "Document conversion produced an invalid ProseMirror document";
595
596
  if (cache === void 0) assertValidProseMirrorDocument(pmDoc, invalid);
596
597
  else cache.validated = assertValidProseMirrorDocumentKeeping(pmDoc, invalid, cache.validated);
598
+ markupViewSources.set(pmDoc, {
599
+ document,
600
+ options: {
601
+ ...packageInputs.styles === void 0 ? {} : { styles: packageInputs.styles },
602
+ theme: packageInputs.theme,
603
+ ...cache === void 0 ? {} : { blockCache: cache },
604
+ textBoxGroupSalt: salt
605
+ }
606
+ });
597
607
  return pmDoc;
598
608
  }
599
609
  /** The comments pending suggestions propose, by comment id. */
@@ -808,7 +818,7 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
808
818
  let bookmarksArr;
809
819
  let emptyHyperlinks;
810
820
  let wrapperStack = [];
811
- let paragraphContainsInlineSdt = false;
821
+ let paragraphKeepsBoundaryNodes = false;
812
822
  const emitInlineNodes = (nodes, commentsAlreadyApplied = false) => {
813
823
  if (nodes.length === 0) return;
814
824
  const wrappedNodes = withInlineWrapperMark(nodes, wrapperStack);
@@ -843,11 +853,11 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
843
853
  historical: getHistoricalRunFormatting
844
854
  };
845
855
  const emitTrackedChange = (change, markType, moveKind) => {
846
- emitInlineNodes(convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, trackedRunFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrapperStack, openCommentIds, { preserveSdtBoundaryOccurrences: paragraphContainsInlineSdt }), true);
856
+ emitInlineNodes(convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, trackedRunFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrapperStack, openCommentIds, { preserveSdtBoundaryOccurrences: paragraphKeepsBoundaryNodes }), true);
847
857
  };
848
858
  const stacked = withInlineWrapperStacks(withFieldWrapperCaptures(withLinkedPiecesInWrappers(paragraph.content)));
849
859
  visitInlineContentSlots(paragraph, ({ item }) => {
850
- if (item.type === "inlineSdt") paragraphContainsInlineSdt = true;
860
+ if (keepsCommentBoundaryNodes(item)) paragraphKeepsBoundaryNodes = true;
851
861
  });
852
862
  const emptyRanges = planEmptyRanges(stacked.map((item) => item.content), stacked.map(({ stack }) => stack));
853
863
  for (const [index, { content, stack }] of stacked.entries()) {
@@ -861,11 +871,11 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
861
871
  switch (content.type) {
862
872
  case "commentRangeStart":
863
873
  openCommentIds.add(content.id);
864
- if (paragraphContainsInlineSdt) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
874
+ if (paragraphKeepsBoundaryNodes) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
865
875
  break;
866
876
  case "commentRangeEnd":
867
877
  openCommentIds.delete(content.id);
868
- if (paragraphContainsInlineSdt) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
878
+ if (paragraphKeepsBoundaryNodes) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
869
879
  break;
870
880
  case "commentReference":
871
881
  if (!storyRangedCommentIds.has(content.id)) anchorPointComment(inlineNodes, content.id);
@@ -1050,6 +1060,12 @@ const runPropertyChangeMark = (changes) => {
1050
1060
  } : {}
1051
1061
  });
1052
1062
  };
1063
+ /**
1064
+ * A content control, or a link holding a comment boundary, writes its comment
1065
+ * boundaries as nodes. Every comment boundary beside it does too, so a range
1066
+ * ending outside such an item still runs between two nodes.
1067
+ */
1068
+ const keepsCommentBoundaryNodes = (item) => item.type === "inlineSdt" || item.type === "hyperlink" && withInlineWrapperStacks(item.children).some(({ content }) => content.type === "commentRangeStart" || content.type === "commentRangeEnd");
1053
1069
  function convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, runFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrappedBy, openCommentIds, options = {}) {
1054
1070
  const nodes = [];
1055
1071
  const preserveParentBoundaryOwnership = options.preserveParentBoundaryOwnership ?? true;
@@ -1069,11 +1085,11 @@ function convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runS
1069
1085
  };
1070
1086
  const getTrackedRunFormatting = markType === "deletion" ? runFormattingResolvers.historical : runFormattingResolvers.current;
1071
1087
  const stacked = withInlineWrapperStacks(change.content);
1072
- let containsInlineSdt = false;
1088
+ let keepsBoundaryNodes = false;
1073
1089
  if (options.preserveSdtBoundaryOccurrences === void 0) visitInlineContentSlotsInContent(change.content, ({ item }) => {
1074
- if (item.type === "inlineSdt") containsInlineSdt = true;
1090
+ if (keepsCommentBoundaryNodes(item)) keepsBoundaryNodes = true;
1075
1091
  });
1076
- const preserveBoundaryOccurrences = options.preserveSdtBoundaryOccurrences ?? containsInlineSdt;
1092
+ const preserveBoundaryOccurrences = options.preserveSdtBoundaryOccurrences ?? keepsBoundaryNodes;
1077
1093
  const emptyRanges = planEmptyRanges(stacked.map(({ content }) => content), stacked.map(({ stack }) => stack));
1078
1094
  for (const [index, { content: item, stack }] of stacked.entries()) {
1079
1095
  if (!isTrackedChangeWrapperChild(item)) continue;
@@ -2981,6 +2997,7 @@ function convertShape(shape, runFormatting) {
2981
2997
  }
2982
2998
  function convertParagraphWithTextBoxes(block, styleResolver, { textBoxGroupId, context, extraRunFormatting, preserveEmptyWrapper, tableParagraphOverlay }) {
2983
2999
  const { textBoxes, textBoxAnchors } = extractTextBoxesFromParagraph(block, textBoxGroupId);
3000
+ if (textBoxes.length > 0) context.placedTextBoxGroup?.();
2984
3001
  const pmParagraph = convertParagraph(block, styleResolver, context, extraRunFormatting, tableParagraphOverlay, textBoxAnchors);
2985
3002
  const nodes = [];
2986
3003
  const isEmptyAfterExtraction = textBoxes.length > 0 && !hasContentBesidesTextBoxAnchors(pmParagraph);
@@ -3,7 +3,7 @@ import { anchorTargetAttrs, normalizeUserUrl, sanitizeExternalUrl } from "../../
3
3
  import { expectHyperlinkMarkAttrs } from "../../attrs/index.js";
4
4
  import { withCanonicalCommand } from "../../canonicalCommands.js";
5
5
  import { canonicalSelectionRange } from "../../canonicalSelectionRange.js";
6
- import { assertHyperlinkRemovalRange, removeHyperlinkInRange } from "../../hyperlinkRemoval.js";
6
+ import { removeHyperlinkInRange, widenHyperlinkRemovalRange } from "../../hyperlinkRemoval.js";
7
7
  import { getDocumentBuiltInStyles } from "../../plugins/documentStyleState.js";
8
8
  import { createMarkExtension } from "../create.js";
9
9
  import { isMarkActive } from "./markUtils.js";
@@ -158,18 +158,16 @@ const HyperlinkExtension = createMarkExtension({
158
158
  }]);
159
159
  const removalRange = (state) => {
160
160
  if (state.selection instanceof CellSelection) return void 0;
161
- const { empty, $from } = state.selection;
162
- const { from, to } = canonicalSelectionRange(state);
163
- assertHyperlinkRemovalRange({
161
+ const { from, to } = widenHyperlinkRemovalRange({
164
162
  doc: state.doc,
165
- from,
166
- to
163
+ ...canonicalSelectionRange(state)
167
164
  });
168
- if (!empty) return {
165
+ if (!state.selection.empty) return {
169
166
  from,
170
167
  to
171
168
  };
172
- const linkMark = $from.marks().find((mark) => mark.type === documentHyperlinkType(state));
169
+ const $from = state.doc.resolve(from);
170
+ const linkMark = (from === to ? $from.marks() : state.doc.nodeAt(from)?.marks ?? []).find((mark) => mark.type === documentHyperlinkType(state));
173
171
  if (!linkMark) return void 0;
174
172
  let contiguous;
175
173
  let selected;
@@ -10,23 +10,26 @@
10
10
  * text never did. Rejecting brings the link back as it was; accepting leaves
11
11
  * the plain text an untracked removal leaves.
12
12
  */
13
- import { TaggedErrorClass } from "better-result";
14
13
  import { EditorState, Transaction } from "prosemirror-state";
15
14
  import { Node } from "prosemirror-model";
16
- declare const HyperlinkRemovalRefusalBase: TaggedErrorClass<"HyperlinkRemovalRefusal">;
17
- export declare class HyperlinkRemovalRefusal extends HyperlinkRemovalRefusalBase<{
18
- message: string;
19
- }> {}
20
15
  type HyperlinkRemovalRangeOptions = {
21
16
  doc: Node;
22
17
  from: number;
23
18
  to: number;
24
19
  };
25
- /** Canonical inline elements have no addressable interior gaps. */
26
- export declare const assertHyperlinkRemovalRange: ({ doc, from, to }: HyperlinkRemovalRangeOptions) => void;
20
+ /**
21
+ * The removal range widened to the edges of every linked inline element an
22
+ * endpoint falls inside. Such an element, a field result a link holds whole
23
+ * (a contents entry's page number), carries the link as one mark: the link
24
+ * leaves all of it or none of it, as Remove Hyperlink takes the whole link.
25
+ */
26
+ export declare const widenHyperlinkRemovalRange: ({ doc, from, to }: HyperlinkRemovalRangeOptions) => {
27
+ from: number;
28
+ to: number;
29
+ };
27
30
  /**
28
31
  * Remove the hyperlinks from [`from`, `to`) of `tr.doc`: directly, or, with
29
32
  * suggestions on, as a tracked replacement of the linked text by plain text.
30
33
  */
31
- export declare const removeHyperlinkInRange: (state: EditorState, tr: Transaction, from: number, to: number) => Transaction;
34
+ export declare const removeHyperlinkInRange: (state: EditorState, tr: Transaction, requestedFrom: number, requestedTo: number) => Transaction;
32
35
  export {};
@@ -3,7 +3,7 @@ import { getDocumentBuiltInStyles, getDocumentStyleResolver } from "./plugins/do
3
3
  import { readAuthoredRunFormatting, reconcileRunFormattingMarks } from "./runFormattingReconciliation.js";
4
4
  import { paragraphRunStyleContextAt } from "./runStyleFormatting.js";
5
5
  import { isSuggestionModeActive, makeRevisionInfo, suggestRangeDeletion } from "./suggestionCommands.js";
6
- import { TaggedError } from "better-result";
6
+ import { panic } from "better-result";
7
7
  // src/prosemirror/hyperlinkRemoval.ts
8
8
  /**
9
9
  * Removing a hyperlink takes the link and its Hyperlink character style off
@@ -17,18 +17,27 @@ import { TaggedError } from "better-result";
17
17
  * text never did. Rejecting brings the link back as it was; accepting leaves
18
18
  * the plain text an untracked removal leaves.
19
19
  */
20
- const HyperlinkRemovalRefusalBase = TaggedError("HyperlinkRemovalRefusal");
21
- var HyperlinkRemovalRefusal = class extends HyperlinkRemovalRefusalBase {};
22
- const partialInlineRefusal = () => new HyperlinkRemovalRefusal({ message: "Hyperlink removal cannot split an indivisible inline element." });
23
- /** Canonical inline elements have no addressable interior gaps. */
24
- const assertHyperlinkRemovalRange = ({ doc, from, to }) => {
25
- for (const position of [from, to]) {
20
+ /**
21
+ * The removal range widened to the edges of every linked inline element an
22
+ * endpoint falls inside. Such an element, a field result a link holds whole
23
+ * (a contents entry's page number), carries the link as one mark: the link
24
+ * leaves all of it or none of it, as Remove Hyperlink takes the whole link.
25
+ */
26
+ const widenHyperlinkRemovalRange = ({ doc, from, to }) => {
27
+ const outermostLinked = (position) => {
26
28
  const resolved = doc.resolve(position);
27
29
  for (let depth = 1; depth <= resolved.depth; depth += 1) {
28
30
  const node = resolved.node(depth);
29
- if (node.isInline && node.marks.some(({ type }) => type.name === "hyperlink")) throw partialInlineRefusal();
31
+ if (node.isInline && node.marks.some(({ type }) => type.name === "hyperlink")) return {
32
+ from: resolved.before(depth),
33
+ to: resolved.after(depth)
34
+ };
30
35
  }
31
- }
36
+ };
37
+ return {
38
+ from: outermostLinked(from)?.from ?? from,
39
+ to: outermostLinked(to)?.to ?? to
40
+ };
32
41
  };
33
42
  /** Contiguous stretches of linked, not yet deleted, inline content in [`from`, `to`) of `doc`. */
34
43
  const linkedRanges = (doc, from, to) => {
@@ -38,7 +47,7 @@ const linkedRanges = (doc, from, to) => {
38
47
  const start = Math.max(position, from);
39
48
  const end = Math.min(position + node.nodeSize, to);
40
49
  if (start >= end) return true;
41
- if (!node.isText && (start !== position || end !== position + node.nodeSize)) throw partialInlineRefusal();
50
+ if (!node.isText && (start !== position || end !== position + node.nodeSize)) panic("A widened removal range cut a linked inline element.");
42
51
  const piece = {
43
52
  from: start,
44
53
  to: end,
@@ -96,11 +105,11 @@ const setInlineMarks = (tr, from, to, current, marks) => {
96
105
  * Remove the hyperlinks from [`from`, `to`) of `tr.doc`: directly, or, with
97
106
  * suggestions on, as a tracked replacement of the linked text by plain text.
98
107
  */
99
- const removeHyperlinkInRange = (state, tr, from, to) => {
100
- assertHyperlinkRemovalRange({
108
+ const removeHyperlinkInRange = (state, tr, requestedFrom, requestedTo) => {
109
+ const { from, to } = widenHyperlinkRemovalRange({
101
110
  doc: tr.doc,
102
- from,
103
- to
111
+ from: requestedFrom,
112
+ to: requestedTo
104
113
  });
105
114
  const { schema } = state;
106
115
  const hyperlinkType = schema.marks["hyperlink"];
@@ -162,4 +171,4 @@ const removeHyperlinkInRange = (state, tr, from, to) => {
162
171
  }
163
172
  return tr;
164
173
  };
165
- export { HyperlinkRemovalRefusal, assertHyperlinkRemovalRange, removeHyperlinkInRange };
174
+ export { removeHyperlinkInRange, widenHyperlinkRemovalRange };
@@ -0,0 +1,27 @@
1
+ import { Node } from "prosemirror-model";
2
+ import { ResolvedMarkupDocumentView, RevisionDecision } from "@stll/docx-core/ops";
3
+ import { StepMap } from "prosemirror-transform";
4
+ type InlineChanges = NonNullable<ResolvedMarkupDocumentView["independentInline"]>;
5
+ type PositionRange = {
6
+ from: number;
7
+ to: number;
8
+ };
9
+ export type IndependentMarkupProjection = {
10
+ doc: Node;
11
+ positionMap: StepMap;
12
+ changeBarRanges: readonly PositionRange[];
13
+ };
14
+ /**
15
+ * The native resolver supplies exactly which text ranges disappeared. Keep the
16
+ * original formatting and addresses of the rest, without converting standing
17
+ * blocks or reconstructing their run styles.
18
+ */
19
+ export declare const projectIndependentMarkup: ({ doc, changes, indices }: {
20
+ doc: Node;
21
+ changes: InlineChanges;
22
+ /** For a detached source, where the inspected paragraphs originally stood. */
23
+ indices?: readonly number[];
24
+ }) => IndependentMarkupProjection | undefined;
25
+ /** Project a detached text story after canonical resolution of its text carriers. */
26
+ export declare const projectDetachedText: (doc: Node, decision: RevisionDecision) => IndependentMarkupProjection | undefined;
27
+ export {};
@@ -0,0 +1,147 @@
1
+ import { expectTrackedChangeMarkAttrs } from "./attrs/index.js";
2
+ import "./extensions/marks/InlineWrapperExtension.js";
3
+ import { getFolioNodeRevisionCarriers } from "./revisionCarriers.js";
4
+ import { resolvedMarkupDocumentView } from "@stll/docx-core/ops";
5
+ import { Fragment } from "prosemirror-model";
6
+ import { StepMap } from "prosemirror-transform";
7
+ // src/prosemirror/independentMarkupProjection.ts
8
+ const isInlineRevision = (name) => name === "insertion" || name === "deletion";
9
+ const projectedText = (paragraph, { omitted }) => {
10
+ const nodes = [];
11
+ let cutIndex = 0;
12
+ for (let index = 0, start = 0; index < paragraph.childCount; index += 1) {
13
+ const node = paragraph.child(index);
14
+ if (!node.isText) return void 0;
15
+ const end = start + node.nodeSize;
16
+ const marks = node.marks.filter(({ type }) => !isInlineRevision(type.name));
17
+ let at = start;
18
+ for (let cut = omitted[cutIndex]; cut !== void 0 && cut.from < end;) {
19
+ if (cut.from > at) nodes.push(node.cut(at - start, cut.from - start).mark(marks));
20
+ at = Math.max(at, cut.to);
21
+ if (cut.to > end) break;
22
+ cutIndex += 1;
23
+ cut = omitted[cutIndex];
24
+ }
25
+ if (at < end) nodes.push(node.cut(at - start).mark(marks));
26
+ start = end;
27
+ }
28
+ return Fragment.fromArray(nodes);
29
+ };
30
+ /**
31
+ * The native resolver supplies exactly which text ranges disappeared. Keep the
32
+ * original formatting and addresses of the rest, without converting standing
33
+ * blocks or reconstructing their run styles.
34
+ */
35
+ const projectIndependentMarkup = ({ doc, changes, indices }) => {
36
+ if (changes.length === 0) return {
37
+ doc,
38
+ positionMap: StepMap.empty,
39
+ changeBarRanges: []
40
+ };
41
+ const children = [];
42
+ const ranges = [];
43
+ const changeBarRanges = [];
44
+ let previous = 0;
45
+ let changeIndex = 0;
46
+ let removed = 0;
47
+ let last = -1;
48
+ for (let index = 0, position = 0; index < doc.childCount; index += 1) {
49
+ const original = doc.child(index);
50
+ const change = changes[changeIndex];
51
+ const target = change === void 0 ? void 0 : indices?.[change.index] ?? change.index;
52
+ if (change === void 0 || target !== index) {
53
+ children.push(original);
54
+ position += original.nodeSize;
55
+ continue;
56
+ }
57
+ if (original.type.name !== "paragraph" || original.content.size !== change.sourceLength) return void 0;
58
+ const content = projectedText(original, change);
59
+ if (content === void 0) return void 0;
60
+ const paragraph = original.copy(content);
61
+ const from = position - removed;
62
+ changeBarRanges.push({
63
+ from,
64
+ to: from + paragraph.nodeSize
65
+ });
66
+ children.push(paragraph);
67
+ for (const { from: first, to } of change.omitted) {
68
+ const start = position + 1 + first;
69
+ const width = to - first;
70
+ if (start === last) ranges[previous + 1] = (ranges[previous + 1] ?? 0) + width;
71
+ else {
72
+ previous = ranges.length;
73
+ ranges.push(start, width, 0);
74
+ }
75
+ last = start + width;
76
+ removed += width;
77
+ }
78
+ position += original.nodeSize;
79
+ changeIndex += 1;
80
+ }
81
+ if (changeIndex !== changes.length) return void 0;
82
+ return {
83
+ doc: doc.copy(Fragment.fromArray(children)),
84
+ positionMap: new StepMap(ranges),
85
+ changeBarRanges
86
+ };
87
+ };
88
+ /** Project a detached text story after canonical resolution of its text carriers. */
89
+ const projectDetachedText = (doc, decision) => {
90
+ const changed = [];
91
+ const indices = [];
92
+ for (let index = 0, position = 0; index < doc.childCount; index += 1) {
93
+ const paragraph = doc.child(index);
94
+ if (paragraph.type.name !== "paragraph" || paragraph.attrs["_suggestedInsert"] != null || getFolioNodeRevisionCarriers(paragraph, position).length > 0) return void 0;
95
+ let revised = false;
96
+ const content = [];
97
+ for (let childIndex = 0; childIndex < paragraph.childCount; childIndex += 1) {
98
+ const child = paragraph.child(childIndex);
99
+ if (!child.isText || child.text === void 0) return void 0;
100
+ let wrapper;
101
+ const run = {
102
+ type: "run",
103
+ content: [{
104
+ type: "text",
105
+ text: child.text
106
+ }]
107
+ };
108
+ for (const mark of child.marks) {
109
+ const type = mark.type.name;
110
+ if (type === "comment" || type === "hyperlink" || type === "runPropertyChange" || type === "inlineWrapper") return void 0;
111
+ if (type !== "insertion" && type !== "deletion") continue;
112
+ const attrs = expectTrackedChangeMarkAttrs(mark);
113
+ if (wrapper !== void 0 || attrs.moveKind != null || attrs._docxResolutionJoins != null || (attrs._docxRevisionAncestors?.length ?? 0) > 0) return void 0;
114
+ wrapper = {
115
+ type,
116
+ info: {
117
+ id: attrs.revisionId,
118
+ author: attrs.author
119
+ },
120
+ content: [run]
121
+ };
122
+ }
123
+ revised ||= wrapper !== void 0;
124
+ content.push(wrapper ?? run);
125
+ }
126
+ if (revised) {
127
+ changed.push({
128
+ type: "paragraph",
129
+ content
130
+ });
131
+ indices.push(index);
132
+ }
133
+ position += paragraph.nodeSize;
134
+ }
135
+ if (changed.length === 0) return {
136
+ doc,
137
+ positionMap: StepMap.empty,
138
+ changeBarRanges: []
139
+ };
140
+ const resolved = resolvedMarkupDocumentView({ package: { document: { content: changed } } }, decision);
141
+ return resolved.independentInline === void 0 ? void 0 : projectIndependentMarkup({
142
+ doc,
143
+ changes: resolved.independentInline,
144
+ indices
145
+ });
146
+ };
147
+ export { projectDetachedText, projectIndependentMarkup };
@@ -12,4 +12,4 @@ import { DisplayMode } from "../managers/EditorModeManager.js";
12
12
  import { document_d_exports } from "../types/document.js";
13
13
  import { EditorState } from "prosemirror-state";
14
14
  /** The footnotes or endnotes as `view` shows them. */
15
- export declare const markupViewNotes: <TNote extends document_d_exports.Footnote | document_d_exports.Endnote>(notes: TNote[] | undefined, view: DisplayMode, state: EditorState, document: document_d_exports.Document | null) => TNote[] | undefined;
15
+ export declare const markupViewNotes: <TNote extends document_d_exports.Footnote | document_d_exports.Endnote>(notes: TNote[] | undefined, view: DisplayMode, _state: EditorState, document: document_d_exports.Document | null) => TNote[] | undefined;
@@ -1,46 +1,43 @@
1
- import { resolveWholeStory } from "../internal/wholeStoryRevisionResolution.js";
2
- import { proseDocToBlocks } from "./conversion/fromProseDoc.js";
3
- import { footnoteToProseDoc } from "./conversion/toProseDoc.js";
4
1
  import { markupViewResolutionMode } from "./markupViewProjection.js";
5
- import { getDocumentNumbering } from "./plugins/documentNumbering.js";
6
- import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
2
+ import { findStoryBody, resolvedMarkupDocumentView } from "@stll/docx-core/ops";
7
3
  // src/prosemirror/markupViewNotes.ts
8
4
  const resolvedNotes = /* @__PURE__ */ new WeakMap();
9
- const resolvedNote = (note, mode, state, document) => {
10
- const styleResolver = getDocumentStyleResolver(state);
11
- const cached = resolvedNotes.get(note)?.get(mode);
12
- if (cached?.styleResolver === styleResolver) return cached.note;
13
- const { styles, theme, numbering } = document.package;
14
- const doc = footnoteToProseDoc(note.content, {
5
+ const resolvedNote = (note, decision, { styles, theme, numbering }) => {
6
+ const byDecision = resolvedNotes.get(note) ?? /* @__PURE__ */ new Map();
7
+ const cached = byDecision.get(decision);
8
+ if (cached !== void 0 && cached.styles === styles && cached.theme === theme && cached.numbering === numbering) return cached.note;
9
+ const source = { package: {
10
+ document: { content: [] },
11
+ ...note.type === "footnote" ? { footnotes: [note] } : { endnotes: [note] },
15
12
  ...styles !== void 0 && { styles },
16
13
  ...theme !== void 0 && { theme },
17
14
  ...numbering !== void 0 && { numbering }
15
+ } };
16
+ const view = resolvedMarkupDocumentView(source, decision);
17
+ const body = findStoryBody(view.document, {
18
+ kind: note.type,
19
+ id: note.id
18
20
  });
19
- const result = resolveWholeStory({
20
- doc,
21
- mode,
22
- styleResolver,
23
- numbering: getDocumentNumbering(state)
24
- });
25
- const resolved = result.failed || result.resolved.eq(doc) ? note : {
21
+ const resolved = body === void 0 || body.content === note.content ? note : {
26
22
  ...note,
27
- content: proseDocToBlocks(result.resolved, note.content, styles)
23
+ content: body.content
28
24
  };
29
- const byMode = resolvedNotes.get(note) ?? /* @__PURE__ */ new Map();
30
- byMode.set(mode, {
31
- styleResolver,
25
+ byDecision.set(decision, {
26
+ ...styles !== void 0 && { styles },
27
+ ...theme !== void 0 && { theme },
28
+ ...numbering !== void 0 && { numbering },
32
29
  note: resolved
33
30
  });
34
- resolvedNotes.set(note, byMode);
31
+ resolvedNotes.set(note, byDecision);
35
32
  return resolved;
36
33
  };
37
34
  /** The footnotes or endnotes as `view` shows them. */
38
- const markupViewNotes = (notes, view, state, document) => {
39
- const mode = markupViewResolutionMode(view);
40
- if (!notes || !mode || !document) return notes;
35
+ const markupViewNotes = (notes, view, _state, document) => {
36
+ const decision = markupViewResolutionMode(view);
37
+ if (!notes || !decision || !document) return notes;
41
38
  let changed = false;
42
39
  const shown = notes.map((note) => {
43
- const resolved = resolvedNote(note, mode, state, document);
40
+ const resolved = resolvedNote(note, decision, document.package);
44
41
  changed ||= resolved !== note;
45
42
  return resolved;
46
43
  });