prosemirror-transform 1.7.3 → 1.7.5
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 +12 -0
- package/dist/index.cjs +23 -16
- package/dist/index.js +15 -7
- package/package.json +1 -1
- package/src/mark.ts +12 -3
- package/src/replace.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 1.7.5 (2023-08-22)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a failure in `replaceRange` to drop wrapper nodes when the same wrapper is already present.
|
|
6
|
+
|
|
7
|
+
## 1.7.4 (2023-07-28)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
When using `setBlockType` to convert a code block to a type of node that doesn't contain code, replace newlines with spaces.
|
|
12
|
+
|
|
1
13
|
## 1.7.3 (2023-06-01)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -28,10 +28,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
28
28
|
|
|
29
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; }
|
|
30
30
|
|
|
31
|
-
Object.defineProperty(exports, '__esModule', {
|
|
32
|
-
value: true
|
|
33
|
-
});
|
|
34
|
-
|
|
35
31
|
var prosemirrorModel = require('prosemirror-model');
|
|
36
32
|
|
|
37
33
|
var lower16 = 0xffff;
|
|
@@ -957,7 +953,7 @@ function _removeMark(tr, from, to, mark) {
|
|
|
957
953
|
function _clearIncompatible(tr, pos, parentType) {
|
|
958
954
|
var match = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : parentType.contentMatch;
|
|
959
955
|
var node = tr.doc.nodeAt(pos);
|
|
960
|
-
var
|
|
956
|
+
var replSteps = [],
|
|
961
957
|
cur = pos + 1;
|
|
962
958
|
|
|
963
959
|
for (var i = 0; i < node.childCount; i++) {
|
|
@@ -966,13 +962,24 @@ function _clearIncompatible(tr, pos, parentType) {
|
|
|
966
962
|
var allowed = match.matchType(child.type);
|
|
967
963
|
|
|
968
964
|
if (!allowed) {
|
|
969
|
-
|
|
965
|
+
replSteps.push(new ReplaceStep(cur, end, prosemirrorModel.Slice.empty));
|
|
970
966
|
} else {
|
|
971
967
|
match = allowed;
|
|
972
968
|
|
|
973
969
|
for (var j = 0; j < child.marks.length; j++) {
|
|
974
970
|
if (!parentType.allowsMarkType(child.marks[j].type)) tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
|
|
975
971
|
}
|
|
972
|
+
|
|
973
|
+
if (child.isText && !parentType.spec.code) {
|
|
974
|
+
var m = void 0,
|
|
975
|
+
newline = /\r?\n|\r/g,
|
|
976
|
+
slice = void 0;
|
|
977
|
+
|
|
978
|
+
while (m = newline.exec(child.text)) {
|
|
979
|
+
if (!slice) slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
|
|
980
|
+
replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
|
|
981
|
+
}
|
|
982
|
+
}
|
|
976
983
|
}
|
|
977
984
|
|
|
978
985
|
cur = end;
|
|
@@ -983,8 +990,8 @@ function _clearIncompatible(tr, pos, parentType) {
|
|
|
983
990
|
tr.replace(cur, cur, new prosemirrorModel.Slice(fill, 0, 0));
|
|
984
991
|
}
|
|
985
992
|
|
|
986
|
-
for (var _i =
|
|
987
|
-
tr.step(
|
|
993
|
+
for (var _i = replSteps.length - 1; _i >= 0; _i--) {
|
|
994
|
+
tr.step(replSteps[_i]);
|
|
988
995
|
}
|
|
989
996
|
}
|
|
990
997
|
|
|
@@ -1652,9 +1659,9 @@ function _replaceRange(tr, from, to, slice) {
|
|
|
1652
1659
|
}
|
|
1653
1660
|
|
|
1654
1661
|
for (var _d3 = preferredDepth - 1; _d3 >= 0; _d3--) {
|
|
1655
|
-
var
|
|
1656
|
-
def = definesContent(type);
|
|
1657
|
-
if (def && $from.node(
|
|
1662
|
+
var leftNode = leftNodes[_d3],
|
|
1663
|
+
def = definesContent(leftNode.type);
|
|
1664
|
+
if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = _d3;else if (def || !leftNode.type.isTextblock) break;
|
|
1658
1665
|
}
|
|
1659
1666
|
|
|
1660
1667
|
for (var j = slice.openStart; j >= 0; j--) {
|
|
@@ -1817,17 +1824,17 @@ var AttrStep = function (_Step7) {
|
|
|
1817
1824
|
Step.jsonID("attr", AttrStep);
|
|
1818
1825
|
|
|
1819
1826
|
exports.TransformError = function (_Error) {
|
|
1820
|
-
_inherits(
|
|
1827
|
+
_inherits(TransformError, _Error);
|
|
1821
1828
|
|
|
1822
|
-
var _super8 = _createSuper(
|
|
1829
|
+
var _super8 = _createSuper(TransformError);
|
|
1823
1830
|
|
|
1824
|
-
function
|
|
1825
|
-
_classCallCheck(this,
|
|
1831
|
+
function TransformError() {
|
|
1832
|
+
_classCallCheck(this, TransformError);
|
|
1826
1833
|
|
|
1827
1834
|
return _super8.apply(this, arguments);
|
|
1828
1835
|
}
|
|
1829
1836
|
|
|
1830
|
-
return _createClass(
|
|
1837
|
+
return _createClass(TransformError);
|
|
1831
1838
|
}(_wrapNativeSuper(Error));
|
|
1832
1839
|
|
|
1833
1840
|
exports.TransformError = function TransformError(message) {
|
package/dist/index.js
CHANGED
|
@@ -938,18 +938,26 @@ function removeMark(tr, from, to, mark) {
|
|
|
938
938
|
}
|
|
939
939
|
function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch) {
|
|
940
940
|
let node = tr.doc.nodeAt(pos);
|
|
941
|
-
let
|
|
941
|
+
let replSteps = [], cur = pos + 1;
|
|
942
942
|
for (let i = 0; i < node.childCount; i++) {
|
|
943
943
|
let child = node.child(i), end = cur + child.nodeSize;
|
|
944
944
|
let allowed = match.matchType(child.type);
|
|
945
945
|
if (!allowed) {
|
|
946
|
-
|
|
946
|
+
replSteps.push(new ReplaceStep(cur, end, Slice.empty));
|
|
947
947
|
}
|
|
948
948
|
else {
|
|
949
949
|
match = allowed;
|
|
950
950
|
for (let j = 0; j < child.marks.length; j++)
|
|
951
951
|
if (!parentType.allowsMarkType(child.marks[j].type))
|
|
952
952
|
tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
|
|
953
|
+
if (child.isText && !parentType.spec.code) {
|
|
954
|
+
let m, newline = /\r?\n|\r/g, slice;
|
|
955
|
+
while (m = newline.exec(child.text)) {
|
|
956
|
+
if (!slice)
|
|
957
|
+
slice = new Slice(Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
|
|
958
|
+
replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
953
961
|
}
|
|
954
962
|
cur = end;
|
|
955
963
|
}
|
|
@@ -957,8 +965,8 @@ function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch)
|
|
|
957
965
|
let fill = match.fillBefore(Fragment.empty, true);
|
|
958
966
|
tr.replace(cur, cur, new Slice(fill, 0, 0));
|
|
959
967
|
}
|
|
960
|
-
for (let i =
|
|
961
|
-
tr.step(
|
|
968
|
+
for (let i = replSteps.length - 1; i >= 0; i--)
|
|
969
|
+
tr.step(replSteps[i]);
|
|
962
970
|
}
|
|
963
971
|
|
|
964
972
|
function canCut(node, start, end) {
|
|
@@ -1593,10 +1601,10 @@ function replaceRange(tr, from, to, slice) {
|
|
|
1593
1601
|
// Back up preferredDepth to cover defining textblocks directly
|
|
1594
1602
|
// above it, possibly skipping a non-defining textblock.
|
|
1595
1603
|
for (let d = preferredDepth - 1; d >= 0; d--) {
|
|
1596
|
-
let
|
|
1597
|
-
if (def && $from.node(
|
|
1604
|
+
let leftNode = leftNodes[d], def = definesContent(leftNode.type);
|
|
1605
|
+
if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1)))
|
|
1598
1606
|
preferredDepth = d;
|
|
1599
|
-
else if (def || !type.isTextblock)
|
|
1607
|
+
else if (def || !leftNode.type.isTextblock)
|
|
1600
1608
|
break;
|
|
1601
1609
|
}
|
|
1602
1610
|
for (let j = slice.openStart; j >= 0; j--) {
|
package/package.json
CHANGED
package/src/mark.ts
CHANGED
|
@@ -74,16 +74,25 @@ export function removeMark(tr: Transform, from: number, to: number, mark?: Mark
|
|
|
74
74
|
|
|
75
75
|
export function clearIncompatible(tr: Transform, pos: number, parentType: NodeType, match = parentType.contentMatch) {
|
|
76
76
|
let node = tr.doc.nodeAt(pos)!
|
|
77
|
-
let
|
|
77
|
+
let replSteps: Step[] = [], cur = pos + 1
|
|
78
78
|
for (let i = 0; i < node.childCount; i++) {
|
|
79
79
|
let child = node.child(i), end = cur + child.nodeSize
|
|
80
80
|
let allowed = match.matchType(child.type)
|
|
81
81
|
if (!allowed) {
|
|
82
|
-
|
|
82
|
+
replSteps.push(new ReplaceStep(cur, end, Slice.empty))
|
|
83
83
|
} else {
|
|
84
84
|
match = allowed
|
|
85
85
|
for (let j = 0; j < child.marks.length; j++) if (!parentType.allowsMarkType(child.marks[j].type))
|
|
86
86
|
tr.step(new RemoveMarkStep(cur, end, child.marks[j]))
|
|
87
|
+
|
|
88
|
+
if (child.isText && !parentType.spec.code) {
|
|
89
|
+
let m, newline = /\r?\n|\r/g, slice
|
|
90
|
+
while (m = newline.exec(child.text!)) {
|
|
91
|
+
if (!slice) slice = new Slice(Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))),
|
|
92
|
+
0, 0)
|
|
93
|
+
replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
cur = end
|
|
89
98
|
}
|
|
@@ -91,5 +100,5 @@ export function clearIncompatible(tr: Transform, pos: number, parentType: NodeTy
|
|
|
91
100
|
let fill = match.fillBefore(Fragment.empty, true)
|
|
92
101
|
tr.replace(cur, cur, new Slice(fill!, 0, 0))
|
|
93
102
|
}
|
|
94
|
-
for (let i =
|
|
103
|
+
for (let i = replSteps.length - 1; i >= 0; i--) tr.step(replSteps[i])
|
|
95
104
|
}
|
package/src/replace.ts
CHANGED
|
@@ -359,7 +359,7 @@ export function replaceRange(tr: Transform, from: number, to: number, slice: Sli
|
|
|
359
359
|
// target depth, starting with the preferred depths.
|
|
360
360
|
let preferredTargetIndex = targetDepths.indexOf(preferredTarget)
|
|
361
361
|
|
|
362
|
-
let leftNodes = [], preferredDepth = slice.openStart
|
|
362
|
+
let leftNodes: Node[] = [], preferredDepth = slice.openStart
|
|
363
363
|
for (let content = slice.content, i = 0;; i++) {
|
|
364
364
|
let node = content.firstChild!
|
|
365
365
|
leftNodes.push(node)
|
|
@@ -370,9 +370,9 @@ export function replaceRange(tr: Transform, from: number, to: number, slice: Sli
|
|
|
370
370
|
// Back up preferredDepth to cover defining textblocks directly
|
|
371
371
|
// above it, possibly skipping a non-defining textblock.
|
|
372
372
|
for (let d = preferredDepth - 1; d >= 0; d--) {
|
|
373
|
-
let
|
|
374
|
-
if (def && $from.node(
|
|
375
|
-
else if (def || !type.isTextblock) break
|
|
373
|
+
let leftNode = leftNodes[d], def = definesContent(leftNode.type)
|
|
374
|
+
if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = d
|
|
375
|
+
else if (def || !leftNode.type.isTextblock) break
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
for (let j = slice.openStart; j >= 0; j--) {
|
|
@@ -443,7 +443,7 @@ export function deleteRange(tr: Transform, from: number, to: number) {
|
|
|
443
443
|
// Returns an array of all depths for which $from - $to spans the
|
|
444
444
|
// whole content of the nodes at that depth.
|
|
445
445
|
function coveredDepths($from: ResolvedPos, $to: ResolvedPos) {
|
|
446
|
-
let result = [], minDepth = Math.min($from.depth, $to.depth)
|
|
446
|
+
let result: number[] = [], minDepth = Math.min($from.depth, $to.depth)
|
|
447
447
|
for (let d = minDepth; d >= 0; d--) {
|
|
448
448
|
let start = $from.start(d)
|
|
449
449
|
if (start < $from.pos - ($from.depth - d) ||
|