@stll/folio-core 0.52.0 → 0.53.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 (307) hide show
  1. package/README.md +23 -0
  2. package/dist/ai-edits/apply.d.ts +26 -1
  3. package/dist/ai-edits/apply.js +1519 -105
  4. package/dist/ai-edits/batch-claims.d.ts +130 -0
  5. package/dist/ai-edits/batch-claims.js +244 -0
  6. package/dist/ai-edits/blockRange.js +9 -3
  7. package/dist/ai-edits/character-boundaries.d.ts +43 -0
  8. package/dist/ai-edits/character-boundaries.js +95 -0
  9. package/dist/ai-edits/clean-text.d.ts +33 -3
  10. package/dist/ai-edits/clean-text.js +52 -6
  11. package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
  12. package/dist/ai-edits/comment-lifecycle.js +52 -0
  13. package/dist/ai-edits/headless.d.ts +71 -7
  14. package/dist/ai-edits/headless.js +381 -41
  15. package/dist/ai-edits/index.d.ts +2 -1
  16. package/dist/ai-edits/index.js +2 -1
  17. package/dist/ai-edits/minimal-replacement.d.ts +21 -6
  18. package/dist/ai-edits/minimal-replacement.js +134 -15
  19. package/dist/ai-edits/newListNumbering.d.ts +23 -0
  20. package/dist/ai-edits/newListNumbering.js +94 -0
  21. package/dist/ai-edits/note-references.d.ts +96 -0
  22. package/dist/ai-edits/note-references.js +139 -0
  23. package/dist/ai-edits/pending-suggestions.d.ts +79 -0
  24. package/dist/ai-edits/pending-suggestions.js +306 -0
  25. package/dist/ai-edits/read.d.ts +1 -1
  26. package/dist/ai-edits/read.js +56 -43
  27. package/dist/ai-edits/result-validation.d.ts +29 -0
  28. package/dist/ai-edits/result-validation.js +164 -0
  29. package/dist/ai-edits/snapshot.d.ts +36 -3
  30. package/dist/ai-edits/snapshot.js +177 -23
  31. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  32. package/dist/ai-edits/table-cell-mutations.js +4 -1
  33. package/dist/ai-edits/table-geometry.d.ts +1 -1
  34. package/dist/ai-edits/table-row-column-mutations.d.ts +38 -16
  35. package/dist/ai-edits/table-row-column-mutations.js +61 -26
  36. package/dist/ai-edits/types.d.ts +155 -16
  37. package/dist/compare/compare.d.ts +1 -1
  38. package/dist/compare/compare.js +65 -16
  39. package/dist/compare/content-alignment.js +13 -2
  40. package/dist/compare/content-types.d.ts +7 -0
  41. package/dist/compare/content.d.ts +4 -1
  42. package/dist/compare/content.js +6 -1
  43. package/dist/compare/formatting.js +2 -1
  44. package/dist/compare/inline-atoms.d.ts +21 -4
  45. package/dist/compare/inline-atoms.js +138 -16
  46. package/dist/compare/plan.js +10 -5
  47. package/dist/compare/scenario.js +14 -3
  48. package/dist/compare/section-boundary-properties.js +1 -1
  49. package/dist/compare/types.d.ts +4 -2
  50. package/dist/compare/types.js +2 -1
  51. package/dist/compare/verification.d.ts +1 -1
  52. package/dist/compare/verification.js +15 -3
  53. package/dist/controller/committedLayoutDiff.d.ts +25 -0
  54. package/dist/controller/committedLayoutDiff.js +71 -0
  55. package/dist/controller/contentControlWidgetController.d.ts +1 -1
  56. package/dist/controller/folioEditor.d.ts +1 -1
  57. package/dist/controller/fontReadiness.d.ts +70 -3
  58. package/dist/controller/fontReadiness.js +100 -10
  59. package/dist/controller/headerFooterEditorManager.js +6 -1
  60. package/dist/controller/layoutPipeline.d.ts +12 -10
  61. package/dist/controller/layoutPipeline.js +62 -9
  62. package/dist/controller/layoutRunOptions.d.ts +24 -0
  63. package/dist/controller/layoutRunOptions.js +17 -0
  64. package/dist/controller/layoutScheduler.d.ts +19 -14
  65. package/dist/controller/layoutScheduler.js +15 -12
  66. package/dist/controller/layoutSession.d.ts +26 -2
  67. package/dist/controller/layoutSession.js +1 -1
  68. package/dist/controller/noteEditorManager.js +8 -3
  69. package/dist/document-operations.d.ts +11 -2
  70. package/dist/document-operations.js +230 -21
  71. package/dist/docx/altChunk.d.ts +8 -0
  72. package/dist/docx/altChunk.js +17 -0
  73. package/dist/docx/attributeRemainder.d.ts +1 -1
  74. package/dist/docx/blockContentParser.d.ts +64 -1
  75. package/dist/docx/blockContentParser.js +17 -4
  76. package/dist/docx/blockCustomXmlShell.d.ts +7 -0
  77. package/dist/docx/blockCustomXmlShell.js +14 -0
  78. package/dist/docx/blockPlainText.js +7 -0
  79. package/dist/docx/commentAnchorIndex.js +1 -1
  80. package/dist/docx/commentRangeIntegrity.js +8 -3
  81. package/dist/docx/commentReferenceNormalization.js +1 -1
  82. package/dist/docx/commentReplyMarkers.js +20 -1
  83. package/dist/docx/compatibility.d.ts +1 -1
  84. package/dist/docx/compatibility.js +34 -13
  85. package/dist/docx/containerChildren.gen.d.ts +1 -1
  86. package/dist/docx/containerChildren.gen.js +1 -0
  87. package/dist/docx/documentParser.js +12 -12
  88. package/dist/docx/drawingIdNormalization.d.ts +3 -1
  89. package/dist/docx/drawingIdNormalization.js +6 -1
  90. package/dist/docx/ensureParaIds.js +119 -97
  91. package/dist/docx/footnoteParser.js +8 -4
  92. package/dist/docx/headerFooterParser.js +3 -3
  93. package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
  94. package/dist/docx/headerFooterReferenceNormalization.js +52 -27
  95. package/dist/docx/hyperlinkParser.d.ts +1 -1
  96. package/dist/docx/index.d.ts +1 -1
  97. package/dist/docx/listNumberingInstances.d.ts +59 -0
  98. package/dist/docx/listNumberingInstances.js +249 -0
  99. package/dist/docx/normalizeBaseDirection.js +2 -1
  100. package/dist/docx/opaqueCarrier.d.ts +7 -0
  101. package/dist/docx/opaqueCarrier.js +38 -0
  102. package/dist/docx/packageParts.js +4 -1
  103. package/dist/docx/paragraphParser.js +91 -24
  104. package/dist/docx/paragraphPropertySource.d.ts +4 -2
  105. package/dist/docx/paragraphPropertySource.js +7 -1
  106. package/dist/docx/paragraphTraversal.js +1 -0
  107. package/dist/docx/parseWarningMessage.js +4 -1
  108. package/dist/docx/parser.js +173 -20
  109. package/dist/docx/rezip.js +27 -5
  110. package/dist/docx/sdtProperties.js +1 -1
  111. package/dist/docx/sdtPropertiesPatch.js +3 -0
  112. package/dist/docx/selectiveSave.js +16 -9
  113. package/dist/docx/selectiveXmlPatch.js +106 -37
  114. package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
  115. package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
  116. package/dist/docx/serializer/documentSerializer.js +2 -0
  117. package/dist/docx/serializer/headerFooterSerializer.js +2 -0
  118. package/dist/docx/serializer/noteSerializer.js +3 -1
  119. package/dist/docx/serializer/paragraphSerializer.js +33 -9
  120. package/dist/docx/serializer/tableSerializer.js +25 -38
  121. package/dist/docx/server/createBilingualDocument.js +3 -3
  122. package/dist/docx/tableParser.d.ts +157 -1
  123. package/dist/docx/tableParser.js +89 -10
  124. package/dist/docx/textBoxParser.js +1 -1
  125. package/dist/docx/unzip.d.ts +2 -1
  126. package/dist/docx/unzip.js +1 -1
  127. package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
  128. package/dist/docx/wordprocessingPrefixes.js +286 -0
  129. package/dist/i18n/messages/catalogs.gen.d.ts +136 -0
  130. package/dist/i18n/messages/catalogs.gen.js +153 -17
  131. package/dist/i18n/messages/messages.gen.d.ts +8 -0
  132. package/dist/internal/compare/inline-presentation.d.ts +2 -1
  133. package/dist/internal/compare/inline-presentation.js +11 -10
  134. package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
  135. package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
  136. package/dist/internal/indexedPositionMap.d.ts +11 -0
  137. package/dist/internal/indexedPositionMap.js +42 -0
  138. package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
  139. package/dist/internal/revisionResolutionEdits.d.ts +13 -0
  140. package/dist/internal/revisionResolutionEdits.js +19 -0
  141. package/dist/internal/revisionResolutionInline.d.ts +24 -0
  142. package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
  143. package/dist/internal/revisionResolutionStep.d.ts +34 -0
  144. package/dist/internal/revisionResolutionStep.js +282 -0
  145. package/dist/internal/revisionResolutionTracking.d.ts +11 -0
  146. package/dist/internal/revisionResolutionTracking.js +124 -0
  147. package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
  148. package/dist/internal/wholeStoryRevisionResolution.js +530 -0
  149. package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
  150. package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
  151. package/dist/layout-bridge/convert/tableConversion.js +1 -1
  152. package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
  153. package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
  154. package/dist/layout-engine/layoutInstrumentation.js +4 -1
  155. package/dist/layout-engine/measure/cache.d.ts +18 -1
  156. package/dist/layout-engine/measure/cache.js +31 -1
  157. package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
  158. package/dist/layout-engine/measure/measureContainer.js +7 -47
  159. package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
  160. package/dist/layout-engine/measure/measureHelpers.js +22 -2
  161. package/dist/layout-engine/measure/measureWorker.js +2 -3
  162. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
  163. package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
  164. package/dist/layout-engine/types.d.ts +6 -0
  165. package/dist/layout-painter/renderPage.js +1 -0
  166. package/dist/layout-painter/renderParagraph.js +1 -1
  167. package/dist/managers/ContextMenuManager.js +5 -2
  168. package/dist/managers/types.d.ts +3 -0
  169. package/dist/markdown/fromMarkdown.js +2 -1
  170. package/dist/markdown/internals.d.ts +11 -1
  171. package/dist/markdown/internals.js +24 -3
  172. package/dist/markdown/renderBlock.js +39 -9
  173. package/dist/markdown/renderParagraph.d.ts +13 -1
  174. package/dist/markdown/renderParagraph.js +85 -38
  175. package/dist/markdown/renderRuns.js +3 -10
  176. package/dist/markdown/renderTable.js +24 -12
  177. package/dist/markdown/trailers.js +2 -2
  178. package/dist/markdown/types.d.ts +29 -7
  179. package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
  180. package/dist/paged-layout/incrementalMeasure.js +1 -9
  181. package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
  182. package/dist/paged-layout/transactionDirtyRange.js +29 -41
  183. package/dist/panel-layout.d.ts +83 -0
  184. package/dist/panel-layout.js +96 -0
  185. package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
  186. package/dist/prosemirror/anchoredTextBoxes.js +156 -0
  187. package/dist/prosemirror/attrs/index.d.ts +6 -2
  188. package/dist/prosemirror/attrs/index.js +172 -1
  189. package/dist/prosemirror/commands/comments.d.ts +7 -8
  190. package/dist/prosemirror/commands/comments.js +241 -207
  191. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  192. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +2 -2
  195. package/dist/prosemirror/commands/index.js +2 -2
  196. package/dist/prosemirror/commands/paragraph.d.ts +7 -1
  197. package/dist/prosemirror/commands/paragraph.js +9 -1
  198. package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
  199. package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
  200. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  201. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
  202. package/dist/prosemirror/commands/resolveAllTableChanges.js +615 -0
  203. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
  204. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
  205. package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
  206. package/dist/prosemirror/commands/resolveParagraphProperties.js +59 -0
  207. package/dist/prosemirror/commands/sectionBreak.js +2 -1
  208. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +8 -2
  209. package/dist/prosemirror/commands/tableCellMergeResolution.js +1 -1
  210. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  211. package/dist/prosemirror/conversion/fromProseDoc.js +181 -31
  212. package/dist/prosemirror/conversion/toProseDoc.js +39 -4
  213. package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
  214. package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
  215. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  216. package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
  217. package/dist/prosemirror/extensions/StarterKit.js +3 -1
  218. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  219. package/dist/prosemirror/extensions/core/ParagraphExtension.js +12 -0
  220. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -0
  221. package/dist/prosemirror/extensions/features/ListExtension.js +161 -123
  222. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
  223. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
  224. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
  225. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
  226. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
  227. package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
  228. package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
  229. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +126 -0
  230. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +21 -5
  231. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
  232. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
  233. package/dist/prosemirror/extensions/marks/markUtils.d.ts +7 -2
  234. package/dist/prosemirror/extensions/marks/markUtils.js +8 -2
  235. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +10 -0
  236. package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +35 -0
  237. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
  238. package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
  239. package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
  240. package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
  241. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
  242. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  243. package/dist/prosemirror/extensions/nodes/TableExtension.js +19 -18
  244. package/dist/prosemirror/extensions/types.d.ts +4 -1
  245. package/dist/prosemirror/findReplaceSelection.js +1 -1
  246. package/dist/prosemirror/index.d.ts +3 -2
  247. package/dist/prosemirror/index.js +3 -2
  248. package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
  249. package/dist/prosemirror/indexedNodeLookup.js +103 -0
  250. package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
  251. package/dist/prosemirror/listAutoformatMarkers.js +98 -0
  252. package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
  253. package/dist/prosemirror/listInstanceReferences.js +72 -0
  254. package/dist/prosemirror/listLabels.d.ts +24 -0
  255. package/dist/prosemirror/listLabels.js +111 -0
  256. package/dist/prosemirror/listNumbering.d.ts +110 -0
  257. package/dist/prosemirror/listNumbering.js +345 -0
  258. package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
  259. package/dist/prosemirror/listRenderingAttrs.js +8 -1
  260. package/dist/prosemirror/markupViewProjection.d.ts +95 -0
  261. package/dist/prosemirror/markupViewProjection.js +83 -0
  262. package/dist/prosemirror/numberingAttr.d.ts +9 -1
  263. package/dist/prosemirror/numberingAttr.js +9 -1
  264. package/dist/prosemirror/outlineLevelAttr.js +1 -1
  265. package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
  266. package/dist/prosemirror/paragraphIndentation.js +29 -7
  267. package/dist/prosemirror/paragraphMarkJoin.d.ts +19 -0
  268. package/dist/prosemirror/paragraphMarkJoin.js +24 -0
  269. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  270. package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
  271. package/dist/prosemirror/plugins/documentNumbering.js +97 -11
  272. package/dist/prosemirror/plugins/documentStyles.d.ts +10 -1
  273. package/dist/prosemirror/plugins/documentStyles.js +14 -1
  274. package/dist/prosemirror/plugins/suggestionMode.d.ts +16 -2
  275. package/dist/prosemirror/plugins/suggestionMode.js +116 -52
  276. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  277. package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
  278. package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
  279. package/dist/prosemirror/positionSweep.d.ts +24 -0
  280. package/dist/prosemirror/positionSweep.js +222 -0
  281. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  282. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  283. package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
  284. package/dist/prosemirror/replacedAnnotations.js +170 -1
  285. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  286. package/dist/prosemirror/schema/index.d.ts +2 -2
  287. package/dist/prosemirror/schema/index.js +3 -0
  288. package/dist/prosemirror/schema/nodes.d.ts +42 -11
  289. package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
  290. package/dist/prosemirror/sectionMarkEdits.js +59 -0
  291. package/dist/prosemirror/storyListNumbering.d.ts +17 -0
  292. package/dist/prosemirror/storyListNumbering.js +102 -0
  293. package/dist/prosemirror/tableGridMutation.d.ts +48 -2
  294. package/dist/prosemirror/tableGridMutation.js +106 -1
  295. package/dist/prosemirror/validation.js +5 -1
  296. package/dist/redline.js +93 -9
  297. package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
  298. package/dist/render-dom/BodySelectionOverlay.js +3 -2
  299. package/dist/utils/findReplace.js +2 -2
  300. package/dist/utils/mergeDocumentContent.js +1 -1
  301. package/dist/utils/noteReferenceLabels.d.ts +36 -0
  302. package/dist/utils/noteReferenceLabels.js +32 -0
  303. package/dist/utils/replaceText.js +1 -1
  304. package/dist/version-comparison.d.ts +1 -0
  305. package/dist/version-comparison.js +1 -0
  306. package/package.json +3 -2
  307. package/dist/internal/headlessRevisionResolution.d.ts +0 -23
