@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.29 → 0.4.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/__tests__/playwrightHelpers.d.ts +2 -2
- package/dist/__tests__/playwrightPage.d.ts +2 -50
- package/dist/commands.js +43 -178
- package/dist/ensureSelectionPlugin.js +3 -3
- package/dist/features/joinOnDelete/index.d.ts +19 -4
- package/dist/features/joinOnDelete/index.js +53 -166
- package/dist/generateId.js +4 -31
- package/dist/index.d.ts +2 -5
- package/dist/index.js +2 -4
- package/dist/replaceStep.d.ts +1 -1
- package/dist/schema.d.ts +1 -2
- package/dist/schema.js +1 -37
- package/dist/testing/testBuilders.d.ts +2 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +2 -6
- package/dist/withSuggestChanges.d.ts +14 -11
- package/dist/withSuggestChanges.js +94 -64
- package/package.json +1 -1
- package/src/features/joinOnDelete/README.md +8 -0
- package/dist/features/joinOnDelete/__tests__/joinOnDeleteInLists.playwright.test.d.ts +0 -1
- package/dist/features/joinOnDelete/__tests__/joinOnDeleteInListsTipTapStyle.playwright.test.d.ts +0 -1
- package/dist/features/joinOnDelete/__tests__/listWithJoinsAndStructureMarks.playwright.test.d.ts +0 -1
- package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.d.ts +0 -6
- package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.js +0 -24
- package/dist/features/joinOnDelete/types.d.ts +0 -34
- package/dist/features/joinOnDelete/types.js +0 -20
- package/dist/features/transactionShaping/detectSpecialTransactionShape.d.ts +0 -3
- package/dist/features/transactionShaping/detectSpecialTransactionShape.js +0 -4
- package/dist/features/transactionShaping/index.d.ts +0 -3
- package/dist/features/transactionShaping/index.js +0 -11
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.d.ts +0 -3
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.js +0 -48
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.d.ts +0 -1
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.js +0 -188
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.d.ts +0 -3
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.js +0 -64
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.d.ts +0 -2
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.js +0 -2
- package/dist/features/transactionShaping/types.d.ts +0 -20
- package/dist/features/transactionShaping/types.js +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteStructure.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/buildMaterializedPaths.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listStructure.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listStructureTextEdits.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/splitDetection.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/addIdAttr.d.ts +0 -2
- package/dist/features/wrapUnwrap/addIdAttr.js +0 -60
- package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.d.ts +0 -10
- package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.js +0 -41
- package/dist/features/wrapUnwrap/apply/index.d.ts +0 -5
- package/dist/features/wrapUnwrap/apply/index.js +0 -21
- package/dist/features/wrapUnwrap/areEquivalentStructureMarks.d.ts +0 -2
- package/dist/features/wrapUnwrap/areEquivalentStructureMarks.js +0 -17
- package/dist/features/wrapUnwrap/buildMaterializedPaths.d.ts +0 -3
- package/dist/features/wrapUnwrap/buildMaterializedPaths.js +0 -82
- package/dist/features/wrapUnwrap/constants.d.ts +0 -3
- package/dist/features/wrapUnwrap/constants.js +0 -3
- package/dist/features/wrapUnwrap/generateUniqueNodeId.d.ts +0 -1
- package/dist/features/wrapUnwrap/generateUniqueNodeId.js +0 -6
- package/dist/features/wrapUnwrap/getNodeId.d.ts +0 -2
- package/dist/features/wrapUnwrap/getNodeId.js +0 -5
- package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.d.ts +0 -3
- package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.js +0 -37
- package/dist/features/wrapUnwrap/revert/index.d.ts +0 -5
- package/dist/features/wrapUnwrap/revert/index.js +0 -19
- package/dist/features/wrapUnwrap/revert/revertAddOp.d.ts +0 -4
- package/dist/features/wrapUnwrap/revert/revertAddOp.js +0 -4
- package/dist/features/wrapUnwrap/revert/revertMoveOp.d.ts +0 -16
- package/dist/features/wrapUnwrap/revert/revertMoveOp.js +0 -122
- package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.d.ts +0 -10
- package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.js +0 -236
- package/dist/features/wrapUnwrap/sameParentChain.d.ts +0 -2
- package/dist/features/wrapUnwrap/sameParentChain.js +0 -4
- package/dist/features/wrapUnwrap/structureChangesPlugin.d.ts +0 -17
- package/dist/features/wrapUnwrap/structureChangesPlugin.js +0 -299
- package/dist/features/wrapUnwrap/types.d.ts +0 -54
- package/dist/features/wrapUnwrap/types.js +0 -23
- package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.d.ts +0 -17
- package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.js +0 -106
- package/dist/listInputRules.d.ts +0 -2
- package/dist/listInputRules.js +0 -14
- package/dist/rebaseStep.d.ts +0 -9
- package/dist/rebaseStep.js +0 -11
- package/dist/testing/e2eTestSchema.d.ts +0 -2
- package/dist/transformToSuggestionTransaction.d.ts +0 -22
- package/dist/transformToSuggestionTransaction.js +0 -101
- package/dist/wrappingInputRule.d.ts +0 -4
- package/dist/wrappingInputRule.js +0 -28
|
@@ -140,9 +140,9 @@ export declare function assertReverted(finalState: EditorState, initialState: Ed
|
|
|
140
140
|
* This helper replaces the editor document with the provided JSON,
|
|
141
141
|
* clears transactions, and returns initial state.
|
|
142
142
|
*/
|
|
143
|
-
export declare function setupDocFromJSON(page: Page, docJSON:
|
|
143
|
+
export declare function setupDocFromJSON(page: Page, docJSON: unknown): Promise<{
|
|
144
144
|
initialState: EditorState;
|
|
145
|
-
initialDoc:
|
|
145
|
+
initialDoc: unknown;
|
|
146
146
|
}>;
|
|
147
147
|
/**
|
|
148
148
|
* Assert that document fully reverted to initial state.
|
|
@@ -1,63 +1,15 @@
|
|
|
1
|
-
import { type Node } from "prosemirror-model";
|
|
2
1
|
import { type Locator, type Page } from "@playwright/test";
|
|
3
2
|
export declare class EditorPage {
|
|
4
3
|
readonly page: Page;
|
|
5
|
-
readonly deletionMarksVisibility: "hidden" | "visible";
|
|
6
4
|
private readonly selectors;
|
|
7
|
-
constructor(page: Page
|
|
5
|
+
constructor(page: Page);
|
|
8
6
|
get editor(): Locator;
|
|
9
|
-
getParagraphText(index: number
|
|
10
|
-
getParagraphAt(index: number): Locator;
|
|
7
|
+
getParagraphText(index: number): Promise<string>;
|
|
11
8
|
getParagraphCount(): Promise<number>;
|
|
12
|
-
getListItems(): Locator;
|
|
13
|
-
getParagraphs(): Locator;
|
|
14
|
-
getListItemCount(): Promise<number>;
|
|
15
9
|
getProseMirrorMarkCount(name: string): Promise<number>;
|
|
16
|
-
getProseMirrorMarksJSON(): Promise<unknown[]>;
|
|
17
10
|
getProseMirrorSelection(): Promise<{
|
|
18
11
|
anchor: number;
|
|
19
12
|
head: number;
|
|
20
13
|
}>;
|
|
21
14
|
getDOMTextContentOfChildAtIndex(index: number): Promise<string>;
|
|
22
|
-
getDocJSON(): Promise<object>;
|
|
23
|
-
getCurrentDoc(): Promise<Node>;
|
|
24
|
-
getCurrentAndExpectedDoc(expectedDocJSON: object): Promise<{
|
|
25
|
-
currentDoc: Node;
|
|
26
|
-
expectedDoc: Node;
|
|
27
|
-
}>;
|
|
28
|
-
revertSuggestion(suggestionId: number): Promise<void>;
|
|
29
|
-
revertAll(): Promise<void>;
|
|
30
|
-
applyAll(): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Perform an action and wait for ProseMirror state to update.
|
|
33
|
-
* Stores the current state reference before pressing, then polls until
|
|
34
|
-
* editor.view.state is a different object (ProseMirror creates a new
|
|
35
|
-
* immutable state on every transaction).
|
|
36
|
-
*/
|
|
37
|
-
private doActionAndWaitForState;
|
|
38
|
-
/**
|
|
39
|
-
* Press a key and wait for ProseMirror state to update.
|
|
40
|
-
* Stores the current state reference before pressing, then polls until
|
|
41
|
-
* editor.view.state is a different object (ProseMirror creates a new
|
|
42
|
-
* immutable state on every transaction).
|
|
43
|
-
*/
|
|
44
|
-
pressKey(key: string, opts?: {
|
|
45
|
-
waitForSelectionChange?: boolean;
|
|
46
|
-
}): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Insert text and wait for ProseMirror state to update.
|
|
49
|
-
* Stores the current state reference before pressing, then polls until
|
|
50
|
-
* editor.view.state is a different object (ProseMirror creates a new
|
|
51
|
-
* immutable state on every transaction).
|
|
52
|
-
*/
|
|
53
|
-
insertText(text: string, opts?: {
|
|
54
|
-
waitForSelectionChange?: boolean;
|
|
55
|
-
}): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Press a key multiple times, waiting for editor state update after each press.
|
|
58
|
-
*/
|
|
59
|
-
pressKeyMultiple(key: string, count: number, opts?: {
|
|
60
|
-
waitForSelectionChange?: boolean;
|
|
61
|
-
}): Promise<void>;
|
|
62
|
-
setNextNodeId(nextNodeId: number): Promise<void>;
|
|
63
15
|
}
|
package/dist/commands.js
CHANGED
|
@@ -5,8 +5,6 @@ import { suggestChangesKey } from "./plugin.js";
|
|
|
5
5
|
import { getSuggestionMarks } from "./utils.js";
|
|
6
6
|
import { ZWSP } from "./constants.js";
|
|
7
7
|
import { maybeRevertJoinMark } from "./features/joinOnDelete/index.js";
|
|
8
|
-
import { revertAllStructureSuggestions, revertStructureSuggestion } from "./features/wrapUnwrap/revert/index.js";
|
|
9
|
-
import { applyAllStructureSuggestions, applyStructureSuggestion } from "./features/wrapUnwrap/apply/index.js";
|
|
10
8
|
/**
|
|
11
9
|
* Given a node and a transform, add a set of steps to the
|
|
12
10
|
* transform that applies all marks of type markTypeToApply
|
|
@@ -31,7 +29,6 @@ import { applyAllStructureSuggestions, applyStructureSuggestion } from "./featur
|
|
|
31
29
|
tr.removeNodeMark(0, markTypeToApply);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
|
-
const restoredStructureSuggestionIds = new Set();
|
|
35
32
|
node.descendants((child, pos)=>{
|
|
36
33
|
if (from !== undefined && pos < from) {
|
|
37
34
|
return true;
|
|
@@ -63,10 +60,8 @@ import { applyAllStructureSuggestions, applyStructureSuggestion } from "./featur
|
|
|
63
60
|
const insertionTo = insertionFrom + child.nodeSize;
|
|
64
61
|
if (child.isInline) {
|
|
65
62
|
tr.removeMark(insertionFrom, insertionTo, markTypeToApply);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
if (joinRevertResult) joinRevertResult.restoredStructureSuggestionIds.forEach((id)=>restoredStructureSuggestionIds.add(id));
|
|
69
|
-
if (!joinRevertResult && child.text === ZWSP) {
|
|
63
|
+
const reverted = maybeRevertJoinMark(tr, insertionFrom, insertionTo, child, markTypeToApply);
|
|
64
|
+
if (!reverted && child.text === ZWSP) {
|
|
70
65
|
tr.delete(insertionFrom, insertionTo);
|
|
71
66
|
}
|
|
72
67
|
} else {
|
|
@@ -74,9 +69,6 @@ import { applyAllStructureSuggestions, applyStructureSuggestion } from "./featur
|
|
|
74
69
|
}
|
|
75
70
|
return true;
|
|
76
71
|
});
|
|
77
|
-
return {
|
|
78
|
-
restoredStructureSuggestionIds
|
|
79
|
-
};
|
|
80
72
|
}
|
|
81
73
|
function revertModifications(node, pos, tr) {
|
|
82
74
|
const { modification } = getSuggestionMarks(node.type.schema);
|
|
@@ -142,42 +134,20 @@ function applyModificationsToTransform(node, tr, dir, suggestionId, from, to) {
|
|
|
142
134
|
}
|
|
143
135
|
export function applySuggestionsToNode(node) {
|
|
144
136
|
const { deletion, insertion } = getSuggestionMarks(node.type.schema);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, insertion, deletion);
|
|
150
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, 1);
|
|
151
|
-
// replay suggestion transform on top of the structure transform
|
|
152
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
153
|
-
structureTransform.step(step);
|
|
154
|
-
});
|
|
155
|
-
const secondStructureTransform = applyAllStructureSuggestions(structureTransform.doc);
|
|
156
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
157
|
-
structureTransform.step(step);
|
|
158
|
-
});
|
|
159
|
-
return structureTransform.doc;
|
|
137
|
+
const transform = new Transform(node);
|
|
138
|
+
applySuggestionsToTransform(node, transform, insertion, deletion);
|
|
139
|
+
applyModificationsToTransform(node, transform, 1);
|
|
140
|
+
return transform.doc;
|
|
160
141
|
}
|
|
161
142
|
export function applySuggestionsToRange(doc, from, to) {
|
|
162
|
-
const { deletion, insertion } = getSuggestionMarks(doc.type.schema);
|
|
163
143
|
// blockRange can only return null if a predicate is provided
|
|
164
144
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
165
145
|
const nodeRange = doc.resolve(from).blockRange(doc.resolve(to));
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, 1, undefined, nodeRange.start, nodeRange.end);
|
|
172
|
-
// replay suggestion transform on top of the structure transform
|
|
173
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
174
|
-
structureTransform.step(step);
|
|
175
|
-
});
|
|
176
|
-
const secondStructureTransform = applyAllStructureSuggestions(structureTransform.doc, structureTransform.mapping.map(from), structureTransform.mapping.map(to));
|
|
177
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
178
|
-
structureTransform.step(step);
|
|
179
|
-
});
|
|
180
|
-
return structureTransform.doc.slice(structureTransform.mapping.map(from), structureTransform.mapping.map(to));
|
|
146
|
+
const { deletion, insertion } = getSuggestionMarks(doc.type.schema);
|
|
147
|
+
const transform = new Transform(doc);
|
|
148
|
+
applySuggestionsToTransform(doc, transform, insertion, deletion, undefined, nodeRange.start, nodeRange.end);
|
|
149
|
+
applyModificationsToTransform(doc, transform, 1, undefined, nodeRange.start, nodeRange.end);
|
|
150
|
+
return transform.doc.slice(transform.mapping.map(from), transform.mapping.map(to));
|
|
181
151
|
}
|
|
182
152
|
/**
|
|
183
153
|
* Command that applies all tracked changes in a document.
|
|
@@ -187,30 +157,13 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
187
157
|
* contents left in the doc.
|
|
188
158
|
*/ export function applySuggestions(state, dispatch) {
|
|
189
159
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, insertion, deletion);
|
|
195
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, 1);
|
|
196
|
-
// replay suggestion transform on top of the structure transform
|
|
197
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
198
|
-
structureTransform.step(step);
|
|
199
|
-
});
|
|
200
|
-
const secondStructureTransform = applyAllStructureSuggestions(structureTransform.doc);
|
|
201
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
202
|
-
structureTransform.step(step);
|
|
203
|
-
});
|
|
204
|
-
// apply the structure transform to the transaction
|
|
205
|
-
const transaction = state.tr;
|
|
206
|
-
structureTransform.steps.forEach((step)=>{
|
|
207
|
-
transaction.step(step);
|
|
208
|
-
});
|
|
209
|
-
if (!transaction.steps.length) return false;
|
|
210
|
-
transaction.setMeta(suggestChangesKey, {
|
|
160
|
+
const tr = state.tr;
|
|
161
|
+
applySuggestionsToTransform(state.doc, tr, insertion, deletion);
|
|
162
|
+
applyModificationsToTransform(tr.doc, tr, 1);
|
|
163
|
+
tr.setMeta(suggestChangesKey, {
|
|
211
164
|
skip: true
|
|
212
165
|
});
|
|
213
|
-
dispatch?.(
|
|
166
|
+
dispatch?.(tr);
|
|
214
167
|
return true;
|
|
215
168
|
}
|
|
216
169
|
/**
|
|
@@ -222,30 +175,13 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
222
175
|
*/ export function applySuggestionsInRange(from, to) {
|
|
223
176
|
return (state, dispatch)=>{
|
|
224
177
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, insertion, deletion, undefined, from, to);
|
|
230
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, 1, undefined, from, to);
|
|
231
|
-
// replay suggestion transform on top of the structure transform
|
|
232
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
233
|
-
structureTransform.step(step);
|
|
234
|
-
});
|
|
235
|
-
const secondStructureTransform = applyAllStructureSuggestions(structureTransform.doc, from === undefined ? undefined : structureTransform.mapping.map(from), to === undefined ? undefined : structureTransform.mapping.map(to));
|
|
236
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
237
|
-
structureTransform.step(step);
|
|
238
|
-
});
|
|
239
|
-
// apply the structure transform to the transaction
|
|
240
|
-
const transaction = state.tr;
|
|
241
|
-
structureTransform.steps.forEach((step)=>{
|
|
242
|
-
transaction.step(step);
|
|
243
|
-
});
|
|
244
|
-
if (!transaction.steps.length) return false;
|
|
245
|
-
transaction.setMeta(suggestChangesKey, {
|
|
178
|
+
const tr = state.tr;
|
|
179
|
+
applySuggestionsToTransform(state.doc, tr, insertion, deletion, undefined, from, to);
|
|
180
|
+
applyModificationsToTransform(tr.doc, tr, 1, undefined, from, to);
|
|
181
|
+
tr.setMeta(suggestChangesKey, {
|
|
246
182
|
skip: true
|
|
247
183
|
});
|
|
248
|
-
dispatch?.(
|
|
184
|
+
dispatch?.(tr);
|
|
249
185
|
return true;
|
|
250
186
|
};
|
|
251
187
|
}
|
|
@@ -258,26 +194,14 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
258
194
|
*/ export function applySuggestion(suggestionId, from, to) {
|
|
259
195
|
return (state, dispatch)=>{
|
|
260
196
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, 1, undefined, from, to);
|
|
267
|
-
// replay suggestion transform on top of the structure transform
|
|
268
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
269
|
-
structureTransform.step(step);
|
|
270
|
-
});
|
|
271
|
-
// apply the structure transform to the transaction
|
|
272
|
-
const transaction = state.tr;
|
|
273
|
-
structureTransform.steps.forEach((step)=>{
|
|
274
|
-
transaction.step(step);
|
|
275
|
-
});
|
|
276
|
-
if (!transaction.steps.length) return false;
|
|
277
|
-
transaction.setMeta(suggestChangesKey, {
|
|
197
|
+
const tr = state.tr;
|
|
198
|
+
applySuggestionsToTransform(state.doc, tr, insertion, deletion, suggestionId, from, to);
|
|
199
|
+
applyModificationsToTransform(tr.doc, tr, 1, undefined, from, to);
|
|
200
|
+
if (!tr.steps.length) return false;
|
|
201
|
+
tr.setMeta(suggestChangesKey, {
|
|
278
202
|
skip: true
|
|
279
203
|
});
|
|
280
|
-
dispatch?.(
|
|
204
|
+
dispatch?.(tr);
|
|
281
205
|
return true;
|
|
282
206
|
};
|
|
283
207
|
}
|
|
@@ -289,30 +213,13 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
289
213
|
* Modifications tracked in modification marks will be reverted.
|
|
290
214
|
*/ export function revertSuggestions(state, dispatch) {
|
|
291
215
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, deletion, insertion);
|
|
297
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, -1);
|
|
298
|
-
// replay suggestion transform on top of the structure transform
|
|
299
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
300
|
-
structureTransform.step(step);
|
|
301
|
-
});
|
|
302
|
-
const secondStructureTransform = revertAllStructureSuggestions(structureTransform.doc);
|
|
303
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
304
|
-
structureTransform.step(step);
|
|
305
|
-
});
|
|
306
|
-
// apply the structure transform to the transaction
|
|
307
|
-
const transaction = state.tr;
|
|
308
|
-
structureTransform.steps.forEach((step)=>{
|
|
309
|
-
transaction.step(step);
|
|
310
|
-
});
|
|
311
|
-
if (!transaction.steps.length) return false;
|
|
312
|
-
transaction.setMeta(suggestChangesKey, {
|
|
216
|
+
const tr = state.tr;
|
|
217
|
+
applySuggestionsToTransform(state.doc, tr, deletion, insertion);
|
|
218
|
+
applyModificationsToTransform(tr.doc, tr, -1);
|
|
219
|
+
tr.setMeta(suggestChangesKey, {
|
|
313
220
|
skip: true
|
|
314
221
|
});
|
|
315
|
-
dispatch?.(
|
|
222
|
+
dispatch?.(tr);
|
|
316
223
|
return true;
|
|
317
224
|
}
|
|
318
225
|
/**
|
|
@@ -324,30 +231,13 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
324
231
|
*/ export function revertSuggestionsInRange(from, to) {
|
|
325
232
|
return (state, dispatch)=>{
|
|
326
233
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, deletion, insertion, undefined, from, to);
|
|
332
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, -1, undefined, from, to);
|
|
333
|
-
// replay suggestion transform on top of the structure transform
|
|
334
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
335
|
-
structureTransform.step(step);
|
|
336
|
-
});
|
|
337
|
-
const secondStructureTransform = revertAllStructureSuggestions(structureTransform.doc, from === undefined ? undefined : structureTransform.mapping.map(from), to === undefined ? undefined : structureTransform.mapping.map(to));
|
|
338
|
-
secondStructureTransform.steps.forEach((step)=>{
|
|
339
|
-
structureTransform.step(step);
|
|
340
|
-
});
|
|
341
|
-
// apply the structure transform to the transaction
|
|
342
|
-
const transaction = state.tr;
|
|
343
|
-
structureTransform.steps.forEach((step)=>{
|
|
344
|
-
transaction.step(step);
|
|
345
|
-
});
|
|
346
|
-
if (!transaction.steps.length) return false;
|
|
347
|
-
transaction.setMeta(suggestChangesKey, {
|
|
234
|
+
const tr = state.tr;
|
|
235
|
+
applySuggestionsToTransform(state.doc, tr, deletion, insertion, undefined, from, to);
|
|
236
|
+
applyModificationsToTransform(tr.doc, tr, -1, undefined, from, to);
|
|
237
|
+
tr.setMeta(suggestChangesKey, {
|
|
348
238
|
skip: true
|
|
349
239
|
});
|
|
350
|
-
dispatch?.(
|
|
240
|
+
dispatch?.(tr);
|
|
351
241
|
return true;
|
|
352
242
|
};
|
|
353
243
|
}
|
|
@@ -360,39 +250,14 @@ export function applySuggestionsToRange(doc, from, to) {
|
|
|
360
250
|
*/ export function revertSuggestion(suggestionId, from, to) {
|
|
361
251
|
return (state, dispatch)=>{
|
|
362
252
|
const { deletion, insertion } = getSuggestionMarks(state.schema);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const { restoredStructureSuggestionIds } = applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, deletion, insertion, suggestionId, from, to);
|
|
368
|
-
applyModificationsToTransform(suggestionsTransform.doc, suggestionsTransform, -1, undefined, from, to);
|
|
369
|
-
// replay suggestion transform on top of the structure transform
|
|
370
|
-
suggestionsTransform.steps.forEach((step)=>{
|
|
371
|
-
structureTransform.step(step);
|
|
372
|
-
});
|
|
373
|
-
if (restoredStructureSuggestionIds.has(suggestionId)) {
|
|
374
|
-
const restoredStructureTransform = revertStructureSuggestion(structureTransform.doc, suggestionId);
|
|
375
|
-
restoredStructureTransform.steps.forEach((step)=>{
|
|
376
|
-
structureTransform.step(step);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
restoredStructureSuggestionIds.forEach((restoredSuggestionId)=>{
|
|
380
|
-
if (restoredSuggestionId === suggestionId) return;
|
|
381
|
-
const restoredStructureTransform = revertStructureSuggestion(structureTransform.doc, restoredSuggestionId);
|
|
382
|
-
restoredStructureTransform.steps.forEach((step)=>{
|
|
383
|
-
structureTransform.step(step);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
// apply the structure transform to the transaction
|
|
387
|
-
const transaction = state.tr;
|
|
388
|
-
structureTransform.steps.forEach((step)=>{
|
|
389
|
-
transaction.step(step);
|
|
390
|
-
});
|
|
391
|
-
if (!transaction.steps.length) return false;
|
|
392
|
-
transaction.setMeta(suggestChangesKey, {
|
|
253
|
+
const tr = state.tr;
|
|
254
|
+
applySuggestionsToTransform(state.doc, tr, deletion, insertion, suggestionId, from, to);
|
|
255
|
+
if (!tr.steps.length) return false;
|
|
256
|
+
tr.setMeta(suggestChangesKey, {
|
|
393
257
|
skip: true
|
|
394
258
|
});
|
|
395
|
-
|
|
259
|
+
applyModificationsToTransform(tr.doc, tr, -1, undefined, from, to);
|
|
260
|
+
dispatch?.(tr);
|
|
396
261
|
return true;
|
|
397
262
|
};
|
|
398
263
|
}
|
|
@@ -63,7 +63,7 @@ export function ensureSelection() {
|
|
|
63
63
|
$newAnchor
|
|
64
64
|
});
|
|
65
65
|
trace("appendTransaction", "search for new valid $head...");
|
|
66
|
-
let $newHead =
|
|
66
|
+
let $newHead = getNewValidPos(newState.selection.$head, getDirection(oldState.selection.$head, newState.selection.$head, pluginState));
|
|
67
67
|
trace("appendTransaction", "new valid $head", $newHead?.pos, {
|
|
68
68
|
$newHead
|
|
69
69
|
});
|
|
@@ -147,8 +147,8 @@ function isPosValid($pos) {
|
|
|
147
147
|
const insertionBefore = insertion.isInSet($pos.nodeBefore?.marks ?? []);
|
|
148
148
|
const insertionAfter = insertion.isInSet($pos.nodeAfter?.marks ?? []);
|
|
149
149
|
const ZWSP_REGEXP = new RegExp(ZWSP, "g");
|
|
150
|
-
const isZWSPBefore = $pos.nodeBefore && $pos.nodeBefore.
|
|
151
|
-
const isZWSPAfter = $pos.nodeAfter && $pos.nodeAfter.
|
|
150
|
+
const isZWSPBefore = $pos.nodeBefore && $pos.nodeBefore.textContent.replace(ZWSP_REGEXP, "") === "";
|
|
151
|
+
const isZWSPAfter = $pos.nodeAfter && $pos.nodeAfter.textContent.replace(ZWSP_REGEXP, "") === "";
|
|
152
152
|
if (insertionBefore && insertionAfter && isZWSPBefore && isZWSPAfter) {
|
|
153
153
|
trace("isPosValid", $pos.pos, "pos invalid", "reason: between two ZWSP insertions", {
|
|
154
154
|
$pos
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { Mark, type Node, type MarkType, type ResolvedPos } from "prosemirror-model";
|
|
1
|
+
import { Mark, type Node, type Attrs, type MarkType, type ResolvedPos } from "prosemirror-model";
|
|
2
2
|
import { Transform } from "prosemirror-transform";
|
|
3
3
|
import { type Transaction } from "prosemirror-state";
|
|
4
4
|
import { type SuggestionId } from "../../generateId.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
interface JoinMarkAttrs {
|
|
6
|
+
type: "join";
|
|
7
|
+
data: {
|
|
8
|
+
leftNode: {
|
|
9
|
+
type: string;
|
|
10
|
+
attrs: object;
|
|
11
|
+
marks: object[];
|
|
12
|
+
};
|
|
13
|
+
rightNode: {
|
|
14
|
+
type: string;
|
|
15
|
+
attrs: object;
|
|
16
|
+
marks: object[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare function isJoinMarkAttrs(attrs: Attrs): attrs is JoinMarkAttrs;
|
|
21
|
+
export declare function maybeRevertJoinMark(tr: Transform, from: number, to: number, node: Node, markType: MarkType): boolean;
|
|
8
22
|
/**
|
|
9
23
|
* Remove ZWSP text nodes marked as deletions (except for type=join) from the given range
|
|
10
24
|
*/
|
|
@@ -20,3 +34,4 @@ export declare function joinNodesAndMarkJoinPoints(trackedTransaction: Transacti
|
|
|
20
34
|
*/
|
|
21
35
|
export declare function collapseZWSPNodes(trackedTransaction: Transaction, from: number, to: number): Transform;
|
|
22
36
|
export declare function findJoinMark(pos: ResolvedPos): Mark | null;
|
|
37
|
+
export {};
|