@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
@@ -4,12 +4,13 @@ import { bookmarkMarkerFromAttrs, readBookmarkBoundaryAttrs } from "../prosemirr
4
4
  import { readCommentRangeBoundaryAttrs } from "../prosemirror/commentRangeBoundaryAttrs.js";
5
5
  import { HYPHEN_TEXT_CARRIERS } from "../prosemirror/conversion/hyphenTextCarriers.js";
6
6
  import "../prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js";
7
+ import "../prosemirror/extensions/nodes/RenderedPageBreakExtension.js";
7
8
  import { readMoveRangeBoundaryAttrs } from "../prosemirror/moveRangeBoundaryAttrs.js";
8
9
  import { readRangeAnchorAttrs } from "../prosemirror/rangeAnchorAttrs.js";
9
10
  import { PRESERVED_XML_LEVELS } from "../prosemirror/schema/nodes.js";
10
11
  import { Result, TaggedError, panic } from "better-result";
11
12
  import { hasIllegalXmlCharacters } from "@stll/docx-core";
12
- import { inlineLeafSpans, paragraphLogicalText } from "@stll/docx-core/ops";
13
+ import { defaultInsertionGap, inlineLeafSpans, paragraphLogicalText } from "@stll/docx-core/ops";
13
14
  // src/controller/canonicalInlineProjection.ts
