@milkdown/vue 5.2.0 → 5.2.1

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.
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var e=require("vue"),m=require("@milkdown/core"),u=require("@milkdown/prose"),C=require("nanoid");const R=n=>n.map(t=>t[0]).join(`
2
+ `),h=e.defineComponent(n=>{const t=e.shallowRef([]),a=e.ref(""),i=e.shallowRef(()=>[]);return e.watch(()=>R(n.portals),o=>{if(o!==a.value){a.value=o;const r=n.portals.map(d=>d[1]);t.value=r}}),e.nextTick(()=>{i.value=()=>t.value.map(o=>e.createVNode(o,null,null))}),()=>e.createVNode(e.Fragment,null,[i.value()])});h.props=["portals"];const p=Symbol(),v=e.defineComponent(({node:n,view:t,getPos:a,decorations:i},o)=>(e.provide(p,{node:n,view:t,getPos:a,decorations:i}),()=>{var r,d,s;return e.createVNode(e.Fragment,null,[(s=(d=(r=o.slots).default)==null?void 0:d.call(r))!=null?s:[]])}));v.props=["editor","node","view","getPos","decorations"];const V=e.defineComponent(n=>{const t=e.ref(null);return e.watchEffect(()=>{!n.dom||!t.value||t.value.appendChild(n.dom)}),()=>e.createVNode("div",{ref:t},null)});V.props=["dom"];const g=C.customAlphabet("abcedfghicklmn",10),N=(n,t)=>a=>(i,o,r,d)=>new P(a,n,t,i,o,r,d);class P{constructor(t,a,i,o,r,d,s){this.component=t,this.addPortal=a,this.removePortalByKey=i,this.node=o,this.view=r,this.getPos=d,this.decorations=s,this.key=g();const l=document.createElement(o instanceof u.Mark?"span":"div");l.classList.add("dom-wrapper");const c=o instanceof u.Node&&o.isLeaf?void 0:document.createElement(o instanceof u.Mark?"span":"div");c&&(c.classList.add("content-dom"),l.appendChild(c)),this.dom=l,this.contentDOM=c,this.renderPortal()}renderPortal(){if(!this.dom)return;const t=this.component,a=e.defineComponent(()=>()=>e.createVNode(e.Teleport,{to:this.dom},{default:()=>[e.createVNode(v,{key:this.key,node:this.node,view:this.view,getPos:this.getPos,decorations:this.decorations},{default:()=>[e.createVNode(t,null,{default:()=>[e.createVNode(V,{dom:this.contentDOM},null)]})]})]}));this.addPortal(a,this.key)}destroy(){this.dom=void 0,this.contentDOM=void 0,this.removePortalByKey(this.key)}ignoreMutation(t){return this.contentDOM?!this.contentDOM.contains(t.target):!0}}const w=Symbol(),k=n=>{const t=e.ref(null),a=e.inject(w,()=>{throw new Error}),i=e.markRaw({});return e.onMounted(()=>{!t.value||n(t.value,a).create().then(o=>{i.editor=o}).catch(o=>console.error(o))}),e.onUnmounted(()=>{var d,s,l;const o=(d=i.editor)==null?void 0:d.action(c=>c.get(m.editorViewCtx)),r=(s=i.editor)==null?void 0:s.action(c=>c.get(m.rootCtx));(l=r==null?void 0:r.firstChild)==null||l.remove(),o==null||o.destroy()}),{divRef:t,editorRef:i}},f=e.defineComponent(n=>{const t=k(n.editor);return n.editorRef&&(n.editorRef.value={get:()=>t.editorRef.editor,dom:()=>t.divRef.value}),()=>e.createVNode("div",{ref:t.divRef},null)});f.props=["editor","editorRef"];const y=e.defineComponent(n=>{const t=e.shallowReactive([]),a=e.markRaw((r,d)=>{t.push([d,r])}),i=e.markRaw(r=>{const d=t.findIndex(s=>s[0]===r);t.splice(d,1)}),o=N(a,i);return e.provide(w,o),()=>e.createVNode(e.Fragment,null,[e.createVNode(h,{portals:t},null),e.createVNode(f,{editorRef:n.editorRef,editor:n.editor},null)])});y.props=["editor","editorRef"];const M=n=>(...t)=>n(...t);exports.EditorComponent=f;exports.VueEditor=y;exports.nodeMetadata=p;exports.useEditor=M;
3
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/Portals.tsx","../src/VueNode.tsx","../src/VueNodeView.tsx","../src/Editor.tsx"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { DefineComponent, defineComponent, Fragment, h, nextTick, ref, shallowRef, watch } from 'vue';\nexport type PortalPair = [key: string, component: DefineComponent];\n\nconst getId = (pairs: PortalPair[]) => pairs.map((p) => p[0]).join('\\n');\n\nexport const Portals = defineComponent((props: { portals: PortalPair[] }) => {\n const portalComponents = shallowRef<Array<DefineComponent>>([]);\n const prev = ref<string>('');\n const renderList = shallowRef<() => JSX.Element[]>(() => []);\n\n watch(\n () => getId(props.portals),\n (ids) => {\n if (ids !== prev.value) {\n prev.value = ids;\n const next = props.portals.map((p) => p[1]);\n portalComponents.value = next;\n }\n },\n );\n\n nextTick(() => {\n renderList.value = () => portalComponents.value.map((P) => <P />);\n });\n\n return () => {\n return <>{renderList.value()}</>;\n };\n});\nPortals.props = ['portals'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Decoration, EditorView, Mark, Node } from '@milkdown/prose';\nimport { defineComponent, Fragment, h, InjectionKey, provide, ref, watchEffect } from 'vue';\n\nexport type NodeContext = {\n node: Node | Mark;\n view: EditorView;\n getPos: boolean | (() => number);\n decorations: Decoration[];\n};\n\nexport const nodeMetadata: InjectionKey<NodeContext> = Symbol();\n\nexport const VueNodeContainer = defineComponent(({ node, view, getPos, decorations }: NodeContext, context) => {\n provide(nodeMetadata, {\n node,\n view,\n getPos,\n decorations,\n });\n return () => <>{context.slots.default?.() ?? []}</>;\n});\nVueNodeContainer.props = ['editor', 'node', 'view', 'getPos', 'decorations'];\n\nexport const Content = defineComponent((props: { dom?: HTMLElement }) => {\n const containerRef = ref<HTMLDivElement | null>(null);\n watchEffect(() => {\n if (!props.dom || !containerRef.value) return;\n containerRef.value.appendChild(props.dom);\n });\n return () => <div ref={containerRef} />;\n});\nContent.props = ['dom'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Decoration, EditorView, NodeView, ViewFactory } from '@milkdown/prose';\nimport { Mark, Node } from '@milkdown/prose';\nimport { customAlphabet } from 'nanoid';\nimport { DefineComponent, defineComponent, h, Teleport } from 'vue';\n\nimport { Content, VueNodeContainer } from './VueNode';\n\nconst nanoid = customAlphabet('abcedfghicklmn', 10);\n\nexport const createVueView =\n (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>\n (component: DefineComponent): ViewFactory =>\n (node, view, getPos, decorations) =>\n new VueNodeView(component, addPortal, removePortalByKey, node, view, getPos, decorations);\n\nexport class VueNodeView implements NodeView {\n dom: HTMLElement | undefined;\n contentDOM: HTMLElement | undefined;\n key: string;\n\n constructor(\n private component: DefineComponent,\n private addPortal: (portal: DefineComponent, key: string) => void,\n private removePortalByKey: (key: string) => void,\n private node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n private decorations: Decoration[],\n ) {\n this.key = nanoid();\n const dom = document.createElement(node instanceof Mark ? 'span' : 'div');\n dom.classList.add('dom-wrapper');\n\n const contentDOM =\n node instanceof Node && node.isLeaf\n ? undefined\n : document.createElement(node instanceof Mark ? 'span' : 'div');\n if (contentDOM) {\n contentDOM.classList.add('content-dom');\n dom.appendChild(contentDOM);\n }\n this.dom = dom;\n this.contentDOM = contentDOM;\n this.renderPortal();\n }\n\n renderPortal() {\n if (!this.dom) return;\n\n const CustomComponent = this.component;\n const Portal = defineComponent(() => {\n return () => (\n <Teleport to={this.dom}>\n <VueNodeContainer\n key={this.key}\n node={this.node}\n view={this.view}\n getPos={this.getPos}\n decorations={this.decorations}\n >\n <CustomComponent>\n <Content dom={this.contentDOM} />\n </CustomComponent>\n </VueNodeContainer>\n </Teleport>\n );\n });\n this.addPortal(Portal, this.key);\n }\n\n destroy() {\n this.dom = undefined;\n this.contentDOM = undefined;\n this.removePortalByKey(this.key);\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\n if (!this.contentDOM) {\n return true;\n }\n return !this.contentDOM.contains(mutation.target);\n }\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Editor, editorViewCtx, rootCtx } from '@milkdown/core';\nimport { ViewFactory } from '@milkdown/prose';\nimport {\n DefineComponent,\n defineComponent,\n Fragment,\n h,\n inject,\n InjectionKey,\n markRaw,\n onMounted,\n onUnmounted,\n provide,\n Ref,\n ref,\n shallowReactive,\n} from 'vue';\n\nimport { PortalPair, Portals } from './Portals';\nimport { createVueView } from './VueNodeView';\n\nconst rendererKey: InjectionKey<(component: DefineComponent) => ViewFactory> = Symbol();\n\ntype GetEditor = (container: HTMLDivElement, renderVue: (Component: DefineComponent) => ViewFactory) => Editor;\n\nconst useGetEditor = (getEditor: GetEditor) => {\n const divRef = ref<HTMLDivElement | null>(null);\n const renderVue = inject<(Component: DefineComponent) => ViewFactory>(rendererKey, () => {\n throw new Error();\n });\n const editorRef = markRaw<{ editor?: Editor }>({});\n onMounted(() => {\n if (!divRef.value) return;\n\n getEditor(divRef.value, renderVue)\n .create()\n .then((editor) => {\n editorRef.editor = editor;\n return;\n })\n .catch((e) => console.error(e));\n });\n onUnmounted(() => {\n const view = editorRef.editor?.action((ctx) => ctx.get(editorViewCtx));\n const root = editorRef.editor?.action((ctx) => ctx.get(rootCtx)) as HTMLElement;\n\n root?.firstChild?.remove();\n view?.destroy();\n });\n\n return { divRef, editorRef };\n};\n\nexport const EditorComponent = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {\n const refs = useGetEditor(props.editor);\n if (props.editorRef) {\n props.editorRef.value = {\n get: () => refs.editorRef.editor,\n dom: () => refs.divRef.value,\n };\n }\n\n return () => <div ref={refs.divRef} />;\n});\nEditorComponent.props = ['editor', 'editorRef'];\n\nexport type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };\n\nexport const VueEditor = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {\n const portals = shallowReactive<PortalPair[]>([]);\n const addPortal = markRaw((component: DefineComponent, key: string) => {\n portals.push([key, component]);\n });\n const removePortalByKey = markRaw((key: string) => {\n const index = portals.findIndex((p) => p[0] === key);\n portals.splice(index, 1);\n });\n const renderVue = createVueView(addPortal, removePortalByKey);\n provide(rendererKey, renderVue);\n\n return () => (\n <>\n <Portals portals={portals} />\n <EditorComponent editorRef={props.editorRef} editor={props.editor} />\n </>\n );\n});\nVueEditor.props = ['editor', 'editorRef'];\n\nexport const useEditor = (getEditor: GetEditor) => {\n return (...args: Parameters<GetEditor>) => getEditor(...args);\n};\n"],"names":["getId","pairs","map","p","join","Portals","defineComponent","props","portalComponents","shallowRef","prev","ref","renderList","watch","portals","ids","value","next","nextTick","P","nodeMetadata","Symbol","VueNodeContainer","node","view","getPos","decorations","context","provide","slots","default","Content","containerRef","watchEffect","dom","appendChild","nanoid","customAlphabet","createVueView","addPortal","removePortalByKey","component","VueNodeView","constructor","key","document","createElement","Mark","classList","add","contentDOM","Node","isLeaf","undefined","renderPortal","CustomComponent","Portal","destroy","ignoreMutation","mutation","contains","target","rendererKey","useGetEditor","getEditor","divRef","renderVue","inject","Error","editorRef","markRaw","onMounted","create","then","editor","catch","e","console","error","onUnmounted","action","ctx","get","editorViewCtx","root","rootCtx","firstChild","remove","EditorComponent","refs","VueEditor","shallowReactive","push","index","findIndex","splice","useEditor","args"],"mappings":"2MAIA,KAAMA,GAASC,GAAwBA,EAAMC,IAAKC,GAAMA,EAAE,IAAIC,KAAK;AAAA,GAEtDC,EAAUC,kBAAiBC,GAAqC,MACnEC,GAAmBC,aAAmC,IACtDC,EAAOC,MAAY,IACnBC,EAAaH,aAAgC,IAAM,IAEzDI,eACI,IAAMb,EAAMO,EAAMO,SACjBC,GAAQ,IACDA,IAAQL,EAAKM,MAAO,CACpBN,EAAKM,MAAQD,OACPE,GAAOV,EAAMO,QAAQZ,IAAKC,GAAMA,EAAE,IACxCK,EAAiBQ,MAAQC,KAKrCC,WAAS,IAAM,CACXN,EAAWI,MAAQ,IAAMR,EAAiBQ,MAAMd,IAAKiB,iCAGlD,mCACOP,EAAWI,YAG7BX,EAAQE,MAAQ,CAAC,gBCnBJa,GAA0CC,SAE1CC,EAAmBhB,kBAAgB,CAAC,CAAEiB,OAAMC,OAAMC,SAAQC,eAA4BC,IAC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4DAEmBpD,oCACUP,EAAM8D,iBAAmB9D,EAAMmE,kBAIvEgB,EAAUnF,MAAQ,CAAC,SAAU,kBAEhByF,GAAahC,GACf,IAAIiC,IAAgCjC,EAAU,GAAGiC"}
@@ -0,0 +1,179 @@
1
+ import { defineComponent, shallowRef, ref, watch, nextTick, createVNode, Fragment, provide, watchEffect, Teleport, shallowReactive, markRaw, inject, onMounted, onUnmounted } from "vue";
2
+ import { editorViewCtx, rootCtx } from "@milkdown/core";
3
+ import { Mark, Node } from "@milkdown/prose";
4
+ import { customAlphabet } from "nanoid";
5
+ const getId = (pairs) => pairs.map((p) => p[0]).join("\n");
6
+ const Portals = defineComponent((props) => {
7
+ const portalComponents = shallowRef([]);
8
+ const prev = ref("");
9
+ const renderList = shallowRef(() => []);
10
+ watch(() => getId(props.portals), (ids) => {
11
+ if (ids !== prev.value) {
12
+ prev.value = ids;
13
+ const next = props.portals.map((p) => p[1]);
14
+ portalComponents.value = next;
15
+ }
16
+ });
17
+ nextTick(() => {
18
+ renderList.value = () => portalComponents.value.map((P) => createVNode(P, null, null));
19
+ });
20
+ return () => {
21
+ return createVNode(Fragment, null, [renderList.value()]);
22
+ };
23
+ });
24
+ Portals.props = ["portals"];
25
+ const nodeMetadata = Symbol();
26
+ const VueNodeContainer = defineComponent(({
27
+ node,
28
+ view,
29
+ getPos,
30
+ decorations
31
+ }, context) => {
32
+ provide(nodeMetadata, {
33
+ node,
34
+ view,
35
+ getPos,
36
+ decorations
37
+ });
38
+ return () => {
39
+ var _a, _b, _c;
40
+ return createVNode(Fragment, null, [(_c = (_b = (_a = context.slots).default) == null ? void 0 : _b.call(_a)) != null ? _c : []]);
41
+ };
42
+ });
43
+ VueNodeContainer.props = ["editor", "node", "view", "getPos", "decorations"];
44
+ const Content = defineComponent((props) => {
45
+ const containerRef = ref(null);
46
+ watchEffect(() => {
47
+ if (!props.dom || !containerRef.value)
48
+ return;
49
+ containerRef.value.appendChild(props.dom);
50
+ });
51
+ return () => createVNode("div", {
52
+ "ref": containerRef
53
+ }, null);
54
+ });
55
+ Content.props = ["dom"];
56
+ const nanoid = customAlphabet("abcedfghicklmn", 10);
57
+ const createVueView = (addPortal, removePortalByKey) => (component) => (node, view, getPos, decorations) => new VueNodeView(component, addPortal, removePortalByKey, node, view, getPos, decorations);
58
+ class VueNodeView {
59
+ constructor(component, addPortal, removePortalByKey, node, view, getPos, decorations) {
60
+ this.component = component;
61
+ this.addPortal = addPortal;
62
+ this.removePortalByKey = removePortalByKey;
63
+ this.node = node;
64
+ this.view = view;
65
+ this.getPos = getPos;
66
+ this.decorations = decorations;
67
+ this.key = nanoid();
68
+ const dom = document.createElement(node instanceof Mark ? "span" : "div");
69
+ dom.classList.add("dom-wrapper");
70
+ const contentDOM = node instanceof Node && node.isLeaf ? void 0 : document.createElement(node instanceof Mark ? "span" : "div");
71
+ if (contentDOM) {
72
+ contentDOM.classList.add("content-dom");
73
+ dom.appendChild(contentDOM);
74
+ }
75
+ this.dom = dom;
76
+ this.contentDOM = contentDOM;
77
+ this.renderPortal();
78
+ }
79
+ renderPortal() {
80
+ if (!this.dom)
81
+ return;
82
+ const CustomComponent = this.component;
83
+ const Portal = defineComponent(() => {
84
+ return () => createVNode(Teleport, {
85
+ "to": this.dom
86
+ }, {
87
+ default: () => [createVNode(VueNodeContainer, {
88
+ "key": this.key,
89
+ "node": this.node,
90
+ "view": this.view,
91
+ "getPos": this.getPos,
92
+ "decorations": this.decorations
93
+ }, {
94
+ default: () => [createVNode(CustomComponent, null, {
95
+ default: () => [createVNode(Content, {
96
+ "dom": this.contentDOM
97
+ }, null)]
98
+ })]
99
+ })]
100
+ });
101
+ });
102
+ this.addPortal(Portal, this.key);
103
+ }
104
+ destroy() {
105
+ this.dom = void 0;
106
+ this.contentDOM = void 0;
107
+ this.removePortalByKey(this.key);
108
+ }
109
+ ignoreMutation(mutation) {
110
+ if (!this.contentDOM) {
111
+ return true;
112
+ }
113
+ return !this.contentDOM.contains(mutation.target);
114
+ }
115
+ }
116
+ const rendererKey = Symbol();
117
+ const useGetEditor = (getEditor) => {
118
+ const divRef = ref(null);
119
+ const renderVue = inject(rendererKey, () => {
120
+ throw new Error();
121
+ });
122
+ const editorRef = markRaw({});
123
+ onMounted(() => {
124
+ if (!divRef.value)
125
+ return;
126
+ getEditor(divRef.value, renderVue).create().then((editor) => {
127
+ editorRef.editor = editor;
128
+ return;
129
+ }).catch((e) => console.error(e));
130
+ });
131
+ onUnmounted(() => {
132
+ var _a, _b, _c;
133
+ const view = (_a = editorRef.editor) == null ? void 0 : _a.action((ctx) => ctx.get(editorViewCtx));
134
+ const root = (_b = editorRef.editor) == null ? void 0 : _b.action((ctx) => ctx.get(rootCtx));
135
+ (_c = root == null ? void 0 : root.firstChild) == null ? void 0 : _c.remove();
136
+ view == null ? void 0 : view.destroy();
137
+ });
138
+ return {
139
+ divRef,
140
+ editorRef
141
+ };
142
+ };
143
+ const EditorComponent = defineComponent((props) => {
144
+ const refs = useGetEditor(props.editor);
145
+ if (props.editorRef) {
146
+ props.editorRef.value = {
147
+ get: () => refs.editorRef.editor,
148
+ dom: () => refs.divRef.value
149
+ };
150
+ }
151
+ return () => createVNode("div", {
152
+ "ref": refs.divRef
153
+ }, null);
154
+ });
155
+ EditorComponent.props = ["editor", "editorRef"];
156
+ const VueEditor = defineComponent((props) => {
157
+ const portals = shallowReactive([]);
158
+ const addPortal = markRaw((component, key) => {
159
+ portals.push([key, component]);
160
+ });
161
+ const removePortalByKey = markRaw((key) => {
162
+ const index = portals.findIndex((p) => p[0] === key);
163
+ portals.splice(index, 1);
164
+ });
165
+ const renderVue = createVueView(addPortal, removePortalByKey);
166
+ provide(rendererKey, renderVue);
167
+ return () => createVNode(Fragment, null, [createVNode(Portals, {
168
+ "portals": portals
169
+ }, null), createVNode(EditorComponent, {
170
+ "editorRef": props.editorRef,
171
+ "editor": props.editor
172
+ }, null)]);
173
+ });
174
+ VueEditor.props = ["editor", "editorRef"];
175
+ const useEditor = (getEditor) => {
176
+ return (...args) => getEditor(...args);
177
+ };
178
+ export { EditorComponent, VueEditor, nodeMetadata, useEditor };
179
+ //# sourceMappingURL=index.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","sources":["../src/Portals.tsx","../src/VueNode.tsx","../src/VueNodeView.tsx","../src/Editor.tsx"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { DefineComponent, defineComponent, Fragment, h, nextTick, ref, shallowRef, watch } from 'vue';\nexport type PortalPair = [key: string, component: DefineComponent];\n\nconst getId = (pairs: PortalPair[]) => pairs.map((p) => p[0]).join('\\n');\n\nexport const Portals = defineComponent((props: { portals: PortalPair[] }) => {\n const portalComponents = shallowRef<Array<DefineComponent>>([]);\n const prev = ref<string>('');\n const renderList = shallowRef<() => JSX.Element[]>(() => []);\n\n watch(\n () => getId(props.portals),\n (ids) => {\n if (ids !== prev.value) {\n prev.value = ids;\n const next = props.portals.map((p) => p[1]);\n portalComponents.value = next;\n }\n },\n );\n\n nextTick(() => {\n renderList.value = () => portalComponents.value.map((P) => <P />);\n });\n\n return () => {\n return <>{renderList.value()}</>;\n };\n});\nPortals.props = ['portals'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Decoration, EditorView, Mark, Node } from '@milkdown/prose';\nimport { defineComponent, Fragment, h, InjectionKey, provide, ref, watchEffect } from 'vue';\n\nexport type NodeContext = {\n node: Node | Mark;\n view: EditorView;\n getPos: boolean | (() => number);\n decorations: Decoration[];\n};\n\nexport const nodeMetadata: InjectionKey<NodeContext> = Symbol();\n\nexport const VueNodeContainer = defineComponent(({ node, view, getPos, decorations }: NodeContext, context) => {\n provide(nodeMetadata, {\n node,\n view,\n getPos,\n decorations,\n });\n return () => <>{context.slots.default?.() ?? []}</>;\n});\nVueNodeContainer.props = ['editor', 'node', 'view', 'getPos', 'decorations'];\n\nexport const Content = defineComponent((props: { dom?: HTMLElement }) => {\n const containerRef = ref<HTMLDivElement | null>(null);\n watchEffect(() => {\n if (!props.dom || !containerRef.value) return;\n containerRef.value.appendChild(props.dom);\n });\n return () => <div ref={containerRef} />;\n});\nContent.props = ['dom'];\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Decoration, EditorView, NodeView, ViewFactory } from '@milkdown/prose';\nimport { Mark, Node } from '@milkdown/prose';\nimport { customAlphabet } from 'nanoid';\nimport { DefineComponent, defineComponent, h, Teleport } from 'vue';\n\nimport { Content, VueNodeContainer } from './VueNode';\n\nconst nanoid = customAlphabet('abcedfghicklmn', 10);\n\nexport const createVueView =\n (addPortal: (portal: DefineComponent, key: string) => void, removePortalByKey: (key: string) => void) =>\n (component: DefineComponent): ViewFactory =>\n (node, view, getPos, decorations) =>\n new VueNodeView(component, addPortal, removePortalByKey, node, view, getPos, decorations);\n\nexport class VueNodeView implements NodeView {\n dom: HTMLElement | undefined;\n contentDOM: HTMLElement | undefined;\n key: string;\n\n constructor(\n private component: DefineComponent,\n private addPortal: (portal: DefineComponent, key: string) => void,\n private removePortalByKey: (key: string) => void,\n private node: Node | Mark,\n private view: EditorView,\n private getPos: boolean | (() => number),\n private decorations: Decoration[],\n ) {\n this.key = nanoid();\n const dom = document.createElement(node instanceof Mark ? 'span' : 'div');\n dom.classList.add('dom-wrapper');\n\n const contentDOM =\n node instanceof Node && node.isLeaf\n ? undefined\n : document.createElement(node instanceof Mark ? 'span' : 'div');\n if (contentDOM) {\n contentDOM.classList.add('content-dom');\n dom.appendChild(contentDOM);\n }\n this.dom = dom;\n this.contentDOM = contentDOM;\n this.renderPortal();\n }\n\n renderPortal() {\n if (!this.dom) return;\n\n const CustomComponent = this.component;\n const Portal = defineComponent(() => {\n return () => (\n <Teleport to={this.dom}>\n <VueNodeContainer\n key={this.key}\n node={this.node}\n view={this.view}\n getPos={this.getPos}\n decorations={this.decorations}\n >\n <CustomComponent>\n <Content dom={this.contentDOM} />\n </CustomComponent>\n </VueNodeContainer>\n </Teleport>\n );\n });\n this.addPortal(Portal, this.key);\n }\n\n destroy() {\n this.dom = undefined;\n this.contentDOM = undefined;\n this.removePortalByKey(this.key);\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\n if (!this.contentDOM) {\n return true;\n }\n return !this.contentDOM.contains(mutation.target);\n }\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Editor, editorViewCtx, rootCtx } from '@milkdown/core';\nimport { ViewFactory } from '@milkdown/prose';\nimport {\n DefineComponent,\n defineComponent,\n Fragment,\n h,\n inject,\n InjectionKey,\n markRaw,\n onMounted,\n onUnmounted,\n provide,\n Ref,\n ref,\n shallowReactive,\n} from 'vue';\n\nimport { PortalPair, Portals } from './Portals';\nimport { createVueView } from './VueNodeView';\n\nconst rendererKey: InjectionKey<(component: DefineComponent) => ViewFactory> = Symbol();\n\ntype GetEditor = (container: HTMLDivElement, renderVue: (Component: DefineComponent) => ViewFactory) => Editor;\n\nconst useGetEditor = (getEditor: GetEditor) => {\n const divRef = ref<HTMLDivElement | null>(null);\n const renderVue = inject<(Component: DefineComponent) => ViewFactory>(rendererKey, () => {\n throw new Error();\n });\n const editorRef = markRaw<{ editor?: Editor }>({});\n onMounted(() => {\n if (!divRef.value) return;\n\n getEditor(divRef.value, renderVue)\n .create()\n .then((editor) => {\n editorRef.editor = editor;\n return;\n })\n .catch((e) => console.error(e));\n });\n onUnmounted(() => {\n const view = editorRef.editor?.action((ctx) => ctx.get(editorViewCtx));\n const root = editorRef.editor?.action((ctx) => ctx.get(rootCtx)) as HTMLElement;\n\n root?.firstChild?.remove();\n view?.destroy();\n });\n\n return { divRef, editorRef };\n};\n\nexport const EditorComponent = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {\n const refs = useGetEditor(props.editor);\n if (props.editorRef) {\n props.editorRef.value = {\n get: () => refs.editorRef.editor,\n dom: () => refs.divRef.value,\n };\n }\n\n return () => <div ref={refs.divRef} />;\n});\nEditorComponent.props = ['editor', 'editorRef'];\n\nexport type EditorRef = { get: () => Editor | undefined; dom: () => HTMLDivElement | null };\n\nexport const VueEditor = defineComponent((props: { editor: GetEditor; editorRef?: Ref<EditorRef> }) => {\n const portals = shallowReactive<PortalPair[]>([]);\n const addPortal = markRaw((component: DefineComponent, key: string) => {\n portals.push([key, component]);\n });\n const removePortalByKey = markRaw((key: string) => {\n const index = portals.findIndex((p) => p[0] === key);\n portals.splice(index, 1);\n });\n const renderVue = createVueView(addPortal, removePortalByKey);\n provide(rendererKey, renderVue);\n\n return () => (\n <>\n <Portals portals={portals} />\n <EditorComponent editorRef={props.editorRef} editor={props.editor} />\n </>\n );\n});\nVueEditor.props = ['editor', 'editorRef'];\n\nexport const useEditor = (getEditor: GetEditor) => {\n return (...args: Parameters<GetEditor>) => getEditor(...args);\n};\n"],"names":["getId","pairs","map","p","join","Portals","defineComponent","props","portalComponents","shallowRef","prev","ref","renderList","watch","portals","ids","value","next","nextTick","P","nodeMetadata","Symbol","VueNodeContainer","node","view","getPos","decorations","context","provide","slots","default","Content","containerRef","watchEffect","dom","appendChild","nanoid","customAlphabet","createVueView","addPortal","removePortalByKey","component","VueNodeView","constructor","key","document","createElement","Mark","classList","add","contentDOM","Node","isLeaf","undefined","renderPortal","CustomComponent","Portal","destroy","ignoreMutation","mutation","contains","target","rendererKey","useGetEditor","getEditor","divRef","renderVue","inject","Error","editorRef","markRaw","onMounted","create","then","editor","catch","e","console","error","onUnmounted","action","ctx","get","editorViewCtx","root","rootCtx","firstChild","remove","EditorComponent","refs","VueEditor","shallowReactive","push","index","findIndex","splice","useEditor","args"],"mappings":";;;;AAIA,MAAMA,QAASC,WAAwBA,MAAMC,IAAKC,OAAMA,EAAE,IAAIC,KAAK;AAE5D,MAAMC,UAAUC,gBAAiBC,WAAqC;QACnEC,mBAAmBC,WAAmC;QACtDC,OAAOC,IAAY;QACnBC,aAAaH,WAAgC,MAAM;AAEzDI,QACI,MAAMb,MAAMO,MAAMO,UACjBC,SAAQ;QACDA,QAAQL,KAAKM,OAAO;AACpBN,WAAKM,QAAQD;YACPE,OAAOV,MAAMO,QAA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G;AAClB/D,iCAAMiC;AAAAA;SAGH;AAAA,IAAEQ;AAAAA,IAAQI;AAAAA;AAAAA;MAGRmB,kBAAkBlF,gBAAiBC,WAA6D;QACnGkF,OAAO1B,aAAaxD,MAAMmE;MAC5BnE,MAAM8D,WAAW;AACjB9D,UAAM8D,UAAUrD,QAAQ;AAAA,MACpBkE,KAAK,MAAMO,KAAKpB,UAAUK;AAAAA,MAC1BxC,KAAK,MAAMuD,KAAKxB,OAAOjD;AAAAA;AAAAA;SAIxB;WAAgByE,KAAKxB;AAAAA;;AAEhCuB,gBAAgBjF,QAAQ,CAAC,UAAU;MAItBmF,YAAYpF,gBAAiBC,WAA6D;QAC7FO,UAAU6E,gBAA8B;QACxCpD,YAAY+B,QAAQ,CAAC7B,WAA4BG,QAAgB;AACnE9B,YAAQ8E,KAAK,CAAChD,KAAKH;AAAAA;QAEjBD,oBAAoB8B,QAAS1B,SAAgB;UACzCiD,QAAQ/E,QAAQgF,UAAW3F,OAAMA,EAAE,OAAOyC;AAChD9B,YAAQiF,OAAOF,OAAO;AAAA;QAEpB3B,YAAY5B,cAAcC,WAAWC;AAC3CZ,UAAQkC,aAAaI;SAEd;eAEmBpD;AAAAA;iBACUP,MAAM8D;AAAAA,cAAmB9D,MAAMmE;AAAAA;;AAIvEgB,UAAUnF,QAAQ,CAAC,UAAU;MAEhByF,YAAahC,eAAyB;SACxC,IAAIiC,SAAgCjC,UAAU,GAAGiC;AAAAA;;"}
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@milkdown/vue",
3
- "version": "5.2.0",
4
- "main": "lib/index.js",
5
- "module": "lib/index.js",
6
- "types": "lib/index.d.ts",
3
+ "version": "5.2.1",
4
+ "main": "./lib/index.cjs.js",
5
+ "module": "./lib/index.es.js",
6
+ "types": "./lib/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./lib/index.es.js",
10
+ "require": "./lib/index.cjs.js"
11
+ }
12
+ },
7
13
  "sideEffects": false,
