Merge branch 'drafts' into 'dev'

separate menu for images in editor

See merge request discoursio/discoursio-webapp!61
This commit is contained in:
Igor 2023-05-04 15:16:47 +00:00
commit 3b1a70f598

View File

@ -39,6 +39,7 @@ import { TextBubbleMenu } from './TextBubbleMenu'
import { ImageBubbleMenu } from './ImageBubbleMenu' import { ImageBubbleMenu } from './ImageBubbleMenu'
import { EditorFloatingMenu } from './EditorFloatingMenu' import { EditorFloatingMenu } from './EditorFloatingMenu'
import { useEditorContext } from '../../context/editor' import { useEditorContext } from '../../context/editor'
import { isTextSelection } from '@tiptap/core'
type EditorProps = { type EditorProps = {
shoutId: number shoutId: number
@ -145,14 +146,23 @@ export const Editor = (props: EditorProps) => {
pluginKey: 'textBubbleMenu', pluginKey: 'textBubbleMenu',
element: textBubbleMenuRef.current, element: textBubbleMenuRef.current,
shouldShow: ({ editor: e, view, state, oldState, from, to }) => { shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
return e.isFocused && !e.isActive('image') const { doc, selection } = state
const { empty } = selection
const isEmptyTextBlock = doc.textBetween(from, to).length === 0 && isTextSelection(selection)
if (!view.hasFocus() || empty || isEmptyTextBlock || e.isActive('image')) {
return false
}
return true
} }
}), }),
BubbleMenu.configure({ BubbleMenu.configure({
pluginKey: 'imageBubbleMenu', pluginKey: 'imageBubbleMenu',
element: imageBubbleMenuRef.current, element: imageBubbleMenuRef.current,
shouldShow: ({ editor: e, view, state, oldState, from, to }) => { shouldShow: ({ editor: e, view, state, oldState, from, to }) => {
return e.isFocused && e.isActive('image') return view.hasFocus() && e.isActive('image')
} }
}), }),
FloatingMenu.configure({ FloatingMenu.configure({