@milkdown/vue 6.5.0 → 6.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- export * from './Editor';
3
- export * from './types';
4
- export * from './useEditor';
5
- export * from './VueNode';
2
+ export * from './Editor'
3
+ export * from './types'
4
+ export * from './useEditor'
5
+ export * from './VueNode'
package/src/types.ts CHANGED
@@ -1,50 +1,50 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx, Editor } from '@milkdown/core';
3
- import type { Mark, Node } from '@milkdown/prose/model';
4
- import { Decoration, DecorationSource, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view';
5
- import { Ref } from 'vue';
2
+ import type { Ctx, Editor } from '@milkdown/core'
3
+ import type { Mark, Node } from '@milkdown/prose/model'
4
+ import type { Decoration, DecorationSource, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view'
5
+ import type { Ref } from 'vue'
6
6
 
7
- import { AnyVueComponent } from './utils';
7
+ import type { AnyVueComponent } from './utils'
8
8
 
9
9
  export type RenderOptions = Partial<
10
10
  {
11
- as: string;
12
- update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
11
+ as: string
12
+ update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean
13
13
  } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>
14
- >;
14
+ >
15
15
 
16
16
  export type RenderVue<U = never> = <T extends Node | Mark = Node | Mark>(
17
17
  Component: AnyVueComponent,
18
18
  options?: RenderOptions,
19
19
  ) => (
20
- ctx: Ctx,
20
+ ctx: Ctx,
21
21
  ) => U extends never
22
- ? T extends Node
23
- ? NodeViewConstructor
24
- : T extends Mark
25
- ? MarkViewConstructor
26
- : NodeViewConstructor & MarkViewConstructor
27
- : U extends Node
22
+ ? T extends Node
23
+ ? NodeViewConstructor
24
+ : T extends Mark
25
+ ? MarkViewConstructor
26
+ : NodeViewConstructor & MarkViewConstructor
27
+ : U extends Node
28
28
  ? NodeViewConstructor
29
29
  : U extends Mark
30
- ? MarkViewConstructor
31
- : NodeViewConstructor & MarkViewConstructor;
30
+ ? MarkViewConstructor
31
+ : NodeViewConstructor & MarkViewConstructor
32
32
 
33
- export type GetEditor = (container: HTMLDivElement, renderVue: RenderVue) => Editor;
33
+ export type GetEditor = (container: HTMLDivElement, renderVue: RenderVue) => Editor
34
34
 
35
- export type EditorInfoCtx = {
36
- dom: Ref<HTMLDivElement | null>;
37
- editor: Ref<Editor | undefined>;
38
- loading: Ref<boolean>;
39
- };
35
+ export interface EditorInfoCtx {
36
+ dom: Ref<HTMLDivElement | null>
37
+ editor: Ref<Editor | undefined>
38
+ loading: Ref<boolean>
39
+ }
40
40
 
41
41
  export type EditorInfo = {
42
- getEditorCallback: Ref<GetEditor>;
43
- } & EditorInfoCtx;
42
+ getEditorCallback: Ref<GetEditor>
43
+ } & EditorInfoCtx
44
44
 
45
- export type UseEditorReturn = {
46
- loading: Ref<boolean>;
47
- getInstance: () => Editor | undefined;
48
- getDom: () => HTMLDivElement | null;
49
- editor: EditorInfo;
50
- };
45
+ export interface UseEditorReturn {
46
+ loading: Ref<boolean>
47
+ getInstance: () => Editor | undefined
48
+ getDom: () => HTMLDivElement | null
49
+ editor: EditorInfo
50
+ }
package/src/useEditor.ts CHANGED
@@ -1,25 +1,25 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- import { Editor } from '@milkdown/core';
4
- import { ref } from 'vue';
3
+ import type { Editor } from '@milkdown/core'
4
+ import { ref } from 'vue'
5
5
 
6
- import { GetEditor, UseEditorReturn } from './types';
6
+ import type { GetEditor, UseEditorReturn } from './types'
7
7
 
8
8
  export const useEditor = (getEditor: GetEditor): UseEditorReturn => {
9
- const dom = ref<HTMLDivElement | null>(null);
10
- const editor = ref<Editor>();
11
- const loading = ref(true);
12
- const getEditorCallback = ref<GetEditor>((...args) => getEditor(...args));
9
+ const dom = ref<HTMLDivElement | null>(null)
10
+ const editor = ref<Editor>()
11
+ const loading = ref(true)
12
+ const getEditorCallback = ref<GetEditor>((...args) => getEditor(...args))
13
13
 
14
- return {
15
- loading,
16
- getInstance: () => editor.value,
17
- getDom: () => dom.value,
18
- editor: {
19
- getEditorCallback,
20
- dom,
21
- editor,
22
- loading,
23
- },
24
- };
25
- };
14
+ return {
15
+ loading,
16
+ getInstance: () => editor.value,
17
+ getDom: () => dom.value,
18
+ editor: {
19
+ getEditorCallback,
20
+ dom,
21
+ editor,
22
+ loading,
23
+ },
24
+ }
25
+ }
@@ -1,47 +1,50 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx } from '@milkdown/core';
3
- import { vueRendererCallOutOfScope } from '@milkdown/exception';
4
- import { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';
5
- import { DefineComponent, inject, InjectionKey, onMounted, onUnmounted, ref } from 'vue';
2
+ import type { Ctx } from '@milkdown/core'
3
+ import { vueRendererCallOutOfScope } from '@milkdown/exception'
4
+ import type { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view'
5
+ import type { DefineComponent, InjectionKey } from 'vue'
6
+ import { inject, onMounted, onUnmounted, ref } from 'vue'
6
7
 
7
- import { editorInfoCtxKey } from '.';
8
- import { EditorInfoCtx, GetEditor, RenderOptions, RenderVue } from './types';
8
+ import type { EditorInfoCtx, GetEditor, RenderOptions, RenderVue } from './types'
9
+ import { editorInfoCtxKey } from '.'
9
10
 
10
11
  export const rendererKey: InjectionKey<
11
12
  (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor
12
- > = Symbol();
13
+ > = Symbol('rendererKey')
13
14
 
14
15
  export const useGetEditor = (getEditor: GetEditor) => {
15
- const renderVue = inject<RenderVue>(rendererKey, () => {
16
- throw vueRendererCallOutOfScope();
17
- });
18
- const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx);
19
- const lock = ref(false);
20
-
21
- onMounted(() => {
22
- if (!dom.value) return;
23
-
24
- const editor = getEditor(dom.value, renderVue);
25
- if (!editor) return;
26
-
27
- if (lock.value) return;
28
-
29
- loading.value = true;
30
- lock.value = true;
31
-
32
- editor
33
- .create()
34
- .then((editor) => {
35
- editorRef.value = editor;
36
- return;
37
- })
38
- .finally(() => {
39
- loading.value = false;
40
- lock.value = false;
41
- })
42
- .catch((e) => console.error(e));
43
- });
44
- onUnmounted(() => {
45
- editorRef.value?.destroy();
46
- });
47
- };
16
+ const renderVue = inject<RenderVue>(rendererKey, () => {
17
+ throw vueRendererCallOutOfScope()
18
+ })
19
+ const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx)
20
+ const lock = ref(false)
21
+
22
+ onMounted(() => {
23
+ if (!dom.value)
24
+ return
25
+
26
+ const editor = getEditor(dom.value, renderVue)
27
+ if (!editor)
28
+ return
29
+
30
+ if (lock.value)
31
+ return
32
+
33
+ loading.value = true
34
+ lock.value = true
35
+
36
+ editor
37
+ .create()
38
+ .then((editor) => {
39
+ editorRef.value = editor
40
+ })
41
+ .finally(() => {
42
+ loading.value = false
43
+ lock.value = false
44
+ })
45
+ .catch(e => console.error(e))
46
+ })
47
+ onUnmounted(() => {
48
+ editorRef.value?.destroy()
49
+ })
50
+ }
package/src/utils.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- import { DefineComponent } from 'vue';
3
+ import type { DefineComponent } from 'vue'
4
4
 
5
- type Prepend<T, U extends unknown[]> = [T, ...U];
5
+ type Prepend<T, U extends unknown[]> = [T, ...U]
6
6
  type Keys_<T extends Record<string, unknown>, U extends PropertyKey[]> = {
7
- [P in keyof T]: Record<string, unknown> extends Omit<T, P> ? [P] : Prepend<P, Keys_<Omit<T, P>, U>>;
8
- }[keyof T];
9
- export type Keys<T extends Record<string, unknown>> = Keys_<T, []>;
7
+ [P in keyof T]: Record<string, unknown> extends Omit<T, P> ? [P] : Prepend<P, Keys_<Omit<T, P>, U>>;
8
+ }[keyof T]
9
+ export type Keys<T extends Record<string, unknown>> = Keys_<T, []>
10
10
 
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- export type AnyVueComponent = DefineComponent<any, any, any, any, any, any, any, any, any, any, any, any>;
11
+ export type AnyVueComponent = DefineComponent<any, any, any, any, any, any, any, any, any, any, any, any>