@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 CHANGED
@@ -1,66 +1,78 @@
1
- import { inject as l, ref as d, onMounted as v, onUnmounted as s, defineComponent as c, createVNode as f, provide as m, Fragment as y } from "vue";
2
- const a = Symbol("editorInfoCtxKey");
3
- function g() {
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: e,
6
- loading: o,
7
- editor: n,
8
- editorFactory: r
9
- } = l(a, {}), i = d();
10
- return v(() => {
11
- if (!e.value) return;
12
- const t = r.value(e.value);
13
- t && (o.value = !0, i.value = t, t.create().then((u) => {
14
- n.value = u;
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
- o.value = !1;
17
- }).catch(console.error));
18
- }), s(() => {
19
- var t;
20
- (t = i.value) == null || t.destroy();
21
- }), e;
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 k = /* @__PURE__ */ c({
29
+ const Milkdown = /* @__PURE__ */ defineComponent({
24
30
  name: "Milkdown",
25
31
  setup: () => {
26
- const e = g();
27
- return () => f("div", {
28
- "data-milkdown-root": !0,
29
- ref: e
32
+ const domRef = useGetEditor();
33
+ return () => createVNode("div", {
34
+ "data-milkdown-root": true,
35
+ "ref": domRef
30
36
  }, null);
31
37
  }
32
- }), w = /* @__PURE__ */ c({
38
+ });
39
+ const MilkdownProvider = /* @__PURE__ */ defineComponent({
33
40
  name: "MilkdownProvider",
34
- setup: (e, {
35
- slots: o
41
+ setup: (_, {
42
+ slots
36
43
  }) => {
37
- const n = d(null), r = d(void 0), i = d(void 0), t = d(!0);
38
- return m(a, {
39
- loading: t,
40
- dom: n,
41
- editor: i,
42
- editorFactory: r
43
- }), () => {
44
- var u;
45
- return f(y, null, [(u = o.default) == null ? void 0 : u.call(o)]);
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 M(e) {
50
- const { editorFactory: o, loading: n, editor: r } = l(a);
51
- return o.value = e, {
52
- loading: n,
53
- get: () => r.value
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 E() {
57
- const e = l(a);
58
- return [e.loading, () => e.editor.value];
68
+ function useInstance() {
69
+ const editorInfo = inject(editorInfoCtxKey);
70
+ return [editorInfo.loading, () => editorInfo.editor.value];
59
71
  }
60
72
  export {
61
- k as Milkdown,
62
- w as MilkdownProvider,
63
- M as useEditor,
64
- E as useInstance
73
+ Milkdown,
74
+ MilkdownProvider,
75
+ useEditor,
76
+ useInstance
65
77
  };
66
78
  //# sourceMappingURL=index.es.js.map
@@ -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":["editorInfoCtxKey","useGetEditor","dom","loading","editorRef","getEditor","inject","currentEditorRef","ref","onMounted","editor","onUnmounted","_a","Milkdown","defineComponent","name","setup","domRef","_createVNode","MilkdownProvider","_","slots","editorFactory","undefined","provide","_Fragment","default","useEditor","useInstance","editorInfo"],"mappings":";AAGa,MAAAA,IACX,OAAO,kBAAkB;ACGpB,SAASC,IAAe;AACvB,QAAA;AAAA,IACJ,KAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAQC;AAAA,IACR,eAAeC;AAAA,EAAA,IACbC,EAAON,GAAkB,EAAmB,GAC1CO,IAAmBC,EAAoB;AAE7C,SAAAC,EAAU,MAAM;AACV,QAAA,CAACP,EAAI,MAAO;AAEhB,UAAMQ,IAASL,EAAU,MAAOH,EAAI,KAAK;AACzC,IAAKQ,MAELP,EAAQ,QAAQ,IAChBI,EAAiB,QAAQG,GACzBA,EACG,OAAO,EACP,KAAK,CAACA,MAAW;AAChB,MAAAN,EAAU,QAAQM;AAAAA,IAAA,CACnB,EACA,QAAQ,MAAM;AACb,MAAAP,EAAQ,QAAQ;AAAA,IAAA,CACjB,EACA,MAAM,QAAQ,KAAK;AAAA,EAAA,CACvB,GACDQ,EAAY,MAAM;;AAChB,KAAAC,IAAAL,EAAiB,UAAjB,QAAAK,EAAwB;AAAA,EAAQ,CACjC,GAEMV;AACT;AC5BaW,MAAAA,IAAWC,gBAAAA,EAAgB;AAAA,EACtCC,MAAM;AAAA,EACNC,OAAOA,MAAM;AACX,UAAMC,IAAShB,EAAc;AAE7B,WAAO,MAAAiB,EAAA,OAAA;AAAA,MAAA,sBAAA;AAAA,MAAA,KAAmCD;AAAAA,IAAU,GAAA,IAAA;AAAA,EACtD;AACF,CAAC,GAEYE,IAAmBL,gBAAAA,EAAgB;AAAA,EAC9CC,MAAM;AAAA,EACNC,OAAOA,CAACI,GAAG;AAAA,IAAEC,OAAAA;AAAAA,EAAM,MAAM;AACvB,UAAMnB,IAAMM,EAA2B,IAAI,GACrCc,IAAgBd,EAA2Be,MAAS,GACpDb,IAASF,EAAwBe,MAAS,GAC1CpB,IAAUK,EAAI,EAAI;AAExBgB,WAAAA,EAAQxB,GAAkB;AAAA,MACxBG,SAAAA;AAAAA,MACAD,KAAAA;AAAAA,MACAQ,QAAAA;AAAAA,MACAY,eAAAA;AAAAA,IACF,CAAC,GAEM,MAAA;;AAAAJ,aAAAA,EAAAO,GAAA,MAAA,EAASJ,IAAAA,EAAMK,YAANL,gBAAAA,EAAAA,KAAAA,EAAiB,CAAI;AAAA;AAAA,EACvC;AACF,CAAC;AChCM,SAASM,EAAUtB,GAAuC;AAC/D,QAAM,EAAE,eAAAiB,GAAe,SAAAnB,GAAS,QAAAO,EAAO,IAAIJ,EAAON,CAAgB;AAElE,SAAAsB,EAAc,QAAQjB,GAEf;AAAA,IACL,SAAAF;AAAA,IACA,KAAK,MAAMO,EAAO;AAAA,EACpB;AACF;ACPO,SAASkB,IAAwB;AAChC,QAAAC,IAAavB,EAAON,CAAgB;AAE1C,SAAO,CAAC6B,EAAW,SAAS,MAAMA,EAAW,OAAO,KAAK;AAC3D;"}
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.3",
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/kit": "7.6.3",
34
- "@milkdown/crepe": "7.6.3"
33
+ "@milkdown/crepe": "7.6.4",
34
+ "@milkdown/kit": "7.6.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "vue": "^3.3.4"