import { clsx } from 'clsx' import { Show, createSignal } from 'solid-js' import { useEditorHTML } from 'solid-tiptap' import Typograf from 'typograf' import { Button } from '~/components/_shared/Button' import { DarkModeToggle } from '~/components/_shared/DarkModeToggle' import { Icon } from '~/components/_shared/Icon' import { useEditorContext } from '~/context/editor' import { useLocalize } from '~/context/localize' import { useUI } from '~/context/ui' import { useEscKeyDownHandler } from '~/utils/useEscKeyDownHandler' import { useOutsideClickHandler } from '~/utils/useOutsideClickHandler' import { A } from '@solidjs/router' import styles from './Panel.module.scss' const typograf = new Typograf({ locale: ['ru', 'en-US'] }) type Props = { shoutId: number } export const Panel = (props: Props) => { const { t } = useLocalize() const { showModal } = useUI() const { isEditorPanelVisible, wordCounter, editor, form, toggleEditorPanel, saveShout, saveDraft, publishShout } = useEditorContext() let containerRef: HTMLElement | undefined const [isShortcutsVisible, setIsShortcutsVisible] = createSignal(false) const [isTypographyFixed, setIsTypographyFixed] = createSignal(false) useOutsideClickHandler({ containerRef, predicate: () => isEditorPanelVisible(), handler: () => toggleEditorPanel() }) useEscKeyDownHandler(() => { if (isEditorPanelVisible()) { toggleEditorPanel() } }) const handleSaveClick = () => { const hasTopics = form.selectedTopics?.length > 0 if (hasTopics) { saveShout(form) } else { saveDraft(form) } } const html = useEditorHTML(() => editor()) // FIXME: lost current() call const handleFixTypographyClick = () => { editor()?.commands.setContent(typograf.execute(html() || '')) // here too setIsTypographyFixed(true) } return ( ) }