@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.
- package/README.md +12 -6
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +215 -1639
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/pendingJoin.js +6 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +9 -4
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +2 -2
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +5 -27
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +282 -75
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +106 -33
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +186 -50
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalComposition.js +1 -1
- package/dist/controller/canonicalInput.js +1 -1
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorApi.js +2 -17
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +79 -23
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +1 -278
- package/dist/docx/canonicalSave.d.ts +1 -1
- package/dist/docx/canonicalSave.js +1 -1
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +31 -8
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.d.ts +1 -1
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +4 -36
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +658 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +230 -0
- package/dist/docx/server/templatePlan/labels.d.ts +45 -0
- package/dist/docx/server/templatePlan/labels.js +155 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +145 -0
- package/dist/docx/server/templatePlan/plan.js +875 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +180 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +442 -0
- package/dist/docx/server/templatePlan/types.js +29 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +976 -0
- package/dist/docx/server/templatePlan/xml.d.ts +74 -0
- package/dist/docx/server/templatePlan/xml.js +125 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +3 -3
- package/dist/prosemirror/commands/comments.js +4 -4
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/index.js +3 -3
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +17 -2
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +13 -92
- package/dist/types/canonicalCapabilities.js +11 -85
- package/package.json +4 -4
- package/dist/ai-edits/apply.d.ts +0 -202
- package/dist/ai-edits/apply.js +0 -6759
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -1,566 +0,0 @@
|
|
|
1
|
-
import { withTrackedSectionEndpointRemoval } from "../../../internal/sectionEndpointResolution.js";
|
|
2
|
-
import { canonicalJson } from "../../../utils/canonicalJson.js";
|
|
3
|
-
import { enclosingParagraphIndexed, nodeAtIndexed, nodesBetweenIndexed } from "../../indexedNodeLookup.js";
|
|
4
|
-
import { createPluginKeyOwner } from "../../pluginKeyOwner.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 paragraphChangeTrackerKey = createPluginKeyOwner("paragraphChangeTracker");
|
|
22
|
-
const CLEAR_META = "clear";
|
|
23
|
-
const IGNORE_META = "ignore";
|
|
24
|
-
const STRUCTURAL_META = "structural";
|
|
25
|
-
const CHANGED_PARAGRAPH_RANGES_META = "folioChangedParagraphRanges";
|
|
26
|
-
const SECTION_ENDPOINT_REMOVAL_META = "folioSectionEndpointRemoval";
|
|
27
|
-
const SECTION_EDIT_META = "folioSectionEdit";
|
|
28
|
-
const isChangedParagraphRangesMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "changed-paragraph-ranges";
|
|
29
|
-
const isRemovedSectionReference = (value) => typeof value === "object" && value !== null && "part" in value && (value.part === "header" || value.part === "footer") && "type" in value && (value.type === "default" || value.type === "first" || value.type === "even") && "relationshipId" in value && typeof value.relationshipId === "string";
|
|
30
|
-
const isTrackedSectionEndpointRemoval = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "tracked-section-endpoint-removal" && "sourceParagraphEndpointCount" in value && typeof value.sourceParagraphEndpointCount === "number" && Number.isSafeInteger(value.sourceParagraphEndpointCount) && "expectedParagraphEndpointCount" in value && typeof value.expectedParagraphEndpointCount === "number" && Number.isSafeInteger(value.expectedParagraphEndpointCount) && value.sourceParagraphEndpointCount > value.expectedParagraphEndpointCount && value.expectedParagraphEndpointCount >= 0 && "sourceEndpointFingerprint" in value && typeof value.sourceEndpointFingerprint === "string" && "expectedEndpointFingerprint" in value && typeof value.expectedEndpointFingerprint === "string" && "removedReferences" in value && Array.isArray(value.removedReferences) && value.removedReferences.every(isRemovedSectionReference);
|
|
31
|
-
const isTrackedSectionEndpointRemovalMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "tracked-section-endpoint-removal-meta" && "authorization" in value && isTrackedSectionEndpointRemoval(value.authorization);
|
|
32
|
-
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";
|
|
33
|
-
const blockStructures = /* @__PURE__ */ new WeakMap();
|
|
34
|
-
const relativePath = (parentPath, index) => parentPath.length === 0 ? `${index}` : `${parentPath}.${index}`;
|
|
35
|
-
const blockStructureOf = (block) => {
|
|
36
|
-
const cached = blockStructures.get(block);
|
|
37
|
-
if (cached) return cached;
|
|
38
|
-
const records = [];
|
|
39
|
-
const endpoints = [];
|
|
40
|
-
let paragraphs = 0;
|
|
41
|
-
const visit = (node, path) => {
|
|
42
|
-
records.push(node.type.name === "paragraph" ? [
|
|
43
|
-
path,
|
|
44
|
-
node.type.name,
|
|
45
|
-
node.attrs["paraId"] ?? null
|
|
46
|
-
] : [
|
|
47
|
-
path,
|
|
48
|
-
node.type.name,
|
|
49
|
-
canonicalJson(node.attrs)
|
|
50
|
-
]);
|
|
51
|
-
if (node.type.name === "paragraph") {
|
|
52
|
-
paragraphs++;
|
|
53
|
-
const sectionProperties = sectionPropertiesOf(node);
|
|
54
|
-
if (sectionProperties !== null) endpoints.push({
|
|
55
|
-
path,
|
|
56
|
-
paraId: node.attrs["paraId"] ?? null,
|
|
57
|
-
sectionProperties
|
|
58
|
-
});
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
node.forEach((child, _offset, index) => visit(child, relativePath(path, index)));
|
|
62
|
-
};
|
|
63
|
-
visit(block, "");
|
|
64
|
-
const structure = {
|
|
65
|
-
records: JSON.stringify(records),
|
|
66
|
-
paragraphs,
|
|
67
|
-
endpoints
|
|
68
|
-
};
|
|
69
|
-
blockStructures.set(block, structure);
|
|
70
|
-
return structure;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Count the structural values the tracker compares for every transaction.
|
|
74
|
-
*
|
|
75
|
-
* Each top-level block's records are kept for the block node, so a keystroke
|
|
76
|
-
* recomputes only the block it changed. The fingerprint joins the blocks'
|
|
77
|
-
* records in order: two documents' fingerprints are equal exactly when their
|
|
78
|
-
* full record lists (every block and nested block with its path) are.
|
|
79
|
-
*/
|
|
80
|
-
function countDocumentStructure(doc) {
|
|
81
|
-
let paragraphs = 0;
|
|
82
|
-
const sectionRecords = /* @__PURE__ */ new Set();
|
|
83
|
-
const blockRecords = [];
|
|
84
|
-
const endpointRecords = [];
|
|
85
|
-
doc.forEach((block, _offset, index) => {
|
|
86
|
-
const structure = blockStructureOf(block);
|
|
87
|
-
blockRecords.push(structure.records);
|
|
88
|
-
paragraphs += structure.paragraphs;
|
|
89
|
-
for (const endpoint of structure.endpoints) {
|
|
90
|
-
sectionRecords.add(endpoint.sectionProperties);
|
|
91
|
-
endpointRecords.push({
|
|
92
|
-
...endpoint,
|
|
93
|
-
path: endpoint.path.length === 0 ? `${index}` : `${index}.${endpoint.path}`
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return {
|
|
98
|
-
blockStructureFingerprint: blockRecords.join(""),
|
|
99
|
-
sectionRecords,
|
|
100
|
-
paragraphs,
|
|
101
|
-
sectionEndpoints: sectionRecords.size,
|
|
102
|
-
sectionEndpointFingerprint: canonicalJson(endpointRecords)
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Whether a transaction left every section record in place, by identity: the
|
|
107
|
-
* same sections, however their paragraphs moved around them. An edit before a
|
|
108
|
-
* section break (a paragraph inserted, a split, a paraId allocated) moves the
|
|
109
|
-
* endpoint without changing which sections the package states, so a removal
|
|
110
|
-
* authorized earlier still describes the saved section count exactly. A record
|
|
111
|
-
* edited, added or dropped is a new transition the authorization never saw.
|
|
112
|
-
*/
|
|
113
|
-
const holdsTheSameSections = (previous, next) => previous.sectionRecords.size === next.sectionRecords.size && [...next.sectionRecords].every((record) => previous.sectionRecords.has(record));
|
|
114
|
-
const isUsableParaId = (value) => typeof value === "string" && value.length > 0 && value !== "00000000";
|
|
115
|
-
/**
|
|
116
|
-
* Collect paraIds of all paragraphs that overlap with the given range
|
|
117
|
-
*/
|
|
118
|
-
function collectAffectedParaIds(doc, from, to) {
|
|
119
|
-
const ids = /* @__PURE__ */ new Set();
|
|
120
|
-
const positions = /* @__PURE__ */ new Set();
|
|
121
|
-
let hasUntracked = false;
|
|
122
|
-
const start = Math.max(0, Math.min(from, doc.content.size));
|
|
123
|
-
const end = Math.max(start, Math.min(to, doc.content.size));
|
|
124
|
-
nodesBetweenIndexed(doc, start, end, (node, pos) => {
|
|
125
|
-
if (node.type.name === "paragraph") {
|
|
126
|
-
positions.add(pos);
|
|
127
|
-
const paraId = node.attrs["paraId"];
|
|
128
|
-
if (isUsableParaId(paraId)) ids.add(paraId);
|
|
129
|
-
else hasUntracked = true;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return {
|
|
133
|
-
ids,
|
|
134
|
-
positions,
|
|
135
|
-
hasUntracked
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* AddMarkStep / RemoveMarkStep inherit Step.getMap() → StepMap.empty, so we use
|
|
140
|
-
* their from/to to find affected paragraphs.
|
|
141
|
-
* Node mark steps use a single position before the target node.
|
|
142
|
-
*/
|
|
143
|
-
function collectAffectedParaIdsFromMarkLikeStep(doc, from, to) {
|
|
144
|
-
const lo = Math.min(from, to);
|
|
145
|
-
const hi = Math.max(from, to);
|
|
146
|
-
const primary = collectAffectedParaIds(doc, lo, hi > lo ? hi : lo + 1);
|
|
147
|
-
if (primary.ids.size > 0 || primary.hasUntracked) return primary;
|
|
148
|
-
const paragraph = enclosingParagraphIndexed(doc, lo);
|
|
149
|
-
if (paragraph) {
|
|
150
|
-
const paraId = paragraph.node.attrs["paraId"];
|
|
151
|
-
return {
|
|
152
|
-
ids: new Set(isUsableParaId(paraId) ? [paraId] : []),
|
|
153
|
-
positions: /* @__PURE__ */ new Set([paragraph.pos]),
|
|
154
|
-
hasUntracked: !isUsableParaId(paraId)
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
ids: /* @__PURE__ */ new Set(),
|
|
159
|
-
positions: /* @__PURE__ */ new Set(),
|
|
160
|
-
hasUntracked: false
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Map edited paragraphs' interiors so markup replacement retains their
|
|
165
|
-
* ownership: each position's paragraph in `tr.doc`, or null once deleted. The
|
|
166
|
-
* positions go through the transaction together (see `sweepPositions`).
|
|
167
|
-
*/
|
|
168
|
-
const mapParagraphPositions = (tr, positions) => sweepPositions([tr.mapping], positions.map((position) => ({
|
|
169
|
-
pos: position + 1,
|
|
170
|
-
assoc: 1,
|
|
171
|
-
from: 0
|
|
172
|
-
}))).map((mapped) => mapped.deletedAcross ? null : enclosingParagraphIndexed(tr.doc, mapped.pos)?.pos ?? null);
|
|
173
|
-
const mapAffectedParagraphPositions = (tr, positions) => {
|
|
174
|
-
const mappedPositions = /* @__PURE__ */ new Set();
|
|
175
|
-
for (const mapped of mapParagraphPositions(tr, [...positions])) if (mapped !== null) mappedPositions.add(mapped);
|
|
176
|
-
return mappedPositions;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Every position the step loop reads, each entering the sweep at the step
|
|
180
|
-
* after the one that produced it: the transaction is mapped once rather than
|
|
181
|
-
* sliced and walked again for every step.
|
|
182
|
-
*/
|
|
183
|
-
const mapStepTouches = (tr, batches) => {
|
|
184
|
-
const queries = [];
|
|
185
|
-
const touches = [];
|
|
186
|
-
const addRange = (kind, from, to, at) => {
|
|
187
|
-
touches.push({
|
|
188
|
-
kind,
|
|
189
|
-
query: queries.length
|
|
190
|
-
});
|
|
191
|
-
queries.push({
|
|
192
|
-
pos: from,
|
|
193
|
-
assoc: 1,
|
|
194
|
-
from: at
|
|
195
|
-
}, {
|
|
196
|
-
pos: to,
|
|
197
|
-
assoc: -1,
|
|
198
|
-
from: at
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
const replacedStepMaps = /* @__PURE__ */ new Set();
|
|
202
|
-
for (const batch of batches) {
|
|
203
|
-
if (batch.replacesStepMapAt !== void 0) replacedStepMaps.add(batch.replacesStepMapAt);
|
|
204
|
-
for (const range of batch.ranges) addRange("mark-range", range.from, range.to, batch.mappingFrom);
|
|
205
|
-
}
|
|
206
|
-
for (let stepIndex = 0; stepIndex < tr.steps.length; stepIndex++) {
|
|
207
|
-
if (replacedStepMaps.has(stepIndex)) continue;
|
|
208
|
-
const step = tr.steps[stepIndex];
|
|
209
|
-
const at = stepIndex + 1;
|
|
210
|
-
if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
|
|
211
|
-
addRange("mark-range", step.from, step.to, at);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
if (step instanceof AddNodeMarkStep || step instanceof RemoveNodeMarkStep || step instanceof AttrStep) {
|
|
215
|
-
touches.push({
|
|
216
|
-
kind: "node",
|
|
217
|
-
query: queries.length
|
|
218
|
-
});
|
|
219
|
-
queries.push({
|
|
220
|
-
pos: step.pos,
|
|
221
|
-
assoc: 1,
|
|
222
|
-
from: at
|
|
223
|
-
});
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
step.getMap().forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
227
|
-
addRange("replaced-range", newStart, newEnd, at);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
touches,
|
|
232
|
-
mapped: sweepPositions([tr.mapping], queries)
|
|
233
|
-
};
|
|
234
|
-
};
|
|
235
|
-
function createParagraphChangeTrackerPlugin() {
|
|
236
|
-
return new Plugin({
|
|
237
|
-
key: paragraphChangeTrackerKey.createKey(),
|
|
238
|
-
state: {
|
|
239
|
-
init(_config, state) {
|
|
240
|
-
const counts = countDocumentStructure(state.doc);
|
|
241
|
-
return {
|
|
242
|
-
affectedParagraphPositions: /* @__PURE__ */ new Set(),
|
|
243
|
-
hasUntrackedSourceChanges: false,
|
|
244
|
-
blockStructureFingerprint: counts.blockStructureFingerprint,
|
|
245
|
-
changedParaIds: /* @__PURE__ */ new Set(),
|
|
246
|
-
structuralChange: false,
|
|
247
|
-
hasUntrackedChanges: false,
|
|
248
|
-
paragraphCount: counts.paragraphs,
|
|
249
|
-
sectionEndpointCount: counts.sectionEndpoints,
|
|
250
|
-
sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
|
|
251
|
-
sectionRecords: counts.sectionRecords,
|
|
252
|
-
sectionEndpointRemoval: null
|
|
253
|
-
};
|
|
254
|
-
},
|
|
255
|
-
apply(tr, prevState) {
|
|
256
|
-
const meta = tr.getMeta(paragraphChangeTrackerKey);
|
|
257
|
-
const changedParagraphRangesMeta = tr.getMeta(CHANGED_PARAGRAPH_RANGES_META);
|
|
258
|
-
const sectionEndpointRemovalMeta = tr.getMeta(SECTION_ENDPOINT_REMOVAL_META);
|
|
259
|
-
const sectionEditMeta = tr.getMeta(SECTION_EDIT_META);
|
|
260
|
-
if (meta === CLEAR_META) {
|
|
261
|
-
const counts = countDocumentStructure(tr.doc);
|
|
262
|
-
return {
|
|
263
|
-
affectedParagraphPositions: /* @__PURE__ */ new Set(),
|
|
264
|
-
hasUntrackedSourceChanges: false,
|
|
265
|
-
blockStructureFingerprint: counts.blockStructureFingerprint,
|
|
266
|
-
changedParaIds: /* @__PURE__ */ new Set(),
|
|
267
|
-
structuralChange: false,
|
|
268
|
-
hasUntrackedChanges: false,
|
|
269
|
-
paragraphCount: counts.paragraphs,
|
|
270
|
-
sectionEndpointCount: counts.sectionEndpoints,
|
|
271
|
-
sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
|
|
272
|
-
sectionRecords: counts.sectionRecords,
|
|
273
|
-
sectionEndpointRemoval: null
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
if (meta === IGNORE_META) {
|
|
277
|
-
if (!tr.docChanged) return prevState;
|
|
278
|
-
const counts = countDocumentStructure(tr.doc);
|
|
279
|
-
const affectedParagraphPositions = mapAffectedParagraphPositions(tr, prevState.affectedParagraphPositions);
|
|
280
|
-
const changedParaIds = /* @__PURE__ */ new Set();
|
|
281
|
-
let unresolvedChanges = prevState.hasUntrackedSourceChanges;
|
|
282
|
-
for (const position of affectedParagraphPositions) {
|
|
283
|
-
const paraId = nodeAtIndexed(tr.doc, position)?.attrs["paraId"];
|
|
284
|
-
if (isUsableParaId(paraId)) changedParaIds.add(paraId);
|
|
285
|
-
else unresolvedChanges = true;
|
|
286
|
-
}
|
|
287
|
-
return {
|
|
288
|
-
...prevState,
|
|
289
|
-
affectedParagraphPositions,
|
|
290
|
-
changedParaIds,
|
|
291
|
-
hasUntrackedChanges: unresolvedChanges,
|
|
292
|
-
blockStructureFingerprint: counts.blockStructureFingerprint,
|
|
293
|
-
paragraphCount: counts.paragraphs,
|
|
294
|
-
sectionEndpointCount: counts.sectionEndpoints,
|
|
295
|
-
sectionEndpointRemoval: holdsTheSameSections(prevState, counts) ? prevState.sectionEndpointRemoval : null,
|
|
296
|
-
sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
|
|
297
|
-
sectionRecords: counts.sectionRecords
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
if (!tr.docChanged) return isSectionEditMeta(sectionEditMeta) && sectionEditMeta.expectedEndpointFingerprint === prevState.sectionEndpointFingerprint ? {
|
|
301
|
-
...prevState,
|
|
302
|
-
sectionEndpointRemoval: sectionEditMeta.authorization
|
|
303
|
-
} : prevState;
|
|
304
|
-
const counts = countDocumentStructure(tr.doc);
|
|
305
|
-
const newCount = counts.paragraphs;
|
|
306
|
-
let sectionEndpointRemoval = prevState.sectionEndpointRemoval;
|
|
307
|
-
if (counts.sectionEndpointFingerprint !== prevState.sectionEndpointFingerprint) {
|
|
308
|
-
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) {
|
|
309
|
-
const authorization = sectionEndpointRemovalMeta.authorization;
|
|
310
|
-
sectionEndpointRemoval = {
|
|
311
|
-
type: "tracked-section-endpoint-removal",
|
|
312
|
-
sourceParagraphEndpointCount: prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.sourceParagraphEndpointCount : authorization.sourceParagraphEndpointCount,
|
|
313
|
-
expectedParagraphEndpointCount: authorization.expectedParagraphEndpointCount,
|
|
314
|
-
sourceEndpointFingerprint: prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.sourceEndpointFingerprint : authorization.sourceEndpointFingerprint,
|
|
315
|
-
expectedEndpointFingerprint: authorization.expectedEndpointFingerprint,
|
|
316
|
-
removedReferences: [...prevState.sectionEndpointRemoval?.expectedParagraphEndpointCount === authorization.sourceParagraphEndpointCount ? prevState.sectionEndpointRemoval.removedReferences : [], ...authorization.removedReferences]
|
|
317
|
-
};
|
|
318
|
-
} else if (!holdsTheSameSections(prevState, counts)) sectionEndpointRemoval = null;
|
|
319
|
-
}
|
|
320
|
-
if (isSectionEditMeta(sectionEditMeta) && sectionEditMeta.expectedEndpointFingerprint === counts.sectionEndpointFingerprint) sectionEndpointRemoval = sectionEditMeta.authorization;
|
|
321
|
-
const newState = {
|
|
322
|
-
affectedParagraphPositions: mapAffectedParagraphPositions(tr, prevState.affectedParagraphPositions),
|
|
323
|
-
hasUntrackedSourceChanges: prevState.hasUntrackedSourceChanges,
|
|
324
|
-
blockStructureFingerprint: counts.blockStructureFingerprint,
|
|
325
|
-
changedParaIds: new Set(prevState.changedParaIds),
|
|
326
|
-
structuralChange: prevState.structuralChange || meta === STRUCTURAL_META,
|
|
327
|
-
hasUntrackedChanges: prevState.hasUntrackedChanges,
|
|
328
|
-
paragraphCount: newCount,
|
|
329
|
-
sectionEndpointCount: counts.sectionEndpoints,
|
|
330
|
-
sectionEndpointFingerprint: counts.sectionEndpointFingerprint,
|
|
331
|
-
sectionRecords: counts.sectionRecords,
|
|
332
|
-
sectionEndpointRemoval
|
|
333
|
-
};
|
|
334
|
-
const recordAffected = ({ ids, positions, hasUntracked }) => {
|
|
335
|
-
for (const position of positions) newState.affectedParagraphPositions.add(position);
|
|
336
|
-
for (const id of ids) newState.changedParaIds.add(id);
|
|
337
|
-
if (hasUntracked) newState.hasUntrackedChanges = true;
|
|
338
|
-
};
|
|
339
|
-
const { touches, mapped } = mapStepTouches(tr, isChangedParagraphRangesMeta(changedParagraphRangesMeta) ? changedParagraphRangesMeta.batches : []);
|
|
340
|
-
for (const touch of touches) {
|
|
341
|
-
const from = mapped[touch.query].pos;
|
|
342
|
-
if (touch.kind === "node") {
|
|
343
|
-
if (mapped[touch.query].deletedAcross) continue;
|
|
344
|
-
const node = nodeAtIndexed(tr.doc, from);
|
|
345
|
-
if (node) recordAffected(collectAffectedParaIds(tr.doc, from, from + node.nodeSize));
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
const to = mapped[touch.query + 1].pos;
|
|
349
|
-
if (touch.kind === "mark-range") {
|
|
350
|
-
if (to > from) recordAffected(collectAffectedParaIdsFromMarkLikeStep(tr.doc, from, to));
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (to >= from) recordAffected(collectAffectedParaIds(tr.doc, from, to));
|
|
354
|
-
}
|
|
355
|
-
if (prevState.blockStructureFingerprint !== counts.blockStructureFingerprint) newState.structuralChange = true;
|
|
356
|
-
if (newState.hasUntrackedChanges || prevState.blockStructureFingerprint !== counts.blockStructureFingerprint) {
|
|
357
|
-
const unidentified = [];
|
|
358
|
-
tr.before.descendants((node, position) => {
|
|
359
|
-
if (node.type.name !== "paragraph") return true;
|
|
360
|
-
if (!isUsableParaId(node.attrs["paraId"])) unidentified.push(position);
|
|
361
|
-
return false;
|
|
362
|
-
});
|
|
363
|
-
for (const survivor of mapParagraphPositions(tr, unidentified)) if (survivor === null || newState.affectedParagraphPositions.has(survivor)) {
|
|
364
|
-
newState.hasUntrackedSourceChanges = true;
|
|
365
|
-
newState.hasUntrackedChanges = true;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return newState;
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
appendTransaction: (transactions, oldState, newState) => sectionEditTransaction(transactions, oldState, newState)
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
const referencesOf = (records) => {
|
|
375
|
-
const references = [];
|
|
376
|
-
for (const record of records) {
|
|
377
|
-
for (const { type, rId } of record.headerReferences ?? []) references.push({
|
|
378
|
-
part: "header",
|
|
379
|
-
type,
|
|
380
|
-
relationshipId: rId
|
|
381
|
-
});
|
|
382
|
-
for (const { type, rId } of record.footerReferences ?? []) references.push({
|
|
383
|
-
part: "footer",
|
|
384
|
-
type,
|
|
385
|
-
relationshipId: rId
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
return references;
|
|
389
|
-
};
|
|
390
|
-
/** `references` without one occurrence of each of `restored`. */
|
|
391
|
-
const withoutReferences = (references, restored) => {
|
|
392
|
-
const remaining = [...references];
|
|
393
|
-
for (const reference of restored) {
|
|
394
|
-
const index = remaining.findIndex((candidate) => candidate.part === reference.part && candidate.type === reference.type && candidate.relationshipId === reference.relationshipId);
|
|
395
|
-
if (index !== -1) remaining.splice(index, 1);
|
|
396
|
-
}
|
|
397
|
-
return remaining;
|
|
398
|
-
};
|
|
399
|
-
/**
|
|
400
|
-
* Carry section breaks through an ordinary edit, and record the ones it
|
|
401
|
-
* deleted.
|
|
402
|
-
*
|
|
403
|
-
* Deleting the mark of a section-ending paragraph (Backspace or Delete across
|
|
404
|
-
* it, a selection, a cut or a paste over it, a join) deletes the break, and
|
|
405
|
-
* the section's content joins the following section: the same outcome as
|
|
406
|
-
* deleting the paragraph as a block, or accepting its tracked deletion. The
|
|
407
|
-
* appended transaction moves each joined paragraph's record to the one its
|
|
408
|
-
* surviving mark carries (see `sectionMarkEditsOf`) and states the removal
|
|
409
|
-
* the save is to accept.
|
|
410
|
-
*
|
|
411
|
-
* Only a record whose mark a replacement deleted counts as removed on
|
|
412
|
-
* purpose. A record that goes any other way (an attribute cleared, a record
|
|
413
|
-
* swapped for another) leaves the edit unauthorized, and the save refuses the
|
|
414
|
-
* smaller package as it always did. Records coming back (an undo) take their
|
|
415
|
-
* removal back out of the authorization.
|
|
416
|
-
*/
|
|
417
|
-
const sectionEditTransaction = (transactions, oldState, newState) => {
|
|
418
|
-
if (!transactions.some((transaction) => transaction.docChanged && transaction.getMeta(paragraphChangeTrackerKey) !== IGNORE_META) || transactions.some((transaction) => transaction.getMeta(SECTION_EDIT_META) !== void 0 || transaction.getMeta(SECTION_ENDPOINT_REMOVAL_META) !== void 0 || transaction.getMeta(paragraphChangeTrackerKey) === CLEAR_META)) return null;
|
|
419
|
-
const base = paragraphChangeTrackerKey.getState(oldState);
|
|
420
|
-
if (!base) return null;
|
|
421
|
-
const dropped = droppedCellSections(transactions, oldState.doc, newState.doc);
|
|
422
|
-
if (base.sectionRecords.size === 0 && dropped.length === 0) return null;
|
|
423
|
-
const edits = sectionMarkEditsOf(transactions, newState.doc);
|
|
424
|
-
const tr = newState.tr;
|
|
425
|
-
const restoring = transactions.some((transaction) => isHistoryTransaction(transaction));
|
|
426
|
-
for (const { position, record } of restoring ? [] : edits.carriers) {
|
|
427
|
-
const paragraph = tr.doc.nodeAt(position);
|
|
428
|
-
if (paragraph?.type.name === "paragraph" && sectionPropertiesOf(paragraph) !== record) tr.setNodeAttribute(position, "_sectionProperties", record);
|
|
429
|
-
}
|
|
430
|
-
for (const position of dropped) tr.setNodeAttribute(position, "_sectionProperties", null);
|
|
431
|
-
const after = countDocumentStructure(tr.doc);
|
|
432
|
-
if (holdsTheSameSections(base, after)) return tr.docChanged ? tr.setMeta(SECTION_EDIT_META, {
|
|
433
|
-
type: "section-edit-meta",
|
|
434
|
-
authorization: base.sectionEndpointRemoval,
|
|
435
|
-
expectedEndpointFingerprint: after.sectionEndpointFingerprint
|
|
436
|
-
}) : null;
|
|
437
|
-
const removed = [...base.sectionRecords].filter((record) => !after.sectionRecords.has(record));
|
|
438
|
-
const added = [...after.sectionRecords].filter((record) => !base.sectionRecords.has(record));
|
|
439
|
-
if (removed.some((record) => !edits.deletedMarks.has(record))) return tr.docChanged ? tr : null;
|
|
440
|
-
const prior = base.sectionEndpointRemoval;
|
|
441
|
-
const sourceParagraphEndpointCount = prior?.sourceParagraphEndpointCount ?? base.sectionEndpointCount;
|
|
442
|
-
const authorization = after.sectionEndpoints < sourceParagraphEndpointCount ? {
|
|
443
|
-
type: "tracked-section-endpoint-removal",
|
|
444
|
-
sourceParagraphEndpointCount,
|
|
445
|
-
expectedParagraphEndpointCount: after.sectionEndpoints,
|
|
446
|
-
sourceEndpointFingerprint: prior?.sourceEndpointFingerprint ?? base.sectionEndpointFingerprint,
|
|
447
|
-
expectedEndpointFingerprint: after.sectionEndpointFingerprint,
|
|
448
|
-
removedReferences: withoutReferences([...prior?.removedReferences ?? [], ...referencesOf(removed)], referencesOf(added))
|
|
449
|
-
} : null;
|
|
450
|
-
return tr.setMeta(SECTION_EDIT_META, {
|
|
451
|
-
type: "section-edit-meta",
|
|
452
|
-
authorization,
|
|
453
|
-
expectedEndpointFingerprint: after.sectionEndpointFingerprint
|
|
454
|
-
});
|
|
455
|
-
};
|
|
456
|
-
/**
|
|
457
|
-
* Get the change tracker state from an EditorState
|
|
458
|
-
*/
|
|
459
|
-
function getChangeTrackerState(state) {
|
|
460
|
-
return paragraphChangeTrackerKey.getState(state);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Get the set of changed paragraph IDs from an EditorState
|
|
464
|
-
*/
|
|
465
|
-
function getChangedParagraphIds(state) {
|
|
466
|
-
return getChangeTrackerState(state)?.changedParaIds ?? /* @__PURE__ */ new Set();
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Check if paragraph membership, order, or block structure changed
|
|
470
|
-
*/
|
|
471
|
-
function hasStructuralChanges(state) {
|
|
472
|
-
return getChangeTrackerState(state)?.structuralChange ?? false;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Check if any changes affected paragraphs without paraId
|
|
476
|
-
*/
|
|
477
|
-
function hasUntrackedChanges(state) {
|
|
478
|
-
return getChangeTrackerState(state)?.hasUntrackedChanges ?? false;
|
|
479
|
-
}
|
|
480
|
-
/** Exact section-count transition authorized by tracked paragraph-mark resolution. */
|
|
481
|
-
function getTrackedSectionEndpointRemoval(state) {
|
|
482
|
-
return getChangeTrackerState(state)?.sectionEndpointRemoval ?? null;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Run an editor save's full repack with the section removals the editor's own
|
|
486
|
-
* edits made.
|
|
487
|
-
*
|
|
488
|
-
* A save refuses a package with fewer sections than its source unless it is
|
|
489
|
-
* told which removals were meant: deleting the paragraph that ends a section,
|
|
490
|
-
* or accepting its tracked deletion, removes that section on purpose. The
|
|
491
|
-
* tracker records exactly those removals; without them the repack throws and
|
|
492
|
-
* the edit cannot be saved.
|
|
493
|
-
*/
|
|
494
|
-
const repackWithEditorSectionRemovals = ({ state, document, repack }) => {
|
|
495
|
-
const resolution = getTrackedSectionEndpointRemoval(state);
|
|
496
|
-
return resolution === null ? repack() : withTrackedSectionEndpointRemoval({
|
|
497
|
-
document,
|
|
498
|
-
resolution,
|
|
499
|
-
repack
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
/** Record only a complete, internally consistent endpoint-removal transition. */
|
|
503
|
-
function markTrackedSectionEndpointRemoval(tr, { sourceDoc, removedEndpointCount, removedReferences }) {
|
|
504
|
-
const sourceStructure = countDocumentStructure(sourceDoc);
|
|
505
|
-
const sourceParagraphEndpointCount = sourceStructure.sectionEndpoints;
|
|
506
|
-
const expectedStructure = countDocumentStructure(tr.doc);
|
|
507
|
-
const expectedParagraphEndpointCount = expectedStructure.sectionEndpoints;
|
|
508
|
-
if (sourceParagraphEndpointCount - expectedParagraphEndpointCount !== removedEndpointCount) return tr;
|
|
509
|
-
return tr.setMeta(SECTION_ENDPOINT_REMOVAL_META, {
|
|
510
|
-
type: "tracked-section-endpoint-removal-meta",
|
|
511
|
-
authorization: {
|
|
512
|
-
type: "tracked-section-endpoint-removal",
|
|
513
|
-
sourceParagraphEndpointCount,
|
|
514
|
-
expectedParagraphEndpointCount,
|
|
515
|
-
sourceEndpointFingerprint: sourceStructure.sectionEndpointFingerprint,
|
|
516
|
-
expectedEndpointFingerprint: expectedStructure.sectionEndpointFingerprint,
|
|
517
|
-
removedReferences
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Record that `tr` removed section breaks on purpose: a command whose job is
|
|
523
|
-
* to remove the break (not to delete its paragraph mark, which the tracker
|
|
524
|
-
* reads for itself). Only a plain removal is recorded; a transaction that also
|
|
525
|
-
* adds or replaces a record is left as it is.
|
|
526
|
-
*/
|
|
527
|
-
function markSectionBreakRemoval(tr, sourceDoc) {
|
|
528
|
-
const before = countDocumentStructure(sourceDoc).sectionRecords;
|
|
529
|
-
const after = countDocumentStructure(tr.doc).sectionRecords;
|
|
530
|
-
const removed = [...before].filter((record) => !after.has(record));
|
|
531
|
-
if (removed.length === 0 || [...after].some((record) => !before.has(record))) return tr;
|
|
532
|
-
return markTrackedSectionEndpointRemoval(tr, {
|
|
533
|
-
sourceDoc,
|
|
534
|
-
removedEndpointCount: removed.length,
|
|
535
|
-
removedReferences: referencesOf(removed)
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Create a transaction that clears the change tracker
|
|
540
|
-
*/
|
|
541
|
-
function clearTrackedChanges(state) {
|
|
542
|
-
return state.tr.setMeta(paragraphChangeTrackerKey, CLEAR_META);
|
|
543
|
-
}
|
|
544
|
-
function ignoreTrackedChanges(tr) {
|
|
545
|
-
return tr.setMeta(paragraphChangeTrackerKey, IGNORE_META);
|
|
546
|
-
}
|
|
547
|
-
function markStructuralChange(tr) {
|
|
548
|
-
return tr.setMeta(paragraphChangeTrackerKey, STRUCTURAL_META);
|
|
549
|
-
}
|
|
550
|
-
/** Record mark-only paragraph changes whose replacement step has a granular map. */
|
|
551
|
-
function markChangedParagraphRanges(tr, batch) {
|
|
552
|
-
const previous = tr.getMeta(CHANGED_PARAGRAPH_RANGES_META);
|
|
553
|
-
const batches = isChangedParagraphRangesMeta(previous) ? [...previous.batches, batch] : [batch];
|
|
554
|
-
return tr.setMeta(CHANGED_PARAGRAPH_RANGES_META, {
|
|
555
|
-
type: "changed-paragraph-ranges",
|
|
556
|
-
batches
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
const ParagraphChangeTrackerExtension = createExtension({
|
|
560
|
-
name: "paragraphChangeTracker",
|
|
561
|
-
defaultOptions: {},
|
|
562
|
-
onSchemaReady() {
|
|
563
|
-
return { plugins: [createParagraphChangeTrackerPlugin()] };
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
export { ParagraphChangeTrackerExtension, clearTrackedChanges, countDocumentStructure, createParagraphChangeTrackerPlugin, getChangeTrackerState, getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges, ignoreTrackedChanges, markChangedParagraphRanges, markSectionBreakRemoval, markStructuralChange, markTrackedSectionEndpointRemoval, paragraphChangeTrackerKey, 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 { Slice } from "prosemirror-model";
|
|
14
|
-
import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
|
|
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 {};
|