add basic support for components
This commit is contained in:
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,
|
plugins: this.plugins,
|
||||||
}),
|
}),
|
||||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||||
|
// @ts-ignore
|
||||||
|
nodeViews: this.extensionManager.nodeViews,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import collect from 'collect.js'
|
import collect from 'collect.js'
|
||||||
import { keymap } from 'prosemirror-keymap'
|
import { keymap } from 'prosemirror-keymap'
|
||||||
import { inputRules } from 'prosemirror-inputrules'
|
import { inputRules } from 'prosemirror-inputrules'
|
||||||
|
import { NodeSpec } from 'prosemirror-model'
|
||||||
import { Editor, CommandSpec } from './Editor'
|
import { Editor, CommandSpec } from './Editor'
|
||||||
import Extension from './Extension'
|
import Extension from './Extension'
|
||||||
import Node from './Node'
|
import Node from './Node'
|
||||||
|
import ComponentView from './ComponentView'
|
||||||
|
|
||||||
export default class ExtensionManager {
|
export default class ExtensionManager {
|
||||||
|
|
||||||
@@ -85,4 +87,21 @@ export default class ExtensionManager {
|
|||||||
.toArray()
|
.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 { Node } from '@tiptap/core'
|
||||||
import { NodeSpec } from 'prosemirror-model'
|
import { NodeSpec } from 'prosemirror-model'
|
||||||
|
import ParagraphComponent from './paragraph.vue'
|
||||||
|
|
||||||
export default class Paragraph extends Node {
|
export default class Paragraph extends Node {
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ export default class Paragraph extends Node {
|
|||||||
group: 'block',
|
group: 'block',
|
||||||
parseDOM: [{ tag: 'p' }],
|
parseDOM: [{ tag: 'p' }],
|
||||||
toDOM: () => ['p', 0],
|
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"
|
"scripthost"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"files": [
|
||||||
|
"./shims/vue.d.ts"
|
||||||
|
],
|
||||||
"include": [
|
"include": [
|
||||||
"docs/src/**/*.ts",
|
"docs/src/**/*.ts",
|
||||||
"docs/src/**/*.tsx",
|
"docs/src/**/*.tsx",
|
||||||
|
|||||||
Reference in New Issue
Block a user