prosemirror-transform 1.2.11 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.2.11",
3
+ "version": "1.3.2",
4
4
  "description": "ProseMirror document transformations",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
package/src/mark_step.js CHANGED
@@ -17,8 +17,14 @@ export class AddMarkStep extends Step {
17
17
  // :: (number, number, Mark)
18
18
  constructor(from, to, mark) {
19
19
  super()
20
+ // :: number
21
+ // The start of the marked range.
20
22
  this.from = from
23
+ // :: number
24
+ // The end of the marked range.
21
25
  this.to = to
26
+ // :: Mark
27
+ // The mark to add.
22
28
  this.mark = mark
23
29
  }
24
30
 
@@ -69,8 +75,14 @@ export class RemoveMarkStep extends Step {
69
75
  // :: (number, number, Mark)
70
76
  constructor(from, to, mark) {
71
77
  super()
78
+ // :: number
79
+ // The start of the unmarked range.
72
80
  this.from = from
81
+ // :: number
82
+ // The end of the unmarked range.
73
83
  this.to = to
84
+ // :: Mark
85
+ // The mark to remove.
74
86
  this.mark = mark
75
87
  }
76
88
 
package/src/replace.js CHANGED
@@ -417,7 +417,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
417
417
  this.replace(from, to, slice)
418
418
  if (this.steps.length > startSteps) break
419
419
  let depth = targetDepths[i]
420
- if (i < 0) continue
420
+ if (depth < 0) continue
421
421
  from = $from.before(depth); to = $to.after(depth)
422
422
  }
423
423
  return this
@@ -15,8 +15,14 @@ export class ReplaceStep extends Step {
15
15
  // overwriting something they weren't supposed to).
16
16
  constructor(from, to, slice, structure) {
17
17
  super()
18
+ // :: number
19
+ // The start position of the replaced range.
18
20
  this.from = from
21
+ // :: number
22
+ // The end position of the replaced range.
19
23
  this.to = to
24
+ // :: Slice
25
+ // The slice to insert.
20
26
  this.slice = slice
21
27
  this.structure = !!structure
22
28
  }
@@ -42,7 +48,7 @@ export class ReplaceStep extends Step {
42
48
  }
43
49
 
44
50
  merge(other) {
45
- if (!(other instanceof ReplaceStep) || other.structure != this.structure) return null
51
+ if (!(other instanceof ReplaceStep) || other.structure || this.structure) return null
46
52
 
47
53
  if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
48
54
  let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
@@ -84,11 +90,24 @@ export class ReplaceAroundStep extends Step {
84
90
  // it has in the [`ReplaceStep`](#transform.ReplaceStep) class.
85
91
  constructor(from, to, gapFrom, gapTo, slice, insert, structure) {
86
92
  super()
93
+ // :: number
94
+ // The start position of the replaced range.
87
95
  this.from = from
96
+ // :: number
97
+ // The end position of the replaced range.
88
98
  this.to = to
99
+ // :: number
100
+ // The start of preserved range.
89
101
  this.gapFrom = gapFrom
102
+ // :: number
103
+ // The end of preserved range.
90
104
  this.gapTo = gapTo
105
+ // :: Slice
106
+ // The slice to insert.
91
107
  this.slice = slice
108
+ // :: number
109
+ // The position in the slice where the preserved range should be
110
+ // inserted.
92
111
  this.insert = insert
93
112
  this.structure = !!structure
94
113
  }
package/src/structure.js CHANGED
@@ -276,9 +276,14 @@ export function dropPoint(doc, pos, slice) {
276
276
  for (let d = $pos.depth; d >= 0; d--) {
277
277
  let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1
278
278
  let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0)
279
- if (pass == 1
280
- ? $pos.node(d).canReplace(insertPos, insertPos, content)
281
- : $pos.node(d).contentMatchAt(insertPos).findWrapping(content.firstChild.type))
279
+ let parent = $pos.node(d), fits = false
280
+ if (pass == 1) {
281
+ fits = parent.canReplace(insertPos, insertPos, content)
282
+ } else {
283
+ let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type)
284
+ fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0])
285
+ }
286
+ if (fits)
282
287
  return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1)
283
288
  }
284
289
  }