add node view playground
This commit is contained in:
@@ -120,7 +120,7 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(item => {
|
.filter(item => {
|
||||||
return ['vue', 'jsx', 'scss'].includes(item.extension)
|
return ['vue', 'ts', 'jsx', 'scss'].includes(item.extension)
|
||||||
})
|
})
|
||||||
.sortBy(item => item.path.split('/').length && !item.path.endsWith('index.vue'))
|
.sortBy(item => item.path.split('/').length && !item.path.endsWith('index.vue'))
|
||||||
.toArray()
|
.toArray()
|
||||||
|
|||||||
15
docs/src/demos/Examples/NodeView/Component.vue
Normal file
15
docs/src/demos/Examples/NodeView/Component.vue
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
node view
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
29
docs/src/demos/Examples/NodeView/Test.ts
Normal file
29
docs/src/demos/Examples/NodeView/Test.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { Node } from '@tiptap/core'
|
||||||
|
import { VueRenderer } from '@tiptap/vue'
|
||||||
|
import Component from './Component.vue'
|
||||||
|
|
||||||
|
export default Node.create({
|
||||||
|
name: 'test',
|
||||||
|
|
||||||
|
group: 'block',
|
||||||
|
|
||||||
|
draggable: true,
|
||||||
|
|
||||||
|
selectable: false,
|
||||||
|
|
||||||
|
parseHTML() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
tag: 'div[data-type="test"]',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
renderHTML() {
|
||||||
|
return ['div', { 'data-type': 'test' }]
|
||||||
|
},
|
||||||
|
|
||||||
|
addNodeView() {
|
||||||
|
return VueRenderer(Component)
|
||||||
|
},
|
||||||
|
})
|
||||||
65
docs/src/demos/Examples/NodeView/index.vue
Normal file
65
docs/src/demos/Examples/NodeView/index.vue
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="editor">
|
||||||
|
<editor-content :editor="editor" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Editor } from '@tiptap/core'
|
||||||
|
import { EditorContent } from '@tiptap/vue'
|
||||||
|
import Dropcursor from '@tiptap/extension-dropcursor'
|
||||||
|
import Document from '@tiptap/extension-document'
|
||||||
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
|
import Text from '@tiptap/extension-text'
|
||||||
|
import Test from './Test.ts'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
editor: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.editor = new Editor({
|
||||||
|
extensions: [
|
||||||
|
Dropcursor,
|
||||||
|
Document,
|
||||||
|
Paragraph,
|
||||||
|
Text,
|
||||||
|
Test,
|
||||||
|
],
|
||||||
|
content: `
|
||||||
|
<p>test</p>
|
||||||
|
<div data-type="test"></div>
|
||||||
|
<p>test</p>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.destroy()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
ul[data-type="taskList"] {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
> input {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
3
docs/src/docPages/examples/node-view.md
Normal file
3
docs/src/docPages/examples/node-view.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Node View
|
||||||
|
|
||||||
|
<demo name="Examples/NodeView" />
|
||||||
@@ -130,6 +130,7 @@ export default class ExtensionManager {
|
|||||||
getPos,
|
getPos,
|
||||||
decorations,
|
decorations,
|
||||||
HTMLAttributes,
|
HTMLAttributes,
|
||||||
|
extension,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ export type NodeViewRendererProps = {
|
|||||||
getPos: (() => number) | boolean,
|
getPos: (() => number) | boolean,
|
||||||
decorations: Decoration[],
|
decorations: Decoration[],
|
||||||
HTMLAttributes: { [key: string]: any },
|
HTMLAttributes: { [key: string]: any },
|
||||||
|
extension: Node,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { NodeViewRendererProps } from '@tiptap/core'
|
import { Node, NodeViewRendererProps } from '@tiptap/core'
|
||||||
import { NodeView } from 'prosemirror-view'
|
import { NodeView } from 'prosemirror-view'
|
||||||
|
|
||||||
|
import {
|
||||||
|
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'
|
||||||
|
|
||||||
@@ -7,12 +11,19 @@ class VueNodeView implements NodeView {
|
|||||||
|
|
||||||
vm!: Vue
|
vm!: Vue
|
||||||
|
|
||||||
|
extension!: Node
|
||||||
|
|
||||||
|
node!: ProseMirrorNode
|
||||||
|
|
||||||
constructor(component: Vue | VueConstructor, props: NodeViewRendererProps) {
|
constructor(component: Vue | VueConstructor, props: NodeViewRendererProps) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { node, editor, getPos } = props
|
const { node, editor, getPos } = props
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const { view } = editor
|
const { view } = editor
|
||||||
|
|
||||||
|
this.extension = props.extension
|
||||||
|
this.node = props.node
|
||||||
|
|
||||||
this.mount(component)
|
this.mount(component)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +44,17 @@ class VueNodeView implements NodeView {
|
|||||||
return this.vm.$refs.content as Element
|
return this.vm.$refs.content as Element
|
||||||
}
|
}
|
||||||
|
|
||||||
stopEvent() {
|
stopEvent(event: Event): boolean {
|
||||||
|
const isDraggable = this.node.type.spec.draggable
|
||||||
|
const isCopy = event.type === 'copy'
|
||||||
|
const isPaste = event.type === 'paste'
|
||||||
|
const isCut = event.type === 'cut'
|
||||||
|
const isDrag = event.type.startsWith('drag') || event.type === 'drop'
|
||||||
|
|
||||||
|
if ((isDraggable && isDrag) || isCopy || isPaste || isCut) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user