@stll/folio-core 0.72.0 → 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 (192) hide show
  1. package/README.md +12 -6
  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 -3
  39. package/dist/compat/eigenpal.js +2 -3
  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/hiddenEditorApi.d.ts +1 -1
  50. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  51. package/dist/controller/hiddenEditorManager.js +75 -15
  52. package/dist/document-operations-apply.d.ts +15 -0
  53. package/dist/document-operations-apply.js +280 -0
  54. package/dist/document-operations.d.ts +1 -14
  55. package/dist/document-operations.js +2 -279
  56. package/dist/docx/modelValidation.js +1 -1
  57. package/dist/docx/paragraphParser.js +2 -2
  58. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  59. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  60. package/dist/docx/reviewResolutionProvenance.js +32 -9
  61. package/dist/docx/revisionIdNormalization.js +30 -7
  62. package/dist/docx/rezip.js +1 -1
  63. package/dist/docx/serializer/borderSerializer.js +1 -1
  64. package/dist/docx/serializer/commentSerializer.js +1 -1
  65. package/dist/docx/serializer/documentSerializer.js +1 -1
  66. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  67. package/dist/docx/serializer/runSerializer.js +1 -1
  68. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  69. package/dist/docx/serializer/tableSerializer.js +5 -37
  70. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  71. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  72. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  73. package/dist/docx/server/templatePlan/apply.js +600 -0
  74. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  75. package/dist/docx/server/templatePlan/blocks.js +355 -0
  76. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  77. package/dist/docx/server/templatePlan/builders.js +237 -0
  78. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  79. package/dist/docx/server/templatePlan/emit.js +466 -0
  80. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  81. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  82. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  83. package/dist/docx/server/templatePlan/inspect.js +177 -0
  84. package/dist/docx/server/templatePlan/labels.d.ts +36 -0
  85. package/dist/docx/server/templatePlan/labels.js +126 -0
  86. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  87. package/dist/docx/server/templatePlan/package.js +99 -0
  88. package/dist/docx/server/templatePlan/plan.d.ts +143 -0
  89. package/dist/docx/server/templatePlan/plan.js +841 -0
  90. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  91. package/dist/docx/server/templatePlan/planShape.js +161 -0
  92. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  93. package/dist/docx/server/templatePlan/resources.js +136 -0
  94. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  95. package/dist/docx/server/templatePlan/story.js +440 -0
  96. package/dist/docx/server/templatePlan/types.d.ts +406 -0
  97. package/dist/docx/server/templatePlan/types.js +28 -0
  98. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  99. package/dist/docx/server/templatePlan/verify.js +968 -0
  100. package/dist/docx/server/templatePlan/xml.d.ts +69 -0
  101. package/dist/docx/server/templatePlan/xml.js +119 -0
  102. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  103. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  104. package/dist/docx/storyBlockReplay.js +1 -1
  105. package/dist/docx/structuralXmlPatch.js +9 -1
  106. package/dist/docx/tableGridXml.d.ts +30 -0
  107. package/dist/docx/tableGridXml.js +54 -0
  108. package/dist/docx/tableParser.js +7 -0
  109. package/dist/docx/xmlParser.js +1 -1
  110. package/dist/index.d.ts +3 -3
  111. package/dist/index.js +2 -3
  112. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  113. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  114. package/dist/managers/ContextMenuManager.js +2 -1
  115. package/dist/managers/editorShortcuts.d.ts +1 -1
  116. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  117. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  118. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  119. package/dist/prosemirror/canonicalTableCommands.js +2 -2
  120. package/dist/prosemirror/commands/comments.js +3 -3
  121. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  122. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  123. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  124. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  125. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  126. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  127. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  128. package/dist/prosemirror/commentRecords.d.ts +1 -1
  129. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  130. package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
  131. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  132. package/dist/prosemirror/documentStructureCounts.js +76 -0
  133. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  134. package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
  135. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
  136. package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
  137. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  138. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  139. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  140. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  141. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
  142. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
  143. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
  144. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
  145. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  146. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  147. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  148. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  149. package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
  150. package/dist/prosemirror/extensions/types.d.ts +1 -1
  151. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  152. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  153. package/dist/prosemirror/index.d.ts +1 -1
  154. package/dist/prosemirror/index.js +1 -1
  155. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  156. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  157. package/dist/prosemirror/listNumbering.d.ts +1 -1
  158. package/dist/prosemirror/lockedControls.d.ts +1 -1
  159. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  160. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  161. package/dist/prosemirror/noteReferenceReview.js +1 -1
  162. package/dist/prosemirror/paraIds.d.ts +46 -0
  163. package/dist/prosemirror/paraIds.js +152 -0
  164. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  165. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  166. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  167. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  168. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  169. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  170. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  171. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  172. package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
  173. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  174. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  175. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  176. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  177. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  178. package/dist/prosemirror/replacedAnnotations.js +16 -1
  179. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  180. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  181. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  182. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  183. package/dist/prosemirror/selectionBounds.js +22 -0
  184. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  185. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  186. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  187. package/dist/prosemirror/textInput.d.ts +1 -1
  188. package/dist/server.d.ts +7 -2
  189. package/dist/server.js +6 -1
  190. package/dist/types/canonicalCapabilities.d.ts +8 -41
  191. package/dist/types/canonicalCapabilities.js +6 -34
  192. package/package.json +4 -4
