@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.
Files changed (88) hide show
  1. package/dist/__tests__/playwrightHelpers.d.ts +2 -2
  2. package/dist/__tests__/playwrightPage.d.ts +2 -50
  3. package/dist/commands.js +43 -178
  4. package/dist/ensureSelectionPlugin.js +3 -3
  5. package/dist/features/joinOnDelete/index.d.ts +19 -4
  6. package/dist/features/joinOnDelete/index.js +53 -166
  7. package/dist/generateId.js +4 -31
  8. package/dist/index.d.ts +2 -5
  9. package/dist/index.js +2 -4
  10. package/dist/replaceStep.d.ts +1 -1
  11. package/dist/schema.d.ts +1 -2
  12. package/dist/schema.js +1 -37
  13. package/dist/testing/testBuilders.d.ts +2 -1
  14. package/dist/utils.d.ts +0 -1
  15. package/dist/utils.js +2 -6
  16. package/dist/withSuggestChanges.d.ts +14 -11
  17. package/dist/withSuggestChanges.js +94 -64
  18. package/package.json +1 -1
  19. package/src/features/joinOnDelete/README.md +8 -0
  20. package/dist/features/joinOnDelete/__tests__/joinOnDeleteInLists.playwright.test.d.ts +0 -1
  21. package/dist/features/joinOnDelete/__tests__/joinOnDeleteInListsTipTapStyle.playwright.test.d.ts +0 -1
  22. package/dist/features/joinOnDelete/__tests__/listWithJoinsAndStructureMarks.playwright.test.d.ts +0 -1
  23. package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.d.ts +0 -6
  24. package/dist/features/joinOnDelete/normalizeJoinNodesMetadata.js +0 -24
  25. package/dist/features/joinOnDelete/types.d.ts +0 -34
  26. package/dist/features/joinOnDelete/types.js +0 -20
  27. package/dist/features/transactionShaping/detectSpecialTransactionShape.d.ts +0 -3
  28. package/dist/features/transactionShaping/detectSpecialTransactionShape.js +0 -4
  29. package/dist/features/transactionShaping/index.d.ts +0 -3
  30. package/dist/features/transactionShaping/index.js +0 -11
  31. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.d.ts +0 -3
  32. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.js +0 -48
  33. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.d.ts +0 -1
  34. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/detectTipTapParagraphIntoListJoin.test.js +0 -188
  35. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.d.ts +0 -3
  36. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.js +0 -64
  37. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.d.ts +0 -2
  38. package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/index.js +0 -2
  39. package/dist/features/transactionShaping/types.d.ts +0 -20
  40. package/dist/features/transactionShaping/types.js +0 -1
  41. package/dist/features/wrapUnwrap/__tests__/blockquoteStructure.playwright.test.d.ts +0 -1
  42. package/dist/features/wrapUnwrap/__tests__/buildMaterializedPaths.test.d.ts +0 -1
  43. package/dist/features/wrapUnwrap/__tests__/listStructure.playwright.test.d.ts +0 -1
  44. package/dist/features/wrapUnwrap/__tests__/listStructureTextEdits.playwright.test.d.ts +0 -1
  45. package/dist/features/wrapUnwrap/__tests__/splitDetection.test.d.ts +0 -1
  46. package/dist/features/wrapUnwrap/addIdAttr.d.ts +0 -2
  47. package/dist/features/wrapUnwrap/addIdAttr.js +0 -60
  48. package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.d.ts +0 -10
  49. package/dist/features/wrapUnwrap/apply/applyStructureSuggestions.js +0 -41
  50. package/dist/features/wrapUnwrap/apply/index.d.ts +0 -5
  51. package/dist/features/wrapUnwrap/apply/index.js +0 -21
  52. package/dist/features/wrapUnwrap/areEquivalentStructureMarks.d.ts +0 -2
  53. package/dist/features/wrapUnwrap/areEquivalentStructureMarks.js +0 -17
  54. package/dist/features/wrapUnwrap/buildMaterializedPaths.d.ts +0 -3
  55. package/dist/features/wrapUnwrap/buildMaterializedPaths.js +0 -82
  56. package/dist/features/wrapUnwrap/constants.d.ts +0 -3
  57. package/dist/features/wrapUnwrap/constants.js +0 -3
  58. package/dist/features/wrapUnwrap/generateUniqueNodeId.d.ts +0 -1
  59. package/dist/features/wrapUnwrap/generateUniqueNodeId.js +0 -6
  60. package/dist/features/wrapUnwrap/getNodeId.d.ts +0 -2
  61. package/dist/features/wrapUnwrap/getNodeId.js +0 -5
  62. package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.d.ts +0 -3
  63. package/dist/features/wrapUnwrap/revert/deleteNodeUpwards.js +0 -37
  64. package/dist/features/wrapUnwrap/revert/index.d.ts +0 -5
  65. package/dist/features/wrapUnwrap/revert/index.js +0 -19
  66. package/dist/features/wrapUnwrap/revert/revertAddOp.d.ts +0 -4
  67. package/dist/features/wrapUnwrap/revert/revertAddOp.js +0 -4
  68. package/dist/features/wrapUnwrap/revert/revertMoveOp.d.ts +0 -16
  69. package/dist/features/wrapUnwrap/revert/revertMoveOp.js +0 -122
  70. package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.d.ts +0 -10
  71. package/dist/features/wrapUnwrap/revert/revertStructureSuggestions.js +0 -236
  72. package/dist/features/wrapUnwrap/sameParentChain.d.ts +0 -2
  73. package/dist/features/wrapUnwrap/sameParentChain.js +0 -4
  74. package/dist/features/wrapUnwrap/structureChangesPlugin.d.ts +0 -17
  75. package/dist/features/wrapUnwrap/structureChangesPlugin.js +0 -299
  76. package/dist/features/wrapUnwrap/types.d.ts +0 -54
  77. package/dist/features/wrapUnwrap/types.js +0 -23
  78. package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.d.ts +0 -17
  79. package/dist/features/wrapUnwrap/uniqueNodeIdsPlugin.js +0 -106
  80. package/dist/listInputRules.d.ts +0 -2
  81. package/dist/listInputRules.js +0 -14
  82. package/dist/rebaseStep.d.ts +0 -9
  83. package/dist/rebaseStep.js +0 -11
  84. package/dist/testing/e2eTestSchema.d.ts +0 -2
  85. package/dist/transformToSuggestionTransaction.d.ts +0 -22
  86. package/dist/transformToSuggestionTransaction.js +0 -101
  87. package/dist/wrappingInputRule.d.ts +0 -4
  88. 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: object): Promise<{
143
+ export declare function setupDocFromJSON(page: Page, docJSON: unknown): Promise<{
144
144
  initialState: EditorState;
145
- initialDoc: object;
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, deletionMarksVisibility?: "hidden" | "visible");
5
+ constructor(page: Page);
8
6
  get editor(): Locator;
9
- getParagraphText(index: number, childIndexes?: number[]): Promise<string>;
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 joinRevertResult = maybeRevertJoinMark(tr, insertionFrom, insertionTo, child, markTypeToApply);
67
- // reverting a join mark may produce new structure marks that were serialized in the join metadata
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
- // first, create a structure transform that applies all structure changes on the given node
146
- const structureTransform = applyAllStructureSuggestions(node);
147
- // then start a clear transform from the document where the structure changes are applied
148
- const suggestionsTransform = new Transform(structureTransform.doc);
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
- // create a structure transform that applies all structure changes on the given node range
167
- const structureTransform = applyAllStructureSuggestions(doc, nodeRange.start, nodeRange.end);
168
- // then start a clear transform from the document where the structure changes are applied
169
- const suggestionsTransform = new Transform(structureTransform.doc);
170
- applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, insertion, deletion, undefined, nodeRange.start, nodeRange.end);
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
- // create a structure transform that applies all structure changes on the given document
191
- const structureTransform = applyAllStructureSuggestions(state.doc);
192
- // then start a clear transform from the document where the structure changes are applied
193
- const suggestionsTransform = new Transform(structureTransform.doc);
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?.(transaction);
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
- // create a structure transform that applies all structure changes on the given node range
226
- const structureTransform = applyAllStructureSuggestions(state.doc, from, to);
227
- // then start a clear transform from the document where the structure changes are applied
228
- const suggestionsTransform = new Transform(structureTransform.doc);
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?.(transaction);
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
- // create a structure transform that applies the given structure change on the given node
262
- const structureTransform = applyStructureSuggestion(state.doc, suggestionId);
263
- // then start a clear transform from the document where the structure changes are applied
264
- const suggestionsTransform = new Transform(structureTransform.doc);
265
- applySuggestionsToTransform(suggestionsTransform.doc, suggestionsTransform, insertion, deletion, suggestionId, from, to);
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?.(transaction);
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
- // create a structure transform that reverts all structure changes on the given document
293
- const structureTransform = revertAllStructureSuggestions(state.doc);
294
- // then start a clear transform from the document where the structure changes are reverted
295
- const suggestionsTransform = new Transform(structureTransform.doc);
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?.(transaction);
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
- // create a structure transform that reverts all structure changes on the given node range
328
- const structureTransform = revertAllStructureSuggestions(state.doc, from, to);
329
- // then start a clear transform from the document where the structure changes are reverted
330
- const suggestionsTransform = new Transform(structureTransform.doc);
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?.(transaction);
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
- // create a structure transform that reverts the given structure change on the given node
364
- const structureTransform = revertStructureSuggestion(state.doc, suggestionId);
365
- // then start a clear transform from the document where the structure changes are reverted
366
- const suggestionsTransform = new Transform(structureTransform.doc);
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
- dispatch?.(transaction);
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 = newState.selection.empty ? $newAnchor : getNewValidPos(newState.selection.$head, getDirection(oldState.selection.$head, newState.selection.$head, pluginState));
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.isText && $pos.nodeBefore.textContent.replace(ZWSP_REGEXP, "") === "";
151
- const isZWSPAfter = $pos.nodeAfter && $pos.nodeAfter.isText && $pos.nodeAfter.textContent.replace(ZWSP_REGEXP, "") === "";
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
- export declare function maybeRevertJoinMark(tr: Transform, from: number, to: number, node: Node, markType: MarkType): false | {
6
- restoredStructureSuggestionIds: Set<SuggestionId>;
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 {};