prosemirror-transform 1.4.2 → 1.5.0-beta.1
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/index.cjs +1781 -0
- package/dist/index.d.ts +690 -0
- package/dist/index.es.js +22 -22
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1699 -1636
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
- package/src/{index.js → index.ts} +4 -2
- package/src/map.ts +256 -0
- package/src/{mark.js → mark.ts} +22 -35
- package/src/{mark_step.js → mark_step.ts} +40 -39
- package/src/{replace.js → replace.ts} +83 -131
- package/src/{replace_step.js → replace_step.ts} +65 -70
- package/src/step.ts +97 -0
- package/src/{structure.js → structure.ts} +78 -99
- package/src/transform.ts +212 -0
- package/rollup.config.js +0 -14
- package/src/map.js +0 -264
- package/src/step.js +0 -110
- package/src/transform.js +0 -71
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1781 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
6
|
+
|
|
7
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
8
|
+
|
|
9
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
26
|
+
|
|
27
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
28
|
+
|
|
29
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
30
|
+
|
|
31
|
+
Object.defineProperty(exports, '__esModule', {
|
|
32
|
+
value: true
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
var prosemirrorModel = require('prosemirror-model');
|
|
36
|
+
|
|
37
|
+
var lower16 = 0xffff;
|
|
38
|
+
var factor16 = Math.pow(2, 16);
|
|
39
|
+
|
|
40
|
+
function makeRecover(index, offset) {
|
|
41
|
+
return index + offset * factor16;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function recoverIndex(value) {
|
|
45
|
+
return value & lower16;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function recoverOffset(value) {
|
|
49
|
+
return (value - (value & lower16)) / factor16;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var MapResult = _createClass(function MapResult(pos) {
|
|
53
|
+
var deleted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
54
|
+
var recover = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
55
|
+
|
|
56
|
+
_classCallCheck(this, MapResult);
|
|
57
|
+
|
|
58
|
+
this.pos = pos;
|
|
59
|
+
this.deleted = deleted;
|
|
60
|
+
this.recover = recover;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
var StepMap = function () {
|
|
64
|
+
function StepMap(ranges) {
|
|
65
|
+
var inverted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
66
|
+
|
|
67
|
+
_classCallCheck(this, StepMap);
|
|
68
|
+
|
|
69
|
+
this.ranges = ranges;
|
|
70
|
+
this.inverted = inverted;
|
|
71
|
+
if (!ranges.length && StepMap.empty) return StepMap.empty;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_createClass(StepMap, [{
|
|
75
|
+
key: "recover",
|
|
76
|
+
value: function recover(value) {
|
|
77
|
+
var diff = 0,
|
|
78
|
+
index = recoverIndex(value);
|
|
79
|
+
if (!this.inverted) for (var i = 0; i < index; i++) {
|
|
80
|
+
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
81
|
+
}
|
|
82
|
+
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "mapResult",
|
|
86
|
+
value: function mapResult(pos) {
|
|
87
|
+
var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
88
|
+
return this._map(pos, assoc, false);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "map",
|
|
92
|
+
value: function map(pos) {
|
|
93
|
+
var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
94
|
+
return this._map(pos, assoc, true);
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "_map",
|
|
98
|
+
value: function _map(pos, assoc, simple) {
|
|
99
|
+
var diff = 0,
|
|
100
|
+
oldIndex = this.inverted ? 2 : 1,
|
|
101
|
+
newIndex = this.inverted ? 1 : 2;
|
|
102
|
+
|
|
103
|
+
for (var i = 0; i < this.ranges.length; i += 3) {
|
|
104
|
+
var start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
105
|
+
if (start > pos) break;
|
|
106
|
+
var oldSize = this.ranges[i + oldIndex],
|
|
107
|
+
newSize = this.ranges[i + newIndex],
|
|
108
|
+
end = start + oldSize;
|
|
109
|
+
|
|
110
|
+
if (pos <= end) {
|
|
111
|
+
var side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
|
|
112
|
+
var result = start + diff + (side < 0 ? 0 : newSize);
|
|
113
|
+
if (simple) return result;
|
|
114
|
+
var recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
115
|
+
return new MapResult(result, assoc < 0 ? pos != start : pos != end, recover);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
diff += newSize - oldSize;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return simple ? pos + diff : new MapResult(pos + diff);
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "touches",
|
|
125
|
+
value: function touches(pos, recover) {
|
|
126
|
+
var diff = 0,
|
|
127
|
+
index = recoverIndex(recover);
|
|
128
|
+
var oldIndex = this.inverted ? 2 : 1,
|
|
129
|
+
newIndex = this.inverted ? 1 : 2;
|
|
130
|
+
|
|
131
|
+
for (var i = 0; i < this.ranges.length; i += 3) {
|
|
132
|
+
var start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
133
|
+
if (start > pos) break;
|
|
134
|
+
var oldSize = this.ranges[i + oldIndex],
|
|
135
|
+
end = start + oldSize;
|
|
136
|
+
if (pos <= end && i == index * 3) return true;
|
|
137
|
+
diff += this.ranges[i + newIndex] - oldSize;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "forEach",
|
|
144
|
+
value: function forEach(f) {
|
|
145
|
+
var oldIndex = this.inverted ? 2 : 1,
|
|
146
|
+
newIndex = this.inverted ? 1 : 2;
|
|
147
|
+
|
|
148
|
+
for (var i = 0, diff = 0; i < this.ranges.length; i += 3) {
|
|
149
|
+
var start = this.ranges[i],
|
|
150
|
+
oldStart = start - (this.inverted ? diff : 0),
|
|
151
|
+
newStart = start + (this.inverted ? 0 : diff);
|
|
152
|
+
var oldSize = this.ranges[i + oldIndex],
|
|
153
|
+
newSize = this.ranges[i + newIndex];
|
|
154
|
+
f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
|
|
155
|
+
diff += newSize - oldSize;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "invert",
|
|
160
|
+
value: function invert() {
|
|
161
|
+
return new StepMap(this.ranges, !this.inverted);
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "toString",
|
|
165
|
+
value: function toString() {
|
|
166
|
+
return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
|
|
167
|
+
}
|
|
168
|
+
}], [{
|
|
169
|
+
key: "offset",
|
|
170
|
+
value: function offset(n) {
|
|
171
|
+
return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
172
|
+
}
|
|
173
|
+
}]);
|
|
174
|
+
|
|
175
|
+
return StepMap;
|
|
176
|
+
}();
|
|
177
|
+
|
|
178
|
+
StepMap.empty = new StepMap([]);
|
|
179
|
+
|
|
180
|
+
var Mapping = function () {
|
|
181
|
+
function Mapping() {
|
|
182
|
+
var maps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
183
|
+
var mirror = arguments.length > 1 ? arguments[1] : undefined;
|
|
184
|
+
var from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
185
|
+
var to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : maps.length;
|
|
186
|
+
|
|
187
|
+
_classCallCheck(this, Mapping);
|
|
188
|
+
|
|
189
|
+
this.maps = maps;
|
|
190
|
+
this.mirror = mirror;
|
|
191
|
+
this.from = from;
|
|
192
|
+
this.to = to;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_createClass(Mapping, [{
|
|
196
|
+
key: "slice",
|
|
197
|
+
value: function slice() {
|
|
198
|
+
var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
199
|
+
var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.maps.length;
|
|
200
|
+
return new Mapping(this.maps, this.mirror, from, to);
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "copy",
|
|
204
|
+
value: function copy() {
|
|
205
|
+
return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to);
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "appendMap",
|
|
209
|
+
value: function appendMap(map, mirrors) {
|
|
210
|
+
this.to = this.maps.push(map);
|
|
211
|
+
if (mirrors != null) this.setMirror(this.maps.length - 1, mirrors);
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "appendMapping",
|
|
215
|
+
value: function appendMapping(mapping) {
|
|
216
|
+
for (var i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) {
|
|
217
|
+
var mirr = mapping.getMirror(i);
|
|
218
|
+
this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "getMirror",
|
|
223
|
+
value: function getMirror(n) {
|
|
224
|
+
if (this.mirror) for (var i = 0; i < this.mirror.length; i++) {
|
|
225
|
+
if (this.mirror[i] == n) return this.mirror[i + (i % 2 ? -1 : 1)];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}, {
|
|
229
|
+
key: "setMirror",
|
|
230
|
+
value: function setMirror(n, m) {
|
|
231
|
+
if (!this.mirror) this.mirror = [];
|
|
232
|
+
this.mirror.push(n, m);
|
|
233
|
+
}
|
|
234
|
+
}, {
|
|
235
|
+
key: "appendMappingInverted",
|
|
236
|
+
value: function appendMappingInverted(mapping) {
|
|
237
|
+
for (var i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) {
|
|
238
|
+
var mirr = mapping.getMirror(i);
|
|
239
|
+
this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: "invert",
|
|
244
|
+
value: function invert() {
|
|
245
|
+
var inverse = new Mapping();
|
|
246
|
+
inverse.appendMappingInverted(this);
|
|
247
|
+
return inverse;
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "map",
|
|
251
|
+
value: function map(pos) {
|
|
252
|
+
var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
253
|
+
if (this.mirror) return this._map(pos, assoc, true);
|
|
254
|
+
|
|
255
|
+
for (var i = this.from; i < this.to; i++) {
|
|
256
|
+
pos = this.maps[i].map(pos, assoc);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return pos;
|
|
260
|
+
}
|
|
261
|
+
}, {
|
|
262
|
+
key: "mapResult",
|
|
263
|
+
value: function mapResult(pos) {
|
|
264
|
+
var assoc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
265
|
+
return this._map(pos, assoc, false);
|
|
266
|
+
}
|
|
267
|
+
}, {
|
|
268
|
+
key: "_map",
|
|
269
|
+
value: function _map(pos, assoc, simple) {
|
|
270
|
+
var deleted = false;
|
|
271
|
+
|
|
272
|
+
for (var i = this.from; i < this.to; i++) {
|
|
273
|
+
var map = this.maps[i],
|
|
274
|
+
result = map.mapResult(pos, assoc);
|
|
275
|
+
|
|
276
|
+
if (result.recover != null) {
|
|
277
|
+
var corr = this.getMirror(i);
|
|
278
|
+
|
|
279
|
+
if (corr != null && corr > i && corr < this.to) {
|
|
280
|
+
i = corr;
|
|
281
|
+
pos = this.maps[corr].recover(result.recover);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (result.deleted) deleted = true;
|
|
287
|
+
pos = result.pos;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return simple ? pos : new MapResult(pos, deleted);
|
|
291
|
+
}
|
|
292
|
+
}]);
|
|
293
|
+
|
|
294
|
+
return Mapping;
|
|
295
|
+
}();
|
|
296
|
+
|
|
297
|
+
var stepsByID = Object.create(null);
|
|
298
|
+
|
|
299
|
+
var Step = function () {
|
|
300
|
+
function Step() {
|
|
301
|
+
_classCallCheck(this, Step);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
_createClass(Step, [{
|
|
305
|
+
key: "getMap",
|
|
306
|
+
value: function getMap() {
|
|
307
|
+
return StepMap.empty;
|
|
308
|
+
}
|
|
309
|
+
}, {
|
|
310
|
+
key: "merge",
|
|
311
|
+
value: function merge(other) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
}], [{
|
|
315
|
+
key: "fromJSON",
|
|
316
|
+
value: function fromJSON(schema, json) {
|
|
317
|
+
if (!json || !json.stepType) throw new RangeError("Invalid input for Step.fromJSON");
|
|
318
|
+
var type = stepsByID[json.stepType];
|
|
319
|
+
if (!type) throw new RangeError("No step type ".concat(json.stepType, " defined"));
|
|
320
|
+
return type.fromJSON(schema, json);
|
|
321
|
+
}
|
|
322
|
+
}, {
|
|
323
|
+
key: "jsonID",
|
|
324
|
+
value: function jsonID(id, stepClass) {
|
|
325
|
+
if (id in stepsByID) throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
326
|
+
stepsByID[id] = stepClass;
|
|
327
|
+
stepClass.prototype.jsonID = id;
|
|
328
|
+
return stepClass;
|
|
329
|
+
}
|
|
330
|
+
}]);
|
|
331
|
+
|
|
332
|
+
return Step;
|
|
333
|
+
}();
|
|
334
|
+
|
|
335
|
+
var StepResult = function () {
|
|
336
|
+
function StepResult(doc, failed) {
|
|
337
|
+
_classCallCheck(this, StepResult);
|
|
338
|
+
|
|
339
|
+
this.doc = doc;
|
|
340
|
+
this.failed = failed;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
_createClass(StepResult, null, [{
|
|
344
|
+
key: "ok",
|
|
345
|
+
value: function ok(doc) {
|
|
346
|
+
return new StepResult(doc, null);
|
|
347
|
+
}
|
|
348
|
+
}, {
|
|
349
|
+
key: "fail",
|
|
350
|
+
value: function fail(message) {
|
|
351
|
+
return new StepResult(null, message);
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "fromReplace",
|
|
355
|
+
value: function fromReplace(doc, from, to, slice) {
|
|
356
|
+
try {
|
|
357
|
+
return StepResult.ok(doc.replace(from, to, slice));
|
|
358
|
+
} catch (e) {
|
|
359
|
+
if (e instanceof prosemirrorModel.ReplaceError) return StepResult.fail(e.message);
|
|
360
|
+
throw e;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}]);
|
|
364
|
+
|
|
365
|
+
return StepResult;
|
|
366
|
+
}();
|
|
367
|
+
|
|
368
|
+
function mapFragment(fragment, f, parent) {
|
|
369
|
+
var mapped = [];
|
|
370
|
+
|
|
371
|
+
for (var i = 0; i < fragment.childCount; i++) {
|
|
372
|
+
var child = fragment.child(i);
|
|
373
|
+
if (child.content.size) child = child.copy(mapFragment(child.content, f, child));
|
|
374
|
+
if (child.isInline) child = f(child, parent, i);
|
|
375
|
+
mapped.push(child);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return prosemirrorModel.Fragment.fromArray(mapped);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
var AddMarkStep = function (_Step) {
|
|
382
|
+
_inherits(AddMarkStep, _Step);
|
|
383
|
+
|
|
384
|
+
var _super = _createSuper(AddMarkStep);
|
|
385
|
+
|
|
386
|
+
function AddMarkStep(from, to, mark) {
|
|
387
|
+
var _this;
|
|
388
|
+
|
|
389
|
+
_classCallCheck(this, AddMarkStep);
|
|
390
|
+
|
|
391
|
+
_this = _super.call(this);
|
|
392
|
+
_this.from = from;
|
|
393
|
+
_this.to = to;
|
|
394
|
+
_this.mark = mark;
|
|
395
|
+
return _this;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
_createClass(AddMarkStep, [{
|
|
399
|
+
key: "apply",
|
|
400
|
+
value: function apply(doc) {
|
|
401
|
+
var _this2 = this;
|
|
402
|
+
|
|
403
|
+
var oldSlice = doc.slice(this.from, this.to),
|
|
404
|
+
$from = doc.resolve(this.from);
|
|
405
|
+
var parent = $from.node($from.sharedDepth(this.to));
|
|
406
|
+
var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node, parent) {
|
|
407
|
+
if (!node.isAtom || !parent.type.allowsMarkType(_this2.mark.type)) return node;
|
|
408
|
+
return node.mark(_this2.mark.addToSet(node.marks));
|
|
409
|
+
}, parent), oldSlice.openStart, oldSlice.openEnd);
|
|
410
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
411
|
+
}
|
|
412
|
+
}, {
|
|
413
|
+
key: "invert",
|
|
414
|
+
value: function invert() {
|
|
415
|
+
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
416
|
+
}
|
|
417
|
+
}, {
|
|
418
|
+
key: "map",
|
|
419
|
+
value: function map(mapping) {
|
|
420
|
+
var from = mapping.mapResult(this.from, 1),
|
|
421
|
+
to = mapping.mapResult(this.to, -1);
|
|
422
|
+
if (from.deleted && to.deleted || from.pos >= to.pos) return null;
|
|
423
|
+
return new AddMarkStep(from.pos, to.pos, this.mark);
|
|
424
|
+
}
|
|
425
|
+
}, {
|
|
426
|
+
key: "merge",
|
|
427
|
+
value: function merge(other) {
|
|
428
|
+
if (other instanceof AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}, {
|
|
432
|
+
key: "toJSON",
|
|
433
|
+
value: function toJSON() {
|
|
434
|
+
return {
|
|
435
|
+
stepType: "addMark",
|
|
436
|
+
mark: this.mark.toJSON(),
|
|
437
|
+
from: this.from,
|
|
438
|
+
to: this.to
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
}], [{
|
|
442
|
+
key: "fromJSON",
|
|
443
|
+
value: function fromJSON(schema, json) {
|
|
444
|
+
if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
445
|
+
return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
446
|
+
}
|
|
447
|
+
}]);
|
|
448
|
+
|
|
449
|
+
return AddMarkStep;
|
|
450
|
+
}(Step);
|
|
451
|
+
|
|
452
|
+
Step.jsonID("addMark", AddMarkStep);
|
|
453
|
+
|
|
454
|
+
var RemoveMarkStep = function (_Step2) {
|
|
455
|
+
_inherits(RemoveMarkStep, _Step2);
|
|
456
|
+
|
|
457
|
+
var _super2 = _createSuper(RemoveMarkStep);
|
|
458
|
+
|
|
459
|
+
function RemoveMarkStep(from, to, mark) {
|
|
460
|
+
var _this3;
|
|
461
|
+
|
|
462
|
+
_classCallCheck(this, RemoveMarkStep);
|
|
463
|
+
|
|
464
|
+
_this3 = _super2.call(this);
|
|
465
|
+
_this3.from = from;
|
|
466
|
+
_this3.to = to;
|
|
467
|
+
_this3.mark = mark;
|
|
468
|
+
return _this3;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
_createClass(RemoveMarkStep, [{
|
|
472
|
+
key: "apply",
|
|
473
|
+
value: function apply(doc) {
|
|
474
|
+
var _this4 = this;
|
|
475
|
+
|
|
476
|
+
var oldSlice = doc.slice(this.from, this.to);
|
|
477
|
+
var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node) {
|
|
478
|
+
return node.mark(_this4.mark.removeFromSet(node.marks));
|
|
479
|
+
}, doc), oldSlice.openStart, oldSlice.openEnd);
|
|
480
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
481
|
+
}
|
|
482
|
+
}, {
|
|
483
|
+
key: "invert",
|
|
484
|
+
value: function invert() {
|
|
485
|
+
return new AddMarkStep(this.from, this.to, this.mark);
|
|
486
|
+
}
|
|
487
|
+
}, {
|
|
488
|
+
key: "map",
|
|
489
|
+
value: function map(mapping) {
|
|
490
|
+
var from = mapping.mapResult(this.from, 1),
|
|
491
|
+
to = mapping.mapResult(this.to, -1);
|
|
492
|
+
if (from.deleted && to.deleted || from.pos >= to.pos) return null;
|
|
493
|
+
return new RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
key: "merge",
|
|
497
|
+
value: function merge(other) {
|
|
498
|
+
if (other instanceof RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
}, {
|
|
502
|
+
key: "toJSON",
|
|
503
|
+
value: function toJSON() {
|
|
504
|
+
return {
|
|
505
|
+
stepType: "removeMark",
|
|
506
|
+
mark: this.mark.toJSON(),
|
|
507
|
+
from: this.from,
|
|
508
|
+
to: this.to
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}], [{
|
|
512
|
+
key: "fromJSON",
|
|
513
|
+
value: function fromJSON(schema, json) {
|
|
514
|
+
if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
515
|
+
return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
516
|
+
}
|
|
517
|
+
}]);
|
|
518
|
+
|
|
519
|
+
return RemoveMarkStep;
|
|
520
|
+
}(Step);
|
|
521
|
+
|
|
522
|
+
Step.jsonID("removeMark", RemoveMarkStep);
|
|
523
|
+
|
|
524
|
+
var ReplaceStep = function (_Step3) {
|
|
525
|
+
_inherits(ReplaceStep, _Step3);
|
|
526
|
+
|
|
527
|
+
var _super3 = _createSuper(ReplaceStep);
|
|
528
|
+
|
|
529
|
+
function ReplaceStep(from, to, slice) {
|
|
530
|
+
var _this5;
|
|
531
|
+
|
|
532
|
+
var structure = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
533
|
+
|
|
534
|
+
_classCallCheck(this, ReplaceStep);
|
|
535
|
+
|
|
536
|
+
_this5 = _super3.call(this);
|
|
537
|
+
_this5.from = from;
|
|
538
|
+
_this5.to = to;
|
|
539
|
+
_this5.slice = slice;
|
|
540
|
+
_this5.structure = structure;
|
|
541
|
+
return _this5;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
_createClass(ReplaceStep, [{
|
|
545
|
+
key: "apply",
|
|
546
|
+
value: function apply(doc) {
|
|
547
|
+
if (this.structure && contentBetween(doc, this.from, this.to)) return StepResult.fail("Structure replace would overwrite content");
|
|
548
|
+
return StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
549
|
+
}
|
|
550
|
+
}, {
|
|
551
|
+
key: "getMap",
|
|
552
|
+
value: function getMap() {
|
|
553
|
+
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
554
|
+
}
|
|
555
|
+
}, {
|
|
556
|
+
key: "invert",
|
|
557
|
+
value: function invert(doc) {
|
|
558
|
+
return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
559
|
+
}
|
|
560
|
+
}, {
|
|
561
|
+
key: "map",
|
|
562
|
+
value: function map(mapping) {
|
|
563
|
+
var from = mapping.mapResult(this.from, 1),
|
|
564
|
+
to = mapping.mapResult(this.to, -1);
|
|
565
|
+
if (from.deleted && to.deleted) return null;
|
|
566
|
+
return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
|
|
567
|
+
}
|
|
568
|
+
}, {
|
|
569
|
+
key: "merge",
|
|
570
|
+
value: function merge(other) {
|
|
571
|
+
if (!(other instanceof ReplaceStep) || other.structure || this.structure) return null;
|
|
572
|
+
|
|
573
|
+
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
574
|
+
var slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
575
|
+
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
576
|
+
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
577
|
+
var _slice = this.slice.size + other.slice.size == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
578
|
+
|
|
579
|
+
return new ReplaceStep(other.from, this.to, _slice, this.structure);
|
|
580
|
+
} else {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}, {
|
|
585
|
+
key: "toJSON",
|
|
586
|
+
value: function toJSON() {
|
|
587
|
+
var json = {
|
|
588
|
+
stepType: "replace",
|
|
589
|
+
from: this.from,
|
|
590
|
+
to: this.to
|
|
591
|
+
};
|
|
592
|
+
if (this.slice.size) json.slice = this.slice.toJSON();
|
|
593
|
+
if (this.structure) json.structure = true;
|
|
594
|
+
return json;
|
|
595
|
+
}
|
|
596
|
+
}], [{
|
|
597
|
+
key: "fromJSON",
|
|
598
|
+
value: function fromJSON(schema, json) {
|
|
599
|
+
if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
600
|
+
return new ReplaceStep(json.from, json.to, prosemirrorModel.Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
601
|
+
}
|
|
602
|
+
}]);
|
|
603
|
+
|
|
604
|
+
return ReplaceStep;
|
|
605
|
+
}(Step);
|
|
606
|
+
|
|
607
|
+
Step.jsonID("replace", ReplaceStep);
|
|
608
|
+
|
|
609
|
+
var ReplaceAroundStep = function (_Step4) {
|
|
610
|
+
_inherits(ReplaceAroundStep, _Step4);
|
|
611
|
+
|
|
612
|
+
var _super4 = _createSuper(ReplaceAroundStep);
|
|
613
|
+
|
|
614
|
+
function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert) {
|
|
615
|
+
var _this6;
|
|
616
|
+
|
|
617
|
+
var structure = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
618
|
+
|
|
619
|
+
_classCallCheck(this, ReplaceAroundStep);
|
|
620
|
+
|
|
621
|
+
_this6 = _super4.call(this);
|
|
622
|
+
_this6.from = from;
|
|
623
|
+
_this6.to = to;
|
|
624
|
+
_this6.gapFrom = gapFrom;
|
|
625
|
+
_this6.gapTo = gapTo;
|
|
626
|
+
_this6.slice = slice;
|
|
627
|
+
_this6.insert = insert;
|
|
628
|
+
_this6.structure = structure;
|
|
629
|
+
return _this6;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
_createClass(ReplaceAroundStep, [{
|
|
633
|
+
key: "apply",
|
|
634
|
+
value: function apply(doc) {
|
|
635
|
+
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to))) return StepResult.fail("Structure gap-replace would overwrite content");
|
|
636
|
+
var gap = doc.slice(this.gapFrom, this.gapTo);
|
|
637
|
+
if (gap.openStart || gap.openEnd) return StepResult.fail("Gap is not a flat range");
|
|
638
|
+
var inserted = this.slice.insertAt(this.insert, gap.content);
|
|
639
|
+
if (!inserted) return StepResult.fail("Content does not fit in gap");
|
|
640
|
+
return StepResult.fromReplace(doc, this.from, this.to, inserted);
|
|
641
|
+
}
|
|
642
|
+
}, {
|
|
643
|
+
key: "getMap",
|
|
644
|
+
value: function getMap() {
|
|
645
|
+
return new StepMap([this.from, this.gapFrom - this.from, this.insert, this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);
|
|
646
|
+
}
|
|
647
|
+
}, {
|
|
648
|
+
key: "invert",
|
|
649
|
+
value: function invert(doc) {
|
|
650
|
+
var gap = this.gapTo - this.gapFrom;
|
|
651
|
+
return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
652
|
+
}
|
|
653
|
+
}, {
|
|
654
|
+
key: "map",
|
|
655
|
+
value: function map(mapping) {
|
|
656
|
+
var from = mapping.mapResult(this.from, 1),
|
|
657
|
+
to = mapping.mapResult(this.to, -1);
|
|
658
|
+
var gapFrom = mapping.map(this.gapFrom, -1),
|
|
659
|
+
gapTo = mapping.map(this.gapTo, 1);
|
|
660
|
+
if (from.deleted && to.deleted || gapFrom < from.pos || gapTo > to.pos) return null;
|
|
661
|
+
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
662
|
+
}
|
|
663
|
+
}, {
|
|
664
|
+
key: "toJSON",
|
|
665
|
+
value: function toJSON() {
|
|
666
|
+
var json = {
|
|
667
|
+
stepType: "replaceAround",
|
|
668
|
+
from: this.from,
|
|
669
|
+
to: this.to,
|
|
670
|
+
gapFrom: this.gapFrom,
|
|
671
|
+
gapTo: this.gapTo,
|
|
672
|
+
insert: this.insert
|
|
673
|
+
};
|
|
674
|
+
if (this.slice.size) json.slice = this.slice.toJSON();
|
|
675
|
+
if (this.structure) json.structure = true;
|
|
676
|
+
return json;
|
|
677
|
+
}
|
|
678
|
+
}], [{
|
|
679
|
+
key: "fromJSON",
|
|
680
|
+
value: function fromJSON(schema, json) {
|
|
681
|
+
if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
682
|
+
return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, prosemirrorModel.Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
683
|
+
}
|
|
684
|
+
}]);
|
|
685
|
+
|
|
686
|
+
return ReplaceAroundStep;
|
|
687
|
+
}(Step);
|
|
688
|
+
|
|
689
|
+
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
690
|
+
|
|
691
|
+
function contentBetween(doc, from, to) {
|
|
692
|
+
var $from = doc.resolve(from),
|
|
693
|
+
dist = to - from,
|
|
694
|
+
depth = $from.depth;
|
|
695
|
+
|
|
696
|
+
while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
697
|
+
depth--;
|
|
698
|
+
dist--;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
if (dist > 0) {
|
|
702
|
+
var next = $from.node(depth).maybeChild($from.indexAfter(depth));
|
|
703
|
+
|
|
704
|
+
while (dist > 0) {
|
|
705
|
+
if (!next || next.isLeaf) return true;
|
|
706
|
+
next = next.firstChild;
|
|
707
|
+
dist--;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function _addMark(tr, from, to, mark) {
|
|
715
|
+
var removed = [],
|
|
716
|
+
added = [];
|
|
717
|
+
var removing, adding;
|
|
718
|
+
tr.doc.nodesBetween(from, to, function (node, pos, parent) {
|
|
719
|
+
if (!node.isInline) return;
|
|
720
|
+
var marks = node.marks;
|
|
721
|
+
|
|
722
|
+
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
723
|
+
var start = Math.max(pos, from),
|
|
724
|
+
end = Math.min(pos + node.nodeSize, to);
|
|
725
|
+
var newSet = mark.addToSet(marks);
|
|
726
|
+
|
|
727
|
+
for (var i = 0; i < marks.length; i++) {
|
|
728
|
+
if (!marks[i].isInSet(newSet)) {
|
|
729
|
+
if (removing && removing.to == start && removing.mark.eq(marks[i])) removing.to = end;else removed.push(removing = new RemoveMarkStep(start, end, marks[i]));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (adding && adding.to == start) adding.to = end;else added.push(adding = new AddMarkStep(start, end, mark));
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
removed.forEach(function (s) {
|
|
737
|
+
return tr.step(s);
|
|
738
|
+
});
|
|
739
|
+
added.forEach(function (s) {
|
|
740
|
+
return tr.step(s);
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function _removeMark(tr, from, to, mark) {
|
|
745
|
+
var matched = [],
|
|
746
|
+
step = 0;
|
|
747
|
+
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
748
|
+
if (!node.isInline) return;
|
|
749
|
+
step++;
|
|
750
|
+
var toRemove = null;
|
|
751
|
+
|
|
752
|
+
if (mark instanceof prosemirrorModel.MarkType) {
|
|
753
|
+
var set = node.marks,
|
|
754
|
+
found;
|
|
755
|
+
|
|
756
|
+
while (found = mark.isInSet(set)) {
|
|
757
|
+
(toRemove || (toRemove = [])).push(found);
|
|
758
|
+
set = found.removeFromSet(set);
|
|
759
|
+
}
|
|
760
|
+
} else if (mark) {
|
|
761
|
+
if (mark.isInSet(node.marks)) toRemove = [mark];
|
|
762
|
+
} else {
|
|
763
|
+
toRemove = node.marks;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (toRemove && toRemove.length) {
|
|
767
|
+
var end = Math.min(pos + node.nodeSize, to);
|
|
768
|
+
|
|
769
|
+
for (var i = 0; i < toRemove.length; i++) {
|
|
770
|
+
var style = toRemove[i],
|
|
771
|
+
_found = void 0;
|
|
772
|
+
|
|
773
|
+
for (var j = 0; j < matched.length; j++) {
|
|
774
|
+
var m = matched[j];
|
|
775
|
+
if (m.step == step - 1 && style.eq(matched[j].style)) _found = m;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (_found) {
|
|
779
|
+
_found.to = end;
|
|
780
|
+
_found.step = step;
|
|
781
|
+
} else {
|
|
782
|
+
matched.push({
|
|
783
|
+
style: style,
|
|
784
|
+
from: Math.max(pos, from),
|
|
785
|
+
to: end,
|
|
786
|
+
step: step
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
matched.forEach(function (m) {
|
|
793
|
+
return tr.step(new RemoveMarkStep(m.from, m.to, m.style));
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function _clearIncompatible(tr, pos, parentType) {
|
|
798
|
+
var match = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : parentType.contentMatch;
|
|
799
|
+
var node = tr.doc.nodeAt(pos);
|
|
800
|
+
var delSteps = [],
|
|
801
|
+
cur = pos + 1;
|
|
802
|
+
|
|
803
|
+
for (var i = 0; i < node.childCount; i++) {
|
|
804
|
+
var child = node.child(i),
|
|
805
|
+
end = cur + child.nodeSize;
|
|
806
|
+
var allowed = match.matchType(child.type);
|
|
807
|
+
|
|
808
|
+
if (!allowed) {
|
|
809
|
+
delSteps.push(new ReplaceStep(cur, end, prosemirrorModel.Slice.empty));
|
|
810
|
+
} else {
|
|
811
|
+
match = allowed;
|
|
812
|
+
|
|
813
|
+
for (var j = 0; j < child.marks.length; j++) {
|
|
814
|
+
if (!parentType.allowsMarkType(child.marks[j].type)) tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
cur = end;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (!match.validEnd) {
|
|
822
|
+
var fill = match.fillBefore(prosemirrorModel.Fragment.empty, true);
|
|
823
|
+
tr.replace(cur, cur, new prosemirrorModel.Slice(fill, 0, 0));
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
for (var _i = delSteps.length - 1; _i >= 0; _i--) {
|
|
827
|
+
tr.step(delSteps[_i]);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function canCut(node, start, end) {
|
|
832
|
+
return (start == 0 || node.canReplace(start, node.childCount)) && (end == node.childCount || node.canReplace(0, end));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function liftTarget(range) {
|
|
836
|
+
var parent = range.parent;
|
|
837
|
+
var content = parent.content.cutByIndex(range.startIndex, range.endIndex);
|
|
838
|
+
|
|
839
|
+
for (var depth = range.depth;; --depth) {
|
|
840
|
+
var node = range.$from.node(depth);
|
|
841
|
+
var index = range.$from.index(depth),
|
|
842
|
+
endIndex = range.$to.indexAfter(depth);
|
|
843
|
+
if (depth < range.depth && node.canReplace(index, endIndex, content)) return depth;
|
|
844
|
+
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function _lift(tr, range, target) {
|
|
851
|
+
var $from = range.$from,
|
|
852
|
+
$to = range.$to,
|
|
853
|
+
depth = range.depth;
|
|
854
|
+
var gapStart = $from.before(depth + 1),
|
|
855
|
+
gapEnd = $to.after(depth + 1);
|
|
856
|
+
var start = gapStart,
|
|
857
|
+
end = gapEnd;
|
|
858
|
+
var before = prosemirrorModel.Fragment.empty,
|
|
859
|
+
openStart = 0;
|
|
860
|
+
|
|
861
|
+
for (var d = depth, splitting = false; d > target; d--) {
|
|
862
|
+
if (splitting || $from.index(d) > 0) {
|
|
863
|
+
splitting = true;
|
|
864
|
+
before = prosemirrorModel.Fragment.from($from.node(d).copy(before));
|
|
865
|
+
openStart++;
|
|
866
|
+
} else {
|
|
867
|
+
start--;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
var after = prosemirrorModel.Fragment.empty,
|
|
872
|
+
openEnd = 0;
|
|
873
|
+
|
|
874
|
+
for (var _d = depth, _splitting = false; _d > target; _d--) {
|
|
875
|
+
if (_splitting || $to.after(_d + 1) < $to.end(_d)) {
|
|
876
|
+
_splitting = true;
|
|
877
|
+
after = prosemirrorModel.Fragment.from($to.node(_d).copy(after));
|
|
878
|
+
openEnd++;
|
|
879
|
+
} else {
|
|
880
|
+
end++;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new prosemirrorModel.Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function findWrapping(range, nodeType) {
|
|
888
|
+
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
889
|
+
var innerRange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : range;
|
|
890
|
+
var around = findWrappingOutside(range, nodeType);
|
|
891
|
+
var inner = around && findWrappingInside(innerRange, nodeType);
|
|
892
|
+
if (!inner) return null;
|
|
893
|
+
return around.map(withAttrs).concat({
|
|
894
|
+
type: nodeType,
|
|
895
|
+
attrs: attrs
|
|
896
|
+
}).concat(inner.map(withAttrs));
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function withAttrs(type) {
|
|
900
|
+
return {
|
|
901
|
+
type: type,
|
|
902
|
+
attrs: null
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function findWrappingOutside(range, type) {
|
|
907
|
+
var parent = range.parent,
|
|
908
|
+
startIndex = range.startIndex,
|
|
909
|
+
endIndex = range.endIndex;
|
|
910
|
+
var around = parent.contentMatchAt(startIndex).findWrapping(type);
|
|
911
|
+
if (!around) return null;
|
|
912
|
+
var outer = around.length ? around[0] : type;
|
|
913
|
+
return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
function findWrappingInside(range, type) {
|
|
917
|
+
var parent = range.parent,
|
|
918
|
+
startIndex = range.startIndex,
|
|
919
|
+
endIndex = range.endIndex;
|
|
920
|
+
var inner = parent.child(startIndex);
|
|
921
|
+
var inside = type.contentMatch.findWrapping(inner.type);
|
|
922
|
+
if (!inside) return null;
|
|
923
|
+
var lastType = inside.length ? inside[inside.length - 1] : type;
|
|
924
|
+
var innerMatch = lastType.contentMatch;
|
|
925
|
+
|
|
926
|
+
for (var i = startIndex; innerMatch && i < endIndex; i++) {
|
|
927
|
+
innerMatch = innerMatch.matchType(parent.child(i).type);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (!innerMatch || !innerMatch.validEnd) return null;
|
|
931
|
+
return inside;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function _wrap2(tr, range, wrappers) {
|
|
935
|
+
var content = prosemirrorModel.Fragment.empty;
|
|
936
|
+
|
|
937
|
+
for (var i = wrappers.length - 1; i >= 0; i--) {
|
|
938
|
+
if (content.size) {
|
|
939
|
+
var match = wrappers[i].type.contentMatch.matchFragment(content);
|
|
940
|
+
if (!match || !match.validEnd) throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
content = prosemirrorModel.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
var start = range.start,
|
|
947
|
+
end = range.end;
|
|
948
|
+
tr.step(new ReplaceAroundStep(start, end, start, end, new prosemirrorModel.Slice(content, 0, 0), wrappers.length, true));
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function _setBlockType(tr, from, to, type, attrs) {
|
|
952
|
+
if (!type.isTextblock) throw new RangeError("Type given to setBlockType should be a textblock");
|
|
953
|
+
var mapFrom = tr.steps.length;
|
|
954
|
+
tr.doc.nodesBetween(from, to, function (node, pos) {
|
|
955
|
+
if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
|
|
956
|
+
tr.clearIncompatible(tr.mapping.slice(mapFrom).map(pos, 1), type);
|
|
957
|
+
var mapping = tr.mapping.slice(mapFrom);
|
|
958
|
+
var startM = mapping.map(pos, 1),
|
|
959
|
+
endM = mapping.map(pos + node.nodeSize, 1);
|
|
960
|
+
tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(type.create(attrs, null, node.marks)), 0, 0), 1, true));
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function canChangeType(doc, pos, type) {
|
|
967
|
+
var $pos = doc.resolve(pos),
|
|
968
|
+
index = $pos.index();
|
|
969
|
+
return $pos.parent.canReplaceWith(index, index + 1, type);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function _setNodeMarkup(tr, pos, type, attrs, marks) {
|
|
973
|
+
var node = tr.doc.nodeAt(pos);
|
|
974
|
+
if (!node) throw new RangeError("No node at given position");
|
|
975
|
+
if (!type) type = node.type;
|
|
976
|
+
var newNode = type.create(attrs, null, marks || node.marks);
|
|
977
|
+
if (node.isLeaf) return tr.replaceWith(pos, pos + node.nodeSize, newNode);
|
|
978
|
+
if (!type.validContent(node.content)) throw new RangeError("Invalid content for node type " + type.name);
|
|
979
|
+
tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(newNode), 0, 0), 1, true));
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function canSplit(doc, pos) {
|
|
983
|
+
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
984
|
+
var typesAfter = arguments.length > 3 ? arguments[3] : undefined;
|
|
985
|
+
var $pos = doc.resolve(pos),
|
|
986
|
+
base = $pos.depth - depth;
|
|
987
|
+
var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent;
|
|
988
|
+
if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false;
|
|
989
|
+
|
|
990
|
+
for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
|
|
991
|
+
var node = $pos.node(d),
|
|
992
|
+
_index = $pos.index(d);
|
|
993
|
+
|
|
994
|
+
if (node.type.spec.isolating) return false;
|
|
995
|
+
var rest = node.content.cutByIndex(_index, node.childCount);
|
|
996
|
+
var after = typesAfter && typesAfter[i] || node;
|
|
997
|
+
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs));
|
|
998
|
+
if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
var index = $pos.indexAfter(base);
|
|
1002
|
+
var baseType = typesAfter && typesAfter[0];
|
|
1003
|
+
return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function _split(tr, pos) {
|
|
1007
|
+
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1008
|
+
var typesAfter = arguments.length > 3 ? arguments[3] : undefined;
|
|
1009
|
+
var $pos = tr.doc.resolve(pos),
|
|
1010
|
+
before = prosemirrorModel.Fragment.empty,
|
|
1011
|
+
after = prosemirrorModel.Fragment.empty;
|
|
1012
|
+
|
|
1013
|
+
for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {
|
|
1014
|
+
before = prosemirrorModel.Fragment.from($pos.node(d).copy(before));
|
|
1015
|
+
var typeAfter = typesAfter && typesAfter[i];
|
|
1016
|
+
after = prosemirrorModel.Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
tr.step(new ReplaceStep(pos, pos, new prosemirrorModel.Slice(before.append(after), depth, depth), true));
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function canJoin(doc, pos) {
|
|
1023
|
+
var $pos = doc.resolve(pos),
|
|
1024
|
+
index = $pos.index();
|
|
1025
|
+
return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function joinable(a, b) {
|
|
1029
|
+
return !!(a && b && !a.isLeaf && a.canAppend(b));
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function joinPoint(doc, pos) {
|
|
1033
|
+
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
|
|
1034
|
+
var $pos = doc.resolve(pos);
|
|
1035
|
+
|
|
1036
|
+
for (var d = $pos.depth;; d--) {
|
|
1037
|
+
var before = void 0,
|
|
1038
|
+
after = void 0,
|
|
1039
|
+
index = $pos.index(d);
|
|
1040
|
+
|
|
1041
|
+
if (d == $pos.depth) {
|
|
1042
|
+
before = $pos.nodeBefore;
|
|
1043
|
+
after = $pos.nodeAfter;
|
|
1044
|
+
} else if (dir > 0) {
|
|
1045
|
+
before = $pos.node(d + 1);
|
|
1046
|
+
index++;
|
|
1047
|
+
after = $pos.node(d).maybeChild(index);
|
|
1048
|
+
} else {
|
|
1049
|
+
before = $pos.node(d).maybeChild(index - 1);
|
|
1050
|
+
after = $pos.node(d + 1);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1)) return pos;
|
|
1054
|
+
if (d == 0) break;
|
|
1055
|
+
pos = dir < 0 ? $pos.before(d) : $pos.after(d);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function _join(tr, pos, depth) {
|
|
1060
|
+
var step = new ReplaceStep(pos - depth, pos + depth, prosemirrorModel.Slice.empty, true);
|
|
1061
|
+
tr.step(step);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function insertPoint(doc, pos, nodeType) {
|
|
1065
|
+
var $pos = doc.resolve(pos);
|
|
1066
|
+
if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) return pos;
|
|
1067
|
+
if ($pos.parentOffset == 0) for (var d = $pos.depth - 1; d >= 0; d--) {
|
|
1068
|
+
var index = $pos.index(d);
|
|
1069
|
+
if ($pos.node(d).canReplaceWith(index, index, nodeType)) return $pos.before(d + 1);
|
|
1070
|
+
if (index > 0) return null;
|
|
1071
|
+
}
|
|
1072
|
+
if ($pos.parentOffset == $pos.parent.content.size) for (var _d2 = $pos.depth - 1; _d2 >= 0; _d2--) {
|
|
1073
|
+
var _index2 = $pos.indexAfter(_d2);
|
|
1074
|
+
|
|
1075
|
+
if ($pos.node(_d2).canReplaceWith(_index2, _index2, nodeType)) return $pos.after(_d2 + 1);
|
|
1076
|
+
if (_index2 < $pos.node(_d2).childCount) return null;
|
|
1077
|
+
}
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function dropPoint(doc, pos, slice) {
|
|
1082
|
+
var $pos = doc.resolve(pos);
|
|
1083
|
+
if (!slice.content.size) return pos;
|
|
1084
|
+
var content = slice.content;
|
|
1085
|
+
|
|
1086
|
+
for (var i = 0; i < slice.openStart; i++) {
|
|
1087
|
+
content = content.firstChild.content;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {
|
|
1091
|
+
for (var d = $pos.depth; d >= 0; d--) {
|
|
1092
|
+
var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
|
|
1093
|
+
var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
|
|
1094
|
+
var parent = $pos.node(d),
|
|
1095
|
+
fits = false;
|
|
1096
|
+
|
|
1097
|
+
if (pass == 1) {
|
|
1098
|
+
fits = parent.canReplace(insertPos, insertPos, content);
|
|
1099
|
+
} else {
|
|
1100
|
+
var wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
|
|
1101
|
+
fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
return null;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function replaceStep(doc, from) {
|
|
1112
|
+
var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : from;
|
|
1113
|
+
var slice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prosemirrorModel.Slice.empty;
|
|
1114
|
+
if (from == to && !slice.size) return null;
|
|
1115
|
+
var $from = doc.resolve(from),
|
|
1116
|
+
$to = doc.resolve(to);
|
|
1117
|
+
if (fitsTrivially($from, $to, slice)) return new ReplaceStep(from, to, slice);
|
|
1118
|
+
return new Fitter($from, $to, slice).fit();
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function fitsTrivially($from, $to, slice) {
|
|
1122
|
+
return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
var Fitter = function () {
|
|
1126
|
+
function Fitter($from, $to, unplaced) {
|
|
1127
|
+
_classCallCheck(this, Fitter);
|
|
1128
|
+
|
|
1129
|
+
this.$from = $from;
|
|
1130
|
+
this.$to = $to;
|
|
1131
|
+
this.unplaced = unplaced;
|
|
1132
|
+
this.frontier = [];
|
|
1133
|
+
this.placed = prosemirrorModel.Fragment.empty;
|
|
1134
|
+
|
|
1135
|
+
for (var i = 0; i <= $from.depth; i++) {
|
|
1136
|
+
var node = $from.node(i);
|
|
1137
|
+
this.frontier.push({
|
|
1138
|
+
type: node.type,
|
|
1139
|
+
match: node.contentMatchAt($from.indexAfter(i))
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
for (var _i2 = $from.depth; _i2 > 0; _i2--) {
|
|
1144
|
+
this.placed = prosemirrorModel.Fragment.from($from.node(_i2).copy(this.placed));
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
_createClass(Fitter, [{
|
|
1149
|
+
key: "depth",
|
|
1150
|
+
get: function get() {
|
|
1151
|
+
return this.frontier.length - 1;
|
|
1152
|
+
}
|
|
1153
|
+
}, {
|
|
1154
|
+
key: "fit",
|
|
1155
|
+
value: function fit() {
|
|
1156
|
+
while (this.unplaced.size) {
|
|
1157
|
+
var fit = this.findFittable();
|
|
1158
|
+
if (fit) this.placeNodes(fit);else this.openMore() || this.dropNode();
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
var moveInline = this.mustMoveInline(),
|
|
1162
|
+
placedSize = this.placed.size - this.depth - this.$from.depth;
|
|
1163
|
+
var $from = this.$from,
|
|
1164
|
+
$to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
|
|
1165
|
+
if (!$to) return null;
|
|
1166
|
+
var content = this.placed,
|
|
1167
|
+
openStart = $from.depth,
|
|
1168
|
+
openEnd = $to.depth;
|
|
1169
|
+
|
|
1170
|
+
while (openStart && openEnd && content.childCount == 1) {
|
|
1171
|
+
content = content.firstChild.content;
|
|
1172
|
+
openStart--;
|
|
1173
|
+
openEnd--;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
var slice = new prosemirrorModel.Slice(content, openStart, openEnd);
|
|
1177
|
+
if (moveInline > -1) return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
|
|
1178
|
+
if (slice.size || $from.pos != this.$to.pos) return new ReplaceStep($from.pos, $to.pos, slice);
|
|
1179
|
+
return null;
|
|
1180
|
+
}
|
|
1181
|
+
}, {
|
|
1182
|
+
key: "findFittable",
|
|
1183
|
+
value: function findFittable() {
|
|
1184
|
+
for (var pass = 1; pass <= 2; pass++) {
|
|
1185
|
+
for (var sliceDepth = this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {
|
|
1186
|
+
var fragment = void 0,
|
|
1187
|
+
parent = null;
|
|
1188
|
+
|
|
1189
|
+
if (sliceDepth) {
|
|
1190
|
+
parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;
|
|
1191
|
+
fragment = parent.content;
|
|
1192
|
+
} else {
|
|
1193
|
+
fragment = this.unplaced.content;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var first = fragment.firstChild;
|
|
1197
|
+
|
|
1198
|
+
for (var frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {
|
|
1199
|
+
var _this$frontier$fronti = this.frontier[frontierDepth],
|
|
1200
|
+
type = _this$frontier$fronti.type,
|
|
1201
|
+
match = _this$frontier$fronti.match,
|
|
1202
|
+
_wrap = void 0,
|
|
1203
|
+
inject = null;
|
|
1204
|
+
|
|
1205
|
+
if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(prosemirrorModel.Fragment.from(first), false)) : parent && type.compatibleContent(parent.type))) return {
|
|
1206
|
+
sliceDepth: sliceDepth,
|
|
1207
|
+
frontierDepth: frontierDepth,
|
|
1208
|
+
parent: parent,
|
|
1209
|
+
inject: inject
|
|
1210
|
+
};else if (pass == 2 && first && (_wrap = match.findWrapping(first.type))) return {
|
|
1211
|
+
sliceDepth: sliceDepth,
|
|
1212
|
+
frontierDepth: frontierDepth,
|
|
1213
|
+
parent: parent,
|
|
1214
|
+
wrap: _wrap
|
|
1215
|
+
};
|
|
1216
|
+
if (parent && match.matchType(parent.type)) break;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}, {
|
|
1222
|
+
key: "openMore",
|
|
1223
|
+
value: function openMore() {
|
|
1224
|
+
var _this$unplaced = this.unplaced,
|
|
1225
|
+
content = _this$unplaced.content,
|
|
1226
|
+
openStart = _this$unplaced.openStart,
|
|
1227
|
+
openEnd = _this$unplaced.openEnd;
|
|
1228
|
+
var inner = contentAt(content, openStart);
|
|
1229
|
+
if (!inner.childCount || inner.firstChild.isLeaf) return false;
|
|
1230
|
+
this.unplaced = new prosemirrorModel.Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
|
|
1231
|
+
return true;
|
|
1232
|
+
}
|
|
1233
|
+
}, {
|
|
1234
|
+
key: "dropNode",
|
|
1235
|
+
value: function dropNode() {
|
|
1236
|
+
var _this$unplaced2 = this.unplaced,
|
|
1237
|
+
content = _this$unplaced2.content,
|
|
1238
|
+
openStart = _this$unplaced2.openStart,
|
|
1239
|
+
openEnd = _this$unplaced2.openEnd;
|
|
1240
|
+
var inner = contentAt(content, openStart);
|
|
1241
|
+
|
|
1242
|
+
if (inner.childCount <= 1 && openStart > 0) {
|
|
1243
|
+
var openAtEnd = content.size - openStart <= openStart + inner.size;
|
|
1244
|
+
this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);
|
|
1245
|
+
} else {
|
|
1246
|
+
this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}, {
|
|
1250
|
+
key: "placeNodes",
|
|
1251
|
+
value: function placeNodes(_ref) {
|
|
1252
|
+
var sliceDepth = _ref.sliceDepth,
|
|
1253
|
+
frontierDepth = _ref.frontierDepth,
|
|
1254
|
+
parent = _ref.parent,
|
|
1255
|
+
inject = _ref.inject,
|
|
1256
|
+
wrap = _ref.wrap;
|
|
1257
|
+
|
|
1258
|
+
while (this.depth > frontierDepth) {
|
|
1259
|
+
this.closeFrontierNode();
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
if (wrap) for (var i = 0; i < wrap.length; i++) {
|
|
1263
|
+
this.openFrontierNode(wrap[i]);
|
|
1264
|
+
}
|
|
1265
|
+
var slice = this.unplaced,
|
|
1266
|
+
fragment = parent ? parent.content : slice.content;
|
|
1267
|
+
var openStart = slice.openStart - sliceDepth;
|
|
1268
|
+
var taken = 0,
|
|
1269
|
+
add = [];
|
|
1270
|
+
var _this$frontier$fronti2 = this.frontier[frontierDepth],
|
|
1271
|
+
match = _this$frontier$fronti2.match,
|
|
1272
|
+
type = _this$frontier$fronti2.type;
|
|
1273
|
+
|
|
1274
|
+
if (inject) {
|
|
1275
|
+
for (var i = 0; i < inject.childCount; i++) {
|
|
1276
|
+
add.push(inject.child(i));
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
match = match.matchFragment(inject);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
var openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd);
|
|
1283
|
+
|
|
1284
|
+
while (taken < fragment.childCount) {
|
|
1285
|
+
var next = fragment.child(taken),
|
|
1286
|
+
matches = match.matchType(next.type);
|
|
1287
|
+
if (!matches) break;
|
|
1288
|
+
taken++;
|
|
1289
|
+
|
|
1290
|
+
if (taken > 1 || openStart == 0 || next.content.size) {
|
|
1291
|
+
match = matches;
|
|
1292
|
+
add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
var toEnd = taken == fragment.childCount;
|
|
1297
|
+
if (!toEnd) openEndCount = -1;
|
|
1298
|
+
this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add));
|
|
1299
|
+
this.frontier[frontierDepth].match = match;
|
|
1300
|
+
if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode();
|
|
1301
|
+
|
|
1302
|
+
for (var _i3 = 0, cur = fragment; _i3 < openEndCount; _i3++) {
|
|
1303
|
+
var node = cur.lastChild;
|
|
1304
|
+
this.frontier.push({
|
|
1305
|
+
type: node.type,
|
|
1306
|
+
match: node.contentMatchAt(node.childCount)
|
|
1307
|
+
});
|
|
1308
|
+
cur = node.content;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
|
|
1312
|
+
}
|
|
1313
|
+
}, {
|
|
1314
|
+
key: "mustMoveInline",
|
|
1315
|
+
value: function mustMoveInline() {
|
|
1316
|
+
if (!this.$to.parent.isTextblock) return -1;
|
|
1317
|
+
var top = this.frontier[this.depth],
|
|
1318
|
+
level;
|
|
1319
|
+
if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth) return -1;
|
|
1320
|
+
var depth = this.$to.depth,
|
|
1321
|
+
after = this.$to.after(depth);
|
|
1322
|
+
|
|
1323
|
+
while (depth > 1 && after == this.$to.end(--depth)) {
|
|
1324
|
+
++after;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
return after;
|
|
1328
|
+
}
|
|
1329
|
+
}, {
|
|
1330
|
+
key: "findCloseLevel",
|
|
1331
|
+
value: function findCloseLevel($to) {
|
|
1332
|
+
scan: for (var i = Math.min(this.depth, $to.depth); i >= 0; i--) {
|
|
1333
|
+
var _this$frontier$i = this.frontier[i],
|
|
1334
|
+
match = _this$frontier$i.match,
|
|
1335
|
+
type = _this$frontier$i.type;
|
|
1336
|
+
var dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));
|
|
1337
|
+
var fit = contentAfterFits($to, i, type, match, dropInner);
|
|
1338
|
+
if (!fit) continue;
|
|
1339
|
+
|
|
1340
|
+
for (var d = i - 1; d >= 0; d--) {
|
|
1341
|
+
var _this$frontier$d = this.frontier[d],
|
|
1342
|
+
_match = _this$frontier$d.match,
|
|
1343
|
+
_type = _this$frontier$d.type;
|
|
1344
|
+
var matches = contentAfterFits($to, d, _type, _match, true);
|
|
1345
|
+
if (!matches || matches.childCount) continue scan;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
return {
|
|
1349
|
+
depth: i,
|
|
1350
|
+
fit: fit,
|
|
1351
|
+
move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}, {
|
|
1356
|
+
key: "close",
|
|
1357
|
+
value: function close($to) {
|
|
1358
|
+
var close = this.findCloseLevel($to);
|
|
1359
|
+
if (!close) return null;
|
|
1360
|
+
|
|
1361
|
+
while (this.depth > close.depth) {
|
|
1362
|
+
this.closeFrontierNode();
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
if (close.fit.childCount) this.placed = addToFragment(this.placed, close.depth, close.fit);
|
|
1366
|
+
$to = close.move;
|
|
1367
|
+
|
|
1368
|
+
for (var d = close.depth + 1; d <= $to.depth; d++) {
|
|
1369
|
+
var node = $to.node(d),
|
|
1370
|
+
add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
|
|
1371
|
+
this.openFrontierNode(node.type, node.attrs, add);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
return $to;
|
|
1375
|
+
}
|
|
1376
|
+
}, {
|
|
1377
|
+
key: "openFrontierNode",
|
|
1378
|
+
value: function openFrontierNode(type) {
|
|
1379
|
+
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1380
|
+
var content = arguments.length > 2 ? arguments[2] : undefined;
|
|
1381
|
+
var top = this.frontier[this.depth];
|
|
1382
|
+
top.match = top.match.matchType(type);
|
|
1383
|
+
this.placed = addToFragment(this.placed, this.depth, prosemirrorModel.Fragment.from(type.create(attrs, content)));
|
|
1384
|
+
this.frontier.push({
|
|
1385
|
+
type: type,
|
|
1386
|
+
match: type.contentMatch
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
}, {
|
|
1390
|
+
key: "closeFrontierNode",
|
|
1391
|
+
value: function closeFrontierNode() {
|
|
1392
|
+
var open = this.frontier.pop();
|
|
1393
|
+
var add = open.match.fillBefore(prosemirrorModel.Fragment.empty, true);
|
|
1394
|
+
if (add.childCount) this.placed = addToFragment(this.placed, this.frontier.length, add);
|
|
1395
|
+
}
|
|
1396
|
+
}]);
|
|
1397
|
+
|
|
1398
|
+
return Fitter;
|
|
1399
|
+
}();
|
|
1400
|
+
|
|
1401
|
+
function dropFromFragment(fragment, depth, count) {
|
|
1402
|
+
if (depth == 0) return fragment.cutByIndex(count, fragment.childCount);
|
|
1403
|
+
return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
function addToFragment(fragment, depth, content) {
|
|
1407
|
+
if (depth == 0) return fragment.append(content);
|
|
1408
|
+
return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function contentAt(fragment, depth) {
|
|
1412
|
+
for (var i = 0; i < depth; i++) {
|
|
1413
|
+
fragment = fragment.firstChild.content;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
return fragment;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function closeNodeStart(node, openStart, openEnd) {
|
|
1420
|
+
if (openStart <= 0) return node;
|
|
1421
|
+
var frag = node.content;
|
|
1422
|
+
if (openStart > 1) frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));
|
|
1423
|
+
|
|
1424
|
+
if (openStart > 0) {
|
|
1425
|
+
frag = node.type.contentMatch.fillBefore(frag).append(frag);
|
|
1426
|
+
if (openEnd <= 0) frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(prosemirrorModel.Fragment.empty, true));
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
return node.copy(frag);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function contentAfterFits($to, depth, type, match, open) {
|
|
1433
|
+
var node = $to.node(depth),
|
|
1434
|
+
index = open ? $to.indexAfter(depth) : $to.index(depth);
|
|
1435
|
+
if (index == node.childCount && !type.compatibleContent(node.type)) return null;
|
|
1436
|
+
var fit = match.fillBefore(node.content, true, index);
|
|
1437
|
+
return fit && !invalidMarks(type, node.content, index) ? fit : null;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
function invalidMarks(type, fragment, start) {
|
|
1441
|
+
for (var i = start; i < fragment.childCount; i++) {
|
|
1442
|
+
if (!type.allowsMarks(fragment.child(i).marks)) return true;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
function definesContent(type) {
|
|
1449
|
+
return type.spec.defining || type.spec.definingForContent;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function _replaceRange(tr, from, to, slice) {
|
|
1453
|
+
if (!slice.size) return tr.deleteRange(from, to);
|
|
1454
|
+
var $from = tr.doc.resolve(from),
|
|
1455
|
+
$to = tr.doc.resolve(to);
|
|
1456
|
+
if (fitsTrivially($from, $to, slice)) return tr.step(new ReplaceStep(from, to, slice));
|
|
1457
|
+
var targetDepths = coveredDepths($from, tr.doc.resolve(to));
|
|
1458
|
+
if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop();
|
|
1459
|
+
var preferredTarget = -($from.depth + 1);
|
|
1460
|
+
targetDepths.unshift(preferredTarget);
|
|
1461
|
+
|
|
1462
|
+
for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
|
|
1463
|
+
var spec = $from.node(d).type.spec;
|
|
1464
|
+
if (spec.defining || spec.definingAsContext || spec.isolating) break;
|
|
1465
|
+
if (targetDepths.indexOf(d) > -1) preferredTarget = d;else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d);
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
var preferredTargetIndex = targetDepths.indexOf(preferredTarget);
|
|
1469
|
+
var leftNodes = [],
|
|
1470
|
+
preferredDepth = slice.openStart;
|
|
1471
|
+
|
|
1472
|
+
for (var content = slice.content, i = 0;; i++) {
|
|
1473
|
+
var node = content.firstChild;
|
|
1474
|
+
leftNodes.push(node);
|
|
1475
|
+
if (i == slice.openStart) break;
|
|
1476
|
+
content = node.content;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
for (var _d3 = preferredDepth - 1; _d3 >= 0; _d3--) {
|
|
1480
|
+
var type = leftNodes[_d3].type,
|
|
1481
|
+
def = definesContent(type);
|
|
1482
|
+
if (def && $from.node(preferredTargetIndex).type != type) preferredDepth = _d3;else if (def || !type.isTextblock) break;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
for (var j = slice.openStart; j >= 0; j--) {
|
|
1486
|
+
var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);
|
|
1487
|
+
var insert = leftNodes[openDepth];
|
|
1488
|
+
if (!insert) continue;
|
|
1489
|
+
|
|
1490
|
+
for (var _i4 = 0; _i4 < targetDepths.length; _i4++) {
|
|
1491
|
+
var targetDepth = targetDepths[(_i4 + preferredTargetIndex) % targetDepths.length],
|
|
1492
|
+
expand = true;
|
|
1493
|
+
|
|
1494
|
+
if (targetDepth < 0) {
|
|
1495
|
+
expand = false;
|
|
1496
|
+
targetDepth = -targetDepth;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
var parent = $from.node(targetDepth - 1),
|
|
1500
|
+
index = $from.index(targetDepth - 1);
|
|
1501
|
+
if (parent.canReplaceWith(index, index, insert.type, insert.marks)) return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new prosemirrorModel.Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
var startSteps = tr.steps.length;
|
|
1506
|
+
|
|
1507
|
+
for (var _i5 = targetDepths.length - 1; _i5 >= 0; _i5--) {
|
|
1508
|
+
tr.replace(from, to, slice);
|
|
1509
|
+
if (tr.steps.length > startSteps) break;
|
|
1510
|
+
var depth = targetDepths[_i5];
|
|
1511
|
+
if (depth < 0) continue;
|
|
1512
|
+
from = $from.before(depth);
|
|
1513
|
+
to = $to.after(depth);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
function closeFragment(fragment, depth, oldOpen, newOpen, parent) {
|
|
1518
|
+
if (depth < oldOpen) {
|
|
1519
|
+
var first = fragment.firstChild;
|
|
1520
|
+
fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
if (depth > newOpen) {
|
|
1524
|
+
var match = parent.contentMatchAt(0);
|
|
1525
|
+
var start = match.fillBefore(fragment).append(fragment);
|
|
1526
|
+
fragment = start.append(match.matchFragment(start).fillBefore(prosemirrorModel.Fragment.empty, true));
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
return fragment;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
function _replaceRangeWith(tr, from, to, node) {
|
|
1533
|
+
if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {
|
|
1534
|
+
var point = insertPoint(tr.doc, from, node.type);
|
|
1535
|
+
if (point != null) from = to = point;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
tr.replaceRange(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(node), 0, 0));
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
function _deleteRange(tr, from, to) {
|
|
1542
|
+
var $from = tr.doc.resolve(from),
|
|
1543
|
+
$to = tr.doc.resolve(to);
|
|
1544
|
+
var covered = coveredDepths($from, $to);
|
|
1545
|
+
|
|
1546
|
+
for (var i = 0; i < covered.length; i++) {
|
|
1547
|
+
var depth = covered[i],
|
|
1548
|
+
last = i == covered.length - 1;
|
|
1549
|
+
if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) return tr["delete"]($from.start(depth), $to.end(depth));
|
|
1550
|
+
if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) return tr["delete"]($from.before(depth), $to.after(depth));
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
for (var d = 1; d <= $from.depth && d <= $to.depth; d++) {
|
|
1554
|
+
if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d) return tr["delete"]($from.before(d), to);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
tr["delete"](from, to);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function coveredDepths($from, $to) {
|
|
1561
|
+
var result = [],
|
|
1562
|
+
minDepth = Math.min($from.depth, $to.depth);
|
|
1563
|
+
|
|
1564
|
+
for (var d = minDepth; d >= 0; d--) {
|
|
1565
|
+
var start = $from.start(d);
|
|
1566
|
+
if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating) break;
|
|
1567
|
+
if (start == $to.start(d) || d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent && d && $to.start(d - 1) == start - 1) result.push(d);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
return result;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
exports.TransformError = function (_Error) {
|
|
1574
|
+
_inherits(_class, _Error);
|
|
1575
|
+
|
|
1576
|
+
var _super5 = _createSuper(_class);
|
|
1577
|
+
|
|
1578
|
+
function _class() {
|
|
1579
|
+
_classCallCheck(this, _class);
|
|
1580
|
+
|
|
1581
|
+
return _super5.apply(this, arguments);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
return _createClass(_class);
|
|
1585
|
+
}(_wrapNativeSuper(Error));
|
|
1586
|
+
|
|
1587
|
+
exports.TransformError = function TransformError(message) {
|
|
1588
|
+
var err = Error.call(this, message);
|
|
1589
|
+
err.__proto__ = TransformError.prototype;
|
|
1590
|
+
return err;
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
exports.TransformError.prototype = Object.create(Error.prototype);
|
|
1594
|
+
exports.TransformError.prototype.constructor = exports.TransformError;
|
|
1595
|
+
exports.TransformError.prototype.name = "TransformError";
|
|
1596
|
+
|
|
1597
|
+
var Transform = function () {
|
|
1598
|
+
function Transform(doc) {
|
|
1599
|
+
_classCallCheck(this, Transform);
|
|
1600
|
+
|
|
1601
|
+
this.doc = doc;
|
|
1602
|
+
this.steps = [];
|
|
1603
|
+
this.docs = [];
|
|
1604
|
+
this.mapping = new Mapping();
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
_createClass(Transform, [{
|
|
1608
|
+
key: "before",
|
|
1609
|
+
get: function get() {
|
|
1610
|
+
return this.docs.length ? this.docs[0] : this.doc;
|
|
1611
|
+
}
|
|
1612
|
+
}, {
|
|
1613
|
+
key: "step",
|
|
1614
|
+
value: function step(_step) {
|
|
1615
|
+
var result = this.maybeStep(_step);
|
|
1616
|
+
if (result.failed) throw new exports.TransformError(result.failed);
|
|
1617
|
+
return this;
|
|
1618
|
+
}
|
|
1619
|
+
}, {
|
|
1620
|
+
key: "maybeStep",
|
|
1621
|
+
value: function maybeStep(step) {
|
|
1622
|
+
var result = step.apply(this.doc);
|
|
1623
|
+
if (!result.failed) this.addStep(step, result.doc);
|
|
1624
|
+
return result;
|
|
1625
|
+
}
|
|
1626
|
+
}, {
|
|
1627
|
+
key: "docChanged",
|
|
1628
|
+
get: function get() {
|
|
1629
|
+
return this.steps.length > 0;
|
|
1630
|
+
}
|
|
1631
|
+
}, {
|
|
1632
|
+
key: "addStep",
|
|
1633
|
+
value: function addStep(step, doc) {
|
|
1634
|
+
this.docs.push(this.doc);
|
|
1635
|
+
this.steps.push(step);
|
|
1636
|
+
this.mapping.appendMap(step.getMap());
|
|
1637
|
+
this.doc = doc;
|
|
1638
|
+
}
|
|
1639
|
+
}, {
|
|
1640
|
+
key: "replace",
|
|
1641
|
+
value: function replace(from) {
|
|
1642
|
+
var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from;
|
|
1643
|
+
var slice = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : prosemirrorModel.Slice.empty;
|
|
1644
|
+
var step = replaceStep(this.doc, from, to, slice);
|
|
1645
|
+
if (step) this.step(step);
|
|
1646
|
+
return this;
|
|
1647
|
+
}
|
|
1648
|
+
}, {
|
|
1649
|
+
key: "replaceWith",
|
|
1650
|
+
value: function replaceWith(from, to, content) {
|
|
1651
|
+
return this.replace(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(content), 0, 0));
|
|
1652
|
+
}
|
|
1653
|
+
}, {
|
|
1654
|
+
key: "delete",
|
|
1655
|
+
value: function _delete(from, to) {
|
|
1656
|
+
return this.replace(from, to, prosemirrorModel.Slice.empty);
|
|
1657
|
+
}
|
|
1658
|
+
}, {
|
|
1659
|
+
key: "insert",
|
|
1660
|
+
value: function insert(pos, content) {
|
|
1661
|
+
return this.replaceWith(pos, pos, content);
|
|
1662
|
+
}
|
|
1663
|
+
}, {
|
|
1664
|
+
key: "replaceRange",
|
|
1665
|
+
value: function replaceRange(from, to, slice) {
|
|
1666
|
+
_replaceRange(this, from, to, slice);
|
|
1667
|
+
|
|
1668
|
+
return this;
|
|
1669
|
+
}
|
|
1670
|
+
}, {
|
|
1671
|
+
key: "replaceRangeWith",
|
|
1672
|
+
value: function replaceRangeWith(from, to, node) {
|
|
1673
|
+
_replaceRangeWith(this, from, to, node);
|
|
1674
|
+
|
|
1675
|
+
return this;
|
|
1676
|
+
}
|
|
1677
|
+
}, {
|
|
1678
|
+
key: "deleteRange",
|
|
1679
|
+
value: function deleteRange(from, to) {
|
|
1680
|
+
_deleteRange(this, from, to);
|
|
1681
|
+
|
|
1682
|
+
return this;
|
|
1683
|
+
}
|
|
1684
|
+
}, {
|
|
1685
|
+
key: "lift",
|
|
1686
|
+
value: function lift(range, target) {
|
|
1687
|
+
_lift(this, range, target);
|
|
1688
|
+
|
|
1689
|
+
return this;
|
|
1690
|
+
}
|
|
1691
|
+
}, {
|
|
1692
|
+
key: "join",
|
|
1693
|
+
value: function join(pos) {
|
|
1694
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1695
|
+
|
|
1696
|
+
_join(this, pos, depth);
|
|
1697
|
+
|
|
1698
|
+
return this;
|
|
1699
|
+
}
|
|
1700
|
+
}, {
|
|
1701
|
+
key: "wrap",
|
|
1702
|
+
value: function wrap(range, wrappers) {
|
|
1703
|
+
_wrap2(this, range, wrappers);
|
|
1704
|
+
|
|
1705
|
+
return this;
|
|
1706
|
+
}
|
|
1707
|
+
}, {
|
|
1708
|
+
key: "setBlockType",
|
|
1709
|
+
value: function setBlockType(from) {
|
|
1710
|
+
var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from;
|
|
1711
|
+
var type = arguments.length > 2 ? arguments[2] : undefined;
|
|
1712
|
+
var attrs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
1713
|
+
|
|
1714
|
+
_setBlockType(this, from, to, type, attrs);
|
|
1715
|
+
|
|
1716
|
+
return this;
|
|
1717
|
+
}
|
|
1718
|
+
}, {
|
|
1719
|
+
key: "setNodeMarkup",
|
|
1720
|
+
value: function setNodeMarkup(pos, type) {
|
|
1721
|
+
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1722
|
+
var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
1723
|
+
|
|
1724
|
+
_setNodeMarkup(this, pos, type, attrs, marks);
|
|
1725
|
+
|
|
1726
|
+
return this;
|
|
1727
|
+
}
|
|
1728
|
+
}, {
|
|
1729
|
+
key: "split",
|
|
1730
|
+
value: function split(pos) {
|
|
1731
|
+
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1732
|
+
var typesAfter = arguments.length > 2 ? arguments[2] : undefined;
|
|
1733
|
+
|
|
1734
|
+
_split(this, pos, depth, typesAfter);
|
|
1735
|
+
|
|
1736
|
+
return this;
|
|
1737
|
+
}
|
|
1738
|
+
}, {
|
|
1739
|
+
key: "addMark",
|
|
1740
|
+
value: function addMark(from, to, mark) {
|
|
1741
|
+
_addMark(this, from, to, mark);
|
|
1742
|
+
|
|
1743
|
+
return this;
|
|
1744
|
+
}
|
|
1745
|
+
}, {
|
|
1746
|
+
key: "removeMark",
|
|
1747
|
+
value: function removeMark(from, to, mark) {
|
|
1748
|
+
_removeMark(this, from, to, mark);
|
|
1749
|
+
|
|
1750
|
+
return this;
|
|
1751
|
+
}
|
|
1752
|
+
}, {
|
|
1753
|
+
key: "clearIncompatible",
|
|
1754
|
+
value: function clearIncompatible(pos, parentType, match) {
|
|
1755
|
+
_clearIncompatible(this, pos, parentType, match);
|
|
1756
|
+
|
|
1757
|
+
return this;
|
|
1758
|
+
}
|
|
1759
|
+
}]);
|
|
1760
|
+
|
|
1761
|
+
return Transform;
|
|
1762
|
+
}();
|
|
1763
|
+
|
|
1764
|
+
exports.AddMarkStep = AddMarkStep;
|
|
1765
|
+
exports.MapResult = MapResult;
|
|
1766
|
+
exports.Mapping = Mapping;
|
|
1767
|
+
exports.RemoveMarkStep = RemoveMarkStep;
|
|
1768
|
+
exports.ReplaceAroundStep = ReplaceAroundStep;
|
|
1769
|
+
exports.ReplaceStep = ReplaceStep;
|
|
1770
|
+
exports.Step = Step;
|
|
1771
|
+
exports.StepMap = StepMap;
|
|
1772
|
+
exports.StepResult = StepResult;
|
|
1773
|
+
exports.Transform = Transform;
|
|
1774
|
+
exports.canJoin = canJoin;
|
|
1775
|
+
exports.canSplit = canSplit;
|
|
1776
|
+
exports.dropPoint = dropPoint;
|
|
1777
|
+
exports.findWrapping = findWrapping;
|
|
1778
|
+
exports.insertPoint = insertPoint;
|
|
1779
|
+
exports.joinPoint = joinPoint;
|
|
1780
|
+
exports.liftTarget = liftTarget;
|
|
1781
|
+
exports.replaceStep = replaceStep;
|