@stll/folio-core 0.75.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 (92) hide show
  1. package/dist/ai-edits/headless.d.ts +2 -1
  2. package/dist/ai-edits/headless.js +18 -12
  3. package/dist/ai-edits/pending-suggestions.js +2 -3
  4. package/dist/ai-edits/read.js +9 -3
  5. package/dist/ai-edits/types.d.ts +9 -4
  6. package/dist/canonical/batchCommentReferences.js +2 -1
  7. package/dist/canonical/canonicalBatchReview.js +5 -8
  8. package/dist/canonical/canonicalComments.js +8 -2
  9. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  10. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  11. package/dist/canonical/canonicalPublicOperations.js +203 -71
  12. package/dist/canonical/canonicalSession.js +3 -1
  13. package/dist/controller/canonicalClipboard.d.ts +1 -1
  14. package/dist/controller/canonicalClipboard.js +71 -17
  15. package/dist/controller/canonicalContentControlValue.js +7 -7
  16. package/dist/controller/canonicalReview.d.ts +21 -0
  17. package/dist/controller/canonicalReview.js +44 -9
  18. package/dist/controller/canonicalStructure.d.ts +1 -2
  19. package/dist/controller/canonicalStructure.js +51 -24
  20. package/dist/controller/fontReadiness.js +50 -23
  21. package/dist/controller/hiddenEditorManager.js +5 -20
  22. package/dist/docx/bulletMarkers.d.ts +8 -0
  23. package/dist/docx/bulletMarkers.js +9 -1
  24. package/dist/docx/canonicalSessionInput.js +25 -11
  25. package/dist/docx/ensureParaIds.d.ts +31 -0
  26. package/dist/docx/ensureParaIds.js +57 -32
  27. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  28. package/dist/docx/ensureUniqueControlIds.js +47 -29
  29. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  30. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  31. package/dist/docx/server/templatePlan/apply.js +62 -8
  32. package/dist/docx/server/templatePlan/blocks.d.ts +55 -3
  33. package/dist/docx/server/templatePlan/blocks.js +182 -6
  34. package/dist/docx/server/templatePlan/builders.d.ts +16 -1
  35. package/dist/docx/server/templatePlan/builders.js +31 -3
  36. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  37. package/dist/docx/server/templatePlan/effects.js +188 -0
  38. package/dist/docx/server/templatePlan/emit.d.ts +2 -1
  39. package/dist/docx/server/templatePlan/emit.js +44 -2
  40. package/dist/docx/server/templatePlan/inspect.js +21 -1
  41. package/dist/docx/server/templatePlan/labels.js +16 -1
  42. package/dist/docx/server/templatePlan/plan.d.ts +12 -3
  43. package/dist/docx/server/templatePlan/plan.js +36 -12
  44. package/dist/docx/server/templatePlan/planShape.js +47 -22
  45. package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
  46. package/dist/docx/server/templatePlan/revisions.js +407 -0
  47. package/dist/docx/server/templatePlan/story.d.ts +15 -1
  48. package/dist/docx/server/templatePlan/story.js +50 -2
  49. package/dist/docx/server/templatePlan/types.d.ts +217 -1
  50. package/dist/docx/server/templatePlan/verify.js +117 -8
  51. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  52. package/dist/docx/server/templatePlan/xml.js +4 -1
  53. package/dist/internal/revisionResolutionStep.d.ts +2 -31
  54. package/dist/internal/revisionResolutionStep.js +2 -171
  55. package/dist/prosemirror/commands/comments.d.ts +6 -234
  56. package/dist/prosemirror/commands/comments.js +5 -2464
  57. package/dist/prosemirror/commands/index.d.ts +4 -2
  58. package/dist/prosemirror/commands/index.js +4 -2
  59. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
  60. package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
  61. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  62. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  63. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  64. package/dist/prosemirror/paraIds.d.ts +1 -14
  65. package/dist/prosemirror/paraIds.js +1 -14
  66. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  67. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  68. package/dist/prosemirror/projectionReview.d.ts +49 -0
  69. package/dist/prosemirror/projectionReview.js +292 -0
  70. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  71. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  72. package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
  73. package/dist/prosemirror/replacedAnnotations.js +1 -10
  74. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  75. package/dist/prosemirror/revisionCarriers.js +15 -1
  76. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  77. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  78. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  79. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  80. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  81. package/dist/prosemirror/suggestionQueries.js +320 -0
  82. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  83. package/dist/prosemirror/tableGridMutation.js +1 -78
  84. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  85. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  86. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  87. package/dist/server.d.ts +2 -2
  88. package/dist/types/canonicalCapabilities.d.ts +1 -25
  89. package/dist/types/canonicalCapabilities.js +1 -23
  90. package/package.json +2 -2
  91. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  92. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
