From 1055c006fcc1c2ca5addc5af1e001197546d69f3 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Fri, 21 Oct 2022 14:07:50 +0300 Subject: [PATCH] postmerge --- src/components/Editor/components/Editor.tsx | 6 +-- src/components/Editor/components/Layout.tsx | 7 +-- .../Editor/components/ProseMirror.tsx | 14 +++--- src/components/Editor/markdown.ts | 45 ++++++++++--------- src/components/Editor/prosemirror/helpers.ts | 8 ++-- src/components/Editor/remote.ts | 2 +- src/components/Editor/store/context.ts | 1 + src/graphql/publicGraphQLClient.ts | 4 +- 8 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/components/Editor/components/Editor.tsx b/src/components/Editor/components/Editor.tsx index 9cb44e3e..b2ee8aca 100644 --- a/src/components/Editor/components/Editor.tsx +++ b/src/components/Editor/components/Editor.tsx @@ -1,5 +1,5 @@ -import { EditorView } from 'prosemirror-view' -import { EditorState } from 'prosemirror-state' +import type { EditorView } from 'prosemirror-view' +import type { EditorState } from 'prosemirror-state' import { useState } from '../store/context' import { ProseMirror } from './ProseMirror' import '../styles/Editor.scss' @@ -10,7 +10,7 @@ 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 ( void; - onMouseEnter?: (e: any) => void; + onMouseEnter?: (e: MouseEvent) => void; } export const Layout = (props: Styled) => { diff --git a/src/components/Editor/components/ProseMirror.tsx b/src/components/Editor/components/ProseMirror.tsx index dcf23d8a..da06ba55 100644 --- a/src/components/Editor/components/ProseMirror.tsx +++ b/src/components/Editor/components/ProseMirror.tsx @@ -1,11 +1,11 @@ import { createEffect, untrack } from 'solid-js' import { Store, unwrap } from 'solid-js/store' -import { EditorState, Transaction } from 'prosemirror-state' +import { EditorState, EditorStateConfig, Transaction } from 'prosemirror-state' import { EditorView } from 'prosemirror-view' import { Schema } from 'prosemirror-model' -import { NodeViewFn, ProseMirrorExtension, ProseMirrorState } from '../prosemirror/helpers' +import type { NodeViewFn, ProseMirrorExtension, ProseMirrorState } from '../prosemirror/helpers' -interface Props { +interface ProseMirrorProps { style?: string; className?: string; text?: Store; @@ -16,7 +16,7 @@ interface Props { onChange: (s: EditorState) => void; } -export const ProseMirror = (props: Props) => { +export const ProseMirror = (props: ProseMirrorProps) => { let editorRef: HTMLDivElement const editorView = () => untrack(() => unwrap(props.editorView)) @@ -30,7 +30,7 @@ export const ProseMirror = (props: Props) => { createEffect((payload: [EditorState, ProseMirrorExtension[]]) => { const [prevText, prevExtensions] = payload - const text: EditorState = unwrap(props.text) + const text = unwrap(props.text) const extensions: ProseMirrorExtension[] = unwrap(props.extensions) if (!text || !extensions?.length) { return [text, extensions] @@ -63,7 +63,7 @@ export const ProseMirror = (props: Props) => {
) @@ -101,7 +101,7 @@ const createEditorState = ( let editorState: EditorState if (reconfigure) { - editorState = text.reconfigure({ schema, plugins }) + editorState = text.reconfigure({ schema, plugins } as EditorStateConfig) } else if (text instanceof EditorState) { editorState = EditorState.fromJSON({ schema, plugins }, text.toJSON()) } else if (text){ diff --git a/src/components/Editor/markdown.ts b/src/components/Editor/markdown.ts index 41d2b2be..b7bc6cee 100644 --- a/src/components/Editor/markdown.ts +++ b/src/components/Editor/markdown.ts @@ -1,7 +1,7 @@ import markdownit from 'markdown-it' -import { MarkdownSerializer, MarkdownParser, defaultMarkdownSerializer } from 'prosemirror-markdown' -import { Node, Schema } from 'prosemirror-model' -import { EditorState } from 'prosemirror-state' +import { MarkdownSerializer, MarkdownParser, defaultMarkdownSerializer, MarkdownSerializerState } from 'prosemirror-markdown' +import type { Node, Schema } from 'prosemirror-model' +import type { EditorState } from 'prosemirror-state' export const serialize = (state: EditorState) => { let text = markdownSerializer.serialize(state.doc) @@ -12,14 +12,30 @@ export const serialize = (state: EditorState) => { return text } + +function findAlignment(cell: Node): string | null { + const alignment = cell.attrs.style as string + if (!alignment) { + return null + } + + const match = alignment.match(/text-align: ?(left|right|center)/) + if (match && match[1]) { + return match[1] + } + + return null +} + export const markdownSerializer = new MarkdownSerializer( { ...defaultMarkdownSerializer.nodes, - image(state, node) { + image(state: MarkdownSerializerState, node: Node) { const alt = state.esc(node.attrs.alt || '') const src = node.attrs.path ?? node.attrs.src - const title = node.attrs.title ? state.quote(node.attrs.title) : undefined + const title = node.attrs.title ? `"${node.attrs.title}"` : undefined state.write(`![${alt}](${src}${title ? ' ' + title : ''})\n`) + /* ![]( "") */ }, code_block(state, node) { const src = node.attrs.params.src @@ -88,20 +104,6 @@ export const markdownSerializer = new MarkdownSerializer( return findAlignment(cell) } - function findAlignment(cell: Node): string | null { - const alignment = cell.attrs.style as string - if (!alignment) { - return null - } - - const match = alignment.match(/text-align:[ ]?(left|right|center)/) - if (match && match[1]) { - return match[1] - } - - return null - } - node.forEach((table_child) => { if (table_child.type.name === 'table_head') serializeTableHead(table_child) if (table_child.type.name === 'table_body') serializeTableBody(table_child) @@ -122,9 +124,10 @@ export const markdownSerializer = new MarkdownSerializer( } ) -function listIsTight(tokens: any, i: number) { +function listIsTight(tokens: any, idx: number) { + let i = idx while (++i < tokens.length) { - if (tokens[i].type != 'list_item_open') return tokens[i].hidden + if (tokens[i].type !== 'list_item_open') return tokens[i].hidden } return false } diff --git a/src/components/Editor/prosemirror/helpers.ts b/src/components/Editor/prosemirror/helpers.ts index fc0ad43c..88f0bb3c 100644 --- a/src/components/Editor/prosemirror/helpers.ts +++ b/src/components/Editor/prosemirror/helpers.ts @@ -1,6 +1,6 @@ import { Plugin, EditorState } from 'prosemirror-state' -import { Node, Schema, SchemaSpec } from 'prosemirror-model' -import { Decoration, EditorView, NodeView } from 'prosemirror-view' +import type { Node, Schema, SchemaSpec } from 'prosemirror-model' +import type { Decoration, EditorView, NodeView } from 'prosemirror-view' export interface ProseMirrorExtension { schema?: (prev: SchemaSpec) => SchemaSpec; @@ -21,7 +21,7 @@ export const isInitialized = (state: any) => state !== undefined && state instan export const isEmpty = (state: any) => !isInitialized(state) || - (state.doc.childCount == 1 && + (state.doc.childCount === 1 && !state.doc.firstChild.type.spec.code && state.doc.firstChild.isTextblock && - state.doc.firstChild.content.size == 0) + state.doc.firstChild.content.size === 0) diff --git a/src/components/Editor/remote.ts b/src/components/Editor/remote.ts index e6f8ceb0..491349ea 100644 --- a/src/components/Editor/remote.ts +++ b/src/components/Editor/remote.ts @@ -1,4 +1,4 @@ -import { EditorState } from 'prosemirror-state' +import type { EditorState } from 'prosemirror-state' import { serialize } from './markdown' export const copy = async (text: string): Promise<void> => { diff --git a/src/components/Editor/store/context.ts b/src/components/Editor/store/context.ts index 43674412..e5141835 100644 --- a/src/components/Editor/store/context.ts +++ b/src/components/Editor/store/context.ts @@ -63,6 +63,7 @@ export interface Collab { export type LoadingType = 'loading' | 'initialized' export interface State { + isMac?: boolean text?: ProseMirrorState; editorView?: EditorView; extensions?: ProseMirrorExtension[]; diff --git a/src/graphql/publicGraphQLClient.ts b/src/graphql/publicGraphQLClient.ts index 2d421737..7bb5d2c1 100644 --- a/src/graphql/publicGraphQLClient.ts +++ b/src/graphql/publicGraphQLClient.ts @@ -2,8 +2,8 @@ import { ClientOptions, dedupExchange, fetchExchange, createClient, Exchange } f import { devtoolsExchange } from '@urql/devtools' import { isDev } from '../utils/config' -// export const baseUrl = 'https://newapi.discours.io' -export const baseUrl = 'http://localhost:8000' +export const baseUrl = 'https://newapi.discours.io' +// export const baseUrl = 'http://localhost:8000' const exchanges: Exchange[] = [dedupExchange, fetchExchange]