prosemirror-transform 1.5.0-beta.1 → 1.7.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/CHANGELOG.md +24 -0
- package/dist/index.cjs +301 -42
- package/dist/index.d.ts +123 -4
- package/dist/index.js +229 -15
- package/package.json +1 -1
- package/src/README.md +3 -0
- package/src/attr_step.ts +53 -0
- package/src/index.ts +2 -1
- package/src/map.ts +28 -9
- package/src/mark_step.ts +96 -0
- package/src/replace_step.ts +2 -2
- package/src/transform.ts +27 -0
- package/dist/index.es.js +0 -1702
- package/dist/index.es.js.map +0 -1
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 1.7.0 (2022-08-16)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The new `AttrStep` (and `Transform.setNodeAttribute`) can be used to set individual attributes on a node.
|
|
6
|
+
|
|
7
|
+
`AddNodeMarkStep` and `RemoveNodeMarkStep` can now be used to add and remove marks on individual nodes. `Transform.addNodeMark`/`removeNodeMark` provide an interface to these in transform objects.
|
|
8
|
+
|
|
9
|
+
## 1.6.0 (2022-06-01)
|
|
10
|
+
|
|
11
|
+
### Bug fixes
|
|
12
|
+
|
|
13
|
+
Allow replace steps to be mapped through changes that delete content next to their start and end points, as long as no delete spans across those points.
|
|
14
|
+
|
|
15
|
+
### New features
|
|
16
|
+
|
|
17
|
+
`MapResult` objects now provide information about whether the tokens before, after, and around the position were deleted.
|
|
18
|
+
|
|
19
|
+
## 1.5.0 (2022-05-30)
|
|
20
|
+
|
|
21
|
+
### New features
|
|
22
|
+
|
|
23
|
+
Include TypeScript type declarations.
|
|
24
|
+
|
|
1
25
|
## 1.4.2 (2022-04-05)
|
|
2
26
|
|
|
3
27
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -22,12 +22,12 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
22
22
|
|
|
23
23
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
24
|
|
|
25
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
26
|
+
|
|
25
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); } }
|
|
26
28
|
|
|
27
29
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
28
30
|
|
|
29
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
30
|
-
|
|
31
31
|
Object.defineProperty(exports, '__esModule', {
|
|
32
32
|
value: true
|
|
33
33
|
});
|
|
@@ -49,16 +49,44 @@ function recoverOffset(value) {
|
|
|
49
49
|
return (value - (value & lower16)) / factor16;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
var DEL_BEFORE = 1,
|
|
53
|
+
DEL_AFTER = 2,
|
|
54
|
+
DEL_ACROSS = 4,
|
|
55
|
+
DEL_SIDE = 8;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
var MapResult = function () {
|
|
58
|
+
function MapResult(pos, delInfo, recover) {
|
|
59
|
+
_classCallCheck(this, MapResult);
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
61
|
+
this.pos = pos;
|
|
62
|
+
this.delInfo = delInfo;
|
|
63
|
+
this.recover = recover;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_createClass(MapResult, [{
|
|
67
|
+
key: "deleted",
|
|
68
|
+
get: function get() {
|
|
69
|
+
return (this.delInfo & DEL_SIDE) > 0;
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "deletedBefore",
|
|
73
|
+
get: function get() {
|
|
74
|
+
return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: "deletedAfter",
|
|
78
|
+
get: function get() {
|
|
79
|
+
return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "deletedAcross",
|
|
83
|
+
get: function get() {
|
|
84
|
+
return (this.delInfo & DEL_ACROSS) > 0;
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
|
|
88
|
+
return MapResult;
|
|
89
|
+
}();
|
|
62
90
|
|
|
63
91
|
var StepMap = function () {
|
|
64
92
|
function StepMap(ranges) {
|
|
@@ -112,13 +140,15 @@ var StepMap = function () {
|
|
|
112
140
|
var result = start + diff + (side < 0 ? 0 : newSize);
|
|
113
141
|
if (simple) return result;
|
|
114
142
|
var recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
115
|
-
|
|
143
|
+
var del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
|
|
144
|
+
if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE;
|
|
145
|
+
return new MapResult(result, del, recover);
|
|
116
146
|
}
|
|
117
147
|
|
|
118
148
|
diff += newSize - oldSize;
|
|
119
149
|
}
|
|
120
150
|
|
|
121
|
-
return simple ? pos + diff : new MapResult(pos + diff);
|
|
151
|
+
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
122
152
|
}
|
|
123
153
|
}, {
|
|
124
154
|
key: "touches",
|
|
@@ -267,7 +297,7 @@ var Mapping = function () {
|
|
|
267
297
|
}, {
|
|
268
298
|
key: "_map",
|
|
269
299
|
value: function _map(pos, assoc, simple) {
|
|
270
|
-
var
|
|
300
|
+
var delInfo = 0;
|
|
271
301
|
|
|
272
302
|
for (var i = this.from; i < this.to; i++) {
|
|
273
303
|
var map = this.maps[i],
|
|
@@ -283,11 +313,11 @@ var Mapping = function () {
|
|
|
283
313
|
}
|
|
284
314
|
}
|
|
285
315
|
|
|
286
|
-
|
|
316
|
+
delInfo |= result.delInfo;
|
|
287
317
|
pos = result.pos;
|
|
288
318
|
}
|
|
289
319
|
|
|
290
|
-
return simple ? pos : new MapResult(pos,
|
|
320
|
+
return simple ? pos : new MapResult(pos, delInfo, null);
|
|
291
321
|
}
|
|
292
322
|
}]);
|
|
293
323
|
|
|
@@ -521,24 +551,154 @@ var RemoveMarkStep = function (_Step2) {
|
|
|
521
551
|
|
|
522
552
|
Step.jsonID("removeMark", RemoveMarkStep);
|
|
523
553
|
|
|
524
|
-
var
|
|
525
|
-
_inherits(
|
|
554
|
+
var AddNodeMarkStep = function (_Step3) {
|
|
555
|
+
_inherits(AddNodeMarkStep, _Step3);
|
|
526
556
|
|
|
527
|
-
var _super3 = _createSuper(
|
|
557
|
+
var _super3 = _createSuper(AddNodeMarkStep);
|
|
528
558
|
|
|
529
|
-
function
|
|
559
|
+
function AddNodeMarkStep(pos, mark) {
|
|
530
560
|
var _this5;
|
|
531
561
|
|
|
562
|
+
_classCallCheck(this, AddNodeMarkStep);
|
|
563
|
+
|
|
564
|
+
_this5 = _super3.call(this);
|
|
565
|
+
_this5.pos = pos;
|
|
566
|
+
_this5.mark = mark;
|
|
567
|
+
return _this5;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
_createClass(AddNodeMarkStep, [{
|
|
571
|
+
key: "apply",
|
|
572
|
+
value: function apply(doc) {
|
|
573
|
+
var node = doc.nodeAt(this.pos);
|
|
574
|
+
if (!node) return StepResult.fail("No node at mark step's position");
|
|
575
|
+
var updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
576
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
577
|
+
}
|
|
578
|
+
}, {
|
|
579
|
+
key: "invert",
|
|
580
|
+
value: function invert(doc) {
|
|
581
|
+
var node = doc.nodeAt(this.pos);
|
|
582
|
+
|
|
583
|
+
if (node) {
|
|
584
|
+
var newSet = this.mark.addToSet(node.marks);
|
|
585
|
+
|
|
586
|
+
if (newSet.length == node.marks.length) {
|
|
587
|
+
for (var i = 0; i < node.marks.length; i++) {
|
|
588
|
+
if (!node.marks[i].isInSet(newSet)) return new AddNodeMarkStep(this.pos, node.marks[i]);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
596
|
+
}
|
|
597
|
+
}, {
|
|
598
|
+
key: "map",
|
|
599
|
+
value: function map(mapping) {
|
|
600
|
+
var pos = mapping.mapResult(this.pos, 1);
|
|
601
|
+
return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
|
|
602
|
+
}
|
|
603
|
+
}, {
|
|
604
|
+
key: "toJSON",
|
|
605
|
+
value: function toJSON() {
|
|
606
|
+
return {
|
|
607
|
+
stepType: "addNodeMark",
|
|
608
|
+
pos: this.pos,
|
|
609
|
+
mark: this.mark.toJSON()
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
}], [{
|
|
613
|
+
key: "fromJSON",
|
|
614
|
+
value: function fromJSON(schema, json) {
|
|
615
|
+
if (typeof json.pos != "number") throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
616
|
+
return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
617
|
+
}
|
|
618
|
+
}]);
|
|
619
|
+
|
|
620
|
+
return AddNodeMarkStep;
|
|
621
|
+
}(Step);
|
|
622
|
+
|
|
623
|
+
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
624
|
+
|
|
625
|
+
var RemoveNodeMarkStep = function (_Step4) {
|
|
626
|
+
_inherits(RemoveNodeMarkStep, _Step4);
|
|
627
|
+
|
|
628
|
+
var _super4 = _createSuper(RemoveNodeMarkStep);
|
|
629
|
+
|
|
630
|
+
function RemoveNodeMarkStep(pos, mark) {
|
|
631
|
+
var _this6;
|
|
632
|
+
|
|
633
|
+
_classCallCheck(this, RemoveNodeMarkStep);
|
|
634
|
+
|
|
635
|
+
_this6 = _super4.call(this);
|
|
636
|
+
_this6.pos = pos;
|
|
637
|
+
_this6.mark = mark;
|
|
638
|
+
return _this6;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
_createClass(RemoveNodeMarkStep, [{
|
|
642
|
+
key: "apply",
|
|
643
|
+
value: function apply(doc) {
|
|
644
|
+
var node = doc.nodeAt(this.pos);
|
|
645
|
+
if (!node) return StepResult.fail("No node at mark step's position");
|
|
646
|
+
var updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
647
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
648
|
+
}
|
|
649
|
+
}, {
|
|
650
|
+
key: "invert",
|
|
651
|
+
value: function invert(doc) {
|
|
652
|
+
var node = doc.nodeAt(this.pos);
|
|
653
|
+
if (!node || !this.mark.isInSet(node.marks)) return this;
|
|
654
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
655
|
+
}
|
|
656
|
+
}, {
|
|
657
|
+
key: "map",
|
|
658
|
+
value: function map(mapping) {
|
|
659
|
+
var pos = mapping.mapResult(this.pos, 1);
|
|
660
|
+
return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
|
|
661
|
+
}
|
|
662
|
+
}, {
|
|
663
|
+
key: "toJSON",
|
|
664
|
+
value: function toJSON() {
|
|
665
|
+
return {
|
|
666
|
+
stepType: "removeNodeMark",
|
|
667
|
+
pos: this.pos,
|
|
668
|
+
mark: this.mark.toJSON()
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
}], [{
|
|
672
|
+
key: "fromJSON",
|
|
673
|
+
value: function fromJSON(schema, json) {
|
|
674
|
+
if (typeof json.pos != "number") throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
675
|
+
return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
676
|
+
}
|
|
677
|
+
}]);
|
|
678
|
+
|
|
679
|
+
return RemoveNodeMarkStep;
|
|
680
|
+
}(Step);
|
|
681
|
+
|
|
682
|
+
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
683
|
+
|
|
684
|
+
var ReplaceStep = function (_Step5) {
|
|
685
|
+
_inherits(ReplaceStep, _Step5);
|
|
686
|
+
|
|
687
|
+
var _super5 = _createSuper(ReplaceStep);
|
|
688
|
+
|
|
689
|
+
function ReplaceStep(from, to, slice) {
|
|
690
|
+
var _this7;
|
|
691
|
+
|
|
532
692
|
var structure = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
533
693
|
|
|
534
694
|
_classCallCheck(this, ReplaceStep);
|
|
535
695
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
return
|
|
696
|
+
_this7 = _super5.call(this);
|
|
697
|
+
_this7.from = from;
|
|
698
|
+
_this7.to = to;
|
|
699
|
+
_this7.slice = slice;
|
|
700
|
+
_this7.structure = structure;
|
|
701
|
+
return _this7;
|
|
542
702
|
}
|
|
543
703
|
|
|
544
704
|
_createClass(ReplaceStep, [{
|
|
@@ -562,7 +722,7 @@ var ReplaceStep = function (_Step3) {
|
|
|
562
722
|
value: function map(mapping) {
|
|
563
723
|
var from = mapping.mapResult(this.from, 1),
|
|
564
724
|
to = mapping.mapResult(this.to, -1);
|
|
565
|
-
if (from.
|
|
725
|
+
if (from.deletedAcross && to.deletedAcross) return null;
|
|
566
726
|
return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
|
|
567
727
|
}
|
|
568
728
|
}, {
|
|
@@ -606,27 +766,27 @@ var ReplaceStep = function (_Step3) {
|
|
|
606
766
|
|
|
607
767
|
Step.jsonID("replace", ReplaceStep);
|
|
608
768
|
|
|
609
|
-
var ReplaceAroundStep = function (
|
|
610
|
-
_inherits(ReplaceAroundStep,
|
|
769
|
+
var ReplaceAroundStep = function (_Step6) {
|
|
770
|
+
_inherits(ReplaceAroundStep, _Step6);
|
|
611
771
|
|
|
612
|
-
var
|
|
772
|
+
var _super6 = _createSuper(ReplaceAroundStep);
|
|
613
773
|
|
|
614
774
|
function ReplaceAroundStep(from, to, gapFrom, gapTo, slice, insert) {
|
|
615
|
-
var
|
|
775
|
+
var _this8;
|
|
616
776
|
|
|
617
777
|
var structure = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
618
778
|
|
|
619
779
|
_classCallCheck(this, ReplaceAroundStep);
|
|
620
780
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
return
|
|
781
|
+
_this8 = _super6.call(this);
|
|
782
|
+
_this8.from = from;
|
|
783
|
+
_this8.to = to;
|
|
784
|
+
_this8.gapFrom = gapFrom;
|
|
785
|
+
_this8.gapTo = gapTo;
|
|
786
|
+
_this8.slice = slice;
|
|
787
|
+
_this8.insert = insert;
|
|
788
|
+
_this8.structure = structure;
|
|
789
|
+
return _this8;
|
|
630
790
|
}
|
|
631
791
|
|
|
632
792
|
_createClass(ReplaceAroundStep, [{
|
|
@@ -657,7 +817,7 @@ var ReplaceAroundStep = function (_Step4) {
|
|
|
657
817
|
to = mapping.mapResult(this.to, -1);
|
|
658
818
|
var gapFrom = mapping.map(this.gapFrom, -1),
|
|
659
819
|
gapTo = mapping.map(this.gapTo, 1);
|
|
660
|
-
if (from.
|
|
820
|
+
if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos) return null;
|
|
661
821
|
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
662
822
|
}
|
|
663
823
|
}, {
|
|
@@ -1570,15 +1730,86 @@ function coveredDepths($from, $to) {
|
|
|
1570
1730
|
return result;
|
|
1571
1731
|
}
|
|
1572
1732
|
|
|
1733
|
+
var AttrStep = function (_Step7) {
|
|
1734
|
+
_inherits(AttrStep, _Step7);
|
|
1735
|
+
|
|
1736
|
+
var _super7 = _createSuper(AttrStep);
|
|
1737
|
+
|
|
1738
|
+
function AttrStep(pos, attr, value) {
|
|
1739
|
+
var _this9;
|
|
1740
|
+
|
|
1741
|
+
_classCallCheck(this, AttrStep);
|
|
1742
|
+
|
|
1743
|
+
_this9 = _super7.call(this);
|
|
1744
|
+
_this9.pos = pos;
|
|
1745
|
+
_this9.attr = attr;
|
|
1746
|
+
_this9.value = value;
|
|
1747
|
+
return _this9;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
_createClass(AttrStep, [{
|
|
1751
|
+
key: "apply",
|
|
1752
|
+
value: function apply(doc) {
|
|
1753
|
+
var node = doc.nodeAt(this.pos);
|
|
1754
|
+
if (!node) return StepResult.fail("No node at attribute step's position");
|
|
1755
|
+
var attrs = Object.create(null);
|
|
1756
|
+
|
|
1757
|
+
for (var name in node.attrs) {
|
|
1758
|
+
attrs[name] = node.attrs[name];
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
attrs[this.attr] = this.value;
|
|
1762
|
+
var updated = node.type.create(attrs, null, node.marks);
|
|
1763
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
1764
|
+
}
|
|
1765
|
+
}, {
|
|
1766
|
+
key: "getMap",
|
|
1767
|
+
value: function getMap() {
|
|
1768
|
+
return StepMap.empty;
|
|
1769
|
+
}
|
|
1770
|
+
}, {
|
|
1771
|
+
key: "invert",
|
|
1772
|
+
value: function invert(doc) {
|
|
1773
|
+
return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
1774
|
+
}
|
|
1775
|
+
}, {
|
|
1776
|
+
key: "map",
|
|
1777
|
+
value: function map(mapping) {
|
|
1778
|
+
var pos = mapping.mapResult(this.pos, 1);
|
|
1779
|
+
return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
|
|
1780
|
+
}
|
|
1781
|
+
}, {
|
|
1782
|
+
key: "toJSON",
|
|
1783
|
+
value: function toJSON() {
|
|
1784
|
+
return {
|
|
1785
|
+
stepType: "attr",
|
|
1786
|
+
pos: this.pos,
|
|
1787
|
+
attr: this.attr,
|
|
1788
|
+
value: this.value
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
}], [{
|
|
1792
|
+
key: "fromJSON",
|
|
1793
|
+
value: function fromJSON(schema, json) {
|
|
1794
|
+
if (typeof json.pos != "number" || typeof json.attr != "string") throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
1795
|
+
return new AttrStep(json.pos, json.attr, json.value);
|
|
1796
|
+
}
|
|
1797
|
+
}]);
|
|
1798
|
+
|
|
1799
|
+
return AttrStep;
|
|
1800
|
+
}(Step);
|
|
1801
|
+
|
|
1802
|
+
Step.jsonID("attr", AttrStep);
|
|
1803
|
+
|
|
1573
1804
|
exports.TransformError = function (_Error) {
|
|
1574
1805
|
_inherits(_class, _Error);
|
|
1575
1806
|
|
|
1576
|
-
var
|
|
1807
|
+
var _super8 = _createSuper(_class);
|
|
1577
1808
|
|
|
1578
1809
|
function _class() {
|
|
1579
1810
|
_classCallCheck(this, _class);
|
|
1580
1811
|
|
|
1581
|
-
return
|
|
1812
|
+
return _super8.apply(this, arguments);
|
|
1582
1813
|
}
|
|
1583
1814
|
|
|
1584
1815
|
return _createClass(_class);
|
|
@@ -1726,6 +1957,31 @@ var Transform = function () {
|
|
|
1726
1957
|
return this;
|
|
1727
1958
|
}
|
|
1728
1959
|
}, {
|
|
1960
|
+
key: "setNodeAttribute",
|
|
1961
|
+
value: function setNodeAttribute(pos, attr, value) {
|
|
1962
|
+
this.step(new AttrStep(pos, attr, value));
|
|
1963
|
+
return this;
|
|
1964
|
+
}
|
|
1965
|
+
}, {
|
|
1966
|
+
key: "addNodeMark",
|
|
1967
|
+
value: function addNodeMark(pos, mark) {
|
|
1968
|
+
this.step(new AddNodeMarkStep(pos, mark));
|
|
1969
|
+
return this;
|
|
1970
|
+
}
|
|
1971
|
+
}, {
|
|
1972
|
+
key: "removeNodeMark",
|
|
1973
|
+
value: function removeNodeMark(pos, mark) {
|
|
1974
|
+
if (!(mark instanceof prosemirrorModel.Mark)) {
|
|
1975
|
+
var node = this.doc.nodeAt(pos);
|
|
1976
|
+
if (!node) throw new RangeError("No node at position " + pos);
|
|
1977
|
+
mark = mark.isInSet(node.marks);
|
|
1978
|
+
if (!mark) return this;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
this.step(new RemoveNodeMarkStep(pos, mark));
|
|
1982
|
+
return this;
|
|
1983
|
+
}
|
|
1984
|
+
}, {
|
|
1729
1985
|
key: "split",
|
|
1730
1986
|
value: function split(pos) {
|
|
1731
1987
|
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
@@ -1762,9 +2018,12 @@ var Transform = function () {
|
|
|
1762
2018
|
}();
|
|
1763
2019
|
|
|
1764
2020
|
exports.AddMarkStep = AddMarkStep;
|
|
2021
|
+
exports.AddNodeMarkStep = AddNodeMarkStep;
|
|
2022
|
+
exports.AttrStep = AttrStep;
|
|
1765
2023
|
exports.MapResult = MapResult;
|
|
1766
2024
|
exports.Mapping = Mapping;
|
|
1767
2025
|
exports.RemoveMarkStep = RemoveMarkStep;
|
|
2026
|
+
exports.RemoveNodeMarkStep = RemoveNodeMarkStep;
|
|
1768
2027
|
exports.ReplaceAroundStep = ReplaceAroundStep;
|
|
1769
2028
|
exports.ReplaceStep = ReplaceStep;
|
|
1770
2029
|
exports.Step = Step;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,10 +32,25 @@ declare class MapResult {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly pos: number;
|
|
34
34
|
/**
|
|
35
|
-
Tells you whether the position was deleted, that is, whether
|
|
36
|
-
|
|
35
|
+
Tells you whether the position was deleted, that is, whether the
|
|
36
|
+
step removed the token on the side queried (via the `assoc`)
|
|
37
|
+
argument from the document.
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
get deleted(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
Tells you whether the token before the mapped position was deleted.
|
|
42
|
+
*/
|
|
43
|
+
get deletedBefore(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
True when the token after the mapped position was deleted.
|
|
46
|
+
*/
|
|
47
|
+
get deletedAfter(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
Tells whether any of the steps mapped through deletes across the
|
|
50
|
+
position (including both the token before and after the
|
|
51
|
+
position).
|
|
52
|
+
*/
|
|
53
|
+
get deletedAcross(): boolean;
|
|
39
54
|
}
|
|
40
55
|
/**
|
|
41
56
|
A map describing the deletions and insertions made by a step, which
|
|
@@ -398,6 +413,19 @@ declare class Transform {
|
|
|
398
413
|
*/
|
|
399
414
|
setNodeMarkup(pos: number, type?: NodeType | null, attrs?: Attrs | null, marks?: readonly Mark[]): this;
|
|
400
415
|
/**
|
|
416
|
+
Set a single attribute on a given node to a new value.
|
|
417
|
+
*/
|
|
418
|
+
setNodeAttribute(pos: number, attr: string, value: any): this;
|
|
419
|
+
/**
|
|
420
|
+
Add a mark to the node at position `pos`.
|
|
421
|
+
*/
|
|
422
|
+
addNodeMark(pos: number, mark: Mark): this;
|
|
423
|
+
/**
|
|
424
|
+
Remove a mark (or a mark of the given type) from the node at
|
|
425
|
+
position `pos`.
|
|
426
|
+
*/
|
|
427
|
+
removeNodeMark(pos: number, mark: Mark | MarkType): this;
|
|
428
|
+
/**
|
|
401
429
|
Split the node at the given position, and optionally, if `depth` is
|
|
402
430
|
greater than one, any number of nodes above that. By default, the
|
|
403
431
|
parts split off will inherit the node type of the original node.
|
|
@@ -555,6 +583,64 @@ declare class RemoveMarkStep extends Step {
|
|
|
555
583
|
merge(other: Step): Step | null;
|
|
556
584
|
toJSON(): any;
|
|
557
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
Add a mark to a specific node.
|
|
588
|
+
*/
|
|
589
|
+
declare class AddNodeMarkStep extends Step {
|
|
590
|
+
/**
|
|
591
|
+
The position of the target node.
|
|
592
|
+
*/
|
|
593
|
+
readonly pos: number;
|
|
594
|
+
/**
|
|
595
|
+
The mark to add.
|
|
596
|
+
*/
|
|
597
|
+
readonly mark: Mark;
|
|
598
|
+
/**
|
|
599
|
+
Create a node mark step.
|
|
600
|
+
*/
|
|
601
|
+
constructor(
|
|
602
|
+
/**
|
|
603
|
+
The position of the target node.
|
|
604
|
+
*/
|
|
605
|
+
pos: number,
|
|
606
|
+
/**
|
|
607
|
+
The mark to add.
|
|
608
|
+
*/
|
|
609
|
+
mark: Mark);
|
|
610
|
+
apply(doc: Node): StepResult;
|
|
611
|
+
invert(doc: Node): Step;
|
|
612
|
+
map(mapping: Mappable): Step | null;
|
|
613
|
+
toJSON(): any;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
Remove a mark from a specific node.
|
|
617
|
+
*/
|
|
618
|
+
declare class RemoveNodeMarkStep extends Step {
|
|
619
|
+
/**
|
|
620
|
+
The position of the target node.
|
|
621
|
+
*/
|
|
622
|
+
readonly pos: number;
|
|
623
|
+
/**
|
|
624
|
+
The mark to remove.
|
|
625
|
+
*/
|
|
626
|
+
readonly mark: Mark;
|
|
627
|
+
/**
|
|
628
|
+
Create a mark-removing step.
|
|
629
|
+
*/
|
|
630
|
+
constructor(
|
|
631
|
+
/**
|
|
632
|
+
The position of the target node.
|
|
633
|
+
*/
|
|
634
|
+
pos: number,
|
|
635
|
+
/**
|
|
636
|
+
The mark to remove.
|
|
637
|
+
*/
|
|
638
|
+
mark: Mark);
|
|
639
|
+
apply(doc: Node): StepResult;
|
|
640
|
+
invert(doc: Node): Step;
|
|
641
|
+
map(mapping: Mappable): Step | null;
|
|
642
|
+
toJSON(): any;
|
|
643
|
+
}
|
|
558
644
|
|
|
559
645
|
/**
|
|
560
646
|
Replace a part of the document with a slice of new content.
|
|
@@ -679,6 +765,39 @@ declare class ReplaceAroundStep extends Step {
|
|
|
679
765
|
toJSON(): any;
|
|
680
766
|
}
|
|
681
767
|
|
|
768
|
+
/**
|
|
769
|
+
Update an attribute in a specific node.
|
|
770
|
+
*/
|
|
771
|
+
declare class AttrStep extends Step {
|
|
772
|
+
/**
|
|
773
|
+
The position of the target node.
|
|
774
|
+
*/
|
|
775
|
+
readonly pos: number;
|
|
776
|
+
/**
|
|
777
|
+
The attribute to set.
|
|
778
|
+
*/
|
|
779
|
+
readonly attr: string;
|
|
780
|
+
readonly value: any;
|
|
781
|
+
/**
|
|
782
|
+
Construct an attribute step.
|
|
783
|
+
*/
|
|
784
|
+
constructor(
|
|
785
|
+
/**
|
|
786
|
+
The position of the target node.
|
|
787
|
+
*/
|
|
788
|
+
pos: number,
|
|
789
|
+
/**
|
|
790
|
+
The attribute to set.
|
|
791
|
+
*/
|
|
792
|
+
attr: string, value: any);
|
|
793
|
+
apply(doc: Node): StepResult;
|
|
794
|
+
getMap(): StepMap;
|
|
795
|
+
invert(doc: Node): AttrStep;
|
|
796
|
+
map(mapping: Mappable): AttrStep | null;
|
|
797
|
+
toJSON(): any;
|
|
798
|
+
static fromJSON(schema: Schema, json: any): AttrStep;
|
|
799
|
+
}
|
|
800
|
+
|
|
682
801
|
/**
|
|
683
802
|
‘Fit’ a slice into a given position in the document, producing a
|
|
684
803
|
[step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if
|
|
@@ -687,4 +806,4 @@ would be a no-op (an empty slice over an empty range).
|
|
|
687
806
|
*/
|
|
688
807
|
declare function replaceStep(doc: Node, from: number, to?: number, slice?: Slice): Step | null;
|
|
689
808
|
|
|
690
|
-
export { AddMarkStep, MapResult, Mappable, Mapping, RemoveMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };
|
|
809
|
+
export { AddMarkStep, AddNodeMarkStep, AttrStep, MapResult, Mappable, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };
|