prosemirror-transform 1.8.0 → 1.10.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,95 @@ 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
- 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);
945
+ var attrsHere = typeof attrs == "function" ? attrs(node) : attrs;
946
+ if (node.isTextblock && !node.hasMarkup(type, attrsHere) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
947
+ var convertNewlines = null;
948
+ if (type.schema.linebreakReplacement) {
949
+ var pre = type.whitespace == "pre",
950
+ supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);
951
+ if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true;
952
+ }
953
+ if (convertNewlines === false) replaceLinebreaks(tr, node, pos, mapFrom);
954
+ _clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);
1124
955
  var mapping = tr.mapping.slice(mapFrom);
1125
956
  var startM = mapping.map(pos, 1),
1126
- endM = mapping.map(pos + node.nodeSize, 1);
1127
- 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));
957
+ endM = mapping.map(pos + node.nodeSize, 1);
958
+ tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));
959
+ if (convertNewlines === true) replaceNewlines(tr, node, pos, mapFrom);
1128
960
  return false;
1129
961
  }
1130
962
  });
1131
963
  }
1132
-
964
+ function replaceNewlines(tr, node, pos, mapFrom) {
965
+ node.forEach(function (child, offset) {
966
+ if (child.isText) {
967
+ var m,
968
+ newline = /\r?\n|\r/g;
969
+ while (m = newline.exec(child.text)) {
970
+ var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index);
971
+ tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create());
972
+ }
973
+ }
974
+ });
975
+ }
976
+ function replaceLinebreaks(tr, node, pos, mapFrom) {
977
+ node.forEach(function (child, offset) {
978
+ if (child.type == child.type.schema.linebreakReplacement) {
979
+ var start = tr.mapping.slice(mapFrom).map(pos + 1 + offset);
980
+ tr.replaceWith(start, start + 1, node.type.schema.text("\n"));
981
+ }
982
+ });
983
+ }
1133
984
  function canChangeType(doc, pos, type) {
1134
985
  var $pos = doc.resolve(pos),
1135
- index = $pos.index();
986
+ index = $pos.index();
1136
987
  return $pos.parent.canReplaceWith(index, index + 1, type);
1137
988
  }
