Skip to content

Commit

Permalink
Merge pull request #1253 from zcuric/main
Browse files Browse the repository at this point in the history
feat: better types for Vue 2
  • Loading branch information
philippkuehn committed May 4, 2021
2 parents b3fb022 + 23a152a commit a96e0c2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
17 changes: 11 additions & 6 deletions packages/vue-2/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Vue, { PropType } from 'vue'
import Vue, { Component, PropType } from 'vue'
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'

export const BubbleMenu = Vue.extend({
interface BubleMenuInterface extends Vue {
tippyOptions: BubbleMenuPluginProps['tippyOptions'],
editor: BubbleMenuPluginProps['editor']
}

export const BubbleMenu: Component = {
name: 'BubbleMenu',

props: {
Expand All @@ -19,7 +24,7 @@ export const BubbleMenu = Vue.extend({
watch: {
editor: {
immediate: true,
handler(editor: BubbleMenuPluginProps['editor']) {
handler(this: BubleMenuInterface, editor: BubbleMenuPluginProps['editor']) {
if (!editor) {
return
}
Expand All @@ -35,11 +40,11 @@ export const BubbleMenu = Vue.extend({
},
},

render(createElement) {
render(this: BubleMenuInterface, createElement) {
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
},

beforeDestroy() {
beforeDestroy(this: BubleMenuInterface) {
this.editor.unregisterPlugin(BubbleMenuPluginKey)
},
})
}
15 changes: 10 additions & 5 deletions packages/vue-2/src/EditorContent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Vue, { PropType } from 'vue'
import Vue, { PropType, Component } from 'vue'
import { Editor } from './Editor'

export const EditorContent = Vue.extend({
interface EditorContentInterface extends Vue {
editor: Editor
}

/** @this Component */
export const EditorContent: Component = {
name: 'EditorContent',

props: {
Expand All @@ -14,7 +19,7 @@ export const EditorContent = Vue.extend({
watch: {
editor: {
immediate: true,
handler(editor: Editor) {
handler(this: EditorContentInterface, editor: Editor) {
if (editor && editor.options.element) {
this.$nextTick(() => {
const element = this.$el
Expand All @@ -24,7 +29,6 @@ export const EditorContent = Vue.extend({
}

element.appendChild(editor.options.element.firstChild)

editor.contentComponent = this

editor.setOptions({
Expand All @@ -43,6 +47,7 @@ export const EditorContent = Vue.extend({
},

beforeDestroy() {
// @ts-ignore
const { editor } = this

if (!editor.isDestroyed) {
Expand All @@ -65,4 +70,4 @@ export const EditorContent = Vue.extend({
element: newElement,
})
},
})
}
17 changes: 11 additions & 6 deletions packages/vue-2/src/FloatingMenu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Vue, { PropType } from 'vue'
import Vue, { Component, PropType } from 'vue'
import { FloatingMenuPlugin, FloatingMenuPluginKey, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'

export const FloatingMenu = Vue.extend({
interface FloatingMenuInterface extends Vue {
tippyOptions: FloatingMenuPluginProps['tippyOptions'],
editor: FloatingMenuPluginProps['editor']
}

export const FloatingMenu: Component = {
name: 'FloatingMenu',

props: {
Expand All @@ -19,7 +24,7 @@ export const FloatingMenu = Vue.extend({
watch: {
editor: {
immediate: true,
handler(editor: FloatingMenuPluginProps['editor']) {
handler(this: FloatingMenuInterface, editor: FloatingMenuPluginProps['editor']) {
if (!editor) {
return
}
Expand All @@ -35,11 +40,11 @@ export const FloatingMenu = Vue.extend({
},
},

render(createElement) {
render(this: FloatingMenuInterface, createElement) {
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
},

beforeDestroy() {
beforeDestroy(this: FloatingMenuInterface) {
this.editor.unregisterPlugin(FloatingMenuPluginKey)
},
})
}
12 changes: 8 additions & 4 deletions packages/vue-2/src/NodeViewContent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import Vue from 'vue'
import Vue, { Component } from 'vue'

export const NodeViewContent = Vue.extend({
interface NodeViewContentInterface extends Vue {
as: string
}

export const NodeViewContent: Component = {
props: {
as: {
type: String,
default: 'div',
},
},

render(createElement) {
render(this: NodeViewContentInterface, createElement) {
return createElement(
this.as, {
style: {
Expand All @@ -20,4 +24,4 @@ export const NodeViewContent = Vue.extend({
},
)
},
})
}
20 changes: 14 additions & 6 deletions packages/vue-2/src/NodeViewWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Vue from 'vue'
import Vue, { Component } from 'vue'

export const NodeViewWrapper = Vue.extend({
interface DecorationClass {
value: string
}

interface NodeViewWrapperInterface extends Vue {
as: string,
decorationClasses: DecorationClass,
onDragStart: Function
}

export const NodeViewWrapper: Component = {
props: {
as: {
type: String,
Expand All @@ -10,10 +20,9 @@ export const NodeViewWrapper = Vue.extend({

inject: ['onDragStart', 'decorationClasses'],

render(createElement) {
render(this: NodeViewWrapperInterface, createElement) {
return createElement(
this.as, {
// @ts-ignore
class: this.decorationClasses.value,
style: {
whiteSpace: 'normal',
Expand All @@ -22,11 +31,10 @@ export const NodeViewWrapper = Vue.extend({
'data-node-view-wrapper': '',
},
on: {
// @ts-ignore
dragstart: this.onDragStart,
},
},
this.$slots.default,
)
},
})
}

0 comments on commit a96e0c2

Please sign in to comment.