import { Switch, Match, createSignal, Show, onMount, onCleanup, createEffect } 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 { Popover } from '../../_shared/Popover' import { InsertLinkForm } from '../InsertLinkForm' import SimplifiedEditor from '../SimplifiedEditor' import { Button } from '../../_shared/Button' import { showModal } from '../../../stores/ui' type BubbleMenuProps = { editor: Editor isCommonMarkup: boolean ref: (el: HTMLDivElement) => void } export const TextBubbleMenu = (props: BubbleMenuProps) => { const { t } = useLocalize() const isActive = (name: string, attributes?: unknown) => createEditorTransaction( () => props.editor, (editor) => editor && editor.isActive(name, attributes) ) const [textSizeBubbleOpen, setTextSizeBubbleOpen] = createSignal(false) const [listBubbleOpen, setListBubbleOpen] = createSignal(false) const [linkEditorOpen, setLinkEditorOpen] = createSignal(false) const [footnoteEditorOpen, setFootnoteEditorOpen] = createSignal(false) const [footNote, setFootNote] = createSignal() const isBold = isActive('bold') const isItalic = isActive('italic') const isH1 = isActive('heading', { level: 2 }) const isH2 = isActive('heading', { level: 3 }) const isH3 = isActive('heading', { level: 4 }) const isQuote = isActive('blockquote', { 'data-type': 'quote' }) const isPunchLine = isActive('blockquote', { 'data-type': 'punchline' }) const isOrderedList = isActive('isOrderedList') const isBulletList = isActive('isBulletList') const isLink = isActive('link') const isHighlight = isActive('highlight') const isFootnote = isActive('footnote') const isIncut = isActive('article') const toggleTextSizePopup = () => { if (listBubbleOpen()) { setListBubbleOpen(false) } setTextSizeBubbleOpen((prev) => !prev) } const toggleListPopup = () => { if (textSizeBubbleOpen()) { setTextSizeBubbleOpen(false) } setListBubbleOpen((prev) => !prev) } const handleKeyDown = async (event) => { if (event.code === 'KeyK' && (event.metaKey || event.ctrlKey) && !props.editor.state.selection.empty) { event.preventDefault() setLinkEditorOpen(true) } } const currentFootnoteValue = createEditorTransaction( () => props.editor, (ed) => (ed && ed.getAttributes('footnote').value) || '' ) const handleAddFootnote = (footnote) => { if (footNote()) { props.editor.chain().focus().updateFootnote(footnote).run() } else { props.editor.chain().focus().setFootnote({ value: footnote }).run() } setFootNote() setFootnoteEditorOpen(false) } const handleOpenFootnoteEditor = () => { setFootNote(currentFootnoteValue()) setFootnoteEditorOpen(true) } onMount(() => { window.addEventListener('keydown', handleKeyDown) }) onCleanup(() => { window.removeEventListener('keydown', handleKeyDown) }) return (
setLinkEditorOpen(false)} />
{t('Headers')}
{(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )}
{t('Quotes')}
{(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )}
{t('squib')}
{(triggerRef: (el) => void) => ( )}
{(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )}
{t('Add url')}
}> {(triggerRef: (el) => void) => ( )} <> {(triggerRef: (el) => void) => ( )}
{t('Lists')}
{(triggerRef: (el) => void) => ( )} {(triggerRef: (el) => void) => ( )}
) }