1138
-
1139
989
  function _setNodeMarkup(tr, pos, type, attrs, marks) {
1140
990
  var node = tr.doc.nodeAt(pos);
1141
991
  if (!node) throw new RangeError("No node at given position");
@@ -1145,19 +995,16 @@ function _setNodeMarkup(tr, pos, type, attrs, marks) {
1145
995
  if (!type.validContent(node.content)) throw new RangeError("Invalid content for node type " + type.name);
1146
996
  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
997
  }
1148
-
1149
998
  function canSplit(doc, pos) {
1150
999
  var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1151
1000
  var typesAfter = arguments.length > 3 ? arguments[3] : undefined;
1152
1001
  var $pos = doc.resolve(pos),
1153
- base = $pos.depth - depth;
1002
+ base = $pos.depth - depth;
1154
1003
  var innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent;
1155
1004
  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
1005
  for (var d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
1158
1006
  var node = $pos.node(d),
1159
- _index = $pos.index(d);
1160
-
1007
+ _index = $pos.index(d);
1161
1008
  if (node.type.spec.isolating) return false;
1162
1009
  var rest = node.content.cutByIndex(_index, node.childCount);
1163
1010
  var overrideChild = typesAfter && typesAfter[i + 1];
@@ -1165,47 +1012,38 @@ function canSplit(doc, pos) {
1165
1012
  var after = typesAfter && typesAfter[i] || node;
1166
1013
  if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false;
1167
1014
  }
1168
-
1169
1015
  var index = $pos.indexAfter(base);
1170
1016
  var baseType = typesAfter && typesAfter[0];
1171
1017
  return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
1172
1018
  }
1173
-
1174
1019
  function _split(tr, pos) {
1175
1020
  var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1176
1021
  var typesAfter = arguments.length > 3 ? arguments[3] : undefined;
1177
1022
  var $pos = tr.doc.resolve(pos),
1178
- before = prosemirrorModel.Fragment.empty,
1179
- after = prosemirrorModel.Fragment.empty;
1180
-
1023
+ before = prosemirrorModel.Fragment.empty,
1024
+ after = prosemirrorModel.Fragment.empty;
1181
1025
  for (var d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {
1182
1026
  before = prosemirrorModel.Fragment.from($pos.node(d).copy(before));
1183
1027
  var typeAfter = typesAfter && typesAfter[i];
1184
1028
  after = prosemirrorModel.Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
1185
1029
  }
1186
-
1187
1030
  tr.step(new ReplaceStep(pos, pos, new prosemirrorModel.Slice(before.append(after), depth, depth), true));
1188
1031
  }
1189
-
1190
1032
  function canJoin(doc, pos) {
1191
1033
  var $pos = doc.resolve(pos),
1192
- index = $pos.index();
1034
+ index = $pos.index();
1193
1035
  return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1);
1194
1036
  }
1195
-
1196
1037
  function joinable(a, b) {
1197
1038
  return !!(a && b && !a.isLeaf && a.canAppend(b));
1198
1039
  }
1199
-
1200
1040
  function joinPoint(doc, pos) {
1201
1041
  var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
1202
1042
  var $pos = doc.resolve(pos);
1203
-
1204
1043
  for (var d = $pos.depth;; d--) {
1205
1044
  var before = void 0,
1206
- after = void 0,
1207
- index = $pos.index(d);
1208
-
1045
+ after = void 0,
1046
+ index = $pos.index(d);
1209
1047
  if (d == $pos.depth) {
1210
1048
  before = $pos.nodeBefore;
1211
1049
  after = $pos.nodeAfter;
@@ -1217,18 +1055,15 @@ function joinPoint(doc, pos) {
1217
1055
  before = $pos.node(d).maybeChild(index - 1);
1218
1056
  after = $pos.node(d + 1);
1219
1057
  }
1220
-
1221
1058
  if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1)) return pos;
1222
1059
  if (d == 0) break;
1223
1060
  pos = dir < 0 ? $pos.before(d) : $pos.after(d);
1224
1061
  }
1225
1062
  }
1226
-
1227
1063
  function _join(tr, pos, depth) {
1228
1064
  var step = new ReplaceStep(pos - depth, pos + depth, prosemirrorModel.Slice.empty, true);
1229
1065
  tr.step(step);
1230
1066
  }
1231
-
1232
1067
  function insertPoint(doc, pos, nodeType) {
1233
1068
  var $pos = doc.resolve(pos);
1234
1069
  if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) return pos;
@@ -1239,67 +1074,53 @@ function insertPoint(doc, pos, nodeType) {
1239
1074
  }
1240
1075
  if ($pos.parentOffset == $pos.parent.content.size) for (var _d2 = $pos.depth - 1; _d2 >= 0; _d2--) {
1241
1076
  var _index2 = $pos.indexAfter(_d2);
1242
-
1243
1077
  if ($pos.node(_d2).canReplaceWith(_index2, _index2, nodeType)) return $pos.after(_d2 + 1);
1244
1078
  if (_index2 < $pos.node(_d2).childCount) return null;
1245
1079
  }
1246
1080
  return null;
1247
1081
  }
1248
-
1249
1082
  function dropPoint(doc, pos, slice) {
1250
1083
  var $pos = doc.resolve(pos);
1251
1084
  if (!slice.content.size) return pos;
1252
1085
  var content = slice.content;
1253
-
1254
- for (var i = 0; i < slice.openStart; i++) {
1255
- content = content.firstChild.content;
1256
- }
1257
-
1086
+ for (var i = 0; i < slice.openStart; i++) content = content.firstChild.content;
1258
1087
  for (var pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {
1259
1088
  for (var d = $pos.depth; d >= 0; d--) {
1260
1089
  var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
1261
1090
  var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
1262
1091
  var parent = $pos.node(d),
1263
- fits = false;
1264
-
1092
+ fits = false;
1265
1093
  if (pass == 1) {
1266
1094
  fits = parent.canReplace(insertPos, insertPos, content);
1267
1095
  } else {
1268
1096
  var wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
1269
1097
  fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
1270
1098
  }
1271
-
1272
1099
  if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
1273
1100
  }
1274
1101
  }
1275
-
1276
1102
  return null;
1277
1103
  }
1278
-
1279
1104
  function replaceStep(doc, from) {
1280
1105
  var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : from;
1281
1106
  var slice = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prosemirrorModel.Slice.empty;
1282
1107
  if (from == to && !slice.size) return null;
1283
1108
  var $from = doc.resolve(from),
1284
- $to = doc.resolve(to);
1109
+ $to = doc.resolve(to);
1285
1110
  if (fitsTrivially($from, $to, slice)) return new ReplaceStep(from, to, slice);
1286
1111
  return new Fitter($from, $to, slice).fit();
1287
1112
  }
1288
-
1289
1113
  function fitsTrivially($from, $to, slice) {
1290
1114
  return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content);
1291
1115
  }
