@stll/folio-core 0.67.0 → 0.68.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 (251) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +104 -34
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/note-references.d.ts +6 -0
  7. package/dist/ai-edits/note-references.js +7 -1
  8. package/dist/ai-edits/read.d.ts +19 -0
  9. package/dist/ai-edits/snapshot.d.ts +6 -0
  10. package/dist/ai-edits/snapshot.js +8 -3
  11. package/dist/ai-edits/types.d.ts +9 -1
  12. package/dist/ai-suggestions/apply.js +13 -4
  13. package/dist/compare/compare.js +2 -1
  14. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  15. package/dist/compare/inserted-resource-snapshot.js +7 -3
  16. package/dist/controller/canonicalClipboard.js +29 -12
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  19. package/dist/controller/canonicalInlineProjection.js +192 -28
  20. package/dist/controller/canonicalInput.d.ts +2 -1
  21. package/dist/controller/canonicalInput.js +28 -1
  22. package/dist/controller/canonicalListRendering.d.ts +2 -1
  23. package/dist/controller/canonicalListRendering.js +1 -1
  24. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  25. package/dist/controller/canonicalLockGuard.js +88 -0
  26. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  27. package/dist/controller/canonicalPublicOperations.js +274 -20
  28. package/dist/controller/canonicalSession.d.ts +87 -7
  29. package/dist/controller/canonicalSession.js +327 -73
  30. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  31. package/dist/controller/canonicalStoryEditor.js +4 -3
  32. package/dist/controller/canonicalStructure.d.ts +2 -1
  33. package/dist/controller/canonicalStructure.js +129 -7
  34. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  35. package/dist/controller/contentControlWidgetController.js +13 -1
  36. package/dist/controller/folioEditor.js +1 -0
  37. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  38. package/dist/controller/headerFooterEditorManager.js +5 -5
  39. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  40. package/dist/controller/hiddenEditorApi.js +1 -0
  41. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  42. package/dist/controller/hiddenEditorManager.js +91 -37
  43. package/dist/controller/layoutPipeline.js +48 -15
  44. package/dist/controller/noteEditorManager.d.ts +2 -2
  45. package/dist/controller/noteEditorManager.js +5 -5
  46. package/dist/display-list/build/pageFurniture.js +41 -19
  47. package/dist/display-list/build/tablePrimitives.js +23 -4
  48. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  49. package/dist/document-operations.d.ts +8 -0
  50. package/dist/document-operations.js +4 -3
  51. package/dist/docx/blockContentParser.d.ts +7 -3
  52. package/dist/docx/blockContentParser.js +2 -3
  53. package/dist/docx/blockPlainText.js +2 -0
  54. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  55. package/dist/docx/bookmarkRangeJoin.js +43 -0
  56. package/dist/docx/canonicalSave.js +5 -1
  57. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  58. package/dist/docx/canonicalSessionInput.js +7 -2
  59. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  60. package/dist/docx/commentAnchorIndex.js +39 -11
  61. package/dist/docx/commentRangeIntegrity.js +30 -24
  62. package/dist/docx/commentRangeJoin.d.ts +4 -0
  63. package/dist/docx/commentRangeJoin.js +26 -12
  64. package/dist/docx/commentReferenceCompletion.js +5 -4
  65. package/dist/docx/commentReferenceNormalization.js +40 -18
  66. package/dist/docx/compatibility.js +9 -2
  67. package/dist/docx/containerChildren.js +22 -1
  68. package/dist/docx/encryption/compoundFile.js +9 -1
  69. package/dist/docx/encryption/encryptionInfo.js +16 -2
  70. package/dist/docx/ensureParaIds.js +46 -7
  71. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  72. package/dist/docx/ensureUniqueControlIds.js +110 -0
  73. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  74. package/dist/docx/headerFooterVerbatim.js +13 -2
  75. package/dist/docx/hostCommentThreads.d.ts +17 -0
  76. package/dist/docx/hostCommentThreads.js +49 -0
  77. package/dist/docx/hyperlinkParser.js +9 -2
  78. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  79. package/dist/docx/inlineWrapperContent.js +9 -2
  80. package/dist/docx/listMarkerComputation.d.ts +35 -1
  81. package/dist/docx/listMarkerComputation.js +39 -1
  82. package/dist/docx/listModelNormalization.d.ts +44 -1
  83. package/dist/docx/listModelNormalization.js +227 -96
  84. package/dist/docx/markupRangeMarker.d.ts +14 -0
  85. package/dist/docx/markupRangeMarker.js +15 -1
  86. package/dist/docx/metadataPrivacy.js +43 -22
  87. package/dist/docx/normalizeBaseDirection.js +3 -1
  88. package/dist/docx/paragraphParser.js +159 -48
  89. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  90. package/dist/docx/paragraphPropertySource.js +22 -1
  91. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  92. package/dist/docx/paragraphTraversal.js +2 -0
  93. package/dist/docx/parseWarningMessage.js +2 -1
  94. package/dist/docx/parser.js +6 -0
  95. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  96. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  97. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  98. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  99. package/dist/docx/reviewResolutionProvenance.js +110 -25
  100. package/dist/docx/rezip.d.ts +6 -0
  101. package/dist/docx/rezip.js +38 -21
  102. package/dist/docx/selectiveSave.js +6 -10
  103. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  104. package/dist/docx/selectiveXmlPatch.js +11 -7
  105. package/dist/docx/serializer/documentSerializer.js +3 -1
  106. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  107. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  108. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  109. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  110. package/dist/docx/serializer/noteSerializer.js +23 -16
  111. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  112. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  113. package/dist/docx/serializer/runSerializer.js +2 -2
  114. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  115. package/dist/docx/serializer/tableSerializer.js +4 -2
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  117. package/dist/docx/server/createBilingualDocument.js +27 -5
  118. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  119. package/dist/docx/sessionListPruning.d.ts +2 -0
  120. package/dist/docx/sessionListPruning.js +50 -0
  121. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  122. package/dist/docx/splitRevisionPieces.js +14 -0
  123. package/dist/docx/storyBlockReplay.js +4 -0
  124. package/dist/docx/structuralXmlPatch.js +19 -7
  125. package/dist/docx/tableParser.d.ts +6 -2
  126. package/dist/docx/tableParser.js +2 -3
  127. package/dist/docx/textBoxContentParser.d.ts +11 -0
  128. package/dist/docx/textBoxContentParser.js +51 -0
  129. package/dist/docx/textBoxParser.d.ts +0 -5
  130. package/dist/docx/textBoxParser.js +1 -23
  131. package/dist/docx/verticalMergeProjection.js +1 -1
  132. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  133. package/dist/fonts/fontsourceFaces.js +1 -7
  134. package/dist/i18n/messages/ar.gen.js +2 -0
  135. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  136. package/dist/i18n/messages/catalogs.gen.js +34 -0
  137. package/dist/i18n/messages/cs.gen.js +2 -0
  138. package/dist/i18n/messages/de.gen.js +2 -0
  139. package/dist/i18n/messages/en.gen.js +2 -0
  140. package/dist/i18n/messages/es.gen.js +2 -0
  141. package/dist/i18n/messages/et.gen.js +2 -0
  142. package/dist/i18n/messages/fr.gen.js +2 -0
  143. package/dist/i18n/messages/he.gen.js +2 -0
  144. package/dist/i18n/messages/hi.gen.js +2 -0
  145. package/dist/i18n/messages/hu.gen.js +2 -0
  146. package/dist/i18n/messages/lt.gen.js +2 -0
  147. package/dist/i18n/messages/lv.gen.js +2 -0
  148. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  149. package/dist/i18n/messages/pl.gen.js +2 -0
  150. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  151. package/dist/i18n/messages/sk.gen.js +2 -0
  152. package/dist/i18n/messages/tr.gen.js +2 -0
  153. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  154. package/dist/internal/acceptedBlockProjection.js +2 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  156. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  157. package/dist/internal/revisionResolutionInline.js +1 -2
  158. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  159. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  160. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  161. package/dist/layout-bridge/engine/hitTest.js +9 -10
  162. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  163. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  164. package/dist/layout-engine/footnoteContinuation.js +210 -0
  165. package/dist/layout-engine/index.d.ts +2 -2
  166. package/dist/layout-engine/index.js +7 -2
  167. package/dist/layout-engine/measure/cache.js +10 -5
  168. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  169. package/dist/layout-engine/tableLayout.js +29 -5
  170. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  171. package/dist/layout-engine/tableRowBreak.js +43 -1
  172. package/dist/layout-engine/types.d.ts +36 -1
  173. package/dist/layout-painter/renderPage.d.ts +4 -4
  174. package/dist/layout-painter/renderPage.js +46 -17
  175. package/dist/layout-painter/renderTable.js +7 -4
  176. package/dist/managers/AutoSaveManager.d.ts +5 -1
  177. package/dist/managers/FindReplaceManager.js +3 -10
  178. package/dist/markdown/escape.d.ts +20 -1
  179. package/dist/markdown/escape.js +43 -1
  180. package/dist/markdown/renderBlock.js +4 -1
  181. package/dist/markdown/renderParagraph.js +13 -27
  182. package/dist/markdown/renderTable.js +6 -2
  183. package/dist/markdown/trailers.js +1 -0
  184. package/dist/pdf/images.d.ts +17 -1
  185. package/dist/pdf/images.js +22 -4
  186. package/dist/pdf/writePdf.js +4 -2
  187. package/dist/prosemirror/attrs/index.js +1 -0
  188. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  189. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  190. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  191. package/dist/prosemirror/commands/comments.d.ts +25 -0
  192. package/dist/prosemirror/commands/comments.js +102 -11
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +1 -1
  195. package/dist/prosemirror/commentIdAllocator.js +2 -2
  196. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  197. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  198. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  199. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  200. package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
  201. package/dist/prosemirror/conversion/index.d.ts +1 -1
  202. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  203. package/dist/prosemirror/conversion/toProseDoc.js +319 -51
  204. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  205. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  206. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  207. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  208. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  209. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  210. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  211. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  212. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  213. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  214. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  215. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  216. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  217. package/dist/prosemirror/index.d.ts +2 -2
  218. package/dist/prosemirror/listLabels.js +3 -2
  219. package/dist/prosemirror/listNumbering.d.ts +6 -0
  220. package/dist/prosemirror/listNumbering.js +12 -9
  221. package/dist/prosemirror/lockedControls.d.ts +13 -0
  222. package/dist/prosemirror/lockedControls.js +106 -0
  223. package/dist/prosemirror/markupViewProjection.js +1 -1
  224. package/dist/prosemirror/noteReferenceReview.js +2 -2
  225. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  226. package/dist/prosemirror/plugins/suggestionMode.js +20 -9
  227. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  228. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  229. package/dist/prosemirror/replacedAnnotations.js +1 -0
  230. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  231. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  232. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  233. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  234. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  235. package/dist/prosemirror/runStyleFormatting.js +16 -13
  236. package/dist/prosemirror/schema/marks.d.ts +6 -0
  237. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  238. package/dist/prosemirror/validation.js +1 -0
  239. package/dist/redline.js +23 -9
  240. package/dist/server.d.ts +2 -2
  241. package/dist/style-sets/extract.js +2 -2
  242. package/dist/types/canonicalCapabilities.d.ts +29 -8
  243. package/dist/types/canonicalCapabilities.js +13 -9
  244. package/dist/utils/cssString.d.ts +7 -0
  245. package/dist/utils/cssString.js +9 -0
  246. package/dist/utils/fontResolver.js +4 -1
  247. package/dist/utils/replaceText.d.ts +11 -0
  248. package/dist/utils/replaceText.js +39 -7
  249. package/dist/version-comparison.d.ts +9 -1
  250. package/dist/version-comparison.js +11 -5
  251. package/package.json +2 -2
