@stll/folio-core 0.74.0 → 0.76.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 (174) 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 +7 -3
  4. package/dist/ai-edits/headless.js +36 -21
  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 +135 -90
  9. package/dist/ai-edits/pendingJoin.d.ts +5 -1
  10. package/dist/ai-edits/pendingJoin.js +6 -2
  11. package/dist/ai-edits/read.js +9 -3
  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/tracked-batch-fidelity.d.ts +6 -10
  15. package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
  16. package/dist/ai-edits/types.d.ts +9 -4
  17. package/dist/canonical/batchCommentReferences.js +2 -1
  18. package/dist/canonical/canonicalBatchReview.d.ts +4 -1
  19. package/dist/canonical/canonicalBatchReview.js +37 -22
  20. package/dist/canonical/canonicalComments.d.ts +6 -2
  21. package/dist/canonical/canonicalComments.js +16 -6
  22. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  23. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  24. package/dist/canonical/canonicalPublicOperations.js +231 -79
  25. package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
  26. package/dist/canonical/canonicalRefusalGrounds.js +56 -0
  27. package/dist/canonical/canonicalSession.d.ts +12 -6
  28. package/dist/canonical/canonicalSession.js +119 -122
  29. package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
  30. package/dist/compare/inline-atoms.d.ts +35 -41
  31. package/dist/compare/inline-atoms.js +2 -465
  32. package/dist/compare/section-boundary-properties.d.ts +3 -30
  33. package/dist/compare/section-boundary-properties.js +4 -72
  34. package/dist/controller/canonicalClipboard.d.ts +1 -1
  35. package/dist/controller/canonicalClipboard.js +110 -55
  36. package/dist/controller/canonicalComposition.d.ts +1 -1
  37. package/dist/controller/canonicalComposition.js +5 -5
  38. package/dist/controller/canonicalContentControlValue.js +7 -7
  39. package/dist/controller/canonicalInput.d.ts +4 -2
  40. package/dist/controller/canonicalInput.js +33 -16
  41. package/dist/controller/canonicalReview.d.ts +21 -0
  42. package/dist/controller/canonicalReview.js +44 -9
  43. package/dist/controller/canonicalStoryEditor.d.ts +2 -3
  44. package/dist/controller/canonicalStoryEditor.js +43 -25
  45. package/dist/controller/canonicalStructure.d.ts +19 -3
  46. package/dist/controller/canonicalStructure.js +182 -58
  47. package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
  48. package/dist/controller/deferredDisplayListPainter.js +34 -0
  49. package/dist/controller/folioEditor.js +4 -2
  50. package/dist/controller/fontReadiness.js +50 -23
  51. package/dist/controller/headerFooterEditorManager.js +3 -17
  52. package/dist/controller/hiddenEditorApi.d.ts +24 -3
  53. package/dist/controller/hiddenEditorApi.js +2 -0
  54. package/dist/controller/hiddenEditorManager.js +135 -207
  55. package/dist/controller/layoutPipeline.d.ts +4 -86
  56. package/dist/controller/layoutPipeline.js +8 -727
  57. package/dist/controller/layoutPipelineExecution.d.ts +94 -0
  58. package/dist/controller/layoutPipelineExecution.js +730 -0
  59. package/dist/controller/noteEditorManager.js +3 -16
  60. package/dist/docx/blockContentParser.d.ts +1 -3
  61. package/dist/docx/blockContentParser.js +3 -10
  62. package/dist/docx/bulletMarkers.d.ts +8 -0
  63. package/dist/docx/bulletMarkers.js +9 -1
  64. package/dist/docx/canonicalSave.d.ts +4 -3
  65. package/dist/docx/canonicalSave.js +4 -3
  66. package/dist/docx/canonicalSessionInput.js +25 -11
  67. package/dist/docx/ensureParaIds.d.ts +31 -0
  68. package/dist/docx/ensureParaIds.js +57 -32
  69. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  70. package/dist/docx/ensureUniqueControlIds.js +47 -29
  71. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  72. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  73. package/dist/docx/listMarkerComputation.d.ts +24 -17
  74. package/dist/docx/listMarkerComputation.js +31 -60
  75. package/dist/docx/listModelNormalization.js +8 -15
  76. package/dist/docx/rezip.d.ts +16 -3
  77. package/dist/docx/rezip.js +35 -9
  78. package/dist/docx/selectiveSave.js +13 -5
  79. package/dist/docx/server/templatePlan/apply.js +96 -7
  80. package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
  81. package/dist/docx/server/templatePlan/blocks.js +272 -10
  82. package/dist/docx/server/templatePlan/builders.d.ts +52 -2
  83. package/dist/docx/server/templatePlan/builders.js +224 -5
  84. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  85. package/dist/docx/server/templatePlan/effects.js +188 -0
  86. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  87. package/dist/docx/server/templatePlan/emit.js +46 -2
  88. package/dist/docx/server/templatePlan/inspect.js +39 -52
  89. package/dist/docx/server/templatePlan/labels.d.ts +7 -2
  90. package/dist/docx/server/templatePlan/labels.js +120 -23
  91. package/dist/docx/server/templatePlan/plan.d.ts +24 -3
  92. package/dist/docx/server/templatePlan/plan.js +54 -15
  93. package/dist/docx/server/templatePlan/planShape.js +76 -22
  94. package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
  95. package/dist/docx/server/templatePlan/revisions.js +407 -0
  96. package/dist/docx/server/templatePlan/story.d.ts +23 -1
  97. package/dist/docx/server/templatePlan/story.js +60 -2
  98. package/dist/docx/server/templatePlan/types.d.ts +354 -16
  99. package/dist/docx/server/templatePlan/verify.js +164 -14
  100. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  101. package/dist/docx/server/templatePlan/xml.js +4 -1
  102. package/dist/i18n/messages/ar.gen.js +1 -0
  103. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  104. package/dist/i18n/messages/catalogs.gen.js +17 -0
  105. package/dist/i18n/messages/cs.gen.js +1 -0
  106. package/dist/i18n/messages/de.gen.js +1 -0
  107. package/dist/i18n/messages/en.gen.js +1 -0
  108. package/dist/i18n/messages/es.gen.js +1 -0
  109. package/dist/i18n/messages/et.gen.js +1 -0
  110. package/dist/i18n/messages/fr.gen.js +1 -0
  111. package/dist/i18n/messages/he.gen.js +1 -0
  112. package/dist/i18n/messages/hi.gen.js +1 -0
  113. package/dist/i18n/messages/hu.gen.js +1 -0
  114. package/dist/i18n/messages/lt.gen.js +1 -0
  115. package/dist/i18n/messages/lv.gen.js +1 -0
  116. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  117. package/dist/i18n/messages/pl.gen.js +1 -0
  118. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  119. package/dist/i18n/messages/sk.gen.js +1 -0
  120. package/dist/i18n/messages/tr.gen.js +1 -0
  121. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  122. package/dist/internal/revisionResolutionStep.d.ts +2 -31
  123. package/dist/internal/revisionResolutionStep.js +2 -171
  124. package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
  125. package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
  126. package/dist/prosemirror/commands/comments.d.ts +6 -234
  127. package/dist/prosemirror/commands/comments.js +5 -2464
  128. package/dist/prosemirror/commands/index.d.ts +4 -2
  129. package/dist/prosemirror/commands/index.js +4 -2
  130. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
  131. package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
  132. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
  133. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  134. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  135. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  136. package/dist/prosemirror/listMarker.d.ts +1 -6
  137. package/dist/prosemirror/listMarker.js +4 -56
  138. package/dist/prosemirror/paraIds.d.ts +1 -14
  139. package/dist/prosemirror/paraIds.js +1 -14
  140. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  141. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  142. package/dist/prosemirror/projectionReview.d.ts +49 -0
  143. package/dist/prosemirror/projectionReview.js +292 -0
  144. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  145. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  146. package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
  147. package/dist/prosemirror/replacedAnnotations.js +1 -10
  148. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  149. package/dist/prosemirror/revisionCarriers.js +15 -1
  150. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  151. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  152. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  153. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  154. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  155. package/dist/prosemirror/suggestionQueries.js +320 -0
  156. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  157. package/dist/prosemirror/tableGridMutation.js +1 -78
  158. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  159. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  160. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  161. package/dist/server.d.ts +2 -2
  162. package/dist/types/canonicalCapabilities.d.ts +40 -69
  163. package/dist/types/canonicalCapabilities.js +51 -65
  164. package/dist/types/canonicalComments.d.ts +2 -2
  165. package/dist/types/canonicalSections.d.ts +2 -2
  166. package/dist/utils/clipboard.d.ts +2 -28
  167. package/dist/utils/clipboard.js +1 -96
  168. package/dist/utils/clipboardFiles.d.ts +27 -0
  169. package/dist/utils/clipboardFiles.js +98 -0
  170. package/dist/utils/rulerControl.d.ts +1 -0
  171. package/dist/utils/rulerControl.js +2 -1
  172. package/package.json +2 -2
  173. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  174. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
