import { For, Show, createEffect, createSignal, onCleanup } from 'solid-js' import { unwrap } from 'solid-js/store' // import { undo, redo } from 'prosemirror-history' import { File, useState /*, Config, PrettierConfig */ } from './store' import { clsx } from 'clsx' import type { Styled } from './Layout' // import type { EditorState } from 'prosemirror-state' // import { serialize } from './prosemirror/markdown' // import { baseUrl } from '../../graphql/client' // import { isServer } from 'solid-js/web' // const copy = async (text: string): Promise => navigator.clipboard.writeText(text) // const copyAllAsMarkdown = async (state: EditorState): Promise => // !isServer && navigator.clipboard.writeText(serialize(state)) const Off = (props: any) => const Label = (props: Styled) => const Link = ( props: Styled & { withMargin?: boolean; disabled?: boolean; title?: string; className?: string } ) => ( ) type FileLinkProps = { file: File onOpenFile: (file: File) => void } const FileLink = (props: FileLinkProps) => { const length = 100 let content = '' const getContent = (node: any) => { if (node.text) { content += node.text } if (content.length > length) { content = `${content.slice(0, Math.max(0, length))}...` return content } if (node.content) { for (const child of node.content) { if (content.length >= length) { break } content = getContent(child) } } return content } const text = () => props.file.path ? props.file.path.slice(Math.max(0, props.file.path.length - length)) : getContent(props.file.text?.doc) return ( // eslint-disable-next-line solid/no-react-specific-props props.onOpenFile(props.file)} data-testid="open"> {text()} {props.file.path && '📎'} ) } export const Sidebar = () => { const [store, ctrl] = useState() const [lastAction, setLastAction] = createSignal() const toggleTheme = () => { document.body.classList.toggle('dark') ctrl.updateConfig({ theme: document.body.className }) } // const collabText = () => (store.collab?.started ? 'Stop' : store.collab?.error ? 'Restart 🚨' : 'Start') const editorView = () => unwrap(store.editorView) // const onToggleMarkdown = () => ctrl.toggleMarkdown() const onOpenFile = (file: File) => ctrl.openFile(unwrap(file)) // const collabUsers = () => store.collab?.y?.provider.awareness.meta.size ?? 0 // const onUndo = () => undo(editorView().state, editorView().dispatch) // const onRedo = () => redo(editorView().state, editorView().dispatch) // const onCopyAllAsMd = () => copyAllAsMarkdown(editorView().state).then(() => setLastAction('copy-md')) // const onToggleAlwaysOnTop = () => ctrl.updateConfig({ alwaysOnTop: !store.config.alwaysOnTop }) // const onToggleFullscreen = () => ctrl.setFullscreen(!store.fullscreen) // const onNew = () => ctrl.newFile() // const onDiscard = () => ctrl.discard() const [isHidden, setIsHidden] = createSignal() const toggleSidebar = () => { setIsHidden(!isHidden()) } toggleSidebar() // const onSaveAs = async () => { // const path = 'test' // TODO: save filename await remote.save(editorView().state) // // if (path) ctrl.updatePath(path) // } // // const onCollab = () => { // const state = unwrap(store) // // store.collab?.started ? ctrl.stopCollab(state) : console.log(state) // } // // const onOpenInApp = () => { // // if (isTauri) return // // if (store.collab?.started) { // window.open(`discoursio://main?room=${store.collab?.room}`, '_self') // } else { // const text = window.btoa(JSON.stringify(editorView().state.toJSON())) // // window.open(`discoursio://main?text=${text}`, '_self') // } // } // // const onCopyCollabLink = () => { // copy(`${baseUrl}/collab/${store.collab?.room}`).then(() => { // editorView().focus() // setLastAction('copy-collab-link') // }) // } // // const onCopyCollabAppLink = () => { // copy(`discoursio://${store.collab?.room}`).then(() => { // editorView().focus() // setLastAction('copy-collab-app-link') // }) // } // const Keys = (props: { keys: string[] }) => ( // // {(k: string) => {k}} // // ) createEffect(() => { setLastAction() }, store.lastModified) createEffect(() => { if (!lastAction()) return const id = setTimeout(() => { setLastAction() }, 1000) onCleanup(() => clearTimeout(id)) }) return (
Советы и предложения editorView().focus()} data-tauri-drag-region="true"> ) }