@milkdown/vue 6.1.4 → 6.3.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 +8 -25
- package/lib/Editor.d.ts.map +1 -1
- package/lib/EditorComponent.d.ts +14 -0
- package/lib/EditorComponent.d.ts.map +1 -0
- package/lib/VueNode.d.ts +9 -7
- package/lib/VueNode.d.ts.map +1 -1
- package/lib/VueNodeView.d.ts +14 -16
- package/lib/VueNodeView.d.ts.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +206 -226
- package/lib/index.es.js.map +1 -1
- package/lib/types.d.ts +26 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/useEditor.d.ts +3 -0
- package/lib/useEditor.d.ts.map +1 -0
- package/lib/useGetEditor.d.ts +7 -0
- package/lib/useGetEditor.d.ts.map +1 -0
- package/package.json +7 -6
- package/src/Editor.tsx +57 -71
- package/src/EditorComponent.tsx +25 -0
- package/src/VueNode.tsx +8 -5
- package/src/VueNodeView.tsx +79 -51
- package/src/index.ts +3 -1
- package/src/types.ts +50 -0
- package/src/useEditor.ts +25 -0
- package/src/useGetEditor.ts +51 -0
package/lib/index.es.js
CHANGED
|
@@ -1,261 +1,241 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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)
|
|
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;
|
|
19
|
+
}).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();
|
|
26
|
+
});
|
|
27
|
+
}, V = p({
|
|
28
|
+
name: "milkdown-dom-root",
|
|
29
|
+
setup: (o, {
|
|
30
|
+
slots: e
|
|
31
|
+
}) => {
|
|
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)]);
|
|
35
39
|
};
|
|
36
40
|
}
|
|
37
41
|
});
|
|
38
|
-
|
|
39
|
-
const
|
|
42
|
+
V.props = ["editor", "editorRef"];
|
|
43
|
+
const b = Symbol(), de = () => g(b), x = p({
|
|
44
|
+
name: "milkdown-node-container",
|
|
45
|
+
setup: ({
|
|
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
|
+
})
|
|
64
|
+
});
|
|
65
|
+
x.props = ["ctx", "editor", "node", "view", "getPos", "decorations", "as"];
|
|
66
|
+
const R = p({
|
|
40
67
|
name: "milkdown-content",
|
|
41
68
|
setup: ({
|
|
42
|
-
isInline
|
|
43
|
-
}) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}, null);
|
|
49
|
-
}
|
|
69
|
+
isInline: o
|
|
70
|
+
}) => () => o ? c("span", {
|
|
71
|
+
"data-view-content": !0
|
|
72
|
+
}, null) : c("div", {
|
|
73
|
+
"data-view-content": !0
|
|
74
|
+
}, null)
|
|
50
75
|
});
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
class
|
|
55
|
-
constructor(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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();
|
|
71
111
|
}
|
|
72
112
|
get isInlineOrMark() {
|
|
73
|
-
return this.node instanceof
|
|
113
|
+
return this.node.value instanceof F || this.node.value.isInline;
|
|
74
114
|
}
|
|
75
115
|
get dom() {
|
|
76
116
|
return this.teleportDOM.firstElementChild || this.teleportDOM;
|
|
77
117
|
}
|
|
78
118
|
get contentDOM() {
|
|
79
|
-
if (this.node instanceof
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
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;
|
|
83
121
|
}
|
|
84
122
|
renderPortal() {
|
|
85
123
|
if (!this.teleportDOM)
|
|
86
124
|
return;
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
setup: () => {
|
|
92
|
-
return () => createVNode(Teleport, {
|
|
93
|
-
"key": this.key,
|
|
94
|
-
"to": this.teleportDOM
|
|
95
|
-
}, {
|
|
96
|
-
default: () => [createVNode(VueNodeContainer, {
|
|
97
|
-
"as": elementName,
|
|
98
|
-
"ctx": this.ctx,
|
|
99
|
-
"node": this.node,
|
|
100
|
-
"view": this.view,
|
|
101
|
-
"getPos": this.getPos,
|
|
102
|
-
"decorations": this.decorations
|
|
103
|
-
}, {
|
|
104
|
-
default: () => [createVNode(CustomComponent, null, {
|
|
105
|
-
default: () => [createVNode(Content, {
|
|
106
|
-
"isInline": this.isInlineOrMark
|
|
107
|
-
}, null)]
|
|
108
|
-
})]
|
|
109
|
-
})]
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
this.addPortal(markRaw(Portal), this.key);
|
|
114
|
-
const instance = getRootInstance();
|
|
115
|
-
if (instance) {
|
|
116
|
-
instance.update();
|
|
117
|
-
}
|
|
125
|
+
const e = this.getPortal();
|
|
126
|
+
this.addPortal(e, this.key);
|
|
127
|
+
const t = Z();
|
|
128
|
+
t && t.update();
|
|
118
129
|
}
|
|
119
130
|
destroy() {
|
|
120
|
-
var
|
|
121
|
-
(
|
|
122
|
-
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);
|
|
123
133
|
}
|
|
124
|
-
ignoreMutation(
|
|
125
|
-
|
|
126
|
-
return this.options.ignoreMutation(mutation);
|
|
127
|
-
}
|
|
128
|
-
if (!this.dom || !this.contentDOM) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
if (this.node instanceof Node) {
|
|
132
|
-
if (this.node.isLeaf || this.node.isAtom) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (mutation.type === "selection") {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (this.contentDOM === this.dom) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (this.contentDOM.contains(mutation.target)) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
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));
|
|
146
136
|
}
|
|
147
|
-
update(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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;
|
|
153
144
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
if (node === this.node && this.decorations === decorations) {
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
this.node = node;
|
|
162
|
-
this.decorations = decorations;
|
|
163
|
-
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
|
+
})();
|
|
164
147
|
}
|
|
165
148
|
}
|
|
166
|
-
function
|
|
167
|
-
return typeof
|
|
149
|
+
function Y(o) {
|
|
150
|
+
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !q(o);
|
|
168
151
|
}
|
|
169
|
-
const
|
|
170
|
-
const useGetEditor = (getEditor) => {
|
|
171
|
-
const divRef = ref(null);
|
|
172
|
-
const renderVue = inject(rendererKey, () => {
|
|
173
|
-
throw new Error();
|
|
174
|
-
});
|
|
175
|
-
const editorRef = markRaw({});
|
|
176
|
-
onMounted(() => {
|
|
177
|
-
if (!divRef.value)
|
|
178
|
-
return;
|
|
179
|
-
getEditor(divRef.value, renderVue).create().then((editor) => {
|
|
180
|
-
editorRef.editor = editor;
|
|
181
|
-
return;
|
|
182
|
-
}).catch((e) => console.error(e));
|
|
183
|
-
});
|
|
184
|
-
onUnmounted(() => {
|
|
185
|
-
var _a2, _b2, _c;
|
|
186
|
-
const view = (_a2 = editorRef.editor) == null ? void 0 : _a2.action((ctx) => ctx.get(editorViewCtx));
|
|
187
|
-
const root = (_b2 = editorRef.editor) == null ? void 0 : _b2.action((ctx) => ctx.get(rootCtx));
|
|
188
|
-
(_c = root == null ? void 0 : root.firstChild) == null ? void 0 : _c.remove();
|
|
189
|
-
view == null ? void 0 : view.destroy();
|
|
190
|
-
});
|
|
191
|
-
return {
|
|
192
|
-
divRef,
|
|
193
|
-
editorRef
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
const EditorComponent = defineComponent({
|
|
197
|
-
name: "milkdown-dom-root",
|
|
198
|
-
setup: (props, {
|
|
199
|
-
slots
|
|
200
|
-
}) => {
|
|
201
|
-
const refs = useGetEditor(props.editor);
|
|
202
|
-
if (props.editorRef) {
|
|
203
|
-
props.editorRef.value = {
|
|
204
|
-
get: () => refs.editorRef.editor,
|
|
205
|
-
dom: () => refs.divRef.value
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
return () => {
|
|
209
|
-
var _a2;
|
|
210
|
-
return createVNode("div", {
|
|
211
|
-
"ref": refs.divRef
|
|
212
|
-
}, [(_a2 = slots["default"]) == null ? void 0 : _a2.call(slots)]);
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
EditorComponent["props"] = ["editor", "editorRef"];
|
|
217
|
-
const rootInstance = {
|
|
152
|
+
const M = {
|
|
218
153
|
instance: null
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
154
|
+
}, Z = () => M.instance, O = Symbol(), $ = `
|
|
155
|
+
@milkdown/vue:
|
|
156
|
+
Passing ref to VueEditor will soon be deprecated, please use:
|
|
157
|
+
|
|
158
|
+
const { editor, getInstance, getDom, loading } = useEditor(/* creator */);
|
|
159
|
+
|
|
160
|
+
effect(() => {
|
|
161
|
+
if (!loading) {
|
|
162
|
+
const editor = getInstance();
|
|
163
|
+
const rootDOM = getDom();
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
<VueEditor editor={editor} />
|
|
168
|
+
`, ee = `
|
|
169
|
+
@milkdown/vue:
|
|
170
|
+
Passing editor directly to VueEditor will soon be deprecated, please use:
|
|
171
|
+
|
|
172
|
+
const { editor } = useEditor(/* creator */);
|
|
173
|
+
|
|
174
|
+
<VueEditor editor={editor} />
|
|
175
|
+
`, te = p({
|
|
224
176
|
name: "milkdown-vue-root",
|
|
225
|
-
setup: (
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
177
|
+
setup: (o) => {
|
|
178
|
+
const e = B([]), t = A();
|
|
179
|
+
L(() => {
|
|
180
|
+
M.instance = t.ctx._;
|
|
181
|
+
}), C(() => {
|
|
182
|
+
M.instance = null;
|
|
230
183
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
|
246
206
|
}, null));
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
default: () => [
|
|
207
|
+
return c(V, {
|
|
208
|
+
editorRef: o.editorRef,
|
|
209
|
+
editor: n.value
|
|
210
|
+
}, Y(l) ? l : {
|
|
211
|
+
default: () => [l]
|
|
252
212
|
});
|
|
253
213
|
};
|
|
254
214
|
}
|
|
255
215
|
});
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
216
|
+
te.props = ["editor", "editorRef"];
|
|
217
|
+
const le = (o) => {
|
|
218
|
+
const e = u(null), t = u(), i = u(!0), a = u((...s) => o(...s));
|
|
219
|
+
return {
|
|
220
|
+
loading: i,
|
|
221
|
+
getInstance: () => t.value,
|
|
222
|
+
getDom: () => e.value,
|
|
223
|
+
editor: {
|
|
224
|
+
getEditorCallback: a,
|
|
225
|
+
dom: e,
|
|
226
|
+
editor: t,
|
|
227
|
+
loading: i
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
};
|
|
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
|
|
259
240
|
};
|
|
260
|
-
export { EditorComponent, VueEditor, getRootInstance, nodeMetadata, useEditor };
|
|
261
241
|
//# sourceMappingURL=index.es.js.map
|
package/lib/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/VueNode.tsx","../src/VueNodeView.tsx","../src/Editor.tsx"],"sourcesContent":["/* 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, InjectionKey, provide } from 'vue';\n\nexport type NodeContext = {\n ctx: Ctx;\n node: Node | Mark;\n view: EditorView;\n getPos: boolean | (() => number);\n decorations: Decoration[];\n};\n\nexport const nodeMetadata: InjectionKey<NodeContext> = Symbol();\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 type { ViewFactory } from '@milkdown/prose';\nimport { Mark, Node } from '@milkdown/prose/model';\nimport type { Decoration, DecorationSet, EditorView, NodeView } 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 } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy' | 'update'>\n>;\n\nexport const createVueView =\n (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>\n (component: DefineComponent, options: RenderOptions = {}): ((ctx: Ctx) => ViewFactory) =>\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: 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;\n }\n\n get contentDOM() {\n if (this.node instanceof Node && this.node.isLeaf) {\n return null;\n }\n\n return this.teleportDOM.querySelector('[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.removePortalByKey(this.key);\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\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.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: Decoration[], innerDecorations: DecorationSet) {\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 { Ctx, Editor, editorViewCtx, rootCtx } from '@milkdown/core';\nimport { ViewFactory } from '@milkdown/prose';\nimport {\n ComponentInternalInstance,\n DefineComponent,\n defineComponent,\n getCurrentInstance,\n h,\n inject,\n InjectionKey,\n markRaw,\n onBeforeMount,\n onMounted,\n onUnmounted,\n provide,\n Ref,\n ref,\n shallowReactive,\n} from 'vue';\n\nimport { AnyVueComponent } from './utils';\nimport { createVueView, RenderOptions } from './VueNodeView';\n\nconst rendererKey: InjectionKey<(component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => ViewFactory> =\n Symbol();\n\ntype GetEditor = (\n container: HTMLDivElement,\n renderVue: (Component: AnyVueComponent, options?: RenderOptions) => (ctx: Ctx) => ViewFactory,\n) => Editor;\n\nconst useGetEditor = (getEditor: GetEditor) => {\n const divRef = ref<HTMLDivElement | null>(null);\n const renderVue = inject<(Component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => ViewFactory>(\n rendererKey,\n () => {\n throw new Error();\n },\n );\n const editorRef = markRaw<{ editor?: Editor }>({});\n onMounted(() => {\n if (!divRef.value) return;\n\n getEditor(divRef.value, renderVue)\n .create()\n .then((editor) => {\n editorRef.editor = editor;\n return;\n })\n .catch((e) => console.error(e));\n });\n onUnmounted(() => {\n const view = editorRef.editor?.action((ctx) => ctx.get(editorViewCtx));\n const root = editorRef.editor?.action((ctx) => ctx.get(rootCtx)) as HTMLElement;\n\n root?.firstChild?.remove();\n view?.destroy();\n });\n\n return { divRef, editorRef };\n};\n\nexport const EditorComponent = defineComponent<{ editor: GetEditor; editorRef?: Ref<EditorRef> }>({\n name: 'milkdown-dom-root',\n setup: (props, { slots }) => {\n const refs = useGetEditor(props.editor);\n if (props.editorRef) {\n props.editorRef.value = {\n get: () => refs.editorRef.editor,\n dom: () => refs.divRef.value,\n };\n }\n\n return () => <div ref={refs.divRef}>{slots['default']?.()}</div>;\n },\n});\nEditorComponent['props'] = ['editor', 'editorRef'];\n\nexport type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };\n\nconst rootInstance: {\n instance: null | ComponentInternalInstance;\n} = {\n instance: null,\n};\nexport const getRootInstance = () => {\n return rootInstance.instance;\n};\n\ntype PortalPair = [key: string, component: DefineComponent];\nexport const VueEditor = defineComponent<{ editor: GetEditor; editorRef?: Ref<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 provide(rendererKey, renderVue);\n\n return () => {\n const portalElements = portals.map(([id, P]) => <P key={id} />);\n return (\n <EditorComponent editorRef={props.editorRef} editor={props.editor}>\n {portalElements}\n </EditorComponent>\n );\n };\n },\n});\nVueEditor['props'] = ['editor', 'editorRef'];\n\nexport const useEditor = (getEditor: GetEditor) => {\n return (...args: Parameters<GetEditor>) => getEditor(...args);\n};\n"],"names":["nodeMetadata","Symbol","VueNodeContainer","defineComponent","name","setup","node","view","getPos","decorations","ctx","as","context","provide","h","slots","Content","isInline","_createVNode","nanoid","customAlphabet","createVueView","addPortal","removePortalByKey","component","options","VueNodeView","constructor","selectNode","deselectNode","key","elementName","isInlineOrMark","teleportDOM","document","createElement","renderPortal","Mark","dom","firstElementChild","contentDOM","Node","isLeaf","querySelector","CustomComponent","Portal","markRaw","instance","getRootInstance","update","destroy","ignoreMutation","mutation","isAtom","type","contains","target","innerDecorations","result","rendererKey","useGetEditor","getEditor","divRef","ref","renderVue","inject","Error","editorRef","onMounted","value","create","then","editor","catch","e","console","error","onUnmounted","action","get","editorViewCtx","root","rootCtx","firstChild","remove","EditorComponent","props","refs","rootInstance","VueEditor","portals","shallowReactive","getCurrentInstance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AA,QAAA,OAAqBoF;AAAAA,MAArB,GAAA,IAAA,CAAZ;AACvB,aAAApF,YAAA,iBAAA;AAAA,QAAA,aACgCoE,MAAMnB;AAAAA,QADtC,UACyDmB,MAAMd;AAAAA,SACtD4B,QAAAA,cAFT,IAESA,iBAFT;AAAA,QAAA,SAAA,MAAA,CAESA,cAFT;AAAA,MAAA,CAAA;AAAA;EAMP;AAlCuF,CAApD;AAoCxCX,UAAU,WAAW,CAAC,UAAU,WAAX;AAERe,MAAAA,YAAa3C,eAAyB;AAC/C,SAAO,IAAI4C,SAAgC5C,UAAU,GAAG4C,IAAJ;AACvD;;"}
|
|
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,IAAO,EAAI,EAAK;AAEtB,IAAU,MAAM;AACZ,QAAI,CAAC,EAAI;AAAO;AAEhB,UAAM,IAAS,EAAU,EAAI,OAAO,CAAS;AAC7C,IAAI,CAAC,KAED,EAAK,SAET,GAAQ,QAAQ,IAChB,EAAK,QAAQ,IAEb,EACK,OAAO,EACP,KAAK,CAAC,MAAW;AACd,QAAU,QAAQ;AAAA,IAClB,CACH,EACA,QAAQ,MAAM;AACX,QAAQ,QAAQ,IAChB,EAAK,QAAQ;AAAA,IAAA,CAChB,EACA,MAAM,CAAC,MAAM,QAAQ,MAAM,CAAC,CAAC;AAAA,EAAA,CACrC,GACD,EAAY,MAAM;;AACR,UAAA,IAAO,OAAU,UAAV,kBAAiB,OAAO,CAAC,MAAQ,EAAI,IAAI,CAAa,IAC7D,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I,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;"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Ctx, Editor } from '@milkdown/core';
|
|
2
|
+
import type { Mark, Node } from '@milkdown/prose/model';
|
|
3
|
+
import { Decoration, DecorationSource, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view';
|
|
4
|
+
import { Ref } from 'vue';
|
|
5
|
+
import { AnyVueComponent } from './utils';
|
|
6
|
+
export declare type RenderOptions = Partial<{
|
|
7
|
+
as: string;
|
|
8
|
+
update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
|
|
9
|
+
} & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>>;
|
|
10
|
+
export declare type RenderVue<U = never> = <T extends Node | Mark = Node | Mark>(Component: AnyVueComponent, options?: RenderOptions) => (ctx: Ctx) => U extends never ? T extends Node ? NodeViewConstructor : T extends Mark ? MarkViewConstructor : NodeViewConstructor & MarkViewConstructor : U extends Node ? NodeViewConstructor : U extends Mark ? MarkViewConstructor : NodeViewConstructor & MarkViewConstructor;
|
|
11
|
+
export declare type GetEditor = (container: HTMLDivElement, renderVue: RenderVue) => Editor;
|
|
12
|
+
export declare type EditorInfoCtx = {
|
|
13
|
+
dom: Ref<HTMLDivElement | null>;
|
|
14
|
+
editor: Ref<Editor | undefined>;
|
|
15
|
+
loading: Ref<boolean>;
|
|
16
|
+
};
|
|
17
|
+
export declare type EditorInfo = {
|
|
18
|
+
getEditorCallback: Ref<GetEditor>;
|
|
19
|
+
} & EditorInfoCtx;
|
|
20
|
+
export declare type UseEditorReturn = {
|
|
21
|
+
loading: Ref<boolean>;
|
|
22
|
+
getInstance: () => Editor | undefined;
|
|
23
|
+
getDom: () => HTMLDivElement | null;
|
|
24
|
+
editor: EditorInfo;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACxH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,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,oBAAY,SAAS,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EACnE,SAAS,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE,aAAa,KACtB,CACD,GAAG,EAAE,GAAG,KACP,CAAC,SAAS,KAAK,GACd,CAAC,SAAS,IAAI,GACV,mBAAmB,GACnB,CAAC,SAAS,IAAI,GACd,mBAAmB,GACnB,mBAAmB,GAAG,mBAAmB,GAC7C,CAAC,SAAS,IAAI,GACd,mBAAmB,GACnB,CAAC,SAAS,IAAI,GACd,mBAAmB,GACnB,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,oBAAY,SAAS,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,KAAK,MAAM,CAAC;AAEpF,oBAAY,aAAa,GAAG;IACxB,GAAG,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAChC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CACzB,CAAC;AAEF,oBAAY,UAAU,GAAG;IACrB,iBAAiB,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;CACrC,GAAG,aAAa,CAAC;AAElB,oBAAY,eAAe,GAAG;IAC1B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,WAAW,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACtC,MAAM,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditor.d.ts","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAErD,eAAO,MAAM,SAAS,cAAe,SAAS,KAAG,eAiBhD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ctx } from '@milkdown/core';
|
|
2
|
+
import { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';
|
|
3
|
+
import { DefineComponent, InjectionKey } from 'vue';
|
|
4
|
+
import { GetEditor, RenderOptions } from './types';
|
|
5
|
+
export declare const rendererKey: InjectionKey<(component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor>;
|
|
6
|
+
export declare const useGetEditor: (getEditor: GetEditor) => void;
|
|
7
|
+
//# sourceMappingURL=useGetEditor.d.ts.map
|
|
@@ -0,0 +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"}
|