@milkdown/vue 6.4.0 → 6.5.0

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 CHANGED
@@ -1,7 +1,6 @@
1
- import { ComponentInternalInstance, DefineComponent, InjectionKey } from 'vue';
1
+ import { DefineComponent, InjectionKey } from 'vue';
2
2
  import { EditorRef } from './EditorComponent';
3
3
  import { EditorInfo, EditorInfoCtx } from './types';
4
- export declare const getRootInstance: () => ComponentInternalInstance | null;
5
4
  export declare const editorInfoCtxKey: InjectionKey<EditorInfoCtx>;
6
5
  export declare const VueEditor: DefineComponent<{
7
6
  editor: EditorInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,yBAAyB,EACzB,eAAe,EAKf,YAAY,EAMf,MAAM,KAAK,CAAC;AAEb,OAAO,EAAmB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AASpD,eAAO,MAAM,eAAe,wCAE3B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,aAAa,CAAY,CAAC;AA4BtE,eAAO,MAAM,SAAS;YAA6B,UAAU;;;YAAV,UAAU;;OA0D3D,CAAC"}
1
+ {"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,EAEH,eAAe,EAKf,YAAY,EAOf,MAAM,KAAK,CAAC;AAEb,OAAO,EAAmB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIpD,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,aAAa,CAAY,CAAC;AA4BtE,eAAO,MAAM,SAAS;YAA6B,UAAU;;;YAAV,UAAU;;OA4D3D,CAAC"}
@@ -1,15 +1,16 @@
1
1
  import { Ctx } from '@milkdown/core';
2
2
  import { Mark, Node } from '@milkdown/prose/model';
3
3
  import type { Decoration, DecorationSource, EditorView, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view';
4
- import { DefineComponent } from 'vue';
4
+ import { ComponentInternalInstance, DefineComponent, Ref } from 'vue';
5
5
  export declare type RenderOptions = Partial<{
6
6
  as: string;
7
7
  update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
8
8
  } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>>;
9
- export declare const createVueView: (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) => (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor;
9
+ export declare const createVueView: (rootInstance: Ref<null | ComponentInternalInstance>, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) => (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor;
10
10
  export declare class VueNodeView implements NodeView {
11
11
  private ctx;
12
12
  private component;
13
+ private rootInstance;
13
14
  private addPortal;
14
15
  private removePortalByKey;
15
16
  private options;
@@ -20,7 +21,7 @@ export declare class VueNodeView implements NodeView {
20
21
  get isInlineOrMark(): boolean;
21
22
  private node;
22
23
  private decorations;
23
- constructor(ctx: Ctx, component: DefineComponent, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void, options: RenderOptions, node: Node | Mark, view: EditorView, getPos: boolean | (() => number), decorations: readonly Decoration[]);
24
+ constructor(ctx: Ctx, component: DefineComponent, rootInstance: Ref<null | ComponentInternalInstance>, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void, options: RenderOptions, node: Node | Mark, view: EditorView, getPos: boolean | (() => number), decorations: readonly Decoration[]);
24
25
  get dom(): HTMLElement;
25
26
  get contentDOM(): HTMLElement | undefined;
26
27
  getPortal: () => DefineComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"VueNodeView.d.ts","sourceRoot":"","sources":["../src/VueNodeView.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EACR,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,QAAQ,EACR,mBAAmB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAmD,MAAM,KAAK,CAAC;AAOvF,oBAAY,aAAa,GAAG,OAAO,CAC/B;IACI,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,UAAU,EAAE,EAAE,gBAAgB,EAAE,gBAAgB,KAAK,OAAO,CAAC;CAC5G,GAAG,IAAI,CAAC,QAAQ,EAAE,gBAAgB,GAAG,cAAc,GAAG,YAAY,GAAG,SAAS,CAAC,CACnF,CAAC;AAEF,eAAO,MAAM,aAAa,uBACD,eAAe,OAAO,MAAM,KAAK,IAAI,2BAA2B,MAAM,KAAK,IAAI,iBAErF,eAAe,YACjB,aAAa,WAChB,GAAG,KAAK,mBAAmB,GAAG,mBAGmE,CAAC;AAEhH,qBAAa,WAAY,YAAW,QAAQ;IAYpC,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,iBAAiB;IACzB,OAAO,CAAC,OAAO;IAEf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IAlBlB,WAAW,EAAE,WAAW,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,cAAc,YAEjB;IAED,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,WAAW,CAA6B;gBAGpC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,QAAQ,EAAE,cAAc;IA6BvC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,UAAU,EAAE,EAAE,gBAAgB,EAAE,gBAAgB;IA0BzF,UAAU,2BAA4B;IAEtC,YAAY,2BAA8B;CAC7C"}
package/lib/index.es.js CHANGED
@@ -1,92 +1,90 @@
1
- var N = Object.defineProperty;
2
- var S = (o, e, t) => e in o ? N(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var v = (o, e, t) => (S(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { inject as g, ref as u, onMounted as j, onUnmounted as C, defineComponent as p, createVNode as c, provide as w, h as K, markRaw as k, Teleport as U, shallowReactive as B, getCurrentInstance as A, onBeforeMount as L, effect as _, isVNode as q } from "vue";
5
- import { editorViewCtx as G, rootCtx as T } from "@milkdown/core";
6
- import { vueRendererCallOutOfScope as z } from "@milkdown/exception";
7
- import { Mark as F, Node as I } from "@milkdown/prose/model";
8
- import { customAlphabet as H } from "nanoid";
9
- const E = Symbol(), J = (o) => {
10
- const e = g(E, () => {
11
- throw z();
12
- }), { dom: t, loading: i, editor: a } = g(O, {}), s = u(!1);
1
+ var x = Object.defineProperty;
2
+ var S = (o, e, t) => e in o ? x(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var p = (o, e, t) => (S(o, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { inject as v, ref as c, onMounted as j, onUnmounted as E, defineComponent as m, createVNode as l, provide as k, h as K, markRaw as M, Teleport as U, shallowReactive as B, getCurrentInstance as A, onBeforeMount as L, effect as _, isVNode as q } from "vue";
5
+ import { vueRendererCallOutOfScope as G } from "@milkdown/exception";
6
+ import { Mark as T, Node as I } from "@milkdown/prose/model";
7
+ import { customAlphabet as z } from "nanoid";
8
+ const C = Symbol(), F = (o) => {
9
+ const e = v(C, () => {
10
+ throw G();
11
+ }), { dom: t, loading: n, editor: a } = v(O, {}), s = c(!1);
13
12
  j(() => {
14
13
  if (!t.value)
15
14
  return;
16
- const r = o(t.value, e);
17
- !r || s.value || (i.value = !0, s.value = !0, r.create().then((n) => {
18
- a.value = n;
15
+ const i = o(t.value, e);
16
+ !i || s.value || (n.value = !0, s.value = !0, i.create().then((r) => {
17
+ a.value = r;
19
18
  }).finally(() => {
20
- i.value = !1, s.value = !1;
21
- }).catch((n) => console.error(n)));
22
- }), C(() => {
23
- var d, f, h;
24
- const r = (d = a.value) == null ? void 0 : d.action((l) => l.get(G)), n = (f = a.value) == null ? void 0 : f.action((l) => l.get(T));
25
- (h = n == null ? void 0 : n.firstChild) == null || h.remove(), r == null || r.destroy();
19
+ n.value = !1, s.value = !1;
20
+ }).catch((r) => console.error(r)));
21
+ }), E(() => {
22
+ var i;
23
+ (i = a.value) == null || i.destroy();
26
24
  });
27
- }, V = p({
25
+ }, V = m({
28
26
  name: "milkdown-dom-root",
29
27
  setup: (o, {
30
28
  slots: e
31
29
  }) => {
32
- J(o.editor);
33
- const t = g(O, {});
30
+ F(o.editor);
31
+ const t = v(O, {});
34
32
  return o.editorRef && (o.editorRef.get = () => t.editor.value, o.editorRef.dom = () => t.dom.value), () => {
35
- var i;
36
- return c("div", {
33
+ var n;
34
+ return l("div", {
37
35
  ref: t.dom
38
- }, [(i = e.default) == null ? void 0 : i.call(e)]);
36
+ }, [(n = e.default) == null ? void 0 : n.call(e)]);
39
37
  };
40
38
  }
41
39
  });
42
40
  V.props = ["editor", "editorRef"];
43
- const b = Symbol(), de = () => g(b), x = p({
41
+ const b = Symbol(), ie = () => v(b), N = m({
44
42
  name: "milkdown-node-container",
45
43
  setup: ({
46
44
  node: o,
47
45
  view: e,
48
46
  getPos: t,
49
- decorations: i,
47
+ decorations: n,
50
48
  ctx: a,
51
49
  as: s
52
- }, r) => (w(b, {
50
+ }, i) => (k(b, {
53
51
  ctx: a,
54
52
  node: o,
55
53
  view: e,
56
54
  getPos: t,
57
- decorations: i
55
+ decorations: n
58
56
  }), () => {
59
- var n, d;
57
+ var r, d;
60
58
  return K(s, {
61
59
  "data-view-container": !0
62
- }, (d = (n = r.slots).default) == null ? void 0 : d.call(n));
60
+ }, (d = (r = i.slots).default) == null ? void 0 : d.call(r));
63
61
  })
64
62
  });
65
- x.props = ["ctx", "editor", "node", "view", "getPos", "decorations", "as"];
66
- const R = p({
63
+ N.props = ["ctx", "editor", "node", "view", "getPos", "decorations", "as"];
64
+ const R = m({
67
65
  name: "milkdown-content",
68
66
  setup: ({
69
67
  isInline: o
70
- }) => () => o ? c("span", {
68
+ }) => () => o ? l("span", {
71
69
  "data-view-content": !0
72
- }, null) : c("div", {
70
+ }, null) : l("div", {
73
71
  "data-view-content": !0
74
72
  }, null)
75
73
  });
76
74
  R.props = ["isInline"];
77
- const Q = H("abcedfghicklmn", 10), W = (o, e) => (t, i = {}) => (a) => (s, r, n, d) => new X(a, t, o, e, i, s, r, n, d);
75
+ const H = z("abcedfghicklmn", 10), J = (o, e, t) => (n, a = {}) => (s) => (i, r, d, f) => new Q(s, n, o, e, t, a, i, r, d, f);
78
76
  var P, D;
79
- class X {
80
- constructor(e, t, i, a, s, r, n, d, f) {
81
- v(this, "getPortal", () => {
77
+ class Q {
78
+ constructor(e, t, n, a, s, i, r, d, f, g) {
79
+ p(this, "getPortal", () => {
82
80
  const e = this.component, t = this.options.as ? this.options.as : this.isInlineOrMark ? "span" : "div";
83
- return k(p({
81
+ return M(m({
84
82
  name: "milkdown-portal",
85
- setup: () => () => c(U, {
83
+ setup: () => () => l(U, {
86
84
  key: this.key,
87
85
  to: this.teleportDOM
88
86
  }, {
89
- default: () => [c(x, {
87
+ default: () => [l(N, {
90
88
  as: t,
91
89
  ctx: this.ctx,
92
90
  node: this.node,
@@ -94,8 +92,8 @@ class X {
94
92
  getPos: this.getPos,
95
93
  decorations: this.decorations
96
94
  }, {
97
- default: () => [c(e, null, {
98
- default: () => [c(R, {
95
+ default: () => [l(e, null, {
96
+ default: () => [l(R, {
99
97
  isInline: this.isInlineOrMark
100
98
  }, null)]
101
99
  })]
@@ -103,14 +101,14 @@ class X {
103
101
  })
104
102
  }));
105
103
  });
106
- v(this, "selectNode", (P = this.options) == null ? void 0 : P.selectNode);
107
- v(this, "deselectNode", (D = this.options) == null ? void 0 : D.deselectNode);
108
- this.ctx = e, this.component = t, this.addPortal = i, this.removePortalByKey = a, this.options = s, this.view = n, this.getPos = d, this.key = Q(), this.node = u(r), this.decorations = u(f);
109
- const h = s.as ? s.as : this.isInlineOrMark ? "span" : "div";
110
- this.teleportDOM = document.createElement(h), this.renderPortal();
104
+ p(this, "selectNode", (P = this.options) == null ? void 0 : P.selectNode);
105
+ p(this, "deselectNode", (D = this.options) == null ? void 0 : D.deselectNode);
106
+ this.ctx = e, this.component = t, this.rootInstance = n, this.addPortal = a, this.removePortalByKey = s, this.options = i, this.view = d, this.getPos = f, this.key = H(), this.node = c(r), this.decorations = c(g);
107
+ const y = i.as ? i.as : this.isInlineOrMark ? "span" : "div";
108
+ this.teleportDOM = document.createElement(y), this.renderPortal();
111
109
  }
112
110
  get isInlineOrMark() {
113
- return this.node.value instanceof F || this.node.value.isInline;
111
+ return this.node.value instanceof T || this.node.value.isInline;
114
112
  }
115
113
  get dom() {
116
114
  return this.teleportDOM.firstElementChild || this.teleportDOM;
@@ -124,7 +122,7 @@ class X {
124
122
  return;
125
123
  const e = this.getPortal();
126
124
  this.addPortal(e, this.key);
127
- const t = Z();
125
+ const t = this.rootInstance.value;
128
126
  t && t.update();
129
127
  }
130
128
  destroy() {
@@ -134,11 +132,11 @@ class X {
134
132
  ignoreMutation(e) {
135
133
  return this.options.ignoreMutation ? this.options.ignoreMutation(e) : !this.dom || !this.contentDOM || this.node instanceof I && (this.node.isLeaf || this.node.isAtom) ? !0 : !(e.type === "selection" || this.contentDOM === this.dom || this.contentDOM.contains(e.target));
136
134
  }
137
- update(e, t, i) {
135
+ update(e, t, n) {
138
136
  return (() => {
139
- var r, n;
137
+ var i, r;
140
138
  if (this.options.update) {
141
- const d = (n = (r = this.options).update) == null ? void 0 : n.call(r, e, t, i);
139
+ const d = (r = (i = this.options).update) == null ? void 0 : r.call(i, e, t, n);
142
140
  if (d != null)
143
141
  return d;
144
142
  }
@@ -146,12 +144,10 @@ class X {
146
144
  })();
147
145
  }
148
146
  }
149
- function Y(o) {
147
+ function W(o) {
150
148
  return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !q(o);
151
149
  }
152
- const M = {
153
- instance: null
154
- }, Z = () => M.instance, O = Symbol(), $ = `
150
+ const O = Symbol(), X = `
155
151
  @milkdown/vue:
156
152
  Passing ref to VueEditor will soon be deprecated, please use:
157
153
 
@@ -165,77 +161,76 @@ effect(() => {
165
161
  })
166
162
 
167
163
  <VueEditor editor={editor} />
168
- `, ee = `
164
+ `, Y = `
169
165
  @milkdown/vue:
170
166
  Passing editor directly to VueEditor will soon be deprecated, please use:
171
167
 
172
168
  const { editor } = useEditor(/* creator */);
173
169
 
174
170
  <VueEditor editor={editor} />
175
- `, te = p({
171
+ `, Z = m({
176
172
  name: "milkdown-vue-root",
177
173
  setup: (o) => {
178
- const e = B([]), t = A();
174
+ const e = B([]), t = A(), n = c(null);
179
175
  L(() => {
180
- M.instance = t.ctx._;
181
- }), C(() => {
182
- M.instance = null;
176
+ n.value = t.ctx._;
177
+ }), E(() => {
178
+ n.value = null;
183
179
  });
184
- const i = k((l, m) => {
185
- e.push([m, l]);
186
- }), a = k((l) => {
187
- const m = e.findIndex((y) => y[0] === l);
188
- e.splice(m, 1);
189
- }), s = W(i, a);
190
- w(E, s);
180
+ const a = M((u, h) => {
181
+ e.push([h, u]);
182
+ }), s = M((u) => {
183
+ const h = e.findIndex((w) => w[0] === u);
184
+ e.splice(h, 1);
185
+ }), i = J(n, a, s);
186
+ k(C, i);
191
187
  const r = Object.hasOwnProperty.call(o.editor, "getInstance"), {
192
- getEditorCallback: n,
193
- dom: d,
194
- editor: f,
195
- loading: h
188
+ getEditorCallback: d,
189
+ dom: f,
190
+ editor: g,
191
+ loading: y
196
192
  } = r ? o.editor.editor : o.editor;
197
193
  return _(() => {
198
- r && console.warn(ee), o.editorRef && console.warn($);
199
- }), w(O, {
200
- dom: d,
201
- editor: f,
202
- loading: h
194
+ r && console.warn(Y), o.editorRef && console.warn(X);
195
+ }), k(O, {
196
+ dom: f,
197
+ editor: g,
198
+ loading: y
203
199
  }), () => {
204
- const l = e.map(([m, y]) => c(y, {
205
- key: m
200
+ const u = e.map(([h, w]) => l(w, {
201
+ key: h
206
202
  }, null));
207
- return c(V, {
203
+ return l(V, {
208
204
  editorRef: o.editorRef,
209
- editor: n.value
210
- }, Y(l) ? l : {
211
- default: () => [l]
205
+ editor: d.value
206
+ }, W(u) ? u : {
207
+ default: () => [u]
212
208
  });
213
209
  };
214
210
  }
215
211
  });
216
- te.props = ["editor", "editorRef"];
217
- const le = (o) => {
218
- const e = u(null), t = u(), i = u(!0), a = u((...s) => o(...s));
212
+ Z.props = ["editor", "editorRef"];
213
+ const re = (o) => {
214
+ const e = c(null), t = c(), n = c(!0), a = c((...s) => o(...s));
219
215
  return {
220
- loading: i,
216
+ loading: n,
221
217
  getInstance: () => t.value,
222
218
  getDom: () => e.value,
223
219
  editor: {
224
220
  getEditorCallback: a,
225
221
  dom: e,
226
222
  editor: t,
227
- loading: i
223
+ loading: n
228
224
  }
229
225
  };
230
226
  };
231
227
  export {
232
228
  R as Content,
233
- te as VueEditor,
234
- x as VueNodeContainer,
229
+ Z as VueEditor,
230
+ N as VueNodeContainer,
235
231
  O as editorInfoCtxKey,
236
- Z as getRootInstance,
237
232
  b as nodeMetadata,
238
- le as useEditor,
239
- de as useNodeCtx
233
+ re as useEditor,
234
+ ie as useNodeCtx
240
235
  };
241
236
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/useGetEditor.ts","../src/EditorComponent.tsx","../src/VueNode.tsx","../src/VueNodeView.tsx","../src/Editor.tsx","../src/useEditor.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx, editorViewCtx, rootCtx } from '@milkdown/core';\nimport { vueRendererCallOutOfScope } from '@milkdown/exception';\nimport { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';\nimport { DefineComponent, inject, InjectionKey, onMounted, onUnmounted, ref } from 'vue';\n\nimport { editorInfoCtxKey } from '.';\nimport { EditorInfoCtx, GetEditor, RenderOptions, RenderVue } from './types';\n\nexport const rendererKey: InjectionKey<\n (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor\n> = Symbol();\n\nexport const useGetEditor = (getEditor: GetEditor) => {\n const renderVue = inject<RenderVue>(rendererKey, () => {\n throw vueRendererCallOutOfScope();\n });\n const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx);\n const lock = ref(false);\n\n onMounted(() => {\n if (!dom.value) return;\n\n const editor = getEditor(dom.value, renderVue);\n if (!editor) return;\n\n if (lock.value) return;\n\n loading.value = true;\n lock.value = true;\n\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor;\n return;\n })\n .finally(() => {\n loading.value = false;\n lock.value = false;\n })\n .catch((e) => console.error(e));\n });\n onUnmounted(() => {\n const view = editorRef.value?.action((ctx) => ctx.get(editorViewCtx));\n const root = editorRef.value?.action((ctx) => ctx.get(rootCtx)) as HTMLElement;\n\n root?.firstChild?.remove();\n view?.destroy();\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Editor } from '@milkdown/core';\nimport { defineComponent, h, inject } from 'vue';\n\nimport { editorInfoCtxKey } from './Editor';\nimport { EditorInfoCtx, GetEditor } from './types';\nimport { useGetEditor } from './useGetEditor';\n\nexport const EditorComponent = defineComponent<{ editor: GetEditor; editorRef?: EditorRef }>({\n name: 'milkdown-dom-root',\n setup: (props, { slots }) => {\n useGetEditor(props.editor);\n const ctx = inject(editorInfoCtxKey, {} as EditorInfoCtx);\n\n if (props.editorRef) {\n props.editorRef.get = () => ctx.editor.value;\n props.editorRef.dom = () => ctx.dom.value;\n }\n\n return () => <div ref={ctx.dom}>{slots['default']?.()}</div>;\n },\n});\nEditorComponent['props'] = ['editor', 'editorRef'];\n\nexport type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx } from '@milkdown/core';\nimport { Mark, Node } from '@milkdown/prose/model';\nimport { Decoration, EditorView } from '@milkdown/prose/view';\nimport { defineComponent, h, inject, InjectionKey, provide, Ref } from 'vue';\n\nexport type NodeContext<T extends Node | Mark = Node | Mark> = {\n ctx: Ctx;\n node: Ref<T>;\n view: EditorView;\n getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);\n decorations: Ref<readonly Decoration[]>;\n};\n\nexport const nodeMetadata: InjectionKey<NodeContext> = Symbol();\n\nexport type UseNodeCtx = <T extends Node | Mark = Node | Mark>() => NodeContext<T>;\nexport const useNodeCtx: UseNodeCtx = () => inject(nodeMetadata) as NodeContext<never>;\n\nexport const VueNodeContainer = defineComponent<NodeContext & { as: string }>({\n name: 'milkdown-node-container',\n setup: ({ node, view, getPos, decorations, ctx, as }, context) => {\n provide(nodeMetadata, {\n ctx,\n node,\n view,\n getPos,\n decorations,\n });\n return () => h(as, { 'data-view-container': true }, context.slots['default']?.());\n },\n});\nVueNodeContainer['props'] = ['ctx', 'editor', 'node', 'view', 'getPos', 'decorations', 'as'];\n\nexport const Content = defineComponent<{ isInline?: boolean }>({\n name: 'milkdown-content',\n setup: ({ isInline }) => {\n return () => (isInline ? <span data-view-content /> : <div data-view-content />);\n },\n});\nContent['props'] = ['isInline'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx } from '@milkdown/core';\nimport { Mark, Node } from '@milkdown/prose/model';\nimport type {\n Decoration,\n DecorationSource,\n EditorView,\n MarkViewConstructor,\n NodeView,\n NodeViewConstructor,\n} from '@milkdown/prose/view';\nimport { customAlphabet } from 'nanoid';\nimport { DefineComponent, defineComponent, h, markRaw, Ref, ref, Teleport } from 'vue';\n\nimport { getRootInstance } from '.';\nimport { Content, VueNodeContainer } from './VueNode';\n\nconst nanoid = customAlphabet('abcedfghicklmn', 10);\n\nexport type RenderOptions = Partial<\n {\n as: string;\n update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;\n } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>\n>;\n\nexport const createVueView =\n (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>\n (\n component: DefineComponent,\n options: RenderOptions = {},\n ): ((ctx: Ctx) => NodeViewConstructor | MarkViewConstructor) =>\n (ctx) =>\n (node, view, getPos, decorations) =>\n new VueNodeView(ctx, component, addPortal, removePortalByKey, options, node, view, getPos, decorations);\n\nexport class VueNodeView implements NodeView {\n teleportDOM: HTMLElement;\n key: string;\n\n get isInlineOrMark() {\n return this.node.value instanceof Mark || this.node.value.isInline;\n }\n\n private node: Ref<Node | Mark>;\n private decorations: Ref<readonly Decoration[]>;\n\n constructor(\n private ctx: Ctx,\n private component: DefineComponent,\n private addPortal: (portal: DefineComponent, key: string) => void,\n private removePortalByKey: (key: string) => void,\n private options: RenderOptions,\n node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n decorations: readonly Decoration[],\n ) {\n this.key = nanoid();\n this.node = ref(node);\n this.decorations = ref(decorations);\n const elementName = options.as ? options.as : this.isInlineOrMark ? 'span' : 'div';\n this.teleportDOM = document.createElement(elementName);\n this.renderPortal();\n }\n\n get dom() {\n return (this.teleportDOM.firstElementChild || this.teleportDOM) as HTMLElement;\n }\n\n get contentDOM() {\n if (this.node instanceof Node && this.node.isLeaf) {\n return undefined;\n }\n\n return this.teleportDOM.querySelector<HTMLElement>('[data-view-content]') || this.dom;\n }\n\n getPortal = (): DefineComponent => {\n const CustomComponent = this.component;\n const elementName = this.options.as ? this.options.as : this.isInlineOrMark ? 'span' : 'div';\n return markRaw(\n defineComponent({\n name: 'milkdown-portal',\n setup: () => {\n return () => (\n <Teleport key={this.key} to={this.teleportDOM}>\n <VueNodeContainer\n as={elementName}\n ctx={this.ctx}\n node={this.node}\n view={this.view}\n getPos={this.getPos}\n decorations={this.decorations}\n >\n <CustomComponent>\n <Content isInline={this.isInlineOrMark} />\n </CustomComponent>\n </VueNodeContainer>\n </Teleport>\n );\n },\n }) as DefineComponent,\n );\n };\n\n renderPortal() {\n if (!this.teleportDOM) return;\n\n const Portal = this.getPortal();\n this.addPortal(Portal, this.key);\n const instance = getRootInstance();\n if (instance) {\n instance.update();\n }\n }\n\n destroy() {\n this.options.destroy?.();\n this.teleportDOM.remove();\n this.removePortalByKey(this.key);\n }\n\n ignoreMutation(mutation: MutationRecord) {\n if (this.options.ignoreMutation) {\n return this.options.ignoreMutation(mutation);\n }\n if (!this.dom || !this.contentDOM) {\n return true;\n }\n\n if (this.node instanceof Node) {\n if (this.node.isLeaf || this.node.isAtom) {\n return true;\n }\n }\n\n if ((mutation as unknown as { type: string }).type === 'selection') {\n return false;\n }\n\n if (this.contentDOM === this.dom) {\n return false;\n }\n\n if (this.contentDOM.contains(mutation.target)) {\n return false;\n }\n\n return true;\n }\n\n update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) {\n const innerUpdate = () => {\n if (this.options.update) {\n const result = this.options.update?.(node, decorations, innerDecorations);\n if (result != null) {\n return result;\n }\n }\n if (this.node.value.type !== node.type) {\n return false;\n }\n\n if (node === this.node.value && this.decorations.value === decorations) {\n return true;\n }\n\n this.node.value = node;\n this.decorations.value = decorations;\n return true;\n };\n\n const shouldUpdate = innerUpdate();\n\n return shouldUpdate;\n }\n\n selectNode = this.options?.selectNode;\n\n deselectNode = this.options?.deselectNode;\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport {\n ComponentInternalInstance,\n DefineComponent,\n defineComponent,\n effect,\n getCurrentInstance,\n h,\n InjectionKey,\n markRaw,\n onBeforeMount,\n onUnmounted,\n provide,\n shallowReactive,\n} from 'vue';\n\nimport { EditorComponent, EditorRef } from './EditorComponent';\nimport { EditorInfo, EditorInfoCtx } from './types';\nimport { rendererKey } from './useGetEditor';\nimport { createVueView } from './VueNodeView';\n\nconst rootInstance: {\n instance: null | ComponentInternalInstance;\n} = {\n instance: null,\n};\nexport const getRootInstance = () => {\n return rootInstance.instance;\n};\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol();\n\nconst refDeprecatedInfo = `\n@milkdown/vue:\nPassing ref to VueEditor will soon be deprecated, please use:\n\nconst { editor, getInstance, getDom, loading } = useEditor(/* creator */);\n\neffect(() => {\n if (!loading) {\n const editor = getInstance();\n const rootDOM = getDom();\n }\n})\n\n<VueEditor editor={editor} />\n`;\n\nconst compositionDeprecatedInfo = `\n@milkdown/vue:\nPassing editor directly to VueEditor will soon be deprecated, please use:\n\nconst { editor } = useEditor(/* creator */);\n\n<VueEditor editor={editor} />\n`;\n\ntype PortalPair = [key: string, component: DefineComponent];\nexport const VueEditor = defineComponent<{ editor: EditorInfo; editorRef?: EditorRef }>({\n name: 'milkdown-vue-root',\n setup: (props) => {\n const portals = shallowReactive<PortalPair[]>([]);\n\n const instance = getCurrentInstance();\n\n onBeforeMount(() => {\n rootInstance.instance = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } })\n .ctx._ as ComponentInternalInstance;\n });\n\n onUnmounted(() => {\n rootInstance.instance = null;\n });\n\n const addPortal = markRaw((component: DefineComponent, key: string) => {\n portals.push([key, component]);\n });\n const removePortalByKey = markRaw((key: string) => {\n const index = portals.findIndex((p) => p[0] === key);\n portals.splice(index, 1);\n });\n const renderVue = createVueView(addPortal, removePortalByKey);\n\n provide(rendererKey, renderVue);\n\n const usingDeprecatedCompositionAPI = Object.hasOwnProperty.call(props.editor, 'getInstance');\n\n const { getEditorCallback, dom, editor, loading } = usingDeprecatedCompositionAPI\n ? // @ts-expect-error deprecated old composition API\n (props.editor.editor as EditorInfo)\n : props.editor;\n\n effect(() => {\n if (usingDeprecatedCompositionAPI) {\n console.warn(compositionDeprecatedInfo);\n }\n if (props.editorRef) {\n console.warn(refDeprecatedInfo);\n }\n });\n\n provide(editorInfoCtxKey, {\n dom,\n editor,\n loading,\n });\n\n return () => {\n const portalElements = portals.map(([id, P]) => <P key={id} />);\n return (\n <EditorComponent editorRef={props.editorRef} editor={getEditorCallback.value}>\n {portalElements}\n </EditorComponent>\n );\n };\n },\n});\nVueEditor['props'] = ['editor', 'editorRef'];\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { Editor } from '@milkdown/core';\nimport { ref } from 'vue';\n\nimport { GetEditor, UseEditorReturn } from './types';\n\nexport const useEditor = (getEditor: GetEditor): UseEditorReturn => {\n const dom = ref<HTMLDivElement | null>(null);\n const editor = ref<Editor>();\n const loading = ref(true);\n const getEditorCallback = ref<GetEditor>((...args) => getEditor(...args));\n\n return {\n loading,\n getInstance: () => editor.value,\n getDom: () => dom.value,\n editor: {\n getEditorCallback,\n dom,\n editor,\n loading,\n },\n };\n};\n"],"names":["EditorComponent","defineComponent","name","setup","props","slots","useGetEditor","editor","ctx","inject","editorInfoCtxKey","editorRef","get","value","dom","_createVNode","nodeMetadata","Symbol","useNodeCtx","VueNodeContainer","node","view","getPos","decorations","as","context","provide","h","Content","isInline","nanoid","customAlphabet","createVueView","addPortal","removePortalByKey","component","options","VueNodeView","constructor","getPortal","CustomComponent","elementName","isInlineOrMark","markRaw","key","teleportDOM","selectNode","deselectNode","ref","document","createElement","renderPortal","Mark","firstElementChild","contentDOM","Node","isLeaf","querySelector","Portal","instance","getRootInstance","update","destroy","remove","ignoreMutation","mutation","isAtom","type","contains","target","innerDecorations","innerUpdate","result","rootInstance","refDeprecatedInfo","compositionDeprecatedInfo","VueEditor","portals","shallowReactive","getCurrentInstance","onBeforeMount","_","onUnmounted","push","index","findIndex","p","splice","renderVue","rendererKey","usingDeprecatedCompositionAPI","Object","hasOwnProperty","call","getEditorCallback","loading","effect","console","warn","portalElements","map","id","P"],"mappings":";;;;;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EAAb,GAEAvE,EAAMO,aACNsF,QAAQC,KAAKxB,CAAb;AAAA,IAEP,CAPK,GASNhD,EAAQhB,GAAkB;AAAA,MACtBI;AAAAA,MACAP;AAAAA,MACAwF;AAAAA,IAHsB,CAAnB,GAMA,MAAM;AACT,YAAMI,IAAiBtB,EAAQuB,IAAI,CAAC,CAACC,GAAIC,OAANvF,EAAA,GAAA;AAAA,QAAA,KAAqBsF;AAAAA,MAArB,GAAA,IAAA,CAAZ;AACvB,aAAAtF,EAAA,GAAA;AAAA,QAAA,WACgCX,EAAMO;AAAAA,QADtC,QACyDmF,EAAkBjF;AAAAA,SAClEsF,EAAAA,CAFT,IAESA,IAFT;AAAA,QAAA,SAAA,MAAA,CAESA,CAFT;AAAA,MAAA,CAAA;AAAA;EAMP;AAzDmF,CAAhD;AA2DxCvB,GAAU,QAAW,CAAC,UAAU,WAAX;AC9GR,MAAA,KAAY,CAAC,MAA0C;AAC1D,QAAA,IAAM,EAA2B,IAAI,GACrC,IAAS,KACT,IAAU,EAAI,EAAI,GAClB,IAAoB,EAAe,IAAI,MAAS,EAAU,GAAG,CAAI,CAAC;AAEjE,SAAA;AAAA,IACH;AAAA,IACA,aAAa,MAAM,EAAO;AAAA,IAC1B,QAAQ,MAAM,EAAI;AAAA,IAClB,QAAQ;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAAA,EAAA;AAER;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/useGetEditor.ts","../src/EditorComponent.tsx","../src/VueNode.tsx","../src/VueNodeView.tsx","../src/Editor.tsx","../src/useEditor.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx } from '@milkdown/core';\nimport { vueRendererCallOutOfScope } from '@milkdown/exception';\nimport { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';\nimport { DefineComponent, inject, InjectionKey, onMounted, onUnmounted, ref } from 'vue';\n\nimport { editorInfoCtxKey } from '.';\nimport { EditorInfoCtx, GetEditor, RenderOptions, RenderVue } from './types';\n\nexport const rendererKey: InjectionKey<\n (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor\n> = Symbol();\n\nexport const useGetEditor = (getEditor: GetEditor) => {\n const renderVue = inject<RenderVue>(rendererKey, () => {\n throw vueRendererCallOutOfScope();\n });\n const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx);\n const lock = ref(false);\n\n onMounted(() => {\n if (!dom.value) return;\n\n const editor = getEditor(dom.value, renderVue);\n if (!editor) return;\n\n if (lock.value) return;\n\n loading.value = true;\n lock.value = true;\n\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor;\n return;\n })\n .finally(() => {\n loading.value = false;\n lock.value = false;\n })\n .catch((e) => console.error(e));\n });\n onUnmounted(() => {\n editorRef.value?.destroy();\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Editor } from '@milkdown/core';\nimport { defineComponent, h, inject } from 'vue';\n\nimport { editorInfoCtxKey } from './Editor';\nimport { EditorInfoCtx, GetEditor } from './types';\nimport { useGetEditor } from './useGetEditor';\n\nexport const EditorComponent = defineComponent<{ editor: GetEditor; editorRef?: EditorRef }>({\n name: 'milkdown-dom-root',\n setup: (props, { slots }) => {\n useGetEditor(props.editor);\n const ctx = inject(editorInfoCtxKey, {} as EditorInfoCtx);\n\n if (props.editorRef) {\n props.editorRef.get = () => ctx.editor.value;\n props.editorRef.dom = () => ctx.dom.value;\n }\n\n return () => <div ref={ctx.dom}>{slots['default']?.()}</div>;\n },\n});\nEditorComponent['props'] = ['editor', 'editorRef'];\n\nexport type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx } from '@milkdown/core';\nimport { Mark, Node } from '@milkdown/prose/model';\nimport { Decoration, EditorView } from '@milkdown/prose/view';\nimport { defineComponent, h, inject, InjectionKey, provide, Ref } from 'vue';\n\nexport type NodeContext<T extends Node | Mark = Node | Mark> = {\n ctx: Ctx;\n node: Ref<T>;\n view: EditorView;\n getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);\n decorations: Ref<readonly Decoration[]>;\n};\n\nexport const nodeMetadata: InjectionKey<NodeContext> = Symbol();\n\nexport type UseNodeCtx = <T extends Node | Mark = Node | Mark>() => NodeContext<T>;\nexport const useNodeCtx: UseNodeCtx = () => inject(nodeMetadata) as NodeContext<never>;\n\nexport const VueNodeContainer = defineComponent<NodeContext & { as: string }>({\n name: 'milkdown-node-container',\n setup: ({ node, view, getPos, decorations, ctx, as }, context) => {\n provide(nodeMetadata, {\n ctx,\n node,\n view,\n getPos,\n decorations,\n });\n return () => h(as, { 'data-view-container': true }, context.slots['default']?.());\n },\n});\nVueNodeContainer['props'] = ['ctx', 'editor', 'node', 'view', 'getPos', 'decorations', 'as'];\n\nexport const Content = defineComponent<{ isInline?: boolean }>({\n name: 'milkdown-content',\n setup: ({ isInline }) => {\n return () => (isInline ? <span data-view-content /> : <div data-view-content />);\n },\n});\nContent['props'] = ['isInline'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Ctx } from '@milkdown/core';\nimport { Mark, Node } from '@milkdown/prose/model';\nimport type {\n Decoration,\n DecorationSource,\n EditorView,\n MarkViewConstructor,\n NodeView,\n NodeViewConstructor,\n} from '@milkdown/prose/view';\nimport { customAlphabet } from 'nanoid';\nimport { ComponentInternalInstance, DefineComponent, defineComponent, h, markRaw, Ref, ref, Teleport } from 'vue';\n\nimport { Content, VueNodeContainer } from './VueNode';\n\nconst nanoid = customAlphabet('abcedfghicklmn', 10);\n\nexport type RenderOptions = Partial<\n {\n as: string;\n update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;\n } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>\n>;\n\nexport const createVueView =\n (\n rootInstance: Ref<null | ComponentInternalInstance>,\n addPortal: (portal: DefineComponent, key: string) => void,\n removePortalByKey: (key: string) => void,\n ) =>\n (\n component: DefineComponent,\n options: RenderOptions = {},\n ): ((ctx: Ctx) => NodeViewConstructor | MarkViewConstructor) =>\n (ctx) =>\n (node, view, getPos, decorations) =>\n new VueNodeView(\n ctx,\n component,\n rootInstance,\n addPortal,\n removePortalByKey,\n options,\n node,\n view,\n getPos,\n decorations,\n );\n\nexport class VueNodeView implements NodeView {\n teleportDOM: HTMLElement;\n key: string;\n\n get isInlineOrMark() {\n return this.node.value instanceof Mark || this.node.value.isInline;\n }\n\n private node: Ref<Node | Mark>;\n private decorations: Ref<readonly Decoration[]>;\n\n constructor(\n private ctx: Ctx,\n private component: DefineComponent,\n private rootInstance: Ref<null | ComponentInternalInstance>,\n private addPortal: (portal: DefineComponent, key: string) => void,\n private removePortalByKey: (key: string) => void,\n private options: RenderOptions,\n node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n decorations: readonly Decoration[],\n ) {\n this.key = nanoid();\n this.node = ref(node);\n this.decorations = ref(decorations);\n const elementName = options.as ? options.as : this.isInlineOrMark ? 'span' : 'div';\n this.teleportDOM = document.createElement(elementName);\n this.renderPortal();\n }\n\n get dom() {\n return (this.teleportDOM.firstElementChild || this.teleportDOM) as HTMLElement;\n }\n\n get contentDOM() {\n if (this.node instanceof Node && this.node.isLeaf) {\n return undefined;\n }\n\n return this.teleportDOM.querySelector<HTMLElement>('[data-view-content]') || this.dom;\n }\n\n getPortal = (): DefineComponent => {\n const CustomComponent = this.component;\n const elementName = this.options.as ? this.options.as : this.isInlineOrMark ? 'span' : 'div';\n return markRaw(\n defineComponent({\n name: 'milkdown-portal',\n setup: () => {\n return () => (\n <Teleport key={this.key} to={this.teleportDOM}>\n <VueNodeContainer\n as={elementName}\n ctx={this.ctx}\n node={this.node}\n view={this.view}\n getPos={this.getPos}\n decorations={this.decorations}\n >\n <CustomComponent>\n <Content isInline={this.isInlineOrMark} />\n </CustomComponent>\n </VueNodeContainer>\n </Teleport>\n );\n },\n }) as DefineComponent,\n );\n };\n\n renderPortal() {\n if (!this.teleportDOM) return;\n\n const Portal = this.getPortal();\n this.addPortal(Portal, this.key);\n const instance = this.rootInstance.value;\n if (instance) {\n instance.update();\n }\n }\n\n destroy() {\n this.options.destroy?.();\n this.teleportDOM.remove();\n this.removePortalByKey(this.key);\n }\n\n ignoreMutation(mutation: MutationRecord) {\n if (this.options.ignoreMutation) {\n return this.options.ignoreMutation(mutation);\n }\n if (!this.dom || !this.contentDOM) {\n return true;\n }\n\n if (this.node instanceof Node) {\n if (this.node.isLeaf || this.node.isAtom) {\n return true;\n }\n }\n\n if ((mutation as unknown as { type: string }).type === 'selection') {\n return false;\n }\n\n if (this.contentDOM === this.dom) {\n return false;\n }\n\n if (this.contentDOM.contains(mutation.target)) {\n return false;\n }\n\n return true;\n }\n\n update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) {\n const innerUpdate = () => {\n if (this.options.update) {\n const result = this.options.update?.(node, decorations, innerDecorations);\n if (result != null) {\n return result;\n }\n }\n if (this.node.value.type !== node.type) {\n return false;\n }\n\n if (node === this.node.value && this.decorations.value === decorations) {\n return true;\n }\n\n this.node.value = node;\n this.decorations.value = decorations;\n return true;\n };\n\n const shouldUpdate = innerUpdate();\n\n return shouldUpdate;\n }\n\n selectNode = this.options?.selectNode;\n\n deselectNode = this.options?.deselectNode;\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport {\n ComponentInternalInstance,\n DefineComponent,\n defineComponent,\n effect,\n getCurrentInstance,\n h,\n InjectionKey,\n markRaw,\n onBeforeMount,\n onUnmounted,\n provide,\n ref,\n shallowReactive,\n} from 'vue';\n\nimport { EditorComponent, EditorRef } from './EditorComponent';\nimport { EditorInfo, EditorInfoCtx } from './types';\nimport { rendererKey } from './useGetEditor';\nimport { createVueView } from './VueNodeView';\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol();\n\nconst refDeprecatedInfo = `\n@milkdown/vue:\nPassing ref to VueEditor will soon be deprecated, please use:\n\nconst { editor, getInstance, getDom, loading } = useEditor(/* creator */);\n\neffect(() => {\n if (!loading) {\n const editor = getInstance();\n const rootDOM = getDom();\n }\n})\n\n<VueEditor editor={editor} />\n`;\n\nconst compositionDeprecatedInfo = `\n@milkdown/vue:\nPassing editor directly to VueEditor will soon be deprecated, please use:\n\nconst { editor } = useEditor(/* creator */);\n\n<VueEditor editor={editor} />\n`;\n\ntype PortalPair = [key: string, component: DefineComponent];\nexport const VueEditor = defineComponent<{ editor: EditorInfo; editorRef?: EditorRef }>({\n name: 'milkdown-vue-root',\n setup: (props) => {\n const portals = shallowReactive<PortalPair[]>([]);\n\n const instance = getCurrentInstance();\n\n const rootInstance = ref<null | ComponentInternalInstance>(null);\n\n onBeforeMount(() => {\n rootInstance.value = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } }).ctx\n ._ as ComponentInternalInstance;\n });\n\n onUnmounted(() => {\n rootInstance.value = null;\n });\n\n const addPortal = markRaw((component: DefineComponent, key: string) => {\n portals.push([key, component]);\n });\n const removePortalByKey = markRaw((key: string) => {\n const index = portals.findIndex((p) => p[0] === key);\n portals.splice(index, 1);\n });\n const renderVue = createVueView(rootInstance, addPortal, removePortalByKey);\n\n provide(rendererKey, renderVue);\n\n const usingDeprecatedCompositionAPI = Object.hasOwnProperty.call(props.editor, 'getInstance');\n\n const { getEditorCallback, dom, editor, loading } = usingDeprecatedCompositionAPI\n ? // @ts-expect-error deprecated old composition API\n (props.editor.editor as EditorInfo)\n : props.editor;\n\n effect(() => {\n if (usingDeprecatedCompositionAPI) {\n console.warn(compositionDeprecatedInfo);\n }\n if (props.editorRef) {\n console.warn(refDeprecatedInfo);\n }\n });\n\n provide(editorInfoCtxKey, {\n dom,\n editor,\n loading,\n });\n\n return () => {\n const portalElements = portals.map(([id, P]) => <P key={id} />);\n return (\n <EditorComponent editorRef={props.editorRef} editor={getEditorCallback.value}>\n {portalElements}\n </EditorComponent>\n );\n };\n },\n});\nVueEditor['props'] = ['editor', 'editorRef'];\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { Editor } from '@milkdown/core';\nimport { ref } from 'vue';\n\nimport { GetEditor, UseEditorReturn } from './types';\n\nexport const useEditor = (getEditor: GetEditor): UseEditorReturn => {\n const dom = ref<HTMLDivElement | null>(null);\n const editor = ref<Editor>();\n const loading = ref(true);\n const getEditorCallback = ref<GetEditor>((...args) => getEditor(...args));\n\n return {\n loading,\n getInstance: () => editor.value,\n getDom: () => dom.value,\n editor: {\n getEditorCallback,\n dom,\n editor,\n loading,\n },\n };\n};\n"],"names":["EditorComponent","defineComponent","name","setup","props","slots","useGetEditor","editor","ctx","inject","editorInfoCtxKey","editorRef","get","value","dom","_createVNode","nodeMetadata","Symbol","useNodeCtx","VueNodeContainer","node","view","getPos","decorations","as","context","provide","h","Content","isInline","nanoid","customAlphabet","createVueView","rootInstance","addPortal","removePortalByKey","component","options","VueNodeView","constructor","getPortal","CustomComponent","elementName","isInlineOrMark","markRaw","key","teleportDOM","selectNode","deselectNode","ref","document","createElement","renderPortal","Mark","firstElementChild","contentDOM","Node","isLeaf","querySelector","Portal","instance","update","destroy","remove","ignoreMutation","mutation","isAtom","type","contains","target","innerDecorations","innerUpdate","result","refDeprecatedInfo","compositionDeprecatedInfo","VueEditor","portals","shallowReactive","getCurrentInstance","onBeforeMount","_","onUnmounted","push","index","findIndex","p","splice","renderVue","rendererKey","usingDeprecatedCompositionAPI","Object","hasOwnProperty","call","getEditorCallback","loading","effect","console","warn","portalElements","map","id","P"],"mappings":";;;;;;;AASO,MAAM,IAET,OAAO,GAEE,IAAe,CAAC,MAAyB;AAC5C,QAAA,IAAY,EAAkB,GAAa,MAAM;AACnD,UAAM,EAA0B;AAAA,EAAA,CACnC,GACK,EAAE,QAAK,YAAS,QAAQ,MAAc,EAAO,GAAkB,CAAA,CAAmB,GAClF,IAAO,EAAI,EAAK;AAEtB,IAAU,MAAM;AACZ,QAAI,CAAC,EAAI;AAAO;AAEhB,UAAM,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T;AAAA,QAAA,SAAA,MAAA,CAESA,CAFT;AAAA,MAAA,CAAA;AAAA;EAMP;AA3DmF,CAAhD;AA6DxCvB,EAAU,QAAW,CAAC,UAAU,WAAX;ACxGR,MAAA,KAAY,CAAC,MAA0C;AAC1D,QAAA,IAAM,EAA2B,IAAI,GACrC,IAAS,KACT,IAAU,EAAI,EAAI,GAClB,IAAoB,EAAe,IAAI,MAAS,EAAU,GAAG,CAAI,CAAC;AAEjE,SAAA;AAAA,IACH;AAAA,IACA,aAAa,MAAM,EAAO;AAAA,IAC1B,QAAQ,MAAM,EAAI;AAAA,IAClB,QAAQ;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAAA,EAAA;AAER;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetEditor.d.ts","sourceRoot":"","sources":["../src/useGetEditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAA0B,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAU,YAAY,EAA+B,MAAM,KAAK,CAAC;AAGzF,OAAO,EAAiB,SAAS,EAAE,aAAa,EAAa,MAAM,SAAS,CAAC;AAE7E,eAAO,MAAM,WAAW,EAAE,YAAY,CAClC,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,GAAG,mBAAmB,CACxG,CAAC;AAEb,eAAO,MAAM,YAAY,cAAe,SAAS,SAqChD,CAAC"}
1
+ {"version":3,"file":"useGetEditor.d.ts","sourceRoot":"","sources":["../src/useGetEditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAU,YAAY,EAA+B,MAAM,KAAK,CAAC;AAGzF,OAAO,EAAiB,SAAS,EAAE,aAAa,EAAa,MAAM,SAAS,CAAC;AAE7E,eAAO,MAAM,WAAW,EAAE,YAAY,CAClC,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,GAAG,mBAAmB,CACxG,CAAC;AAEb,eAAO,MAAM,YAAY,cAAe,SAAS,SAiChD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milkdown/vue",
3
- "version": "6.4.0",
3
+ "version": "6.5.0",
4
4
  "type": "module",
5
5
  "main": "./lib/index.es.js",
6
6
  "types": "./lib/index.d.ts",
@@ -16,8 +16,8 @@
16
16
  "vue"
17
17
  ],
18
18
  "dependencies": {
19
- "@milkdown/utils": "6.4.0",
20
- "@milkdown/exception": "6.4.0",
19
+ "@milkdown/utils": "6.5.0",
20
+ "@milkdown/exception": "6.5.0",
21
21
  "nanoid": "^4.0.0",
22
22
  "tslib": "^2.4.0"
23
23
  },
@@ -27,8 +27,8 @@
27
27
  "vue": "^3.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@milkdown/core": "6.4.0",
31
- "@milkdown/prose": "6.4.0",
30
+ "@milkdown/core": "6.5.0",
31
+ "@milkdown/prose": "6.5.0",
32
32
  "vue": "^3.2.38"
33
33
  },
34
34
  "nx": {
package/src/Editor.tsx CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  onBeforeMount,
12
12
  onUnmounted,
13
13
  provide,
14
+ ref,
14
15
  shallowReactive,
15
16
  } from 'vue';
16
17
 
@@ -19,15 +20,6 @@ import { EditorInfo, EditorInfoCtx } from './types';
19
20
  import { rendererKey } from './useGetEditor';
20
21
  import { createVueView } from './VueNodeView';
21
22
 
22
- const rootInstance: {
23
- instance: null | ComponentInternalInstance;
24
- } = {
25
- instance: null,
26
- };
27
- export const getRootInstance = () => {
28
- return rootInstance.instance;
29
- };
30
-
31
23
  export const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol();
32
24
 
33
25
  const refDeprecatedInfo = `
@@ -63,13 +55,15 @@ export const VueEditor = defineComponent<{ editor: EditorInfo; editorRef?: Edito
63
55
 
64
56
  const instance = getCurrentInstance();
65
57
 
58
+ const rootInstance = ref<null | ComponentInternalInstance>(null);
59
+
66
60
  onBeforeMount(() => {
67
- rootInstance.instance = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } })
68
- .ctx._ as ComponentInternalInstance;
61
+ rootInstance.value = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } }).ctx
62
+ ._ as ComponentInternalInstance;
69
63
  });
70
64
 
71
65
  onUnmounted(() => {
72
- rootInstance.instance = null;
66
+ rootInstance.value = null;
73
67
  });
74
68
 
75
69
  const addPortal = markRaw((component: DefineComponent, key: string) => {
@@ -79,7 +73,7 @@ export const VueEditor = defineComponent<{ editor: EditorInfo; editorRef?: Edito
79
73
  const index = portals.findIndex((p) => p[0] === key);
80
74
  portals.splice(index, 1);
81
75
  });
82
- const renderVue = createVueView(addPortal, removePortalByKey);
76
+ const renderVue = createVueView(rootInstance, addPortal, removePortalByKey);
83
77
 
84
78
  provide(rendererKey, renderVue);
85
79
 
@@ -10,9 +10,8 @@ import type {
10
10
  NodeViewConstructor,
11
11
  } from '@milkdown/prose/view';
12
12
  import { customAlphabet } from 'nanoid';
13
- import { DefineComponent, defineComponent, h, markRaw, Ref, ref, Teleport } from 'vue';
13
+ import { ComponentInternalInstance, DefineComponent, defineComponent, h, markRaw, Ref, ref, Teleport } from 'vue';
14
14
 
15
- import { getRootInstance } from '.';
16
15
  import { Content, VueNodeContainer } from './VueNode';
17
16
 
18
17
  const nanoid = customAlphabet('abcedfghicklmn', 10);
@@ -25,14 +24,29 @@ export type RenderOptions = Partial<
25
24
  >;
26
25
 
27
26
  export const createVueView =
28
- (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>
27
+ (
28
+ rootInstance: Ref<null | ComponentInternalInstance>,
29
+ addPortal: (portal: DefineComponent, key: string) => void,
30
+ removePortalByKey: (key: string) => void,
31
+ ) =>
29
32
  (
30
33
  component: DefineComponent,
31
34
  options: RenderOptions = {},
32
35
  ): ((ctx: Ctx) => NodeViewConstructor | MarkViewConstructor) =>
33
36
  (ctx) =>
34
37
  (node, view, getPos, decorations) =>
35
- new VueNodeView(ctx, component, addPortal, removePortalByKey, options, node, view, getPos, decorations);
38
+ new VueNodeView(
39
+ ctx,
40
+ component,
41
+ rootInstance,
42
+ addPortal,
43
+ removePortalByKey,
44
+ options,
45
+ node,
46
+ view,
47
+ getPos,
48
+ decorations,
49
+ );
36
50
 
37
51
  export class VueNodeView implements NodeView {
38
52
  teleportDOM: HTMLElement;
@@ -48,6 +62,7 @@ export class VueNodeView implements NodeView {
48
62
  constructor(
49
63
  private ctx: Ctx,
50
64
  private component: DefineComponent,
65
+ private rootInstance: Ref<null | ComponentInternalInstance>,
51
66
  private addPortal: (portal: DefineComponent, key: string) => void,
52
67
  private removePortalByKey: (key: string) => void,
53
68
  private options: RenderOptions,
@@ -109,7 +124,7 @@ export class VueNodeView implements NodeView {
109
124
 
110
125
  const Portal = this.getPortal();
111
126
  this.addPortal(Portal, this.key);
112
- const instance = getRootInstance();
127
+ const instance = this.rootInstance.value;
113
128
  if (instance) {
114
129
  instance.update();
115
130
  }
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx, editorViewCtx, rootCtx } from '@milkdown/core';
2
+ import { Ctx } from '@milkdown/core';
3
3
  import { vueRendererCallOutOfScope } from '@milkdown/exception';
4
4
  import { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';
5
5
  import { DefineComponent, inject, InjectionKey, onMounted, onUnmounted, ref } from 'vue';
@@ -42,10 +42,6 @@ export const useGetEditor = (getEditor: GetEditor) => {
42
42
  .catch((e) => console.error(e));
43
43
  });
44
44
  onUnmounted(() => {
45
- const view = editorRef.value?.action((ctx) => ctx.get(editorViewCtx));
46
- const root = editorRef.value?.action((ctx) => ctx.get(rootCtx)) as HTMLElement;
47
-
48
- root?.firstChild?.remove();
49
- view?.destroy();
45
+ editorRef.value?.destroy();
50
46
  });
51
47
  };