prosemirror-transform 1.7.2 → 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 +12 -0
- package/dist/index.cjs +17 -5
- package/dist/index.js +15 -6
- package/package.json +1 -1
- package/src/mark.ts +12 -3
- package/src/structure.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 1.7.4 (2023-07-28)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
When using `setBlockType` to convert a code block to a type of node that doesn't contain code, replace newlines with spaces.
|
|
6
|
+
|
|
7
|
+
## 1.7.3 (2023-06-01)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix a bug in `canSplit` that made it interpret the `typesAfter` argument incorrectly on splits of depth greater than 1.
|
|
12
|
+
|
|
1
13
|
## 1.7.2 (2023-05-17)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
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
|
|
|
@@ -1153,8 +1164,9 @@ function canSplit(doc, pos) {
|
|
|
1153
1164
|
|
|
1154
1165
|
if (node.type.spec.isolating) return false;
|
|
1155
1166
|
var rest = node.content.cutByIndex(_index, node.childCount);
|
|
1167
|
+
var overrideChild = typesAfter && typesAfter[i + 1];
|
|
1168
|
+
if (overrideChild) rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
|
|
1156
1169
|
var after = typesAfter && typesAfter[i] || node;
|
|
1157
|
-
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs));
|
|
1158
1170
|
if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false;
|
|
1159
1171
|
}
|
|
1160
1172
|
|
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) {
|
|
@@ -1112,9 +1120,10 @@ function canSplit(doc, pos, depth = 1, typesAfter) {
|
|
|
1112
1120
|
if (node.type.spec.isolating)
|
|
1113
1121
|
return false;
|
|
1114
1122
|
let rest = node.content.cutByIndex(index, node.childCount);
|
|
1123
|
+
let overrideChild = typesAfter && typesAfter[i + 1];
|
|
1124
|
+
if (overrideChild)
|
|
1125
|
+
rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
|
|
1115
1126
|
let after = (typesAfter && typesAfter[i]) || node;
|
|
1116
|
-
if (after != node)
|
|
1117
|
-
rest = rest.replaceChild(0, after.type.create(after.attrs));
|
|
1118
1127
|
if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
|
|
1119
1128
|
return false;
|
|
1120
1129
|
}
|
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/structure.ts
CHANGED
|
@@ -163,8 +163,10 @@ export function canSplit(doc: Node, pos: number, depth = 1,
|
|
|
163
163
|
let node = $pos.node(d), index = $pos.index(d)
|
|
164
164
|
if (node.type.spec.isolating) return false
|
|
165
165
|
let rest = node.content.cutByIndex(index, node.childCount)
|
|
166
|
+
let overrideChild = typesAfter && typesAfter[i + 1]
|
|
167
|
+
if (overrideChild)
|
|
168
|
+
rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs))
|
|
166
169
|
let after = (typesAfter && typesAfter[i]) || node
|
|
167
|
-
if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs))
|
|
168
170
|
if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
|
|
169
171
|
return false
|
|
170
172
|
}
|