2019-10-03 21:56:41 +08:00
|
|
|
import { Node } from 'tiptap'
|
|
|
|
|
|
|
|
export default class DragItem extends Node {
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return 'drag_item'
|
|
|
|
}
|
|
|
|
|
|
|
|
get schema() {
|
|
|
|
return {
|
|
|
|
group: 'block',
|
|
|
|
draggable: true,
|
|
|
|
content: 'paragraph+',
|
|
|
|
toDOM: () => ['div', { 'data-type': this.name }, 0],
|
|
|
|
parseDOM: [{
|
|
|
|
tag: `[data-type="${this.name}"]`,
|
|
|
|
}],
|
|
|
|
}
|
|
|
|
}
|
2020-07-21 00:46:50 +08:00
|
|
|
// Attention! For the data-drag-handle to work, the component must contain another element with `ref="content"` somewhere (it can be invisible).
|
2019-10-03 21:56:41 +08:00
|
|
|
get view() {
|
|
|
|
return {
|
|
|
|
template: `
|
2019-10-04 17:08:37 +08:00
|
|
|
<div data-type="drag_item" contenteditable="false">
|
2019-10-03 21:56:41 +08:00
|
|
|
<div ref="content" contenteditable="true"></div>
|
2019-10-04 17:08:37 +08:00
|
|
|
<div data-drag-handle></div>
|
2019-10-03 21:56:41 +08:00
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|