1292
-
1293
1116
  var Fitter = function () {
1294
1117
  function Fitter($from, $to, unplaced) {
1295
1118
  _classCallCheck(this, Fitter);
1296
-
1297
1119
  this.$from = $from;
1298
1120
  this.$to = $to;
1299
1121
  this.unplaced = unplaced;
1300
1122
  this.frontier = [];
1301
1123
  this.placed = prosemirrorModel.Fragment.empty;
1302
-
1303
1124
  for (var i = 0; i <= $from.depth; i++) {
1304
1125
  var node = $from.node(i);
1305
1126
  this.frontier.push({
@@ -1307,12 +1128,8 @@ var Fitter = function () {
1307
1128
  match: node.contentMatchAt($from.indexAfter(i))
1308
1129
  });
1309
1130
  }
1310
-
1311
- for (var _i2 = $from.depth; _i2 > 0; _i2--) {
1312
- this.placed = prosemirrorModel.Fragment.from($from.node(_i2).copy(this.placed));
1313
- }
1131
+ for (var _i2 = $from.depth; _i2 > 0; _i2--) this.placed = prosemirrorModel.Fragment.from($from.node(_i2).copy(this.placed));
1314
1132
  }
1315
-
1316
1133
  _createClass(Fitter, [{
1317
1134
  key: "depth",
1318
1135
  get: function get() {
@@ -1325,22 +1142,19 @@ var Fitter = function () {
1325
1142
  var fit = this.findFittable();
1326
1143
  if (fit) this.placeNodes(fit);else this.openMore() || this.dropNode();
1327
1144
  }
1328
-
1329
1145
  var moveInline = this.mustMoveInline(),
1330
- placedSize = this.placed.size - this.depth - this.$from.depth;
1146
+ placedSize = this.placed.size - this.depth - this.$from.depth;
1331
1147
  var $from = this.$from,
1332
- $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
1148
+ $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
1333
1149
  if (!$to) return null;
1334
1150
  var content = this.placed,
1335
- openStart = $from.depth,
1336
- openEnd = $to.depth;
1337
-
1151
+ openStart = $from.depth,
1152
+ openEnd = $to.depth;
1338
1153
  while (openStart && openEnd && content.childCount == 1) {
1339
1154
  content = content.firstChild.content;
1340
1155
  openStart--;
1341
1156
  openEnd--;
1342
1157
  }
1343
-
1344
1158
  var slice = new prosemirrorModel.Slice(content, openStart, openEnd);
1345
1159
  if (moveInline > -1) return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
1346
1160
  if (slice.size || $from.pos != this.$to.pos) return new ReplaceStep($from.pos, $to.pos, slice);
@@ -1350,40 +1164,32 @@ var Fitter = function () {
1350
1164
  key: "findFittable",
1351
1165
  value: function findFittable() {
1352
1166
  var startDepth = this.unplaced.openStart;
1353
-
1354
1167
  for (var cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {
1355
1168
  var node = cur.firstChild;
1356
1169
  if (cur.childCount > 1) openEnd = 0;
1357
-
1358
1170
  if (node.type.spec.isolating && openEnd <= d) {
1359
1171
  startDepth = d;
1360
1172
  break;
1361
1173
  }
1362
-
1363
1174
  cur = node.content;
1364
1175
  }
1365
-
1366
1176
  for (var pass = 1; pass <= 2; pass++) {
1367
1177
  for (var sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {
1368
1178
  var fragment = void 0,
1369
- parent = null;
1370
-
1179
+ parent = null;
1371
1180
  if (sliceDepth) {
1372
1181
  parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;
1373
1182
  fragment = parent.content;
1374
1183
  } else {
1375
1184
  fragment = this.unplaced.content;
1376
1185
  }
1377
-
1378
1186
  var first = fragment.firstChild;
1379
-
1380
1187
  for (var frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {
1381
1188
  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
-
1189
+ type = _this$frontier$fronti.type,
1190
+ match = _this$frontier$fronti.match,
1191
+ _wrap = void 0,
1192
+ inject = null;
1387
1193
  if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(prosemirrorModel.Fragment.from(first), false)) : parent && type.compatibleContent(parent.type))) return {
1388
1194
  sliceDepth: sliceDepth,
1389
1195
  frontierDepth: frontierDepth,
@@ -1404,9 +1210,9 @@ var Fitter = function () {
1404
1210
  key: "openMore",
1405
1211
  value: function openMore() {
1406
1212
  var _this$unplaced = this.unplaced,
1407
- content = _this$unplaced.content,
1408
- openStart = _this$unplaced.openStart,
1409
- openEnd = _this$unplaced.openEnd;
1213
+ content = _this$unplaced.content,
1214
+ openStart = _this$unplaced.openStart,
1215
+ openEnd = _this$unplaced.openEnd;
1410
1216
  var inner = contentAt(content, openStart);
1411
1217
  if (!inner.childCount || inner.firstChild.isLeaf) return false;
1412
1218
  this.unplaced = new prosemirrorModel.Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
@@ -1416,11 +1222,10 @@ var Fitter = function () {
1416
1222
  key: "dropNode",
1417
1223
  value: function dropNode() {
1418
1224
  var _this$unplaced2 = this.unplaced,
1419
- content = _this$unplaced2.content,
1420
- openStart = _this$unplaced2.openStart,
1421
- openEnd = _this$unplaced2.openEnd;
1225
+ content = _this$unplaced2.content,
1226
+ openStart = _this$unplaced2.openStart,
1227
+ openEnd = _this$unplaced2.openEnd;
1422
1228
  var inner = contentAt(content, openStart);
1423
-
1424
1229
  if (inner.childCount <= 1 && openStart > 0) {
1425
1230
  var openAtEnd = content.size - openStart <= openStart + inner.size;
1426
1231
  this.unplaced = new prosemirrorModel.Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);
@@ -1432,56 +1237,41 @@ var Fitter = function () {
1432
1237
  key: "placeNodes",
1433
1238
  value: function placeNodes(_ref) {
1434
1239
  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
- }
1240
+ frontierDepth = _ref.frontierDepth,
1241
+ parent = _ref.parent,
1242
+ inject = _ref.inject,
1243
+ wrap = _ref.wrap;
1244
+ while (this.depth > frontierDepth) this.closeFrontierNode();
1245
+ if (wrap) for (var i = 0; i < wrap.length; i++) this.openFrontierNode(wrap[i]);
1447
1246
  var slice = this.unplaced,
1448
- fragment = parent ? parent.content : slice.content;
1247
+ fragment = parent ? parent.content : slice.content;
1449
1248
  var openStart = slice.openStart - sliceDepth;
1450
1249
  var taken = 0,
1451
- add = [];
1250
+ add = [];
1452
1251
  var _this$frontier$fronti2 = this.frontier[frontierDepth],
1453
- match = _this$frontier$fronti2.match,
1454
- type = _this$frontier$fronti2.type;
1455
-
1252
+ match = _this$frontier$fronti2.match,
1253
+ type = _this$frontier$fronti2.type;
1456
1254
  if (inject) {
1457
- for (var i = 0; i < inject.childCount; i++) {
1458
- add.push(inject.child(i));
1459
- }
1460
-
1255
+ for (var _i3 = 0; _i3 < inject.childCount; _i3++) add.push(inject.child(_i3));
1461
1256
  match = match.matchFragment(inject);
1462
1257
  }
1463
-
1464
1258
  var openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd);
1465
-
1466
1259
  while (taken < fragment.childCount) {
1467
1260
  var next = fragment.child(taken),
1468
- matches = match.matchType(next.type);
1261
+ matches = match.matchType(next.type);
1469
1262
  if (!matches) break;
1470
1263
  taken++;
1471
-
1472
1264
  if (taken > 1 || openStart == 0 || next.content.size) {
1473
1265
  match = matches;
1474
1266
  add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));
1475
1267
  }
1476
1268
  }
1477
-
1478
1269
  var toEnd = taken == fragment.childCount;
1479
1270
  if (!toEnd) openEndCount = -1;
1480
1271
  this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add));
1481
1272
  this.frontier[frontierDepth].match = match;
1482
1273
  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++) {
1274
+ for (var _i4 = 0, cur = fragment; _i4 < openEndCount; _i4++) {
1485
1275
  var node = cur.lastChild;
1486
1276
  this.frontier.push({
1487
1277
  type: node.type,
@@ -1489,7 +1279,6 @@ var Fitter = function () {
1489
1279
  });
1490
1280
  cur = node.content;
1491
1281
  }
1492
-
1493
1282
  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
1283
  }
1495
1284
  }, {
@@ -1497,15 +1286,11 @@ var Fitter = function () {
1497
1286
  value: function mustMoveInline() {
1498
1287
  if (!this.$to.parent.isTextblock) return -1;
1499
1288
  var top = this.frontier[this.depth],
1500
- level;
1289
+ level;
1501
1290
  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
1291
  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
-
1292
+ after = this.$to.after(depth);
1293
+ while (depth > 1 && after == this.$to.end(--depth)) ++after;
1509
1294
  return after;
1510
1295
  }
1511
1296
  }, {
@@ -1513,20 +1298,18 @@ var Fitter = function () {
1513
1298
  value: function findCloseLevel($to) {
1514
1299
  scan: for (var i = Math.min(this.depth, $to.depth); i >= 0; i--) {
1515
1300
  var _this$frontier$i = this.frontier[i],
1516
- match = _this$frontier$i.match,
1517
- type = _this$frontier$i.type;
1301
+ match = _this$frontier$i.match,
1302
+ type = _this$frontier$i.type;
1518
1303
  var dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));
1519
1304
  var fit = contentAfterFits($to, i, type, match, dropInner);
1520
1305
  if (!fit) continue;
1521
-
1522
1306
  for (var d = i - 1; d >= 0; d--) {
1523
1307
  var _this$frontier$d = this.frontier[d],
1524
- _match = _this$frontier$d.match,
1525
- _type = _this$frontier$d.type;
1308
+ _match = _this$frontier$d.match,
1309
+ _type = _this$frontier$d.type;
1526
1310
  var matches = contentAfterFits($to, d, _type, _match, true);
1527
1311
  if (!matches || matches.childCount) continue scan;
1528
1312
  }
1529
-
1530
1313
  return {
1531
1314
  depth: i,
1532
1315
  fit: fit,
@@ -1539,20 +1322,14 @@ var Fitter = function () {
1539
1322
  value: function close($to) {
1540
1323
  var close = this.findCloseLevel($to);
1541
1324
  if (!close) return null;
1542
-
1543
- while (this.depth > close.depth) {
1544
- this.closeFrontierNode();
1545
- }
1546
-
1325
+ while (this.depth > close.depth) this.closeFrontierNode();
1547
1326
  if (close.fit.childCount) this.placed = addToFragment(this.placed, close.depth, close.fit);
1548
1327
  $to = close.move;
1549
-
1550
1328
  for (var d = close.depth + 1; d <= $to.depth; d++) {
1551
1329
  var node = $to.node(d),
1552
- add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
1330
+ add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
1553
1331
  this.openFrontierNode(node.type, node.attrs, add);
1554
1332
  }
1555
-
1556
1333
  return $to;
1557
1334
  }
1558
1335
  }, {
@@ -1576,210 +1353,161 @@ var Fitter = function () {
1576
1353
  if (add.childCount) this.placed = addToFragment(this.placed, this.frontier.length, add);
1577
1354
  }
1578
1355
  }]);
1579
-
1580
1356
  return Fitter;
1581
1357
  }();
1582
-
1583
1358
  function dropFromFragment(fragment, depth, count) {
1584
1359
  if (depth == 0) return fragment.cutByIndex(count, fragment.childCount);
1585
1360
  return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));
1586
1361
  }
1587
-
1588
1362
  function addToFragment(fragment, depth, content) {
1589
1363
  if (depth == 0) return fragment.append(content);
1590
1364
  return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));
1591
1365
  }
1592
-
1593
1366
  function contentAt(fragment, depth) {
1594
- for (var i = 0; i < depth; i++) {
1595
- fragment = fragment.firstChild.content;
1596
- }
1597
-
1367
+ for (var i = 0; i < depth; i++) fragment = fragment.firstChild.content;
1598
1368
  return fragment;
1599
1369
  }
1600
-
1601
1370
  function closeNodeStart(node, openStart, openEnd) {
1602
1371
  if (openStart <= 0) return node;
1603
1372
  var frag = node.content;
1604
1373
  if (openStart > 1) frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));
1605
-
1606
1374
  if (openStart > 0) {
1607
1375
  frag = node.type.contentMatch.fillBefore(frag).append(frag);
1608
1376
  if (openEnd <= 0) frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(prosemirrorModel.Fragment.empty, true));
1609
1377
  }
1610
-
1611
1378
  return node.copy(frag);
1612
1379
  }
1613
-
1614
1380
  function contentAfterFits($to, depth, type, match, open) {
1615
1381
  var node = $to.node(depth),
1616
- index = open ? $to.indexAfter(depth) : $to.index(depth);
1382
+ index = open ? $to.indexAfter(depth) : $to.index(depth);
1617
1383
  if (index == node.childCount && !type.compatibleContent(node.type)) return null;
1618
1384
  var fit = match.fillBefore(node.content, true, index);
1619
1385
  return fit && !invalidMarks(type, node.content, index) ? fit : null;
1620
1386
  }
1621
-
1622
1387
  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
-
1388
+ for (var i = start; i < fragment.childCount; i++) if (!type.allowsMarks(fragment.child(i).marks)) return true;
1627
1389
  return false;
1628
1390
  }
1629
-
1630
1391
  function definesContent(type) {
1631
1392
  return type.spec.defining || type.spec.definingForContent;
1632
1393
  }
1633
-
1634
1394
  function _replaceRange(tr, from, to, slice) {
1635
1395
  if (!slice.size) return tr.deleteRange(from, to);
1636
1396
  var $from = tr.doc.resolve(from),
1637
- $to = tr.doc.resolve(to);
1397
+ $to = tr.doc.resolve(to);
1638
1398
  if (fitsTrivially($from, $to, slice)) return tr.step(new ReplaceStep(from, to, slice));
1639
1399
  var targetDepths = coveredDepths($from, tr.doc.resolve(to));
1640
1400
  if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop();
1641
1401
  var preferredTarget = -($from.depth + 1);
1642
1402
  targetDepths.unshift(preferredTarget);
1643
-
1644
1403
  for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
1645
1404
  var spec = $from.node(d).type.spec;
1646
1405
  if (spec.defining || spec.definingAsContext || spec.isolating) break;
1647
1406
  if (targetDepths.indexOf(d) > -1) preferredTarget = d;else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d);
1648
1407
  }
1649
-
1650
1408
  var preferredTargetIndex = targetDepths.indexOf(preferredTarget);
1651
1409
  var leftNodes = [],
1652
- preferredDepth = slice.openStart;
1653
-
1410
+ preferredDepth = slice.openStart;
1654
1411
  for (var content = slice.content, i = 0;; i++) {
1655
1412
  var node = content.firstChild;
1656
1413
  leftNodes.push(node);
1657
1414
  if (i == slice.openStart) break;
1658
1415
  content = node.content;
1659
1416
  }
1660
-
1661
1417
  for (var _d3 = preferredDepth - 1; _d3 >= 0; _d3--) {
1662
1418
  var leftNode = leftNodes[_d3],
1663
- def = definesContent(leftNode.type);
1419
+ def = definesContent(leftNode.type);
1664
1420
  if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = _d3;else if (def || !leftNode.type.isTextblock) break;
1665
1421
  }
1666
-
1667
1422
  for (var j = slice.openStart; j >= 0; j--) {
1668
1423
  var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);
1669
1424
  var insert = leftNodes[openDepth];
1670
1425
  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
-
1426
+ for (var _i5 = 0; _i5 < targetDepths.length; _i5++) {
1427
+ var targetDepth = targetDepths[(_i5 + preferredTargetIndex) % targetDepths.length],
1428
+ expand = true;
1676
1429
  if (targetDepth < 0) {
1677
1430
  expand = false;
1678
1431
  targetDepth = -targetDepth;
1679
1432
  }
1680
-
1681
1433
  var parent = $from.node(targetDepth - 1),
1682
- index = $from.index(targetDepth - 1);
1434
+ index = $from.index(targetDepth - 1);
1683
1435
  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
1436
  }
1685
1437
  }
1686
-
1687
1438
  var startSteps = tr.steps.length;
1688
-
1689
- for (var _i5 = targetDepths.length - 1; _i5 >= 0; _i5--) {
1439
+ for (var _i6 = targetDepths.length - 1; _i6 >= 0; _i6--) {
1690
1440
  tr.replace(from, to, slice);
1691
1441
  if (tr.steps.length > startSteps) break;
1692
- var depth = targetDepths[_i5];
1442
+ var depth = targetDepths[_i6];
1693
1443
  if (depth < 0) continue;
1694
1444
  from = $from.before(depth);
1695
1445
  to = $to.after(depth);
1696
1446
  }
1697
1447
  }
1698
-
1699
1448
  function closeFragment(fragment, depth, oldOpen, newOpen, parent) {
1700
1449
  if (depth < oldOpen) {
1701
1450
  var first = fragment.firstChild;
1702
1451
  fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));
1703
1452
  }
1704
-
1705
1453
  if (depth > newOpen) {
1706
1454
  var match = parent.contentMatchAt(0);
1707
1455
  var start = match.fillBefore(fragment).append(fragment);
1708
1456
  fragment = start.append(match.matchFragment(start).fillBefore(prosemirrorModel.Fragment.empty, true));
1709
1457
  }
1710
-
1711
1458
  return fragment;
1712
1459
  }
