prosemirror-transform 1.7.3 → 1.7.4
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 +6 -0
- package/dist/index.cjs +15 -4
- package/dist/index.js +12 -4
- package/package.json +1 -1
- package/src/mark.ts +12 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -957,7 +957,7 @@ function _removeMark(tr, from, to, mark) {
|
|
|
957
957
|
function _clearIncompatible(tr, pos, parentType) {
|
|
958
958
|
var match = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : parentType.contentMatch;
|
|
959
959
|
var node = tr.doc.nodeAt(pos);
|
|
960
|
-
var
|
|
960
|
+
var replSteps = [],
|
|
961
961
|
cur = pos + 1;
|
|
962
962
|
|
|
963
963
|
for (var i = 0; i < node.childCount; i++) {
|
|
@@ -966,13 +966,24 @@ function _clearIncompatible(tr, pos, parentType) {
|
|
|
966
966
|
var allowed = match.matchType(child.type);
|
|
967
967
|
|
|
968
968
|
if (!allowed) {
|
|
969
|
-
|
|
969
|
+
replSteps.push(new ReplaceStep(cur, end, prosemirrorModel.Slice.empty));
|
|
970
970
|
} else {
|
|
971
971
|
match = allowed;
|
|
972
972
|
|
|
973
973
|
for (var j = 0; j < child.marks.length; j++) {
|
|
974
974
|
if (!parentType.allowsMarkType(child.marks[j].type)) tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
|
|
975
975
|
}
|
|
976
|
+
|
|
977
|
+
if (child.isText && !parentType.spec.code) {
|
|
978
|
+
var m = void 0,
|
|
979
|
+
newline = /\r?\n|\r/g,
|
|
980
|
+
slice = void 0;
|
|
981
|
+
|
|
982
|
+
while (m = newline.exec(child.text)) {
|
|
983
|
+
if (!slice) slice = new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
|
|
984
|
+
replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
|
|
985
|
+
}
|
|
986
|
+
}
|
|
976
987
|
}
|
|
977
988
|
|
|
978
989
|
cur = end;
|
|
@@ -983,8 +994,8 @@ function _clearIncompatible(tr, pos, parentType) {
|
|
|
983
994
|
tr.replace(cur, cur, new prosemirrorModel.Slice(fill, 0, 0));
|
|
984
995
|
}
|
|
985
996
|
|
|
986
|
-
for (var _i =
|
|
987
|
-
tr.step(
|
|
997
|
+
for (var _i = replSteps.length - 1; _i >= 0; _i--) {
|
|
998
|
+
tr.step(replSteps[_i]);
|
|
988
999
|
}
|
|
989
1000
|
}
|
|
990
1001
|
|
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) {
|
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
|
}
|