@@ -12,9 +12,12 @@ const CommentExtension = createMarkExtension({
12
12
  schemaMarkName: "comment",
13
13
  markSpec: {
14
14
  excludes: "",
15
- attrs: {
16
- /** Comment ID (matches Comment.id) */
17
- commentId: { default: 0 } },
15
+ attrs: {
16
+ /** Comment ID (matches Comment.id) */
17
+ commentId: { default: 0 },
18
+ /** Shown at a point comment's reference; see `CommentAttrs.point`. */
19
+ point: { default: false }
20
+ },
18
21
  inclusive: false,
19
22
  parseDOM: [{
20
23
  tag: "span.docx-comment",
@@ -0,0 +1,4 @@
1
+ import { NodeExtension } from "../types.js";
2
+ /** The node name, for callers asking what a block container holds. */
3
+ export declare const BLOCK_COMMENT_RANGE_BOUNDARY_NODE_NAME = "blockCommentRangeBoundary";
4
+ export declare const BlockCommentRangeBoundaryExtension: () => NodeExtension;
@@ -0,0 +1,49 @@
1
+ import { expectCommentRangeBoundaryAttrs, readCommentRangeBoundaryMarker } from "../../commentRangeBoundaryAttrs.js";
2
+ import { createNodeExtension } from "../create.js";
3
+ // src/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.ts
4
+ /**
5
+ * A comment range boundary that stands between two blocks.
6
+ *
7
+ * The block-level twin of `commentRangeBoundary`, as `blockBookmarkBoundary`
8
+ * is of `bookmarkBoundary`: `CT_Body`, `CT_Tc` and `CT_SdtContentBlock`
9
+ * declare `w:commentRangeStart` and `w:commentRangeEnd` beside their blocks,
10
+ * and a range that opens beside a content control is written there. The node
11
+ * carries the same marker, read by the same reader, so the two levels cannot
12
+ * describe a comment range differently. The comment's mark still covers the
13
+ * text; the save keeps this node's marker as the range's own start or end.
14
+ */
15
+ /** The node name, for callers asking what a block container holds. */
16
+ const BLOCK_COMMENT_RANGE_BOUNDARY_NODE_NAME = "blockCommentRangeBoundary";
17
+ const BLOCK_COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE = "data-docx-block-comment-range-boundary";
18
+ const BlockCommentRangeBoundaryExtension = createNodeExtension({
19
+ name: BLOCK_COMMENT_RANGE_BOUNDARY_NODE_NAME,
20
+ schemaNodeName: BLOCK_COMMENT_RANGE_BOUNDARY_NODE_NAME,
21
+ nodeSpec: {
22
+ group: "block",
23
+ atom: true,
24
+ selectable: false,
25
+ attrs: { marker: {} },
26
+ parseDOM: [{
27
+ tag: `div[${BLOCK_COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE}]`,
28
+ getAttrs(dom) {
29
+ const raw = dom.getAttribute(BLOCK_COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE);
30
+ if (raw === null) return false;
31
+ try {
32
+ const marker = readCommentRangeBoundaryMarker(JSON.parse(raw));
33
+ return marker ? { marker } : false;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+ }],
39
+ toDOM(node) {
40
+ return ["div", {
41
+ [BLOCK_COMMENT_RANGE_BOUNDARY_DOM_ATTRIBUTE]: JSON.stringify(expectCommentRangeBoundaryAttrs(node).marker),
42
+ "aria-hidden": "true",
43
+ contenteditable: "false",
44
+ style: "display: none;"
45
+ }];
46
+ }
47
+ }
48
+ });
49
+ export { BLOCK_COMMENT_RANGE_BOUNDARY_NODE_NAME, BlockCommentRangeBoundaryExtension };
@@ -1,4 +1,5 @@
1
1
  import { imageLuminanceFilter } from "../../../utils/imageLuminance.js";
2
+ import { sanitizeImageSrc } from "../../../utils/sanitizeImageSrc.js";
2
3
  import { expectImageAttrs } from "../../attrs/index.js";
3
4
  import { pictureNamesDomAttrs, pictureNamesFromDom } from "../../imagePictureNames.js";
4
5
  import { createNodeExtension } from "../create.js";
@@ -6,6 +7,12 @@ import { createNodeExtension } from "../create.js";
6
7
  /**
7
8
  * Image Extension — inline/floating image node
8
9
  */
10
+ /**
11
+ * A source the DOM must not load (anything `sanitizeImageSrc` rejects, such
12
+ * as a linked `https:` image) is kept under this attribute instead of `src`,
13
+ * so the node still round-trips through the clipboard without a request.
14
+ */
15
+ const UNLOADED_SRC_ATTRIBUTE = "data-folio-src";
9
16
  const ImageExtension = createNodeExtension({
10
17
  name: "image",
11
18
  schemaNodeName: "image",
@@ -72,9 +79,10 @@ const ImageExtension = createNodeExtension({
72
79
  _docxRunFormatting: { default: null }
73
80
  },
74
81
  parseDOM: [{
75
- tag: "img[src]",
82
+ tag: `img[src], img[${UNLOADED_SRC_ATTRIBUTE}]`,
76
83
  getAttrs(dom) {
77
84
  const element = dom;
85
+ const src = element.getAttribute("src") || element.getAttribute(UNLOADED_SRC_ATTRIBUTE) || "";
78
86
  const pictureNames = pictureNamesFromDom(element);
79
87
  const alt = element.getAttribute("alt");
80
88
  const title = element.getAttribute("title");
@@ -87,7 +95,7 @@ const ImageExtension = createNodeExtension({
87
95
  const contrastRaw = element.dataset["contrast"];
88
96
  const contrast = contrastRaw === void 0 ? NaN : Number(contrastRaw);
89
97
  return {
90
- src: element.getAttribute("src") || "",
98
+ src,
91
99
  ...element.dataset["docPrName"] === void 0 ? {} : { docPrName: element.dataset["docPrName"] },
92
100
  ...Object.keys(pictureNames).length > 0 ? { pictureNames } : {},
93
101
  ...alt ? { alt } : {},
@@ -110,8 +118,9 @@ const ImageExtension = createNodeExtension({
110
118
  }],
111
119
  toDOM(node) {
112
120
  const attrs = expectImageAttrs(node);
121
+ const loadable = sanitizeImageSrc(attrs.src);
113
122
  const domAttrs = {
114
- src: attrs.src,
123
+ ...loadable === void 0 ? { [UNLOADED_SRC_ATTRIBUTE]: attrs.src } : { src: loadable },
115
124
  class: "docx-image",
116
125
  ...pictureNamesDomAttrs(attrs.pictureNames)
117
126
  };
@@ -6,6 +6,7 @@ import { isValidHexColor, resolveColor } from "../../../utils/colorResolver.js";
6
6
  import { resolveTablePlacementAlignment } from "../../../utils/tablePlacement.js";
7
7
  import { textFlowCss } from "../../../utils/textDirectionFlow.js";
8
8
  import { expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, mergeTableAttrs, mergeTableCellAttrs, mergeTableRowAttrs } from "../../attrs/index.js";
9
+ import { withCanonicalCellMerge, withCanonicalCellSplit, withCanonicalColumnDeletion, withCanonicalColumnInsertion, withCanonicalRowDeletion, withCanonicalRowInsertion, withCanonicalTableAttributeCommand, withCanonicalTableDeletion, withCanonicalTableInsertion } from "../../canonicalTableCommands.js";
9
10
  import { mintRevisionId } from "../../plugins/revisionIds.js";
10
11
  import { makeRevisionInfo } from "../../plugins/suggestionMode.js";
11
12
  import { pasteTableCells, pastedSliceWithNewTableCells } from "../../tableCellPaste.js";
@@ -398,7 +399,7 @@ const statedCellWidth = (value, type) => ({
398
399
  }
399
400
  });
400
401
  const tableCellSpec = {
401
- content: "(paragraph | table | textBox | blockSdt | blockCustomXml | preservedBlock | blockBookmarkBoundary | blockMoveRangeBoundary)+",
402
+ content: "(paragraph | table | textBox | blockSdt | blockCustomXml | preservedBlock | blockBookmarkBoundary | blockMoveRangeBoundary | blockCommentRangeBoundary)+",
402
403
  tableRole: "cell",
403
404
  isolating: true,
404
405
  attrs: {
@@ -468,7 +469,7 @@ const tableCellSpec = {
468
469
  }
469
470
  };
470
471
  const tableHeaderSpec = {
471
- content: "(paragraph | table | textBox | blockSdt | blockCustomXml | preservedBlock | blockBookmarkBoundary | blockMoveRangeBoundary)+",
472
+ content: "(paragraph | table | textBox | blockSdt | blockCustomXml | preservedBlock | blockBookmarkBoundary | blockMoveRangeBoundary | blockCommentRangeBoundary)+",
472
473
  tableRole: "header_cell",
473
474
  isolating: true,
474
475
  attrs: {
@@ -2004,39 +2005,39 @@ const TablePluginExtension = createExtension({
2004
2005
  Delete: chainCommands(deleteTableIfSelected(), preventTableMergeAtGap())
2005
2006
  },
2006
2007
  commands: {
2007
- insertTable: (rows, cols) => insertTable(rows, cols),
2008
- addRowAbove: () => addRowAbove,
2009
- addRowBelow: () => addRowBelow,
2010
- deleteRow: () => deleteRow,
2011
- addColumnLeft: () => addColumnLeft,
2012
- addColumnRight: () => addColumnRight,
2013
- deleteColumn: () => deleteColumn,
2014
- deleteTable: () => deleteTable,
2008
+ insertTable: (rows, cols) => withCanonicalTableInsertion(insertTable(rows, cols)),
2009
+ addRowAbove: () => withCanonicalRowInsertion(addRowAbove, "above"),
2010
+ addRowBelow: () => withCanonicalRowInsertion(addRowBelow, "below"),
2011
+ deleteRow: () => withCanonicalRowDeletion(deleteRow),
2012
+ addColumnLeft: () => withCanonicalColumnInsertion(addColumnLeft, "left"),
2013
+ addColumnRight: () => withCanonicalColumnInsertion(addColumnRight, "right"),
2014
+ deleteColumn: () => withCanonicalColumnDeletion(deleteColumn),
2015
+ deleteTable: () => withCanonicalTableDeletion(deleteTable),
2015
2016
  selectTable: () => selectTable,
2016
2017
  selectRow: () => selectRow,
2017
2018
  selectColumn: () => selectColumn,
2018
- mergeCells: () => preserveOmittedGridSlots(mergeCells),
2019
- splitCell: () => preserveOmittedGridSlots(preserveSourceCellIdentity(splitCell)),
2020
- setCellBorder: (side, spec, clearOthers) => setCellBorder(side, spec, clearOthers),
2021
- setTableBorders: (preset, borderSpec) => setTableBorders(preset, borderSpec),
2022
- setTableBorderPreset: (preset) => setTableBorderPreset(preset),
2023
- setCellVerticalAlign: (align) => setCellVerticalAlign(align),
2024
- setCellMargins: (margins) => setCellMargins(margins),
2025
- setCellTextDirection: (direction) => setCellTextDirection(direction),
2026
- toggleNoWrap: () => toggleNoWrap(),
2027
- setRowHeight: (height, rule) => setRowHeight(height, rule),
2028
- toggleHeaderRow: () => toggleHeaderRow(),
2029
- distributeColumns: () => distributeColumns(),
2019
+ mergeCells: () => withCanonicalCellMerge(preserveOmittedGridSlots(mergeCells)),
2020
+ splitCell: () => withCanonicalCellSplit(preserveOmittedGridSlots(preserveSourceCellIdentity(splitCell))),
2021
+ setCellBorder: (side, spec, clearOthers) => withCanonicalTableAttributeCommand(setCellBorder(side, spec, clearOthers)),
2022
+ setTableBorders: (preset, borderSpec) => withCanonicalTableAttributeCommand(setTableBorders(preset, borderSpec)),
2023
+ setTableBorderPreset: (preset) => withCanonicalTableAttributeCommand(setTableBorderPreset(preset)),
2024
+ setCellVerticalAlign: (align) => withCanonicalTableAttributeCommand(setCellVerticalAlign(align)),
2025
+ setCellMargins: (margins) => withCanonicalTableAttributeCommand(setCellMargins(margins)),
2026
+ setCellTextDirection: (direction) => withCanonicalTableAttributeCommand(setCellTextDirection(direction)),
2027
+ toggleNoWrap: () => withCanonicalTableAttributeCommand(toggleNoWrap()),
2028
+ setRowHeight: (height, rule) => withCanonicalTableAttributeCommand(setRowHeight(height, rule)),
2029
+ toggleHeaderRow: () => withCanonicalTableAttributeCommand(toggleHeaderRow()),
2030
+ distributeColumns: () => withCanonicalTableAttributeCommand(distributeColumns()),
2030
2031
  autoFitContents: () => autoFitContents(),
2031
- setTableProperties: (props) => setTableProperties(props),
2032
- applyTableStyle: (styleData) => applyTableStyle(styleData),
2033
- setCellFillColor: (color) => setCellFillColor(color),
2034
- setTableBorderColor: (color) => setTableBorderColor(color),
2035
- setTableBorderWidth: (size) => setTableBorderWidth(size),
2036
- removeTableBorders: () => setTableBorders("none"),
2037
- setAllTableBorders: (borderSpec) => setTableBorders("all", borderSpec),
2038
- setOutsideTableBorders: (borderSpec) => setTableBorders("outside", borderSpec),
2039
- setInsideTableBorders: (borderSpec) => setTableBorders("inside", borderSpec)
2032
+ setTableProperties: (props) => withCanonicalTableAttributeCommand(setTableProperties(props)),
2033
+ applyTableStyle: (styleData) => withCanonicalTableAttributeCommand(applyTableStyle(styleData)),
2034
+ setCellFillColor: (color) => withCanonicalTableAttributeCommand(setCellFillColor(color)),
2035
+ setTableBorderColor: (color) => withCanonicalTableAttributeCommand(setTableBorderColor(color)),
2036
+ setTableBorderWidth: (size) => withCanonicalTableAttributeCommand(setTableBorderWidth(size)),
2037
+ removeTableBorders: () => withCanonicalTableAttributeCommand(setTableBorders("none")),
2038
+ setAllTableBorders: (borderSpec) => withCanonicalTableAttributeCommand(setTableBorders("all", borderSpec)),
2039
+ setOutsideTableBorders: (borderSpec) => withCanonicalTableAttributeCommand(setTableBorders("outside", borderSpec)),
2040
+ setInsideTableBorders: (borderSpec) => withCanonicalTableAttributeCommand(setTableBorders("inside", borderSpec))
2040
2041
  }
2041
2042
  };
2042
2043
  }
@@ -71,7 +71,7 @@ const TextBoxExtension = createNodeExtension({
71
71
  schemaNodeName: "textBox",
72
72
  nodeSpec: {
73
73
  group: "block",
74
- content: "(paragraph | table)+",
74
+ content: "(paragraph | table | blockSdt | blockCustomXml | preservedBlock | blockBookmarkBoundary | blockMoveRangeBoundary | blockCommentRangeBoundary)+",
75
75
  isolating: true,
76
76
  draggable: true,
77
77
  attrs: {
@@ -1,13 +1,14 @@
1
1
  import { FontFamilyAttrs, FontSizeAttrs, HyperlinkAttrs, TextColorAttrs, UnderlineAttrs } from "./schema/marks.js";
2
2
  import { ImageAttrs, ParagraphAttrs } from "./schema/nodes.js";
3
3
  import { ResolvedParagraphStyle, StyleResolver, createStyleResolver } from "./styles/styleResolver.js";
4
+ import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
5
+ import { ToProseDocOptions, createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
4
6
  import { schema, singletonManager } from "./schema/index.js";
5
7
  import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
6
8
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
7
9
  import { TableBorderCommandSpec, TableCellBorderCommandSpec } from "./extensions/types.js";
8
10
  import { ListNumberingMenuState, NO_LIST_NUMBERING_MENU, listNumberingMenuState } from "./listNumbering.js";
9
11
  import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./commands/formatPainter.js";
10
- import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
11
12
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensions/marks/HyperlinkExtension.js";
12
13
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./commands/formatting.js";
13
14
  import { insertImageFromFile } from "./commands/image.js";
@@ -17,7 +18,6 @@ import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyl
17
18
  import { insertPageBreak } from "./commands/pageBreak.js";
18
19
  import "./commands/index.js";
19
20
  import { FromProseDocOptions, ProjectionReuse, fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.js";
20
- import { ToProseDocOptions, createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
21
21
  import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
22
22
  import "./conversion/index.js";
23
23
  import { ActiveListState, ListState, ListType, NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
@@ -134,11 +134,12 @@ const createListLabelCounter = (numberingOrStreams = null, suppliedStreams) => {
134
134
  numPrFromStyle: counterAttrs.numPrFromStyle
135
135
  });
136
136
  const countedNumbering = effectiveParagraphNumberingReference(countedSources);
137
- const revisionSelectedRendering = counterInput._propertyChanges?.length && counterAttrs !== counterInput && numbering === null ? listRenderingFromAttrs({
137
+ const revisionSelectedRendering = counterInput._propertyChanges?.length && counterAttrs !== counterInput && numbering === null && countedNumbering !== void 0 ? listRenderingFromAttrs({
138
138
  attrs: counterAttrs,
139
139
  numId: countedNumbering?.numId ?? 1
140
140
  }) : void 0;
141
- const countedList = resolveParagraphList(countedSources, numbering, revisionSelectedRendering ?? projectedRendering);
141
+ const revisionSelected = counterInput._propertyChanges?.length && counterAttrs !== counterInput && numbering === null;
142
+ const countedList = resolveParagraphList(countedSources, numbering, revisionSelected ? revisionSelectedRendering : revisionSelectedRendering ?? projectedRendering);
142
143
  switch (countedList.kind) {
143
144
  case "none": return {
144
145
  kind: "none",
@@ -29,6 +29,12 @@ type ResolveListTargetOptions = {
29
29
  /** Candidate requests, most likely first (see `listRequestsForMarker`). */
30
30
  requests: readonly ListRequest[];
31
31
  };
32
+ /**
33
+ * The instance the package already defines for `request` that no paragraph
34
+ * of the story refers to (`referenced`): a new list takes it before one is
35
+ * minted. One rule for both engines.
36
+ */
37
+ export declare const unusedListInstanceFor: (numbering: NumberingMap, referenced: ReadonlySet<number>, request: ListRequest) => number | undefined;
32
38
  /**
33
39
  * The list a paragraph range joins: the list directly above it, else the one
34
40
  * directly below it, when it matches one of `requests`; otherwise a new list:
@@ -149,14 +149,17 @@ const referencedNumIds = (doc) => {
149
149
  * naming a `w:pStyle`, or a style link) belongs to that style and is never
150
150
  * offered.
151
151
  */
152
- const unusedInstanceFor = (numbering, doc, request) => {
153
- const referenced = referencedNumIds(doc);
154
- return numbering.definitions.nums.find(({ numId, abstractNumId }) => {
155
- const abstract = numbering.getAbstract(abstractNumId);
156
- const level = numbering.getLevel(numId, 0);
157
- return !referenced.has(numId) && abstract !== null && abstract.styleLink === void 0 && abstract.numStyleLink === void 0 && abstract.levels.every(({ pStyle }) => pStyle === void 0) && level !== null && levelMatches(level, request) && (level.start ?? 1) === (request.start ?? level.start ?? 1);
158
- })?.numId;
159
- };
152
+ const unusedInstanceFor = (numbering, doc, request) => unusedListInstanceFor(numbering, referencedNumIds(doc), request);
153
+ /**
154
+ * The instance the package already defines for `request` that no paragraph
155
+ * of the story refers to (`referenced`): a new list takes it before one is
156
+ * minted. One rule for both engines.
157
+ */
158
+ const unusedListInstanceFor = (numbering, referenced, request) => numbering.definitions.nums.find(({ numId, abstractNumId }) => {
159
+ const abstract = numbering.getAbstract(abstractNumId);
160
+ const level = numbering.getLevel(numId, 0);
161
+ return !referenced.has(numId) && abstract !== null && abstract.styleLink === void 0 && abstract.numStyleLink === void 0 && abstract.levels.every(({ pStyle }) => pStyle === void 0) && level !== null && levelMatches(level, request) && (level.start ?? 1) === (request.start ?? level.start ?? 1);
162
+ })?.numId;
160
163
  /**
161
164
  * The list a paragraph range joins: the list directly above it, else the one
162
165
  * directly below it, when it matches one of `requests`; otherwise a new list:
@@ -348,4 +351,4 @@ const listNumberingMenuState = (state) => restartNumbering(state) ? {
348
351
  type: "listItem",
349
352
  canContinue: continueNumbering(state)
350
353
  } : NO_LIST_NUMBERING_MENU;
351
- export { NO_LIST_NUMBERING_MENU, applyParagraphUpdates, continueNumbering, listItemAttrs, listNumberingMenuState, resolveListTarget, restartNumbering, setNumberingValue };
354
+ export { NO_LIST_NUMBERING_MENU, applyParagraphUpdates, continueNumbering, listItemAttrs, listNumberingMenuState, resolveListTarget, restartNumbering, setNumberingValue, unusedListInstanceFor };
@@ -0,0 +1,13 @@
1
+ import { Node } from "prosemirror-model";
2
+ import { LockedControlSpan, LockedControlTouch, LockedControlViolation } from "@stll/docx-core/model";
3
+ import { Transform } from "prosemirror-transform";
4
+ export declare const lockedControlSpans: (doc: Node) => readonly LockedControlSpan[];
5
+ /** What the locks of `doc` say about `touches`: `null` when they permit them all. */
6
+ export declare const lockedControlViolationIn: (doc: Node, touches: readonly LockedControlTouch[]) => LockedControlViolation | null;
7
+ /**
8
+ * What the locks of `transform`'s starting document say about its result: a
9
+ * control whose content is locked must come through with the same content,
10
+ * and one locked against removal must come through at all. Read from the
11
+ * result rather than the steps, so it holds for any step a command takes.
12
+ */
13
+ export declare const lockedControlViolationOfTransform: (transform: Transform) => LockedControlViolation | null;
@@ -0,0 +1,106 @@
1
+ import { contentControlLockAllows, firstLockedControlViolation } from "@stll/docx-core/model";
2
+ // src/prosemirror/lockedControls.ts
3
+ /** The node types that carry a content control's `w:lock`. */
4
+ const CONTROL_NODE_NAMES = /* @__PURE__ */ new Set(["sdt", "blockSdt"]);
5
+ const lockOf = (node) => {
6
+ if (!CONTROL_NODE_NAMES.has(node.type.name)) return null;
7
+ const lock = node.attrs["lock"];
8
+ switch (lock) {
9
+ case "contentLocked":
10
+ case "sdtContentLocked":
11
+ case "sdtLocked": return lock;
12
+ default: return null;
13
+ }
14
+ };
15
+ /** Every control of `doc` whose lock forbids something, outermost first. */
16
+ const spansByDoc = /* @__PURE__ */ new WeakMap();
17
+ const lockedControlSpans = (doc) => {
18
+ const known = spansByDoc.get(doc);
19
+ if (known !== void 0) return known;
20
+ const spans = [];
21
+ doc.descendants((node, pos) => {
22
+ const lock = lockOf(node);
23
+ if (lock !== null) spans.push({
24
+ lock,
25
+ from: pos,
26
+ to: pos + node.nodeSize,
27
+ contentFrom: pos + 1,
28
+ contentTo: pos + node.nodeSize - 1
29
+ });
30
+ return true;
31
+ });
32
+ spansByDoc.set(doc, spans);
33
+ return spans;
34
+ };
35
+ /** What the locks of `doc` say about `touches`: `null` when they permit them all. */
36
+ const lockedControlViolationIn = (doc, touches) => touches.length === 0 ? null : firstLockedControlViolation(lockedControlSpans(doc), touches);
37
+ /** Marks that annotate content without being part of it. */
38
+ const ANNOTATION_MARKS = /* @__PURE__ */ new Set(["comment", "runIdentity"]);
39
+ /** Attributes that identify a node without being part of its content. */
40
+ const IDENTITY_ATTRS = /* @__PURE__ */ new Set(["paraId", "textId"]);
41
+ const sameAttrs = (left, right) => {
42
+ const keys = /* @__PURE__ */ new Set([...Object.keys(left.attrs), ...Object.keys(right.attrs)]);
43
+ for (const key of keys) {
44
+ if (IDENTITY_ATTRS.has(key)) continue;
45
+ if (JSON.stringify(left.attrs[key]) !== JSON.stringify(right.attrs[key])) return false;
46
+ }
47
+ return true;
48
+ };
49
+ const contentMarks = (node) => node.marks.filter((mark) => !ANNOTATION_MARKS.has(mark.type.name));
50
+ /** Whether two nodes hold the same content, annotations and identities aside. */
51
+ const sameLockedContent = (left, right) => {
52
+ if (left.type !== right.type) return false;
53
+ if (left.isText && left.text !== right.text) return false;
54
+ if (!sameAttrs(left, right)) return false;
55
+ const leftMarks = contentMarks(left);
56
+ const rightMarks = contentMarks(right);
57
+ if (leftMarks.length !== rightMarks.length || leftMarks.some((mark, index) => {
58
+ const other = rightMarks[index];
59
+ return other === void 0 || !mark.eq(other);
60
+ })) return false;
61
+ return sameLockedChildren(left, right);
62
+ };
63
+ /** Whether two nodes' children hold the same content (their own attributes aside). */
64
+ function sameLockedChildren(left, right) {
65
+ if (left.childCount !== right.childCount) return false;
66
+ for (let index = 0; index < left.childCount; index += 1) if (!sameLockedContent(left.child(index), right.child(index))) return false;
67
+ return true;
68
+ }
69
+ /**
70
+ * The node `span`'s control is in `transform`'s result, or `null` when it is
71
+ * gone. A step may rewrite the stretch around a control with a copy of it, so
72
+ * the control is looked for at either side of where its ends map to.
73
+ */
74
+ const survivorOf = (transform, span, before) => {
75
+ const { mapping, doc } = transform;
76
+ for (const startSide of [1, -1]) for (const endSide of [-1, 1]) {
77
+ const start = mapping.map(span.from, startSide);
78
+ const end = mapping.map(span.to, endSide);
79
+ const after = doc.nodeAt(start);
80
+ if (after?.type === before.type && start + after.nodeSize === end) return after;
81
+ }
82
+ return null;
83
+ };
84
+ /**
85
+ * What the locks of `transform`'s starting document say about its result: a
86
+ * control whose content is locked must come through with the same content,
87
+ * and one locked against removal must come through at all. Read from the
88
+ * result rather than the steps, so it holds for any step a command takes.
89
+ */
90
+ const lockedControlViolationOfTransform = (transform) => {
91
+ if (!transform.docChanged) return null;
92
+ for (const span of lockedControlSpans(transform.before)) {
93
+ const before = transform.before.nodeAt(span.from);
94
+ if (before === null) continue;
95
+ const after = survivorOf(transform, span, before);
96
+ let change = null;
97
+ if (after === null) change = "removeControl";
98
+ else if (!sameLockedChildren(before, after)) change = "editContent";
99
+ if (change !== null && !contentControlLockAllows(span.lock, change)) return {
100
+ lock: span.lock,
101
+ change
102
+ };
103
+ }
104
+ return null;
105
+ };
106
+ export { lockedControlSpans, lockedControlViolationIn, lockedControlViolationOfTransform };
@@ -93,7 +93,7 @@ const projectStoryMarkupView = ({ doc, markupView, styles, numbering }) => {
93
93
  if (cached && cached.styles === styles && cached.numbering === numbering) return projectMarkupView(cached.state, markupView);
94
94
  const state = EditorState.create({
95
95
  doc,
96
- plugins: [createDocumentStyleContextPlugin(styles), createDocumentNumberingPlugin(numbering)]
96
+ plugins: [createDocumentNumberingPlugin(numbering), createDocumentStyleContextPlugin(styles)]
97
97
  });
98
98
  storyProjectionStates.set(doc, {
99
99
  styles,
@@ -75,9 +75,9 @@ const restoredNote = (note, document, reference) => {
75
75
  schema,
76
76
  doc,
77
77
  plugins: [
78
+ createDocumentNumberingPlugin(numbering),
78
79
  ...pluginsForHeadlessRevisionResolution(singletonManager.getPlugins()),
79
- createDocumentStylesPlugin(styles),
80
- createDocumentNumberingPlugin(numbering)
80
+ createDocumentStylesPlugin(styles)
81
81
  ]
82
82
  });
83
83
  rejectAIEditRevision(revisions)(state, (transaction) => {
@@ -1,9 +1,11 @@
1
1
  import { getCachedNumberingMap } from "../../docx/numberingParser.js";
2
2
  import { completeNumberingForDoc, paragraphListReferences } from "../listInstanceReferences.js";
3
3
  import { createPluginKeyOwner } from "../pluginKeyOwner.js";
4
+ import { panic } from "better-result";
4
5
  import { AddMarkStep, DocAttrStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
5
6
  import { Plugin } from "prosemirror-state";
6
7
  // src/prosemirror/plugins/documentNumbering.ts
8
+ /** Document-scoped numbering definitions for list-editing commands. */
7
9
  const documentNumberingKey = createPluginKeyOwner("documentNumbering");
8
10
  const completedState = (definitions, doc) => {
9
11
  const completed = completeNumberingForDoc(definitions ?? void 0, doc);
@@ -73,6 +75,7 @@ const getDocumentNumberingForDoc = (doc) => {
73
75
  const getDocumentNumbering = (state) => {
74
76
  const tracked = documentNumberingKey.getState(state);
75
77
  if (tracked) return tracked.map;
78
+ if (documentNumberingKey.get(state) !== void 0) panic("Document numbering was read before its plugin applied: place the numbering plugin before the plugins that read it.");
76
79
  return getDocumentNumberingForDoc(state.doc);
77
80
  };
78
81
  /** The package's own definitions, without the instances the document defines. */
@@ -106,6 +109,6 @@ const getDocumentNumberingInstanceIds = (state) => {
106
109
  const withDocumentNumbering = (state, definitions) => {
107
110
  const previous = documentNumberingKey.get(state);
108
111
  const retained = state.plugins.filter((plugin) => plugin !== previous);
109
- return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [...retained, createDocumentNumberingPlugin(definitions)] });
112
+ return state.reconfigure({ plugins: retained }).reconfigure({ plugins: [createDocumentNumberingPlugin(definitions), ...retained] });
110
113
  };
111
114
  export { createDocumentNumberingPlugin, getDocumentNumbering, getDocumentNumberingForDoc, getDocumentNumberingInstanceIds, getPackageNumberingDefinitions, getStatedDocumentNumbering, hasDocumentNumbering, withDocumentNumbering };
@@ -266,8 +266,9 @@ function handleSuggestionPaste(view, slice, pluginState) {
266
266
  suffix.forEach((node) => {
267
267
  if (!node.marks.some((mark) => mark.type === deletionType)) deletedSuffix = false;
268
268
  });
269
+ const rotates = deletedSuffix && ($from.parent.attrs["pPrMark"]?.kind ?? "del") === "del" && paragraphEndsItsContainer($from.doc.resolve($from.before()), "paragraph") && slice.content.firstChild?.type === $from.parent.type && slice.content.lastChild?.type === $from.parent.type;
269
270
  const tr = view.state.tr.setMeta(SUGGESTION_META, true).setMeta("paste", true);
270
- const at = $from.before();
271
+ const at = rotates ? $from.after() : $from.before();
271
272
  tr.replaceRange(at, at, slice);
272
273
  const revision = makeMarkAttrs(pluginState);
273
274
  const end = tr.mapping.map(at, 1);
@@ -290,6 +291,13 @@ function handleSuggestionPaste(view, slice, pluginState) {
290
291
  return false;
291
292
  });
292
293
  markRangeAsInserted(tr, tr.doc, at, end, insertionType, deletionType, revision);
294
+ if (rotates) {
295
+ const rotation = tr.steps.length;
296
+ rotateIntoFinalParagraph(view.state, tr, $from.before(), revision);
297
+ tr.setSelection(TextSelection.near(tr.doc.resolve(tr.mapping.slice(rotation).map(end, -1)), -1));
298
+ view.dispatch(tr.scrollIntoView());
299
+ return true;
300
+ }
293
301
  if (deletedSuffix && $from.parent.attrs["pPrMark"] == null && !paragraphEndsItsContainer($from.doc.resolve($from.before()), "paragraph")) tr.setNodeAttribute(tr.mapping.map($from.before()), "pPrMark", {
294
302
  kind: "del",
295
303
  info: makeParagraphMarkInfo(pluginState)
@@ -362,9 +370,9 @@ function handleSuggestionPaste(view, slice, pluginState) {
362
370
  });
363
371
  markRangeAsInserted(tr, tr.doc, insertFrom, insertTo, insertionType, deletionType, insertAttrs);
364
372
  if (!inlineSlice) carryAcross();
365
- if (!closedBlocks && $to.parent.type.name === "paragraph") {
366
- const $end = tr.doc.resolve(tr.mapping.map(to));
367
- if ($end.parent.type.name === "paragraph" && $end.before() !== tr.mapping.map($from.before())) recordReplacedParagraphProperties({
373
+ if ($to.parent.type.name === "paragraph") {
374
+ const $end = tr.doc.resolve(closedBlocks ? Math.max(insertFrom, insertTo - 1) : tr.mapping.map(to));
375
+ if ($end.parent.type.name === "paragraph" && $end.before() !== tr.mapping.map($from.before()) && expectParagraphAttrs($end.parent).pPrMark?.kind !== "ins") recordReplacedParagraphProperties({
368
376
  tr,
369
377
  position: $end.before(),
370
378
  replaced: $to.parent,
@@ -833,7 +841,7 @@ function isCurrentAuthorParagraphInsertion(value, author) {
833
841
  /**
834
842
  * Handle delete (forward or backward) in suggestion mode.
835
843
  */
836
- function handleSuggestionDelete(state, dispatch, direction) {
844
+ function handleSuggestionDelete(state, dispatch, direction, { cut = false } = {}) {
837
845
  const pluginState = suggestionModeKey.getState(state);
838
846
  if (!pluginState?.active) return false;
839
847
  const { $from, $to, empty } = state.selection;
@@ -849,8 +857,11 @@ function handleSuggestionDelete(state, dispatch, direction) {
849
857
  to: rangeTo.pos
850
858
  }).sort((a, b) => b.from - a.from);
851
859
  for (const { from, to } of ranges) markRangeAsDeleted(tr, state.doc, from, to, deletionType, pluginState, state);
852
- if (state.selection instanceof CellSelection) tr.setSelection(state.selection.map(tr.doc, tr.mapping));
853
- else {
860
+ if (state.selection instanceof CellSelection && !cut) tr.setSelection(state.selection.map(tr.doc, tr.mapping));
861
+ else if (state.selection instanceof CellSelection) {
862
+ const caret = Selection.findFrom(tr.doc.resolve(tr.mapping.map(state.selection.to)), -1);
863
+ if (caret) tr.setSelection(caret);
864
+ } else {
854
865
  const cursorPos = tr.mapping.map($to.pos);
855
866
  tr.setSelection(TextSelection.near(tr.doc.resolve(cursorPos)));
856
867
  }
@@ -894,7 +905,7 @@ function handleSuggestionDelete(state, dispatch, direction) {
894
905
  return true;
895
906
  }
896
907
  /** Apply the editor's selected-content deletion path for a host cut action. */
897
- const deleteSelectionAsSuggestion = (state, dispatch) => state.selection.empty ? false : handleSuggestionDelete(state, dispatch, "forward");
908
+ const deleteSelectionAsSuggestion = (state, dispatch) => state.selection.empty ? false : handleSuggestionDelete(state, dispatch, "forward", { cut: true });
898
909
  /**
899
910
  * PM reads the removal of cancelled text back from the DOM, which can take the
900
911
  * text around it along and drop its revision marks. The same text was there when
@@ -1123,7 +1134,7 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
1123
1134
  data.setData("text/html", dom.innerHTML);
1124
1135
  data.setData("text/plain", text);
1125
1136
  event.preventDefault();
1126
- return handleSuggestionDelete(view.state, view.dispatch, "forward");
1137
+ return handleSuggestionDelete(view.state, view.dispatch, "forward", { cut: true });
1127
1138
  },
1128
1139
  compositionstart(view) {
1129
1140
  if (!suggestionModeKey.getState(view.state)?.active) return false;
@@ -78,6 +78,21 @@ const FIELD_PATH_HEAD_RE = /^[\p{L}_]/u;
78
78
  * keeps a real expression on exact matching.
79
79
  */
80
80
  const filterChainPath = ({ conditionPath }) => conditionPath !== void 0 && isFieldPath(conditionPath) && FIELD_PATH_HEAD_RE.test(conditionPath) ? conditionPath : void 0;
81
+ const isPreviewSpan = (span) => typeof span === "object" && span !== null && typeof Reflect.get(span, "text") === "string";
82
+ /**
83
+ * The value stored under one key, read like {@link ownVerdict}: only a key the
84
+ * host set itself, holding text or a list of text spans, counts. A marker named
85
+ * after an inherited property (`constructor`) or holding a malformed value
86
+ * keeps its authored text.
87
+ */
88
+ const ownPreviewValue = (values, key) => {
89
+ if (!Object.hasOwn(values, key)) return;
90
+ const value = values[key];
91
+ if (typeof value === "string") return value;
92
+ if (typeof value !== "object" || value === null) return;
93
+ const runs = Reflect.get(value, "runs");
94
+ return Array.isArray(runs) && runs.every(isPreviewSpan) ? { runs } : void 0;
95
+ };
81
96
  /**
82
97
  * The verdict stored under one key. Only a key the host set itself, holding a
83
98
  * real boolean, counts: an inherited property (`constructor`, or a boolean the
@@ -189,7 +204,7 @@ function collectPreviewEntries(ranges, values, hidden) {
189
204
  const entries = [];
190
205
  for (const range of ranges) {
191
206
  if (range.kind !== "placeholder" && range.kind !== "clause") continue;
192
- const value = values[range.expr];
207
+ const value = ownPreviewValue(values, range.expr);
193
208
  if (value === void 0 || templatePreviewValueText(value) === "") continue;
194
209
  if (hidden.some((block) => range.from >= block.from && range.from < block.to)) continue;
195
210
  entries.push({
@@ -6,7 +6,7 @@ import { paragraphRunStyleContext } from "./runStyleFormatting.js";
6
6
  import { Mark } from "prosemirror-model";
7
7
  // src/prosemirror/rebaseParagraphRuns.ts
8
8
  /** Two contexts that lend runs the same formatting: rebasing between them changes nothing. */
9
- const sameRunStyleContext = (source, target) => source.paragraphMarkPrecedesStyle === target.paragraphMarkPrecedesStyle && formattingEquals(source.baseParagraphFormatting, target.baseParagraphFormatting) && formattingEquals(source.paragraphFormatting, target.paragraphFormatting) && formattingEquals(source.paragraphMarkFormatting, target.paragraphMarkFormatting);
9
+ const sameRunStyleContext = (source, target) => formattingEquals(source.baseParagraphFormatting, target.baseParagraphFormatting) && formattingEquals(source.paragraphFormatting, target.paragraphFormatting) && formattingEquals(source.paragraphMarkFormatting, target.paragraphMarkFormatting);
10
10
  /** Rebuild rendered marks after the paragraph's style cascade changes. */
11
11
  const rebaseParagraphRuns = ({ tr, position, previous, target, styleResolver, range, storedMarks: initialStoredMarks }) => {
12
12
  const paragraph = tr.doc.nodeAt(position);
@@ -147,6 +147,7 @@ const createResolvedCommentPointCollector = ({ removes, retiresStructure }) => {
147
147
  const removedWithStructure = removedStructures.some(({ from, to }) => position > from && position < to);
148
148
  for (const mark of node.marks) {
149
149
  if (mark.type.name !== "comment") continue;
150
+ if (mark.attrs["point"] === true) continue;
150
151
  const id = mark.attrs["commentId"];
151
152
  if (!removedWithStructure && !removes(node, position)) retained.add(id);
152
153
  else if (!points.has(id)) points.set(id, position);
@@ -9,7 +9,6 @@ export type MarksToTextFormattingOptions = {
9
9
  baseParagraphFormatting?: document_d_exports.TextFormatting | undefined;
10
10
  inheritedFormatting?: document_d_exports.TextFormatting | undefined;
11
11
  paragraphMarkFormatting?: document_d_exports.TextFormatting | undefined;
12
- paragraphMarkPrecedesStyle?: boolean | undefined;
13
12
  styleResolver?: RunStyleResolver | null | undefined;
14
13
  };
15
14
  /** Overlay only changed visual marks; private authored properties stay with the run. */