@stll/folio-core 0.72.0 → 0.74.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 (244) hide show
  1. package/README.md +12 -6
  2. package/dist/ai-edits/applyTypes.d.ts +85 -0
  3. package/dist/ai-edits/applyTypes.js +24 -0
  4. package/dist/ai-edits/clean-text.d.ts +7 -1
  5. package/dist/ai-edits/clean-text.js +23 -2
  6. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  7. package/dist/ai-edits/headless.d.ts +29 -147
  8. package/dist/ai-edits/headless.js +215 -1639
  9. package/dist/ai-edits/index.d.ts +3 -3
  10. package/dist/ai-edits/index.js +2 -3
  11. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  12. package/dist/ai-edits/pending-suggestions.js +183 -90
  13. package/dist/ai-edits/pendingJoin.js +6 -1
  14. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  15. package/dist/ai-edits/snapshot.js +9 -4
  16. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  17. package/dist/ai-edits/table-cell-mutations.js +2 -2
  18. package/dist/ai-edits/table-geometry.d.ts +1 -1
  19. package/dist/ai-edits/table-geometry.js +1 -1
  20. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  21. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  22. package/dist/ai-edits/tableNodes.d.ts +38 -0
  23. package/dist/ai-edits/tableNodes.js +86 -0
  24. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  25. package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
  26. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  27. package/dist/canonical/batchCommentReferences.js +1 -0
  28. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  29. package/dist/canonical/canonicalInlineGaps.js +118 -0
  30. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  31. package/dist/canonical/canonicalInlineProjection.js +5 -27
  32. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  33. package/dist/canonical/canonicalPublicOperations.js +282 -75
  34. package/dist/canonical/canonicalSelection.js +1 -1
  35. package/dist/canonical/canonicalSession.d.ts +9 -1
  36. package/dist/canonical/canonicalSession.js +106 -33
  37. package/dist/compare/compare.d.ts +1 -1
  38. package/dist/compare/inline-atoms-model.d.ts +1 -1
  39. package/dist/compare/inline-atoms.d.ts +2 -2
  40. package/dist/compare/inline-provenance-model.d.ts +1 -1
  41. package/dist/compare/inline-provenance.d.ts +2 -2
  42. package/dist/compat/eigenpal.d.ts +3 -3
  43. package/dist/compat/eigenpal.js +2 -3
  44. package/dist/controller/autocompleteSuggestion.js +1 -1
  45. package/dist/controller/canonicalClipboard.d.ts +13 -3
  46. package/dist/controller/canonicalClipboard.js +186 -50
  47. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  48. package/dist/controller/canonicalClipboardResources.js +22 -2
  49. package/dist/controller/canonicalComposition.js +1 -1
  50. package/dist/controller/canonicalInput.js +1 -1
  51. package/dist/controller/canonicalPresence.js +1 -1
  52. package/dist/controller/canonicalReview.d.ts +1 -1
  53. package/dist/controller/canonicalReview.js +1 -1
  54. package/dist/controller/canonicalRoomAuthority.js +1 -1
  55. package/dist/controller/canonicalRoomWire.js +1 -1
  56. package/dist/controller/canonicalStructure.js +1 -1
  57. package/dist/controller/canonicalTabRoom.js +1 -1
  58. package/dist/controller/canonicalWatermark.d.ts +10 -0
  59. package/dist/controller/canonicalWatermark.js +37 -0
  60. package/dist/controller/canonicalYjsRoom.js +1 -1
  61. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  62. package/dist/controller/hiddenEditorApi.js +2 -17
  63. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  64. package/dist/controller/hiddenEditorManager.js +79 -23
  65. package/dist/document-operations.d.ts +1 -14
  66. package/dist/document-operations.js +1 -278
  67. package/dist/docx/canonicalSave.d.ts +1 -1
  68. package/dist/docx/canonicalSave.js +1 -1
  69. package/dist/docx/canonicalSessionInput.js +1 -1
  70. package/dist/docx/containerChildren.js +1 -1
  71. package/dist/docx/createDocx.d.ts +4 -0
  72. package/dist/docx/createDocx.js +6 -0
  73. package/dist/docx/paragraphParser.js +2 -2
  74. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  75. package/dist/docx/parser.js +1 -1
  76. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  77. package/dist/docx/reviewResolutionProvenance.js +31 -8
  78. package/dist/docx/revisionIdNormalization.js +30 -7
  79. package/dist/docx/rezip.d.ts +1 -1
  80. package/dist/docx/rezip.js +1 -1
  81. package/dist/docx/serializer/tableSerializer.js +4 -36
  82. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  83. package/dist/docx/server/templatePlan/apply.js +658 -0
  84. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  85. package/dist/docx/server/templatePlan/blocks.js +355 -0
  86. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  87. package/dist/docx/server/templatePlan/builders.js +237 -0
  88. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  89. package/dist/docx/server/templatePlan/emit.js +466 -0
  90. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  91. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  92. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  93. package/dist/docx/server/templatePlan/inspect.js +230 -0
  94. package/dist/docx/server/templatePlan/labels.d.ts +45 -0
  95. package/dist/docx/server/templatePlan/labels.js +155 -0
  96. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  97. package/dist/docx/server/templatePlan/package.js +99 -0
  98. package/dist/docx/server/templatePlan/plan.d.ts +145 -0
  99. package/dist/docx/server/templatePlan/plan.js +875 -0
  100. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  101. package/dist/docx/server/templatePlan/planShape.js +180 -0
  102. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  103. package/dist/docx/server/templatePlan/resources.js +136 -0
  104. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  105. package/dist/docx/server/templatePlan/story.js +440 -0
  106. package/dist/docx/server/templatePlan/types.d.ts +442 -0
  107. package/dist/docx/server/templatePlan/types.js +29 -0
  108. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  109. package/dist/docx/server/templatePlan/verify.js +976 -0
  110. package/dist/docx/server/templatePlan/xml.d.ts +74 -0
  111. package/dist/docx/server/templatePlan/xml.js +125 -0
  112. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  113. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  114. package/dist/docx/structuralXmlPatch.js +9 -1
  115. package/dist/docx/tableGridXml.d.ts +30 -0
  116. package/dist/docx/tableGridXml.js +54 -0
  117. package/dist/docx/tableParser.js +7 -0
  118. package/dist/i18n/loadMessages.d.ts +5 -0
  119. package/dist/i18n/loadMessages.js +46 -0
  120. package/dist/i18n/locales.d.ts +3 -0
  121. package/dist/i18n/locales.js +17 -0
  122. package/dist/i18n/messages.d.ts +3 -2
  123. package/dist/i18n/messages.js +4 -16
  124. package/dist/index.d.ts +3 -3
  125. package/dist/index.js +2 -3
  126. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  127. package/dist/internal/clipboardTransformPlugin.js +13 -0
  128. package/dist/internal/extensionRuntime.d.ts +7 -0
  129. package/dist/internal/extensionRuntime.js +28 -0
  130. package/dist/internal/starterKitExtensions.d.ts +20 -0
  131. package/dist/internal/starterKitExtensions.js +123 -0
  132. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  133. package/dist/managers/ContextMenuManager.js +2 -1
  134. package/dist/managers/editorShortcuts.d.ts +1 -1
  135. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  136. package/dist/prosemirror/attrs/index.js +1 -1
  137. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  138. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  139. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  140. package/dist/prosemirror/canonicalTableCommands.js +3 -3
  141. package/dist/prosemirror/commands/comments.js +4 -4
  142. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  143. package/dist/prosemirror/commands/contentControls.js +1 -1
  144. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  145. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  146. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  147. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  148. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  149. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  150. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  151. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  152. package/dist/prosemirror/commentRecords.d.ts +1 -1
  153. package/dist/prosemirror/commentRecords.js +2 -2
  154. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  155. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  156. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  157. package/dist/prosemirror/conversion/index.d.ts +2 -2
  158. package/dist/prosemirror/conversion/index.js +2 -2
  159. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  160. package/dist/prosemirror/documentStructureCounts.js +76 -0
  161. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  162. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  163. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  164. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  165. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  166. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  167. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  168. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  169. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  170. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  171. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  172. package/dist/prosemirror/extensions/index.d.ts +2 -1
  173. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  174. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  175. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  176. package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
  177. package/dist/prosemirror/extensions/types.d.ts +1 -1
  178. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  179. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  180. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  181. package/dist/prosemirror/index.d.ts +3 -3
  182. package/dist/prosemirror/index.js +3 -3
  183. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  184. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  185. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  186. package/dist/prosemirror/listNumbering.d.ts +1 -1
  187. package/dist/prosemirror/listNumbering.js +1 -1
  188. package/dist/prosemirror/lockedControls.d.ts +1 -1
  189. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  190. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  191. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  192. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  193. package/dist/prosemirror/noteReferenceReview.js +2 -243
  194. package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
  195. package/dist/prosemirror/paraIds.js +152 -0
  196. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  197. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  198. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  199. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  200. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  201. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  202. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  203. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  204. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  205. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  206. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  207. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  208. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  209. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  210. package/dist/prosemirror/replacedAnnotations.js +17 -2
  211. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  212. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  213. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  214. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  215. package/dist/prosemirror/selectionBounds.js +22 -0
  216. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  217. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  218. package/dist/prosemirror/suggestionCommands.js +31 -0
  219. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  220. package/dist/prosemirror/tableCellPaste.js +1 -1
  221. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  222. package/dist/prosemirror/tableRunIn.js +1 -1
  223. package/dist/prosemirror/textInput.d.ts +1 -1
  224. package/dist/prosemirror/textInput.js +1 -1
  225. package/dist/server.d.ts +7 -2
  226. package/dist/server.js +6 -1
  227. package/dist/types/canonicalCapabilities.d.ts +13 -92
  228. package/dist/types/canonicalCapabilities.js +11 -85
  229. package/package.json +4 -4
  230. package/dist/ai-edits/apply.d.ts +0 -202
  231. package/dist/ai-edits/apply.js +0 -6759
  232. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  233. package/dist/ai-edits/note-story-inventory.js +0 -10
  234. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  235. package/dist/ai-edits/revisionStretches.js +0 -147
  236. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
  237. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
  238. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
  239. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
  240. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
  241. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  242. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  243. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  244. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -1,8 +1,8 @@
