@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/lib/Editor.d.ts +3 -3
- package/lib/Editor.d.ts.map +1 -1
- package/lib/EditorComponent.d.ts +4 -4
- package/lib/EditorComponent.d.ts.map +1 -1
- package/lib/VueNode.d.ts +7 -7
- package/lib/VueNode.d.ts.map +1 -1
- package/lib/VueNodeView.d.ts +3 -3
- package/lib/VueNodeView.d.ts.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +44 -44
- package/lib/index.es.js.map +1 -1
- package/lib/types.d.ts +12 -12
- package/lib/types.d.ts.map +1 -1
- package/lib/useEditor.d.ts +1 -1
- package/lib/useEditor.d.ts.map +1 -1
- package/lib/useGetEditor.d.ts +4 -4
- package/lib/useGetEditor.d.ts.map +1 -1
- package/lib/utils.d.ts +5 -5
- package/lib/utils.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/Editor.tsx +84 -82
- package/src/EditorComponent.tsx +20 -18
- package/src/VueNode.tsx +35 -33
- package/src/VueNodeView.tsx +153 -161
- package/src/index.ts +4 -4
- package/src/types.ts +31 -31
- package/src/useEditor.ts +19 -19
- package/src/useGetEditor.ts +43 -40
- package/src/utils.ts +6 -7
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
20
|
+
ctx: Ctx,
|
|
21
21
|
) => U extends never
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
} & EditorInfoCtx
|
|
42
|
+
getEditorCallback: Ref<GetEditor>
|
|
43
|
+
} & EditorInfoCtx
|
|
44
44
|
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
package/src/useGetEditor.ts
CHANGED
|
@@ -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,
|
|
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 {
|
|
8
|
-
import {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>
|