@stll/folio-core 0.10.0 → 0.12.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 (217) hide show
  1. package/dist/ai-edits/apply.js +602 -50
  2. package/dist/ai-edits/block-identity.d.ts +4 -0
  3. package/dist/ai-edits/block-identity.js +9 -0
  4. package/dist/ai-edits/blockRange.d.ts +28 -1
  5. package/dist/ai-edits/blockRange.js +67 -1
  6. package/dist/ai-edits/headless.d.ts +4 -4
  7. package/dist/ai-edits/headless.js +9 -9
  8. package/dist/ai-edits/index.d.ts +2 -2
  9. package/dist/ai-edits/index.js +2 -2
  10. package/dist/ai-edits/read.d.ts +7 -7
  11. package/dist/ai-edits/read.js +110 -3
  12. package/dist/ai-edits/table-cell-mutations.d.ts +48 -0
  13. package/dist/ai-edits/table-cell-mutations.js +237 -0
  14. package/dist/ai-edits/table-mutation-plan.d.ts +38 -0
  15. package/dist/ai-edits/table-mutation-plan.js +90 -0
  16. package/dist/ai-edits/table-row-column-mutations.d.ts +100 -0
  17. package/dist/ai-edits/table-row-column-mutations.js +300 -0
  18. package/dist/ai-edits/table-targets.d.ts +32 -0
  19. package/dist/ai-edits/table-targets.js +70 -0
  20. package/dist/ai-edits/types.d.ts +34 -0
  21. package/dist/compat/eigenpal.js +1 -1
  22. package/dist/content-controls/mutateContentControls.js +1 -1
  23. package/dist/controller/activeEditorStory.d.ts +36 -0
  24. package/dist/controller/activeEditorStory.js +30 -0
  25. package/dist/controller/collaborationModules.d.ts +7 -0
  26. package/dist/controller/collaborationModules.js +15 -0
  27. package/dist/controller/contentControlWidgetController.d.ts +55 -0
  28. package/dist/controller/contentControlWidgetController.js +141 -0
  29. package/dist/controller/folioEditor.d.ts +1 -1
  30. package/dist/controller/fontReadiness.js +2 -0
  31. package/dist/controller/headerFooterEditorManager.d.ts +41 -0
  32. package/dist/controller/headerFooterEditorManager.js +182 -0
  33. package/dist/controller/hiddenEditorApi.js +2 -2
  34. package/dist/controller/hiddenEditorManager.d.ts +13 -2
  35. package/dist/controller/hiddenEditorManager.js +32 -11
  36. package/dist/controller/layoutPipeline.d.ts +2 -0
  37. package/dist/controller/layoutPipeline.js +16 -1
  38. package/dist/controller/noteEditorManager.d.ts +36 -0
  39. package/dist/controller/noteEditorManager.js +210 -0
  40. package/dist/document-operations.d.ts +35 -3
  41. package/dist/document-operations.js +161 -3
  42. package/dist/docx/blockContentParser.js +2 -2
  43. package/dist/docx/commentParser.js +6 -1
  44. package/dist/docx/conformance.js +8 -1
  45. package/dist/docx/documentGrid.d.ts +8 -0
  46. package/dist/docx/documentGrid.js +8 -0
  47. package/dist/docx/drawingUtils.js +1 -1
  48. package/dist/docx/ensureParaIds.js +1 -1
  49. package/dist/docx/fieldParser.js +1 -1
  50. package/dist/docx/notePropertiesParser.js +1 -1
  51. package/dist/docx/numberingParser.js +1 -1
  52. package/dist/docx/paragraphParser.js +63 -58
  53. package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
  54. package/dist/docx/paragraphTextBoxEnrichment.js +67 -13
  55. package/dist/docx/paragraphTraversal.js +1 -1
  56. package/dist/docx/parser.js +3 -3
  57. package/dist/docx/rezip.js +1 -1
  58. package/dist/docx/runParser.js +4 -2
  59. package/dist/docx/sdtProperties.js +1 -1
  60. package/dist/docx/sectionParser.js +1 -1
  61. package/dist/docx/selectiveSave.js +1 -1
  62. package/dist/docx/serializer/commentSerializer.js +1 -2
  63. package/dist/docx/serializer/documentSerializer.js +2 -2
  64. package/dist/docx/serializer/headerFooterSerializer.js +2 -2
  65. package/dist/docx/serializer/noteSerializer.js +2 -2
  66. package/dist/docx/serializer/paragraphSerializer.js +7 -1
  67. package/dist/docx/serializer/runSerializer.js +4 -2
  68. package/dist/docx/serializer/stylesSerializer.js +1 -1
  69. package/dist/docx/serializer/tableSerializer.d.ts +5 -4
  70. package/dist/docx/serializer/tableSerializer.js +17 -13
  71. package/dist/docx/server/applyDocxXmlPatchProposal.d.ts +87 -0
  72. package/dist/docx/server/applyDocxXmlPatchProposal.js +204 -0
  73. package/dist/docx/server/boundedArchive.d.ts +14 -3
  74. package/dist/docx/server/boundedArchive.js +56 -11
  75. package/dist/docx/server/evaluateDocxXmlPatchProposal.d.ts +85 -0
  76. package/dist/docx/server/evaluateDocxXmlPatchProposal.js +361 -0
  77. package/dist/docx/server/inspectDocxPackage.d.ts +70 -0
  78. package/dist/docx/server/inspectDocxPackage.js +217 -0
  79. package/dist/docx/server/validateDocxConformance.d.ts +41 -0
  80. package/dist/docx/server/validateDocxConformance.js +336 -0
  81. package/dist/docx/settingsParser.js +11 -1
  82. package/dist/docx/shapeParser.js +1 -1
  83. package/dist/docx/styleParser.js +4 -2
  84. package/dist/docx/tableParser.js +18 -7
  85. package/dist/docx/textBoxParser.d.ts +3 -3
  86. package/dist/docx/textBoxParser.js +16 -12
  87. package/dist/docx/xmlSafety.d.ts +5 -0
  88. package/dist/docx/xmlSafety.js +9 -0
  89. package/dist/fields/resolveFieldValues.js +1 -3
  90. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  91. package/dist/i18n/messages/catalogs.gen.js +17 -0
  92. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  93. package/dist/index.js +1 -1
  94. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  95. package/dist/layout-bridge/convert/footnoteLayout.js +47 -40
  96. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  97. package/dist/layout-bridge/convert/headerFooterLayout.js +3 -0
  98. package/dist/layout-bridge/convert/templatePreviewFlow.js +3 -3
  99. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +4 -2
  100. package/dist/layout-bridge/convert/toFlowBlocks.js +136 -20
  101. package/dist/layout-bridge/dom/noteStoryDom.d.ts +6 -0
  102. package/dist/layout-bridge/dom/noteStoryDom.js +17 -0
  103. package/dist/layout-bridge/engine/clickToPosition.js +2 -2
  104. package/dist/layout-engine/index.d.ts +2 -2
  105. package/dist/layout-engine/index.js +43 -28
  106. package/dist/layout-engine/justificationCompatibility.d.ts +6 -0
  107. package/dist/layout-engine/justificationCompatibility.js +8 -0
  108. package/dist/layout-engine/keep-together.js +11 -1
  109. package/dist/layout-engine/measure/cache.js +21 -5
  110. package/dist/layout-engine/measure/lineBreakProvider.js +53 -34
  111. package/dist/layout-engine/measure/measureBlocks.js +6 -3
  112. package/dist/layout-engine/measure/measureContainer.js +1 -1
  113. package/dist/layout-engine/measure/measureHelpers.d.ts +1 -1
  114. package/dist/layout-engine/measure/measureHelpers.js +3 -3
  115. package/dist/layout-engine/measure/measureParagraph.js +69 -25
  116. package/dist/layout-engine/measure/measureProvider.js +4 -3
  117. package/dist/layout-engine/measure/tableCellFlow.js +5 -2
  118. package/dist/layout-engine/measure/textBoxParagraphLayout.d.ts +9 -7
  119. package/dist/layout-engine/measure/textBoxParagraphLayout.js +22 -6
  120. package/dist/layout-engine/measure/textMeasurementPolicy.d.ts +3 -1
  121. package/dist/layout-engine/measure/textMeasurementPolicy.js +7 -1
  122. package/dist/layout-engine/paginator.js +5 -1
  123. package/dist/layout-engine/paragraphSpacing.d.ts +28 -4
  124. package/dist/layout-engine/paragraphSpacing.js +107 -13
  125. package/dist/layout-engine/renderedBreakReconciliation.js +1 -1
  126. package/dist/layout-engine/types.d.ts +26 -13
  127. package/dist/layout-painter/registry/modules/textBox.js +5 -1
  128. package/dist/layout-painter/renderPage.d.ts +5 -2
  129. package/dist/layout-painter/renderPage.js +56 -12
  130. package/dist/layout-painter/renderParagraph.js +22 -6
  131. package/dist/layout-painter/renderTable.d.ts +5 -1
  132. package/dist/layout-painter/renderTable.js +5 -2
  133. package/dist/layout-painter/renderTextBox.d.ts +2 -1
  134. package/dist/layout-painter/renderTextBox.js +25 -14
  135. package/dist/managers/DocumentLoaderManager.js +1 -1
  136. package/dist/managers/FindReplaceManager.d.ts +8 -0
  137. package/dist/managers/FindReplaceManager.js +18 -0
  138. package/dist/managers/TableSelectionManager.d.ts +6 -0
  139. package/dist/managers/TableSelectionManager.js +14 -0
  140. package/dist/model.js +1 -1
  141. package/dist/prosemirror/attrs/index.d.ts +4 -2
  142. package/dist/prosemirror/attrs/index.js +154 -18
  143. package/dist/prosemirror/commands/comments.d.ts +3 -3
  144. package/dist/prosemirror/commands/comments.js +248 -12
  145. package/dist/prosemirror/commands/contentControls.js +1 -1
  146. package/dist/prosemirror/commands/index.js +1 -1
  147. package/dist/prosemirror/commands/pageBreak.js +1 -1
  148. package/dist/prosemirror/commands/propertyChangeScope.d.ts +2 -2
  149. package/dist/prosemirror/commands/propertyChangeScope.js +3 -2
  150. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +9 -0
  151. package/dist/prosemirror/commands/tableCellMergeResolution.js +181 -0
  152. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -1
  153. package/dist/prosemirror/conversion/fromProseDoc.js +286 -61
  154. package/dist/prosemirror/conversion/sdtAttrs.d.ts +9 -0
  155. package/dist/prosemirror/conversion/sdtAttrs.js +49 -0
  156. package/dist/prosemirror/conversion/toProseDoc.d.ts +2 -1
  157. package/dist/prosemirror/conversion/toProseDoc.js +347 -98
  158. package/dist/prosemirror/extensions/ExtensionManager.js +1 -1
  159. package/dist/prosemirror/extensions/StarterKit.js +6 -1
  160. package/dist/prosemirror/extensions/core/ParagraphExtension.js +4 -1
  161. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -0
  162. package/dist/prosemirror/extensions/features/ListExtension.js +1 -1
  163. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +10 -1
  164. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +93 -2
  165. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +2 -1
  166. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +6 -2
  167. package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +1 -1
  168. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +9 -1
  169. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +24 -1
  170. package/dist/prosemirror/extensions/nodes/FieldExtension.js +1 -1
  171. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.d.ts +7 -0
  172. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +22 -0
  173. package/dist/prosemirror/extensions/nodes/TableExtension.js +9 -3
  174. package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.d.ts +13 -0
  175. package/dist/prosemirror/extensions/nodes/TextBoxAnchorExtension.js +41 -0
  176. package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +5 -2
  177. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +4 -1
  178. package/dist/prosemirror/findReplaceSelection.d.ts +6 -1
  179. package/dist/prosemirror/findReplaceSelection.js +57 -13
  180. package/dist/prosemirror/plugins/contentControlWidgets.d.ts +34 -8
  181. package/dist/prosemirror/plugins/contentControlWidgets.js +125 -91
  182. package/dist/prosemirror/plugins/selectionTracker.js +1 -0
  183. package/dist/prosemirror/plugins/suggestionMode.js +1 -1
  184. package/dist/prosemirror/schema/index.d.ts +2 -2
  185. package/dist/prosemirror/schema/marks.d.ts +5 -1
  186. package/dist/prosemirror/schema/nodes.d.ts +64 -7
  187. package/dist/prosemirror/selectionState.js +1 -0
  188. package/dist/prosemirror/styles/resolvedStyleAttrs.js +1 -0
  189. package/dist/prosemirror/tableCellMergeRevision.d.ts +9 -0
  190. package/dist/prosemirror/tableCellMergeRevision.js +22 -0
  191. package/dist/prosemirror/textBoxAnchorAttrs.d.ts +9 -0
  192. package/dist/prosemirror/textBoxAnchorAttrs.js +33 -0
  193. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +1 -1
  194. package/dist/prosemirror/utils/extractTrackedChanges.js +62 -14
  195. package/dist/prosemirror/validation.js +9 -1
  196. package/dist/render-dom/BodySelectionOverlay.d.ts +31 -0
  197. package/dist/render-dom/BodySelectionOverlay.js +76 -0
  198. package/dist/render-dom/HeaderFooterSelectionOverlay.d.ts +28 -0
  199. package/dist/render-dom/HeaderFooterSelectionOverlay.js +121 -0
  200. package/dist/render-dom/RemoteSelectionOverlay.d.ts +30 -0
  201. package/dist/render-dom/RemoteSelectionOverlay.js +67 -0
  202. package/dist/render-dom/RenderedDomContext.d.ts +40 -0
  203. package/dist/render-dom/RenderedDomContext.js +126 -0
  204. package/dist/render-dom/resolveSidebarItemPositions.d.ts +33 -0
  205. package/dist/render-dom/resolveSidebarItemPositions.js +45 -0
  206. package/dist/server.d.ts +6 -2
  207. package/dist/server.js +5 -1
  208. package/dist/utils/findReplace.d.ts +32 -0
  209. package/dist/utils/findReplace.js +118 -0
  210. package/dist/utils/fontFamilyMerge.js +9 -11
  211. package/dist/utils/fontLoader.js +3 -2
  212. package/dist/utils/fontResolver.js +22 -4
  213. package/dist/utils/fontWeights.d.ts +1 -1
  214. package/dist/utils/fontWeights.js +1 -1
  215. package/dist/utils/headerFooter.js +24 -1
  216. package/dist/utils/paragraphFormattingMerge.js +1 -0
  217. package/package.json +1 -1
