@stll/folio-core 0.54.2 → 0.56.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 (267) hide show
  1. package/dist/ai-edits/apply.js +185 -33
  2. package/dist/ai-edits/headless.js +3 -2
  3. package/dist/ai-edits/types.d.ts +7 -1
  4. package/dist/compare/compare.js +1 -0
  5. package/dist/compare/content-types.d.ts +3 -15
  6. package/dist/compare/reproducible-package.d.ts +0 -17
  7. package/dist/compare/reproducible-package.js +12 -18
  8. package/dist/controller/canonicalClipboard.d.ts +23 -0
  9. package/dist/controller/canonicalClipboard.js +476 -0
  10. package/dist/controller/canonicalClipboardResources.d.ts +21 -0
  11. package/dist/controller/canonicalClipboardResources.js +382 -0
  12. package/dist/controller/canonicalComposition.d.ts +53 -0
  13. package/dist/controller/canonicalComposition.js +296 -0
  14. package/dist/controller/canonicalInlineProjection.d.ts +113 -0
  15. package/dist/controller/canonicalInlineProjection.js +393 -0
  16. package/dist/controller/canonicalInput.d.ts +54 -0
  17. package/dist/controller/canonicalInput.js +377 -0
  18. package/dist/controller/canonicalInputTimer.d.ts +7 -0
  19. package/dist/controller/canonicalInputTimer.js +11 -0
  20. package/dist/controller/canonicalOperations.d.ts +22 -0
  21. package/dist/controller/canonicalOperations.js +85 -0
  22. package/dist/controller/canonicalPublicOperations.d.ts +48 -0
  23. package/dist/controller/canonicalPublicOperations.js +556 -0
  24. package/dist/controller/canonicalReview.d.ts +12 -0
  25. package/dist/controller/canonicalReview.js +19 -0
  26. package/dist/controller/canonicalSession.d.ts +167 -0
  27. package/dist/controller/canonicalSession.js +1186 -0
  28. package/dist/controller/canonicalStoryEditor.d.ts +36 -0
  29. package/dist/controller/canonicalStoryEditor.js +87 -0
  30. package/dist/controller/canonicalStructure.d.ts +16 -0
  31. package/dist/controller/canonicalStructure.js +322 -0
  32. package/dist/controller/canonicalTocSelection.d.ts +11 -0
  33. package/dist/controller/canonicalTocSelection.js +43 -0
  34. package/dist/controller/folioEditor.d.ts +3 -10
  35. package/dist/controller/folioEditor.js +14 -4
  36. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  37. package/dist/controller/headerFooterEditorManager.js +72 -3
  38. package/dist/controller/hiddenEditorApi.d.ts +45 -0
  39. package/dist/controller/hiddenEditorApi.js +29 -8
  40. package/dist/controller/hiddenEditorManager.d.ts +13 -2
  41. package/dist/controller/hiddenEditorManager.js +639 -31
  42. package/dist/controller/layoutPipeline.d.ts +1 -1
  43. package/dist/controller/layoutPipeline.js +2 -0
  44. package/dist/controller/noteEditorManager.d.ts +5 -0
  45. package/dist/controller/noteEditorManager.js +114 -15
  46. package/dist/document-operations.d.ts +8 -1
  47. package/dist/document-operations.js +6 -4
  48. package/dist/docx/attributeRemainder.js +1 -0
  49. package/dist/docx/blockPlainText.d.ts +1 -1
  50. package/dist/docx/blockPlainText.js +11 -3
  51. package/dist/docx/canonicalResourceSave.d.ts +16 -0
  52. package/dist/docx/canonicalResourceSave.js +27 -0
  53. package/dist/docx/canonicalSave.d.ts +29 -0
  54. package/dist/docx/canonicalSave.js +101 -0
  55. package/dist/docx/canonicalSessionInput.d.ts +11 -0
  56. package/dist/docx/canonicalSessionInput.js +27 -0
  57. package/dist/docx/canonicalStoryRepack.d.ts +10 -0
  58. package/dist/docx/canonicalStoryRepack.js +74 -0
  59. package/dist/docx/contentTypeRegistry.d.ts +8 -0
  60. package/dist/docx/contentTypeRegistry.js +64 -0
  61. package/dist/docx/documentParser.d.ts +1 -13
  62. package/dist/docx/documentParser.js +1 -47
  63. package/dist/docx/ensureParaIds.d.ts +7 -1
  64. package/dist/docx/ensureParaIds.js +173 -215
  65. package/dist/docx/foldedListNumberFields.d.ts +85 -0
  66. package/dist/docx/foldedListNumberFields.js +267 -0
  67. package/dist/docx/footnoteParser.d.ts +1 -11
  68. package/dist/docx/footnoteParser.js +1 -16
  69. package/dist/docx/headerFooterParser.d.ts +1 -9
  70. package/dist/docx/headerFooterParser.js +1 -12
  71. package/dist/docx/headerFooterVerbatim.d.ts +39 -1
  72. package/dist/docx/headerFooterVerbatim.js +173 -2
  73. package/dist/docx/imageParser.d.ts +13 -1
  74. package/dist/docx/imageParser.js +20 -11
  75. package/dist/docx/metadataPrivacy.js +6 -1
  76. package/dist/docx/noteIds.d.ts +5 -0
  77. package/dist/docx/noteIds.js +6 -2
  78. package/dist/docx/noteReferenceMark.d.ts +3 -1
  79. package/dist/docx/noteReferenceMark.js +15 -14
  80. package/dist/docx/numberingParser.d.ts +3 -1
  81. package/dist/docx/numberingParser.js +17 -3
  82. package/dist/docx/packageParts.d.ts +3 -1
  83. package/dist/docx/packageParts.js +74 -19
  84. package/dist/docx/paragraphMarkPropertyPresence.d.ts +9 -0
  85. package/dist/docx/paragraphMarkPropertyPresence.js +21 -0
  86. package/dist/docx/paragraphParser.js +101 -53
  87. package/dist/docx/paragraphPropertySource.d.ts +15 -1
  88. package/dist/docx/paragraphPropertySource.js +77 -22
  89. package/dist/docx/parser.js +3 -1
  90. package/dist/docx/removeHeaderFooterParts.js +17 -6
  91. package/dist/docx/reviewHistoryNamespace.d.ts +4 -0
  92. package/dist/docx/reviewHistoryNamespace.js +4 -0
  93. package/dist/docx/reviewResolutionProvenance.d.ts +25 -0
  94. package/dist/docx/reviewResolutionProvenance.js +153 -0
  95. package/dist/docx/rezip.d.ts +54 -6
  96. package/dist/docx/rezip.js +835 -257
  97. package/dist/docx/runConsolidator.d.ts +2 -58
  98. package/dist/docx/runConsolidator.js +3 -175
  99. package/dist/docx/runParser.d.ts +2 -1
  100. package/dist/docx/runParser.js +156 -116
  101. package/dist/docx/saveDiagnostics.d.ts +22 -0
  102. package/dist/docx/saveDiagnostics.js +0 -0
  103. package/dist/docx/selectiveSave.d.ts +3 -1
  104. package/dist/docx/selectiveSave.js +36 -4
  105. package/dist/docx/selectiveXmlPatch.d.ts +16 -8
  106. package/dist/docx/selectiveXmlPatch.js +81 -7
  107. package/dist/docx/serializer/documentSerializer.d.ts +9 -2
  108. package/dist/docx/serializer/documentSerializer.js +29 -10
  109. package/dist/docx/serializer/headerFooterSerializer.d.ts +5 -1
  110. package/dist/docx/serializer/headerFooterSerializer.js +19 -11
  111. package/dist/docx/serializer/noteSerializer.d.ts +2 -2
  112. package/dist/docx/serializer/noteSerializer.js +24 -8
  113. package/dist/docx/serializer/paragraphSerializer.js +41 -4
  114. package/dist/docx/serializer/partNamespaces.js +2 -1
  115. package/dist/docx/serializer/runSerializer.js +3 -1
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +14 -9
  117. package/dist/docx/settingsHeaderFooterUpdate.d.ts +5 -0
  118. package/dist/docx/settingsHeaderFooterUpdate.js +90 -0
  119. package/dist/docx/settingsParser.d.ts +1 -2
  120. package/dist/docx/settingsParser.js +5 -6
  121. package/dist/docx/storyBlockReplay.d.ts +31 -0
  122. package/dist/docx/storyBlockReplay.js +471 -0
  123. package/dist/docx/storyPlainText.d.ts +20 -0
  124. package/dist/docx/storyPlainText.js +23 -0
  125. package/dist/docx/streamingXmlParser.d.ts +22 -1
  126. package/dist/docx/streamingXmlParser.js +49 -3
  127. package/dist/docx/structuralXmlPatch.js +18 -23
  128. package/dist/docx/styleParser.d.ts +5 -1
  129. package/dist/docx/styleParser.js +1 -1
  130. package/dist/docx/tableParser.d.ts +1 -8
  131. package/dist/docx/tableParser.js +1 -28
  132. package/dist/docx/textBoxParser.d.ts +1 -5
  133. package/dist/docx/textBoxParser.js +1 -20
  134. package/dist/docx/unzip.js +6 -1
  135. package/dist/docx/verbatimCapture.d.ts +3 -1
  136. package/dist/docx/verbatimCapture.js +49 -6
  137. package/dist/i18n/messages/ar.gen.d.ts +5 -0
  138. package/dist/i18n/messages/ar.gen.js +656 -0
  139. package/dist/i18n/messages/cs.gen.d.ts +5 -0
  140. package/dist/i18n/messages/cs.gen.js +656 -0
  141. package/dist/i18n/messages/de.gen.d.ts +5 -0
  142. package/dist/i18n/messages/de.gen.js +656 -0
  143. package/dist/i18n/messages/en.gen.d.ts +5 -0
  144. package/dist/i18n/messages/en.gen.js +656 -0
  145. package/dist/i18n/messages/es.gen.d.ts +5 -0
  146. package/dist/i18n/messages/es.gen.js +656 -0
  147. package/dist/i18n/messages/et.gen.d.ts +5 -0
  148. package/dist/i18n/messages/et.gen.js +656 -0
  149. package/dist/i18n/messages/fr.gen.d.ts +5 -0
  150. package/dist/i18n/messages/fr.gen.js +656 -0
  151. package/dist/i18n/messages/he.gen.d.ts +5 -0
  152. package/dist/i18n/messages/he.gen.js +656 -0
  153. package/dist/i18n/messages/hi.gen.d.ts +5 -0
  154. package/dist/i18n/messages/hi.gen.js +656 -0
  155. package/dist/i18n/messages/hu.gen.d.ts +5 -0
  156. package/dist/i18n/messages/hu.gen.js +656 -0
  157. package/dist/i18n/messages/locales.d.ts +5 -0
  158. package/dist/i18n/messages/locales.js +22 -0
  159. package/dist/i18n/messages/lt.gen.d.ts +5 -0
  160. package/dist/i18n/messages/lt.gen.js +656 -0
  161. package/dist/i18n/messages/lv.gen.d.ts +5 -0
  162. package/dist/i18n/messages/lv.gen.js +656 -0
  163. package/dist/i18n/messages/pl.gen.d.ts +5 -0
  164. package/dist/i18n/messages/pl.gen.js +656 -0
  165. package/dist/i18n/messages/pt-BR.gen.d.ts +5 -0
  166. package/dist/i18n/messages/pt-BR.gen.js +656 -0
  167. package/dist/i18n/messages/sk.gen.d.ts +5 -0
  168. package/dist/i18n/messages/sk.gen.js +656 -0
  169. package/dist/i18n/messages/tr.gen.d.ts +5 -0
  170. package/dist/i18n/messages/tr.gen.js +656 -0
  171. package/dist/i18n/messages/zh-CN.gen.d.ts +5 -0
  172. package/dist/i18n/messages/zh-CN.gen.js +656 -0
  173. package/dist/i18n/messages.d.ts +2 -3
  174. package/dist/i18n/messages.js +1 -19
  175. package/dist/internal/acceptedBlockProjection.d.ts +12 -0
  176. package/dist/internal/acceptedBlockProjection.js +45 -0
  177. package/dist/internal/noteMarkerAttrs.d.ts +8 -0
  178. package/dist/internal/noteMarkerAttrs.js +16 -0
  179. package/dist/internal/pageBreakRunSourceDescendantIndex.js +1 -0
  180. package/dist/internal/prosemirrorAttrBoundary.d.ts +21 -0
  181. package/dist/internal/prosemirrorAttrBoundary.js +50 -0
  182. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  183. package/dist/layout-bridge/convert/footnoteLayout.js +3 -3
  184. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  185. package/dist/layout-bridge/convert/headerFooterLayout.js +1 -0
  186. package/dist/layout-bridge/convert/noteReferences.d.ts +1 -3
  187. package/dist/layout-bridge/convert/noteReferences.js +1 -6
  188. package/dist/layout-bridge/convert/paragraphRuns.js +2 -4
  189. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -2
  190. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -2
  191. package/dist/managers/DocumentLoaderManager.d.ts +1 -0
  192. package/dist/managers/DocumentLoaderManager.js +9 -1
  193. package/dist/markdown/escape.d.ts +3 -1
  194. package/dist/markdown/escape.js +9 -2
  195. package/dist/markdown/renderBlock.js +20 -121
  196. package/dist/markdown/renderParagraph.js +13 -15
  197. package/dist/markdown/renderRuns.d.ts +7 -1
  198. package/dist/markdown/renderRuns.js +35 -15
  199. package/dist/markdown/renderTable.js +2 -0
  200. package/dist/markdown/types.d.ts +3 -9
  201. package/dist/prosemirror/attrs/index.d.ts +2 -12
  202. package/dist/prosemirror/attrs/index.js +22 -48
  203. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -1
  204. package/dist/prosemirror/canonicalCommands.d.ts +121 -0
  205. package/dist/prosemirror/canonicalCommands.js +35 -0
  206. package/dist/prosemirror/canonicalSelectionRange.d.ts +9 -0
  207. package/dist/prosemirror/canonicalSelectionRange.js +15 -0
  208. package/dist/prosemirror/clipboardIntent.d.ts +7 -0
  209. package/dist/prosemirror/clipboardIntent.js +9 -0
  210. package/dist/prosemirror/commands/pageBreak.js +15 -1
  211. package/dist/prosemirror/commands/pastePlainText.js +2 -1
  212. package/dist/prosemirror/commentReferenceAttrs.d.ts +2 -1
  213. package/dist/prosemirror/conversion/fromProseDoc.js +91 -19
  214. package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +8 -0
  215. package/dist/prosemirror/conversion/hyphenTextCarriers.js +8 -0
  216. package/dist/prosemirror/conversion/listRenderingDefinition.d.ts +6 -0
  217. package/dist/prosemirror/conversion/listRenderingDefinition.js +97 -0
  218. package/dist/prosemirror/conversion/toProseDoc.d.ts +11 -4
  219. package/dist/prosemirror/conversion/toProseDoc.js +55 -14
  220. package/dist/prosemirror/executeEditorCommand.d.ts +11 -0
  221. package/dist/prosemirror/executeEditorCommand.js +26 -0
  222. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  223. package/dist/prosemirror/extensions/core/ParagraphExtension.js +88 -48
  224. package/dist/prosemirror/extensions/features/ListExtension.js +18 -5
  225. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +5 -2
  226. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +13 -1
  227. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +56 -28
  228. package/dist/prosemirror/extensions/marks/TextColorExtension.js +3 -2
  229. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
  230. package/dist/prosemirror/extensions/marks/markUtils.js +72 -8
  231. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts +6 -0
  232. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +36 -0
  233. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +4 -2
  234. package/dist/prosemirror/insertOperations.js +2 -1
  235. package/dist/prosemirror/listMarker.d.ts +1 -0
  236. package/dist/prosemirror/listMarker.js +16 -7
  237. package/dist/prosemirror/listNumbering.js +26 -5
  238. package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
  239. package/dist/prosemirror/listRenderingAttrs.js +3 -0
  240. package/dist/prosemirror/markupViewNotes.js +3 -2
  241. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +2 -1
  242. package/dist/prosemirror/noteReferenceReview.js +5 -3
  243. package/dist/prosemirror/paragraphPropertyCarry.d.ts +7 -1
  244. package/dist/prosemirror/paragraphPropertyCarry.js +8 -3
  245. package/dist/prosemirror/plugins/suggestionMode.js +57 -7
  246. package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -1
  247. package/dist/prosemirror/runFormattingFromMarks.d.ts +4 -1
  248. package/dist/prosemirror/runFormattingFromMarks.js +15 -1
  249. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -1
  250. package/dist/prosemirror/runFormattingInlineCarriers.js +4 -1
  251. package/dist/prosemirror/schema/marks.d.ts +2 -0
  252. package/dist/prosemirror/schema/nodes.d.ts +10 -2
  253. package/dist/prosemirror/textBoxAnchorAttrs.d.ts +2 -1
  254. package/dist/prosemirror/textInput.js +5 -1
  255. package/dist/prosemirror/trackedRevisionPath.js +2 -1
  256. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +1 -0
  257. package/dist/prosemirror/trackedRunInlineAtoms.js +1 -0
  258. package/dist/prosemirror/validation.js +4 -0
  259. package/dist/types/canonicalCapabilities.d.ts +215 -0
  260. package/dist/types/canonicalCapabilities.js +212 -0
  261. package/dist/types/canonicalSave.d.ts +11 -0
  262. package/dist/types/canonicalSave.js +0 -0
  263. package/dist/types/content.d.ts +2 -2
  264. package/dist/types/docxSerialization.d.ts +14 -0
  265. package/dist/types/docxSerialization.js +7 -0
  266. package/dist/utils/createDocument.js +2 -2
  267. package/package.json +16 -4