@@ -1,5 +1,5 @@
1
- import { Node } from "prosemirror-model";
2
1
  import { EditorState } from "prosemirror-state";
2
+ import { Node } from "prosemirror-model";
3
3
  import { CellSelection } from "prosemirror-tables";
4
4
  /** Document edges denote the first and last editable content gaps. */
5
5
  export declare const canonicalContentPosition: (doc: Node, position: number) => number;
@@ -130,13 +130,13 @@ const gridEdit = (before, after, at) => {
130
130
  const was = expectTableAttrs(before).columnWidths;
131
131
  const is = expectTableAttrs(after).columnWidths;
132
132
  if (JSON.stringify(was) === JSON.stringify(is)) return void 0;
133
- if (at === void 0 || is === void 0 || is.length === 0) return null;
133
+ if (at === void 0) return null;
134
134
  return {
135
135
  type: "editTable",
136
136
  at,
137
137
  edit: {
138
138
  type: DOCUMENT_OP_TYPES.SET_TABLE_GRID,
139
- columnWidths: [...is]
139
+ columnWidths: [...is ?? []]
140
140
  }
141
141
  };
142
142
  };
@@ -10,13 +10,13 @@ import { enclosingRevisionIds, resolutionRemovesControl, withoutResolvedEnclosur
10
10
  import { copyOriginBoundaryAttrsAfterResolution } from "../copyOriginResolution.js";
11
11
  import { resolveEmptyFieldResultRuns } from "../emptyFieldResultRuns.js";
12
12
  import { JOINED_RUNS_RESTYLED_META } from "../extensions/features/JoinedRunStyleExtension.js";
13
- import { requestDeterministicParaIds } from "../extensions/features/ParaIdAllocatorExtension.js";
14
- import { markChangedParagraphRanges, markStructuralChange, markTrackedSectionEndpointRemoval } from "../extensions/features/ParagraphChangeTrackerExtension.js";
15
13
  import "../extensions/nodes/SdtExtension.js";
16
14
  import { canonicalFieldNode } from "../fieldRepresentation.js";
17
15
  import { isBlockBoundaryNode, normalizeKeptRangeBoundaries, paragraphRemainsOf, removeResolvedSubtree, revisionLayerRemovesContent } from "../keptRangeBoundaries.js";
18
16
  import { lockedControlSpans, lockedControlViolationOfTransform } from "../lockedControls.js";
19
17
  import { resolveStateStory } from "../markupViewProjection.js";
18
+ import { requestDeterministicParaIds } from "../paraIds.js";
19
+ import { markChangedParagraphRanges, markStructuralChange, markTrackedSectionEndpointRemoval } from "../paragraphChangeTrackerMeta.js";
20
20
  import { joinAtParagraphMark } from "../paragraphMarkJoin.js";
21
21
  import { carryParagraphProperties, paragraphLeftAfter } from "../paragraphPropertyCarry.js";
22
22
  import { getDocumentNumbering } from "../plugins/documentNumbering.js";
@@ -42,10 +42,10 @@ import { resolveNodePropertyChangeAttrs } from "./resolveNodePropertyChangeAttrs
42
42
  import { resolveParagraphChangeAttrs } from "./resolveParagraphProperties.js";
43
43
  import { hasMatchingCollapsedTableCellMerge, resolveCollapsedTableCellMerge, resolveVisibleTableCellMerge } from "./tableCellMergeResolution.js";
44
44
  import { panic } from "better-result";
45
- import { PARAGRAPH_MARK_CHANGE_KINDS, REVIEW_CARRIERS } from "@stll/docx-core/model";
46
45
  import { Fragment } from "prosemirror-model";
47
46
  import { TableMap } from "prosemirror-tables";
48
47
  import { Mapping } from "prosemirror-transform";
48
+ import { PARAGRAPH_MARK_CHANGE_KINDS, REVIEW_CARRIERS } from "@stll/docx-core/model";
49
49
  import { paragraphMarkOutcome } from "@stll/docx-core/ops";
50
50
  import { closeHistory } from "prosemirror-history";
51
51
  // src/prosemirror/commands/comments.ts
@@ -12,8 +12,8 @@ import { ContentControlFilter } from "../../content-controls/findContentControls
12
12
  import "../../content-controls/index.js";
13
13
  import { SetContentControlContentInput, SetContentControlValueInput } from "../../content-controls/mutateContentControls.js";
14
14
  import { document_d_exports } from "../../types/document.js";
15
- import { Node } from "prosemirror-model";
16
15
  import { Command, EditorState, Transaction } from "prosemirror-state";
16
+ import { Node } from "prosemirror-model";
17
17
  type ForceOption = {
18
18
  force?: boolean;
19
19
  };
@@ -9,8 +9,8 @@
9
9
  * logic is here so it can be unit-tested without a DOM.
10
10
  */
11
11
  import { document_d_exports } from "../../types/document.js";
12
- import { Mark } from "prosemirror-model";
13
12
  import { Command, EditorState } from "prosemirror-state";
13
+ import { Mark } from "prosemirror-model";
14
14
  /**
15
15
  * Character-formatting marks the painter copies. Structural marks — comments,
16
16
  * hyperlinks, tracked changes (insertion/deletion), footnote references — are
@@ -10,8 +10,8 @@ import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extens
10
10
  import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
11
11
  import "../schema/index.js";
12
12
  import { TextColorAttrs } from "../schema/marks.js";
13
- import { Mark } from "prosemirror-model";
14
13
  import { Command } from "prosemirror-state";
14
+ import { Mark } from "prosemirror-model";
15
15
  /**
16
16
  * textFormattingToMarks — wraps markUtils version to use singleton schema
17
17
  */
@@ -6,8 +6,8 @@
6
6
  * paragraph's own style. This is the "paste without formatting" escape hatch,
7
7
  * distinct from the default rich paste that preserves source formatting.
8
8
  */
9
- import { Schema, Slice } from "prosemirror-model";
10
9
  import { Command } from "prosemirror-state";
10
+ import { Schema, Slice } from "prosemirror-model";
11
11
  import { EditorView } from "prosemirror-view";
12
12
  /**
13
13
  * Dispatched on the editor view DOM when the clipboard read behind a
@@ -1,4 +1,4 @@
1
- import { markSectionBreakRemoval } from "../extensions/features/ParagraphChangeTrackerExtension.js";
1
+ import { markSectionBreakRemoval } from "../paragraphChangeTrackerMeta.js";
2
2
  import { mintSectionProperties, sectionPropertiesOf } from "../sectionCarrier.js";
3
3
  import { TextSelection } from "prosemirror-state";
4
4
  // src/prosemirror/commands/sectionBreak.ts
@@ -1,7 +1,7 @@
1
1
  import { DecodedTableCellParagraphSourcePayload } from "../../docx/paragraphPropertySource.js";
2
2
  import { document_d_exports } from "../../types/document.js";
3
- import { Node } from "prosemirror-model";
4
3
  import { Transaction } from "prosemirror-state";
4
+ import { Node } from "prosemirror-model";
5
5
  export declare const tableCellContinuationPayload: (node: Node) => DecodedTableCellParagraphSourcePayload | null;
6
6
  export declare const hasMatchingCollapsedTableCellMerge: (node: Node, revisionSet: Set<number> | null) => boolean;
7
7
  type ResolveVisibleTableCellMergeOptions = {
@@ -1,5 +1,5 @@
1
- import { Node } from "prosemirror-model";
2
1
  import { CellMargins, ConditionalFormatStyle, PreservedMarkup, ShadingProperties, TableCellBorders, TableMeasurement, TextDirection } from "@stll/docx-core/model";
2
+ import { Node } from "prosemirror-model";
3
3
  type TableMergeFoldDecisionsOptions = {
4
4
  table: Node;
5
5
  mode: "accept" | "reject";
@@ -16,8 +16,8 @@
16
16
  * controlled `comments` prop and document operations read the same records.
17
17
  */
18
18
  import { Comment } from "../types/content.js";
19
- import { Node, Schema } from "prosemirror-model";
20
19
  import { EditorState, Plugin, Transaction } from "prosemirror-state";
20
+ import { Node, Schema } from "prosemirror-model";
21
21
  import { EditorView } from "prosemirror-view";
22
22
  import { Step, StepMap, StepResult } from "prosemirror-transform";
23
23
  export type CommentRecords = readonly Comment[];
@@ -12,8 +12,8 @@
12
12
  * A revision encloses the control while it still covers everything the control
13
13
  * holds, which is also when the save leg can write it around the control.
14
14
  */
15
- import { MarkType, Node } from "prosemirror-model";
16
15
  import { Transaction } from "prosemirror-state";
16
+ import { MarkType, Node } from "prosemirror-model";
17
17
  export declare const ENCLOSING_REVISION_IDS_ATTR = "_docxEnclosingRevisionIds";
18
18
  /** The revisions whose element encloses `control`. */
19
19
  export declare const enclosingRevisionIds: (control: Node) => readonly number[];
@@ -68,8 +68,8 @@ import { hyphenElementRunContent } from "./hyphenTextCarriers.js";
68
68
  import { hasSinkChildren } from "./preservedSinkCarriers.js";
69
69
  import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
70
70
  import { TaggedError, panic } from "better-result";
71
- import { DRAWING_RAW_XML_MODES, finalizeParagraphFormatting, relationshipIdOf, setDocumentBodyComments } from "@stll/docx-core/model";
72
71
  import { Fragment } from "prosemirror-model";
72
+ import { DRAWING_RAW_XML_MODES, finalizeParagraphFormatting, relationshipIdOf, setDocumentBodyComments } from "@stll/docx-core/model";
73
73
  import { registerStatedParagraphFormatting, survivingComments } from "@stll/docx-core/ops";
74
74
  // src/prosemirror/conversion/fromProseDoc.ts
75
75
  /**
@@ -0,0 +1,24 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { Node } from "prosemirror-model";
3
+ export type DocumentStructureCounts = {
4
+ blockStructureFingerprint: string;
5
+ sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
6
+ paragraphs: number;
7
+ /**
8
+ * Distinct section records the paragraphs carry, which is the number of
9
+ * `w:sectPr` the package states for them. A split copies a node's attrs, so
10
+ * both halves of a split section-ending paragraph hold one record until the
11
+ * from-leg keeps it on the trailing half: one section, not two.
12
+ */
13
+ sectionEndpoints: number;
14
+ sectionEndpointFingerprint: string;
15
+ };
16
+ /**
17
+ * Count the structural values the tracker compares for every transaction.
18
+ *
19
+ * Each top-level block's records are kept for the block node, so a keystroke
20
+ * recomputes only the block it changed. The fingerprint joins the blocks'
21
+ * records in order: two documents' fingerprints are equal exactly when their
22
+ * full record lists (every block and nested block with its path) are.
23
+ */
24
+ export declare function countDocumentStructure(doc: Node): DocumentStructureCounts;
@@ -0,0 +1,76 @@
1
+ import { canonicalJson } from "../utils/canonicalJson.js";
2
+ import { sectionPropertiesOf } from "./sectionCarrier.js";
3
+ // src/prosemirror/documentStructureCounts.ts
4
+ const blockStructures = /* @__PURE__ */ new WeakMap();
5
+ const relativePath = (parentPath, index) => parentPath.length === 0 ? `${index}` : `${parentPath}.${index}`;
6
+ const blockStructureOf = (block) => {
7
+ const cached = blockStructures.get(block);
8
+ if (cached) return cached;
9
+ const records = [];
10
+ const endpoints = [];
11
+ let paragraphs = 0;
12
+ const visit = (node, path) => {
13
+ records.push(node.type.name === "paragraph" ? [
14
+ path,
15
+ node.type.name,
16
+ node.attrs["paraId"] ?? null
17
+ ] : [
18
+ path,
19
+ node.type.name,
20
+ canonicalJson(node.attrs)
21
+ ]);
22
+ if (node.type.name === "paragraph") {
23
+ paragraphs++;
24
+ const sectionProperties = sectionPropertiesOf(node);
25
+ if (sectionProperties !== null) endpoints.push({
26
+ path,
27
+ paraId: node.attrs["paraId"] ?? null,
28
+ sectionProperties
29
+ });
30
+ return;
31
+ }
32
+ node.forEach((child, _offset, index) => visit(child, relativePath(path, index)));
33
+ };
34
+ visit(block, "");
35
+ const structure = {
36
+ records: JSON.stringify(records),
37
+ paragraphs,
38
+ endpoints
39
+ };
40
+ blockStructures.set(block, structure);
41
+ return structure;
42
+ };
43
+ /**
44
+ * Count the structural values the tracker compares for every transaction.
45
+ *
46
+ * Each top-level block's records are kept for the block node, so a keystroke
47
+ * recomputes only the block it changed. The fingerprint joins the blocks'
48
+ * records in order: two documents' fingerprints are equal exactly when their
49
+ * full record lists (every block and nested block with its path) are.
50
+ */
51
+ function countDocumentStructure(doc) {
52
+ let paragraphs = 0;
53
+ const sectionRecords = /* @__PURE__ */ new Set();
54
+ const blockRecords = [];
55
+ const endpointRecords = [];
56
+ doc.forEach((block, _offset, index) => {
57
+ const structure = blockStructureOf(block);
58
+ blockRecords.push(structure.records);
59
+ paragraphs += structure.paragraphs;
60
+ for (const endpoint of structure.endpoints) {
61
+ sectionRecords.add(endpoint.sectionProperties);
62
+ endpointRecords.push({
63
+ ...endpoint,
64
+ path: endpoint.path.length === 0 ? `${index}` : `${index}.${endpoint.path}`
65
+ });
66
+ }
67
+ });
68
+ return {
69
+ blockStructureFingerprint: blockRecords.join(""),
70
+ sectionRecords,
71
+ paragraphs,
72
+ sectionEndpoints: sectionRecords.size,
73
+ sectionEndpointFingerprint: canonicalJson(endpointRecords)
74
+ };
75
+ }
76
+ export { countDocumentStructure };
@@ -6,8 +6,8 @@
6
6
  * 2. initializeRuntime() — calls onSchemaReady() on each extension, collects plugins/commands/keymaps