8
14
  "license": "MIT",
9
15
  "files": [
@@ -16,7 +22,7 @@
16
22
  "vue"
17
23
  ],
18
24
  "dependencies": {
19
- "@milkdown/utils": "5.2.0",
25
+ "@milkdown/utils": "5.2.1",
20
26
  "nanoid": "^3.1.25",
21
27
  "tslib": "^2.3.1"
22
28
  },
@@ -25,13 +31,17 @@
25
31
  "vue": "^3.0.0"
26
32
  },
27
33
  "devDependencies": {
34
+ "@milkdown/core": "5.2.1",
35
+ "@milkdown/prose": "5.2.1",
36
+ "@milkdown/preset-commonmark": "5.2.1",
37
+ "@milkdown/theme-nord": "5.2.1",
28
38
  "vue": "^3.0.0"
29
39
  },
30
40
  "scripts": {
31
41
  "start": "vite",
32
- "watch": "tsc -w",
42
+ "watch": "vite build --watch",
33
43
  "test": "jest",
34
44
  "tsc": "tsc --noEmit",
35
- "build": "tsc"
45
+ "build": "vite build && tsc --emitDeclarationOnly"
36
46
  }
37
47
  }
package/lib/Editor.js DELETED
@@ -1,63 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { editorViewCtx, rootCtx } from '@milkdown/core';
3
- import { defineComponent, Fragment, h, inject, markRaw, onMounted, onUnmounted, provide, ref, shallowReactive, } from 'vue';
4
- import { Portals } from './Portals';
5
- import { createVueView } from './VueNodeView';
6
- const rendererKey = Symbol();
7
- const useGetEditor = (getEditor) => {
8
- const divRef = ref(null);
9
- const renderVue = inject(rendererKey, () => {
10
- throw new Error();
11
- });
12
- const editorRef = markRaw({});
13
- onMounted(() => {
14
- if (!divRef.value)
15
- return;
16
- getEditor(divRef.value, renderVue)
17
- .create()
18
- .then((editor) => {
19
- editorRef.editor = editor;
20
- return;
21
- })
22
- .catch((e) => console.error(e));
23
- });
24
- onUnmounted(() => {
25
- var _a, _b, _c;
26
- const view = (_a = editorRef.editor) === null || _a === void 0 ? void 0 : _a.action((ctx) => ctx.get(editorViewCtx));
27
- const root = (_b = editorRef.editor) === null || _b === void 0 ? void 0 : _b.action((ctx) => ctx.get(rootCtx));
28
- (_c = root === null || root === void 0 ? void 0 : root.firstChild) === null || _c === void 0 ? void 0 : _c.remove();
29
- view === null || view === void 0 ? void 0 : view.destroy();
30
- });
31
- return { divRef, editorRef };
32
- };
33
- export const EditorComponent = defineComponent((props) => {
34
- const refs = useGetEditor(props.editor);
35
- if (props.editorRef) {
36
- props.editorRef.value = {
37
- get: () => refs.editorRef.editor,
38
- dom: () => refs.divRef.value,
39
- };
40
- }
41
- return () => h("div", { ref: refs.divRef });
42
- });
43
- EditorComponent.props = ['editor', 'editorRef'];
44
- export const VueEditor = defineComponent((props) => {
45
- const portals = shallowReactive([]);
46
- const addPortal = markRaw((component, key) => {
47
- portals.push([key, component]);
48
- });
49
- const removePortalByKey = markRaw((key) => {
50
- const index = portals.findIndex((p) => p[0] === key);
51
- portals.splice(index, 1);
52
- });
53
- const renderVue = createVueView(addPortal, removePortalByKey);
54
- provide(rendererKey, renderVue);
55
- return () => (h(Fragment, null,
56
- h(Portals, { portals: portals }),
57
- h(EditorComponent, { editorRef: props.editorRef, editor: props.editor })));
58
- });
59
- VueEditor.props = ['editor', 'editorRef'];
60
- export const useEditor = (getEditor) => {
61
- return (...args) => getEditor(...args);
62
- };
63
- //# sourceMappingURL=Editor.js.map
package/lib/Editor.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../src/Editor.tsx"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAU,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEhE,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,E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AEhC,OAAO,GAAG,EAAE,CAAC,CACT;QACI,EAAC,OAAO,IAAC,OAAO,EAAE,OAAO,GAAI;QAC7B,EAAC,eAAe,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAI,CACtE,CACN,CAAC;AACN,CAAC,CAAC,CAAC;AACH,SAAS,CAAC,KAAK,GAAG,CAAC,QAAQ,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/Portals.js DELETED
@@ -1,23 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { defineComponent, Fragment, h, nextTick, ref, shallowRef, watch } from 'vue';
3
- const getId = (pairs) => pairs.map((p) => p[0]).join('\n');
4
- export const Portals = defineComponent((props) => {
5
- const portalComponents = shallowRef([]);
6
- const prev = ref('');
7
- const renderList = shallowRef(() => []);
8
- watch(() => getId(props.portals), (ids) => {
9
- if (ids !== prev.value) {
10
- prev.value = ids;
11
- const next = props.portals.map((p) => p[1]);
12
- portalComponents.value = next;
13
- }
14
- });
15
- nextTick(() => {
16
- renderList.value = () => portalComponents.value.map((P) => h(P, null));
17
- });
18
- return () => {
19
- return h(Fragment, null, renderList.value());
20
- };
21
- });
22
- Portals.props = ['portals'];
23
- //# sourceMappingURL=Portals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Portals.js","sourceRoot":"","sources":["../src/Portals.tsx"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAmB,eAAe,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAGtG,MAAM,KAAK,GAAG,CAAC,KAAmB,EAAE,EA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ffect } from 'vue';
2
- export const nodeMetadata = Symbol();
3
- export const VueNodeContainer = defineComponent(({ node, view, getPos, decorations }, context) => {
4
- provide(nodeMetadata, {
5
- node,
6
- view,
7
- getPos,
8
- decorations,
9
- });
10
- return () => { var _a, _b, _c; return h(Fragment, null, (_c = (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : []); };
11
- });
12
- VueNodeContainer.props = ['editor', 'node', 'view', 'getPos', 'decorations'];
13
- export const Content = defineComponent((props) => {
14
- const containerRef = ref(null);
15
- watchEffect(() => {
16
- if (!props.dom || !containerRef.value)
17
- return;
18
- containerRef.value.appendChild(props.dom);
19
- });
20
- return () => h("div", { ref: containerRef });
21
- });
22
- Content.props = ['dom'];
23
- //# sourceMappingURL=VueNode.js.map
@@ -1 +0,0 @@
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,KAA4B,EAAE,EAAE;IACpE,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"}
@@ -1,54 +0,0 @@
1
- import { Mark, Node } from '@milkdown/prose';
2
- import { customAlphabet } from 'nanoid';
3
- import { defineComponent, h, Teleport } from 'vue';
4
- import { Content, VueNodeContainer } from './VueNode';
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);
7
- export class VueNodeView {
8
- constructor(component, addPortal, removePortalByKey, node, view, getPos, decorations) {
9
- this.component = component;
10
- this.addPortal = addPortal;
11
- this.removePortalByKey = removePortalByKey;
12
- this.node = node;
13
- this.view = view;
14
- this.getPos = getPos;
15
- this.decorations = decorations;
16
- this.key = nanoid();
17
- const dom = document.createElement(node instanceof Mark ? 'span' : 'div');
18
- dom.classList.add('dom-wrapper');
19
- const contentDOM = node instanceof Node && node.isLeaf
20
- ? undefined
21
- : document.createElement(node instanceof Mark ? 'span' : 'div');
22
- if (contentDOM) {
23
- contentDOM.classList.add('content-dom');
24
- dom.appendChild(contentDOM);
25
- }
26
- this.dom = dom;
27
- this.contentDOM = contentDOM;
28
- this.renderPortal();
29
- }
30
- renderPortal() {
31
- if (!this.dom)
32
- return;
33
- const CustomComponent = this.component;
34
- const Portal = defineComponent(() => {
35
- return () => (h(Teleport, { to: this.dom },
36
- h(VueNodeContainer, { key: this.key, node: this.node, view: this.view, getPos: this.getPos, decorations: this.decorations },
37
- h(CustomComponent, null,
38
- h(Content, { dom: this.contentDOM })))));
39
- });
40
- this.addPortal(Portal, this.key);
41
- }
42
- destroy() {
43
- this.dom = undefined;
44
- this.contentDOM = undefined;
45
- this.removePortalByKey(this.key);
46
- }
47
- ignoreMutation(mutation) {
48
- if (!this.contentDOM) {
49
- return true;
50
- }
51
- return !this.contentDOM.contains(mutation.target);
52
- }
53
- }
54
- //# sourceMappingURL=VueNodeView.js.map
@@ -1 +0,0 @@
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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AC,gBAAgB,IACb,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,WAAW,EAAE,IAAI,CAAC,WAAW;oBAE7B,EAAC,eAAe;wBACZ,EAAC,OAAO,IAAC,GAAG,EAAE,IAAI,CAAC,UAAU,GAAI,CACnB,CACH,CACZ,CACd,CAAC;QACN,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,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/index.js DELETED
@@ -1,4 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- export * from './Editor';
3
- export { nodeMetadata } from './VueNode';
4
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
package/lib/utils.js DELETED
@@ -1,3 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- export {};
3
- //# sourceMappingURL=utils.js.map
package/lib/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,yCAAyC"}