prosemirror-transform 1.10.1 → 1.10.3
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +32 -26
- package/dist/index.d.cts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.js +33 -31
- package/package.json +1 -1
- package/src/map.ts +28 -19
- package/src/structure.ts +9 -6
- package/src/transform.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 1.10.3 (2025-03-04)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Make sure `Mapping.appendMap` doesn't mutate shared arrays passed to its constructor.
|
|
6
|
+
|
|
7
|
+
## 1.10.2 (2024-10-11)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Allow `Transform.join` to clear incompatible inline content from the node after the join.
|
|
12
|
+
|
|
1
13
|
## 1.10.1 (2024-10-10)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -167,41 +167,45 @@ var StepMap = function () {
|
|
|
167
167
|
}();
|
|
168
168
|
StepMap.empty = new StepMap([]);
|
|
169
169
|
var Mapping = function () {
|
|
170
|
-
function Mapping() {
|
|
171
|
-
var maps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
172
|
-
var mirror = arguments.length > 1 ? arguments[1] : undefined;
|
|
170
|
+
function Mapping(maps, mirror) {
|
|
173
171
|
var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
174
|
-
var to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : maps.length;
|
|
172
|
+
var to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : maps ? maps.length : 0;
|
|
175
173
|
_classCallCheck(this, Mapping);
|
|
176
|
-
this.maps = maps;
|
|
177
174
|
this.mirror = mirror;
|
|
178
175
|
this.from = from;
|
|
179
176
|
this.to = to;
|
|
177
|
+
this._maps = maps || [];
|
|
178
|
+
this.ownData = !(maps || mirror);
|
|
180
179
|
}
|
|
181
180
|
_createClass(Mapping, [{
|
|
181
|
+
key: "maps",
|
|
182
|
+
get: function get() {
|
|
183
|
+
return this._maps;
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
182
186
|
key: "slice",
|
|
183
187
|
value: function slice() {
|
|
184
188
|
var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
185
189
|
var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.maps.length;
|
|
186
|
-
return new Mapping(this.
|
|
187
|
-
}
|
|
188
|
-
}, {
|
|
189
|
-
key: "copy",
|
|
190
|
-
value: function copy() {
|
|
191
|
-
return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to);
|
|
190
|
+
return new Mapping(this._maps, this.mirror, from, to);
|
|
192
191
|
}
|
|
193
192
|
}, {
|
|
194
193
|
key: "appendMap",
|
|
195
194
|
value: function appendMap(map, mirrors) {
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
if (!this.ownData) {
|
|
196
|
+
this._maps = this._maps.slice();
|
|
197
|
+
this.mirror = this.mirror && this.mirror.slice();
|
|
198
|
+
this.ownData = true;
|
|
199
|
+
}
|
|
200
|
+
this.to = this._maps.push(map);
|
|
201
|
+
if (mirrors != null) this.setMirror(this._maps.length - 1, mirrors);
|
|
198
202
|
}
|
|
199
203
|
}, {
|
|
200
204
|
key: "appendMapping",
|
|
201
205
|
value: function appendMapping(mapping) {
|
|
202
|
-
for (var i = 0, startSize = this.
|
|
206
|
+
for (var i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
|
|
203
207
|
var mirr = mapping.getMirror(i);
|
|
204
|
-
this.appendMap(mapping.
|
|
208
|
+
this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
}, {
|
|
@@ -218,9 +222,9 @@ var Mapping = function () {
|
|
|
218
222
|
}, {
|
|
219
223
|
key: "appendMappingInverted",
|
|
220
224
|
value: function appendMappingInverted(mapping) {
|
|
221
|
-
for (var i = mapping.maps.length - 1, totalSize = this.
|
|
225
|
+
for (var i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
|
|
222
226
|
var mirr = mapping.getMirror(i);
|
|
223
|
-
this.appendMap(mapping.
|
|
227
|
+
this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
230
|
}, {
|
|
@@ -235,7 +239,7 @@ var Mapping = function () {
|
|
|
235
239
|
value: function map(pos) {
|
|
236
240
|
var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
237
241
|
if (this.mirror) return this._map(pos, assoc, true);
|
|
238
|
-
for (var i = this.from; i < this.to; i++) pos = this.
|
|
242
|
+
for (var i = this.from; i < this.to; i++) pos = this._maps[i].map(pos, assoc);
|
|
239
243
|
return pos;
|
|
240
244
|
}
|
|
241
245
|
}, {
|
|
@@ -249,13 +253,13 @@ var Mapping = function () {
|
|
|
249
253
|
value: function _map(pos, assoc, simple) {
|
|
250
254
|
var delInfo = 0;
|
|
251
255
|
for (var i = this.from; i < this.to; i++) {
|
|
252
|
-
var map = this.
|
|
256
|
+
var map = this._maps[i],
|
|
253
257
|
result = map.mapResult(pos, assoc);
|
|
254
258
|
if (result.recover != null) {
|
|
255
259
|
var corr = this.getMirror(i);
|
|
256
260
|
if (corr != null && corr > i && corr < this.to) {
|
|
257
261
|
i = corr;
|
|
258
|
-
pos = this.
|
|
262
|
+
pos = this._maps[corr].recover(result.recover);
|
|
259
263
|
continue;
|
|
260
264
|
}
|
|
261
265
|
}
|
|
@@ -1034,7 +1038,7 @@ function canJoin(doc, pos) {
|
|
|
1034
1038
|
index = $pos.index();
|
|
1035
1039
|
return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1);
|
|
1036
1040
|
}
|
|
1037
|
-
function
|
|
1041
|
+
function canAppendWithSubstitutedLinebreaks(a, b) {
|
|
1038
1042
|
if (!b.content.size) a.type.compatibleContent(b.type);
|
|
1039
1043
|
var match = a.contentMatchAt(a.childCount);
|
|
1040
1044
|
var linebreakReplacement = a.type.schema.linebreakReplacement;
|
|
@@ -1048,7 +1052,7 @@ function canAppendWithSubstitutedLinebeaks(a, b) {
|
|
|
1048
1052
|
return match.validEnd;
|
|
1049
1053
|
}
|
|
1050
1054
|
function joinable(a, b) {
|
|
1051
|
-
return !!(a && b && !a.isLeaf &&
|
|
1055
|
+
return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
|
|
1052
1056
|
}
|
|
1053
1057
|
function joinPoint(doc, pos) {
|
|
1054
1058
|
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
|
|
@@ -1076,10 +1080,11 @@ function joinPoint(doc, pos) {
|
|
|
1076
1080
|
function _join(tr, pos, depth) {
|
|
1077
1081
|
var convertNewlines = null;
|
|
1078
1082
|
var linebreakReplacement = tr.doc.type.schema.linebreakReplacement;
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
var
|
|
1083
|
+
var $before = tr.doc.resolve(pos - depth),
|
|
1084
|
+
beforeType = $before.node().type;
|
|
1085
|
+
if (linebreakReplacement && beforeType.inlineContent) {
|
|
1086
|
+
var pre = beforeType.whitespace == "pre";
|
|
1087
|
+
var supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
|
|
1083
1088
|
if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true;
|
|
1084
1089
|
}
|
|
1085
1090
|
var mapFrom = tr.steps.length;
|
|
@@ -1087,6 +1092,7 @@ function _join(tr, pos, depth) {
|
|
|
1087
1092
|
var $after = tr.doc.resolve(pos + depth);
|
|
1088
1093
|
replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
|
|
1089
1094
|
}
|
|
1095
|
+
if (beforeType.inlineContent) _clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
|
|
1090
1096
|
var mapping = tr.mapping.slice(mapFrom),
|
|
1091
1097
|
start = mapping.map(pos - depth);
|
|
1092
1098
|
tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), prosemirrorModel.Slice.empty, true));
|
package/dist/index.d.cts
CHANGED
|
@@ -101,14 +101,10 @@ A mapping represents a pipeline of zero or more [step
|
|
|
101
101
|
maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
|
|
102
102
|
handling mapping positions through a series of steps in which some
|
|
103
103
|
steps are inverted versions of earlier steps. (This comes up when
|
|
104
|
-
‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
|
|
104
|
+
‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
|
|
105
105
|
collaboration or history management.)
|
|
106
106
|
*/
|
|
107
107
|
declare class Mapping implements Mappable {
|
|
108
|
-
/**
|
|
109
|
-
The step maps in this mapping.
|
|
110
|
-
*/
|
|
111
|
-
readonly maps: StepMap[];
|
|
112
108
|
/**
|
|
113
109
|
The starting position in the `maps` array, used when `map` or
|
|
114
110
|
`mapResult` is called.
|
|
@@ -121,11 +117,7 @@ declare class Mapping implements Mappable {
|
|
|
121
117
|
/**
|
|
122
118
|
Create a new mapping with the given position maps.
|
|
123
119
|
*/
|
|
124
|
-
constructor(
|
|
125
|
-
/**
|
|
126
|
-
The step maps in this mapping.
|
|
127
|
-
*/
|
|
128
|
-
maps?: StepMap[],
|
|
120
|
+
constructor(maps?: readonly StepMap[],
|
|
129
121
|
/**
|
|
130
122
|
@internal
|
|
131
123
|
*/
|
|
@@ -140,6 +132,12 @@ declare class Mapping implements Mappable {
|
|
|
140
132
|
*/
|
|
141
133
|
to?: number);
|
|
142
134
|
/**
|
|
135
|
+
The step maps in this mapping.
|
|
136
|
+
*/
|
|
137
|
+
get maps(): readonly StepMap[];
|
|
138
|
+
private _maps;
|
|
139
|
+
private ownData;
|
|
140
|
+
/**
|
|
143
141
|
Create a mapping that maps only through a part of this one.
|
|
144
142
|
*/
|
|
145
143
|
slice(from?: number, to?: number): Mapping;
|
|
@@ -436,7 +434,7 @@ declare class Transform {
|
|
|
436
434
|
greater than one, any number of nodes above that. By default, the
|
|
437
435
|
parts split off will inherit the node type of the original node.
|
|
438
436
|
This can be changed by passing an array of types and attributes to
|
|
439
|
-
use after the split.
|
|
437
|
+
use after the split (with the outermost nodes coming first).
|
|
440
438
|
*/
|
|
441
439
|
split(pos: number, depth?: number, typesAfter?: (null | {
|
|
442
440
|
type: NodeType;
|
package/dist/index.d.ts
CHANGED
|
@@ -101,14 +101,10 @@ A mapping represents a pipeline of zero or more [step
|
|
|
101
101
|
maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
|
|
102
102
|
handling mapping positions through a series of steps in which some
|
|
103
103
|
steps are inverted versions of earlier steps. (This comes up when
|
|
104
|
-
‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
|
|
104
|
+
‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
|
|
105
105
|
collaboration or history management.)
|
|
106
106
|
*/
|
|
107
107
|
declare class Mapping implements Mappable {
|
|
108
|
-
/**
|
|
109
|
-
The step maps in this mapping.
|
|
110
|
-
*/
|
|
111
|
-
readonly maps: StepMap[];
|
|
112
108
|
/**
|
|
113
109
|
The starting position in the `maps` array, used when `map` or
|
|
114
110
|
`mapResult` is called.
|
|
@@ -121,11 +117,7 @@ declare class Mapping implements Mappable {
|
|
|
121
117
|
/**
|
|
122
118
|
Create a new mapping with the given position maps.
|
|
123
119
|
*/
|
|
124
|
-
constructor(
|
|
125
|
-
/**
|
|
126
|
-
The step maps in this mapping.
|
|
127
|
-
*/
|
|
128
|
-
maps?: StepMap[],
|
|
120
|
+
constructor(maps?: readonly StepMap[],
|
|
129
121
|
/**
|
|
130
122
|
@internal
|
|
131
123
|
*/
|
|
@@ -140,6 +132,12 @@ declare class Mapping implements Mappable {
|
|
|
140
132
|
*/
|
|
141
133
|
to?: number);
|
|
142
134
|
/**
|
|
135
|
+
The step maps in this mapping.
|
|
136
|
+
*/
|
|
137
|
+
get maps(): readonly StepMap[];
|
|
138
|
+
private _maps;
|
|
139
|
+
private ownData;
|
|
140
|
+
/**
|
|
143
141
|
Create a mapping that maps only through a part of this one.
|
|
144
142
|
*/
|
|
145
143
|
slice(from?: number, to?: number): Mapping;
|
|
@@ -436,7 +434,7 @@ declare class Transform {
|
|
|
436
434
|
greater than one, any number of nodes above that. By default, the
|
|
437
435
|
parts split off will inherit the node type of the original node.
|
|
438
436
|
This can be changed by passing an array of types and attributes to
|
|
439
|
-
use after the split.
|
|
437
|
+
use after the split (with the outermost nodes coming first).
|
|
440
438
|
*/
|
|
441
439
|
split(pos: number, depth?: number, typesAfter?: (null | {
|
|
442
440
|
type: NodeType;
|
package/dist/index.js
CHANGED
|
@@ -185,18 +185,14 @@ A mapping represents a pipeline of zero or more [step
|
|
|
185
185
|
maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
|
|
186
186
|
handling mapping positions through a series of steps in which some
|
|
187
187
|
steps are inverted versions of earlier steps. (This comes up when
|
|
188
|
-
‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
|
|
188
|
+
‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
|
|
189
189
|
collaboration or history management.)
|
|
190
190
|
*/
|
|
191
191
|
class Mapping {
|
|
192
192
|
/**
|
|
193
193
|
Create a new mapping with the given position maps.
|
|
194
194
|
*/
|
|
195
|
-
constructor(
|
|
196
|
-
/**
|
|
197
|
-
The step maps in this mapping.
|
|
198
|
-
*/
|
|
199
|
-
maps = [],
|
|
195
|
+
constructor(maps,
|
|
200
196
|
/**
|
|
201
197
|
@internal
|
|
202
198
|
*/
|
|
@@ -209,23 +205,22 @@ class Mapping {
|
|
|
209
205
|
/**
|
|
210
206
|
The end position in the `maps` array.
|
|
211
207
|
*/
|
|
212
|
-
to = maps.length) {
|
|
213
|
-
this.maps = maps;
|
|
208
|
+
to = maps ? maps.length : 0) {
|
|
214
209
|
this.mirror = mirror;
|
|
215
210
|
this.from = from;
|
|
216
211
|
this.to = to;
|
|
212
|
+
this._maps = maps || [];
|
|
213
|
+
this.ownData = !(maps || mirror);
|
|
217
214
|
}
|
|
218
215
|
/**
|
|
219
|
-
|
|
216
|
+
The step maps in this mapping.
|
|
220
217
|
*/
|
|
221
|
-
|
|
222
|
-
return new Mapping(this.maps, this.mirror, from, to);
|
|
223
|
-
}
|
|
218
|
+
get maps() { return this._maps; }
|
|
224
219
|
/**
|
|
225
|
-
|
|
220
|
+
Create a mapping that maps only through a part of this one.
|
|
226
221
|
*/
|
|
227
|
-
|
|
228
|
-
return new Mapping(this.
|
|
222
|
+
slice(from = 0, to = this.maps.length) {
|
|
223
|
+
return new Mapping(this._maps, this.mirror, from, to);
|
|
229
224
|
}
|
|
230
225
|
/**
|
|
231
226
|
Add a step map to the end of this mapping. If `mirrors` is
|
|
@@ -233,18 +228,23 @@ class Mapping {
|
|
|
233
228
|
image of this one.
|
|
234
229
|
*/
|
|
235
230
|
appendMap(map, mirrors) {
|
|
236
|
-
|
|
231
|
+
if (!this.ownData) {
|
|
232
|
+
this._maps = this._maps.slice();
|
|
233
|
+
this.mirror = this.mirror && this.mirror.slice();
|
|
234
|
+
this.ownData = true;
|
|
235
|
+
}
|
|
236
|
+
this.to = this._maps.push(map);
|
|
237
237
|
if (mirrors != null)
|
|
238
|
-
this.setMirror(this.
|
|
238
|
+
this.setMirror(this._maps.length - 1, mirrors);
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
Add all the step maps in a given mapping to this one (preserving
|
|
242
242
|
mirroring information).
|
|
243
243
|
*/
|
|
244
244
|
appendMapping(mapping) {
|
|
245
|
-
for (let i = 0, startSize = this.
|
|
245
|
+
for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
|
|
246
246
|
let mirr = mapping.getMirror(i);
|
|
247
|
-
this.appendMap(mapping.
|
|
247
|
+
this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
@@ -270,9 +270,9 @@ class Mapping {
|
|
|
270
270
|
Append the inverse of the given mapping to this one.
|
|
271
271
|
*/
|
|
272
272
|
appendMappingInverted(mapping) {
|
|
273
|
-
for (let i = mapping.maps.length - 1, totalSize = this.
|
|
273
|
+
for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
|
|
274
274
|
let mirr = mapping.getMirror(i);
|
|
275
|
-
this.appendMap(mapping.
|
|
275
|
+
this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
@@ -290,7 +290,7 @@ class Mapping {
|
|
|
290
290
|
if (this.mirror)
|
|
291
291
|
return this._map(pos, assoc, true);
|
|
292
292
|
for (let i = this.from; i < this.to; i++)
|
|
293
|
-
pos = this.
|
|
293
|
+
pos = this._maps[i].map(pos, assoc);
|
|
294
294
|
return pos;
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
@@ -304,12 +304,12 @@ class Mapping {
|
|
|
304
304
|
_map(pos, assoc, simple) {
|
|
305
305
|
let delInfo = 0;
|
|
306
306
|
for (let i = this.from; i < this.to; i++) {
|
|
307
|
-
let map = this.
|
|
307
|
+
let map = this._maps[i], result = map.mapResult(pos, assoc);
|
|
308
308
|
if (result.recover != null) {
|
|
309
309
|
let corr = this.getMirror(i);
|
|
310
310
|
if (corr != null && corr > i && corr < this.to) {
|
|
311
311
|
i = corr;
|
|
312
|
-
pos = this.
|
|
312
|
+
pos = this._maps[corr].recover(result.recover);
|
|
313
313
|
continue;
|
|
314
314
|
}
|
|
315
315
|
}
|
|
@@ -1183,7 +1183,7 @@ function canJoin(doc, pos) {
|
|
|
1183
1183
|
return joinable($pos.nodeBefore, $pos.nodeAfter) &&
|
|
1184
1184
|
$pos.parent.canReplace(index, index + 1);
|
|
1185
1185
|
}
|
|
1186
|
-
function
|
|
1186
|
+
function canAppendWithSubstitutedLinebreaks(a, b) {
|
|
1187
1187
|
if (!b.content.size)
|
|
1188
1188
|
a.type.compatibleContent(b.type);
|
|
1189
1189
|
let match = a.contentMatchAt(a.childCount);
|
|
@@ -1200,7 +1200,7 @@ function canAppendWithSubstitutedLinebeaks(a, b) {
|
|
|
1200
1200
|
return match.validEnd;
|
|
1201
1201
|
}
|
|
1202
1202
|
function joinable(a, b) {
|
|
1203
|
-
return !!(a && b && !a.isLeaf &&
|
|
1203
|
+
return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
|
|
1204
1204
|
}
|
|
1205
1205
|
/**
|
|
1206
1206
|
Find an ancestor of the given position that can be joined to the
|
|
@@ -1235,10 +1235,10 @@ function joinPoint(doc, pos, dir = -1) {
|
|
|
1235
1235
|
function join(tr, pos, depth) {
|
|
1236
1236
|
let convertNewlines = null;
|
|
1237
1237
|
let { linebreakReplacement } = tr.doc.type.schema;
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
let pre =
|
|
1241
|
-
let supportLinebreak = !!
|
|
1238
|
+
let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;
|
|
1239
|
+
if (linebreakReplacement && beforeType.inlineContent) {
|
|
1240
|
+
let pre = beforeType.whitespace == "pre";
|
|
1241
|
+
let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
|
|
1242
1242
|
if (pre && !supportLinebreak)
|
|
1243
1243
|
convertNewlines = false;
|
|
1244
1244
|
else if (!pre && supportLinebreak)
|
|
@@ -1249,6 +1249,8 @@ function join(tr, pos, depth) {
|
|
|
1249
1249
|
let $after = tr.doc.resolve(pos + depth);
|
|
1250
1250
|
replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
|
|
1251
1251
|
}
|
|
1252
|
+
if (beforeType.inlineContent)
|
|
1253
|
+
clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
|
|
1252
1254
|
let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);
|
|
1253
1255
|
tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));
|
|
1254
1256
|
if (convertNewlines === true) {
|
|
@@ -2109,7 +2111,7 @@ class Transform {
|
|
|
2109
2111
|
greater than one, any number of nodes above that. By default, the
|
|
2110
2112
|
parts split off will inherit the node type of the original node.
|
|
2111
2113
|
This can be changed by passing an array of types and attributes to
|
|
2112
|
-
use after the split.
|
|
2114
|
+
use after the split (with the outermost nodes coming first).
|
|
2113
2115
|
*/
|
|
2114
2116
|
split(pos, depth = 1, typesAfter) {
|
|
2115
2117
|
split(this, pos, depth, typesAfter);
|
package/package.json
CHANGED
package/src/map.ts
CHANGED
|
@@ -172,41 +172,50 @@ export class StepMap implements Mappable {
|
|
|
172
172
|
export class Mapping implements Mappable {
|
|
173
173
|
/// Create a new mapping with the given position maps.
|
|
174
174
|
constructor(
|
|
175
|
-
|
|
176
|
-
readonly maps: StepMap[] = [],
|
|
175
|
+
maps?: readonly StepMap[],
|
|
177
176
|
/// @internal
|
|
178
177
|
public mirror?: number[],
|
|
179
178
|
/// The starting position in the `maps` array, used when `map` or
|
|
180
179
|
/// `mapResult` is called.
|
|
181
180
|
public from = 0,
|
|
182
181
|
/// The end position in the `maps` array.
|
|
183
|
-
public to = maps.length
|
|
184
|
-
) {
|
|
182
|
+
public to = maps ? maps.length : 0
|
|
183
|
+
) {
|
|
184
|
+
this._maps = (maps as StepMap[]) || []
|
|
185
|
+
this.ownData = !(maps || mirror)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// The step maps in this mapping.
|
|
189
|
+
get maps(): readonly StepMap[] { return this._maps }
|
|
190
|
+
|
|
191
|
+
private _maps: StepMap[]
|
|
192
|
+
// False if maps/mirror are shared arrays that we shouldn't mutate
|
|
193
|
+
private ownData: boolean
|
|
185
194
|
|
|
186
195
|
/// Create a mapping that maps only through a part of this one.
|
|
187
196
|
slice(from = 0, to = this.maps.length) {
|
|
188
|
-
return new Mapping(this.
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/// @internal
|
|
192
|
-
copy() {
|
|
193
|
-
return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to)
|
|
197
|
+
return new Mapping(this._maps, this.mirror, from, to)
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
/// Add a step map to the end of this mapping. If `mirrors` is
|
|
197
201
|
/// given, it should be the index of the step map that is the mirror
|
|
198
202
|
/// image of this one.
|
|
199
203
|
appendMap(map: StepMap, mirrors?: number) {
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
if (!this.ownData) {
|
|
205
|
+
this._maps = this._maps.slice()
|
|
206
|
+
this.mirror = this.mirror && this.mirror.slice()
|
|
207
|
+
this.ownData = true
|
|
208
|
+
}
|
|
209
|
+
this.to = this._maps.push(map)
|
|
210
|
+
if (mirrors != null) this.setMirror(this._maps.length - 1, mirrors)
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
/// Add all the step maps in a given mapping to this one (preserving
|
|
205
214
|
/// mirroring information).
|
|
206
215
|
appendMapping(mapping: Mapping) {
|
|
207
|
-
for (let i = 0, startSize = this.
|
|
216
|
+
for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
|
|
208
217
|
let mirr = mapping.getMirror(i)
|
|
209
|
-
this.appendMap(mapping.
|
|
218
|
+
this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined)
|
|
210
219
|
}
|
|
211
220
|
}
|
|
212
221
|
|
|
@@ -226,9 +235,9 @@ export class Mapping implements Mappable {
|
|
|
226
235
|
|
|
227
236
|
/// Append the inverse of the given mapping to this one.
|
|
228
237
|
appendMappingInverted(mapping: Mapping) {
|
|
229
|
-
for (let i = mapping.maps.length - 1, totalSize = this.
|
|
238
|
+
for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
|
|
230
239
|
let mirr = mapping.getMirror(i)
|
|
231
|
-
this.appendMap(mapping.
|
|
240
|
+
this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined)
|
|
232
241
|
}
|
|
233
242
|
}
|
|
234
243
|
|
|
@@ -243,7 +252,7 @@ export class Mapping implements Mappable {
|
|
|
243
252
|
map(pos: number, assoc = 1) {
|
|
244
253
|
if (this.mirror) return this._map(pos, assoc, true) as number
|
|
245
254
|
for (let i = this.from; i < this.to; i++)
|
|
246
|
-
pos = this.
|
|
255
|
+
pos = this._maps[i].map(pos, assoc)
|
|
247
256
|
return pos
|
|
248
257
|
}
|
|
249
258
|
|
|
@@ -256,12 +265,12 @@ export class Mapping implements Mappable {
|
|
|
256
265
|
let delInfo = 0
|
|
257
266
|
|
|
258
267
|
for (let i = this.from; i < this.to; i++) {
|
|
259
|
-
let map = this.
|
|
268
|
+
let map = this._maps[i], result = map.mapResult(pos, assoc)
|
|
260
269
|
if (result.recover != null) {
|
|
261
270
|
let corr = this.getMirror(i)
|
|
262
271
|
if (corr != null && corr > i && corr < this.to) {
|
|
263
272
|
i = corr
|
|
264
|
-
pos = this.
|
|
273
|
+
pos = this._maps[corr].recover(result.recover)
|
|
265
274
|
continue
|
|
266
275
|
}
|
|
267
276
|
}
|
package/src/structure.ts
CHANGED
|
@@ -226,7 +226,7 @@ export function canJoin(doc: Node, pos: number): boolean {
|
|
|
226
226
|
$pos.parent.canReplace(index, index + 1)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
function
|
|
229
|
+
function canAppendWithSubstitutedLinebreaks(a: Node, b: Node) {
|
|
230
230
|
if (!b.content.size) a.type.compatibleContent(b.type)
|
|
231
231
|
let match: ContentMatch | null = a.contentMatchAt(a.childCount)
|
|
232
232
|
let {linebreakReplacement} = a.type.schema
|
|
@@ -241,7 +241,7 @@ function canAppendWithSubstitutedLinebeaks(a: Node, b: Node) {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
function joinable(a: Node | null, b: Node | null) {
|
|
244
|
-
return !!(a && b && !a.isLeaf &&
|
|
244
|
+
return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b))
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
/// Find an ancestor of the given position that can be joined to the
|
|
@@ -272,10 +272,10 @@ export function joinPoint(doc: Node, pos: number, dir = -1) {
|
|
|
272
272
|
export function join(tr: Transform, pos: number, depth: number) {
|
|
273
273
|
let convertNewlines = null
|
|
274
274
|
let {linebreakReplacement} = tr.doc.type.schema
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
let pre =
|
|
278
|
-
let supportLinebreak = !!
|
|
275
|
+
let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type
|
|
276
|
+
if (linebreakReplacement && beforeType.inlineContent) {
|
|
277
|
+
let pre = beforeType.whitespace == "pre"
|
|
278
|
+
let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement)
|
|
279
279
|
if (pre && !supportLinebreak) convertNewlines = false
|
|
280
280
|
else if (!pre && supportLinebreak) convertNewlines = true
|
|
281
281
|
}
|
|
@@ -284,6 +284,9 @@ export function join(tr: Transform, pos: number, depth: number) {
|
|
|
284
284
|
let $after = tr.doc.resolve(pos + depth)
|
|
285
285
|
replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom)
|
|
286
286
|
}
|
|
287
|
+
if (beforeType.inlineContent)
|
|
288
|
+
clearIncompatible(tr, pos + depth - 1, beforeType,
|
|
289
|
+
$before.node().contentMatchAt($before.index()), convertNewlines == null)
|
|
287
290
|
let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth)
|
|
288
291
|
tr.step(new ReplaceStep(start, mapping.map(pos + depth, - 1), Slice.empty, true))
|
|
289
292
|
if (convertNewlines === true) {
|
package/src/transform.ts
CHANGED
|
@@ -215,7 +215,7 @@ export class Transform {
|
|
|
215
215
|
/// greater than one, any number of nodes above that. By default, the
|
|
216
216
|
/// parts split off will inherit the node type of the original node.
|
|
217
217
|
/// This can be changed by passing an array of types and attributes to
|
|
218
|
-
/// use after the split.
|
|
218
|
+
/// use after the split (with the outermost nodes coming first).
|
|
219
219
|
split(pos: number, depth = 1, typesAfter?: (null | {type: NodeType, attrs?: Attrs | null})[]) {
|
|
220
220
|
split(this, pos, depth, typesAfter)
|
|
221
221
|
return this
|