@stll/folio-core 0.73.0 → 0.75.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 (221) hide show
  1. package/dist/ai-edits/clean-text.d.ts +4 -1
  2. package/dist/ai-edits/clean-text.js +21 -7
  3. package/dist/ai-edits/headless.d.ts +5 -2
  4. package/dist/ai-edits/headless.js +20 -14
  5. package/dist/ai-edits/note-references.d.ts +1 -1
  6. package/dist/ai-edits/note-references.js +1 -1
  7. package/dist/ai-edits/pending-suggestions.d.ts +9 -7
  8. package/dist/ai-edits/pending-suggestions.js +134 -88
  9. package/dist/ai-edits/pendingJoin.d.ts +5 -1
  10. package/dist/ai-edits/pendingJoin.js +12 -3
  11. package/dist/ai-edits/result-validation.js +1 -1
  12. package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
  13. package/dist/ai-edits/retired-comment-receipts.js +3 -18
  14. package/dist/ai-edits/snapshot.js +1 -1
  15. package/dist/ai-edits/table-cell-mutations.js +1 -1
  16. package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
  17. package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
  18. package/dist/canonical/canonicalBatchReview.d.ts +4 -1
  19. package/dist/canonical/canonicalBatchReview.js +32 -14
  20. package/dist/canonical/canonicalComments.d.ts +6 -2
  21. package/dist/canonical/canonicalComments.js +8 -4
  22. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  23. package/dist/canonical/canonicalInlineGaps.js +118 -0
  24. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  25. package/dist/canonical/canonicalInlineProjection.js +6 -28
  26. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  27. package/dist/canonical/canonicalPublicOperations.js +99 -36
  28. package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
  29. package/dist/canonical/canonicalRefusalGrounds.js +56 -0
  30. package/dist/canonical/canonicalSelection.js +1 -1
  31. package/dist/canonical/canonicalSession.d.ts +12 -6
  32. package/dist/canonical/canonicalSession.js +129 -141
  33. package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
  34. package/dist/compare/inline-atoms.d.ts +35 -41
  35. package/dist/compare/inline-atoms.js +2 -465
  36. package/dist/compare/section-boundary-properties.d.ts +3 -30
  37. package/dist/compare/section-boundary-properties.js +4 -72
  38. package/dist/controller/autocompleteSuggestion.js +1 -1
  39. package/dist/controller/canonicalClipboard.js +45 -44
  40. package/dist/controller/canonicalComposition.d.ts +1 -1
  41. package/dist/controller/canonicalComposition.js +6 -6
  42. package/dist/controller/canonicalInput.d.ts +4 -2
  43. package/dist/controller/canonicalInput.js +34 -17
  44. package/dist/controller/canonicalPresence.js +1 -1
  45. package/dist/controller/canonicalRoomAuthority.js +1 -1
  46. package/dist/controller/canonicalRoomWire.js +1 -1
  47. package/dist/controller/canonicalStoryEditor.d.ts +2 -3
  48. package/dist/controller/canonicalStoryEditor.js +43 -25
  49. package/dist/controller/canonicalStructure.d.ts +19 -2
  50. package/dist/controller/canonicalStructure.js +140 -43
  51. package/dist/controller/canonicalTabRoom.js +1 -1
  52. package/dist/controller/canonicalYjsRoom.js +1 -1
  53. package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
  54. package/dist/controller/deferredDisplayListPainter.js +34 -0
  55. package/dist/controller/folioEditor.js +4 -2
  56. package/dist/controller/headerFooterEditorManager.js +3 -17
  57. package/dist/controller/hiddenEditorApi.d.ts +24 -3
  58. package/dist/controller/hiddenEditorApi.js +4 -17
  59. package/dist/controller/hiddenEditorManager.js +136 -197
  60. package/dist/controller/layoutPipeline.d.ts +4 -86
  61. package/dist/controller/layoutPipeline.js +8 -727
  62. package/dist/controller/layoutPipelineExecution.d.ts +94 -0
  63. package/dist/controller/layoutPipelineExecution.js +730 -0
  64. package/dist/controller/noteEditorManager.js +3 -16
  65. package/dist/document-operations.js +1 -1
  66. package/dist/docx/blockContentParser.d.ts +1 -3
  67. package/dist/docx/blockContentParser.js +3 -10
  68. package/dist/docx/canonicalSave.d.ts +4 -3
  69. package/dist/docx/canonicalSave.js +4 -3
  70. package/dist/docx/canonicalSessionInput.js +1 -1
  71. package/dist/docx/containerChildren.js +1 -1
  72. package/dist/docx/createDocx.d.ts +4 -0
  73. package/dist/docx/createDocx.js +6 -0
  74. package/dist/docx/listMarkerComputation.d.ts +24 -17
  75. package/dist/docx/listMarkerComputation.js +31 -60
  76. package/dist/docx/listModelNormalization.js +8 -15
  77. package/dist/docx/modelValidation.js +1 -1
  78. package/dist/docx/parser.js +1 -1
  79. package/dist/docx/reviewResolutionProvenance.js +1 -1
  80. package/dist/docx/rezip.d.ts +16 -3
  81. package/dist/docx/rezip.js +36 -10
  82. package/dist/docx/selectiveSave.js +13 -5
  83. package/dist/docx/serializer/borderSerializer.js +1 -1
  84. package/dist/docx/serializer/commentSerializer.js +1 -1
  85. package/dist/docx/serializer/documentSerializer.js +1 -1
  86. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  87. package/dist/docx/serializer/runSerializer.js +1 -1
  88. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  89. package/dist/docx/serializer/tableSerializer.js +1 -1
  90. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  91. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  92. package/dist/docx/server/templatePlan/apply.js +107 -14
  93. package/dist/docx/server/templatePlan/blocks.d.ts +16 -1
  94. package/dist/docx/server/templatePlan/blocks.js +93 -7
  95. package/dist/docx/server/templatePlan/builders.d.ts +37 -2
  96. package/dist/docx/server/templatePlan/builders.js +196 -5
  97. package/dist/docx/server/templatePlan/emit.d.ts +2 -0
  98. package/dist/docx/server/templatePlan/emit.js +2 -0
  99. package/dist/docx/server/templatePlan/inspect.js +81 -61
  100. package/dist/docx/server/templatePlan/labels.d.ts +16 -2
  101. package/dist/docx/server/templatePlan/labels.js +131 -20
  102. package/dist/docx/server/templatePlan/plan.d.ts +15 -1
  103. package/dist/docx/server/templatePlan/plan.js +62 -13
  104. package/dist/docx/server/templatePlan/planShape.js +52 -4
  105. package/dist/docx/server/templatePlan/story.d.ts +8 -0
  106. package/dist/docx/server/templatePlan/story.js +11 -1
  107. package/dist/docx/server/templatePlan/types.d.ts +176 -18
  108. package/dist/docx/server/templatePlan/types.js +1 -0
  109. package/dist/docx/server/templatePlan/verify.js +60 -11
  110. package/dist/docx/server/templatePlan/xml.d.ts +5 -0
  111. package/dist/docx/server/templatePlan/xml.js +7 -1
  112. package/dist/docx/storyBlockReplay.js +1 -1
  113. package/dist/docx/xmlParser.js +1 -1
  114. package/dist/i18n/loadMessages.d.ts +5 -0
  115. package/dist/i18n/loadMessages.js +46 -0
  116. package/dist/i18n/locales.d.ts +3 -0
  117. package/dist/i18n/locales.js +17 -0
  118. package/dist/i18n/messages/ar.gen.js +1 -0
  119. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  120. package/dist/i18n/messages/catalogs.gen.js +17 -0
  121. package/dist/i18n/messages/cs.gen.js +1 -0
  122. package/dist/i18n/messages/de.gen.js +1 -0
  123. package/dist/i18n/messages/en.gen.js +1 -0
  124. package/dist/i18n/messages/es.gen.js +1 -0
  125. package/dist/i18n/messages/et.gen.js +1 -0
  126. package/dist/i18n/messages/fr.gen.js +1 -0
  127. package/dist/i18n/messages/he.gen.js +1 -0
  128. package/dist/i18n/messages/hi.gen.js +1 -0
  129. package/dist/i18n/messages/hu.gen.js +1 -0
  130. package/dist/i18n/messages/lt.gen.js +1 -0
  131. package/dist/i18n/messages/lv.gen.js +1 -0
  132. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  133. package/dist/i18n/messages/pl.gen.js +1 -0
  134. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  135. package/dist/i18n/messages/sk.gen.js +1 -0
  136. package/dist/i18n/messages/tr.gen.js +1 -0
  137. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  138. package/dist/i18n/messages.d.ts +3 -2
  139. package/dist/i18n/messages.js +4 -16
  140. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  141. package/dist/internal/clipboardTransformPlugin.js +13 -0
  142. package/dist/internal/extensionRuntime.d.ts +7 -0
  143. package/dist/internal/extensionRuntime.js +28 -0
  144. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  145. package/dist/internal/starterKitExtensions.d.ts +20 -0
  146. package/dist/internal/starterKitExtensions.js +123 -0
  147. package/dist/internal/wholeStoryRevisionResolution.js +2 -2
  148. package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
  149. package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
  150. package/dist/prosemirror/attrs/index.js +1 -1
  151. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  152. package/dist/prosemirror/canonicalTableCommands.js +1 -1
  153. package/dist/prosemirror/commands/comments.js +3 -3
  154. package/dist/prosemirror/commands/contentControls.js +1 -1
  155. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  156. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  157. package/dist/prosemirror/commentRecords.js +2 -2
  158. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  159. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  160. package/dist/prosemirror/conversion/index.d.ts +2 -2
  161. package/dist/prosemirror/conversion/index.js +2 -2
  162. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  163. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  164. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  165. package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -2
  166. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  167. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
  168. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  169. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  170. package/dist/prosemirror/extensions/index.d.ts +2 -1
  171. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  172. package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
  173. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  174. package/dist/prosemirror/index.d.ts +2 -2
  175. package/dist/prosemirror/index.js +2 -2
  176. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  177. package/dist/prosemirror/listMarker.d.ts +1 -6
  178. package/dist/prosemirror/listMarker.js +4 -56
  179. package/dist/prosemirror/listNumbering.js +1 -1
  180. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  181. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  182. package/dist/prosemirror/noteReferenceReview.js +2 -243
  183. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  184. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  185. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  186. package/dist/prosemirror/replacedAnnotations.js +1 -1
  187. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  188. package/dist/prosemirror/suggestionCommands.js +31 -0
  189. package/dist/prosemirror/tableCellPaste.js +1 -1
  190. package/dist/prosemirror/tableRunIn.js +1 -1
  191. package/dist/prosemirror/textInput.js +1 -1
  192. package/dist/server.d.ts +2 -2
  193. package/dist/types/canonicalCapabilities.d.ts +42 -93
  194. package/dist/types/canonicalCapabilities.js +53 -91
  195. package/dist/types/canonicalComments.d.ts +2 -2
  196. package/dist/types/canonicalSections.d.ts +2 -2
  197. package/dist/utils/clipboard.d.ts +2 -28
  198. package/dist/utils/clipboard.js +1 -96
  199. package/dist/utils/clipboardFiles.d.ts +27 -0
  200. package/dist/utils/clipboardFiles.js +98 -0
  201. package/dist/utils/rulerControl.d.ts +1 -0
  202. package/dist/utils/rulerControl.js +2 -1
  203. package/package.json +2 -2
  204. package/dist/ai-edits/apply.d.ts +0 -94
  205. package/dist/ai-edits/apply.js +0 -6637
  206. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  207. package/dist/ai-edits/note-story-inventory.js +0 -10
  208. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  209. package/dist/ai-edits/revisionStretches.js +0 -147
  210. package/dist/document-operations-apply.d.ts +0 -15
  211. package/dist/document-operations-apply.js +0 -280
  212. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
  213. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
  214. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
  215. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
  216. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
  217. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
  218. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  219. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  220. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  221. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -1,6 +1,5 @@