1713
-
1714
1460
  function _replaceRangeWith(tr, from, to, node) {
1715
1461
  if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {
1716
1462
  var point = insertPoint(tr.doc, from, node.type);
1717
1463
  if (point != null) from = to = point;
1718
1464
  }
1719
-
1720
1465
  tr.replaceRange(from, to, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(node), 0, 0));
1721
1466
  }
1722
-
1723
1467
  function _deleteRange(tr, from, to) {
1724
1468
  var $from = tr.doc.resolve(from),
1725
- $to = tr.doc.resolve(to);
1469
+ $to = tr.doc.resolve(to);
1726
1470
  var covered = coveredDepths($from, $to);
1727
-
1728
1471
  for (var i = 0; i < covered.length; i++) {
1729
1472
  var depth = covered[i],
1730
- last = i == covered.length - 1;
1473
+ last = i == covered.length - 1;
1731
1474
  if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) return tr["delete"]($from.start(depth), $to.end(depth));
1732
1475
  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
1476
  }
1734
-
1735
1477
  for (var d = 1; d <= $from.depth && d <= $to.depth; d++) {
1736
1478
  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
1479
  }
1738
-
1739
1480
  tr["delete"](from, to);
1740
1481
  }
1741
-
1742
1482
  function coveredDepths($from, $to) {
1743
1483
  var result = [],
1744
- minDepth = Math.min($from.depth, $to.depth);
1745
-
1484
+ minDepth = Math.min($from.depth, $to.depth);
1746
1485
  for (var d = minDepth; d >= 0; d--) {
1747
1486
  var start = $from.start(d);
1748
1487
  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
1488
  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
1489
  }
1751
-
1752
1490
  return result;
1753
1491
  }