1
1
  import { RowsEmptiedInBatch } from "../prosemirror/tableGridMutation.js";
2
2
  import { TableRowTarget } from "./table-targets.js";
3
3
  import { TableStructureRevision } from "./table-template.js";
4
- import { Node } from "prosemirror-model";
5
4
  import { Transaction } from "prosemirror-state";
5
+ import { Node } from "prosemirror-model";
6
6
  import { TableMap } from "prosemirror-tables";
7
7
  export type TableRowInsertion = {
8
8
  tableStart: number;
@@ -1,5 +1,5 @@
1
1
  import { addTrackedDeletionMark } from "../prosemirror/addTrackedDeletionMark.js";
2
- import { markStructuralChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
2
+ import { markStructuralChange } from "../prosemirror/paragraphChangeTrackerMeta.js";
3
3
  import { markRowsEmptiedInBatch, omittedSlotTakingColumn, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeTableRow } from "../prosemirror/tableGridMutation.js";
4
4
  import { sliceText } from "../utils/sliceText.js";
5
5
  import { stripBlockIdentityAttrs } from "./block-identity.js";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Table nodes an operation inserts: a plain grid of cell texts, or the
3
+ * signature table `insertSignatureTable` places.
4
+ */
5
+ import { TableStructureRevision } from "./table-template.js";
6
+ import { FolioAISignatureParty } from "./types.js";
7
+ import { Node, Schema } from "prosemirror-model";
8
+ type BuildTableNodeOptions = {
9
+ schema: Schema;
10
+ rows: readonly (readonly string[])[];
11
+ /** Present in tracked mode: every row is stamped as an insertion. */
12
+ revision?: TableStructureRevision;
13
+ };
14
+ /**
15
+ * A plain table from a grid of cell texts, `null` when the schema has no
16
+ * tables. In tracked mode every row carries `trIns` and every run inside it
17
+ * carries `w:ins`, which is how the format says "this table is new": there is
18
+ * no whole-table insertion element, only rows that were inserted, and a
19
+ * consumer that reads only run-level revisions keeps the text of a rejected
20
+ * insertion when the row marker stands alone.
21
+ */
22
+ export declare const buildTableNode: ({ schema, rows, revision }: BuildTableNodeOptions) => Node | null;
23
+ type BuildSignatureTableNodeOptions = {
24
+ schema: Schema;
25
+ parties: readonly FolioAISignatureParty[];
26
+ };
27
+ /**
28
+ * Build a borderless PM table mirroring docx-core's
29
+ * `signatureTable` helper: one row, one cell per party, each cell
30
+ * containing party name (bold), two spacer paragraphs, a signature
31
+ * rule, then optional signatory and italic title lines.
32
+ *
33
+ * Returns `null` when the editor schema is missing one of the
34
+ * required node types — callers should surface the op as a skip
35
+ * rather than crashing.
36
+ */
37
+ export declare const buildSignatureTableNode: ({ schema, parties }: BuildSignatureTableNodeOptions) => Node | null;
38
+ export {};
@@ -0,0 +1,86 @@
1
+ import { cleanTextInlineNodes } from "./clean-text.js";
2
+ import { splitCellParagraphTexts } from "./table-row-column-mutations.js";
3
+ // src/ai-edits/tableNodes.ts
4
+ /**
5
+ * Length of the underscore signature rule. Mirrors the constant
6
+ * in `docx-core/legal-source/compile.ts` so the on-screen signature
7
+ * line matches what `create-document` produces.
8
+ */
9
+ const SIGNATURE_LINE = "_".repeat(28);
10
+ /**
11
+ * A plain table from a grid of cell texts, `null` when the schema has no
12
+ * tables. In tracked mode every row carries `trIns` and every run inside it
13
+ * carries `w:ins`, which is how the format says "this table is new": there is
14
+ * no whole-table insertion element, only rows that were inserted, and a
15
+ * consumer that reads only run-level revisions keeps the text of a rejected
16
+ * insertion when the row marker stands alone.
17
+ */
18
+ const buildTableNode = ({ schema, rows, revision }) => {
19
+ const paragraphType = schema.nodes["paragraph"];
20
+ const cellType = schema.nodes["tableCell"];
21
+ const rowType = schema.nodes["tableRow"];
22
+ const tableType = schema.nodes["table"];
23
+ if (!paragraphType || !cellType || !rowType || !tableType || rows.length === 0) return null;
24
+ const insertionType = schema.marks["insertion"];
25
+ const marks = revision && insertionType ? [insertionType.create({
26
+ revisionId: revision.revisionId,
27
+ author: revision.author,
28
+ date: revision.date,
29
+ ...revision.initials != null && { initials: revision.initials },
30
+ ...revision.provenance != null && { provenance: revision.provenance },
31
+ ...revision.suggestionId != null && { suggestionId: revision.suggestionId }
32
+ })] : void 0;
33
+ 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({
34
+ schema,
35
+ text: line,
36
+ marks
37
+ }) : null))))));
38
+ return tableType.create(null, rowNodes);
39
+ };
40
+ /**
41
+ * Build a borderless PM table mirroring docx-core's
42
+ * `signatureTable` helper: one row, one cell per party, each cell
43
+ * containing party name (bold), two spacer paragraphs, a signature
44
+ * rule, then optional signatory and italic title lines.
45
+ *
46
+ * Returns `null` when the editor schema is missing one of the
47
+ * required node types — callers should surface the op as a skip
48
+ * rather than crashing.
49
+ */
50
+ const buildSignatureTableNode = ({ schema, parties }) => {
51
+ const paragraphType = schema.nodes["paragraph"];
52
+ const cellType = schema.nodes["tableCell"];
53
+ const rowType = schema.nodes["tableRow"];
54
+ const tableType = schema.nodes["table"];
55
+ if (!paragraphType || !cellType || !rowType || !tableType) return null;
56
+ const boldType = schema.marks["bold"];
57
+ const italicType = schema.marks["italic"];
58
+ const buildParagraph = (text, options) => {
59
+ const marks = [];
60
+ if (options.bold && boldType) marks.push(boldType.create());
61
+ if (options.italic && italicType) marks.push(italicType.create());
62
+ const content = text.length > 0 ? schema.text(text, marks) : null;
63
+ return paragraphType.create({ styleId: options.styleId }, content);
64
+ };
65
+ const buildCell = (party) => {
66
+ const cellContent = [
67
+ buildParagraph(party.name, {
68
+ styleId: "SignatureParty",
69
+ bold: true
70
+ }),
71
+ buildParagraph("", { styleId: "SignatureSpacer" }),
72
+ buildParagraph("", { styleId: "SignatureSpacer" }),
73
+ buildParagraph(SIGNATURE_LINE, { styleId: "SignatureRule" })
74
+ ];
75
+ if (party.signatory && party.signatory.length > 0) cellContent.push(buildParagraph(party.signatory, { styleId: "SignatureField" }));
76
+ if (party.title && party.title.length > 0) cellContent.push(buildParagraph(party.title, {
77
+ styleId: "SignatureField",
78
+ italic: true
79
+ }));
80
+ return cellType.create({}, cellContent);
81
+ };
82
+ const cells = parties.map(buildCell);
83
+ const row = rowType.create({}, cells);
84
+ return tableType.create({}, row);
85
+ };
86
+ export { buildSignatureTableNode, buildTableNode };
@@ -1,6 +1,6 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { Node } from "prosemirror-model";
3
2
  import { EditorState } from "prosemirror-state";
