@stll/folio-core 0.66.1 → 0.67.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 +13 -1
- package/dist/ai-edits/apply.js +572 -140
- package/dist/ai-edits/batch-claims.d.ts +26 -0
- package/dist/ai-edits/batch-claims.js +32 -5
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/headless.d.ts +6 -0
- package/dist/ai-edits/headless.js +25 -3
- package/dist/ai-edits/newListNumbering.d.ts +4 -1
- package/dist/ai-edits/newListNumbering.js +4 -2
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.js +24 -14
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- package/dist/ai-edits/types.d.ts +1 -1
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +76 -18
- package/dist/controller/canonicalInput.d.ts +0 -1
- package/dist/controller/canonicalInput.js +19 -1
- package/dist/controller/canonicalSession.js +1 -2
- package/dist/controller/hiddenEditorManager.d.ts +6 -0
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +7 -3
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +29 -13
- package/dist/document-operations.d.ts +13 -1
- package/dist/document-operations.js +11 -4
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/listNumberingInstances.d.ts +6 -4
- package/dist/docx/listNumberingInstances.js +12 -11
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- package/dist/docx/numberingIds.d.ts +10 -0
- package/dist/docx/numberingIds.js +5 -1
- package/dist/docx/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/paragraphParser.js +16 -3
- package/dist/docx/paragraphProperties.js +2 -1
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -1
- package/dist/docx/rezip.js +4 -4
- package/dist/docx/serializer/paragraphSerializer.js +86 -66
- package/dist/docx/shapeAlternateContent.js +19 -0
- package/dist/docx/unzip.js +2 -0
- 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/wholeStoryRevisionResolution.d.ts +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +81 -21
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/runMarkFormatting.js +1 -0
- package/dist/layout-bridge/convert/tableConversion.js +6 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +7 -4
- package/dist/layout-engine/tableRowBreak.d.ts +10 -0
- package/dist/layout-engine/tableRowBreak.js +151 -36
- package/dist/layout-engine/types.d.ts +7 -2
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +1 -0
- package/dist/layout-painter/renderPage.js +6 -3
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +33 -19
- package/dist/markdown/renderRuns.js +68 -12
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/commands/comments.js +22 -7
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- package/dist/prosemirror/commands/resolveParagraphProperties.js +15 -2
- package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
- package/dist/prosemirror/conversion/fromProseDoc.js +94 -22
- package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +23 -1
- package/dist/prosemirror/conversion/hyphenTextCarriers.js +46 -1
- package/dist/prosemirror/conversion/toProseDoc.js +21 -13
- package/dist/prosemirror/extensions/StarterKit.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/features/pasteCleanup.js +6 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -1
- package/dist/prosemirror/extensions/markRegistry.d.ts +3 -1
- package/dist/prosemirror/extensions/markRegistry.js +3 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/HyphenElementExtension.js +54 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/fieldRepresentation.js +2 -1
- package/dist/prosemirror/hyphenElementAttrs.d.ts +10 -0
- package/dist/prosemirror/hyphenElementAttrs.js +32 -0
- package/dist/prosemirror/keptRangeBoundaries.d.ts +2 -0
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.js +3 -2
- package/dist/prosemirror/paragraphIndentation.js +2 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -14
- package/dist/prosemirror/paragraphPropertyCarry.js +4 -28
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +194 -27
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -0
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -0
- package/dist/prosemirror/sectionCarrier.d.ts +8 -0
- package/dist/prosemirror/sectionCarrier.js +29 -1
- package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +10 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +12 -2
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/tableRunIn.d.ts +24 -9
- package/dist/prosemirror/tableRunIn.js +107 -21
- package/dist/prosemirror/textInput.js +3 -1
- package/dist/prosemirror/validation.js +7 -1
- package/dist/utils/createDocument.js +11 -8
- package/dist/utils/formatToStyle.js +2 -2
- package/dist/utils/units.d.ts +5 -0
- package/dist/utils/units.js +6 -1
- package/package.json +3 -3
|
@@ -3,7 +3,6 @@ import { NumberingMap } from "../docx/numberingParser.js";
|
|
|
3
3
|
import { RunStyleResolver } from "./runStyleFormatting.js";
|
|
4
4
|
import { Node } from "prosemirror-model";
|
|
5
5
|
import { Transaction } from "prosemirror-state";
|
|
6
|
-
type RecordedFormatting = NonNullable<ParagraphPropertyChangeAttrs["previousFormatting"]>;
|
|
7
6
|
type CarryParagraphPropertiesOptions = {
|
|
8
7
|
tr: Transaction;
|
|
9
8
|
/** The paragraph that takes the properties. */
|
|
@@ -14,14 +13,7 @@ type CarryParagraphPropertiesOptions = {
|
|
|
14
13
|
numbering: NumberingMap | null;
|
|
15
14
|
/** Records the change as a tracked property change; applied directly when omitted. */
|
|
16
15
|
revision?: ParagraphPropertyChangeAttrs["info"];
|
|
17
|
-
/** Properties the paragraph keeps its own values of: ones its own batch set. */
|
|
18
|
-
keep?: ReadonlySet<string>;
|
|
19
16
|
};
|
|
20
|
-
type CarriedParagraphPropertiesOptions = Pick<CarryParagraphPropertiesOptions, "source" | "keep"> & {
|
|
21
|
-
target: Node;
|
|
22
|
-
};
|
|
23
|
-
/** The exact formatting transfer, shared with pre-mutation capacity checks. */
|
|
24
|
-
export declare const carriedParagraphProperties: ({ source, target, keep }: CarriedParagraphPropertiesOptions) => RecordedFormatting;
|
|
25
17
|
/**
|
|
26
18
|
* Give a paragraph another one's properties: the pPr a property change
|
|
27
19
|
* covers. Its identity, mark, mark run properties and section stay its own,
|
|
@@ -29,7 +21,7 @@ export declare const carriedParagraphProperties: ({ source, target, keep }: Carr
|
|
|
29
21
|
* change now records what it had: a paragraph holds one, and a pending one
|
|
30
22
|
* already records it.
|
|
31
23
|
*/
|
|
32
|
-
export declare const carryParagraphProperties: ({ tr, position, source, styleResolver, numbering, revision
|
|
24
|
+
export declare const carryParagraphProperties: ({ tr, position, source, styleResolver, numbering, revision }: CarryParagraphPropertiesOptions) => {
|
|
33
25
|
tr: Transaction;
|
|
34
26
|
changed: boolean;
|
|
35
27
|
tracked: boolean;
|
|
@@ -60,9 +52,4 @@ export declare const recordReplacedParagraphProperties: ({ tr, position, replace
|
|
|
60
52
|
replaced: Node;
|
|
61
53
|
revision: ParagraphPropertyChangeAttrs["info"];
|
|
62
54
|
}) => boolean;
|
|
63
|
-
/**
|
|
64
|
-
* The properties a batch's own property change set on a paragraph: the ones
|
|
65
|
-
* whose value differs from what that change records as before.
|
|
66
|
-
*/
|
|
67
|
-
export declare const propertiesSetInBatch: (node: Node, batchRevisionIds: ReadonlySet<number>) => ReadonlySet<string>;
|
|
68
55
|
export {};
|
|
@@ -18,8 +18,6 @@ import { panic } from "better-result";
|
|
|
18
18
|
* revision, so accepting reads as the direct edit and rejecting restores the
|
|
19
19
|
* second's own.
|
|
20
20
|
*/
|
|
21
|
-
/** The exact formatting transfer, shared with pre-mutation capacity checks. */
|
|
22
|
-
const carriedParagraphProperties = ({ source, target, keep }) => Object.fromEntries([...Object.entries(paragraphPropertiesSnapshot(source)).filter(([key]) => !keep?.has(key)), ...Object.entries(paragraphPropertiesSnapshot(target)).filter(([key]) => keep?.has(key))]);
|
|
23
21
|
/**
|
|
24
22
|
* Give a paragraph another one's properties: the pPr a property change
|
|
25
23
|
* covers. Its identity, mark, mark run properties and section stay its own,
|
|
@@ -27,7 +25,7 @@ const carriedParagraphProperties = ({ source, target, keep }) => Object.fromEntr
|
|
|
27
25
|
* change now records what it had: a paragraph holds one, and a pending one
|
|
28
26
|
* already records it.
|
|
29
27
|
*/
|
|
30
|
-
const carryParagraphProperties = ({ tr, position, source, styleResolver, numbering, revision
|
|
28
|
+
const carryParagraphProperties = ({ tr, position, source, styleResolver, numbering, revision }) => {
|
|
31
29
|
const target = tr.doc.nodeAt(position);
|
|
32
30
|
if (!target || target.type !== source.type) return {
|
|
33
31
|
tr,
|
|
@@ -35,11 +33,7 @@ const carryParagraphProperties = ({ tr, position, source, styleResolver, numberi
|
|
|
35
33
|
tracked: false
|
|
36
34
|
};
|
|
37
35
|
const previousFormatting = paragraphPropertiesSnapshot(target);
|
|
38
|
-
const formatting =
|
|
39
|
-
source,
|
|
40
|
-
target,
|
|
41
|
-
...keep === void 0 ? {} : { keep }
|
|
42
|
-
});
|
|
36
|
+
const formatting = paragraphPropertiesSnapshot(source);
|
|
43
37
|
if (JSON.stringify(previousFormatting) === JSON.stringify(formatting)) return {
|
|
44
38
|
tr,
|
|
45
39
|
changed: false,
|
|
@@ -74,7 +68,7 @@ const carryParagraphProperties = ({ tr, position, source, styleResolver, numberi
|
|
|
74
68
|
}] : []];
|
|
75
69
|
tr.setNodeMarkup(position, void 0, {
|
|
76
70
|
...carried,
|
|
77
|
-
|
|
71
|
+
numPrFromStyle: expectParagraphAttrs(source).numPrFromStyle,
|
|
78
72
|
_sectionProperties: target.attrs["_sectionProperties"],
|
|
79
73
|
_propertyChanges: changes.length > 0 ? changes : null
|
|
80
74
|
});
|
|
@@ -91,12 +85,6 @@ const carryParagraphProperties = ({ tr, position, source, styleResolver, numberi
|
|
|
91
85
|
};
|
|
92
86
|
};
|
|
93
87
|
/**
|
|
94
|
-
* Whether the carried numbering is the paragraph's own or its style's: the
|
|
95
|
-
* record holds only stated numbering, and a style's numbering
|
|
96
|
-
* stays the style's rather than becoming the paragraph's own `w:numPr`.
|
|
97
|
-
*/
|
|
98
|
-
const carriedNumberingProvenance = (source, target, keep) => ({ numPrFromStyle: expectParagraphAttrs(keep?.has("numPr") ? target : source).numPrFromStyle });
|
|
99
|
-
/**
|
|
100
88
|
* The paragraph left once the break of the paragraph at `paragraphPos` goes:
|
|
101
89
|
* the next one, or, when its own break is pending deletion too, the first
|
|
102
90
|
* paragraph after it whose break stays. Null when no paragraph follows.
|
|
@@ -143,16 +131,4 @@ const recordReplacedParagraphProperties = ({ tr, position, replaced, revision })
|
|
|
143
131
|
}]);
|
|
144
132
|
return true;
|
|
145
133
|
};
|
|
146
|
-
|
|
147
|
-
* The properties a batch's own property change set on a paragraph: the ones
|
|
148
|
-
* whose value differs from what that change records as before.
|
|
149
|
-
*/
|
|
150
|
-
const propertiesSetInBatch = (node, batchRevisionIds) => {
|
|
151
|
-
const changes = expectParagraphAttrs(node)._propertyChanges;
|
|
152
|
-
const change = Array.isArray(changes) ? changes.find(({ info }) => batchRevisionIds.has(info.id)) : void 0;
|
|
153
|
-
if (change === void 0) return /* @__PURE__ */ new Set();
|
|
154
|
-
const before = change.previousFormatting ?? {};
|
|
155
|
-
const now = paragraphPropertiesSnapshot(node);
|
|
156
|
-
return new Set([.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(now)])].filter((key) => JSON.stringify(before[key]) !== JSON.stringify(now[key])));
|
|
157
|
-
};
|
|
158
|
-
export { carriedParagraphProperties, carryParagraphProperties, paragraphLeftAfter, propertiesSetInBatch, recordReplacedParagraphProperties };
|
|
134
|
+
export { carryParagraphProperties, paragraphLeftAfter, recordReplacedParagraphProperties };
|
|
@@ -35,14 +35,6 @@ export declare function makeRevisionInfo(state: EditorState): {
|
|
|
35
35
|
* (eigenpal/docx-editor#784).
|
|
36
36
|
*/
|
|
37
37
|
export declare function handleSuggestionPaste(view: Pick<EditorView, "dispatch" | "state">, slice: Slice, pluginState: SuggestionModeState): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* With track changes on, a paste into a table's cells (a cell selection, or a
|
|
40
|
-
* block of copied cells) replaces each cell's content the way a paste over a
|
|
41
|
-
* text selection does: the old content struck through, the pasted content
|
|
42
|
-
* after it as an insertion. When the pasted content is whole paragraphs, the
|
|
43
|
-
* last one ends the cell, so its paragraph mark is tracked as added too:
|
|
44
|
-
* rejecting then drops it and accepting joins the struck paragraphs into it.
|
|
45
|
-
*/
|
|
46
38
|
export declare function handleSuggestionTableCellPaste(view: EditorView, slice: Slice, pluginState: SuggestionModeState): boolean;
|
|
47
39
|
/**
|
|
48
40
|
* Remove `from`..`to` of `tr.doc` as a suggestion: text the current author
|
|
@@ -7,6 +7,7 @@ import { encloseWholeControls } from "../contentControlRevisions.js";
|
|
|
7
7
|
import { splitBlockClearBorders } from "../extensions/features/BaseKeymapExtension.js";
|
|
8
8
|
import { JOINED_RUNS_RESTYLED_META } from "../extensions/features/JoinedRunStyleExtension.js";
|
|
9
9
|
import { expandNoteReferenceDeletionRange } from "../extensions/marks/noteReferenceDeletion.js";
|
|
10
|
+
import { isInlineAnchor } from "../extensions/nodes/inlineAnchorDom.js";
|
|
10
11
|
import { carryParagraphProperties, paragraphLeftAfter, recordReplacedParagraphProperties } from "../paragraphPropertyCarry.js";
|
|
11
12
|
import { createPluginKeyOwner } from "../pluginKeyOwner.js";
|
|
12
13
|
import { rebaseParagraphRuns } from "../rebaseParagraphRunFormatting.js";
|
|
@@ -21,7 +22,7 @@ import { selectLockedInlineControl } from "./lockedControlKeyHandling.js";
|
|
|
21
22
|
import { mintRevisionId, seedRevisionIdsFromDoc } from "./revisionIds.js";
|
|
22
23
|
import { Slice } from "prosemirror-model";
|
|
23
24
|
import { CellSelection } from "prosemirror-tables";
|
|
24
|
-
import { Mapping, ReplaceStep } from "prosemirror-transform";
|
|
25
|
+
import { Mapping, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
|
|
25
26
|
import { AllSelection, EditorState, Plugin, Selection, TextSelection } from "prosemirror-state";
|
|
26
27
|
import { isHistoryTransaction } from "prosemirror-history";
|
|
27
28
|
import { joinBackward, joinForward, selectNodeBackward, selectNodeForward } from "prosemirror-commands";
|
|
@@ -122,6 +123,7 @@ function findAdjacentRevisionForRange(doc, from, to, markTypeName, author) {
|
|
|
122
123
|
*/
|
|
123
124
|
function markRangeAsDeleted(tr, doc, from, to, deletionType, pluginState, joinState) {
|
|
124
125
|
let hasMarkableContent = false;
|
|
126
|
+
const stepsBeforeDoc = doc === tr.doc ? tr.mapping.maps.length : 0;
|
|
125
127
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
126
128
|
if (!canCarryTrackedRunMark(node)) return;
|
|
127
129
|
if (Math.max(pos, from) >= Math.min(pos + node.nodeSize, to)) return;
|
|
@@ -149,7 +151,7 @@ function markRangeAsDeleted(tr, doc, from, to, deletionType, pluginState, joinSt
|
|
|
149
151
|
const $first = doc.resolve(from);
|
|
150
152
|
const $last = doc.resolve(to);
|
|
151
153
|
if (joinState && removedMark && $first.parent.type.name === "paragraph" && $last.parent.type.name === "paragraph" && $first.parent !== $last.parent && from > $first.start()) {
|
|
152
|
-
const lastPos =
|
|
154
|
+
const lastPos = tr.mapping.slice(stepsBeforeDoc).map($last.before());
|
|
153
155
|
const lastMark = tr.doc.nodeAt(lastPos)?.attrs["pPrMark"];
|
|
154
156
|
const survivorPos = lastMark?.kind === "del" || lastMark?.kind === "moveFrom" ? paragraphLeftAfter({
|
|
155
157
|
doc: tr.doc,
|
|
@@ -248,13 +250,17 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
248
250
|
if (!insertionType || !deletionType) return false;
|
|
249
251
|
if (selection.empty) {
|
|
250
252
|
const { $from } = selection;
|
|
251
|
-
const
|
|
253
|
+
const closedBlocks = slice.openStart === 0 && slice.openEnd === 0 && slice.content.firstChild?.isBlock === true;
|
|
252
254
|
const prefix = $from.parent.content.cut(0, $from.parentOffset);
|
|
253
|
-
let deletedPrefix =
|
|
255
|
+
let deletedPrefix = false;
|
|
256
|
+
let keptPrefix = false;
|
|
254
257
|
prefix.forEach((node) => {
|
|
255
|
-
if (
|
|
258
|
+
if (isInlineAnchor(node)) return;
|
|
259
|
+
if (node.marks.some((mark) => mark.type === deletionType)) deletedPrefix = true;
|
|
260
|
+
else keptPrefix = true;
|
|
256
261
|
});
|
|
257
|
-
|
|
262
|
+
deletedPrefix &&= !keptPrefix;
|
|
263
|
+
if (!closedBlocks || $from.parent.type.name !== "paragraph" || !deletedPrefix) return false;
|
|
258
264
|
const suffix = $from.parent.content.cut($from.parentOffset);
|
|
259
265
|
let deletedSuffix = true;
|
|
260
266
|
suffix.forEach((node) => {
|
|
@@ -271,6 +277,18 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
271
277
|
to: end,
|
|
272
278
|
revision
|
|
273
279
|
});
|
|
280
|
+
tr.doc.nodesBetween(at, end, (node, pos) => {
|
|
281
|
+
if (node.type.name !== "paragraph" || node.attrs["pPrMark"] != null) return false;
|
|
282
|
+
tr.setNodeAttribute(pos, "pPrMark", {
|
|
283
|
+
kind: "ins",
|
|
284
|
+
info: {
|
|
285
|
+
id: revision.revisionId,
|
|
286
|
+
author: revision.author,
|
|
287
|
+
date: revision.date
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return false;
|
|
291
|
+
});
|
|
274
292
|
markRangeAsInserted(tr, tr.doc, at, end, insertionType, deletionType, revision);
|
|
275
293
|
if (deletedSuffix && $from.parent.attrs["pPrMark"] == null && !paragraphEndsItsContainer($from.doc.resolve($from.before()), "paragraph")) tr.setNodeAttribute(tr.mapping.map($from.before()), "pPrMark", {
|
|
276
294
|
kind: "del",
|
|
@@ -379,7 +397,8 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
379
397
|
insertFrom = Math.min(tr.mapping.slice(rotation).map(insertFrom, -1), joined);
|
|
380
398
|
insertTo = tr.mapping.slice(rotation).map(insertTo);
|
|
381
399
|
}
|
|
382
|
-
tr.
|
|
400
|
+
const caret = beforeStruck && !wholeBlocks ? tr.mapping.map(to) : insertTo;
|
|
401
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(caret)));
|
|
383
402
|
view.dispatch(tr.scrollIntoView());
|
|
384
403
|
return true;
|
|
385
404
|
}
|
|
@@ -391,6 +410,13 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
391
410
|
* last one ends the cell, so its paragraph mark is tracked as added too:
|
|
392
411
|
* rejecting then drops it and accepting joins the struck paragraphs into it.
|
|
393
412
|
*/
|
|
413
|
+
const holdsOnlyStruckText = (paragraph, deletion) => {
|
|
414
|
+
let struck = true;
|
|
415
|
+
paragraph.forEach((node) => {
|
|
416
|
+
if (!node.marks.some((mark) => mark.type === deletion)) struck = false;
|
|
417
|
+
});
|
|
418
|
+
return struck;
|
|
419
|
+
};
|
|
394
420
|
function handleSuggestionTableCellPaste(view, slice, pluginState) {
|
|
395
421
|
const insertionType = view.state.schema.marks["insertion"];
|
|
396
422
|
const deletionType = view.state.schema.marks["deletion"];
|
|
@@ -434,15 +460,25 @@ function handleSuggestionTableCellPaste(view, slice, pluginState) {
|
|
|
434
460
|
});
|
|
435
461
|
}
|
|
436
462
|
const emptyInsertions = [];
|
|
437
|
-
|
|
463
|
+
const struckBreaks = [];
|
|
464
|
+
tr.doc.nodeAt(cellPos)?.forEach((node, offset, index) => {
|
|
438
465
|
const pos = cellPos + 1 + offset;
|
|
439
|
-
if (pos
|
|
466
|
+
if (pos >= pastedFrom || node.type.name !== "paragraph" || !isCurrentAuthorParagraphInsertion(node.attrs["pPrMark"], pluginState.author)) return;
|
|
467
|
+
if (node.content.size === 0) emptyInsertions.push({
|
|
440
468
|
from: pos,
|
|
441
469
|
to: pos + node.nodeSize
|
|
442
470
|
});
|
|
471
|
+
else if (holdsOnlyStruckText(node, deletionType) && isCurrentAuthorParagraphInsertion(cell.maybeChild(index)?.attrs["pPrMark"], pluginState.author)) struckBreaks.push(pos + node.nodeSize);
|
|
443
472
|
});
|
|
444
473
|
const retraction = tr.mapping.maps.length;
|
|
445
474
|
for (const range of emptyInsertions.toReversed()) tr.delete(range.from, range.to);
|
|
475
|
+
for (const boundary of struckBreaks.toReversed()) {
|
|
476
|
+
const at = tr.mapping.slice(retraction).map(boundary);
|
|
477
|
+
const { nodeBefore, nodeAfter } = tr.doc.resolve(at);
|
|
478
|
+
if (nodeBefore?.type.name !== "paragraph" || !nodeAfter) continue;
|
|
479
|
+
tr.setNodeMarkup(at - nodeBefore.nodeSize, void 0, nodeAfter.attrs);
|
|
480
|
+
tr.join(at);
|
|
481
|
+
}
|
|
446
482
|
const retracted = tr.mapping.slice(retraction);
|
|
447
483
|
pastedFrom = retracted.map(pastedFrom);
|
|
448
484
|
insertTo = retracted.map(insertTo);
|
|
@@ -531,6 +567,17 @@ function applySuggestionInsert(view, from, to, text, pluginState) {
|
|
|
531
567
|
if (selectsAll) {
|
|
532
568
|
from = Math.max(from, Selection.atStart(view.state.doc).from);
|
|
533
569
|
to = Math.min(to, Selection.atEnd(view.state.doc).to);
|
|
570
|
+
} else if (typesOverSelection && selection instanceof CellSelection) {
|
|
571
|
+
const cellDeletion = view.state.schema.marks["deletion"];
|
|
572
|
+
if (cellDeletion) {
|
|
573
|
+
const ranges = selection.ranges.toSorted((a, b) => b.$from.pos - a.$from.pos);
|
|
574
|
+
for (const range of ranges) markRangeAsDeleted(tr, view.state.doc, range.$from.pos, range.$to.pos, cellDeletion, pluginState, view.state);
|
|
575
|
+
}
|
|
576
|
+
const last = Selection.findFrom(view.state.doc.resolve(to), -1, true);
|
|
577
|
+
if (last && last.to >= from) {
|
|
578
|
+
from = last.to;
|
|
579
|
+
to = last.to;
|
|
580
|
+
}
|
|
534
581
|
}
|
|
535
582
|
const replacedFormatting = selectsAll ? (view.state.doc.resolve(from).nodeAfter?.marks ?? []).filter(({ type }) => RUN_FORMATTING_MARK_NAMES.has(type.name)) : null;
|
|
536
583
|
const insertAttrs = findAdjacentRevision(view.state.doc, from, "insertion", pluginState.author) || makeMarkAttrs(pluginState);
|
|
@@ -545,16 +592,18 @@ function applySuggestionInsert(view, from, to, text, pluginState) {
|
|
|
545
592
|
to
|
|
546
593
|
});
|
|
547
594
|
if (formattingMarks !== void 0) tr.setStoredMarks(formattingMarks);
|
|
595
|
+
const typedFrom = tr.doc.resolve(insertAt).parent.inlineContent ? insertAt : insertAt + 1;
|
|
596
|
+
const typedTo = typedFrom + text.length;
|
|
548
597
|
tr.insertText(text, insertAt, insertAt);
|
|
549
598
|
const deletionType = view.state.schema.marks["deletion"];
|
|
550
|
-
if (deletionType) tr.removeMark(
|
|
551
|
-
tr.addMark(
|
|
599
|
+
if (deletionType) tr.removeMark(typedFrom, typedTo, deletionType);
|
|
600
|
+
tr.addMark(typedFrom, typedTo, insertionType.create(insertAttrs));
|
|
552
601
|
if (replacedFormatting) {
|
|
553
|
-
for (const mark of tr.doc.resolve(
|
|
554
|
-
for (const mark of replacedFormatting) tr.addMark(
|
|
602
|
+
for (const mark of tr.doc.resolve(typedFrom).nodeAfter?.marks ?? []) if (RUN_FORMATTING_MARK_NAMES.has(mark.type.name)) tr.removeMark(typedFrom, typedTo, mark.type);
|
|
603
|
+
for (const mark of replacedFormatting) tr.addMark(typedFrom, typedTo, mark);
|
|
555
604
|
}
|
|
556
|
-
separateSplitStretch(tr,
|
|
557
|
-
if (typesOverSelection) tr.setSelection(TextSelection.create(tr.doc,
|
|
605
|
+
separateSplitStretch(tr, typedFrom, typedTo, insertAttrs.revisionId);
|
|
606
|
+
if (typesOverSelection) tr.setSelection(TextSelection.create(tr.doc, typedTo));
|
|
558
607
|
view.dispatch(tr.scrollIntoView());
|
|
559
608
|
return true;
|
|
560
609
|
}
|
|
@@ -673,7 +722,7 @@ function caretDeleteTarget(state, direction) {
|
|
|
673
722
|
while (cursor >= $from.start() && cursor <= $from.end()) {
|
|
674
723
|
const adjacent = backward ? state.doc.resolve(cursor).nodeBefore : state.doc.resolve(cursor).nodeAfter;
|
|
675
724
|
if (!adjacent) return { type: "paragraphEdge" };
|
|
676
|
-
if (adjacent
|
|
725
|
+
if (!isInlineAnchor(adjacent) && !adjacent.marks.some((mark) => mark.type === state.schema.marks["deletion"])) {
|
|
677
726
|
const size = adjacent.isAtom && !adjacent.isText ? adjacent.nodeSize : 1;
|
|
678
727
|
return {
|
|
679
728
|
type: "inlineUnit",
|
|
@@ -846,11 +895,34 @@ function handleSuggestionDelete(state, dispatch, direction) {
|
|
|
846
895
|
}
|
|
847
896
|
/** Apply the editor's selected-content deletion path for a host cut action. */
|
|
848
897
|
const deleteSelectionAsSuggestion = (state, dispatch) => state.selection.empty ? false : handleSuggestionDelete(state, dispatch, "forward");
|
|
849
|
-
|
|
898
|
+
/**
|
|
899
|
+
* PM reads the removal of cancelled text back from the DOM, which can take the
|
|
900
|
+
* text around it along and drop its revision marks. The same text was there when
|
|
901
|
+
* the composition started: put back what it was.
|
|
902
|
+
*/
|
|
903
|
+
function restoreAfterCancelledComposition(view, startDoc) {
|
|
904
|
+
const { doc } = view.state;
|
|
905
|
+
const start = startDoc.content.findDiffStart(doc.content);
|
|
906
|
+
const end = startDoc.content.findDiffEnd(doc.content);
|
|
907
|
+
if (start === null || end === null) return;
|
|
908
|
+
if (end.a !== end.b || end.a <= start || startDoc.textBetween(start, end.a, "\n", "\n") !== doc.textBetween(start, end.a, "\n", "\n")) return;
|
|
909
|
+
const tr = view.state.tr.replace(start, end.a, startDoc.slice(start, end.a));
|
|
910
|
+
tr.setMeta(SUGGESTION_META, true);
|
|
911
|
+
tr.setMeta("addToHistory", false);
|
|
912
|
+
view.dispatch(tr);
|
|
913
|
+
}
|
|
914
|
+
function markComposedAsInsertion({ view, from, startDoc, foreignSize, foreignEdit, pluginState, replaced, compositionId }) {
|
|
850
915
|
const insertionType = view.state.schema.marks["insertion"];
|
|
851
916
|
const deletionType = view.state.schema.marks["deletion"];
|
|
852
917
|
if (!insertionType || !deletionType) return;
|
|
853
|
-
const
|
|
918
|
+
const { doc } = view.state;
|
|
919
|
+
const composedSize = doc.content.size - startDoc.content.size - foreignSize + (replaced?.size ?? 0);
|
|
920
|
+
const to = Math.min(from + composedSize, view.state.selection.to);
|
|
921
|
+
if (doc.eq(startDoc)) return;
|
|
922
|
+
if (composedSize === 0 && !replaced) {
|
|
923
|
+
if (!foreignEdit) restoreAfterCancelledComposition(view, startDoc);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
854
926
|
if (to <= from && !replaced) return;
|
|
855
927
|
const tr = view.state.tr;
|
|
856
928
|
tr.setMeta(SUGGESTION_META, true);
|
|
@@ -894,15 +966,24 @@ function recordSplitParagraph(tr, before, step, insertedFrom, insertedTo, attrs)
|
|
|
894
966
|
if ($last.parent.type.name === "paragraph") lastPos = $last.before();
|
|
895
967
|
else if ($last.nodeBefore?.type.name === "paragraph") lastPos = insertedTo - $last.nodeBefore.nodeSize;
|
|
896
968
|
if ($first.parent.type.name !== "paragraph" || lastPos === null || lastPos === $first.before()) return;
|
|
969
|
+
const revision = {
|
|
970
|
+
id: attrs.revisionId,
|
|
971
|
+
author: attrs.author,
|
|
972
|
+
date: attrs.date
|
|
973
|
+
};
|
|
974
|
+
const { pPrMark } = expectParagraphAttrs(split);
|
|
975
|
+
if (pPrMark) {
|
|
976
|
+
tr.setNodeAttribute(lastPos, "pPrMark", pPrMark);
|
|
977
|
+
tr.setNodeAttribute($first.before(), "pPrMark", {
|
|
978
|
+
kind: "ins",
|
|
979
|
+
info: revision
|
|
980
|
+
});
|
|
981
|
+
}
|
|
897
982
|
recordReplacedParagraphProperties({
|
|
898
983
|
tr,
|
|
899
984
|
position: lastPos,
|
|
900
985
|
replaced: split,
|
|
901
|
-
revision
|
|
902
|
-
id: attrs.revisionId,
|
|
903
|
-
author: attrs.author,
|
|
904
|
-
date: attrs.date
|
|
905
|
-
}
|
|
986
|
+
revision
|
|
906
987
|
});
|
|
907
988
|
}
|
|
908
989
|
/**
|
|
@@ -937,6 +1018,62 @@ function restoreReplacedInline({ tr, replaced, deletionType, pluginState }) {
|
|
|
937
1018
|
markRangeAsDeleted(tr, tr.doc, pos, pos + content.size, deletionType, pluginState);
|
|
938
1019
|
}
|
|
939
1020
|
}
|
|
1021
|
+
const readableContent = (content) => content.textBetween(0, content.size, "", "");
|
|
1022
|
+
/**
|
|
1023
|
+
* The inline content a step puts in place of a selection, or null for block
|
|
1024
|
+
* content. Between containers, the step also carries the text after the
|
|
1025
|
+
* selection over into the first one, and fills out what it cut with empty blocks.
|
|
1026
|
+
*/
|
|
1027
|
+
const insertedInline = (step, $to, to) => {
|
|
1028
|
+
const { content } = step.slice;
|
|
1029
|
+
let inline = content;
|
|
1030
|
+
while (inline.firstChild && !inline.firstChild.isInline) inline = inline.firstChild.content;
|
|
1031
|
+
if (readableContent(inline) !== readableContent(content)) return null;
|
|
1032
|
+
if (step.to === to || step instanceof ReplaceAroundStep) return inline;
|
|
1033
|
+
const tail = $to.parent.content.cut($to.parentOffset);
|
|
1034
|
+
const kept = inline.size - tail.size;
|
|
1035
|
+
return kept >= 0 && inline.cut(kept).eq(tail) ? inline.cut(0, kept) : null;
|
|
1036
|
+
};
|
|
1037
|
+
/**
|
|
1038
|
+
* A transaction the plugin did not build (a key binding, a command) replacing a
|
|
1039
|
+
* selection that spans textblocks. Null for anything else: table structure and
|
|
1040
|
+
* block content have their own paths, and a replacement inside one textblock
|
|
1041
|
+
* is `replacedInline`'s.
|
|
1042
|
+
*/
|
|
1043
|
+
function spanningReplacement(oldState, userTr) {
|
|
1044
|
+
const [step] = userTr.steps;
|
|
1045
|
+
const { doc, selection } = oldState;
|
|
1046
|
+
if (userTr.steps.length !== 1 || !(step instanceof ReplaceStep || step instanceof ReplaceAroundStep) || userTr.before !== doc || selection.empty) return null;
|
|
1047
|
+
const selectsAll = selection instanceof AllSelection;
|
|
1048
|
+
const from = selectsAll ? Selection.atStart(doc).from : selection.from;
|
|
1049
|
+
const to = selectsAll ? Selection.atEnd(doc).to : selection.to;
|
|
1050
|
+
const $from = doc.resolve(from);
|
|
1051
|
+
const $to = doc.resolve(to);
|
|
1052
|
+
if (!$from.parent.inlineContent || !$to.parent.inlineContent || $from.sameParent($to) || step.from > from || step.to < to || step instanceof ReplaceAroundStep && step.gapFrom < to) return null;
|
|
1053
|
+
const inserted = insertedInline(step, $to, to);
|
|
1054
|
+
return inserted && {
|
|
1055
|
+
step,
|
|
1056
|
+
from,
|
|
1057
|
+
to,
|
|
1058
|
+
inserted
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Put the document back and make the same replacement as typing over the
|
|
1063
|
+
* selection does: the selected text is struck and what replaced it follows, so
|
|
1064
|
+
* rejecting restores the source and accepting matches the direct edit.
|
|
1065
|
+
*/
|
|
1066
|
+
function trackSpanningReplacement({ tr, oldState, replacement: { step, from, to, inserted }, insertionType, deletionType, pluginState }) {
|
|
1067
|
+
tr.step(step.invert(oldState.doc));
|
|
1068
|
+
const restored = tr.mapping.maps.length;
|
|
1069
|
+
markRangeAsDeleted(tr, tr.doc, from, to, deletionType, pluginState, oldState);
|
|
1070
|
+
const at = tr.mapping.slice(restored).map(to);
|
|
1071
|
+
tr.insert(at, inserted);
|
|
1072
|
+
const end = at + inserted.size;
|
|
1073
|
+
tr.removeMark(at, end, deletionType);
|
|
1074
|
+
markRangeAsInserted(tr, tr.doc, at, end, insertionType, deletionType, makeMarkAttrs(pluginState));
|
|
1075
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(end), -1));
|
|
1076
|
+
}
|
|
940
1077
|
/**
|
|
941
1078
|
* Create the suggestion mode plugin.
|
|
942
1079
|
* When active, text edits become tracked changes.
|
|
@@ -944,6 +1081,9 @@ function restoreReplacedInline({ tr, replaced, deletionType, pluginState }) {
|
|
|
944
1081
|
function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
945
1082
|
let composing = false;
|
|
946
1083
|
let compositionFrom = null;
|
|
1084
|
+
let compositionStartDoc = null;
|
|
1085
|
+
let compositionForeignSize = 0;
|
|
1086
|
+
let compositionForeignEdit = false;
|
|
947
1087
|
let compositionReplaced = null;
|
|
948
1088
|
let compositionId = null;
|
|
949
1089
|
return new Plugin({
|
|
@@ -959,6 +1099,11 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
959
1099
|
apply(tr, state) {
|
|
960
1100
|
const nativeCompositionId = tr.getMeta("composition");
|
|
961
1101
|
if (composing && tr.docChanged && typeof nativeCompositionId === "number") compositionId = nativeCompositionId;
|
|
1102
|
+
if (composing && tr.docChanged && tr.getMeta("y-sync$") !== void 0) {
|
|
1103
|
+
compositionForeignEdit = true;
|
|
1104
|
+
compositionForeignSize += tr.doc.content.size - tr.before.content.size;
|
|
1105
|
+
if (compositionFrom !== null) compositionFrom = tr.mapping.map(compositionFrom);
|
|
1106
|
+
}
|
|
962
1107
|
const meta = tr.getMeta(suggestionModeKey);
|
|
963
1108
|
if (meta) return {
|
|
964
1109
|
...state,
|
|
@@ -987,16 +1132,21 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
987
1132
|
compositionId = null;
|
|
988
1133
|
const { from, to } = view.state.selection;
|
|
989
1134
|
compositionFrom = from;
|
|
1135
|
+
compositionStartDoc = view.state.doc;
|
|
1136
|
+
compositionForeignSize = 0;
|
|
1137
|
+
compositionForeignEdit = false;
|
|
990
1138
|
compositionReplaced = from === to ? null : view.state.doc.slice(from, to);
|
|
991
1139
|
return false;
|
|
992
1140
|
},
|
|
993
1141
|
compositionend(view) {
|
|
994
1142
|
const pluginState = suggestionModeKey.getState(view.state);
|
|
995
1143
|
const from = compositionFrom;
|
|
1144
|
+
const startDoc = compositionStartDoc;
|
|
996
1145
|
const replaced = compositionReplaced;
|
|
997
1146
|
compositionFrom = null;
|
|
1147
|
+
compositionStartDoc = null;
|
|
998
1148
|
compositionReplaced = null;
|
|
999
|
-
if (!pluginState?.active || from == null) {
|
|
1149
|
+
if (!pluginState?.active || from == null || !startDoc) {
|
|
1000
1150
|
composing = false;
|
|
1001
1151
|
compositionId = null;
|
|
1002
1152
|
return false;
|
|
@@ -1008,6 +1158,9 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1008
1158
|
if (current?.active) markComposedAsInsertion({
|
|
1009
1159
|
view,
|
|
1010
1160
|
from,
|
|
1161
|
+
startDoc,
|
|
1162
|
+
foreignSize: compositionForeignSize,
|
|
1163
|
+
foreignEdit: compositionForeignEdit,
|
|
1011
1164
|
pluginState: current,
|
|
1012
1165
|
replaced,
|
|
1013
1166
|
compositionId: nativeCompositionId
|
|
@@ -1027,6 +1180,7 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1027
1180
|
handleKeyDown(view, event) {
|
|
1028
1181
|
const pluginState = suggestionModeKey.getState(view.state);
|
|
1029
1182
|
if (!pluginState?.active) return false;
|
|
1183
|
+
if (composing) return false;
|
|
1030
1184
|
if (selectLockedInlineControl(view, event)) return true;
|
|
1031
1185
|
if (event.key === "Enter" && !event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
1032
1186
|
const { $from, empty } = view.state.selection;
|
|
@@ -1036,8 +1190,9 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1036
1190
|
if (event.key === "Backspace" && undoInputRule(view.state, view.dispatch)) return true;
|
|
1037
1191
|
if (event.key === "Backspace" || event.key === "Delete") {
|
|
1038
1192
|
const { $from, empty } = view.state.selection;
|
|
1039
|
-
|
|
1040
|
-
if (event.
|
|
1193
|
+
const atListItemStart = event.key === "Backspace" && empty && $from.parentOffset === 0 && $from.parent.type.name === "paragraph" && expectParagraphAttrs($from.parent).numPr?.kind === "reference";
|
|
1194
|
+
if (atListItemStart && !event.ctrlKey && !event.metaKey && !event.shiftKey) return false;
|
|
1195
|
+
if (event.key === "Backspace" && !atListItemStart && clearIndentOnBackspace(view.state, (tr) => {
|
|
1041
1196
|
const revision = makeMarkAttrs(pluginState);
|
|
1042
1197
|
recordReplacedParagraphProperties({
|
|
1043
1198
|
tr,
|
|
@@ -1070,7 +1225,7 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1070
1225
|
return handleSuggestionTableCellPaste(view, slice, pluginState) || handleSuggestionPaste(view, slice, pluginState);
|
|
1071
1226
|
}
|
|
1072
1227
|
},
|
|
1073
|
-
appendTransaction(transactions,
|
|
1228
|
+
appendTransaction(transactions, oldState, newState) {
|
|
1074
1229
|
const pluginState = suggestionModeKey.getState(newState);
|
|
1075
1230
|
if (!pluginState?.active) return null;
|
|
1076
1231
|
if (composing) return null;
|
|
@@ -1084,6 +1239,18 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1084
1239
|
const deletionType = newState.schema.marks["deletion"];
|
|
1085
1240
|
const laterMaps = transactions.slice(transactions.indexOf(userTr) + 1).flatMap((transaction) => transaction.mapping.maps);
|
|
1086
1241
|
const restoresReplaced = userTr.getMeta("appendedTransaction") === void 0;
|
|
1242
|
+
const spanning = deletionType && restoresReplaced && newState.doc === userTr.doc ? spanningReplacement(oldState, userTr) : null;
|
|
1243
|
+
if (deletionType && spanning) {
|
|
1244
|
+
trackSpanningReplacement({
|
|
1245
|
+
tr,
|
|
1246
|
+
oldState,
|
|
1247
|
+
replacement: spanning,
|
|
1248
|
+
insertionType,
|
|
1249
|
+
deletionType,
|
|
1250
|
+
pluginState
|
|
1251
|
+
});
|
|
1252
|
+
return tr;
|
|
1253
|
+
}
|
|
1087
1254
|
const replaced = [];
|
|
1088
1255
|
for (const [stepIndex, step] of userTr.steps.entries()) {
|
|
1089
1256
|
const stepMap = step.getMap();
|
|
@@ -12,6 +12,7 @@ export declare const NON_INCLUSIVE_MARK_DISPOSITION: {
|
|
|
12
12
|
readonly hyperlink: "carry";
|
|
13
13
|
readonly footnoteRef: "followsTheText";
|
|
14
14
|
readonly runIdentity: "followsTheText";
|
|
15
|
+
readonly hyphenElement: "followsTheText";
|
|
15
16
|
readonly insertion: "followsTheText";
|
|
16
17
|
readonly deletion: "followsTheText";
|
|
17
18
|
readonly runPropertyChange: "followsTheText";
|
|
@@ -84,6 +84,7 @@ const NON_INCLUSIVE_MARK_DISPOSITION = {
|
|
|
84
84
|
hyperlink: "carry",
|
|
85
85
|
footnoteRef: "followsTheText",
|
|
86
86
|
runIdentity: "followsTheText",
|
|
87
|
+
hyphenElement: "followsTheText",
|
|
87
88
|
insertion: "followsTheText",
|
|
88
89
|
deletion: "followsTheText",
|
|
89
90
|
runPropertyChange: "followsTheText",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
/**
|
|
3
|
+
* What a row omits, as its placeholders hold it now: column edits move them, and
|
|
4
|
+
* the formatting the row was read with goes stale. Before its cells, this is
|
|
5
|
+
* what places them. After them it stays a statement of no more than the row
|
|
6
|
+
* omits: the row may stop short of the table by more than it states.
|
|
7
|
+
*/
|
|
8
|
+
export declare const rowGridOmissions: (row: Node, statedAfter: number) => {
|
|
9
|
+
gridBefore: number;
|
|
10
|
+
gridAfter: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/prosemirror/rowGridOmissions.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a row omits, as its placeholders hold it now: column edits move them, and
|
|
4
|
+
* the formatting the row was read with goes stale. Before its cells, this is
|
|
5
|
+
* what places them. After them it stays a statement of no more than the row
|
|
6
|
+
* omits: the row may stop short of the table by more than it states.
|
|
7
|
+
*/
|
|
8
|
+
const rowGridOmissions = (row, statedAfter) => {
|
|
9
|
+
let before = 0;
|
|
10
|
+
let after = 0;
|
|
11
|
+
row.forEach((cell) => {
|
|
12
|
+
const colspan = Number(cell.attrs["colspan"]) || 1;
|
|
13
|
+
if (cell.attrs["_omittedGridSlot"] === "before") before += colspan;
|
|
14
|
+
if (cell.attrs["_omittedGridSlot"] === "after") after += colspan;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
gridBefore: before,
|
|
18
|
+
gridAfter: Math.min(statedAfter, after)
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { rowGridOmissions };
|
|
@@ -14,6 +14,14 @@ export type SectionBreakType = (typeof SECTION_BREAK_TYPES)[number];
|
|
|
14
14
|
export declare const parseSectionBreakType: (value: unknown) => SectionBreakType | null;
|
|
15
15
|
/** The section record a paragraph holds, or `null` when it ends no section. */
|
|
16
16
|
export declare const sectionPropertiesOf: (paragraph: Node) => document_d_exports.SectionProperties | null;
|
|
17
|
+
/**
|
|
18
|
+
* The positions of paragraphs that hold only a copy of a section record: every
|
|
19
|
+
* carrier of a record but its last. The from-leg writes the record on the last
|
|
20
|
+
* carrier alone (`keepTheSectionBreakOnTheLastParagraphThatCarriesIt`), so a
|
|
21
|
+
* resolution that lets the last carrier's mark go must not leave a copy to
|
|
22
|
+
* inherit the section a saved package no longer has.
|
|
23
|
+
*/
|
|
24
|
+
export declare const sectionRecordCopyPositions: (doc: Node) => number[];
|
|
17
25
|
/**
|
|
18
26
|
* The break type a section record states, or `null` when it states none.
|
|
19
27
|
*
|
|
@@ -19,6 +19,34 @@ const parseSectionBreakType = (value) => isSectionBreakType(value) ? value : nul
|
|
|
19
19
|
/** The section record a paragraph holds, or `null` when it ends no section. */
|
|
20
20
|
const sectionPropertiesOf = (paragraph) => paragraph.attrs["_sectionProperties"] ?? null;
|
|
21
21
|
/**
|
|
22
|
+
* The positions of paragraphs that hold only a copy of a section record: every
|
|
23
|
+
* carrier of a record but its last. The from-leg writes the record on the last
|
|
24
|
+
* carrier alone (`keepTheSectionBreakOnTheLastParagraphThatCarriesIt`), so a
|
|
25
|
+
* resolution that lets the last carrier's mark go must not leave a copy to
|
|
26
|
+
* inherit the section a saved package no longer has.
|
|
27
|
+
*/
|
|
28
|
+
const sectionRecordCopyPositions = (doc) => {
|
|
29
|
+
const lastCarrier = /* @__PURE__ */ new Map();
|
|
30
|
+
const copies = [];
|
|
31
|
+
const visit = (parent, parentStart) => {
|
|
32
|
+
parent.forEach((node, offset) => {
|
|
33
|
+
const position = parentStart + offset;
|
|
34
|
+
if (!node.isTextblock) {
|
|
35
|
+
if (!node.isLeaf) visit(node, position + 1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (node.type.name !== "paragraph") return;
|
|
39
|
+
const record = sectionPropertiesOf(node);
|
|
40
|
+
if (record === null) return;
|
|
41
|
+
const earlier = lastCarrier.get(record);
|
|
42
|
+
if (earlier !== void 0) copies.push(earlier);
|
|
43
|
+
lastCarrier.set(record, position);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
visit(doc, 0);
|
|
47
|
+
return copies;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
22
50
|
* The break type a section record states, or `null` when it states none.
|
|
23
51
|
*
|
|
24
52
|
* The single derivation every reader goes through. Every producer of a record
|
|
@@ -36,4 +64,4 @@ const sectionBreakTypeOf = (properties) => properties?.sectionStart ?? null;
|
|
|
36
64
|
* package does with a `w:sectPr` that omits them.
|
|
37
65
|
*/
|
|
38
66
|
const mintSectionProperties = (breakType) => ({ sectionStart: breakType });
|
|
39
|
-
export { SECTION_BREAK_TYPES, mintSectionProperties, parseSectionBreakType, sectionBreakTypeOf, sectionPropertiesOf };
|
|
67
|
+
export { SECTION_BREAK_TYPES, mintSectionProperties, parseSectionBreakType, sectionBreakTypeOf, sectionPropertiesOf, sectionRecordCopyPositions };
|