import { For, Show, createEffect, createSignal, onCleanup, onMount } from 'solid-js' import type { JSX } from 'solid-js' import { undo, redo } from 'prosemirror-history' import { clsx } from 'clsx' import styles from './Sidebar.module.scss' import { useOutsideClickHandler } from '../../utils/useOutsideClickHandler' import { useEscKeyDownHandler } from '../../utils/useEscKeyDownHandler' import type { EditorView } from 'prosemirror-view' const Off = (props) =>
{props.children}
const Link = (props: { withMargin?: boolean disabled?: boolean title?: string className?: string children: JSX.Element onClick?: () => void }) => ( ) const Keys = (props: { keys: string[] }) => ( {(k) => {k}} ) type SidebarProps = { editorViewRef: { current: EditorView } } export const Sidebar = (props: SidebarProps) => { const [lastAction, setLastAction] = createSignal() const { editorViewRef } = props const onUndo = () => undo(editorViewRef.current.state, editorViewRef.current.dispatch) const onRedo = () => redo(editorViewRef.current.state, editorViewRef.current.dispatch) const [isHidden, setIsHidden] = createSignal(true) const toggleSidebar = () => { setIsHidden((oldIsHidden) => !oldIsHidden) } createEffect(() => { setLastAction() }) createEffect(() => { if (!lastAction()) return const id = setTimeout(() => { setLastAction() }, 1000) onCleanup(() => clearTimeout(id)) }) const [mod, setMod] = createSignal<'Ctrl' | 'Cmd'>('Ctrl') onMount(() => { setMod(navigator.platform.includes('Mac') ? 'Cmd' : 'Ctrl') }) const containerRef: { current: HTMLElement } = { current: null } useEscKeyDownHandler(() => setIsHidden(true)) useOutsideClickHandler({ containerRef, predicate: () => !isHidden(), handler: () => setIsHidden(true) }) return (
(containerRef.current = el)} > Советы и предложения editorViewRef.current.focus()}>
Undo Redo
) }