@@ -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 };
@@ -29,5 +29,5 @@ type PrepareCanonicalPasteOptions = {
29
29
  to: number;
30
30
  };
31
31
  };
32
- export declare const prepareCanonicalPaste: ({ session, state, slice, plain, moveTarget, pasteTarget, sourceDocument, moveSource }: PrepareCanonicalPasteOptions) => Result<CanonicalCommit, CanonicalSessionError>;
32
+ export declare const prepareCanonicalPaste: ({ session, state, slice: copied, plain, moveTarget, pasteTarget, sourceDocument, moveSource }: PrepareCanonicalPasteOptions) => Result<CanonicalCommit, CanonicalSessionError>;
33
33
  export {};
@@ -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,7 +9,8 @@ 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 { pastedCells } from "../prosemirror/tableCellPaste.js";
13
+ import { CANONICAL_CONDITION, CANONICAL_GAP } from "../types/canonicalCapabilities.js";
12
14
  import { readModel } from "../types/documentModel.js";
13
15
  import { bytesToDataUrl } from "../utils/base64.js";
14
16
  import { base64ToBytes } from "../utils/textEncoding.js";
@@ -16,31 +18,73 @@ import { flattenClipboardStyleReferences, importClipboardStyles } from "./canoni
16
18
  import { Result, panic } from "better-result";
