import { Switch, Match, createSignal, Show } from 'solid-js' import type { Editor } from '@tiptap/core' import styles from './TextBubbleMenu.module.scss' import { Icon } from '../../_shared/Icon' import { clsx } from 'clsx' import { createEditorTransaction } from 'solid-tiptap' import { useLocalize } from '../../../context/localize' import { InlineForm } from '../InlineForm' import { validateUrl } from '../../../utils/validateUrl' type BubbleMenuProps = { editor: Editor isCommonMarkup: boolean ref: (el: HTMLDivElement) => void } export const TextBubbleMenu = (props: BubbleMenuProps) => { const { t } = useLocalize() const [textSizeBubbleOpen, setTextSizeBubbleOpen] = createSignal(false) const [listBubbleOpen, setListBubbleOpen] = createSignal(false) const [linkEditorOpen, setLinkEditorOpen] = createSignal(false) const isActive = (name: string, attributes?: unknown) => createEditorTransaction( () => props.editor, (editor) => { return editor && editor.isActive(name, attributes) } ) const isBold = isActive('bold') const isItalic = isActive('italic') const isH1 = isActive('heading', { level: 1 }) const isH2 = isActive('heading', { level: 2 }) const isH3 = isActive('heading', { level: 3 }) const isBlockQuote = isActive('blockquote') const isOrderedList = isActive('isOrderedList') const isBulletList = isActive('isBulletList') const isLink = isActive('link') const isHighlight = isActive('highlight') const toggleLinkForm = () => { setLinkEditorOpen(true) } const toggleTextSizePopup = () => { if (listBubbleOpen()) { setListBubbleOpen(false) } setTextSizeBubbleOpen((prev) => !prev) } const toggleListPopup = () => { if (textSizeBubbleOpen()) { setTextSizeBubbleOpen(false) } setListBubbleOpen((prev) => !prev) } const handleLinkFormSubmit = (value: string) => { props.editor.chain().focus().setLink({ href: value }).run() } const currentUrl = createEditorTransaction( () => props.editor, (editor) => { return (editor && editor.getAttributes('link').href) || '' } ) const handleClearLinkForm = () => { if (currentUrl()) { props.editor.chain().focus().unsetLink().run() } setLinkEditorOpen(false) } return (
(validateUrl(value) ? '' : t('Invalid url format'))} onSubmit={handleLinkFormSubmit} onClose={() => setLinkEditorOpen(false)} /> <> <>
{t('Headers')}
{t('Quotes')}
<>
{t('Lists')}
) }