@stll/folio-core 0.73.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 (135) hide show
  1. package/dist/ai-edits/headless.js +2 -5
  2. package/dist/ai-edits/pendingJoin.js +6 -1
  3. package/dist/ai-edits/result-validation.js +1 -1
  4. package/dist/ai-edits/snapshot.js +1 -1
  5. package/dist/ai-edits/table-cell-mutations.js +1 -1
  6. package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
  7. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  8. package/dist/canonical/canonicalInlineGaps.js +118 -0
  9. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  10. package/dist/canonical/canonicalInlineProjection.js +6 -28
  11. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  12. package/dist/canonical/canonicalPublicOperations.js +70 -27
  13. package/dist/canonical/canonicalSelection.js +1 -1
  14. package/dist/canonical/canonicalSession.js +14 -21
  15. package/dist/controller/autocompleteSuggestion.js +1 -1
  16. package/dist/controller/canonicalClipboard.js +2 -2
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInput.js +1 -1
  19. package/dist/controller/canonicalPresence.js +1 -1
  20. package/dist/controller/canonicalRoomAuthority.js +1 -1
  21. package/dist/controller/canonicalRoomWire.js +1 -1
  22. package/dist/controller/canonicalStructure.js +1 -1
  23. package/dist/controller/canonicalTabRoom.js +1 -1
  24. package/dist/controller/canonicalYjsRoom.js +1 -1
  25. package/dist/controller/hiddenEditorApi.js +2 -17
  26. package/dist/controller/hiddenEditorManager.js +4 -8
  27. package/dist/document-operations.js +1 -1
  28. package/dist/docx/canonicalSave.d.ts +1 -1
  29. package/dist/docx/canonicalSave.js +1 -1
  30. package/dist/docx/canonicalSessionInput.js +1 -1
  31. package/dist/docx/containerChildren.js +1 -1
  32. package/dist/docx/createDocx.d.ts +4 -0
  33. package/dist/docx/createDocx.js +6 -0
  34. package/dist/docx/modelValidation.js +1 -1
  35. package/dist/docx/parser.js +1 -1
  36. package/dist/docx/reviewResolutionProvenance.js +1 -1
  37. package/dist/docx/rezip.d.ts +1 -1
  38. package/dist/docx/rezip.js +2 -2
  39. package/dist/docx/serializer/borderSerializer.js +1 -1
  40. package/dist/docx/serializer/commentSerializer.js +1 -1
  41. package/dist/docx/serializer/documentSerializer.js +1 -1
  42. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  43. package/dist/docx/serializer/runSerializer.js +1 -1
  44. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  45. package/dist/docx/serializer/tableSerializer.js +1 -1
  46. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  47. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  48. package/dist/docx/server/templatePlan/apply.js +69 -11
  49. package/dist/docx/server/templatePlan/inspect.js +88 -35
  50. package/dist/docx/server/templatePlan/labels.d.ts +10 -1
  51. package/dist/docx/server/templatePlan/labels.js +31 -2
  52. package/dist/docx/server/templatePlan/plan.d.ts +2 -0
  53. package/dist/docx/server/templatePlan/plan.js +41 -7
  54. package/dist/docx/server/templatePlan/planShape.js +22 -3
  55. package/dist/docx/server/templatePlan/types.d.ts +38 -2
  56. package/dist/docx/server/templatePlan/types.js +1 -0
  57. package/dist/docx/server/templatePlan/verify.js +11 -3
  58. package/dist/docx/server/templatePlan/xml.d.ts +5 -0
  59. package/dist/docx/server/templatePlan/xml.js +7 -1
  60. package/dist/docx/storyBlockReplay.js +1 -1
  61. package/dist/docx/xmlParser.js +1 -1
  62. package/dist/i18n/loadMessages.d.ts +5 -0
  63. package/dist/i18n/loadMessages.js +46 -0
  64. package/dist/i18n/locales.d.ts +3 -0
  65. package/dist/i18n/locales.js +17 -0
  66. package/dist/i18n/messages.d.ts +3 -2
  67. package/dist/i18n/messages.js +4 -16
  68. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  69. package/dist/internal/clipboardTransformPlugin.js +13 -0
  70. package/dist/internal/extensionRuntime.d.ts +7 -0
  71. package/dist/internal/extensionRuntime.js +28 -0
  72. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  73. package/dist/internal/starterKitExtensions.d.ts +20 -0
  74. package/dist/internal/starterKitExtensions.js +123 -0
  75. package/dist/internal/wholeStoryRevisionResolution.js +2 -2
  76. package/dist/prosemirror/attrs/index.js +1 -1
  77. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  78. package/dist/prosemirror/canonicalTableCommands.js +1 -1
  79. package/dist/prosemirror/commands/comments.js +3 -3
  80. package/dist/prosemirror/commands/contentControls.js +1 -1
  81. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  82. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  83. package/dist/prosemirror/commentRecords.js +2 -2
  84. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  85. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  86. package/dist/prosemirror/conversion/index.d.ts +2 -2
  87. package/dist/prosemirror/conversion/index.js +2 -2
  88. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  89. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  90. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  91. package/dist/prosemirror/extensions/core/ParagraphExtension.js +2 -2
  92. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  93. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  94. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  95. package/dist/prosemirror/extensions/index.d.ts +2 -1
  96. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  97. package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
  98. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  99. package/dist/prosemirror/index.d.ts +2 -2
  100. package/dist/prosemirror/index.js +2 -2
  101. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  102. package/dist/prosemirror/listNumbering.js +1 -1
  103. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  104. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  105. package/dist/prosemirror/noteReferenceReview.js +2 -243
  106. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  107. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  108. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  109. package/dist/prosemirror/replacedAnnotations.js +1 -1
  110. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  111. package/dist/prosemirror/suggestionCommands.js +31 -0
  112. package/dist/prosemirror/tableCellPaste.js +1 -1
  113. package/dist/prosemirror/tableRunIn.js +1 -1
  114. package/dist/prosemirror/textInput.js +1 -1
  115. package/dist/types/canonicalCapabilities.d.ts +6 -52
  116. package/dist/types/canonicalCapabilities.js +6 -52
  117. package/package.json +2 -2
  118. package/dist/ai-edits/apply.d.ts +0 -94
  119. package/dist/ai-edits/apply.js +0 -6637
  120. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  121. package/dist/ai-edits/note-story-inventory.js +0 -10
  122. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  123. package/dist/ai-edits/revisionStretches.js +0 -147
  124. package/dist/document-operations-apply.d.ts +0 -15
  125. package/dist/document-operations-apply.js +0 -280
  126. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
  127. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
  128. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
  129. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
  130. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
  131. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
  132. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  133. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  134. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  135. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -1,411 +0,0 @@