17
19
  import { NUMBER_FORMATS, paragraphNumberingReference, relationshipIdOf } from "@stll/docx-core/model";
18
20
  import { packageResourcesOpOf } from "@stll/docx-core/ops";
19
- import { CellSelection } from "prosemirror-tables";
21
+ import { CellSelection, tableNodeTypes } from "prosemirror-tables";
20
22
  import { Fragment, Slice } from "prosemirror-model";
21
23
  // 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({
24
+ /** A refusal under the gap, rule or condition it belongs to. */
25
+ const refuse = (message, ground) => Result.err(new CanonicalSessionError({
29
26
  ground,
30
27
  message,
31
28
  reason: "refused"
32
29
  }));
30
+ /** Clipboard content the paste cannot read or resolve as given. */
31
+ const INVALID_CLIPBOARD = { condition: CANONICAL_CONDITION.invalidRequest };
33
32
  /**
34
- * The gap a clipboard block the paste cannot place falls under: a table's,
35
- * or for any other block, the story content the session cannot project.
33
+ * The gap a clipboard block the paste cannot place falls under: a block
34
+ * other than a paragraph or a table, at the top or in a cell, is story
35
+ * content the session cannot project.
36
36
  */
37
- const unplacedBlockGround = (slice) => {
38
- let table = false;
39
- slice.content.descendants((node) => {
40
- if (node.type.name === "table") table = true;
41
- return !table;
42
- });
43
- return { gap: table ? CANONICAL_GAP.trackedTableStructure : CANONICAL_GAP.storyContentProjection };
37
+ const UNPLACED_BLOCK = { gap: CANONICAL_GAP.storyContentProjection };
38
+ const tableRole = (node) => node?.type.spec["tableRole"];
39
+ /**
40
+ * A table the clipboard holds part of, opened `left` levels deep at its start
41
+ * and `right` at its end, as the table of the cells it holds: a first or last
42
+ * row cut short keeps the cells copied and is filled out with empty ones.
43
+ * Undefined when the part holds no cells.
44
+ */
45
+ const closedTable = (table, left, right) => {
46
+ if (left <= 1 && right <= 1) return table;
47
+ const cells = pastedCells(new Slice(Fragment.from(table), left, right));
48
+ if (cells === null) return void 0;
49
+ const rowType = tableNodeTypes(table.type.schema).row;
50
+ return table.type.create(table.attrs, cells.rows.map((row, index) => rowType.create(index < table.childCount ? table.child(index).attrs : null, row)), table.marks);
51
+ };
52
+ /**
53
+ * A slice that opens or closes inside a table, its edges closed at the table:
54
+ * it pastes the table of the cells it holds, as a selection of cells pastes.
55
+ * Selected cells, rows or cells without their table, paste as a table
56
+ * of their own. The slice is returned as given when no table edge is open,
57
+ * and undefined when an open table edge holds no cells.
58
+ */
59
+ const withClosedTableEdges = (slice) => {
60
+ const { content } = slice;
61
+ const first = content.firstChild;
62
+ const last = content.lastChild;
63
+ const role = tableRole(first);
64
+ if (role === "row" || role === "cell" || role === "header_cell") {
65
+ if (first === null) return slice;
66
+ const cells = pastedCells(slice);
67
+ if (cells === null) return void 0;
68
+ const { table, row } = tableNodeTypes(first.type.schema);
69
+ return new Slice(Fragment.from(table.create(null, cells.rows.map((cellsOfRow) => row.create(null, cellsOfRow)))), 0, 0);
70
+ }
71
+ const opensTable = slice.openStart > 1 && tableRole(first) === "table";
72
+ const closesTable = slice.openEnd > 1 && tableRole(last) === "table";
73
+ if (!opensTable && !closesTable) return slice;
74
+ const blocks = [];
75
+ content.forEach((node) => blocks.push(node));
76
+ const lastIndex = blocks.length - 1;
77
+ const edges = /* @__PURE__ */ new Set();
78
+ if (opensTable) edges.add(0);
79
+ if (closesTable) edges.add(lastIndex);
80
+ for (const index of edges) {
81
+ const node = blocks[index];
82
+ if (node === void 0) continue;
83
+ const closed = closedTable(node, opensTable && index === 0 ? slice.openStart : 0, closesTable && index === lastIndex ? slice.openEnd : 0);
84
+ if (closed === void 0) return void 0;
85
+ blocks[index] = closed;
86
+ }
87
+ return new Slice(Fragment.from(blocks), opensTable ? 1 : slice.openStart, closesTable ? 1 : slice.openEnd);
44
88
  };
45
89
  /**
46
90
  * A pasted block's paragraphs in document order, a table's cell paragraphs
@@ -133,9 +177,9 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
133
177
  numbering: destination,
134
178
  numIds: /* @__PURE__ */ new Map()
135
179
  });
