@stll/folio-core 0.71.1 → 0.73.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 (213) hide show
  1. package/README.md +14 -8
  2. package/dist/ai-edits/apply.d.ts +6 -114
  3. package/dist/ai-edits/apply.js +9 -131
  4. package/dist/ai-edits/applyTypes.d.ts +85 -0
  5. package/dist/ai-edits/applyTypes.js +24 -0
  6. package/dist/ai-edits/clean-text.d.ts +7 -1
  7. package/dist/ai-edits/clean-text.js +23 -2
  8. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  9. package/dist/ai-edits/headless.d.ts +29 -147
  10. package/dist/ai-edits/headless.js +213 -1634
  11. package/dist/ai-edits/index.d.ts +3 -3
  12. package/dist/ai-edits/index.js +2 -3
  13. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  14. package/dist/ai-edits/pending-suggestions.js +183 -90
  15. package/dist/ai-edits/result-validation.js +1 -1
  16. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  17. package/dist/ai-edits/snapshot.js +8 -3
  18. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  19. package/dist/ai-edits/table-cell-mutations.js +1 -1
  20. package/dist/ai-edits/table-geometry.d.ts +1 -1
  21. package/dist/ai-edits/table-geometry.js +1 -1
  22. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  23. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  24. package/dist/ai-edits/tableNodes.d.ts +38 -0
  25. package/dist/ai-edits/tableNodes.js +86 -0
  26. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  27. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  28. package/dist/canonical/batchCommentReferences.js +1 -0
  29. package/dist/canonical/canonicalInlineProjection.js +1 -1
  30. package/dist/canonical/canonicalPublicOperations.js +228 -64
  31. package/dist/canonical/canonicalSession.d.ts +9 -1
  32. package/dist/canonical/canonicalSession.js +95 -15
  33. package/dist/compare/compare.d.ts +1 -1
  34. package/dist/compare/inline-atoms-model.d.ts +1 -1
  35. package/dist/compare/inline-atoms.d.ts +2 -2
  36. package/dist/compare/inline-provenance-model.d.ts +1 -1
  37. package/dist/compare/inline-provenance.d.ts +2 -2
  38. package/dist/compat/eigenpal.d.ts +3 -4
  39. package/dist/compat/eigenpal.js +2 -4
  40. package/dist/controller/canonicalClipboard.d.ts +13 -3
  41. package/dist/controller/canonicalClipboard.js +185 -49
  42. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  43. package/dist/controller/canonicalClipboardResources.js +22 -2
  44. package/dist/controller/canonicalReview.d.ts +1 -1
  45. package/dist/controller/canonicalReview.js +1 -1
  46. package/dist/controller/canonicalStructure.js +1 -1
  47. package/dist/controller/canonicalWatermark.d.ts +10 -0
  48. package/dist/controller/canonicalWatermark.js +37 -0
  49. package/dist/controller/canonicalYjsRoom.d.ts +1 -1
  50. package/dist/controller/headerFooterEditorManager.d.ts +11 -7
  51. package/dist/controller/headerFooterEditorManager.js +39 -151
  52. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  53. package/dist/controller/hiddenEditorManager.d.ts +6 -40
  54. package/dist/controller/hiddenEditorManager.js +173 -306
  55. package/dist/controller/noteEditorManager.d.ts +3 -10
  56. package/dist/controller/noteEditorManager.js +33 -206
  57. package/dist/document-operations-apply.d.ts +15 -0
  58. package/dist/document-operations-apply.js +280 -0
  59. package/dist/document-operations.d.ts +1 -14
  60. package/dist/document-operations.js +2 -279
  61. package/dist/docx/modelValidation.js +1 -1
  62. package/dist/docx/paragraphParser.js +2 -2
  63. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  64. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  65. package/dist/docx/reviewResolutionProvenance.js +32 -9
  66. package/dist/docx/revisionIdNormalization.js +30 -7
  67. package/dist/docx/rezip.js +1 -1
  68. package/dist/docx/serializer/borderSerializer.js +1 -1
  69. package/dist/docx/serializer/commentSerializer.js +1 -1
  70. package/dist/docx/serializer/documentSerializer.js +1 -1
  71. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  72. package/dist/docx/serializer/runSerializer.js +1 -1
  73. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  74. package/dist/docx/serializer/tableSerializer.js +5 -37
  75. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  76. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  77. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  78. package/dist/docx/server/templatePlan/apply.js +600 -0
  79. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  80. package/dist/docx/server/templatePlan/blocks.js +355 -0
  81. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  82. package/dist/docx/server/templatePlan/builders.js +237 -0
  83. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  84. package/dist/docx/server/templatePlan/emit.js +466 -0
  85. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  86. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  87. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  88. package/dist/docx/server/templatePlan/inspect.js +177 -0
  89. package/dist/docx/server/templatePlan/labels.d.ts +36 -0
  90. package/dist/docx/server/templatePlan/labels.js +126 -0
  91. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  92. package/dist/docx/server/templatePlan/package.js +99 -0
  93. package/dist/docx/server/templatePlan/plan.d.ts +143 -0
  94. package/dist/docx/server/templatePlan/plan.js +841 -0
  95. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  96. package/dist/docx/server/templatePlan/planShape.js +161 -0
  97. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  98. package/dist/docx/server/templatePlan/resources.js +136 -0
  99. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  100. package/dist/docx/server/templatePlan/story.js +440 -0
  101. package/dist/docx/server/templatePlan/types.d.ts +406 -0
  102. package/dist/docx/server/templatePlan/types.js +28 -0
  103. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  104. package/dist/docx/server/templatePlan/verify.js +968 -0
  105. package/dist/docx/server/templatePlan/xml.d.ts +69 -0
  106. package/dist/docx/server/templatePlan/xml.js +119 -0
  107. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  108. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  109. package/dist/docx/storyBlockReplay.js +1 -1
  110. package/dist/docx/structuralXmlPatch.js +9 -1
  111. package/dist/docx/tableGridXml.d.ts +30 -0
  112. package/dist/docx/tableGridXml.js +54 -0
  113. package/dist/docx/tableParser.js +7 -0
  114. package/dist/docx/xmlParser.js +1 -1
  115. package/dist/index.d.ts +3 -4
  116. package/dist/index.js +2 -4
  117. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  118. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  119. package/dist/managers/ContextMenuManager.js +2 -1
  120. package/dist/managers/DocumentLoaderManager.d.ts +0 -4
  121. package/dist/managers/DocumentLoaderManager.js +4 -12
  122. package/dist/managers/editorShortcuts.d.ts +1 -1
  123. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  124. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  125. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  126. package/dist/prosemirror/canonicalTableCommands.js +2 -2
  127. package/dist/prosemirror/commands/comments.js +3 -3
  128. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  129. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  130. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  131. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  132. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  133. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  134. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  135. package/dist/prosemirror/commentRecords.d.ts +1 -1
  136. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  137. package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
  138. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  139. package/dist/prosemirror/documentStructureCounts.js +76 -0
  140. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  141. package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
  142. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
  143. package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
  144. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  145. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  146. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  147. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  148. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
  149. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
  150. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
  151. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
  152. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  153. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  154. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  155. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  156. package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
  157. package/dist/prosemirror/extensions/types.d.ts +1 -1
  158. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  159. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  160. package/dist/prosemirror/index.d.ts +1 -1
  161. package/dist/prosemirror/index.js +1 -1
  162. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  163. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  164. package/dist/prosemirror/listNumbering.d.ts +1 -1
  165. package/dist/prosemirror/lockedControls.d.ts +1 -1
  166. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  167. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  168. package/dist/prosemirror/noteReferenceReview.js +1 -1
  169. package/dist/prosemirror/numberingAttr.d.ts +1 -2
  170. package/dist/prosemirror/numberingAttr.js +1 -2
  171. package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
  172. package/dist/prosemirror/outlineLevelAttr.js +1 -2
  173. package/dist/prosemirror/paraIds.d.ts +46 -0
  174. package/dist/prosemirror/paraIds.js +152 -0
  175. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  176. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  177. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  178. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  179. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  180. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  181. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  182. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  183. package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
  184. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  185. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  186. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  187. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  188. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  189. package/dist/prosemirror/replacedAnnotations.js +16 -1
  190. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  191. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  192. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  193. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  194. package/dist/prosemirror/selectionBounds.js +22 -0
  195. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  196. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  197. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  198. package/dist/prosemirror/textInput.d.ts +1 -1
  199. package/dist/server.d.ts +7 -5
  200. package/dist/server.js +6 -4
  201. package/dist/types/canonicalCapabilities.d.ts +8 -41
  202. package/dist/types/canonicalCapabilities.js +6 -34
  203. package/package.json +4 -6
  204. package/dist/controller/collaborationModules.d.ts +0 -3
  205. package/dist/controller/collaborationModules.js +0 -14
  206. package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
  207. package/dist/docx/server/materializeYjsDocx.js +0 -96
  208. package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
  209. package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
  210. package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
  211. package/dist/prosemirror/plugins/derivedFields.js +0 -52
  212. package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
  213. package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
