mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
fix: make shouldShow and pluginKey option for menus, fix #1779
This commit is contained in:
parent
1618e8ee85
commit
70a328bd3d
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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({
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user