fix: make shouldShow and pluginKey option for menus, fix #1779

This commit is contained in:
Philipp Kühn 2021-08-23 18:44:40 +02:00
parent 1618e8ee85
commit 70a328bd3d
4 changed files with 16 additions and 12 deletions

View File

@ -13,7 +13,7 @@ export interface BubbleMenuPluginProps {
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
shouldShow: ((props: {
shouldShow?: ((props: {
editor: Editor,
view: EditorView,
state: EditorState,
@ -140,7 +140,7 @@ export class BubbleMenuView {
const from = Math.min(...ranges.map(range => range.$from.pos))
const to = Math.max(...ranges.map(range => range.$to.pos))
const shouldShow = this.shouldShow({
const shouldShow = this.shouldShow?.({
editor: this.editor,
view,
state,

View File

@ -8,7 +8,7 @@ export interface FloatingMenuPluginProps {
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
shouldShow: ((props: {
shouldShow?: ((props: {
editor: Editor,
view: EditorView,
state: EditorState,
@ -122,7 +122,7 @@ export class FloatingMenuView {
return
}
const shouldShow = this.shouldShow({
const shouldShow = this.shouldShow?.({
editor: this.editor,
view,
state,

View File

@ -1,7 +1,9 @@
import React, { useEffect, useRef } from 'react'
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
export type BubbleMenuProps = Omit<BubbleMenuPluginProps, 'element'> & {
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
export type BubbleMenuProps = Omit<Optional<BubbleMenuPluginProps, 'pluginKey'>, 'element'> & {
className?: string,
}
@ -10,10 +12,10 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
useEffect(() => {
const {
pluginKey,
pluginKey = 'bubbleMenu',
editor,
tippyOptions,
shouldShow,
tippyOptions = {},
shouldShow = null,
} = props
editor.registerPlugin(BubbleMenuPlugin({

View File

@ -1,7 +1,9 @@
import React, { useEffect, useRef } from 'react'
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
export type FloatingMenuProps = Omit<FloatingMenuPluginProps, 'element'> & {
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
export type FloatingMenuProps = Omit<Optional<FloatingMenuPluginProps, 'pluginKey'>, 'element'> & {
className?: string,
}
@ -10,10 +12,10 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
useEffect(() => {
const {
pluginKey,
pluginKey = 'floatingMenu',
editor,
tippyOptions,
shouldShow,
tippyOptions = {},
shouldShow = null,
} = props
editor.registerPlugin(FloatingMenuPlugin({