136
- if (source === void 0) return refuse("The clipboard list has no numbering definition.");
180
+ if (source === void 0) return refuse("The clipboard list has no numbering definition.", INVALID_CLIPBOARD);
137
181
  const sourceDefinitions = source;
138
- if (references.some((id) => !sourceDefinitions.nums.some(({ numId }) => numId === id))) return refuse("The clipboard list has no numbering definition.");
182
+ if (references.some((id) => !sourceDefinitions.nums.some(({ numId }) => numId === id))) return refuse("The clipboard list has no numbering definition.", INVALID_CLIPBOARD);
139
183
  const used = new Set(references);
140
184
  const sourceNums = source.nums.filter(({ numId }) => used.has(numId));
141
185
  const usedAbstracts = new Set(sourceNums.map(({ abstractNumId }) => abstractNumId));
@@ -149,9 +193,9 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
149
193
  if (rendering === void 0) continue;
150
194
  const instance = source.nums.find(({ numId }) => numId === rendering.numId);
151
195
  const definition = source.abstractNums.find(({ abstractNumId }) => abstractNumId === instance?.abstractNumId);
152
- if (definition === void 0) return refuse("The clipboard list has no abstract definition.");
196
+ if (definition === void 0) return refuse("The clipboard list has no abstract definition.", INVALID_CLIPBOARD);
153
197
  const level = definition.levels.find(({ ilvl }) => ilvl === rendering.level);