1
1
  import { sectionReferenceHistory } from "../docx/sectionReferenceHistory.js";
2
2
  import { expectParagraphAttrs } from "../prosemirror/attrs/index.js";
3
- import { resolveAllChangesInHeadlessStateWithMapping } from "../prosemirror/commands/comments.js";
4
3
  import { canonicalJson } from "../utils/canonicalJson.js";
5
4
  import { DOCUMENT_OP_TYPES } from "@stll/docx-core/ops";
6
5
  // src/compare/section-boundary-properties.ts
@@ -222,77 +221,10 @@ const stagedBoundaryProperties = ({ update, id, author, date }) => {
222
221
  }]
223
222
  };
224
223
  };
225
- /** Stage section deltas after document operations, against the accepted projection. */
226
- const stageSectionBoundaryProperties = ({ state, target, originalRevisionIdSeed, revisionStamp, author, maxRanges, mapTargetProperties }) => {
227
- if (!Number.isSafeInteger(maxRanges) || maxRanges < 0) return { status: "budget-exceeded" };
228
- if (!hasSectionEndpoint(target)) return {
229
- status: "matched",
230
- transaction: state.tr,
231
- nextRevisionId: revisionStamp.idSeed,
232
- rangeCount: 0
233
- };
234
- const reviewedState = resolveAllChangesInHeadlessStateWithMapping(state, "accept");
235
- const inverse = reviewedState.mapping.invert();
236
- const plan = planSectionBoundaryUpdates({
237
- accepted: reviewedState.state.doc,
238
- target,
239
- originalRevisionIdSeed,
240
- maxRanges,
241
- mapTargetProperties,
242
- sourceOf: (paragraph) => {
243
- const mapped = inverse.mapResult(paragraph.position, 1);
244
- if (mapped.deleted) return {
245
- status: "missing",
246
- detail: "boundary has no source position"
247
- };
248
- const current = state.doc.nodeAt(mapped.pos);
249
- if (!current || current.type.name !== "paragraph") return {
250
- status: "missing",
251
- detail: "mapped boundary is not a paragraph"
252
- };
253
- const attrs = expectParagraphAttrs(current);
254
- return {
255
- status: "found",
256
- key: mapped.pos,
257
- sectionProperties: attrs._sectionProperties,
258
- pPrMark: attrs.pPrMark ?? void 0
259
- };
260
- }
261
- });
262
- if (plan.status !== "matched") return plan;
263
- let nextRevisionId = revisionStamp.idSeed;
264
- let transaction = state.tr;
265
- for (const update of plan.updates.toSorted((left, right) => right.key - left.key)) {
266
- const position = transaction.mapping.map(update.key, 1);
267
- const node = transaction.doc.nodeAt(position);
268
- if (!node || node.type.name !== "paragraph") return {
269
- status: "unalignable",
270
- detail: "boundary moved while staging"
271
- };
272
- transaction = transaction.setNodeMarkup(position, void 0, {
273
- ...node.attrs,
274
- _sectionProperties: stagedBoundaryProperties({
275
- update,
276
- id: nextRevisionId++,
277
- author,
278
- date: revisionStamp.date
279
- })
280
- });
281
- }
282
- return {
283
- status: "matched",
284
- transaction,
285
- nextRevisionId,
286
- rangeCount: plan.updates.length
287
- };
288
- };
289
224
  /**
290
- * Stage section deltas on a document model: planned as
291
- * {@link stageSectionBoundaryProperties} plans them, on `accepted`, the
292
- * accepted projection of `document`, with each boundary paragraph found in
293
- * `document` by its paragraph id. One section-endpoint operation per
294
- * endpoint, revision ids given from the last endpoint back as the
295
- * transaction gives them.
225
+ * Plan section deltas on the accepted projection of `document` and find each
226
+ * boundary in the authored document by paragraph id. Emit one operation per
227
+ * endpoint, assigning revision ids from the last endpoint back.
296
228
  */
