Add Link Bubble Menu fixes (#326)

This commit is contained in:
Ilya Y 2023-11-21 08:31:17 +03:00 committed by GitHub
parent 671e627ae5
commit e716dd9304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import styles from './LinkBubbleMenu.module.scss'
type Props = { type Props = {
editor: Editor editor: Editor
ref: (el: HTMLDivElement) => void ref: (el: HTMLDivElement) => void
shouldShow: boolean
onClose: () => void onClose: () => void
} }

View File

@ -146,6 +146,9 @@ const SimplifiedEditor = (props: Props) => {
const { empty } = selection const { empty } = selection
return !empty && shouldShowLinkBubbleMenu() return !empty && shouldShowLinkBubbleMenu()
}, },
tippyOptions: {
placement: 'bottom',
},
}), }),
ImageFigure, ImageFigure,
Image, Image,
@ -223,16 +226,21 @@ const SimplifiedEditor = (props: Props) => {
return return
} }
if (event.code === 'Escape' && editor()) {
handleHideLinkBubble()
}
if (event.code === 'Enter' && props.submitByCtrlEnter && (event.metaKey || event.ctrlKey)) { if (event.code === 'Enter' && props.submitByCtrlEnter && (event.metaKey || event.ctrlKey)) {
event.preventDefault() event.preventDefault()
props.onSubmit(html()) props.onSubmit(html())
handleClear() handleClear()
} }
if (event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !editor().state.selection.empty) { // if (event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !editor().state.selection.empty) {
event.preventDefault() // event.preventDefault()
setShouldShowLinkBubbleMenu(true) // handleShowLinkBubble()
} //
// }
} }
onMount(() => { onMount(() => {
@ -264,6 +272,12 @@ const SimplifiedEditor = (props: Props) => {
editor().chain().focus().run() editor().chain().focus().run()
setShouldShowLinkBubbleMenu(true) setShouldShowLinkBubbleMenu(true)
} }
const handleHideLinkBubble = () => {
editor().commands.focus()
setShouldShowLinkBubbleMenu(false)
}
return ( return (
<ShowOnlyOnClient> <ShowOnlyOnClient>
<div <div
@ -386,10 +400,9 @@ const SimplifiedEditor = (props: Props) => {
/> />
</Show> </Show>
<LinkBubbleMenuModule <LinkBubbleMenuModule
shouldShow={shouldShowLinkBubbleMenu()}
editor={editor()} editor={editor()}
ref={(el) => (linkBubbleMenuRef.current = el)} ref={(el) => (linkBubbleMenuRef.current = el)}
onClose={() => setShouldShowLinkBubbleMenu(false)} onClose={handleHideLinkBubble}
/> />
</div> </div>
</ShowOnlyOnClient> </ShowOnlyOnClient>