154
- if (level === void 0) return refuse("The clipboard list level could not be imported.");
198
+ if (level === void 0) return refuse("The clipboard list level could not be imported.", INVALID_CLIPBOARD);
155
199
  Object.assign(level, {
156
200
  ...numberFormatFields(rendering.numFmt ?? (rendering.isBullet ? "bullet" : "decimal")),
157
201
  lvlText: rendering.markerTemplate ?? rendering.marker,
@@ -180,7 +224,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
180
224
  for (const formatting of formats) {
181
225
  if (formatting?.numPr?.kind !== "reference") continue;
182
226
  const numId = nums.get(formatting.numPr.numId);
183
- if (numId === void 0) return refuse("The clipboard list instance could not be imported.");
227
+ if (numId === void 0) return refuse("The clipboard list instance could not be imported.", INVALID_CLIPBOARD);
184
228
  formatting.numPr = paragraphNumberingReference({
185
229
  numId,
186
230
  ...formatting.numPr.ilvl === void 0 ? {} : { ilvl: formatting.numPr.ilvl }
@@ -200,7 +244,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
200
244
  for (const instance of source.nums) {
201
245
  const numId = nums.get(instance.numId);
202
246
  const abstractNumId = abstracts.get(instance.abstractNumId);
203
- if (numId === void 0 || abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.");
247
+ if (numId === void 0 || abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.", INVALID_CLIPBOARD);
204
248
  const imported = {
205
249
  ...instance,
206
250
  numId,
@@ -209,7 +253,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
209
253
  for (const override of imported.levelOverrides ?? []) {
210
254
  if (override.lvl?.pStyle === void 0 || styleIds === void 0) continue;
211
255
  const mapped = styleIds.get(override.lvl.pStyle);
212
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
256
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
213
257
  override.lvl.pStyle = mapped;
214
258
  }
215
259
  importedNums.push(imported);
@@ -217,7 +261,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
217
261
  const importedAbstracts = [];
218
262
  for (const definition of source.abstractNums) {
219
263
  const abstractNumId = abstracts.get(definition.abstractNumId);
220
- if (abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.");
264
+ if (abstractNumId === void 0) return refuse("The clipboard numbering definition could not be imported.", INVALID_CLIPBOARD);
221
265
  const imported = {
222
266
  ...definition,
223
267
  abstractNumId
@@ -225,18 +269,18 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
225
269
  if (styleIds !== void 0) {
226
270
  if (imported.numStyleLink !== void 0) {
227
271
  const mapped = styleIds.get(imported.numStyleLink);
228
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
272
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
229
273
  imported.numStyleLink = mapped;
230
274
  }
231
275
  if (imported.styleLink !== void 0) {
232
276
  const mapped = styleIds.get(imported.styleLink);
233
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
277
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
234
278
  imported.styleLink = mapped;
235
279
  }
236
280
  for (const level of imported.levels) {
237
281
  if (level.pStyle === void 0) continue;
238
282
  const mapped = styleIds.get(level.pStyle);
239
- if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.");
283
+ if (mapped === void 0) return refuse("A clipboard numbering style dependency could not be imported.", INVALID_CLIPBOARD);
240
284
  level.pStyle = mapped;
241
285
  }
242
286
  }
@@ -282,16 +326,18 @@ const clipboardAnnotations = ({ paragraphs, source }) => {
282
326
  if (annotations.notes.length !== notes.size || annotations.comments.length !== comments.size) return refusal("A clipboard comment or note reference names none in the document it was copied from.");
283
327
  return Result.ok(annotations);
284
328
  };
285
- const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
286
- if (session.isComposing) return refuse("Composition must finish before using the clipboard.");
287
- if (slice.content.size === 0) return Result.err(new CanonicalSessionError({
288
- ground: { gap: CANONICAL_GAP.dispatch },
329
+ const prepareCanonicalPaste = ({ session, state, slice: copied, plain = false, moveTarget, pasteTarget, sourceDocument, moveSource }) => {
330
+ if (session.isComposing) return refuse("Composition must finish before using the clipboard.", { condition: CANONICAL_CONDITION.composing });
331
+ if (copied.content.size === 0) return Result.err(new CanonicalSessionError({
332
+ ground: INVALID_CLIPBOARD,
289
333
  message: "The clipboard contains no content.",
290
334
  reason: "noChange"
291
335
  }));
292
- if (slice.openStart > 1 || slice.openEnd > 1) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and nested block containers require canonical table editing.");
336
+ const slice = withClosedTableEdges(copied);
337
+ if (slice === void 0) return refuse("The clipboard table holds no cells.", INVALID_CLIPBOARD);
338
+ if (slice.openStart > 1 || slice.openEnd > 1) return refuse("Clipboard tables and nested block containers require canonical table editing.", UNPLACED_BLOCK);
293
339
  const paragraphType = state.schema.nodes["paragraph"];
294
- if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.");
340
+ if (paragraphType === void 0) return refuse("Clipboard input requires a paragraph schema.", { condition: CANONICAL_CONDITION.internal });
295
341
  const tableType = state.schema.nodes["table"];
296
342
  let inline = true;
297
343
  let blocksOnly = true;
@@ -299,12 +345,12 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
299
345
  inline &&= node.isInline;
300
346
  blocksOnly &&= node.type === paragraphType || node.type === tableType;
301
347
  });
302
- if (!inline && !blocksOnly) return refuseUnder(unplacedBlockGround(slice), "Clipboard tables and embedded blocks require canonical table editing.");
348
+ if (!inline && !blocksOnly) return refuse("Clipboard tables and embedded blocks require canonical table editing.", UNPLACED_BLOCK);
303
349
  const importedSlice = inline ? new Slice(Fragment.from(paragraphType.create(null, slice.content)), 1, 1) : slice;
304
350
  const converted = Result.try({
305
351
  try: () => proseDocToBlocks(state.schema.topNodeType.create(null, importedSlice.content), []),
306
352
  catch: (cause) => new CanonicalSessionError({
307
- ground: { gap: CANONICAL_GAP.dispatch },
353
+ ground: INVALID_CLIPBOARD,
308
354
  reason: "refused",
309
355
  message: `Clipboard normalization failed: ${cause instanceof Error ? cause.message : String(cause)}`
310
356
  })
@@ -312,7 +358,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
312
358
  if (converted.isErr()) return converted;
313
359
  const blocks = [];
314
360
  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.");
361
+ if (block.type !== "paragraph" && block.type !== "table" || clipboardParagraphs(block) === void 0) return refuse("The clipboard contains an unsupported block.", UNPLACED_BLOCK);
316
362
  blocks.push(cloneClipboardBlock(block));
317
363
  }
318
364
  const places = blocks.flatMap((block, index) => clipboardParagraphs(block, (next) => {
@@ -325,7 +371,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
325
371
  for (const table of tables) delete table.formatting?.styleId;
326
372
  }
327
373
  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.");
374
+ if (state.selection instanceof CellSelection && !overCells) return refuse("Pasting over selected cells requires a per-cell paste operation.", INVALID_CLIPBOARD);
329
375
  const selectionRange = overCells ? {
330
376
  from: state.selection.from,
331
377
  to: state.selection.to
@@ -365,7 +411,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
365
411
  visitParagraphRuns(paragraph, (run) => {
366
412
  if (run.content.some((child) => child.type === "drawing")) related = true;
367
413
  });
368
- if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.");
414
+ if (related) return refuse("Copied notes and comments holding images or external links require their part's relationships.", { gap: CANONICAL_GAP.storyContentProjection });
369
415
  }
370
416
  const destination = readModel(session.document);
371
417
  let styles = destination.package.styles;
@@ -379,7 +425,10 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
379
425
  annotationParagraphs,
380
426
  tableStyleIds: tables.flatMap(({ formatting }) => formatting?.styleId === void 0 ? [] : [formatting.styleId])
381
427
  });
382
- if (importedStyles.isErr()) return refuse(importedStyles.error.message);
428
+ if (importedStyles.isErr()) {
429
+ const { reason, message } = importedStyles.error;
430
+ return refuse(message, groundForDocumentOpRefusal(reason));
431
+ }
383
432
  styles = importedStyles.value.styles;
384
433
  for (const [index, place] of places.entries()) {
385
434
  const imported = importedStyles.value.paragraphs[index] ?? panic("An imported clipboard paragraph is missing.");
@@ -412,7 +461,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
412
461
  for (const style of styles.styles) {
413
462
  if (!importedStyleIds.has(style.styleId) || style.pPr?.numPr?.kind !== "reference") continue;
414
463
  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.");
464
+ if (numId === void 0) return refuse("A clipboard style numbering dependency could not be imported.", INVALID_CLIPBOARD);
416
465
  style.pPr.numPr = paragraphNumberingReference({
417
466
  numId,
418
467
  ...style.pPr.numPr.ilvl === void 0 ? {} : { ilvl: style.pPr.numPr.ilvl }
@@ -428,7 +477,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
428
477
  const source = previousId === void 0 ? void 0 : sourceDocument?.package.relationships?.get(previousId);
429
478
  let target = href;
430
479
  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.");
480
+ if (target === void 0 || target.length === 0) return refuse("The clipboard hyperlink has no resolved target.", INVALID_CLIPBOARD);
432
481
  while (relationships.has(`rId${relationshipIndex}`)) relationshipIndex += 1;
433
482
  const id = `rId${relationshipIndex++}`;
434
483
  relationships.set(id, {
@@ -447,7 +496,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
447
496
  const parsed = Result.try({
448
497
  try: () => parseXml(xml, OOXML_NAMESPACE_SCOPE),
449
498
  catch: () => new CanonicalSessionError({
450
- ground: { gap: CANONICAL_GAP.dispatch },
499
+ ground: INVALID_CLIPBOARD,
451
500
  reason: "refused",
452
501
  message: "The clipboard hyperlink metadata is malformed."
453
502
  })
@@ -457,7 +506,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
457
506
  for (const name of Object.keys(element.attributes ?? {})) {
458
507
  const attribute = findAttributeByNamespaceUri(element, OFFICE_RELATIONSHIP_NAMESPACE_URIS, getLocalName(name));
459
508
  if (attribute === null || attribute.name !== name) continue;
460
- if (getLocalName(name) !== "id") return refuse("Clipboard hyperlink metadata references an unsupported package part.");
509
+ if (getLocalName(name) !== "id") return refuse("Clipboard hyperlink metadata references an unsupported package part.", INVALID_CLIPBOARD);
461
510
  let id = remapped.get(attribute.value);
462
511
  if (id === void 0) {
463
512
  const imported = importExternalLink(void 0, attribute.value);
@@ -500,7 +549,7 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
500
549
  if (plain) item.formatting = marksToTextFormatting(state.storedMarks ?? state.doc.resolve(pasteTarget ?? moveSource?.from ?? selectionRange.from).marks());
501
550
  for (const child of item.content) {
502
551
  if (child.type !== "drawing") continue;
503
- if (child.rawXmlMode !== void 0) return refuse("Opaque drawings and embedded objects require their source package parts.");
552
+ if (child.rawXmlMode !== void 0) return refuse("Opaque drawings and embedded objects require their source package parts.", { gap: CANONICAL_GAP.storyContentProjection });
504
553
  delete child.rawXml;
505
554
  delete child.rawImageFingerprint;
506
555
  const image = child.image;
@@ -538,9 +587,9 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
538
587
  const sourceRelationship = image.rId === void 0 ? void 0 : sourceDocument?.package.relationships?.get(image.rId);
539
588
  const sourcePath = sourceRelationship?.target.startsWith("/") ? sourceRelationship.target.slice(1) : `word/${sourceRelationship?.target ?? ""}`;
540
589
  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.");
590
+ if (sourceMedia !== void 0 && sourceMedia.data.byteLength > MAX_CLIPBOARD_IMAGE_BYTES) return refuse("The clipboard image exceeds the import size limit.", INVALID_CLIPBOARD);
542
591
  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.");
592
+ if (src === void 0) return refuse("The clipboard image has no source bytes or URL.", INVALID_CLIPBOARD);
544
593
  image.src = src;
545
594
  while (relationships.has(`rId${relationshipIndex}`)) relationshipIndex += 1;
546
595
  const id = `rId${relationshipIndex++}`;
@@ -548,12 +597,12 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
548
597
  if (data !== null) {
549
598
  const mimeType = data.at(1);
550
599
  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.");
600
+ if (mimeType === void 0 || payload === void 0) return refuse("The clipboard image data is malformed.", INVALID_CLIPBOARD);
601
+ if (payload.length > Math.ceil(MAX_CLIPBOARD_IMAGE_BYTES * 4 / 3)) return refuse("The clipboard image exceeds the import size limit.", INVALID_CLIPBOARD);
553
602
  const decoded = Result.try({
554
603
  try: () => base64ToBytes(payload),
555
604
  catch: () => new CanonicalSessionError({
556
- ground: { gap: CANONICAL_GAP.dispatch },
605
+ ground: INVALID_CLIPBOARD,
557
606
  message: "The clipboard image data is malformed.",
558
607
  reason: "refused"
559
608
  })
@@ -579,9 +628,9 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
579
628
  target: src,
580
629
  targetMode: "External"
581
630
  });
582
- else return refuse("Clipboard images require image bytes or an HTTP image URL.");
631
+ else return refuse("Clipboard images require image bytes or an HTTP image URL.", INVALID_CLIPBOARD);
583
632
  const relationshipId = relationshipIdOf(id);
584
- if (relationshipId === void 0) return refuse("The clipboard image relationship id is invalid.");
633
+ if (relationshipId === void 0) return refuse("The clipboard image relationship id is invalid.", INVALID_CLIPBOARD);
585
634
  image.rId = relationshipId;
586
635
  delete image.id;
587
636
  importedResource = true;
@@ -650,17 +699,23 @@ const prepareCanonicalPaste = ({ session, state, slice, plain = false, moveTarge
650
699
  resourceOps,
651
700
  semantic: "paste"
652
701
  });
653
- if (topParagraphs.length !== blocks.length) return refuseUnder({ gap: CANONICAL_GAP.trackedTableStructure }, "Moving a table by dragging requires a table move operation.");
654
702
  const target = session.projection.addressAt(moveTarget);
655
703
  if (target.isErr()) return target;
656
704
  return session.prepareIntents(state, {
657
- intents: [{
705
+ intents: [topParagraphs.length === blocks.length ? {
658
706
  type: "moveFragment",
659
707
  target: target.value,
660
708
  ...range,
661
709
  paragraphs: topParagraphs,
662
710
  openStart,
663
711
  openEnd
712
+ } : {
713
+ type: "moveBlocks",
714
+ target: target.value,
715
+ ...range,
716
+ blocks,
717
+ openStart,
718
+ openEnd
664
719
  }],
665
720
  resourceOps,
666
721
  semantic: "paste"
@@ -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,6 +1,6 @@
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
6
  import { EditorState, TextSelection } from "prosemirror-state";
@@ -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)) {
@@ -1,7 +1,7 @@
1
1
  import { CanonicalSessionError } from "../canonical/canonicalSession.js";
2
2
  import { ContentControlBoundError, ContentControlLockedError, ContentControlTypeError } from "../content-controls/errors.js";
3
3
  import { setContentControlValue } from "../content-controls/mutateContentControls.js";
4
- import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
4
+ import { CANONICAL_CONDITION, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
5
5
  import { readModel } from "../types/documentModel.js";
6
6
  import { Result, panic } from "better-result";
7
7
  import { DOCUMENT_OP_TYPES, blockControlHolding, storyBody } from "@stll/docx-core/ops";
@@ -14,35 +14,35 @@ import { DOCUMENT_OP_TYPES, blockControlHolding, storyBody } from "@stll/docx-co
14
14
  * The headless content-control rules decide the new value: a lock, a type
15
15
  * mismatch or a data binding refuses, and the refusal names its ground.
16
16
  */
17
- const refuse = (message, ground = { gap: CANONICAL_GAP.commands }) => Result.err(new CanonicalSessionError({
17
+ const refuse = (message, ground) => Result.err(new CanonicalSessionError({
18
18
  ground,
19
19
  message,
20
20
  reason: "refused"
21
21
  }));
22
22
  const prepareContentControlValue = (session, state, command) => {
23
23
  const node = session.projection.doc.nodeAt(command.at);
24
- if (node?.type.name !== "blockSdt") return refuse("The content control is no longer there.");
24
+ if (node?.type.name !== "blockSdt") return refuse("The content control is no longer there.", { condition: CANONICAL_CONDITION.stale });
25
25
  let paragraphsOnly = node.childCount > 0;
26
26
  node.forEach((child) => {
27
27
  if (child.type.name !== "paragraph") paragraphsOnly = false;
28
28
  });
29
- if (!paragraphsOnly) return refuse("A control that holds more than paragraphs has no value.");
29
+ if (!paragraphsOnly) return refuse("A control that holds more than paragraphs has no value.", { condition: CANONICAL_CONDITION.invalidRequest });
30
30
  const from = session.projection.addressAt(command.at + 2);
31
31
  if (from.isErr()) return from;
32
32
  const to = session.projection.addressAt(command.at + node.nodeSize - 2);
33
33
  if (to.isErr()) return to;
34
34
  const document = readModel(session.document);
35
35
  const held = blockControlHolding(storyBody(document, from.value.story).content, from.value.blockId);
36
- if (held === void 0) return refuse("The content control is no longer there.");
36
+ if (held === void 0) return refuse("The content control is no longer there.", { condition: CANONICAL_CONDITION.stale });
37
37
  const { control } = held;
38
38
  const controlId = control.properties.id;
39
- if (controlId === void 0) return refuse("A content control without an id cannot be set.");
39
+ if (controlId === void 0) return refuse("A content control without an id cannot be set.", { condition: CANONICAL_CONDITION.invalidRequest });
40
40
  let next;
41
41
  try {
42
42
  next = setContentControlValue({ package: { document: { content: [control] } } }, { id: controlId }, command.input).package.document.content.at(0);
43
43
  } catch (error) {
44
44
  if (error instanceof ContentControlLockedError) return refuse(error.message, { rule: CANONICAL_RULE.contentControlLock });
45
- if (error instanceof ContentControlTypeError || error instanceof ContentControlBoundError) return refuse(error.message);
45
+ if (error instanceof ContentControlTypeError || error instanceof ContentControlBoundError) return refuse(error.message, { condition: CANONICAL_CONDITION.invalidRequest });
46
46
  throw error;
47
47
  }
48
48
  if (next?.type !== "blockSdt") return panic("A control's value keeps it a block-level control.");
@@ -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;