@magic-marker/prosemirror-suggest-changes 0.3.3-wrap-unwrap.26 → 0.3.3-wrap-unwrap.28
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__/playwrightPage.d.ts +1 -0
- package/dist/features/startToStartTextblockDeletion/index.d.ts +6 -0
- package/dist/features/startToStartTextblockDeletion/index.js +54 -0
- package/dist/features/transactionShaping/tipTapParagraphIntoListJoin/handleTipTapParagraphIntoListJoin.js +1 -20
- package/dist/replaceStep.js +8 -6
- package/package.json +24 -12
|
@@ -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,9 +1,6 @@
|
|
|
1
1
|
import { EditorState } from "prosemirror-state";
|
|
2
2
|
import { preserveTransactionData, transformToSuggestionTransaction } from "../../../transformToSuggestionTransaction.js";
|
|
3
|
-
import { getSuggestionMarks } from "../../../utils.js";
|
|
4
|
-
import { getNodeId } from "../../wrapUnwrap/getNodeId.js";
|
|
5
3
|
import { suggestStructureChanges } from "../../wrapUnwrap/structureChangesPlugin.js";
|
|
6
|
-
import { guardStructureMarkAttrs } from "../../wrapUnwrap/types.js";
|
|
7
4
|
import { detectSpecialTransactionShape } from "../detectSpecialTransactionShape.js";
|
|
8
5
|
// handle the specific TipTap pattern when backspacing from a paragraph into a list above
|
|
9
6
|
// causes a transaction with 3 steps
|
|
@@ -16,8 +13,6 @@ export function handleTipTapParagraphIntoListJoin(args) {
|
|
|
16
13
|
if (!args.structuralContextPaths || !args.ensureUniqueNodeIds) return null;
|
|
17
14
|
const docBefore = args.transaction.docs[0];
|
|
18
15
|
if (!docBefore) return null;
|
|
19
|
-
const movedNodeId = getNodeId(shape.movedNode);
|
|
20
|
-
if (!movedNodeId) return null;
|
|
21
16
|
const trackedTransaction = args.state.tr;
|
|
22
17
|
try {
|
|
23
18
|
trackedTransaction.step(shape.deleteStep);
|
|
@@ -32,7 +27,7 @@ export function handleTipTapParagraphIntoListJoin(args) {
|
|
|
32
27
|
trackedTransaction.step(step);
|
|
33
28
|
});
|
|
34
29
|
const structureChangesResult = suggestStructureChanges(docBefore, uniqueNodeIdsTransform.doc, args.structuralContextPaths, args.generateId);
|
|
35
|
-
if (!structureChangesResult.handled
|
|
30
|
+
if (!structureChangesResult.handled) {
|
|
36
31
|
return null;
|
|
37
32
|
}
|
|
38
33
|
structureChangesResult.transform.steps.forEach((step)=>{
|
|
@@ -64,17 +59,3 @@ export function handleTipTapParagraphIntoListJoin(args) {
|
|
|
64
59
|
function isTipTapParagraphIntoListJoinShape(shape) {
|
|
65
60
|
return shape?.type === "tipTapParagraphIntoListJoin";
|
|
66
61
|
}
|
|
67
|
-
function hasMoveStructureMark(structureChangesResult, movedNodeId) {
|
|
68
|
-
const { structure } = getSuggestionMarks(structureChangesResult.transform.doc.type.schema);
|
|
69
|
-
let found = false;
|
|
70
|
-
structureChangesResult.transform.doc.descendants((node)=>{
|
|
71
|
-
if (getNodeId(node) !== movedNodeId) return true;
|
|
72
|
-
found = node.marks.some((mark)=>{
|
|
73
|
-
if (mark.type !== structure) return false;
|
|
74
|
-
if (!guardStructureMarkAttrs(mark.attrs)) return false;
|
|
75
|
-
return mark.attrs.data.op.op === "move";
|
|
76
|
-
});
|
|
77
|
-
return !found;
|
|
78
|
-
});
|
|
79
|
-
return found;
|
|
80
|
-
}
|
package/dist/replaceStep.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
48
|
-
let stepTo = rebasePos(
|
|
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(
|
|
62
|
-
stepTo = rebasePos(
|
|
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.
|
|
3
|
+
"version": "0.3.3-wrap-unwrap.28",
|
|
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": "
|
|
59
|
-
"prosemirror-history": "
|
|
60
|
-
"prosemirror-inputrules": "
|
|
61
|
-
"prosemirror-keymap": "
|
|
62
|
-
"prosemirror-model": "
|
|
63
|
-
"prosemirror-schema-basic": "
|
|
64
|
-
"prosemirror-schema-list": "
|
|
65
|
-
"prosemirror-state": "
|
|
66
|
-
"prosemirror-test-builder": "
|
|
67
|
-
"prosemirror-transform": "
|
|
68
|
-
"prosemirror-view": "
|
|
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
|
}
|