mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
refactoring
This commit is contained in:
parent
18d3cbdef8
commit
3cb4b0f71f
22
docs/src/demos/Nodes/Mention/MentionList.vue
Normal file
22
docs/src/demos/Nodes/Mention/MentionList.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div v-for="(item, index) in items" :key="index">
|
||||||
|
{{ item }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
items: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
@ -5,14 +5,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue'
|
|
||||||
import tippy, { sticky } from 'tippy.js'
|
import tippy, { sticky } from 'tippy.js'
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor, EditorContent, VueRenderer } from '@tiptap/vue'
|
||||||
import { EditorContent } from '@tiptap/vue'
|
|
||||||
import Document from '@tiptap/extension-document'
|
import Document from '@tiptap/extension-document'
|
||||||
import Paragraph from '@tiptap/extension-paragraph'
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import Mention from '@tiptap/extension-mention'
|
import Mention from '@tiptap/extension-mention'
|
||||||
|
import MentionList from './MentionList'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -33,47 +32,37 @@ export default {
|
|||||||
Text,
|
Text,
|
||||||
Mention.configure({
|
Mention.configure({
|
||||||
items: query => {
|
items: query => {
|
||||||
console.log('items', query)
|
return ['foo', 'bar']
|
||||||
|
|
||||||
return [query]
|
|
||||||
},
|
},
|
||||||
renderer: () => {
|
renderer: () => {
|
||||||
|
let component
|
||||||
let popup
|
let popup
|
||||||
const Component = new (Vue.extend({
|
|
||||||
template: '<div>YAAAAY</div>',
|
|
||||||
}))().$mount()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onStart(props) {
|
onStart(props) {
|
||||||
console.log('start')
|
component = new VueRenderer(MentionList, props)
|
||||||
|
|
||||||
popup = tippy('.app', {
|
popup = tippy('.app', {
|
||||||
getReferenceClientRect: () => props.virtualNode.getBoundingClientRect(),
|
getReferenceClientRect: () => props.virtualNode.getBoundingClientRect(),
|
||||||
appendTo: () => document.body,
|
appendTo: () => document.body,
|
||||||
interactive: true,
|
interactive: true,
|
||||||
sticky: true, // make sure position of tippy is updated when content changes
|
sticky: true,
|
||||||
plugins: [sticky],
|
plugins: [sticky],
|
||||||
content: Component.$el,
|
content: component.element,
|
||||||
trigger: 'mouseenter', // manual
|
trigger: 'mouseenter',
|
||||||
showOnCreate: true,
|
showOnCreate: true,
|
||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
placement: 'top-start',
|
placement: 'top-start',
|
||||||
inertia: true,
|
inertia: true,
|
||||||
duration: [400, 200],
|
duration: [400, 200],
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
onUpdate(props) {
|
onUpdate(props) {
|
||||||
console.log('update', props)
|
component.update(props)
|
||||||
},
|
},
|
||||||
onExit(props) {
|
onExit() {
|
||||||
console.log('exit', props)
|
popup[0].destroy()
|
||||||
|
component.destroy()
|
||||||
if (popup) {
|
|
||||||
popup[0].destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.$destroy()
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
41
packages/vue/src/VueRenderer.ts
Normal file
41
packages/vue/src/VueRenderer.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import { VueConstructor } from 'vue/types/umd'
|
||||||
|
|
||||||
|
export default class VueRenderer {
|
||||||
|
vm!: Vue
|
||||||
|
|
||||||
|
constructor(component: Vue | VueConstructor, props: any) {
|
||||||
|
const Component = Vue.extend(component)
|
||||||
|
|
||||||
|
this.vm = new Component({
|
||||||
|
// parent,
|
||||||
|
propsData: props,
|
||||||
|
}).$mount()
|
||||||
|
}
|
||||||
|
|
||||||
|
get element() {
|
||||||
|
return this.vm.$el
|
||||||
|
}
|
||||||
|
|
||||||
|
update(data: { [key: string]: any } = {}) {
|
||||||
|
if (!this.vm.$props) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevents `Avoid mutating a prop directly` error message
|
||||||
|
const originalSilent = Vue.config.silent
|
||||||
|
Vue.config.silent = true
|
||||||
|
|
||||||
|
Object
|
||||||
|
.entries(data)
|
||||||
|
.forEach(([key, value]) => {
|
||||||
|
this.vm.$props[key] = value
|
||||||
|
})
|
||||||
|
|
||||||
|
Vue.config.silent = originalSilent
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.vm.$destroy()
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
export * from '@tiptap/core'
|
export * from '@tiptap/core'
|
||||||
|
export { default as VueRenderer } from './VueRenderer'
|
||||||
export { default as VueNodeViewRenderer } from './VueNodeViewRenderer'
|
export { default as VueNodeViewRenderer } from './VueNodeViewRenderer'
|
||||||
export { default as EditorContent } from './components/EditorContent'
|
export { default as EditorContent } from './components/EditorContent'
|
||||||
|
Loading…
Reference in New Issue
Block a user