@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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { recreateProseNodeWithParagraphPropertySource, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource } from "../docx/paragraphPropertySource.js";
|
|
2
|
+
import { prosePositionalParagraphId } from "../docx/unnamedParagraphIds.js";
|
|
3
|
+
import { deterministicHexId } from "../utils/hexId.js";
|
|
4
|
+
import { ignoreTrackedChanges } from "./paragraphChangeTrackerMeta.js";
|
|
5
|
+
import { createPluginKeyOwner } from "./pluginKeyOwner.js";
|
|
6
|
+
import { Fragment } from "prosemirror-model";
|
|
7
|
+
// src/prosemirror/paraIds.ts
|
|
8
|
+
/**
|
|
9
|
+
* Paragraph-id allocation shared by load-time seeding and the live
|
|
10
|
+
* allocator plugin (`ParaIdAllocatorExtension`).
|
|
11
|
+
*
|
|
12
|
+
* Split out of
|
|
13
|
+
* https://github.com/eigenpal/docx-editor/blob/main/packages/core/src/prosemirror/extensions/features/ParaIdAllocatorExtension.ts
|
|
14
|
+
* (Apache-2.0); see that module for the id lifecycle rules.
|
|
15
|
+
*/
|
|
16
|
+
const paraIdAllocatorKey = createPluginKeyOwner("paraIdAllocator");
|
|
17
|
+
/**
|
|
18
|
+
* Transaction meta asking this plugin to derive the ids it mints from a
|
|
19
|
+
* caller-supplied seed instead of `Math.random()`.
|
|
20
|
+
*
|
|
21
|
+
* A live editor wants random ids: two people typing must not collide. A
|
|
22
|
+
* generator whose whole output has to be reproducible — the document compare —
|
|
23
|
+
* cannot afford them, and it is the only party that knows its run is meant to
|
|
24
|
+
* be deterministic, so it says so on its own transaction rather than leaving
|
|
25
|
+
* the plugin to guess.
|
|
26
|
+
*/
|
|
27
|
+
const deterministicParaIdSeedKey = "stll.folio.meta.deterministicParaIdSeed";
|
|
28
|
+
/** Ask the allocator to mint reproducible ids for the paragraphs `tr` creates. */
|
|
29
|
+
const requestDeterministicParaIds = (tr, seed) => tr.setMeta(deterministicParaIdSeedKey, seed);
|
|
30
|
+
const isUsableParaId = (value) => typeof value === "string" && value.length > 0 && value !== "00000000";
|
|
31
|
+
/** Omitted grid cells render absent positions and own no package paragraphs. */
|
|
32
|
+
const isOmittedGridCell = (node) => (node.type.spec["tableRole"] === "cell" || node.type.spec["tableRole"] === "header_cell") && (node.attrs["_omittedGridSlot"] === "before" || node.attrs["_omittedGridSlot"] === "after");
|
|
33
|
+
const visitAuthoredParagraphs = (doc, visit) => {
|
|
34
|
+
doc.descendants((node, pos) => {
|
|
35
|
+
if (isOmittedGridCell(node)) return false;
|
|
36
|
+
if (node.type.name !== "paragraph") return true;
|
|
37
|
+
visit(node, pos);
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The ids a loaded document's paragraphs take, in document order: `null`
|
|
43
|
+
* keeps the paragraph's own id, a string replaces it.
|
|
44
|
+
*
|
|
45
|
+
* This is the only load-time allocator. The live editor and the headless
|
|
46
|
+
* reviewer both seed through it, so the same document gives the same block ids
|
|
47
|
+
* on either side: an id read from the editor resolves when the edit is applied
|
|
48
|
+
* headlessly, and re-parsing the same bytes mints the same ids. A paragraph
|
|
49
|
+
* the package names no id for takes the id its place in the package gives it
|
|
50
|
+
* (the one `ensureParaIds` writes, so a canonical session agrees); one the
|
|
51
|
+
* parser could not place, such as a paragraph a host built, takes an id
|
|
52
|
+
* derived from its text and its document ordinal, never drawn at random.
|
|
53
|
+
* Authored ids are reserved first, so a minted id never takes one a later
|
|
54
|
+
* paragraph owns; of a duplicated authored id, the first occurrence keeps it.
|
|
55
|
+
*/
|
|
56
|
+
const planLoadParaIds = (doc) => {
|
|
57
|
+
const paragraphs = [];
|
|
58
|
+
const taken = /* @__PURE__ */ new Set();
|
|
59
|
+
visitAuthoredParagraphs(doc, (node) => {
|
|
60
|
+
paragraphs.push(node);
|
|
61
|
+
const id = node.attrs["paraId"];
|
|
62
|
+
if (isUsableParaId(id)) {
|
|
63
|
+
taken.add(id);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const positional = prosePositionalParagraphId(node);
|
|
67
|
+
if (positional !== void 0) taken.add(positional);
|
|
68
|
+
});
|
|
69
|
+
const kept = /* @__PURE__ */ new Set();
|
|
70
|
+
return paragraphs.map((paragraph, index) => {
|
|
71
|
+
const id = paragraph.attrs["paraId"];
|
|
72
|
+
if (isUsableParaId(id) && !kept.has(id)) {
|
|
73
|
+
kept.add(id);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const positional = prosePositionalParagraphId(paragraph);
|
|
77
|
+
if (positional !== void 0 && !kept.has(positional)) {
|
|
78
|
+
kept.add(positional);
|
|
79
|
+
return positional;
|
|
80
|
+
}
|
|
81
|
+
const seed = `${paragraph.textContent}:${String(index + 1)}`;
|
|
82
|
+
let minted = deterministicHexId(seed);
|
|
83
|
+
for (let salt = 1; taken.has(minted); salt++) minted = deterministicHexId(`${seed}:${String(salt)}`);
|
|
84
|
+
taken.add(minted);
|
|
85
|
+
return minted;
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
/** A paragraph's attrs once it holds an id folio minted rather than read. */
|
|
89
|
+
const mintedParagraphAttrs = (paragraph, paraId) => ({
|
|
90
|
+
...paragraph.attrs,
|
|
91
|
+
paraId,
|
|
92
|
+
...paragraph.type.spec.attrs?.["idStability"] !== void 0 && { idStability: "positional" }
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Allocate initial paragraph IDs before constructing editor state.
|
|
96
|
+
*
|
|
97
|
+
* Rebuilding only changed branches avoids applying one ProseMirror transaction
|
|
98
|
+
* step per missing paragraph. Live edits still use the transaction-based plugin
|
|
99
|
+
* below so history, mappings, and duplicate ownership retain their semantics.
|
|
100
|
+
*/
|
|
101
|
+
const ensureParaIdsInDoc = (doc) => {
|
|
102
|
+
const plan = planLoadParaIds(doc);
|
|
103
|
+
if (plan.every((paraId) => paraId === null)) return doc;
|
|
104
|
+
let ordinal = 0;
|
|
105
|
+
const rewrite = (parent) => {
|
|
106
|
+
let changed = false;
|
|
107
|
+
const children = [];
|
|
108
|
+
parent.forEach((child) => {
|
|
109
|
+
if (isOmittedGridCell(child)) {
|
|
110
|
+
children.push(child);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let next = child;
|
|
114
|
+
if (child.type.name === "paragraph") {
|
|
115
|
+
const minted = plan[ordinal];
|
|
116
|
+
ordinal += 1;
|
|
117
|
+
if (minted !== null && minted !== void 0) next = recreateProseNodeWithParagraphPropertySource(child, { attrs: mintedParagraphAttrs(child, minted) });
|
|
118
|
+
const paraId = next.attrs["paraId"];
|
|
119
|
+
if (typeof paraId === "string") transferProseParagraphPropertySource(next, child, paraId);
|
|
120
|
+
} else if (child.childCount > 0) {
|
|
121
|
+
const content = rewrite(child);
|
|
122
|
+
if (content !== child.content) next = recreateProseNodeWithParagraphPropertySource(child, { content });
|
|
123
|
+
}
|
|
124
|
+
if (next !== child) changed = true;
|
|
125
|
+
children.push(next);
|
|
126
|
+
});
|
|
127
|
+
return changed ? Fragment.fromArray(children) : parent.content;
|
|
128
|
+
};
|
|
129
|
+
return recreateProseNodeWithParagraphPropertySource(doc, { content: rewrite(doc) });
|
|
130
|
+
};
|
|
131
|
+
/** {@link ensureParaIdsInDoc} for a state that already exists. */
|
|
132
|
+
const ensureParaIdsInState = (state) => {
|
|
133
|
+
const plan = planLoadParaIds(state.doc);
|
|
134
|
+
if (plan.every((paraId) => paraId === null)) return state;
|
|
135
|
+
const tr = state.tr;
|
|
136
|
+
let ordinal = 0;
|
|
137
|
+
visitAuthoredParagraphs(state.doc, (node, pos) => {
|
|
138
|
+
const minted = plan[ordinal];
|
|
139
|
+
ordinal += 1;
|
|
140
|
+
if (minted !== null && minted !== void 0) setProseParagraphMarkupWithPropertySource({
|
|
141
|
+
attrs: mintedParagraphAttrs(node, minted),
|
|
142
|
+
ownership: "transfer-allocated-id",
|
|
143
|
+
pos,
|
|
144
|
+
transaction: tr
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
ignoreTrackedChanges(tr);
|
|
148
|
+
tr.setMeta(paraIdAllocatorKey, "allocated");
|
|
149
|
+
tr.setMeta("addToHistory", false);
|
|
150
|
+
return state.apply(tr);
|
|
151
|
+
};
|
|
152
|
+
export { deterministicParaIdSeedKey, ensureParaIdsInDoc, ensureParaIdsInState, isUsableParaId, paraIdAllocatorKey, requestDeterministicParaIds, visitAuthoredParagraphs };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction meta the paragraph change tracker reads, and the state it
|
|
3
|
+
* keeps. Commands state what an edit did through these setters; only the
|
|
4
|
+
* tracker plugin (`ParagraphChangeTrackerExtension`) reads them.
|
|
5
|
+
*/
|
|
6
|
+
import { RemovedSectionReference, TrackedSectionEndpointRemoval } from "../internal/sectionEndpointResolution.js";
|
|
7
|
+
import { document_d_exports } from "../types/document.js";
|
|
8
|
+
import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
|
|
9
|
+
import { Node } from "prosemirror-model";
|
|
10
|
+
export declare const paragraphChangeTrackerKey: Readonly<{
|
|
11
|
+
key: string;
|
|
12
|
+
createKey: () => PluginKey<InternalParagraphChangeTrackerState>;
|
|
13
|
+
owns: (plugin: Plugin<InternalParagraphChangeTrackerState>) => boolean;
|
|
14
|
+
get: (state: EditorState) => Plugin<InternalParagraphChangeTrackerState> | undefined;
|
|
15
|
+
getState: (state: EditorState) => InternalParagraphChangeTrackerState | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const CLEAR_META = "clear";
|
|
18
|
+
export declare const IGNORE_META = "ignore";
|
|
19
|
+
export declare const STRUCTURAL_META = "structural";
|
|
20
|
+
export declare const CHANGED_PARAGRAPH_RANGES_META = "folioChangedParagraphRanges";
|
|
21
|
+
export declare const SECTION_ENDPOINT_REMOVAL_META = "folioSectionEndpointRemoval";
|
|
22
|
+
export type ChangedParagraphRangeBatch = {
|
|
23
|
+
ranges: readonly {
|
|
24
|
+
from: number;
|
|
25
|
+
to: number;
|
|
26
|
+
}[];
|
|
27
|
+
mappingFrom: number;
|
|
28
|
+
replacesStepMapAt?: number;
|
|
29
|
+
};
|
|
30
|
+
type ChangedParagraphRangesMeta = {
|
|
31
|
+
type: "changed-paragraph-ranges";
|
|
32
|
+
batches: readonly ChangedParagraphRangeBatch[];
|
|
33
|
+
};
|
|
34
|
+
export declare const isChangedParagraphRangesMeta: (value: unknown) => value is ChangedParagraphRangesMeta;
|
|
35
|
+
export declare const isTrackedSectionEndpointRemoval: (value: unknown) => value is TrackedSectionEndpointRemoval;
|
|
36
|
+
type TrackedSectionEndpointRemovalMeta = {
|
|
37
|
+
type: "tracked-section-endpoint-removal-meta";
|
|
38
|
+
authorization: TrackedSectionEndpointRemoval;
|
|
39
|
+
};
|
|
40
|
+
export declare const isTrackedSectionEndpointRemovalMeta: (value: unknown) => value is TrackedSectionEndpointRemovalMeta;
|
|
41
|
+
export type ParagraphChangeTrackerState = {
|
|
42
|
+
/** Set of paraIds that were modified since last clear */
|
|
43
|
+
changedParaIds: Set<string>;
|
|
44
|
+
/** Whether paragraph order, membership, or block structure changed. */
|
|
45
|
+
structuralChange: boolean;
|
|
46
|
+
/** Whether edited paragraphs still lack IDs or source identity was unavailable. */
|
|
47
|
+
hasUntrackedChanges: boolean;
|
|
48
|
+
/** Paragraph count in the current tracked document. */
|
|
49
|
+
paragraphCount: number;
|
|
50
|
+
/** Cached section-endpoint count used to invalidate stale save authorization. */
|
|
51
|
+
sectionEndpointCount: number;
|
|
52
|
+
/** Exact endpoint owners and properties used to invalidate count-neutral changes. */
|
|
53
|
+
sectionEndpointFingerprint: string;
|
|
54
|
+
/** Exact tracked-resolution transition that may reduce the saved section count. */
|
|
55
|
+
sectionEndpointRemoval: TrackedSectionEndpointRemoval | null;
|
|
56
|
+
};
|
|
57
|
+
export type InternalParagraphChangeTrackerState = ParagraphChangeTrackerState & {
|
|
58
|
+
/** Edited paragraph positions retained across allocator-only transactions. */
|
|
59
|
+
affectedParagraphPositions: Set<number>;
|
|
60
|
+
/** Editing an already unidentified source paragraph cannot become selective. */
|
|
61
|
+
hasUntrackedSourceChanges: boolean;
|
|
62
|
+
blockStructureFingerprint: string;
|
|
63
|
+
/** The section records themselves, by identity. */
|
|
64
|
+
sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
|
|
65
|
+
};
|
|
66
|
+
export declare const referencesOf: (records: readonly document_d_exports.SectionProperties[]) => RemovedSectionReference[];
|
|
67
|
+
type MarkTrackedSectionEndpointRemovalOptions = {
|
|
68
|
+
sourceDoc: Node;
|
|
69
|
+
removedEndpointCount: number;
|
|
70
|
+
removedReferences: readonly RemovedSectionReference[];
|
|
71
|
+
};
|
|
72
|
+
/** Record only a complete, internally consistent endpoint-removal transition. */
|
|
73
|
+
export declare function markTrackedSectionEndpointRemoval(tr: Transaction, { sourceDoc, removedEndpointCount, removedReferences }: MarkTrackedSectionEndpointRemovalOptions): Transaction;
|
|
74
|
+
/**
|
|
75
|
+
* Record that `tr` removed section breaks on purpose: a command whose job is
|
|
76
|
+
* to remove the break (not to delete its paragraph mark, which the tracker
|
|
77
|
+
* reads for itself). Only a plain removal is recorded; a transaction that also
|
|
78
|
+
* adds or replaces a record is left as it is.
|
|
79
|
+
*/
|
|
80
|
+
export declare function markSectionBreakRemoval(tr: Transaction, sourceDoc: Node): Transaction;
|
|
81
|
+
/**
|
|
82
|
+
* Create a transaction that clears the change tracker
|
|
83
|
+
*/
|
|
84
|
+
export declare function clearTrackedChanges(state: EditorState): Transaction;
|
|
85
|
+
export declare function ignoreTrackedChanges(tr: Transaction): Transaction;
|
|
86
|
+
export declare function markStructuralChange(tr: Transaction): Transaction;
|
|
87
|
+
type MarkChangedParagraphRangesOptions = {
|
|
88
|
+
ranges: readonly {
|
|
89
|
+
from: number;
|
|
90
|
+
to: number;
|
|
91
|
+
}[];
|
|
92
|
+
mappingFrom: number;
|
|
93
|
+
replacesStepMapAt?: number;
|
|
94
|
+
};
|
|
95
|
+
/** Record mark-only paragraph changes whose replacement step has a granular map. */
|
|
96
|
+
export declare function markChangedParagraphRanges(tr: Transaction, batch: MarkChangedParagraphRangesOptions): Transaction;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { countDocumentStructure } from "./documentStructureCounts.js";
|
|
2
|
+
import { createPluginKeyOwner } from "./pluginKeyOwner.js";
|
|
3
|
+
// src/prosemirror/paragraphChangeTrackerMeta.ts
|
|
4
|
+
const paragraphChangeTrackerKey = createPluginKeyOwner("paragraphChangeTracker");
|
|
5
|
+
const CLEAR_META = "clear";
|
|
6
|
+
const IGNORE_META = "ignore";
|
|
7
|
+
const STRUCTURAL_META = "structural";
|
|
8
|
+
const CHANGED_PARAGRAPH_RANGES_META = "folioChangedParagraphRanges";
|
|
9
|
+
const SECTION_ENDPOINT_REMOVAL_META = "folioSectionEndpointRemoval";
|
|
10
|
+
const isChangedParagraphRangesMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "changed-paragraph-ranges";
|
|
11
|
+
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";
|
|
12
|
+
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);
|
|
13
|
+
const isTrackedSectionEndpointRemovalMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "tracked-section-endpoint-removal-meta" && "authorization" in value && isTrackedSectionEndpointRemoval(value.authorization);
|
|
14
|
+
const referencesOf = (records) => {
|
|
15
|
+
const references = [];
|
|
16
|
+
for (const record of records) {
|
|
17
|
+
for (const { type, rId } of record.headerReferences ?? []) references.push({
|
|
18
|
+
part: "header",
|
|
19
|
+
type,
|
|
20
|
+
relationshipId: rId
|
|
21
|
+
});
|
|
22
|
+
for (const { type, rId } of record.footerReferences ?? []) references.push({
|
|
23
|
+
part: "footer",
|
|
24
|
+
type,
|
|
25
|
+
relationshipId: rId
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return references;
|
|
29
|
+
};
|
|
30
|
+
/** Record only a complete, internally consistent endpoint-removal transition. */
|
|
31
|
+
function markTrackedSectionEndpointRemoval(tr, { sourceDoc, removedEndpointCount, removedReferences }) {
|
|
32
|
+
const sourceStructure = countDocumentStructure(sourceDoc);
|
|
33
|
+
const sourceParagraphEndpointCount = sourceStructure.sectionEndpoints;
|
|
34
|
+
const expectedStructure = countDocumentStructure(tr.doc);
|
|
35
|
+
const expectedParagraphEndpointCount = expectedStructure.sectionEndpoints;
|
|
36
|
+
if (sourceParagraphEndpointCount - expectedParagraphEndpointCount !== removedEndpointCount) return tr;
|
|
37
|
+
return tr.setMeta(SECTION_ENDPOINT_REMOVAL_META, {
|
|
38
|
+
type: "tracked-section-endpoint-removal-meta",
|
|
39
|
+
authorization: {
|
|
40
|
+
type: "tracked-section-endpoint-removal",
|
|
41
|
+
sourceParagraphEndpointCount,
|
|
42
|
+
expectedParagraphEndpointCount,
|
|
43
|
+
sourceEndpointFingerprint: sourceStructure.sectionEndpointFingerprint,
|
|
44
|
+
expectedEndpointFingerprint: expectedStructure.sectionEndpointFingerprint,
|
|
45
|
+
removedReferences
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record that `tr` removed section breaks on purpose: a command whose job is
|
|
51
|
+
* to remove the break (not to delete its paragraph mark, which the tracker
|
|
52
|
+
* reads for itself). Only a plain removal is recorded; a transaction that also
|
|
53
|
+
* adds or replaces a record is left as it is.
|
|
54
|
+
*/
|
|
55
|
+
function markSectionBreakRemoval(tr, sourceDoc) {
|
|
56
|
+
const before = countDocumentStructure(sourceDoc).sectionRecords;
|
|
57
|
+
const after = countDocumentStructure(tr.doc).sectionRecords;
|
|
58
|
+
const removed = [...before].filter((record) => !after.has(record));
|
|
59
|
+
if (removed.length === 0 || [...after].some((record) => !before.has(record))) return tr;
|
|
60
|
+
return markTrackedSectionEndpointRemoval(tr, {
|
|
61
|
+
sourceDoc,
|
|
62
|
+
removedEndpointCount: removed.length,
|
|
63
|
+
removedReferences: referencesOf(removed)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a transaction that clears the change tracker
|
|
68
|
+
*/
|
|
69
|
+
function clearTrackedChanges(state) {
|
|
70
|
+
return state.tr.setMeta(paragraphChangeTrackerKey, CLEAR_META);
|
|
71
|
+
}
|
|
72
|
+
function ignoreTrackedChanges(tr) {
|
|
73
|
+
return tr.setMeta(paragraphChangeTrackerKey, IGNORE_META);
|
|
74
|
+
}
|
|
75
|
+
function markStructuralChange(tr) {
|
|
76
|
+
return tr.setMeta(paragraphChangeTrackerKey, STRUCTURAL_META);
|
|
77
|
+
}
|
|
78
|
+
/** Record mark-only paragraph changes whose replacement step has a granular map. */
|
|
79
|
+
function markChangedParagraphRanges(tr, batch) {
|
|
80
|
+
const previous = tr.getMeta(CHANGED_PARAGRAPH_RANGES_META);
|
|
81
|
+
const batches = isChangedParagraphRangesMeta(previous) ? [...previous.batches, batch] : [batch];
|
|
82
|
+
return tr.setMeta(CHANGED_PARAGRAPH_RANGES_META, {
|
|
83
|
+
type: "changed-paragraph-ranges",
|
|
84
|
+
batches
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export { CHANGED_PARAGRAPH_RANGES_META, CLEAR_META, IGNORE_META, SECTION_ENDPOINT_REMOVAL_META, STRUCTURAL_META, clearTrackedChanges, ignoreTrackedChanges, isChangedParagraphRangesMeta, isTrackedSectionEndpointRemoval, isTrackedSectionEndpointRemovalMeta, markChangedParagraphRanges, markSectionBreakRemoval, markStructuralChange, markTrackedSectionEndpointRemoval, paragraphChangeTrackerKey, referencesOf };
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* lent them is re-read in the next paragraph's style.
|
|
15
15
|
*/
|
|
16
16
|
import { RunStyleResolver } from "./runStyleFormatting.js";
|
|
17
|
-
import { Node } from "prosemirror-model";
|
|
18
17
|
import { Transaction } from "prosemirror-state";
|
|
18
|
+
import { Node } from "prosemirror-model";
|
|
19
19
|
/** The two paragraphs a join runs together, and what stands between them. */
|
|
20
20
|
type JoinSides = {
|
|
21
21
|
/** The paragraph whose mark goes. */
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
import { NumberingMap } from "../docx/numberingParser.js";
|
|
14
14
|
import { RunStyleResolver } from "./runStyleFormatting.js";
|
|
15
15
|
import { ParagraphPropertyChangeAttrs } from "./schema/nodes.js";
|
|
16
|
-
import { Node } from "prosemirror-model";
|
|
17
16
|
import { Transaction } from "prosemirror-state";
|
|
17
|
+
import { Node } from "prosemirror-model";
|
|
18
18
|
type RecordedFormatting = NonNullable<ParagraphPropertyChangeAttrs["previousFormatting"]>;
|
|
19
19
|
export declare const paragraphPropertySnapshotsDiffer: (left: RecordedFormatting, right: RecordedFormatting) => boolean;
|
|
20
20
|
type CarryParagraphPropertiesOptions = {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { Comment } from "../types/content.js";
|
|
23
23
|
import { PastedRepeat, PlacedRange } from "./pastePlacement.js";
|
|
24
|
-
import { Node, Slice } from "prosemirror-model";
|
|
25
24
|
import { Transaction } from "prosemirror-state";
|
|
25
|
+
import { Node, Slice } from "prosemirror-model";
|
|
26
26
|
/** The comments a paste carries, for settling them where they are placed. */
|
|
27
27
|
export type PastedComments = {
|
|
28
28
|
/** The comment each fresh id the slice's anchors took stands for. */
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* plugin rescans on that and on every `docChanged` transaction.
|
|
17
17
|
*/
|
|
18
18
|
import { PluginKeyOwner } from "../pluginKeyOwner.js";
|
|
19
|
-
import { Node } from "prosemirror-model";
|
|
20
19
|
import { EditorState, Plugin } from "prosemirror-state";
|
|
20
|
+
import { Node } from "prosemirror-model";
|
|
21
21
|
declare const SET_META = "set";
|
|
22
22
|
export type DocScanState<TConfig, TRange> = {
|
|
23
23
|
config: TConfig;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Document-scoped numbering definitions for list-editing commands. */
|
|
2
2
|
import { NumberingMap } from "../../docx/numberingParser.js";
|
|
3
3
|
import { document_d_exports } from "../../types/document.js";
|
|
4
|
-
import { Node } from "prosemirror-model";
|
|
5
4
|
import { EditorState, Plugin } from "prosemirror-state";
|
|
5
|
+
import { Node } from "prosemirror-model";
|
|
6
6
|
export declare const createDocumentNumberingPlugin: (definitions: document_d_exports.NumberingDefinitions | null | undefined) => Plugin;
|
|
7
7
|
/** Numbering derived from a document when no editor plugin owns package definitions. */
|
|
8
8
|
export declare const getDocumentNumberingForDoc: (doc: Node) => NumberingMap | null;
|
|
@@ -2,8 +2,8 @@ import { getCachedNumberingMap } from "../../docx/numberingParser.js";
|
|
|
2
2
|
import { completeNumberingForDoc, paragraphListReferences } from "../listInstanceReferences.js";
|
|
3
3
|
import { createPluginKeyOwner } from "../pluginKeyOwner.js";
|
|
4
4
|
import { panic } from "better-result";
|
|
5
|
-
import { AddMarkStep, DocAttrStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
|
|
6
5
|
import { Plugin } from "prosemirror-state";
|
|
6
|
+
import { AddMarkStep, DocAttrStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
|
|
7
7
|
// src/prosemirror/plugins/documentNumbering.ts
|
|
8
8
|
/** Document-scoped numbering definitions for list-editing commands. */
|
|
9
9
|
const documentNumberingKey = createPluginKeyOwner("documentNumbering");
|
|
@@ -4,9 +4,9 @@ import { StyleResolver, createStyleResolver } from "../styles/styleResolver.js";
|
|
|
4
4
|
import { getDocumentNumbering } from "./documentNumbering.js";
|
|
5
5
|
import { documentStylesKey, getDocumentBuiltInStyles, getDocumentStyleDefinitions, getDocumentStyleResolver } from "./documentStyleState.js";
|
|
6
6
|
import { resolveEditedParagraphStyles } from "./paragraphStyleResolution.js";
|
|
7
|
+
import { Plugin } from "prosemirror-state";
|
|
7
8
|
import { Mark } from "prosemirror-model";
|
|
8
9
|
import { Mapping, ReplaceStep } from "prosemirror-transform";
|
|
9
|
-
import { Plugin } from "prosemirror-state";
|
|
10
10
|
import { isHistoryTransaction } from "prosemirror-history";
|
|
11
11
|
// src/prosemirror/plugins/documentStyles.ts
|
|
12
12
|
/**
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* automatically.
|
|
17
17
|
*/
|
|
18
18
|
import { DocScanState } from "./createDocScanPlugin.js";
|
|
19
|
-
import { Node } from "prosemirror-model";
|
|
20
19
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
20
|
+
import { Node } from "prosemirror-model";
|
|
21
21
|
import { DirectiveKind } from "@stll/template-conditions";
|
|
22
22
|
export type DirectiveRange = {
|
|
23
23
|
/** Inclusive PM doc position of the marker start. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
-
import { Node } from "prosemirror-model";
|
|
3
2
|
import { Transaction } from "prosemirror-state";
|
|
3
|
+
import { Node } from "prosemirror-model";
|
|
4
4
|
import { Transform } from "prosemirror-transform";
|
|
5
5
|
type RebaseParagraphRunFormattingOptions = {
|
|
6
6
|
nextAttrs: Record<string, unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
|
-
import { Fragment, Mark, Node } from "prosemirror-model";
|
|
3
2
|
import { Transaction } from "prosemirror-state";
|
|
3
|
+
import { Fragment, Mark, Node } from "prosemirror-model";
|
|
4
4
|
/** Two contexts that lend runs the same formatting: rebasing between them changes nothing. */
|
|
5
5
|
export declare const sameRunStyleContext: (source: ParagraphRunStyleContext, target: ParagraphRunStyleContext) => boolean;
|
|
6
6
|
type RebaseParagraphRunsOptions = {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* (`runIdentityAcrossRevisions.ts`).
|
|
17
17
|
*/
|
|
18
18
|
import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
|
|
19
|
-
import { Mark, Node } from "prosemirror-model";
|
|
20
19
|
import { Transaction } from "prosemirror-state";
|
|
20
|
+
import { Mark, Node } from "prosemirror-model";
|
|
21
21
|
type ContinuedRunMarksOptions = {
|
|
22
22
|
left: Node;
|
|
23
23
|
right: Node;
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
* canonical guard refuses point transitions whose outcome is not proven.
|
|
64
64
|
*/
|
|
65
65
|
import { document_d_exports } from "../types/document.js";
|
|
66
|
-
import { Fragment, Mark, Node, Schema } from "prosemirror-model";
|
|
67
66
|
import { Transaction } from "prosemirror-state";
|
|
67
|
+
import { Fragment, Mark, Node, Schema } from "prosemirror-model";
|
|
68
68
|
/**
|
|
69
69
|
* What a replacement does with each mark the schema declares
|
|
70
70
|
* `inclusive: false`. Boundary inheritance already handles every other mark,
|
|
@@ -12,8 +12,8 @@ import { readMoveRangeBoundaryAttrs } from "./moveRangeBoundaryAttrs.js";
|
|
|
12
12
|
import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
|
|
13
13
|
import { isZeroWidthAnchor } from "./zeroWidthAnchors.js";
|
|
14
14
|
import { panic } from "better-result";
|
|
15
|
-
import { Fragment, Mark } from "prosemirror-model";
|
|
16
15
|
import { isCommentExhausted, withoutCommentThreads } from "@stll/docx-core/ops";
|
|
16
|
+
import { Fragment, Mark } from "prosemirror-model";
|
|
17
17
|
// src/prosemirror/replacedAnnotations.ts
|
|
18
18
|
/**
|
|
19
19
|
* What survives when an edit replaces a span of inline content.
|
|
@@ -270,6 +270,17 @@ const rangedCommentLeaves = (visit) => (node, position) => {
|
|
|
270
270
|
return false;
|
|
271
271
|
};
|
|
272
272
|
/**
|
|
273
|
+
* Whether every word each of `ids` covers lies inside a change, so that
|
|
274
|
+
* accepting the tracked replacement leaves those comments nothing to cover.
|
|
275
|
+
*/
|
|
276
|
+
const coveredOnlyInside = ({ doc, changes, ids }) => {
|
|
277
|
+
let outside = false;
|
|
278
|
+
doc.descendants(rangedCommentLeaves((leafIds, from, to) => {
|
|
279
|
+
if (!changes.some((change) => change.from <= from && to <= change.to) && leafIds.some((id) => ids.has(id))) outside = true;
|
|
280
|
+
}));
|
|
281
|
+
return !outside;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
273
284
|
* The comment threads a direct replacement takes with its words: each root
|
|
274
285
|
* whose every accepted covered word lies inside a change, with its replies.
|
|
275
286
|
* Accepting the tracked replacement leaves such a root nothing to cover, so
|
|
@@ -362,7 +373,11 @@ const preservesReplacementCommentAlignment = ({ doc, source, changes, retiredCom
|
|
|
362
373
|
containers: "descend"
|
|
363
374
|
}).carried.filter((mark) => mark.type.name === "comment" && !retired.has(mark.attrs["commentId"]));
|
|
364
375
|
if (comments.some((mark) => mark.attrs["point"] === true)) return false;
|
|
365
|
-
if (change.markers === "selected" && comments.length > 0)
|
|
376
|
+
if (change.markers === "selected" && comments.length > 0 && (removal.type === "direct" || !doc.resolve(change.from).sameParent(doc.resolve(change.to)) || !coveredOnlyInside({
|
|
377
|
+
doc,
|
|
378
|
+
changes,
|
|
379
|
+
ids: new Set(comments.map((mark) => Number(mark.attrs["commentId"])))
|
|
380
|
+
}))) return false;
|
|
366
381
|
if (removal.type === "tracked") continue;
|
|
367
382
|
let internalCarrier = false;
|
|
368
383
|
doc.nodesBetween(change.from, change.to, (node, position) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Mark, Node } from "prosemirror-model";
|
|
2
1
|
import { Transaction } from "prosemirror-state";
|
|
2
|
+
import { Mark, Node } from "prosemirror-model";
|
|
3
3
|
export type RunFormattingInlineAtomDisposition = "break-run" | "field-run" | "not-a-run" | "note-marker-run" | "page-break-carrier" | "preserved-xml-run" | "structured-field" | "symbol-run" | "tab-run" | "text-run";
|
|
4
4
|
/**
|
|
5
5
|
* How every inline atom maps to a serialized run-formatting carrier.
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* @packageDocumentation
|
|
18
18
|
*/
|
|
19
19
|
import { document_d_exports } from "../types/document.js";
|
|
20
|
-
import { Node } from "prosemirror-model";
|
|
21
20
|
import { Transaction } from "prosemirror-state";
|
|
21
|
+
import { Node } from "prosemirror-model";
|
|
22
22
|
export type SectionMarkEdits = {
|
|
23
23
|
/** Section records whose paragraph mark a replacement deleted. */
|
|
24
24
|
deletedMarks: ReadonlySet<document_d_exports.SectionProperties>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Selection } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* A selection's outer bounds. Selected cells keep the head cell as their
|
|
4
|
+
* primary range, so `from` and `to` alone miss the other cells; the bounds
|
|
5
|
+
* run from the first selected cell to the last, in either direction.
|
|
6
|
+
*/
|
|
7
|
+
export declare const selectionBounds: ({ ranges }: Pick<Selection, "ranges">) => {
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/prosemirror/selectionBounds.ts
|
|
2
|
+
/**
|
|
3
|
+
* A selection's outer bounds. Selected cells keep the head cell as their
|
|
4
|
+
* primary range, so `from` and `to` alone miss the other cells; the bounds
|
|
5
|
+
* run from the first selected cell to the last, in either direction.
|
|
6
|
+
*/
|
|
7
|
+
const selectionBounds = ({ ranges }) => {
|
|
8
|
+
let from = Number.POSITIVE_INFINITY;
|
|
9
|
+
let to = Number.NEGATIVE_INFINITY;
|
|
10
|
+
for (const { $from, $to } of ranges) {
|
|
11
|
+
from = Math.min(from, $from.pos);
|
|
12
|
+
to = Math.max(to, $to.pos);
|
|
13
|
+
}
|
|
14
|
+
return Number.isFinite(from) ? {
|
|
15
|
+
from,
|
|
16
|
+
to
|
|
17
|
+
} : {
|
|
18
|
+
from: 0,
|
|
19
|
+
to: 0
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export { selectionBounds };
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* list keeps its own definition.
|
|
10
10
|
*/
|
|
11
11
|
import { document_d_exports } from "../types/document.js";
|
|
12
|
-
import { Node } from "prosemirror-model";
|
|
13
12
|
import { EditorState } from "prosemirror-state";
|
|
13
|
+
import { Node } from "prosemirror-model";
|
|
14
14
|
type StoryListNumbering = {
|
|
15
15
|
/** The story with every colliding list moved to its own ids. */
|
|
16
16
|
doc: Node;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EditorState, Transaction } from "prosemirror-state";
|
|
2
|
+
import { Slice } from "prosemirror-model";
|
|
3
|
+
import { EditorView } from "prosemirror-view";
|
|
4
|
+
export declare const SUGGESTION_META = "suggestionModeApplied";
|
|
5
|
+
export declare const SUGGESTION_BYPASS_META = "suggestionModeBypass";
|
|
6
|
+
/** Text typed before list autoformat rules get to see it. */
|
|
7
|
+
export declare const SUGGESTED_TEXT_INPUT_META = "suggestionModeTextInput";
|
|
8
|
+
export type SuggestionMode = {
|
|
9
|
+
active: boolean;
|
|
10
|
+
author: string;
|
|
11
|
+
};
|
|
12
|
+
export type SuggestedRangeDeletion = {
|
|
13
|
+
state: EditorState;
|
|
14
|
+
tr: Transaction;
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
};
|
|
18
|
+
type SuggestionModeState = SuggestionMode & {
|
|
19
|
+
commands: {
|
|
20
|
+
paste: (view: EditorView, slice: Slice, mode: SuggestionMode) => boolean;
|
|
21
|
+
deleteRange: (range: SuggestedRangeDeletion) => boolean;
|
|
22
|
+
deleteSelection: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const suggestionModeKey: Readonly<{
|
|
26
|
+
key: string;
|
|
27
|
+
createKey: () => import("prosemirror-state").PluginKey<SuggestionModeState>;
|
|
28
|
+
owns: (plugin: import("prosemirror-state").Plugin<SuggestionModeState>) => boolean;
|
|
29
|
+
get: (state: EditorState) => import("prosemirror-state").Plugin<SuggestionModeState> | undefined;
|
|
30
|
+
getState: (state: EditorState) => SuggestionModeState | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const isSuggestionModeActive: (state: EditorState) => boolean;
|
|
33
|
+
export type SuggestionMarkAttrs = {
|
|
34
|
+
revisionId: number;
|
|
35
|
+
author: string;
|
|
36
|
+
date: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const makeMarkAttrs: ({ author }: SuggestionMode) => SuggestionMarkAttrs;
|
|
39
|
+
export declare const makeRevisionInfo: (state: EditorState) => {
|
|
40
|
+
id: number;
|
|
41
|
+
author: string;
|
|
42
|
+
date: string;
|
|
43
|
+
} | null;
|
|
44
|
+
export declare const pasteAsSuggestion: (view: EditorView, slice: Slice) => boolean;
|
|
45
|
+
export declare const suggestRangeDeletion: (range: SuggestedRangeDeletion) => boolean;
|
|
46
|
+
export declare const deleteSelectionAsSuggestion: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
|
|
47
|
+
export {};
|