@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
package/README.md CHANGED
@@ -4,11 +4,17 @@
4
4
 
5
5
  # @stll/folio-core
6
6
 
7
- The headless, framework-neutral core of [folio](https://github.com/stella/folio):
8
- the OOXML (`.docx`) parser, the document model, the ProseMirror integration, and
9
- the page-layout engine. It opens a real `.docx`, models it, paginates it, and
10
- writes a real `.docx` back — preserving tables, headers and footers, tracked
11
- changes, and footnotes.
7
+ The headless DOCX engine behind [folio](https://github.com/stella/folio). It
8
+ reads a `.docx` into a typed OOXML model, applies every edit as a validated
9
+ operation on that model, paginates it, and writes a valid `.docx` back. Parts
10
+ of the package that no edit touched are written back byte for byte.
11
+
12
+ Typing in the editor, tracked changes, comments, AI suggestions, collaborative
13
+ edits and server-side review all go through the same operations, so the same
14
+ edit gives the same document wherever it runs. An edit the engine cannot make
15
+ is refused whole, never half-applied. In the browser editors, ProseMirror
16
+ handles keyboard input and selection; the document model is the source of
17
+ truth, and folio lays out and paints the pages itself.
12
18
 
13
19
  There is **no React** in the import graph, so the core runs on a server or under
14
20
  any framework. The React editor lives in
@@ -23,12 +29,12 @@ Part of [stella](https://github.com/stella/stella), an open-source legal workspa
23
29
  bun add @stll/folio-core \
24
30
  prosemirror-commands@^1.7.1 prosemirror-dropcursor@^1.8.2 prosemirror-gapcursor@^1.4.1 prosemirror-history@^1.5.0 \
25
31
  prosemirror-inputrules@^1.5.0 prosemirror-keymap@^1.2.3 prosemirror-model@^1.25.9 prosemirror-state@^1.4.4 \
26
- prosemirror-tables@^1.8.5 prosemirror-transform@^1.12.0 prosemirror-view@^1.42.6 y-prosemirror@^1.3.7 \
32
+ prosemirror-tables@^1.8.5 prosemirror-transform@^1.12.0 prosemirror-view@^1.42.6 \
27
33
  y-protocols@^1.0.6 yjs@^13.6.31
28
34
  ```
29
35
 
30
36
  ProseMirror and Yjs packages are required peers, including the collaboration
31
- packages `y-prosemirror` and `y-protocols`. Install one compatible copy of each in the host
37
+ package `y-protocols`. Install one compatible copy of each in the host
32
38
  application so schemas, plugins, editor states, and collaborative documents share
33
39
  the same runtime. The command above includes the complete editor peer closure.
34
40
 
@@ -36,7 +42,7 @@ the same runtime. The command above includes the complete editor peer closure.
36
42
 
37
43
  | Import | What it is |
38
44
  | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
39
- | `@stll/folio-core` | the headless public API — document creation, representation-neutral comparison, the document model, AI-suggestion primitives, and ProseMirror plugins |
45
+ | `@stll/folio-core` | the headless public API — document creation, representation-neutral comparison, the document model, AI-suggestion primitives, and editor decoration plugins |
40
46
  | `@stll/folio-core/markdown` | DOCX ↔ Markdown conversion |
41
47
  | `@stll/folio-core/server` | DOM-free document review, explicit tracked edits, comparison, creation, and package helpers |
42
48
  | `@stll/folio-core/redline` | Compare two `.docx` buffers and generate a native Word redline |
@@ -1,37 +1,10 @@
1
1
  import { NumberingIdsInUse } from "../docx/numberingIds.js";
2
- import { FolioTableTemplates, TableStructureRevision } from "./table-template.js";
3
- import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioAIResolvedEditOperation, FolioAISignatureParty } from "./types.js";
2
+ import { FolioAIEditApplyOutcome, FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioWordDiffOptions } from "./applyTypes.js";
3
+ import { FolioTableTemplates } from "./table-template.js";
4
+ import { FolioAIEditApplyMode, FolioAIEditOperation, FolioAIEditSnapshot } from "./types.js";
4
5
  import { FolioUndefinedReferencePolicy } from "./undefinedReferences.js";
5
- import { WordDiffGranularity } from "./word-diff.js";
6
- import { Node, Schema } from "prosemirror-model";
7
- import { EditorState, Transaction } from "prosemirror-state";
8
- /**
9
- * The only editor surface the apply logic touches: a current `state`
10
- * and a `dispatch` that swaps in the next one. A live `EditorView`
11
- * satisfies this structurally, and so does a headless seam
12
- * (`{ state, dispatch: (tr) => { state = state.apply(tr); } }`) — the
13
- * apply path never reaches for anything DOM-bound on the view, which is
14
- * what lets the same operation applier drive both the React editor and
15
- * the server-side reviewer in `./headless`.
16
- */
17
- export type FolioAIEditView = {
18
- state: EditorState;
19
- dispatch: (transaction: Transaction) => void;
20
- };
21
- /**
22
- * Fixed revision provenance, for callers whose output must be reproducible.
23
- * Both halves of the stamp travel together because either one left to the
24
- * ambient clock (`new Date()` for the date, the shared bounded allocator for
25
- * the ids) makes the produced package differ between two runs over the same
26
- * inputs. `idSeed` starts a contiguous range the batch allocates from, so it
27
- * must sit above every revision id the target document already carries.
28
- */
29
- export type FolioRevisionStamp = {
30
- /** ISO-8601 date stamped on every `w:ins` / `w:del` this batch produces. */
31
- date: string;
32
- /** First revision id the batch may allocate. */
33
- idSeed: number;
34
- };
6
+ import { Transaction } from "prosemirror-state";
7
+ import { Node } from "prosemirror-model";
35
8
  type ApplyFolioAIEditOperationsOptions = {
36
9
  view: FolioAIEditView;
37
10
  snapshot: FolioAIEditSnapshot;
@@ -74,87 +47,6 @@ type ApplyFolioAIEditOperationsInPackageOptions = ApplyFolioAIEditOperationsOpti
74
47
  numberingIdsElsewhere: NumberingIdsInUse;
75
48
  refuseCrossAuthorRevisions?: boolean;
76
49
  };
77
- /**
78
- * How an apply batch cuts the redline for a replacement. Word-level by
79
- * default; character granularity marks the changed letters inside a token,
80
- * which reads well for a reference or a date. Normalization is deliberately
81
- * absent: a batch that leaves a difference unmarked does not accept back to
82
- * the text the caller asked for.
83
- */
84
- export type FolioWordDiffOptions = {
85
- granularity?: WordDiffGranularity;
86
- };
87
- /**
88
- * What a replacement does with a highlight or `w:shd` the text it replaces
89
- * carries.
90
- *
91
- * `clear` is the authoring default: text typed over a highlighted placeholder
92
- * is new text, and keeping the marker that said "fill this in" would carry it
93
- * into the finished document. `keep` is for a caller that states the
94
- * replacement's own run properties rather than letting it inherit them — a
95
- * comparison reproducing a revised document holds the properties that document
96
- * has, and clearing them first records a run-property change it takes straight
97
- * back, which reaches the reader as a revision whose before and after are the
98
- * same.
99
- */
100
- export type FolioReplacementBackground = "clear" | "keep";
101
- /**
102
- * An apply result plus where the batch left the revision-id counter.
103
- *
104
- * A caller writing several batches into one package — a comparison walking
105
- * the main story, then each header, footer and note — has to give every batch
106
- * a seed above the last id the previous one used, or two stories claim the
107
- * same `w:id` and a consumer resolving one revision resolves the other with
108
- * it. The batch is the only thing that knows how many ids it took, so it says
109
- * so rather than making the caller guess a stride.
110
- */
111
- export type FolioAIEditApplyOutcome = FolioAIEditApplyResult & {
112
- /** The held transaction was refused when its final geometry exposed a protected break. */
113
- heldRevisionConflict?: true;
114
- /**
115
- * First revision id a following batch may allocate: one past the last id
116
- * this batch used, or the seed it started from when it allocated none.
117
- */
118
- nextRevisionId: number;
119
- };
120
- /**
121
- * Operation types applied in `"suggested"` mode. Every produced revision — an
122
- * inline mark, a whole-node `_suggestedInsert` marker, or a suggested
123
- * `trIns`/`trDel`/`cellMarker` — is stripped from serialized DOCX until
124
- * accepted. Cell merge/split (not row/column ops) and comment ops stay
125
- * `unsupportedMode`.
126
- */
127
- export declare const SUGGESTED_SUPPORTED_OPERATION_TYPES: ReadonlySet<FolioAIResolvedEditOperation["type"]>;
128
- type BuildTableNodeOptions = {
129
- schema: Schema;
130
- rows: readonly (readonly string[])[];
131
- /** Present in tracked mode: every row is stamped as an insertion. */
132
- revision?: TableStructureRevision;
133
- };
134
- /**
135
- * A plain table from a grid of cell texts, `null` when the schema has no
136
- * tables. In tracked mode every row carries `trIns` and every run inside it
137
- * carries `w:ins`, which is how the format says "this table is new": there is
138
- * no whole-table insertion element, only rows that were inserted, and a
139
- * consumer that reads only run-level revisions keeps the text of a rejected
140
- * insertion when the row marker stands alone.
141
- */
142
- export declare const buildTableNode: ({ schema, rows, revision }: BuildTableNodeOptions) => Node | null;
143
- type BuildSignatureTableNodeOptions = {
144
- schema: Schema;
145
- parties: readonly FolioAISignatureParty[];
146
- };
147
- /**
148
- * Build a borderless PM table mirroring docx-core's
149
- * `signatureTable` helper: one row, one cell per party, each cell
150
- * containing party name (bold), two spacer paragraphs, a signature
151
- * rule, then optional signatory and italic title lines.
152
- *
153
- * Returns `null` when the editor schema is missing one of the
154
- * required node types — callers should surface the op as a skip
155
- * rather than crashing.
156
- */
157
- export declare const buildSignatureTableNode: ({ schema, parties }: BuildSignatureTableNodeOptions) => Node | null;
158
50
  export declare const applyFolioAIEditOperations: (options: ApplyFolioAIEditOperationsOptions) => FolioAIEditApplyOutcome;
159
51
  /** {@link applyFolioAIEditOperations} for a caller holding every story. Internal. */
160
52
  export declare const applyFolioAIEditOperationsInPackage: (options: ApplyFolioAIEditOperationsInPackageOptions) => FolioAIEditApplyOutcome;
@@ -199,4 +91,4 @@ type InsertedCleanText = {
199
91
  end: number;
200
92
  };
201
93
  export declare const insertCleanText: ({ tr, from, to, text, standsInFor, keepsReplacedText }: InsertCleanTextOptions) => InsertedCleanText;
202
- export type { FolioUndefinedReferencePolicy };
94
+ export {};
@@ -12,15 +12,15 @@ import { resolveParagraphChangeAttrs } from "../prosemirror/commands/resolvePara
12
12
  import { addedBreakCarrierBefore, containerEndsAt, finalParagraphsOf, paragraphEndsItsContainer } from "../prosemirror/containerFinalParagraph.js";
13
13
  import { encloseWholeControls } from "../prosemirror/contentControlRevisions.js";
14
14
  import { JOINED_RUNS_RESTYLED_META } from "../prosemirror/extensions/features/JoinedRunStyleExtension.js";
15
- import { requestDeterministicParaIds } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
16
- import { markStructuralChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
17
15
  import "../prosemirror/extensions/nodes/TextBoxAnchorExtension.js";
18
16
  import { InsertionGapOrder, insertionGap, insertionGapEnd } from "../prosemirror/insertionGaps.js";
19
17
  import { blockBoundariesOf, carriesCommentAnchor, inlineBoundariesOf, isBlockBoundaryNode, removeResolvedSubtree } from "../prosemirror/keptRangeBoundaries.js";
20
18
  import { CLEARED_LIST_RENDERING_ATTRS } from "../prosemirror/listMarker.js";
21
19
  import { lockedControlSpans } from "../prosemirror/lockedControls.js";
22
20
  import { effectiveParagraphNumbering, paragraphNumberingAttr, paragraphNumberingSourcesFromBoundary, readParagraphNumberingAttr, removedNumberingAttr } from "../prosemirror/numberingAttr.js";
21
+ import { requestDeterministicParaIds } from "../prosemirror/paraIds.js";
23
22
  import { directParagraphAlignment } from "../prosemirror/paragraphAlignment.js";
23
+ import { markStructuralChange } from "../prosemirror/paragraphChangeTrackerMeta.js";
24
24
  import { styleResolvedParagraphFormatting } from "../prosemirror/paragraphFormattingProvenance.js";
25
25
  import { directParagraphIndentation, paragraphIndentationAttrPatch, paragraphIndentationEqual, paragraphIndentationFromFormatting, withDirectParagraphIndentation } from "../prosemirror/paragraphIndentation.js";
26
26
  import { joinAtParagraphMark } from "../prosemirror/paragraphMarkJoin.js";
@@ -31,7 +31,7 @@ import { getDocumentStyleDefinitions, getDocumentStyleResolver } from "../prosem
31
31
  import { claimRevisionIds, nextRevisionId, nextRevisionIdRange, reserveRevisionIds, seedRevisionIdsFromDoc } from "../prosemirror/plugins/revisionIds.js";
32
32
  import { rebaseParagraphRuns } from "../prosemirror/rebaseParagraphRuns.js";
33
33
  import { NON_INCLUSIVE_MARK_DISPOSITION, addCarriedMarks, annotatedReplacement, commentsAcrossBlockBoundary, commentsForTrackedInsertion, commentsSpanningInsertion, hasReplacedAnnotations, inheritedReplacementMarks, joinCommentStretches, placeTrackedInsertion, surveyAcceptedReplacedAnnotations, surveyReplacedAnnotations } from "../prosemirror/replacedAnnotations.js";
34
- import { applyMarksToRunFormattingRepresentation, runFormattingInlineControlNodeName, selectRunFormattingCarrierRepresentations } from "../prosemirror/runFormattingInlineCarriers.js";
34
+ import { applyMarksToRunFormattingRepresentation, selectRunFormattingCarrierRepresentations } from "../prosemirror/runFormattingInlineCarriers.js";
35
35
  import { RUN_FORMATTING_MARK_NAMES } from "../prosemirror/runFormattingMarkNames.js";
36
36
  import { readAuthoredRunFormatting, readAuthoredRunPropertySnapshot, reconcileRunFormattingMarks } from "../prosemirror/runFormattingReconciliation.js";
37
37
  import { paragraphRunStyleContext, paragraphRunStyleContextAt, resolveParagraphBodyRunFormatting } from "../prosemirror/runStyleFormatting.js";
@@ -42,10 +42,11 @@ import { paragraphGoes, tableGoes } from "../prosemirror/tableRunIn.js";
42
42
  import { isZeroWidthAnchor } from "../prosemirror/zeroWidthAnchors.js";
43
43
  import { getFolioParaIdFromBlockId } from "../types/block-id.js";
44
44
  import { canonicalJson } from "../utils/canonicalJson.js";
45
+ import { SUGGESTED_SUPPORTED_OPERATION_TYPES } from "./applyTypes.js";
45
46
  import { BatchClaims } from "./batch-claims.js";
46
47
  import { stripBlockIdentityAttrs } from "./block-identity.js";
47
48
  import { describeCharacterSplit } from "./character-boundaries.js";
48
- import { buildCleanBlockText, resolveCleanTextRange } from "./clean-text.js";
49
+ import { buildCleanBlockText, cleanTextInlineNodes, resolveCleanTextRange } from "./clean-text.js";
49
50
  import { directJoinSurvivor, directJoinTakes } from "./directJoin.js";
50
51
  import { EXISTING_REVISION_CONFLICT_MESSAGE, createExistingRevisionGuard } from "./existingRevisions.js";
51
52
  import { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "./inline-emphasis.js";
@@ -61,17 +62,18 @@ import { collectNoteReferenceLabels, hashFolioAIBlockContent, hashFolioAIBlockSt
61
62
  import { followedOnlyByDeletedParagraphs, isInsertedPPrMark, isPlainDeletedPPrMark, snapshotBatchClaim } from "./snapshotBatchFacts.js";
62
63
  import { mergeTableRectangle, mergeTrackedVerticalTableCells, splitTableRectangle, splitTrackedVerticalTableCell } from "./table-cell-mutations.js";
63
64
  import { planTableMutations } from "./table-mutation-plan.js";
64
- import { applyTableColumnDeletion, applyTableColumnInsertions, applyTableRowDeletion, applyTableRowInsertion, describeUnplacedCellTexts, findTableColumnInsertion, findTableRowInsertion, getTableColumnCoordinateKey, markTableRowContent, splitCellParagraphTexts } from "./table-row-column-mutations.js";
65
+ import { applyTableColumnDeletion, applyTableColumnInsertions, applyTableRowDeletion, applyTableRowInsertion, describeUnplacedCellTexts, findTableColumnInsertion, findTableRowInsertion, getTableColumnCoordinateKey, markTableRowContent } from "./table-row-column-mutations.js";
65
66
  import { findEnclosingTableCell, findEnclosingTableRow, findOutermostTableBoundary, tableRectangleCutsMergedCell } from "./table-targets.js";
66
67
  import { tableFromTemplate } from "./table-template.js";
67
68
  import { supportsTableInsertionMode } from "./tableInsertionModes.js";
69
+ import { buildSignatureTableNode, buildTableNode } from "./tableNodes.js";
68
70
  import { findUndefinedOperationReference } from "./undefinedReferences.js";
69
71
  import { wordDiffSessionFromOptions } from "./word-diff.js";
70
72
  import { panic } from "better-result";
71
- import { CONTENT_CONTROL_LOCK, REVIEW_CARRIERS, firstLockedControlViolation, lockedControlMessage } from "@stll/docx-core/model";
72
73
  import { Fragment, Mark } from "prosemirror-model";
73
74
  import { TableMap } from "prosemirror-tables";
74
75
  import { canSplit } from "prosemirror-transform";
76
+ import { CONTENT_CONTROL_LOCK, REVIEW_CARRIERS, firstLockedControlViolation, lockedControlMessage } from "@stll/docx-core/model";
75
77
  import { BATCH_ANNOTATION_KINDS, SPLIT_HALVES, contentRank, deletionRemovesBlock, finalBreakCarrier, groupInsertionRuns, orderAddressingBeforeRemoval, orderBatchOperations } from "@stll/docx-core/ops";
76
78
  // src/ai-edits/apply.ts
77
79
  const coarseWordDiff = (before, after) => {
@@ -125,28 +127,6 @@ const commitProvisionalComment = ({ tr, commentType, provisionalId, committedId
125
127
  }
126
128
  return tr;
127
129
  };
128
- /**
129
- * Operation types applied in `"suggested"` mode. Every produced revision — an
130
- * inline mark, a whole-node `_suggestedInsert` marker, or a suggested
131
- * `trIns`/`trDel`/`cellMarker` — is stripped from serialized DOCX until
132
- * accepted. Cell merge/split (not row/column ops) and comment ops stay
133
- * `unsupportedMode`.
134
- */
135
- const SUGGESTED_SUPPORTED_OPERATION_TYPES = /* @__PURE__ */ new Set([
136
- "replaceInBlock",
137
- "replaceRange",
138
- "formatRange",
139
- "setBlockParagraphProperties",
140
- "replaceBlock",
141
- "deleteBlock",
142
- "insertAfterBlock",
143
- "insertBeforeBlock",
144
- "insertSignatureTable",
145
- "insertTableRow",
146
- "deleteTableRow",
147
- "insertTableColumn",
148
- "deleteTableColumn"
149
- ]);
150
130
  /** Operations that only add marks: they move no position of the document. */
151
131
  const ANNOTATION_KIND_OF = /* @__PURE__ */ new Map([
152
132
  ["formatRange", BATCH_ANNOTATION_KINDS.FORMATTING],
@@ -1193,88 +1173,6 @@ const ordinalAmongSameHash = (snapshot, blockId) => {
1193
1173
  }
1194
1174
  return -1;
1195
1175
  };
1196
- /**
1197
- * Length of the underscore signature rule. Mirrors the constant
1198
- * in `docx-core/legal-source/compile.ts` so the on-screen signature
1199
- * line matches what `create-document` produces.
1200
- */
1201
- const SIGNATURE_LINE = "_".repeat(28);
1202
- /**
1203
- * A plain table from a grid of cell texts, `null` when the schema has no
1204
- * tables. In tracked mode every row carries `trIns` and every run inside it
1205
- * carries `w:ins`, which is how the format says "this table is new": there is
1206
- * no whole-table insertion element, only rows that were inserted, and a
1207
- * consumer that reads only run-level revisions keeps the text of a rejected
1208
- * insertion when the row marker stands alone.
1209
- */
1210
- const buildTableNode = ({ schema, rows, revision }) => {
1211
- const paragraphType = schema.nodes["paragraph"];
1212
- const cellType = schema.nodes["tableCell"];
1213
- const rowType = schema.nodes["tableRow"];
1214
- const tableType = schema.nodes["table"];
1215
- if (!paragraphType || !cellType || !rowType || !tableType || rows.length === 0) return null;
1216
- const insertionType = schema.marks["insertion"];
1217
- const marks = revision && insertionType ? [insertionType.create({
1218
- revisionId: revision.revisionId,
1219
- author: revision.author,
1220
- date: revision.date,
1221
- ...revision.initials != null && { initials: revision.initials },
1222
- ...revision.provenance != null && { provenance: revision.provenance },
1223
- ...revision.suggestionId != null && { suggestionId: revision.suggestionId }
1224
- })] : void 0;
1225
- const rowNodes = rows.map((cells) => rowType.create(revision ? { trIns: revision } : null, cells.map((text) => cellType.create(null, splitCellParagraphTexts(text).map((line) => paragraphType.create(null, line.length > 0 ? cleanTextInlineNodes({
1226
- schema,
1227
- text: line,
1228
- marks
1229
- }) : null))))));
1230
- return tableType.create(null, rowNodes);
1231
- };
1232
- /**
1233
- * Build a borderless PM table mirroring docx-core's
1234
- * `signatureTable` helper: one row, one cell per party, each cell
1235
- * containing party name (bold), two spacer paragraphs, a signature
1236
- * rule, then optional signatory and italic title lines.
1237
- *
1238
- * Returns `null` when the editor schema is missing one of the
1239
- * required node types — callers should surface the op as a skip
1240
- * rather than crashing.
1241
- */
1242
- const buildSignatureTableNode = ({ schema, parties }) => {
1243
- const paragraphType = schema.nodes["paragraph"];
1244
- const cellType = schema.nodes["tableCell"];
1245
- const rowType = schema.nodes["tableRow"];
1246
- const tableType = schema.nodes["table"];
1247
- if (!paragraphType || !cellType || !rowType || !tableType) return null;
1248
- const boldType = schema.marks["bold"];
1249
- const italicType = schema.marks["italic"];
1250
- const buildParagraph = (text, options) => {
1251
- const marks = [];
1252
- if (options.bold && boldType) marks.push(boldType.create());
1253
- if (options.italic && italicType) marks.push(italicType.create());
1254
- const content = text.length > 0 ? schema.text(text, marks) : null;
1255
- return paragraphType.create({ styleId: options.styleId }, content);
1256
- };
1257
- const buildCell = (party) => {
1258
- const cellContent = [
1259
- buildParagraph(party.name, {
1260
- styleId: "SignatureParty",
1261
- bold: true
1262
- }),
1263
- buildParagraph("", { styleId: "SignatureSpacer" }),
1264
- buildParagraph("", { styleId: "SignatureSpacer" }),
1265
- buildParagraph(SIGNATURE_LINE, { styleId: "SignatureRule" })
1266
- ];
1267
- if (party.signatory && party.signatory.length > 0) cellContent.push(buildParagraph(party.signatory, { styleId: "SignatureField" }));
1268
- if (party.title && party.title.length > 0) cellContent.push(buildParagraph(party.title, {
1269
- styleId: "SignatureField",
1270
- italic: true
1271
- }));
1272
- return cellType.create({}, cellContent);
1273
- };
1274
- const cells = parties.map(buildCell);
1275
- const row = rowType.create({}, cells);
1276
- return tableType.create({}, row);
1277
- };
1278
1176
  const LINE_BREAK_PATTERN = /\r\n|\r|\n/;
1279
1177
  /**
1280
1178
  * Split `insertAfterBlock` / `insertBeforeBlock` text on line breaks into one
@@ -5247,27 +5145,7 @@ const previewFolioAIEditOperationsWithResult = (options, wordDiffMode = "coarse"
5247
5145
  commentIds
5248
5146
  };
5249
5147
  };
5250
- const CLEAN_TEXT_CONTROL_PATTERN = /[\t\n]/gu;
5251
5148
  const hasCleanTextControls = (text) => text.includes(" ") || text.includes("\n");
5252
- const cleanTextInlineNodes = ({ schema, text, marks = [] }) => {
5253
- const nodes = [];
5254
- let offset = 0;
5255
- for (const match of text.matchAll(CLEAN_TEXT_CONTROL_PATTERN)) {
5256
- const index = match.index;
5257
- const preceding = text.slice(offset, index);
5258
- if (preceding.length > 0) nodes.push(schema.text(preceding, marks));
5259
- const control = match[0];
5260
- const nodeName = runFormattingInlineControlNodeName(control);
5261
- if (nodeName === null) panic("A clean-text control pattern matched an unrepresentable character", { control });
5262
- const type = schema.nodes[nodeName];
5263
- if (!type) panic("The editor schema cannot represent a clean-text control character", { control });
5264
- nodes.push(type.create(null, null, marks));
5265
- offset = index + control.length;
5266
- }
5267
- const trailing = text.slice(offset);
5268
- if (trailing.length > 0) nodes.push(schema.text(trailing, marks));
5269
- return nodes;
5270
- };
5271
5149
  const insertCleanText = ({ tr, from, to, text, standsInFor, keepsReplacedText = false }) => {
5272
5150
  const annotations = surveyReplacedAnnotations(tr.doc, from, to);
5273
5151
  const carried = standsInFor ? surveyReplacedAnnotations(tr.doc, standsInFor.from, standsInFor.to).carried : [];
@@ -6756,4 +6634,4 @@ const getOperationQuote = (operation) => {
6756
6634
  if (operation.type === "replaceInBlock") return operation.find;
6757
6635
  if (operation.type === "commentOnBlock") return operation.quote;
6758
6636
  };
6759
- export { SUGGESTED_SUPPORTED_OPERATION_TYPES, applyFolioAIEditOperations, applyFolioAIEditOperationsInPackage, buildSignatureTableNode, buildTableNode, insertCleanText, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
6637
+ export { applyFolioAIEditOperations, applyFolioAIEditOperationsInPackage, insertCleanText, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The public option and result types of the AI edit applier, and the
3
+ * operation types it applies in suggested mode.
4
+ */
5
+ import { FolioAIEditApplyResult, FolioAIResolvedEditOperation } from "./types.js";
6
+ import { WordDiffGranularity } from "./word-diff.js";
7
+ import { EditorState, Transaction } from "prosemirror-state";
8
+ /**
9
+ * The only editor surface the apply logic touches: a current `state`
10
+ * and a `dispatch` that swaps in the next one. A live `EditorView`
11
+ * satisfies this structurally, and so does a headless seam
12
+ * (`{ state, dispatch: (tr) => { state = state.apply(tr); } }`) — the
13
+ * apply path never reaches for anything DOM-bound on the view, which is
14
+ * what lets the same operation applier drive both the React editor and
15
+ * the server-side reviewer in `./headless`.
16
+ */
17
+ export type FolioAIEditView = {
18
+ state: EditorState;
19
+ dispatch: (transaction: Transaction) => void;
20
+ };
21
+ /**
22
+ * Fixed revision provenance, for callers whose output must be reproducible.
23
+ * Both halves of the stamp travel together because either one left to the
24
+ * ambient clock (`new Date()` for the date, the shared bounded allocator for
25
+ * the ids) makes the produced package differ between two runs over the same
26
+ * inputs. `idSeed` starts a contiguous range the batch allocates from, so it
27
+ * must sit above every revision id the target document already carries.
28
+ */
29
+ export type FolioRevisionStamp = {
30
+ /** ISO-8601 date stamped on every `w:ins` / `w:del` this batch produces. */
31
+ date: string;
32
+ /** First revision id the batch may allocate. */
33
+ idSeed: number;
34
+ };
35
+ /**
36
+ * How an apply batch cuts the redline for a replacement. Word-level by
37
+ * default; character granularity marks the changed letters inside a token,
38
+ * which reads well for a reference or a date. Normalization is deliberately
39
+ * absent: a batch that leaves a difference unmarked does not accept back to
40
+ * the text the caller asked for.
41
+ */
42
+ export type FolioWordDiffOptions = {
43
+ granularity?: WordDiffGranularity;
44
+ };
45
+ /**
46
+ * What a replacement does with a highlight or `w:shd` the text it replaces
47
+ * carries.
48
+ *
49
+ * `clear` is the authoring default: text typed over a highlighted placeholder
50
+ * is new text, and keeping the marker that said "fill this in" would carry it
51
+ * into the finished document. `keep` is for a caller that states the
52
+ * replacement's own run properties rather than letting it inherit them — a
53
+ * comparison reproducing a revised document holds the properties that document
54
+ * has, and clearing them first records a run-property change it takes straight
55
+ * back, which reaches the reader as a revision whose before and after are the
56
+ * same.
57
+ */
58
+ export type FolioReplacementBackground = "clear" | "keep";
59
+ /**
60
+ * An apply result plus where the batch left the revision-id counter.
61
+ *
62
+ * A caller writing several batches into one package — a comparison walking
63
+ * the main story, then each header, footer and note — has to give every batch
64
+ * a seed above the last id the previous one used, or two stories claim the
65
+ * same `w:id` and a consumer resolving one revision resolves the other with
66
+ * it. The batch is the only thing that knows how many ids it took, so it says
67
+ * so rather than making the caller guess a stride.
68
+ */
69
+ export type FolioAIEditApplyOutcome = FolioAIEditApplyResult & {
70
+ /** The held transaction was refused when its final geometry exposed a protected break. */
71
+ heldRevisionConflict?: true;
72
+ /**
73
+ * First revision id a following batch may allocate: one past the last id
74
+ * this batch used, or the seed it started from when it allocated none.
75
+ */
76
+ nextRevisionId: number;
77
+ };
78
+ /**
79
+ * Operation types applied in `"suggested"` mode. Every produced revision — an
80
+ * inline mark, a whole-node `_suggestedInsert` marker, or a suggested
81
+ * `trIns`/`trDel`/`cellMarker` — is stripped from serialized DOCX until
82
+ * accepted. Cell merge/split (not row/column ops) and comment ops stay
83
+ * `unsupportedMode`.
84
+ */
85
+ export declare const SUGGESTED_SUPPORTED_OPERATION_TYPES: ReadonlySet<FolioAIResolvedEditOperation["type"]>;
@@ -0,0 +1,24 @@
1
+ // src/ai-edits/applyTypes.ts
2
+ /**
3
+ * Operation types applied in `"suggested"` mode. Every produced revision — an
4
+ * inline mark, a whole-node `_suggestedInsert` marker, or a suggested
5
+ * `trIns`/`trDel`/`cellMarker` — is stripped from serialized DOCX until
6
+ * accepted. Cell merge/split (not row/column ops) and comment ops stay
7
+ * `unsupportedMode`.
8
+ */
9
+ const SUGGESTED_SUPPORTED_OPERATION_TYPES = /* @__PURE__ */ new Set([
10
+ "replaceInBlock",
11
+ "replaceRange",
12
+ "formatRange",
13
+ "setBlockParagraphProperties",
14
+ "replaceBlock",
15
+ "deleteBlock",
16
+ "insertAfterBlock",
17
+ "insertBeforeBlock",
18
+ "insertSignatureTable",
19
+ "insertTableRow",
20
+ "deleteTableRow",
21
+ "insertTableColumn",
22
+ "deleteTableColumn"
23
+ ]);
24
+ export { SUGGESTED_SUPPORTED_OPERATION_TYPES };
@@ -1,7 +1,7 @@
1
1
  import { PageBreakRunAttrs } from "../prosemirror/schema/nodes.js";
2
2
  import { NoteReferenceKind } from "../utils/noteReferenceLabels.js";
3
3
  import { NoteReferenceLabels } from "./note-references.js";
4
- import { Node } from "prosemirror-model";
4
+ import { Mark, Node, Schema } from "prosemirror-model";
5
5
  /**
6
6
  * "Post-tracked-changes" view of a textblock: the string the user
7
7
  * would see if every existing tracked change were accepted.
@@ -135,4 +135,10 @@ export declare const buildAnnotatedBlockText: (blockNode: Node) => string;
135
135
  * reference reads as the marker every other reader of the story shows.
136
136
  */
137
137
  export declare const buildAnnotatedBlockTextWithNoteReferences: (blockNode: Node, noteReferences: NoteReferenceLabels | undefined) => string;
138
+ type CleanTextInlineNodesOptions = {
139
+ schema: Schema;
140
+ text: string;
141
+ marks?: readonly Mark[] | undefined;
142
+ };
143
+ export declare const cleanTextInlineNodes: ({ schema, text, marks }: CleanTextInlineNodesOptions) => Node[];
138
144
  export {};
@@ -1,7 +1,8 @@
1
1
  import { expectPageBreakRunAttrs } from "../prosemirror/attrs/index.js";
2
- import { runFormattingInlineAtomCleanText, runFormattingInlineControlCharacter } from "../prosemirror/runFormattingInlineCarriers.js";
2
+ import { runFormattingInlineAtomCleanText, runFormattingInlineControlCharacter, runFormattingInlineControlNodeName } from "../prosemirror/runFormattingInlineCarriers.js";
3
3
  import { createNoteReferenceNumbering, noteReferenceMarker } from "../utils/noteReferenceLabels.js";
4
4
  import { noteReferenceOf } from "./note-references.js";
5
+ import { panic } from "better-result";
5
6
  // src/ai-edits/clean-text.ts
6
7
  const EMPTY_CLEAN_TEXT_STRUCTURAL_BOUNDARIES = Object.freeze([]);
7
8
  const cutsIntoSpan = ({ offset, length }, boundaryOffset) => boundaryOffset > offset && boundaryOffset < offset + length;
@@ -214,4 +215,24 @@ const renderAnnotatedSegment = ({ annotation, text }) => {
214
215
  if (annotation.commentId !== null) inner = `<comment id="${annotation.commentId}">${inner}</comment>`;
215
216
  return inner;
216
217
  };
217
- export { buildAnnotatedBlockText, buildAnnotatedBlockTextWithNoteReferences, buildCleanBlockText, isOmittedFromCleanView, resolveCleanTextRange };
218
+ const CLEAN_TEXT_CONTROL_PATTERN = /[\t\n]/gu;
219
+ const cleanTextInlineNodes = ({ schema, text, marks = [] }) => {
220
+ const nodes = [];
221
+ let offset = 0;
222
+ for (const match of text.matchAll(CLEAN_TEXT_CONTROL_PATTERN)) {
223
+ const index = match.index;
224
+ const preceding = text.slice(offset, index);
225
+ if (preceding.length > 0) nodes.push(schema.text(preceding, marks));
226
+ const control = match[0];
227
+ const nodeName = runFormattingInlineControlNodeName(control);
228
+ if (nodeName === null) panic("A clean-text control pattern matched an unrepresentable character", { control });
229
+ const type = schema.nodes[nodeName];
230
+ if (!type) panic("The editor schema cannot represent a clean-text control character", { control });
231
+ nodes.push(type.create(null, null, marks));
232
+ offset = index + control.length;
233
+ }
234
+ const trailing = text.slice(offset);
235
+ if (trailing.length > 0) nodes.push(schema.text(trailing, marks));
236
+ return nodes;
237
+ };
238
+ export { buildAnnotatedBlockText, buildAnnotatedBlockTextWithNoteReferences, buildCleanBlockText, cleanTextInlineNodes, isOmittedFromCleanView, resolveCleanTextRange };
@@ -1,5 +1,5 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { FolioRevisionStamp } from "./apply.js";
2
+ import { FolioRevisionStamp } from "./applyTypes.js";
3
3
  type StageFinalSectionPropertiesOptions = {
4
4
  target: document_d_exports.SectionProperties;
5
5
  previous: document_d_exports.SectionProperties;