@milkdown/vue 4.13.0 → 4.14.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/README.md +4 -0
- package/lib/Editor.d.ts +2 -1
- package/lib/Editor.d.ts.map +1 -1
- package/lib/Editor.js.map +1 -1
- package/lib/VueNode.d.ts +2 -7
- package/lib/VueNode.d.ts.map +1 -1
- package/lib/VueNode.js +1 -2
- package/lib/VueNode.js.map +1 -1
- package/lib/VueNodeView.d.ts +4 -5
- package/lib/VueNodeView.d.ts.map +1 -1
- package/lib/VueNodeView.js +7 -7
- package/lib/VueNodeView.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +1 -0
- package/lib/utils.js.map +1 -1
- package/package.json +5 -3
- package/src/Editor.tsx +93 -0
- package/src/Portals.tsx +31 -0
- package/src/VueNode.tsx +33 -0
- package/src/VueNodeView.tsx +84 -0
- package/src/index.ts +3 -0
- package/src/utils.ts +7 -0
package/README.md
CHANGED
package/lib/Editor.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Editor
|
|
1
|
+
import { Editor } from '@milkdown/core';
|
|
2
|
+
import { ViewFactory } from '@milkdown/prose';
|
|
2
3
|
import { DefineComponent, Ref } from 'vue';
|
|
3
4
|
declare type GetEditor = (container: HTMLDivElement, renderVue: (Component: DefineComponent) => ViewFactory) => Editor;
|
|
4
5
|
export declare const EditorComponent: DefineComponent<{
|
package/lib/Editor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAiB,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAiB,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACH,eAAe,EAUf,GAAG,EAGN,MAAM,KAAK,CAAC;AAOb,aAAK,SAAS,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,eAAe,KAAK,WAAW,KAAK,MAAM,CAAC;AA8B/G,eAAO,MAAM,eAAe;YAAqC,SAAS;;;;;;;;OAUxE,CAAC;AAGH,oBAAY,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;CAAE,CAAC;AAE5F,eAAO,MAAM,SAAS;YAAqC,SAAS;;;;;;;;OAkBlE,CAAC;AAGH,eAAO,MAAM,SAAS,cAAe,SAAS,wDAlEsB,eAAe,KAAK,WAAW,WAoElG,CAAC"}
|
package/lib/Editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAU,aAAa,
|
|
1
|
+
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAU,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAEH,eAAe,EACf,QAAQ,EACR,CAAC,EACD,MAAM,EAEN,OAAO,EACP,SAAS,EACT,WAAW,EACX,OAAO,EAEP,GAAG,EACH,eAAe,GAClB,MAAM,KAAK,CAAC;AAEb,OAAO,EAAc,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,GAA8D,MAAM,EAAE,CAAC;AAIxF,MAAM,YAAY,GAAG,CAAC,SAAoB,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,GAAG,CAAwB,IA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,EAAE,WAAW,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAoB,EAAE,EAAE;IAC9C,OAAO,CAAC,GAAG,IAA2B,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
package/lib/VueNode.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { Mark, Node } from '
|
|
3
|
-
import { Decoration, EditorView } from 'prosemirror-view';
|
|
1
|
+
/// <reference types="prosemirror-model" />
|
|
2
|
+
import { Decoration, EditorView, Mark, Node } from '@milkdown/prose';
|
|
4
3
|
import { InjectionKey } from 'vue';
|
|
5
4
|
export declare type NodeContext = {
|
|
6
|
-
editor: Editor;
|
|
7
5
|
node: Node | Mark;
|
|
8
6
|
view: EditorView;
|
|
9
7
|
getPos: boolean | (() => number);
|
|
@@ -11,13 +9,11 @@ export declare type NodeContext = {
|
|
|
11
9
|
};
|
|
12
10
|
export declare const nodeMetadata: InjectionKey<NodeContext>;
|
|
13
11
|
export declare const VueNodeContainer: import("vue").DefineComponent<{
|
|
14
|
-
editor: Editor;
|
|
15
12
|
node: Node | Mark;
|
|
16
13
|
view: EditorView;
|
|
17
14
|
getPos: boolean | (() => number);
|
|
18
15
|
decorations: Decoration[];
|
|
19
16
|
}, () => JSX.Element, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
20
|
-
editor?: unknown;
|
|
21
17
|
node?: unknown;
|
|
22
18
|
view?: unknown;
|
|
23
19
|
getPos?: unknown;
|
|
@@ -28,7 +24,6 @@ export declare const VueNodeContainer: import("vue").DefineComponent<{
|
|
|
28
24
|
}>[] | undefined;
|
|
29
25
|
node?: Mark<any> | Node<any> | undefined;
|
|
30
26
|
view?: EditorView<any> | undefined;
|
|
31
|
-
editor?: Editor | undefined;
|
|
32
27
|
getPos?: boolean | (() => number) | undefined;
|
|
33
28
|
}>, {}>;
|
|
34
29
|
export declare const Content: import("vue").DefineComponent<{
|
package/lib/VueNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VueNode.d.ts","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"VueNode.d.ts","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAgC,YAAY,EAA6B,MAAM,KAAK,CAAC;AAE5F,oBAAY,WAAW,GAAG;IACtB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACjC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,WAAW,CAAY,CAAC;AAEhE,eAAO,MAAM,gBAAgB;UARnB,IAAI,GAAG,IAAI;UACX,UAAU;YACR,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC;iBACnB,UAAU,EAAE;;;;;;;;;;;;8BADA,MAAM;OAcjC,CAAC;AAGH,eAAO,MAAM,OAAO;SAAkC,WAAW;;;;;OAO/D,CAAC"}
|
package/lib/VueNode.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { defineComponent, Fragment, h, provide, ref, watchEffect } from 'vue';
|
|
2
2
|
export const nodeMetadata = Symbol();
|
|
3
|
-
export const VueNodeContainer = defineComponent(({
|
|
3
|
+
export const VueNodeContainer = defineComponent(({ node, view, getPos, decorations }, context) => {
|
|
4
4
|
provide(nodeMetadata, {
|
|
5
|
-
editor,
|
|
6
5
|
node,
|
|
7
6
|
view,
|
|
8
7
|
getPos,
|
package/lib/VueNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VueNode.js","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VueNode.js","sourceRoot":"","sources":["../src/VueNode.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,EAAgB,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAS5F,MAAM,CAAC,MAAM,YAAY,GAA8B,MAAM,EAAE,CAAC;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAe,EAAE,OAAO,EAAE,EAAE;IAC1G,OAAO,CAAC,YAAY,EAAE;QAClB,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,WAAW;KACd,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,mBAAC,OAAA,kBAAG,MAAA,MAAA,MAAA,OAAO,CAAC,KAAK,EAAC,OAAO,kDAAI,mCAAI,EAAE,CAAI,CAAA,EAAA,CAAC;AACxD,CAAC,CAAC,CAAC;AACH,gBAAgB,CAAC,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,KAA2B,EAAE,EAAE;IACnE,MAAM,YAAY,GAAG,GAAG,CAAwB,IAAI,CAAC,CAAC;IACtD,WAAW,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE,OAAO;QAC9C,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,CAAC,WAAK,GAAG,EAAE,YAAY,GAAI,CAAC;AAC5C,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC"}
|
package/lib/VueNodeView.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
/// <reference types="prosemirror-model" />
|
|
2
|
+
import type { Decoration, EditorView, NodeView, ViewFactory } from '@milkdown/prose';
|
|
3
|
+
import { Mark, Node } from '@milkdown/prose';
|
|
4
4
|
import { DefineComponent } from 'vue';
|
|
5
5
|
export declare const createVueView: (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) => (component: DefineComponent) => ViewFactory;
|
|
6
6
|
export declare class VueNodeView implements NodeView {
|
|
7
7
|
private component;
|
|
8
8
|
private addPortal;
|
|
9
9
|
private removePortalByKey;
|
|
10
|
-
private editor;
|
|
11
10
|
private node;
|
|
12
11
|
private view;
|
|
13
12
|
private getPos;
|
|
@@ -15,7 +14,7 @@ export declare class VueNodeView implements NodeView {
|
|
|
15
14
|
dom: HTMLElement | undefined;
|
|
16
15
|
contentDOM: HTMLElement | undefined;
|
|
17
16
|
key: string;
|
|
18
|
-
constructor(component: DefineComponent, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void,
|
|
17
|
+
constructor(component: DefineComponent, addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void, node: Node | Mark, view: EditorView, getPos: boolean | (() => number), decorations: Decoration[]);
|
|
19
18
|
renderPortal(): void;
|
|
20
19
|
destroy(): void;
|
|
21
20
|
ignoreMutation(mutation: MutationRecord | {
|
package/lib/VueNodeView.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VueNodeView.d.ts","sourceRoot":"","sources":["../src/VueNodeView.ts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ib/VueNodeView.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Mark, Node } from '@milkdown/prose';
|
|
2
|
+
import { customAlphabet } from 'nanoid';
|
|
3
3
|
import { defineComponent, h, Teleport } from 'vue';
|
|
4
4
|
import { Content, VueNodeContainer } from './VueNode';
|
|
5
|
-
|
|
5
|
+
const nanoid = customAlphabet('abcedfghicklmn', 10);
|
|
6
|
+
export const createVueView = (addPortal, removePortalByKey) => (component) => (node, view, getPos, decorations) => new VueNodeView(component, addPortal, removePortalByKey, node, view, getPos, decorations);
|
|
6
7
|
export class VueNodeView {
|
|
7
|
-
constructor(component, addPortal, removePortalByKey,
|
|
8
|
+
constructor(component, addPortal, removePortalByKey, node, view, getPos, decorations) {
|
|
8
9
|
this.component = component;
|
|
9
10
|
this.addPortal = addPortal;
|
|
10
11
|
this.removePortalByKey = removePortalByKey;
|
|
11
|
-
this.editor = editor;
|
|
12
12
|
this.node = node;
|
|
13
13
|
this.view = view;
|
|
14
14
|
this.getPos = getPos;
|
|
15
15
|
this.decorations = decorations;
|
|
16
|
-
this.key =
|
|
16
|
+
this.key = nanoid();
|
|
17
17
|
const dom = document.createElement(node instanceof Mark ? 'span' : 'div');
|
|
18
18
|
dom.classList.add('dom-wrapper');
|
|
19
19
|
const contentDOM = node instanceof Node && node.isLeaf
|
|
@@ -33,7 +33,7 @@ export class VueNodeView {
|
|
|
33
33
|
const CustomComponent = this.component;
|
|
34
34
|
const Portal = defineComponent(() => {
|
|
35
35
|
return () => (h(Teleport, { to: this.dom },
|
|
36
|
-
h(VueNodeContainer, { key: this.key,
|
|
36
|
+
h(VueNodeContainer, { key: this.key, node: this.node, view: this.view, getPos: this.getPos, decorations: this.decorations },
|
|
37
37
|
h(CustomComponent, null,
|
|
38
38
|
h(Content, { dom: this.contentDOM })))));
|
|
39
39
|
});
|
package/lib/VueNodeView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VueNodeView.js","sourceRoot":"","sources":["../src/VueNodeView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"VueNodeView.js","sourceRoot":"","sources":["../src/VueNodeView.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAmB,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,MAAM,GAAG,cAAc,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,aAAa,GACtB,CAAC,SAAyD,EAAE,iBAAwC,EAAE,EAAE,CACxG,CAAC,SAA0B,EAAe,EAAE,CAC5C,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAChC,IAAI,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AAElG,MAAM,OAAO,WAAW;IAKpB,YACY,SAA0B,EAC1B,SAAyD,EACzD,iBAAwC,EACxC,IAAiB,EACjB,IAAgB,EAChB,MAAgC,EAChC,WAAyB;QANzB,cAAS,GAAT,SAAS,CAAiB;QAC1B,cAAS,GAAT,SAAS,CAAgD;QACzD,sBAAiB,GAAjB,iBAAiB,CAAuB;QACxC,SAAI,GAAJ,IAAI,CAAa;QACjB,SAAI,GAAJ,IAAI,CAAY;QAChB,WAAM,GAAN,MAAM,CAA0B;QAChC,gBAAW,GAAX,WAAW,CAAc;QAEjC,IAAI,CAAC,GAAG,GAAG,MAAM,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CA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AAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,OAAO;QACH,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,QAAiE;QAC5E,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAClB,OAAO,IAAI,CAAC;SACf;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;CACJ"}
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,aAAK,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AACjD,aAAK,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,IAAI;KACpE,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;CACtG,CAAC,MAAM,CAAC,CAAC,CAAC;AACX,oBAAY,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC"}
|
package/lib/utils.js
CHANGED
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,yCAAyC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/vue",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"files": [
|
|
10
|
-
"lib"
|
|
10
|
+
"lib",
|
|
11
|
+
"src"
|
|
11
12
|
],
|
|
12
13
|
"keywords": [
|
|
13
14
|
"milkdown",
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
"vue"
|
|
16
17
|
],
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@milkdown/utils": "4.
|
|
19
|
+
"@milkdown/utils": "4.14.0",
|
|
20
|
+
"nanoid": "^3.1.25",
|
|
19
21
|
"tslib": "^2.2.0"
|
|
20
22
|
},
|
|
21
23
|
"peerDependencies": {
|
package/src/Editor.tsx
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Editor, editorViewCtx } from '@milkdown/core';
|
|
3
|
+
import { ViewFactory } from '@milkdown/prose';
|
|
4
|
+
import {
|
|
5
|
+
DefineComponent,
|
|
6
|
+
defineComponent,
|
|
7
|
+
Fragment,
|
|
8
|
+
h,
|
|
9
|
+
inject,
|
|
10
|
+
InjectionKey,
|
|
11
|
+
markRaw,
|
|
12
|
+
onMounted,
|
|
13
|
+
onUnmounted,
|
|
14
|
+
provide,
|
|
15
|
+
Ref,
|
|
16
|
+
ref,
|
|
17
|
+
shallowReactive,
|
|
18
|
+
} from 'vue';
|
|
19
|
+
|
|
20
|
+
import { PortalPair, Portals } from './Portals';
|
|
21
|
+
import { createVueView } from './VueNodeView';
|
|
22
|
+
|
|
23
|
+
const rendererKey: InjectionKey<(component: DefineComponent) => ViewFactory> = Symbol();
|
|
24
|
+
|
|
25
|
+
type GetEditor = (container: HTMLDivElement, renderVue: (Component: DefineComponent) => ViewFactory) => Editor;
|
|
26
|
+
|
|
27
|
+
const useGetEditor = (getEditor: GetEditor) => {
|
|
28
|
+
const divRef = ref<HTMLDivElement | null>(null);
|
|
29
|
+
const renderVue = inject<(Component: DefineComponent) => ViewFactory>(rendererKey, () => {
|
|
30
|
+
throw new Error();
|
|
31
|
+
});
|
|
32
|
+
const editorRef = markRaw<{ editor?: Editor }>({});
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
if (!divRef.value) return;
|
|
35
|
+
|
|
36
|
+
getEditor(divRef.value, renderVue)
|
|
37
|
+
.create()
|
|
38
|
+
.then((editor) => {
|
|
39
|
+
editorRef.editor = editor;
|
|
40
|
+
return;
|
|
41
|
+
})
|
|
42
|
+
.catch((e) => console.error(e));
|
|
43
|
+
});
|
|
44
|
+
onUnmounted(() => {
|
|
45
|
+
const view = editorRef.editor?.action((ctx) => ctx.get(editorViewCtx));
|
|
46
|
+
if (!view) return;
|
|
47
|
+
|
|
48
|
+
view.dom.parentElement?.remove();
|
|
49
|
+
view.destroy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return { divRef, editorRef };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const EditorComponent = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {
|
|
56
|
+
const refs = useGetEditor(props.editor);
|
|
57
|
+
if (props.editorRef) {
|
|
58
|
+
props.editorRef.value = {
|
|
59
|
+
get: () => refs.editorRef.editor,
|
|
60
|
+
dom: () => refs.divRef.value,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return () => <div ref={refs.divRef} />;
|
|
65
|
+
});
|
|
66
|
+
EditorComponent.props = ['editor', 'editorRef'];
|
|
67
|
+
|
|
68
|
+
export type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };
|
|
69
|
+
|
|
70
|
+
export const VueEditor = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {
|
|
71
|
+
const portals = shallowReactive<PortalPair[]>([]);
|
|
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(addPortal, removePortalByKey);
|
|
80
|
+
provide(rendererKey, renderVue);
|
|
81
|
+
|
|
82
|
+
return () => (
|
|
83
|
+
<>
|
|
84
|
+
<Portals portals={portals} />
|
|
85
|
+
<EditorComponent editorRef={props.editorRef} editor={props.editor} />
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
VueEditor.props = ['editor', 'editorRef'];
|
|
90
|
+
|
|
91
|
+
export const useEditor = (getEditor: GetEditor) => {
|
|
92
|
+
return (...args: Parameters<GetEditor>) => getEditor(...args);
|
|
93
|
+
};
|
package/src/Portals.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { DefineComponent, defineComponent, Fragment, h, nextTick, ref, shallowRef, watch } from 'vue';
|
|
3
|
+
export type PortalPair = [key: string, component: DefineComponent];
|
|
4
|
+
|
|
5
|
+
const getId = (pairs: PortalPair[]) => pairs.map((p) => p[0]).join('\n');
|
|
6
|
+
|
|
7
|
+
export const Portals = defineComponent((props: { portals: PortalPair[] }) => {
|
|
8
|
+
const portalComponents = shallowRef<Array<DefineComponent>>([]);
|
|
9
|
+
const prev = ref<string>('');
|
|
10
|
+
const renderList = shallowRef<() => JSX.Element[]>(() => []);
|
|
11
|
+
|
|
12
|
+
watch(
|
|
13
|
+
() => getId(props.portals),
|
|
14
|
+
(ids) => {
|
|
15
|
+
if (ids !== prev.value) {
|
|
16
|
+
prev.value = ids;
|
|
17
|
+
const next = props.portals.map((p) => p[1]);
|
|
18
|
+
portalComponents.value = next;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
nextTick(() => {
|
|
24
|
+
renderList.value = () => portalComponents.value.map((P) => <P />);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
return <>{renderList.value()}</>;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
Portals.props = ['portals'];
|
package/src/VueNode.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Decoration, EditorView, Mark, Node } from '@milkdown/prose';
|
|
3
|
+
import { defineComponent, Fragment, h, InjectionKey, provide, ref, watchEffect } from 'vue';
|
|
4
|
+
|
|
5
|
+
export type NodeContext = {
|
|
6
|
+
node: Node | Mark;
|
|
7
|
+
view: EditorView;
|
|
8
|
+
getPos: boolean | (() => number);
|
|
9
|
+
decorations: Decoration[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const nodeMetadata: InjectionKey<NodeContext> = Symbol();
|
|
13
|
+
|
|
14
|
+
export const VueNodeContainer = defineComponent(({ node, view, getPos, decorations }: NodeContext, context) => {
|
|
15
|
+
provide(nodeMetadata, {
|
|
16
|
+
node,
|
|
17
|
+
view,
|
|
18
|
+
getPos,
|
|
19
|
+
decorations,
|
|
20
|
+
});
|
|
21
|
+
return () => <>{context.slots.default?.() ?? []}</>;
|
|
22
|
+
});
|
|
23
|
+
VueNodeContainer.props = ['editor', 'node', 'view', 'getPos', 'decorations'];
|
|
24
|
+
|
|
25
|
+
export const Content = defineComponent((props: { dom: HTMLElement }) => {
|
|
26
|
+
const containerRef = ref<HTMLDivElement | null>(null);
|
|
27
|
+
watchEffect(() => {
|
|
28
|
+
if (!props.dom || !containerRef.value) return;
|
|
29
|
+
containerRef.value.appendChild(props.dom);
|
|
30
|
+
});
|
|
31
|
+
return () => <div ref={containerRef} />;
|
|
32
|
+
});
|
|
33
|
+
Content.props = ['dom'];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Decoration, EditorView, NodeView, ViewFactory } from '@milkdown/prose';
|
|
3
|
+
import { Mark, Node } from '@milkdown/prose';
|
|
4
|
+
import { customAlphabet } from 'nanoid';
|
|
5
|
+
import { DefineComponent, defineComponent, h, Teleport } from 'vue';
|
|
6
|
+
|
|
7
|
+
import { Content, VueNodeContainer } from './VueNode';
|
|
8
|
+
|
|
9
|
+
const nanoid = customAlphabet('abcedfghicklmn', 10);
|
|
10
|
+
|
|
11
|
+
export const createVueView =
|
|
12
|
+
(addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>
|
|
13
|
+
(component: DefineComponent): ViewFactory =>
|
|
14
|
+
(node, view, getPos, decorations) =>
|
|
15
|
+
new VueNodeView(component, addPortal, removePortalByKey, node, view, getPos, decorations);
|
|
16
|
+
|
|
17
|
+
export class VueNodeView implements NodeView {
|
|
18
|
+
dom: HTMLElement | undefined;
|
|
19
|
+
contentDOM: HTMLElement | undefined;
|
|
20
|
+
key: string;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private component: DefineComponent,
|
|
24
|
+
private addPortal: (portal: DefineComponent, key: string) => void,
|
|
25
|
+
private removePortalByKey: (key: string) => void,
|
|
26
|
+
private node: Node | Mark,
|
|
27
|
+
private view: EditorView,
|
|
28
|
+
private getPos: boolean | (() => number),
|
|
29
|
+
private decorations: Decoration[],
|
|
30
|
+
) {
|
|
31
|
+
this.key = nanoid();
|
|
32
|
+
const dom = document.createElement(node instanceof Mark ? 'span' : 'div');
|
|
33
|
+
dom.classList.add('dom-wrapper');
|
|
34
|
+
|
|
35
|
+
const contentDOM =
|
|
36
|
+
node instanceof Node && node.isLeaf
|
|
37
|
+
? undefined
|
|
38
|
+
: document.createElement(node instanceof Mark ? 'span' : 'div');
|
|
39
|
+
if (contentDOM) {
|
|
40
|
+
contentDOM.classList.add('content-dom');
|
|
41
|
+
dom.appendChild(contentDOM);
|
|
42
|
+
}
|
|
43
|
+
this.dom = dom;
|
|
44
|
+
this.contentDOM = contentDOM;
|
|
45
|
+
this.renderPortal();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
renderPortal() {
|
|
49
|
+
if (!this.dom) return;
|
|
50
|
+
|
|
51
|
+
const CustomComponent = this.component;
|
|
52
|
+
const Portal = defineComponent(() => {
|
|
53
|
+
return () => (
|
|
54
|
+
<Teleport to={this.dom}>
|
|
55
|
+
<VueNodeContainer
|
|
56
|
+
key={this.key}
|
|
57
|
+
node={this.node}
|
|
58
|
+
view={this.view}
|
|
59
|
+
getPos={this.getPos}
|
|
60
|
+
decorations={this.decorations}
|
|
61
|
+
>
|
|
62
|
+
<CustomComponent>
|
|
63
|
+
<Content dom={this.contentDOM} />
|
|
64
|
+
</CustomComponent>
|
|
65
|
+
</VueNodeContainer>
|
|
66
|
+
</Teleport>
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
this.addPortal(Portal, this.key);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
destroy() {
|
|
73
|
+
this.dom = undefined;
|
|
74
|
+
this.contentDOM = undefined;
|
|
75
|
+
this.removePortalByKey(this.key);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {
|
|
79
|
+
if (!this.contentDOM) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return !this.contentDOM.contains(mutation.target);
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/index.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
|
|
3
|
+
type Prepend<T, U extends unknown[]> = [T, ...U];
|
|
4
|
+
type Keys_<T extends Record<string, unknown>, U extends PropertyKey[]> = {
|
|
5
|
+
[P in keyof T]: Record<string, unknown> extends Omit<T, P> ? [P] : Prepend<P, Keys_<Omit<T, P>, U>>;
|
|
6
|
+
}[keyof T];
|
|
7
|
+
export type Keys<T extends Record<string, unknown>> = Keys_<T, []>;
|