Bubble menu positioning (#232)

This commit is contained in:
Ilya Y 2023-09-25 13:16:06 +03:00 committed by GitHub
parent f741ab9af1
commit b204f5dbba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 7 deletions

View File

@ -15,6 +15,10 @@ const backgrounds = [null, 'white', 'black', 'yellow', 'pink', 'green']
export const IncutBubbleMenu = (props: Props) => {
const { t } = useLocalize()
const [substratBubbleOpen, setSubstratBubbleOpen] = createSignal(false)
const handleChangeBg = (bg) => {
props.editor.chain().focus().setArticleBg(bg).run()
setSubstratBubbleOpen(false)
}
return (
<div ref={props.ref} class={styles.BubbleMenu}>
<button
@ -49,16 +53,11 @@ export const IncutBubbleMenu = (props: Props) => {
<span style={{ color: 'white' }}>{t('Substrate')}</span>
<Icon name="down-triangle" class={styles.triangle} />
</button>
<Show when={!substratBubbleOpen()}>
<Show when={substratBubbleOpen()}>
<div class={styles.dropDown}>
<div class={styles.actions}>
<For each={backgrounds}>
{(bg) => (
<div
onClick={() => props.editor.chain().focus().setArticleBg(bg).run()}
class={clsx(styles.color, styles[bg])}
/>
)}
{(bg) => <div onClick={() => handleChangeBg(bg)} class={clsx(styles.color, styles[bg])} />}
</For>
</div>
</div>

View File

@ -54,6 +54,20 @@ type Props = {
const yDocs: Record<string, Doc> = {}
const providers: Record<string, HocuspocusProvider> = {}
const fixedTippy = (editor, containerClassName: string) => {
return {
offset: [0, -16],
placement: 'top',
getReferenceClientRect: () => {
const selectedElement = editor.view.dom.querySelector('.has-focus')
if (selectedElement) {
return selectedElement.getBoundingClientRect()
}
return null
}
}
}
export const Editor = (props: Props) => {
const { t } = useLocalize()
const { user } = useSession()
@ -199,6 +213,16 @@ export const Editor = (props: Props) => {
const { selection } = state
const { empty } = selection
return empty && e.isActive('blockquote')
},
tippyOptions: {
offset: [0, 0],
placement: 'top',
getReferenceClientRect: () => {
const selectedElement = editor().view.dom.querySelector('.has-focus')
if (selectedElement) {
return selectedElement.getBoundingClientRect()
}
}
}
}),
BubbleMenu.configure({
@ -208,6 +232,16 @@ export const Editor = (props: Props) => {
const { selection } = state
const { empty } = selection
return empty && e.isActive('article')
},
tippyOptions: {
offset: [0, -16],
placement: 'top',
getReferenceClientRect: () => {
const selectedElement = editor().view.dom.querySelector('.has-focus')
if (selectedElement) {
return selectedElement.getBoundingClientRect()
}
}
}
}),
BubbleMenu.configure({