import {FaceSmileIcon} from '@heroicons/react/24/outline' import {CodeBracketIcon, PhotoIcon} from '@heroicons/react/24/solid' import {Editor} from '@tiptap/react' import {MouseEventHandler, useState} from 'react' import {Row} from 'web/components/layout/row' import {useT} from 'web/lib/locale' import {FileUploadButton} from '../buttons/file-upload-button' import {LoadingIndicator} from '../widgets/loading-indicator' import {Tooltip} from '../widgets/tooltip' import {EmbedModal} from './embed-modal' import type {UploadMutation} from './upload-extension' /* Toolbar, with buttons for images and embeds */ export function StickyFormatMenu(props: { editor: Editor | null hideEmbed?: boolean children?: React.ReactNode }) { const {editor, hideEmbed, children} = props const upload = editor?.storage.upload.mutation const t = useT() const [iframeOpen, setIframeOpen] = useState(false) return ( {!hideEmbed && ( ) => { e.stopPropagation() e.preventDefault() setIframeOpen(true) }} > )} insertEmoji(editor)} >
{children} ) } function UploadButton(props: {upload: UploadMutation}) { const {upload} = props const t = useT() return ( upload?.mutate(files)} className="hover:text-ink-700 disabled:text-ink-300 active:text-ink-800 text-ink-400 relative flex rounded px-3 py-1 pl-4 transition-colors" > ) } function ToolbarButton(props: { label: string onClick: MouseEventHandler children: React.ReactNode }) { const {label, onClick, children} = props return ( ) } /** insert a colon, and a space if necessary, to bring up emoji selector */ const insertEmoji = (editor: Editor | null) => { if (!editor) return const textBefore = editor.view.state.selection.$from.nodeBefore?.text const addSpace = textBefore && !textBefore.endsWith(' ') editor .chain() .focus() .createParagraphNear() .insertContent(addSpace ? ' :' : ':') .run() }