prosemirror-view 1.18.3 → 1.18.7

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.3",
3
+ "version": "1.18.7",
4
4
  "description": "ProseMirror's view component",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
package/src/dom.js CHANGED
@@ -8,7 +8,7 @@ export const domIndex = function(node) {
8
8
  }
9
9
 
10
10
  export const parentNode = function(node) {
11
- let parent = node.parentNode
11
+ let parent = node.assignedSlot || node.parentNode
12
12
  return parent && parent.nodeType == 11 ? parent.host : parent
13
13
  }
14
14
 
package/src/domchange.js CHANGED
@@ -25,7 +25,7 @@ function parseBetween(view, from_, to_) {
25
25
  if (browser.chrome && view.lastKeyCode === 8) {
26
26
  for (let off = toOffset; off > fromOffset; off--) {
27
27
  let node = parent.childNodes[off - 1], desc = node.pmViewDesc
28
- if (node.nodeType == "BR" && !desc) { toOffset = off; break }
28
+ if (node.nodeName == "BR" && !desc) { toOffset = off; break }
29
29
  if (!desc || desc.size) break
30
30
  }
31
31
  }
@@ -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
@@ -266,12 +266,14 @@ handlers.mousedown = (view, event) => {
266
266
  let pos = view.posAtCoords(eventCoords(event))
267
267
  if (!pos) return
268
268
 
269
- if (type == "singleClick")
269
+ if (type == "singleClick") {
270
+ if (view.mouseDown) view.mouseDown.done()
270
271
  view.mouseDown = new MouseDown(view, pos, event, flushed)
271
- else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event))
272
+ } else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) {
272
273
  event.preventDefault()
273
- else
274
+ } else {
274
275
  setSelectionOrigin(view, "pointer")
276
+ }
275
277
  }
276
278
 
277
279
  class MouseDown {
@@ -300,8 +302,9 @@ class MouseDown {
300
302
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null
301
303
  this.target = targetDesc ? targetDesc.dom : null
302
304
 
305
+ let {selection} = view.state
303
306
  if (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
304
- view.state.selection instanceof NodeSelection && targetPos == view.state.selection.from)
307
+ selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
305
308
  this.mightDrag = {node: targetNode,
306
309
  pos: targetPos,
307
310
  addAttr: this.target && !this.target.draggable,
@@ -311,7 +314,9 @@ class MouseDown {
311
314
  this.view.domObserver.stop()
312
315
  if (this.mightDrag.addAttr) this.target.draggable = true
313
316
  if (this.mightDrag.setUneditable)
314
- setTimeout(() => this.target.setAttribute("contentEditable", "false"), 20)
317
+ setTimeout(() => {
318
+ if (this.view.mouseDown == this) this.target.setAttribute("contentEditable", "false")
319
+ }, 20)
315
320
  this.view.domObserver.start()
316
321
  }
317
322
 
@@ -356,7 +361,8 @@ class MouseDown {
356
361
  // thus doesn't get a reaction from ProseMirror. This
357
362
  // works around that.
358
363
  (browser.chrome && !(this.view.state.selection instanceof TextSelection) &&
359
- (pos.pos == this.view.state.selection.from || pos.pos == this.view.state.selection.to))) {
364
+ Math.min(Math.abs(pos.pos - this.view.state.selection.from),
365
+ Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
360
366
  updateSelection(this.view, Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer")
361
367
  event.preventDefault()
362
368
  } else {
@@ -369,6 +375,7 @@ class MouseDown {
369
375
  Math.abs(this.event.y - event.clientY) > 4))
370
376
  this.allowDefault = true
371
377
  setSelectionOrigin(this.view, "pointer")
378
+ if (event.buttons == 0) this.done()
372
379
  }
373
380
  }
374
381
 
@@ -576,6 +583,8 @@ handlers.dragstart = (view, e) => {
576
583
  let slice = view.state.selection.content(), {dom, text} = serializeForClipboard(view, slice)
577
584
  e.dataTransfer.clearData()
578
585
  e.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML)
586
+ // See https://github.com/ProseMirror/prosemirror/issues/1156
587
+ e.dataTransfer.effectAllowed = "copyMove"
579
588
  if (!brokenClipboardAPI) e.dataTransfer.setData("text/plain", text)
580
589
  view.dragging = new Dragging(slice, !e[dragCopyModifier])
581
590
  }
@@ -599,9 +608,13 @@ editHandlers.drop = (view, e) => {
599
608
  if (!eventPos) return
600
609
  let $mouse = view.state.doc.resolve(eventPos.pos)
601
610
  if (!$mouse) return
602
- let slice = dragging && dragging.slice ||
603
- parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
604
- brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse)
611
+ let slice = dragging && dragging.slice
612
+ if (slice) {
613
+ view.someProp("transformPasted", f => { slice = f(slice) })
614
+ } else {
615
+ slice = parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
616
+ brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse)
617
+ }
605
618
  let move = dragging && !e[dragCopyModifier]
606
619
  if (view.someProp("handleDrop", f => f(view, e, slice || Slice.empty, move))) {
607
620
  e.preventDefault()
package/src/viewdesc.js CHANGED
@@ -382,6 +382,12 @@ class ViewDesc {
382
382
  brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false")
383
383
  }
384
384
  }
385
+ // Firefox can act strangely when the selection is in front of an
386
+ // uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
387
+ if (browser.gecko && domSel.focusNode && domSel.focusNode != headDOM.node && domSel.focusNode.nodeType == 1) {
388
+ let after = domSel.focusNode.childNodes[domSel.focusOffset]
389
+ if (after && after.contentEditable == "false") force = true
390
+ }
385
391
 
386
392
  if (!(force || brKludge && browser.safari) &&
387
393
  isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset) &&
@@ -841,9 +847,9 @@ class TextViewDesc extends NodeViewDesc {
841
847
  get domAtom() { return false }
842
848
  }
843
849
 
844
- // A dummy desc used to tag trailing BR or span nodes created to work
850
+ // A dummy desc used to tag trailing BR or IMG nodes created to work
845
851
  // around contentEditable terribleness.
846
- class BRHackViewDesc extends ViewDesc {
852
+ class TrailingHackViewDesc extends ViewDesc {
847
853
  parseRule() { return {ignore: true} }
848
854
  matchesHack() { return this.dirty == NOT_DIRTY }
849
855
  get domAtom() { return true }
@@ -1186,7 +1192,7 @@ class ViewTreeUpdater {
1186
1192
  this.index++
1187
1193
  } else {
1188
1194
  let dom = document.createElement("br")
1189
- this.top.children.splice(this.index++, 0, new BRHackViewDesc(this.top, nothing, dom, null))
1195
+ this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null))
1190
1196
  this.changed = true
1191
1197
  }
1192
1198
  }