prosemirror-view
Advanced tools
Comparing version 1.32.3 to 1.32.4
@@ -469,2 +469,3 @@ import { EditorState, Transaction, Selection, Plugin } from 'prosemirror-state'; | ||
private updatePluginViews; | ||
private updateDraggedNode; | ||
/** | ||
@@ -471,0 +472,0 @@ Goes over the values of a prop, first those provided directly, |
{ | ||
"name": "prosemirror-view", | ||
"version": "1.32.3", | ||
"version": "1.32.4", | ||
"description": "ProseMirror's view component", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -357,2 +357,4 @@ import {Fragment, DOMParser, ParseRule, Node, Mark, ResolvedPos} from "prosemirror-model" | ||
start -= move | ||
if (start && start < b.size && isSurrogatePair(b.textBetween(start - 1, start + 1))) | ||
start += move ? 1 : -1 | ||
endB = start + (endB - endA) | ||
@@ -363,2 +365,4 @@ endA = start | ||
start -= move | ||
if (start && start < a.size && isSurrogatePair(a.textBetween(start - 1, start + 1))) | ||
start += move ? 1 : -1 | ||
endA = start + (endA - endB) | ||
@@ -369,1 +373,7 @@ endB = start | ||
} | ||
function isSurrogatePair(str: string) { | ||
if (str.length != 2) return false | ||
let a = str.charCodeAt(0), b = str.charCodeAt(1) | ||
return a >= 0xDC00 && a <= 0xDFFF && b >= 0xD800 && b <= 0xDBFF | ||
} |
@@ -7,3 +7,4 @@ import {NodeSelection, EditorState, Plugin, PluginView, Transaction, Selection} from "prosemirror-state" | ||
import {docViewDesc, ViewDesc, NodeView, NodeViewDesc} from "./viewdesc" | ||
import {initInput, destroyInput, dispatchEvent, ensureListeners, clearComposition, InputState, doPaste} from "./input" | ||
import {initInput, destroyInput, dispatchEvent, ensureListeners, clearComposition, | ||
InputState, doPaste, Dragging} from "./input" | ||
import {selectionToDOM, anchorInRightPlace, syncNodeSelection} from "./selection" | ||
@@ -223,2 +224,4 @@ import {Decoration, viewDecorations, DecorationSource} from "./decoration" | ||
this.updatePluginViews(prev) | ||
if ((this.dragging as Dragging)?.node && !prev.doc.eq(state.doc)) | ||
this.updateDraggedNode(this.dragging as Dragging, prev) | ||
@@ -272,2 +275,15 @@ if (scroll == "reset") { | ||
private updateDraggedNode(dragging: Dragging, prev: EditorState) { | ||
let sel = dragging.node!, found = -1 | ||
if (this.state.doc.nodeAt(sel.from) == sel.node) { | ||
found = sel.from | ||
} else { | ||
let movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size) | ||
let moved = movedPos > 0 && this.state.doc.nodeAt(movedPos) | ||
if (moved == sel.node) found = movedPos | ||
} | ||
this.dragging = new Dragging(dragging.slice, dragging.move, | ||
found < 0 ? undefined : NodeSelection.create(this.state.doc, found)) | ||
} | ||
/// Goes over the values of a prop, first those provided directly, | ||
@@ -274,0 +290,0 @@ /// then those from plugins given to the view, then from plugins in |
@@ -633,4 +633,4 @@ import {Selection, NodeSelection, TextSelection} from "prosemirror-state" | ||
class Dragging { | ||
constructor(readonly slice: Slice, readonly move: boolean) {} | ||
export class Dragging { | ||
constructor(readonly slice: Slice, readonly move: boolean, readonly node?: NodeSelection) {} | ||
} | ||
@@ -648,12 +648,13 @@ | ||
let pos = sel.empty ? null : view.posAtCoords(eventCoords(event)) | ||
let node: undefined | NodeSelection | ||
if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof NodeSelection ? sel.to - 1: sel.to)) { | ||
// In selection | ||
} else if (mouseDown && mouseDown.mightDrag) { | ||
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos))) | ||
node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos) | ||
} else if (event.target && (event.target as HTMLElement).nodeType == 1) { | ||
let desc = view.docView.nearestDesc(event.target as HTMLElement, true) | ||
if (desc && desc.node.type.spec.draggable && desc != view.docView) | ||
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, desc.posBefore))) | ||
node = NodeSelection.create(view.state.doc, desc.posBefore) | ||
} | ||
let slice = view.state.selection.content(), {dom, text} = serializeForClipboard(view, slice) | ||
let slice = (node || view.state.selection).content(), {dom, text} = serializeForClipboard(view, slice) | ||
event.dataTransfer.clearData() | ||
@@ -664,3 +665,3 @@ event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML) | ||
if (!brokenClipboardAPI) event.dataTransfer.setData("text/plain", text) | ||
view.dragging = new Dragging(slice, !event[dragCopyModifier]) | ||
view.dragging = new Dragging(slice, !event[dragCopyModifier], node) | ||
} | ||
@@ -706,3 +707,7 @@ | ||
let tr = view.state.tr | ||
if (move) tr.deleteSelection() | ||
if (move) { | ||
let {node} = dragging as Dragging | ||
if (node) node.replace(tr) | ||
else tr.deleteSelection() | ||
} | ||
@@ -709,0 +714,0 @@ let pos = tr.mapping.map(insertPos) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
845717
17194