@textbus/adapter-viewfly 5.1.6 → 5.2.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/LICENSE +21 -674
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +120 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/{bundles → dist}/viewfly-adapter.d.ts +2 -2
- package/{bundles → dist}/viewfly-vdom-adapter.d.ts +2 -2
- package/package.json +30 -21
- package/bundles/index.esm.js +0 -181
- package/bundles/index.js +0 -184
- /package/{bundles → dist}/public-api.d.ts +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { makeError as R, VElement as w, VTextNode as V, merge as A, Adapter as y } from "@textbus/core";
|
|
2
|
+
import { jsx as f, createDynamicRef as m, DynamicRef as C, getCurrentInstance as x, onUnmounted as E, onUpdated as p, ReflectiveInjector as g } from "@viewfly/core";
|
|
3
|
+
import { DomAdapter as u } from "@textbus/platform-browser";
|
|
4
|
+
import { NodeViewAdapter as k } from "@textbus/platform-node";
|
|
5
|
+
const h = R("ViewflyDOMRenderer");
|
|
6
|
+
class d extends u {
|
|
7
|
+
components = {};
|
|
8
|
+
componentRefs = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
constructor(c, a) {
|
|
10
|
+
super({
|
|
11
|
+
createCompositionNode(e, r) {
|
|
12
|
+
const t = m((n) => (r(n), () => {
|
|
13
|
+
r(null);
|
|
14
|
+
}));
|
|
15
|
+
return new w("span", {
|
|
16
|
+
style: {
|
|
17
|
+
textDecoration: "underline"
|
|
18
|
+
},
|
|
19
|
+
ref: t
|
|
20
|
+
}, [
|
|
21
|
+
new V(e.text)
|
|
22
|
+
]);
|
|
23
|
+
},
|
|
24
|
+
getParentNode(e) {
|
|
25
|
+
return e.parentNode;
|
|
26
|
+
},
|
|
27
|
+
getChildNodes(e) {
|
|
28
|
+
return Array.from(e.childNodes);
|
|
29
|
+
},
|
|
30
|
+
isNativeElementNode(e) {
|
|
31
|
+
return e instanceof Element;
|
|
32
|
+
},
|
|
33
|
+
getChildByIndex(e, r) {
|
|
34
|
+
return e.childNodes[r];
|
|
35
|
+
},
|
|
36
|
+
getAndUpdateSlotRootNativeElement(e, r) {
|
|
37
|
+
const t = e.attrs.get("ref"), n = m((o) => (r(o), () => {
|
|
38
|
+
r(null);
|
|
39
|
+
}));
|
|
40
|
+
t instanceof C ? e.attrs.set("ref", [t, n]) : Array.isArray(t) ? t.push(n) : e.attrs.set("ref", n);
|
|
41
|
+
},
|
|
42
|
+
componentRender: (e) => {
|
|
43
|
+
const r = this.components[e.name] || this.components["*"];
|
|
44
|
+
if (r) {
|
|
45
|
+
let t = this.componentRefs.get(e);
|
|
46
|
+
return t || (t = m((n) => (this.componentRootElementCaches.set(e, n), () => {
|
|
47
|
+
this.componentRootElementCaches.get(e) === n && this.componentRootElementCaches.remove(e);
|
|
48
|
+
})), this.componentRefs.set(e, t)), f(r, {
|
|
49
|
+
component: e,
|
|
50
|
+
rootRef: t
|
|
51
|
+
}, e.id);
|
|
52
|
+
}
|
|
53
|
+
throw h(`cannot found view component \`${e.name}\`!`);
|
|
54
|
+
},
|
|
55
|
+
vElementToViewElement(e, r) {
|
|
56
|
+
let t;
|
|
57
|
+
const n = Array.from(e.attrs).reduce((o, s) => {
|
|
58
|
+
const l = s[0];
|
|
59
|
+
return l === "key" ? (t = s[1], o) : (o[l] = s[1], o);
|
|
60
|
+
}, {});
|
|
61
|
+
return e.classes.size && (n.class = Array.from(e.classes).join(" ")), e.styles && (n.style = Array.from(e.styles).reduce((o, s) => (o[s[0]] = s[1], o), {})), r.length && (n.children = r), f(e.tagName, n, t);
|
|
62
|
+
}
|
|
63
|
+
}, a);
|
|
64
|
+
let i = !0;
|
|
65
|
+
Object.entries(c).forEach(([e, r]) => {
|
|
66
|
+
this.components[e] = (t) => {
|
|
67
|
+
const n = x(), o = t.component, s = A(
|
|
68
|
+
o.changeMarker.onChange,
|
|
69
|
+
o.changeMarker.onForceChange
|
|
70
|
+
).subscribe(() => {
|
|
71
|
+
o.changeMarker.dirty && n.markAsDirtied();
|
|
72
|
+
});
|
|
73
|
+
return E(() => {
|
|
74
|
+
s.unsubscribe();
|
|
75
|
+
}), i && (p(() => {
|
|
76
|
+
this.onViewUpdated.next();
|
|
77
|
+
}), i = !1), p(() => {
|
|
78
|
+
if (o.changeMarker.rendered(), !this.componentRootElementCaches.get(o))
|
|
79
|
+
throw h(`Component \`${o.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
|
|
80
|
+
}), r(t);
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
render(c, a) {
|
|
85
|
+
const i = new g(a, [{
|
|
86
|
+
provide: y,
|
|
87
|
+
useValue: this
|
|
88
|
+
}, {
|
|
89
|
+
provide: u,
|
|
90
|
+
useValue: this
|
|
91
|
+
}, {
|
|
92
|
+
provide: d,
|
|
93
|
+
useValue: this
|
|
94
|
+
}]);
|
|
95
|
+
return super.render(c, i);
|
|
96
|
+
}
|
|
97
|
+
copy() {
|
|
98
|
+
document.execCommand("copy");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class I extends k {
|
|
102
|
+
render(c, a) {
|
|
103
|
+
const i = new g(a, [{
|
|
104
|
+
provide: y,
|
|
105
|
+
useValue: this
|
|
106
|
+
}, {
|
|
107
|
+
provide: u,
|
|
108
|
+
useValue: this
|
|
109
|
+
}, {
|
|
110
|
+
provide: d,
|
|
111
|
+
useValue: this
|
|
112
|
+
}]);
|
|
113
|
+
return super.render(c, i);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
d as ViewflyAdapter,
|
|
118
|
+
I as ViewflyVDomAdapter
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/viewfly-adapter.ts","../src/viewfly-vdom-adapter.ts"],"sourcesContent":["import { Component, CompositionState, makeError, VElement, ViewMount, VTextNode, merge, Adapter } from '@textbus/core'\nimport {\n ComponentSetup,\n createDynamicRef,\n DynamicRef,\n getCurrentInstance, Injector,\n jsx,\n JSXNode, onUnmounted,\n onUpdated, ReflectiveInjector,\n ViewFlyNode,\n} from '@viewfly/core'\nimport { DomAdapter } from '@textbus/platform-browser'\n\nconst adapterError = makeError('ViewflyDOMRenderer')\n\nexport interface ViewComponentProps<T extends Component> {\n component: T\n rootRef: DynamicRef<Element>\n}\n\nexport interface ViewflyAdapterComponents {\n [key: string]: ComponentSetup<ViewComponentProps<any>>\n}\n\nexport class ViewflyAdapter extends DomAdapter<ViewFlyNode, ViewFlyNode> {\n private components: ViewflyAdapterComponents = {}\n\n private componentRefs = new WeakMap<Component, DynamicRef<Element>>()\n\n constructor(components: ViewflyAdapterComponents,\n mount: ViewMount<ViewFlyNode, Element>\n ) {\n super({\n createCompositionNode(compositionState: CompositionState,\n updateNativeCompositionNode: (nativeNode: (Element | null)) => void): VElement {\n const ref = createDynamicRef<Element>(node => {\n updateNativeCompositionNode(node)\n return () => {\n updateNativeCompositionNode(null)\n }\n })\n return new VElement('span', {\n style: {\n textDecoration: 'underline'\n },\n ref\n }, [\n new VTextNode(compositionState.text)\n ])\n },\n getParentNode(node: Element | Text): Element | null {\n return (node as Node).parentNode as Element\n },\n getChildNodes(parentElement: Element): Array<Element | Text> {\n return Array.from(parentElement.childNodes) as Element[]\n },\n isNativeElementNode(node: Element | Text): node is Element {\n return node instanceof Element\n },\n getChildByIndex(parentElement, index) {\n return parentElement.childNodes[index] as Element\n },\n getAndUpdateSlotRootNativeElement(vEle: VElement, update: (nativeElement: (Element | null)) => void) {\n const currentRef = vEle.attrs.get('ref')\n const ref = createDynamicRef<Element>(nativeNode => {\n update(nativeNode)\n return () => {\n update(null)\n }\n })\n if (currentRef instanceof DynamicRef) {\n vEle.attrs.set('ref', [currentRef, ref])\n } else if (Array.isArray(currentRef)) {\n currentRef.push(ref)\n } else {\n vEle.attrs.set('ref', ref)\n }\n },\n componentRender: (component: Component<any>): ViewFlyNode => {\n const comp = this.components[component.name] || this.components['*']\n if (comp) {\n let ref = this.componentRefs.get(component)\n if (!ref) {\n ref = createDynamicRef<Element>(rootNode => {\n this.componentRootElementCaches.set(component, rootNode)\n return () => {\n // 当组件移动层级位置到原位置之前并重新渲染后,由于时序的原因,再删除缓存会导致组件找不到对应视图节点\n if (this.componentRootElementCaches.get(component) === rootNode) {\n this.componentRootElementCaches.remove(component)\n }\n }\n })\n this.componentRefs.set(component, ref)\n }\n return jsx(comp, {\n component,\n rootRef: ref\n }, component.id)\n }\n throw adapterError(`cannot found view component \\`${component.name}\\`!`)\n },\n vElementToViewElement(vNode: VElement, children: Array<JSXNode>): ViewFlyNode {\n let key: any\n const props = Array.from(vNode.attrs).reduce((a, b) => {\n const propName = b[0]\n if (propName === 'key') {\n key = b[1]\n return a\n }\n a[propName] = b[1]\n return a\n }, {} as Record<string, any>)\n if (vNode.classes.size) {\n props.class = Array.from(vNode.classes).join(' ')\n }\n if (vNode.styles) {\n props.style = Array.from(vNode.styles).reduce((a, b) => {\n a[b[0]] = b[1]\n return a\n }, {} as Record<string, any>)\n }\n if (children.length) {\n props.children = children\n }\n return jsx(vNode.tagName, props, key)\n }\n }, mount)\n\n let isRoot = true\n Object.entries(components).forEach(([key, viewFlyComponent]) => {\n this.components[key] = (props: ViewComponentProps<Component>) => {\n const comp = getCurrentInstance()\n const textbusComponent = props.component\n const subscription = merge(textbusComponent.changeMarker.onChange,\n textbusComponent.changeMarker.onForceChange).subscribe(() => {\n if (textbusComponent.changeMarker.dirty) {\n comp.markAsDirtied()\n }\n })\n onUnmounted(() => {\n subscription.unsubscribe()\n })\n if (isRoot) {\n onUpdated(() => {\n this.onViewUpdated.next()\n })\n isRoot = false\n }\n onUpdated(() => {\n textbusComponent.changeMarker.rendered()\n if (!this.componentRootElementCaches.get(textbusComponent)) {\n // eslint-disable-next-line max-len\n throw adapterError(`Component \\`${textbusComponent.name}\\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`)\n }\n })\n return viewFlyComponent(props)\n }\n })\n }\n\n override render(rootComponent: Component, injector: Injector): void | (() => void) {\n const childInjector = new ReflectiveInjector(injector, [{\n provide: Adapter,\n useValue: this\n }, {\n provide: DomAdapter,\n useValue: this\n }, {\n provide: ViewflyAdapter,\n useValue: this\n }])\n return super.render(rootComponent, childInjector)\n }\n\n override copy() {\n document.execCommand('copy')\n }\n}\n","import { NodeViewAdapter } from '@textbus/platform-node'\nimport { Injector, ReflectiveInjector } from '@viewfly/core'\nimport { Adapter, Component } from '@textbus/core'\nimport { DomAdapter } from '@textbus/platform-browser'\nimport { ViewflyAdapter } from './viewfly-adapter'\n\nexport class ViewflyVDomAdapter extends NodeViewAdapter {\n override render(rootComponent: Component, injector: Injector): void | (() => void) {\n const childInjector = new ReflectiveInjector(injector, [{\n provide: Adapter,\n useValue: this\n }, {\n provide: DomAdapter,\n useValue: this\n }, {\n provide: ViewflyAdapter,\n useValue: this\n }])\n return super.render(rootComponent, childInjector)\n }\n}\n"],"names":["adapterError","makeError","ViewflyAdapter","DomAdapter","components","mount","compositionState","updateNativeCompositionNode","ref","createDynamicRef","node","VElement","VTextNode","parentElement","index","vEle","update","currentRef","nativeNode","DynamicRef","component","comp","rootNode","jsx","vNode","children","key","props","a","b","propName","isRoot","viewFlyComponent","getCurrentInstance","textbusComponent","subscription","merge","onUnmounted","onUpdated","rootComponent","injector","childInjector","ReflectiveInjector","Adapter","ViewflyVDomAdapter","NodeViewAdapter"],"mappings":";;;;AAaA,MAAMA,IAAeC,EAAU,oBAAoB;AAW5C,MAAMC,UAAuBC,EAAqC;AAAA,EAC/D,aAAuC,CAAA;AAAA,EAEvC,oCAAoB,QAAA;AAAA,EAE5B,YAAYC,GACAC,GACV;AACA,UAAM;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C7D,UAAIA,EAAiB,aAAa,SAChCb,EAAK,cAAA;AAAA,QAET,CAAC;AACD,eAAAgB,EAAY,MAAM;AAChB,UAAAF,EAAa,YAAA;AAAA,QACf,CAAC,GACGJ,MACFO,EAAU,MAAM;AACd,eAAK,cAAc,KAAA;AAAA,QACrB,CAAC,GACDP,IAAS,KAEXO,EAAU,MAAM;AAEd,cADAJ,EAAiB,aAAa,SAAA,GAC1B,CAAC,KAAK,2BAA2B,IAAIA,CAAgB;AAEvD,kBAAMlC,EAAa,eAAekC,EAAiB,IAAI,mGAAmG;AAAA,QAE9J,CAAC,GACMF,EAAiBL,CAAK;AAAA,MAC/B;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAES,OAAOY,GAA0BC,GAAyC;AACjF,UAAMC,IAAgB,IAAIC,EAAmBF,GAAU,CAAC;AAAA,MACtD,SAASG;AAAA,MACT,UAAU;AAAA,IAAA,GACT;AAAA,MACD,SAASxC;AAAA,MACT,UAAU;AAAA,IAAA,GACT;AAAA,MACD,SAASD;AAAA,MACT,UAAU;AAAA,IAAA,CACX,CAAC;AACF,WAAO,MAAM,OAAOqC,GAAeE,CAAa;AAAA,EAClD;AAAA,EAES,OAAO;AACd,aAAS,YAAY,MAAM;AAAA,EAC7B;AACF;AC3KO,MAAMG,UAA2BC,EAAgB;AAAA,EAC7C,OAAON,GAA0BC,GAAyC;AACjF,UAAMC,IAAgB,IAAIC,EAAmBF,GAAU,CAAC;AAAA,MACtD,SAASG;AAAA,MACT,UAAU;AAAA,IAAA,GACT;AAAA,MACD,SAASxC;AAAA,MACT,UAAU;AAAA,IAAA,GACT;AAAA,MACD,SAASD;AAAA,MACT,UAAU;AAAA,IAAA,CACX,CAAC;AACF,WAAO,MAAM,OAAOqC,GAAeE,CAAa;AAAA,EAClD;AACF;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@textbus/core"),s=require("@viewfly/core"),m=require("@textbus/platform-browser"),h=require("@textbus/platform-node"),p=a.makeError("ViewflyDOMRenderer");class l extends m.DomAdapter{components={};componentRefs=new WeakMap;constructor(d,u){super({createCompositionNode(e,r){const t=s.createDynamicRef(n=>(r(n),()=>{r(null)}));return new a.VElement("span",{style:{textDecoration:"underline"},ref:t},[new a.VTextNode(e.text)])},getParentNode(e){return e.parentNode},getChildNodes(e){return Array.from(e.childNodes)},isNativeElementNode(e){return e instanceof Element},getChildByIndex(e,r){return e.childNodes[r]},getAndUpdateSlotRootNativeElement(e,r){const t=e.attrs.get("ref"),n=s.createDynamicRef(o=>(r(o),()=>{r(null)}));t instanceof s.DynamicRef?e.attrs.set("ref",[t,n]):Array.isArray(t)?t.push(n):e.attrs.set("ref",n)},componentRender:e=>{const r=this.components[e.name]||this.components["*"];if(r){let t=this.componentRefs.get(e);return t||(t=s.createDynamicRef(n=>(this.componentRootElementCaches.set(e,n),()=>{this.componentRootElementCaches.get(e)===n&&this.componentRootElementCaches.remove(e)})),this.componentRefs.set(e,t)),s.jsx(r,{component:e,rootRef:t},e.id)}throw p(`cannot found view component \`${e.name}\`!`)},vElementToViewElement(e,r){let t;const n=Array.from(e.attrs).reduce((o,i)=>{const f=i[0];return f==="key"?(t=i[1],o):(o[f]=i[1],o)},{});return e.classes.size&&(n.class=Array.from(e.classes).join(" ")),e.styles&&(n.style=Array.from(e.styles).reduce((o,i)=>(o[i[0]]=i[1],o),{})),r.length&&(n.children=r),s.jsx(e.tagName,n,t)}},u);let c=!0;Object.entries(d).forEach(([e,r])=>{this.components[e]=t=>{const n=s.getCurrentInstance(),o=t.component,i=a.merge(o.changeMarker.onChange,o.changeMarker.onForceChange).subscribe(()=>{o.changeMarker.dirty&&n.markAsDirtied()});return s.onUnmounted(()=>{i.unsubscribe()}),c&&(s.onUpdated(()=>{this.onViewUpdated.next()}),c=!1),s.onUpdated(()=>{if(o.changeMarker.rendered(),!this.componentRootElementCaches.get(o))throw p(`Component \`${o.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`)}),r(t)}})}render(d,u){const c=new s.ReflectiveInjector(u,[{provide:a.Adapter,useValue:this},{provide:m.DomAdapter,useValue:this},{provide:l,useValue:this}]);return super.render(d,c)}copy(){document.execCommand("copy")}}class y extends h.NodeViewAdapter{render(d,u){const c=new s.ReflectiveInjector(u,[{provide:a.Adapter,useValue:this},{provide:m.DomAdapter,useValue:this},{provide:l,useValue:this}]);return super.render(d,c)}}exports.ViewflyAdapter=l;exports.ViewflyVDomAdapter=y;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/viewfly-adapter.ts","../src/viewfly-vdom-adapter.ts"],"sourcesContent":["import { Component, CompositionState, makeError, VElement, ViewMount, VTextNode, merge, Adapter } from '@textbus/core'\nimport {\n ComponentSetup,\n createDynamicRef,\n DynamicRef,\n getCurrentInstance, Injector,\n jsx,\n JSXNode, onUnmounted,\n onUpdated, ReflectiveInjector,\n ViewFlyNode,\n} from '@viewfly/core'\nimport { DomAdapter } from '@textbus/platform-browser'\n\nconst adapterError = makeError('ViewflyDOMRenderer')\n\nexport interface ViewComponentProps<T extends Component> {\n component: T\n rootRef: DynamicRef<Element>\n}\n\nexport interface ViewflyAdapterComponents {\n [key: string]: ComponentSetup<ViewComponentProps<any>>\n}\n\nexport class ViewflyAdapter extends DomAdapter<ViewFlyNode, ViewFlyNode> {\n private components: ViewflyAdapterComponents = {}\n\n private componentRefs = new WeakMap<Component, DynamicRef<Element>>()\n\n constructor(components: ViewflyAdapterComponents,\n mount: ViewMount<ViewFlyNode, Element>\n ) {\n super({\n createCompositionNode(compositionState: CompositionState,\n updateNativeCompositionNode: (nativeNode: (Element | null)) => void): VElement {\n const ref = createDynamicRef<Element>(node => {\n updateNativeCompositionNode(node)\n return () => {\n updateNativeCompositionNode(null)\n }\n })\n return new VElement('span', {\n style: {\n textDecoration: 'underline'\n },\n ref\n }, [\n new VTextNode(compositionState.text)\n ])\n },\n getParentNode(node: Element | Text): Element | null {\n return (node as Node).parentNode as Element\n },\n getChildNodes(parentElement: Element): Array<Element | Text> {\n return Array.from(parentElement.childNodes) as Element[]\n },\n isNativeElementNode(node: Element | Text): node is Element {\n return node instanceof Element\n },\n getChildByIndex(parentElement, index) {\n return parentElement.childNodes[index] as Element\n },\n getAndUpdateSlotRootNativeElement(vEle: VElement, update: (nativeElement: (Element | null)) => void) {\n const currentRef = vEle.attrs.get('ref')\n const ref = createDynamicRef<Element>(nativeNode => {\n update(nativeNode)\n return () => {\n update(null)\n }\n })\n if (currentRef instanceof DynamicRef) {\n vEle.attrs.set('ref', [currentRef, ref])\n } else if (Array.isArray(currentRef)) {\n currentRef.push(ref)\n } else {\n vEle.attrs.set('ref', ref)\n }\n },\n componentRender: (component: Component<any>): ViewFlyNode => {\n const comp = this.components[component.name] || this.components['*']\n if (comp) {\n let ref = this.componentRefs.get(component)\n if (!ref) {\n ref = createDynamicRef<Element>(rootNode => {\n this.componentRootElementCaches.set(component, rootNode)\n return () => {\n // 当组件移动层级位置到原位置之前并重新渲染后,由于时序的原因,再删除缓存会导致组件找不到对应视图节点\n if (this.componentRootElementCaches.get(component) === rootNode) {\n this.componentRootElementCaches.remove(component)\n }\n }\n })\n this.componentRefs.set(component, ref)\n }\n return jsx(comp, {\n component,\n rootRef: ref\n }, component.id)\n }\n throw adapterError(`cannot found view component \\`${component.name}\\`!`)\n },\n vElementToViewElement(vNode: VElement, children: Array<JSXNode>): ViewFlyNode {\n let key: any\n const props = Array.from(vNode.attrs).reduce((a, b) => {\n const propName = b[0]\n if (propName === 'key') {\n key = b[1]\n return a\n }\n a[propName] = b[1]\n return a\n }, {} as Record<string, any>)\n if (vNode.classes.size) {\n props.class = Array.from(vNode.classes).join(' ')\n }\n if (vNode.styles) {\n props.style = Array.from(vNode.styles).reduce((a, b) => {\n a[b[0]] = b[1]\n return a\n }, {} as Record<string, any>)\n }\n if (children.length) {\n props.children = children\n }\n return jsx(vNode.tagName, props, key)\n }\n }, mount)\n\n let isRoot = true\n Object.entries(components).forEach(([key, viewFlyComponent]) => {\n this.components[key] = (props: ViewComponentProps<Component>) => {\n const comp = getCurrentInstance()\n const textbusComponent = props.component\n const subscription = merge(textbusComponent.changeMarker.onChange,\n textbusComponent.changeMarker.onForceChange).subscribe(() => {\n if (textbusComponent.changeMarker.dirty) {\n comp.markAsDirtied()\n }\n })\n onUnmounted(() => {\n subscription.unsubscribe()\n })\n if (isRoot) {\n onUpdated(() => {\n this.onViewUpdated.next()\n })\n isRoot = false\n }\n onUpdated(() => {\n textbusComponent.changeMarker.rendered()\n if (!this.componentRootElementCaches.get(textbusComponent)) {\n // eslint-disable-next-line max-len\n throw adapterError(`Component \\`${textbusComponent.name}\\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`)\n }\n })\n return viewFlyComponent(props)\n }\n })\n }\n\n override render(rootComponent: Component, injector: Injector): void | (() => void) {\n const childInjector = new ReflectiveInjector(injector, [{\n provide: Adapter,\n useValue: this\n }, {\n provide: DomAdapter,\n useValue: this\n }, {\n provide: ViewflyAdapter,\n useValue: this\n }])\n return super.render(rootComponent, childInjector)\n }\n\n override copy() {\n document.execCommand('copy')\n }\n}\n","import { NodeViewAdapter } from '@textbus/platform-node'\nimport { Injector, ReflectiveInjector } from '@viewfly/core'\nimport { Adapter, Component } from '@textbus/core'\nimport { DomAdapter } from '@textbus/platform-browser'\nimport { ViewflyAdapter } from './viewfly-adapter'\n\nexport class ViewflyVDomAdapter extends NodeViewAdapter {\n override render(rootComponent: Component, injector: Injector): void | (() => void) {\n const childInjector = new ReflectiveInjector(injector, [{\n provide: Adapter,\n useValue: this\n }, {\n provide: DomAdapter,\n useValue: this\n }, {\n provide: ViewflyAdapter,\n useValue: this\n }])\n return super.render(rootComponent, childInjector)\n }\n}\n"],"names":["adapterError","makeError","ViewflyAdapter","DomAdapter","components","mount","compositionState","updateNativeCompositionNode","ref","createDynamicRef","node","VElement","VTextNode","parentElement","index","vEle","update","currentRef","nativeNode","DynamicRef","component","comp","rootNode","jsx","vNode","children","key","props","a","b","propName","isRoot","viewFlyComponent","getCurrentInstance","textbusComponent","subscription","merge","onUnmounted","onUpdated","rootComponent","injector","childInjector","ReflectiveInjector","Adapter","ViewflyVDomAdapter","NodeViewAdapter"],"mappings":"uNAaMA,EAAeC,EAAAA,UAAU,oBAAoB,EAW5C,MAAMC,UAAuBC,EAAAA,UAAqC,CAC/D,WAAuC,CAAA,EAEvC,kBAAoB,QAE5B,YAAYC,EACAC,EACV,CACA,MAAM,CACJ,sBAAsBC,EACAC,EAA+E,CACnG,MAAMC,EAAMC,mBAA0BC,IACpCH,EAA4BG,CAAI,EACzB,IAAM,CACXH,EAA4B,IAAI,CAClC,EACD,EACD,OAAO,IAAII,EAAAA,SAAS,OAAQ,CAC1B,MAAO,CACL,eAAgB,WAAA,EAElB,IAAAH,CAAA,EACC,CACD,IAAII,EAAAA,UAAUN,EAAiB,IAAI,CAAA,CACpC,CACH,EACA,cAAcI,EAAsC,CAClD,OAAQA,EAAc,UACxB,EACA,cAAcG,EAA+C,CAC3D,OAAO,MAAM,KAAKA,EAAc,UAAU,CAC5C,EACA,oBAAoBH,EAAuC,CACzD,OAAOA,aAAgB,OACzB,EACA,gBAAgBG,EAAeC,EAAO,CACpC,OAAOD,EAAc,WAAWC,CAAK,CACvC,EACA,kCAAkCC,EAAgBC,EAAmD,CACnG,MAAMC,EAAaF,EAAK,MAAM,IAAI,KAAK,EACjCP,EAAMC,mBAA0BS,IACpCF,EAAOE,CAAU,EACV,IAAM,CACXF,EAAO,IAAI,CACb,EACD,EACGC,aAAsBE,EAAAA,WACxBJ,EAAK,MAAM,IAAI,MAAO,CAACE,EAAYT,CAAG,CAAC,EAC9B,MAAM,QAAQS,CAAU,EACjCA,EAAW,KAAKT,CAAG,EAEnBO,EAAK,MAAM,IAAI,MAAOP,CAAG,CAE7B,EACA,gBAAkBY,GAA2C,CAC3D,MAAMC,EAAO,K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GAAyC,CAC/D,MAAMN,EAAOY,EAAAA,mBAAA,EACPC,EAAmBP,EAAM,UACzBQ,EAAeC,EAAAA,MAAMF,EAAiB,aAAa,SACvDA,EAAiB,aAAa,aAAA,EAAe,UAAU,IAAM,CACzDA,EAAiB,aAAa,OAChCb,EAAK,cAAA,CAET,CAAC,EACDgB,OAAAA,EAAAA,YAAY,IAAM,CAChBF,EAAa,YAAA,CACf,CAAC,EACGJ,IACFO,EAAAA,UAAU,IAAM,CACd,KAAK,cAAc,KAAA,CACrB,CAAC,EACDP,EAAS,IAEXO,EAAAA,UAAU,IAAM,CAEd,GADAJ,EAAiB,aAAa,SAAA,EAC1B,CAAC,KAAK,2BAA2B,IAAIA,CAAgB,EAEvD,MAAMlC,EAAa,eAAekC,EAAiB,IAAI,mGAAmG,CAE9J,CAAC,EACMF,EAAiBL,CAAK,CAC/B,CACF,CAAC,CACH,CAES,OAAOY,EAA0BC,EAAyC,CACjF,MAAMC,EAAgB,IAAIC,qBAAmBF,EAAU,CAAC,CACtD,QAASG,EAAAA,QACT,SAAU,IAAA,EACT,CACD,QAASxC,EAAAA,WACT,SAAU,IAAA,EACT,CACD,QAASD,EACT,SAAU,IAAA,CACX,CAAC,EACF,OAAO,MAAM,OAAOqC,EAAeE,CAAa,CAClD,CAES,MAAO,CACd,SAAS,YAAY,MAAM,CAC7B,CACF,CC3KO,MAAMG,UAA2BC,EAAAA,eAAgB,CAC7C,OAAON,EAA0BC,EAAyC,CACjF,MAAMC,EAAgB,IAAIC,qBAAmBF,EAAU,CAAC,CACtD,QAASG,EAAAA,QACT,SAAU,IAAA,EACT,CACD,QAASxC,EAAAA,WACT,SAAU,IAAA,EACT,CACD,QAASD,EACT,SAAU,IAAA,CACX,CAAC,EACF,OAAO,MAAM,OAAOqC,EAAeE,CAAa,CAClD,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Component, ViewMount } from '
|
|
1
|
+
import { Component, ViewMount } from '../../core/src/index.ts';
|
|
2
2
|
import { ComponentSetup, DynamicRef, Injector, ViewFlyNode } from '@viewfly/core';
|
|
3
|
-
import { DomAdapter } from '
|
|
3
|
+
import { DomAdapter } from '../../platform-browser/src/index.ts';
|
|
4
4
|
export interface ViewComponentProps<T extends Component> {
|
|
5
5
|
component: T;
|
|
6
6
|
rootRef: DynamicRef<Element>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NodeViewAdapter } from '
|
|
1
|
+
import { NodeViewAdapter } from '../../platform-node/src/index.ts';
|
|
2
2
|
import { Injector } from '@viewfly/core';
|
|
3
|
-
import { Component } from '
|
|
3
|
+
import { Component } from '../../core/src/index.ts';
|
|
4
4
|
export declare class ViewflyVDomAdapter extends NodeViewAdapter {
|
|
5
5
|
render(rootComponent: Component, injector: Injector): void | (() => void);
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textbus/adapter-viewfly",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
14
21
|
},
|
|
15
|
-
"license": "
|
|
22
|
+
"license": "MIT",
|
|
16
23
|
"keywords": [
|
|
17
24
|
"textbus",
|
|
18
25
|
"富文本编辑器",
|
|
@@ -26,17 +33,14 @@
|
|
|
26
33
|
],
|
|
27
34
|
"dependencies": {
|
|
28
35
|
"@tanbo/stream": "^1.2.7",
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@textbus/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
36
|
+
"@viewfly/core": "^2.2.0 || >=3.0.0-alpha.0 <4",
|
|
37
|
+
"@viewfly/platform-browser": "^2.2.0 || >=3.0.0-alpha.0 <4",
|
|
38
|
+
"@textbus/core": "^5.2.0",
|
|
39
|
+
"@textbus/platform-browser": "^5.2.0",
|
|
40
|
+
"@textbus/platform-node": "^5.2.0"
|
|
34
41
|
},
|
|
35
42
|
"devDependencies": {
|
|
36
|
-
"@rollup/plugin-commonjs": "^28.0.2",
|
|
37
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
38
43
|
"rimraf": "^3.0.2",
|
|
39
|
-
"rollup": "4.22.4",
|
|
40
44
|
"tslib": "^2.4.1"
|
|
41
45
|
},
|
|
42
46
|
"author": {
|
|
@@ -50,5 +54,10 @@
|
|
|
50
54
|
"bugs": {
|
|
51
55
|
"url": "https://github.com/textbus/textbus.git/issues"
|
|
52
56
|
},
|
|
53
|
-
"
|
|
54
|
-
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "cross-env env=test jest",
|
|
59
|
+
"test-c": "cross-env env=test jest --coverage",
|
|
60
|
+
"build:lib": "rimraf dist && vite build",
|
|
61
|
+
"publish:lib": "npm run build:lib && npm publish --access=public"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/bundles/index.esm.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { makeError, VElement, VTextNode, merge, Adapter } from '@textbus/core';
|
|
2
|
-
import { createDynamicRef, DynamicRef, jsx, getCurrentInstance, onUnmounted, onUpdated, ReflectiveInjector } from '@viewfly/core';
|
|
3
|
-
import { DomAdapter } from '@textbus/platform-browser';
|
|
4
|
-
import { NodeViewAdapter } from '@textbus/platform-node';
|
|
5
|
-
|
|
6
|
-
const adapterError = makeError('ViewflyDOMRenderer');
|
|
7
|
-
class ViewflyAdapter extends DomAdapter {
|
|
8
|
-
constructor(components, mount) {
|
|
9
|
-
super({
|
|
10
|
-
createCompositionNode(compositionState, updateNativeCompositionNode) {
|
|
11
|
-
const ref = createDynamicRef(node => {
|
|
12
|
-
updateNativeCompositionNode(node);
|
|
13
|
-
return () => {
|
|
14
|
-
updateNativeCompositionNode(null);
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
return new VElement('span', {
|
|
18
|
-
style: {
|
|
19
|
-
textDecoration: 'underline'
|
|
20
|
-
},
|
|
21
|
-
ref
|
|
22
|
-
}, [
|
|
23
|
-
new VTextNode(compositionState.text)
|
|
24
|
-
]);
|
|
25
|
-
},
|
|
26
|
-
getParentNode(node) {
|
|
27
|
-
return node.parentNode;
|
|
28
|
-
},
|
|
29
|
-
getChildNodes(parentElement) {
|
|
30
|
-
return Array.from(parentElement.childNodes);
|
|
31
|
-
},
|
|
32
|
-
isNativeElementNode(node) {
|
|
33
|
-
return node instanceof Element;
|
|
34
|
-
},
|
|
35
|
-
getChildByIndex(parentElement, index) {
|
|
36
|
-
return parentElement.childNodes[index];
|
|
37
|
-
},
|
|
38
|
-
getAndUpdateSlotRootNativeElement(vEle, update) {
|
|
39
|
-
const currentRef = vEle.attrs.get('ref');
|
|
40
|
-
const ref = createDynamicRef(nativeNode => {
|
|
41
|
-
update(nativeNode);
|
|
42
|
-
return () => {
|
|
43
|
-
update(null);
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
if (currentRef instanceof DynamicRef) {
|
|
47
|
-
vEle.attrs.set('ref', [currentRef, ref]);
|
|
48
|
-
}
|
|
49
|
-
else if (Array.isArray(currentRef)) {
|
|
50
|
-
currentRef.push(ref);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
vEle.attrs.set('ref', ref);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
componentRender: (component) => {
|
|
57
|
-
const comp = this.components[component.name] || this.components['*'];
|
|
58
|
-
if (comp) {
|
|
59
|
-
let ref = this.componentRefs.get(component);
|
|
60
|
-
if (!ref) {
|
|
61
|
-
ref = createDynamicRef(rootNode => {
|
|
62
|
-
this.componentRootElementCaches.set(component, rootNode);
|
|
63
|
-
return () => {
|
|
64
|
-
// 当组件移动层级位置到原位置之前并重新渲染后,由于时序的原因,再删除缓存会导致组件找不到对应视图节点
|
|
65
|
-
if (this.componentRootElementCaches.get(component) === rootNode) {
|
|
66
|
-
this.componentRootElementCaches.remove(component);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
this.componentRefs.set(component, ref);
|
|
71
|
-
}
|
|
72
|
-
return jsx(comp, {
|
|
73
|
-
component,
|
|
74
|
-
rootRef: ref
|
|
75
|
-
}, component.id);
|
|
76
|
-
}
|
|
77
|
-
throw adapterError(`cannot found view component \`${component.name}\`!`);
|
|
78
|
-
},
|
|
79
|
-
vElementToViewElement(vNode, children) {
|
|
80
|
-
let key;
|
|
81
|
-
const props = Array.from(vNode.attrs).reduce((a, b) => {
|
|
82
|
-
const propName = b[0];
|
|
83
|
-
if (propName === 'key') {
|
|
84
|
-
key = b[1];
|
|
85
|
-
return a;
|
|
86
|
-
}
|
|
87
|
-
a[propName] = b[1];
|
|
88
|
-
return a;
|
|
89
|
-
}, {});
|
|
90
|
-
if (vNode.classes.size) {
|
|
91
|
-
props.class = Array.from(vNode.classes).join(' ');
|
|
92
|
-
}
|
|
93
|
-
if (vNode.styles) {
|
|
94
|
-
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
|
95
|
-
a[b[0]] = b[1];
|
|
96
|
-
return a;
|
|
97
|
-
}, {});
|
|
98
|
-
}
|
|
99
|
-
if (children.length) {
|
|
100
|
-
props.children = children;
|
|
101
|
-
}
|
|
102
|
-
return jsx(vNode.tagName, props, key);
|
|
103
|
-
}
|
|
104
|
-
}, mount);
|
|
105
|
-
Object.defineProperty(this, "components", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: {}
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(this, "componentRefs", {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true,
|
|
115
|
-
value: new WeakMap()
|
|
116
|
-
});
|
|
117
|
-
let isRoot = true;
|
|
118
|
-
Object.entries(components).forEach(([key, viewFlyComponent]) => {
|
|
119
|
-
this.components[key] = (props) => {
|
|
120
|
-
const comp = getCurrentInstance();
|
|
121
|
-
const textbusComponent = props.component;
|
|
122
|
-
const subscription = merge(textbusComponent.changeMarker.onChange, textbusComponent.changeMarker.onForceChange).subscribe(() => {
|
|
123
|
-
if (textbusComponent.changeMarker.dirty) {
|
|
124
|
-
comp.markAsDirtied();
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
onUnmounted(() => {
|
|
128
|
-
subscription.unsubscribe();
|
|
129
|
-
});
|
|
130
|
-
if (isRoot) {
|
|
131
|
-
onUpdated(() => {
|
|
132
|
-
this.onViewUpdated.next();
|
|
133
|
-
});
|
|
134
|
-
isRoot = false;
|
|
135
|
-
}
|
|
136
|
-
onUpdated(() => {
|
|
137
|
-
textbusComponent.changeMarker.rendered();
|
|
138
|
-
if (!this.componentRootElementCaches.get(textbusComponent)) {
|
|
139
|
-
// eslint-disable-next-line max-len
|
|
140
|
-
throw adapterError(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return viewFlyComponent(props);
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
render(rootComponent, injector) {
|
|
148
|
-
const childInjector = new ReflectiveInjector(injector, [{
|
|
149
|
-
provide: Adapter,
|
|
150
|
-
useValue: this
|
|
151
|
-
}, {
|
|
152
|
-
provide: DomAdapter,
|
|
153
|
-
useValue: this
|
|
154
|
-
}, {
|
|
155
|
-
provide: ViewflyAdapter,
|
|
156
|
-
useValue: this
|
|
157
|
-
}]);
|
|
158
|
-
return super.render(rootComponent, childInjector);
|
|
159
|
-
}
|
|
160
|
-
copy() {
|
|
161
|
-
document.execCommand('copy');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
class ViewflyVDomAdapter extends NodeViewAdapter {
|
|
166
|
-
render(rootComponent, injector) {
|
|
167
|
-
const childInjector = new ReflectiveInjector(injector, [{
|
|
168
|
-
provide: Adapter,
|
|
169
|
-
useValue: this
|
|
170
|
-
}, {
|
|
171
|
-
provide: DomAdapter,
|
|
172
|
-
useValue: this
|
|
173
|
-
}, {
|
|
174
|
-
provide: ViewflyAdapter,
|
|
175
|
-
useValue: this
|
|
176
|
-
}]);
|
|
177
|
-
return super.render(rootComponent, childInjector);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export { ViewflyAdapter, ViewflyVDomAdapter };
|
package/bundles/index.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@textbus/core');
|
|
4
|
-
var core$1 = require('@viewfly/core');
|
|
5
|
-
var platformBrowser = require('@textbus/platform-browser');
|
|
6
|
-
var platformNode = require('@textbus/platform-node');
|
|
7
|
-
|
|
8
|
-
const adapterError = core.makeError('ViewflyDOMRenderer');
|
|
9
|
-
class ViewflyAdapter extends platformBrowser.DomAdapter {
|
|
10
|
-
constructor(components, mount) {
|
|
11
|
-
super({
|
|
12
|
-
createCompositionNode(compositionState, updateNativeCompositionNode) {
|
|
13
|
-
const ref = core$1.createDynamicRef(node => {
|
|
14
|
-
updateNativeCompositionNode(node);
|
|
15
|
-
return () => {
|
|
16
|
-
updateNativeCompositionNode(null);
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return new core.VElement('span', {
|
|
20
|
-
style: {
|
|
21
|
-
textDecoration: 'underline'
|
|
22
|
-
},
|
|
23
|
-
ref
|
|
24
|
-
}, [
|
|
25
|
-
new core.VTextNode(compositionState.text)
|
|
26
|
-
]);
|
|
27
|
-
},
|
|
28
|
-
getParentNode(node) {
|
|
29
|
-
return node.parentNode;
|
|
30
|
-
},
|
|
31
|
-
getChildNodes(parentElement) {
|
|
32
|
-
return Array.from(parentElement.childNodes);
|
|
33
|
-
},
|
|
34
|
-
isNativeElementNode(node) {
|
|
35
|
-
return node instanceof Element;
|
|
36
|
-
},
|
|
37
|
-
getChildByIndex(parentElement, index) {
|
|
38
|
-
return parentElement.childNodes[index];
|
|
39
|
-
},
|
|
40
|
-
getAndUpdateSlotRootNativeElement(vEle, update) {
|
|
41
|
-
const currentRef = vEle.attrs.get('ref');
|
|
42
|
-
const ref = core$1.createDynamicRef(nativeNode => {
|
|
43
|
-
update(nativeNode);
|
|
44
|
-
return () => {
|
|
45
|
-
update(null);
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
if (currentRef instanceof core$1.DynamicRef) {
|
|
49
|
-
vEle.attrs.set('ref', [currentRef, ref]);
|
|
50
|
-
}
|
|
51
|
-
else if (Array.isArray(currentRef)) {
|
|
52
|
-
currentRef.push(ref);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
vEle.attrs.set('ref', ref);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
componentRender: (component) => {
|
|
59
|
-
const comp = this.components[component.name] || this.components['*'];
|
|
60
|
-
if (comp) {
|
|
61
|
-
let ref = this.componentRefs.get(component);
|
|
62
|
-
if (!ref) {
|
|
63
|
-
ref = core$1.createDynamicRef(rootNode => {
|
|
64
|
-
this.componentRootElementCaches.set(component, rootNode);
|
|
65
|
-
return () => {
|
|
66
|
-
// 当组件移动层级位置到原位置之前并重新渲染后,由于时序的原因,再删除缓存会导致组件找不到对应视图节点
|
|
67
|
-
if (this.componentRootElementCaches.get(component) === rootNode) {
|
|
68
|
-
this.componentRootElementCaches.remove(component);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
this.componentRefs.set(component, ref);
|
|
73
|
-
}
|
|
74
|
-
return core$1.jsx(comp, {
|
|
75
|
-
component,
|
|
76
|
-
rootRef: ref
|
|
77
|
-
}, component.id);
|
|
78
|
-
}
|
|
79
|
-
throw adapterError(`cannot found view component \`${component.name}\`!`);
|
|
80
|
-
},
|
|
81
|
-
vElementToViewElement(vNode, children) {
|
|
82
|
-
let key;
|
|
83
|
-
const props = Array.from(vNode.attrs).reduce((a, b) => {
|
|
84
|
-
const propName = b[0];
|
|
85
|
-
if (propName === 'key') {
|
|
86
|
-
key = b[1];
|
|
87
|
-
return a;
|
|
88
|
-
}
|
|
89
|
-
a[propName] = b[1];
|
|
90
|
-
return a;
|
|
91
|
-
}, {});
|
|
92
|
-
if (vNode.classes.size) {
|
|
93
|
-
props.class = Array.from(vNode.classes).join(' ');
|
|
94
|
-
}
|
|
95
|
-
if (vNode.styles) {
|
|
96
|
-
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
|
97
|
-
a[b[0]] = b[1];
|
|
98
|
-
return a;
|
|
99
|
-
}, {});
|
|
100
|
-
}
|
|
101
|
-
if (children.length) {
|
|
102
|
-
props.children = children;
|
|
103
|
-
}
|
|
104
|
-
return core$1.jsx(vNode.tagName, props, key);
|
|
105
|
-
}
|
|
106
|
-
}, mount);
|
|
107
|
-
Object.defineProperty(this, "components", {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
configurable: true,
|
|
110
|
-
writable: true,
|
|
111
|
-
value: {}
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(this, "componentRefs", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
writable: true,
|
|
117
|
-
value: new WeakMap()
|
|
118
|
-
});
|
|
119
|
-
let isRoot = true;
|
|
120
|
-
Object.entries(components).forEach(([key, viewFlyComponent]) => {
|
|
121
|
-
this.components[key] = (props) => {
|
|
122
|
-
const comp = core$1.getCurrentInstance();
|
|
123
|
-
const textbusComponent = props.component;
|
|
124
|
-
const subscription = core.merge(textbusComponent.changeMarker.onChange, textbusComponent.changeMarker.onForceChange).subscribe(() => {
|
|
125
|
-
if (textbusComponent.changeMarker.dirty) {
|
|
126
|
-
comp.markAsDirtied();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
core$1.onUnmounted(() => {
|
|
130
|
-
subscription.unsubscribe();
|
|
131
|
-
});
|
|
132
|
-
if (isRoot) {
|
|
133
|
-
core$1.onUpdated(() => {
|
|
134
|
-
this.onViewUpdated.next();
|
|
135
|
-
});
|
|
136
|
-
isRoot = false;
|
|
137
|
-
}
|
|
138
|
-
core$1.onUpdated(() => {
|
|
139
|
-
textbusComponent.changeMarker.rendered();
|
|
140
|
-
if (!this.componentRootElementCaches.get(textbusComponent)) {
|
|
141
|
-
// eslint-disable-next-line max-len
|
|
142
|
-
throw adapterError(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
return viewFlyComponent(props);
|
|
146
|
-
};
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
render(rootComponent, injector) {
|
|
150
|
-
const childInjector = new core$1.ReflectiveInjector(injector, [{
|
|
151
|
-
provide: core.Adapter,
|
|
152
|
-
useValue: this
|
|
153
|
-
}, {
|
|
154
|
-
provide: platformBrowser.DomAdapter,
|
|
155
|
-
useValue: this
|
|
156
|
-
}, {
|
|
157
|
-
provide: ViewflyAdapter,
|
|
158
|
-
useValue: this
|
|
159
|
-
}]);
|
|
160
|
-
return super.render(rootComponent, childInjector);
|
|
161
|
-
}
|
|
162
|
-
copy() {
|
|
163
|
-
document.execCommand('copy');
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
class ViewflyVDomAdapter extends platformNode.NodeViewAdapter {
|
|
168
|
-
render(rootComponent, injector) {
|
|
169
|
-
const childInjector = new core$1.ReflectiveInjector(injector, [{
|
|
170
|
-
provide: core.Adapter,
|
|
171
|
-
useValue: this
|
|
172
|
-
}, {
|
|
173
|
-
provide: platformBrowser.DomAdapter,
|
|
174
|
-
useValue: this
|
|
175
|
-
}, {
|
|
176
|
-
provide: ViewflyAdapter,
|
|
177
|
-
useValue: this
|
|
178
|
-
}]);
|
|
179
|
-
return super.render(rootComponent, childInjector);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
exports.ViewflyAdapter = ViewflyAdapter;
|
|
184
|
-
exports.ViewflyVDomAdapter = ViewflyVDomAdapter;
|
|
File without changes
|