import { getPagePath } from '@nanostores/router' import { clsx } from 'clsx' import { createSignal, Show } from 'solid-js' import { useEditorHTML } from 'solid-tiptap' import Typograf from 'typograf' import { useEditorContext } from '../../../context/editor' import { useLocalize } from '../../../context/localize' import { router } from '../../../stores/router' import { useEscKeyDownHandler } from '../../../utils/useEscKeyDownHandler' import { useOutsideClickHandler } from '../../../utils/useOutsideClickHandler' import { Button } from '../../_shared/Button' import { DarkModeToggle } from '../../_shared/DarkModeToggle' import { Icon } from '../../_shared/Icon' 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 { isEditorPanelVisible, wordCounter, editorRef, form, actions: { toggleEditorPanel, saveShout, publishShout }, } = useEditorContext() const containerRef: { current: HTMLElement } = { current: null, } const [isShortcutsVisible, setIsShortcutsVisible] = createSignal(false) const [isTypographyFixed, setIsTypographyFixed] = createSignal(false) useOutsideClickHandler({ containerRef, predicate: () => isEditorPanelVisible(), handler: () => toggleEditorPanel(), }) useEscKeyDownHandler(() => { if (isEditorPanelVisible()) { toggleEditorPanel() } }) const handleSaveClick = () => { saveShout(form) } const handlePublishClick = () => { publishShout(form) } const handleFixTypographyClick = () => { const html = useEditorHTML(() => editorRef.current()) editorRef.current().commands.setContent(typograf.execute(html())) setIsTypographyFixed(true) } return ( ) }