2023-05-04 12:16:39 +00:00
|
|
|
import type { Editor } from '@tiptap/core'
|
2024-09-27 16:31:54 +00:00
|
|
|
import { renderUploadedImage } from '~/components/Upload/renderUploadedImage'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { Icon } from '~/components/_shared/Icon'
|
|
|
|
import { Popover } from '~/components/_shared/Popover'
|
|
|
|
import { useLocalize } from '~/context/localize'
|
2024-09-27 16:31:54 +00:00
|
|
|
import { useUI } from '~/context/ui'
|
2024-06-24 17:50:27 +00:00
|
|
|
import { UploadedFile } from '~/types/upload'
|
2024-09-27 16:31:54 +00:00
|
|
|
import { UploadModalContent } from '../../Upload/UploadModalContent'
|
2024-07-21 02:17:42 +00:00
|
|
|
import { Modal } from '../../_shared/Modal'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
|
|
|
import styles from './BubbleMenu.module.scss'
|
2023-05-04 12:16:39 +00:00
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
type Props = {
|
2023-05-04 12:16:39 +00:00
|
|
|
editor: Editor
|
2023-05-29 10:09:44 +00:00
|
|
|
ref: (el: HTMLElement) => void
|
2023-05-04 12:16:39 +00:00
|
|
|
}
|
|
|
|
|
2023-05-29 10:09:44 +00:00
|
|
|
export const FigureBubbleMenu = (props: Props) => {
|
|
|
|
const { t } = useLocalize()
|
2024-06-24 17:50:27 +00:00
|
|
|
const { hideModal } = useUI()
|
2023-08-15 09:38:49 +00:00
|
|
|
|
2024-09-30 10:38:44 +00:00
|
|
|
const handleUpload = (image?: UploadedFile) => {
|
|
|
|
image && renderUploadedImage(props.editor, image)
|
2024-06-24 17:50:27 +00:00
|
|
|
hideModal()
|
2023-08-15 09:38:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 12:16:39 +00:00
|
|
|
return (
|
2023-05-29 17:14:58 +00:00
|
|
|
<div ref={props.ref} class={styles.BubbleMenu}>
|
|
|
|
<Popover content={t('Alignment left')}>
|
2024-06-24 17:50:27 +00:00
|
|
|
{(triggerRef: (el: HTMLElement) => void) => (
|
2023-05-29 17:14:58 +00:00
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2024-09-15 18:43:35 +00:00
|
|
|
onClick={() => props.editor?.chain().focus().setFigureFloat('left').run()}
|
2023-05-29 17:14:58 +00:00
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-left" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
<Popover content={t('Alignment center')}>
|
2024-06-24 17:50:27 +00:00
|
|
|
{(triggerRef: (el: HTMLElement) => void) => (
|
2023-05-29 17:14:58 +00:00
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2024-09-15 18:43:35 +00:00
|
|
|
onClick={() => props.editor?.chain().focus().setFigureFloat(null).run()}
|
2023-05-29 17:14:58 +00:00
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-center" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
<Popover content={t('Alignment right')}>
|
2024-06-24 17:50:27 +00:00
|
|
|
{(triggerRef: (el: HTMLElement) => void) => (
|
2023-05-29 17:14:58 +00:00
|
|
|
<button
|
|
|
|
ref={triggerRef}
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2024-09-15 18:43:35 +00:00
|
|
|
onClick={() => props.editor?.chain().focus().setFigureFloat('right').run()}
|
2023-05-29 17:14:58 +00:00
|
|
|
>
|
|
|
|
<Icon name="editor-image-align-right" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2023-05-04 13:36:53 +00:00
|
|
|
<div class={styles.delimiter} />
|
2023-05-07 13:16:03 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2023-06-10 14:10:05 +00:00
|
|
|
class={styles.bubbleMenuButton}
|
2024-09-15 18:43:35 +00:00
|
|
|
onClick={() => props.editor?.chain().focus().setFigcaptionFocus(true).run()}
|
2023-05-07 13:16:03 +00:00
|
|
|
>
|
2023-05-29 10:09:44 +00:00
|
|
|
<span style={{ color: 'white' }}>{t('Add signature')}</span>
|
2023-05-07 13:16:03 +00:00
|
|
|
</button>
|
|
|
|
<div class={styles.delimiter} />
|
2023-05-29 17:14:58 +00:00
|
|
|
<Popover content={t('Add image')}>
|
2024-06-24 17:50:27 +00:00
|
|
|
{(triggerRef: (el: HTMLElement) => void) => (
|
2023-06-10 14:10:05 +00:00
|
|
|
<button type="button" ref={triggerRef} class={styles.bubbleMenuButton}>
|
2023-05-29 17:14:58 +00:00
|
|
|
<Icon name="editor-image-add" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2023-08-15 09:38:49 +00:00
|
|
|
|
|
|
|
<Modal variant="narrow" name="uploadImage">
|
2024-09-30 10:38:44 +00:00
|
|
|
<UploadModalContent onClose={handleUpload} />
|
2023-08-15 09:38:49 +00:00
|
|
|
</Modal>
|
2023-05-04 12:16:39 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|