@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.27 → 0.3.3-wrap-unwrap.29

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.
@@ -7,7 +7,10 @@ export declare class EditorPage {
7
7
  constructor(page: Page, deletionMarksVisibility?: "hidden" | "visible");
8
8
  get editor(): Locator;
9
9
  getParagraphText(index: number, childIndexes?: number[]): Promise<string>;
10
+ getParagraphAt(index: number): Locator;
10
11
  getParagraphCount(): Promise<number>;
12
+ getListItems(): Locator;
13
+ getParagraphs(): Locator;
11
14
  getListItemCount(): Promise<number>;
12
15
  getProseMirrorMarkCount(name: string): Promise<number>;
13
16
  getProseMirrorMarksJSON(): Promise<unknown[]>;
package/dist/commands.js CHANGED
@@ -370,11 +370,18 @@ export function applySuggestionsToRange(doc, from, to) {
370
370
  suggestionsTransform.steps.forEach((step)=>{
371
371
  structureTransform.step(step);
372
372
  });
373
- restoredStructureSuggestionIds.forEach((suggestionId)=>{
373
+ if (restoredStructureSuggestionIds.has(suggestionId)) {
374
374
  const restoredStructureTransform = revertStructureSuggestion(structureTransform.doc, suggestionId);
375
375
  restoredStructureTransform.steps.forEach((step)=>{
376
376
  structureTransform.step(step);
377
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
+ });
378
385
  });
379
386
  // apply the structure transform to the transaction
380
387
  const transaction = state.tr;
@@ -0,0 +1,6 @@
1
+ import { type Selection } from "prosemirror-state";
2
+ import { type ReplaceStep, type Step } from "prosemirror-transform";
3
+ export declare function adjustForStartToStartTextblockDeletion(selection: Selection, step: ReplaceStep, prevSteps: Step[]): {
4
+ from: number;
5
+ to: number;
6
+ };
@@ -0,0 +1,54 @@
1
+ import { TextSelection } from "prosemirror-state";
2
+ export function adjustForStartToStartTextblockDeletion(selection, step, prevSteps) {
3
+ if (prevSteps.length > 0) return {
4
+ from: step.from,
5
+ to: step.to
6
+ };
7
+ if (!(selection instanceof TextSelection)) {
8
+ return {
9
+ from: step.from,
10
+ to: step.to
11
+ };
12
+ }
13
+ if (selection.empty || step.slice.size !== 0) {
14
+ return {
15
+ from: step.from,
16
+ to: step.to
17
+ };
18
+ }
19
+ const { $from, $to } = selection;
20
+ if (!$from.parent.isTextblock || !$to.parent.isTextblock) {
21
+ return {
22
+ from: step.from,
23
+ to: step.to
24
+ };
25
+ }
26
+ if ($from.parentOffset !== 0 || $to.parentOffset !== 0) {
27
+ return {
28
+ from: step.from,
29
+ to: step.to
30
+ };
31
+ }
32
+ if ($from.start() === $to.start()) return {
33
+ from: step.from,
34
+ to: step.to
35
+ };
36
+ if (step.from !== $from.before($from.depth)) {
37
+ return {
38
+ from: step.from,
39
+ to: step.to
40
+ };
41
+ }
42
+ if (step.to !== $to.before($to.depth)) {
43
+ return {
44
+ from: step.from,
45
+ to: step.to
46
+ };
47
+ }
48
+ // The step boundary is moved before the right textblock, but the selection
49
+ // boundary is the user-visible end of the deleted text range.
50
+ return {
51
+ from: step.from,
52
+ to: selection.to
53
+ };
54
+ }
@@ -1,5 +1,6 @@
1
1
  import { EditorState } from "prosemirror-state";
2
2
  import { preserveTransactionData, transformToSuggestionTransaction } from "../../../transformToSuggestionTransaction.js";
3
+ import { generateNextNumberId } from "../../../generateId.js";
3
4
  import { suggestStructureChanges } from "../../wrapUnwrap/structureChangesPlugin.js";
4
5
  import { detectSpecialTransactionShape } from "../detectSpecialTransactionShape.js";
5
6
  // handle the specific TipTap pattern when backspacing from a paragraph into a list above
@@ -14,6 +15,8 @@ export function handleTipTapParagraphIntoListJoin(args) {
14
15
  const docBefore = args.transaction.docs[0];
15
16
  if (!docBefore) return null;
16
17
  const trackedTransaction = args.state.tr;
18
+ const sharedSuggestionId = args.generateId ? args.generateId(args.state.schema, docBefore) : generateNextNumberId(args.state.schema, docBefore);
19
+ const generateSharedSuggestionId = ()=>sharedSuggestionId;
17
20
  try {
18
21
  trackedTransaction.step(shape.deleteStep);
19
22
  trackedTransaction.step(shape.insertStep);
@@ -26,7 +29,7 @@ export function handleTipTapParagraphIntoListJoin(args) {
26
29
  uniqueNodeIdsTransform.steps.forEach((step)=>{
27
30
  trackedTransaction.step(step);
28
31
  });
29
- const structureChangesResult = suggestStructureChanges(docBefore, uniqueNodeIdsTransform.doc, args.structuralContextPaths, args.generateId);
32
+ const structureChangesResult = suggestStructureChanges(docBefore, uniqueNodeIdsTransform.doc, args.structuralContextPaths, generateSharedSuggestionId);
30
33
  if (!structureChangesResult.handled) {
31
34
  return null;
32
35
  }
@@ -43,7 +46,7 @@ export function handleTipTapParagraphIntoListJoin(args) {
43
46
  } catch {
44
47
  return null;
45
48
  }
46
- const trackedJoinTransaction = transformToSuggestionTransaction(joinTransaction, intermediateState, args.generateId);
49
+ const trackedJoinTransaction = transformToSuggestionTransaction(joinTransaction, intermediateState, generateSharedSuggestionId);
47
50
  trackedJoinTransaction.steps.forEach((step)=>{
48
51
  trackedTransaction.step(step);
49
52
  });
@@ -4,6 +4,7 @@ import { rebasePos } from "./rebasePos.js";
4
4
  import { getSuggestionMarks } from "./utils.js";
5
5
  import { joinBlocks } from "./features/joinBlocks/index.js";
6
6
  import { collapseZWSPNodes, findJoinMark, joinNodesAndMarkJoinPoints, removeZWSPDeletions } from "./features/joinOnDelete/index.js";
7
+ import { adjustForStartToStartTextblockDeletion } from "./features/startToStartTextblockDeletion/index.js";
7
8
  /**
8
9
  * Transform a replace step into its equivalent tracked steps.
9
10
  *
@@ -35,17 +36,18 @@ import { collapseZWSPNodes, findJoinMark, joinNodesAndMarkJoinPoints, removeZWSP
35
36
  * zero-width spaces will be removed.
36
37
  */ export function suggestReplaceStep(trackedTransaction, state, doc, step, prevSteps, suggestionId) {
37
38
  const { deletion, insertion } = getSuggestionMarks(state.schema);
39
+ const semanticStep = adjustForStartToStartTextblockDeletion(state.selection, step, prevSteps);
38
40
  // Check for insertion and deletion marks directly
39
41
  // adjacent to this step's boundaries. If they exist,
40
42
  // we'll use their ids, rather than producing a new one
41
- const nodeBefore = doc.resolve(step.from).nodeBefore;
43
+ const nodeBefore = doc.resolve(semanticStep.from).nodeBefore;
42
44
  const markBefore = nodeBefore?.marks.find((mark)=>mark.type === deletion || mark.type === insertion) ?? null;
43
- const nodeAfter = doc.resolve(step.to).nodeAfter;
45
+ const nodeAfter = doc.resolve(semanticStep.to).nodeAfter;
44
46
  const markAfter = nodeAfter?.marks.find((mark)=>mark.type === deletion || mark.type === insertion) ?? null;
45
47
  let markId = markBefore?.attrs["id"] ?? markAfter?.attrs["id"] ?? suggestionId;
46
48
  // Rebase this step's boundaries onto the newest doc
47
- let stepFrom = rebasePos(step.from, prevSteps, trackedTransaction.steps);
48
- let stepTo = rebasePos(step.to, prevSteps, trackedTransaction.steps);
49
+ let stepFrom = rebasePos(semanticStep.from, prevSteps, trackedTransaction.steps);
50
+ let stepTo = rebasePos(semanticStep.to, prevSteps, trackedTransaction.steps);
49
51
  if (state.selection.empty && stepFrom !== stepTo) {
50
52
  trackedTransaction.setSelection(TextSelection.near(trackedTransaction.doc.resolve(stepFrom)));
51
53
  }
@@ -58,8 +60,8 @@ import { collapseZWSPNodes, findJoinMark, joinNodesAndMarkJoinPoints, removeZWSP
58
60
  }
59
61
  // Update the step boundaries, since we may have just changed
60
62
  // the document
61
- stepFrom = rebasePos(step.from, prevSteps, trackedTransaction.steps);
62
- stepTo = rebasePos(step.to, prevSteps, trackedTransaction.steps);
63
+ stepFrom = rebasePos(semanticStep.from, prevSteps, trackedTransaction.steps);
64
+ stepTo = rebasePos(semanticStep.to, prevSteps, trackedTransaction.steps);
63
65
  // Re-resolve nodeAfter and markAfter if we did a block join
64
66
  // The original values are stale after joinBlocks modifies the document
65
67
  let nodeAfterResolved = nodeAfter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic-marker/prosemirror-suggest-changes",
3
- "version": "0.3.3-wrap-unwrap.27",
3
+ "version": "0.3.3-wrap-unwrap.29",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
@@ -55,17 +55,17 @@
55
55
  "markdown-toc": "^1.2.0",
56
56
  "playwright": "^1.56.0",
57
57
  "prettier": "^3.5.3",
58
- "prosemirror-commands": "^1.7.0",
59
- "prosemirror-history": "^1.5.0",
60
- "prosemirror-inputrules": "^1.4.0",
61
- "prosemirror-keymap": "^1.2.2",
62
- "prosemirror-model": "^1.24.1",
63
- "prosemirror-schema-basic": "^1.2.3",
64
- "prosemirror-schema-list": "^1.5.0",
65
- "prosemirror-state": "^1.4.3",
66
- "prosemirror-test-builder": "^1.1.1",
67
- "prosemirror-transform": "^1.10.2",
68
- "prosemirror-view": "^1.38.0",
58
+ "prosemirror-commands": "1.7.1",
59
+ "prosemirror-history": "1.5.0",
60
+ "prosemirror-inputrules": "1.5.1",
61
+ "prosemirror-keymap": "1.2.3",
62
+ "prosemirror-model": "1.25.4",
63
+ "prosemirror-schema-basic": "1.2.4",
64
+ "prosemirror-schema-list": "1.5.1",
65
+ "prosemirror-state": "1.4.4",
66
+ "prosemirror-test-builder": "1.1.1",
67
+ "prosemirror-transform": "1.12.0",
68
+ "prosemirror-view": "1.41.9",
69
69
  "remark-parse": "^11.0.0",
70
70
  "rimraf": "^6.0.1",
71
71
  "typescript": "^5.8.2",
@@ -79,5 +79,17 @@
79
79
  "prosemirror-state": "^1.0.0",
80
80
  "prosemirror-transform": "^1.0.0",
81
81
  "prosemirror-view": "^1.0.0"
82
+ },
83
+ "resolutions": {
84
+ "prosemirror-model": "1.25.4",
85
+ "prosemirror-state": "1.4.4",
86
+ "prosemirror-transform": "1.12.0",
87
+ "prosemirror-view": "1.41.9",
88
+ "prosemirror-keymap": "1.2.3",
89
+ "prosemirror-commands": "1.7.1",
90
+ "prosemirror-schema-basic": "1.2.4",
91
+ "prosemirror-schema-list": "1.5.1",
92
+ "prosemirror-history": "1.5.0",
93
+ "prosemirror-inputrules": "1.5.1"
82
94
  }
83
95
  }