@@ -2,6 +2,8 @@ import { FONT_THEME_VALUES } from "../../../types/documentEnumValues.js";
2
2
  import { mergeFontFamily } from "../../../utils/fontFamilyMerge.js";
3
3
  import { normalizeHorizontalScalePercent } from "../../../utils/horizontalScale.js";
4
4
  import { expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectEmphasisMarkAttrs, expectFontFamilyMarkAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectStrikeMarkAttrs, expectTextEffectMarkAttrs } from "../../attrs/index.js";
5
+ import { canonicalRunFormatting, withCanonicalCommand } from "../../canonicalCommands.js";
6
+ import { canonicalSelectionRange } from "../../canonicalSelectionRange.js";
5
7
  import { runShadingAttrsToShading, shadingToRunShadingAttrs } from "../../conversion/runShadingMark.js";
6
8
  import { documentMarkType } from "../../documentSchema.js";
7
9
  import { selectRunFormattingCarrierRepresentations } from "../../runFormattingInlineCarriers.js";
@@ -12,6 +14,12 @@ import { applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs } from
12
14
  import { readThemeColor } from "@stll/docx-core/model";
13
15
  import { toggleMark } from "prosemirror-commands";
14
16
  //#region src/prosemirror/extensions/marks/markUtils.ts