@@ -0,0 +1,615 @@
1
+ import { restoreTableCellsWithParagraphPropertySources, transportTableCellsWithParagraphPropertySources } from "../../docx/paragraphPropertySource.js";
2
+ import { isTableCellMergeRevisionContinuation, isTableCellMergeRevisionValue } from "../../docx/tableParser.js";
3
+ import { expectTableAttrs, mergeTableAttrs } from "../attrs/index.js";
4
+ import { nodePropertyRevisionSites, propertyRevisionRecords } from "../revisionCarriers.js";
5
+ import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
6
+ import { isTableCellRetainedInReviewView } from "../tableCellRevisionVisibility.js";
7
+ import { resolveAllNodePropertyChangeAttrs } from "./resolveNodePropertyChangeAttrs.js";
8
+ import { createRestoredTableCell, hasMatchingCollapsedTableCellMerge, tableCellContinuationCells, tableCellContinuationFromNode, tableCellContinuationPayload } from "./tableCellMergeResolution.js";
9
+ import { panic } from "better-result";
10
+ import { TableMap } from "prosemirror-tables";
11
+ import { StepMap } from "prosemirror-transform";
12
+ //#region src/prosemirror/commands/resolveAllTableChanges.ts
13
+ const indexedTableCells = (map) => {
14
+ const rectangles = /* @__PURE__ */ new Map();
15
+ for (let index = 0; index < map.map.length; index++) {
16
+ const position = map.map[index];
17
+ if (position === void 0 || rectangles.has(position)) continue;
18
+ const left = index % map.width;
19
+ const top = Math.floor(index / map.width);
20
+ let right = left + 1;
21
+ let bottom = top + 1;
22
+ while (right < map.width && map.map[index + right - left] === position) right++;
23
+ while (bottom < map.height && map.map[index + (bottom - top) * map.width] === position) bottom++;
24
+ rectangles.set(position, {
25
+ left,
26
+ top,
27
+ right,
28
+ bottom
29
+ });
30
+ }
31
+ return (position) => rectangles.get(position) ?? panic("Missing table resolution rectangle", { position });
32
+ };
33
+ const elementAt = (items, index) => {
34
+ const item = items.at(index);
35
+ return item === void 0 ? panic("Missing table resolution element", { index }) : item;
36
+ };
37
+ const tableResolutionMetadata = ({ sourceTable, table, rows, tableTouched }) => {
38
+ const changedParagraphRanges = [];
39
+ const paragraphOffsets = [];
40
+ const anchors = [];
41
+ const finalCellStarts = [];
42
+ if (tableTouched) changedParagraphRanges.push({
43
+ from: 0,
44
+ to: table.nodeSize
45
+ });
46
+ let rowStart = 1;
47
+ for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
48
+ const row = table.child(rowIndex);
49
+ const metadata = elementAt(rows, rowIndex);
50
+ if (!tableTouched && metadata.touched) changedParagraphRanges.push({
51
+ from: rowStart,
52
+ to: rowStart + row.nodeSize
53
+ });
54
+ let cellStart = rowStart + 1;
55
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) {
56
+ const cell = row.child(cellIndex);
57
+ const cellMetadata = elementAt(metadata.cells, cellIndex);
58
+ finalCellStarts.push(cellStart);
59
+ if (cellMetadata.mapSourcePosition >= 0) anchors.push({
60
+ source: cellMetadata.mapSourcePosition + 1,
61
+ final: cellStart,
62
+ size: cell.nodeSize
63
+ });
64
+ if (!tableTouched && !metadata.touched && cellMetadata.touched) changedParagraphRanges.push({
65
+ from: cellStart,
66
+ to: cellStart + cell.nodeSize
67
+ });
68
+ if (cellMetadata.sourcePosition >= 0) {
69
+ const sourceCellPosition = cellMetadata.sourcePosition;
70
+ const finalCellPosition = cellStart;
71
+ cell.descendants((node, offset) => {
72
+ if (node.type.name === "table") return false;
73
+ if (node.type.name !== "paragraph") return true;
74
+ paragraphOffsets.push({
75
+ source: sourceCellPosition + 2 + offset,
76
+ final: finalCellPosition + 1 + offset
77
+ });
78
+ return false;
79
+ });
80
+ }
81
+ cellStart += cell.nodeSize;
82
+ }
83
+ rowStart += row.nodeSize;
84
+ }
85
+ const sourceCellStarts = [];
86
+ let sourceRowStart = 1;
87
+ for (let rowIndex = 0; rowIndex < sourceTable.childCount; rowIndex++) {
88
+ const row = sourceTable.child(rowIndex);
89
+ let cellStart = sourceRowStart + 1;
90
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) {
91
+ sourceCellStarts.push(cellStart);
92
+ cellStart += row.child(cellIndex).nodeSize;
93
+ }
94
+ sourceRowStart += row.nodeSize;
95
+ }
96
+ const ranges = [];
97
+ let sourceCursor = 0;
98
+ let finalCursor = 0;
99
+ let sourceCellIndex = 0;
100
+ let finalCellIndex = 0;
101
+ for (const anchor of [...anchors, {
102
+ source: sourceTable.nodeSize,
103
+ final: table.nodeSize,
104
+ size: 0
105
+ }]) {
106
+ if (anchor.source < sourceCursor || anchor.final < finalCursor) continue;
107
+ while (sourceCellStarts.at(sourceCellIndex) !== void 0 && elementAt(sourceCellStarts, sourceCellIndex) < sourceCursor) sourceCellIndex++;
108
+ while (finalCellStarts.at(finalCellIndex) !== void 0 && elementAt(finalCellStarts, finalCellIndex) < finalCursor) finalCellIndex++;
109
+ const sourceGap = anchor.source - sourceCursor;
110
+ const finalGap = anchor.final - finalCursor;
111
+ const hasUnmatchedCell = (sourceCellStarts.at(sourceCellIndex) ?? Infinity) < anchor.source || (finalCellStarts.at(finalCellIndex) ?? Infinity) < anchor.final;
112
+ if (sourceGap !== finalGap || hasUnmatchedCell) ranges.push(sourceCursor, sourceGap, finalGap);
113
+ sourceCursor = anchor.source + anchor.size;
114
+ finalCursor = anchor.final + anchor.size;
115
+ }
116
+ return {
117
+ changedParagraphRanges,
118
+ paragraphOffsets,
119
+ positionMap: new StepMap(ranges)
120
+ };
121
+ };
122
+ const hasNodePropertyRevision = (node) => nodePropertyRevisionSites(node.type.name).some((site) => site.resolution === "node-attrs" && propertyRevisionRecords(node, site).length > 0);
123
+ const rowRevisionKind = (row) => {
124
+ for (const kind of ["trIns", "trDel"]) {
125
+ const marker = row.attrs[kind];
126
+ if (typeof marker === "object" && marker !== null && "revisionId" in marker && typeof marker.revisionId === "number") return kind;
127
+ }
128
+ return null;
129
+ };
130
+ const cellRevisionMarker = (cell) => {
131
+ const marker = cell.attrs["cellMarker"];
132
+ if (typeof marker !== "object" || marker === null || !("kind" in marker) || marker.kind !== "ins" && marker.kind !== "del" && marker.kind !== "merge" || !("info" in marker) || typeof marker.info !== "object" || marker.info === null || !("revisionId" in marker.info) || typeof marker.info.revisionId !== "number") return null;
133
+ const verticalMergeOriginal = "verticalMergeOriginal" in marker && isTableCellMergeRevisionValue(marker.verticalMergeOriginal) ? marker.verticalMergeOriginal : void 0;
134
+ return {
135
+ kind: marker.kind,
136
+ info: { revisionId: marker.info.revisionId },
137
+ ...verticalMergeOriginal ? { verticalMergeOriginal } : {}
138
+ };
139
+ };
140
+ /**
141
+ * Resolve a table in one grid pass for row revisions and ordinary cell
142
+ * membership revisions. The grid records each original cell rectangle once;
143
+ * retaining rows reduces its rowspan, while a cell whose starting row is
144
+ * removed moves to the next retained row inside that rectangle. This is the
145
+ * same topology operation as prosemirror-tables' removeRow.
146
+ */
147
+ const resolveAllTableChanges = ({ table, resolvedRows, mode }) => {
148
+ const sourceRows = resolvedRows ?? Array.from({ length: table.childCount }, (_, i) => table.child(i));
149
+ const tableWithResolvedChildren = table.type.create(table.attrs, sourceRows, table.marks);
150
+ const tablePropertyTouched = hasNodePropertyRevision(tableWithResolvedChildren);
151
+ const rowPropertyTouched = sourceRows.map(hasNodePropertyRevision);
152
+ const propertyResolvedTable = resolveTablePropertyAttrs(tableWithResolvedChildren, mode);
153
+ const rows = Array.from({ length: propertyResolvedTable.childCount }, (_, i) => propertyResolvedTable.child(i));
154
+ const rowKinds = rows.map(rowRevisionKind);
155
+ const keepRows = rowKinds.map((kind) => kind === null || kind === "trIns" === (mode === "accept"));
156
+ const hasRowRevision = rowKinds.some((kind) => kind !== null);
157
+ const hasMerge = rows.some((row) => {
158
+ for (let i = 0; i < row.childCount; i++) {
159
+ const cell = row.child(i);
160
+ if (cellRevisionMarker(cell)?.kind === "merge" || hasMatchingCollapsedTableCellMerge(cell, null)) return true;
161
+ }
162
+ return false;
163
+ });
164
+ const map = TableMap.get(propertyResolvedTable);
165
+ const cellRectangle = indexedTableCells(map);
166
+ const cells = [];
167
+ let rowOffset = 0;
168
+ let hasCellRevision = false;
169
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
170
+ const row = elementAt(rows, rowIndex);
171
+ let cellOffset = rowOffset + 1;
172
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) {
173
+ const cell = row.child(cellIndex);
174
+ const rectangle = cellRectangle(cellOffset);
175
+ const marker = cellRevisionMarker(cell);
176
+ if ((marker?.kind === "ins" || marker?.kind === "del" ? marker : null) !== null) hasCellRevision = true;
177
+ cells.push({
178
+ node: cell,
179
+ left: rectangle.left,
180
+ originRow: rowIndex,
181
+ bottom: rectangle.bottom,
182
+ sourcePosition: cellOffset,
183
+ mapSourcePosition: cellOffset,
184
+ touched: hasNodePropertyRevision(elementAt(sourceRows, rowIndex).child(cellIndex))
185
+ });
186
+ cellOffset += cell.nodeSize;
187
+ }
188
+ rowOffset += row.nodeSize;
189
+ }
190
+ if (!keepRows.some(Boolean)) return {
191
+ node: null,
192
+ changed: true,
193
+ structural: hasRowRevision || hasCellRevision,
194
+ failed: false,
195
+ changedParagraphRanges: [],
196
+ paragraphOffsets: [],
197
+ positionMap: new StepMap([
198
+ 0,
199
+ tableWithResolvedChildren.nodeSize,
200
+ 0
201
+ ])
202
+ };
203
+ const keptBefore = [0];
204
+ for (const keep of keepRows) keptBefore.push((keptBefore.at(-1) ?? 0) + Number(keep));
205
+ const nextKeptRow = rows.map(() => rows.length);
206
+ let next = rows.length;
207
+ for (let index = rows.length - 1; index >= 0; index--) {
208
+ if (elementAt(keepRows, index)) next = index;
209
+ nextKeptRow[index] = next;
210
+ }
211
+ const placements = rows.map(() => []);
212
+ for (const cell of cells) {
213
+ const destination = elementAt(nextKeptRow, cell.originRow);
214
+ if (destination >= cell.bottom) continue;
215
+ const rowspan = elementAt(keptBefore, cell.bottom) - elementAt(keptBefore, destination);
216
+ elementAt(placements, destination)[cell.left] = {
217
+ ...cell,
218
+ mapSourcePosition: destination === cell.originRow ? cell.mapSourcePosition : -1,
219
+ touched: cell.touched || rowspan !== cell.node.attrs["rowspan"],
220
+ node: rowspan === cell.node.attrs["rowspan"] ? cell.node : cell.node.type.create({
221
+ ...cell.node.attrs,
222
+ rowspan
223
+ }, cell.node.content, cell.node.marks)
224
+ };
225
+ }
226
+ const nextRows = [];
227
+ const rowMetadata = [];
228
+ for (let index = 0; index < rows.length; index++) {
229
+ if (!elementAt(keepRows, index)) continue;
230
+ const row = elementAt(rows, index);
231
+ const rowCells = elementAt(placements, index).flatMap((placement) => placement === void 0 ? [] : [placement.node]);
232
+ const kind = elementAt(rowKinds, index);
233
+ const attrs = kind ? {
234
+ ...row.attrs,
235
+ [kind]: null
236
+ } : row.attrs;
237
+ nextRows.push(row.type.create(attrs, rowCells, row.marks));
238
+ rowMetadata.push({
239
+ touched: elementAt(rowPropertyTouched, index) || kind !== null,
240
+ cells: elementAt(placements, index).flatMap((placement) => placement === void 0 ? [] : [placement])
241
+ });
242
+ }
243
+ const nextTable = propertyResolvedTable.type.create(propertyResolvedTable.attrs, nextRows, propertyResolvedTable.marks);
244
+ if (hasMerge || hasCellRevision) return resolvePureTableMerges({
245
+ table: nextTable,
246
+ mode,
247
+ rowMetadata,
248
+ tablePropertyTouched,
249
+ sourceTable: tableWithResolvedChildren
250
+ });
251
+ const structural = hasRowRevision || hasCellRevision || hasTablePropertyRevision(tableWithResolvedChildren);
252
+ return {
253
+ node: nextTable,
254
+ changed: structural || !nextTable.eq(table),
255
+ structural,
256
+ failed: false,
257
+ ...tableResolutionMetadata({
258
+ table: nextTable,
259
+ rows: rowMetadata,
260
+ tableTouched: tablePropertyTouched,
261
+ sourceTable: tableWithResolvedChildren
262
+ })
263
+ };
264
+ };
265
+ const resolveTablePropertyAttrs = (table, mode) => {
266
+ const rows = [];
267
+ for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
268
+ const row = table.child(rowIndex);
269
+ const cells = [];
270
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) cells.push(resolveAllNodePropertyChangeAttrs(row.child(cellIndex), mode));
271
+ rows.push(resolveAllNodePropertyChangeAttrs(row.type.create(row.attrs, cells, row.marks), mode));
272
+ }
273
+ return resolveAllNodePropertyChangeAttrs(table.type.create(table.attrs, rows, table.marks), mode);
274
+ };
275
+ const hasTablePropertyRevision = (table) => {
276
+ if (table.attrs["tblPrChange"] != null) return true;
277
+ for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
278
+ const row = table.child(rowIndex);
279
+ if (row.attrs["trPrChange"] != null || row.attrs["tblPrExChange"] != null) return true;
280
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) if (row.child(cellIndex).attrs["tcPrChange"] != null) return true;
281
+ }
282
+ return false;
283
+ };
284
+ const appendContinuation = (sequence, cell) => {
285
+ const link = {
286
+ cell,
287
+ next: null
288
+ };
289
+ if (sequence.tail) sequence.tail.next = link;
290
+ else sequence.head = link;
291
+ sequence.tail = link;
292
+ };
293
+ const continuationSequence = (cells) => {
294
+ const sequence = {
295
+ head: null,
296
+ tail: null
297
+ };
298
+ for (const cell of cells) appendContinuation(sequence, cell);
299
+ return sequence;
300
+ };
301
+ const appendContinuationSequence = (destination, source) => {
302
+ if (!source.head) return;
303
+ if (destination.tail) destination.tail.next = source.head;
304
+ else destination.head = source.head;
305
+ destination.tail = source.tail;
306
+ };
307
+ const materializeContinuation = (entry) => {
308
+ if (!entry.continuation) return;
309
+ const cells = [];
310
+ for (let link = entry.continuation.head; link !== null; link = link.next) cells.push(link.cell);
311
+ entry.node = entry.node.type.create({
312
+ ...entry.node.attrs,
313
+ _docxVMergeContinuationCells: transportTableCellsWithParagraphPropertySources(cells)
314
+ }, entry.node.content, entry.node.marks);
315
+ entry.continuation = null;
316
+ };
317
+ const failedTableResolution = (table) => ({
318
+ node: table,
319
+ changed: false,
320
+ structural: false,
321
+ failed: true,
322
+ changedParagraphRanges: [],
323
+ paragraphOffsets: [],
324
+ positionMap: StepMap.empty
325
+ });
326
+ /** Replay width deletions by live column rank without shifting the remaining array. */
327
+ const compactColumnWidths = (widths, removals) => {
328
+ if (removals.length === 0) return [...widths];
329
+ const length = widths.length;
330
+ const tree = new Int32Array(length + 1);
331
+ const removed = new Uint8Array(length);
332
+ for (let index = 1; index <= length; index++) tree[index] = index & -index;
333
+ let highestBit = 1;
334
+ while (highestBit * 2 <= length) highestBit *= 2;
335
+ let remaining = length;
336
+ for (const { left, count } of removals) {
337
+ const start = Math.min(left, remaining);
338
+ const removedCount = Math.min(count, remaining - start);
339
+ for (let deleted = 0; deleted < removedCount; deleted++) {
340
+ let rank = start + 1;
341
+ let originalIndex = 0;
342
+ for (let bit = highestBit; bit > 0; bit >>= 1) {
343
+ const next = originalIndex + bit;
344
+ if (next <= length && (tree[next] ?? 0) < rank) {
345
+ originalIndex = next;
346
+ rank -= tree[next] ?? 0;
347
+ }
348
+ }
349
+ removed[originalIndex] = 1;
350
+ for (let index = originalIndex + 1; index <= length; index += index & -index) tree[index] = (tree[index] ?? 0) - 1;
351
+ remaining--;
352
+ }
353
+ }
354
+ return widths.filter((_width, index) => removed[index] === 0);
355
+ };
356
+ /** Resolve all cell edits in reverse order against one grid and mutable slots. */
357
+ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched, sourceTable }) => {
358
+ const map = TableMap.get(table);
359
+ const cellRectangle = indexedTableCells(map);
360
+ const rows = Array.from({ length: table.childCount }, (_, index) => table.child(index));
361
+ const rowCells = rows.map(() => /* @__PURE__ */ new Map());
362
+ const rowOccupancy = rows.map(() => 0);
363
+ const activeRows = rows.map(() => true);
364
+ const widthCounts = /* @__PURE__ */ new Map();
365
+ const authoredWidths = expectTableAttrs(table).columnWidths;
366
+ const columnWidths = authoredWidths?.length === map.width ? [...authoredWidths] : void 0;
367
+ const widthRemovals = [];
368
+ let currentWidth = map.width;
369
+ let removedCell = false;
370
+ const deletedRows = /* @__PURE__ */ new Set();
371
+ const byPosition = /* @__PURE__ */ new Map();
372
+ const ordered = [];
373
+ let rowOffset = 0;
374
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
375
+ const row = elementAt(rows, rowIndex);
376
+ let cellOffset = rowOffset + 1;
377
+ for (let cellIndex = 0; cellIndex < row.childCount; cellIndex++) {
378
+ const node = row.child(cellIndex);
379
+ const rectangle = cellRectangle(cellOffset);
380
+ const left = rectangle.left;
381
+ for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
382
+ const initial = elementAt(elementAt(rowMetadata, rowIndex).cells, cellIndex);
383
+ const entry = {
384
+ node,
385
+ position: cellOffset,
386
+ left,
387
+ row: rowIndex,
388
+ sourcePosition: initial.sourcePosition,
389
+ mapSourcePosition: initial.mapSourcePosition,
390
+ touched: initial.touched,
391
+ continuation: null
392
+ };
393
+ elementAt(rowCells, rowIndex).set(left, entry);
394
+ byPosition.set(cellOffset, entry);
395
+ ordered.push(entry);
396
+ cellOffset += node.nodeSize;
397
+ }
398
+ rowOffset += row.nodeSize;
399
+ }
400
+ for (const width of rowOccupancy) widthCounts.set(width, (widthCounts.get(width) ?? 0) + 1);
401
+ const changeRowWidth = (rowIndex, nextWidth) => {
402
+ if (!elementAt(activeRows, rowIndex)) return;
403
+ const previous = elementAt(rowOccupancy, rowIndex);
404
+ widthCounts.set(previous, (widthCounts.get(previous) ?? 0) - 1);
405
+ rowOccupancy[rowIndex] = nextWidth;
406
+ widthCounts.set(nextWidth, (widthCounts.get(nextWidth) ?? 0) + 1);
407
+ };
408
+ for (let index = ordered.length - 1; index >= 0; index--) {
409
+ const entry = elementAt(ordered, index);
410
+ const marker = cellRevisionMarker(entry.node);
411
+ if (marker && marker.kind !== "merge") {
412
+ const view = mode === "accept" ? "final" : "original";
413
+ if (isTableCellRetainedInReviewView(marker.kind, view)) {
414
+ entry.touched = true;
415
+ entry.node = entry.node.type.create({
416
+ ...entry.node.attrs,
417
+ cellMarker: null
418
+ }, entry.node.content, entry.node.marks);
419
+ } else {
420
+ removedCell = true;
421
+ const previousWidth = currentWidth;
422
+ const rectangle = cellRectangle(entry.position);
423
+ const colspan = rectangle.right - rectangle.left;
424
+ for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) changeRowWidth(coveredRow, elementAt(rowOccupancy, coveredRow) - colspan);
425
+ elementAt(rowCells, entry.row).delete(entry.left);
426
+ if (elementAt(rowCells, entry.row).size === 0) {
427
+ deletedRows.add(entry.row);
428
+ activeRows[entry.row] = false;
429
+ const rowWidth = elementAt(rowOccupancy, entry.row);
430
+ widthCounts.set(rowWidth, (widthCounts.get(rowWidth) ?? 0) - 1);
431
+ }
432
+ while (currentWidth > 0 && (widthCounts.get(currentWidth) ?? 0) === 0) currentWidth--;
433
+ if (columnWidths && currentWidth < previousWidth) widthRemovals.push({
434
+ left: entry.left,
435
+ count: previousWidth - currentWidth
436
+ });
437
+ }
438
+ } else if (marker?.kind === "merge") if (mode === "accept") {
439
+ entry.touched = true;
440
+ entry.node = entry.node.type.create({
441
+ ...entry.node.attrs,
442
+ cellMarker: null
443
+ }, entry.node.content, entry.node.marks);
444
+ } else if (!isTableCellMergeRevisionContinuation(marker.verticalMergeOriginal)) {
445
+ entry.touched = true;
446
+ const original = entry.node.attrs["_originalFormatting"];
447
+ let formatting = original;
448
+ if (typeof original === "object" && original !== null) {
449
+ const copy = { ...original };
450
+ delete copy["vMerge"];
451
+ formatting = copy;
452
+ }
453
+ entry.node = entry.node.type.create({
454
+ ...entry.node.attrs,
455
+ cellMarker: null,
456
+ _originalFormatting: formatting
457
+ }, entry.node.content, entry.node.marks);
458
+ } else {
459
+ const rectangle = cellRectangle(entry.position);
460
+ if (rectangle.top === 0) return failedTableResolution(table);
461
+ const abovePosition = map.map[(rectangle.top - 1) * map.width + rectangle.left];
462
+ if (abovePosition === void 0) return failedTableResolution(table);
463
+ const aboveRectangle = cellRectangle(abovePosition);
464
+ const above = byPosition.get(abovePosition);
465
+ if (!above || !elementAt(rowCells, above.row).has(above.left) || aboveRectangle.left !== rectangle.left || aboveRectangle.right !== rectangle.right || aboveRectangle.bottom !== rectangle.top) return failedTableResolution(table);
466
+ const aboveRowspan = above.node.attrs["rowspan"];
467
+ const cellRowspan = entry.node.attrs["rowspan"];
468
+ if (typeof aboveRowspan !== "number" || typeof cellRowspan !== "number" || aboveRowspan < 1 || cellRowspan < 1) return failedTableResolution(table);
469
+ above.continuation ??= continuationSequence(tableCellContinuationCells(above.node, aboveRowspan));
470
+ appendContinuation(above.continuation, tableCellContinuationFromNode(entry.node));
471
+ const nested = entry.continuation ?? continuationSequence(tableCellContinuationPayload(entry.node)?.cells ?? []);
472
+ appendContinuationSequence(above.continuation, nested);
473
+ above.node = above.node.type.create({
474
+ ...above.node.attrs,
475
+ rowspan: aboveRowspan + cellRowspan
476
+ }, above.node.content, above.node.marks);
477
+ elementAt(rowCells, entry.row).delete(entry.left);
478
+ }
479
+ if (!elementAt(rowCells, entry.row).has(entry.left)) continue;
480
+ if (!tableCellContinuationPayload(entry.node)?.cells.some((cell) => getTableCellMergeChange(cell) !== null)) continue;
481
+ materializeContinuation(entry);
482
+ const payload = tableCellContinuationPayload(entry.node);
483
+ if (!payload) return failedTableResolution(table);
484
+ const stored = payload.cells;
485
+ const splitIndices = [];
486
+ let matched = false;
487
+ const nextCells = stored.map((source, sourceIndex) => {
488
+ const change = getTableCellMergeChange(source);
489
+ if (!change) return source;
490
+ matched = true;
491
+ if (mode === "reject" && isTableCellMergeRevisionContinuation(change.verticalMerge) && !isTableCellMergeRevisionContinuation(change.verticalMergeOriginal)) splitIndices.push(sourceIndex);
492
+ const cleaned = { ...source };
493
+ delete cleaned.structuralChange;
494
+ return cleaned;
495
+ });
496
+ if (!matched) continue;
497
+ if (mode === "accept" || splitIndices.length === 0) {
498
+ entry.touched = true;
499
+ entry.node = entry.node.type.create({
500
+ ...entry.node.attrs,
501
+ _docxVMergeContinuationCells: nextCells
502
+ }, entry.node.content, entry.node.marks);
503
+ continue;
504
+ }
505
+ const firstSplitIndex = splitIndices.at(0);
506
+ if (firstSplitIndex === void 0 || splitIndices.length !== stored.length - firstSplitIndex || splitIndices.some((splitIndex, offset) => splitIndex !== firstSplitIndex + offset)) return failedTableResolution(table);
507
+ const rectangle = cellRectangle(entry.position);
508
+ const rowspan = entry.node.attrs["rowspan"];
509
+ if (typeof rowspan !== "number" || rowspan !== stored.length + 1 || rectangle.bottom - rectangle.top !== rowspan) return failedTableResolution(table);
510
+ const restored = restoreTableCellsWithParagraphPropertySources(payload);
511
+ for (const splitIndex of splitIndices) {
512
+ const source = restored[splitIndex];
513
+ const restoredCell = source && createRestoredTableCell(entry.node, source);
514
+ const rowIndex = rectangle.top + splitIndex + 1;
515
+ if (!restoredCell || elementAt(rowCells, rowIndex).has(rectangle.left)) return failedTableResolution(table);
516
+ elementAt(rowCells, rowIndex).set(rectangle.left, {
517
+ node: restoredCell,
518
+ position: -1,
519
+ left: rectangle.left,
520
+ row: rowIndex,
521
+ sourcePosition: -1,
522
+ mapSourcePosition: -1,
523
+ touched: true,
524
+ continuation: null
525
+ });
526
+ }
527
+ const remaining = nextCells.slice(0, firstSplitIndex);
528
+ entry.node = entry.node.type.create({
529
+ ...entry.node.attrs,
530
+ rowspan: firstSplitIndex + 1,
531
+ _docxVMergeContinuationCells: remaining.length > 0 ? remaining : null
532
+ }, entry.node.content, entry.node.marks);
533
+ }
534
+ if (deletedRows.size === rows.length) return {
535
+ node: null,
536
+ changed: true,
537
+ structural: true,
538
+ failed: false,
539
+ changedParagraphRanges: [],
540
+ paragraphOffsets: [],
541
+ positionMap: new StepMap([
542
+ 0,
543
+ sourceTable.nodeSize,
544
+ 0
545
+ ])
546
+ };
547
+ const keptBefore = [0];
548
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) keptBefore.push((keptBefore.at(-1) ?? 0) + Number(!deletedRows.has(rowIndex)));
549
+ const compacted = rows.map(() => /* @__PURE__ */ new Map());
550
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) for (const entry of elementAt(rowCells, rowIndex).values()) {
551
+ materializeContinuation(entry);
552
+ const originalRowspan = entry.node.attrs["rowspan"];
553
+ if (typeof originalRowspan !== "number") continue;
554
+ const bottom = Math.min(rowIndex + originalRowspan, rows.length);
555
+ let destination = rowIndex;
556
+ while (destination < bottom && deletedRows.has(destination)) destination++;
557
+ if (destination === bottom) continue;
558
+ const rowspan = elementAt(keptBefore, bottom) - elementAt(keptBefore, destination);
559
+ const node = rowspan === originalRowspan ? entry.node : entry.node.type.create({
560
+ ...entry.node.attrs,
561
+ rowspan
562
+ }, entry.node.content, entry.node.marks);
563
+ elementAt(compacted, destination).set(entry.left, {
564
+ ...entry,
565
+ node,
566
+ row: destination,
567
+ touched: entry.touched || rowspan !== originalRowspan
568
+ });
569
+ }
570
+ const nextRowMetadata = [];
571
+ const nextRows = rows.flatMap((row, rowIndex) => {
572
+ if (deletedRows.has(rowIndex)) return [];
573
+ const cells = [];
574
+ const cellMetadata = [];
575
+ for (let column = 0; column < map.width; column++) {
576
+ const entry = elementAt(compacted, rowIndex).get(column);
577
+ if (entry) {
578
+ cells.push(entry.node);
579
+ cellMetadata.push(entry);
580
+ }
581
+ }
582
+ nextRowMetadata.push({
583
+ touched: elementAt(rowMetadata, rowIndex).touched,
584
+ cells: cellMetadata
585
+ });
586
+ return [row.type.create(row.attrs, cells, row.marks)];
587
+ });
588
+ let nextTable = table.type.create(table.attrs, nextRows, table.marks);
589
+ const nextWidth = TableMap.get(nextTable).width;
590
+ const gridChanged = removedCell && nextWidth < map.width;
591
+ if (gridChanged) {
592
+ const survivingColumnWidths = columnWidths === void 0 ? void 0 : compactColumnWidths(columnWidths, widthRemovals);
593
+ const formatting = expectTableAttrs(nextTable)._originalFormatting;
594
+ const originalFormatting = formatting ? { ...formatting } : void 0;
595
+ if (originalFormatting) delete originalFormatting.gridSourceXml;
596
+ nextTable = nextTable.type.create(mergeTableAttrs(nextTable, {
597
+ columnWidths: survivingColumnWidths?.length === nextWidth ? survivingColumnWidths : void 0,
598
+ _originalFormatting: originalFormatting
599
+ }), nextTable.content, nextTable.marks);
600
+ }
601
+ return {
602
+ node: nextTable,
603
+ changed: true,
604
+ structural: true,
605
+ failed: false,
606
+ ...tableResolutionMetadata({
607
+ table: nextTable,
608
+ rows: nextRowMetadata,
609
+ tableTouched: tablePropertyTouched || gridChanged,
610
+ sourceTable
611
+ })
612
+ };
613
+ };
614
+ //#endregion
615
+ export { resolveAllTableChanges };
@@ -0,0 +1,15 @@
1
+ import { NodeAttrsPropertyRevisionSite } from "../revisionCarriers.js";
2
+ import { Node } from "prosemirror-model";
3
+ //#region src/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts
4
+ /** Resolve one property-change site without a transaction. */
5
+ type ResolveNodePropertyChangeAttrsOptions = {
6
+ node: Node;
7
+ site: NodeAttrsPropertyRevisionSite;
8
+ mode: "accept" | "reject";
9
+ revisionSet: ReadonlySet<number> | null;
10
+ };
11
+ declare const resolveNodePropertyChangeAttrs: ({ node, site, mode, revisionSet }: ResolveNodePropertyChangeAttrsOptions) => Record<string, unknown> | null;
12
+ /** Resolve every node-attr site, including both independent sites on a row. */
13
+ declare const resolveAllNodePropertyChangeAttrs: (node: Node, mode: "accept" | "reject") => Node;
14
+ //#endregion
15
+ export { resolveAllNodePropertyChangeAttrs, resolveNodePropertyChangeAttrs };
@@ -0,0 +1,46 @@
1
+ import { nodePropertyRevisionSites, propertyRevisionMetadata, propertyRevisionRecords } from "../revisionCarriers.js";
2
+ import { tableCellRejectAttrPatch, tablePropertyExceptionsRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch } from "./propertyChangeScope.js";
3
+ //#region src/prosemirror/commands/resolveNodePropertyChangeAttrs.ts
4
+ /** The old property set each node-attr revision restores on rejection. */
5
+ const NODE_ATTRS_REJECT_PATCHES = {
6
+ tablePropertyChange: (previousFormatting) => tableRejectAttrPatch(previousFormatting),
7
+ tablePropertyExceptionChange: (previousFormatting) => tablePropertyExceptionsRejectAttrPatch(previousFormatting),
8
+ tableRowPropertyChange: (previousFormatting) => tableRowRejectAttrPatch(previousFormatting),
9
+ tableCellPropertyChange: (previousFormatting, node) => tableCellRejectAttrPatch(previousFormatting, node.attrs["_originalFormatting"])
10
+ };
11
+ const resolveNodePropertyChangeAttrs = ({ node, site, mode, revisionSet }) => {
12
+ const changes = propertyRevisionRecords(node, site);
13
+ if (changes.length === 0) return null;
14
+ const matches = changes.filter((change) => {
15
+ const metadata = propertyRevisionMetadata(change.info);
16
+ return revisionSet === null || metadata !== null && revisionSet.has(metadata.id);
17
+ });
18
+ if (matches.length === 0) return null;
19
+ const remaining = revisionSet === null ? [] : changes.filter((change) => !matches.includes(change));
20
+ const nextAttrs = {
21
+ ...node.attrs,
22
+ [site.attr]: remaining.length > 0 ? remaining : null
23
+ };
24
+ if (mode === "reject") {
25
+ const rejectPatch = NODE_ATTRS_REJECT_PATCHES[site.kind];
26
+ for (const change of matches.toReversed()) Object.assign(nextAttrs, rejectPatch(change.previousFormatting, node));
27
+ }
28
+ return nextAttrs;
29
+ };
30
+ /** Resolve every node-attr site, including both independent sites on a row. */
31
+ const resolveAllNodePropertyChangeAttrs = (node, mode) => {
32
+ let current = node;
33
+ for (const site of nodePropertyRevisionSites(node.type.name)) {
34
+ if (site.resolution !== "node-attrs") continue;
35
+ const attrs = resolveNodePropertyChangeAttrs({
36
+ node: current,
37
+ site,
38
+ mode,
39
+ revisionSet: null
40
+ });
41
+ if (attrs !== null) current = current.type.create(attrs, current.content, current.marks);
42
+ }
43
+ return current;
44
+ };
45
+ //#endregion
46
+ export { resolveAllNodePropertyChangeAttrs, resolveNodePropertyChangeAttrs };