mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
add basic support for components
This commit is contained in:
parent
c2bd2b21fa
commit
3470a7be1c
29
packages/core/src/ComponentView.ts
Normal file
29
packages/core/src/ComponentView.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
export default class ComponentView {
|
||||
// @ts-ignore
|
||||
constructor(component, options) {
|
||||
// @ts-ignore
|
||||
this.component = component
|
||||
// @ts-ignore
|
||||
this.dom = this.createDOM()
|
||||
// @ts-ignore
|
||||
this.contentDOM = this.vm.$refs.content
|
||||
}
|
||||
|
||||
createDOM() {
|
||||
// @ts-ignore
|
||||
const Component = Vue.extend(this.component)
|
||||
|
||||
// @ts-ignore
|
||||
this.vm = new Component({
|
||||
// parent: this.parent,
|
||||
// propsData: props,
|
||||
}).$mount()
|
||||
|
||||
// @ts-ignore
|
||||
return this.vm.$el
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -170,6 +170,8 @@ export class Editor extends EventEmitter {
|
||||
plugins: this.plugins,
|
||||
}),
|
||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||
// @ts-ignore
|
||||
nodeViews: this.extensionManager.nodeViews,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
import collect from 'collect.js'
|
||||
import { keymap } from 'prosemirror-keymap'
|
||||
import { inputRules } from 'prosemirror-inputrules'
|
||||
import { NodeSpec } from 'prosemirror-model'
|
||||
import { Editor, CommandSpec } from './Editor'
|
||||
import Extension from './Extension'
|
||||
import Node from './Node'
|
||||
import ComponentView from './ComponentView'
|
||||
|
||||
export default class ExtensionManager {
|
||||
|
||||
@ -85,4 +87,21 @@ export default class ExtensionManager {
|
||||
.toArray()
|
||||
}
|
||||
|
||||
get nodeViews() {
|
||||
return collect(this.nodes)
|
||||
.filter((schema: any) => schema.toVue)
|
||||
.map((schema: any) => {
|
||||
// @ts-ignore
|
||||
return (node, view, getPos, decorations) => {
|
||||
return new ComponentView(schema.toVue, {
|
||||
node,
|
||||
view,
|
||||
getPos,
|
||||
decorations,
|
||||
})
|
||||
}
|
||||
})
|
||||
.all()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { NodeSpec } from 'prosemirror-model'
|
||||
import ParagraphComponent from './paragraph.vue'
|
||||
|
||||
export default class Paragraph extends Node {
|
||||
|
||||
@ -11,6 +12,7 @@ export default class Paragraph extends Node {
|
||||
group: 'block',
|
||||
parseDOM: [{ tag: 'p' }],
|
||||
toDOM: () => ['p', 0],
|
||||
// toVue: ParagraphComponent,
|
||||
}
|
||||
}
|
||||
|
||||
|
9
packages/extension-paragraph/paragraph.vue
Normal file
9
packages/extension-paragraph/paragraph.vue
Normal file
@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<p ref="content"></p>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
}
|
||||
</script>
|
4
shims/vue.d.ts
vendored
Normal file
4
shims/vue.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
declare module "*.vue" {
|
||||
import Vue from "vue";
|
||||
export default Vue;
|
||||
}
|
@ -25,6 +25,9 @@
|
||||
"scripthost"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"./shims/vue.d.ts"
|
||||
],
|
||||
"include": [
|
||||
"docs/src/**/*.ts",
|
||||
"docs/src/**/*.tsx",
|
||||
|
Loading…
Reference in New Issue
Block a user