@@ -477,7 +477,8 @@ export declare class FolioDocxReviewer {
477
477
  * the anchor map the apply layer resolves operations against.
478
478
  */
479
479
  snapshot(): FolioAIEditSnapshot;
480
- /** Every suggestion id the document's stories still carry. */
480
+ private pendingSuggestionIdsForStory;
481
+ /** Every suggestion id the document's editable stories still carry. */
481
482
  private activeSuggestionIds;
482
483
  /** Export staged AI operations for storage by the host, outside the DOCX. */
483
484
  exportPendingSuggestions(): FolioPendingSuggestionRecord[];
@@ -18,7 +18,6 @@ import { getCachedNumberingMap } from "../docx/numberingParser.js";
18
18
  import { cloneDocumentWithParagraphPropertySources } from "../docx/paragraphPropertySource.js";
19
19
  import { getEndnoteText, getFootnoteText, getHeaderFooterText } from "../docx/storyPlainText.js";
20
20
  import { expectCharacterStyleMarkAttrs } from "../prosemirror/attrs/index.js";
21
- import { getSuggestions, suggestionIdOfRevision, suggestionOwnersByRevision } from "../prosemirror/commands/comments.js";
22
21
  import { createCommentIdAllocator, seedCommentAllocator } from "../prosemirror/commentIdAllocator.js";
23
22
  import { commentThreadIds } from "../prosemirror/commentRecords.js";
24
23
  import { paragraphListReferences } from "../prosemirror/listInstanceReferences.js";
@@ -31,6 +30,7 @@ import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documen
31
30
  import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
32
31
  import { schema } from "../prosemirror/schema/index.js";
33
32
  import { sectionPropertiesOf } from "../prosemirror/sectionCarrier.js";
33
+ import { getSuggestions } from "../prosemirror/suggestionQueries.js";
34
34
  import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
35
35
  import { readModel } from "../types/documentModel.js";
36
36
  import { canonicalJson } from "../utils/canonicalJson.js";
@@ -45,7 +45,7 @@ import { matchTableGeometryOperations } from "./table-geometry.js";
45
45
  import { tableTemplateCanCrossPackageLosslessly } from "./table-template.js";
46
46
  import { TaggedError, panic } from "better-result";
47
47
  import { CONTENT_CONTROL_LOCK, lockedControlMessage, numberingLevelEntries } from "@stll/docx-core/model";
48
- import { DOCUMENT_OP_TYPES, OP_STORIES, captureStoryParts, freshCommentId, packageResourcesOpOf, pendingSuggestionIdsIn, reconcileDocumentPartRelationships, resolveSectionChange, resolveSectionChanges, sectionResolutionPatch, withoutPendingSuggestions } from "@stll/docx-core/ops";
48
+ import { DOCUMENT_OP_TYPES, OP_STORIES, captureStoryParts, freshCommentId, packageResourcesOpOf, pendingSuggestionIdsIn, reconcileDocumentPartRelationships, resolveSectionChange, resolveSectionChanges, sectionResolutionPatch, suggestionOwnersInStory, withoutPendingSuggestions } from "@stll/docx-core/ops";
49
49
  import { ZipArchive } from "@stll/docx-core/zip";
50
50
  import { EditorState, Selection, TextSelection } from "prosemirror-state";
51
51
  // src/ai-edits/headless.ts
@@ -873,7 +873,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
873
873
  for (const handle of handles) {
874
874
  const state = copy.getEditableStoryState(handle);
875
875
  if (!state) continue;
876
- if (getSuggestions(state).length > 0) throw canonicalReviewerRefusal("project a story holding a suggestion the session will not accept");
876
+ if (copy.pendingSuggestionIdsForStory(handle, state).size > 0) throw canonicalReviewerRefusal("project a story holding a suggestion the session will not accept");
877
877
  if (mode === "with-revision-census") {
878
878
  const stats = getTrackedChangeStatsFromDoc(state.doc);
879
879
  for (const id of stats.ids) ids.add(id);
@@ -1041,7 +1041,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1041
1041
  const story = canonicalOpStory(handle);
1042
1042
  const listed = listedRevisionGroups(state.doc);
1043
1043
  if (listed.length === 0) return [];
1044
- const owners = suggestionOwnersByRevision(state);
1044
+ const owners = suggestionOwnersInStory(this.baseDocument, story);
1045
1045
  const changes = listed.flatMap(({ id, groupIds }) => {
1046
1046
  const suggestionId = owners.get(id) ?? null;
1047
1047
  return resolution === "accept" && suggestionId !== null ? [] : [{
@@ -1165,13 +1165,19 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1165
1165
  snapshot() {
1166
1166
  return this.snapshotOf(this.state);
1167
1167
  }
1168
- /** Every suggestion id the document's stories still carry. */
1168
+ pendingSuggestionIdsForStory(story, state) {
1169
+ const ids = new Set(getSuggestions(state).map(({ suggestionId }) => suggestionId));
1170
+ for (const suggestionId of suggestionOwnersInStory(this.baseDocument, canonicalOpStory(story)).values()) ids.add(suggestionId);
1171
+ return ids;
1172
+ }
1173
+ /** Every suggestion id the document's editable stories still carry. */
1169
1174
  activeSuggestionIds() {
1170
- const active = new Set(getSuggestions(this.state).map(({ suggestionId }) => suggestionId));
1175
+ const active = /* @__PURE__ */ new Set();
1176
+ if (pendingSuggestionIdsIn(this.baseDocument).size === 0) return active;
1171
1177
  for (const handle of this.listStoryHandlesInternal()) {
1172
- if (handle.type === "main") continue;
1173
1178
  const state = this.getEditableStoryState(handle);
1174
- for (const { suggestionId } of state ? getSuggestions(state) : []) active.add(suggestionId);
1179
+ if (state === null) continue;
1180
+ for (const id of this.pendingSuggestionIdsForStory(handle, state)) active.add(id);
1175
1181
  }
1176
1182
  return active;
1177
1183
  }
@@ -1813,7 +1819,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1813
1819
  resolveChangeOnSession(target, resolution) {
1814
1820
  const { session } = this.engine;
1815
1821
  const id = revisionIdOf(target);
1816
- const suggestionId = suggestionIdOfRevision(this.state, id);
1822
+ const suggestionId = suggestionOwnersInStory(this.baseDocument, OP_STORIES.MAIN).get(id) ?? null;
1817
1823
  if (suggestionId !== null) {
1818
1824
  const adopted = this.resolveSuggestionOnSession(session, suggestionId, resolution, this.author);
1819
1825
  if (!adopted || resolution === "reject") return adopted;
@@ -1984,7 +1990,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1984
1990
  for (const handle of this.listStoryHandlesInternal()) {
1985
1991
  if (editableStoryKey(handle) === key) continue;
1986
1992
  const other = this.getEditableStoryState(handle);
1987
- if (other && getSuggestions(other).some(({ suggestionId }) => staged.has(suggestionId))) throw canonicalReviewerRefusal("resolve one story of a suggestion that reaches another");
1993
+ if (other && [...this.pendingSuggestionIdsForStory(handle, other)].some((suggestionId) => staged.has(suggestionId))) throw canonicalReviewerRefusal("resolve one story of a suggestion that reaches another");
1988
1994
  }
1989
1995
  const copy = this.fork();
1990
1996
  const { session } = copy.engine;
@@ -1994,7 +2000,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
1994
2000
  try {
1995
2001
  for (const suggestionId of staged) copy.resolveSuggestionOnSession(session, suggestionId, view === "final" ? "accept" : "reject", this.author);
1996
2002
  const after = copy.getEditableStoryState(story);
1997
- if (after && getSuggestions(after).length > 0) throw canonicalReviewerRefusal("resolve a story holding a suggestion the session will not resolve");
2003
+ if (after && copy.pendingSuggestionIdsForStory(story, after).size > 0) throw canonicalReviewerRefusal("resolve a story holding a suggestion the session will not resolve");
1998
2004
  resolved = copy.resolveStoryOnSession(session, story, view);
1999
2005
  } finally {
2000
2006
  unsubscribe();
@@ -2013,7 +2019,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
2013
2019
  });
2014
2020
  const state = this.getEditableStoryState(story);
2015
2021
  if (!state) return false;
2016
- const staged = new Set(getSuggestions(state).map(({ suggestionId }) => suggestionId));
2022
+ const staged = this.pendingSuggestionIdsForStory(story, state);
2017
2023
  if (staged.size > 0) return this.resolveStoryWithSuggestions({
2018
2024
  story,
2019
2025
  view,
@@ -1,10 +1,10 @@
1
1
  import { parseFolioDocumentOperationBatch } from "../document-operations.js";
2
2
  import { expectParagraphAttrs, expectTrackedChangeMarkAttrs } from "../prosemirror/attrs/index.js";
3
- import { getSuggestions } from "../prosemirror/commands/comments.js";
4
3
  import { storyConversionOptions } from "../prosemirror/conversion/storyConversionOptions.js";
5
4
  import { toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
6
5
  import { getDocumentStyleResolver } from "../prosemirror/plugins/documentStyleState.js";
7
6
  import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
7
+ import { getSuggestionRanges } from "../prosemirror/suggestionQueries.js";
8
8
  import { getFolioParaIdFromBlockId } from "../types/block-id.js";
9
9
  import { canonicalJson } from "../utils/canonicalJson.js";
10
10
  import { persistedBlock } from "./block-identity.js";
@@ -615,12 +615,11 @@ var FolioPendingSuggestionRegistry = class FolioPendingSuggestionRegistry {
615
615
  continue;
616
616
  }
617
617
  }
618
- const ranges = getSuggestions(view.state).find((entry) => entry.suggestionId === suggestionId)?.ranges ?? [];
619
618
  const placed = saved === null ? null : placedRecord({
620
619
  record,
621
620
  live: view.live,
622
621
  saved,
623
- ranges
622
+ ranges: getSuggestionRanges(view.state, suggestionId)
624
623
  });
625
624
  this.records.set(key, placed ?? retiredRecord(record));
626
625
  }
@@ -2,6 +2,7 @@ import { expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedCh
2
2
  import { getFolioNodeRevisionCarriers } from "../prosemirror/revisionCarriers.js";
3
3
  import { expandRunFormattingCarrier, runFormattingCarrierReviewText, runFormattingInlineAtomCleanText, runFormattingInlineAtomDisposition, runFormattingInlineAtomResultText } from "../prosemirror/runFormattingInlineCarriers.js";
4
4
  import { getTableCellMergeChange } from "../prosemirror/tableCellMergeRevision.js";
5
+ import { isTableRowRevisionCompanion } from "../prosemirror/tableRowRevisionOwnership.js";
5
6
  import { enclosingInsertionAncestors, trackedRevisionLayerOf } from "../prosemirror/trackedRevisionPath.js";
6
7
  import { commentAnchorIdsForNode } from "./comment-lifecycle.js";
7
8
  import { readerTextOf } from "./note-references.js";
@@ -64,7 +65,6 @@ const firstBlockIdWithin = ({ node, nodePos, blockStarts }) => {
64
65
  });
65
66
  return blockId;
66
67
  };
67
- const belongsToRowRevision = (scope, revision) => revision.id === scope.change.id || revision.author === scope.change.author && revision.date === scope.change.date;
68
68
  /**
69
69
  * The paragraph-mark revision a marked row writes on its cells' paragraphs:
70
70
  * a row deletion deletes each cell paragraph's mark with it, an insertion
@@ -207,7 +207,10 @@ const getTrackedChangeGroupsFromProjectedDoc = (doc, blockStarts, revisionRanges
207
207
  to: carrier.to
208
208
  });
209
209
  const rowScope = rowRevisionScopes.at(-1);
210
- if (rowScope !== void 0 && ROW_PARAGRAPH_MARK_CARRIERS[rowScope.kind] === carrier.type && belongsToRowRevision(rowScope, carrier)) {
210
+ if (rowScope !== void 0 && ROW_PARAGRAPH_MARK_CARRIERS[rowScope.kind] === carrier.type && isTableRowRevisionCompanion({
211
+ row: rowScope.change,
212
+ candidate: carrier
213
+ })) {
211
214
  fold(rowScope.key, [carrier.id]);
212
215
  return;
213
216
  }
@@ -430,7 +433,10 @@ const getTrackedChangeGroupsFromProjectedDoc = (doc, blockStarts, revisionRanges
430
433
  for (const [layerIndex, { kind: layerKind, revision }] of layers.entries()) {
431
434
  if (deletedFieldScopes.some(({ layers: enclosingLayers }) => enclosingLayers.some((layer) => layer.kind === layerKind && layer.revision.id === revision.id))) continue;
432
435
  const rowScope = rowRevisionScopes.at(-1);
433
- if (rowScope?.kind === layerKind && belongsToRowRevision(rowScope, revision)) {
436
+ if (rowScope?.kind === layerKind && isTableRowRevisionCompanion({
437
+ row: rowScope.change,
438
+ candidate: revision
439
+ })) {
434
440
  fold(rowScope.key, [revision.id]);
435
441
  continue;
436
442
  }
@@ -1,6 +1,6 @@
1
1
  import { FolioContentBlock, FolioContentBlockIdentity, FolioContentInlineBooleanProperty, FolioContentInlineFormatting, FolioContentInlineFormattingPatch, FolioContentListReference, FolioContentParagraphIndentation, FolioContentParagraphKind, FolioContentParagraphSpacing, FolioContentRun, FolioContentSnapshot, FolioContentStatedNumbering, FolioContentTableLocation } from "../compare/content-types.js";
2
2
  import { ListKind } from "../docx/listNumberingInstances.js";
3
- import { CanonicalGap } from "../types/canonicalCapabilities.js";
3
+ import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
4
4
  import { document_d_exports } from "../types/document.js";
5
5
  export type FolioAIBlockKind = FolioContentParagraphKind | "diagnostic";
6
6
  /** Boolean run properties supported by snapshots and range-formatting mutations. */
@@ -762,9 +762,14 @@ export type FolioAIEditParagraphIdentity = {
762
762
  export type FolioAIEditSkippedOperation = {
763
763
  id: string;
764
764
  reason: FolioAIEditSkipReason;
765
- canonicalRefusal?: {
766
- gap: CanonicalGap;
767
- };
765
+ /**
766
+ * Why the canonical session refused it: a capability it does not have yet
767
+ * (`gap`), a rule the document states (`rule`), or a condition of the
768
+ * session or the request (`condition`), as `canonicalRefusalNotice` reads
769
+ * them. Absent where the reason alone says it, as the default engine
770
+ * reports the skip.
771
+ */
772
+ canonicalRefusal?: CanonicalRefusalGround;
768
773
  /**
769
774
  * What exactly was wrong when the reason alone does not say: the values a
770
775
  * `payloadDoesNotFit` skip could not place, the earlier operation an
@@ -59,7 +59,8 @@ const mapIntentPositions = (intent, map) => {
59
59
  from: map(intent.from),
60
60
  to: map(intent.to)
61
61
  };
62
- case "moveFragment": return {
62
+ case "moveFragment":
63
+ case "moveBlocks": return {
63
64
  ...intent,
64
65
  from: map(intent.from),
65
66
  to: map(intent.to),
@@ -1,21 +1,18 @@
1
1
  import { anchoredCommentIdsInBlocks } from "../ai-edits/comment-lifecycle.js";
2
2
  import { getTrackedChangeGroupsForIds, getTrackedChangeStatsFromDoc } from "../ai-edits/read.js";
3
- import { pendingSuggestionRevisionIds } from "../prosemirror/commands/comments.js";
4
3
  import { lockedControlSpans } from "../prosemirror/lockedControls.js";
5
4
  import { lockViolationBetween } from "./canonicalLockGuard.js";
6
5
  import { canonicalRevisionLocks } from "./canonicalRevisionLocks.js";
7
6
  import { preservePropertySources } from "./propertySourcePreservation.js";
8
- import { DOCUMENT_OP_TYPES, applyDocumentOps, findStoryBody } from "@stll/docx-core/ops";
9
- import { EditorState } from "prosemirror-state";
7
+ import { DOCUMENT_OP_TYPES, applyDocumentOps, findStoryBody, suggestionOwnersInStory } from "@stll/docx-core/ops";
10
8
  // src/canonical/canonicalBatchReview.ts
11
- const revisionIdsOf = (doc) => {
12
- const { ids } = getTrackedChangeStatsFromDoc(doc);
9
+ const revisionIdsOf = (version, story) => {
10
+ const { ids } = getTrackedChangeStatsFromDoc(version.projection);
13
11
  if (ids.length === 0) return {
14
12
  all: ids,
15
13
  ordinary: ids
16
14
  };
17
- const state = EditorState.create({ doc });
18
- const suggested = pendingSuggestionRevisionIds(state);
15
+ const suggested = suggestionOwnersInStory(version.document, story);
19
16
  return {
20
17
  all: ids,
21
18
  ordinary: suggested.size === 0 ? ids : ids.filter((id) => !suggested.has(id))
@@ -99,7 +96,7 @@ const resolveStoryPair = ({ before, after, story, decision, restores }) => {
99
96
  const createCanonicalBatchReview = ({ before, after, story }) => {
100
97
  let beforeIds;
101
98
  let afterIds;
102
- const revisions = (side) => side === "before" ? beforeIds ??= revisionIdsOf(before.projection) : afterIds ??= revisionIdsOf(after.projection);
99
+ const revisions = (side) => side === "before" ? beforeIds ??= revisionIdsOf(before, story) : afterIds ??= revisionIdsOf(after, story);
103
100
  let accepted;
104
101
  const accept = () => {
105
102
  if (accepted !== void 0) return accepted;
@@ -3,6 +3,7 @@ import { cloneParagraphWithPropertySource } from "../docx/paragraphPropertySourc
3
3
  import { threadedCommentIds } from "../docx/serializer/commentSerializer.js";
4
4
  import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
5
5
  import { canonicalJson } from "../utils/canonicalJson.js";
6
+ import { groundForDocumentOpRefusal } from "./canonicalRefusalGrounds.js";
6
7
  import { Result, TaggedError } from "better-result";
7
8
  import { DOCUMENT_OP_TYPES, ID_KIND_LIMITS, ID_LEASE_KINDS, allocateCommentAnchorIds, applyDocumentOps, formatParaId, freshLeasedIds, packageParagraphIds } from "@stll/docx-core/ops";
8
9
  // src/canonical/canonicalComments.ts
@@ -17,6 +18,11 @@ const refuse = (message, condition = CANONICAL_CONDITION.invalidRequest) => Resu
17
18
  message,
18
19
  ground: { condition }
19
20
  }));
21
+ /** A refusal the document operations stated, under its reason's ground. */
22
+ const refuseOp = ({ reason, message }) => Result.err(new CanonicalCommentError({
23
+ message,
24
+ ground: groundForDocumentOpRefusal(reason)
25
+ }));
20
26
  const compileCanonicalComments = ({ document, command, idLease }) => {
21
27
  const current = document.package.document.comments ?? [];
22
28
  const byId = new Map(current.map((comment) => [comment.id, comment]));
@@ -131,9 +137,9 @@ const compileCanonicalComments = ({ document, command, idLease }) => {
131
137
  newIds: allocation.value
132
138
  });
133
139
  })();
134
- if (materialized.isErr()) return refuse(materialized.error.message);
140
+ if (materialized.isErr()) return refuseOp(materialized.error);
135
141
  const applied = applyDocumentOps(draft, [materialized.value]);
136
- if (applied.isErr()) return refuse(applied.error.message);
142
+ if (applied.isErr()) return refuseOp(applied.error);
137
143
  compiled.push(materialized.value);
138
144
  draft = applied.value.document;
139
145
  }
@@ -1,12 +1,10 @@
1
1
  import { FolioAIEditSkipReason } from "../ai-edits/types.js";
2
- import { CanonicalGap } from "../types/canonicalCapabilities.js";
2
+ import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
3
3
  import { DocumentOpRefusal } from "@stll/docx-core/ops";
4
4
  type CompilerRefusalSkip = {
5
5
  reason: FolioAIEditSkipReason;
6
6
  message: string;
7
- refusal?: {
8
- gap: CanonicalGap;
9
- };
7
+ refusal?: CanonicalRefusalGround;
10
8
  };
11
9
  /** The skip a refused compilation reports. */
12
10
  export declare const compilerRefusalSkip: ({ reason, message }: DocumentOpRefusal) => CompilerRefusalSkip;
@@ -1,18 +1,24 @@
1
- import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
1
+ import { groundForDocumentOpRefusal } from "./canonicalRefusalGrounds.js";
2
2
  import { DOCUMENT_OP_REFUSAL_REASONS } from "@stll/docx-core/ops";
3
3
  // src/canonical/canonicalCompilerRefusal.ts
4
4
  const typed = (reason) => ({
5
5
  type: "typed",
6
6
  reason
7
7
  });
8
- const UNSUPPORTED = { type: "unsupported" };
8
+ const grounded = (reason) => ({
9
+ type: "grounded",
10
+ reason
11
+ });
12
+ const UNSUPPORTED = grounded("unsupportedBlock");
9
13
  const R = DOCUMENT_OP_REFUSAL_REASONS;
10
14
  /**
11
15
  * Every compiler refusal reason's public disposition. A deliberate refusal
12
- * names its own reason, as the legacy engine reports one; `untrackable`
13
- * gathers shapes the engine does not record yet, and `revisionConflict` a
14
- * tracked split the compiler stated with records of its own, so both report
15
- * a gap.
16
+ * names its own reason, as the legacy engine reports one, and so does a
17
+ * change that would change nothing. A document that moved on is a stale
18
+ * range, and an offset inside a character splits it. Every other reason
19
+ * reports its ground besides: `untrackable` the shapes the tracked-change
20
+ * records do not express yet, `unrecordableLinkSuggestion` the rule the
21
+ * review records state, and the rest a request the document does not allow.
16
22
  */
17
23
  const COMPILER_REFUSAL_DISPOSITIONS = {
18
24
  [R.PENDING_RUN_PROPERTY_CHANGE]: typed("pendingRunPropertyChange"),
@@ -25,13 +31,13 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
25
31
  [R.PENDING_PARAGRAPH_MARK_INSERTION]: typed("pendingParagraphMarkInsertion"),
26
32
  [R.PENDING_PARAGRAPH_JOIN]: typed("pendingParagraphMarkDeletion"),
27
33
  [R.UNSUPPORTED_SCHEMA]: UNSUPPORTED,
28
- [R.BLOCK_NOT_FOUND]: UNSUPPORTED,
34
+ [R.BLOCK_NOT_FOUND]: grounded("missingBlock"),
29
35
  [R.INVALID_OPERATION]: UNSUPPORTED,
30
- [R.NO_CHANGE]: UNSUPPORTED,
36
+ [R.NO_CHANGE]: typed("noopOperation"),
31
37
  [R.DEPENDENT_RECORDS]: UNSUPPORTED,
32
38
  [R.INVALID_OFFSET]: UNSUPPORTED,
33
39
  [R.CROSS_BLOCK_RANGE]: UNSUPPORTED,
34
- [R.SPLITS_SURROGATE_PAIR]: UNSUPPORTED,
40
+ [R.SPLITS_SURROGATE_PAIR]: grounded("splitsCharacter"),
35
41
  [R.INVALID_TEXT]: UNSUPPORTED,
36
42
  [R.INVALID_BLOCK_ID]: UNSUPPORTED,
37
43
  [R.ID_COLLISION]: UNSUPPORTED,
@@ -41,7 +47,7 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
41
47
  [R.NEEDS_NEW_IDS]: UNSUPPORTED,
42
48
  [R.INVALID_NEW_ID]: UNSUPPORTED,
43
49
  [R.SHARED_ID]: UNSUPPORTED,
44
- [R.STALE]: UNSUPPORTED,
50
+ [R.STALE]: grounded("staleRange"),
45
51
  [R.STRUCTURE_MISMATCH]: UNSUPPORTED,
46
52
  [R.EMPTY_CONTENT]: UNSUPPORTED,
47
53
  [R.EMPTY_BLOCK_LIST]: UNSUPPORTED,
@@ -53,7 +59,7 @@ const COMPILER_REFUSAL_DISPOSITIONS = {
53
59
  [R.MISSING_BLOCK_ID]: UNSUPPORTED,
54
60
  [R.DUPLICATE_BLOCK_ID]: UNSUPPORTED,
55
61
  [R.DUPLICATE_RECORD_ID]: UNSUPPORTED,
56
- [R.SECTIONS_OUT_OF_STEP]: UNSUPPORTED,
62
+ [R.SECTIONS_OUT_OF_STEP]: grounded("staleRange"),
57
63
  [R.EMPTY_RECORD]: UNSUPPORTED
58
64
  };
59
65
  /** The skip a refused compilation reports. */
@@ -64,10 +70,10 @@ const compilerRefusalSkip = ({ reason, message }) => {
64
70
  reason: disposition.reason,
65
71
  message
66
72
  };
67
- case "unsupported": return {
68
- reason: "unsupportedBlock",
73
+ case "grounded": return {
74
+ reason: disposition.reason,
69
75
  message,
70
- refusal: { gap: CANONICAL_GAP.publicUnsupportedInline }
76
+ refusal: groundForDocumentOpRefusal(reason)
71
77
  };
72
78
  default: return disposition;
73
79
  }