@stll/folio-core 0.67.0 → 0.68.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/dist/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +29 -12
- package/dist/controller/canonicalComposition.js +1 -1
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +28 -1
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +327 -73
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +91 -37
- package/dist/controller/layoutPipeline.js +48 -15
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +17 -0
- package/dist/docx/hostCommentThreads.js +49 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +227 -96
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +6 -0
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +3 -1
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
- package/dist/i18n/messages/catalogs.gen.js +34 -0
- package/dist/i18n/messages/cs.gen.js +2 -0
- package/dist/i18n/messages/de.gen.js +2 -0
- package/dist/i18n/messages/en.gen.js +2 -0
- package/dist/i18n/messages/es.gen.js +2 -0
- package/dist/i18n/messages/et.gen.js +2 -0
- package/dist/i18n/messages/fr.gen.js +2 -0
- package/dist/i18n/messages/he.gen.js +2 -0
- package/dist/i18n/messages/hi.gen.js +2 -0
- package/dist/i18n/messages/hu.gen.js +2 -0
- package/dist/i18n/messages/lt.gen.js +2 -0
- package/dist/i18n/messages/lv.gen.js +2 -0
- package/dist/i18n/messages/messages.gen.d.ts +2 -0
- package/dist/i18n/messages/pl.gen.js +2 -0
- package/dist/i18n/messages/pt-BR.gen.js +2 -0
- package/dist/i18n/messages/sk.gen.js +2 -0
- package/dist/i18n/messages/tr.gen.js +2 -0
- package/dist/i18n/messages/zh-CN.gen.js +2 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +36 -1
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +46 -17
- package/dist/layout-painter/renderTable.js +7 -4
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +25 -0
- package/dist/prosemirror/commands/comments.js +102 -11
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +319 -51
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.js +20 -9
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/validation.js +1 -0
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CanonicalCommandIntent } from "./canonicalCommands.js";
|
|
2
|
+
import { Command, EditorState } from "prosemirror-state";
|
|
3
|
+
/**
|
|
4
|
+
* What an attribute-only table command does, as table formatting patches.
|
|
5
|
+
*
|
|
6
|
+
* The command runs against the state without dispatching to the view. Every
|
|
7
|
+
* table, row and cell whose attributes it changed lowers to a patch of the
|
|
8
|
+
* formatting the save would write for it, so the session applies exactly what
|
|
9
|
+
* the editor would have saved. A command that changes anything else (content,
|
|
10
|
+
* a node's type, a span) has no attribute lowering and stays refused.
|
|
11
|
+
*/
|
|
12
|
+
export declare const lowerTableAttributeCommand: (command: Command, state: EditorState) => readonly CanonicalCommandIntent[] | undefined;
|
|
13
|
+
/** Register a command whose whole effect is table, row and cell attributes. */
|
|
14
|
+
export declare const withCanonicalTableAttributeCommand: (command: Command) => Command;
|
|
15
|
+
export declare const withCanonicalColumnInsertion: (command: Command, side: "left" | "right") => Command;
|
|
16
|
+
export declare const withCanonicalColumnDeletion: (command: Command) => Command;
|
|
17
|
+
export declare const withCanonicalCellMerge: (command: Command) => Command;
|
|
18
|
+
export declare const withCanonicalCellSplit: (command: Command) => Command;
|
|
19
|
+
export declare const withCanonicalRowInsertion: (command: Command, side: "above" | "below") => Command;
|
|
20
|
+
export declare const withCanonicalRowDeletion: (command: Command) => Command;
|
|
21
|
+
export declare const withCanonicalTableDeletion: (command: Command) => Command;
|
|
22
|
+
/**
|
|
23
|
+
* Register the insert table command, lowered to a table and an empty
|
|
24
|
+
* paragraph after the paragraph that holds the caret, as the command places
|
|
25
|
+
* them. The table is the one the command built, without the revision marks
|
|
26
|
+
* it put on its rows; in suggesting mode the engine records its own.
|
|
27
|
+
*/
|
|
28
|
+
export declare const withCanonicalTableInsertion: (command: Command) => Command;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs } from "./attrs/index.js";
|
|
2
|
+
import { withCanonicalCommand } from "./canonicalCommands.js";
|
|
3
|
+
import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting, tableCellAttrsToFormatting, tableRowAttrsToFormatting } from "./conversion/fromProseDoc.js";
|
|
4
|
+
import { isInTable, selectedRect } from "prosemirror-tables";
|
|
5
|
+
import { DOCUMENT_OP_TYPES } from "@stll/docx-core/ops";
|
|
6
|
+
// src/prosemirror/canonicalTableCommands.ts
|
|
7
|
+
const SCOPES = {
|
|
8
|
+
table: "table",
|
|
9
|
+
tableRow: "row",
|
|
10
|
+
tableCell: "cell",
|
|
11
|
+
tableHeader: "cell"
|
|
12
|
+
};
|
|
13
|
+
const isScoped = (name) => Object.hasOwn(SCOPES, name);
|
|
14
|
+
/** Keys whose saved value changed: the new value, or null where the key went. */
|
|
15
|
+
const patchBetween = (before, after) => {
|
|
16
|
+
const patch = {};
|
|
17
|
+
const keys = Object.keys({
|
|
18
|
+
...before,
|
|
19
|
+
...after
|
|
20
|
+
});
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const was = before?.[key];
|
|
23
|
+
const is = after?.[key];
|
|
24
|
+
if (JSON.stringify(was) === JSON.stringify(is)) continue;
|
|
25
|
+
patch[key] = after !== void 0 && Object.hasOwn(after, key) ? is : null;
|
|
26
|
+
}
|
|
27
|
+
return patch;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The patch of the formatting the save writes for a table, row or cell node,
|
|
31
|
+
* between its attributes before and after the command, as a target at `at`.
|
|
32
|
+
*/
|
|
33
|
+
const targetBetween = (scope, before, after, at) => {
|
|
34
|
+
switch (scope) {
|
|
35
|
+
case "table": return {
|
|
36
|
+
scope,
|
|
37
|
+
at,
|
|
38
|
+
patch: patchBetween(tableAttrsToFormatting(expectTableAttrs(before)), tableAttrsToFormatting(expectTableAttrs(after)))
|
|
39
|
+
};
|
|
40
|
+
case "row": return {
|
|
41
|
+
scope,
|
|
42
|
+
at,
|
|
43
|
+
patch: patchBetween(tableRowAttrsToFormatting(expectTableRowAttrs(before)), tableRowAttrsToFormatting(expectTableRowAttrs(after)))
|
|
44
|
+
};
|
|
45
|
+
case "cell": return {
|
|
46
|
+
scope,
|
|
47
|
+
at,
|
|
48
|
+
patch: patchBetween(tableCellAttrsToFormatting(expectTableCellAttrs(before)), tableCellAttrsToFormatting(expectTableCellAttrs(after)))
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A position inside the first paragraph that belongs to the node itself, which
|
|
54
|
+
* addresses it. A paragraph of a nested table would address the inner table.
|
|
55
|
+
*/
|
|
56
|
+
const firstParagraphPosition = (node, position) => {
|
|
57
|
+
let found;
|
|
58
|
+
node.descendants((child, offset) => {
|
|
59
|
+
if (found !== void 0 || child.type.name === "table") return false;
|
|
60
|
+
if (child.isTextblock) {
|
|
61
|
+
found = position + 1 + offset + 1;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
return found;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* What an attribute-only table command does, as table formatting patches.
|
|
70
|
+
*
|
|
71
|
+
* The command runs against the state without dispatching to the view. Every
|
|
72
|
+
* table, row and cell whose attributes it changed lowers to a patch of the
|
|
73
|
+
* formatting the save would write for it, so the session applies exactly what
|
|
74
|
+
* the editor would have saved. A command that changes anything else (content,
|
|
75
|
+
* a node's type, a span) has no attribute lowering and stays refused.
|
|
76
|
+
*/
|
|
77
|
+
const lowerTableAttributeCommand = (command, state) => {
|
|
78
|
+
let transaction;
|
|
79
|
+
if (!command(state, (dispatched) => {
|
|
80
|
+
transaction = dispatched;
|
|
81
|
+
}) || transaction === void 0) return void 0;
|
|
82
|
+
const changed = transaction;
|
|
83
|
+
const targets = [];
|
|
84
|
+
const grids = [];
|
|
85
|
+
const expected = state.tr;
|
|
86
|
+
let lowerable = true;
|
|
87
|
+
state.doc.descendants((node, position) => {
|
|
88
|
+
if (!lowerable) return false;
|
|
89
|
+
if (!isScoped(node.type.name)) return true;
|
|
90
|
+
const after = changed.doc.nodeAt(changed.mapping.map(position, -1));
|
|
91
|
+
if (after === null || after.type !== node.type) {
|
|
92
|
+
lowerable = false;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (after.attrs["colspan"] !== node.attrs["colspan"] || after.attrs["rowspan"] !== node.attrs["rowspan"]) {
|
|
96
|
+
lowerable = false;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (JSON.stringify(after.attrs) === JSON.stringify(node.attrs)) return true;
|
|
100
|
+
expected.setNodeMarkup(position, void 0, after.attrs, node.marks);
|
|
101
|
+
const at = firstParagraphPosition(node, position);
|
|
102
|
+
if (node.type.name === "table") {
|
|
103
|
+
const grid = gridEdit(node, after, at);
|
|
104
|
+
if (grid === null) {
|
|
105
|
+
lowerable = false;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (grid !== void 0) grids.push(grid);
|
|
109
|
+
}
|
|
110
|
+
const target = targetBetween(SCOPES[node.type.name], node, after, at ?? 0);
|
|
111
|
+
if (Object.keys(target.patch).length === 0) return true;
|
|
112
|
+
if (at === void 0) {
|
|
113
|
+
lowerable = false;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
targets.push(target);
|
|
117
|
+
return true;
|
|
118
|
+
});
|
|
119
|
+
if (!lowerable || !expected.doc.eq(changed.doc)) return void 0;
|
|
120
|
+
return [...grids, ...targets.length === 0 ? [] : [{
|
|
121
|
+
type: "formatTable",
|
|
122
|
+
targets
|
|
123
|
+
}]];
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* The grid a command left on a table, as a grid edit: `undefined` when the
|
|
127
|
+
* grid is unchanged, `null` when the change cannot be written as a grid.
|
|
128
|
+
*/
|
|
129
|
+
const gridEdit = (before, after, at) => {
|
|
130
|
+
const was = expectTableAttrs(before).columnWidths;
|
|
131
|
+
const is = expectTableAttrs(after).columnWidths;
|
|
132
|
+
if (JSON.stringify(was) === JSON.stringify(is)) return void 0;
|
|
133
|
+
if (at === void 0 || is === void 0 || is.length === 0) return null;
|
|
134
|
+
return {
|
|
135
|
+
type: "editTable",
|
|
136
|
+
at,
|
|
137
|
+
edit: {
|
|
138
|
+
type: DOCUMENT_OP_TYPES.SET_TABLE_GRID,
|
|
139
|
+
columnWidths: [...is]
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
/** Register a command whose whole effect is table, row and cell attributes. */
|
|
144
|
+
const withCanonicalTableAttributeCommand = (command) => withCanonicalCommand(command, (state) => lowerTableAttributeCommand(command, state));
|
|
145
|
+
/** A paragraph of the table's own, outside the given columns, that addresses it. */
|
|
146
|
+
const tableAnchor = (rect, avoid = {
|
|
147
|
+
left: 0,
|
|
148
|
+
right: 0
|
|
149
|
+
}) => {
|
|
150
|
+
const { map, table, tableStart } = rect;
|
|
151
|
+
for (let row = 0; row < map.height; row += 1) for (let column = 0; column < map.width; column += 1) {
|
|
152
|
+
if (column >= avoid.left && column < avoid.right) continue;
|
|
153
|
+
const offset = map.map[row * map.width + column];
|
|
154
|
+
if (offset === void 0) continue;
|
|
155
|
+
const cell = table.nodeAt(offset);
|
|
156
|
+
if (cell === null || cell.attrs["_omittedGridSlot"] != null) continue;
|
|
157
|
+
const cellRect = map.findCell(offset);
|
|
158
|
+
if (cellRect.left < avoid.right && cellRect.right > avoid.left) continue;
|
|
159
|
+
const at = firstParagraphPosition(cell, tableStart + offset);
|
|
160
|
+
if (at !== void 0) return at;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Register a command that changes a table's columns or cells, lowered from the
|
|
165
|
+
* selection it acts on to the engine's table edit. The command still runs
|
|
166
|
+
* against the state first: one it would refuse has no lowering.
|
|
167
|
+
*/
|
|
168
|
+
const withCanonicalTableStructureCommand = (command, lower) => withCanonicalCommand(command, (state) => {
|
|
169
|
+
if (!isInTable(state)) return void 0;
|
|
170
|
+
let transaction;
|
|
171
|
+
if (!command(state, (dispatched) => {
|
|
172
|
+
transaction = dispatched;
|
|
173
|
+
}) || transaction === void 0) return void 0;
|
|
174
|
+
return lower(selectedRect(state), state, transaction);
|
|
175
|
+
});
|
|
176
|
+
/** The width the command gave the column it inserted, from the table it left. */
|
|
177
|
+
const insertedWidth = (rect, changed, column) => {
|
|
178
|
+
const after = changed.doc.nodeAt(changed.mapping.map(rect.tableStart - 1, -1));
|
|
179
|
+
if (after === null || after.type.name !== "table") return void 0;
|
|
180
|
+
return expectTableAttrs(after).columnWidths?.[column];
|
|
181
|
+
};
|
|
182
|
+
const insertColumn = (side) => (rect, _state, changed) => {
|
|
183
|
+
const column = side === "left" ? rect.left : rect.right;
|
|
184
|
+
const width = insertedWidth(rect, changed, column);
|
|
185
|
+
const at = tableAnchor(rect);
|
|
186
|
+
if (width === void 0 || at === void 0) return void 0;
|
|
187
|
+
return [{
|
|
188
|
+
type: "editTable",
|
|
189
|
+
at,
|
|
190
|
+
edit: {
|
|
191
|
+
type: DOCUMENT_OP_TYPES.INSERT_COLUMN,
|
|
192
|
+
column,
|
|
193
|
+
width
|
|
194
|
+
}
|
|
195
|
+
}];
|
|
196
|
+
};
|
|
197
|
+
/** Each selected column, from the right so the indices still hold. */
|
|
198
|
+
const deleteColumns = (rect) => {
|
|
199
|
+
const at = tableAnchor(rect, {
|
|
200
|
+
left: rect.left,
|
|
201
|
+
right: rect.right
|
|
202
|
+
});
|
|
203
|
+
if (at === void 0) return void 0;
|
|
204
|
+
const intents = [];
|
|
205
|
+
for (let column = rect.right - 1; column >= rect.left; column -= 1) intents.push({
|
|
206
|
+
type: "editTable",
|
|
207
|
+
at,
|
|
208
|
+
edit: {
|
|
209
|
+
type: DOCUMENT_OP_TYPES.DELETE_COLUMN,
|
|
210
|
+
column
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return intents;
|
|
214
|
+
};
|
|
215
|
+
const mergeCells$1 = (rect) => {
|
|
216
|
+
const at = tableAnchor(rect);
|
|
217
|
+
if (at === void 0) return void 0;
|
|
218
|
+
return [{
|
|
219
|
+
type: "editTable",
|
|
220
|
+
at,
|
|
221
|
+
edit: {
|
|
222
|
+
type: DOCUMENT_OP_TYPES.MERGE_CELLS,
|
|
223
|
+
top: rect.top,
|
|
224
|
+
bottom: rect.bottom,
|
|
225
|
+
left: rect.left,
|
|
226
|
+
right: rect.right
|
|
227
|
+
}
|
|
228
|
+
}];
|
|
229
|
+
};
|
|
230
|
+
/** The cell at the selection's top left, addressed by its own paragraph. */
|
|
231
|
+
const splitCell$1 = (rect) => {
|
|
232
|
+
const offset = rect.map.map[rect.top * rect.map.width + rect.left];
|
|
233
|
+
const cell = offset === void 0 ? null : rect.table.nodeAt(offset);
|
|
234
|
+
if (offset === void 0 || cell === null) return void 0;
|
|
235
|
+
const at = firstParagraphPosition(cell, rect.tableStart + offset);
|
|
236
|
+
if (at === void 0) return void 0;
|
|
237
|
+
return [{
|
|
238
|
+
type: "editTable",
|
|
239
|
+
at,
|
|
240
|
+
edit: { type: DOCUMENT_OP_TYPES.SPLIT_CELL }
|
|
241
|
+
}];
|
|
242
|
+
};
|
|
243
|
+
const withCanonicalColumnInsertion = (command, side) => withCanonicalTableStructureCommand(command, insertColumn(side));
|
|
244
|
+
const withCanonicalColumnDeletion = (command) => withCanonicalTableStructureCommand(command, deleteColumns);
|
|
245
|
+
const withCanonicalCellMerge = (command) => withCanonicalTableStructureCommand(command, mergeCells$1);
|
|
246
|
+
const withCanonicalCellSplit = (command) => withCanonicalTableStructureCommand(command, splitCell$1);
|
|
247
|
+
/** A paragraph of the table's own in the given row. */
|
|
248
|
+
const rowAnchor = (rect, row) => {
|
|
249
|
+
const { map, table, tableStart } = rect;
|
|
250
|
+
for (let column = 0; column < map.width; column += 1) {
|
|
251
|
+
const offset = map.map[row * map.width + column];
|
|
252
|
+
if (offset === void 0) continue;
|
|
253
|
+
const cell = table.nodeAt(offset);
|
|
254
|
+
if (cell === null || cell.attrs["_omittedGridSlot"] != null) continue;
|
|
255
|
+
if (map.findCell(offset).top !== row) continue;
|
|
256
|
+
const at = firstParagraphPosition(cell, tableStart + offset);
|
|
257
|
+
if (at !== void 0) return at;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* The row the command inserted, as the save would write it. Revision marks
|
|
262
|
+
* the command put on it are left to the engine, which records its own.
|
|
263
|
+
*/
|
|
264
|
+
const insertedRow = (rect, changed, index) => {
|
|
265
|
+
const after = changed.doc.nodeAt(changed.mapping.map(rect.tableStart - 1, -1));
|
|
266
|
+
if (after === null || after.type.name !== "table") return void 0;
|
|
267
|
+
const row = standaloneTableRowsFromProseMirror(after)[index];
|
|
268
|
+
if (row === void 0) return void 0;
|
|
269
|
+
const { structuralChange: _structuralChange, propertyChanges: _propertyChanges, ...plain } = row;
|
|
270
|
+
return plain;
|
|
271
|
+
};
|
|
272
|
+
const insertRow = (side) => (rect, _state, changed) => {
|
|
273
|
+
const index = side === "above" ? rect.top : rect.bottom;
|
|
274
|
+
const row = insertedRow(rect, changed, index);
|
|
275
|
+
const at = rowAnchor(rect, side === "above" ? rect.top : rect.bottom - 1);
|
|
276
|
+
if (row === void 0 || at === void 0) return void 0;
|
|
277
|
+
return [{
|
|
278
|
+
type: "editTableRow",
|
|
279
|
+
at,
|
|
280
|
+
edit: {
|
|
281
|
+
type: DOCUMENT_OP_TYPES.INSERT_ROW,
|
|
282
|
+
at: index,
|
|
283
|
+
row
|
|
284
|
+
}
|
|
285
|
+
}];
|
|
286
|
+
};
|
|
287
|
+
/** Each selected row from the bottom, addressed by a paragraph of its own. */
|
|
288
|
+
const deleteRows = (rect) => {
|
|
289
|
+
const intents = [];
|
|
290
|
+
for (let row = rect.bottom - 1; row >= rect.top; row -= 1) {
|
|
291
|
+
const at = rowAnchor(rect, row);
|
|
292
|
+
if (at === void 0) return void 0;
|
|
293
|
+
intents.push({
|
|
294
|
+
type: "editTableRow",
|
|
295
|
+
at,
|
|
296
|
+
edit: { type: DOCUMENT_OP_TYPES.DELETE_ROW }
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return intents;
|
|
300
|
+
};
|
|
301
|
+
const withCanonicalRowInsertion = (command, side) => withCanonicalTableStructureCommand(command, insertRow(side));
|
|
302
|
+
const withCanonicalRowDeletion = (command) => withCanonicalTableStructureCommand(command, deleteRows);
|
|
303
|
+
/** The table the selection is in, addressed by a paragraph of its own. */
|
|
304
|
+
const deleteTable = (rect) => {
|
|
305
|
+
const at = tableAnchor(rect);
|
|
306
|
+
if (at === void 0) return void 0;
|
|
307
|
+
return [{
|
|
308
|
+
type: "editTableBlock",
|
|
309
|
+
at,
|
|
310
|
+
edit: { type: DOCUMENT_OP_TYPES.DELETE_TABLE }
|
|
311
|
+
}];
|
|
312
|
+
};
|
|
313
|
+
const withCanonicalTableDeletion = (command) => withCanonicalTableStructureCommand(command, deleteTable);
|
|
314
|
+
/**
|
|
315
|
+
* Register the insert table command, lowered to a table and an empty
|
|
316
|
+
* paragraph after the paragraph that holds the caret, as the command places
|
|
317
|
+
* them. The table is the one the command built, without the revision marks
|
|
318
|
+
* it put on its rows; in suggesting mode the engine records its own.
|
|
319
|
+
*/
|
|
320
|
+
const withCanonicalTableInsertion = (command) => withCanonicalCommand(command, (state) => {
|
|
321
|
+
const { $from } = state.selection;
|
|
322
|
+
let depth = $from.depth;
|
|
323
|
+
while (depth > 0 && $from.node(depth).type.name !== "paragraph" && $from.node(depth).type.name !== "table") depth -= 1;
|
|
324
|
+
const afterTable = depth > 0 && $from.node(depth).type.name === "table";
|
|
325
|
+
const atStart = depth === 0 && $from.pos === 0 && state.doc.firstChild?.type.name === "paragraph";
|
|
326
|
+
if (depth === 0 && !atStart) return void 0;
|
|
327
|
+
const following = afterTable ? state.doc.resolve($from.after(depth)).nodeAfter : null;
|
|
328
|
+
if (afterTable && following?.type.name !== "paragraph") return void 0;
|
|
329
|
+
let transaction;
|
|
330
|
+
if (!command(state, (dispatched) => {
|
|
331
|
+
transaction = dispatched;
|
|
332
|
+
}) || transaction === void 0) return void 0;
|
|
333
|
+
const at = atStart ? 0 : transaction.mapping.map($from.after(depth), -1);
|
|
334
|
+
const leading = afterTable ? transaction.doc.nodeAt(at) : null;
|
|
335
|
+
const inserted = transaction.doc.nodeAt(leading?.type.name === "paragraph" ? at + leading.nodeSize : at);
|
|
336
|
+
const before = atStart || afterTable;
|
|
337
|
+
const anchorPosition = () => {
|
|
338
|
+
if (atStart) return 1;
|
|
339
|
+
if (afterTable) return $from.after(depth) + 1;
|
|
340
|
+
return $from.start(depth);
|
|
341
|
+
};
|
|
342
|
+
if (inserted === null || inserted.type.name !== "table") return void 0;
|
|
343
|
+
const formatting = tableAttrsToFormatting(expectTableAttrs(inserted));
|
|
344
|
+
const columnWidths = expectTableAttrs(inserted).columnWidths;
|
|
345
|
+
const table = {
|
|
346
|
+
type: "table",
|
|
347
|
+
...formatting === void 0 ? {} : { formatting },
|
|
348
|
+
...columnWidths === void 0 ? {} : { columnWidths: [...columnWidths] },
|
|
349
|
+
rows: standaloneTableRowsFromProseMirror(inserted).map(({ structuralChange: _change, propertyChanges: _changes, ...row }) => row)
|
|
350
|
+
};
|
|
351
|
+
return [{
|
|
352
|
+
type: "editTableBlock",
|
|
353
|
+
at: anchorPosition(),
|
|
354
|
+
edit: {
|
|
355
|
+
type: DOCUMENT_OP_TYPES.INSERT_TABLE,
|
|
356
|
+
table,
|
|
357
|
+
...before ? { side: "before" } : {},
|
|
358
|
+
...afterTable ? { separated: true } : {}
|
|
359
|
+
}
|
|
360
|
+
}];
|
|
361
|
+
});
|
|
362
|
+
export { lowerTableAttributeCommand, withCanonicalCellMerge, withCanonicalCellSplit, withCanonicalColumnDeletion, withCanonicalColumnInsertion, withCanonicalRowDeletion, withCanonicalRowInsertion, withCanonicalTableAttributeCommand, withCanonicalTableDeletion, withCanonicalTableInsertion };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { TrackedChangeEntry } from "../utils/extractTrackedChanges.js";
|
|
1
2
|
import { Command, EditorState } from "prosemirror-state";
|
|
3
|
+
import { LockedControlViolation } from "@stll/docx-core/model";
|
|
2
4
|
import { Mapping } from "prosemirror-transform";
|
|
3
5
|
/**
|
|
4
6
|
* Add a comment mark to the current selection.
|
|
@@ -18,6 +20,21 @@ export type ParagraphBoundaryChange = {
|
|
|
18
20
|
revisionId?: number;
|
|
19
21
|
};
|
|
20
22
|
export declare function findParagraphBoundaryChangeAtPosition(state: EditorState, pos: number): ParagraphBoundaryChange | null;
|
|
23
|
+
/**
|
|
24
|
+
* What the content-control locks say about resolving the tracked changes
|
|
25
|
+
* between `from` and `to` (only those of `revisionIds`, when given): `null`
|
|
26
|
+
* when they allow it or there is nothing there to resolve. A revision whose
|
|
27
|
+
* resolution would change a content-locked control's content, or remove a
|
|
28
|
+
* control locked against removal, stays pending.
|
|
29
|
+
*/
|
|
30
|
+
export declare const changeResolutionLockViolation: (state: EditorState, { from, to, mode, revisionIds }: {
|
|
31
|
+
from: number;
|
|
32
|
+
to: number;
|
|
33
|
+
mode: "accept" | "reject";
|
|
34
|
+
revisionIds?: readonly number[];
|
|
35
|
+
}) => LockedControlViolation | null;
|
|
36
|
+
/** {@link changeResolutionLockViolation} for the revisions `revisionIds`, wherever they are. */
|
|
37
|
+
export declare const revisionResolutionLockViolation: (state: EditorState, revisionIds: number | readonly number[], mode: "accept" | "reject") => LockedControlViolation | null;
|
|
21
38
|
/**
|
|
22
39
|
* Accept a tracked change at the given range.
|
|
23
40
|
* - Insertion: remove mark, keep text
|
|
@@ -39,6 +56,14 @@ export declare function acceptAllChanges(): Command;
|
|
|
39
56
|
* Reject all tracked changes in the document.
|
|
40
57
|
*/
|
|
41
58
|
export declare function rejectAllChanges(): Command;
|
|
59
|
+
/**
|
|
60
|
+
* The revisions of `state` that a content control's lock keeps from being
|
|
61
|
+
* resolved in `mode`, each with the lock's verdict: see
|
|
62
|
+
* {@link changeResolutionLockViolation}. Empty without a locked control.
|
|
63
|
+
*/
|
|
64
|
+
export declare const lockHeldRevisions: (state: EditorState, mode: "accept" | "reject") => Map<number, LockedControlViolation>;
|
|
65
|
+
/** Every revision id one sidebar entry stands for. */
|
|
66
|
+
export declare const trackedChangeEntryRevisionIds: (entry: TrackedChangeEntry) => number[];
|
|
42
67
|
/**
|
|
43
68
|
* Resolve a complete state synchronously for a headless reader or writer.
|
|
44
69
|
*
|
|
@@ -4,7 +4,7 @@ import { RevisionResolutionStep } from "../../internal/revisionResolutionStep.js
|
|
|
4
4
|
import { finalRevisionParagraphRanges } from "../../internal/revisionResolutionTracking.js";
|
|
5
5
|
import { deleteTextBoxesAnchoredAt, droppedTextBoxAnchorIds, moveTextBoxesPastNextParagraph } from "../anchoredTextBoxes.js";
|
|
6
6
|
import { expectFieldAttrs, expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
|
|
7
|
-
import { readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
|
|
7
|
+
import { isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
|
|
8
8
|
import { addedBreakCarrierBefore, finalParagraphsOf } from "../containerFinalParagraph.js";
|
|
9
9
|
import { enclosingRevisionIds, resolutionRemovesControl, withoutResolvedEnclosures } from "../contentControlRevisions.js";
|
|
10
10
|
import { copyOriginBoundaryAttrsAfterResolution } from "../copyOriginResolution.js";
|
|
@@ -15,6 +15,7 @@ import { markChangedParagraphRanges, markStructuralChange, markTrackedSectionEnd
|
|
|
15
15
|
import "../extensions/nodes/SdtExtension.js";
|
|
16
16
|
import { canonicalFieldNode } from "../fieldRepresentation.js";
|
|
17
17
|
import { isBlockBoundaryNode, normalizeKeptRangeBoundaries, paragraphRemainsOf, removeResolvedSubtree, revisionLayerRemovesContent } from "../keptRangeBoundaries.js";
|
|
18
|
+
import { lockedControlSpans, lockedControlViolationOfTransform } from "../lockedControls.js";
|
|
18
19
|
import { resolveStateStory } from "../markupViewProjection.js";
|
|
19
20
|
import { joinAtParagraphMark } from "../paragraphMarkJoin.js";
|
|
20
21
|
import { carryParagraphProperties, paragraphLeftAfter } from "../paragraphPropertyCarry.js";
|
|
@@ -86,7 +87,7 @@ function removeCommentMark(commentId) {
|
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
const keptIn = (range) => range.removals.flatMap(({ kept }) => kept);
|
|
89
|
-
function
|
|
90
|
+
function resolveChangeUnguarded(from, to, mode, revisionIds) {
|
|
90
91
|
return (state, dispatch) => {
|
|
91
92
|
const insertionType = state.schema.marks["insertion"];
|
|
92
93
|
const deletionType = state.schema.marks["deletion"];
|
|
@@ -522,7 +523,7 @@ function resolveChange(from, to, mode, revisionIds) {
|
|
|
522
523
|
});
|
|
523
524
|
return false;
|
|
524
525
|
}
|
|
525
|
-
if (node
|
|
526
|
+
if (isCommentRangeBoundaryNode(node)) {
|
|
526
527
|
const attrs = readCommentRangeBoundaryAttrs(node);
|
|
527
528
|
if (attrs.ok && doomed.has(attrs.value.marker.id)) {
|
|
528
529
|
carriers.push({
|
|
@@ -894,6 +895,50 @@ function findParagraphBoundaryChangeAtPosition(state, pos) {
|
|
|
894
895
|
}
|
|
895
896
|
return null;
|
|
896
897
|
}
|
|
898
|
+
/** The transaction `command` would dispatch on `state`, or `null` when it would not apply. */
|
|
899
|
+
const attemptedTransaction = (command, state, view) => {
|
|
900
|
+
let attempted = null;
|
|
901
|
+
return command(state, (transaction) => {
|
|
902
|
+
attempted = transaction;
|
|
903
|
+
}, view) ? attempted : null;
|
|
904
|
+
};
|
|
905
|
+
/**
|
|
906
|
+
* `command`, refused when what it would do breaks a content control's lock
|
|
907
|
+
* (`lockedControlViolationOfTransform`). A document without a locked control
|
|
908
|
+
* runs it as it is.
|
|
909
|
+
*/
|
|
910
|
+
const honouringContentControlLocks = (command) => (state, dispatch, view) => {
|
|
911
|
+
if (lockedControlSpans(state.doc).length === 0) return command(state, dispatch, view);
|
|
912
|
+
const attempted = attemptedTransaction(command, state, view);
|
|
913
|
+
if (attempted === null) return false;
|
|
914
|
+
if (lockedControlViolationOfTransform(attempted) !== null) return false;
|
|
915
|
+
dispatch?.(attempted);
|
|
916
|
+
return true;
|
|
917
|
+
};
|
|
918
|
+
function resolveChange(from, to, mode, revisionIds) {
|
|
919
|
+
return honouringContentControlLocks(resolveChangeUnguarded(from, to, mode, revisionIds));
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* What the content-control locks say about resolving the tracked changes
|
|
923
|
+
* between `from` and `to` (only those of `revisionIds`, when given): `null`
|
|
924
|
+
* when they allow it or there is nothing there to resolve. A revision whose
|
|
925
|
+
* resolution would change a content-locked control's content, or remove a
|
|
926
|
+
* control locked against removal, stays pending.
|
|
927
|
+
*/
|
|
928
|
+
const changeResolutionLockViolation = (state, { from, to, mode, revisionIds }) => {
|
|
929
|
+
if (lockedControlSpans(state.doc).length === 0) return null;
|
|
930
|
+
const attempted = attemptedTransaction(resolveChangeUnguarded(from, to, mode, revisionIds), state);
|
|
931
|
+
return attempted === null ? null : lockedControlViolationOfTransform(attempted);
|
|
932
|
+
};
|
|
933
|
+
/** {@link changeResolutionLockViolation} for the revisions `revisionIds`, wherever they are. */
|
|
934
|
+
const revisionResolutionLockViolation = (state, revisionIds, mode) => {
|
|
935
|
+
const range = findAIEditRevisionRange(state, revisionIds);
|
|
936
|
+
return range === null ? null : changeResolutionLockViolation(state, {
|
|
937
|
+
...range,
|
|
938
|
+
mode,
|
|
939
|
+
revisionIds: typeof revisionIds === "number" ? [revisionIds] : revisionIds
|
|
940
|
+
});
|
|
941
|
+
};
|
|
897
942
|
/**
|
|
898
943
|
* Accept a tracked change at the given range.
|
|
899
944
|
* - Insertion: remove mark, keep text
|
|
@@ -944,19 +989,65 @@ const resolveAllChanges = (mode) => (state, dispatch) => {
|
|
|
944
989
|
* suggestions are present because this command cannot restage them.
|
|
945
990
|
*/
|
|
946
991
|
function acceptAllChanges() {
|
|
947
|
-
const resolve =
|
|
948
|
-
return (state, dispatch) => {
|
|
992
|
+
const resolve = resolveAllChangesHonouringLocks("accept");
|
|
993
|
+
return (state, dispatch, view) => {
|
|
949
994
|
if (getSuggestions(state).length > 0) return false;
|
|
950
|
-
return resolve(state, dispatch);
|
|
995
|
+
return resolve(state, dispatch, view);
|
|
951
996
|
};
|
|
952
997
|
}
|
|
953
998
|
/**
|
|
954
999
|
* Reject all tracked changes in the document.
|
|
955
1000
|
*/
|
|
956
1001
|
function rejectAllChanges() {
|
|
957
|
-
return
|
|
1002
|
+
return resolveAllChangesHonouringLocks("reject");
|
|
958
1003
|
}
|
|
959
1004
|
/**
|
|
1005
|
+
* The revisions of `state` that a content control's lock keeps from being
|
|
1006
|
+
* resolved in `mode`, each with the lock's verdict: see
|
|
1007
|
+
* {@link changeResolutionLockViolation}. Empty without a locked control.
|
|
1008
|
+
*/
|
|
1009
|
+
const lockHeldRevisions = (state, mode) => {
|
|
1010
|
+
const held = /* @__PURE__ */ new Map();
|
|
1011
|
+
if (lockedControlSpans(state.doc).length === 0) return held;
|
|
1012
|
+
for (const id of new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds))) {
|
|
1013
|
+
const violation = revisionResolutionLockViolation(state, id, mode);
|
|
1014
|
+
if (violation !== null) held.set(id, violation);
|
|
1015
|
+
}
|
|
1016
|
+
return held;
|
|
1017
|
+
};
|
|
1018
|
+
/** Every revision id one sidebar entry stands for. */
|
|
1019
|
+
const trackedChangeEntryRevisionIds = (entry) => [.../* @__PURE__ */ new Set([
|
|
1020
|
+
entry.revisionId,
|
|
1021
|
+
...entry.insertionRevisionId === void 0 ? [] : [entry.insertionRevisionId],
|
|
1022
|
+
...entry.coalescedRevisionIds ?? []
|
|
1023
|
+
])];
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve every tracked change a content control's lock allows. Without a
|
|
1026
|
+
* change the locks hold, the whole story resolves in one pass, as before;
|
|
1027
|
+
* otherwise each other change resolves on its own, in an editor view (a
|
|
1028
|
+
* transaction each), and the held ones stay pending as they are. Without a
|
|
1029
|
+
* view nothing resolves when any change is held.
|
|
1030
|
+
*/
|
|
1031
|
+
const resolveAllChangesHonouringLocks = (mode) => (state, dispatch, view) => {
|
|
1032
|
+
const resolveAll = resolveAllChanges(mode);
|
|
1033
|
+
if (lockedControlSpans(state.doc).length === 0) return resolveAll(state, dispatch, view);
|
|
1034
|
+
const attempted = attemptedTransaction(resolveAll, state, view);
|
|
1035
|
+
if (attempted === null) return false;
|
|
1036
|
+
if (lockedControlViolationOfTransform(attempted) === null) {
|
|
1037
|
+
dispatch?.(attempted);
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
if (!dispatch) return true;
|
|
1041
|
+
if (!view) return false;
|
|
1042
|
+
const held = lockHeldRevisions(state, mode);
|
|
1043
|
+
const ids = new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds));
|
|
1044
|
+
for (const id of [...ids].toReversed()) {
|
|
1045
|
+
if (held.has(id)) continue;
|
|
1046
|
+
(mode === "accept" ? acceptAIEditRevision(id) : rejectAIEditRevision(id))(view.state, view.dispatch, view);
|
|
1047
|
+
}
|
|
1048
|
+
return true;
|
|
1049
|
+
};
|
|
1050
|
+
/**
|
|
960
1051
|
* Resolve a complete state synchronously for a headless reader or writer.
|
|
961
1052
|
*
|
|
962
1053
|
* Uses the same single-step resolver as the interactive editor command.
|
|
@@ -1798,7 +1889,7 @@ function rejectSuggestion(suggestionId) {
|
|
|
1798
1889
|
if (entry.revisionIds.size > 0) {
|
|
1799
1890
|
const ranges = mergeSegments(entry.segments);
|
|
1800
1891
|
const from = ranges[0]?.from ?? 0;
|
|
1801
|
-
|
|
1892
|
+
resolveChangeUnguarded(from, ranges.at(-1)?.to ?? from, "reject", [...entry.revisionIds])(state, (resolved) => {
|
|
1802
1893
|
tr = resolved;
|
|
1803
1894
|
});
|
|
1804
1895
|
}
|
|
@@ -1838,7 +1929,7 @@ function rejectAllSuggestions() {
|
|
|
1838
1929
|
}
|
|
1839
1930
|
const rotationCandidates = removesWholeNode ? collectAddedBreakRotationCandidates(state.doc) : [];
|
|
1840
1931
|
let tr = null;
|
|
1841
|
-
if (revisionIds.size > 0)
|
|
1932
|
+
if (revisionIds.size > 0) resolveChangeUnguarded(0, state.doc.content.size, "reject", [...revisionIds])(state, (resolved) => {
|
|
1842
1933
|
tr = resolved;
|
|
1843
1934
|
});
|
|
1844
1935
|
const workingTr = tr ?? state.tr;
|
|
@@ -1909,7 +2000,7 @@ function findChangeAtPosition(state, from, to) {
|
|
|
1909
2000
|
};
|
|
1910
2001
|
const $pos = state.doc.resolve(from);
|
|
1911
2002
|
const node = $pos.parent;
|
|
1912
|
-
if (!node.
|
|
2003
|
+
if (!node.inlineContent) return {
|
|
1913
2004
|
from,
|
|
1914
2005
|
to
|
|
1915
2006
|
};
|
|
@@ -2070,4 +2161,4 @@ function findPreviousChange(state, startPos) {
|
|
|
2070
2161
|
if (result.value === null && startPos < state.doc.content.size) return findPreviousChange(state, state.doc.content.size);
|
|
2071
2162
|
return result.value;
|
|
2072
2163
|
}
|
|
2073
|
-
export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, suggestionIdOfRevision };
|
|
2164
|
+
export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, changeResolutionLockViolation, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, lockHeldRevisions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, revisionResolutionLockViolation, suggestionIdOfRevision, trackedChangeEntryRevisionIds };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { document_d_exports } from "../../types/document.js";
|
|
2
2
|
import { TextColorAttrs } from "../schema/marks.js";
|
|
3
|
-
import "../schema/index.js";
|
|
4
3
|
import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
|
|
4
|
+
import "../schema/index.js";
|
|
5
5
|
import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
|
|
6
6
|
import { Mark } from "prosemirror-model";
|
|
7
7
|
import { Command } from "prosemirror-state";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
|
|
1
2
|
import { GenerateTableOfContentsOptions, ResolvedStyleAttrs, getParagraphAlignment, getParagraphBidi, getStyleId } from "../extensions/core/ParagraphExtension.js";
|
|
2
3
|
import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
|
|
3
4
|
import { AcceptSuggestionOptions, FolioSuggestion, SuggestionAppliedAs, SuggestionKind, acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findNextChange, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark } from "./comments.js";
|
|
4
5
|
import { CapturedTextFormatting, PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./formatPainter.js";
|
|
5
|
-
import { clearFormatting, createRemoveMarkCommand, createSetMarkCommand, getMarkAttr, isMarkActive } from "../extensions/marks/markUtils.js";
|
|
6
6
|
import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "../extensions/marks/HyperlinkExtension.js";
|
|
7
7
|
import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, setUnderlineStyle, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./formatting.js";
|
|
8
8
|
import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expectCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
|
|
1
|
+
import { expectCommentRangeBoundaryAttrs, isCommentRangeBoundaryNode } from "./commentRangeBoundaryAttrs.js";
|
|
2
2
|
import { maxAnnotationIdInDoc, seedRevisionIdsAbove } from "./plugins/revisionIds.js";
|
|
3
3
|
import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
|
|
4
4
|
import { TaggedError } from "better-result";
|
|
@@ -57,7 +57,7 @@ function seedCommentAllocator(allocator, comments, view) {
|
|
|
57
57
|
const attrs = readRangeAnchorAttrs(node);
|
|
58
58
|
if (attrs.ok && attrs.value.start.type === "commentRangeStart") allocator.seedAbove(attrs.value.start.id);
|
|
59
59
|
}
|
|
60
|
-
if (node
|
|
60
|
+
if (isCommentRangeBoundaryNode(node)) allocator.seedAbove(expectCommentRangeBoundaryAttrs(node).marker.id);
|
|
61
61
|
});
|
|
62
62
|
max = Math.max(max, maxAnnotationIdInDoc(view.state.doc));
|
|
63
63
|
}
|
|
@@ -8,6 +8,12 @@ type CommentRangeBoundaryMarker = Extract<ParagraphContent, {
|
|
|
8
8
|
type CommentRangeBoundaryAttrs = {
|
|
9
9
|
marker: CommentRangeBoundaryMarker;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Whether a node is a comment range boundary, inside a paragraph or between
|
|
13
|
+
* blocks. Both carry the same marker, so every reader asks this rather than
|
|
14
|
+
* naming one of them.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isCommentRangeBoundaryNode: (node: Node) => boolean;
|
|
11
17
|
export declare const readCommentRangeBoundaryMarker: (value: unknown) => CommentRangeBoundaryMarker | undefined;
|
|
12
18
|
export declare const readCommentRangeBoundaryAttrs: (node: Node) => ReadProseMirrorAttrsResult<CommentRangeBoundaryAttrs>;
|
|
13
19
|
export declare const expectCommentRangeBoundaryAttrs: (node: Node) => CommentRangeBoundaryAttrs;
|