17
+ /**
18
+ * Shared mark utility functions
19
+ *
20
+ * setMark, removeMark, isMarkActive, getMarkAttr, marksToTextFormatting,
21
+ * textFormattingToMarks, clearFormatting
22
+ */
15
23
  const isFontTheme = (value) => value !== void 0 && FONT_THEME_VALUES.some((theme) => theme === value);
16
24
  const fontFamilyAttrsToFormatting = ({ ascii, hAnsi, eastAsia, cs, hint, asciiTheme, hAnsiTheme, eastAsiaTheme, csTheme }) => ({
17
25
  ...ascii !== void 0 ? { ascii } : {},
@@ -179,8 +187,24 @@ function createMarkWithMergedAttrs(markType, currentMark, nextAttrs) {
179
187
  if (!markRequiresAttrMerge(markType)) return markType.create(nextAttrs);
180
188
  return markType.create(mergeMarkAttrs(markType, currentMark, nextAttrs));
181
189
  }
190
+ const canonicalSetMarkFormatting = ({ state, type, attrs }) => {
191
+ const markType = documentMarkType(state, type);
192
+ const { empty } = state.selection;
193
+ const { from, to } = canonicalSelectionRange(state);
194
+ if (empty) return canonicalRunFormatting(state, marksToTextFormatting([createMarkWithMergedAttrs(markType, markType.isInSet(state.storedMarks ?? state.selection.$from.marks()), attrs)]));
195
+ return selectRunFormattingCarrierRepresentations({
196
+ doc: state.doc,
197
+ from,
198
+ to
199
+ }).map((representation) => ({
200
+ type: "formatRun",
201
+ from: representation.from,
202
+ to: representation.to,
203
+ patch: marksToTextFormatting([createMarkWithMergedAttrs(markType, markType.isInSet(representation.node.marks), attrs)])
204
+ }));
205
+ };
182
206
  function setMark(type, attrs) {
183
- return (state, dispatch) => {
207
+ const command = (state, dispatch) => {
184
208
  const markType = documentMarkType(state, type);
185
209
  const { from, to, empty } = state.selection;
186
210
  if (empty) {
@@ -211,6 +235,12 @@ function setMark(type, attrs) {
211
235
  }
212
236
  return true;
213
237
  };
238
+ if (!RUN_FORMATTING_MARK_NAMES.has(type.name)) return command;
239
+ return withCanonicalCommand(command, (state) => canonicalSetMarkFormatting({
240
+ state,
241
+ type,
242
+ attrs
243
+ }));
214
244
  }
215
245
  const DIRECT_FONT_PROPERTIES = [
216
246
  "color",
@@ -287,17 +317,42 @@ const withRunFormattingOverride = (command, update) => (state, dispatch) => comm
287
317
  dispatch(updateRunFormattingOverride(state, tr, update));
288
318
  } : void 0);
289
319
  /** `toggleMark` for the document's own counterpart of `type`. */
290
- const toggleDocumentMark = (type) => (state, dispatch, view) => toggleMark(documentMarkType(state, type))(state, dispatch, view);
320
+ const toggleDocumentMark = (type) => {
321
+ const command = (state, dispatch, view) => toggleMark(documentMarkType(state, type))(state, dispatch, view);
322
+ if (!RUN_FORMATTING_MARK_NAMES.has(type.name)) return command;
323
+ return withCanonicalCommand(command, (state) => {
324
+ const markType = documentMarkType(state, type);
325
+ const formatting = marksToTextFormatting([markType.create()]);
326
+ if (!isMarkActive(state, markType)) return canonicalRunFormatting(state, formatting);
327
+ const keys = markType.name === "strike" ? ["strike", "doubleStrike"] : Object.keys(formatting);
328
+ return canonicalRunFormatting(state, Object.fromEntries(keys.map((key) => [key, null])));
329
+ });
330
+ };
291
331
  /** UI toggle whose direct-formatting contract explicitly targets both script families. */
292
- const toggleMarkForAllScripts = (type, property) => (state, dispatch) => {
332
+ const toggleMarkForAllScripts = (type, property) => withCanonicalCommand((state, dispatch) => {
293
333
  const markType = documentMarkType(state, type);
294
334
  const enabled = !isMarkActive(state, markType);
295
335
  return withRunFormattingOverride(toggleMark(markType), (attrs) => updatePairedToggleAttrs(attrs, property, enabled))(state, dispatch);
296
- };
336
+ }, (state) => {
337
+ const enabled = !isMarkActive(state, documentMarkType(state, type));
338
+ return canonicalRunFormatting(state, property === "bold" ? {
339
+ bold: enabled,
340
+ boldCs: enabled
341
+ } : {
342
+ italic: enabled,
343
+ italicCs: enabled
344
+ });
345
+ });
297
346
  /** UI size command whose direct-formatting contract explicitly targets both script families. */
298
- const setFontSizeForAllScripts = (markType, size) => withRunFormattingOverride(setMark(markType, { size }), (attrs) => updateFontSizeCompanionAttrs(attrs, size));
347
+ const setFontSizeForAllScripts = (markType, size) => withCanonicalCommand(withRunFormattingOverride(setMark(markType, { size }), (attrs) => updateFontSizeCompanionAttrs(attrs, size)), (state) => canonicalRunFormatting(state, {
348
+ fontSize: size,
349
+ fontSizeCs: size
350
+ }));
299
351
  /** Clears both ordinary and complex-script direct size through the UI command boundary. */
300
- const clearFontSizeForAllScripts = (markType) => withRunFormattingOverride(removeMark(markType), (attrs) => updateFontSizeCompanionAttrs(attrs, void 0));
352
+ const clearFontSizeForAllScripts = (markType) => withCanonicalCommand(withRunFormattingOverride(removeMark(markType), (attrs) => updateFontSizeCompanionAttrs(attrs, void 0)), (state) => canonicalRunFormatting(state, {
353
+ fontSize: null,
354
+ fontSizeCs: null
355
+ }));
301
356
  function selectionHasVisibleUnderline(state, markType) {
302
357
  const { from, to, empty, $from } = state.selection;
303
358
  if (empty) {
@@ -317,10 +372,14 @@ function selectionHasVisibleUnderline(state, markType) {
317
372
  return hasVisibleUnderline;
318
373
  }
319
374
  function toggleUnderlineMark(markType) {
320
- return (state, dispatch) => setMark(markType, { style: selectionHasVisibleUnderline(state, documentMarkType(state, markType)) ? "none" : "single" })(state, dispatch);
375
+ return withCanonicalCommand((state, dispatch) => setMark(markType, { style: selectionHasVisibleUnderline(state, documentMarkType(state, markType)) ? "none" : "single" })(state, dispatch), (state) => canonicalSetMarkFormatting({
376
+ state,
377
+ type: markType,
378
+ attrs: { style: selectionHasVisibleUnderline(state, documentMarkType(state, markType)) ? "none" : "single" }
379
+ }));
321
380
  }
322
381
  function removeMark(type) {
323
- return (state, dispatch) => {
382
+ const command = (state, dispatch) => {
324
383
  const markType = documentMarkType(state, type);
325
384
  const { from, to, empty } = state.selection;
326
385
  if (empty) {
@@ -330,6 +389,11 @@ function removeMark(type) {
330
389
  if (dispatch) dispatch(state.tr.removeMark(from, to, markType).scrollIntoView());
331
390
  return true;
332
391
  };
392
+ if (!RUN_FORMATTING_MARK_NAMES.has(type.name)) return command;
393
+ return withCanonicalCommand(command, (state) => {
394
+ const formatting = marksToTextFormatting([documentMarkType(state, type).create()]);
395
+ return canonicalRunFormatting(state, Object.fromEntries(Object.keys(formatting).map((key) => [key, null])));
396
+ });
333
397
  }
334
398
  /**
335
399
  * Check if a mark is active in the current selection
@@ -0,0 +1,6 @@
1
+ import { NodeExtension } from "../types.js";
2
+ //#region src/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts
3
+ declare const NOTE_MARKER_NODE_NAME = "noteMarker";
4
+ declare const NoteMarkerExtension: (options?: Partial<Record<string, unknown>> | undefined) => NodeExtension;
5
+ //#endregion
6
+ export { NOTE_MARKER_NODE_NAME, NoteMarkerExtension };
@@ -0,0 +1,36 @@
1
+ import { expectNoteMarkerAttrs } from "../../../internal/noteMarkerAttrs.js";
2
+ import { createNodeExtension } from "../create.js";
3
+ //#region src/prosemirror/extensions/nodes/NoteMarkerExtension.ts
4
+ /** An authored automatic note mark: invisible, but retained through PM JSON and edits. */
5
+ const NOTE_MARKER_NODE_NAME = "noteMarker";
6
+ const NoteMarkerExtension = createNodeExtension({
7
+ name: NOTE_MARKER_NODE_NAME,
8
+ schemaNodeName: NOTE_MARKER_NODE_NAME,
9
+ nodeSpec: {
10
+ inline: true,
11
+ group: "inline",
12
+ atom: true,
13
+ marks: "_",
14
+ selectable: false,
15
+ attrs: { kind: {} },
16
+ parseDOM: [{
17
+ tag: "span[data-docx-note-marker]",
18
+ getAttrs(node) {
19
+ if (!(node instanceof HTMLElement)) return false;
20
+ const kind = node.dataset["docxNoteMarker"];
21
+ return kind === "footnote" || kind === "endnote" ? { kind } : false;
22
+ }
23
+ }],
24
+ toDOM(node) {
25
+ const { kind } = expectNoteMarkerAttrs(node);
26
+ return ["span", {
27
+ "data-docx-note-marker": kind,
28
+ "aria-hidden": "true",
29
+ contenteditable: "false",
30
+ style: "display: none;"
31
+ }];
32
+ }
33
+ }
34
+ });
35
+ //#endregion
36
+ export { NOTE_MARKER_NODE_NAME, NoteMarkerExtension };
@@ -25,7 +25,8 @@ const PreservedXmlExtension = createNodeExtension({
25
25
  attrs: {
26
26
  xml: {},
27
27
  text: { default: "" },
28
- level: { default: PRESERVED_XML_LEVELS.run }
28
+ level: { default: PRESERVED_XML_LEVELS.run },
29
+ foldedListNumber: { default: void 0 }
29
30
  },
30
31
  parseDOM: [{
31
32
  tag: "span[data-docx-preserved-xml]",
@@ -42,7 +43,8 @@ const PreservedXmlExtension = createNodeExtension({
42
43
  }
43
44
  }],
44
45
  toDOM(node) {
45
- const { xml, text, level } = expectPreservedXmlAttrs(node);
46
+ const { xml, text, level, foldedListNumber } = expectPreservedXmlAttrs(node);
47
+ if (foldedListNumber) return ["span", { contenteditable: "false" }];
46
48
  return [
47
49
  "span",
48
50
  {
@@ -2,6 +2,7 @@ import { insertImageFromFile } from "./commands/image.js";
2
2
  import { insertPageBreak } from "./commands/pageBreak.js";
3
3
  import { generateTableOfContents } from "./commands/paragraph.js";
4
4
  import { insertTable } from "./commands/table.js";
5
+ import { executeEditorCommand } from "./executeEditorCommand.js";
5
6
  //#region src/prosemirror/insertOperations.ts
6
7
  /** Insert a `rows × columns` table at the current selection. */
7
8
  function insertTableInView(view, rows, columns) {
@@ -18,7 +19,7 @@ function insertPageBreakInView(view) {
18
19
  * {@link GenerateTableOfContentsOptions}.
19
20
  */
20
21
  function insertTableOfContentsInView(view, options) {
21
- return generateTableOfContents(options)(view.state, view.dispatch);
22
+ return executeEditorCommand(view, generateTableOfContents(options));
22
23
  }
23
24
  //#endregion
24
25
  export { insertImageFromFile, insertPageBreakInView, insertTableInView, insertTableOfContentsInView };
@@ -55,6 +55,7 @@ declare const CLEARED_LIST_RENDERING_ATTRS: Readonly<{
55
55
  listMarkerSuffix: null;
56
56
  listMarkerAllCaps: null;
57
57
  listImplicitChildLevelAdvances: null;
58
+ listFoldedMarkerSuffix: null;
58
59
  listMarkerSecondSlotOffsetTwips: null;
59
60
  listLevelNumFmts: null;
60
61
  listLevelStarts: null;
@@ -17,6 +17,7 @@ const CLEARED_LIST_RENDERING_ATTRS = Object.freeze({
17
17
  listMarkerSuffix: null,
18
18
  listMarkerAllCaps: null,
19
19
  listImplicitChildLevelAdvances: null,
20
+ listFoldedMarkerSuffix: null,
20
21
  listMarkerSecondSlotOffsetTwips: null,
21
22
  listLevelNumFmts: null,
22
23
  listLevelStarts: null,
@@ -76,6 +77,7 @@ function previousListAttrs(attrs) {
76
77
  ...previous.listNumFmt !== void 0 ? { listNumFmt: previous.listNumFmt } : {},
77
78
  ...previous.listMarker !== void 0 ? { listMarker: previous.listMarker } : {},
78
79
  ...previous.listMarkerTemplate !== void 0 ? { listMarkerTemplate: previous.listMarkerTemplate } : {},
80
+ ...previous.listFoldedMarkerSuffix !== void 0 ? { listFoldedMarkerSuffix: previous.listFoldedMarkerSuffix } : {},
79
81
  ...previous.listMarkerHidden !== void 0 ? { listMarkerHidden: previous.listMarkerHidden } : {},
80
82
  ...previous.listMarkerFormatting !== void 0 ? { listMarkerFormatting: previous.listMarkerFormatting } : {},
81
83
  ...previous.listMarkerAlignment !== void 0 ? { listMarkerAlignment: previous.listMarkerAlignment } : {},
@@ -178,6 +180,7 @@ function formatNumberedMarker(counters, level) {
178
180
  }
179
181
  function advanceListMarker(attrs, state) {
180
182
  const markerTemplate = attrs.listMarkerTemplate ?? attrs.listMarker;
183
+ const foldedMarkerSuffix = attrs.listFoldedMarkerSuffix ?? void 0;
181
184
  const level = paragraphNumberingLevel(attrs.numPr) ?? 0;
182
185
  if (!Number.isInteger(level) || level < 0 || level > 8) return null;
183
186
  const numId = paragraphNumberingReferenceId(attrs.numPr);
@@ -205,7 +208,9 @@ function advanceListMarker(attrs, state) {
205
208
  fromStyle: false,
206
209
  numId: null
207
210
  };
208
- return convertBulletToUnicode(attrs.listMarker ?? markerTemplate ?? "", bulletMarkerFontName(attrs.listMarkerFormatting));
211
+ if (foldedMarkerSuffix !== void 0 && attrs.listMarkerTemplate == null) return attrs.listMarker ?? null;
212
+ const marker = convertBulletToUnicode(attrs.listMarkerTemplate ?? attrs.listMarker ?? "", bulletMarkerFontName(attrs.listMarkerFormatting));
213
+ return foldedMarkerSuffix === void 0 ? marker : `${marker}\t${foldedMarkerSuffix}`;
209
214
  }
210
215
  const firstInstanceEncounter = !state.counters.has(numId);
211
216
  let counters = state.counters.get(numId) ?? Array.from({ length: 9 }, () => NaN);
@@ -250,12 +255,16 @@ function advanceListMarker(attrs, state) {
250
255
  numId
251
256
  };
252
257
  const levelFormats = attrs.listLevelNumFmts ?? (attrs.listNumFmt ? [attrs.listNumFmt] : void 0);
253
- if (markerTemplate?.includes("%")) return resolveListTemplate({
254
- template: markerTemplate,
255
- counters,
256
- levelFormats,
257
- forceDecimal: attrs.listIsLegal
258
- });
258
+ if (markerTemplate?.includes("%") && (foldedMarkerSuffix === void 0 || attrs.listMarkerTemplate != null)) {
259
+ const marker = resolveListTemplate({
260
+ template: markerTemplate,
261
+ counters,
262
+ levelFormats,
263
+ forceDecimal: attrs.listIsLegal
264
+ });
265
+ return foldedMarkerSuffix === void 0 ? marker : `${marker}\t${foldedMarkerSuffix}`;
266
+ }
267
+ if (foldedMarkerSuffix !== void 0 && attrs.listMarkerTemplate != null) return `${attrs.listMarkerTemplate}\t${foldedMarkerSuffix}`;
259
268
  if (attrs.listMarker) return attrs.listMarker;
260
269
  if ((levelFormats?.[level] ?? attrs.listNumFmt) === "none" || attrs.listMarker === "") return null;
261
270
  return formatNumberedMarker(counters, level);
@@ -2,6 +2,7 @@ import { mintListInstance, restartListInstance } from "../docx/listNumberingInst
2
2
  import { createNumberingMap, isBulletLevel } from "../docx/numberingParser.js";
3
3
  import { paragraphNumberingLevel, paragraphNumberingReferenceId } from "../docx/numberingReference.js";
4
4
  import { expectParagraphAttrs } from "./attrs/index.js";
5
+ import { withCanonicalCommand } from "./canonicalCommands.js";
5
6
  import { paragraphPropertiesSnapshot } from "./commands/propertyChangeScope.js";
6
7
  import { listRenderingFor, recordsListRendering } from "./listRendering.js";
7
8
  import { LIST_RENDERING_ATTR_KEYS } from "./listRenderingAttrs.js";
@@ -11,6 +12,22 @@ import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
11
12
  import { SUGGESTION_META, makeRevisionInfo } from "./plugins/suggestionMode.js";
12
13
  import { listAttrsFromNumbering, listLevelIndentAttrPatch } from "./styles/resolvedStyleAttrs.js";
13
14
  //#region src/prosemirror/listNumbering.ts
15
+ /**
16
+ * Which numbering instance a list command puts a paragraph in, and the
17
+ * *Restart Numbering*, *Continue Numbering* and *Set Numbering Value* commands.
18
+ *
19
+ * A paragraph made into a list item continues the list directly above or below
20
+ * it when that list is of the requested kind (and, for a typed marker, has the
21
+ * typed format). Otherwise it starts a new list: a new `w:num`, defined on the
22
+ * paragraphs it numbers (see `docx/listNumberingInstances.ts`). A list that a
23
+ * paragraph style supplies (a heading's numbering from `styles.xml`) is never
24
+ * joined implicitly; it belongs to the style, not to the body text around it.
25
+ *
26
+ * Every change made while suggesting is recorded as one `w:pPrChange` per
27
+ * paragraph. A paragraph that already carries one keeps a single record whose
28
+ * previous state is the paragraph's original, so rejecting it restores what the
29
+ * paragraph was before any of the tracked changes.
30
+ */
14
31
  const PARAGRAPH_NODE = "paragraph";
15
32
  /**
16
33
  * The paragraph's properties as a `w:pPrChange` records them before a list
@@ -187,6 +204,7 @@ const listItemAttrs = (attrs, { numId, ilvl }, numbering) => ({
187
204
  ilvl
188
205
  }, numbering),
189
206
  listImplicitChildLevelAdvances: attrs["listImplicitChildLevelAdvances"] ?? null,
207
+ listFoldedMarkerSuffix: attrs["listFoldedMarkerSuffix"] ?? void 0,
190
208
  listMarkerSecondSlotOffsetTwips: attrs["listMarkerSecondSlotOffsetTwips"] ?? null
191
209
  });
192
210
  /**
@@ -260,7 +278,7 @@ const moveItems = ({ state, items, numId, numbering }) => {
260
278
  * its list move to a new instance of the same definition, whose
261
279
  * `w:startOverride` at the item's level is `value`.
262
280
  */
263
- const setNumberingValue = (value) => (state, dispatch) => {
281
+ const setNumberingValue = (value) => withCanonicalCommand((state, dispatch) => {
264
282
  if (!Number.isSafeInteger(value) || value < 0) return false;
265
283
  const selected = selectedListParagraph(state);
266
284
  const numbering = getDocumentNumbering(state);
@@ -279,9 +297,12 @@ const setNumberingValue = (value) => (state, dispatch) => {
279
297
  numbering: createNumberingMap(restarted.definitions)
280
298
  }));
281
299
  return true;
282
- };
300
+ }, () => [{
301
+ type: "restartNumbering",
302
+ start: value
303
+ }]);
283
304
  /** *Restart at 1*: the selected item starts its list over at one. */
284
- const restartNumbering = (state, dispatch) => setNumberingValue(1)(state, dispatch);
305
+ const restartNumbering = withCanonicalCommand((state, dispatch) => setNumberingValue(1)(state, dispatch), () => [{ type: "restartNumbering" }]);
285
306
  /** The nearest list before `beforePos` of the kind `membership` has, other than its own. */
286
307
  const previousListOfKind = (state, beforePos, membership) => {
287
308
  const numbering = getDocumentNumbering(state);
@@ -301,7 +322,7 @@ const previousListOfKind = (state, beforePos, membership) => {
301
322
  * join the nearest earlier list of the same kind, so their numbers carry on
302
323
  * from it. Not applicable when no such list precedes the item.
303
324
  */
304
- const continueNumbering = (state, dispatch) => {
325
+ const continueNumbering = withCanonicalCommand((state, dispatch) => {
305
326
  const selected = selectedListParagraph(state);
306
327
  const numbering = getDocumentNumbering(state);
307
328
  if (!selected || !numbering) return false;
@@ -315,7 +336,7 @@ const continueNumbering = (state, dispatch) => {
315
336
  numbering
316
337
  }));
317
338
  return true;
318
- };
339
+ }, () => [{ type: "continueNumbering" }]);
319
340
  const NO_LIST_NUMBERING_MENU = { type: "none" };
320
341
  /**
321
342
  * Whether the selection is in a list item whose numbering can be restarted
@@ -6,6 +6,7 @@ type ListRenderingAttrField = Exclude<keyof document_d_exports.ListRendering, "l
6
6
  declare const LIST_RENDERING_ATTR_BY_FIELD: {
7
7
  readonly marker: "listMarker";
8
8
  readonly markerTemplate: "listMarkerTemplate";
9
+ readonly foldedMarkerSuffix: "listFoldedMarkerSuffix";
9
10
  readonly isBullet: "listIsBullet";
10
11
  readonly isLegal: "listIsLegal";
11
12
  readonly numFmt: "listNumFmt";
@@ -12,6 +12,7 @@ import { paragraphNumberingLevel } from "@stll/docx-core/model";
12
12
  const LIST_RENDERING_ATTR_BY_FIELD = {
13
13
  marker: "listMarker",
14
14
  markerTemplate: "listMarkerTemplate",
15
+ foldedMarkerSuffix: "listFoldedMarkerSuffix",
15
16
  isBullet: "listIsBullet",
16
17
  isLegal: "listIsLegal",
17
18
  numFmt: "listNumFmt",
@@ -41,6 +42,7 @@ const listRenderingAttrPatch = (rendering) => {
41
42
  const patch = {
42
43
  listMarker: rendering.marker || void 0,
43
44
  listMarkerTemplate: rendering.markerTemplate || void 0,
45
+ listFoldedMarkerSuffix: rendering.foldedMarkerSuffix,
44
46
  listIsBullet: rendering.isBullet || void 0,
45
47
  listIsLegal: rendering.isLegal || void 0,
46
48
  listNumFmt: rendering.numFmt || void 0,
@@ -73,6 +75,7 @@ const hasListRendering = (attrs) => attrs.listMarker != null || attrs.listIsBull
73
75
  const listRenderingFromAttrs = ({ attrs, numId }) => {
74
76
  const optional = {
75
77
  markerTemplate: attrs.listMarkerTemplate ?? void 0,
78
+ foldedMarkerSuffix: attrs.listFoldedMarkerSuffix ?? void 0,
76
79
  isLegal: attrs.listIsLegal ?? void 0,
77
80
  numFmt: attrs.listNumFmt ?? void 0,
78
81
  markerHidden: attrs.listMarkerHidden ?? void 0,
@@ -10,10 +10,11 @@ const resolvedNote = (note, mode, state, document) => {
10
10
  const styleResolver = getDocumentStyleResolver(state);
11
11
  const cached = resolvedNotes.get(note)?.get(mode);
12
12
  if (cached?.styleResolver === styleResolver) return cached.note;
13
- const { styles, theme } = document.package;
13
+ const { styles, theme, numbering } = document.package;
14
14
  const doc = footnoteToProseDoc(note.content, {
15
15
  ...styles !== void 0 && { styles },
16
- ...theme !== void 0 && { theme }
16
+ ...theme !== void 0 && { theme },
17
+ ...numbering !== void 0 && { numbering }
17
18
  });
18
19
  const result = resolveWholeStory({
19
20
  doc,
@@ -1,5 +1,6 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { ReadProseMirrorAttrsResult } from "./attrs/index.js";
2
+ import { ReadProseMirrorAttrsResult } from "../internal/prosemirrorAttrBoundary.js";
3
+ import "./attrs/index.js";
3
4
  import { Node } from "prosemirror-model";
4
5
  //#region src/prosemirror/moveRangeBoundaryAttrs.d.ts
5
6
  type MoveRangeMarker = Extract<document_d_exports.ParagraphContent, {
@@ -64,7 +64,8 @@ const restoredNote = (note, document, reference) => {
64
64
  const { styles, theme, numbering } = document.package;
65
65
  const doc = footnoteToProseDoc(note.content, {
66
66
  ...styles !== void 0 && { styles },
67
- ...theme !== void 0 && { theme }
67
+ ...theme !== void 0 && { theme },
68
+ ...numbering !== void 0 && { numbering }
68
69
  });
69
70
  const revisions = noteDeletionRevisions(doc, reference);
70
71
  if (revisions.length === 0) return note;
@@ -164,10 +165,11 @@ const deleteNoteWithReference = (transform, reference) => {
164
165
  * deleted too, by the reference's author at the reference's date.
165
166
  */
166
167
  const deletedNote = (note, document, reference) => {
167
- const { styles, theme } = document.package;
168
+ const { styles, theme, numbering } = document.package;
168
169
  const doc = footnoteToProseDoc(note.content, {
169
170
  ...styles !== void 0 && { styles },
170
- ...theme !== void 0 && { theme }
171
+ ...theme !== void 0 && { theme },
172
+ ...numbering !== void 0 && { numbering }
171
173
  });
172
174
  const transform = deleteNoteWithReference(new Transform(doc), reference);
173
175
  if (!transform.docChanged) return note;
@@ -4,6 +4,7 @@ import { NumberingMap } from "../docx/numberingParser.js";
4
4
  import { Node } from "prosemirror-model";
5
5
  import { Transaction } from "prosemirror-state";
6
6
  //#region src/prosemirror/paragraphPropertyCarry.d.ts
7
+ type RecordedFormatting = NonNullable<ParagraphPropertyChangeAttrs["previousFormatting"]>;
7
8
  type CarryParagraphPropertiesOptions = {
8
9
  tr: Transaction;
9
10
  /** The paragraph that takes the properties. */
@@ -17,6 +18,11 @@ type CarryParagraphPropertiesOptions = {
17
18
  /** Properties the paragraph keeps its own values of: ones its own batch set. */
18
19
  keep?: ReadonlySet<string>;
19
20
  };
21
+ type CarriedParagraphPropertiesOptions = Pick<CarryParagraphPropertiesOptions, "source" | "keep"> & {
22
+ target: Node;
23
+ };
24
+ /** The exact formatting transfer, shared with pre-mutation capacity checks. */
25
+ declare const carriedParagraphProperties: ({ source, target, keep }: CarriedParagraphPropertiesOptions) => RecordedFormatting;
20
26
  /**
21
27
  * Give a paragraph another one's properties: the pPr a property change
22
28
  * covers. Its identity, mark, mark run properties and section stay its own,
@@ -61,4 +67,4 @@ declare const recordReplacedParagraphProperties: ({ tr, position, replaced, revi
61
67
  */
62
68
  declare const propertiesSetInBatch: (node: Node, batchRevisionIds: ReadonlySet<number>) => ReadonlySet<string>;
63
69
  //#endregion
64
- export { carryParagraphProperties, paragraphLeftAfter, propertiesSetInBatch, recordReplacedParagraphProperties };
70
+ export { carriedParagraphProperties, carryParagraphProperties, paragraphLeftAfter, propertiesSetInBatch, recordReplacedParagraphProperties };
@@ -17,6 +17,8 @@ import { panic } from "better-result";
17
17
  * revision, so accepting reads as the direct edit and rejecting restores the
18
18
  * second's own.
19
19
  */
20
+ /** The exact formatting transfer, shared with pre-mutation capacity checks. */
21
+ const carriedParagraphProperties = ({ source, target, keep }) => Object.fromEntries([...Object.entries(paragraphPropertiesSnapshot(source)).filter(([key]) => !keep?.has(key)), ...Object.entries(paragraphPropertiesSnapshot(target)).filter(([key]) => keep?.has(key))]);
20
22
  /**
21
23
  * Give a paragraph another one's properties: the pPr a property change
22
24
  * covers. Its identity, mark, mark run properties and section stay its own,
@@ -32,8 +34,11 @@ const carryParagraphProperties = ({ tr, position, source, styleResolver, numberi
32
34
  tracked: false
33
35
  };
34
36
  const previousFormatting = paragraphPropertiesSnapshot(target);
35
- const own = previousFormatting;
36
- const formatting = Object.fromEntries([...Object.entries(paragraphPropertiesSnapshot(source)).filter(([key]) => !keep?.has(key)), ...Object.entries(own).filter(([key]) => keep?.has(key))]);
37
+ const formatting = carriedParagraphProperties({
38
+ source,
39
+ target,
40
+ ...keep === void 0 ? {} : { keep }
41
+ });
37
42
  if (JSON.stringify(previousFormatting) === JSON.stringify(formatting)) return {
38
43
  tr,
39
44
  changed: false,
@@ -152,4 +157,4 @@ const propertiesSetInBatch = (node, batchRevisionIds) => {
152
157
  return new Set([.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(now)])].filter((key) => JSON.stringify(before[key]) !== JSON.stringify(now[key])));
153
158
  };
154
159
  //#endregion
155
- export { carryParagraphProperties, paragraphLeftAfter, propertiesSetInBatch, recordReplacedParagraphProperties };
160
+ export { carriedParagraphProperties, carryParagraphProperties, paragraphLeftAfter, propertiesSetInBatch, recordReplacedParagraphProperties };
@@ -527,7 +527,9 @@ function applySuggestionInsert(view, from, to, text, pluginState) {
527
527
  const tr = view.state.tr;
528
528
  tr.setMeta(SUGGESTION_META, true);
529
529
  tr.setMeta(SUGGESTED_TEXT_INPUT_META, text);
530
- const selectsAll = view.state.selection instanceof AllSelection;
530
+ const { selection } = view.state;
531
+ const typesOverSelection = !selection.empty && selection.from === from && selection.to === to;
532
+ const selectsAll = selection instanceof AllSelection;
531
533
  if (selectsAll) {
532
534
  from = Math.max(from, Selection.atStart(view.state.doc).from);
533
535
  to = Math.min(to, Selection.atEnd(view.state.doc).to);
@@ -548,7 +550,7 @@ function applySuggestionInsert(view, from, to, text, pluginState) {
548
550
  for (const mark of replacedFormatting) tr.addMark(insertAt, insertAt + text.length, mark);
549
551
  }
550
552
  separateSplitStretch(tr, insertAt, insertAt + text.length, insertAttrs.revisionId);
551
- if (view.state.selection instanceof AllSelection) tr.setSelection(TextSelection.create(tr.doc, insertAt + text.length));
553
+ if (typesOverSelection) tr.setSelection(TextSelection.create(tr.doc, insertAt + text.length));
552
554
  view.dispatch(tr.scrollIntoView());
553
555
  return true;
554
556
  }
@@ -659,21 +661,23 @@ function handleSuggestionEnter(view, pluginState) {
659
661
  view.dispatch(tr.scrollIntoView());
660
662
  return true;
661
663
  }
662
- /** Find the adjacent visible unit without consuming a bookmark range marker. */
664
+ /** Find the adjacent visible unit without consuming retained deletions or bookmark markers. */
663
665
  function caretDeleteTarget(state, direction) {
664
666
  const { $from } = state.selection;
665
667
  const backward = direction === "backward";
666
668
  let from = backward ? $from.pos - 1 : $from.pos;
667
669
  let to = backward ? $from.pos : $from.pos + 1;
668
670
  while (from >= $from.start() && to <= $from.end()) {
669
- const adjacent = state.doc.resolve(from).nodeAfter;
670
- if (adjacent?.type.name !== "bookmarkBoundary") return {
671
+ const $adjacent = state.doc.resolve(from);
672
+ const adjacent = $adjacent.nodeAfter;
673
+ if (!adjacent || adjacent.type.name !== "bookmarkBoundary" && !adjacent.marks.some((mark) => mark.type === state.schema.marks["deletion"])) return {
671
674
  type: "inlineUnit",
672
675
  from,
673
676
  to
674
677
  };
675
- from += backward ? -adjacent.nodeSize : adjacent.nodeSize;
676
- to += backward ? -adjacent.nodeSize : adjacent.nodeSize;
678
+ const skipped = backward && adjacent.isText ? $adjacent.textOffset + 1 : adjacent.nodeSize;
679
+ from += backward ? -skipped : skipped;
680
+ to += backward ? -skipped : skipped;
677
681
  }
678
682
  return { type: "paragraphEdge" };
679
683
  }
@@ -895,6 +899,38 @@ function recordSplitParagraph(tr, before, step, insertedFrom, insertedTo, attrs)
895
899
  });
896
900
  }
897
901
  /**
902
+ * The inline content a step removed from within one textblock, and where it
903
+ * started: the node a node selection held (an image, a field, a note
904
+ * reference) or a range of runs. Null for a step that removed nothing, or removed paragraph or table
905
+ * structure the catch-all cannot put back.
906
+ */
907
+ function replacedInline(before, step) {
908
+ if (!(step instanceof ReplaceStep) || !before || step.from === step.to) return null;
909
+ const $from = before.resolve(step.from);
910
+ if (!$from.parent.inlineContent || !$from.sameParent(before.resolve(step.to))) return null;
911
+ return {
912
+ from: step.from,
913
+ content: $from.parent.content.cut($from.parentOffset, step.to - $from.start())
914
+ };
915
+ }
916
+ /**
917
+ * A transaction the plugin did not build (a command, a default paste, a
918
+ * keymap) replaced inline content directly. Put it back in front of what
919
+ * replaced it as a tracked deletion, as typing over a selection does, so
920
+ * rejecting restores it and accepting removes it. The author's own
921
+ * insertions are retracted instead.
922
+ */
923
+ function restoreReplacedInline({ tr, replaced, insertionType, deletionType, pluginState }) {
924
+ for (const { at, content } of replaced) {
925
+ const pos = tr.mapping.map(at, -1);
926
+ const $pos = tr.doc.resolve(pos);
927
+ const index = $pos.index();
928
+ if (!$pos.parent.canReplace(index, index, content)) continue;
929
+ tr.insert(pos, content);
930
+ markRangeAsDeleted(tr, tr.doc, pos, pos + content.size, insertionType, deletionType, pluginState);
931
+ }
932
+ }
933
+ /**
898
934
  * Create the suggestion mode plugin.
899
935
  * When active, text edits become tracked changes.
900
936
  */
@@ -1039,9 +1075,16 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
1039
1075
  tr.setMeta(SUGGESTION_META, true);
1040
1076
  const deletionType = newState.schema.marks["deletion"];
1041
1077
  const laterMaps = transactions.slice(transactions.indexOf(userTr) + 1).flatMap((transaction) => transaction.mapping.maps);
1078
+ const restoresReplaced = userTr.getMeta("appendedTransaction") === void 0;
1079
+ const replaced = [];
1042
1080
  for (const [stepIndex, step] of userTr.steps.entries()) {
1043
1081
  const stepMap = step.getMap();
1044
1082
  const following = new Mapping([...userTr.mapping.maps.slice(stepIndex + 1), ...laterMaps]);
1083
+ const removed = restoresReplaced ? replacedInline(userTr.docs[stepIndex], step) : null;
1084
+ if (removed) replaced.push({
1085
+ at: following.map(removed.from, -1),
1086
+ content: removed.content
1087
+ });
1045
1088
  stepMap.forEach((_oldFrom, _oldTo, stepFrom, stepTo) => {
1046
1089
  const newFrom = following.map(stepFrom, -1);
1047
1090
  const newTo = following.map(stepTo, 1);
@@ -1057,6 +1100,13 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
1057
1100
  }
1058
1101
  });
1059
1102
  }
1103
+ if (deletionType) restoreReplacedInline({
1104
+ tr,
1105
+ replaced,
1106
+ insertionType,
1107
+ deletionType,
1108
+ pluginState
1109
+ });
1060
1110
  return tr.steps.length > 0 ? tr : null;
1061
1111
  }
1062
1112
  });
@@ -1,4 +1,5 @@
1
- import { ReadProseMirrorAttrsResult } from "./attrs/index.js";
1
+ import { ReadProseMirrorAttrsResult } from "../internal/prosemirrorAttrBoundary.js";
2
+ import "./attrs/index.js";
2
3
  import { RangeAnchorAttrs } from "./emptyRangeAnchor.js";
3
4
  import { Node } from "prosemirror-model";
4
5
  //#region src/prosemirror/rangeAnchorAttrs.d.ts
@@ -1,6 +1,7 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { RunStyleResolver } from "./runStyleFormatting.js";
3
3
  import { Mark } from "prosemirror-model";
4
+ import { RunPropsPatch } from "@stll/docx-core/ops";
4
5
  //#region src/prosemirror/runFormattingFromMarks.d.ts
5
6
  /**
6
7
  * Convert ProseMirror marks to TextFormatting
@@ -12,7 +13,9 @@ type MarksToTextFormattingOptions = {
12
13
  paragraphMarkPrecedesStyle?: boolean | undefined;
13
14
  styleResolver?: RunStyleResolver | null | undefined;
14
15
  };
16
+ /** Overlay only changed visual marks; private authored properties stay with the run. */
17
+ declare const runFormattingPatchFromMarks: (beforeMarks: readonly Mark[], afterMarks: readonly Mark[]) => RunPropsPatch;
15
18
  declare const sameFormattingValue: (left: unknown, right: unknown) => boolean;
16
19
  declare function marksToTextFormatting(marks: readonly Mark[], options?: MarksToTextFormattingOptions): document_d_exports.TextFormatting;
17
20
  //#endregion
18
- export { MarksToTextFormattingOptions, marksToTextFormatting, sameFormattingValue };
21
+ export { MarksToTextFormattingOptions, marksToTextFormatting, runFormattingPatchFromMarks, sameFormattingValue };