1
- import { withTrackedSectionEndpointRemoval } from "../../../internal/sectionEndpointResolution.js";
2
- import { countDocumentStructure } from "../../documentStructureCounts.js";
3
- import { enclosingParagraphIndexed, nodeAtIndexed, nodesBetweenIndexed } from "../../indexedNodeLookup.js";
4
- import { CHANGED_PARAGRAPH_RANGES_META, SECTION_ENDPOINT_REMOVAL_META, isChangedParagraphRangesMeta, isTrackedSectionEndpointRemoval, isTrackedSectionEndpointRemovalMeta, paragraphChangeTrackerKey, referencesOf } from "../../paragraphChangeTrackerMeta.js";
5
- import { sweepPositions } from "../../positionSweep.js";
6
- import { sectionPropertiesOf } from "../../sectionCarrier.js";
7
- import { sectionMarkEditsOf } from "../../sectionMarkEdits.js";
8
- import { createExtension } from "../create.js";
9
- import { droppedCellSections } from "./pastedCellSections.js";
10
- import { AddMarkStep, AddNodeMarkStep, AttrStep, RemoveMarkStep, RemoveNodeMarkStep } from "prosemirror-transform";
11
- import { Plugin } from "prosemirror-state";
12
- import { isHistoryTransaction } from "prosemirror-history";
13
- // src/prosemirror/extensions/features/ParagraphChangeTrackerExtension.ts
14
- /**
15
- * Paragraph Change Tracker Extension
16
- *
17
- * Watches ProseMirror transactions and records which paragraph IDs (paraId)
18
- * were modified. Also detects paragraph and block-structure changes.
19
- * Used by the selective save system to patch only changed paragraphs in document.xml.
20
- */
21
- const SECTION_EDIT_META = "folioSectionEdit";
22
- const isSectionEditMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "section-edit-meta" && "authorization" in value && (value.authorization === null || isTrackedSectionEndpointRemoval(value.authorization)) && "expectedEndpointFingerprint" in value && typeof value.expectedEndpointFingerprint === "string";
23
- /**
24
- * Whether a transaction left every section record in place, by identity: the
25
- * same sections, however their paragraphs moved around them. An edit before a
26
- * section break (a paragraph inserted, a split, a paraId allocated) moves the
27
- * endpoint without changing which sections the package states, so a removal
28
- * authorized earlier still describes the saved section count exactly. A record
29
- * edited, added or dropped is a new transition the authorization never saw.
30
- */
31
- const holdsTheSameSections = (previous, next) => previous.sectionRecords.size === next.sectionRecords.size && [...next.sectionRecords].every((record) => previous.sectionRecords.has(record));
32
- const isUsableParaId = (value) => typeof value === "string" && value.length > 0 && value !== "00000000";
33
- /**
34
- * Collect paraIds of all paragraphs that overlap with the given range
35
- */
36
- function collectAffectedParaIds(doc, from, to) {
37
- const ids = /* @__PURE__ */ new Set();
38
- const positions = /* @__PURE__ */ new Set();
39
- let hasUntracked = false;
40
- const start = Math.max(0, Math.min(from, doc.content.size));
41
- const end = Math.max(start, Math.min(to, doc.content.size));
42
- nodesBetweenIndexed(doc, start, end, (node, pos) => {
43
- if (node.type.name === "paragraph") {
44
- positions.add(pos);
45
- const paraId = node.attrs["paraId"];
46
- if (isUsableParaId(paraId)) ids.add(paraId);
47
- else hasUntracked = true;
48
- }
49
- });
50
- return {
51
- ids,
52
- positions,
53
- hasUntracked
54
- };
55
- }
56
- /**
57
- * AddMarkStep / RemoveMarkStep inherit Step.getMap() → StepMap.empty, so we use
58
- * their from/to to find affected paragraphs.
59
- * Node mark steps use a single position before the target node.
60
- */
61
- function collectAffectedParaIdsFromMarkLikeStep(doc, from, to) {
62
- const lo = Math.min(from, to);
63
- const hi = Math.max(from, to);
64
- const primary = collectAffectedParaIds(doc, lo, hi > lo ? hi : lo + 1);
65
- if (primary.ids.size > 0 || primary.hasUntracked) return primary;
66
- const paragraph = enclosingParagraphIndexed(doc, lo);
67
- if (paragraph) {
68
- const paraId = paragraph.node.attrs["paraId"];
69
- return {
70
- ids: new Set(isUsableParaId(paraId) ? [paraId] : []),
71
- positions: /* @__PURE__ */ new Set([paragraph.pos]),
72
- hasUntracked: !isUsableParaId(paraId)
73
- };
74
- }
75
- return {
76
- ids: /* @__PURE__ */ new Set(),
77
- positions: /* @__PURE__ */ new Set(),
78
- hasUntracked: false
79
- };
80
- }
81
- /**
82
- * Map edited paragraphs' interiors so markup replacement retains their
83
- * ownership: each position's paragraph in `tr.doc`, or null once deleted. The
84
- * positions go through the transaction together (see `sweepPositions`).
85
- */
86
- const mapParagraphPositions = (tr, positions) => sweepPositions([tr.mapping], positions.map((position) => ({
87
- pos: position + 1,
88
- assoc: 1,
89
- from: 0
90
- }))).map((mapped) => mapped.deletedAcross ? null : enclosingParagraphIndexed(tr.doc, mapped.pos)?.pos ?? null);
91
- const mapAffectedParagraphPositions = (tr, positions) => {
92
- const mappedPositions = /* @__PURE__ */ new Set();
93
- for (const mapped of mapParagraphPositions(tr, [...positions])) if (mapped !== null) mappedPositions.add(mapped);
94
- return mappedPositions;
95
- };
96
- /**
97
- * Every position the step loop reads, each entering the sweep at the step
98
- * after the one that produced it: the transaction is mapped once rather than
99
- * sliced and walked again for every step.
100
- */
101
- const mapStepTouches = (tr, batches) => {
102
- const queries = [];
103
- const touches = [];
104
- const addRange = (kind, from, to, at) => {
105
- touches.push({
106
- kind,
107
- query: queries.length
108
- });
109
- queries.push({
110
- pos: from,
111
- assoc: 1,
112
- from: at
113
- }, {
114
- pos: to,
115
- assoc: -1,
116
- from: at
117
- });
118
- };
119
- const replacedStepMaps = /* @__PURE__ */ new Set();
120
- for (const batch of batches) {
121
- if (batch.replacesStepMapAt !== void 0) replacedStepMaps.add(batch.replacesStepMapAt);
122
- for (const range of batch.ranges) addRange("mark-range", range.from, range.to, batch.mappingFrom);
123
- }
124
- for (let stepIndex = 0; stepIndex < tr.steps.length; stepIndex++) {
125
- if (replacedStepMaps.has(stepIndex)) continue;
126
- const step = tr.steps[stepIndex];
127
- const at = stepIndex + 1;
128
- if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
129
- addRange("mark-range", step.from, step.to, at);
130
- continue;
131
- }
132
- if (step instanceof AddNodeMarkStep || step instanceof RemoveNodeMarkStep || step instanceof AttrStep) {
133
- touches.push({
134
- kind: "node",
135
- query: queries.length
136
- });
137
- queries.push({
138
- pos: step.pos,
139
- assoc: 1,
140
- from: at
141
- });
142
- continue;
143
- }
144
- step.getMap().forEach((_oldStart, _oldEnd, newStart, newEnd) => {
145
- addRange("replaced-range", newStart, newEnd, at);
146
- });
147
- }
148
- return {
149
- touches,
150
- mapped: sweepPositions([tr.mapping], queries)
151
- };
152
- };
153
- function createParagraphChangeTrackerPlugin() {
154
- return new Plugin({
155
- key: paragraphChangeTrackerKey.createKey(),
156
- state: {
157
- init(_config, state) {
158
- const counts = countDocumentStructure(state.doc);
159
- return {
160
- affectedParagraphPositions: /* @__PURE__ */ new Set(),
161
- hasUntrackedSourceChanges: false,
162
- blockStructureFingerprint: counts.blockStructureFingerprint,
163
- changedParaIds: /* @__PURE__ */ new Set(),
164
- structuralChange: false,
165
- hasUntrackedChanges: false,
166
- paragraphCount: counts.paragraphs,
167
- sectionEndpointCount: counts.sectionEndpoints,
168
- sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
169
- sectionRecords: counts.sectionRecords,
170
- sectionEndpointRemoval: null
171
- };
172
- },
173
- apply(tr, prevState) {
174
- const meta = tr.getMeta(paragraphChangeTrackerKey);
175
- const changedParagraphRangesMeta = tr.getMeta(CHANGED_PARAGRAPH_RANGES_META);
176
- const sectionEndpointRemovalMeta = tr.getMeta(SECTION_ENDPOINT_REMOVAL_META);
177
- const sectionEditMeta = tr.getMeta(SECTION_EDIT_META);
178
- if (meta === "clear") {
179
- const counts = countDocumentStructure(tr.doc);
180
- return {
181
- affectedParagraphPositions: /* @__PURE__ */ new Set(),
182
- hasUntrackedSourceChanges: false,
183
- blockStructureFingerprint: counts.blockStructureFingerprint,
184
- changedParaIds: /* @__PURE__ */ new Set(),
185
- structuralChange: false,
186
- hasUntrackedChanges: false,
187
- paragraphCount: counts.paragraphs,
188
- sectionEndpointCount: counts.sectionEndpoints,
189
- sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
190
- sectionRecords: counts.sectionRecords,
191
- sectionEndpointRemoval: null
192
- };
193
- }
194
- if (meta === "ignore") {
195
- if (!tr.docChanged) return prevState;
196
- const counts = countDocumentStructure(tr.doc);
197
- const affectedParagraphPositions = mapAffectedParagraphPositions(tr, prevState.affectedParagraphPositions);
198
- const changedParaIds = /* @__PURE__ */ new Set();
199
- let unresolvedChanges = prevState.hasUntrackedSourceChanges;
200
- for (const position of affectedParagraphPositions) {
201
- const paraId = nodeAtIndexed(tr.doc, position)?.attrs["paraId"];
202
- if (isUsableParaId(paraId)) changedParaIds.add(paraId);
203
- else unresolvedChanges = true;
204
- }
205
- return {
206
- ...prevState,
207
- affectedParagraphPositions,
208
- changedParaIds,
209
- hasUntrackedChanges: unresolvedChanges,
210
- blockStructureFingerprint: counts.blockStructureFingerprint,
211
- paragraphCount: counts.paragraphs,
212
- sectionEndpointCount: counts.sectionEndpoints,
213
- sectionEndpointRemoval: holdsTheSameSections(prevState, counts) ? prevState.sectionEndpointRemoval : null,
214
- sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
215
- sectionRecords: counts.sectionRecords
216
- };
217
- }
218
- if (!tr.docChanged) return isSectionEditMeta(sectionEditMeta) && sectionEditMeta.expectedEndpointFingerprint === prevState.sectionEndpointFingerprint ? {
219
- ...prevState,
220
- sectionEndpointRemoval: sectionEditMeta.authorization
221
- } : prevState;
222
- const counts = countDocumentStructure(tr.doc);
223
- const newCount = counts.paragraphs;
224
- let sectionEndpointRemoval = prevState.sectionEndpointRemoval;
225
- if (counts.sectionEndpointFingerprint !== prevState.sectionEndpointFingerprint) {
226
- if (isTrackedSectionEndpointRemovalMeta(sectionEndpointRemovalMeta) && sectionEndpointRemovalMeta.authorization.sourceEndpointFingerprint === prevState.sectionEndpointFingerprint && sectionEndpointRemovalMeta.authorization.expectedEndpointFingerprint === counts.sectionEndpointFingerprint && sectionEndpointRemovalMeta.authorization.sourceParagraphEndpointCount === prevState.sectionEndpointCount && sectionEndpointRemovalMeta.authorization.expectedParagraphEndpointCount === counts.sectionEndpoints && counts.sectionEndpoints < prevState.sectionEndpointCount) {
227
- const authorization = sectionEndpointRemovalMeta.authorization;
228
- sectionEndpointRemoval = {
229
- type: "tracked-section-endpoint-removal",
230
- sourceParagraphEndpointCount: prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.sourceParagraphEndpointCount : authorization.sourceParagraphEndpointCount,
231
- expectedParagraphEndpointCount: authorization.expectedParagraphEndpointCount,
232
- sourceEndpointFingerprint: prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.sourceEndpointFingerprint : authorization.sourceEndpointFingerprint,
233
- expectedEndpointFingerprint: authorization.expectedEndpointFingerprint,
234
- removedReferences: [...prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.removedReferences : [], ...authorization.removedReferences]
235
- };
236
- } else if (!holdsTheSameSections(prevState, counts)) sectionEndpointRemoval = null;
237
- }
238
- if (isSectionEditMeta(sectionEditMeta) && sectionEditMeta.expectedEndpointFingerprint === counts.sectionEndpointFingerprint) sectionEndpointRemoval = sectionEditMeta.authorization;
239
- const newState = {
240
- affectedParagraphPositions: mapAffectedParagraphPositions(tr, prevState.affectedParagraphPositions),
241
- hasUntrackedSourceChanges: prevState.hasUntrackedSourceChanges,
242
- blockStructureFingerprint: counts.blockStructureFingerprint,
243
- changedParaIds: new Set(prevState.changedParaIds),
244
- structuralChange: prevState.structuralChange || meta === "structural",
245
- hasUntrackedChanges: prevState.hasUntrackedChanges,
246
- paragraphCount: newCount,
247
- sectionEndpointCount: counts.sectionEndpoints,
248
- sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
249
- sectionRecords: counts.sectionRecords,
250
- sectionEndpointRemoval
251
- };
252
- const recordAffected = ({ ids, positions, hasUntracked }) => {
253
- for (const position of positions) newState.affectedParagraphPositions.add(position);
254
- for (const id of ids) newState.changedParaIds.add(id);
255
- if (hasUntracked) newState.hasUntrackedChanges = true;
256
- };
257
- const { touches, mapped } = mapStepTouches(tr, isChangedParagraphRangesMeta(changedParagraphRangesMeta) ? changedParagraphRangesMeta.batches : []);
258
- for (const touch of touches) {
259
- const from = mapped[touch.query].pos;
260
- if (touch.kind === "node") {
261
- if (mapped[touch.query].deletedAcross) continue;
262
- const node = nodeAtIndexed(tr.doc, from);
263
- if (node) recordAffected(collectAffectedParaIds(tr.doc, from, from + node.nodeSize));
264
- continue;
265
- }
266
- const to = mapped[touch.query + 1].pos;
267
- if (touch.kind === "mark-range") {
268
- if (to > from) recordAffected(collectAffectedParaIdsFromMarkLikeStep(tr.doc, from, to));
269
- continue;
270
- }
271
- if (to >= from) recordAffected(collectAffectedParaIds(tr.doc, from, to));
272
- }
273
- if (prevState.blockStructureFingerprint !== counts.blockStructureFingerprint) newState.structuralChange = true;
274
- if (newState.hasUntrackedChanges || prevState.blockStructureFingerprint !== counts.blockStructureFingerprint) {
275
- const unidentified = [];
276
- tr.before.descendants((node, position) => {
277
- if (node.type.name !== "paragraph") return true;
278
- if (!isUsableParaId(node.attrs["paraId"])) unidentified.push(position);
279
- return false;
280
- });
281
- for (const survivor of mapParagraphPositions(tr, unidentified)) if (survivor === null || newState.affectedParagraphPositions.has(survivor)) {
282
- newState.hasUntrackedSourceChanges = true;
283
- newState.hasUntrackedChanges = true;
284
- }
285
- }
286
- return newState;
287
- }
288
- },
289
- appendTransaction: (transactions, oldState, newState) => sectionEditTransaction(transactions, oldState, newState)
290
- });
291
- }
292
- /** `references` without one occurrence of each of `restored`. */
293
- const withoutReferences = (references, restored) => {
294
- const remaining = [...references];
295
- for (const reference of restored) {
296
- const index = remaining.findIndex((candidate) => candidate.part === reference.part && candidate.type === reference.type && candidate.relationshipId === reference.relationshipId);
297
- if (index !== -1) remaining.splice(index, 1);
298
- }
299
- return remaining;
300
- };
301
- /**
302
- * Carry section breaks through an ordinary edit, and record the ones it
303
- * deleted.
304
- *
305
- * Deleting the mark of a section-ending paragraph (Backspace or Delete across
306
- * it, a selection, a cut or a paste over it, a join) deletes the break, and
307
- * the section's content joins the following section: the same outcome as
308
- * deleting the paragraph as a block, or accepting its tracked deletion. The
309
- * appended transaction moves each joined paragraph's record to the one its
310
- * surviving mark carries (see `sectionMarkEditsOf`) and states the removal
311
- * the save is to accept.
312
- *
313
- * Only a record whose mark a replacement deleted counts as removed on
314
- * purpose. A record that goes any other way (an attribute cleared, a record
315
- * swapped for another) leaves the edit unauthorized, and the save refuses the
316
- * smaller package as it always did. Records coming back (an undo) take their
317
- * removal back out of the authorization.
318
- */
319
- const sectionEditTransaction = (transactions, oldState, newState) => {
320
- if (!transactions.some((transaction) => transaction.docChanged && transaction.getMeta(paragraphChangeTrackerKey) !== "ignore") || transactions.some((transaction) => transaction.getMeta(SECTION_EDIT_META) !== void 0 || transaction.getMeta("folioSectionEndpointRemoval") !== void 0 || transaction.getMeta(paragraphChangeTrackerKey) === "clear")) return null;
321
- const base = paragraphChangeTrackerKey.getState(oldState);
322
- if (!base) return null;
323
- const dropped = droppedCellSections(transactions, oldState.doc, newState.doc);
324
- if (base.sectionRecords.size === 0 && dropped.length === 0) return null;
325
- const edits = sectionMarkEditsOf(transactions, newState.doc);
326
- const tr = newState.tr;
327
- const restoring = transactions.some((transaction) => isHistoryTransaction(transaction));
328
- for (const { position, record } of restoring ? [] : edits.carriers) {
329
- const paragraph = tr.doc.nodeAt(position);
330
- if (paragraph?.type.name === "paragraph" && sectionPropertiesOf(paragraph) !== record) tr.setNodeAttribute(position, "_sectionProperties", record);
331
- }
332
- for (const position of dropped) tr.setNodeAttribute(position, "_sectionProperties", null);
333
- const after = countDocumentStructure(tr.doc);
334
- if (holdsTheSameSections(base, after)) return tr.docChanged ? tr.setMeta(SECTION_EDIT_META, {
335
- type: "section-edit-meta",
336
- authorization: base.sectionEndpointRemoval,
337
- expectedEndpointFingerprint: after.sectionEndpointFingerprint
338
- }) : null;
339
- const removed = [...base.sectionRecords].filter((record) => !after.sectionRecords.has(record));
340
- const added = [...after.sectionRecords].filter((record) => !base.sectionRecords.has(record));
341
- if (removed.some((record) => !edits.deletedMarks.has(record))) return tr.docChanged ? tr : null;
342
- const prior = base.sectionEndpointRemoval;
343
- const sourceParagraphEndpointCount = prior?.sourceParagraphEndpointCount ?? base.sectionEndpointCount;
344
- const authorization = after.sectionEndpoints < sourceParagraphEndpointCount ? {
345
- type: "tracked-section-endpoint-removal",
346
- sourceParagraphEndpointCount,
347
- expectedParagraphEndpointCount: after.sectionEndpoints,
348
- sourceEndpointFingerprint: prior?.sourceEndpointFingerprint ?? base.sectionEndpointFingerprint,
349
- expectedEndpointFingerprint: after.sectionEndpointFingerprint,
350
- removedReferences: withoutReferences([...prior?.removedReferences ?? [], ...referencesOf(removed)], referencesOf(added))
351
- } : null;
352
- return tr.setMeta(SECTION_EDIT_META, {
353
- type: "section-edit-meta",
354
- authorization,
355
- expectedEndpointFingerprint: after.sectionEndpointFingerprint
356
- });
357
- };
358
- /**
359
- * Get the change tracker state from an EditorState
360
- */
361
- function getChangeTrackerState(state) {
362
- return paragraphChangeTrackerKey.getState(state);
363
- }
364
- /**
365
- * Get the set of changed paragraph IDs from an EditorState
366
- */
367
- function getChangedParagraphIds(state) {
368
- return getChangeTrackerState(state)?.changedParaIds ?? /* @__PURE__ */ new Set();
369
- }
370
- /**
371
- * Check if paragraph membership, order, or block structure changed
372
- */
373
- function hasStructuralChanges(state) {
374
- return getChangeTrackerState(state)?.structuralChange ?? false;
375
- }
376
- /**
377
- * Check if any changes affected paragraphs without paraId
378
- */
379
- function hasUntrackedChanges(state) {
380
- return getChangeTrackerState(state)?.hasUntrackedChanges ?? false;
381
- }
382
- /** Exact section-count transition authorized by tracked paragraph-mark resolution. */
383
- function getTrackedSectionEndpointRemoval(state) {
384
- return getChangeTrackerState(state)?.sectionEndpointRemoval ?? null;
385
- }
386
- /**
387
- * Run an editor save's full repack with the section removals the editor's own
388
- * edits made.
389
- *
390
- * A save refuses a package with fewer sections than its source unless it is
391
- * told which removals were meant: deleting the paragraph that ends a section,
392
- * or accepting its tracked deletion, removes that section on purpose. The
393
- * tracker records exactly those removals; without them the repack throws and
394
- * the edit cannot be saved.
395
- */
396
- const repackWithEditorSectionRemovals = ({ state, document, repack }) => {
397
- const resolution = getTrackedSectionEndpointRemoval(state);
398
- return resolution === null ? repack() : withTrackedSectionEndpointRemoval({
399
- document,
400
- resolution,
401
- repack
402
- });
403
- };
404
- const ParagraphChangeTrackerExtension = createExtension({
405
- name: "paragraphChangeTracker",
406
- defaultOptions: {},
407
- onSchemaReady() {
408
- return { plugins: [createParagraphChangeTrackerPlugin()] };
409
- }
410
- });
411
- export { ParagraphChangeTrackerExtension, createParagraphChangeTrackerPlugin, getChangeTrackerState, getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges, repackWithEditorSectionRemovals };
@@ -1,92 +0,0 @@
1
- /**
2
- * Suggestion Mode Plugin
3
- *
4
- * When active, intercepts all text insertions and deletions,
5
- * wrapping them in tracked change marks (insertion/deletion)
6
- * instead of modifying the document directly.
7
- *
8
- * - Typed text is marked as insertion (green underline)
9
- * - Deleted text is NOT removed — it's marked as deletion (red strikethrough)
10
- * - Text already marked as insertion by the current author is deleted normally
11
- * (retracting your own suggestion)
12
- */
13
- import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
14
- import { Slice } from "prosemirror-model";
15
- import { EditorView } from "prosemirror-view";
16
- export declare const suggestionModeKey: Readonly<{
17
- key: string;
18
- createKey: () => PluginKey<SuggestionModeState>;
19
- owns: (plugin: Plugin<SuggestionModeState>) => boolean;
20
- get: (state: EditorState) => Plugin<SuggestionModeState> | undefined;
21
- getState: (state: EditorState) => SuggestionModeState | undefined;
22
- }>;
23
- export declare const SUGGESTION_META = "suggestionModeApplied";
24
- export declare const SUGGESTION_BYPASS_META = "suggestionModeBypass";
25
- /**
26
- * The text a tracked text-input transaction typed. Rules that react to typing
27
- * (list autoformat) read it, because this plugin claims text input before any
28
- * input rule sees it.
29
- */
30
- export declare const SUGGESTED_TEXT_INPUT_META = "suggestionModeTextInput";
31
- type SuggestionModeState = {
32
- active: boolean;
33
- author: string;
34
- };
35
- export declare function makeRevisionInfo(state: EditorState): {
36
- id: number;
37
- author: string;
38
- date: string;
39
- } | null;
40
- export declare function handleSuggestionPaste(view: Pick<EditorView, "dispatch" | "state">, slice: Slice, pluginState: SuggestionModeState): boolean;
41
- export declare function handleSuggestionTableCellPaste(view: EditorView, slice: Slice, pluginState: SuggestionModeState): boolean;
42
- /**
43
- * Remove `from`..`to` of `tr.doc` as a suggestion: text the current author
44
- * inserted is retracted, anything else is marked deleted. `false` when the
45
- * editor is not suggesting.
46
- */
47
- export declare function suggestRangeDeletion(state: EditorState, tr: Transaction, from: number, to: number): boolean;
48
- /**
49
- * Track-changes Enter: split the paragraph and stamp `pPrMark = 'ins'` on the
50
- * FIRST half of the split (the upper paragraph), per ECMA-376 §17.13.5. The
51
- * actual splitting reuses `splitBlockClearBorders` so border/style/stored-mark
52
- * behavior stays identical to ordinary editing.
53
- *
54
- * A `pPrMark` the source paragraph already carries belongs to its break, which
55
- * now ends the new paragraph: it moves there, so no revision is lost.
56
- */
57
- export declare function handleSuggestionEnter(view: EditorView, pluginState: SuggestionModeState): boolean;
58
- /**
59
- * Detect a caret-at-paragraph-boundary scenario where Backspace/Delete should
60
- * record a tracked paragraph-mark deletion instead of joining paragraphs.
61
- *
62
- * Returns the position of the paragraph whose `pPrMark` should be set, or
63
- * `null` if the caret is mid-paragraph (let the normal text-delete path run).
64
- *
65
- * - Backspace-at-paragraph-start → previous sibling paragraph.
66
- * - Delete-at-paragraph-end → current paragraph.
67
- *
68
- * Returns `null` when there is no adjacent sibling paragraph (the join would
69
- * not produce paragraph-mark merging, e.g. doc start, doc end, or a table).
70
- * Bookmark markers at an edge do not hide the adjacent paragraph break.
71
- */
72
- export declare function paragraphBoundaryTarget(state: EditorState, direction: "backward" | "forward"): number | null;
73
- /** Apply the editor's selected-content deletion path for a host cut action. */
74
- export declare const deleteSelectionAsSuggestion: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
75
- /**
76
- * Create the suggestion mode plugin.
77
- * When active, text edits become tracked changes.
78
- */
79
- export declare function createSuggestionModePlugin(initialActive?: boolean, author?: string): Plugin;
80
- /**
81
- * Toggle suggestion mode on/off.
82
- */
83
- export declare function toggleSuggestionMode(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
84
- /**
85
- * Set suggestion mode active state and author.
86
- */
87
- export declare function setSuggestionMode(active: boolean, state: EditorState, dispatch?: (tr: Transaction) => void, author?: string): boolean;
88
- /**
89
- * Check if suggestion mode is currently active.
90
- */
91
- export declare function isSuggestionModeActive(state: EditorState): boolean;
92
- export {};