@@ -1,12 +1,14 @@
1
1
  import { OUTLINE_STYLE_CSS_ALIASES } from "../../types/documentEnumValues.js";
2
+ import { directionToBidi } from "../paragraphDirection.js";
3
+ import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunPropertyChangeMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
2
4
  import { ShapeOutlineStyleSchema, narrowEnum } from "../../docx/parserEnums.js";
3
- import { pixelsToEmu } from "../../utils/units.js";
4
5
  import { numPrEqual } from "../../docx/numberingParser.js";
6
+ import { pixelsToEmu } from "../../utils/units.js";
5
7
  import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
6
- import { directionToBidi } from "../paragraphDirection.js";
7
- import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
8
+ import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
8
9
  import { assertValidProseMirrorDocument } from "../validation.js";
9
10
  import { runShadingAttrsToShading } from "./runShadingMark.js";
11
+ import { sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
10
12
  //#region src/prosemirror/conversion/fromProseDoc.ts
11
13
  function normalizeShapeOutlineStyle(style) {
12
14
  if (!style) return;
@@ -75,6 +77,7 @@ function fromProseDoc(pmDoc, baseDocument) {
75
77
  */
76
78
  function extractBlocks(pmDoc) {
77
79
  const blocks = [];
80
+ const textBoxAnchorMarkers = /* @__PURE__ */ new Map();
78
81
  const documentCounts = buildDocumentTrackedChangeCounts(pmDoc);
79
82
  let pendingPageBreaks = 0;
80
83
  let previousStandaloneTextBox = null;
@@ -96,7 +99,7 @@ function extractBlocks(pmDoc) {
96
99
  return;
97
100
  }
98
101
  if (node.type.name === "paragraph") {
99
- const paragraph = convertPMParagraph(node, documentCounts);
102
+ const paragraph = convertPMParagraph(node, documentCounts, textBoxAnchorMarkers);
100
103
  prependPageBreaks(paragraph, pendingPageBreaks);
101
104
  pendingPageBreaks = 0;
102
105
  blocks.push(paragraph);
@@ -108,7 +111,8 @@ function extractBlocks(pmDoc) {
108
111
  } else if (node.type.name === "textBox") {
109
112
  previousStandaloneTextBox = appendTextBoxBlock(blocks, node, {
110
113
  pendingPageBreaks,
111
- previousStandaloneTextBox
114
+ previousStandaloneTextBox,
115
+ textBoxAnchorMarkers
112
116
  });
113
117
  pendingPageBreaks = 0;
114
118
  } else if (node.type.name === "blockSdt") {
@@ -118,6 +122,7 @@ function extractBlocks(pmDoc) {
118
122
  }
119
123
  });
120
124
  if (pendingPageBreaks > 0 && !appendPendingPageBreaksToPreviousParagraph()) flushPendingPageBreaks();
125
+ removeUnresolvedTextBoxAnchors(blocks, textBoxAnchorMarkers);
121
126
  return blocks;
122
127
  }
123
128
  function convertPMBlockSdt(node) {
@@ -176,11 +181,18 @@ function appendTextBoxBlock(blocks, node, options) {
176
181
  const previousBlock = blocks.at(-1);
177
182
  if (attrs._docxPlacement === "inlineWithPrevious" && previousBlock?.type === "paragraph") {
178
183
  appendPageBreaks(previousBlock, options.pendingPageBreaks);
179
- previousBlock.content.push(...paragraph.content);
184
+ const anchorId = attrs._docxAnchorId;
185
+ const anchorMarker = anchorId ? options.textBoxAnchorMarkers.get(anchorId) : void 0;
186
+ const textBoxRun = findTextBoxShapeRun(paragraph.content);
187
+ if (anchorId && anchorMarker && textBoxRun && replaceTextBoxAnchorInBlocks(blocks, anchorMarker, textBoxRun)) {
188
+ options.textBoxAnchorMarkers.delete(anchorId);
189
+ return null;
190
+ }
191
+ if (!mergeTextBoxIntoTrailingInlineSdts(previousBlock, paragraph, attrs._docxInlineSdts ?? [])) previousBlock.content.push(...paragraph.content);
180
192
  return null;
181
193
  }
182
194
  if (attrs._docxPlacement === "standalone" && attrs._docxGroupId && options.previousStandaloneTextBox?.groupId === attrs._docxGroupId) {
183
- options.previousStandaloneTextBox.paragraph.content.push(...paragraph.content);
195
+ if (!mergeTextBoxIntoTrailingInlineSdts(options.previousStandaloneTextBox.paragraph, paragraph, attrs._docxInlineSdts ?? [])) options.previousStandaloneTextBox.paragraph.content.push(...paragraph.content);
184
196
  return options.previousStandaloneTextBox;
185
197
  }
186
198
  prependPageBreaks(paragraph, options.pendingPageBreaks);
@@ -190,6 +202,108 @@ function appendTextBoxBlock(blocks, node, options) {
190
202
  groupId: attrs._docxGroupId
191
203
  } : null;
192
204
  }
205
+ function mergeTextBoxIntoTrailingInlineSdts(target, incoming, inlineSdts) {
206
+ if (inlineSdts.length === 0 || incoming.content.length !== 1) return false;
207
+ const incomingSdt = incoming.content.at(0);
208
+ const outerAttrs = inlineSdts.at(0);
209
+ if (!outerAttrs || incomingSdt?.type !== "inlineSdt") return false;
210
+ let targetSdt;
211
+ for (let index = target.content.length - 1; index >= 0; index -= 1) {
212
+ const content = target.content[index];
213
+ if (content?.type === "inlineSdt" && sdtPropertiesMatchAttrs(content.properties, outerAttrs)) {
214
+ targetSdt = content;
215
+ break;
216
+ }
217
+ }
218
+ if (!targetSdt) return false;
219
+ return mergeInlineSdtNodes(targetSdt, incomingSdt, inlineSdts, 0);
220
+ }
221
+ function mergeInlineSdtNodes(target, incoming, inlineSdts, index) {
222
+ const attrs = inlineSdts[index];
223
+ if (!attrs || !sdtPropertiesMatchAttrs(target.properties, attrs) || !sdtPropertiesMatchAttrs(incoming.properties, attrs)) return false;
224
+ if (index === inlineSdts.length - 1) {
225
+ target.content.push(...incoming.content);
226
+ return true;
227
+ }
228
+ const incomingNested = incoming.content.at(0);
229
+ const nestedAttrs = inlineSdts[index + 1];
230
+ if (!nestedAttrs || incomingNested?.type !== "inlineSdt") return false;
231
+ let targetNested;
232
+ for (let nestedIndex = target.content.length - 1; nestedIndex >= 0; nestedIndex -= 1) {
233
+ const content = target.content[nestedIndex];
234
+ if (content?.type === "inlineSdt" && sdtPropertiesMatchAttrs(content.properties, nestedAttrs)) {
235
+ targetNested = content;
236
+ break;
237
+ }
238
+ }
239
+ if (!targetNested) {
240
+ target.content.push(incomingNested);
241
+ return true;
242
+ }
243
+ return mergeInlineSdtNodes(targetNested, incomingNested, inlineSdts, index + 1);
244
+ }
245
+ function findTextBoxShapeRun(content) {
246
+ for (const item of content) {
247
+ if (item.type === "run") {
248
+ if (item.content.some((runContent) => runContent.type === "shape" && runContent.shape.shapeType === "textBox")) return item;
249
+ continue;
250
+ }
251
+ if (item.type === "inlineSdt" || item.type === "hyperlink" || item.type === "insertion" || item.type === "deletion" || item.type === "moveFrom" || item.type === "moveTo") {
252
+ const run = findTextBoxShapeRun(item.type === "hyperlink" ? item.children : item.content);
253
+ if (run) return run;
254
+ }
255
+ }
256
+ }
257
+ function replaceTextBoxAnchorInBlocks(blocks, marker, textBoxRun) {
258
+ for (const block of blocks) {
259
+ if (block.type === "paragraph") {
260
+ if (editTextBoxAnchorInContent(block.content, marker, textBoxRun)) return true;
261
+ continue;
262
+ }
263
+ if (block.type === "table") {
264
+ for (const row of block.rows) for (const cell of row.cells) if (replaceTextBoxAnchorInBlocks(cell.content, marker, textBoxRun)) return true;
265
+ continue;
266
+ }
267
+ if (replaceTextBoxAnchorInBlocks(block.content, marker, textBoxRun)) return true;
268
+ }
269
+ return false;
270
+ }
271
+ function editTextBoxAnchorInContent(content, marker, replacement) {
272
+ for (let index = 0; index < content.length; index += 1) {
273
+ const item = content[index];
274
+ if (item === marker) {
275
+ content.splice(index, 1, ...replacement ? [replacement] : []);
276
+ return true;
277
+ }
278
+ let nestedContent;
279
+ if (item?.type === "hyperlink") nestedContent = item.children;
280
+ else if (item?.type === "inlineSdt" || item?.type === "insertion" || item?.type === "deletion" || item?.type === "moveFrom" || item?.type === "moveTo") nestedContent = item.content;
281
+ if (!nestedContent) continue;
282
+ const hadContent = nestedContent.length > 0;
283
+ if (editTextBoxAnchorInContent(nestedContent, marker, replacement)) {
284
+ if (!replacement && hadContent && nestedContent.length === 0) content.splice(index, 1);
285
+ return true;
286
+ }
287
+ }
288
+ return false;
289
+ }
290
+ function removeUnresolvedTextBoxAnchors(blocks, markers) {
291
+ for (const marker of markers.values()) removeTextBoxAnchorFromBlocks(blocks, marker);
292
+ }
293
+ function removeTextBoxAnchorFromBlocks(blocks, marker) {
294
+ for (const block of blocks) {
295
+ if (block.type === "paragraph") {
296
+ if (editTextBoxAnchorInContent(block.content, marker)) return true;
297
+ continue;
298
+ }
299
+ if (block.type === "table") {
300
+ for (const row of block.rows) for (const cell of row.cells) if (removeTextBoxAnchorFromBlocks(cell.content, marker)) return true;
301
+ continue;
302
+ }
303
+ if (removeTextBoxAnchorFromBlocks(block.content, marker)) return true;
304
+ }
305
+ return false;
306
+ }
193
307
  /**
194
308
  * Inverse of toProseDoc's listRendering → list* attrs flattening. Markdown
195
309
  * export (`toMarkdown`) and re-layout of the rebuilt Document key off
@@ -254,9 +368,9 @@ function appendPageBreaks(paragraph, count) {
254
368
  /**
255
369
  * Convert a ProseMirror paragraph node to our Paragraph type
256
370
  */
257
- function convertPMParagraph(node, documentCounts) {
371
+ function convertPMParagraph(node, documentCounts, textBoxAnchorMarkers) {
258
372
  const attrs = expectParagraphAttrs(node);
259
- let content = extractParagraphContent(node, documentCounts, attrs._emptyHyperlinks ?? void 0);
373
+ let content = extractParagraphContent(node, documentCounts, attrs._emptyHyperlinks ?? void 0, textBoxAnchorMarkers, attrs.renderedPageBreakBefore === true);
260
374
  const bookmarks = attrs.bookmarks;
261
375
  if (bookmarks && bookmarks.length > 0) {
262
376
  const starts = bookmarks.map((b) => ({
@@ -344,6 +458,7 @@ function paragraphAttrsToFormatting(attrs) {
344
458
  else delete result.styleId;
345
459
  assignBooleanToggle(result, attrs, orig, "pageBreakBefore");
346
460
  assignBooleanToggle(result, attrs, orig, "widowControl");
461
+ assignBooleanToggle(result, attrs, orig, "snapToGrid");
347
462
  assignBooleanToggle(result, attrs, orig, "kinsoku");
348
463
  assignBooleanToggle(result, attrs, orig, "overflowPunctuation");
349
464
  assignBooleanToggle(result, attrs, orig, "suppressAutoHyphens");
@@ -356,7 +471,7 @@ function paragraphAttrsToFormatting(attrs) {
356
471
  }
357
472
  const outlineLevel = Reflect.get(attrs, "outlineLevel");
358
473
  const bidi = directionToBidi(attrs.direction);
359
- if (!(attrs.alignment || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || attrs.lineSpacing || attrs.indentLeft || attrs.indentRight || attrs.indentFirstLine || attrs.numPr || attrs.styleId || attrs.borders || attrs.shading || attrs.tabs || typeof outlineLevel === "number" || attrs.contextualSpacing || attrs.spacingExplicit || bidi != null || attrs.pageBreakBefore != null || attrs.widowControl != null || attrs.kinsoku != null || attrs.overflowPunctuation != null || attrs.suppressAutoHyphens != null)) return;
474
+ if (!(attrs.alignment || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || attrs.lineSpacing || attrs.snapToGrid != null || attrs.indentLeft || attrs.indentRight || attrs.indentFirstLine || attrs.numPr || attrs.styleId || attrs.borders || attrs.shading || attrs.tabs || typeof outlineLevel === "number" || attrs.contextualSpacing || attrs.spacingExplicit || bidi != null || attrs.pageBreakBefore != null || attrs.widowControl != null || attrs.kinsoku != null || attrs.overflowPunctuation != null || attrs.suppressAutoHyphens != null)) return;
360
475
  const f = {};
361
476
  if (attrs.alignment) f.alignment = attrs.alignment;
362
477
  if (shouldSerializeSpaceBefore) f.spaceBefore = spaceBefore;
@@ -365,6 +480,7 @@ function paragraphAttrsToFormatting(attrs) {
365
480
  if (afterAutospacingEdited) f.afterAutospacing = false;
366
481
  if (attrs.lineSpacing) f.lineSpacing = attrs.lineSpacing;
367
482
  if (attrs.lineSpacingRule) f.lineSpacingRule = attrs.lineSpacingRule;
483
+ if (attrs.snapToGrid != null) f.snapToGrid = attrs.snapToGrid;
368
484
  if (attrs.spacingExplicit) f.spacingExplicit = attrs.spacingExplicit;
369
485
  if (attrs.indentLeft) f.indentLeft = attrs.indentLeft;
370
486
  if (attrs.indentRight) f.indentRight = attrs.indentRight;
@@ -391,13 +507,14 @@ function paragraphAttrsToFormatting(attrs) {
391
507
  * Coalesces consecutive text with the same marks into single Runs
392
508
  * for efficient DOCX representation.
393
509
  */
394
- function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
510
+ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks, textBoxAnchorMarkers, skipLeadingRenderedPageBreak = false) {
395
511
  const content = [];
396
512
  const sortedEmptyHyperlinks = (emptyHyperlinks ?? []).map((attrs, order) => ({
397
513
  attrs,
398
514
  order
399
515
  })).toSorted((left, right) => left.attrs.offset - right.attrs.offset || left.order - right.order);
400
516
  let nextEmptyHyperlink = 0;
517
+ let leadingRenderedPageBreakPending = skipLeadingRenderedPageBreak;
401
518
  let currentRun = null;
402
519
  let currentMarksKey = null;
403
520
  let currentHyperlink = null;
@@ -455,11 +572,53 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
455
572
  }
456
573
  };
457
574
  const processInlineNode = (node, offset) => {
575
+ if (node.type.name === "renderedPageBreak" && leadingRenderedPageBreakPending) {
576
+ leadingRenderedPageBreakPending = false;
577
+ return;
578
+ }
579
+ leadingRenderedPageBreakPending = false;
458
580
  syncCommentRanges(node, offset);
459
581
  const linkMark = node.marks.find((m) => m.type.name === "hyperlink");
460
582
  const noteRefMark = node.marks.find((m) => m.type.name === "footnoteRef");
461
583
  const insertionMark = node.marks.find((m) => m.type.name === "insertion");
462
584
  const deletionMark = node.marks.find((m) => m.type.name === "deletion");
585
+ if (node.type.name === "textBoxAnchor") {
586
+ flushCurrentInline();
587
+ if (!textBoxAnchorMarkers) return;
588
+ const { anchorId } = expectTextBoxAnchorAttrs(node);
589
+ const marker = {
590
+ type: "run",
591
+ content: []
592
+ };
593
+ if (textBoxAnchorMarkers.has(anchorId)) return;
594
+ textBoxAnchorMarkers.set(anchorId, marker);
595
+ const anchoredContent = linkMark ? {
596
+ ...createHyperlink(linkMark),
597
+ children: [marker]
598
+ } : marker;
599
+ const changeMark = insertionMark ?? deletionMark;
600
+ if (!changeMark) {
601
+ content.push(anchoredContent);
602
+ return;
603
+ }
604
+ const changeAttrs = expectTrackedChangeMarkAttrs(changeMark);
605
+ const info = {
606
+ id: changeAttrs.revisionId,
607
+ author: changeAttrs.author || "Unknown",
608
+ ...changeAttrs.date ? { date: changeAttrs.date } : {}
609
+ };
610
+ if (insertionMark) content.push({
611
+ type: changeAttrs.moveKind === "moveTo" ? "moveTo" : "insertion",
612
+ info,
613
+ content: [anchoredContent]
614
+ });
615
+ else content.push({
616
+ type: changeAttrs.moveKind === "moveFrom" ? "moveFrom" : "deletion",
617
+ info,
618
+ content: [anchoredContent]
619
+ });
620
+ return;
621
+ }
463
622
  if (insertionMark || deletionMark) {
464
623
  flushCurrentInline();
465
624
  const changeMark = insertionMark ?? deletionMark;
@@ -467,6 +626,10 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
467
626
  const changeAttrs = expectTrackedChangeMarkAttrs(changeMark);
468
627
  const run = createTrackedChangeRun(node, node.marks.filter((m) => m.type.name !== "insertion" && m.type.name !== "deletion"));
469
628
  if (!run) return;
629
+ const trackedContent = linkMark ? {
630
+ ...createHyperlink(linkMark),
631
+ children: [run]
632
+ } : run;
470
633
  const info = {
471
634
  id: changeAttrs.revisionId,
472
635
  author: changeAttrs.author || "Unknown"
@@ -475,22 +638,22 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
475
638
  if (insertionMark) if (changeAttrs.moveKind === "moveTo") content.push({
476
639
  type: "moveTo",
477
640
  info,
478
- content: [run]
641
+ content: [trackedContent]
479
642
  });
480
643
  else content.push({
481
644
  type: "insertion",
482
645
  info,
483
- content: [run]
646
+ content: [trackedContent]
484
647
  });
485
648
  else if (changeAttrs.moveKind === "moveFrom") content.push({
486
649
  type: "moveFrom",
487
650
  info,
488
- content: [run]
651
+ content: [trackedContent]
489
652
  });
490
653
  else content.push({
491
654
  type: "deletion",
492
655
  info,
493
- content: [run]
656
+ content: [trackedContent]
494
657
  });
495
658
  return;
496
659
  }
@@ -530,12 +693,15 @@ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
530
693
  } else if (node.type.name === "tab") {
531
694
  flushCurrentInline();
532
695
  content.push(createTabRun());
696
+ } else if (node.type.name === "renderedPageBreak") {
697
+ flushCurrentInline();
698
+ content.push(createRenderedPageBreakRun());
533
699
  } else if (node.type.name === "field") {
534
700
  flushCurrentInline();
535
701
  content.push(createFieldFromNode(node, node.marks));
536
702
  } else if (node.type.name === "sdt") {
537
703
  flushCurrentInline();
538
- content.push(createInlineSdtFromNode(node));
704
+ content.push(createInlineSdtFromNode(node, textBoxAnchorMarkers));
539
705
  } else if (node.type.name === "math") {
540
706
  flushCurrentInline();
541
707
  content.push(createMathFromNode(node));
@@ -576,7 +742,7 @@ function createTrackedChangeRun(node, marks) {
576
742
  if (noteRefMark) return createNoteReferenceRun(noteRefMark, marks);
577
743
  if (node.isText) {
578
744
  const formatting = marksToTextFormatting(marks);
579
- return {
745
+ const run = {
580
746
  type: "run",
581
747
  content: node.text ? [{
582
748
  type: "text",
@@ -584,11 +750,14 @@ function createTrackedChangeRun(node, marks) {
584
750
  }] : [],
585
751
  ...Object.keys(formatting).length > 0 ? { formatting } : {}
586
752
  };
753
+ restoreRunPropertyChanges(run, marks);
754
+ return run;
587
755
  }
588
756
  if (node.type.name === "hardBreak") return createBreakRun(readHardBreakType(node));
589
757
  if (node.type.name === "image") return createImageRun(node);
590
758
  if (node.type.name === "shape") return createShapeRun(node);
591
759
  if (node.type.name === "tab") return createTabRun();
760
+ if (node.type.name === "renderedPageBreak") return createRenderedPageBreakRun();
592
761
  return null;
593
762
  }
594
763
  function createEmptyHyperlink(attrs) {
@@ -699,6 +868,10 @@ function addNodeToHyperlink(hyperlink, node) {
699
868
  hyperlink.children.push(createTabRun(nonLinkMarks));
700
869
  return;
701
870
  }
871
+ if (node.type.name === "renderedPageBreak") {
872
+ hyperlink.children.push(createRenderedPageBreakRun());
873
+ return;
874
+ }
702
875
  if (node.type.name === "image") {
703
876
  hyperlink.children.push(createImageRun(node));
704
877
  return;
@@ -736,8 +909,16 @@ function createRunFromText(text, marks) {
736
909
  }]
737
910
  };
738
911
  if (formatting) run.formatting = formatting;
912
+ restoreRunPropertyChanges(run, marks);
739
913
  return run;
740
914
  }
915
+ function restoreRunPropertyChanges(run, marks) {
916
+ const changeMark = marks.find((mark) => mark.type.name === "runPropertyChange");
917
+ if (!changeMark) return;
918
+ const { changes } = expectRunPropertyChangeMarkAttrs(changeMark);
919
+ if (changes.length === 0) return;
920
+ run.propertyChanges = [...changes];
921
+ }
741
922
  function getRunFormattingFromMarks(marks) {
742
923
  if (!marks || marks.length === 0) return;
743
924
  const formatting = marksToTextFormatting(marks);
@@ -769,6 +950,12 @@ function createBreakRun(breakType = "textWrapping", marks) {
769
950
  if (formatting) run.formatting = formatting;
770
951
  return run;
771
952
  }
953
+ function createRenderedPageBreakRun() {
954
+ return {
955
+ type: "run",
956
+ content: [{ type: "renderedPageBreak" }]
957
+ };
958
+ }
772
959
  function readHardBreakType(node) {
773
960
  return expectHardBreakAttrs(node).breakType ?? "textWrapping";
774
961
  }
@@ -848,41 +1035,13 @@ function createMathFromNode(node) {
848
1035
  /**
849
1036
  * Create an InlineSdt from a PM sdt node
850
1037
  */
851
- function createInlineSdtFromNode(node) {
852
- const attrs = expectSdtAttrs(node);
853
- const properties = { sdtType: attrs.sdtType };
854
- if (attrs.alias) properties.alias = attrs.alias;
855
- if (attrs.tag) properties.tag = attrs.tag;
856
- if (typeof attrs.id === "number") properties.id = attrs.id;
857
- if (attrs.lock) properties.lock = attrs.lock;
858
- if (attrs.placeholder) properties.placeholder = attrs.placeholder;
859
- if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
860
- if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
861
- if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
862
- if (attrs.listItems) properties.listItems = parseSdtListItems(attrs.listItems);
863
- if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
864
- if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
865
- if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
866
- if (attrs.rawEndPropertiesXml) properties.rawEndPropertiesXml = attrs.rawEndPropertiesXml;
1038
+ function createInlineSdtFromNode(node, textBoxAnchorMarkers) {
867
1039
  return {
868
1040
  type: "inlineSdt",
869
- properties,
870
- content: extractParagraphContent(node).filter((c) => c.type === "run" || c.type === "hyperlink" || c.type === "simpleField" || c.type === "complexField" || c.type === "inlineSdt" || c.type === "insertion" || c.type === "deletion" || c.type === "mathEquation")
1041
+ properties: sdtPropertiesFromAttrs(expectSdtAttrs(node)),
1042
+ content: extractParagraphContent(node, void 0, void 0, textBoxAnchorMarkers).filter((c) => c.type === "run" || c.type === "hyperlink" || c.type === "simpleField" || c.type === "complexField" || c.type === "inlineSdt" || c.type === "insertion" || c.type === "deletion" || c.type === "moveFrom" || c.type === "moveTo" || c.type === "mathEquation")
871
1043
  };
872
1044
  }
873
- function parseSdtListItems(rawItems) {
874
- const parsed = JSON.parse(rawItems);
875
- if (!Array.isArray(parsed)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems is not an array");
876
- return parsed.map((item) => {
877
- if (!item || typeof item !== "object" || Array.isArray(item)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
878
- const itemAttrs = item;
879
- if (typeof itemAttrs.displayText !== "string" || typeof itemAttrs.value !== "string") throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
880
- return {
881
- displayText: itemAttrs.displayText,
882
- value: itemAttrs.value
883
- };
884
- });
885
- }
886
1045
  /**
887
1046
  * Create a Run containing an image
888
1047
  */
@@ -1399,6 +1558,22 @@ function convertPMTableRow(node, documentCounts, activeVerticalMerges) {
1399
1558
  const rowFormatting = tableRowAttrsToFormatting(attrs);
1400
1559
  if (rowFormatting) row.formatting = rowFormatting;
1401
1560
  if (Array.isArray(attrs.trPrChange) && attrs.trPrChange.length > 0) row.propertyChanges = [...attrs.trPrChange];
1561
+ if (attrs.trIns) row.structuralChange = {
1562
+ type: "tableRowInsertion",
1563
+ info: {
1564
+ id: attrs.trIns.revisionId,
1565
+ author: attrs.trIns.author,
1566
+ ...attrs.trIns.date != null && { date: attrs.trIns.date }
1567
+ }
1568
+ };
1569
+ else if (attrs.trDel) row.structuralChange = {
1570
+ type: "tableRowDeletion",
1571
+ info: {
1572
+ id: attrs.trDel.revisionId,
1573
+ author: attrs.trDel.author,
1574
+ ...attrs.trDel.date != null && { date: attrs.trDel.date }
1575
+ }
1576
+ };
1402
1577
  return row;
1403
1578
  }
1404
1579
  function createVerticalMergeContinuationCell(colspan) {
@@ -1450,19 +1625,22 @@ function tableRowAttrsToFormatting(attrs) {
1450
1625
  function convertPMTableCell(node, documentCounts) {
1451
1626
  const attrs = expectTableCellAttrs(node);
1452
1627
  const content = [];
1628
+ const textBoxAnchorMarkers = /* @__PURE__ */ new Map();
1453
1629
  let previousStandaloneTextBox = null;
1454
1630
  node.forEach((contentNode) => {
1455
1631
  if (contentNode.type.name === "paragraph") {
1456
- content.push(convertPMParagraph(contentNode, documentCounts));
1632
+ content.push(convertPMParagraph(contentNode, documentCounts, textBoxAnchorMarkers));
1457
1633
  previousStandaloneTextBox = null;
1458
1634
  } else if (contentNode.type.name === "table") {
1459
1635
  content.push(convertPMTable(contentNode, documentCounts));
1460
1636
  previousStandaloneTextBox = null;
1461
1637
  } else if (contentNode.type.name === "textBox") previousStandaloneTextBox = appendTextBoxBlock(content, contentNode, {
1462
1638
  pendingPageBreaks: 0,
1463
- previousStandaloneTextBox
1639
+ previousStandaloneTextBox,
1640
+ textBoxAnchorMarkers
1464
1641
  });
1465
1642
  });
1643
+ removeUnresolvedTextBoxAnchors(content, textBoxAnchorMarkers);
1466
1644
  const cell = {
1467
1645
  type: "tableCell",
1468
1646
  content
@@ -1470,8 +1648,26 @@ function convertPMTableCell(node, documentCounts) {
1470
1648
  const cellFormatting = tableCellAttrsToFormatting(attrs);
1471
1649
  if (cellFormatting) cell.formatting = cellFormatting;
1472
1650
  if (Array.isArray(attrs.tcPrChange) && attrs.tcPrChange.length > 0) cell.propertyChanges = [...attrs.tcPrChange];
1651
+ if (attrs.cellMarker) {
1652
+ const info = {
1653
+ id: attrs.cellMarker.info.revisionId,
1654
+ author: attrs.cellMarker.info.author,
1655
+ ...attrs.cellMarker.info.date != null && { date: attrs.cellMarker.info.date }
1656
+ };
1657
+ if (attrs.cellMarker.kind === "merge") cell.structuralChange = {
1658
+ type: "tableCellMerge",
1659
+ info,
1660
+ ...attrs.cellMarker.verticalMerge !== void 0 ? { verticalMerge: attrs.cellMarker.verticalMerge } : {},
1661
+ ...attrs.cellMarker.verticalMergeOriginal !== void 0 ? { verticalMergeOriginal: attrs.cellMarker.verticalMergeOriginal } : {}
1662
+ };
1663
+ else cell.structuralChange = {
1664
+ type: attrs.cellMarker.kind === "ins" ? "tableCellInsertion" : "tableCellDeletion",
1665
+ info
1666
+ };
1667
+ }
1473
1668
  return cell;
1474
1669
  }
1670
+ const standaloneTableCellFromProseMirror = (node) => convertPMTableCell(node);
1475
1671
  const cellShadingFromAttrs = (attrs) => attrs.backgroundColor ? { fill: { rgb: attrs.backgroundColor } } : { pattern: "nil" };
1476
1672
  function tableCellAttrsToFormatting(attrs) {
1477
1673
  const backgroundChanged = attrs.backgroundColor !== attrs._resolvedBackgroundColor;
@@ -1479,6 +1675,7 @@ function tableCellAttrsToFormatting(attrs) {
1479
1675
  const orig = attrs._originalFormatting;
1480
1676
  const result = { ...orig };
1481
1677
  if (attrs.colspan > 1) result.gridSpan = attrs.colspan;
1678
+ else delete result.gridSpan;
1482
1679
  if (attrs.rowspan > 1) result.vMerge = "restart";
1483
1680
  else if (result.vMerge === "restart" && !attrs._preserveVMergeRestart) delete result.vMerge;
1484
1681
  const cellWidth = attrs.width;
@@ -1517,9 +1714,10 @@ function tableCellAttrsToFormatting(attrs) {
1517
1714
  */
1518
1715
  function convertPMTextBox(node) {
1519
1716
  const attrs = expectTextBoxAttrs(node);
1520
- const childParagraphs = [];
1717
+ const childBlocks = [];
1521
1718
  node.forEach((child) => {
1522
- if (child.type.name === "paragraph") childParagraphs.push(convertPMParagraph(child));
1719
+ if (child.type.name === "paragraph") childBlocks.push(convertPMParagraph(child));
1720
+ else if (child.type.name === "table") childBlocks.push(convertPMTable(child));
1523
1721
  });
1524
1722
  const shape = {
1525
1723
  type: "shape",
@@ -1529,7 +1727,7 @@ function convertPMTextBox(node) {
1529
1727
  height: attrs.height ? pixelsToEmu(attrs.height) : 0
1530
1728
  },
1531
1729
  textBody: {
1532
- content: childParagraphs.length > 0 ? childParagraphs : [{
1730
+ content: childBlocks.length > 0 ? childBlocks : [{
1533
1731
  type: "paragraph",
1534
1732
  content: []
1535
1733
  }],
@@ -1561,16 +1759,43 @@ function convertPMTextBox(node) {
1561
1759
  if (wrap) shape.wrap = wrap;
1562
1760
  const position = imagePositionFromAttrs(attrs.position);
1563
1761
  if (position) shape.position = position;
1564
- return {
1565
- type: "paragraph",
1762
+ const run = {
1763
+ type: "run",
1566
1764
  content: [{
1567
- type: "run",
1568
- content: [{
1569
- type: "shape",
1570
- shape
1571
- }]
1765
+ type: "shape",
1766
+ shape
1572
1767
  }]
1573
1768
  };
1769
+ const trackedChange = attrs._docxTrackedChange;
1770
+ const inlineSdts = attrs._docxInlineSdts ?? [];
1771
+ if (inlineSdts.length > 0) {
1772
+ let wrapped = trackedChange ? {
1773
+ type: trackedChange.type,
1774
+ info: trackedChange.info,
1775
+ content: [run]
1776
+ } : run;
1777
+ for (let index = inlineSdts.length - 1; index >= 0; index -= 1) {
1778
+ const sdtAttrs = inlineSdts[index];
1779
+ if (!sdtAttrs) continue;
1780
+ wrapped = {
1781
+ type: "inlineSdt",
1782
+ properties: sdtPropertiesFromAttrs(sdtAttrs),
1783
+ content: [wrapped]
1784
+ };
1785
+ }
1786
+ return {
1787
+ type: "paragraph",
1788
+ content: [wrapped]
1789
+ };
1790
+ }
1791
+ return {
1792
+ type: "paragraph",
1793
+ content: trackedChange ? [{
1794
+ type: trackedChange.type,
1795
+ info: trackedChange.info,
1796
+ content: [run]
1797
+ }] : [run]
1798
+ };
1574
1799
  }
1575
1800
  /**
1576
1801
  * Update a Document with content from a ProseMirror document
@@ -1590,4 +1815,4 @@ function proseDocToBlocks(pmDoc) {
1590
1815
  return extractBlocks(pmDoc);
1591
1816
  }
1592
1817
  //#endregion
1593
- export { fromProseDoc, marksToTextFormatting, proseDocToBlocks, updateDocumentContent };
1818
+ export { fromProseDoc, marksToTextFormatting, proseDocToBlocks, standaloneTableCellFromProseMirror, updateDocumentContent };
@@ -0,0 +1,9 @@
1
+ import { document_d_exports } from "../../types/document.js";
2
+ import { SdtAttrs } from "../schema/nodes.js";
3
+
4
+ //#region src/prosemirror/conversion/sdtAttrs.d.ts
5
+ declare const sdtAttrsFromProperties: (properties: document_d_exports.SdtProperties) => SdtAttrs;
6
+ declare const sdtPropertiesFromAttrs: (attrs: SdtAttrs) => document_d_exports.SdtProperties;
7
+ declare const sdtPropertiesMatchAttrs: (properties: document_d_exports.SdtProperties, attrs: SdtAttrs) => boolean;
8
+ //#endregion
9
+ export { sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };
@@ -0,0 +1,49 @@
1
+ //#region src/prosemirror/conversion/sdtAttrs.ts
2
+ const sdtAttrsFromProperties = (properties) => ({
3
+ sdtType: properties.sdtType,
4
+ ...properties.alias !== void 0 ? { alias: properties.alias } : {},
5
+ ...properties.tag !== void 0 ? { tag: properties.tag } : {},
6
+ ...properties.id !== void 0 ? { id: properties.id } : {},
7
+ ...properties.lock !== void 0 ? { lock: properties.lock } : {},
8
+ ...properties.placeholder !== void 0 ? { placeholder: properties.placeholder } : {},
9
+ showingPlaceholder: properties.showingPlaceholder ?? false,
10
+ ...properties.dateFormat !== void 0 ? { dateFormat: properties.dateFormat } : {},
11
+ ...properties.dateValueISO !== void 0 ? { dateValueISO: properties.dateValueISO } : {},
12
+ ...properties.listItems !== void 0 ? { listItems: JSON.stringify(properties.listItems) } : {},
13
+ ...properties.dropdownLastValue !== void 0 ? { dropdownLastValue: properties.dropdownLastValue } : {},
14
+ ...properties.checked !== void 0 ? { checked: properties.checked } : {},
15
+ ...properties.rawPropertiesXml !== void 0 ? { rawPropertiesXml: properties.rawPropertiesXml } : {},
16
+ ...properties.rawEndPropertiesXml !== void 0 ? { rawEndPropertiesXml: properties.rawEndPropertiesXml } : {}
17
+ });
18
+ const sdtPropertiesFromAttrs = (attrs) => {
19
+ const properties = { sdtType: attrs.sdtType };
20
+ if (attrs.alias) properties.alias = attrs.alias;
21
+ if (attrs.tag) properties.tag = attrs.tag;
22
+ if (typeof attrs.id === "number") properties.id = attrs.id;
23
+ if (attrs.lock) properties.lock = attrs.lock;
24
+ if (attrs.placeholder) properties.placeholder = attrs.placeholder;
25
+ if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
26
+ if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
27
+ if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
28
+ if (attrs.listItems) properties.listItems = parseSdtListItems(attrs.listItems);
29
+ if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
30
+ if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
31
+ if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
32
+ if (attrs.rawEndPropertiesXml) properties.rawEndPropertiesXml = attrs.rawEndPropertiesXml;
33
+ return properties;
34
+ };
35
+ const sdtPropertiesMatchAttrs = (properties, attrs) => JSON.stringify(sdtAttrsFromProperties(properties)) === JSON.stringify(sdtAttrsFromProperties(sdtPropertiesFromAttrs(attrs)));
36
+ const parseSdtListItems = (rawItems) => {
37
+ const parsed = JSON.parse(rawItems);
38
+ if (!Array.isArray(parsed)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems is not an array");
39
+ return parsed.map((item) => {
40
+ if (!item || typeof item !== "object" || Array.isArray(item)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
41
+ if (!("displayText" in item) || typeof item.displayText !== "string" || !("value" in item) || typeof item.value !== "string") throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
42
+ return {
43
+ displayText: item.displayText,
44
+ value: item.value
45
+ };
46
+ });
47
+ };
48
+ //#endregion
49
+ export { sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };