@milkdown/vue 7.6.3 → 7.6.4
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/index.es.js +60 -48
- package/lib/index.es.js.map +1 -1
- package/package.json +3 -3
package/lib/index.es.js
CHANGED
|
@@ -1,66 +1,78 @@
|
|
|
1
|
-
import { inject
|
|
2
|
-
const
|
|
3
|
-
function
|
|
1
|
+
import { inject, ref, onMounted, onUnmounted, defineComponent, createVNode, provide, Fragment } from "vue";
|
|
2
|
+
const editorInfoCtxKey = Symbol("editorInfoCtxKey");
|
|
3
|
+
function useGetEditor() {
|
|
4
4
|
const {
|
|
5
|
-
dom
|
|
6
|
-
loading
|
|
7
|
-
editor:
|
|
8
|
-
editorFactory:
|
|
9
|
-
} =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
dom,
|
|
6
|
+
loading,
|
|
7
|
+
editor: editorRef,
|
|
8
|
+
editorFactory: getEditor
|
|
9
|
+
} = inject(editorInfoCtxKey, {});
|
|
10
|
+
const currentEditorRef = ref();
|
|
11
|
+
onMounted(() => {
|
|
12
|
+
if (!dom.value) return;
|
|
13
|
+
const editor = getEditor.value(dom.value);
|
|
14
|
+
if (!editor) return;
|
|
15
|
+
loading.value = true;
|
|
16
|
+
currentEditorRef.value = editor;
|
|
17
|
+
editor.create().then((editor2) => {
|
|
18
|
+
editorRef.value = editor2;
|
|
15
19
|
}).finally(() => {
|
|
16
|
-
|
|
17
|
-
}).catch(console.error)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
loading.value = false;
|
|
21
|
+
}).catch(console.error);
|
|
22
|
+
});
|
|
23
|
+
onUnmounted(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = currentEditorRef.value) == null ? void 0 : _a.destroy();
|
|
26
|
+
});
|
|
27
|
+
return dom;
|
|
22
28
|
}
|
|
23
|
-
const
|
|
29
|
+
const Milkdown = /* @__PURE__ */ defineComponent({
|
|
24
30
|
name: "Milkdown",
|
|
25
31
|
setup: () => {
|
|
26
|
-
const
|
|
27
|
-
return () =>
|
|
28
|
-
"data-milkdown-root":
|
|
29
|
-
ref:
|
|
32
|
+
const domRef = useGetEditor();
|
|
33
|
+
return () => createVNode("div", {
|
|
34
|
+
"data-milkdown-root": true,
|
|
35
|
+
"ref": domRef
|
|
30
36
|
}, null);
|
|
31
37
|
}
|
|
32
|
-
})
|
|
38
|
+
});
|
|
39
|
+
const MilkdownProvider = /* @__PURE__ */ defineComponent({
|
|
33
40
|
name: "MilkdownProvider",
|
|
34
|
-
setup: (
|
|
35
|
-
slots
|
|
41
|
+
setup: (_, {
|
|
42
|
+
slots
|
|
36
43
|
}) => {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const dom = ref(null);
|
|
45
|
+
const editorFactory = ref(void 0);
|
|
46
|
+
const editor = ref(void 0);
|
|
47
|
+
const loading = ref(true);
|
|
48
|
+
provide(editorInfoCtxKey, {
|
|
49
|
+
loading,
|
|
50
|
+
dom,
|
|
51
|
+
editor,
|
|
52
|
+
editorFactory
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
var _a;
|
|
56
|
+
return createVNode(Fragment, null, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
|
|
46
57
|
};
|
|
47
58
|
}
|
|
48
59
|
});
|
|
49
|
-
function
|
|
50
|
-
const { editorFactory
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
function useEditor(getEditor) {
|
|
61
|
+
const { editorFactory, loading, editor } = inject(editorInfoCtxKey);
|
|
62
|
+
editorFactory.value = getEditor;
|
|
63
|
+
return {
|
|
64
|
+
loading,
|
|
65
|
+
get: () => editor.value
|
|
54
66
|
};
|
|
55
67
|
}
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
return [
|
|
68
|
+
function useInstance() {
|
|
69
|
+
const editorInfo = inject(editorInfoCtxKey);
|
|
70
|
+
return [editorInfo.loading, () => editorInfo.editor.value];
|
|
59
71
|
}
|
|
60
72
|
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
Milkdown,
|
|
74
|
+
MilkdownProvider,
|
|
75
|
+
useEditor,
|
|
76
|
+
useInstance
|
|
65
77
|
};
|
|
66
78
|
//# sourceMappingURL=index.es.js.map
|
package/lib/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/consts.ts","../src/use-get-editor.ts","../src/editor.tsx","../src/use-editor.ts","../src/use-instance.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { EditorInfoCtx } from './types'\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> =\n Symbol('editorInfoCtxKey')\n","import { inject, onMounted, onUnmounted, ref } from 'vue'\n\nimport type { EditorInfoCtx } from './types'\nimport { editorInfoCtxKey } from './consts'\nimport type { Crepe } from '@milkdown/crepe'\nimport type { Editor } from '@milkdown/kit/core'\n\nexport function useGetEditor() {\n const {\n dom,\n loading,\n editor: editorRef,\n editorFactory: getEditor,\n } = inject(editorInfoCtxKey, {} as EditorInfoCtx)\n const currentEditorRef = ref<Editor | Crepe>()\n\n onMounted(() => {\n if (!dom.value) return\n\n const editor = getEditor.value!(dom.value)\n if (!editor) return\n\n loading.value = true\n currentEditorRef.value = editor\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor\n })\n .finally(() => {\n loading.value = false\n })\n .catch(console.error)\n })\n onUnmounted(() => {\n currentEditorRef.value?.destroy()\n })\n\n return dom\n}\n","import type { Editor } from '@milkdown/kit/core'\nimport type { Ref } from 'vue'\nimport { Fragment, defineComponent, h, provide, ref } from 'vue'\n\nimport type { GetEditor } from './types'\nimport { useGetEditor } from './use-get-editor'\nimport { editorInfoCtxKey } from './consts'\n\nh\nFragment\n\nexport const Milkdown = defineComponent({\n name: 'Milkdown',\n setup: () => {\n const domRef = useGetEditor()\n\n return () => <div data-milkdown-root ref={domRef} />\n },\n})\n\nexport const MilkdownProvider = defineComponent({\n name: 'MilkdownProvider',\n setup: (_, { slots }) => {\n const dom = ref<HTMLDivElement | null>(null)\n const editorFactory = ref<GetEditor | undefined>(undefined)\n const editor = ref<Editor | undefined>(undefined) as Ref<Editor | undefined>\n const loading = ref(true)\n\n provide(editorInfoCtxKey, {\n loading,\n dom,\n editor,\n editorFactory,\n })\n\n return () => <>{slots.default?.()}</>\n },\n})\n","import { inject } from 'vue'\nimport { editorInfoCtxKey } from './consts'\n\nimport type { GetEditor, UseEditorReturn } from './types'\n\nexport function useEditor(getEditor: GetEditor): UseEditorReturn {\n const { editorFactory, loading, editor } = inject(editorInfoCtxKey)!\n\n editorFactory.value = getEditor\n\n return {\n loading,\n get: () => editor.value,\n }\n}\n","import type { Editor } from '@milkdown/kit/core'\nimport type { Ref } from 'vue'\nimport { inject } from 'vue'\nimport { editorInfoCtxKey } from './consts'\n\nexport type Instance = [Ref<true>, () => undefined] | [Ref<false>, () => Editor]\n\nexport function useInstance(): Instance {\n const editorInfo = inject(editorInfoCtxKey)!\n\n return [editorInfo.loading, () => editorInfo.editor.value] as Instance\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/consts.ts","../src/use-get-editor.ts","../src/editor.tsx","../src/use-editor.ts","../src/use-instance.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { EditorInfoCtx } from './types'\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> =\n Symbol('editorInfoCtxKey')\n","import { inject, onMounted, onUnmounted, ref } from 'vue'\n\nimport type { EditorInfoCtx } from './types'\nimport { editorInfoCtxKey } from './consts'\nimport type { Crepe } from '@milkdown/crepe'\nimport type { Editor } from '@milkdown/kit/core'\n\nexport function useGetEditor() {\n const {\n dom,\n loading,\n editor: editorRef,\n editorFactory: getEditor,\n } = inject(editorInfoCtxKey, {} as EditorInfoCtx)\n const currentEditorRef = ref<Editor | Crepe>()\n\n onMounted(() => {\n if (!dom.value) return\n\n const editor = getEditor.value!(dom.value)\n if (!editor) return\n\n loading.value = true\n currentEditorRef.value = editor\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor\n })\n .finally(() => {\n loading.value = false\n })\n .catch(console.error)\n })\n onUnmounted(() => {\n currentEditorRef.value?.destroy()\n })\n\n return dom\n}\n","import type { Editor } from '@milkdown/kit/core'\nimport type { Ref } from 'vue'\nimport { Fragment, defineComponent, h, provide, ref } from 'vue'\n\nimport type { GetEditor } from './types'\nimport { useGetEditor } from './use-get-editor'\nimport { editorInfoCtxKey } from './consts'\n\nh\nFragment\n\nexport const Milkdown = defineComponent({\n name: 'Milkdown',\n setup: () => {\n const domRef = useGetEditor()\n\n return () => <div data-milkdown-root ref={domRef} />\n },\n})\n\nexport const MilkdownProvider = defineComponent({\n name: 'MilkdownProvider',\n setup: (_, { slots }) => {\n const dom = ref<HTMLDivElement | null>(null)\n const editorFactory = ref<GetEditor | undefined>(undefined)\n const editor = ref<Editor | undefined>(undefined) as Ref<Editor | undefined>\n const loading = ref(true)\n\n provide(editorInfoCtxKey, {\n loading,\n dom,\n editor,\n editorFactory,\n })\n\n return () => <>{slots.default?.()}</>\n },\n})\n","import { inject } from 'vue'\nimport { editorInfoCtxKey } from './consts'\n\nimport type { GetEditor, UseEditorReturn } from './types'\n\nexport function useEditor(getEditor: GetEditor): UseEditorReturn {\n const { editorFactory, loading, editor } = inject(editorInfoCtxKey)!\n\n editorFactory.value = getEditor\n\n return {\n loading,\n get: () => editor.value,\n }\n}\n","import type { Editor } from '@milkdown/kit/core'\nimport type { Ref } from 'vue'\nimport { inject } from 'vue'\nimport { editorInfoCtxKey } from './consts'\n\nexport type Instance = [Ref<true>, () => undefined] | [Ref<false>, () => Editor]\n\nexport function useInstance(): Instance {\n const editorInfo = inject(editorInfoCtxKey)!\n\n return [editorInfo.loading, () => editorInfo.editor.value] as Instance\n}\n"],"names":["editor","Milkdown","defineComponent","name","setup","domRef","useGetEditor","_createVNode","MilkdownProvider","_","slots","dom","ref","editorFactory","undefined","loading","provide","editorInfoCtxKey","_Fragment","default"],"mappings":";AAGa,MAAA,mBACX,OAAO,kBAAkB;ACGpB,SAAS,eAAe;AACvB,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,eAAe;AAAA,EAAA,IACb,OAAO,kBAAkB,EAAmB;AAChD,QAAM,mBAAmB,IAAoB;AAE7C,YAAU,MAAM;AACV,QAAA,CAAC,IAAI,MAAO;AAEhB,UAAM,SAAS,UAAU,MAAO,IAAI,KAAK;AACzC,QAAI,CAAC,OAAQ;AAEb,YAAQ,QAAQ;AAChB,qBAAiB,QAAQ;AACzB,WACG,OAAO,EACP,KAAK,CAACA,YAAW;AAChB,gBAAU,QAAQA;AAAAA,IAAA,CACnB,EACA,QAAQ,MAAM;AACb,cAAQ,QAAQ;AAAA,IAAA,CACjB,EACA,MAAM,QAAQ,KAAK;AAAA,EAAA,CACvB;AACD,cAAY,MAAM;;AAChB,2BAAiB,UAAjB,mBAAwB;AAAA,EAAQ,CACjC;AAEM,SAAA;AACT;AC5BaC,MAAAA,WAAWC,gCAAgB;AAAA,EACtCC,MAAM;AAAA,EACNC,OAAOA,MAAM;AACX,UAAMC,SAASC,aAAc;AAE7B,WAAO,MAAAC,YAAA,OAAA;AAAA,MAAA,sBAAA;AAAA,MAAA,OAAmCF;AAAAA,IAAU,GAAA,IAAA;AAAA,EACtD;AACF,CAAC;AAEYG,MAAAA,mBAAmBN,gCAAgB;AAAA,EAC9CC,MAAM;AAAA,EACNC,OAAOA,CAACK,GAAG;AAAA,IAAEC;AAAAA,EAAM,MAAM;AACvB,UAAMC,MAAMC,IAA2B,IAAI;AAC3C,UAAMC,gBAAgBD,IAA2BE,MAAS;AAC1D,UAAMd,SAASY,IAAwBE,MAAS;AAChD,UAAMC,UAAUH,IAAI,IAAI;AAExBI,YAAQC,kBAAkB;AAAA,MACxBF;AAAAA,MACAJ;AAAAA,MACAX;AAAAA,MACAa;AAAAA,IACF,CAAC;AAED,WAAO,MAAA;;AAAAN,yBAAAW,UAAA,MAAA,EAASR,WAAMS,YAANT,8BAAiB,CAAI;AAAA;AAAA,EACvC;AACF,CAAC;AChCM,SAAS,UAAU,WAAuC;AAC/D,QAAM,EAAE,eAAe,SAAS,OAAO,IAAI,OAAO,gBAAgB;AAElE,gBAAc,QAAQ;AAEf,SAAA;AAAA,IACL;AAAA,IACA,KAAK,MAAM,OAAO;AAAA,EACpB;AACF;ACPO,SAAS,cAAwB;AAChC,QAAA,aAAa,OAAO,gBAAgB;AAE1C,SAAO,CAAC,WAAW,SAAS,MAAM,WAAW,OAAO,KAAK;AAC3D;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.6.
|
|
4
|
+
"version": "7.6.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"tslib": "^2.8.1",
|
|
33
|
-
"@milkdown/
|
|
34
|
-
"@milkdown/
|
|
33
|
+
"@milkdown/crepe": "7.6.4",
|
|
34
|
+
"@milkdown/kit": "7.6.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vue": "^3.3.4"
|