feat: add tippyOptions prop

This commit is contained in:
Philipp Kühn
2021-04-16 12:42:56 +02:00
parent 398fc7f210
commit 9a56f666a1
10 changed files with 56 additions and 12 deletions

View File

@@ -1,11 +1,12 @@
import { Editor, posToClientRect } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import tippy, { Instance } from 'tippy.js'
import tippy, { Instance, Props } from 'tippy.js'
export interface BubbleMenuPluginProps {
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
}
export type BubbleMenuViewProps = BubbleMenuPluginProps & {
@@ -23,14 +24,19 @@ export class BubbleMenuView {
public tippy!: Instance
constructor({ editor, element, view }: BubbleMenuViewProps) {
constructor({
editor,
element,
view,
tippyOptions,
}: BubbleMenuViewProps) {
this.editor = editor
this.element = element
this.view = view
this.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
this.editor.on('focus', this.focusHandler)
this.editor.on('blur', this.blurHandler)
this.createTooltip()
this.createTooltip(tippyOptions)
this.element.style.visibility = 'visible'
}
@@ -60,7 +66,7 @@ export class BubbleMenuView {
this.hide()
}
createTooltip() {
createTooltip(options: Partial<Props> = {}) {
this.tippy = tippy(this.view.dom, {
duration: 0,
getReferenceClientRect: null,
@@ -69,6 +75,7 @@ export class BubbleMenuView {
trigger: 'manual',
placement: 'top',
hideOnClick: 'toggle',
...options,
})
}