@stll/folio-core 0.71.1 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/dist/ai-edits/apply.d.ts +6 -114
- package/dist/ai-edits/apply.js +9 -131
- 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 +213 -1634
- 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/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- 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/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineProjection.js +1 -1
- package/dist/canonical/canonicalPublicOperations.js +228 -64
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +95 -15
- 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 -4
- package/dist/compat/eigenpal.js +2 -4
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +185 -49
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/canonicalYjsRoom.d.ts +1 -1
- package/dist/controller/headerFooterEditorManager.d.ts +11 -7
- package/dist/controller/headerFooterEditorManager.js +39 -151
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +6 -40
- package/dist/controller/hiddenEditorManager.js +173 -306
- package/dist/controller/noteEditorManager.d.ts +3 -10
- package/dist/controller/noteEditorManager.js +33 -206
- package/dist/document-operations-apply.d.ts +15 -0
- package/dist/document-operations-apply.js +280 -0
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +2 -279
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +32 -9
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +5 -37
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +600 -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 +177 -0
- package/dist/docx/server/templatePlan/labels.d.ts +36 -0
- package/dist/docx/server/templatePlan/labels.js +126 -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 +143 -0
- package/dist/docx/server/templatePlan/plan.js +841 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +161 -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 +406 -0
- package/dist/docx/server/templatePlan/types.js +28 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +968 -0
- package/dist/docx/server/templatePlan/xml.d.ts +69 -0
- package/dist/docx/server/templatePlan/xml.js +119 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/storyBlockReplay.js +1 -1
- 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/docx/xmlParser.js +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -4
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/DocumentLoaderManager.d.ts +0 -4
- package/dist/managers/DocumentLoaderManager.js +4 -12
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +2 -2
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.d.ts +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/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/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
- 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/StarterKit.d.ts +1 -1
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
- package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
- 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/ParaIdAllocatorExtension.d.ts +2 -35
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- 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 +2 -2
- 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/index.d.ts +1 -1
- package/dist/prosemirror/index.js +1 -1
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/listNumbering.d.ts +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/noteReferenceReview.js +1 -1
- package/dist/prosemirror/numberingAttr.d.ts +1 -2
- package/dist/prosemirror/numberingAttr.js +1 -2
- package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
- package/dist/prosemirror/outlineLevelAttr.js +1 -2
- package/dist/prosemirror/paraIds.d.ts +46 -0
- 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/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +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 +16 -1
- 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/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/server.d.ts +7 -5
- package/dist/server.js +6 -4
- package/dist/types/canonicalCapabilities.d.ts +8 -41
- package/dist/types/canonicalCapabilities.js +6 -34
- package/package.json +4 -6
- package/dist/controller/collaborationModules.d.ts +0 -3
- package/dist/controller/collaborationModules.js +0 -14
- package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
- package/dist/docx/server/materializeYjsDocx.js +0 -96
- package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
- package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
- package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
- package/dist/prosemirror/plugins/derivedFields.js +0 -52
- package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
- package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, getExplicitParagraphPropertySourceTransfers, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, paragraphPropertySourceTokenMatchesContract,
|
|
2
|
-
import { prosePositionalParagraphId } from "../../../docx/unnamedParagraphIds.js";
|
|
1
|
+
import { PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, getExplicitParagraphPropertySourceTransfers, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, paragraphPropertySourceTokenMatchesContract, setProseParagraphMarkupWithPropertySource } from "../../../docx/paragraphPropertySource.js";
|
|
3
2
|
import { deterministicHexId, generateHexId } from "../../../utils/hexId.js";
|
|
4
|
-
import {
|
|
3
|
+
import { deterministicParaIdSeedKey, isUsableParaId, paraIdAllocatorKey, visitAuthoredParagraphs } from "../../paraIds.js";
|
|
4
|
+
import { ignoreTrackedChanges } from "../../paragraphChangeTrackerMeta.js";
|
|
5
5
|
import { sweepPositions } from "../../positionSweep.js";
|
|
6
6
|
import { createExtension } from "../create.js";
|
|
7
|
-
import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
|
|
8
7
|
import { panic } from "better-result";
|
|
9
|
-
import { Fragment } from "prosemirror-model";
|
|
10
8
|
import { Plugin, Transaction } from "prosemirror-state";
|
|
11
9
|
// src/prosemirror/extensions/features/ParaIdAllocatorExtension.ts
|
|
12
10
|
/**
|
|
@@ -49,20 +47,6 @@ import { Plugin, Transaction } from "prosemirror-state";
|
|
|
49
47
|
* split therefore restores the same allocated id instead of minting
|
|
50
48
|
* another one.
|
|
51
49
|
*/
|
|
52
|
-
const paraIdAllocatorKey = createPluginKeyOwner("paraIdAllocator");
|
|
53
|
-
/**
|
|
54
|
-
* Transaction meta asking this plugin to derive the ids it mints from a
|
|
55
|
-
* caller-supplied seed instead of `Math.random()`.
|
|
56
|
-
*
|
|
57
|
-
* A live editor wants random ids: two people typing must not collide. A
|
|
58
|
-
* generator whose whole output has to be reproducible — the document compare —
|
|
59
|
-
* cannot afford them, and it is the only party that knows its run is meant to
|
|
60
|
-
* be deterministic, so it says so on its own transaction rather than leaving
|
|
61
|
-
* the plugin to guess.
|
|
62
|
-
*/
|
|
63
|
-
const deterministicParaIdSeedKey = "stll.folio.meta.deterministicParaIdSeed";
|
|
64
|
-
/** Ask the allocator to mint reproducible ids for the paragraphs `tr` creates. */
|
|
65
|
-
const requestDeterministicParaIds = (tr, seed) => tr.setMeta(deterministicParaIdSeedKey, seed);
|
|
66
50
|
const deterministicSeedOf = (transaction) => {
|
|
67
51
|
const seed = transaction.getMeta(deterministicParaIdSeedKey);
|
|
68
52
|
if (typeof seed === "string") return seed;
|
|
@@ -87,17 +71,6 @@ const mintParaId = (taken, seed, pos) => {
|
|
|
87
71
|
for (let salt = 1; taken.has(id); salt++) id = deterministicHexId(`${seed}:${String(pos)}:${String(salt)}`);
|
|
88
72
|
return id;
|
|
89
73
|
};
|
|
90
|
-
const isUsableParaId = (value) => typeof value === "string" && value.length > 0 && value !== "00000000";
|
|
91
|
-
/** Omitted grid cells render absent positions and own no package paragraphs. */
|
|
92
|
-
const isOmittedGridCell = (node) => (node.type.spec["tableRole"] === "cell" || node.type.spec["tableRole"] === "header_cell") && (node.attrs["_omittedGridSlot"] === "before" || node.attrs["_omittedGridSlot"] === "after");
|
|
93
|
-
const visitAuthoredParagraphs = (doc, visit) => {
|
|
94
|
-
doc.descendants((node, pos) => {
|
|
95
|
-
if (isOmittedGridCell(node)) return false;
|
|
96
|
-
if (node.type.name !== "paragraph") return true;
|
|
97
|
-
visit(node, pos);
|
|
98
|
-
return false;
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
74
|
const collectParagraphPropertySourceSeed = (doc) => {
|
|
102
75
|
const contract = getProseDocumentParagraphPropertySourceContract(doc);
|
|
103
76
|
if (!contract) return {
|
|
@@ -244,117 +217,6 @@ const collectParagraphPropertySourceUpdates = (census, keeperPositions, transact
|
|
|
244
217
|
token
|
|
245
218
|
})).sort((left, right) => left.pos - right.pos);
|
|
246
219
|
};
|
|
247
|
-
/**
|
|
248
|
-
* The ids a loaded document's paragraphs take, in document order: `null`
|
|
249
|
-
* keeps the paragraph's own id, a string replaces it.
|
|
250
|
-
*
|
|
251
|
-
* This is the only load-time allocator. The live editor and the headless
|
|
252
|
-
* reviewer both seed through it, so the same document gives the same block ids
|
|
253
|
-
* on either side: an id read from the editor resolves when the edit is applied
|
|
254
|
-
* headlessly, and re-parsing the same bytes mints the same ids. A paragraph
|
|
255
|
-
* the package names no id for takes the id its place in the package gives it
|
|
256
|
-
* (the one `ensureParaIds` writes, so a canonical session agrees); one the
|
|
257
|
-
* parser could not place, such as a paragraph a host built, takes an id
|
|
258
|
-
* derived from its text and its document ordinal, never drawn at random.
|
|
259
|
-
* Authored ids are reserved first, so a minted id never takes one a later
|
|
260
|
-
* paragraph owns; of a duplicated authored id, the first occurrence keeps it.
|
|
261
|
-
*/
|
|
262
|
-
const planLoadParaIds = (doc) => {
|
|
263
|
-
const paragraphs = [];
|
|
264
|
-
const taken = /* @__PURE__ */ new Set();
|
|
265
|
-
visitAuthoredParagraphs(doc, (node) => {
|
|
266
|
-
paragraphs.push(node);
|
|
267
|
-
const id = node.attrs["paraId"];
|
|
268
|
-
if (isUsableParaId(id)) {
|
|
269
|
-
taken.add(id);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const positional = prosePositionalParagraphId(node);
|
|
273
|
-
if (positional !== void 0) taken.add(positional);
|
|
274
|
-
});
|
|
275
|
-
const kept = /* @__PURE__ */ new Set();
|
|
276
|
-
return paragraphs.map((paragraph, index) => {
|
|
277
|
-
const id = paragraph.attrs["paraId"];
|
|
278
|
-
if (isUsableParaId(id) && !kept.has(id)) {
|
|
279
|
-
kept.add(id);
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
const positional = prosePositionalParagraphId(paragraph);
|
|
283
|
-
if (positional !== void 0 && !kept.has(positional)) {
|
|
284
|
-
kept.add(positional);
|
|
285
|
-
return positional;
|
|
286
|
-
}
|
|
287
|
-
const seed = `${paragraph.textContent}:${String(index + 1)}`;
|
|
288
|
-
let minted = deterministicHexId(seed);
|
|
289
|
-
for (let salt = 1; taken.has(minted); salt++) minted = deterministicHexId(`${seed}:${String(salt)}`);
|
|
290
|
-
taken.add(minted);
|
|
291
|
-
return minted;
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
/** A paragraph's attrs once it holds an id folio minted rather than read. */
|
|
295
|
-
const mintedParagraphAttrs = (paragraph, paraId) => ({
|
|
296
|
-
...paragraph.attrs,
|
|
297
|
-
paraId,
|
|
298
|
-
...paragraph.type.spec.attrs?.["idStability"] !== void 0 && { idStability: "positional" }
|
|
299
|
-
});
|
|
300
|
-
/**
|
|
301
|
-
* Allocate initial paragraph IDs before constructing editor state.
|
|
302
|
-
*
|
|
303
|
-
* Rebuilding only changed branches avoids applying one ProseMirror transaction
|
|
304
|
-
* step per missing paragraph. Live edits still use the transaction-based plugin
|
|
305
|
-
* below so history, mappings, and duplicate ownership retain their semantics.
|
|
306
|
-
*/
|
|
307
|
-
const ensureParaIdsInDoc = (doc) => {
|
|
308
|
-
const plan = planLoadParaIds(doc);
|
|
309
|
-
if (plan.every((paraId) => paraId === null)) return doc;
|
|
310
|
-
let ordinal = 0;
|
|
311
|
-
const rewrite = (parent) => {
|
|
312
|
-
let changed = false;
|
|
313
|
-
const children = [];
|
|
314
|
-
parent.forEach((child) => {
|
|
315
|
-
if (isOmittedGridCell(child)) {
|
|
316
|
-
children.push(child);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
let next = child;
|
|
320
|
-
if (child.type.name === "paragraph") {
|
|
321
|
-
const minted = plan[ordinal];
|
|
322
|
-
ordinal += 1;
|
|
323
|
-
if (minted !== null && minted !== void 0) next = recreateProseNodeWithParagraphPropertySource(child, { attrs: mintedParagraphAttrs(child, minted) });
|
|
324
|
-
const paraId = next.attrs["paraId"];
|
|
325
|
-
if (typeof paraId === "string") transferProseParagraphPropertySource(next, child, paraId);
|
|
326
|
-
} else if (child.childCount > 0) {
|
|
327
|
-
const content = rewrite(child);
|
|
328
|
-
if (content !== child.content) next = recreateProseNodeWithParagraphPropertySource(child, { content });
|
|
329
|
-
}
|
|
330
|
-
if (next !== child) changed = true;
|
|
331
|
-
children.push(next);
|
|
332
|
-
});
|
|
333
|
-
return changed ? Fragment.fromArray(children) : parent.content;
|
|
334
|
-
};
|
|
335
|
-
return recreateProseNodeWithParagraphPropertySource(doc, { content: rewrite(doc) });
|
|
336
|
-
};
|
|
337
|
-
/** {@link ensureParaIdsInDoc} for a state that already exists. */
|
|
338
|
-
const ensureParaIdsInState = (state) => {
|
|
339
|
-
const plan = planLoadParaIds(state.doc);
|
|
340
|
-
if (plan.every((paraId) => paraId === null)) return state;
|
|
341
|
-
const tr = state.tr;
|
|
342
|
-
let ordinal = 0;
|
|
343
|
-
visitAuthoredParagraphs(state.doc, (node, pos) => {
|
|
344
|
-
const minted = plan[ordinal];
|
|
345
|
-
ordinal += 1;
|
|
346
|
-
if (minted !== null && minted !== void 0) setProseParagraphMarkupWithPropertySource({
|
|
347
|
-
attrs: mintedParagraphAttrs(node, minted),
|
|
348
|
-
ownership: "transfer-allocated-id",
|
|
349
|
-
pos,
|
|
350
|
-
transaction: tr
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
ignoreTrackedChanges(tr);
|
|
354
|
-
tr.setMeta(paraIdAllocatorKey, "allocated");
|
|
355
|
-
tr.setMeta("addToHistory", false);
|
|
356
|
-
return state.apply(tr);
|
|
357
|
-
};
|
|
358
220
|
const createParaIdAllocatorPlugin = () => new Plugin({
|
|
359
221
|
key: paraIdAllocatorKey.createKey(),
|
|
360
222
|
state: {
|
|
@@ -405,4 +267,4 @@ const ParaIdAllocatorExtension = createExtension({
|
|
|
405
267
|
return { plugins: [createParaIdAllocatorPlugin()] };
|
|
406
268
|
}
|
|
407
269
|
});
|
|
408
|
-
export { ParaIdAllocatorExtension,
|
|
270
|
+
export { ParaIdAllocatorExtension, mapParagraphKeepers };
|
|
@@ -5,65 +5,11 @@
|
|
|
5
5
|
* were modified. Also detects paragraph and block-structure changes.
|
|
6
6
|
* Used by the selective save system to patch only changed paragraphs in document.xml.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { TrackedSectionEndpointRemoval } from "../../../internal/sectionEndpointResolution.js";
|
|
9
9
|
import { document_d_exports } from "../../../types/document.js";
|
|
10
|
+
import { InternalParagraphChangeTrackerState, ParagraphChangeTrackerState } from "../../paragraphChangeTrackerMeta.js";
|
|
10
11
|
import { Extension } from "../types.js";
|
|
11
|
-
import {
|
|
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;
|
|
12
|
+
import { EditorState, Plugin } from "prosemirror-state";
|
|
67
13
|
export declare function createParagraphChangeTrackerPlugin(): Plugin<InternalParagraphChangeTrackerState>;
|
|
68
14
|
/**
|
|
69
15
|
* Get the change tracker state from an EditorState
|
|
@@ -101,35 +47,5 @@ type RepackWithEditorSectionRemovalsOptions<T> = {
|
|
|
101
47
|
* the edit cannot be saved.
|
|
102
48
|
*/
|
|
103
49
|
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
50
|
export declare const ParagraphChangeTrackerExtension: (options?: Partial<Record<never, never>> | undefined) => Extension;
|
|
135
51
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { withTrackedSectionEndpointRemoval } from "../../../internal/sectionEndpointResolution.js";
|
|
2
|
-
import {
|
|
2
|
+
import { countDocumentStructure } from "../../documentStructureCounts.js";
|
|
3
3
|
import { enclosingParagraphIndexed, nodeAtIndexed, nodesBetweenIndexed } from "../../indexedNodeLookup.js";
|
|
4
|
-
import {
|
|
4
|
+
import { CHANGED_PARAGRAPH_RANGES_META, SECTION_ENDPOINT_REMOVAL_META, isChangedParagraphRangesMeta, isTrackedSectionEndpointRemoval, isTrackedSectionEndpointRemovalMeta, paragraphChangeTrackerKey, referencesOf } from "../../paragraphChangeTrackerMeta.js";
|
|
5
5
|
import { sweepPositions } from "../../positionSweep.js";
|
|
6
6
|
import { sectionPropertiesOf } from "../../sectionCarrier.js";
|
|
7
7
|
import { sectionMarkEditsOf } from "../../sectionMarkEdits.js";
|
|
@@ -18,90 +18,8 @@ import { isHistoryTransaction } from "prosemirror-history";
|
|
|
18
18
|
* were modified. Also detects paragraph and block-structure changes.
|
|
19
19
|
* Used by the selective save system to patch only changed paragraphs in document.xml.
|
|
20
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
21
|
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
22
|
const isSectionEditMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "section-edit-meta" && "authorization" in value && (value.authorization === null || isTrackedSectionEndpointRemoval(value.authorization)) && "expectedEndpointFingerprint" in value && typeof value.expectedEndpointFingerprint === "string";
|
|
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
23
|
/**
|
|
106
24
|
* Whether a transaction left every section record in place, by identity: the
|
|
107
25
|
* same sections, however their paragraphs moved around them. An edit before a
|
|
@@ -257,7 +175,7 @@ function createParagraphChangeTrackerPlugin() {
|
|
|
257
175
|
const changedParagraphRangesMeta = tr.getMeta(CHANGED_PARAGRAPH_RANGES_META);
|
|
258
176
|
const sectionEndpointRemovalMeta = tr.getMeta(SECTION_ENDPOINT_REMOVAL_META);
|
|
259
177
|
const sectionEditMeta = tr.getMeta(SECTION_EDIT_META);
|
|
260
|
-
if (meta ===
|
|
178
|
+
if (meta === "clear") {
|
|
261
179
|
const counts = countDocumentStructure(tr.doc);
|
|
262
180
|
return {
|
|
263
181
|
affectedParagraphPositions: /* @__PURE__ */ new Set(),
|
|
@@ -273,7 +191,7 @@ function createParagraphChangeTrackerPlugin() {
|
|
|
273
191
|
sectionEndpointRemoval: null
|
|
274
192
|
};
|
|
275
193
|
}
|
|
276
|
-
if (meta ===
|
|
194
|
+
if (meta === "ignore") {
|
|
277
195
|
if (!tr.docChanged) return prevState;
|
|
278
196
|
const counts = countDocumentStructure(tr.doc);
|
|
279
197
|
const affectedParagraphPositions = mapAffectedParagraphPositions(tr, prevState.affectedParagraphPositions);
|
|
@@ -323,7 +241,7 @@ function createParagraphChangeTrackerPlugin() {
|
|
|
323
241
|
hasUntrackedSourceChanges: prevState.hasUntrackedSourceChanges,
|
|
324
242
|
blockStructureFingerprint: counts.blockStructureFingerprint,
|
|
325
243
|
changedParaIds: new Set(prevState.changedParaIds),
|
|
326
|
-
structuralChange: prevState.structuralChange || meta ===
|
|
244
|
+
structuralChange: prevState.structuralChange || meta === "structural",
|
|
327
245
|
hasUntrackedChanges: prevState.hasUntrackedChanges,
|
|
328
246
|
paragraphCount: newCount,
|
|
329
247
|
sectionEndpointCount: counts.sectionEndpoints,
|
|
@@ -371,22 +289,6 @@ function createParagraphChangeTrackerPlugin() {
|
|
|
371
289
|
appendTransaction: (transactions, oldState, newState) => sectionEditTransaction(transactions, oldState, newState)
|
|
372
290
|
});
|
|
373
291
|
}
|
|
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
292
|
/** `references` without one occurrence of each of `restored`. */
|
|
391
293
|
const withoutReferences = (references, restored) => {
|
|
392
294
|
const remaining = [...references];
|
|
@@ -415,7 +317,7 @@ const withoutReferences = (references, restored) => {
|
|
|
415
317
|
* removal back out of the authorization.
|
|
416
318
|
*/
|
|
417
319
|
const sectionEditTransaction = (transactions, oldState, newState) => {
|
|
418
|
-
if (!transactions.some((transaction) => transaction.docChanged && transaction.getMeta(paragraphChangeTrackerKey) !==
|
|
320
|
+
if (!transactions.some((transaction) => transaction.docChanged && transaction.getMeta(paragraphChangeTrackerKey) !== "ignore") || transactions.some((transaction) => transaction.getMeta(SECTION_EDIT_META) !== void 0 || transaction.getMeta("folioSectionEndpointRemoval") !== void 0 || transaction.getMeta(paragraphChangeTrackerKey) === "clear")) return null;
|
|
419
321
|
const base = paragraphChangeTrackerKey.getState(oldState);
|
|
420
322
|
if (!base) return null;
|
|
421
323
|
const dropped = droppedCellSections(transactions, oldState.doc, newState.doc);
|
|
@@ -499,63 +401,6 @@ const repackWithEditorSectionRemovals = ({ state, document, repack }) => {
|
|
|
499
401
|
repack
|
|
500
402
|
});
|
|
501
403
|
};
|
|
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
404
|
const ParagraphChangeTrackerExtension = createExtension({
|
|
560
405
|
name: "paragraphChangeTracker",
|
|
561
406
|
defaultOptions: {},
|
|
@@ -563,4 +408,4 @@ const ParagraphChangeTrackerExtension = createExtension({
|
|
|
563
408
|
return { plugins: [createParagraphChangeTrackerPlugin()] };
|
|
564
409
|
}
|
|
565
410
|
});
|
|
566
|
-
export { ParagraphChangeTrackerExtension,
|
|
411
|
+
export { ParagraphChangeTrackerExtension, createParagraphChangeTrackerPlugin, getChangeTrackerState, getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges, repackWithEditorSectionRemovals };
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* in a cell, or that stands in a pasted cell, comes without the break it ended
|
|
6
6
|
* its own section with.
|
|
7
7
|
*/
|
|
8
|
-
import { Node, Slice } from "prosemirror-model";
|
|
9
8
|
import { Transaction } from "prosemirror-state";
|
|
9
|
+
import { Node, Slice } from "prosemirror-model";
|
|
10
10
|
import { EditorView } from "prosemirror-view";
|
|
11
11
|
/**
|
|
12
12
|
* Where a drop put a section break in a table cell. The drop's target is not
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readOutlineLevelAttr } from "../../outlineLevelAttr.js";
|
|
2
2
|
import { getDocumentBuiltInStyles, getDocumentStyleResolver } from "../../plugins/documentStyleState.js";
|
|
3
|
-
import { headingLevelOf } from "@stll/docx-core/model";
|
|
4
3
|
import { Fragment, Slice } from "prosemirror-model";
|
|
4
|
+
import { headingLevelOf } from "@stll/docx-core/model";
|
|
5
5
|
// src/prosemirror/extensions/features/pastedHeadingStyles.ts
|
|
6
6
|
/**
|
|
7
7
|
* Retarget pasted heading paragraphs at the open document's own heading style.
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import { document_d_exports } from "../../../types/document.js";
|
|
8
8
|
import { DeepReadonly } from "../../../types/documentModel.js";
|
|
9
9
|
import { CanonicalCommandIntent } from "../../canonicalCommands.js";
|
|
10
|
-
import { Attrs, Mark, MarkType, Schema } from "prosemirror-model";
|
|
11
10
|
import { Command, EditorState } from "prosemirror-state";
|
|
11
|
+
import { Attrs, Mark, MarkType, Schema } from "prosemirror-model";
|
|
12
12
|
import { FormattingPatch } from "@stll/docx-core/ops";
|
|
13
13
|
type MarkAttrs = Record<string, unknown>;
|
|
14
14
|
export declare const withRunFormattingLock: (command: Command, describe: (state: EditorState) => readonly CanonicalCommandIntent[] | undefined) => Command;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import { ColorValue } from "../../../types/colors.js";
|
|
8
8
|
import { DeepReadonly } from "../../../types/documentModel.js";
|
|
9
9
|
import { AnyExtension, Extension, NodeExtension } from "../types.js";
|
|
10
|
-
import { Node } from "prosemirror-model";
|
|
11
10
|
import { Command, EditorState } from "prosemirror-state";
|
|
11
|
+
import { Node } from "prosemirror-model";
|
|
12
12
|
export type TableContextInfo = {
|
|
13
13
|
isInTable: boolean;
|
|
14
14
|
table?: Node;
|
|
@@ -14,8 +14,8 @@ import { insertTableColumn, removeTableColumns, removeTableRow } from "../../tab
|
|
|
14
14
|
import { tablePositionedBookmarksPlugin } from "../../tablePositionedBookmarks.js";
|
|
15
15
|
import { createExtension, createNodeExtension } from "../create.js";
|
|
16
16
|
import { panic } from "better-result";
|
|
17
|
-
import { statesNoBorder } from "@stll/docx-core/model";
|
|
18
17
|
import { CellSelection, TableMap, columnResizing, mergeCells, selectedRect, splitCell, tableEditing, tableNodeTypes } from "prosemirror-tables";
|
|
18
|
+
import { statesNoBorder } from "@stll/docx-core/model";
|
|
19
19
|
import { Plugin, PluginKey, Selection, TextSelection } from "prosemirror-state";
|
|
20
20
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
21
21
|
// src/prosemirror/extensions/nodes/TableExtension.ts
|
|
@@ -2028,7 +2028,7 @@ const TablePluginExtension = createExtension({
|
|
|
2028
2028
|
setRowHeight: (height, rule) => withCanonicalTableAttributeCommand(setRowHeight(height, rule)),
|
|
2029
2029
|
toggleHeaderRow: () => withCanonicalTableAttributeCommand(toggleHeaderRow()),
|
|
2030
2030
|
distributeColumns: () => withCanonicalTableAttributeCommand(distributeColumns()),
|
|
2031
|
-
autoFitContents: () => autoFitContents(),
|
|
2031
|
+
autoFitContents: () => withCanonicalTableAttributeCommand(autoFitContents()),
|
|
2032
2032
|
setTableProperties: (props) => withCanonicalTableAttributeCommand(setTableProperties(props)),
|
|
2033
2033
|
applyTableStyle: (styleData) => withCanonicalTableAttributeCommand(applyTableStyle(styleData)),
|
|
2034
2034
|
setCellFillColor: (color) => withCanonicalTableAttributeCommand(setCellFillColor(color)),
|
|
@@ -14,8 +14,8 @@ import { TextColorAttrs } from "../schema/marks.js";
|
|
|
14
14
|
import { SectionBreakType } from "../sectionCarrier.js";
|
|
15
15
|
import { GenerateTableOfContentsOptions, ResolvedStyleAttrs } from "./core/ParagraphExtension.js";
|
|
16
16
|
import { BorderPreset, TableBorderPreset } from "./nodes/TableExtension.js";
|
|
17
|
-
import { MarkSpec, NodeSpec, Schema } from "prosemirror-model";
|
|
18
17
|
import { Command, Plugin } from "prosemirror-state";
|
|
18
|
+
import { MarkSpec, NodeSpec, Schema } from "prosemirror-model";
|
|
19
19
|
/**
|
|
20
20
|
* A border a host asks folio to apply.
|
|
21
21
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DisplayMode } from "../managers/EditorModeManager.js";
|
|
2
2
|
import { document_d_exports } from "../types/document.js";
|
|
3
3
|
import { FindMatch, FindOptions, FindSearchContext } from "../utils/findReplace.js";
|
|
4
|
-
import { Node } from "prosemirror-model";
|
|
5
4
|
import { EditorState } from "prosemirror-state";
|
|
5
|
+
import { Node } from "prosemirror-model";
|
|
6
6
|
/**
|
|
7
7
|
* Positional fields of a document search match that the range resolver needs.
|
|
8
8
|
*
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* the plain text an untracked removal leaves.
|
|
12
12
|
*/
|
|
13
13
|
import { TaggedErrorClass } from "better-result";
|
|
14
|
-
import { Node } from "prosemirror-model";
|
|
15
14
|
import { EditorState, Transaction } from "prosemirror-state";
|
|
15
|
+
import { Node } from "prosemirror-model";
|
|
16
16
|
declare const HyperlinkRemovalRefusalBase: TaggedErrorClass<"HyperlinkRemovalRefusal">;
|
|
17
17
|
export declare class HyperlinkRemovalRefusal extends HyperlinkRemovalRefusalBase<{
|
|
18
18
|
message: string;
|
|
@@ -20,7 +20,6 @@ import "./conversion/index.js";
|
|
|
20
20
|
import { ToProseDocOptions, createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
|
|
21
21
|
import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
|
|
22
22
|
import { getListInfo, isInList } from "./extensions/features/ListExtension.js";
|
|
23
|
-
import { ensureParaIdsInState } from "./extensions/features/ParaIdAllocatorExtension.js";
|
|
24
23
|
import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensions/marks/HyperlinkExtension.js";
|
|
25
24
|
import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
|
|
26
25
|
import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
|
|
@@ -28,6 +27,7 @@ import { TableBorderCommandSpec, TableCellBorderCommandSpec } from "./extensions
|
|
|
28
27
|
import { insertPageBreakInView, insertTableInView, insertTableOfContentsInView } from "./insertOperations.js";
|
|
29
28
|
import { ListNumberingMenuState, NO_LIST_NUMBERING_MENU, listNumberingMenuState } from "./listNumbering.js";
|
|
30
29
|
import { ActiveListState, ListState, ListType, NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
|
|
30
|
+
import { ensureParaIdsInState } from "./paraIds.js";
|
|
31
31
|
import { documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./plugins/documentStyleState.js";
|
|
32
32
|
import { createDocumentStylesPlugin } from "./plugins/documentStyles.js";
|
|
33
33
|
import "./plugins/index.js";
|
|
@@ -8,13 +8,13 @@ import { fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.j
|
|
|
8
8
|
import { createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
|
|
9
9
|
import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
|
|
10
10
|
import { getListInfo, isInList } from "./extensions/features/ListExtension.js";
|
|
11
|
-
import { ensureParaIdsInState } from "./extensions/features/ParaIdAllocatorExtension.js";
|
|
12
11
|
import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensions/marks/HyperlinkExtension.js";
|
|
13
12
|
import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
|
|
14
13
|
import { getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
|
|
15
14
|
import { insertPageBreakInView, insertTableInView, insertTableOfContentsInView } from "./insertOperations.js";
|
|
16
15
|
import { NO_LIST_NUMBERING_MENU, listNumberingMenuState } from "./listNumbering.js";
|
|
17
16
|
import { NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
|
|
17
|
+
import { ensureParaIdsInState } from "./paraIds.js";
|
|
18
18
|
import { documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleResolver } from "./plugins/documentStyleState.js";
|
|
19
19
|
import { createDocumentStylesPlugin } from "./plugins/documentStyles.js";
|
|
20
20
|
import { createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./plugins/selectionTracker.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Node } from "prosemirror-model";
|
|
2
1
|
import { Transaction } from "prosemirror-state";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
3
3
|
/** The gap a block put on `side` of the block at `boundary` lands in. */
|
|
4
4
|
export declare const insertionGap: (doc: Node, boundary: number, side: "before" | "after") => number;
|
|
5
5
|
/**
|