prosemirror-transform 1.8.0 → 1.9.0

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