1754
-
1755
1492
  var AttrStep = function (_Step7) {
1756
1493
  _inherits(AttrStep, _Step7);
1757
-
1758
1494
  var _super7 = _createSuper(AttrStep);
1759
-
1760
1495
  function AttrStep(pos, attr, value) {
1761
1496
  var _this9;
1762
-
1763
1497
  _classCallCheck(this, AttrStep);
1764
-
1765
1498
  _this9 = _super7.call(this);
1766
1499
  _this9.pos = pos;
1767
1500
  _this9.attr = attr;
1768
1501
  _this9.value = value;
1769
1502
  return _this9;
1770
1503
  }
1771
-
1772
1504
  _createClass(AttrStep, [{
1773
1505
  key: "apply",
1774
1506
  value: function apply(doc) {
1775
1507
  var node = doc.nodeAt(this.pos);
1776
1508
  if (!node) return StepResult.fail("No node at attribute step's position");
1777
1509
  var attrs = Object.create(null);
1778
-
1779
- for (var name in node.attrs) {
1780
- attrs[name] = node.attrs[name];
1781
- }
1782
-
1510
+ for (var name in node.attrs) attrs[name] = node.attrs[name];
1783
1511
  attrs[this.attr] = this.value;
1784
1512
  var updated = node.type.create(attrs, null, node.marks);
1785
1513
  return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
@@ -1817,37 +1545,25 @@ var AttrStep = function (_Step7) {
1817
1545
  return new AttrStep(json.pos, json.attr, json.value);
1818
1546
  }
1819
1547
  }]);
1820
-
1821
1548
  return AttrStep;
1822
1549
  }(Step);
1823
-
1824
1550
  Step.jsonID("attr", AttrStep);
1825
-
1826
1551
  var DocAttrStep = function (_Step8) {
1827
1552
  _inherits(DocAttrStep, _Step8);
1828
-
1829
1553
  var _super8 = _createSuper(DocAttrStep);
1830
-
1831
1554
  function DocAttrStep(attr, value) {
1832
1555
  var _this10;
1833
-
1834
1556
  _classCallCheck(this, DocAttrStep);
1835
-
1836
1557
  _this10 = _super8.call(this);
1837
1558
  _this10.attr = attr;
1838
1559
  _this10.value = value;
1839
1560
  return _this10;
1840
1561
  }
1841
-
1842
1562
  _createClass(DocAttrStep, [{
1843
1563
  key: "apply",
1844
1564
  value: function apply(doc) {
1845
1565
  var attrs = Object.create(null);
1846
-
1847
- for (var name in doc.attrs) {
1848
- attrs[name] = doc.attrs[name];
1849
- }
1850
-
1566
+ for (var name in doc.attrs) attrs[name] = doc.attrs[name];
1851
1567
  attrs[this.attr] = this.value;
1852
1568
  var updated = doc.type.create(attrs, doc.content, doc.marks);
1853
1569
  return StepResult.ok(updated);
@@ -1883,46 +1599,34 @@ var DocAttrStep = function (_Step8) {
1883
1599
  return new DocAttrStep(json.attr, json.value);
1884
1600
  }
1885
1601
  }]);
1886
-
1887
1602
  return DocAttrStep;
1888
1603
  }(Step);
1889
-
1890
1604
  Step.jsonID("docAttr", DocAttrStep);
1891
-
1892
1605
  exports.TransformError = function (_Error) {
1893
1606
  _inherits(TransformError, _Error);
1894
-
1895
1607
  var _super9 = _createSuper(TransformError);
1896
-
1897
1608
  function TransformError() {
1898
1609
  _classCallCheck(this, TransformError);
1899
-
1900
1610
  return _super9.apply(this, arguments);
1901
1611
  }
1902
-
1903
1612
  return _createClass(TransformError);
1904
1613
  }(_wrapNativeSuper(Error));
1905
-
1906
1614
  exports.TransformError = function TransformError(message) {
1907
1615
  var err = Error.call(this, message);
1908
1616
  err.__proto__ = TransformError.prototype;
1909
1617
  return err;
1910
1618
  };
1911
-
1912
1619
  exports.TransformError.prototype = Object.create(Error.prototype);
1913
1620
  exports.TransformError.prototype.constructor = exports.TransformError;
1914
1621
  exports.TransformError.prototype.name = "TransformError";
1915
-
1916
1622
  var Transform = function () {
1917
1623
  function Transform(doc) {
1918
1624
  _classCallCheck(this, Transform);
1919
-
1920
1625
  this.doc = doc;
1921
1626
  this.steps = [];
1922
1627
  this.docs = [];
1923
1628
  this.mapping = new Mapping();
1924
1629
  }
1925
-
1926
1630
  _createClass(Transform, [{
1927
1631
  key: "before",
1928
1632
  get: function get() {
@@ -1983,44 +1687,37 @@ var Transform = function () {
1983
1687
  key: "replaceRange",
1984
1688
  value: function replaceRange(from, to, slice) {
1985
1689
  _replaceRange(this, from, to, slice);
1986
-
1987
1690
  return this;
1988
1691
  }
1989
1692
  }, {
1990
1693
  key: "replaceRangeWith",
1991
1694
  value: function replaceRangeWith(from, to, node) {
1992
1695
  _replaceRangeWith(this, from, to, node);
1993
-
1994
1696
  return this;
1995
1697
  }
1996
1698
  }, {
1997
1699
  key: "deleteRange",
1998
1700
  value: function deleteRange(from, to) {
1999
1701
  _deleteRange(this, from, to);
2000
-
2001
1702
  return this;
2002
1703
  }
2003
1704
  }, {
2004
1705
  key: "lift",
2005
1706
  value: function lift(range, target) {
2006
1707
  _lift(this, range, target);
2007
-
2008
1708
  return this;
2009
1709
  }
2010
1710
  }, {
2011
1711
  key: "join",
2012
1712
  value: function join(pos) {
2013
1713
  var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
2014
-
2015
1714
  _join(this, pos, depth);
2016
-
2017
1715
  return this;
2018
1716
  }
2019
1717
  }, {
2020
1718
  key: "wrap",
2021
1719
  value: function wrap(range, wrappers) {
2022
1720
  _wrap2(this, range, wrappers);
2023
-
2024
1721
  return this;
2025
1722
  }
2026
1723
  }, {
@@ -2029,9 +1726,7 @@ var Transform = function () {
2029
1726
  var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : from;
2030
1727
  var type = arguments.length > 2 ? arguments[2] : undefined;
2031
1728
  var attrs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
2032
-
2033
1729
  _setBlockType(this, from, to, type, attrs);
2034
-
2035
1730
  return this;
2036
1731
  }
2037
1732
  }, {
@@ -2039,9 +1734,7 @@ var Transform = function () {
2039
1734
  value: function setNodeMarkup(pos, type) {
2040
1735
  var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2041
1736
  var marks = arguments.length > 3 ? arguments[3] : undefined;
2042
-
2043
1737
  _setNodeMarkup(this, pos, type, attrs, marks);
2044
-
2045
1738
  return this;
2046
1739
  }
2047
1740
  }, {
@@ -2071,7 +1764,6 @@ var Transform = function () {
2071
1764
  mark = mark.isInSet(node.marks);
2072
1765
  if (!mark) return this;
2073
1766
  }
2074
-
2075
1767
  this.step(new RemoveNodeMarkStep(pos, mark));
2076
1768
  return this;
2077
1769
  }
@@ -2080,37 +1772,30 @@ var Transform = function () {
2080
1772
  value: function split(pos) {
2081
1773
  var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
2082
1774
  var typesAfter = arguments.length > 2 ? arguments[2] : undefined;
2083
-
2084
1775
  _split(this, pos, depth, typesAfter);
2085
-
2086
1776
  return this;
2087
1777
  }
2088
1778
  }, {
2089
1779
  key: "addMark",
2090
1780
  value: function addMark(from, to, mark) {
2091
1781
  _addMark(this, from, to, mark);
2092
-
2093
1782
  return this;
2094
1783
  }
2095
1784
  }, {
2096
1785
  key: "removeMark",
2097
1786
  value: function removeMark(from, to, mark) {
2098
1787
  _removeMark(this, from, to, mark);
2099
-
2100
1788
  return this;
2101
1789
  }
2102
1790
  }, {
2103
1791
  key: "clearIncompatible",
2104
1792
  value: function clearIncompatible(pos, parentType, match) {
2105
1793
  _clearIncompatible(this, pos, parentType, match);
2106
-
2107
1794
  return this;
2108
1795
  }
2109
1796
  }]);
2110
-
2111
1797
  return Transform;
2112
1798
  }();
2113
-
2114
1799
  exports.AddMarkStep = AddMarkStep;
2115
1800
  exports.AddNodeMarkStep = AddNodeMarkStep;
2116
1801
  exports.AttrStep = AttrStep;