prosemirror-view 1.18.4 → 1.18.8

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-view",
3
- "version": "1.18.4",
3
+ "version": "1.18.8",
4
4
  "description": "ProseMirror's view component",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
package/src/domchange.js CHANGED
@@ -242,7 +242,7 @@ export function readDOMChange(view, from, to, typeOver, addedNodes) {
242
242
  // Edge just doesn't move the cursor forward when you start typing
243
243
  // in an empty block or between br nodes.
244
244
  if (sel && !(browser.chrome && browser.android && view.composing && sel.empty &&
245
- (change.from != change.toB || view.lastAndroidDelete < Date.now() - 100) &&
245
+ (change.start != change.endB || view.lastAndroidDelete < Date.now() - 100) &&
246
246
  (sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1) ||
247
247
  browser.ie && sel.empty && sel.head == chFrom))
248
248
  tr.setSelection(sel)
package/src/domcoords.js CHANGED
@@ -250,7 +250,10 @@ export function posAtCoords(view, coords) {
250
250
  if (!elt) return null
251
251
  }
252
252
  // Safari's caretRangeFromPoint returns nonsense when on a draggable element
253
- if (browser.safari && elt.draggable) node = offset = null
253
+ if (browser.safari) {
254
+ for (let p = elt; node && p; p = parentNode(p))
255
+ if (p.draggable) node = offset = null
256
+ }
254
257
  elt = targetKludge(elt, coords)
255
258
  if (node) {
256
259
  if (browser.gecko && node.nodeType == 1) {
package/src/input.js CHANGED
@@ -100,7 +100,7 @@ export function dispatchEvent(view, event) {
100
100
  editHandlers.keydown = (view, event) => {
101
101
  view.shiftKey = event.keyCode == 16 || event.shiftKey
102
102
  if (inOrNearComposition(view, event)) return
103
- view.domObserver.forceFlush()
103
+ if (event.keyCode != 229) view.domObserver.forceFlush()
104
104
  view.lastKeyCode = event.keyCode
105
105
  view.lastKeyCodeTime = Date.now()
106
106
  // On iOS, if we preventDefault enter key presses, the virtual
@@ -220,10 +220,11 @@ function handleDoubleClick(view, pos, inside, event) {
220
220
  function handleTripleClick(view, pos, inside, event) {
221
221
  return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) ||
222
222
  view.someProp("handleTripleClick", f => f(view, pos, event)) ||
223
- defaultTripleClick(view, inside)
223
+ defaultTripleClick(view, inside, event)
224
224
  }
225
225
 
226
- function defaultTripleClick(view, inside) {
226
+ function defaultTripleClick(view, inside, event) {
227
+ if (event.button != 0) return false
227
228
  let doc = view.state.doc
228
229
  if (inside == -1) {
229
230
  if (doc.inlineContent) {
@@ -284,7 +285,7 @@ class MouseDown {
284
285
  this.event = event
285
286
  this.flushed = flushed
286
287
  this.selectNode = event[selectNodeModifier]
287
- this.allowDefault = event.shiftKey
288
+ this.allowDefault = event.shiftKey || event.button != 0
288
289
 
289
290
  let targetNode, targetPos
290
291
  if (pos.inside > -1) {
@@ -302,8 +303,10 @@ class MouseDown {
302
303
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null
303
304
  this.target = targetDesc ? targetDesc.dom : null
304
305
 
305
- if (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
306
- view.state.selection instanceof NodeSelection && targetPos == view.state.selection.from)
306
+ let {selection} = view.state
307
+ if (event.button == 0 &&
308
+ targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
309
+ selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
307
310
  this.mightDrag = {node: targetNode,
308
311
  pos: targetPos,
309
312
  addAttr: this.target && !this.target.draggable,
@@ -360,7 +363,8 @@ class MouseDown {
360
363
  // thus doesn't get a reaction from ProseMirror. This
361
364
  // works around that.
362
365
  (browser.chrome && !(this.view.state.selection instanceof TextSelection) &&
363
- (pos.pos == this.view.state.selection.from || pos.pos == this.view.state.selection.to))) {
366
+ Math.min(Math.abs(pos.pos - this.view.state.selection.from),
367
+ Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
364
368
  updateSelection(this.view, Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer")
365
369
  event.preventDefault()
366
370
  } else {
@@ -606,9 +610,13 @@ editHandlers.drop = (view, e) => {
606
610
  if (!eventPos) return
607
611
  let $mouse = view.state.doc.resolve(eventPos.pos)
608
612
  if (!$mouse) return
609
- let slice = dragging && dragging.slice ||
610
- parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
611
- brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse)
613
+ let slice = dragging && dragging.slice
614
+ if (slice) {
615
+ view.someProp("transformPasted", f => { slice = f(slice) })
616
+ } else {
617
+ slice = parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
618
+ brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse)
619
+ }
612
620
  let move = dragging && !e[dragCopyModifier]
613
621
  if (view.someProp("handleDrop", f => f(view, e, slice || Slice.empty, move))) {
614
622
  e.preventDefault()
package/src/viewdesc.js CHANGED
@@ -113,7 +113,7 @@ class ViewDesc {
113
113
  matchesWidget() { return false }
114
114
  matchesMark() { return false }
115
115
  matchesNode() { return false }
116
- matchesHack() { return false }
116
+ matchesHack(_nodeName) { return false }
117
117
 
118
118
  get beforePosition() { return false }
119
119
 
@@ -374,14 +374,28 @@ class ViewDesc {
374
374
  if (node.nodeType == 3) {
375
375
  brKludge = offset && node.nodeValue[offset - 1] == "\n"
376
376
  // Issue #1128
377
- if (brKludge && offset == node.nodeValue.length &&
378
- node.nextSibling && node.nextSibling.nodeName == "BR")
379
- anchorDOM = headDOM = {node: node.parentNode, offset: domIndex(node) + 1}
377
+ if (brKludge && offset == node.nodeValue.length) {
378
+ for (let scan = node, after; scan; scan = scan.parentNode) {
379
+ if (after = scan.nextSibling) {
380
+ if (after.nodeName == "BR")
381
+ anchorDOM = headDOM = {node: after.parentNode, offset: domIndex(after) + 1}
382
+ break
383
+ }
384
+ let desc = scan.pmViewDesc
385
+ if (desc && desc.node && desc.node.isBlock) break
386
+ }
387
+ }
380
388
  } else {
381
389
  let prev = node.childNodes[offset - 1]
382
390
  brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false")
383
391
  }
384
392
  }
393
+ // Firefox can act strangely when the selection is in front of an
394
+ // uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
395
+ if (browser.gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) {
396
+ let after = domSel.focusNode.childNodes[domSel.focusOffset]
397
+ if (after && after.contentEditable == "false") force = true
398
+ }
385
399
 
386
400
  if (!(force || brKludge && browser.safari) &&
387
401
  isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) &&
@@ -838,14 +852,20 @@ class TextViewDesc extends NodeViewDesc {
838
852
  return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view)
839
853
  }
840
854
 
855
+ markDirty(from, to) {
856
+ super.markDirty(from, to)
857
+ if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length))
858
+ this.dirty = NODE_DIRTY
859
+ }
860
+
841
861
  get domAtom() { return false }
842
862
  }
843
863
 
844
- // A dummy desc used to tag trailing BR or span nodes created to work
864
+ // A dummy desc used to tag trailing BR or IMG nodes created to work
845
865
  // around contentEditable terribleness.
846
- class BRHackViewDesc extends ViewDesc {
866
+ class TrailingHackViewDesc extends ViewDesc {
847
867
  parseRule() { return {ignore: true} }
848
- matchesHack() { return this.dirty == NOT_DIRTY }
868
+ matchesHack(nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName }
849
869
  get domAtom() { return true }
850
870
  }
851
871
 
@@ -1182,13 +1202,20 @@ class ViewTreeUpdater {
1182
1202
  if (!lastChild || // Empty textblock
1183
1203
  !(lastChild instanceof TextViewDesc) ||
1184
1204
  /\n$/.test(lastChild.node.text)) {
1185
- if (this.index < this.top.children.length && this.top.children[this.index].matchesHack()) {
1186
- this.index++
1187
- } else {
1188
- let dom = document.createElement("br")
1189
- this.top.children.splice(this.index++, 0, new BRHackViewDesc(this.top, nothing, dom, null))
1190
- this.changed = true
1191
- }
1205
+ // Avoid a bug in Safari's cursor drawing (#1165)
1206
+ if (browser.safari && lastChild && lastChild.dom.contentEditable == "false")
1207
+ this.addHackNode("IMG")
1208
+ this.addHackNode("BR")
1209
+ }
1210
+ }
1211
+
1212
+ addHackNode(nodeName) {
1213
+ if (this.index < this.top.children.length && this.top.children[this.index].matchesHack(nodeName)) {
1214
+ this.index++
1215
+ } else {
1216
+ let dom = document.createElement(nodeName)
1217
+ this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null))
1218
+ this.changed = true
1192
1219
  }
1193
1220
  }
1194
1221
  }