@milkdown/vue 6.5.4 → 7.0.0-next.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 +4 -10
- package/lib/Editor.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +47 -224
- package/lib/index.es.js.map +1 -1
- package/lib/types.d.ts +4 -16
- package/lib/types.d.ts.map +1 -1
- package/lib/useEditor.d.ts.map +1 -1
- package/lib/useGetEditor.d.ts +1 -6
- package/lib/useGetEditor.d.ts.map +1 -1
- package/lib/useInstance.d.ts +5 -0
- package/lib/useInstance.d.ts.map +1 -0
- package/package.json +6 -8
- package/src/Editor.tsx +22 -92
- package/src/index.ts +1 -1
- package/src/types.ts +4 -37
- package/src/useEditor.ts +6 -14
- package/src/useGetEditor.ts +8 -24
- package/src/useInstance.ts +13 -0
- package/lib/EditorComponent.d.ts +0 -14
- package/lib/EditorComponent.d.ts.map +0 -1
- package/lib/VueNode.d.ts +0 -25
- package/lib/VueNode.d.ts.map +0 -1
- package/lib/VueNodeView.d.ts +0 -35
- package/lib/VueNodeView.d.ts.map +0 -1
- package/lib/utils.d.ts +0 -9
- package/lib/utils.d.ts.map +0 -1
- package/src/EditorComponent.tsx +0 -27
- package/src/VueNode.tsx +0 -43
- package/src/VueNodeView.tsx +0 -189
- package/src/utils.ts +0 -11
package/lib/Editor.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { EditorInfo, EditorInfoCtx } from './types';
|
|
1
|
+
import type { InjectionKey } from 'vue';
|
|
2
|
+
import type { EditorInfoCtx } from './types';
|
|
4
3
|
export declare const editorInfoCtxKey: InjectionKey<EditorInfoCtx>;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
editorRef?: EditorRef | undefined;
|
|
8
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
9
|
-
editor: EditorInfo;
|
|
10
|
-
editorRef?: EditorRef | undefined;
|
|
11
|
-
}>, {}>;
|
|
4
|
+
export declare const Milkdown: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
|
|
5
|
+
export declare const MilkdownProvider: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
|
|
12
6
|
//# sourceMappingURL=Editor.d.ts.map
|
package/lib/Editor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AASvC,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,SAAS,CAAA;AAGvD,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,aAAa,CAA8B,CAAA;AAEvF,eAAO,MAAM,QAAQ,+SAOnB,CAAA;AAEF,eAAO,MAAM,gBAAgB,+SAiB3B,CAAA"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
package/lib/index.es.js
CHANGED
|
@@ -1,236 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { Mark as T, Node as I } from "@milkdown/prose/model";
|
|
7
|
-
import { customAlphabet as z } from "nanoid";
|
|
8
|
-
const E = Symbol("rendererKey"), F = (o) => {
|
|
9
|
-
const e = v(E, () => {
|
|
10
|
-
throw G();
|
|
11
|
-
}), { dom: t, loading: n, editor: a } = v(O, {}), s = u(!1);
|
|
12
|
-
S(() => {
|
|
13
|
-
if (!t.value)
|
|
1
|
+
import { inject as a, onMounted as s, onUnmounted as v, defineComponent as c, createVNode as f, ref as d, provide as m, Fragment as y } from "vue";
|
|
2
|
+
const g = () => {
|
|
3
|
+
const { dom: e, loading: o, editor: n, editorFactory: r } = a(i, {});
|
|
4
|
+
return s(() => {
|
|
5
|
+
if (!e.value)
|
|
14
6
|
return;
|
|
15
|
-
const
|
|
16
|
-
!
|
|
17
|
-
|
|
7
|
+
const t = r.value(e.value);
|
|
8
|
+
!t || (o.value = !0, t.create().then((u) => {
|
|
9
|
+
n.value = u;
|
|
18
10
|
}).finally(() => {
|
|
19
|
-
|
|
20
|
-
}).catch(
|
|
21
|
-
}),
|
|
22
|
-
var
|
|
23
|
-
(
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
name: "
|
|
27
|
-
setup: (
|
|
28
|
-
|
|
11
|
+
o.value = !1;
|
|
12
|
+
}).catch(console.error));
|
|
13
|
+
}), v(() => {
|
|
14
|
+
var t;
|
|
15
|
+
(t = n.value) == null || t.destroy();
|
|
16
|
+
}), e;
|
|
17
|
+
}, i = Symbol("editorInfoCtxKey"), k = /* @__PURE__ */ c({
|
|
18
|
+
name: "Milkdown",
|
|
19
|
+
setup: () => {
|
|
20
|
+
const e = g();
|
|
21
|
+
return () => f("div", {
|
|
22
|
+
"data-milkdown-root": !0,
|
|
23
|
+
ref: e
|
|
24
|
+
}, null);
|
|
25
|
+
}
|
|
26
|
+
}), w = /* @__PURE__ */ c({
|
|
27
|
+
name: "MilkdownProvider",
|
|
28
|
+
setup: (e, {
|
|
29
|
+
slots: o
|
|
29
30
|
}) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [(n = e.default) == null ? void 0 : n.call(e)]);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
V.props = ["editor", "editorRef"];
|
|
41
|
-
const R = Symbol("nodeMetadata"), ie = () => v(R), b = p({
|
|
42
|
-
name: "MilkdownNodeContainer",
|
|
43
|
-
setup: ({
|
|
44
|
-
node: o,
|
|
45
|
-
view: e,
|
|
46
|
-
getPos: t,
|
|
47
|
-
decorations: n,
|
|
48
|
-
ctx: a,
|
|
49
|
-
as: s
|
|
50
|
-
}, i) => (w(R, {
|
|
51
|
-
ctx: a,
|
|
52
|
-
node: o,
|
|
53
|
-
view: e,
|
|
54
|
-
getPos: t,
|
|
55
|
-
decorations: n
|
|
56
|
-
}), () => {
|
|
57
|
-
var r, d;
|
|
58
|
-
return j(s, {
|
|
59
|
-
"data-view-container": !0
|
|
60
|
-
}, (d = (r = i.slots).default) == null ? void 0 : d.call(r));
|
|
61
|
-
})
|
|
62
|
-
});
|
|
63
|
-
b.props = ["ctx", "editor", "node", "view", "getPos", "decorations", "as"];
|
|
64
|
-
const N = p({
|
|
65
|
-
name: "MilkdownContent",
|
|
66
|
-
setup: ({
|
|
67
|
-
isInline: o
|
|
68
|
-
}) => () => o ? l("span", {
|
|
69
|
-
"data-view-content": !0
|
|
70
|
-
}, null) : l("div", {
|
|
71
|
-
"data-view-content": !0
|
|
72
|
-
}, null)
|
|
73
|
-
});
|
|
74
|
-
N.props = ["isInline"];
|
|
75
|
-
const H = z("abcedfghicklmn", 10), J = (o, e, t) => (n, a = {}) => (s) => (i, r, d, f) => new Q(s, n, o, e, t, a, i, r, d, f);
|
|
76
|
-
var P, D;
|
|
77
|
-
class Q {
|
|
78
|
-
constructor(e, t, n, a, s, i, r, d, f, g) {
|
|
79
|
-
m(this, "getPortal", () => {
|
|
80
|
-
const e = this.component, t = this.options.as ? this.options.as : this.isInlineOrMark ? "span" : "div";
|
|
81
|
-
return k(p({
|
|
82
|
-
name: "MilkdownPortal",
|
|
83
|
-
setup: () => () => l(U, {
|
|
84
|
-
key: this.key,
|
|
85
|
-
to: this.teleportDOM
|
|
86
|
-
}, {
|
|
87
|
-
default: () => [l(b, {
|
|
88
|
-
as: t,
|
|
89
|
-
ctx: this.ctx,
|
|
90
|
-
node: this.node,
|
|
91
|
-
view: this.view,
|
|
92
|
-
getPos: this.getPos,
|
|
93
|
-
decorations: this.decorations
|
|
94
|
-
}, {
|
|
95
|
-
default: () => [l(e, null, {
|
|
96
|
-
default: () => [l(N, {
|
|
97
|
-
isInline: this.isInlineOrMark
|
|
98
|
-
}, null)]
|
|
99
|
-
})]
|
|
100
|
-
})]
|
|
101
|
-
})
|
|
102
|
-
}));
|
|
103
|
-
});
|
|
104
|
-
m(this, "selectNode", (P = this.options) == null ? void 0 : P.selectNode);
|
|
105
|
-
m(this, "deselectNode", (D = this.options) == null ? void 0 : D.deselectNode);
|
|
106
|
-
this.ctx = e, this.component = t, this.rootInstance = n, this.addPortal = a, this.removePortalByKey = s, this.options = i, this.view = d, this.getPos = f, this.key = H(), this.node = u(r), this.decorations = u(g);
|
|
107
|
-
const y = i.as ? i.as : this.isInlineOrMark ? "span" : "div";
|
|
108
|
-
this.teleportDOM = document.createElement(y), this.renderPortal();
|
|
109
|
-
}
|
|
110
|
-
get isInlineOrMark() {
|
|
111
|
-
return this.node.value instanceof T || this.node.value.isInline;
|
|
112
|
-
}
|
|
113
|
-
get dom() {
|
|
114
|
-
return this.teleportDOM.firstElementChild || this.teleportDOM;
|
|
115
|
-
}
|
|
116
|
-
get contentDOM() {
|
|
117
|
-
if (!(this.node instanceof I && this.node.isLeaf))
|
|
118
|
-
return this.teleportDOM.querySelector("[data-view-content]") || this.dom;
|
|
119
|
-
}
|
|
120
|
-
renderPortal() {
|
|
121
|
-
if (!this.teleportDOM)
|
|
122
|
-
return;
|
|
123
|
-
const e = this.getPortal();
|
|
124
|
-
this.addPortal(e, this.key);
|
|
125
|
-
const t = this.rootInstance.value;
|
|
126
|
-
t && t.update();
|
|
127
|
-
}
|
|
128
|
-
destroy() {
|
|
129
|
-
var e, t;
|
|
130
|
-
(t = (e = this.options).destroy) == null || t.call(e), this.teleportDOM.remove(), this.removePortalByKey(this.key);
|
|
131
|
-
}
|
|
132
|
-
ignoreMutation(e) {
|
|
133
|
-
return this.options.ignoreMutation ? this.options.ignoreMutation(e) : !this.dom || !this.contentDOM || this.node instanceof I && (this.node.isLeaf || this.node.isAtom) ? !0 : !(e.type === "selection" || this.contentDOM === this.dom || this.contentDOM.contains(e.target));
|
|
134
|
-
}
|
|
135
|
-
update(e, t, n) {
|
|
136
|
-
return (() => {
|
|
137
|
-
var i, r;
|
|
138
|
-
if (this.options.update) {
|
|
139
|
-
const d = (r = (i = this.options).update) == null ? void 0 : r.call(i, e, t, n);
|
|
140
|
-
if (d != null)
|
|
141
|
-
return d;
|
|
142
|
-
}
|
|
143
|
-
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);
|
|
144
|
-
})();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function W(o) {
|
|
148
|
-
return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !q(o);
|
|
149
|
-
}
|
|
150
|
-
const O = Symbol("editorInfoCtxKey"), X = `
|
|
151
|
-
@milkdown/vue:
|
|
152
|
-
Passing ref to VueEditor will soon be deprecated, please use:
|
|
153
|
-
|
|
154
|
-
const { editor, getInstance, getDom, loading } = useEditor(/* creator */);
|
|
155
|
-
|
|
156
|
-
effect(() => {
|
|
157
|
-
if (!loading) {
|
|
158
|
-
const editor = getInstance();
|
|
159
|
-
const rootDOM = getDom();
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
<VueEditor editor={editor} />
|
|
164
|
-
`, Y = `
|
|
165
|
-
@milkdown/vue:
|
|
166
|
-
Passing editor directly to VueEditor will soon be deprecated, please use:
|
|
167
|
-
|
|
168
|
-
const { editor } = useEditor(/* creator */);
|
|
169
|
-
|
|
170
|
-
<VueEditor editor={editor} />
|
|
171
|
-
`, Z = p({
|
|
172
|
-
name: "MilkdownVueRoot",
|
|
173
|
-
setup: (o) => {
|
|
174
|
-
const e = B([]), t = A(), n = u(null);
|
|
175
|
-
L(() => {
|
|
176
|
-
n.value = t.ctx._;
|
|
177
|
-
}), C(() => {
|
|
178
|
-
n.value = null;
|
|
179
|
-
});
|
|
180
|
-
const a = k((c, h) => {
|
|
181
|
-
e.push([h, c]);
|
|
182
|
-
}), s = k((c) => {
|
|
183
|
-
const h = e.findIndex((M) => M[0] === c);
|
|
184
|
-
e.splice(h, 1);
|
|
185
|
-
}), i = J(n, a, s);
|
|
186
|
-
w(E, i);
|
|
187
|
-
const r = Object.hasOwnProperty.call(o.editor, "getInstance"), {
|
|
188
|
-
getEditorCallback: d,
|
|
189
|
-
dom: f,
|
|
190
|
-
editor: g,
|
|
191
|
-
loading: y
|
|
192
|
-
} = r ? o.editor.editor : o.editor;
|
|
193
|
-
return _(() => {
|
|
194
|
-
r && console.warn(Y), o.editorRef && console.warn(X);
|
|
195
|
-
}), w(O, {
|
|
196
|
-
dom: f,
|
|
197
|
-
editor: g,
|
|
198
|
-
loading: y
|
|
31
|
+
const n = d(null), r = d(void 0), t = d(void 0), u = d(!0);
|
|
32
|
+
return m(i, {
|
|
33
|
+
loading: u,
|
|
34
|
+
dom: n,
|
|
35
|
+
editor: t,
|
|
36
|
+
editorFactory: r
|
|
199
37
|
}), () => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}, null));
|
|
203
|
-
return l(V, {
|
|
204
|
-
editorRef: o.editorRef,
|
|
205
|
-
editor: d.value
|
|
206
|
-
}, W(c) ? c : {
|
|
207
|
-
default: () => [c]
|
|
208
|
-
});
|
|
38
|
+
var l;
|
|
39
|
+
return f(y, null, [(l = o.default) == null ? void 0 : l.call(o)]);
|
|
209
40
|
};
|
|
210
41
|
}
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const e = u(null), t = u(), n = u(!0), a = u((...s) => o(...s));
|
|
215
|
-
return {
|
|
42
|
+
}), M = (e) => {
|
|
43
|
+
const { editorFactory: o, loading: n, editor: r } = a(i);
|
|
44
|
+
return o.value = e, {
|
|
216
45
|
loading: n,
|
|
217
|
-
|
|
218
|
-
getDom: () => e.value,
|
|
219
|
-
editor: {
|
|
220
|
-
getEditorCallback: a,
|
|
221
|
-
dom: e,
|
|
222
|
-
editor: t,
|
|
223
|
-
loading: n
|
|
224
|
-
}
|
|
46
|
+
get: () => r.value
|
|
225
47
|
};
|
|
48
|
+
}, F = () => {
|
|
49
|
+
const e = a(i);
|
|
50
|
+
return [e.loading, () => e.editor.value];
|
|
226
51
|
};
|
|
227
52
|
export {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
re as useEditor,
|
|
234
|
-
ie as useNodeCtx
|
|
53
|
+
k as Milkdown,
|
|
54
|
+
w as MilkdownProvider,
|
|
55
|
+
i as editorInfoCtxKey,
|
|
56
|
+
M as useEditor,
|
|
57
|
+
F as useInstance
|
|
235
58
|
};
|
|
236
59
|
//# 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 type { Ctx } from '@milkdown/core'\nimport { vueRendererCallOutOfScope } from '@milkdown/exception'\nimport type { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view'\nimport type { DefineComponent, InjectionKey } from 'vue'\nimport { inject, onMounted, onUnmounted, ref } from 'vue'\n\nimport type { EditorInfoCtx, GetEditor, RenderOptions, RenderVue } from './types'\nimport { editorInfoCtxKey } from '.'\n\nexport const rendererKey: InjectionKey<\n (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor\n> = Symbol('rendererKey')\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)\n return\n\n const editor = getEditor(dom.value, renderVue)\n if (!editor)\n return\n\n if (lock.value)\n return\n\n loading.value = true\n lock.value = true\n\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor\n })\n .finally(() => {\n loading.value = false\n lock.value = false\n })\n .catch(e => console.error(e))\n })\n onUnmounted(() => {\n editorRef.value?.destroy()\n })\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Editor } from '@milkdown/core'\nimport { defineComponent, h, inject } from 'vue'\n\nimport { editorInfoCtxKey } from './Editor'\nimport type { EditorInfoCtx, GetEditor } from './types'\nimport { useGetEditor } from './useGetEditor'\n\nexport const EditorComponent = defineComponent<{ editor: GetEditor; editorRef?: EditorRef }>({\n name: 'MilkdownDomRoot',\n setup: (props, { slots }) => {\n useGetEditor(props.editor)\n const ctx = inject(editorInfoCtxKey, {} as EditorInfoCtx)\n\n if (props.editorRef) {\n // eslint-disable-next-line vue/no-mutating-props\n props.editorRef.get = () => ctx.editor.value\n // eslint-disable-next-line vue/no-mutating-props\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 interface EditorRef { get: () => Editor | undefined; dom: () => HTMLDivElement | null }\n","/* Copyright 2021, Milkdown by Mirone. */\n/* eslint-disable vue/one-component-per-file */\nimport type { Ctx } from '@milkdown/core'\nimport type { Mark, Node } from '@milkdown/prose/model'\nimport type { Decoration, EditorView } from '@milkdown/prose/view'\nimport type { InjectionKey, Ref } from 'vue'\nimport { defineComponent, h, inject, provide } from 'vue'\n\nexport interface 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('nodeMetadata')\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: 'MilkdownNodeContainer',\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: 'MilkdownContent',\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 type { 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 type { ComponentInternalInstance, DefineComponent, Ref } from 'vue'\nimport { Teleport, defineComponent, h, markRaw, ref } from 'vue'\n\nimport { Content, VueNodeContainer } from './VueNode'\n\nconst nanoid = customAlphabet('abcedfghicklmn', 10)\n\nexport type RenderOptions = Partial<\n {\n as: string\n update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean\n } & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>\n>\n\nexport const createVueView\n = (\n rootInstance: Ref<null | ComponentInternalInstance>,\n addPortal: (portal: DefineComponent, key: string) => void,\n removePortalByKey: (key: string) => void,\n ) =>\n (\n component: DefineComponent,\n options: RenderOptions = {},\n ): ((ctx: Ctx) => NodeViewConstructor | MarkViewConstructor) =>\n ctx =>\n (node, view, getPos, decorations) =>\n new VueNodeView(\n ctx,\n component,\n rootInstance,\n addPortal,\n removePortalByKey,\n options,\n node,\n view,\n getPos,\n decorations,\n )\n\nexport class VueNodeView implements NodeView {\n teleportDOM: HTMLElement\n key: string\n\n get isInlineOrMark() {\n return this.node.value instanceof Mark || this.node.value.isInline\n }\n\n private node: Ref<Node | Mark>\n private decorations: Ref<readonly Decoration[]>\n\n constructor(\n private ctx: Ctx,\n private component: DefineComponent,\n private rootInstance: Ref<null | ComponentInternalInstance>,\n private addPortal: (portal: DefineComponent, key: string) => void,\n private removePortalByKey: (key: string) => void,\n private options: RenderOptions,\n node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n decorations: readonly Decoration[],\n ) {\n this.key = nanoid()\n this.node = ref(node)\n this.decorations = ref(decorations)\n const elementName = options.as ? options.as : this.isInlineOrMark ? 'span' : 'div'\n this.teleportDOM = document.createElement(elementName)\n this.renderPortal()\n }\n\n get dom() {\n return (this.teleportDOM.firstElementChild || this.teleportDOM) as HTMLElement\n }\n\n get contentDOM() {\n if (this.node instanceof Node && this.node.isLeaf)\n return undefined\n\n 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: 'MilkdownPortal',\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)\n return\n\n const Portal = this.getPortal()\n this.addPortal(Portal, this.key)\n const instance = this.rootInstance.value\n if (instance)\n instance.update()\n }\n\n 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 if (this.node instanceof Node) {\n if (this.node.isLeaf || this.node.isAtom)\n return true\n }\n\n if ((mutation as unknown as { type: string }).type === 'selection')\n return false\n\n if (this.contentDOM === this.dom)\n return false\n\n if (this.contentDOM.contains(mutation.target))\n return false\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 if (this.node.value.type !== node.type)\n return false\n\n if (node === this.node.value && this.decorations.value === decorations)\n return true\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 type {\n ComponentInternalInstance,\n DefineComponent,\n InjectionKey,\n} from 'vue'\nimport {\n defineComponent,\n effect,\n getCurrentInstance,\n h,\n markRaw,\n onBeforeMount,\n onUnmounted,\n provide,\n ref,\n shallowReactive,\n} from 'vue'\n\nimport type { EditorRef } from './EditorComponent'\nimport { EditorComponent } from './EditorComponent'\nimport type { EditorInfo, EditorInfoCtx } from './types'\nimport { rendererKey } from './useGetEditor'\nimport { createVueView } from './VueNodeView'\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol('editorInfoCtxKey')\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: 'MilkdownVueRoot',\n setup: (props) => {\n const portals = shallowReactive<PortalPair[]>([])\n\n const instance = getCurrentInstance()\n\n const rootInstance = ref<null | ComponentInternalInstance>(null)\n\n onBeforeMount(() => {\n rootInstance.value = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } }).ctx\n ._ as ComponentInternalInstance\n })\n\n onUnmounted(() => {\n rootInstance.value = null\n })\n\n const addPortal = markRaw((component: DefineComponent, key: string) => {\n portals.push([key, component])\n })\n const removePortalByKey = markRaw((key: string) => {\n const index = portals.findIndex(p => p[0] === key)\n portals.splice(index, 1)\n })\n const renderVue = createVueView(rootInstance, addPortal, removePortalByKey)\n\n provide(rendererKey, renderVue)\n\n const usingDeprecatedCompositionAPI = Object.hasOwnProperty.call(props.editor, 'getInstance')\n\n const { getEditorCallback, dom, editor, loading } = usingDeprecatedCompositionAPI\n // @ts-expect-error deprecated old composition API\n ? (props.editor.editor as EditorInfo)\n : props.editor\n\n effect(() => {\n if (usingDeprecatedCompositionAPI)\n console.warn(compositionDeprecatedInfo)\n\n if (props.editorRef)\n console.warn(refDeprecatedInfo)\n })\n\n 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 type { Editor } from '@milkdown/core'\nimport { ref } from 'vue'\n\nimport type { 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":["rendererKey","useGetEditor","getEditor","renderVue","inject","vueRendererCallOutOfScope","dom","loading","editorRef","editorInfoCtxKey","lock","ref","onMounted","editor","e","onUnmounted","_a","EditorComponent","defineComponent","name","setup","props","slots","ctx","get","value","_createVNode","default","nodeMetadata","Symbol","useNodeCtx","VueNodeContainer","node","view","getPos","decorations","as","context","provide","h","Content","isInline","nanoid","customAlphabet","createVueView","rootInstance","addPortal","removePortalByKey","component","options","VueNodeView","constructor","getPortal","CustomComponent","elementName","isInlineOrMark","markRaw","Teleport","key","teleportDOM","selectNode","deselectNode","_b","document","createElement","renderPortal","Mark","firstElementChild","contentDOM","Node","isLeaf","querySelector","Portal","instance","update","destroy","remove","ignoreMutation","mutation","isAtom","type","contains","target","innerDecorations","result","refDeprecatedInfo","compositionDeprecatedInfo","VueEditor","portals","shallowReactive","getCurrentInstance","onBeforeMount","_","push","index","findIndex","p","splice","usingDeprecatedCompositionAPI","Object","hasOwnProperty","call","getEditorCallback","effect","console","warn","portalElements","map","id","P","useEditor","args"],"mappings":";;;;;;;AAUa,MAAAA,IAET,OAAO,aAAa,GAEXC,IAAe,CAACC,MAAyB;AAC9C,QAAAC,IAAYC,EAAkBJ,GAAa,MAAM;AACrD,UAAMK,EAA0B;AAAA,EAAA,CACjC,GACK,EAAE,KAAAC,GAAK,SAAAC,GAAS,QAAQC,MAAcJ,EAAOK,GAAkB,CAAA,CAAmB,GAClFC,IAAOC,EAAI,EAAK;AAEtB,EAAAC,EAAU,MAAM;AACd,QAAI,CAACN,EAAI;AACP;AAEF,UAAMO,IAASX,EAAUI,EAAI,OAAOH,CAAS;AAC7C,IAAI,CAACU,KAGDH,EAAK,UAGTH,EAAQ,QAAQ,IAChBG,EAAK,QAAQ,IAEbG,EACG,OAAO,EACP,KAAK,CAACA,MAAW;AAChB,MAAAL,EAAU,QAAQK;AAAAA,IAAA,CACnB,EACA,QAAQ,MAAM;AACb,MAAAN,EAAQ,QAAQ,IAChBG,EAAK,QAAQ;AAAA,IAAA,CACd,EACA,MAAM,OAAK,QAAQ,MAAMI,CAAC,CAAC;AAAA,EAAA,CAC/B,GACDC,EAAY,MAAM;;AAChB,KAAAC,IAAAR,EAAU,UAAV,QAAAQ,EAAiB;AAAA,EAAQ,CAC1B;AACH,GCzCaC,IAAkBC,EAA8D;AAAA,EAC3FC,MAAM;AAAA,EACNC,OAAO,CAACC,GAAO;AAAA,IAAEC,OAAAA;AAAAA,EAAF,MAAc;AAC3BrB,IAAAA,EAAaoB,EAAMR,MAAP;AACZ,UAAMU,IAAMnB,EAAOK,GAAkB,CAAnB,CAAA;AAElB,WAAIY,EAAMb,cAERa,EAAMb,UAAUgB,MAAM,MAAMD,EAAIV,OAAOY,OAEvC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,UAAU,WAAX;AC1GL,MAAAyF,KAAY,CAAC5G,MAA0C;AAC5D,QAAAI,IAAMK,EAA2B,IAAI,GACrCE,IAASF,KACTJ,IAAUI,EAAI,EAAI,GAClB2F,IAAoB3F,EAAe,IAAIoG,MAAS7G,EAAU,GAAG6G,CAAI,CAAC;AAEjE,SAAA;AAAA,IACL,SAAAxG;AAAA,IACA,aAAa,MAAMM,EAAO;AAAA,IAC1B,QAAQ,MAAMP,EAAI;AAAA,IAClB,QAAQ;AAAA,MACN,mBAAAgG;AAAA,MACA,KAAAhG;AAAA,MACA,QAAAO;AAAA,MACA,SAAAN;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/useGetEditor.ts","../src/Editor.tsx","../src/useEditor.ts","../src/useInstance.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { inject, onMounted, onUnmounted } from 'vue'\n\nimport type { EditorInfoCtx } from './types'\nimport { editorInfoCtxKey } from '.'\n\nexport const useGetEditor = () => {\n const { dom, loading, editor: editorRef, editorFactory: getEditor } = inject(editorInfoCtxKey, {} as EditorInfoCtx)\n\n onMounted(() => {\n if (!dom.value)\n return\n\n const editor = getEditor.value!(dom.value)\n if (!editor)\n return\n\n loading.value = true\n editor\n .create()\n .then((editor) => {\n editorRef.value = editor\n })\n .finally(() => {\n loading.value = false\n })\n .catch(console.error)\n })\n onUnmounted(() => {\n editorRef.value?.destroy()\n })\n\n return dom\n}\n","/* Copyright 2021, Milkdown by Mirone. */\n/* eslint-disable vue/one-component-per-file */\nimport type { Editor } from '@milkdown/core'\nimport type { InjectionKey } from 'vue'\nimport {\n Fragment,\n defineComponent,\n h,\n provide,\n ref,\n} from 'vue'\n\nimport type { EditorInfoCtx, GetEditor } from './types'\nimport { useGetEditor } from './useGetEditor'\n\nexport const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol('editorInfoCtxKey')\n\nexport const Milkdown = defineComponent({\n name: 'Milkdown',\n setup: () => {\n const domRef = useGetEditor()\n\n return () => <div data-milkdown-root ref={domRef} />\n },\n})\n\nexport const MilkdownProvider = defineComponent({\n name: 'MilkdownProvider',\n setup: (_, { slots }) => {\n const dom = ref<HTMLDivElement | null>(null)\n const editorFactory = ref<GetEditor | undefined>(undefined)\n const editor = ref<Editor | undefined>(undefined)\n const loading = ref(true)\n\n provide(editorInfoCtxKey, {\n loading,\n dom,\n editor,\n editorFactory,\n })\n\n return () => <>{slots.default?.()}</>\n },\n})\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { inject } from 'vue'\nimport { editorInfoCtxKey } from './Editor'\n\nimport type { GetEditor, UseEditorReturn } from './types'\n\nexport const useEditor = (getEditor: GetEditor): UseEditorReturn => {\n const { editorFactory, loading, editor } = inject(editorInfoCtxKey)!\n\n editorFactory.value = getEditor\n\n return {\n loading,\n get: () => editor.value,\n }\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Editor } from '@milkdown/core'\nimport type { Ref } from 'vue'\nimport { inject } from 'vue'\nimport { editorInfoCtxKey } from './Editor'\n\nexport type Instance = [Ref<true>, () => undefined] | [Ref<false>, () => Editor]\n\nexport const useInstance = (): Instance => {\n const editorInfo = inject(editorInfoCtxKey)!\n\n return [editorInfo.loading, () => editorInfo.editor.value] as Instance\n}\n"],"names":["useGetEditor","dom","loading","editorRef","getEditor","inject","editorInfoCtxKey","onMounted","editor","onUnmounted","_a","Symbol","Milkdown","defineComponent","name","setup","domRef","_createVNode","MilkdownProvider","_","slots","ref","editorFactory","undefined","provide","default","useEditor","useInstance","editorInfo"],"mappings":";AAMO,MAAMA,IAAe,MAAM;AAC1B,QAAA,EAAE,KAAAC,GAAK,SAAAC,GAAS,QAAQC,GAAW,eAAeC,MAAcC,EAAOC,GAAkB,CAAmB,CAAA;AAElH,SAAAC,EAAU,MAAM;AACd,QAAI,CAACN,EAAI;AACP;AAEF,UAAMO,IAASJ,EAAU,MAAOH,EAAI,KAAK;AACzC,IAA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IACL,SAAAF;AAAA,IACA,KAAK,MAAMM,EAAO;AAAA,EAAA;AAEtB,GCRamB,IAAc,MAAgB;AACnC,QAAAC,IAAavB,EAAOC,CAAgB;AAE1C,SAAO,CAACsB,EAAW,SAAS,MAAMA,EAAW,OAAO,KAAK;AAC3D;"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Mark, Node } from '@milkdown/prose/model';
|
|
3
|
-
import type { Decoration, DecorationSource, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view';
|
|
1
|
+
import type { Editor } from '@milkdown/core';
|
|
4
2
|
import type { Ref } from 'vue';
|
|
5
|
-
|
|
6
|
-
export 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 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 type GetEditor = (container: HTMLDivElement, renderVue: RenderVue) => Editor;
|
|
3
|
+
export type GetEditor = (container: HTMLDivElement) => Editor;
|
|
12
4
|
export interface EditorInfoCtx {
|
|
13
5
|
dom: Ref<HTMLDivElement | null>;
|
|
14
6
|
editor: Ref<Editor | undefined>;
|
|
7
|
+
editorFactory: Ref<GetEditor | undefined>;
|
|
15
8
|
loading: Ref<boolean>;
|
|
16
9
|
}
|
|
17
|
-
export type EditorInfo = {
|
|
18
|
-
getEditorCallback: Ref<GetEditor>;
|
|
19
|
-
} & EditorInfoCtx;
|
|
20
10
|
export interface UseEditorReturn {
|
|
21
11
|
loading: Ref<boolean>;
|
|
22
|
-
|
|
23
|
-
getDom: () => HTMLDivElement | null;
|
|
24
|
-
editor: EditorInfo;
|
|
12
|
+
get: () => Editor | undefined;
|
|
25
13
|
}
|
|
26
14
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,MAAM,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,cAAc,KAAK,MAAM,CAAA;AAE7D,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC/B,aAAa,EAAE,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,CAAA;IACzC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACrB,GAAG,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;CAC9B"}
|
package/lib/useEditor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.d.ts","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzD,eAAO,MAAM,SAAS,cAAe,SAAS,KAAG,
|
|
1
|
+
{"version":3,"file":"useEditor.d.ts","sourceRoot":"","sources":["../src/useEditor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzD,eAAO,MAAM,SAAS,cAAe,SAAS,KAAG,eAShD,CAAA"}
|
package/lib/useGetEditor.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view';
|
|
3
|
-
import type { DefineComponent, InjectionKey } from 'vue';
|
|
4
|
-
import type { 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;
|
|
1
|
+
export declare const useGetEditor: () => import("vue").Ref<HTMLDivElement | null>;
|
|
7
2
|
//# sourceMappingURL=useGetEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetEditor.d.ts","sourceRoot":"","sources":["../src/useGetEditor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGetEditor.d.ts","sourceRoot":"","sources":["../src/useGetEditor.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,gDA2BxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInstance.d.ts","sourceRoot":"","sources":["../src/useInstance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAI9B,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC,CAAA;AAEhF,eAAO,MAAM,WAAW,QAAO,QAI9B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-next.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,20 +21,18 @@
|
|
|
21
21
|
"src"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@milkdown/core": "^
|
|
25
|
-
"@milkdown/prose": "^
|
|
24
|
+
"@milkdown/core": "^7.0.0-next.0",
|
|
25
|
+
"@milkdown/prose": "^7.0.0-next.0",
|
|
26
26
|
"vue": "^3.0.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"nanoid": "^4.0.0",
|
|
30
29
|
"tslib": "^2.4.0",
|
|
31
|
-
"@milkdown/
|
|
32
|
-
"@milkdown/utils": "6.5.4"
|
|
30
|
+
"@milkdown/utils": "7.0.0-next.0"
|
|
33
31
|
},
|
|
34
32
|
"devDependencies": {
|
|
35
33
|
"vue": "^3.2.38",
|
|
36
|
-
"@milkdown/core": "
|
|
37
|
-
"@milkdown/prose": "
|
|
34
|
+
"@milkdown/core": "7.0.0-next.0",
|
|
35
|
+
"@milkdown/prose": "7.0.0-next.0"
|
|
38
36
|
},
|
|
39
37
|
"nx": {
|
|
40
38
|
"targets": {
|
package/src/Editor.tsx
CHANGED
|
@@ -1,114 +1,44 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
InjectionKey,
|
|
6
|
-
} from 'vue'
|
|
2
|
+
/* eslint-disable vue/one-component-per-file */
|
|
3
|
+
import type { Editor } from '@milkdown/core'
|
|
4
|
+
import type { InjectionKey } from 'vue'
|
|
7
5
|
import {
|
|
6
|
+
Fragment,
|
|
8
7
|
defineComponent,
|
|
9
|
-
effect,
|
|
10
|
-
getCurrentInstance,
|
|
11
8
|
h,
|
|
12
|
-
markRaw,
|
|
13
|
-
onBeforeMount,
|
|
14
|
-
onUnmounted,
|
|
15
9
|
provide,
|
|
16
10
|
ref,
|
|
17
|
-
shallowReactive,
|
|
18
11
|
} from 'vue'
|
|
19
12
|
|
|
20
|
-
import type {
|
|
21
|
-
import {
|
|
22
|
-
import type { EditorInfo, EditorInfoCtx } from './types'
|
|
23
|
-
import { rendererKey } from './useGetEditor'
|
|
24
|
-
import { createVueView } from './VueNodeView'
|
|
13
|
+
import type { EditorInfoCtx, GetEditor } from './types'
|
|
14
|
+
import { useGetEditor } from './useGetEditor'
|
|
25
15
|
|
|
26
16
|
export const editorInfoCtxKey: InjectionKey<EditorInfoCtx> = Symbol('editorInfoCtxKey')
|
|
27
17
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const { editor, getInstance, getDom, loading } = useEditor(/* creator */);
|
|
18
|
+
export const Milkdown = defineComponent({
|
|
19
|
+
name: 'Milkdown',
|
|
20
|
+
setup: () => {
|
|
21
|
+
const domRef = useGetEditor()
|
|
33
22
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const editor = getInstance();
|
|
37
|
-
const rootDOM = getDom();
|
|
38
|
-
}
|
|
23
|
+
return () => <div data-milkdown-root ref={domRef} />
|
|
24
|
+
},
|
|
39
25
|
})
|
|
40
26
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const { editor } = useEditor(/* creator */);
|
|
49
|
-
|
|
50
|
-
<VueEditor editor={editor} />
|
|
51
|
-
`
|
|
52
|
-
|
|
53
|
-
type PortalPair = [key: string, component: DefineComponent]
|
|
54
|
-
export const VueEditor = defineComponent<{ editor: EditorInfo; editorRef?: EditorRef }>({
|
|
55
|
-
name: 'MilkdownVueRoot',
|
|
56
|
-
setup: (props) => {
|
|
57
|
-
const portals = shallowReactive<PortalPair[]>([])
|
|
58
|
-
|
|
59
|
-
const instance = getCurrentInstance()
|
|
60
|
-
|
|
61
|
-
const rootInstance = ref<null | ComponentInternalInstance>(null)
|
|
62
|
-
|
|
63
|
-
onBeforeMount(() => {
|
|
64
|
-
rootInstance.value = (instance as ComponentInternalInstance & { ctx: { _: ComponentInternalInstance } }).ctx
|
|
65
|
-
._ as ComponentInternalInstance
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
onUnmounted(() => {
|
|
69
|
-
rootInstance.value = null
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const addPortal = markRaw((component: DefineComponent, key: string) => {
|
|
73
|
-
portals.push([key, component])
|
|
74
|
-
})
|
|
75
|
-
const removePortalByKey = markRaw((key: string) => {
|
|
76
|
-
const index = portals.findIndex(p => p[0] === key)
|
|
77
|
-
portals.splice(index, 1)
|
|
78
|
-
})
|
|
79
|
-
const renderVue = createVueView(rootInstance, addPortal, removePortalByKey)
|
|
80
|
-
|
|
81
|
-
provide(rendererKey, renderVue)
|
|
82
|
-
|
|
83
|
-
const usingDeprecatedCompositionAPI = Object.hasOwnProperty.call(props.editor, 'getInstance')
|
|
84
|
-
|
|
85
|
-
const { getEditorCallback, dom, editor, loading } = usingDeprecatedCompositionAPI
|
|
86
|
-
// @ts-expect-error deprecated old composition API
|
|
87
|
-
? (props.editor.editor as EditorInfo)
|
|
88
|
-
: props.editor
|
|
89
|
-
|
|
90
|
-
effect(() => {
|
|
91
|
-
if (usingDeprecatedCompositionAPI)
|
|
92
|
-
console.warn(compositionDeprecatedInfo)
|
|
93
|
-
|
|
94
|
-
if (props.editorRef)
|
|
95
|
-
console.warn(refDeprecatedInfo)
|
|
96
|
-
})
|
|
27
|
+
export const MilkdownProvider = defineComponent({
|
|
28
|
+
name: 'MilkdownProvider',
|
|
29
|
+
setup: (_, { slots }) => {
|
|
30
|
+
const dom = ref<HTMLDivElement | null>(null)
|
|
31
|
+
const editorFactory = ref<GetEditor | undefined>(undefined)
|
|
32
|
+
const editor = ref<Editor | undefined>(undefined)
|
|
33
|
+
const loading = ref(true)
|
|
97
34
|
|
|
98
35
|
provide(editorInfoCtxKey, {
|
|
36
|
+
loading,
|
|
99
37
|
dom,
|
|
100
38
|
editor,
|
|
101
|
-
|
|
39
|
+
editorFactory,
|
|
102
40
|
})
|
|
103
41
|
|
|
104
|
-
return () => {
|
|
105
|
-
const portalElements = portals.map(([id, P]) => <P key={id} />)
|
|
106
|
-
return (
|
|
107
|
-
<EditorComponent editorRef={props.editorRef} editor={getEditorCallback.value}>
|
|
108
|
-
{portalElements}
|
|
109
|
-
</EditorComponent>
|
|
110
|
-
)
|
|
111
|
-
}
|
|
42
|
+
return () => <>{slots.default?.()}</>
|
|
112
43
|
},
|
|
113
44
|
})
|
|
114
|
-
VueEditor.props = ['editor', 'editorRef']
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,50 +1,17 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type {
|
|
3
|
-
import type { Mark, Node } from '@milkdown/prose/model'
|
|
4
|
-
import type { Decoration, DecorationSource, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view'
|
|
2
|
+
import type { Editor } from '@milkdown/core'
|
|
5
3
|
import type { Ref } from 'vue'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type RenderOptions = Partial<
|
|
10
|
-
{
|
|
11
|
-
as: string
|
|
12
|
-
update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean
|
|
13
|
-
} & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>
|
|
14
|
-
>
|
|
15
|
-
|
|
16
|
-
export type RenderVue<U = never> = <T extends Node | Mark = Node | Mark>(
|
|
17
|
-
Component: AnyVueComponent,
|
|
18
|
-
options?: RenderOptions,
|
|
19
|
-
) => (
|
|
20
|
-
ctx: Ctx,
|
|
21
|
-
) => U extends never
|
|
22
|
-
? T extends Node
|
|
23
|
-
? NodeViewConstructor
|
|
24
|
-
: T extends Mark
|
|
25
|
-
? MarkViewConstructor
|
|
26
|
-
: NodeViewConstructor & MarkViewConstructor
|
|
27
|
-
: U extends Node
|
|
28
|
-
? NodeViewConstructor
|
|
29
|
-
: U extends Mark
|
|
30
|
-
? MarkViewConstructor
|
|
31
|
-
: NodeViewConstructor & MarkViewConstructor
|
|
32
|
-
|
|
33
|
-
export type GetEditor = (container: HTMLDivElement, renderVue: RenderVue) => Editor
|
|
5
|
+
export type GetEditor = (container: HTMLDivElement) => Editor
|
|
34
6
|
|
|
35
7
|
export interface EditorInfoCtx {
|
|
36
8
|
dom: Ref<HTMLDivElement | null>
|
|
37
9
|
editor: Ref<Editor | undefined>
|
|
10
|
+
editorFactory: Ref<GetEditor | undefined>
|
|
38
11
|
loading: Ref<boolean>
|
|
39
12
|
}
|
|
40
13
|
|
|
41
|
-
export type EditorInfo = {
|
|
42
|
-
getEditorCallback: Ref<GetEditor>
|
|
43
|
-
} & EditorInfoCtx
|
|
44
|
-
|
|
45
14
|
export interface UseEditorReturn {
|
|
46
15
|
loading: Ref<boolean>
|
|
47
|
-
|
|
48
|
-
getDom: () => HTMLDivElement | null
|
|
49
|
-
editor: EditorInfo
|
|
16
|
+
get: () => Editor | undefined
|
|
50
17
|
}
|
package/src/useEditor.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { inject } from 'vue'
|
|
4
|
+
import { editorInfoCtxKey } from './Editor'
|
|
5
5
|
|
|
6
6
|
import type { GetEditor, UseEditorReturn } from './types'
|
|
7
7
|
|
|
8
8
|
export const useEditor = (getEditor: GetEditor): UseEditorReturn => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const getEditorCallback = ref<GetEditor>((...args) => getEditor(...args))
|
|
9
|
+
const { editorFactory, loading, editor } = inject(editorInfoCtxKey)!
|
|
10
|
+
|
|
11
|
+
editorFactory.value = getEditor
|
|
13
12
|
|
|
14
13
|
return {
|
|
15
14
|
loading,
|
|
16
|
-
|
|
17
|
-
getDom: () => dom.value,
|
|
18
|
-
editor: {
|
|
19
|
-
getEditorCallback,
|
|
20
|
-
dom,
|
|
21
|
-
editor,
|
|
22
|
-
loading,
|
|
23
|
-
},
|
|
15
|
+
get: () => editor.value,
|
|
24
16
|
}
|
|
25
17
|
}
|
package/src/useGetEditor.ts
CHANGED
|
@@ -1,38 +1,21 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import
|
|
3
|
-
import { vueRendererCallOutOfScope } from '@milkdown/exception'
|
|
4
|
-
import type { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view'
|
|
5
|
-
import type { DefineComponent, InjectionKey } from 'vue'
|
|
6
|
-
import { inject, onMounted, onUnmounted, ref } from 'vue'
|
|
2
|
+
import { inject, onMounted, onUnmounted } from 'vue'
|
|
7
3
|
|
|
8
|
-
import type { EditorInfoCtx
|
|
4
|
+
import type { EditorInfoCtx } from './types'
|
|
9
5
|
import { editorInfoCtxKey } from '.'
|
|
10
6
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
> = Symbol('rendererKey')
|
|
14
|
-
|
|
15
|
-
export const useGetEditor = (getEditor: GetEditor) => {
|
|
16
|
-
const renderVue = inject<RenderVue>(rendererKey, () => {
|
|
17
|
-
throw vueRendererCallOutOfScope()
|
|
18
|
-
})
|
|
19
|
-
const { dom, loading, editor: editorRef } = inject(editorInfoCtxKey, {} as EditorInfoCtx)
|
|
20
|
-
const lock = ref(false)
|
|
7
|
+
export const useGetEditor = () => {
|
|
8
|
+
const { dom, loading, editor: editorRef, editorFactory: getEditor } = inject(editorInfoCtxKey, {} as EditorInfoCtx)
|
|
21
9
|
|
|
22
10
|
onMounted(() => {
|
|
23
11
|
if (!dom.value)
|
|
24
12
|
return
|
|
25
13
|
|
|
26
|
-
const editor = getEditor(dom.value
|
|
14
|
+
const editor = getEditor.value!(dom.value)
|
|
27
15
|
if (!editor)
|
|
28
16
|
return
|
|
29
17
|
|
|
30
|
-
if (lock.value)
|
|
31
|
-
return
|
|
32
|
-
|
|
33
18
|
loading.value = true
|
|
34
|
-
lock.value = true
|
|
35
|
-
|
|
36
19
|
editor
|
|
37
20
|
.create()
|
|
38
21
|
.then((editor) => {
|
|
@@ -40,11 +23,12 @@ export const useGetEditor = (getEditor: GetEditor) => {
|
|
|
40
23
|
})
|
|
41
24
|
.finally(() => {
|
|
42
25
|
loading.value = false
|
|
43
|
-
lock.value = false
|
|
44
26
|
})
|
|
45
|
-
.catch(
|
|
27
|
+
.catch(console.error)
|
|
46
28
|
})
|
|
47
29
|
onUnmounted(() => {
|
|
48
30
|
editorRef.value?.destroy()
|
|
49
31
|
})
|
|
32
|
+
|
|
33
|
+
return dom
|
|
50
34
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Editor } from '@milkdown/core'
|
|
3
|
+
import type { Ref } from 'vue'
|
|
4
|
+
import { inject } from 'vue'
|
|
5
|
+
import { editorInfoCtxKey } from './Editor'
|
|
6
|
+
|
|
7
|
+
export type Instance = [Ref<true>, () => undefined] | [Ref<false>, () => Editor]
|
|
8
|
+
|
|
9
|
+
export const useInstance = (): Instance => {
|
|
10
|
+
const editorInfo = inject(editorInfoCtxKey)!
|
|
11
|
+
|
|
12
|
+
return [editorInfo.loading, () => editorInfo.editor.value] as Instance
|
|
13
|
+
}
|
package/lib/EditorComponent.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Editor } from '@milkdown/core';
|
|
2
|
-
import type { GetEditor } from './types';
|
|
3
|
-
export declare const EditorComponent: import("vue").DefineComponent<{
|
|
4
|
-
editor: GetEditor;
|
|
5
|
-
editorRef?: EditorRef | undefined;
|
|
6
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
7
|
-
editor: GetEditor;
|
|
8
|
-
editorRef?: EditorRef | undefined;
|
|
9
|
-
}>, {}>;
|
|
10
|
-
export interface EditorRef {
|
|
11
|
-
get: () => Editor | undefined;
|
|
12
|
-
dom: () => HTMLDivElement | null;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=EditorComponent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditorComponent.d.ts","sourceRoot":"","sources":["../src/EditorComponent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAI5C,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,SAAS,CAAA;AAGvD,eAAO,MAAM,eAAe;YAA6B,SAAS;;;YAAT,SAAS;;OAehE,CAAA;AAGF,MAAM,WAAW,SAAS;IAAG,GAAG,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;CAAE"}
|
package/lib/VueNode.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/core';
|
|
2
|
-
import type { Mark, Node } from '@milkdown/prose/model';
|
|
3
|
-
import type { Decoration, EditorView } from '@milkdown/prose/view';
|
|
4
|
-
import type { InjectionKey, Ref } from 'vue';
|
|
5
|
-
export interface NodeContext<T extends Node | Mark = Node | Mark> {
|
|
6
|
-
ctx: Ctx;
|
|
7
|
-
node: Ref<T>;
|
|
8
|
-
view: EditorView;
|
|
9
|
-
getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number);
|
|
10
|
-
decorations: Ref<readonly Decoration[]>;
|
|
11
|
-
}
|
|
12
|
-
export declare const nodeMetadata: InjectionKey<NodeContext>;
|
|
13
|
-
export type UseNodeCtx = <T extends Node | Mark = Node | Mark>() => NodeContext<T>;
|
|
14
|
-
export declare const useNodeCtx: UseNodeCtx;
|
|
15
|
-
export declare const VueNodeContainer: import("vue").DefineComponent<NodeContext<Node | Mark> & {
|
|
16
|
-
as: string;
|
|
17
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<NodeContext<Node | Mark> & {
|
|
18
|
-
as: string;
|
|
19
|
-
}>, {}>;
|
|
20
|
-
export declare const Content: import("vue").DefineComponent<{
|
|
21
|
-
isInline?: boolean | undefined;
|
|
22
|
-
}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
23
|
-
isInline?: boolean | undefined;
|
|
24
|
-
}>, {}>;
|
|
25
|
-
//# sourceMappingURL=VueNode.d.ts.map
|
package/lib/VueNode.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VueNode.d.ts","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAG5C,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;IAC9D,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACZ,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,CAAC,SAAS,IAAI,GAAG,OAAO,GAAG,CAAC,SAAS,IAAI,GAAG,MAAM,MAAM,GAAG,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,CAAA;IAC3F,WAAW,EAAE,GAAG,CAAC,SAAS,UAAU,EAAE,CAAC,CAAA;CACxC;AAED,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,WAAW,CAA0B,CAAA;AAE7E,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,OAAO,WAAW,CAAC,CAAC,CAAC,CAAA;AAClF,eAAO,MAAM,UAAU,EAAE,UAA6D,CAAA;AAEtF,eAAO,MAAM,gBAAgB;QAAuC,MAAM;;QAAN,MAAM;OAYxE,CAAA;AAGF,eAAO,MAAM,OAAO;;;;OAKlB,CAAA"}
|
package/lib/VueNodeView.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/core';
|
|
2
|
-
import { Mark, Node } from '@milkdown/prose/model';
|
|
3
|
-
import type { Decoration, DecorationSource, EditorView, MarkViewConstructor, NodeView, NodeViewConstructor } from '@milkdown/prose/view';
|
|
4
|
-
import type { ComponentInternalInstance, DefineComponent, Ref } from 'vue';
|
|
5
|
-
export type RenderOptions = Partial<{
|
|
6
|
-
as: string;
|
|
7
|
-
update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
|
|
8
|
-
} & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>>;
|
|
9
|
-
export declare const createVueView: (rootInstance: Ref<null | ComponentInternalInstance>, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) => (component: DefineComponent, options?: RenderOptions) => (ctx: Ctx) => NodeViewConstructor | MarkViewConstructor;
|
|
10
|
-
export declare class VueNodeView implements NodeView {
|
|
11
|
-
private ctx;
|
|
12
|
-
private component;
|
|
13
|
-
private rootInstance;
|
|
14
|
-
private addPortal;
|
|
15
|
-
private removePortalByKey;
|
|
16
|
-
private options;
|
|
17
|
-
private view;
|
|
18
|
-
private getPos;
|
|
19
|
-
teleportDOM: HTMLElement;
|
|
20
|
-
key: string;
|
|
21
|
-
get isInlineOrMark(): boolean;
|
|
22
|
-
private node;
|
|
23
|
-
private decorations;
|
|
24
|
-
constructor(ctx: Ctx, component: DefineComponent, rootInstance: Ref<null | ComponentInternalInstance>, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void, options: RenderOptions, node: Node | Mark, view: EditorView, getPos: boolean | (() => number), decorations: readonly Decoration[]);
|
|
25
|
-
get dom(): HTMLElement;
|
|
26
|
-
get contentDOM(): HTMLElement | undefined;
|
|
27
|
-
getPortal: () => DefineComponent;
|
|
28
|
-
renderPortal(): void;
|
|
29
|
-
destroy(): void;
|
|
30
|
-
ignoreMutation(mutation: MutationRecord): boolean;
|
|
31
|
-
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
32
|
-
selectNode: (() => void) | undefined;
|
|
33
|
-
deselectNode: (() => void) | undefined;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=VueNodeView.d.ts.map
|
package/lib/VueNodeView.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VueNodeView.d.ts","sourceRoot":"","sources":["../src/VueNodeView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,QAAQ,EACR,mBAAmB,EACpB,MAAM,sBAA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AAa,EAC9B,IAAI,EAAE,IAAI,GAAG,IAAI,EACT,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,EACxC,WAAW,EAAE,SAAS,UAAU,EAAE;IAUpC,IAAI,GAAG,gBAEN;IAED,IAAI,UAAU,4BAKb;IAED,SAAS,QAAO,eAAe,CA0B9B;IAED,YAAY;IAWZ,OAAO;IAMP,cAAc,CAAC,QAAQ,EAAE,cAAc;IAwBvC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,UAAU,EAAE,EAAE,gBAAgB,EAAE,gBAAgB;IAuBzF,UAAU,2BAA2B;IAErC,YAAY,2BAA6B;CAC1C"}
|
package/lib/utils.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { DefineComponent } from 'vue';
|
|
2
|
-
type Prepend<T, U extends unknown[]> = [T, ...U];
|
|
3
|
-
type Keys_<T extends Record<string, unknown>, U extends PropertyKey[]> = {
|
|
4
|
-
[P in keyof T]: Record<string, unknown> extends Omit<T, P> ? [P] : Prepend<P, Keys_<Omit<T, P>, U>>;
|
|
5
|
-
}[keyof T];
|
|
6
|
-
export type Keys<T extends Record<string, unknown>> = Keys_<T, []>;
|
|
7
|
-
export type AnyVueComponent = DefineComponent<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAChD,KAAK,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,IAAI;KACtE,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACpG,CAAC,MAAM,CAAC,CAAC,CAAA;AACV,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAElE,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA"}
|
package/src/EditorComponent.tsx
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Editor } from '@milkdown/core'
|
|
3
|
-
import { defineComponent, h, inject } from 'vue'
|
|
4
|
-
|
|
5
|
-
import { editorInfoCtxKey } from './Editor'
|
|
6
|
-
import type { EditorInfoCtx, GetEditor } from './types'
|
|
7
|
-
import { useGetEditor } from './useGetEditor'
|
|
8
|
-
|
|
9
|
-
export const EditorComponent = defineComponent<{ editor: GetEditor; editorRef?: EditorRef }>({
|
|
10
|
-
name: 'MilkdownDomRoot',
|
|
11
|
-
setup: (props, { slots }) => {
|
|
12
|
-
useGetEditor(props.editor)
|
|
13
|
-
const ctx = inject(editorInfoCtxKey, {} as EditorInfoCtx)
|
|
14
|
-
|
|
15
|
-
if (props.editorRef) {
|
|
16
|
-
// eslint-disable-next-line vue/no-mutating-props
|
|
17
|
-
props.editorRef.get = () => ctx.editor.value
|
|
18
|
-
// eslint-disable-next-line vue/no-mutating-props
|
|
19
|
-
props.editorRef.dom = () => ctx.dom.value
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return () => <div ref={ctx.dom}>{slots.default?.()}</div>
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
EditorComponent.props = ['editor', 'editorRef']
|
|
26
|
-
|
|
27
|
-
export interface EditorRef { get: () => Editor | undefined; dom: () => HTMLDivElement | null }
|
package/src/VueNode.tsx
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
/* eslint-disable vue/one-component-per-file */
|
|
3
|
-
import type { Ctx } from '@milkdown/core'
|
|
4
|
-
import type { Mark, Node } from '@milkdown/prose/model'
|
|
5
|
-
import type { Decoration, EditorView } from '@milkdown/prose/view'
|
|
6
|
-
import type { InjectionKey, Ref } from 'vue'
|
|
7
|
-
import { defineComponent, h, inject, provide } from 'vue'
|
|
8
|
-
|
|
9
|
-
export interface NodeContext<T extends Node | Mark = Node | Mark> {
|
|
10
|
-
ctx: Ctx
|
|
11
|
-
node: Ref<T>
|
|
12
|
-
view: EditorView
|
|
13
|
-
getPos: T extends Mark ? boolean : T extends Node ? () => number : boolean | (() => number)
|
|
14
|
-
decorations: Ref<readonly Decoration[]>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const nodeMetadata: InjectionKey<NodeContext> = Symbol('nodeMetadata')
|
|
18
|
-
|
|
19
|
-
export type UseNodeCtx = <T extends Node | Mark = Node | Mark>() => NodeContext<T>
|
|
20
|
-
export const useNodeCtx: UseNodeCtx = () => inject(nodeMetadata) as NodeContext<never>
|
|
21
|
-
|
|
22
|
-
export const VueNodeContainer = defineComponent<NodeContext & { as: string }>({
|
|
23
|
-
name: 'MilkdownNodeContainer',
|
|
24
|
-
setup: ({ node, view, getPos, decorations, ctx, as }, context) => {
|
|
25
|
-
provide(nodeMetadata, {
|
|
26
|
-
ctx,
|
|
27
|
-
node,
|
|
28
|
-
view,
|
|
29
|
-
getPos,
|
|
30
|
-
decorations,
|
|
31
|
-
})
|
|
32
|
-
return () => h(as, { 'data-view-container': true }, context.slots.default?.())
|
|
33
|
-
},
|
|
34
|
-
})
|
|
35
|
-
VueNodeContainer.props = ['ctx', 'editor', 'node', 'view', 'getPos', 'decorations', 'as']
|
|
36
|
-
|
|
37
|
-
export const Content = defineComponent<{ isInline?: boolean }>({
|
|
38
|
-
name: 'MilkdownContent',
|
|
39
|
-
setup: ({ isInline }) => {
|
|
40
|
-
return () => (isInline ? <span data-view-content /> : <div data-view-content />)
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
Content.props = ['isInline']
|
package/src/VueNodeView.tsx
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { Ctx } from '@milkdown/core'
|
|
3
|
-
import { Mark, Node } from '@milkdown/prose/model'
|
|
4
|
-
import type {
|
|
5
|
-
Decoration,
|
|
6
|
-
DecorationSource,
|
|
7
|
-
EditorView,
|
|
8
|
-
MarkViewConstructor,
|
|
9
|
-
NodeView,
|
|
10
|
-
NodeViewConstructor,
|
|
11
|
-
} from '@milkdown/prose/view'
|
|
12
|
-
import { customAlphabet } from 'nanoid'
|
|
13
|
-
import type { ComponentInternalInstance, DefineComponent, Ref } from 'vue'
|
|
14
|
-
import { Teleport, defineComponent, h, markRaw, ref } from 'vue'
|
|
15
|
-
|
|
16
|
-
import { Content, VueNodeContainer } from './VueNode'
|
|
17
|
-
|
|
18
|
-
const nanoid = customAlphabet('abcedfghicklmn', 10)
|
|
19
|
-
|
|
20
|
-
export type RenderOptions = Partial<
|
|
21
|
-
{
|
|
22
|
-
as: string
|
|
23
|
-
update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean
|
|
24
|
-
} & Pick<NodeView, 'ignoreMutation' | 'deselectNode' | 'selectNode' | 'destroy'>
|
|
25
|
-
>
|
|
26
|
-
|
|
27
|
-
export const createVueView
|
|
28
|
-
= (
|
|
29
|
-
rootInstance: Ref<null | ComponentInternalInstance>,
|
|
30
|
-
addPortal: (portal: DefineComponent, key: string) => void,
|
|
31
|
-
removePortalByKey: (key: string) => void,
|
|
32
|
-
) =>
|
|
33
|
-
(
|
|
34
|
-
component: DefineComponent,
|
|
35
|
-
options: RenderOptions = {},
|
|
36
|
-
): ((ctx: Ctx) => NodeViewConstructor | MarkViewConstructor) =>
|
|
37
|
-
ctx =>
|
|
38
|
-
(node, view, getPos, decorations) =>
|
|
39
|
-
new VueNodeView(
|
|
40
|
-
ctx,
|
|
41
|
-
component,
|
|
42
|
-
rootInstance,
|
|
43
|
-
addPortal,
|
|
44
|
-
removePortalByKey,
|
|
45
|
-
options,
|
|
46
|
-
node,
|
|
47
|
-
view,
|
|
48
|
-
getPos,
|
|
49
|
-
decorations,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
export class VueNodeView implements NodeView {
|
|
53
|
-
teleportDOM: HTMLElement
|
|
54
|
-
key: string
|
|
55
|
-
|
|
56
|
-
get isInlineOrMark() {
|
|
57
|
-
return this.node.value instanceof Mark || this.node.value.isInline
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private node: Ref<Node | Mark>
|
|
61
|
-
private decorations: Ref<readonly Decoration[]>
|
|
62
|
-
|
|
63
|
-
constructor(
|
|
64
|
-
private ctx: Ctx,
|
|
65
|
-
private component: DefineComponent,
|
|
66
|
-
private rootInstance: Ref<null | ComponentInternalInstance>,
|
|
67
|
-
private addPortal: (portal: DefineComponent, key: string) => void,
|
|
68
|
-
private removePortalByKey: (key: string) => void,
|
|
69
|
-
private options: RenderOptions,
|
|
70
|
-
node: Node | Mark,
|
|
71
|
-
private view: EditorView,
|
|
72
|
-
private getPos: boolean | (() => number),
|
|
73
|
-
decorations: readonly Decoration[],
|
|
74
|
-
) {
|
|
75
|
-
this.key = nanoid()
|
|
76
|
-
this.node = ref(node)
|
|
77
|
-
this.decorations = ref(decorations)
|
|
78
|
-
const elementName = options.as ? options.as : this.isInlineOrMark ? 'span' : 'div'
|
|
79
|
-
this.teleportDOM = document.createElement(elementName)
|
|
80
|
-
this.renderPortal()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get dom() {
|
|
84
|
-
return (this.teleportDOM.firstElementChild || this.teleportDOM) as HTMLElement
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get contentDOM() {
|
|
88
|
-
if (this.node instanceof Node && this.node.isLeaf)
|
|
89
|
-
return undefined
|
|
90
|
-
|
|
91
|
-
return this.teleportDOM.querySelector<HTMLElement>('[data-view-content]') || this.dom
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getPortal = (): DefineComponent => {
|
|
95
|
-
const CustomComponent = this.component
|
|
96
|
-
const elementName = this.options.as ? this.options.as : this.isInlineOrMark ? 'span' : 'div'
|
|
97
|
-
return markRaw(
|
|
98
|
-
defineComponent({
|
|
99
|
-
name: 'MilkdownPortal',
|
|
100
|
-
setup: () => {
|
|
101
|
-
return () => (
|
|
102
|
-
<Teleport key={this.key} to={this.teleportDOM}>
|
|
103
|
-
<VueNodeContainer
|
|
104
|
-
as={elementName}
|
|
105
|
-
ctx={this.ctx}
|
|
106
|
-
node={this.node}
|
|
107
|
-
view={this.view}
|
|
108
|
-
getPos={this.getPos}
|
|
109
|
-
decorations={this.decorations}
|
|
110
|
-
>
|
|
111
|
-
<CustomComponent>
|
|
112
|
-
<Content isInline={this.isInlineOrMark} />
|
|
113
|
-
</CustomComponent>
|
|
114
|
-
</VueNodeContainer>
|
|
115
|
-
</Teleport>
|
|
116
|
-
)
|
|
117
|
-
},
|
|
118
|
-
}) as DefineComponent,
|
|
119
|
-
)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
renderPortal() {
|
|
123
|
-
if (!this.teleportDOM)
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
const Portal = this.getPortal()
|
|
127
|
-
this.addPortal(Portal, this.key)
|
|
128
|
-
const instance = this.rootInstance.value
|
|
129
|
-
if (instance)
|
|
130
|
-
instance.update()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
destroy() {
|
|
134
|
-
this.options.destroy?.()
|
|
135
|
-
this.teleportDOM.remove()
|
|
136
|
-
this.removePortalByKey(this.key)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
ignoreMutation(mutation: MutationRecord) {
|
|
140
|
-
if (this.options.ignoreMutation)
|
|
141
|
-
return this.options.ignoreMutation(mutation)
|
|
142
|
-
|
|
143
|
-
if (!this.dom || !this.contentDOM)
|
|
144
|
-
return true
|
|
145
|
-
|
|
146
|
-
if (this.node instanceof Node) {
|
|
147
|
-
if (this.node.isLeaf || this.node.isAtom)
|
|
148
|
-
return true
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if ((mutation as unknown as { type: string }).type === 'selection')
|
|
152
|
-
return false
|
|
153
|
-
|
|
154
|
-
if (this.contentDOM === this.dom)
|
|
155
|
-
return false
|
|
156
|
-
|
|
157
|
-
if (this.contentDOM.contains(mutation.target))
|
|
158
|
-
return false
|
|
159
|
-
|
|
160
|
-
return true
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) {
|
|
164
|
-
const innerUpdate = () => {
|
|
165
|
-
if (this.options.update) {
|
|
166
|
-
const result = this.options.update?.(node, decorations, innerDecorations)
|
|
167
|
-
if (result != null)
|
|
168
|
-
return result
|
|
169
|
-
}
|
|
170
|
-
if (this.node.value.type !== node.type)
|
|
171
|
-
return false
|
|
172
|
-
|
|
173
|
-
if (node === this.node.value && this.decorations.value === decorations)
|
|
174
|
-
return true
|
|
175
|
-
|
|
176
|
-
this.node.value = node
|
|
177
|
-
this.decorations.value = decorations
|
|
178
|
-
return true
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const shouldUpdate = innerUpdate()
|
|
182
|
-
|
|
183
|
-
return shouldUpdate
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
selectNode = this.options?.selectNode
|
|
187
|
-
|
|
188
|
-
deselectNode = this.options?.deselectNode
|
|
189
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
|
|
3
|
-
import type { DefineComponent } from 'vue'
|
|
4
|
-
|
|
5
|
-
type Prepend<T, U extends unknown[]> = [T, ...U]
|
|
6
|
-
type Keys_<T extends Record<string, unknown>, U extends PropertyKey[]> = {
|
|
7
|
-
[P in keyof T]: Record<string, unknown> extends Omit<T, P> ? [P] : Prepend<P, Keys_<Omit<T, P>, U>>;
|
|
8
|
-
}[keyof T]
|
|
9
|
-
export type Keys<T extends Record<string, unknown>> = Keys_<T, []>
|
|
10
|
-
|
|
11
|
-
export type AnyVueComponent = DefineComponent<any, any, any, any, any, any, any, any, any, any, any, any>
|