14
15
  const CANONICAL_SOURCE_INLINE_POLICIES = {
15
16
  run: "container",
@@ -19,7 +20,7 @@ const CANONICAL_SOURCE_INLINE_POLICIES = {
19
20
  moveFrom: "container",
20
21
  moveTo: "container",
21
22
  inlineWrapper: "container",
22
- inlineSdt: "control",
23
+ inlineSdt: "container",
23
24
  simpleField: "leaf",
24
25
  complexField: "leaf",
25
26
  mathEquation: "leaf",
@@ -44,7 +45,7 @@ const CANONICAL_SOURCE_INLINE_POLICIES = {
44
45
  instrText: "rawField",
45
46
  softHyphen: "leaf",
46
47
  noBreakHyphen: "leaf",
47
- renderedPageBreak: "layout",
48
+ renderedPageBreak: "leaf",
48
49
  preservedXml: "leaf",
49
50
  drawing: "leaf",
50
51
  shape: "leaf"
@@ -68,8 +69,8 @@ const CANONICAL_NATIVE_INLINE_POLICIES = {
68
69
  tab: "unit",
69
70
  textBoxAnchor: "unit",
70
71
  commentReference: "unit",
71
- renderedPageBreak: "refused",
72
- sdt: "refused"
72
+ renderedPageBreak: "markers",
73
+ sdt: "control"
73
74
  };
74
75
  const nativePolicies = new Map(Object.entries(CANONICAL_NATIVE_INLINE_POLICIES));
75
76
  const InlineProjectionErrorBase = TaggedError("InlineProjectionError");
@@ -78,22 +79,13 @@ const refuse = (message) => Result.err(new InlineProjectionError({ message }));
78
79
  /** Every source variant makes a decision before conversion can discard its positions. */
79
80
  const canonicalInlineSourceIssue = (items, context = "paragraph") => {
80
81
  for (const item of items) switch (CANONICAL_SOURCE_INLINE_POLICIES[item.type]) {
81
- case "control":
82
- if (context === "fieldPayload" && item.type === "inlineSdt") {
83
- const issue = canonicalInlineSourceIssue(item.content, context);
84
- if (issue !== null) return issue;
85
- break;
86
- }
87
- return "Canonical editing cannot preserve inline content-control boundary positions.";
88
82
  case "rawField":
89
83
  if (context === "fieldPayload") break;
90
84
  return "Canonical editing cannot preserve unstructured field instructions; a structured field is required.";
91
- case "layout": return "Canonical editing cannot preserve cached rendered page-break positions.";
92
85
  case "text":
93
86
  if (item.type === "text" && (hasIllegalXmlCharacters(item.text) || /[\t\r\n]/u.test(item.text))) return "Canonical text requires valid XML characters and explicit tab or break elements.";
94
87
  break;
95
88
  case "container": {
96
- if ((item.type === "insertion" || item.type === "deletion") && item.resolutionJoins !== void 0 && item.content.some((child) => child.type === "hyperlink")) return "Canonical editing cannot preserve hyperlink wrapper review provenance.";
97
89
  const children = sourceContainerChildren(item);
98
90
  const issue = canonicalInlineSourceIssue(children, context);
99
91
  if (issue !== null) return issue;
@@ -118,7 +110,8 @@ const sourceContainerChildren = (item) => {
118
110
  case "deletion":
119
111
  case "moveFrom":
120
112
  case "moveTo":
121
- case "inlineWrapper": return item.content;
113
+ case "inlineWrapper":
114
+ case "inlineSdt": return item.content;
122
115
  default: return panic(`Source policy incorrectly classified ${item.type} as a container.`);
123
116
  }
124
117
  };
@@ -126,7 +119,7 @@ const sourceContainerChildren = (item) => {
126
119
  const canonicalNativeCells = (paragraph) => {
127
120
  const cells = [];
128
121
  let issue;
129
- paragraph.forEach((node, from) => {
122
+ const visit = (node, from) => {
130
123
  if (issue !== void 0) return;
131
124
  const to = from + node.nodeSize;
132
125
  switch (nativePolicies.get(node.type.name)) {
@@ -185,7 +178,14 @@ const canonicalNativeCells = (paragraph) => {
185
178
  to,
186
179
  node
187
180
  });
188
- } else if (node.type.name === "moveRangeBoundary") {
181
+ } else if (node.type.name === "renderedPageBreak") cells.push({
182
+ type: "zeroWidth",
183
+ sources: [{ type: "renderedPageBreak" }],
184
+ from,
185
+ to,
186
+ node
187
+ });
188
+ else if (node.type.name === "moveRangeBoundary") {
189
189
  const attrs = readMoveRangeBoundaryAttrs(node);
190
190
  if (!attrs.ok) {
191
191
  issue = "Canonical editing requires valid move-range boundary attributes.";
@@ -269,6 +269,23 @@ const canonicalNativeCells = (paragraph) => {
269
269
  });
270
270
  return;
271
271
  }
272
+ case "control":
273
+ cells.push({
274
+ type: "zeroWidth",
275
+ sources: [],
276
+ from,
277
+ to: from + 1,
278
+ node
279
+ });
280
+ node.forEach((child, offset) => visit(child, from + 1 + offset));
281
+ cells.push({
282
+ type: "zeroWidth",
283
+ sources: [],
284
+ from: to - 1,
285
+ to,
286
+ node
287
+ });
288
+ return;
272
289
  case "refused":
273
290
  issue = `Canonical editing cannot preserve ${node.type.name} boundary positions.`;
274
291
  return;
@@ -276,7 +293,8 @@ const canonicalNativeCells = (paragraph) => {
276
293
  issue = `Canonical editing has no position mapping for inline ${node.type.name}.`;
277
294
  return;
278
295
  }
279
- });
296
+ };
297
+ paragraph.forEach((node, from) => visit(node, from));
280
298
  return issue === void 0 ? Result.ok(cells) : refuse(issue);
281
299
  };
282
300
  const sameSourceMarker = (left, right) => {
@@ -290,19 +308,34 @@ const sameSourceMarker = (left, right) => {
290
308
  case "moveToRangeStart":
291
309
  case "moveToRangeEnd": return right.type === left.type && left.id === right.id;
292
310
  case "noteMarker": return right.type === "noteMarker" && left.kind === right.kind;
311
+ case "renderedPageBreak": return right.type === "renderedPageBreak";
293
312
  case "preservedInline": return right.type === "preservedInline" && left.xml === right.xml && left.text === right.text;
294
313
  default: return false;
295
314
  }
296
315
  };
316
+ /**
317
+ * What each input of a paragraph's projection depends on: the paragraph
318
+ * alone (its source records and its editor node), or the story around it.
319
+ * A cached projection is reused only for the same paragraph inputs, and only
320
+ * where every story fact it read still holds. Total over the inputs: an input
321
+ * added to them does not compile until it is placed in one half or the other.
322
+ */
323
+ const INLINE_INPUT_DEPENDENCY = {
324
+ source: "paragraph",
325
+ paragraph: "paragraph",
326
+ pairedBookmarkIds: "story",
327
+ commentContext: "story"
328
+ };
329
+ const PARAGRAPH_INPUT_FIELDS = Object.keys(INLINE_INPUT_DEPENDENCY).filter((field) => INLINE_INPUT_DEPENDENCY[field] === "paragraph");
297
330
  /** Marks carry nonempty ranges; explicit range anchors carry empty ranges. */
298
331
  const commentMarkTransitions = ({ source, paragraph, commentContext, explicitCommentIds }) => {
299
332
  const spans = inlineLeafSpans(source.content);
300
- const rangedIds = new Set(commentContext?.rangedIds);
301
- const pointIds = new Set(commentContext?.pointIds);
333
+ const ownRangedIds = /* @__PURE__ */ new Set();
334
+ const ownPointIds = /* @__PURE__ */ new Set();
302
335
  const finalIds = new Set(commentContext?.openIds);
303
336
  for (const { node } of spans) {
304
- if (node.type === "commentRangeStart" || node.type === "commentRangeEnd") rangedIds.add(node.id);
305
- if (node.type === "commentReference") pointIds.add(node.id);
337
+ if (node.type === "commentRangeStart" || node.type === "commentRangeEnd") ownRangedIds.add(node.id);
338
+ if (node.type === "commentReference") ownPointIds.add(node.id);
306
339
  if (node.type === "commentRangeStart") finalIds.add(node.id);
307
340
  if (node.type === "commentRangeEnd") finalIds.delete(node.id);
308
341
  }
@@ -329,9 +362,9 @@ const commentMarkTransitions = ({ source, paragraph, commentContext, explicitCom
329
362
  return;
330
363
  }
331
364
  const id = attrs.value.commentId;
332
- if (rangedIds.has(id)) {
365
+ if (ownRangedIds.has(id) || (commentContext?.rangedIds.has(id) ?? false)) {
333
366
  if (!explicitCommentIds.has(id)) current.add(id);
334
- } else if (!pointIds.has(id)) {
367
+ } else if (!ownPointIds.has(id) && !(commentContext?.pointIds.has(id) ?? false)) {
335
368
  issue = "Canonical editing cannot attribute a comment mark to its source.";
336
369
  return;
337
370
  }
@@ -397,7 +430,26 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
397
430
  const boundaries = Array.from({ length: text.length + 1 }, () => []);
398
431
  let index = 0;
399
432
  let consumed = 0;
433
+ const insertionOrdinals = /* @__PURE__ */ new Map();
434
+ const insertionOrdinalAt = (offset) => {
435
+ const known = insertionOrdinals.get(offset);
436
+ if (known !== void 0) return known;
437
+ const ordinal = defaultInsertionGap(source.content, offset).zeroWidthBefore;
438
+ insertionOrdinals.set(offset, ordinal);
439
+ return ordinal;
440
+ };
441
+ const extents = /* @__PURE__ */ new Map();
400
442
  const addGap = (position, gap) => {
443
+ const key = `${gap.offset}:${position}`;
444
+ const extent = extents.get(key);
445
+ if (extent === void 0) extents.set(key, {
446
+ first: gap.zeroWidthBefore,
447
+ last: gap.zeroWidthBefore
448
+ });
449
+ else {
450
+ extent.first = Math.min(extent.first, gap.zeroWidthBefore);
451
+ extent.last = Math.max(extent.last, gap.zeroWidthBefore);
452
+ }
401
453
  const gaps = boundaries.at(gap.offset);
402
454
  if (!gaps) panic(`Source leaf offset ${gap.offset} exceeds paragraph ${source.paraId}.`);
403
455
  const existing = gaps.findIndex((entry) => entry.position === position);
@@ -405,8 +457,13 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
405
457
  position,
406
458
  zeroWidthBefore: gap.zeroWidthBefore
407
459
  };
408
- if (existing < 0) gaps.push(entry);
409
- else gaps[existing] = entry;
460
+ if (existing < 0) {
461
+ gaps.push(entry);
462
+ return;
463
+ }
464
+ const preferred = insertionOrdinalAt(gap.offset);
465
+ const kept = gaps[existing] ?? panic("Missing canonical seam gap");
466
+ if (Math.abs(entry.zeroWidthBefore - preferred) < Math.abs(kept.zeroWidthBefore - preferred)) gaps[existing] = entry;
410
467
  };
411
468
  const consumeErasedLeaves = (position) => {
412
469
  while (consumed === 0) {
@@ -430,6 +487,16 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
430
487
  });
431
488
  for (const cell of native.value) {
432
489
  consumeErasedLeaves(cell.from);
490
+ if (cell.type === "zeroWidth" && cell.sources.length === 0) {
491
+ if (consumed !== 0) return refuse("Canonical editing cannot place a content control edge inside text.");
492
+ const gap = spans.at(index)?.before ?? spans.at(index - 1)?.after ?? {
493
+ offset: 0,
494
+ zeroWidthBefore: 0
495
+ };
496
+ addGap(cell.from, gap);
497
+ addGap(cell.to, gap);
498
+ continue;
499
+ }
433
500
  let span = spans.at(index);
434
501
  if (!span) return refuse(`Canonical editing cannot map native ${cell.node.type.name} to a source leaf.`);
435
502
  addGap(cell.from, consumed === 0 ? span.before : {
@@ -499,9 +566,106 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
499
566
  const missing = spans.at(index);
500
567
  if (missing || consumed !== 0) return refuse(`Canonical editing cannot display the source positions of ${missing?.node.type ?? "incomplete text"}.`);
501
568
  if (boundaries.some((gaps) => gaps.length === 0)) return refuse("Canonical editing lost a source character boundary.");
569
+ const seams = boundaries.map((gaps, offset) => gaps.map(({ position }) => extents.get(`${offset}:${position}`) ?? panic("A canonical gap lost its seam")));
502
570
  return Result.ok({
503
571
  text,
504
- boundaries
572
+ boundaries,
573
+ seams
505
574
  });
506
575
  };
507
- export { CANONICAL_NATIVE_INLINE_POLICIES, CANONICAL_SOURCE_INLINE_POLICIES, canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline };
576
+ /** A membership whose answers one paragraph's projection read, recorded to check later. */
577
+ var RecordedMembership = class {
578
+ answers = /* @__PURE__ */ new Map();
579
+ source;
580
+ constructor(source) {
581
+ this.source = source;
582
+ }
583
+ has(value) {
584
+ const answer = this.source.has(value);
585
+ this.answers.set(value, answer);
586
+ return answer;
587
+ }
588
+ };
589
+ const answersHold = (answers, set) => {
590
+ for (const [value, answer] of answers) if (set.has(value) !== answer) return false;
591
+ return true;
592
+ };
593
+ const sameIds = (left, right) => {
594
+ let index = 0;
595
+ for (const value of right) {
596
+ if (left[index] !== value) return false;
597
+ index += 1;
598
+ }
599
+ return index === left.length;
600
+ };
601
+ /** The story inputs behind recorders, and what they read once the projection ran. */
602
+ const recordStory = (story) => {
603
+ const pairedBookmarkIds = new RecordedMembership(story.pairedBookmarkIds);
604
+ const context = story.commentContext;
605
+ if (context === void 0) return {
606
+ recorded: { pairedBookmarkIds },
607
+ reads: () => ({
608
+ pairedBookmarkIds: pairedBookmarkIds.answers,
609
+ commentContext: void 0
610
+ })
611
+ };
612
+ const rangedIds = new RecordedMembership(context.rangedIds);
613
+ const pointIds = new RecordedMembership(context.pointIds);
614
+ const openIds = [...context.openIds];
615
+ return {
616
+ recorded: {
617
+ pairedBookmarkIds,
618
+ commentContext: {
619
+ rangedIds,
620
+ pointIds,
621
+ openIds: new Set(openIds)
622
+ }
623
+ },
624
+ reads: () => ({
625
+ pairedBookmarkIds: pairedBookmarkIds.answers,
626
+ commentContext: {
627
+ rangedIds: rangedIds.answers,
628
+ pointIds: pointIds.answers,
629
+ openIds
630
+ }
631
+ })
632
+ };
633
+ };
634
+ const storyReadsHold = (reads, story) => {
635
+ if (!answersHold(reads.pairedBookmarkIds, story.pairedBookmarkIds)) return false;
636
+ const read = reads.commentContext;
637
+ const context = story.commentContext;
638
+ if (read === void 0 || context === void 0) return read === void 0 && context === void 0;
639
+ return sameIds(read.openIds, context.openIds) && answersHold(read.rangedIds, context.rangedIds) && answersHold(read.pointIds, context.pointIds);
640
+ };
641
+ /**
642
+ * Paragraph projections kept across projections of a story.
643
+ *
644
+ * A paragraph an edit left keeps its source records, and the block cache
645
+ * keeps its editor node, so its gaps can be reused where the story facts its
646
+ * projection read are the same: the comments open at its start and the
647
+ * comment and bookmark ids it asked about. Gap positions are relative to the
648
+ * paragraph, so a reused projection holds wherever the paragraph now starts.
649
+ */
650
+ var InlineProjectionCache = class {
651
+ paragraphs = /* @__PURE__ */ new WeakMap();
652
+ project(args) {
653
+ const known = this.paragraphs.get(args.source);
654
+ if (known !== void 0 && PARAGRAPH_INPUT_FIELDS.every((field) => known.inputs[field] === args[field]) && storyReadsHold(known.reads, args)) return Result.ok(known.projection);
655
+ const { recorded, reads } = recordStory(args);
656
+ const projected = projectCanonicalInline({
657
+ ...args,
658
+ ...recorded
659
+ });
660
+ if (projected.isOk()) this.paragraphs.set(args.source, {
661
+ inputs: {
662
+ source: args.source,
663
+ paragraph: args.paragraph
664
+ },
665
+ reads: reads(),
666
+ projection: projected.value
667
+ });
668
+ return projected;
669
+ }
670
+ };
671
+ export { CANONICAL_NATIVE_INLINE_POLICIES, CANONICAL_SOURCE_INLINE_POLICIES, InlineProjectionCache, canonicalInlineSourceIssue, canonicalNativeCells, projectCanonicalInline };
@@ -14,7 +14,7 @@ type ReplaceTextInput = {
14
14
  });
15
15
  type CanonicalInputOptions = {
16
16
  replace: (input: ReplaceTextInput) => void;
17
- structure?: (type: "split" | "joinBackward" | "joinForward" | "lineBreak" | "pageBreak" | "tab" | "indent" | "outdent") => void;
17
+ structure?: (type: "split" | "joinBackward" | "joinForward" | "lineBreak" | "pageBreak" | "tab" | "indent" | "outdent" | "deleteTable") => void;
18
18
  command?: (name: "toggleBold" | "toggleItalic" | "toggleUnderline") => void;
19
19
  breakUndoGroup?: () => void;
20
20
  beginComposition?: () => boolean;
@@ -31,6 +31,7 @@ export declare const createCanonicalInputBoundary: (options: CanonicalInputOptio
31
31
  acceptComposition: (view: EditorView, transaction: Transaction) => boolean;
32
32
  handleTextInput: (view: EditorView, from: number, to: number, text: string) => boolean;
33
33
  handleKeyDown: (view: EditorView, event: KeyboardEvent) => boolean;
34
+ handleKeyPress: (view: EditorView, event: KeyboardEvent) => boolean;
34
35
  handleDOMEvents: {
35
36
  keydown: (view: EditorView, event: KeyboardEvent) => boolean;
36
37
  compositionstart: (view: EditorView) => boolean;
@@ -1,6 +1,7 @@
1
1
  import { getEditorInputTargetRange, handleEditorBeforeInput } from "../prosemirror/textInput.js";
2
2
  import { createCanonicalComposition } from "./canonicalComposition.js";
3
3
  import { deletionRange, isCanonicalJoinBoundary } from "./canonicalSession.js";
4
+ import { CellSelection } from "prosemirror-tables";
4
5
  import { ReplaceStep } from "prosemirror-transform";
5
6
  import { Selection, TextSelection } from "prosemirror-state";
6
7
  // src/controller/canonicalInput.ts
@@ -121,6 +122,26 @@ const createCanonicalInputBoundary = (options) => {
121
122
  refuseNativeMutation(view);
122
123
  return true;
123
124
  },
125
+ /**
126
+ * ProseMirror types a key over a selection that is not text inside one
127
+ * paragraph (one across paragraphs, a whole document, cells, a node) itself
128
+ * from keypress, cancelling it, so no beforeinput ever classifies that
129
+ * text. It is the same typing a beforeinput carries, at the same selection.
130
+ */
131
+ handleKeyPress: (view, event) => {
132
+ if (composition.active || composition.pendingFinal) return false;
133
+ const { selection } = view.state;
134
+ if (selection instanceof TextSelection && selection.$from.sameParent(selection.$to)) return false;
135
+ const text = String.fromCharCode(event.charCode);
136
+ if (/[\r\n]/u.test(text)) return false;
137
+ options.replace({
138
+ from: selection.from,
139
+ to: selection.to,
140
+ text,
141
+ semantic: "typing"
142
+ });
143
+ return true;
144
+ },
124
145
  handleKeyDown: (view, event) => {
125
146
  if (event.isComposing || event.keyCode === 229) return false;
126
147
  beginGesture();
@@ -195,7 +216,13 @@ const createCanonicalInputBoundary = (options) => {
195
216
  if (!composition.active) options.refuse("Only plain character deletion is available in this session.");
196
217
  return true;
197
218
  }
198
- if (view.state.selection.empty && options.structure !== void 0 && isCanonicalJoinBoundary(view.state, event.key === "Backspace" ? "backward" : "forward")) {
219
+ const selection = view.state.selection;
220
+ if (selection instanceof CellSelection && selection.isRowSelection() && selection.isColSelection() && options.structure !== void 0) {
221
+ closeGroup();
222
+ options.structure("deleteTable");
223
+ return true;
224
+ }
225
+ if (selection.empty && options.structure !== void 0 && isCanonicalJoinBoundary(view.state, event.key === "Backspace" ? "backward" : "forward")) {
199
226
  closeGroup();
200
227
  options.structure(event.key === "Backspace" ? "joinBackward" : "joinForward");
201
228
  return true;
@@ -1,7 +1,8 @@
1
+ import { ListNormalizationCache } from "../docx/listModelNormalization.js";
1
2
  import { DocumentOp } from "./canonicalOperations.js";
2
3
  import { Document } from "@stll/docx-core";
3
4
  /** Canonical edits share list model normalization with the headless projection. */
4
- export declare const normalizeCanonicalListRendering: (document: Document) => {
5
+ export declare const normalizeCanonicalListRendering: (document: Document, cache?: ListNormalizationCache) => {
5
6
  document: Document;
6
7
  inverse: DocumentOp[];
7
8
  };
@@ -1,5 +1,5 @@
1
1
  import { normalizeListModelRendering } from "../docx/listModelNormalization.js";
2
2
  // src/controller/canonicalListRendering.ts
3
3
  /** Canonical edits share list model normalization with the headless projection. */
4
- const normalizeCanonicalListRendering = normalizeListModelRendering;
4
+ const normalizeCanonicalListRendering = (document, cache) => normalizeListModelRendering(document, cache === void 0 ? {} : { cache });
5
5
  export { normalizeCanonicalListRendering };
@@ -0,0 +1,8 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { LockedControlViolation } from "@stll/docx-core/model";
3
+ /**
4
+ * What a change from `before` to `after` does to a locked content control,
5
+ * judged on the result rather than the steps that produced it, so every path
6
+ * into the session meets the same rule.
7
+ */
8
+ export declare const lockViolationBetween: (before: document_d_exports.Document, after: document_d_exports.Document) => LockedControlViolation | null;
@@ -0,0 +1,88 @@
1
+ import { contentControlLockAllows, locksContent, locksControl } from "@stll/docx-core/model";
2
+ import { documentStories, findStoryBody } from "@stll/docx-core/ops";
3
+ // src/controller/canonicalLockGuard.ts
4
+ /** Comment marks, anchors and identities: what a lock does not hold still. */
5
+ const IGNORED_KEYS = /* @__PURE__ */ new Set(["paraId", "textId"]);
6
+ const IGNORED_ITEMS = /* @__PURE__ */ new Set([
7
+ "commentRangeStart",
8
+ "commentRangeEnd",
9
+ "commentReference"
10
+ ]);
11
+ const isIgnoredItem = (item) => typeof item === "object" && item !== null && "type" in item && IGNORED_ITEMS.has(String(item.type));
12
+ const isRevisionIdentity = (key, value) => key === "preservedAttributes" && Array.isArray(value);
13
+ /** What a control holds, as the lock judges it. */
14
+ const signatureOf = (content) => JSON.stringify(content, (key, value) => {
15
+ if (IGNORED_KEYS.has(key)) return void 0;
16
+ if (isRevisionIdentity(key, value)) return value.filter(({ name }) => typeof name !== "string" || !name.startsWith("rsid"));
17
+ if (Array.isArray(value)) return value.filter((item) => !isIgnoredItem(item));
18
+ return value;
19
+ });
20
+ const storyKey = (story) => {
21
+ if (story === "main") return "main";
22
+ return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
23
+ };
24
+ /**
25
+ * Every content control in the document, keyed by its story and `w:id`, or by
26
+ * its order among the controls without one.
27
+ */
28
+ const controlsOf = (document) => {
29
+ const controls = /* @__PURE__ */ new Map();
30
+ for (const story of documentStories(document)) {
31
+ const body = findStoryBody(document, story);
32
+ if (body === void 0) continue;
33
+ let anonymous = 0;
34
+ const visit = (value) => {
35
+ if (Array.isArray(value)) {
36
+ for (const item of value) visit(item);
37
+ return;
38
+ }
39
+ if (typeof value !== "object" || value === null) return;
40
+ const node = value;
41
+ if (node.type === "blockSdt" || node.type === "inlineSdt") {
42
+ const id = node.properties?.id;
43
+ const key = `${storyKey(story)}#${id === void 0 ? `anonymous ${String(anonymous++)}` : String(id)}`;
44
+ controls.set(key, {
45
+ lock: node.properties?.lock,
46
+ signature: signatureOf(node.content)
47
+ });
48
+ }
49
+ for (const child of Object.values(value)) visit(child);
50
+ };
51
+ visit(body.content);
52
+ }
53
+ return controls;
54
+ };
55
+ const lockedControls = /* @__PURE__ */ new WeakMap();
56
+ const lockedIn = (document) => {
57
+ let locked = lockedControls.get(document);
58
+ if (locked === void 0) {
59
+ locked = new Map([...controlsOf(document)].filter(([, { lock }]) => locksContent(lock) || locksControl(lock)));
60
+ lockedControls.set(document, locked);
61
+ }
62
+ return locked;
63
+ };
64
+ /**
65
+ * What a change from `before` to `after` does to a locked content control,
66
+ * judged on the result rather than the steps that produced it, so every path
67
+ * into the session meets the same rule.
68
+ */
69
+ const lockViolationBetween = (before, after) => {
70
+ const locked = lockedIn(before);
71
+ if (locked.size === 0 || before === after) return null;
72
+ const now = controlsOf(after);
73
+ for (const [key, { lock, signature }] of locked) {
74
+ if (lock === void 0) continue;
75
+ const kept = now.get(key);
76
+ if (kept === void 0) {
77
+ if (!contentControlLockAllows(lock, "removeControl")) return {
78
+ lock,
79
+ change: "removeControl"
80
+ };
81
+ } else if (kept.signature !== signature && !contentControlLockAllows(lock, "editContent")) return {
82
+ lock,
83
+ change: "editContent"
84
+ };
85
+ }
86
+ return null;
87
+ };
88
+ export { lockViolationBetween };
@@ -10,10 +10,10 @@ export declare const CANONICAL_PUBLIC_OPERATION_DISPOSITIONS: {
10
10
  readonly splitBlock: "compile";
11
11
  readonly formatRange: "compile";
12
12
  readonly mergeBlockWithNext: "compile";
13
- readonly setBlockParagraphProperties: "publicOps.unsupportedInline";
14
- readonly insertAfterBlock: "publicOps.unsupportedInline";
15
- readonly insertBeforeBlock: "publicOps.unsupportedInline";
16
- readonly deleteBlock: "publicOps.unsupportedInline";
13
+ readonly setBlockParagraphProperties: "compile";
14
+ readonly insertAfterBlock: "compile";
15
+ readonly insertBeforeBlock: "compile";
16
+ readonly deleteBlock: "compile";
17
17
  readonly commentOnBlock: "compile";
18
18
  readonly commentOnRange: "compile";
19
19
  readonly insertTable: "publicOps.tableStructure";
@@ -41,6 +41,14 @@ export declare class CanonicalPublicOperations {
41
41
  constructor(options: CanonicalPublicOperationsOptions);
42
42
  apply(options: CanonicalPublicOperationOptions): FolioDocumentOperationResult;
43
43
  undo(handle: FolioDocumentOperationUndoHandle): FolioDocumentOperationUndoResult;
44
+ /**
45
+ * A whole paragraph removed as the editor removes a selection of it with
46
+ * its paragraph mark: from its start to the start of the paragraph after
47
+ * it, or, for the paragraph that ends its block list, from the end of the
48
+ * paragraph before it, whose mark then ends the list. Tracked, the text and
49
+ * the mark are marked deleted.
50
+ */
51
+ private resolveBlockDeletion;
44
52
  private resolve;
45
53
  }
46
54
  export {};