@textbus/adapter-viewfly 5.2.0 → 5.2.2
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/dist/index.esm.js +7 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/viewfly-adapter.d.ts +2 -2
- package/dist/viewfly-vdom-adapter.d.ts +2 -2
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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,
|
|
2
|
+
import { jsx as f, createDynamicRef as m, getCurrentInstance as C, onUnmounted as x, onUpdated as p, ReflectiveInjector as g } from "@viewfly/core";
|
|
3
3
|
import { DomAdapter as u } from "@textbus/platform-browser";
|
|
4
|
-
import { NodeViewAdapter as
|
|
4
|
+
import { NodeViewAdapter as E } from "@textbus/platform-node";
|
|
5
5
|
const h = R("ViewflyDOMRenderer");
|
|
6
6
|
class d extends u {
|
|
7
7
|
components = {};
|
|
@@ -37,7 +37,7 @@ class d extends u {
|
|
|
37
37
|
const t = e.attrs.get("ref"), n = m((o) => (r(o), () => {
|
|
38
38
|
r(null);
|
|
39
39
|
}));
|
|
40
|
-
t
|
|
40
|
+
typeof t == "function" ? e.attrs.set("ref", [t, n]) : Array.isArray(t) ? t.push(n) : e.attrs.set("ref", n);
|
|
41
41
|
},
|
|
42
42
|
componentRender: (e) => {
|
|
43
43
|
const r = this.components[e.name] || this.components["*"];
|
|
@@ -64,13 +64,13 @@ class d extends u {
|
|
|
64
64
|
let i = !0;
|
|
65
65
|
Object.entries(c).forEach(([e, r]) => {
|
|
66
66
|
this.components[e] = (t) => {
|
|
67
|
-
const n =
|
|
67
|
+
const n = C(), o = t.component, s = A(
|
|
68
68
|
o.changeMarker.onChange,
|
|
69
69
|
o.changeMarker.onForceChange
|
|
70
70
|
).subscribe(() => {
|
|
71
71
|
o.changeMarker.dirty && n.markAsDirtied();
|
|
72
72
|
});
|
|
73
|
-
return
|
|
73
|
+
return x(() => {
|
|
74
74
|
s.unsubscribe();
|
|
75
75
|
}), i && (p(() => {
|
|
76
76
|
this.onViewUpdated.next();
|
|
@@ -98,7 +98,7 @@ class d extends u {
|
|
|
98
98
|
document.execCommand("copy");
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
class
|
|
101
|
+
class v extends E {
|
|
102
102
|
render(c, a) {
|
|
103
103
|
const i = new g(a, [{
|
|
104
104
|
provide: y,
|
|
@@ -115,6 +115,6 @@ class I extends k {
|
|
|
115
115
|
}
|
|
116
116
|
export {
|
|
117
117
|
d as ViewflyAdapter,
|
|
118
|
-
|
|
118
|
+
v as ViewflyVDomAdapter
|
|
119
119
|
};
|
|
120
120
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +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;AAAA,MACJ,sBAAsBC,GACAC,GAA+E;AACnG,cAAMC,IAAMC,EAA0B,CAAAC,OACpCH,EAA4BG,CAAI,GACzB,MAAM;AACX,UAAAH,EAA4B,IAAI;AAAA,QAClC,EACD;AACD,eAAO,IAAII,EAAS,QAAQ;AAAA,UAC1B,OAAO;AAAA,YACL,gBAAgB;AAAA,UAAA;AAAA,UAElB,KAAAH;AAAA,QAAA,GACC;AAAA,UACD,IAAII,EAAUN,EAAiB,IAAI;AAAA,QAAA,CACpC;AAAA,MACH;AAAA,MACA,cAAcI,GAAsC;AAClD,eAAQA,EAAc;AAAA,MACxB;AAAA,MACA,cAAcG,GAA+C;AAC3D,eAAO,MAAM,KAAKA,EAAc,UAAU;AAAA,MAC5C;AAAA,MACA,oBAAoBH,GAAuC;AACzD,eAAOA,aAAgB;AAAA,MACzB;AAAA,MACA,gBAAgBG,GAAeC,GAAO;AACpC,eAAOD,EAAc,WAAWC,CAAK;AAAA,MACvC;AAAA,MACA,kCAAkCC,GAAgBC,GAAmD;AAC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A,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;"}
|
|
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 (typeof currentRef === 'function') {\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","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;AAAA,MACJ,sBAAsBC,GACAC,GAA+E;AACnG,cAAMC,IAAMC,EAA0B,CAAAC,OACpCH,EAA4BG,CAAI,GACzB,MAAM;AACX,UAAAH,EAA4B,IAAI;AAAA,QAClC,EACD;AACD,eAAO,IAAII,EAAS,QAAQ;AAAA,UAC1B,OAAO;AAAA,YACL,gBAAgB;AAAA,UAAA;AAAA,UAElB,KAAAH;AAAA,QAAA,GACC;AAAA,UACD,IAAII,EAAUN,EAAiB,IAAI;AAAA,QAAA,CACpC;AAAA,MACH;AAAA,MACA,cAAcI,GAAsC;AAClD,eAAQA,EAAc;AAAA,MACxB;AAAA,MACA,cAAcG,GAA+C;AAC3D,eAAO,MAAM,KAAKA,EAAc,UAAU;AAAA,MAC5C;AAAA,MACA,oBAAoBH,GAAuC;AACzD,eAAOA,aAAgB;AAAA,MACzB;AAAA,MACA,gBAAgBG,GAAeC,GAAO;AACpC,eAAOD,EAAc,WAAWC,CAAK;AAAA,MACvC;AAAA,MACA,kCAAkCC,GAAgBC,GAAmD;AACnG,cAAMC,IAAaF,EAAK,MAAM,IAAI,KAAK,GACjCP,IAAMC,EAA0B,CAAAS,OACpCF,EAAOE,CAAU,GACV,MAAM;AACX,UAAAF,EAAO,IAAI;AAAA,QACb,EACD;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ACF;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,SAASvC;AAAA,MACT,UAAU;AAAA,IAAA,GACT;AAAA,MACD,SAASD;AAAA,MACT,UAAU;AAAA,IAAA,CACX,CAAC;AACF,WAAO,MAAM,OAAOoC,GAAeE,CAAa;AAAA,EAClD;AACF;"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +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
|
|
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(u,d){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)}));typeof t=="function"?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)}},d);let c=!0;Object.entries(u).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(u,d){const c=new s.ReflectiveInjector(d,[{provide:a.Adapter,useValue:this},{provide:m.DomAdapter,useValue:this},{provide:l,useValue:this}]);return super.render(u,c)}copy(){document.execCommand("copy")}}class y extends h.NodeViewAdapter{render(u,d){const c=new s.ReflectiveInjector(d,[{provide:a.Adapter,useValue:this},{provide:m.DomAdapter,useValue:this},{provide:l,useValue:this}]);return super.render(u,c)}}exports.ViewflyAdapter=l;exports.ViewflyVDomAdapter=y;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,CAC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AAyC,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
|
+
{"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 (typeof currentRef === 'function') {\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","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,EACG,OAAOC,GAAe,WACxBF,EAAK,MAAM,IAAI,MAAO,CAACE,EAAYT,CAAG,CAAC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AM,OAAOoC,EAAeE,CAAa,CAClD,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Component, ViewMount } from '
|
|
1
|
+
import { Component, ViewMount } from '@textbus/core';
|
|
2
2
|
import { ComponentSetup, DynamicRef, Injector, ViewFlyNode } from '@viewfly/core';
|
|
3
|
-
import { DomAdapter } from '
|
|
3
|
+
import { DomAdapter } from '@textbus/platform-browser';
|
|
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 '@textbus/platform-node';
|
|
2
2
|
import { Injector } from '@viewfly/core';
|
|
3
|
-
import { Component } from '
|
|
3
|
+
import { Component } from '@textbus/core';
|
|
4
4
|
export declare class ViewflyVDomAdapter extends NodeViewAdapter {
|
|
5
5
|
render(rootComponent: Component, injector: Injector): void | (() => void);
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textbus/adapter-viewfly",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@tanbo/stream": "^1.2.7",
|
|
36
36
|
"@viewfly/core": "^2.2.0 || >=3.0.0-alpha.0 <4",
|
|
37
37
|
"@viewfly/platform-browser": "^2.2.0 || >=3.0.0-alpha.0 <4",
|
|
38
|
-
"@textbus/
|
|
39
|
-
"@textbus/
|
|
40
|
-
"@textbus/platform-node": "^5.2.
|
|
38
|
+
"@textbus/platform-browser": "^5.2.2",
|
|
39
|
+
"@textbus/core": "^5.2.2",
|
|
40
|
+
"@textbus/platform-node": "^5.2.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"rimraf": "^3.0.2",
|