fix: make shouldShow and pluginKey option for menus, fix #1779
This commit is contained in:
@@ -13,7 +13,7 @@ export interface BubbleMenuPluginProps {
|
|||||||
editor: Editor,
|
editor: Editor,
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
tippyOptions?: Partial<Props>,
|
tippyOptions?: Partial<Props>,
|
||||||
shouldShow: ((props: {
|
shouldShow?: ((props: {
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
view: EditorView,
|
view: EditorView,
|
||||||
state: EditorState,
|
state: EditorState,
|
||||||
@@ -140,7 +140,7 @@ export class BubbleMenuView {
|
|||||||
const from = Math.min(...ranges.map(range => range.$from.pos))
|
const from = Math.min(...ranges.map(range => range.$from.pos))
|
||||||
const to = Math.max(...ranges.map(range => range.$to.pos))
|
const to = Math.max(...ranges.map(range => range.$to.pos))
|
||||||
|
|
||||||
const shouldShow = this.shouldShow({
|
const shouldShow = this.shouldShow?.({
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
view,
|
view,
|
||||||
state,
|
state,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export interface FloatingMenuPluginProps {
|
|||||||
editor: Editor,
|
editor: Editor,
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
tippyOptions?: Partial<Props>,
|
tippyOptions?: Partial<Props>,
|
||||||
shouldShow: ((props: {
|
shouldShow?: ((props: {
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
view: EditorView,
|
view: EditorView,
|
||||||
state: EditorState,
|
state: EditorState,
|
||||||
@@ -122,7 +122,7 @@ export class FloatingMenuView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldShow = this.shouldShow({
|
const shouldShow = this.shouldShow?.({
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
view,
|
view,
|
||||||
state,
|
state,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import React, { useEffect, useRef } from 'react'
|
import React, { useEffect, useRef } from 'react'
|
||||||
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
|
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,
|
className?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,10 +12,10 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const {
|
const {
|
||||||
pluginKey,
|
pluginKey = 'bubbleMenu',
|
||||||
editor,
|
editor,
|
||||||
tippyOptions,
|
tippyOptions = {},
|
||||||
shouldShow,
|
shouldShow = null,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
editor.registerPlugin(BubbleMenuPlugin({
|
editor.registerPlugin(BubbleMenuPlugin({
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import React, { useEffect, useRef } from 'react'
|
import React, { useEffect, useRef } from 'react'
|
||||||
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
|
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,
|
className?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,10 +12,10 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const {
|
const {
|
||||||
pluginKey,
|
pluginKey = 'floatingMenu',
|
||||||
editor,
|
editor,
|
||||||
tippyOptions,
|
tippyOptions = {},
|
||||||
shouldShow,
|
shouldShow = null,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
editor.registerPlugin(FloatingMenuPlugin({
|
editor.registerPlugin(FloatingMenuPlugin({
|
||||||
|
|||||||
Reference in New Issue
Block a user