7
7
  */
8
8
  import { AnyExtension, CommandFactory, CommandMap, FolioCommandArguments, FolioCommandName } from "./types.js";
9
- import { Schema } from "prosemirror-model";
10
9
  import { Plugin } from "prosemirror-state";
10
+ import { Schema } from "prosemirror-model";
11
11
  export declare class ExtensionManager {
12
12
  private readonly extensions;
13
13
  private schema;
@@ -8,7 +8,7 @@
8
8
  * manager.initializeRuntime();
9
9
  */
10
10
  import { SelectionChangeCallback } from "../plugins/selectionTracker.js";
11
- import { HistoryShortcutOwner } from "./core/HistoryExtension.js";
11
+ import { HistoryShortcutOwner } from "./core/historyCommands.js";
12
12
  import { AnyExtension } from "./types.js";
13
13
  export type StarterKitOptions = {
14
14
  /** Extensions to disable by name */
@@ -2,13 +2,7 @@
2
2
  * History Extension — undo/redo via prosemirror-history
3
3
  */
4
4
  import { Extension } from "../types.js";
5
- /**
6
- * Who answers the undo and redo keys (Mod-z, Mod-y, Mod-Shift-z).
7
- * - `"editor"`: the extension binds them. Default.
8
- * - `"host"`: nothing binds them. The host keeps its own undo stack and runs
9
- * the `undo` / `redo` commands itself, so one press never undoes twice.
10
- */
11
- export type HistoryShortcutOwner = "editor" | "host";
5
+ import { HistoryShortcutOwner } from "./historyCommands.js";
12
6
  type HistoryOptions = {
13
7
  depth: number;
14
8
  newGroupDelay: number;
@@ -1,7 +1,7 @@
1
- import { withCanonicalHistory } from "../../canonicalCommands.js";
2
1
  import { createExtension } from "../create.js";
2
+ import { historyKeyboardShortcuts, redoCommand, undoCommand } from "./historyCommands.js";
3
3
  import { Plugin } from "prosemirror-state";
4
- import { closeHistory, history, isHistoryTransaction, redo, undo } from "prosemirror-history";
4
+ import { closeHistory, history, isHistoryTransaction } from "prosemirror-history";
5
5
  // src/prosemirror/extensions/core/HistoryExtension.ts
6
6
  /**
7
7
  * History Extension — undo/redo via prosemirror-history
@@ -90,10 +90,6 @@ const inputBoundaryPlugin = (newGroupDelay) => {
90
90
  }
91
91
  });
92
92
  };
93
- const consumeHistoryShortcut = (command) => (state, dispatch, view) => {
94
- command(state, dispatch, view);
95
- return true;
96
- };
97
93
  const HistoryExtension = createExtension({
98
94
  name: "history",
99
95
  defaultOptions: {
@@ -108,14 +104,10 @@ const HistoryExtension = createExtension({
108
104
  newGroupDelay: options.newGroupDelay
109
105
  }), inputBoundaryPlugin(options.newGroupDelay)],
110
106
  commands: {
111
- undo: () => withCanonicalHistory(undo, "undo"),
112
- redo: () => withCanonicalHistory(redo, "redo")
107
+ undo: undoCommand,
108
+ redo: redoCommand
113
109
  },
114
- ...options.shortcuts === "editor" && { keyboardShortcuts: {
115
- "Mod-z": consumeHistoryShortcut(undo),
116
- "Mod-y": consumeHistoryShortcut(redo),
117
- "Mod-Shift-z": consumeHistoryShortcut(redo)
118
- } }
110
+ ...options.shortcuts === "editor" && { keyboardShortcuts: historyKeyboardShortcuts }
119
111
  };
120
112
  }
121
113
  });
@@ -25,8 +25,8 @@ import { rebaseParagraphRuns } from "../../rebaseParagraphRuns.js";
25
25
  import { mintSectionProperties, parseSectionBreakType, sectionBreakTypeOf } from "../../sectionCarrier.js";
26
26
  import { listAttrsFromResolvedStyle, listIndentationProvenancePatch, paragraphAttrsFromResolvedStyle } from "../../styles/resolvedStyleAttrs.js";
27
27
  import { createNodeExtension } from "../create.js";
28
- import { headingOutlineLevel } from "@stll/docx-core/model";
29
28
  import { Fragment } from "prosemirror-model";
29
+ import { headingOutlineLevel } from "@stll/docx-core/model";
30
30
  // src/prosemirror/extensions/core/ParagraphExtension.ts
31
31
  /**
32
32
  * Paragraph Extension — paragraph node with alignment, spacing, indent, style commands
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Undo and redo: the commands and the keys that run them, apart from the
3
+ * `prosemirror-history` plugin that keeps the stack.
4
+ */
5
+ import { KeyboardShortcutMap } from "../types.js";
6
+ import { Command } from "prosemirror-state";
7
+ /**
8
+ * Who answers the undo and redo keys (Mod-z, Mod-y, Mod-Shift-z).
9
+ * - `"editor"`: the extension binds them. Default.
10
+ * - `"host"`: nothing binds them. The host keeps its own undo stack and runs
11
+ * the `undo` / `redo` commands itself, so one press never undoes twice.
12
+ */
13
+ export type HistoryShortcutOwner = "editor" | "host";
14
+ export declare const undoCommand: () => Command;
15
+ export declare const redoCommand: () => Command;
16
+ export declare const historyKeyboardShortcuts: KeyboardShortcutMap;
@@ -0,0 +1,19 @@
1
+ import { withCanonicalHistory } from "../../canonicalCommands.js";
2
+ import { redo, undo } from "prosemirror-history";
3
+ // src/prosemirror/extensions/core/historyCommands.ts
4
+ /**
5
+ * Undo and redo: the commands and the keys that run them, apart from the
6
+ * `prosemirror-history` plugin that keeps the stack.
7
+ */
8
+ const undoCommand = () => withCanonicalHistory(undo, "undo");
9
+ const redoCommand = () => withCanonicalHistory(redo, "redo");
10
+ const consumeHistoryShortcut = (command) => (state, dispatch, view) => {
11
+ command(state, dispatch, view);
12
+ return true;
13
+ };
14
+ const historyKeyboardShortcuts = {
15
+ "Mod-z": consumeHistoryShortcut(undo),
16
+ "Mod-y": consumeHistoryShortcut(redo),
17
+ "Mod-Shift-z": consumeHistoryShortcut(redo)
18
+ };
19
+ export { historyKeyboardShortcuts, redoCommand, undoCommand };
@@ -1,11 +1,11 @@
1
1
  import { setProseParagraphMarkupWithPropertySource } from "../../../docx/paragraphPropertySource.js";
2
2
  import { getTransactionDirtyRange } from "../../../paged-layout/transactionDirtyRange.js";
3
3
  import { detectBaseDirection } from "../../../utils/baseDirection.js";
4
+ import { ignoreTrackedChanges } from "../../paragraphChangeTrackerMeta.js";
4
5
  import { directionIsAutoManaged } from "../../paragraphDirection.js";
5
6
  import { createPluginKeyOwner } from "../../pluginKeyOwner.js";
6
7
  import { afterNativeCompositionFlush } from "../../textInput.js";
7
8
  import { createExtension } from "../create.js";
8
- import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
9
9
  import { Plugin } from "prosemirror-state";
10
10
  // src/prosemirror/extensions/features/AutoBidiDetectionExtension.ts
11
11
  /**
@@ -1,30 +1,7 @@
1
+ import { ParagraphPropertySourceSeed } from "../../paraIds.js";
1
2
  import { Extension } from "../types.js";
3
+ import { Transaction } from "prosemirror-state";
2
4
  import { Node } from "prosemirror-model";
3
- import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
4
- type ParagraphPropertySourceSeed = {
5
- contract: string | null;
6
- tokens: ReadonlySet<string>;
7
- };
8
- export declare const paraIdAllocatorKey: Readonly<{
9
- key: string;
10
- createKey: () => PluginKey<ParagraphPropertySourceSeed>;
11
- owns: (plugin: Plugin<ParagraphPropertySourceSeed>) => boolean;
12
- get: (state: EditorState) => Plugin<ParagraphPropertySourceSeed> | undefined;
13
- getState: (state: EditorState) => ParagraphPropertySourceSeed | undefined;
14
- }>;
15
- /**
16
- * Transaction meta asking this plugin to derive the ids it mints from a
17
- * caller-supplied seed instead of `Math.random()`.
18
- *
19
- * A live editor wants random ids: two people typing must not collide. A
20
- * generator whose whole output has to be reproducible — the document compare —
21
- * cannot afford them, and it is the only party that knows its run is meant to
22
- * be deterministic, so it says so on its own transaction rather than leaving
23
- * the plugin to guess.
24
- */
25
- export declare const deterministicParaIdSeedKey = "stll.folio.meta.deterministicParaIdSeed";
26
- /** Ask the allocator to mint reproducible ids for the paragraphs `tr` creates. */
27
- export declare const requestDeterministicParaIds: (tr: Transaction, seed: string) => Transaction;
28
5
  type ParagraphPropertySourceKeeper = {
29
6
  status: "ambiguous";
30
7
  } | {
@@ -42,15 +19,5 @@ type MappedParagraphKeepers = {
42
19
  * @internal Exported for the per-step equivalence test.
43
20
  */
44
21
  export declare const mapParagraphKeepers: (oldDoc: Node, transactions: readonly Transaction[], sourceSeed: ParagraphPropertySourceSeed) => MappedParagraphKeepers;
45
- /**
46
- * Allocate initial paragraph IDs before constructing editor state.
47
- *
48
- * Rebuilding only changed branches avoids applying one ProseMirror transaction
49
- * step per missing paragraph. Live edits still use the transaction-based plugin
50
- * below so history, mappings, and duplicate ownership retain their semantics.
51
- */
52
- export declare const ensureParaIdsInDoc: (doc: Node) => Node;
53
- /** {@link ensureParaIdsInDoc} for a state that already exists. */
54
- export declare const ensureParaIdsInState: (state: EditorState) => EditorState;
55
22
  export declare const ParaIdAllocatorExtension: (options?: Partial<Record<never, never>> | undefined) => Extension;
56
23
  export {};
@@ -1,12 +1,10 @@
1
- import { PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, getExplicitParagraphPropertySourceTransfers, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, paragraphPropertySourceTokenMatchesContract, recreateProseNodeWithParagraphPropertySource, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource } from "../../../docx/paragraphPropertySource.js";
2
- import { prosePositionalParagraphId } from "../../../docx/unnamedParagraphIds.js";
1
+ import { PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, getExplicitParagraphPropertySourceTransfers, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, paragraphPropertySourceTokenMatchesContract, setProseParagraphMarkupWithPropertySource } from "../../../docx/paragraphPropertySource.js";
3
2
  import { deterministicHexId, generateHexId } from "../../../utils/hexId.js";
4
- import { createPluginKeyOwner } from "../../pluginKeyOwner.js";
3
+ import { deterministicParaIdSeedKey, isUsableParaId, paraIdAllocatorKey, visitAuthoredParagraphs } from "../../paraIds.js";
4
+ import { ignoreTrackedChanges } from "../../paragraphChangeTrackerMeta.js";
5
5
  import { sweepPositions } from "../../positionSweep.js";
6
6
  import { createExtension } from "../create.js";
7
- import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
8
7
  import { panic } from "better-result";
9
- import { Fragment } from "prosemirror-model";
10
8
  import { Plugin, Transaction } from "prosemirror-state";
11
9
  // src/prosemirror/extensions/features/ParaIdAllocatorExtension.ts
12
10
  /**
@@ -49,20 +47,6 @@ import { Plugin, Transaction } from "prosemirror-state";
49
47
  * split therefore restores the same allocated id instead of minting
50
48
  * another one.
51
49
  */
52
- const paraIdAllocatorKey = createPluginKeyOwner("paraIdAllocator");
53
- /**
54
- * Transaction meta asking this plugin to derive the ids it mints from a
55
- * caller-supplied seed instead of `Math.random()`.
56
- *
57
- * A live editor wants random ids: two people typing must not collide. A
58
- * generator whose whole output has to be reproducible — the document compare —
59
- * cannot afford them, and it is the only party that knows its run is meant to
60
- * be deterministic, so it says so on its own transaction rather than leaving
61
- * the plugin to guess.
62
- */
63
- const deterministicParaIdSeedKey = "stll.folio.meta.deterministicParaIdSeed";
64
- /** Ask the allocator to mint reproducible ids for the paragraphs `tr` creates. */
65
- const requestDeterministicParaIds = (tr, seed) => tr.setMeta(deterministicParaIdSeedKey, seed);
66
50
  const deterministicSeedOf = (transaction) => {
67
51
  const seed = transaction.getMeta(deterministicParaIdSeedKey);
68
52
  if (typeof seed === "string") return seed;
@@ -87,17 +71,6 @@ const mintParaId = (taken, seed, pos) => {
87
71
  for (let salt = 1; taken.has(id); salt++) id = deterministicHexId(`${seed}:${String(pos)}:${String(salt)}`);
88
72
  return id;
89
73
  };
90
- const isUsableParaId = (value) => typeof value === "string" && value.length > 0 && value !== "00000000";
91
- /** Omitted grid cells render absent positions and own no package paragraphs. */
92
- const isOmittedGridCell = (node) => (node.type.spec["tableRole"] === "cell" || node.type.spec["tableRole"] === "header_cell") && (node.attrs["_omittedGridSlot"] === "before" || node.attrs["_omittedGridSlot"] === "after");
93
- const visitAuthoredParagraphs = (doc, visit) => {
94
- doc.descendants((node, pos) => {
95
- if (isOmittedGridCell(node)) return false;
96
- if (node.type.name !== "paragraph") return true;
97
- visit(node, pos);
98
- return false;
99
- });
100
- };
101
74
  const collectParagraphPropertySourceSeed = (doc) => {
102
75
  const contract = getProseDocumentParagraphPropertySourceContract(doc);
103
76
  if (!contract) return {
@@ -244,117 +217,6 @@ const collectParagraphPropertySourceUpdates = (census, keeperPositions, transact
244
217
  token
245
218
  })).sort((left, right) => left.pos - right.pos);
246
219
  };
247
- /**
248
- * The ids a loaded document's paragraphs take, in document order: `null`
249
- * keeps the paragraph's own id, a string replaces it.
250
- *
251
- * This is the only load-time allocator. The live editor and the headless
252
- * reviewer both seed through it, so the same document gives the same block ids
253
- * on either side: an id read from the editor resolves when the edit is applied
254
- * headlessly, and re-parsing the same bytes mints the same ids. A paragraph
255
- * the package names no id for takes the id its place in the package gives it
256
- * (the one `ensureParaIds` writes, so a canonical session agrees); one the
257
- * parser could not place, such as a paragraph a host built, takes an id
258
- * derived from its text and its document ordinal, never drawn at random.
259
- * Authored ids are reserved first, so a minted id never takes one a later
260
- * paragraph owns; of a duplicated authored id, the first occurrence keeps it.
261
- */
262
- const planLoadParaIds = (doc) => {
263
- const paragraphs = [];
264
- const taken = /* @__PURE__ */ new Set();
265
- visitAuthoredParagraphs(doc, (node) => {
266
- paragraphs.push(node);
267
- const id = node.attrs["paraId"];
268
- if (isUsableParaId(id)) {
269
- taken.add(id);
270
- return;
271
- }
272
- const positional = prosePositionalParagraphId(node);
273
- if (positional !== void 0) taken.add(positional);
274
- });
275
- const kept = /* @__PURE__ */ new Set();
276
- return paragraphs.map((paragraph, index) => {
277
- const id = paragraph.attrs["paraId"];
278
- if (isUsableParaId(id) && !kept.has(id)) {
279
- kept.add(id);
280
- return null;
281
- }
282
- const positional = prosePositionalParagraphId(paragraph);
283
- if (positional !== void 0 && !kept.has(positional)) {
284
- kept.add(positional);
285
- return positional;
286
- }
287
- const seed = `${paragraph.textContent}:${String(index + 1)}`;
288
- let minted = deterministicHexId(seed);
289
- for (let salt = 1; taken.has(minted); salt++) minted = deterministicHexId(`${seed}:${String(salt)}`);
290
- taken.add(minted);
291
- return minted;
292
- });
293
- };
294
- /** A paragraph's attrs once it holds an id folio minted rather than read. */
295
- const mintedParagraphAttrs = (paragraph, paraId) => ({
296
- ...paragraph.attrs,
297
- paraId,
298
- ...paragraph.type.spec.attrs?.["idStability"] !== void 0 && { idStability: "positional" }
299
- });
300
- /**
301
- * Allocate initial paragraph IDs before constructing editor state.
302
- *
303
- * Rebuilding only changed branches avoids applying one ProseMirror transaction
304
- * step per missing paragraph. Live edits still use the transaction-based plugin
305
- * below so history, mappings, and duplicate ownership retain their semantics.
306
- */
307
- const ensureParaIdsInDoc = (doc) => {
308
- const plan = planLoadParaIds(doc);
309
- if (plan.every((paraId) => paraId === null)) return doc;
310
- let ordinal = 0;
311
- const rewrite = (parent) => {
312
- let changed = false;
313
- const children = [];
314
- parent.forEach((child) => {
315
- if (isOmittedGridCell(child)) {
316
- children.push(child);
317
- return;
318
- }
319
- let next = child;
320
- if (child.type.name === "paragraph") {
321
- const minted = plan[ordinal];
322
- ordinal += 1;
323
- if (minted !== null && minted !== void 0) next = recreateProseNodeWithParagraphPropertySource(child, { attrs: mintedParagraphAttrs(child, minted) });
324
- const paraId = next.attrs["paraId"];
325
- if (typeof paraId === "string") transferProseParagraphPropertySource(next, child, paraId);
326
- } else if (child.childCount > 0) {
327
- const content = rewrite(child);
328
- if (content !== child.content) next = recreateProseNodeWithParagraphPropertySource(child, { content });
329
- }
330
- if (next !== child) changed = true;
331
- children.push(next);
332
- });
333
- return changed ? Fragment.fromArray(children) : parent.content;
334
- };
335
- return recreateProseNodeWithParagraphPropertySource(doc, { content: rewrite(doc) });
336
- };
337
- /** {@link ensureParaIdsInDoc} for a state that already exists. */
338
- const ensureParaIdsInState = (state) => {
339
- const plan = planLoadParaIds(state.doc);
340
- if (plan.every((paraId) => paraId === null)) return state;
341
- const tr = state.tr;
342
- let ordinal = 0;
343
- visitAuthoredParagraphs(state.doc, (node, pos) => {
344
- const minted = plan[ordinal];
345
- ordinal += 1;
346
- if (minted !== null && minted !== void 0) setProseParagraphMarkupWithPropertySource({
347
- attrs: mintedParagraphAttrs(node, minted),
348
- ownership: "transfer-allocated-id",
349
- pos,
350
- transaction: tr
351
- });
352
- });
353
- ignoreTrackedChanges(tr);
354
- tr.setMeta(paraIdAllocatorKey, "allocated");
355
- tr.setMeta("addToHistory", false);
356
- return state.apply(tr);
357
- };
358
220
  const createParaIdAllocatorPlugin = () => new Plugin({
359
221
  key: paraIdAllocatorKey.createKey(),
360
222
  state: {
@@ -405,4 +267,4 @@ const ParaIdAllocatorExtension = createExtension({
405
267
  return { plugins: [createParaIdAllocatorPlugin()] };
406
268
  }
407
269
  });
408
- export { ParaIdAllocatorExtension, deterministicParaIdSeedKey, ensureParaIdsInDoc, ensureParaIdsInState, mapParagraphKeepers, paraIdAllocatorKey, requestDeterministicParaIds };
270
+ export { ParaIdAllocatorExtension, mapParagraphKeepers };