From 1910d83a6ac0005b6969f78b7554ee5c3da8698e Mon Sep 17 00:00:00 2001 From: surmon-china Date: Fri, 22 Jul 2022 04:42:34 +0800 Subject: [PATCH] styles: improve component --- src/codemirror.ts | 12 +++++------- src/component.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/codemirror.ts b/src/codemirror.ts index 2207508..7a98f29 100644 --- a/src/codemirror.ts +++ b/src/codemirror.ts @@ -33,10 +33,8 @@ export const createEditorState = ({ onUpdate, onChange, onFocus, onBlur, ...conf }) } +export const createEditorView = (config: EditorViewConfig) => new EditorView({ ...config }) export const destroyEditorView = (view: EditorView) => view.destroy() -export const createEditorView = (config: EditorViewConfig) => { - return new EditorView({ ...config }) -} // https://codemirror.net/examples/config/ // https://github.com/uiwjs/react-codemirror/blob/22cc81971a/src/useCodeMirror.ts#L144 @@ -61,10 +59,7 @@ export const createEditorExtensionToggler = (view: EditorView, extension: Extens } } -export const createEditorTools = (view: EditorView) => { - // UE state - const focus = () => view.focus() - +export const getEditorTools = (view: EditorView) => { // doc state const getDoc = () => view.state.doc.toString() const setDoc = (newDoc: string) => { @@ -79,6 +74,9 @@ export const createEditorTools = (view: EditorView) => { } } + // UX operations + const focus = () => view.focus() + // reconfigure extension const { run: reExtensions } = createEditorCompartment(view) diff --git a/src/component.ts b/src/component.ts index 034de85..016abd8 100644 --- a/src/component.ts +++ b/src/component.ts @@ -1,7 +1,7 @@ import { defineComponent, shallowRef, computed, watch, toRaw, onMounted, onBeforeUnmount, h } from 'vue' import { EditorState } from '@codemirror/state' import { EditorView } from '@codemirror/view' -import { createEditorState, createEditorView, createEditorTools, destroyEditorView } from './codemirror' +import { createEditorState, createEditorView, destroyEditorView, getEditorTools } from './codemirror' import { useGlobalConfig, DEFAULT_CONFIG } from './config' import { props, ConfigProps } from './props' import { events, EventKey } from './events' @@ -57,7 +57,7 @@ export default defineComponent({ root: config.value.root }) - const editorTools = createEditorTools(view.value) + const editorTools = getEditorTools(view.value) // watch prop.modelValue watch(