3
+ import { Node } from "prosemirror-model";
4
4
  type TrackedBatchFidelityOptions = {
5
5
  before: EditorState;
6
6
  after: Node;
@@ -13,9 +13,9 @@ import { commentAnchorIdsForNode, ownCommentAnchorIds } from "./comment-lifecycl
13
13
  import { comparisonApplying, noteReferenceOf } from "./note-references.js";
14
14
  import { changedTopLevelWindow } from "./result-validation.js";
15
15
  import { Result } from "better-result";
16
- import { Fragment } from "prosemirror-model";
17
16
  import { mergeRunContent } from "@stll/docx-core/ops";
18
17
  import { EditorState } from "prosemirror-state";
18
+ import { Fragment } from "prosemirror-model";
19
19
  // src/ai-edits/tracked-batch-fidelity.ts
20
20
  const copyRange = (doc, from, to) => {
21
21
  if (from === 0 && to === doc.childCount) return doc;
@@ -14,6 +14,13 @@ import { FolioAIEditOperation } from "./types.js";
14
14
  * What an editing request does with a style or numbering reference the
15
15
  * document does not define: `refuse` the operation, or `keep` the reference
16
16
  * verbatim (source-preserving imports).
17
+ *
18
+ * Editing callers explicitly select `refuse`: an undefined reference would
19
+ * report a formatting edit without changing its appearance. Missing references are skipped with
20
+ * `missingStyle` or `missingNumbering`.
21
+ * Comparison and redline use `keep` for unknown source styles; their import
22
+ * boundary clears destination style collisions with warnings before application.
23
+ * The parser already normalizes undefined source numbering to none.
17
24
  */
18
25
  export type FolioUndefinedReferencePolicy = "refuse" | "keep";
19
26
  /** An operation as either engine holds it: staged (new lists deferred) or as parsed. */
@@ -51,6 +51,7 @@ const mapIntentPositions = (intent, map) => {
51
51
  case "formatRun":
52
52
  case "insertAtom":
53
53
  case "replaceFragment":
54
+ case "pasteBlocks":
54
55
  case "setHyperlink":
55
56
  case "removeHyperlink":
56
57
  case "insertHyperlink": return {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The source gaps of one paragraph's logical text, by offset.
3
+ *
4
+ * Each offset of the text (`0` to `text.length`) has one or more gaps: an
5
+ * editor position, relative to the paragraph, that stands for it, the
6
+ * zero-width source ordinal that position names, and the ordinals its seam
7
+ * covers (`first` to `last`). Gaps at one offset keep the order they were
8
+ * added in.
9
+ *
10
+ * Nearly every offset has exactly one gap, so the first gap of each offset is
11
+ * held flat, four integers per offset in one `Int32Array`, and only the rare
12
+ * further gaps (zero-width markers at one offset that several editor positions
13
+ * reach) go to a side map. A paragraph's gaps then cost about sixteen bytes
14
+ * per character, not two arrays and two objects per character; a canonical
15
+ * session keeps them for every paragraph of the story.
16
+ */
17
+ /** An editor position (relative to its paragraph) and the source ordinal it names. */
18
+ export type CanonicalInlineGap = {
19
+ position: number;
20
+ zeroWidthBefore: number;
21
+ };
22
+ /** The source ordinals one editor position stands for: from `first` to `last`. */
23
+ export type CanonicalSeamExtent = {
24
+ first: number;
25
+ last: number;
26
+ };
27
+ /** One gap with its seam. */
28
+ export type CanonicalGapEntry = CanonicalInlineGap & CanonicalSeamExtent;
29
+ export declare class CanonicalInlineGaps {
30
+ /** The first gap of each offset: position, zeroWidthBefore, first, last. */
31
+ private readonly flat;
32
+ /** The second and later gaps of an offset, in the order they were added. */
33
+ private readonly more;
34
+ /** Room for `offsets` offsets (`text.length + 1`), none holding a gap yet. */
35
+ constructor(offsets: number);
36
+ /** How many offsets the table holds: the text's length plus one. */
37
+ get offsets(): number;
38
+ /**
39
+ * Record a gap at `offset`. A gap at an editor position the offset already
40
+ * has widens that gap's seam to the ordinal, and the gap then names the
41
+ * ordinal of the two that is nearer to `preferred()` (asked only then); a
42
+ * tie keeps the earlier one. Returns false when the offset is outside the
43
+ * text.
44
+ */
45
+ add(offset: number, position: number, zeroWidthBefore: number, preferred: () => number): boolean;
46
+ /** Whether some offset has no gap. */
47
+ hasEmptyOffset(): boolean;
48
+ /** The gaps at `offset` with their seams, in order; undefined outside the text. */
49
+ at(offset: number): readonly CanonicalGapEntry[] | undefined;
50
+ /** The first offset with a gap at editor `position`, or -1. */
51
+ offsetOf(position: number): number;
52
+ /** Every offset's gaps, without their seams. */
53
+ toBoundaries(): CanonicalInlineGap[][];
54
+ /** Every offset's seams, parallel to {@link toBoundaries}. */
55
+ toSeams(): CanonicalSeamExtent[][];
56
+ }
@@ -0,0 +1,118 @@
1
+ // src/canonical/canonicalInlineGaps.ts
2
+ const SLOTS = 4;
3
+ const POSITION = 0;
4
+ const ZERO_WIDTH_BEFORE = 1;
5
+ const FIRST = 2;
6
+ const LAST = 3;
7
+ /** No gap at this offset yet. Positions are never negative. */
8
+ const EMPTY = -1;
9
+ var CanonicalInlineGaps = class {
10
+ /** The first gap of each offset: position, zeroWidthBefore, first, last. */
11
+ flat;
12
+ /** The second and later gaps of an offset, in the order they were added. */
13
+ more = /* @__PURE__ */ new Map();
14
+ /** Room for `offsets` offsets (`text.length + 1`), none holding a gap yet. */
15
+ constructor(offsets) {
16
+ this.flat = new Int32Array(offsets * SLOTS).fill(EMPTY);
17
+ }
18
+ /** How many offsets the table holds: the text's length plus one. */
19
+ get offsets() {
20
+ return this.flat.length / SLOTS;
21
+ }
22
+ /**
23
+ * Record a gap at `offset`. A gap at an editor position the offset already
24
+ * has widens that gap's seam to the ordinal, and the gap then names the
25
+ * ordinal of the two that is nearer to `preferred()` (asked only then); a
26
+ * tie keeps the earlier one. Returns false when the offset is outside the
27
+ * text.
28
+ */
29
+ add(offset, position, zeroWidthBefore, preferred) {
30
+ if (!Number.isInteger(offset) || offset < 0 || offset >= this.offsets) return false;
31
+ const at = offset * SLOTS;
32
+ const flat = this.flat;
33
+ if (flat[at + POSITION] === EMPTY) {
34
+ flat[at + POSITION] = position;
35
+ flat[at + ZERO_WIDTH_BEFORE] = zeroWidthBefore;
36
+ flat[at + FIRST] = zeroWidthBefore;
37
+ flat[at + LAST] = zeroWidthBefore;
38
+ return true;
39
+ }
40
+ if (flat[at + POSITION] === position) {
41
+ flat[at + FIRST] = Math.min(flat[at + FIRST] ?? 0, zeroWidthBefore);
42
+ flat[at + LAST] = Math.max(flat[at + LAST] ?? 0, zeroWidthBefore);
43
+ const kept = flat[at + ZERO_WIDTH_BEFORE] ?? 0;
44
+ const target = preferred();
45
+ if (Math.abs(zeroWidthBefore - target) < Math.abs(kept - target)) flat[at + ZERO_WIDTH_BEFORE] = zeroWidthBefore;
46
+ return true;
47
+ }
48
+ const more = this.more.get(offset);
49
+ const known = more?.find((entry) => entry.position === position);
50
+ if (known === void 0) {
51
+ const entry = {
52
+ position,
53
+ zeroWidthBefore,
54
+ first: zeroWidthBefore,
55
+ last: zeroWidthBefore
56
+ };
57
+ if (more === void 0) this.more.set(offset, [entry]);
58
+ else more.push(entry);
59
+ return true;
60
+ }
61
+ known.first = Math.min(known.first, zeroWidthBefore);
62
+ known.last = Math.max(known.last, zeroWidthBefore);
63
+ const target = preferred();
64
+ if (Math.abs(zeroWidthBefore - target) < Math.abs(known.zeroWidthBefore - target)) known.zeroWidthBefore = zeroWidthBefore;
65
+ return true;
66
+ }
67
+ /** Whether some offset has no gap. */
68
+ hasEmptyOffset() {
69
+ for (let offset = 0; offset < this.offsets; offset += 1) if (this.flat[offset * SLOTS + POSITION] === EMPTY) return true;
70
+ return false;
71
+ }
72
+ /** The gaps at `offset` with their seams, in order; undefined outside the text. */
73
+ at(offset) {
74
+ if (!Number.isInteger(offset) || offset < 0 || offset >= this.offsets) return void 0;
75
+ const at = offset * SLOTS;
76
+ const flat = this.flat;
77
+ const position = flat[at + POSITION] ?? EMPTY;
78
+ if (position === EMPTY) return [];
79
+ const head = {
80
+ position,
81
+ zeroWidthBefore: flat[at + ZERO_WIDTH_BEFORE] ?? 0,
82
+ first: flat[at + FIRST] ?? 0,
83
+ last: flat[at + LAST] ?? 0
84
+ };
85
+ const more = this.more.get(offset);
86
+ return more === void 0 ? [head] : [head, ...more.map((entry) => ({
87
+ position: entry.position,
88
+ zeroWidthBefore: entry.zeroWidthBefore,
89
+ first: entry.first,
90
+ last: entry.last
91
+ }))];
92
+ }
93
+ /** The first offset with a gap at editor `position`, or -1. */
94
+ offsetOf(position) {
95
+ const flat = this.flat;
96
+ const hasMore = this.more.size > 0;
97
+ for (let offset = 0; offset < this.offsets; offset += 1) {
98
+ if (flat[offset * SLOTS + POSITION] === position) return offset;
99
+ if (hasMore && this.more.get(offset)?.some((entry) => entry.position === position)) return offset;
100
+ }
101
+ return -1;
102
+ }
103
+ /** Every offset's gaps, without their seams. */
104
+ toBoundaries() {
105
+ return Array.from({ length: this.offsets }, (_, offset) => (this.at(offset) ?? []).map(({ position, zeroWidthBefore }) => ({
106
+ position,
107
+ zeroWidthBefore
108
+ })));
109
+ }
110
+ /** Every offset's seams, parallel to {@link toBoundaries}. */
111
+ toSeams() {
112
+ return Array.from({ length: this.offsets }, (_, offset) => (this.at(offset) ?? []).map(({ first, last }) => ({
113
+ first,
114
+ last
115
+ })));
116
+ }
117
+ };
118
+ export { CanonicalInlineGaps };
@@ -1,4 +1,5 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { CanonicalGapEntry, CanonicalInlineGap, CanonicalInlineGaps, CanonicalSeamExtent } from "./canonicalInlineGaps.js";
2
3
  import { Result, TaggedErrorClass } from "better-result";
3
4
  import { Node } from "prosemirror-model";
4
5
  export declare const CANONICAL_SOURCE_INLINE_POLICIES: {
@@ -94,20 +95,10 @@ type NativeCell = {
94
95
  };
95
96
  /** Native positions and deletion geometry read the same inline-cell classification. */
96
97
  export declare const canonicalNativeCells: (paragraph: Node) => Result<NativeCell[], InlineProjectionError>;
97
- export type CanonicalInlineGap = {
98
- position: number;
99
- zeroWidthBefore: number;
100
- };
101
- /** The source ordinals one editor position stands for: from `first` to `last`. */
102
- export type CanonicalSeamExtent = {
103
- first: number;
104
- last: number;
105
- };
106
98
  type InlineProjection = {
107
99
  text: string;
108
- boundaries: CanonicalInlineGap[][];
109
- /** Parallel to `boundaries`: each gap's whole seam. */
110
- seams: CanonicalSeamExtent[][];
100
+ /** Each offset's editor positions and the seams they stand for. */
101
+ gaps: CanonicalInlineGaps;
111
102
  };
112
103
  /** Whether a story holds an id: all a paragraph's projection asks of a story id set. */
113
104
  export type StoryIdMembership = Pick<ReadonlySet<number>, "has">;
@@ -139,4 +130,4 @@ export declare class InlineProjectionCache {
139
130
  private paragraphs;
140
131
  project(args: CanonicalInlineProjectionArgs): Result<InlineProjection, InlineProjectionError>;
141
132
  }
142
- export {};
133
+ export type { CanonicalGapEntry, CanonicalInlineGap, CanonicalSeamExtent };
@@ -10,6 +10,7 @@ import { readMoveRangeBoundaryAttrs } from "../prosemirror/moveRangeBoundaryAttr
10
10
  import { readRangeAnchorAttrs } from "../prosemirror/rangeAnchorAttrs.js";
11
11
  import { PRESERVED_XML_LEVELS } from "../prosemirror/schema/nodes.js";
12
12
  import { itemBefore } from "../utils/listItems.js";
13
+ import { CanonicalInlineGaps } from "./canonicalInlineGaps.js";
13
14
  import { Result, TaggedError, panic } from "better-result";
14
15
  import { hasIllegalXmlCharacters } from "@stll/docx-core";
15
16
  import { defaultInsertionGap, inlineLeafSpans, paragraphLogicalText } from "@stll/docx-core/ops";
@@ -450,7 +451,7 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
450
451
  if (!(offsets?.start !== void 0 && offsets.end !== void 0 && offsets.start === offsets.end) && markedCommentIds.has(node.id) && !explicitCommentIds.has(node.id)) erasedCommentMarkers.add(node);
451
452
  }
452
453
  const text = paragraphLogicalText(source);
453
- const boundaries = Array.from({ length: text.length + 1 }, () => []);
454
+ const gaps = new CanonicalInlineGaps(text.length + 1);
454
455
  let index = 0;
455
456
  let consumed = 0;
456
457
  const insertionOrdinals = /* @__PURE__ */ new Map();
@@ -461,30 +462,8 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
461
462
  insertionOrdinals.set(offset, ordinal);
462
463
  return ordinal;
463
464
  };
464
- const seams = Array.from({ length: text.length + 1 }, () => []);
465
465
  const addGap = (position, gap) => {
466
- const gaps = boundaries.at(gap.offset);
467
- const extents = seams.at(gap.offset);
468
- if (!gaps || !extents) panic(`Source leaf offset ${gap.offset} exceeds paragraph ${source.paraId}.`);
469
- const existing = gaps.findIndex((entry) => entry.position === position);
470
- const entry = {
471
- position,
472
- zeroWidthBefore: gap.zeroWidthBefore
473
- };
474
- if (existing < 0) {
475
- gaps.push(entry);
476
- extents.push({
477
- first: gap.zeroWidthBefore,
478
- last: gap.zeroWidthBefore
479
- });
480
- return;
481
- }
482
- const extent = extents[existing] ?? panic("Missing canonical seam extent");
483
- extent.first = Math.min(extent.first, gap.zeroWidthBefore);
484
- extent.last = Math.max(extent.last, gap.zeroWidthBefore);
485
- const preferred = insertionOrdinalAt(gap.offset);
486
- const kept = gaps[existing] ?? panic("Missing canonical seam gap");
487
- if (Math.abs(entry.zeroWidthBefore - preferred) < Math.abs(kept.zeroWidthBefore - preferred)) gaps[existing] = entry;
466
+ if (!gaps.add(gap.offset, position, gap.zeroWidthBefore, () => insertionOrdinalAt(gap.offset))) panic(`Source leaf offset ${gap.offset} exceeds paragraph ${source.paraId}.`);
488
467
  };
489
468
  const consumeErasedLeaves = (position) => {
490
469
  while (consumed === 0) {
@@ -586,11 +565,10 @@ const projectCanonicalInline = ({ source, paragraph, pairedBookmarkIds, commentC
586
565
  if ([...comments.value.values()].some(({ starts, ends }) => starts.size > 0 || ends.size > 0)) return refuse("Canonical editing cannot attribute a comment mark transition to its source.");
587
566
  const missing = spans.at(index);
588
567
  if (missing || consumed !== 0) return refuse(`Canonical editing cannot display the source positions of ${missing?.node.type ?? "incomplete text"}.`);
589
- if (boundaries.some((gaps) => gaps.length === 0)) return refuse("Canonical editing lost a source character boundary.");
568
+ if (gaps.hasEmptyOffset()) return refuse("Canonical editing lost a source character boundary.");
590
569
  return Result.ok({
591
570
  text,
592
- boundaries,
593
- seams
571
+ gaps
594
572
  });
595
573
  };
596
574
  /** A membership whose answers one paragraph's projection read, recorded to check later. */
@@ -10,15 +10,15 @@
10
10
  */
11
11
  import { ParagraphCommentMarkers } from "../docx/commentAnchorIndex.js";
12
12
  import { document_d_exports } from "../types/document.js";
13
- import { CanonicalInlineGap, CanonicalSeamExtent } from "./canonicalInlineProjection.js";
13
+ import { CanonicalInlineGaps } from "./canonicalInlineGaps.js";
14
14
  import { Node } from "prosemirror-model";
15
15
  export type ParagraphAddress = {
16
16
  blockId: string;
17
17
  container: readonly document_d_exports.BlockContent[];
18
18
  start: number;
19
19
  text: string;
20
- boundaries: readonly (readonly CanonicalInlineGap[])[];
21
- seams: readonly (readonly CanonicalSeamExtent[])[];
20
+ /** Each offset's editor positions and the seams they stand for. */
21
+ gaps: CanonicalInlineGaps;
22
22
  node: Node;
23
23
  source: document_d_exports.Paragraph;
24
24
  };
@@ -29,7 +29,7 @@ export type BlockParagraph = {
29
29
  container: readonly document_d_exports.BlockContent[] | undefined;
30
30
  /** From the start of the top-level node holding it. */
31
31
  offset: number;
32
- inline: Pick<ParagraphAddress, "text" | "boundaries" | "seams">;
32
+ inline: Pick<ParagraphAddress, "text" | "gaps">;
33
33
  node: Node;
34
34
  source: document_d_exports.Paragraph;
35
35
  };