try to solve nested drag handles
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<node-view-wrapper>
|
<node-view-wrapper style="padding-left: 1rem">
|
||||||
<button @click="toggleChecked" contenteditable="false">
|
<button @click="toggleChecked" contenteditable="false">
|
||||||
toggle checked
|
toggle checked
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ export default Node.create({
|
|||||||
|
|
||||||
group: 'block',
|
group: 'block',
|
||||||
|
|
||||||
content: 'inline*',
|
// content: 'inline*',
|
||||||
|
content: 'block*',
|
||||||
|
|
||||||
draggable: true,
|
draggable: true,
|
||||||
|
|
||||||
selectable: false,
|
selectable: true,
|
||||||
|
|
||||||
addAttributes() {
|
addAttributes() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ export default {
|
|||||||
content: `
|
content: `
|
||||||
<p>paragraph</p>
|
<p>paragraph</p>
|
||||||
<div data-type="test">
|
<div data-type="test">
|
||||||
text
|
one
|
||||||
|
<div data-type="test">
|
||||||
|
two
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>paragraph</p>
|
<p>paragraph</p>
|
||||||
`,
|
`,
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { Editor, Node, NodeViewRendererProps } from '@tiptap/core'
|
import { Editor, Node, NodeViewRendererProps } from '@tiptap/core'
|
||||||
import { Decoration, NodeView } from 'prosemirror-view'
|
import { Decoration, NodeView } from 'prosemirror-view'
|
||||||
|
import { NodeSelection } from 'prosemirror-state'
|
||||||
import {
|
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
||||||
Node as ProseMirrorNode,
|
|
||||||
} from 'prosemirror-model'
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { VueConstructor } from 'vue/types/umd'
|
import { VueConstructor } from 'vue/types/umd'
|
||||||
|
|
||||||
@@ -39,6 +37,10 @@ class VueNodeView implements NodeView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createNodeViewWrapper() {
|
createNodeViewWrapper() {
|
||||||
|
const nodeview = this
|
||||||
|
const { view } = this.editor
|
||||||
|
const { getPos } = this
|
||||||
|
|
||||||
return Vue.extend({
|
return Vue.extend({
|
||||||
props: {
|
props: {
|
||||||
as: {
|
as: {
|
||||||
@@ -52,6 +54,21 @@ class VueNodeView implements NodeView {
|
|||||||
style: {
|
style: {
|
||||||
whiteSpace: 'normal',
|
whiteSpace: 'normal',
|
||||||
},
|
},
|
||||||
|
// attrs: {
|
||||||
|
// // draggable: false,
|
||||||
|
// contenteditable: false,
|
||||||
|
// },
|
||||||
|
on: {
|
||||||
|
dragstart: (event: Event) => {
|
||||||
|
const target = (event.target as HTMLElement)
|
||||||
|
|
||||||
|
if (nodeview.contentDOM?.contains(target)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, getPos())))
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
this.$slots.default,
|
this.$slots.default,
|
||||||
)
|
)
|
||||||
@@ -127,6 +144,7 @@ class VueNodeView implements NodeView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stopEvent(event: Event) {
|
stopEvent(event: Event) {
|
||||||
|
const target = (event.target as HTMLElement)
|
||||||
const isDraggable = this.node.type.spec.draggable
|
const isDraggable = this.node.type.spec.draggable
|
||||||
const isCopyEvent = event.type === 'copy'
|
const isCopyEvent = event.type === 'copy'
|
||||||
const isPasteEvent = event.type === 'paste'
|
const isPasteEvent = event.type === 'paste'
|
||||||
@@ -138,10 +156,11 @@ class VueNodeView implements NodeView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDraggable && !this.isDragging && event.type === 'mousedown') {
|
if (isDraggable && !this.isDragging && event.type === 'mousedown') {
|
||||||
const target = (event.target as HTMLElement)
|
|
||||||
const dragHandle = target.closest('[data-drag-handle]')
|
const dragHandle = target.closest('[data-drag-handle]')
|
||||||
|
// const isValidDragHandle = dragHandle
|
||||||
|
// && (this.dom === dragHandle || (this.dom.contains(dragHandle) && !this.contentDOM?.contains(dragHandle)))
|
||||||
const isValidDragHandle = dragHandle
|
const isValidDragHandle = dragHandle
|
||||||
&& (this.dom === dragHandle || this.dom.contains(dragHandle))
|
&& (this.dom === dragHandle || (this.dom.contains(dragHandle)))
|
||||||
|
|
||||||
if (isValidDragHandle) {
|
if (isValidDragHandle) {
|
||||||
this.isDragging = true
|
this.isDragging = true
|
||||||
@@ -173,6 +192,18 @@ class VueNodeView implements NodeView {
|
|||||||
return contentDOMHasChanged
|
return contentDOMHasChanged
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectNode() {
|
||||||
|
// this.updateComponentProps({
|
||||||
|
// selected: true,
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
deselectNode() {
|
||||||
|
// this.updateComponentProps({
|
||||||
|
// selected: false,
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
update(node: ProseMirrorNode, decorations: Decoration[]) {
|
update(node: ProseMirrorNode, decorations: Decoration[]) {
|
||||||
if (node.type !== this.node.type) {
|
if (node.type !== this.node.type) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user