import { clsx } from 'clsx' import { Button } from '../../_shared/Button' import { Icon } from '../../_shared/Icon' import { useLocalize } from '../../../context/localize' import styles from './Panel.module.scss' import { useEditorContext } from '../../../context/editor' import { useOutsideClickHandler } from '../../../utils/useOutsideClickHandler' import { useEscKeyDownHandler } from '../../../utils/useEscKeyDownHandler' import { getPagePath } from '@nanostores/router' import { router } from '../../../stores/router' import { useEditorHTML } from 'solid-tiptap' import Typograf from 'typograf' const typograf = new Typograf({ locale: ['ru', 'en-US'] }) type Props = { shoutId: number } export const Panel = (props: Props) => { const { t } = useLocalize() const { isEditorPanelVisible, wordCounter, editorRef, actions: { toggleEditorPanel, saveShout, publishShout } } = useEditorContext() const containerRef: { current: HTMLElement } = { current: null } useOutsideClickHandler({ containerRef, predicate: () => isEditorPanelVisible(), handler: () => toggleEditorPanel() }) useEscKeyDownHandler(() => { if (isEditorPanelVisible()) { toggleEditorPanel() } }) const handleSaveLinkClick = (e) => { e.preventDefault() saveShout() } const handlePublishLinkClick = (e) => { e.preventDefault() publishShout() } const handleFixTypographyLinkClick = (e) => { e.preventDefault() const html = useEditorHTML(() => editorRef.current()) editorRef.current().commands.setContent(typograf.execute(html())) } return ( ) }