slate 0.115.1 → 0.116.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.es.js +407 -346
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +421 -408
- package/dist/index.js.map +1 -1
- package/dist/interfaces/point.d.ts.map +1 -1
- package/dist/interfaces/range.d.ts.map +1 -1
- package/dist/interfaces/transforms/general.d.ts.map +1 -1
- package/dist/slate.js +1648 -1635
- package/dist/slate.min.js +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { produce } from 'immer';
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line no-redeclare
|
|
4
4
|
var PathRef = {
|
|
@@ -372,280 +372,337 @@ function _defineProperty(obj, key, value) {
|
|
|
372
372
|
|
|
373
373
|
function ownKeys$e(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
374
374
|
function _objectSpread$e(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$e(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
375
|
+
var insertChildren = function insertChildren(xs, index) {
|
|
376
|
+
for (var _len = arguments.length, newValues = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
377
|
+
newValues[_key - 2] = arguments[_key];
|
|
378
|
+
}
|
|
379
|
+
return [...xs.slice(0, index), ...newValues, ...xs.slice(index)];
|
|
380
|
+
};
|
|
381
|
+
var replaceChildren = function replaceChildren(xs, index, removeCount) {
|
|
382
|
+
for (var _len2 = arguments.length, newValues = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
383
|
+
newValues[_key2 - 3] = arguments[_key2];
|
|
384
|
+
}
|
|
385
|
+
return [...xs.slice(0, index), ...newValues, ...xs.slice(index + removeCount)];
|
|
386
|
+
};
|
|
387
|
+
var removeChildren = replaceChildren;
|
|
388
|
+
/**
|
|
389
|
+
* Replace a descendant with a new node, replacing all ancestors
|
|
390
|
+
*/
|
|
391
|
+
var modifyDescendant = (editor, path, f) => {
|
|
392
|
+
if (path.length === 0) {
|
|
393
|
+
throw new Error('Cannot modify the editor');
|
|
394
|
+
}
|
|
395
|
+
var node = Node.get(editor, path);
|
|
396
|
+
var slicedPath = path.slice();
|
|
397
|
+
var modifiedNode = f(node);
|
|
398
|
+
while (slicedPath.length > 1) {
|
|
399
|
+
var _index = slicedPath.pop();
|
|
400
|
+
var ancestorNode = Node.get(editor, slicedPath);
|
|
401
|
+
modifiedNode = _objectSpread$e(_objectSpread$e({}, ancestorNode), {}, {
|
|
402
|
+
children: replaceChildren(ancestorNode.children, _index, 1, modifiedNode)
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
var index = slicedPath.pop();
|
|
406
|
+
editor.children = replaceChildren(editor.children, index, 1, modifiedNode);
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* Replace the children of a node, replacing all ancestors
|
|
410
|
+
*/
|
|
411
|
+
var modifyChildren = (editor, path, f) => {
|
|
412
|
+
if (path.length === 0) {
|
|
413
|
+
editor.children = f(editor.children);
|
|
414
|
+
} else {
|
|
415
|
+
modifyDescendant(editor, path, node => {
|
|
416
|
+
if (Text.isText(node)) {
|
|
417
|
+
throw new Error("Cannot get the element at path [".concat(path, "] because it refers to a leaf node: ").concat(Scrubber.stringify(node)));
|
|
414
418
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
419
|
+
return _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
420
|
+
children: f(node.children)
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Replace a leaf, replacing all ancestors
|
|
427
|
+
*/
|
|
428
|
+
var modifyLeaf = (editor, path, f) => modifyDescendant(editor, path, node => {
|
|
429
|
+
if (!Text.isText(node)) {
|
|
430
|
+
throw new Error("Cannot get the leaf node at path [".concat(path, "] because it refers to a non-leaf node: ").concat(Scrubber.stringify(node)));
|
|
431
|
+
}
|
|
432
|
+
return f(node);
|
|
433
|
+
});
|
|
434
|
+
// eslint-disable-next-line no-redeclare
|
|
435
|
+
var GeneralTransforms = {
|
|
436
|
+
transform(editor, op) {
|
|
437
|
+
var transformSelection = false;
|
|
438
|
+
switch (op.type) {
|
|
439
|
+
case 'insert_node':
|
|
440
|
+
{
|
|
441
|
+
var {
|
|
442
|
+
path,
|
|
443
|
+
node
|
|
444
|
+
} = op;
|
|
445
|
+
modifyChildren(editor, Path.parent(path), children => {
|
|
446
|
+
var index = path[path.length - 1];
|
|
447
|
+
if (index > children.length) {
|
|
448
|
+
throw new Error("Cannot apply an \"insert_node\" operation at path [".concat(path, "] because the destination is past the end of the node."));
|
|
449
|
+
}
|
|
450
|
+
return insertChildren(children, index, node);
|
|
451
|
+
});
|
|
452
|
+
transformSelection = true;
|
|
453
|
+
break;
|
|
431
454
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
455
|
+
case 'insert_text':
|
|
456
|
+
{
|
|
457
|
+
var {
|
|
458
|
+
path: _path,
|
|
459
|
+
offset,
|
|
460
|
+
text
|
|
461
|
+
} = op;
|
|
462
|
+
if (text.length === 0) break;
|
|
463
|
+
modifyLeaf(editor, _path, node => {
|
|
464
|
+
var before = node.text.slice(0, offset);
|
|
465
|
+
var after = node.text.slice(offset);
|
|
466
|
+
return _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
467
|
+
text: before + text + after
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
transformSelection = true;
|
|
471
|
+
break;
|
|
437
472
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
473
|
+
case 'merge_node':
|
|
474
|
+
{
|
|
475
|
+
var {
|
|
476
|
+
path: _path2
|
|
477
|
+
} = op;
|
|
478
|
+
var index = _path2[_path2.length - 1];
|
|
479
|
+
var prevPath = Path.previous(_path2);
|
|
480
|
+
var prevIndex = prevPath[prevPath.length - 1];
|
|
481
|
+
modifyChildren(editor, Path.parent(_path2), children => {
|
|
482
|
+
var node = children[index];
|
|
483
|
+
var prev = children[prevIndex];
|
|
484
|
+
var newNode;
|
|
485
|
+
if (Text.isText(node) && Text.isText(prev)) {
|
|
486
|
+
newNode = _objectSpread$e(_objectSpread$e({}, prev), {}, {
|
|
487
|
+
text: prev.text + node.text
|
|
488
|
+
});
|
|
489
|
+
} else if (!Text.isText(node) && !Text.isText(prev)) {
|
|
490
|
+
newNode = _objectSpread$e(_objectSpread$e({}, prev), {}, {
|
|
491
|
+
children: prev.children.concat(node.children)
|
|
492
|
+
});
|
|
493
|
+
} else {
|
|
494
|
+
throw new Error("Cannot apply a \"merge_node\" operation at path [".concat(_path2, "] to nodes of different interfaces: ").concat(Scrubber.stringify(node), " ").concat(Scrubber.stringify(prev)));
|
|
495
|
+
}
|
|
496
|
+
return replaceChildren(children, prevIndex, 2, newNode);
|
|
497
|
+
});
|
|
498
|
+
transformSelection = true;
|
|
499
|
+
break;
|
|
448
500
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
_parent2.children.splice(_index2, 1);
|
|
459
|
-
var truePath = Path.transform(_path3, op);
|
|
460
|
-
var newParent = Node.get(editor, Path.parent(truePath));
|
|
461
|
-
var newIndex = truePath[truePath.length - 1];
|
|
462
|
-
newParent.children.splice(newIndex, 0, _node3);
|
|
463
|
-
if (selection) {
|
|
464
|
-
for (var [_point3, _key3] of Range.points(selection)) {
|
|
465
|
-
selection[_key3] = Point.transform(_point3, op);
|
|
501
|
+
case 'move_node':
|
|
502
|
+
{
|
|
503
|
+
var {
|
|
504
|
+
path: _path3,
|
|
505
|
+
newPath
|
|
506
|
+
} = op;
|
|
507
|
+
var _index2 = _path3[_path3.length - 1];
|
|
508
|
+
if (Path.isAncestor(_path3, newPath)) {
|
|
509
|
+
throw new Error("Cannot move a path [".concat(_path3, "] to new path [").concat(newPath, "] because the destination is inside itself."));
|
|
466
510
|
}
|
|
511
|
+
var _node = Node.get(editor, _path3);
|
|
512
|
+
modifyChildren(editor, Path.parent(_path3), children => removeChildren(children, _index2, 1));
|
|
513
|
+
// This is tricky, but since the `path` and `newPath` both refer to
|
|
514
|
+
// the same snapshot in time, there's a mismatch. After either
|
|
515
|
+
// removing the original position, the second step's path can be out
|
|
516
|
+
// of date. So instead of using the `op.newPath` directly, we
|
|
517
|
+
// transform `op.path` to ascertain what the `newPath` would be after
|
|
518
|
+
// the operation was applied.
|
|
519
|
+
var truePath = Path.transform(_path3, op);
|
|
520
|
+
var newIndex = truePath[truePath.length - 1];
|
|
521
|
+
modifyChildren(editor, Path.parent(truePath), children => insertChildren(children, newIndex, _node));
|
|
522
|
+
transformSelection = true;
|
|
523
|
+
break;
|
|
467
524
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
break;
|
|
525
|
+
case 'remove_node':
|
|
526
|
+
{
|
|
527
|
+
var {
|
|
528
|
+
path: _path4
|
|
529
|
+
} = op;
|
|
530
|
+
var _index3 = _path4[_path4.length - 1];
|
|
531
|
+
modifyChildren(editor, Path.parent(_path4), children => removeChildren(children, _index3, 1));
|
|
532
|
+
// Transform all the points in the value, but if the point was in the
|
|
533
|
+
// node that was removed we need to update the range or remove it.
|
|
534
|
+
if (editor.selection) {
|
|
535
|
+
var selection = _objectSpread$e({}, editor.selection);
|
|
536
|
+
for (var [point, key] of Range.points(selection)) {
|
|
537
|
+
var result = Point.transform(point, op);
|
|
538
|
+
if (selection != null && result != null) {
|
|
539
|
+
selection[key] = result;
|
|
540
|
+
} else {
|
|
541
|
+
var prev = void 0;
|
|
542
|
+
var next = void 0;
|
|
543
|
+
for (var [n, p] of Node.texts(editor)) {
|
|
544
|
+
if (Path.compare(p, _path4) === -1) {
|
|
545
|
+
prev = [n, p];
|
|
546
|
+
} else {
|
|
547
|
+
next = [n, p];
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
494
550
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
551
|
+
var preferNext = false;
|
|
552
|
+
if (prev && next) {
|
|
553
|
+
if (Path.equals(next[1], _path4)) {
|
|
554
|
+
preferNext = !Path.hasPrevious(next[1]);
|
|
555
|
+
} else {
|
|
556
|
+
preferNext = Path.common(prev[1], _path4).length < Path.common(next[1], _path4).length;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (prev && !preferNext) {
|
|
560
|
+
selection[key] = {
|
|
561
|
+
path: prev[1],
|
|
562
|
+
offset: prev[0].text.length
|
|
563
|
+
};
|
|
564
|
+
} else if (next) {
|
|
565
|
+
selection[key] = {
|
|
566
|
+
path: next[1],
|
|
567
|
+
offset: 0
|
|
568
|
+
};
|
|
500
569
|
} else {
|
|
501
|
-
|
|
570
|
+
selection = null;
|
|
502
571
|
}
|
|
503
572
|
}
|
|
504
|
-
if (_prev && !preferNext) {
|
|
505
|
-
_point4.path = _prev[1];
|
|
506
|
-
_point4.offset = _prev[0].text.length;
|
|
507
|
-
} else if (next) {
|
|
508
|
-
_point4.path = next[1];
|
|
509
|
-
_point4.offset = 0;
|
|
510
|
-
} else {
|
|
511
|
-
selection = null;
|
|
512
|
-
}
|
|
513
573
|
}
|
|
574
|
+
editor.selection = selection;
|
|
514
575
|
}
|
|
576
|
+
break;
|
|
515
577
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
case 'set_node':
|
|
538
|
-
{
|
|
539
|
-
var {
|
|
540
|
-
path: _path6,
|
|
541
|
-
properties,
|
|
542
|
-
newProperties
|
|
543
|
-
} = op;
|
|
544
|
-
if (_path6.length === 0) {
|
|
545
|
-
throw new Error("Cannot set properties on the root node!");
|
|
578
|
+
case 'remove_text':
|
|
579
|
+
{
|
|
580
|
+
var {
|
|
581
|
+
path: _path5,
|
|
582
|
+
offset: _offset,
|
|
583
|
+
text: _text
|
|
584
|
+
} = op;
|
|
585
|
+
if (_text.length === 0) break;
|
|
586
|
+
modifyLeaf(editor, _path5, node => {
|
|
587
|
+
var before = node.text.slice(0, _offset);
|
|
588
|
+
var after = node.text.slice(_offset + _text.length);
|
|
589
|
+
return _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
590
|
+
text: before + after
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
transformSelection = true;
|
|
594
|
+
break;
|
|
546
595
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
_node5[_key6] = value;
|
|
596
|
+
case 'set_node':
|
|
597
|
+
{
|
|
598
|
+
var {
|
|
599
|
+
path: _path6,
|
|
600
|
+
properties,
|
|
601
|
+
newProperties
|
|
602
|
+
} = op;
|
|
603
|
+
if (_path6.length === 0) {
|
|
604
|
+
throw new Error("Cannot set properties on the root node!");
|
|
557
605
|
}
|
|
606
|
+
modifyDescendant(editor, _path6, node => {
|
|
607
|
+
var newNode = _objectSpread$e({}, node);
|
|
608
|
+
for (var _key3 in newProperties) {
|
|
609
|
+
if (_key3 === 'children' || _key3 === 'text') {
|
|
610
|
+
throw new Error("Cannot set the \"".concat(_key3, "\" property of nodes!"));
|
|
611
|
+
}
|
|
612
|
+
var value = newProperties[_key3];
|
|
613
|
+
if (value == null) {
|
|
614
|
+
delete newNode[_key3];
|
|
615
|
+
} else {
|
|
616
|
+
newNode[_key3] = value;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
// properties that were previously defined, but are now missing, must be deleted
|
|
620
|
+
for (var _key4 in properties) {
|
|
621
|
+
if (!newProperties.hasOwnProperty(_key4)) {
|
|
622
|
+
delete newNode[_key4];
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return newNode;
|
|
626
|
+
});
|
|
627
|
+
break;
|
|
558
628
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
629
|
+
case 'set_selection':
|
|
630
|
+
{
|
|
631
|
+
var {
|
|
632
|
+
newProperties: _newProperties
|
|
633
|
+
} = op;
|
|
634
|
+
if (_newProperties == null) {
|
|
635
|
+
editor.selection = null;
|
|
636
|
+
break;
|
|
563
637
|
}
|
|
564
|
-
|
|
565
|
-
break;
|
|
566
|
-
}
|
|
567
|
-
case 'set_selection':
|
|
568
|
-
{
|
|
569
|
-
var {
|
|
570
|
-
newProperties: _newProperties
|
|
571
|
-
} = op;
|
|
572
|
-
if (_newProperties == null) {
|
|
573
|
-
selection = _newProperties;
|
|
574
|
-
} else {
|
|
575
|
-
if (selection == null) {
|
|
638
|
+
if (editor.selection == null) {
|
|
576
639
|
if (!Range.isRange(_newProperties)) {
|
|
577
640
|
throw new Error("Cannot apply an incomplete \"set_selection\" operation properties ".concat(Scrubber.stringify(_newProperties), " when there is no current selection."));
|
|
578
641
|
}
|
|
579
|
-
selection = _objectSpread$e({}, _newProperties);
|
|
642
|
+
editor.selection = _objectSpread$e({}, _newProperties);
|
|
643
|
+
break;
|
|
580
644
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
645
|
+
var _selection = _objectSpread$e({}, editor.selection);
|
|
646
|
+
for (var _key5 in _newProperties) {
|
|
647
|
+
var value = _newProperties[_key5];
|
|
648
|
+
if (value == null) {
|
|
649
|
+
if (_key5 === 'anchor' || _key5 === 'focus') {
|
|
650
|
+
throw new Error("Cannot remove the \"".concat(_key5, "\" selection property"));
|
|
586
651
|
}
|
|
587
|
-
delete
|
|
652
|
+
delete _selection[_key5];
|
|
588
653
|
} else {
|
|
589
|
-
|
|
654
|
+
_selection[_key5] = value;
|
|
590
655
|
}
|
|
591
656
|
}
|
|
657
|
+
editor.selection = _selection;
|
|
658
|
+
break;
|
|
592
659
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
|
|
604
|
-
}
|
|
605
|
-
var _node6 = Node.get(editor, _path7);
|
|
606
|
-
var _parent4 = Node.parent(editor, _path7);
|
|
607
|
-
var _index4 = _path7[_path7.length - 1];
|
|
608
|
-
var newNode;
|
|
609
|
-
if (Text.isText(_node6)) {
|
|
610
|
-
var _before2 = _node6.text.slice(0, position);
|
|
611
|
-
var _after2 = _node6.text.slice(position);
|
|
612
|
-
_node6.text = _before2;
|
|
613
|
-
newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
614
|
-
text: _after2
|
|
615
|
-
});
|
|
616
|
-
} else {
|
|
617
|
-
var _before3 = _node6.children.slice(0, position);
|
|
618
|
-
var _after3 = _node6.children.slice(position);
|
|
619
|
-
_node6.children = _before3;
|
|
620
|
-
newNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
621
|
-
children: _after3
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
_parent4.children.splice(_index4 + 1, 0, newNode);
|
|
625
|
-
if (selection) {
|
|
626
|
-
for (var [_point6, _key9] of Range.points(selection)) {
|
|
627
|
-
selection[_key9] = Point.transform(_point6, op);
|
|
660
|
+
case 'split_node':
|
|
661
|
+
{
|
|
662
|
+
var {
|
|
663
|
+
path: _path7,
|
|
664
|
+
position,
|
|
665
|
+
properties: _properties
|
|
666
|
+
} = op;
|
|
667
|
+
var _index4 = _path7[_path7.length - 1];
|
|
668
|
+
if (_path7.length === 0) {
|
|
669
|
+
throw new Error("Cannot apply a \"split_node\" operation at path [".concat(_path7, "] because the root node cannot be split."));
|
|
628
670
|
}
|
|
671
|
+
modifyChildren(editor, Path.parent(_path7), children => {
|
|
672
|
+
var node = children[_index4];
|
|
673
|
+
var newNode;
|
|
674
|
+
var nextNode;
|
|
675
|
+
if (Text.isText(node)) {
|
|
676
|
+
var before = node.text.slice(0, position);
|
|
677
|
+
var after = node.text.slice(position);
|
|
678
|
+
newNode = _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
679
|
+
text: before
|
|
680
|
+
});
|
|
681
|
+
nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
682
|
+
text: after
|
|
683
|
+
});
|
|
684
|
+
} else {
|
|
685
|
+
var _before = node.children.slice(0, position);
|
|
686
|
+
var _after = node.children.slice(position);
|
|
687
|
+
newNode = _objectSpread$e(_objectSpread$e({}, node), {}, {
|
|
688
|
+
children: _before
|
|
689
|
+
});
|
|
690
|
+
nextNode = _objectSpread$e(_objectSpread$e({}, _properties), {}, {
|
|
691
|
+
children: _after
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
return replaceChildren(children, _index4, 1, newNode, nextNode);
|
|
695
|
+
});
|
|
696
|
+
transformSelection = true;
|
|
697
|
+
break;
|
|
629
698
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
// eslint-disable-next-line no-redeclare
|
|
636
|
-
var GeneralTransforms = {
|
|
637
|
-
transform(editor, op) {
|
|
638
|
-
editor.children = createDraft(editor.children);
|
|
639
|
-
var selection = editor.selection && createDraft(editor.selection);
|
|
640
|
-
try {
|
|
641
|
-
selection = applyToDraft(editor, selection, op);
|
|
642
|
-
} finally {
|
|
643
|
-
editor.children = finishDraft(editor.children);
|
|
644
|
-
if (selection) {
|
|
645
|
-
editor.selection = isDraft(selection) ? finishDraft(selection) : selection;
|
|
646
|
-
} else {
|
|
647
|
-
editor.selection = null;
|
|
699
|
+
}
|
|
700
|
+
if (transformSelection && editor.selection) {
|
|
701
|
+
var _selection2 = _objectSpread$e({}, editor.selection);
|
|
702
|
+
for (var [_point, _key6] of Range.points(_selection2)) {
|
|
703
|
+
_selection2[_key6] = Point.transform(_point, op);
|
|
648
704
|
}
|
|
705
|
+
editor.selection = _selection2;
|
|
649
706
|
}
|
|
650
707
|
}
|
|
651
708
|
};
|
|
@@ -874,51 +931,51 @@ var Range = {
|
|
|
874
931
|
},
|
|
875
932
|
transform(range, op) {
|
|
876
933
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
affinityFocus = isCollapsed ? affinityAnchor : 'backward';
|
|
894
|
-
} else {
|
|
895
|
-
affinityAnchor = 'backward';
|
|
896
|
-
affinityFocus = isCollapsed ? affinityAnchor : 'forward';
|
|
897
|
-
}
|
|
898
|
-
} else if (affinity === 'outward') {
|
|
899
|
-
if (Range.isForward(r)) {
|
|
900
|
-
affinityAnchor = 'backward';
|
|
901
|
-
affinityFocus = 'forward';
|
|
902
|
-
} else {
|
|
903
|
-
affinityAnchor = 'forward';
|
|
904
|
-
affinityFocus = 'backward';
|
|
905
|
-
}
|
|
934
|
+
if (range === null) {
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
var {
|
|
938
|
+
affinity = 'inward'
|
|
939
|
+
} = options;
|
|
940
|
+
var affinityAnchor;
|
|
941
|
+
var affinityFocus;
|
|
942
|
+
if (affinity === 'inward') {
|
|
943
|
+
// If the range is collapsed, make sure to use the same affinity to
|
|
944
|
+
// avoid the two points passing each other and expanding in the opposite
|
|
945
|
+
// direction
|
|
946
|
+
var isCollapsed = Range.isCollapsed(range);
|
|
947
|
+
if (Range.isForward(range)) {
|
|
948
|
+
affinityAnchor = 'forward';
|
|
949
|
+
affinityFocus = isCollapsed ? affinityAnchor : 'backward';
|
|
906
950
|
} else {
|
|
907
|
-
affinityAnchor =
|
|
908
|
-
affinityFocus =
|
|
951
|
+
affinityAnchor = 'backward';
|
|
952
|
+
affinityFocus = isCollapsed ? affinityAnchor : 'forward';
|
|
909
953
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
return null;
|
|
954
|
+
} else if (affinity === 'outward') {
|
|
955
|
+
if (Range.isForward(range)) {
|
|
956
|
+
affinityAnchor = 'backward';
|
|
957
|
+
affinityFocus = 'forward';
|
|
958
|
+
} else {
|
|
959
|
+
affinityAnchor = 'forward';
|
|
960
|
+
affinityFocus = 'backward';
|
|
918
961
|
}
|
|
919
|
-
|
|
920
|
-
|
|
962
|
+
} else {
|
|
963
|
+
affinityAnchor = affinity;
|
|
964
|
+
affinityFocus = affinity;
|
|
965
|
+
}
|
|
966
|
+
var anchor = Point.transform(range.anchor, op, {
|
|
967
|
+
affinity: affinityAnchor
|
|
968
|
+
});
|
|
969
|
+
var focus = Point.transform(range.focus, op, {
|
|
970
|
+
affinity: affinityFocus
|
|
921
971
|
});
|
|
972
|
+
if (!anchor || !focus) {
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
975
|
+
return {
|
|
976
|
+
anchor,
|
|
977
|
+
focus
|
|
978
|
+
};
|
|
922
979
|
}
|
|
923
980
|
};
|
|
924
981
|
|
|
@@ -1680,72 +1737,76 @@ var Point = {
|
|
|
1680
1737
|
},
|
|
1681
1738
|
transform(point, op) {
|
|
1682
1739
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1740
|
+
if (point === null) {
|
|
1741
|
+
return null;
|
|
1742
|
+
}
|
|
1743
|
+
var {
|
|
1744
|
+
affinity = 'forward'
|
|
1745
|
+
} = options;
|
|
1746
|
+
var {
|
|
1747
|
+
path,
|
|
1748
|
+
offset
|
|
1749
|
+
} = point;
|
|
1750
|
+
switch (op.type) {
|
|
1751
|
+
case 'insert_node':
|
|
1752
|
+
case 'move_node':
|
|
1753
|
+
{
|
|
1754
|
+
path = Path.transform(path, op, options);
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
case 'insert_text':
|
|
1758
|
+
{
|
|
1759
|
+
if (Path.equals(op.path, path) && (op.offset < offset || op.offset === offset && affinity === 'forward')) {
|
|
1760
|
+
offset += op.text.length;
|
|
1700
1761
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1762
|
+
break;
|
|
1763
|
+
}
|
|
1764
|
+
case 'merge_node':
|
|
1765
|
+
{
|
|
1766
|
+
if (Path.equals(op.path, path)) {
|
|
1767
|
+
offset += op.position;
|
|
1707
1768
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1769
|
+
path = Path.transform(path, op, options);
|
|
1770
|
+
break;
|
|
1771
|
+
}
|
|
1772
|
+
case 'remove_text':
|
|
1773
|
+
{
|
|
1774
|
+
if (Path.equals(op.path, path) && op.offset <= offset) {
|
|
1775
|
+
offset -= Math.min(offset - op.offset, op.text.length);
|
|
1715
1776
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
case 'remove_node':
|
|
1780
|
+
{
|
|
1781
|
+
if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) {
|
|
1782
|
+
return null;
|
|
1722
1783
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1784
|
+
path = Path.transform(path, op, options);
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
case 'split_node':
|
|
1788
|
+
{
|
|
1789
|
+
if (Path.equals(op.path, path)) {
|
|
1790
|
+
if (op.position === offset && affinity == null) {
|
|
1726
1791
|
return null;
|
|
1792
|
+
} else if (op.position < offset || op.position === offset && affinity === 'forward') {
|
|
1793
|
+
offset -= op.position;
|
|
1794
|
+
path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
|
|
1795
|
+
affinity: 'forward'
|
|
1796
|
+
}));
|
|
1727
1797
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
case 'split_node':
|
|
1732
|
-
{
|
|
1733
|
-
if (Path.equals(op.path, path)) {
|
|
1734
|
-
if (op.position === offset && affinity == null) {
|
|
1735
|
-
return null;
|
|
1736
|
-
} else if (op.position < offset || op.position === offset && affinity === 'forward') {
|
|
1737
|
-
p.offset -= op.position;
|
|
1738
|
-
p.path = Path.transform(path, op, _objectSpread$b(_objectSpread$b({}, options), {}, {
|
|
1739
|
-
affinity: 'forward'
|
|
1740
|
-
}));
|
|
1741
|
-
}
|
|
1742
|
-
} else {
|
|
1743
|
-
p.path = Path.transform(path, op, options);
|
|
1744
|
-
}
|
|
1745
|
-
break;
|
|
1798
|
+
} else {
|
|
1799
|
+
path = Path.transform(path, op, options);
|
|
1746
1800
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
default:
|
|
1804
|
+
return point;
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
path,
|
|
1808
|
+
offset
|
|
1809
|
+
};
|
|
1749
1810
|
}
|
|
1750
1811
|
};
|
|
1751
1812
|
|