diff --git a/src/components/Discours/Banner.tsx b/src/components/Discours/Banner.tsx index 17c8875a..f14d2a8e 100644 --- a/src/components/Discours/Banner.tsx +++ b/src/components/Discours/Banner.tsx @@ -1,7 +1,7 @@ import styles from './Banner.module.scss' import { t } from '../../utils/intl' import { showModal } from '../../stores/ui' -import {clsx} from "clsx"; +import { clsx } from 'clsx' export default () => { return ( diff --git a/src/components/Discours/Footer.tsx b/src/components/Discours/Footer.tsx index ed0a50f7..941c5d3a 100644 --- a/src/components/Discours/Footer.tsx +++ b/src/components/Discours/Footer.tsx @@ -4,7 +4,7 @@ import { Icon } from '../Nav/Icon' import Subscribe from './Subscribe' import { t } from '../../utils/intl' import { locale } from '../../stores/ui' -import {clsx} from "clsx"; +import { clsx } from 'clsx' export const Footer = () => { const locale_title = createMemo(() => (locale() === 'ru' ? 'English' : 'Русский')) diff --git a/src/components/Editor/components/Editor.tsx b/src/components/Editor/components/Editor.tsx index b2ee8aca..7df08ee5 100644 --- a/src/components/Editor/components/Editor.tsx +++ b/src/components/Editor/components/Editor.tsx @@ -10,10 +10,10 @@ export const Editor = () => { const onReconfigure = (text: EditorState) => ctrl.setState({ text }) const onChange = (text: EditorState) => ctrl.setState({ text, lastModified: new Date() }) // const editorCss = (config) => css`` - const style = () => (store.error ? `display: none;` : (store.markdown ? `white-space: pre-wrap;` : '')) + const style = () => (store.error ? `display: none;` : store.markdown ? `white-space: pre-wrap;` : '') return ( { return ( }> - + - + - + ) @@ -24,8 +24,8 @@ const InvalidState = (props: { title: string }) => { const onClick = () => ctrl.clean() return ( -
-
+
+

{props.title}

There is an error with the editor state. This is probably due to an old version in which the data @@ -35,7 +35,7 @@ const InvalidState = (props: { title: string }) => {

           {JSON.stringify(store.error.props)}
         
-
@@ -53,13 +53,13 @@ const Other = () => { } return ( -
-
+
+

An error occurred.

           {getMessage()}
         
-
diff --git a/src/components/Editor/components/Layout.tsx b/src/components/Editor/components/Layout.tsx index 2d9a35e0..eeea10a8 100644 --- a/src/components/Editor/components/Layout.tsx +++ b/src/components/Editor/components/Layout.tsx @@ -1,17 +1,19 @@ -import type { JSX } from 'solid-js/jsx-runtime'; +import type { JSX } from 'solid-js/jsx-runtime' import type { Config } from '../store/context' import '../styles/Layout.scss' export type Styled = { - children: JSX.Element; - config?: Config; - 'data-testid'?: string; - onClick?: () => void; - onMouseEnter?: (e: MouseEvent) => void; + children: JSX.Element + config?: Config + 'data-testid'?: string + onClick?: () => void + onMouseEnter?: (e: MouseEvent) => void } export const Layout = (props: Styled) => { - return (
- {props.children} -
) + return ( +
+ {props.children} +
+ ) } diff --git a/src/components/Editor/components/ProseMirror.tsx b/src/components/Editor/components/ProseMirror.tsx index da06ba55..573cbac3 100644 --- a/src/components/Editor/components/ProseMirror.tsx +++ b/src/components/Editor/components/ProseMirror.tsx @@ -6,14 +6,14 @@ import { Schema } from 'prosemirror-model' import type { NodeViewFn, ProseMirrorExtension, ProseMirrorState } from '../prosemirror/helpers' interface ProseMirrorProps { - style?: string; - className?: string; - text?: Store; - editorView?: Store; - extensions?: Store; - onInit: (s: EditorState, v: EditorView) => void; - onReconfigure: (s: EditorState) => void; - onChange: (s: EditorState) => void; + style?: string + className?: string + text?: Store + editorView?: Store + extensions?: Store + onInit: (s: EditorState, v: EditorView) => void + onReconfigure: (s: EditorState) => void + onChange: (s: EditorState) => void } export const ProseMirror = (props: ProseMirrorProps) => { @@ -28,45 +28,39 @@ export const ProseMirror = (props: ProseMirrorProps) => { props.onChange(newState) } - createEffect((payload: [EditorState, ProseMirrorExtension[]]) => { - const [prevText, prevExtensions] = payload - const text = unwrap(props.text) - const extensions: ProseMirrorExtension[] = unwrap(props.extensions) - if (!text || !extensions?.length) { + createEffect( + (payload: [EditorState, ProseMirrorExtension[]]) => { + const [prevText, prevExtensions] = payload + const text = unwrap(props.text) + const extensions: ProseMirrorExtension[] = unwrap(props.extensions) + if (!text || !extensions?.length) { + return [text, extensions] + } + + if (!props.editorView) { + const { editorState, nodeViews } = createEditorState(text, extensions) + const view = new EditorView(editorRef, { state: editorState, nodeViews, dispatchTransaction }) + view.focus() + props.onInit(editorState, view) + return [editorState, extensions] + } + + if (extensions !== prevExtensions || (!(text instanceof EditorState) && text !== prevText)) { + const { editorState, nodeViews } = createEditorState(text, extensions, prevText) + if (!editorState) return + editorView().updateState(editorState) + editorView().setProps({ nodeViews, dispatchTransaction }) + props.onReconfigure(editorState) + editorView().focus() + return [editorState, extensions] + } + return [text, extensions] - } - - if (!props.editorView) { - const { editorState, nodeViews } = createEditorState(text, extensions) - const view = new EditorView(editorRef, { state: editorState, nodeViews, dispatchTransaction }) - view.focus() - props.onInit(editorState, view) - return [editorState, extensions] - } - - if (extensions !== prevExtensions || (!(text instanceof EditorState) && text !== prevText)) { - const { editorState, nodeViews } = createEditorState(text, extensions, prevText) - if (!editorState) return - editorView().updateState(editorState) - editorView().setProps({ nodeViews, dispatchTransaction }) - props.onReconfigure(editorState) - editorView().focus() - return [editorState, extensions] - } - - return [text, extensions] - }, - [props.text, props.extensions] + }, + [props.text, props.extensions] ) - return ( -
- ) + return
} const createEditorState = ( @@ -74,8 +68,8 @@ const createEditorState = ( extensions: ProseMirrorExtension[], prevText?: EditorState ): { - editorState: EditorState; - nodeViews: { [key: string]: NodeViewFn }; + editorState: EditorState + nodeViews: { [key: string]: NodeViewFn } } => { const reconfigure = text instanceof EditorState && prevText?.schema let schemaSpec = { nodes: {} } @@ -104,7 +98,7 @@ const createEditorState = ( editorState = text.reconfigure({ schema, plugins } as EditorStateConfig) } else if (text instanceof EditorState) { editorState = EditorState.fromJSON({ schema, plugins }, text.toJSON()) - } else if (text){ + } else if (text) { console.debug(text) editorState = EditorState.fromJSON({ schema, plugins }, text) } diff --git a/src/components/Editor/components/Sidebar.tsx b/src/components/Editor/components/Sidebar.tsx index ecb392c1..33c7e2dd 100644 --- a/src/components/Editor/components/Sidebar.tsx +++ b/src/components/Editor/components/Sidebar.tsx @@ -8,16 +8,16 @@ import { isEmpty } from '../prosemirror/helpers' import type { Styled } from './Layout' import '../styles/Sidebar.scss' -const Off = (props) => +const Off = (props) => -const Label = (props: Styled) => +const Label = (props: Styled) => const Link = ( props: Styled & { withMargin?: boolean; disabled?: boolean; title?: string; className?: string } ) => (