@milkdown/vue 6.2.0 → 6.3.2
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/VueNode.d.ts +3 -3
- package/lib/VueNode.d.ts.map +1 -1
- package/lib/VueNodeView.d.ts +3 -2
- package/lib/VueNodeView.d.ts.map +1 -1
- package/lib/index.es.js +175 -260
- package/lib/index.es.js.map +1 -1
- package/lib/useGetEditor.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/VueNode.tsx +3 -3
- package/src/VueNodeView.tsx +58 -41
- package/src/useGetEditor.ts +2 -1
package/lib/VueNode.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Ctx } from '@milkdown/core';
|
|
2
2
|
import { Mark, Node } from '@milkdown/prose/model';
|
|
3
3
|
import { Decoration, EditorView } from '@milkdown/prose/view';
|
|
4
|
-
import { InjectionKey } from 'vue';
|
|
4
|
+
import { InjectionKey, Ref } from 'vue';
|
|
5
5
|
export declare type NodeContext<T extends Node | Mark = Node | Mark> = {
|
|
6
6
|
ctx: Ctx;
|
|
7
|
-
node: T
|
|
7
|
+
node: Ref<T>;
|
|
8
8
|
view: EditorView;
|
|
9
9
|
getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);
|
|
10
|
-
decorations: readonly Decoration[]
|
|
10
|
+
decorations: Ref<readonly Decoration[]>;
|
|
11
11
|
};
|
|
12
12
|
export declare const nodeMetadata: InjectionKey<NodeContext>;
|
|
13
13
|
export declare type UseNodeCtx = <T extends Node | Mark = Node | Mark>() => NodeContext<T>;
|
package/lib/VueNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VueNode.d.ts","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,uBAAuB,CA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declare class VueNodeView implements NodeView {
|
|
|
13
13
|
private addPortal;
|
|
14
14
|
private removePortalByKey;
|
|
15
15
|
private options;
|
|
16
|
-
private node;
|
|
17
16
|
private view;
|
|
18
17
|
private getPos;
|
|
19
|
-
private decorations;
|
|
20
18
|
teleportDOM: HTMLElement;
|
|
21
19
|
key: string;
|
|
22
20
|
get isInlineOrMark(): boolean;
|
|
21
|
+
private node;
|
|
22
|
+
private decorations;
|
|
23
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
24
|
get dom(): HTMLElement;
|
|
25
25
|
get contentDOM(): HTMLElement | undefined;
|
|
26
|
+
getPortal: () => DefineComponent;
|
|
26
27
|
renderPortal(): void;
|
|
27
28
|
destroy(): void;
|
|
28
29
|
ignoreMutation(mutation: MutationRecord): boolean;
|
package/lib/VueNodeView.d.ts.map
CHANGED
|
@@ -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,
|
|
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,gBA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AE,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,EACxC,WAAW,EAAE,SAAS,UAAU,EAAE;IAUtC,IAAI,GAAG,gBAEN;IAED,IAAI,UAAU,4BAMb;IAED,SAAS,QAAO,eAAe,CA0B7B;IAEF,YAAY;IAWZ,OAAO;IAMP,cAAc,CAAC,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,234 +1,157 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error();
|
|
16
|
-
});
|
|
17
|
-
const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {});
|
|
18
|
-
const lock = ref(false);
|
|
19
|
-
onMounted(() => {
|
|
20
|
-
if (!dom.value)
|
|
21
|
-
return;
|
|
22
|
-
const editor = getEditor(dom.value, renderVue);
|
|
23
|
-
if (!editor)
|
|
24
|
-
return;
|
|
25
|
-
if (lock.value)
|
|
26
|
-
return;
|
|
27
|
-
loading.value = true;
|
|
28
|
-
lock.value = true;
|
|
29
|
-
editor.create().then((editor2) => {
|
|
30
|
-
editorRef.value = editor2;
|
|
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);
|
|
13
|
+
j(() => {
|
|
14
|
+
if (!t.value)
|
|
31
15
|
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;
|
|
32
19
|
}).finally(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const view = (_a2 = editorRef.value) == null ? void 0 : _a2.action((ctx) => ctx.get(editorViewCtx));
|
|
40
|
-
const root = (_b2 = editorRef.value) == null ? void 0 : _b2.action((ctx) => ctx.get(rootCtx));
|
|
41
|
-
(_c = root == null ? void 0 : root.firstChild) == null ? void 0 : _c.remove();
|
|
42
|
-
view == null ? void 0 : view.destroy();
|
|
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();
|
|
43
26
|
});
|
|
44
|
-
}
|
|
45
|
-
const EditorComponent = defineComponent({
|
|
27
|
+
}, V = p({
|
|
46
28
|
name: "milkdown-dom-root",
|
|
47
|
-
setup: (
|
|
48
|
-
slots
|
|
29
|
+
setup: (o, {
|
|
30
|
+
slots: e
|
|
49
31
|
}) => {
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var _a2;
|
|
58
|
-
return createVNode("div", {
|
|
59
|
-
"ref": ctx.dom
|
|
60
|
-
}, [(_a2 = slots["default"]) == null ? void 0 : _a2.call(slots)]);
|
|
32
|
+
J(o.editor);
|
|
33
|
+
const t = g(O, {});
|
|
34
|
+
return o.editorRef && (o.editorRef.get = () => t.editor.value, o.editorRef.dom = () => t.dom.value), () => {
|
|
35
|
+
var i;
|
|
36
|
+
return c("div", {
|
|
37
|
+
ref: t.dom
|
|
38
|
+
}, [(i = e.default) == null ? void 0 : i.call(e)]);
|
|
61
39
|
};
|
|
62
40
|
}
|
|
63
41
|
});
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const useNodeCtx = () => inject(nodeMetadata);
|
|
67
|
-
const VueNodeContainer = defineComponent({
|
|
42
|
+
V.props = ["editor", "editorRef"];
|
|
43
|
+
const b = Symbol(), de = () => g(b), x = p({
|
|
68
44
|
name: "milkdown-node-container",
|
|
69
45
|
setup: ({
|
|
70
|
-
node,
|
|
71
|
-
view,
|
|
72
|
-
getPos,
|
|
73
|
-
decorations,
|
|
74
|
-
ctx,
|
|
75
|
-
as
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}, (_b2 = (_a2 = context.slots)["default"]) == null ? void 0 : _b2.call(_a2));
|
|
89
|
-
};
|
|
90
|
-
}
|
|
46
|
+
node: o,
|
|
47
|
+
view: e,
|
|
48
|
+
getPos: t,
|
|
49
|
+
decorations: i,
|
|
50
|
+
ctx: a,
|
|
51
|
+
as: s
|
|
52
|
+
}, r) => (w(b, {
|
|
53
|
+
ctx: a,
|
|
54
|
+
node: o,
|
|
55
|
+
view: e,
|
|
56
|
+
getPos: t,
|
|
57
|
+
decorations: i
|
|
58
|
+
}), () => {
|
|
59
|
+
var n, d;
|
|
60
|
+
return K(s, {
|
|
61
|
+
"data-view-container": !0
|
|
62
|
+
}, (d = (n = r.slots).default) == null ? void 0 : d.call(n));
|
|
63
|
+
})
|
|
91
64
|
});
|
|
92
|
-
|
|
93
|
-
const
|
|
65
|
+
x.props = ["ctx", "editor", "node", "view", "getPos", "decorations", "as"];
|
|
66
|
+
const R = p({
|
|
94
67
|
name: "milkdown-content",
|
|
95
68
|
setup: ({
|
|
96
|
-
isInline
|
|
97
|
-
}) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}, null);
|
|
103
|
-
}
|
|
69
|
+
isInline: o
|
|
70
|
+
}) => () => o ? c("span", {
|
|
71
|
+
"data-view-content": !0
|
|
72
|
+
}, null) : c("div", {
|
|
73
|
+
"data-view-content": !0
|
|
74
|
+
}, null)
|
|
104
75
|
});
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
class
|
|
109
|
-
constructor(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
76
|
+
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);
|
|
78
|
+
var P, D;
|
|
79
|
+
class X {
|
|
80
|
+
constructor(e, t, i, a, s, r, n, d, f) {
|
|
81
|
+
v(this, "getPortal", () => {
|
|
82
|
+
const e = this.component, t = this.options.as ? this.options.as : this.isInlineOrMark ? "span" : "div";
|
|
83
|
+
return k(p({
|
|
84
|
+
name: "milkdown-portal",
|
|
85
|
+
setup: () => () => c(U, {
|
|
86
|
+
key: this.key,
|
|
87
|
+
to: this.teleportDOM
|
|
88
|
+
}, {
|
|
89
|
+
default: () => [c(x, {
|
|
90
|
+
as: t,
|
|
91
|
+
ctx: this.ctx,
|
|
92
|
+
node: this.node,
|
|
93
|
+
view: this.view,
|
|
94
|
+
getPos: this.getPos,
|
|
95
|
+
decorations: this.decorations
|
|
96
|
+
}, {
|
|
97
|
+
default: () => [c(e, null, {
|
|
98
|
+
default: () => [c(R, {
|
|
99
|
+
isInline: this.isInlineOrMark
|
|
100
|
+
}, null)]
|
|
101
|
+
})]
|
|
102
|
+
})]
|
|
103
|
+
})
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
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();
|
|
125
111
|
}
|
|
126
112
|
get isInlineOrMark() {
|
|
127
|
-
return this.node instanceof
|
|
113
|
+
return this.node.value instanceof F || this.node.value.isInline;
|
|
128
114
|
}
|
|
129
115
|
get dom() {
|
|
130
116
|
return this.teleportDOM.firstElementChild || this.teleportDOM;
|
|
131
117
|
}
|
|
132
118
|
get contentDOM() {
|
|
133
|
-
if (this.node instanceof
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
return this.teleportDOM.querySelector("[data-view-content]") || this.dom;
|
|
119
|
+
if (!(this.node instanceof I && this.node.isLeaf))
|
|
120
|
+
return this.teleportDOM.querySelector("[data-view-content]") || this.dom;
|
|
137
121
|
}
|
|
138
122
|
renderPortal() {
|
|
139
123
|
if (!this.teleportDOM)
|
|
140
124
|
return;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
setup: () => {
|
|
146
|
-
return () => createVNode(Teleport, {
|
|
147
|
-
"key": this.key,
|
|
148
|
-
"to": this.teleportDOM
|
|
149
|
-
}, {
|
|
150
|
-
default: () => [createVNode(VueNodeContainer, {
|
|
151
|
-
"as": elementName,
|
|
152
|
-
"ctx": this.ctx,
|
|
153
|
-
"node": this.node,
|
|
154
|
-
"view": this.view,
|
|
155
|
-
"getPos": this.getPos,
|
|
156
|
-
"decorations": this.decorations
|
|
157
|
-
}, {
|
|
158
|
-
default: () => [createVNode(CustomComponent, null, {
|
|
159
|
-
default: () => [createVNode(Content, {
|
|
160
|
-
"isInline": this.isInlineOrMark
|
|
161
|
-
}, null)]
|
|
162
|
-
})]
|
|
163
|
-
})]
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
this.addPortal(markRaw(Portal), this.key);
|
|
168
|
-
const instance = getRootInstance();
|
|
169
|
-
if (instance) {
|
|
170
|
-
instance.update();
|
|
171
|
-
}
|
|
125
|
+
const e = this.getPortal();
|
|
126
|
+
this.addPortal(e, this.key);
|
|
127
|
+
const t = Z();
|
|
128
|
+
t && t.update();
|
|
172
129
|
}
|
|
173
130
|
destroy() {
|
|
174
|
-
var
|
|
175
|
-
(
|
|
176
|
-
this.teleportDOM.remove();
|
|
177
|
-
this.removePortalByKey(this.key);
|
|
131
|
+
var e, t;
|
|
132
|
+
(t = (e = this.options).destroy) == null || t.call(e), this.teleportDOM.remove(), this.removePortalByKey(this.key);
|
|
178
133
|
}
|
|
179
|
-
ignoreMutation(
|
|
180
|
-
|
|
181
|
-
return this.options.ignoreMutation(mutation);
|
|
182
|
-
}
|
|
183
|
-
if (!this.dom || !this.contentDOM) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
if (this.node instanceof Node) {
|
|
187
|
-
if (this.node.isLeaf || this.node.isAtom) {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (mutation.type === "selection") {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
if (this.contentDOM === this.dom) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
if (this.contentDOM.contains(mutation.target)) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
134
|
+
ignoreMutation(e) {
|
|
135
|
+
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));
|
|
201
136
|
}
|
|
202
|
-
update(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
137
|
+
update(e, t, i) {
|
|
138
|
+
return (() => {
|
|
139
|
+
var r, n;
|
|
140
|
+
if (this.options.update) {
|
|
141
|
+
const d = (n = (r = this.options).update) == null ? void 0 : n.call(r, e, t, i);
|
|
142
|
+
if (d != null)
|
|
143
|
+
return d;
|
|
208
144
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
if (node === this.node && this.decorations === decorations) {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
this.node = node;
|
|
217
|
-
this.decorations = decorations;
|
|
218
|
-
return true;
|
|
145
|
+
return this.node.value.type !== e.type ? !1 : (e === this.node.value && this.decorations.value === t || (this.node.value = e, this.decorations.value = t), !0);
|
|
146
|
+
})();
|
|
219
147
|
}
|
|
220
148
|
}
|
|
221
|
-
function
|
|
222
|
-
return typeof
|
|
149
|
+
function Y(o) {
|
|
150
|
+
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !q(o);
|
|
223
151
|
}
|
|
224
|
-
const
|
|
152
|
+
const M = {
|
|
225
153
|
instance: null
|
|
226
|
-
}
|
|
227
|
-
const getRootInstance = () => {
|
|
228
|
-
return rootInstance.instance;
|
|
229
|
-
};
|
|
230
|
-
const editorInfoCtxKey = Symbol();
|
|
231
|
-
const refDeprecatedInfo = `
|
|
154
|
+
}, Z = () => M.instance, O = Symbol(), $ = `
|
|
232
155
|
@milkdown/vue:
|
|
233
156
|
Passing ref to VueEditor will soon be deprecated, please use:
|
|
234
157
|
|
|
@@ -242,85 +165,77 @@ effect(() => {
|
|
|
242
165
|
})
|
|
243
166
|
|
|
244
167
|
<VueEditor editor={editor} />
|
|
245
|
-
|
|
246
|
-
const compositionDeprecatedInfo = `
|
|
168
|
+
`, ee = `
|
|
247
169
|
@milkdown/vue:
|
|
248
170
|
Passing editor directly to VueEditor will soon be deprecated, please use:
|
|
249
171
|
|
|
250
172
|
const { editor } = useEditor(/* creator */);
|
|
251
173
|
|
|
252
174
|
<VueEditor editor={editor} />
|
|
253
|
-
|
|
254
|
-
const VueEditor = defineComponent({
|
|
175
|
+
`, te = p({
|
|
255
176
|
name: "milkdown-vue-root",
|
|
256
|
-
setup: (
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
onUnmounted(() => {
|
|
263
|
-
rootInstance.instance = null;
|
|
264
|
-
});
|
|
265
|
-
const addPortal = markRaw((component, key) => {
|
|
266
|
-
portals.push([key, component]);
|
|
177
|
+
setup: (o) => {
|
|
178
|
+
const e = B([]), t = A();
|
|
179
|
+
L(() => {
|
|
180
|
+
M.instance = t.ctx._;
|
|
181
|
+
}), C(() => {
|
|
182
|
+
M.instance = null;
|
|
267
183
|
});
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const {
|
|
276
|
-
getEditorCallback,
|
|
277
|
-
dom,
|
|
278
|
-
editor,
|
|
279
|
-
loading
|
|
280
|
-
} =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
dom,
|
|
291
|
-
editor,
|
|
292
|
-
loading
|
|
293
|
-
});
|
|
294
|
-
return () => {
|
|
295
|
-
const portalElements = portals.map(([id, P]) => createVNode(P, {
|
|
296
|
-
"key": id
|
|
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);
|
|
191
|
+
const r = Object.hasOwnProperty.call(o.editor, "getInstance"), {
|
|
192
|
+
getEditorCallback: n,
|
|
193
|
+
dom: d,
|
|
194
|
+
editor: f,
|
|
195
|
+
loading: h
|
|
196
|
+
} = r ? o.editor.editor : o.editor;
|
|
197
|
+
return _(() => {
|
|
198
|
+
r && console.warn(ee), o.editorRef && console.warn($);
|
|
199
|
+
}), w(O, {
|
|
200
|
+
dom: d,
|
|
201
|
+
editor: f,
|
|
202
|
+
loading: h
|
|
203
|
+
}), () => {
|
|
204
|
+
const l = e.map(([m, y]) => c(y, {
|
|
205
|
+
key: m
|
|
297
206
|
}, null));
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
},
|
|
302
|
-
default: () => [
|
|
207
|
+
return c(V, {
|
|
208
|
+
editorRef: o.editorRef,
|
|
209
|
+
editor: n.value
|
|
210
|
+
}, Y(l) ? l : {
|
|
211
|
+
default: () => [l]
|
|
303
212
|
});
|
|
304
213
|
};
|
|
305
214
|
}
|
|
306
215
|
});
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
const
|
|
310
|
-
const editor = ref();
|
|
311
|
-
const loading = ref(true);
|
|
312
|
-
const getEditorCallback = ref((...args) => getEditor(...args));
|
|
216
|
+
te.props = ["editor", "editorRef"];
|
|
217
|
+
const le = (o) => {
|
|
218
|
+
const e = u(null), t = u(), i = u(!0), a = u((...s) => o(...s));
|
|
313
219
|
return {
|
|
314
|
-
loading,
|
|
315
|
-
getInstance: () =>
|
|
316
|
-
getDom: () =>
|
|
220
|
+
loading: i,
|
|
221
|
+
getInstance: () => t.value,
|
|
222
|
+
getDom: () => e.value,
|
|
317
223
|
editor: {
|
|
318
|
-
getEditorCallback,
|
|
319
|
-
dom,
|
|
320
|
-
editor,
|
|
321
|
-
loading
|
|
224
|
+
getEditorCallback: a,
|
|
225
|
+
dom: e,
|
|
226
|
+
editor: t,
|
|
227
|
+
loading: i
|
|
322
228
|
}
|
|
323
229
|
};
|
|
324
230
|
};
|
|
325
|
-
export {
|
|
231
|
+
export {
|
|
232
|
+
R as Content,
|
|
233
|
+
te as VueEditor,
|
|
234
|
+
x as VueNodeContainer,
|
|
235
|
+
O as editorInfoCtxKey,
|
|
236
|
+
Z as getRootInstance,
|
|
237
|
+
b as nodeMetadata,
|
|
238
|
+
le as useEditor,
|
|
239
|
+
de as useNodeCtx
|
|
240
|
+
};
|
|
326
241
|
//# sourceMappingURL=index.es.js.map
|
package/lib/index.es.js.map
CHANGED
|
@@ -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 { 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 new Error();\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 } from 'vue';\n\nexport type NodeContext<T extends Node | Mark = Node | Mark> = {\n ctx: Ctx;\n node: T;\n view: EditorView;\n getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);\n decorations: 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, 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 instanceof Mark || this.node.isInline;\n }\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 private node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n private decorations: readonly Decoration[],\n ) {\n this.key = nanoid();\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 renderPortal() {\n if (!this.teleportDOM) return;\n\n const CustomComponent = this.component;\n const elementName = this.options.as ? this.options.as : this.isInlineOrMark ? 'span' : 'div';\n const Portal = 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 });\n this.addPortal(markRaw(Portal) as DefineComponent, 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 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.type !== node.type) {\n return false;\n }\n\n if (node === this.node && this.decorations === decorations) {\n return true;\n }\n\n this.node = node;\n this.decorations = decorations;\n return true;\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","selectNode","deselectNode","key","elementName","isInlineOrMark","teleportDOM","document","createElement","renderPortal","Mark","firstElementChild","contentDOM","Node","isLeaf","undefined","querySelector","CustomComponent","Portal","markRaw","instance","getRootInstance","update","destroy","remove","ignoreMutation","mutation","isAtom","type","contains","target","innerDecorations","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":";;;;;;;;;;;AAQO,MAAM,cAET,OAAO;AAEE,MAAA,eAAe,CAAC,cAAyB;AAC5C,QAAA,YAAY,OAAkB,aAAa,MAAM;AACnD,UAAM,IAAI,MAAM;AAAA,EAAA,CACnB;AACK,QAAA,EAAE,KAAK,SAAS,QAAQ,cAAc,OAAO,kBAAkB,CAAA,CAAmB;AAClF,QAAA,OAAO,IAAI,KAAK;AAEtB,YAAU,MAAM;AACZ,QAAI,CAAC,IAAI;AAAO;AAEhB,UAAM,SAAS,UAAU,IAAI,OAAO,SAAS;AAC7C,QAAI,CAAC;AAAQ;AAEb,QAAI,KAAK;AAAO;AAEhB,YAAQ,QAAQ;AAChB,SAAK,QAAQ;AAEb,WACK,OAAO,EACP,KAAK,CAAC,YAAW;AACd,gBAAU,QAAQ;AAClB;AAAA,IAAA,CACH,EACA,QAAQ,MAAM;AACX,cAAQ,QAAQ;AAChB,WAAK,QAAQ;AAAA,IAAA,C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AKxB,iBAAb;AAAA,MACH;AAAA,IACJ,CAPK;AASN9C,YAAQhB,kBAAkB;AAAA,MACtBI;AAAAA,MACAP;AAAAA,MACAsF;AAAAA,IAHsB,CAAnB;AAMP,WAAO,MAAM;AACT,YAAMI,iBAAiBtB,QAAQuB,IAAI,CAAC,CAACC,IAAIC,OAANrF,YAAA,GAAA;AAAA,QAAA,OAAqBoF;AAAAA,MAArB,GAAA,IAAA,CAAZ;AACvB,aAAApF,YAAA,iBAAA;AAAA,QAAA,aACgCX,MAAMO;AAAAA,QADtC,UACyDiF,kBAAkB/E;AAAAA,SAClEoF,QAAAA,cAFT,IAESA,iBAFT;AAAA,QAAA,SAAA,MAAA,CAESA,cAFT;AAAA,MAAA,CAAA;AAAA;EAMP;AAzDmF,CAAhD;AA2DxCvB,UAAU,WAAW,CAAC,UAAU,WAAX;AC9GR,MAAA,YAAY,CAAC,cAA0C;AAC1D,QAAA,MAAM,IAA2B,IAAI;AAC3C,QAAM,SAAS;AACT,QAAA,UAAU,IAAI,IAAI;AACxB,QAAM,oBAAoB,IAAe,IAAI,SAAS,UAAU,GAAG,IAAI,CAAC;AAEjE,SAAA;AAAA,IACH;AAAA,IACA,aAAa,MAAM,OAAO;AAAA,IAC1B,QAAQ,MAAM,IAAI;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, 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":";;;;;;;;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,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,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetEditor.d.ts","sourceRoot":"","sources":["../src/useGetEditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAA0B,MAAM,gBAAgB,CAAC;
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/vue",
|
|
3
|
-
"version": "6.2
|
|
3
|
+
"version": "6.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.es.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"vue"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@milkdown/utils": "6.2
|
|
19
|
+
"@milkdown/utils": "6.3.2",
|
|
20
|
+
"@milkdown/exception": "6.3.2",
|
|
20
21
|
"nanoid": "^4.0.0",
|
|
21
|
-
"tslib": "^2.
|
|
22
|
+
"tslib": "^2.4.0"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"@milkdown/core": "^6.0.1",
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
"vue": "^3.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@milkdown/core": "6.2
|
|
30
|
-
"@milkdown/prose": "6.2
|
|
30
|
+
"@milkdown/core": "6.3.2",
|
|
31
|
+
"@milkdown/prose": "6.3.2",
|
|
31
32
|
"vue": "^3.0.0"
|
|
32
33
|
},
|
|
33
34
|
"nx": {
|
package/src/VueNode.tsx
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { Ctx } from '@milkdown/core';
|
|
3
3
|
import { Mark, Node } from '@milkdown/prose/model';
|
|
4
4
|
import { Decoration, EditorView } from '@milkdown/prose/view';
|
|
5
|
-
import { defineComponent, h, inject, InjectionKey, provide } from 'vue';
|
|
5
|
+
import { defineComponent, h, inject, InjectionKey, provide, Ref } from 'vue';
|
|
6
6
|
|
|
7
7
|
export type NodeContext<T extends Node | Mark = Node | Mark> = {
|
|
8
8
|
ctx: Ctx;
|
|
9
|
-
node: T
|
|
9
|
+
node: Ref<T>;
|
|
10
10
|
view: EditorView;
|
|
11
11
|
getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);
|
|
12
|
-
decorations: readonly Decoration[]
|
|
12
|
+
decorations: Ref<readonly Decoration[]>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export const nodeMetadata: InjectionKey<NodeContext> = Symbol();
|
package/src/VueNodeView.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
NodeViewConstructor,
|
|
11
11
|
} from '@milkdown/prose/view';
|
|
12
12
|
import { customAlphabet } from 'nanoid';
|
|
13
|
-
import { DefineComponent, defineComponent, h, markRaw, Teleport } from 'vue';
|
|
13
|
+
import { DefineComponent, defineComponent, h, markRaw, Ref, ref, Teleport } from 'vue';
|
|
14
14
|
|
|
15
15
|
import { getRootInstance } from '.';
|
|
16
16
|
import { Content, VueNodeContainer } from './VueNode';
|
|
@@ -39,21 +39,26 @@ export class VueNodeView implements NodeView {
|
|
|
39
39
|
key: string;
|
|
40
40
|
|
|
41
41
|
get isInlineOrMark() {
|
|
42
|
-
return this.node instanceof Mark || this.node.isInline;
|
|
42
|
+
return this.node.value instanceof Mark || this.node.value.isInline;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
private node: Ref<Node | Mark>;
|
|
46
|
+
private decorations: Ref<readonly Decoration[]>;
|
|
47
|
+
|
|
45
48
|
constructor(
|
|
46
49
|
private ctx: Ctx,
|
|
47
50
|
private component: DefineComponent,
|
|
48
51
|
private addPortal: (portal: DefineComponent, key: string) => void,
|
|
49
52
|
private removePortalByKey: (key: string) => void,
|
|
50
53
|
private options: RenderOptions,
|
|
51
|
-
|
|
54
|
+
node: Node | Mark,
|
|
52
55
|
private view: EditorView,
|
|
53
56
|
private getPos: boolean | (() => number),
|
|
54
|
-
|
|
57
|
+
decorations: readonly Decoration[],
|
|
55
58
|
) {
|
|
56
59
|
this.key = nanoid();
|
|
60
|
+
this.node = ref(node);
|
|
61
|
+
this.decorations = ref(decorations);
|
|
57
62
|
const elementName = options.as ? options.as : this.isInlineOrMark ? 'span' : 'div';
|
|
58
63
|
this.teleportDOM = document.createElement(elementName);
|
|
59
64
|
this.renderPortal();
|
|
@@ -71,33 +76,39 @@ export class VueNodeView implements NodeView {
|
|
|
71
76
|
return this.teleportDOM.querySelector<HTMLElement>('[data-view-content]') || this.dom;
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
getPortal = (): DefineComponent => {
|
|
80
|
+
const CustomComponent = this.component;
|
|
81
|
+
const elementName = this.options.as ? this.options.as : this.isInlineOrMark ? 'span' : 'div';
|
|
82
|
+
return markRaw(
|
|
83
|
+
defineComponent({
|
|
84
|
+
name: 'milkdown-portal',
|
|
85
|
+
setup: () => {
|
|
86
|
+
return () => (
|
|
87
|
+
<Teleport key={this.key} to={this.teleportDOM}>
|
|
88
|
+
<VueNodeContainer
|
|
89
|
+
as={elementName}
|
|
90
|
+
ctx={this.ctx}
|
|
91
|
+
node={this.node}
|
|
92
|
+
view={this.view}
|
|
93
|
+
getPos={this.getPos}
|
|
94
|
+
decorations={this.decorations}
|
|
95
|
+
>
|
|
96
|
+
<CustomComponent>
|
|
97
|
+
<Content isInline={this.isInlineOrMark} />
|
|
98
|
+
</CustomComponent>
|
|
99
|
+
</VueNodeContainer>
|
|
100
|
+
</Teleport>
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
}) as DefineComponent,
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
74
107
|
renderPortal() {
|
|
75
108
|
if (!this.teleportDOM) return;
|
|
76
109
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const Portal = defineComponent({
|
|
80
|
-
name: 'milkdown-portal',
|
|
81
|
-
setup: () => {
|
|
82
|
-
return () => (
|
|
83
|
-
<Teleport key={this.key} to={this.teleportDOM}>
|
|
84
|
-
<VueNodeContainer
|
|
85
|
-
as={elementName}
|
|
86
|
-
ctx={this.ctx}
|
|
87
|
-
node={this.node}
|
|
88
|
-
view={this.view}
|
|
89
|
-
getPos={this.getPos}
|
|
90
|
-
decorations={this.decorations}
|
|
91
|
-
>
|
|
92
|
-
<CustomComponent>
|
|
93
|
-
<Content isInline={this.isInlineOrMark} />
|
|
94
|
-
</CustomComponent>
|
|
95
|
-
</VueNodeContainer>
|
|
96
|
-
</Teleport>
|
|
97
|
-
);
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
this.addPortal(markRaw(Portal) as DefineComponent, this.key);
|
|
110
|
+
const Portal = this.getPortal();
|
|
111
|
+
this.addPortal(Portal, this.key);
|
|
101
112
|
const instance = getRootInstance();
|
|
102
113
|
if (instance) {
|
|
103
114
|
instance.update();
|
|
@@ -140,23 +151,29 @@ export class VueNodeView implements NodeView {
|
|
|
140
151
|
}
|
|
141
152
|
|
|
142
153
|
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
const innerUpdate = () => {
|
|
155
|
+
if (this.options.update) {
|
|
156
|
+
const result = this.options.update?.(node, decorations, innerDecorations);
|
|
157
|
+
if (result != null) {
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (this.node.value.type !== node.type) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (node === this.node.value && this.decorations.value === decorations) {
|
|
166
|
+
return true;
|
|
147
167
|
}
|
|
148
|
-
}
|
|
149
|
-
if (this.node.type !== node.type) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
168
|
|
|
153
|
-
|
|
169
|
+
this.node.value = node;
|
|
170
|
+
this.decorations.value = decorations;
|
|
154
171
|
return true;
|
|
155
|
-
}
|
|
172
|
+
};
|
|
156
173
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return
|
|
174
|
+
const shouldUpdate = innerUpdate();
|
|
175
|
+
|
|
176
|
+
return shouldUpdate;
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
selectNode = this.options?.selectNode;
|
package/src/useGetEditor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { Ctx, editorViewCtx, rootCtx } from '@milkdown/core';
|
|
3
|
+
import { vueRendererCallOutOfScope } from '@milkdown/exception';
|
|
3
4
|
import { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';
|
|
4
5
|
import { DefineComponent, inject, InjectionKey, onMounted, onUnmounted, ref } from 'vue';
|
|
5
6
|
|
|
@@ -12,7 +13,7 @@ export const rendererKey: InjectionKey<
|
|
|
12
13
|
|
|
13
14
|
export const useGetEditor = (getEditor: GetEditor) => {
|
|
14
15
|
const renderVue = inject<RenderVue>(rendererKey, () => {
|
|
15
|
-
throw
|
|
16
|
+
throw vueRendererCallOutOfScope();
|
|
16
17
|
});
|
|
17
18
|
const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx);
|
|
18
19
|
const lock = ref(false);
|