@magic-marker/prosemirror-suggest-changes 0.2.1-wrap-unwrap.2 → 0.3.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__/playwrightBaseTest.d.ts +6 -0
- package/dist/__tests__/playwrightPage.d.ts +15 -0
- package/dist/commands.js +1 -10
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/decorations.js +4 -3
- package/dist/ensureSelectionPlugin.d.ts +13 -0
- package/dist/ensureSelectionPlugin.js +307 -0
- package/dist/generateId.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/plugin.js +2 -14
- package/dist/prependDeletionsWithZWSP.d.ts +2 -0
- package/dist/prependDeletionsWithZWSP.js +45 -0
- package/dist/replaceAroundStep.js +1 -6
- package/dist/replaceStep.js +3 -7
- package/dist/schema.d.ts +4 -2
- package/dist/schema.js +32 -39
- package/dist/testing/testBuilders.d.ts +2 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +2 -6
- package/dist/withSuggestChanges.js +4 -0
- package/package.json +1 -1
- package/dist/contentBetween.d.ts +0 -2
- package/dist/contentBetween.js +0 -33
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapAllNodes.data.d.ts +0 -38
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapOneNode.data.d.ts +0 -45
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapOneNode.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapSingleNode.data.d.ts +0 -38
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapSingleNode.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteUnwrapSingleNode.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapAllNodes.data.d.ts +0 -38
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapAllNodes.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapAllNodes.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapSingleNode.data.d.ts +0 -38
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapSingleNode.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/blockquoteWrapSingleNode.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftLast.data.d.ts +0 -54
- package/dist/features/wrapUnwrap/__tests__/listItemLiftLast.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftLast.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMiddle.data.d.ts +0 -48
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMiddle.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMiddle.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMultipleToTheTop.data.d.ts +0 -74
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMultipleToTheTop.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftMultipleToTheTop.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftNestedOnce.data.d.ts +0 -71
- package/dist/features/wrapUnwrap/__tests__/listItemLiftNestedOnce.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftNestedOnce.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftTop.data.d.ts +0 -54
- package/dist/features/wrapUnwrap/__tests__/listItemLiftTop.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemLiftTop.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemSinkMultiple.data.d.ts +0 -221
- package/dist/features/wrapUnwrap/__tests__/listItemSinkMultiple.page.d.ts +0 -16
- package/dist/features/wrapUnwrap/__tests__/listItemSinkMultiple.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemSinkMultiple.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemSinkOneOnce.data.d.ts +0 -51
- package/dist/features/wrapUnwrap/__tests__/listItemSinkOneOnce.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemSinkOneOnce.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemsLiftMixedLevels.data.d.ts +0 -74
- package/dist/features/wrapUnwrap/__tests__/listItemsLiftMixedLevels.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/listItemsLiftMixedLevels.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/nestedListItemLiftToOuter.data.d.ts +0 -71
- package/dist/features/wrapUnwrap/__tests__/nestedListItemLiftToOuter.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/nestedListItemLiftToOuter.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/nestedListItemsLiftMultipleLevels.data.d.ts +0 -114
- package/dist/features/wrapUnwrap/__tests__/nestedListItemsLiftMultipleLevels.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/nestedListItemsLiftMultipleLevels.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/testUtils.d.ts +0 -5
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesToTheTop.data.d.ts +0 -44
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesToTheTop.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesToTheTop.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesUp.data.d.ts +0 -38
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesUp.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftMultipleNodesUp.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeFromMiddle.data.d.ts +0 -46
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeFromMiddle.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeFromMiddle.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeToTheTop.data.d.ts +0 -57
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeToTheTop.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeToTheTop.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeUp.data.d.ts +0 -45
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeUp.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteLiftOneNodeUp.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrap.data.d.ts +0 -44
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrap.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrap.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrapMultiple.data.d.ts +0 -44
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrapMultiple.playwright.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/__tests__/tripleBlockquoteWrapMultiple.test.d.ts +0 -1
- package/dist/features/wrapUnwrap/handleStructureStep.d.ts +0 -4
- package/dist/features/wrapUnwrap/handleStructureStep.js +0 -630
- package/dist/features/wrapUnwrap/revertStructureSuggestion.d.ts +0 -44
- package/dist/features/wrapUnwrap/revertStructureSuggestion.js +0 -368
- package/dist/rebaseStep.d.ts +0 -9
- package/dist/rebaseStep.js +0 -11
- package/src/features/wrapUnwrap/README.md +0 -198
- /package/dist/features/{wrapUnwrap/__tests__/blockquoteUnwrapAllNodes.playwright.test.d.ts → hiddenDeletions/__tests__/hiddenDeletionsBehavior.playwright.test.d.ts} +0 -0
- /package/dist/features/{wrapUnwrap/__tests__/blockquoteUnwrapAllNodes.test.d.ts → joinBlocks/__tests__/joinBlockBackspace.playwright.test.d.ts} +0 -0
- /package/dist/features/{wrapUnwrap/__tests__/blockquoteUnwrapOneNode.playwright.test.d.ts → joinBlocks/__tests__/joinBlockDelete.playwright.test.d.ts} +0 -0
|
@@ -1,630 +0,0 @@
|
|
|
1
|
-
import { ReplaceAroundStep, ReplaceStep, Transform } from "prosemirror-transform";
|
|
2
|
-
import { contentBetween } from "../../contentBetween.js";
|
|
3
|
-
import { getSuggestionMarks } from "../../utils.js";
|
|
4
|
-
import { rebaseStep } from "../../rebaseStep.js";
|
|
5
|
-
export function handleStructureStep(trackedTransaction, state, step, prevSteps, suggestionId) {
|
|
6
|
-
if (step instanceof ReplaceAroundStep) {
|
|
7
|
-
return handleReplaceAroundStep(trackedTransaction, state, step, prevSteps, suggestionId);
|
|
8
|
-
}
|
|
9
|
-
if (step instanceof ReplaceStep) {
|
|
10
|
-
return handleReplaceStep(trackedTransaction, state, step, prevSteps, suggestionId);
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
function handleReplaceAroundStep(trackedTransaction, state, step, prevSteps, suggestionId) {
|
|
15
|
-
// consider step structure if structure === true or there is no content in from-gapFrom and gapTo-to
|
|
16
|
-
// inspired by https://github.com/ProseMirror/prosemirror-transform/blob/1.11.0/src/replace_step.ts#L110
|
|
17
|
-
const isStructureStep = step.structure || !(contentBetween(trackedTransaction.doc, step.from, step.gapFrom) || contentBetween(trackedTransaction.doc, step.gapTo, step.to));
|
|
18
|
-
if (!isStructureStep) return false;
|
|
19
|
-
console.groupCollapsed(`handle structure ReplaceAround step from = ${step.from.toString()}, to = ${step.to.toString()}, gapFrom = ${step.gapFrom.toString()}, gapTo = ${step.gapTo.toString()}`);
|
|
20
|
-
const { structure } = getSuggestionMarks(state.schema);
|
|
21
|
-
const rebasedStep = rebaseStep(step, prevSteps, trackedTransaction.steps);
|
|
22
|
-
console.log({
|
|
23
|
-
step,
|
|
24
|
-
rebasedStep
|
|
25
|
-
});
|
|
26
|
-
if (!rebasedStep || !(rebasedStep instanceof ReplaceAroundStep)) {
|
|
27
|
-
throw new Error("Failed to rebase replace around step: unexpected step type");
|
|
28
|
-
}
|
|
29
|
-
const docBeforeStep = trackedTransaction.doc;
|
|
30
|
-
trackedTransaction.step(rebasedStep);
|
|
31
|
-
const inverseStep = rebasedStep.invert(docBeforeStep);
|
|
32
|
-
console.log({
|
|
33
|
-
inverseStep
|
|
34
|
-
});
|
|
35
|
-
if (!(inverseStep instanceof ReplaceAroundStep)) {
|
|
36
|
-
throw new Error("Failed to invert replace around step: unexpected step type");
|
|
37
|
-
}
|
|
38
|
-
const inverseFrom = inverseStep.from;
|
|
39
|
-
const inverseTo = inverseStep.to;
|
|
40
|
-
const $inverseFrom = trackedTransaction.doc.resolve(inverseFrom);
|
|
41
|
-
const $inverseTo = trackedTransaction.doc.resolve(inverseTo);
|
|
42
|
-
const inverseGapFrom = inverseStep.gapFrom;
|
|
43
|
-
const inverseGapTo = inverseStep.gapTo;
|
|
44
|
-
const $inverseGapFrom = trackedTransaction.doc.resolve(inverseGapFrom);
|
|
45
|
-
const $inverseGapTo = trackedTransaction.doc.resolve(inverseGapTo);
|
|
46
|
-
const inverseBlockRange = $inverseFrom.blockRange($inverseTo);
|
|
47
|
-
const inverseGapBlockRange = $inverseGapFrom.blockRange($inverseGapTo);
|
|
48
|
-
if (!inverseBlockRange || !inverseGapBlockRange) {
|
|
49
|
-
throw new Error("Failed to get inverse block range: unexpected range");
|
|
50
|
-
}
|
|
51
|
-
const slice = inverseStep.slice.toJSON();
|
|
52
|
-
const insert = inverseStep.insert;
|
|
53
|
-
// positive number - subtract from gapFrom later to reconstruct "from"
|
|
54
|
-
const fromOffset = inverseGapFrom - inverseFrom;
|
|
55
|
-
// positive number - add to gapTo on reverse to reconstruct "to"
|
|
56
|
-
const toOffset = inverseTo - inverseGapTo;
|
|
57
|
-
// positive number - add to from later to reconstruct "gapFrom"
|
|
58
|
-
const gapFromOffset = inverseGapFrom - inverseFrom;
|
|
59
|
-
// positive number - subtract from to later to reconstruct "gapTo"
|
|
60
|
-
const gapToOffset = inverseTo - inverseGapTo;
|
|
61
|
-
let fromFound = false;
|
|
62
|
-
let toFound = false;
|
|
63
|
-
let gapFromFound = false;
|
|
64
|
-
let gapToFound = false;
|
|
65
|
-
const isInverseStepStructural = inverseStep.structure;
|
|
66
|
-
const addStructureMark = (pos, data)=>{
|
|
67
|
-
trackedTransaction.addNodeMark(pos, structure.create({
|
|
68
|
-
id: suggestionId,
|
|
69
|
-
data: {
|
|
70
|
-
...data,
|
|
71
|
-
type: "replaceAround",
|
|
72
|
-
slice,
|
|
73
|
-
insert,
|
|
74
|
-
structure: isInverseStepStructural,
|
|
75
|
-
debug: {
|
|
76
|
-
inverseFrom,
|
|
77
|
-
inverseTo,
|
|
78
|
-
inverseGapFrom,
|
|
79
|
-
inverseGapTo,
|
|
80
|
-
gapFromOffset,
|
|
81
|
-
gapToOffset,
|
|
82
|
-
fromOffset,
|
|
83
|
-
toOffset
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}));
|
|
87
|
-
};
|
|
88
|
-
// check if inverseGapFrom or inverseGapTo are at the start of some node in range
|
|
89
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
90
|
-
if (node.isInline) return true;
|
|
91
|
-
let localGapFromFound = false;
|
|
92
|
-
// inverseGapFrom is at start of this node?
|
|
93
|
-
if (!gapFromFound && pos === inverseGapFrom) {
|
|
94
|
-
addStructureMark(pos, {
|
|
95
|
-
value: "gapFrom",
|
|
96
|
-
position: "start",
|
|
97
|
-
fromOffset
|
|
98
|
-
});
|
|
99
|
-
gapFromFound = localGapFromFound = true;
|
|
100
|
-
console.log("gapFrom at start of node", {
|
|
101
|
-
inverseGapFrom,
|
|
102
|
-
node,
|
|
103
|
-
pos
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
// inverseGapFrom is at inner start of this node?
|
|
107
|
-
if (!gapFromFound && pos + 1 === inverseGapFrom) {
|
|
108
|
-
addStructureMark(pos, {
|
|
109
|
-
value: "gapFrom",
|
|
110
|
-
position: "innerStart",
|
|
111
|
-
fromOffset
|
|
112
|
-
});
|
|
113
|
-
gapFromFound = localGapFromFound = true;
|
|
114
|
-
console.log("gapFrom at inner start of node", {
|
|
115
|
-
inverseGapFrom,
|
|
116
|
-
node,
|
|
117
|
-
pos: pos + 1
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
// if inverseGapFrom is at start of this node, maybe inverseGapTo is at the end of this node?
|
|
121
|
-
// this way the case when both gapFrom and gapTo can be indicated by the same node is prioritized
|
|
122
|
-
if (localGapFromFound && !gapToFound) {
|
|
123
|
-
// inverseGapTo is at end of this node?
|
|
124
|
-
if (pos + node.nodeSize === inverseGapTo) {
|
|
125
|
-
addStructureMark(pos, {
|
|
126
|
-
value: "gapTo",
|
|
127
|
-
position: "end",
|
|
128
|
-
toOffset
|
|
129
|
-
});
|
|
130
|
-
gapToFound = true;
|
|
131
|
-
console.log("ALSO gapTo at end of node", {
|
|
132
|
-
inverseGapTo,
|
|
133
|
-
node,
|
|
134
|
-
pos: pos + node.nodeSize
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// inverseGapTo is at inner end of this node?
|
|
138
|
-
if (pos + node.nodeSize - 1 === inverseGapTo) {
|
|
139
|
-
addStructureMark(pos, {
|
|
140
|
-
value: "gapTo",
|
|
141
|
-
position: "innerEnd",
|
|
142
|
-
toOffset
|
|
143
|
-
});
|
|
144
|
-
gapToFound = true;
|
|
145
|
-
console.log("ALSO gapTo at inner end of node", {
|
|
146
|
-
inverseGapTo,
|
|
147
|
-
node,
|
|
148
|
-
pos: pos + node.nodeSize - 1
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// inverseGapTo is at start of this node?
|
|
153
|
-
if (!gapToFound && pos === inverseGapTo) {
|
|
154
|
-
addStructureMark(pos, {
|
|
155
|
-
value: "gapTo",
|
|
156
|
-
position: "start",
|
|
157
|
-
toOffset
|
|
158
|
-
});
|
|
159
|
-
gapToFound = true;
|
|
160
|
-
console.log("gapTo at start of node", {
|
|
161
|
-
inverseGapTo,
|
|
162
|
-
node,
|
|
163
|
-
pos
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
// inverseGapTo is at inner start of this node?
|
|
167
|
-
if (!gapToFound && pos + 1 === inverseGapTo) {
|
|
168
|
-
addStructureMark(pos, {
|
|
169
|
-
value: "gapTo",
|
|
170
|
-
position: "innerStart",
|
|
171
|
-
toOffset
|
|
172
|
-
});
|
|
173
|
-
gapToFound = true;
|
|
174
|
-
console.log("gapTo at inner start of node", {
|
|
175
|
-
inverseGapTo,
|
|
176
|
-
node,
|
|
177
|
-
pos: pos + 1
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
});
|
|
182
|
-
// check if inverseGapFrom or inverseGapTo are at the end of some node
|
|
183
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
184
|
-
if (node.isInline) return true;
|
|
185
|
-
// inverseGapFrom is at end of this node?
|
|
186
|
-
if (!gapFromFound && pos + node.nodeSize === inverseGapFrom) {
|
|
187
|
-
addStructureMark(pos, {
|
|
188
|
-
value: "gapFrom",
|
|
189
|
-
position: "end",
|
|
190
|
-
fromOffset
|
|
191
|
-
});
|
|
192
|
-
gapFromFound = true;
|
|
193
|
-
console.log("gapFrom at end of node", {
|
|
194
|
-
inverseGapFrom,
|
|
195
|
-
node,
|
|
196
|
-
pos: pos + node.nodeSize
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
// inverseGapFrom is at inner end of this node?
|
|
200
|
-
if (!gapFromFound && pos + node.nodeSize - 1 === inverseGapFrom) {
|
|
201
|
-
addStructureMark(pos, {
|
|
202
|
-
value: "gapFrom",
|
|
203
|
-
position: "innerEnd",
|
|
204
|
-
fromOffset
|
|
205
|
-
});
|
|
206
|
-
gapFromFound = true;
|
|
207
|
-
console.log("gapFrom at inner end of node", {
|
|
208
|
-
inverseGapFrom,
|
|
209
|
-
node,
|
|
210
|
-
pos: pos + node.nodeSize - 1
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
// inverseGapTo is at end of this node?
|
|
214
|
-
if (!gapToFound && pos + node.nodeSize === inverseGapTo) {
|
|
215
|
-
addStructureMark(pos, {
|
|
216
|
-
value: "gapTo",
|
|
217
|
-
position: "end",
|
|
218
|
-
toOffset
|
|
219
|
-
});
|
|
220
|
-
gapToFound = true;
|
|
221
|
-
console.log("gapTo at end of node", {
|
|
222
|
-
inverseGapTo,
|
|
223
|
-
node,
|
|
224
|
-
pos: pos + node.nodeSize
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
// inverseGapTo is at inner end of this node?
|
|
228
|
-
if (!gapToFound && pos + node.nodeSize - 1 === inverseGapTo) {
|
|
229
|
-
addStructureMark(pos, {
|
|
230
|
-
value: "gapTo",
|
|
231
|
-
position: "innerEnd",
|
|
232
|
-
toOffset
|
|
233
|
-
});
|
|
234
|
-
gapToFound = true;
|
|
235
|
-
console.log("gapTo at inner end of node", {
|
|
236
|
-
inverseGapTo,
|
|
237
|
-
node,
|
|
238
|
-
pos: pos + node.nodeSize - 1
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return true;
|
|
242
|
-
});
|
|
243
|
-
// check if inverseFrom, inverseTo are at the start of some node in range
|
|
244
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
245
|
-
if (node.isInline) return true;
|
|
246
|
-
let localFromFound = false;
|
|
247
|
-
// inverseFrom is at start of this node?
|
|
248
|
-
if (!fromFound && pos === inverseFrom) {
|
|
249
|
-
addStructureMark(pos, {
|
|
250
|
-
value: "from",
|
|
251
|
-
position: "start",
|
|
252
|
-
gapFromOffset
|
|
253
|
-
});
|
|
254
|
-
fromFound = localFromFound = true;
|
|
255
|
-
console.log("from at start of node", {
|
|
256
|
-
inverseFrom,
|
|
257
|
-
node,
|
|
258
|
-
pos
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
// inverseFrom is at inner start of this node?
|
|
262
|
-
if (!fromFound && pos + 1 === inverseFrom) {
|
|
263
|
-
addStructureMark(pos, {
|
|
264
|
-
value: "from",
|
|
265
|
-
position: "innerStart",
|
|
266
|
-
gapFromOffset
|
|
267
|
-
});
|
|
268
|
-
fromFound = localFromFound = true;
|
|
269
|
-
console.log("from at inner start of node", {
|
|
270
|
-
inverseFrom,
|
|
271
|
-
node,
|
|
272
|
-
pos: pos + 1
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
// if inverseFrom is at start of this node, maybe inverseTo is at the end of this node?
|
|
276
|
-
// this way the case when both from and to can be indicated by the same node is prioritized
|
|
277
|
-
if (localFromFound && !toFound) {
|
|
278
|
-
// inverseTo is at end of this node?
|
|
279
|
-
if (pos + node.nodeSize === inverseTo) {
|
|
280
|
-
addStructureMark(pos, {
|
|
281
|
-
value: "to",
|
|
282
|
-
position: "end",
|
|
283
|
-
gapToOffset
|
|
284
|
-
});
|
|
285
|
-
toFound = true;
|
|
286
|
-
console.log("ALSO found to at end of node", {
|
|
287
|
-
inverseTo,
|
|
288
|
-
node,
|
|
289
|
-
pos: pos + node.nodeSize
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
// inverseTo is at inner end of this node?
|
|
293
|
-
if (pos + node.nodeSize - 1 === inverseTo) {
|
|
294
|
-
addStructureMark(pos, {
|
|
295
|
-
value: "to",
|
|
296
|
-
position: "innerEnd",
|
|
297
|
-
gapToOffset
|
|
298
|
-
});
|
|
299
|
-
toFound = true;
|
|
300
|
-
console.log("ALSO found to at inner end of node", {
|
|
301
|
-
inverseTo,
|
|
302
|
-
node,
|
|
303
|
-
pos: pos + node.nodeSize - 1
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// inverseTo is at start of this node?
|
|
308
|
-
if (!toFound && pos === inverseTo) {
|
|
309
|
-
addStructureMark(pos, {
|
|
310
|
-
value: "to",
|
|
311
|
-
position: "start",
|
|
312
|
-
gapToOffset
|
|
313
|
-
});
|
|
314
|
-
toFound = true;
|
|
315
|
-
console.log("to at start of node", {
|
|
316
|
-
inverseTo,
|
|
317
|
-
node,
|
|
318
|
-
pos
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
// inverseTo is at inner start of this node?
|
|
322
|
-
if (!toFound && pos + 1 === inverseTo) {
|
|
323
|
-
addStructureMark(pos, {
|
|
324
|
-
value: "to",
|
|
325
|
-
position: "innerStart",
|
|
326
|
-
gapToOffset
|
|
327
|
-
});
|
|
328
|
-
toFound = true;
|
|
329
|
-
console.log("to at inner start of node", {
|
|
330
|
-
inverseTo,
|
|
331
|
-
node,
|
|
332
|
-
pos: pos + 1
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
return true;
|
|
336
|
-
});
|
|
337
|
-
// check if inverseFrom, inverseTo are at the end of some node in range
|
|
338
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
339
|
-
if (node.isInline) return true;
|
|
340
|
-
// inverseFrom is at end of this node?
|
|
341
|
-
if (!fromFound && pos + node.nodeSize === inverseFrom) {
|
|
342
|
-
addStructureMark(pos, {
|
|
343
|
-
value: "from",
|
|
344
|
-
position: "end",
|
|
345
|
-
gapFromOffset
|
|
346
|
-
});
|
|
347
|
-
fromFound = true;
|
|
348
|
-
console.log("from at end of node", {
|
|
349
|
-
inverseFrom,
|
|
350
|
-
node,
|
|
351
|
-
pos: pos + node.nodeSize
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
// inverseFrom is at inner end of this node?
|
|
355
|
-
if (!fromFound && pos + node.nodeSize - 1 === inverseFrom) {
|
|
356
|
-
addStructureMark(pos, {
|
|
357
|
-
value: "from",
|
|
358
|
-
position: "innerEnd",
|
|
359
|
-
gapFromOffset
|
|
360
|
-
});
|
|
361
|
-
fromFound = true;
|
|
362
|
-
console.log("from at inner end of node", {
|
|
363
|
-
inverseFrom,
|
|
364
|
-
node,
|
|
365
|
-
pos: pos + node.nodeSize - 1
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
// inverseTo is at end of this node?
|
|
369
|
-
if (!toFound && pos + node.nodeSize === inverseTo) {
|
|
370
|
-
addStructureMark(pos, {
|
|
371
|
-
value: "to",
|
|
372
|
-
position: "end",
|
|
373
|
-
gapToOffset
|
|
374
|
-
});
|
|
375
|
-
toFound = true;
|
|
376
|
-
console.log("found to at end of node", {
|
|
377
|
-
inverseTo,
|
|
378
|
-
node,
|
|
379
|
-
pos: pos + node.nodeSize
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
// inverseTo is at inner end of this node?
|
|
383
|
-
if (!toFound && pos + node.nodeSize - 1 === inverseTo) {
|
|
384
|
-
addStructureMark(pos, {
|
|
385
|
-
value: "to",
|
|
386
|
-
position: "innerEnd",
|
|
387
|
-
gapToOffset
|
|
388
|
-
});
|
|
389
|
-
toFound = true;
|
|
390
|
-
console.log("found to at inner end of node", {
|
|
391
|
-
inverseTo,
|
|
392
|
-
node,
|
|
393
|
-
pos: pos + node.nodeSize - 1
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return true;
|
|
397
|
-
});
|
|
398
|
-
if (gapFromFound && gapToFound && fromFound && toFound) {
|
|
399
|
-
console.log("all points found");
|
|
400
|
-
} else {
|
|
401
|
-
console.log("not all points found", {
|
|
402
|
-
step,
|
|
403
|
-
inverseStep,
|
|
404
|
-
rebasedStep
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
console.groupEnd();
|
|
408
|
-
return true;
|
|
409
|
-
}
|
|
410
|
-
function handleReplaceStep(trackedTransaction, state, step, prevSteps, suggestionId) {
|
|
411
|
-
const isStructureStep = step.structure || !contentBetween(trackedTransaction.doc, step.from, step.to);
|
|
412
|
-
if (!isStructureStep) return false;
|
|
413
|
-
// handle this step as structure step
|
|
414
|
-
console.groupCollapsed(`handle structure Replace step from = ${step.from.toString()}, to = ${step.to.toString()}`);
|
|
415
|
-
const { structure } = getSuggestionMarks(state.schema);
|
|
416
|
-
const rebasedStep = rebaseStep(step, prevSteps, trackedTransaction.steps);
|
|
417
|
-
if (!rebasedStep || !(rebasedStep instanceof ReplaceStep)) {
|
|
418
|
-
throw new Error("Failed to rebase replace step: unexpected step type");
|
|
419
|
-
}
|
|
420
|
-
const transform = new Transform(trackedTransaction.doc);
|
|
421
|
-
const $stepFromBefore = trackedTransaction.doc.resolve(rebasedStep.from);
|
|
422
|
-
const $stepToBefore = trackedTransaction.doc.resolve(rebasedStep.to);
|
|
423
|
-
console.log({
|
|
424
|
-
$stepFromBefore,
|
|
425
|
-
$stepToBefore
|
|
426
|
-
});
|
|
427
|
-
transform.step(rebasedStep);
|
|
428
|
-
const $stepFromAfter = transform.doc.resolve(transform.mapping.map($stepFromBefore.pos));
|
|
429
|
-
const $stepToAfter = transform.doc.resolve(transform.mapping.map($stepToBefore.pos));
|
|
430
|
-
console.log({
|
|
431
|
-
$stepFromAfter,
|
|
432
|
-
$stepToAfter
|
|
433
|
-
});
|
|
434
|
-
// detect join inside textblock so we can bail out
|
|
435
|
-
// those are not handled with structure marks, those are handled with a ZWSP deletion mark
|
|
436
|
-
if (!$stepFromBefore.sameParent($stepToBefore) && $stepFromAfter.sameParent($stepToAfter) && $stepFromAfter.pos === $stepToAfter.pos && $stepFromAfter.parent.isTextblock) {
|
|
437
|
-
console.log("this is a join inside textblock");
|
|
438
|
-
console.groupEnd();
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
if (!$stepFromBefore.sameParent($stepToBefore) && $stepFromAfter.sameParent($stepToAfter) && $stepFromAfter.pos === $stepToAfter.pos && !$stepFromAfter.parent.isTextblock) {
|
|
442
|
-
console.log("this is a join inside non-textblock");
|
|
443
|
-
}
|
|
444
|
-
const docBeforeStep = trackedTransaction.doc;
|
|
445
|
-
trackedTransaction.step(rebasedStep);
|
|
446
|
-
const inverseStep = rebasedStep.invert(docBeforeStep);
|
|
447
|
-
if (!(inverseStep instanceof ReplaceStep)) {
|
|
448
|
-
throw new Error("Failed to invert replace step: unexpected step type");
|
|
449
|
-
}
|
|
450
|
-
const inverseFrom = inverseStep.from;
|
|
451
|
-
const inverseTo = inverseStep.to;
|
|
452
|
-
const $inverseFrom = trackedTransaction.doc.resolve(inverseFrom);
|
|
453
|
-
const $inverseTo = trackedTransaction.doc.resolve(inverseTo);
|
|
454
|
-
const inverseBlockRange = $inverseFrom.blockRange($inverseTo);
|
|
455
|
-
if (!inverseBlockRange) {
|
|
456
|
-
throw new Error("Failed to get inverse block range: unexpected range");
|
|
457
|
-
}
|
|
458
|
-
const slice = inverseStep.slice.toJSON();
|
|
459
|
-
let fromFound = false;
|
|
460
|
-
let toFound = false;
|
|
461
|
-
const isInverseStepStructural = inverseStep.structure || !contentBetween(trackedTransaction.doc, inverseFrom, inverseTo);
|
|
462
|
-
const addStructureMark = (pos, data)=>{
|
|
463
|
-
trackedTransaction.addNodeMark(pos, structure.create({
|
|
464
|
-
id: suggestionId,
|
|
465
|
-
data: {
|
|
466
|
-
...data,
|
|
467
|
-
type: "replace",
|
|
468
|
-
slice,
|
|
469
|
-
structure: isInverseStepStructural,
|
|
470
|
-
debug: {
|
|
471
|
-
inverseFrom,
|
|
472
|
-
inverseTo
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}));
|
|
476
|
-
};
|
|
477
|
-
// check if inverseFrom, inverseTo are at the start of some node in range
|
|
478
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
479
|
-
if (node.isInline) return true;
|
|
480
|
-
let localFromFound = false;
|
|
481
|
-
// inverseFrom is at start of this node?
|
|
482
|
-
if (!fromFound && pos === inverseFrom) {
|
|
483
|
-
addStructureMark(pos, {
|
|
484
|
-
value: "from",
|
|
485
|
-
position: "start"
|
|
486
|
-
});
|
|
487
|
-
fromFound = localFromFound = true;
|
|
488
|
-
console.log("from at start of node", {
|
|
489
|
-
inverseFrom,
|
|
490
|
-
node,
|
|
491
|
-
pos
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
// inverseFrom is at inner start of this node?
|
|
495
|
-
if (!fromFound && pos + 1 === inverseFrom) {
|
|
496
|
-
addStructureMark(pos, {
|
|
497
|
-
value: "from",
|
|
498
|
-
position: "innerStart"
|
|
499
|
-
});
|
|
500
|
-
fromFound = localFromFound = true;
|
|
501
|
-
console.log("from at inner start of node", {
|
|
502
|
-
inverseFrom,
|
|
503
|
-
node,
|
|
504
|
-
pos: pos + 1
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
// if inverseFrom is at start or innerStart of this node, maybe inverseTo is at the end or innerEnd of this node?
|
|
508
|
-
// this way the case when both from and to can be indicated by the same node is prioritized
|
|
509
|
-
if (localFromFound && !toFound) {
|
|
510
|
-
if (pos + node.nodeSize === inverseTo) {
|
|
511
|
-
addStructureMark(pos, {
|
|
512
|
-
value: "to",
|
|
513
|
-
position: "end"
|
|
514
|
-
});
|
|
515
|
-
toFound = true;
|
|
516
|
-
console.log("ALSO found to at end of node", {
|
|
517
|
-
inverseTo,
|
|
518
|
-
node,
|
|
519
|
-
pos: pos + node.nodeSize
|
|
520
|
-
});
|
|
521
|
-
} else if (pos + node.nodeSize - 1 === inverseTo) {
|
|
522
|
-
addStructureMark(pos, {
|
|
523
|
-
value: "to",
|
|
524
|
-
position: "innerEnd"
|
|
525
|
-
});
|
|
526
|
-
toFound = true;
|
|
527
|
-
console.log("ALSO found to at inner end of node", {
|
|
528
|
-
inverseTo,
|
|
529
|
-
node,
|
|
530
|
-
pos: pos + node.nodeSize - 1
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
// inverseTo is at start of this node?
|
|
535
|
-
if (!toFound && pos === inverseTo) {
|
|
536
|
-
addStructureMark(pos, {
|
|
537
|
-
value: "to",
|
|
538
|
-
position: "start"
|
|
539
|
-
});
|
|
540
|
-
toFound = true;
|
|
541
|
-
console.log("to at start of node", {
|
|
542
|
-
inverseTo,
|
|
543
|
-
node,
|
|
544
|
-
pos
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
// inverseTo is at inner start of this node?
|
|
548
|
-
if (!toFound && pos + 1 === inverseTo) {
|
|
549
|
-
addStructureMark(pos, {
|
|
550
|
-
value: "to",
|
|
551
|
-
position: "innerStart"
|
|
552
|
-
});
|
|
553
|
-
toFound = true;
|
|
554
|
-
console.log("to at inner start of node", {
|
|
555
|
-
inverseTo,
|
|
556
|
-
node,
|
|
557
|
-
pos: pos + 1
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
return true;
|
|
561
|
-
});
|
|
562
|
-
// check if inverseFrom, inverseTo are at the end of some node in range
|
|
563
|
-
trackedTransaction.doc.nodesBetween(inverseBlockRange.start, inverseBlockRange.end, (node, pos)=>{
|
|
564
|
-
if (node.isInline) return true;
|
|
565
|
-
// inverseFrom is at end of this node?
|
|
566
|
-
if (!fromFound && pos + node.nodeSize === inverseFrom) {
|
|
567
|
-
addStructureMark(pos, {
|
|
568
|
-
value: "from",
|
|
569
|
-
position: "end"
|
|
570
|
-
});
|
|
571
|
-
fromFound = true;
|
|
572
|
-
console.log("from at end of node", {
|
|
573
|
-
inverseFrom,
|
|
574
|
-
node,
|
|
575
|
-
pos: pos + node.nodeSize
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
// inverseFrom is at inner end of this node?
|
|
579
|
-
if (!fromFound && pos + node.nodeSize - 1 === inverseFrom) {
|
|
580
|
-
addStructureMark(pos, {
|
|
581
|
-
value: "from",
|
|
582
|
-
position: "innerEnd"
|
|
583
|
-
});
|
|
584
|
-
fromFound = true;
|
|
585
|
-
console.log("from at inner end of node", {
|
|
586
|
-
inverseFrom,
|
|
587
|
-
node,
|
|
588
|
-
pos: pos + node.nodeSize - 1
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
// inverseTo is at end of this node?
|
|
592
|
-
if (!toFound && pos + node.nodeSize === inverseTo) {
|
|
593
|
-
addStructureMark(pos, {
|
|
594
|
-
value: "to",
|
|
595
|
-
position: "end"
|
|
596
|
-
});
|
|
597
|
-
toFound = true;
|
|
598
|
-
console.log("found to at end of node", {
|
|
599
|
-
inverseTo,
|
|
600
|
-
node,
|
|
601
|
-
pos: pos + node.nodeSize
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
// inverseTo is at inner end of this node?
|
|
605
|
-
if (!toFound && pos + node.nodeSize - 1 === inverseTo) {
|
|
606
|
-
addStructureMark(pos, {
|
|
607
|
-
value: "to",
|
|
608
|
-
position: "innerEnd"
|
|
609
|
-
});
|
|
610
|
-
toFound = true;
|
|
611
|
-
console.log("found to at inner end of node", {
|
|
612
|
-
inverseTo,
|
|
613
|
-
node,
|
|
614
|
-
pos: pos + node.nodeSize - 1
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
return true;
|
|
618
|
-
});
|
|
619
|
-
if (fromFound && toFound) {
|
|
620
|
-
console.log("all points found");
|
|
621
|
-
} else {
|
|
622
|
-
console.log("not all points found", {
|
|
623
|
-
step,
|
|
624
|
-
rebasedStep,
|
|
625
|
-
inverseStep
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
console.groupEnd();
|
|
629
|
-
return true;
|
|
630
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type Transaction, type Command } from "prosemirror-state";
|
|
2
|
-
import { type SuggestionId } from "../../generateId.js";
|
|
3
|
-
import { type Node, type Mark } from "prosemirror-model";
|
|
4
|
-
import { type Transform } from "prosemirror-transform";
|
|
5
|
-
export declare function isStructureSuggestion(suggestionId: SuggestionId, tr: Transaction): boolean;
|
|
6
|
-
export declare function revertAllStructureSuggestions(doc: Node, tr: Transaction): void;
|
|
7
|
-
export declare function revertStructureSuggestion(suggestionId: SuggestionId): Command;
|
|
8
|
-
export declare function applyStructureSuggestion(suggestionId: SuggestionId): Command;
|
|
9
|
-
export declare function revertStructureSuggestions(suggestionIds: SuggestionId[]): Command;
|
|
10
|
-
export declare function applyStructureMarkGroup(group: {
|
|
11
|
-
type: "replaceAround";
|
|
12
|
-
markFrom: {
|
|
13
|
-
pos: number;
|
|
14
|
-
node: Node;
|
|
15
|
-
mark: Mark;
|
|
16
|
-
};
|
|
17
|
-
markTo: {
|
|
18
|
-
pos: number;
|
|
19
|
-
node: Node;
|
|
20
|
-
mark: Mark;
|
|
21
|
-
};
|
|
22
|
-
markGapFrom: {
|
|
23
|
-
pos: number;
|
|
24
|
-
node: Node;
|
|
25
|
-
mark: Mark;
|
|
26
|
-
};
|
|
27
|
-
markGapTo: {
|
|
28
|
-
pos: number;
|
|
29
|
-
node: Node;
|
|
30
|
-
mark: Mark;
|
|
31
|
-
};
|
|
32
|
-
} | {
|
|
33
|
-
type: "replace";
|
|
34
|
-
markFrom: {
|
|
35
|
-
pos: number;
|
|
36
|
-
node: Node;
|
|
37
|
-
mark: Mark;
|
|
38
|
-
};
|
|
39
|
-
markTo: {
|
|
40
|
-
pos: number;
|
|
41
|
-
node: Node;
|
|
42
|
-
mark: Mark;
|
|
43
|
-
};
|
|
44
|
-
}, tr: Transform): void;
|