@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,408 +0,0 @@
|
|
|
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";
|
|
3
|
-
import { deterministicHexId, generateHexId } from "../../../utils/hexId.js";
|
|
4
|
-
import { createPluginKeyOwner } from "../../pluginKeyOwner.js";
|
|
5
|
-
import { sweepPositions } from "../../positionSweep.js";
|
|
6
|
-
import { createExtension } from "../create.js";
|
|
7
|
-
import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
|
|
8
|
-
import { panic } from "better-result";
|
|
9
|
-
import { Fragment } from "prosemirror-model";
|
|
10
|
-
import { Plugin, Transaction } from "prosemirror-state";
|
|
11
|
-
// src/prosemirror/extensions/features/ParaIdAllocatorExtension.ts
|
|
12
|
-
/**
|
|
13
|
-
* ParaIdAllocator — assigns a stable `w14:paraId` to every paragraph.
|
|
14
|
-
*
|
|
15
|
-
* Lifted from
|
|
16
|
-
* https://github.com/eigenpal/docx-editor/blob/main/packages/core/src/prosemirror/extensions/features/ParaIdAllocatorExtension.ts
|
|
17
|
-
* (Apache-2.0). Adapted to folio's `createExtension` + import style;
|
|
18
|
-
* keep behaviour in sync upstream. folio divergences: duplicate
|
|
19
|
-
* resolution maps the original paragraph's position through the
|
|
20
|
-
* transaction (see below), and the appended allocation transaction is
|
|
21
|
-
* excluded from paragraph change tracking like `ensureParaIdsInState`.
|
|
22
|
-
*
|
|
23
|
-
* Why: AI tooling, chat citation chips, and the change tracker all
|
|
24
|
-
* anchor on `paraId`. A paragraph with `paraId: null` is invisible
|
|
25
|
-
* to those surfaces; a duplicated paraId (the second half of an
|
|
26
|
-
* Enter-split, or content pasted from another doc) silently desyncs
|
|
27
|
-
* their anchors. This plugin closes both gaps by allocating fresh
|
|
28
|
-
* ids in an `appendTransaction` hook after every doc-changed step.
|
|
29
|
-
*
|
|
30
|
-
* Id lifecycle rules (locked by the co-located tests):
|
|
31
|
-
* - Load: a missing/empty/reserved-zero or duplicate id gets one derived
|
|
32
|
-
* from the paragraph's text and ordinal (`ensureParaIdsInDoc`), the same
|
|
33
|
-
* id the headless reviewer derives for the same document.
|
|
34
|
-
* - Missing/empty/reserved-zero id after an edit: a fresh random id is minted.
|
|
35
|
-
* - Split: the half holding the paragraph's original start position
|
|
36
|
-
* keeps the id; the other half gets a fresh one. Anchors inside the
|
|
37
|
-
* content stay resolvable on the half that carries them.
|
|
38
|
-
* - Merge/join: the surviving paragraph keeps its id; the absorbed id
|
|
39
|
-
* dangles by design (consumers degrade to snapshot fallback).
|
|
40
|
-
* - Paste/duplicate carrying an id already in the doc: the paragraph
|
|
41
|
-
* whose mapped pre-transaction position matches keeps it — pasting a
|
|
42
|
-
* copy above its source no longer steals the source's id. When no
|
|
43
|
-
* occurrence maps back (e.g. both are new), the first in document
|
|
44
|
-
* order keeps it.
|
|
45
|
-
* - Paste of an id unknown to this doc (cross-doc paste, cut-then-
|
|
46
|
-
* paste move): the id is kept, so a moved paragraph stays anchored.
|
|
47
|
-
* - Undo/redo: allocation applies with `addToHistory: false`, and
|
|
48
|
-
* ProseMirror remaps it into the originating history event. Redoing a
|
|
49
|
-
* split therefore restores the same allocated id instead of minting
|
|
50
|
-
* another one.
|
|
51
|
-
*/
|
|
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
|
-
const deterministicSeedOf = (transaction) => {
|
|
67
|
-
const seed = transaction.getMeta(deterministicParaIdSeedKey);
|
|
68
|
-
if (typeof seed === "string") return seed;
|
|
69
|
-
const root = transaction.getMeta("appendedTransaction");
|
|
70
|
-
if (!(root instanceof Transaction)) return void 0;
|
|
71
|
-
const rootSeed = root.getMeta(deterministicParaIdSeedKey);
|
|
72
|
-
return typeof rootSeed === "string" ? rootSeed : void 0;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* A fresh id not already in `taken`: derived from `seed` and the paragraph's
|
|
76
|
-
* position when the caller asked for reproducibility, random otherwise. Both
|
|
77
|
-
* loops terminate — the id space is 2^31 wide and `taken` holds at most one
|
|
78
|
-
* entry per paragraph.
|
|
79
|
-
*/
|
|
80
|
-
const mintParaId = (taken, seed, pos) => {
|
|
81
|
-
if (seed === null) {
|
|
82
|
-
let id = generateHexId();
|
|
83
|
-
while (taken.has(id)) id = generateHexId();
|
|
84
|
-
return id;
|
|
85
|
-
}
|
|
86
|
-
let id = deterministicHexId(`${seed}:${String(pos)}`);
|
|
87
|
-
for (let salt = 1; taken.has(id); salt++) id = deterministicHexId(`${seed}:${String(pos)}:${String(salt)}`);
|
|
88
|
-
return id;
|
|
89
|
-
};
|
|
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
|
-
const collectParagraphPropertySourceSeed = (doc) => {
|
|
102
|
-
const contract = getProseDocumentParagraphPropertySourceContract(doc);
|
|
103
|
-
if (!contract) return {
|
|
104
|
-
contract: null,
|
|
105
|
-
tokens: /* @__PURE__ */ new Set()
|
|
106
|
-
};
|
|
107
|
-
const counts = /* @__PURE__ */ new Map();
|
|
108
|
-
visitAuthoredParagraphs(doc, (node) => {
|
|
109
|
-
const token = getProseParagraphPropertySourceToken(node);
|
|
110
|
-
if (paragraphPropertySourceTokenMatchesContract(token, contract)) counts.set(token, (counts.get(token) ?? 0) + 1);
|
|
111
|
-
});
|
|
112
|
-
return {
|
|
113
|
-
contract,
|
|
114
|
-
tokens: new Set([...counts].filter(([, count]) => count === 1).map(([token]) => token))
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Where each id's and each seeded source token's owner went: the first
|
|
119
|
-
* occurrence that survives the batch keeps an id.
|
|
120
|
-
*
|
|
121
|
-
* @internal Exported for the per-step equivalence test.
|
|
122
|
-
*/
|
|
123
|
-
const mapParagraphKeepers = (oldDoc, transactions, sourceSeed) => {
|
|
124
|
-
const paragraphs = [];
|
|
125
|
-
visitAuthoredParagraphs(oldDoc, (node, pos) => {
|
|
126
|
-
const id = node.attrs["paraId"];
|
|
127
|
-
const token = getProseParagraphPropertySourceToken(node);
|
|
128
|
-
if (isUsableParaId(id) || typeof token === "string" && sourceSeed.tokens.has(token)) paragraphs.push({
|
|
129
|
-
pos,
|
|
130
|
-
id,
|
|
131
|
-
token
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
const swept = sweepPositions(transactions.map((transaction) => transaction.mapping), paragraphs.flatMap(({ pos }) => [{
|
|
135
|
-
pos,
|
|
136
|
-
assoc: 1,
|
|
137
|
-
from: 0
|
|
138
|
-
}, {
|
|
139
|
-
pos: pos + 1,
|
|
140
|
-
assoc: -1,
|
|
141
|
-
from: 0
|
|
142
|
-
}]));
|
|
143
|
-
const paraIds = /* @__PURE__ */ new Map();
|
|
144
|
-
const sourceTokens = /* @__PURE__ */ new Map();
|
|
145
|
-
for (const [index, { id, token }] of paragraphs.entries()) {
|
|
146
|
-
const mapped = swept[2 * index].pos;
|
|
147
|
-
const deleted = swept[2 * index + 1].deletedAcross;
|
|
148
|
-
if (isUsableParaId(id) && !paraIds.has(id) && !deleted) paraIds.set(id, mapped);
|
|
149
|
-
if (typeof token === "string" && sourceSeed.tokens.has(token)) sourceTokens.set(token, sourceTokens.has(token) ? { status: "ambiguous" } : {
|
|
150
|
-
pos: mapped,
|
|
151
|
-
status: deleted ? "deleted" : "mapped"
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
paraIds,
|
|
156
|
-
sourceTokens
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
const collectParagraphCensus = (doc, sourceSeed) => {
|
|
160
|
-
const census = {
|
|
161
|
-
invalidSourceTokens: [],
|
|
162
|
-
missingParaIds: [],
|
|
163
|
-
paragraphs: /* @__PURE__ */ new Map(),
|
|
164
|
-
paraIds: /* @__PURE__ */ new Map(),
|
|
165
|
-
sourceTokens: /* @__PURE__ */ new Map()
|
|
166
|
-
};
|
|
167
|
-
const contractMatchesSeed = sourceSeed?.contract !== null && sourceSeed?.contract !== void 0 && getProseDocumentParagraphPropertySourceContract(doc) === sourceSeed.contract;
|
|
168
|
-
visitAuthoredParagraphs(doc, (node, pos) => {
|
|
169
|
-
const occurrence = {
|
|
170
|
-
pos,
|
|
171
|
-
attrs: node.attrs
|
|
172
|
-
};
|
|
173
|
-
census.paragraphs.set(pos, occurrence);
|
|
174
|
-
const id = node.attrs["paraId"];
|
|
175
|
-
if (isUsableParaId(id)) {
|
|
176
|
-
const occurrences = census.paraIds.get(id) ?? [];
|
|
177
|
-
occurrences.push(occurrence);
|
|
178
|
-
census.paraIds.set(id, occurrences);
|
|
179
|
-
} else census.missingParaIds.push(occurrence);
|
|
180
|
-
if (sourceSeed) {
|
|
181
|
-
const token = getProseParagraphPropertySourceToken(node);
|
|
182
|
-
if (token !== null && token !== void 0) {
|
|
183
|
-
if (typeof token !== "string" || !contractMatchesSeed || !sourceSeed.contract || !sourceSeed.tokens.has(token) || !paragraphPropertySourceTokenMatchesContract(token, sourceSeed.contract)) census.invalidSourceTokens.push(occurrence);
|
|
184
|
-
else {
|
|
185
|
-
const occurrences = census.sourceTokens.get(token) ?? [];
|
|
186
|
-
occurrences.push(occurrence);
|
|
187
|
-
census.sourceTokens.set(token, occurrences);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
return census;
|
|
193
|
-
};
|
|
194
|
-
const collectParaIdUpdatesFromCensus = (census, keeperPositions, deterministicSeed = null) => {
|
|
195
|
-
const needFreshId = [...census.missingParaIds];
|
|
196
|
-
for (const [id, occurrences] of census.paraIds) {
|
|
197
|
-
if (occurrences.length === 1) continue;
|
|
198
|
-
const keeperPos = keeperPositions?.get(id);
|
|
199
|
-
const keeper = occurrences.find(({ pos }) => pos === keeperPos) ?? occurrences[0];
|
|
200
|
-
for (const occurrence of occurrences) if (occurrence !== keeper) needFreshId.push(occurrence);
|
|
201
|
-
}
|
|
202
|
-
const taken = new Set(census.paraIds.keys());
|
|
203
|
-
const updates = [];
|
|
204
|
-
for (const { pos, attrs } of needFreshId) {
|
|
205
|
-
const newId = mintParaId(taken, deterministicSeed, pos);
|
|
206
|
-
taken.add(newId);
|
|
207
|
-
updates.push({
|
|
208
|
-
pos,
|
|
209
|
-
attrs: {
|
|
210
|
-
...attrs,
|
|
211
|
-
paraId: newId
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
updates.sort((left, right) => left.pos - right.pos);
|
|
216
|
-
return updates;
|
|
217
|
-
};
|
|
218
|
-
const collectParagraphPropertySourceUpdates = (census, keeperPositions, transactions) => {
|
|
219
|
-
const updates = /* @__PURE__ */ new Map();
|
|
220
|
-
for (const { pos } of census.invalidSourceTokens) updates.set(pos, null);
|
|
221
|
-
const explicitTransfers = transactions.flatMap((transaction) => [...getExplicitParagraphPropertySourceTransfers(transaction)]);
|
|
222
|
-
const explicitlySelected = new Set(explicitTransfers.map(({ selectedToken }) => selectedToken).filter((token) => token !== null));
|
|
223
|
-
const explicitlyDisplaced = new Set(explicitTransfers.map(({ displacedToken }) => displacedToken).filter((token) => token !== null));
|
|
224
|
-
const keptPositions = /* @__PURE__ */ new Set();
|
|
225
|
-
const keptTokens = /* @__PURE__ */ new Set();
|
|
226
|
-
for (const [token, occurrences] of census.sourceTokens) {
|
|
227
|
-
const mappedOwner = keeperPositions.get(token);
|
|
228
|
-
const mappedKeeper = mappedOwner?.status === "mapped" ? occurrences.find(({ pos }) => pos === mappedOwner.pos) : void 0;
|
|
229
|
-
const transferredKeeper = !mappedKeeper && explicitlySelected.has(token) && occurrences.length === 1 ? occurrences.at(0) : void 0;
|
|
230
|
-
const detachedKeeper = !mappedKeeper && !transferredKeeper && occurrences.length === 1 && (mappedOwner === void 0 || mappedOwner.status === "deleted" && mappedOwner.pos === occurrences.at(0)?.pos) ? occurrences.at(0) : void 0;
|
|
231
|
-
const keeper = mappedKeeper ?? transferredKeeper ?? detachedKeeper;
|
|
232
|
-
if (keeper) {
|
|
233
|
-
keptPositions.add(keeper.pos);
|
|
234
|
-
keptTokens.add(token);
|
|
235
|
-
}
|
|
236
|
-
for (const occurrence of occurrences) if (occurrence !== keeper) updates.set(occurrence.pos, null);
|
|
237
|
-
}
|
|
238
|
-
for (const [token, mappedOwner] of keeperPositions) {
|
|
239
|
-
if (mappedOwner.status !== "mapped" || keptTokens.has(token) || explicitlyDisplaced.has(token) || keptPositions.has(mappedOwner.pos) || !census.paragraphs.has(mappedOwner.pos)) continue;
|
|
240
|
-
updates.set(mappedOwner.pos, token);
|
|
241
|
-
}
|
|
242
|
-
return [...updates].map(([pos, token]) => ({
|
|
243
|
-
pos,
|
|
244
|
-
token
|
|
245
|
-
})).sort((left, right) => left.pos - right.pos);
|
|
246
|
-
};
|
|
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
|
-
const createParaIdAllocatorPlugin = () => new Plugin({
|
|
359
|
-
key: paraIdAllocatorKey.createKey(),
|
|
360
|
-
state: {
|
|
361
|
-
init: (_config, state) => collectParagraphPropertySourceSeed(state.doc),
|
|
362
|
-
apply: (_transaction, seed) => seed
|
|
363
|
-
},
|
|
364
|
-
appendTransaction(transactions, oldState, newState) {
|
|
365
|
-
if (!transactions.some((t) => t.docChanged)) return null;
|
|
366
|
-
const paragraphSourceSeed = paraIdAllocatorKey.getState(oldState);
|
|
367
|
-
if (!paragraphSourceSeed) panic("ParaId allocator lost its paragraph-property source seed");
|
|
368
|
-
const keeperPositions = mapParagraphKeepers(oldState.doc, transactions, paragraphSourceSeed);
|
|
369
|
-
const deterministicSeed = transactions.map(deterministicSeedOf).find((value) => typeof value === "string") ?? null;
|
|
370
|
-
const census = collectParagraphCensus(newState.doc, paragraphSourceSeed);
|
|
371
|
-
const updates = collectParaIdUpdatesFromCensus(census, keeperPositions.paraIds, deterministicSeed);
|
|
372
|
-
const paragraphSourceUpdates = collectParagraphPropertySourceUpdates(census, keeperPositions.sourceTokens, transactions);
|
|
373
|
-
if (updates.length === 0 && paragraphSourceUpdates.length === 0) return null;
|
|
374
|
-
const tr = newState.tr;
|
|
375
|
-
for (const u of updates) setProseParagraphMarkupWithPropertySource({
|
|
376
|
-
attrs: u.attrs,
|
|
377
|
-
ownership: "transfer-allocated-id",
|
|
378
|
-
pos: u.pos,
|
|
379
|
-
transaction: tr
|
|
380
|
-
});
|
|
381
|
-
for (const { pos, token } of paragraphSourceUpdates) {
|
|
382
|
-
const paragraph = tr.doc.nodeAt(pos);
|
|
383
|
-
if (!paragraph || paragraph.type.name !== "paragraph") panic("Paragraph-property token update lost its paragraph");
|
|
384
|
-
setProseParagraphMarkupWithPropertySource({
|
|
385
|
-
attrs: {
|
|
386
|
-
...paragraph.attrs,
|
|
387
|
-
[PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR]: token
|
|
388
|
-
},
|
|
389
|
-
ownership: "preserve",
|
|
390
|
-
pos,
|
|
391
|
-
transaction: tr
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
ignoreTrackedChanges(tr);
|
|
395
|
-
tr.setMeta(paraIdAllocatorKey, "allocated");
|
|
396
|
-
tr.setMeta("addToHistory", false);
|
|
397
|
-
if (newState.storedMarks !== null) tr.setStoredMarks(newState.storedMarks);
|
|
398
|
-
return tr;
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
const ParaIdAllocatorExtension = createExtension({
|
|
402
|
-
name: "paraIdAllocator",
|
|
403
|
-
defaultOptions: {},
|
|
404
|
-
onSchemaReady() {
|
|
405
|
-
return { plugins: [createParaIdAllocatorPlugin()] };
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
export { ParaIdAllocatorExtension, deterministicParaIdSeedKey, ensureParaIdsInDoc, ensureParaIdsInState, mapParagraphKeepers, paraIdAllocatorKey, requestDeterministicParaIds };
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paragraph Change Tracker Extension
|
|
3
|
-
*
|
|
4
|
-
* Watches ProseMirror transactions and records which paragraph IDs (paraId)
|
|
5
|
-
* were modified. Also detects paragraph and block-structure changes.
|
|
6
|
-
* Used by the selective save system to patch only changed paragraphs in document.xml.
|
|
7
|
-
*/
|
|
8
|
-
import { RemovedSectionReference, TrackedSectionEndpointRemoval } from "../../../internal/sectionEndpointResolution.js";
|
|
9
|
-
import { document_d_exports } from "../../../types/document.js";
|
|
10
|
-
import { Extension } from "../types.js";
|
|
11
|
-
import { Node } from "prosemirror-model";
|
|
12
|
-
import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
|
|
13
|
-
export declare const paragraphChangeTrackerKey: Readonly<{
|
|
14
|
-
key: string;
|
|
15
|
-
createKey: () => PluginKey<InternalParagraphChangeTrackerState>;
|
|
16
|
-
owns: (plugin: Plugin<InternalParagraphChangeTrackerState>) => boolean;
|
|
17
|
-
get: (state: EditorState) => Plugin<InternalParagraphChangeTrackerState> | undefined;
|
|
18
|
-
getState: (state: EditorState) => InternalParagraphChangeTrackerState | undefined;
|
|
19
|
-
}>;
|
|
20
|
-
export type ParagraphChangeTrackerState = {
|
|
21
|
-
/** Set of paraIds that were modified since last clear */
|
|
22
|
-
changedParaIds: Set<string>;
|
|
23
|
-
/** Whether paragraph order, membership, or block structure changed. */
|
|
24
|
-
structuralChange: boolean;
|
|
25
|
-
/** Whether edited paragraphs still lack IDs or source identity was unavailable. */
|
|
26
|
-
hasUntrackedChanges: boolean;
|
|
27
|
-
/** Paragraph count in the current tracked document. */
|
|
28
|
-
paragraphCount: number;
|
|
29
|
-
/** Cached section-endpoint count used to invalidate stale save authorization. */
|
|
30
|
-
sectionEndpointCount: number;
|
|
31
|
-
/** Exact endpoint owners and properties used to invalidate count-neutral changes. */
|
|
32
|
-
sectionEndpointFingerprint: string;
|
|
33
|
-
/** Exact tracked-resolution transition that may reduce the saved section count. */
|
|
34
|
-
sectionEndpointRemoval: TrackedSectionEndpointRemoval | null;
|
|
35
|
-
};
|
|
36
|
-
type InternalParagraphChangeTrackerState = ParagraphChangeTrackerState & {
|
|
37
|
-
/** Edited paragraph positions retained across allocator-only transactions. */
|
|
38
|
-
affectedParagraphPositions: Set<number>;
|
|
39
|
-
/** Editing an already unidentified source paragraph cannot become selective. */
|
|
40
|
-
hasUntrackedSourceChanges: boolean;
|
|
41
|
-
blockStructureFingerprint: string;
|
|
42
|
-
/** The section records themselves, by identity. */
|
|
43
|
-
sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
|
|
44
|
-
};
|
|
45
|
-
type DocumentStructureCounts = {
|
|
46
|
-
blockStructureFingerprint: string;
|
|
47
|
-
sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
|
|
48
|
-
paragraphs: number;
|
|
49
|
-
/**
|
|
50
|
-
* Distinct section records the paragraphs carry, which is the number of
|
|
51
|
-
* `w:sectPr` the package states for them. A split copies a node's attrs, so
|
|
52
|
-
* both halves of a split section-ending paragraph hold one record until the
|
|
53
|
-
* from-leg keeps it on the trailing half: one section, not two.
|
|
54
|
-
*/
|
|
55
|
-
sectionEndpoints: number;
|
|
56
|
-
sectionEndpointFingerprint: string;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Count the structural values the tracker compares for every transaction.
|
|
60
|
-
*
|
|
61
|
-
* Each top-level block's records are kept for the block node, so a keystroke
|
|
62
|
-
* recomputes only the block it changed. The fingerprint joins the blocks'
|
|
63
|
-
* records in order: two documents' fingerprints are equal exactly when their
|
|
64
|
-
* full record lists (every block and nested block with its path) are.
|
|
65
|
-
*/
|
|
66
|
-
export declare function countDocumentStructure(doc: Node): DocumentStructureCounts;
|
|
67
|
-
export declare function createParagraphChangeTrackerPlugin(): Plugin<InternalParagraphChangeTrackerState>;
|
|
68
|
-
/**
|
|
69
|
-
* Get the change tracker state from an EditorState
|
|
70
|
-
*/
|
|
71
|
-
export declare function getChangeTrackerState(state: EditorState): ParagraphChangeTrackerState | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Get the set of changed paragraph IDs from an EditorState
|
|
74
|
-
*/
|
|
75
|
-
export declare function getChangedParagraphIds(state: EditorState): Set<string>;
|
|
76
|
-
/**
|
|
77
|
-
* Check if paragraph membership, order, or block structure changed
|
|
78
|
-
*/
|
|
79
|
-
export declare function hasStructuralChanges(state: EditorState): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Check if any changes affected paragraphs without paraId
|
|
82
|
-
*/
|
|
83
|
-
export declare function hasUntrackedChanges(state: EditorState): boolean;
|
|
84
|
-
/** Exact section-count transition authorized by tracked paragraph-mark resolution. */
|
|
85
|
-
export declare function getTrackedSectionEndpointRemoval(state: EditorState): TrackedSectionEndpointRemoval | null;
|
|
86
|
-
type RepackWithEditorSectionRemovalsOptions<T> = {
|
|
87
|
-
/** The editor state the document was built from. */
|
|
88
|
-
state: EditorState;
|
|
89
|
-
/** The exact document object `repack` hands to `repackDocx`. */
|
|
90
|
-
document: document_d_exports.Document;
|
|
91
|
-
repack: () => Promise<T>;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Run an editor save's full repack with the section removals the editor's own
|
|
95
|
-
* edits made.
|
|
96
|
-
*
|
|
97
|
-
* A save refuses a package with fewer sections than its source unless it is
|
|
98
|
-
* told which removals were meant: deleting the paragraph that ends a section,
|
|
99
|
-
* or accepting its tracked deletion, removes that section on purpose. The
|
|
100
|
-
* tracker records exactly those removals; without them the repack throws and
|
|
101
|
-
* the edit cannot be saved.
|
|
102
|
-
*/
|
|
103
|
-
export declare const repackWithEditorSectionRemovals: <T>({ state, document, repack }: RepackWithEditorSectionRemovalsOptions<T>) => Promise<T>;
|
|
104
|
-
type MarkTrackedSectionEndpointRemovalOptions = {
|
|
105
|
-
sourceDoc: Node;
|
|
106
|
-
removedEndpointCount: number;
|
|
107
|
-
removedReferences: readonly RemovedSectionReference[];
|
|
108
|
-
};
|
|
109
|
-
/** Record only a complete, internally consistent endpoint-removal transition. */
|
|
110
|
-
export declare function markTrackedSectionEndpointRemoval(tr: Transaction, { sourceDoc, removedEndpointCount, removedReferences }: MarkTrackedSectionEndpointRemovalOptions): Transaction;
|
|
111
|
-
/**
|
|
112
|
-
* Record that `tr` removed section breaks on purpose: a command whose job is
|
|
113
|
-
* to remove the break (not to delete its paragraph mark, which the tracker
|
|
114
|
-
* reads for itself). Only a plain removal is recorded; a transaction that also
|
|
115
|
-
* adds or replaces a record is left as it is.
|
|
116
|
-
*/
|
|
117
|
-
export declare function markSectionBreakRemoval(tr: Transaction, sourceDoc: Node): Transaction;
|
|
118
|
-
/**
|
|
119
|
-
* Create a transaction that clears the change tracker
|
|
120
|
-
*/
|
|
121
|
-
export declare function clearTrackedChanges(state: EditorState): Transaction;
|
|
122
|
-
export declare function ignoreTrackedChanges(tr: Transaction): Transaction;
|
|
123
|
-
export declare function markStructuralChange(tr: Transaction): Transaction;
|
|
124
|
-
type MarkChangedParagraphRangesOptions = {
|
|
125
|
-
ranges: readonly {
|
|
126
|
-
from: number;
|
|
127
|
-
to: number;
|
|
128
|
-
}[];
|
|
129
|
-
mappingFrom: number;
|
|
130
|
-
replacesStepMapAt?: number;
|
|
131
|
-
};
|
|
132
|
-
/** Record mark-only paragraph changes whose replacement step has a granular map. */
|
|
133
|
-
export declare function markChangedParagraphRanges(tr: Transaction, batch: MarkChangedParagraphRangesOptions): Transaction;
|
|
134
|
-
export declare const ParagraphChangeTrackerExtension: (options?: Partial<Record<never, never>> | undefined) => Extension;
|
|
135
|
-
export {};
|