297
229
  const stageSectionBoundaryOperations = ({ document, accepted, target, originalRevisionIdSeed, revisionStamp, author, maxRanges, mapTargetProperties }) => {
298
230
  if (!Number.isSafeInteger(maxRanges) || maxRanges < 0) return { status: "budget-exceeded" };
@@ -360,4 +292,4 @@ const stageSectionBoundaryOperations = ({ document, accepted, target, originalRe
360
292
  nextRevisionId
361
293
  };
362
294
  };
363
- export { compareSectionBoundaryProperties, stageSectionBoundaryOperations, stageSectionBoundaryProperties };
295
+ export { compareSectionBoundaryProperties, stageSectionBoundaryOperations };
@@ -1,8 +1,8 @@
1
1
  import { canonicalTypingOf } from "../internal/canonicalTyping.js";
2
2
  import { Subscribable } from "../managers/Subscribable.js";
3
3
  import { legacyTextAddressAt } from "./legacyTextAddress.js";
4
- import { ReplaceStep } from "prosemirror-transform";
5
4
  import { DOCUMENT_OP_SCHEMA_VERSION, sameStory, transformPosition } from "@stll/docx-core/ops";
5
+ import { ReplaceStep } from "prosemirror-transform";
6
6
  import { isHistoryTransaction } from "prosemirror-history";
7
7
  // src/controller/autocompleteSuggestion.ts
8
8
  /**
@@ -1,3 +1,4 @@
1
+ import { groundForDocumentOpRefusal } from "../canonical/canonicalRefusalGrounds.js";
1
2
  import { CanonicalSessionError } from "../canonical/canonicalSession.js";
2
3
  import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
3
4
  import { copyParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
@@ -8,28 +9,25 @@ import { canonicalSelectionRange } from "../prosemirror/canonicalSelectionRange.
8
9
  import { proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
9
10
  import { completeNumberingForDoc } from "../prosemirror/listInstanceReferences.js";
10
11
  import { marksToTextFormatting } from "../prosemirror/runFormattingFromMarks.js";
11
- import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
12
+ import { CANONICAL_CONDITION, CANONICAL_GAP } from "../types/canonicalCapabilities.js";
12
13
  import { readModel } from "../types/documentModel.js";
13
14
  import { bytesToDataUrl } from "../utils/base64.js";
14
15
  import { base64ToBytes } from "../utils/textEncoding.js";
15
16
  import { flattenClipboardStyleReferences, importClipboardStyles } from "./canonicalClipboardResources.js";
16
17
  import { Result, panic } from "better-result";
17
- import { Fragment, Slice } from "prosemirror-model";
18
- import { CellSelection } from "prosemirror-tables";
19
18
  import { NUMBER_FORMATS, paragraphNumberingReference, relationshipIdOf } from "@stll/docx-core/model";
20
19
  import { packageResourcesOpOf } from "@stll/docx-core/ops";
20
+ import { CellSelection } from "prosemirror-tables";
21
+ import { Fragment, Slice } from "prosemirror-model";
21
22
  // src/controller/canonicalClipboard.ts
22
- const refuse = (message) => Result.err(new CanonicalSessionError({
23
- ground: { gap: CANONICAL_GAP.dispatch },
24
- message,
25
- reason: "refused"
26
- }));
27
- /** A refusal under the gap or rule it belongs to. */
28
- const refuseUnder = (ground, message) => Result.err(new CanonicalSessionError({
23
+ /** A refusal under the gap, rule or condition it belongs to. */
24
+ const refuse = (message, ground) => Result.err(new CanonicalSessionError({
29
25
  ground,
30
26
  message,
31
27
  reason: "refused"
32
28
  }));
29
+ /** Clipboard content the paste cannot read or resolve as given. */
30
+ const INVALID_CLIPBOARD = { condition: CANONICAL_CONDITION.invalidRequest };
33
31
  /**
34
32
  * The gap a clipboard block the paste cannot place falls under: a table's,
35
33
  * or for any other block, the story content the session cannot project.
@@ -133,9 +131,9 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
133
131
  numbering: destination,
134
132
  numIds: /* @__PURE__ */ new Map()
135
133
  });
136
- if (source === void 0) return refuse("The clipboard list has no numbering definition.");
134
+ if (source === void 0) return refuse("The clipboard list has no numbering definition.", INVALID_CLIPBOARD);
137
135
  const sourceDefinitions = source;
138
- if (references.some((id) => !sourceDefinitions.nums.some(({ numId }) => numId === id))) return refuse("The clipboard list has no numbering definition.");
136
+ if (references.some((id) => !sourceDefinitions.nums.some(({ numId }) => numId === id))) return refuse("The clipboard list has no numbering definition.", INVALID_CLIPBOARD);
139
137
  const used = new Set(references);
140
138
  const sourceNums = source.nums.filter(({ numId }) => used.has(numId));
141
139
  const usedAbstracts = new Set(sourceNums.map(({ abstractNumId }) => abstractNumId));
@@ -149,9 +147,9 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
149
147
  if (rendering === void 0) continue;
150
148
  const instance = source.nums.find(({ numId }) => numId === rendering.numId);
151
149
  const definition = source.abstractNums.find(({ abstractNumId }) => abstractNumId === instance?.abstractNumId);
152
- if (definition === void 0) return refuse("The clipboard list has no abstract definition.");
150
+ if (definition === void 0) return refuse("The clipboard list has no abstract definition.", INVALID_CLIPBOARD);
153
151
  const level = definition.levels.find(({ ilvl }) => ilvl === rendering.level);
154
- if (level === void 0) return refuse("The clipboard list level could not be imported.");
152
+ if (level === void 0) return refuse("The clipboard list level could not be imported.", INVALID_CLIPBOARD);
155
153
  Object.assign(level, {
156
154
  ...numberFormatFields(rendering.numFmt ?? (rendering.isBullet ? "bullet" : "decimal")),
157
155
  lvlText: rendering.markerTemplate ?? rendering.marker,
@@ -180,7 +178,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
180
178
  for (const formatting of formats) {
181
179
  if (formatting?.numPr?.kind !== "reference") continue;
182
180
  const numId = nums.get(formatting.numPr.numId);
183
- if (numId === void 0) return refuse("The clipboard list instance could not be imported.");
181
+ if (numId === void 0) return refuse("The clipboard list instance could not be imported.", INVALID_CLIPBOARD);
184
182
  formatting.numPr = paragraphNumberingReference({
185
183
  numId,
186
184
  ...formatting.numPr.ilvl === void 0 ? {} : { ilvl: formatting.numPr.ilvl }
@@ -200,7 +198,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
200
198
  for (const instance of source.nums) {
201
199
  const numId = nums.get(instance.numId);
202
200
  const abstractNumId = abstracts.get(instance.abstractNumId);
203
- if (numId === void 0 || abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.");
201
+ if (numId === void 0 || abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.", INVALID_CLIPBOARD);
204
202
  const imported = {
205
203
  ...instance,
206
204
  numId,
@@ -209,7 +207,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
209
207
  for (const override of imported.levelOverrides ?? []) {
210
208
  if (override.lvl?.pStyle === void 0 || styleIds === void 0) continue;
211
209
  const mapped = styleIds.get(override.lvl.pStyle);
212
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
210
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
213
211
  override.lvl.pStyle = mapped;
214
212
  }
215
213
  importedNums.push(imported);
@@ -217,7 +215,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
217
215
  const importedAbstracts = [];
218
216
  for (const definition of source.abstractNums) {
219
217
  const abstractNumId = abstracts.get(definition.abstractNumId);
220
- if (abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.");
218
+ if (abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.", INVALID_CLIPBOARD);
221
219
  const imported = {
222
220
  ...definition,
223
221
  abstractNumId
@@ -225,18 +223,18 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
225
223
  if (styleIds !== void 0) {
226
224
  if (imported.numStyleLink !== void 0) {
227
225
  const mapped = styleIds.get(imported.numStyleLink);
228
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
226
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
229
227
  imported.numStyleLink = mapped;
230
228
  }
231
229
  if (imported.styleLink !== void 0) {
232
230
  const mapped = styleIds.get(imported.styleLink);
233
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
231
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
234
232
  imported.styleLink = mapped;
235
233
  }
236
234
  for (const level of imported.levels) {
237
235
  if (level.pStyle === void 0) continue;
238
236
  const mapped = styleIds.get(level.pStyle);
239
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
237
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
240
238
  level.pStyle = mapped;
241
239
  }
242
240
  }
@@ -283,15 +281,15 @@ const clipboardAnnotations = ({ paragraphs, source }) => {
283
281
  return Result.ok(annotations);
284
282
  };
285
283
  const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
286
- if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
284
+ if (session.isComposing) return refuse("Composition must finish before using the clipboard.", { condition: CANONICAL_CONDITION.composing });
287
285
  if (slice.content.size === 0) return Result.err(new CanonicalSessionError({
288
- ground: { gap: CANONICAL_GAP.dispatch },
286
+ ground: INVALID_CLIPBOARD,
289
287
  message: "The clipboard contains no content.",
290
288
  reason: "noChange"
291
289
  }));
292
- if (slice.openStart > 1 || slice.openEnd > 1) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and nested block containers require canonical table editing.");
290
+ if (slice.openStart > 1 || slice.openEnd > 1) return refuse("Clipboard tables and nested block containers require canonical table editing.", unplacedBlockGround(slice));
293
291
  const paragraphType = state.schema.nodes["paragraph"];
294
- if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.");
292
+ if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.", { condition: CANONICAL_CONDITION.internal });
295
293
  const tableType = state.schema.nodes["table"];
296
294
  let inline = true;
297
295
  let blocksOnly = true;
@@ -299,12 +297,12 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
299
297
  inline &&= node.isInline;
300
298
  blocksOnly &&= node.type === paragraphType || node.type === tableType;
301
299
  });
302
- if (!inline && !blocksOnly) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and embedded blocks require canonical table editing.");
300
+ if (!inline && !blocksOnly) return refuse("Clipboard tables and embedded blocks require canonical table editing.", unplacedBlockGround(slice));
303
301
  const importedSlice = inline ? new Slice(Fragment.from(paragraphType.create(null, slice.content)), 1, 1) : slice;
304
302
  const converted = Result.try({
305
303
  try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
306
304
  catch: (cause) => new CanonicalSessionError({
307
- ground: { gap: CANONICAL_GAP.dispatch },
305
+ ground: INVALID_CLIPBOARD,
308
306
  reason: "refused",
309
307
  message: `Clipboard normalization failed: ${cause instanceof Error ? cause.message : String(cause)}`
310
308
  })
@@ -312,7 +310,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
312
310
  if (converted.isErr()) return converted;
313
311
  const blocks = [];
314
312
  for (const block of converted.value) {
315
- if (block.type !== "paragraph" && block.type !== "table" || clipboardParagraphs(block) === void 0) return refuseUnder(unplacedBlockGround(slice), "The clipboard contains an unsupported block.");
313
+ if (block.type !== "paragraph" && block.type !== "table" || clipboardParagraphs(block) === void 0) return refuse("The clipboard contains an unsupported block.", unplacedBlockGround(slice));
316
314
  blocks.push(cloneClipboardBlock(block));
317
315
  }
318
316
  const places = blocks.flatMap((block, index) => clipboardParagraphs(block, (next) => {
@@ -325,7 +323,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
325
323
  for (const table of tables) delete table.formatting?.styleId;
326
324
  }
327
325
  const overCells = state.selection instanceof CellSelection && pasteTarget === void 0 && moveSource === void 0 && moveTarget === void 0;
328
- if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.");
326
+ if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.", INVALID_CLIPBOARD);
329
327
  const selectionRange = overCells ? {
330
328
  from: state.selection.from,
331
329
  to: state.selection.to
@@ -365,7 +363,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
365
363
  visitParagraphRuns(paragraph, (run) => {
366
364
  if (run.content.some((child) => child.type === "drawing")) related = true;
367
365
  });
368
- if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.");
366
+ if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.", { gap: CANONICAL_GAP.storyContentProjection });
369
367
  }
370
368
  const destination = readModel(session.document);
371
369
  let styles = destination.package.styles;
@@ -379,7 +377,10 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
379
377
  annotationParagraphs,
380
378
  tableStyleIds: tables.flatMap(({ formatting }) => formatting?.styleId === void 0 ? [] : [formatting.styleId])
381
379
  });
382
- if (importedStyles.isErr()) return refuse(importedStyles.error.message);
380
+ if (importedStyles.isErr()) {
381
+ const { reason, message } = importedStyles.error;
382
+ return refuse(message, groundForDocumentOpRefusal(reason));
383
+ }
383
384
  styles = importedStyles.value.styles;
384
385
  for (const [index, place] of places.entries()) {
385
386
  const imported = importedStyles.value.paragraphs[index] ?? panic("An imported clipboard paragraph is missing.");
@@ -412,7 +413,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
412
413
  for (const style of styles.styles) {
413
414
  if (!importedStyleIds.has(style.styleId) || style.pPr?.numPr?.kind !== "reference") continue;
414
415
  const numId = importedNumbering.value.numIds.get(style.pPr.numPr.numId);
415
- if (numId === void 0) return refuse("A clipboard style numbering dependency could not be imported.");
416
+ if (numId === void 0) return refuse("A clipboard style numbering dependency could not be imported.", INVALID_CLIPBOARD);
416
417
  style.pPr.numPr = paragraphNumberingReference({
417
418
  numId,
418
419
  ...style.pPr.numPr.ilvl === void 0 ? {} : { ilvl: style.pPr.numPr.ilvl }
@@ -428,7 +429,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
428
429
  const source = previousId === void 0 ? void 0 : sourceDocument?.package.relationships?.get(previousId);
429
430
  let target = href;
430
431
  if (target === void 0 || target.length === 0) target = source?.targetMode === "External" ? source.target : void 0;
431
- if (target === void 0 || target.length === 0) return refuse("The clipboard hyperlink has no resolved target.");
432
+ if (target === void 0 || target.length === 0) return refuse("The clipboard hyperlink has no resolved target.", INVALID_CLIPBOARD);
432
433
  while (relationships.has(`rId${relationshipIndex}`)) relationshipIndex += 1;
433
434
  const id = `rId${relationshipIndex++}`;
434
435
  relationships.set(id, {
@@ -447,7 +448,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
447
448
  const parsed = Result.try({
448
449
  try: () => parseXml(xml, OOXML_NAMESPACE_SCOPE),
449
450
  catch: () => new CanonicalSessionError({
450
- ground: { gap: CANONICAL_GAP.dispatch },
451
+ ground: INVALID_CLIPBOARD,
451
452
  reason: "refused",
452
453
  message: "The clipboard hyperlink metadata is malformed."
453
454
  })
@@ -457,7 +458,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
457
458
  for (const name of Object.keys(element.attributes ?? {})) {
458
459
  const attribute = findAttributeByNamespaceUri(element, OFFICE_RELATIONSHIP_NAMESPACE_URIS, getLocalName(name));
459
460
  if (attribute === null || attribute.name !== name) continue;
460
- if (getLocalName(name) !== "id") return refuse("Clipboard hyperlink metadata references an unsupported package part.");
461
+ if (getLocalName(name) !== "id") return refuse("Clipboard hyperlink metadata references an unsupported package part.", INVALID_CLIPBOARD);
461
462
  let id = remapped.get(attribute.value);
462
463
  if (id === void 0) {
463
464
  const imported = importExternalLink(void 0, attribute.value);
@@ -500,7 +501,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
500
501
  if (plain) item.formatting = marksToTextFormatting(state.storedMarks ?? state.doc.resolve(pasteTarget ?? moveSource?.from ?? selectionRange.from).marks());
501
502
  for (const child of item.content) {
502
503
  if (child.type !== "drawing") continue;
503
- if (child.rawXmlMode !== void 0) return refuse("Opaque drawings and embedded objects require their source package parts.");
504
+ if (child.rawXmlMode !== void 0) return refuse("Opaque drawings and embedded objects require their source package parts.", { gap: CANONICAL_GAP.storyContentProjection });
504
505
  delete child.rawXml;
505
506
  delete child.rawImageFingerprint;
506
507
  const image = child.image;
@@ -538,9 +539,9 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
538
539
  const sourceRelationship = image.rId === void 0 ? void 0 : sourceDocument?.package.relationships?.get(image.rId);
539
540
  const sourcePath = sourceRelationship?.target.startsWith("/") ? sourceRelationship.target.slice(1) : `word/${sourceRelationship?.target ?? ""}`;
540
541
  const sourceMedia = sourceDocument?.package.media?.get(sourcePath);
541
- if (sourceMedia !== void 0 && sourceMedia.data.byteLength > MAX_CLIPBOARD_IMAGE_BYTES) return refuse("The clipboard image exceeds the import size limit.");
542
+ if (sourceMedia !== void 0 && sourceMedia.data.byteLength > MAX_CLIPBOARD_IMAGE_BYTES) return refuse("The clipboard image exceeds the import size limit.", INVALID_CLIPBOARD);
542
543
  const src = image.src ?? (sourceMedia === void 0 ? void 0 : bytesToDataUrl(new Uint8Array(sourceMedia.data), sourceMedia.mimeType)) ?? (sourceRelationship?.targetMode === "External" ? sourceRelationship.target : void 0);
543
- if (src === void 0) return refuse("The clipboard image has no source bytes or URL.");
544
+ if (src === void 0) return refuse("The clipboard image has no source bytes or URL.", INVALID_CLIPBOARD);
544
545
  image.src = src;
545
546
  while (relationships.has(`rId${relationshipIndex}`)) relationshipIndex += 1;
546
547
  const id = `rId${relationshipIndex++}`;
@@ -548,12 +549,12 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
548
549
  if (data !== null) {
549
550
  const mimeType = data.at(1);
550
551
  const payload = data.at(2);
551
- if (mimeType === void 0 || payload === void 0) return refuse("The clipboard image data is malformed.");
552
- if (payload.length > Math.ceil(MAX_CLIPBOARD_IMAGE_BYTES * 4 / 3)) return refuse("The clipboard image exceeds the import size limit.");
552
+ if (mimeType === void 0 || payload === void 0) return refuse("The clipboard image data is malformed.", INVALID_CLIPBOARD);
553
+ if (payload.length > Math.ceil(MAX_CLIPBOARD_IMAGE_BYTES * 4 / 3)) return refuse("The clipboard image exceeds the import size limit.", INVALID_CLIPBOARD);
553
554
  const decoded = Result.try({
554
555
  try: () => base64ToBytes(payload),
555
556
  catch: () => new CanonicalSessionError({
556
- ground: { gap: CANONICAL_GAP.dispatch },
557
+ ground: INVALID_CLIPBOARD,
557
558
  message: "The clipboard image data is malformed.",
558
559
  reason: "refused"
559
560
  })
@@ -579,9 +580,9 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
579
580
  target: src,
580
581
  targetMode: "External"
581
582
  });
582
- else return refuse("Clipboard images require image bytes or an HTTP image URL.");
583
+ else return refuse("Clipboard images require image bytes or an HTTP image URL.", INVALID_CLIPBOARD);
583
584
  const relationshipId = relationshipIdOf(id);
584
- if (relationshipId === void 0) return refuse("The clipboard image relationship id is invalid.");
585
+ if (relationshipId === void 0) return refuse("The clipboard image relationship id is invalid.", INVALID_CLIPBOARD);
585
586
  image.rId = relationshipId;
586
587
  delete image.id;
587
588
  importedResource = true;
@@ -650,7 +651,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
650
651
  resourceOps,
651
652
  semantic: "paste"
652
653
  });
653
- if (topParagraphs.length !== blocks.length) return refuseUnder({ gap: CANONICAL_GAP.trackedTableStructure }, "Moving a table by dragging requires a table move operation.");
654
+ if (topParagraphs.length !== blocks.length) return refuse("Moving a table by dragging requires a table move operation.", { gap: CANONICAL_GAP.trackedTableStructure });
654
655
  const target = session.projection.addressAt(moveTarget);
655
656
  if (target.isErr()) return target;
656
657
  return session.prepareIntents(state, {
@@ -11,7 +11,7 @@ type CompositionOptions = {
11
11
  semantic: "composition";
12
12
  compositionPhase?: "correction";
13
13
  }) => void;
14
- refuse: (reason: string, ground?: CanonicalRefusalGround) => void;
14
+ refuse: (reason: string, ground: CanonicalRefusalGround) => void;
15
15
  /**
16
16
  * The view shows provisional composition text, or the baseline again, that
17
17
  * no commit published: it needs a layout pass but changes no document.
@@ -1,10 +1,10 @@
1
1
  import { splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
2
2
  import { CanonicalSessionError } from "../canonical/canonicalSession.js";
3
- import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
3
+ import { CANONICAL_CONDITION, CANONICAL_GAP } from "../types/canonicalCapabilities.js";
4
4
  import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
5
5
  import { Result } from "better-result";
6
- import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
7
6
  import { EditorState, TextSelection } from "prosemirror-state";
7
+ import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
8
8
  // src/controller/canonicalComposition.ts
9
9
  /** A composition over content the session cannot project, restored. */
10
10
  const UNSUPPORTED_COMPOSITION = { gap: CANONICAL_GAP.storyContentProjection };
@@ -232,7 +232,7 @@ const createCanonicalComposition = (options) => {
232
232
  const applyNative = (view, transaction) => Result.try({
233
233
  try: () => view.state.applyTransaction(transaction),
234
234
  catch: (cause) => new CanonicalSessionError({
235
- ground: { gap: CANONICAL_GAP.dispatch },
235
+ ground: { condition: CANONICAL_CONDITION.internal },
236
236
  reason: "refused",
237
237
  message: `Composition projection failed: ${String(cause)}`
238
238
  })
@@ -419,7 +419,7 @@ const createCanonicalComposition = (options) => {
419
419
  const input = applied.isOk() ? replacement(baseline, applied.value.state) : null;
420
420
  if (applied.isErr() || !input || input.from < final.receipt.from || input.to > final.receipt.to || selectedText(baseline, applied.value.state) !== final.text) {
421
421
  view.updateState(final.receipt.state);
422
- options.refuse(applied.isErr() ? applied.error.message : "Final composition changed unsupported content; the canonical document was restored.");
422
+ options.refuse(applied.isErr() ? applied.error.message : "Final composition changed unsupported content; the canonical document was restored.", applied.isErr() ? applied.error.ground : UNSUPPORTED_COMPOSITION);
423
423
  return true;
424
424
  }
425
425
  if (final.receipt.text !== final.text) options.replace({
@@ -452,7 +452,7 @@ const createCanonicalComposition = (options) => {
452
452
  return true;
453
453
  }
454
454
  if (typeof transaction.getMeta("composition") !== "number" && authorizedNativeState !== view.state) {
455
- options.refuse("Other edits must wait until composition finishes.");
455
+ options.refuse("Other edits must wait until composition finishes.", { condition: CANONICAL_CONDITION.composing });
456
456
  return true;
457
457
  }
458
458
  authorizedNativeState = null;
@@ -466,7 +466,7 @@ const createCanonicalComposition = (options) => {
466
466
  phase: state.phase,
467
467
  text: selectedText(state.baseline, transaction)
468
468
  };
469
- options.refuse(applied.error.message);
469
+ options.refuse(applied.error.message, applied.error.ground);
470
470
  return true;
471
471
  }
472
472
  if (!replacement(state.baseline, applied.value.state)) {
@@ -21,9 +21,11 @@ type ReplaceTextInput = {
21
21
  semantic?: "typing" | "deleteBackward" | "deleteForward";
22
22
  compositionPhase?: never;
23
23
  });
24
+ /** A paragraph structure edit a key asks for. */
25
+ export type CanonicalStructureInput = "split" | "joinBackward" | "joinForward" | "lineBreak" | "pageBreak" | "tab" | "indent" | "outdent" | "deleteTable";
24
26
  type CanonicalInputOptions = {
25
27
  replace: (input: ReplaceTextInput) => void;
26
- structure?: (type: "split" | "joinBackward" | "joinForward" | "lineBreak" | "pageBreak" | "tab" | "indent" | "outdent" | "deleteTable") => void;
28
+ structure?: (type: CanonicalStructureInput) => void;
27
29
  command?: (name: "toggleBold" | "toggleItalic" | "toggleUnderline") => void;
28
30
  breakUndoGroup?: () => void;
29
31
  beginComposition?: () => boolean;
@@ -34,7 +36,7 @@ type CanonicalInputOptions = {
34
36
  cut?: (view: EditorView, event: ClipboardEvent) => boolean;
35
37
  undo: () => boolean;
36
38
  redo: () => boolean;
37
- refuse: (reason: string, ground?: CanonicalRefusalGround) => void;
39
+ refuse: (reason: string, ground: CanonicalRefusalGround) => void;
38
40
  };
39
41
  export declare const createCanonicalInputBoundary: (options: CanonicalInputOptions) => {
40
42
  reset: () => void;
@@ -1,11 +1,20 @@
1
1
  import { deletionRange, isCanonicalJoinBoundary, measuredDeletionRange } from "../canonical/canonicalSession.js";
2
2
  import { textCaretOf } from "../prosemirror/nativeSelection.js";
3
3
  import { getEditorInputTargetRange, handleEditorBeforeInput } from "../prosemirror/textInput.js";
4
+ import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
4
5
  import { createCanonicalComposition } from "./canonicalComposition.js";
6
+ import { Selection, TextSelection } from "prosemirror-state";
5
7
  import { CellSelection } from "prosemirror-tables";
6
8
  import { ReplaceStep } from "prosemirror-transform";
7
- import { Selection, TextSelection } from "prosemirror-state";
8
9
  // src/controller/canonicalInput.ts
10
+ const INVALID_REQUEST = { condition: CANONICAL_CONDITION.invalidRequest };
11
+ const COMPOSING = { condition: CANONICAL_CONDITION.composing };
12
+ /**
13
+ * A boundary built without a structure or cut handler. Every editor folio
14
+ * builds, the body and each header, footer and note, gives it both; one built
15
+ * without them takes no such edit.
16
+ */
17
+ const NO_HANDLER = INVALID_REQUEST;
9
18
  /** Deletions whose extent the browser measures: by word or by line. */
10
19
  const WORD_AND_LINE_DELETIONS = /* @__PURE__ */ new Set([
11
20
  "deleteWordBackward",
@@ -54,6 +63,12 @@ const unclassifiedMutationMessage = (transactions, unnamed = "Unclassified nativ
54
63
  const keys = [...new Set(transactions.filter(({ docChanged }) => docChanged).flatMap(transactionMetaKeys))];
55
64
  return keys.length === 0 ? unnamed : `A transaction with meta ${keys.join(", ")} changed the document outside the session's operations; express the edit as document operations.`;
56
65
  };
66
+ /**
67
+ * The ground of such a refusal: a transaction a plugin or a host named changed
68
+ * the document outside document operations; native text no classifier reads
69
+ * is not an input the session takes.
70
+ */
71
+ const unclassifiedMutationGround = (transactions) => transactions.some((transaction) => transaction.docChanged && transactionMetaKeys(transaction).length > 0) ? { condition: CANONICAL_CONDITION.hostTransaction } : INVALID_REQUEST;
57
72
  const CANONICAL_COMPOSITION_INPUT_TYPES = [
58
73
  "insertCompositionText",
59
74
  "insertFromComposition",
@@ -102,22 +117,24 @@ const createCanonicalInputBoundary = (options) => {
102
117
  if (!view.isDestroyed) view.updateState(view.state);
103
118
  });
104
119
  };
105
- const refuseEvent = (event, reason) => {
120
+ const refuseEvent = (event, reason, ground) => {
106
121
  event.preventDefault();
107
122
  closeGroup();
108
- if (!composition.active && proposal.type !== "refused") options.refuse(reason);
123
+ if (!composition.active && proposal.type !== "refused") options.refuse(reason, ground);
109
124
  if (!composition.active) proposal = { type: "refused" };
110
125
  return true;
111
126
  };
127
+ /** A clipboard gesture made while a composition is in progress. */
112
128
  const refuseClipboardGesture = (event, reason) => {
113
129
  event.preventDefault();
114
130
  closeGroup();
115
- options.refuse(reason);
131
+ options.refuse(reason, COMPOSING);
116
132
  return true;
117
133
  };
118
134
  const refuseNativeMutation = (view, transaction) => {
119
135
  if (!composition.active && proposal.type !== "refused") {
120
- options.refuse(unclassifiedMutationMessage(transaction ? [transaction] : []));
136
+ const transactions = transaction ? [transaction] : [];
137
+ options.refuse(unclassifiedMutationMessage(transactions), unclassifiedMutationGround(transactions));
121
138
  proposal = { type: "refused" };
122
139
  }
123
140
  repaint(view);
@@ -242,10 +259,10 @@ const createCanonicalInputBoundary = (options) => {
242
259
  return true;
243
260
  }
244
261
  if (event.key === "Enter") {
245
- if (view.composing) return refuseEvent(event, "Paragraph structure edits are unavailable during composition.");
262
+ if (view.composing) return refuseEvent(event, "Paragraph structure edits are unavailable during composition.", COMPOSING);
246
263
  event.preventDefault();
247
264
  closeGroup();
248
- if (options.structure === void 0) return refuseEvent(event, "Paragraph structure edits are unavailable in this session.");
265
+ if (options.structure === void 0) return refuseEvent(event, "Paragraph structure edits are unavailable in this session.", NO_HANDLER);
249
266
  if (modifier) options.structure("pageBreak");
250
267
  else options.structure(event.shiftKey ? "lineBreak" : "split");
251
268
  return true;
@@ -260,7 +277,7 @@ const createCanonicalInputBoundary = (options) => {
260
277
  if (view.composing || composition.active) {
261
278
  event.preventDefault();
262
279
  closeGroup();
263
- if (!composition.active) options.refuse("Only plain character deletion is available in this session.");
280
+ if (!composition.active) options.refuse("Only plain character deletion is available in this session.", COMPOSING);
264
281
  return true;
265
282
  }
266
283
  const selection = view.state.selection;
@@ -278,7 +295,7 @@ const createCanonicalInputBoundary = (options) => {
278
295
  const range = deletionRange(view.state, event.key === "Backspace" ? "backward" : "forward");
279
296
  if (range.isErr()) {
280
297
  closeGroup();
281
- options.refuse(range.error.message);
298
+ options.refuse(range.error.message, range.error.ground);
282
299
  } else options.replace({
283
300
  ...range.value,
284
301
  text: "",
@@ -333,7 +350,7 @@ const createCanonicalInputBoundary = (options) => {
333
350
  return false;
334
351
  }
335
352
  if (event.inputType === "insertFromComposition" && composition.authorizeLateFinal(view, event.data)) return false;
336
- return refuseEvent(event, "Composition has no captured canonical baseline.");
353
+ return refuseEvent(event, "Composition has no captured canonical baseline.", { condition: CANONICAL_CONDITION.internal });
337
354
  }
338
355
  if (composition.active) {
339
356
  if (view.composing && (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward")) {
@@ -376,12 +393,12 @@ const createCanonicalInputBoundary = (options) => {
376
393
  };
377
394
  try {
378
395
  if (handleEditorBeforeInput(view, event)) return true;
379
- return refuseEvent(event, "This native replacement cannot be addressed safely.");
396
+ return refuseEvent(event, "This native replacement cannot be addressed safely.", INVALID_REQUEST);
380
397
  } finally {
381
398
  authorizedInput = null;
382
399
  }
383
400
  }
384
- if (event.inputType !== "insertText" || event.data === null) return refuseEvent(event, "This native replacement cannot be addressed safely.");
401
+ if (event.inputType !== "insertText" || event.data === null) return refuseEvent(event, "This native replacement cannot be addressed safely.", INVALID_REQUEST);
385
402
  proposal = {
386
403
  type: "replacement",
387
404
  state: view.state,
@@ -410,7 +427,7 @@ const createCanonicalInputBoundary = (options) => {
410
427
  return true;
411
428
  }
412
429
  const range = deletionRange(view.state, event.inputType === "deleteContentBackward" ? "backward" : "forward");
413
- if (range.isErr()) return refuseEvent(event, range.error.message);
430
+ if (range.isErr()) return refuseEvent(event, range.error.message, range.error.ground);
414
431
  const input = {
415
432
  ...range.value,
416
433
  text: "",
@@ -430,9 +447,9 @@ const createCanonicalInputBoundary = (options) => {
430
447
  }
431
448
  if (WORD_AND_LINE_DELETIONS.has(event.inputType)) {
432
449
  const measured = browserTargetRange(view, event);
433
- if (measured === void 0) return refuseEvent(event, "The browser named no range for this deletion.");
450
+ if (measured === void 0) return refuseEvent(event, "The browser named no range for this deletion.", INVALID_REQUEST);
434
451
  const range = measuredDeletionRange(view.state, measured);
435
- if (range.isErr()) return refuseEvent(event, range.error.message);
452
+ if (range.isErr()) return refuseEvent(event, range.error.message, range.error.ground);
436
453
  closeGroup();
437
454
  if (range.value === null) {
438
455
  event.preventDefault();
@@ -461,7 +478,7 @@ const createCanonicalInputBoundary = (options) => {
461
478
  else options.redo();
462
479
  return true;
463
480
  }
464
- return refuseEvent(event, `Input ${event.inputType} is unavailable in this session.`);
481
+ return refuseEvent(event, `Input ${event.inputType} is unavailable in this session.`, INVALID_REQUEST);
465
482
  },
466
483
  input: (view) => {
467
484
  if (composition.active || composition.pendingFinal) {
@@ -489,7 +506,7 @@ const createCanonicalInputBoundary = (options) => {
489
506
  closeGroup();
490
507
  return options.cut(view, event);
491
508
  }
492
- return refuseEvent(event, "The canonical clipboard owner is unavailable.");
509
+ return refuseEvent(event, "The canonical clipboard owner is unavailable.", NO_HANDLER);
493
510
  },
494
511
  drop: (_view, event) => {
495
512
  beginGesture();
@@ -1,6 +1,6 @@
1
1
  import { remapSelection } from "../canonical/canonicalRemoteHistory.js";
2
- import { OP_STORIES } from "@stll/docx-core/ops";
3
2
  import * as v from "valibot";
3
+ import { OP_STORIES } from "@stll/docx-core/ops";
4
4
  // src/controller/canonicalPresence.ts
5
5
  const COUNT = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
6
6
  const STORY = v.union([
@@ -1,6 +1,6 @@
1
1
  import { Result, TaggedError } from "better-result";
2
- import { DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_SCHEMA_VERSION, ID_LEASE_KINDS, createSequencer, validateSequencedBatch } from "@stll/docx-core/ops";
3
2
  import * as v from "valibot";
3
+ import { DEFAULT_ID_BLOCK_SIZES, DOCUMENT_OP_SCHEMA_VERSION, ID_LEASE_KINDS, createSequencer, validateSequencedBatch } from "@stll/docx-core/ops";
4
4
  // src/controller/canonicalRoomAuthority.ts
5
5
  const CanonicalRoomAuthorityErrorBase = TaggedError("CanonicalRoomAuthorityError");
6
6
  /**