mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
38765c367d
Co-authored-by: Baptiste Leproux <leproux.baptiste@gmail.com>
41 lines
973 B
TypeScript
41 lines
973 B
TypeScript
import { Node, mergeAttributes } from '@tiptap/core'
|
|
import type { NodeViewRenderer } from '@tiptap/core'
|
|
import { VueNodeViewRenderer } from '@tiptap/vue-3'
|
|
import ImageUploadNodeComponent from './ImageUploadNode.vue'
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands<ReturnType> {
|
|
imageUpload: {
|
|
insertImageUpload: () => ReturnType
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Node.create({
|
|
name: 'imageUpload',
|
|
group: 'block',
|
|
atom: true,
|
|
draggable: true,
|
|
addAttributes() {
|
|
return {}
|
|
},
|
|
parseHTML() {
|
|
return [{
|
|
tag: 'div[data-type="image-upload"]'
|
|
}]
|
|
},
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['div', mergeAttributes(HTMLAttributes, { 'data-type': 'image-upload' })]
|
|
},
|
|
addNodeView(): NodeViewRenderer {
|
|
return VueNodeViewRenderer(ImageUploadNodeComponent)
|
|
},
|
|
addCommands() {
|
|
return {
|
|
insertImageUpload: () => ({ commands }) => {
|
|
return commands.insertContent({ type: this.name })
|
|
}
|
|
}
|
|
}
|
|
})
|