prosemirror-transform 1.10.1 → 1.10.2

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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.10.2 (2024-10-11)
2
+
3
+ ### Bug fixes
4
+
5
+ Allow `Transform.join` to clear incompatible inline content from the node after the join.
6
+
1
7
  ## 1.10.1 (2024-10-10)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1034,7 +1034,7 @@ function canJoin(doc, pos) {
1034
1034
  index = $pos.index();
1035
1035
  return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1);
1036
1036
  }
1037
- function canAppendWithSubstitutedLinebeaks(a, b) {
1037
+ function canAppendWithSubstitutedLinebreaks(a, b) {
1038
1038
  if (!b.content.size) a.type.compatibleContent(b.type);
1039
1039
  var match = a.contentMatchAt(a.childCount);
1040
1040
  var linebreakReplacement = a.type.schema.linebreakReplacement;
@@ -1048,7 +1048,7 @@ function canAppendWithSubstitutedLinebeaks(a, b) {
1048
1048
  return match.validEnd;
1049
1049
  }
1050
1050
  function joinable(a, b) {
1051
- return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebeaks(a, b));
1051
+ return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
1052
1052
  }
1053
1053
  function joinPoint(doc, pos) {
1054
1054
  var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
@@ -1076,10 +1076,11 @@ function joinPoint(doc, pos) {
1076
1076
  function _join(tr, pos, depth) {
1077
1077
  var convertNewlines = null;
1078
1078
  var linebreakReplacement = tr.doc.type.schema.linebreakReplacement;
1079
- if (linebreakReplacement) {
1080
- var before = tr.doc.resolve(pos - depth).node().type;
1081
- var pre = before.whitespace == "pre";
1082
- var supportLinebreak = !!before.contentMatch.matchType(linebreakReplacement);
1079
+ var $before = tr.doc.resolve(pos - depth),
1080
+ beforeType = $before.node().type;
1081
+ if (linebreakReplacement && beforeType.inlineContent) {
1082
+ var pre = beforeType.whitespace == "pre";
1083
+ var supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
1083
1084
  if (pre && !supportLinebreak) convertNewlines = false;else if (!pre && supportLinebreak) convertNewlines = true;
1084
1085
  }
1085
1086
  var mapFrom = tr.steps.length;
@@ -1087,6 +1088,7 @@ function _join(tr, pos, depth) {
1087
1088
  var $after = tr.doc.resolve(pos + depth);
1088
1089
  replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
1089
1090
  }
1091
+ if (beforeType.inlineContent) _clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
1090
1092
  var mapping = tr.mapping.slice(mapFrom),
1091
1093
  start = mapping.map(pos - depth);
1092
1094
  tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), prosemirrorModel.Slice.empty, true));
package/dist/index.js CHANGED
@@ -1183,7 +1183,7 @@ function canJoin(doc, pos) {
1183
1183
  return joinable($pos.nodeBefore, $pos.nodeAfter) &&
1184
1184
  $pos.parent.canReplace(index, index + 1);
1185
1185
  }
1186
- function canAppendWithSubstitutedLinebeaks(a, b) {
1186
+ function canAppendWithSubstitutedLinebreaks(a, b) {
1187
1187
  if (!b.content.size)
1188
1188
  a.type.compatibleContent(b.type);
1189
1189
  let match = a.contentMatchAt(a.childCount);
@@ -1200,7 +1200,7 @@ function canAppendWithSubstitutedLinebeaks(a, b) {
1200
1200
  return match.validEnd;
1201
1201
  }
1202
1202
  function joinable(a, b) {
1203
- return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebeaks(a, b));
1203
+ return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
1204
1204
  }
1205
1205
  /**
1206
1206
  Find an ancestor of the given position that can be joined to the
@@ -1235,10 +1235,10 @@ function joinPoint(doc, pos, dir = -1) {
1235
1235
  function join(tr, pos, depth) {
1236
1236
  let convertNewlines = null;
1237
1237
  let { linebreakReplacement } = tr.doc.type.schema;
1238
- if (linebreakReplacement) {
1239
- let before = tr.doc.resolve(pos - depth).node().type;
1240
- let pre = before.whitespace == "pre";
1241
- let supportLinebreak = !!before.contentMatch.matchType(linebreakReplacement);
1238
+ let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;
1239
+ if (linebreakReplacement && beforeType.inlineContent) {
1240
+ let pre = beforeType.whitespace == "pre";
1241
+ let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
1242
1242
  if (pre && !supportLinebreak)
1243
1243
  convertNewlines = false;
1244
1244
  else if (!pre && supportLinebreak)
@@ -1249,6 +1249,8 @@ function join(tr, pos, depth) {
1249
1249
  let $after = tr.doc.resolve(pos + depth);
1250
1250
  replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
1251
1251
  }
1252
+ if (beforeType.inlineContent)
1253
+ clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
1252
1254
  let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);
1253
1255
  tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));
1254
1256
  if (convertNewlines === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "description": "ProseMirror document transformations",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/structure.ts CHANGED
@@ -226,7 +226,7 @@ export function canJoin(doc: Node, pos: number): boolean {
226
226
  $pos.parent.canReplace(index, index + 1)
227
227
  }
228
228
 
229
- function canAppendWithSubstitutedLinebeaks(a: Node, b: Node) {
229
+ function canAppendWithSubstitutedLinebreaks(a: Node, b: Node) {
230
230
  if (!b.content.size) a.type.compatibleContent(b.type)
231
231
  let match: ContentMatch | null = a.contentMatchAt(a.childCount)
232
232
  let {linebreakReplacement} = a.type.schema
@@ -241,7 +241,7 @@ function canAppendWithSubstitutedLinebeaks(a: Node, b: Node) {
241
241
  }
242
242
 
243
243
  function joinable(a: Node | null, b: Node | null) {
244
- return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebeaks(a, b))
244
+ return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b))
245
245
  }
246
246
 
247
247
  /// Find an ancestor of the given position that can be joined to the
@@ -272,10 +272,10 @@ export function joinPoint(doc: Node, pos: number, dir = -1) {
272
272
  export function join(tr: Transform, pos: number, depth: number) {
273
273
  let convertNewlines = null
274
274
  let {linebreakReplacement} = tr.doc.type.schema
275
- if (linebreakReplacement) {
276
- let before = tr.doc.resolve(pos - depth).node().type
277
- let pre = before.whitespace == "pre"
278
- let supportLinebreak = !!before.contentMatch.matchType(linebreakReplacement)
275
+ let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type
276
+ if (linebreakReplacement && beforeType.inlineContent) {
277
+ let pre = beforeType.whitespace == "pre"
278
+ let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement)
279
279
  if (pre && !supportLinebreak) convertNewlines = false
280
280
  else if (!pre && supportLinebreak) convertNewlines = true
281
281
  }
@@ -284,6 +284,9 @@ export function join(tr: Transform, pos: number, depth: number) {
284
284
  let $after = tr.doc.resolve(pos + depth)
285
285
  replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom)
286
286
  }
287
+ if (beforeType.inlineContent)
288
+ clearIncompatible(tr, pos + depth - 1, beforeType,
289
+ $before.node().contentMatchAt($before.index()), convertNewlines == null)
287
290
  let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth)
288
291
  tr.step(new ReplaceStep(start, mapping.map(pos + depth, - 1), Slice.empty, true))
289
292
  if (convertNewlines === true) {