@@ -1,10 +1,8 @@
1
- /** Framework-neutral lifecycle owner for editable footnote and endnote stories. */
2
- import { CanonicalRefusalGround, EditorSession } from "../types/canonicalCapabilities.js";
1
+ import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
3
2
  import { document_d_exports } from "../types/document.js";
4
3
  import { DeepReadonly, ReadonlyDocument } from "../types/documentModel.js";
5
4
  import { NoteStoryKey } from "../types/editor-story.js";
6
5
  import { HiddenEditorApi } from "./hiddenEditorApi.js";
7
- import { Plugin } from "prosemirror-state";
8
6
  import { DirectEditorProps, EditorView } from "prosemirror-view";
9
7
  export type NoteStoryKind = NoteStoryKey["kind"];
10
8
  export type NoteEditorTransaction = NoteStoryKey & {
@@ -14,19 +12,15 @@ export type NoteEditorTransaction = NoteStoryKey & {
14
12
  };
15
13
  export type NoteEditorManagerDeps = {
16
14
  createView?: ((mountNode: HTMLElement, props: DirectEditorProps) => EditorView) | undefined;
17
- getDocument: () => ReadonlyDocument | null;
18
15
  getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
19
16
  /**
20
17
  * The canonical session's own document, read without a copy (see
21
18
  * `HiddenEditorManager.readCanonicalDocument`); null outside a session.
22
19
  */
23
20
  readCanonicalDocument: () => ReadonlyDocument | null;
24
- getExperimentalSession?: (() => EditorSession | undefined) | undefined;
25
21
  onSessionRefusal?: ((reason: string, ground: CanonicalRefusalGround, error?: Error) => void) | undefined;
26
22
  getHost: () => HTMLElement | null;
27
- getPlugins?: (() => Plugin[]) | undefined;
28
23
  getStyles: () => DeepReadonly<document_d_exports.StyleDefinitions> | null | undefined;
29
- getTheme: () => DeepReadonly<document_d_exports.Theme> | null | undefined;
30
24
  onTransaction?: ((transaction: NoteEditorTransaction) => void) | undefined;
31
25
  };
32
26
  export type NoteEditorManager = {
@@ -36,11 +30,10 @@ export type NoteEditorManager = {
36
30
  getView: (story: NoteStoryKey) => EditorView | null;
37
31
  listStories: () => NoteStoryKey[];
38
32
  /**
39
- * The model with the edited notes written back. It shares what no edit
40
- * touched with `model` and with the mounted editors, so it is read-only: a
33
+ * The session's document with every story's edits. It is read-only: a
41
34
  * writer copies it first (`cloneDocumentWithParagraphPropertySources`).
42
35
  */
43
- snapshotDocument: (model: ReadonlyDocument) => ReadonlyDocument;
36
+ snapshotDocument: () => ReadonlyDocument;
44
37
  sync: () => void;
45
38
  };
46
39
  export declare const enumerateDocumentNoteStories: (document: document_d_exports.Document | null) => NoteStoryKey[];
@@ -1,29 +1,18 @@
1
1
  import { CanonicalSessionError } from "../canonical/canonicalSession.js";
2
2
  import { isSeparatorEndnote, isSeparatorFootnote } from "../docx/footnoteParser.js";
3
- import { cloneDocumentWithParagraphPropertySources } from "../docx/paragraphPropertySource.js";
4
- import { visitDocxParagraphs, visitParagraphRuns } from "../docx/paragraphTraversal.js";
5
- import { proseDocToBlocks } from "../prosemirror/conversion/fromProseDoc.js";
6
- import { storyConversionOptions } from "../prosemirror/conversion/storyConversionOptions.js";
7
- import { footnoteToProseDoc } from "../prosemirror/conversion/toProseDoc.js";
8
- import { ExtensionManager } from "../prosemirror/extensions/ExtensionManager.js";
9
- import { createStarterKit } from "../prosemirror/extensions/StarterKit.js";
10
- import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
11
- import { ensureParaIdsInState } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
12
3
  import { createNativeNavigationPlugin, createNativeSelectionRefreshPlugin } from "../prosemirror/nativeSelection.js";
13
4
  import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
14
5
  import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
15
- import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
16
- import { schema } from "../prosemirror/schema/index.js";
17
- import { storyListNumbering } from "../prosemirror/storyListNumbering.js";
18
- import { CANONICAL_GAP, usesCanonicalSession } from "../types/canonicalCapabilities.js";
6
+ import { createDocumentStyleContextPlugin } from "../prosemirror/plugins/documentStyles.js";
7
+ import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
19
8
  import { readModel } from "../types/documentModel.js";
20
9
  import { createCanonicalStoryEditor, refreshCanonicalStoryView } from "./canonicalStoryEditor.js";
21
10
  import { OP_STORIES } from "@stll/docx-core/ops";
22
11
  import { EditorState } from "prosemirror-state";
23
12
  import { EditorView } from "prosemirror-view";
24
13
  // src/controller/noteEditorManager.ts
14
+ /** Framework-neutral lifecycle owner for editable footnote and endnote stories. */
25
15
  const createEditorView = (mountNode, props) => new EditorView(mountNode, props);
26
- const EMPTY_PLUGINS = [];
27
16
  const storyMapKey = ({ kind, noteId }) => `${kind}:${String(noteId)}`;
28
17
  const isNormalFootnote = (note) => !isSeparatorFootnote(note);
29
18
  const isNormalEndnote = (note) => !isSeparatorEndnote(note);
@@ -37,44 +26,6 @@ const enumerateDocumentNoteStories = (document) => [...(document?.package.footno
37
26
  const resolveNote = (document, story) => {
38
27
  return (story.kind === "footnote" ? document?.package.footnotes : document?.package.endnotes)?.find(({ id }) => id === story.noteId) ?? null;
39
28
  };
40
- const noteToProseDocument = (note, options) => footnoteToProseDoc(note.content, options);
41
- const buildInitialState = (document, styles, numbering, manager, externalPlugins) => {
42
- return ensureBaseDirectionInState(ensureParaIdsInState(EditorState.create({
43
- doc: document,
44
- schema,
45
- plugins: [
46
- createDocumentNumberingPlugin(numbering),
47
- ...manager.getPlugins(),
48
- ...externalPlugins,
49
- createDocumentStylesPlugin(styles)
50
- ]
51
- })));
52
- };
53
- /** Automatic note marks have no PM width; retain their authored runs on default writeback. */
54
- const preserveNoteMarkers = ({ source, projected }) => {
55
- const marks = [];
56
- visitDocxParagraphs({ documentBody: { content: source } }, (paragraph) => visitParagraphRuns(paragraph, (run) => {
57
- const content = run.content.filter((child) => child.type === "noteMarker");
58
- if (content.length > 0) marks.push({
59
- ...run,
60
- content
61
- });
62
- }));
63
- if (marks.length === 0) return projected;
64
- let hasMarker = false;
65
- visitDocxParagraphs({ documentBody: { content: projected } }, (paragraph) => visitParagraphRuns(paragraph, (run) => {
66
- if (run.content.some((child) => child.type === "noteMarker")) hasMarker = true;
67
- }));
68
- if (hasMarker) return projected;
69
- const owned = cloneDocumentWithParagraphPropertySources({ package: { document: { content: projected } } }).package.document.content;
70
- const paragraphs = [];
71
- visitDocxParagraphs({ documentBody: { content: owned } }, (paragraph) => {
72
- paragraphs.push(paragraph);
73
- });
74
- const first = paragraphs.at(0);
75
- if (first) first.content.unshift(...marks);
76
- return owned;
77
- };
78
29
  const createNoteEditorManager = (deps) => {
79
30
  const mounted = /* @__PURE__ */ new Map();
80
31
  let active = null;
@@ -84,7 +35,6 @@ const createNoteEditorManager = (deps) => {
84
35
  };
85
36
  const destroyMounted = (story) => {
86
37
  story.view.destroy();
87
- story.manager.destroy();
88
38
  story.mountNode.remove();
89
39
  };
90
40
  const destroy = () => {
@@ -92,22 +42,14 @@ const createNoteEditorManager = (deps) => {
92
42
  mounted.clear();
93
43
  active = null;
94
44
  };
95
- const getOwnedDocument = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.readCanonicalDocument() : deps.getDocument();
96
45
  const sync = () => {
97
46
  const host = deps.getHost();
98
47
  if (!host) return;
99
- if (usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) && !deps.getCanonicalApi?.()?.getCanonicalStoryProjection(OP_STORIES.MAIN)) return;
100
- const owned = getOwnedDocument();
48
+ if (!deps.getCanonicalApi?.()?.getCanonicalStoryProjection(OP_STORIES.MAIN)) return;
49
+ const owned = deps.readCanonicalDocument();
101
50
  const document = owned && readModel(owned);
102
51
  const styles = deps.getStyles();
103
- const theme = deps.getTheme();
104
52
  const numbering = document?.package.numbering;
105
- const proseOptions = storyConversionOptions({
106
- styles,
107
- theme,
108
- numbering
109
- });
110
- const externalPlugins = deps.getPlugins?.() ?? EMPTY_PLUGINS;
111
53
  const wanted = new Map(enumerateDocumentNoteStories(document).map((story) => [storyMapKey(story), story]));
112
54
  const activeKey = active ? storyMapKey(active) : null;
113
55
  for (const [key, story] of mounted) {
@@ -117,57 +59,20 @@ const createNoteEditorManager = (deps) => {
117
59
  }
118
60
  for (const [key, storyKey] of wanted) {
119
61
  if (!mounted.has(key) && key !== activeKey) continue;
120
- const note = resolveNote(document, storyKey);
121
- if (!note) continue;
62
+ if (!resolveNote(document, storyKey)) continue;
122
63
  const existing = mounted.get(key);
123
64
  if (existing) {
124
65
  if (existing.mountNode.parentElement !== host) host.append(existing.mountNode);
125
- if (usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) {
126
- refreshCanonicalStoryView({
127
- view: existing.view,
128
- story: {
129
- kind: storyKey.kind,
130
- id: storyKey.noteId
131
- },
132
- api: deps.getCanonicalApi?.()
133
- });
134
- existing.appliedNote = note;
135
- existing.appliedContent = note.content;
136
- existing.appliedProseDocument = existing.view.state.doc;
137
- existing.appliedStyles = styles;
138
- existing.appliedTheme = theme;
139
- existing.appliedNumbering = numbering;
140
- existing.appliedPlugins = externalPlugins;
141
- existing.dirty = false;
142
- continue;
143
- }
144
- const nextProseDocument = noteToProseDocument(note, proseOptions);
145
- const contextIsCurrent = existing.appliedStyles === styles && existing.appliedTheme === theme && existing.appliedNumbering === numbering && existing.appliedPlugins === externalPlugins;
146
- if ((existing.appliedNote === note && existing.appliedContent === note.content || existing.appliedProseDocument.eq(nextProseDocument)) && contextIsCurrent) {
147
- existing.appliedNote = note;
148
- existing.appliedContent = note.content;
149
- existing.appliedProseDocument = nextProseDocument;
150
- continue;
151
- }
152
- existing.view.updateState(buildInitialState(nextProseDocument, styles, numbering, existing.manager, externalPlugins));
153
- existing.appliedNote = note;
154
- existing.appliedContent = note.content;
155
- existing.appliedStyles = styles;
156
- existing.appliedTheme = theme;
157
- existing.appliedNumbering = numbering;
158
- existing.appliedPlugins = externalPlugins;
159
- existing.appliedProseDocument = nextProseDocument;
160
- existing.dirty = false;
66
+ refreshCanonicalStoryView({
67
+ view: existing.view,
68
+ story: {
69
+ kind: storyKey.kind,
70
+ id: storyKey.noteId
71
+ },
72
+ api: deps.getCanonicalApi?.()
73
+ });
161
74
  continue;
162
75
  }
163
- const manager = new ExtensionManager(createStarterKit());
164
- manager.buildSchema();
165
- manager.initializeRuntime();
166
- const mountNode = host.ownerDocument.createElement("div");
167
- mountNode.dataset["noteKind"] = storyKey.kind;
168
- mountNode.dataset["noteId"] = String(storyKey.noteId);
169
- host.append(mountNode);
170
- const proseDocument = noteToProseDocument(note, proseOptions);
171
76
  const canonical = createCanonicalStoryEditor({
172
77
  story: {
173
78
  kind: storyKey.kind,
@@ -175,7 +80,7 @@ const createNoteEditorManager = (deps) => {
175
80
  },
176
81
  getView: () => view,
177
82
  getApi: () => deps.getCanonicalApi?.() ?? null,
178
- enabled: () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting),
83
+ enabled: () => true,
179
84
  onRefusal: deps.onSessionRefusal,
180
85
  onSelectionChange: () => deps.onTransaction?.({
181
86
  ...storyKey,
@@ -184,18 +89,18 @@ const createNoteEditorManager = (deps) => {
184
89
  selectionChanged: true
185
90
  })
186
91
  });
187
- const canonicalProjection = usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) ? deps.getCanonicalApi?.()?.getCanonicalStoryProjection({
92
+ const canonicalProjection = deps.getCanonicalApi?.()?.getCanonicalStoryProjection({
188
93
  kind: storyKey.kind,
189
94
  id: storyKey.noteId
190
- }) : null;
191
- if (usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting) && !canonicalProjection) {
192
- manager.destroy();
193
- mountNode.remove();
194
- continue;
195
- }
95
+ });
96
+ if (!canonicalProjection) continue;
97
+ const mountNode = host.ownerDocument.createElement("div");
98
+ mountNode.dataset["noteKind"] = storyKey.kind;
99
+ mountNode.dataset["noteId"] = String(storyKey.noteId);
100
+ host.append(mountNode);
196
101
  const view = (deps.createView ?? createEditorView)(mountNode, {
197
102
  ...canonical.props,
198
- state: canonicalProjection ? EditorState.create({
103
+ state: EditorState.create({
199
104
  doc: canonicalProjection,
200
105
  plugins: [
201
106
  createDocumentNumberingPlugin(numbering),
@@ -203,7 +108,7 @@ const createNoteEditorManager = (deps) => {
203
108
  createNativeSelectionRefreshPlugin(),
204
109
  createNativeNavigationPlugin()
205
110
  ]
206
- }) : buildInitialState(proseDocument, styles, numbering, manager, externalPlugins),
111
+ }),
207
112
  dispatchTransaction(transaction) {
208
113
  if (canonical.dispatch(transaction)) return;
209
114
  const nextState = view.state.apply(transaction);
@@ -211,8 +116,6 @@ const createNoteEditorManager = (deps) => {
211
116
  view.updateState(nextState);
212
117
  const noteIssue = noteReferenceTransactionIssue(transaction);
213
118
  if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
214
- const mountedStory = mounted.get(key);
215
- if (mountedStory && docChanged) mountedStory.dirty = true;
216
119
  deps.onTransaction?.({
217
120
  ...storyKey,
218
121
  docChanged,
@@ -222,15 +125,6 @@ const createNoteEditorManager = (deps) => {
222
125
  }
223
126
  });
224
127
  mounted.set(key, {
225
- appliedContent: note.content,
226
- appliedNote: note,
227
- appliedNumbering: numbering,
228
- appliedPlugins: externalPlugins,
229
- appliedProseDocument: proseDocument,
230
- appliedStyles: styles,
231
- appliedTheme: theme,
232
- dirty: false,
233
- manager,
234
128
  mountNode,
235
129
  note: storyKey,
236
130
  view
@@ -254,84 +148,17 @@ const createNoteEditorManager = (deps) => {
254
148
  getActive: () => active,
255
149
  getView: (story) => mounted.get(storyMapKey(story))?.view ?? null,
256
150
  listStories: () => {
257
- const owned = getOwnedDocument();
151
+ const owned = deps.readCanonicalDocument();
258
152
  return enumerateDocumentNoteStories(owned && readModel(owned));
259
153
  },
260
- snapshotDocument: (model) => {
261
- if (usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) {
262
- const canonical = deps.getCanonicalApi?.()?.getCanonicalDocument();
263
- if (canonical) return canonical;
264
- throw new CanonicalSessionError({
265
- ground: { gap: CANONICAL_GAP.authorityRouting },
266
- reason: "refused",
267
- message: "Canonical story snapshot is unavailable."
268
- });
269
- }
270
- const document = readModel(model);
271
- let footnotes = document.package.footnotes;
272
- let endnotes = document.package.endnotes;
273
- let footnotesChanged = false;
274
- let endnotesChanged = false;
275
- let numbering = document.package.numbering;
276
- for (const story of mounted.values()) {
277
- if (!story.dirty) continue;
278
- const lists = storyListNumbering(story.view.state, numbering);
279
- numbering = lists.numbering;
280
- const proseOptions = storyConversionOptions({
281
- styles: story.appliedStyles,
282
- theme: story.appliedTheme,
283
- numbering
284
- });
285
- if (story.note.kind === "footnote") {
286
- const index = footnotes?.findIndex(({ id }) => id === story.note.noteId) ?? -1;
287
- const current = index === -1 ? null : footnotes?.at(index);
288
- if (!current || !footnotes) continue;
289
- if (!footnotesChanged) {
290
- footnotes = [...footnotes];
291
- footnotesChanged = true;
292
- }
293
- const updated = {
294
- ...current,
295
- content: preserveNoteMarkers({
296
- source: current.content,
297
- projected: proseDocToBlocks(lists.doc, current.content, document.package.styles)
298
- })
299
- };
300
- footnotes[index] = updated;
301
- story.appliedNote = updated;
302
- story.appliedContent = updated.content;
303
- story.appliedProseDocument = noteToProseDocument(updated, proseOptions);
304
- continue;
305
- }
306
- const index = endnotes?.findIndex(({ id }) => id === story.note.noteId) ?? -1;
307
- const current = index === -1 ? null : endnotes?.at(index);
308
- if (!current || !endnotes) continue;
309
- if (!endnotesChanged) {
310
- endnotes = [...endnotes];
311
- endnotesChanged = true;
312
- }
313
- const updated = {
314
- ...current,
315
- content: preserveNoteMarkers({
316
- source: current.content,
317
- projected: proseDocToBlocks(lists.doc, current.content, document.package.styles)
318
- })
319
- };
320
- endnotes[index] = updated;
321
- story.appliedNote = updated;
322
- story.appliedContent = updated.content;
323
- story.appliedProseDocument = noteToProseDocument(updated, proseOptions);
324
- }
325
- if (!footnotesChanged && !endnotesChanged) return model;
326
- return {
327
- ...document,
328
- package: {
329
- ...document.package,
330
- ...footnotesChanged && footnotes ? { footnotes } : {},
331
- ...endnotesChanged && endnotes ? { endnotes } : {},
332
- ...numbering ? { numbering } : {}
333
- }
334
- };
154
+ snapshotDocument: () => {
155
+ const canonical = deps.getCanonicalApi?.()?.getCanonicalDocument();
156
+ if (canonical) return canonical;
157
+ throw new CanonicalSessionError({
158
+ ground: { gap: CANONICAL_GAP.authorityRouting },
159
+ reason: "refused",
160
+ message: "Canonical story snapshot is unavailable."
161
+ });
335
162
  },
336
163
  sync
337
164
  };
@@ -0,0 +1,15 @@
1
+ import { ApplyFolioDocumentOperationsOptions, FolioDocumentOperationResult } from "./document-operations.js";
2
+ import { NumberingIdsInUse } from "./docx/numberingIds.js";
3
+ export declare const applyFolioDocumentOperations: (input: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
4
+ /**
5
+ * Options of a caller that holds every story of the package: the numbering
6
+ * ids (`w:num`, `w:abstractNum`) the other stories define. A list the batch
7
+ * starts takes none of them, so its id names it in every story and survives a
8
+ * save.
9
+ */
10
+ type ApplyFolioDocumentOperationsInPackageOptions = ApplyFolioDocumentOperationsOptions & {
11
+ numberingIdsElsewhere: NumberingIdsInUse;
12
+ };
13
+ /** {@link applyFolioDocumentOperations} for a caller holding every story. Internal. */
14
+ export declare const applyFolioDocumentOperationsInPackage: ({ view, snapshot, batch, story, author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, pendingSuggestionIds, numberingIdsElsewhere, restagesSuggestions }: ApplyFolioDocumentOperationsInPackageOptions) => FolioDocumentOperationResult;
15
+ export {};
@@ -0,0 +1,280 @@
1
+ import { applyFolioAIEditOperationsInPackage, previewFolioAIEditOperationsWithResult } from "./ai-edits/apply.js";
2
+ import { describeModelError, findIntroducedModelErrors } from "./ai-edits/result-validation.js";
3
+ import { trackedBatchFidelityError } from "./ai-edits/tracked-batch-fidelity.js";
4
+ import { getFolioDocumentOperationIssues, getFolioDocumentOperationReceiptsForStory, parseFolioDocumentOperationBatch, withDistinctSuggestionIds } from "./document-operations.js";
5
+ import { NO_NUMBERING_IDS_IN_USE } from "./docx/numberingIds.js";
6
+ import { getSuggestions } from "./prosemirror/commands/comments.js";
7
+ import { completeNumberingForDoc } from "./prosemirror/listInstanceReferences.js";
8
+ import { getStatedDocumentNumbering } from "./prosemirror/plugins/documentNumbering.js";
9
+ // src/document-operations-apply.ts
10
+ const NO_COMMIT = () => {};
11
+ /** Skips reported in the order of the operations they belong to. */
12
+ const inOperationOrder = (operations, skipped) => {
13
+ const indexById = new Map(operations.map(({ id }, index) => [id, index]));
14
+ return [...skipped].sort((left, right) => (indexById.get(left.id) ?? -1) - (indexById.get(right.id) ?? -1));
15
+ };
16
+ const applyFolioDocumentOperations = (input) => applyFolioDocumentOperationsInPackage({
17
+ ...input,
18
+ numberingIdsElsewhere: NO_NUMBERING_IDS_IN_USE
19
+ });
20
+ /** {@link applyFolioDocumentOperations} for a caller holding every story. Internal. */
21
+ const applyFolioDocumentOperationsInPackage = ({ view, snapshot, batch, story = "main", author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences, pendingSuggestionIds, numberingIdsElsewhere, restagesSuggestions }) => {
22
+ const validatedBatch = parseFolioDocumentOperationBatch(batch);
23
+ const parsedBatch = restagesSuggestions === true ? validatedBatch : withDistinctSuggestionIds(validatedBatch, /* @__PURE__ */ new Set([...getSuggestions(view.state).map(({ suggestionId }) => suggestionId), ...pendingSuggestionIds ?? []]));
24
+ const isAtomic = parsedBatch.atomic === true;
25
+ const beforeDoc = view.state.doc;
26
+ const packageNumbering = getStatedDocumentNumbering(view.state);
27
+ const attempt = (operations, preview) => {
28
+ const common = {
29
+ snapshot,
30
+ operations,
31
+ mode: parsedBatch.mode ?? "tracked-changes",
32
+ ...parsedBatch.existingRevisions === "refuse-cross-author" && { refuseCrossAuthorRevisions: true },
33
+ ...author !== void 0 && { author },
34
+ ...revisionStamp !== void 0 && { revisionStamp },
35
+ ...wordDiff !== void 0 && { wordDiff },
36
+ ...tableTemplates !== void 0 && { tableTemplates },
37
+ ...replacementBackground !== void 0 && { replacementBackground },
38
+ numberingIdsElsewhere,
39
+ undefinedReferences
40
+ };
41
+ if (preview) return {
42
+ ...previewFolioAIEditOperationsWithResult({
43
+ ...common,
44
+ view,
45
+ ...createCommentId !== void 0 && { createCommentId }
46
+ }, parsedBatch.dryRun && common.mode === "tracked-changes" ? "bounded" : "coarse"),
47
+ commit: NO_COMMIT
48
+ };
49
+ const held = {};
50
+ const commentIds = [];
51
+ return {
52
+ outcome: applyFolioAIEditOperationsInPackage({
53
+ ...common,
54
+ view: {
55
+ state: view.state,
56
+ dispatch: (transaction) => {
57
+ held.transaction = transaction;
58
+ }
59
+ },
60
+ ...createCommentId !== void 0 && { createCommentId: (text) => {
61
+ const id = createCommentId(text);
62
+ commentIds.push(id);
63
+ return id;
64
+ } }
65
+ }),
66
+ doc: held.transaction?.doc ?? null,
67
+ commentIds,
68
+ commit: () => {
69
+ if (held.transaction !== void 0) view.dispatch(held.transaction);
70
+ }
71
+ };
72
+ };
73
+ const introducedErrors = (run) => {
74
+ if (run.doc === null || run.outcome.applied.length === 0) return [];
75
+ const numbering = packageNumbering === void 0 ? void 0 : completeNumberingForDoc(packageNumbering ?? void 0, run.doc) ?? null;
76
+ return findIntroducedModelErrors(beforeDoc, run.doc, {
77
+ numbering,
78
+ createdCommentIds: run.commentIds,
79
+ ...author !== void 0 && { commentAuthor: author }
80
+ });
81
+ };
82
+ /**
83
+ * An attempt on the refusal path, where the applier runs on subsets of the
84
+ * batch it was not asked to apply: a throw there is one more reason to
85
+ * refuse, never a reason to fail a batch the first run could apply.
86
+ */
87
+ const checkedAttempt = (operations, preview) => {
88
+ try {
89
+ const run = attempt(operations, preview);
90
+ return {
91
+ run,
92
+ error: introducedErrors(run)[0]
93
+ };
94
+ } catch (error) {
95
+ return {
96
+ run: null,
97
+ error: {
98
+ path: "package.document",
99
+ message: `the operation could not be applied (${error instanceof Error ? error.message : String(error)}).`,
100
+ severity: "error"
101
+ }
102
+ };
103
+ }
104
+ };
105
+ /**
106
+ * Which applied operations produced the unsaveable result: each one is
107
+ * previewed alone against the unchanged story. When none fails alone, the
108
+ * failure is their combination, and every one of them is refused.
109
+ */
110
+ const refuseInvalidResult = (run, firstError) => {
111
+ const operationsById = new Map(parsedBatch.operations.map((operation) => [operation.id, operation]));
112
+ const refused = [];
113
+ for (const { id } of run.outcome.applied) {
114
+ const operation = operationsById.get(id);
115
+ if (operation === void 0) continue;
116
+ const alone = checkedAttempt([operation], true).error;
117
+ if (alone !== void 0) refused.push({
118
+ id,
119
+ reason: "invalidResult",
120
+ message: describeModelError(alone)
121
+ });
122
+ }
123
+ if (refused.length > 0) return refused;
124
+ return run.outcome.applied.map(({ id }) => ({
125
+ id,
126
+ reason: "invalidResult",
127
+ message: describeModelError(firstError)
128
+ }));
129
+ };
130
+ /**
131
+ * A fidelity failure invalidates the batch. Preserve the refusal details
132
+ * for operations already skipped by the applier or save-time validator.
133
+ */
134
+ const refuseFidelityLoss = (run, skipped = []) => {
135
+ if (run.doc === null || parsedBatch.mode === "direct" || parsedBatch.mode === "suggested") return null;
136
+ const message = trackedBatchFidelityError({
137
+ before: view.state,
138
+ after: run.doc,
139
+ createdCommentIds: run.commentIds,
140
+ retiredCommentIds: run.outcome.applied.flatMap(({ retiredCommentIds }) => retiredCommentIds ?? [])
141
+ });
142
+ if (message === null) return null;
143
+ return {
144
+ fidelityRefused: true,
145
+ outcome: {
146
+ ...run.outcome,
147
+ applied: [],
148
+ skipped: inOperationOrder(parsedBatch.operations, [
149
+ ...run.outcome.skipped,
150
+ ...skipped,
151
+ ...run.outcome.applied.map(({ id }) => ({
152
+ id,
153
+ reason: "invalidResult",
154
+ message
155
+ }))
156
+ ])
157
+ },
158
+ commit: NO_COMMIT
159
+ };
160
+ };
161
+ /** Check the held result before dispatching any operation to the caller. */
162
+ const guardedAttempt = (preview) => {
163
+ const first = attempt(parsedBatch.operations, preview);
164
+ const [firstError] = introducedErrors(first);
165
+ if (firstError === void 0) {
166
+ const fidelity = preview && !parsedBatch.dryRun ? null : refuseFidelityLoss(first);
167
+ if (fidelity !== null) return fidelity;
168
+ return {
169
+ outcome: {
170
+ ...first.outcome,
171
+ skipped: inOperationOrder(parsedBatch.operations, first.outcome.skipped)
172
+ },
173
+ commit: first.commit
174
+ };
175
+ }
176
+ const refused = refuseInvalidResult(first, firstError);
177
+ const refusedIds = new Set(refused.map(({ id }) => id));
178
+ if (isAtomic) return {
179
+ outcome: {
180
+ ...first.outcome,
181
+ applied: [],
182
+ skipped: inOperationOrder(parsedBatch.operations, [...first.outcome.skipped, ...refused])
183
+ },
184
+ commit: NO_COMMIT
185
+ };
186
+ const second = checkedAttempt(parsedBatch.operations.filter(({ id }) => !refusedIds.has(id)), preview);
187
+ if (second.run === null || second.error !== void 0) {
188
+ const reported = second.run?.outcome ?? first.outcome;
189
+ return {
190
+ outcome: {
191
+ ...reported,
192
+ applied: [],
193
+ skipped: inOperationOrder(parsedBatch.operations, [
194
+ ...reported.skipped.filter(({ id }) => !refusedIds.has(id)),
195
+ ...refused,
196
+ ...reported.applied.filter(({ id }) => !refusedIds.has(id)).map(({ id }) => ({
197
+ id,
198
+ reason: "invalidResult",
199
+ message: describeModelError(second.error ?? firstError)
200
+ }))
201
+ ])
202
+ },
203
+ commit: NO_COMMIT
204
+ };
205
+ }
206
+ const fidelity = refuseFidelityLoss(second.run, refused);
207
+ if (fidelity !== null) return fidelity;
208
+ return {
209
+ outcome: {
210
+ ...second.run.outcome,
211
+ skipped: inOperationOrder(parsedBatch.operations, [...second.run.outcome.skipped, ...refused])
212
+ },
213
+ commit: second.run.commit
214
+ };
215
+ };
216
+ const preview = () => guardedAttempt(true).outcome;
217
+ const atomicResult = (previewResult, status) => {
218
+ const skippedById = new Map(previewResult.skipped.map((operation) => [operation.id, operation]));
219
+ const skipped = parsedBatch.operations.map(({ id }) => skippedById.get(id) ?? {
220
+ id,
221
+ reason: "atomicBatchRejected"
222
+ });
223
+ return {
224
+ version: 1,
225
+ status,
226
+ applied: [],
227
+ skipped,
228
+ issues: getFolioDocumentOperationIssues(parsedBatch.operations, skipped),
229
+ receipts: [],
230
+ ...previewResult.normalizations !== void 0 && { normalizations: previewResult.normalizations },
231
+ undoHandle: null,
232
+ nextRevisionId: previewResult.nextRevisionId
233
+ };
234
+ };
235
+ if (parsedBatch.dryRun === true) {
236
+ const previewResult = preview();
237
+ if (isAtomic && previewResult.skipped.length > 0) return atomicResult(previewResult, "previewed");
238
+ return {
239
+ version: 1,
240
+ status: "previewed",
241
+ applied: previewResult.applied.map(({ id, paragraphIdentity, retiredCommentIds }) => ({
242
+ id,
243
+ ...paragraphIdentity === void 0 ? {} : { paragraphIdentity },
244
+ ...retiredCommentIds === void 0 ? {} : { retiredCommentIds }
245
+ })),
246
+ skipped: previewResult.skipped,
247
+ issues: getFolioDocumentOperationIssues(parsedBatch.operations, previewResult.skipped),
248
+ receipts: getFolioDocumentOperationReceiptsForStory({
249
+ operations: parsedBatch.operations,
250
+ applied: previewResult.applied,
251
+ story
252
+ }),
253
+ ...previewResult.normalizations !== void 0 && { normalizations: previewResult.normalizations },
254
+ undoHandle: null,
255
+ nextRevisionId: previewResult.nextRevisionId
256
+ };
257
+ }
258
+ if (isAtomic) {
259
+ const previewResult = preview();
260
+ if (previewResult.skipped.length > 0) return atomicResult(previewResult, "rejected");
261
+ }
262
+ const guarded = guardedAttempt(false);
263
+ const { heldRevisionConflict, ...result } = guarded.outcome;
264
+ if (heldRevisionConflict) return atomicResult(result, "rejected");
265
+ if (guarded.fidelityRefused === true || isAtomic && result.skipped.some(({ reason }) => reason === "invalidResult")) return atomicResult(result, "rejected");
266
+ guarded.commit();
267
+ return {
268
+ version: 1,
269
+ status: "committed",
270
+ ...result,
271
+ issues: getFolioDocumentOperationIssues(parsedBatch.operations, result.skipped),
272
+ receipts: getFolioDocumentOperationReceiptsForStory({
273
+ operations: parsedBatch.operations,
274
+ applied: result.applied,
275
+ story
276
+ }),
277
+ undoHandle: result.applied.length > 0 && createUndoHandle !== void 0 ? createUndoHandle() : null
278
+ };
279
+ };
280
+ export { applyFolioDocumentOperations, applyFolioDocumentOperationsInPackage };