@textbus/adapter-viewfly 4.0.0-alpha.0 → 4.0.0-alpha.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.
- package/bundles/adapter.d.ts +4 -0
- package/bundles/index.esm.js +28 -9
- package/bundles/index.js +27 -8
- package/package.json +5 -5
package/bundles/adapter.d.ts
CHANGED
@@ -9,9 +9,13 @@ export interface ViewComponentProps<T extends Component = Component> {
|
|
9
9
|
export interface ViewflyAdapterComponents {
|
10
10
|
[key: string]: JSXInternal.ComponentSetup<ViewComponentProps>;
|
11
11
|
}
|
12
|
+
/**
|
13
|
+
* Textbus 桥接 [Viewfly](https://viewfly.org) 渲染能力适配器,用于在 Viewfly 项目中渲染 Textbus 数据
|
14
|
+
*/
|
12
15
|
export declare class Adapter extends DomAdapter<JSXComponent, JSXInternal.Element> {
|
13
16
|
onViewUpdated: Subject<void>;
|
14
17
|
private components;
|
18
|
+
private componentRefs;
|
15
19
|
constructor(components: ViewflyAdapterComponents, mount: (host: HTMLElement, root: JSXComponent) => (void | (() => void)));
|
16
20
|
componentRender(component: ComponentInstance): JSXInternal.JSXNode;
|
17
21
|
slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement): JSXInternal.Element;
|
package/bundles/index.esm.js
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
import { provide, onUpdated,
|
1
|
+
import { provide, onUpdated, useRef, jsx, Ref } from '@viewfly/core';
|
2
2
|
import { Subject } from '@tanbo/stream';
|
3
3
|
import { makeError, VElement, VTextNode, replaceEmpty } from '@textbus/core';
|
4
4
|
import { DomAdapter } from '@textbus/platform-browser';
|
5
5
|
|
6
6
|
const adapterError = makeError('ViewflyAdapter');
|
7
|
+
/**
|
8
|
+
* Textbus 桥接 [Viewfly](https://viewfly.org) 渲染能力适配器,用于在 Viewfly 项目中渲染 Textbus 数据
|
9
|
+
*/
|
7
10
|
class Adapter extends DomAdapter {
|
8
11
|
constructor(components, mount) {
|
9
12
|
super(mount);
|
10
13
|
this.onViewUpdated = new Subject();
|
11
14
|
this.components = {};
|
15
|
+
this.componentRefs = new WeakMap();
|
12
16
|
let isRoot = true;
|
13
17
|
Object.keys(components).forEach(key => {
|
14
18
|
this.components[key] = (props) => {
|
@@ -35,14 +39,20 @@ class Adapter extends DomAdapter {
|
|
35
39
|
componentRender(component) {
|
36
40
|
const comp = this.components[component.name] || this.components['*'];
|
37
41
|
if (comp) {
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
component.changeMarker.rendered();
|
43
|
+
let ref = this.componentRefs.get(component);
|
44
|
+
if (!ref) {
|
45
|
+
ref = useRef(rootNode => {
|
41
46
|
this.componentRootElementCaches.set(component, rootNode);
|
42
47
|
return () => {
|
43
|
-
this.componentRootElementCaches.
|
48
|
+
this.componentRootElementCaches.remove(component);
|
44
49
|
};
|
45
|
-
})
|
50
|
+
});
|
51
|
+
this.componentRefs.set(component, ref);
|
52
|
+
}
|
53
|
+
return jsx(comp, {
|
54
|
+
component,
|
55
|
+
rootRef: ref
|
46
56
|
}, component.id);
|
47
57
|
}
|
48
58
|
throw adapterError(`cannot found view component \`${component.name}\`!`);
|
@@ -64,13 +74,22 @@ class Adapter extends DomAdapter {
|
|
64
74
|
children.push(this.componentRender(child));
|
65
75
|
}
|
66
76
|
}
|
67
|
-
const props = Object.assign(
|
77
|
+
const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
|
68
78
|
a[b[0]] = b[1];
|
69
79
|
return a;
|
70
|
-
}, {})))
|
80
|
+
}, {})));
|
81
|
+
if (vNode.classes.size) {
|
82
|
+
props.className = Array.from(vNode.classes).join(' ');
|
83
|
+
}
|
84
|
+
if (vNode.styles) {
|
85
|
+
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
71
86
|
a[b[0]] = b[1];
|
72
87
|
return a;
|
73
|
-
}, {})
|
88
|
+
}, {});
|
89
|
+
}
|
90
|
+
if (children.length) {
|
91
|
+
props.children = children;
|
92
|
+
}
|
74
93
|
return jsx(vNode.tagName, props);
|
75
94
|
};
|
76
95
|
const jsxNode = vNodeToJSX(vElement);
|
package/bundles/index.js
CHANGED
@@ -6,11 +6,15 @@ var core = require('@textbus/core');
|
|
6
6
|
var platformBrowser = require('@textbus/platform-browser');
|
7
7
|
|
8
8
|
const adapterError = core.makeError('ViewflyAdapter');
|
9
|
+
/**
|
10
|
+
* Textbus 桥接 [Viewfly](https://viewfly.org) 渲染能力适配器,用于在 Viewfly 项目中渲染 Textbus 数据
|
11
|
+
*/
|
9
12
|
class Adapter extends platformBrowser.DomAdapter {
|
10
13
|
constructor(components, mount) {
|
11
14
|
super(mount);
|
12
15
|
this.onViewUpdated = new stream.Subject();
|
13
16
|
this.components = {};
|
17
|
+
this.componentRefs = new WeakMap();
|
14
18
|
let isRoot = true;
|
15
19
|
Object.keys(components).forEach(key => {
|
16
20
|
this.components[key] = (props) => {
|
@@ -37,14 +41,20 @@ class Adapter extends platformBrowser.DomAdapter {
|
|
37
41
|
componentRender(component) {
|
38
42
|
const comp = this.components[component.name] || this.components['*'];
|
39
43
|
if (comp) {
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
component.changeMarker.rendered();
|
45
|
+
let ref = this.componentRefs.get(component);
|
46
|
+
if (!ref) {
|
47
|
+
ref = core$1.useRef(rootNode => {
|
43
48
|
this.componentRootElementCaches.set(component, rootNode);
|
44
49
|
return () => {
|
45
|
-
this.componentRootElementCaches.
|
50
|
+
this.componentRootElementCaches.remove(component);
|
46
51
|
};
|
47
|
-
})
|
52
|
+
});
|
53
|
+
this.componentRefs.set(component, ref);
|
54
|
+
}
|
55
|
+
return core$1.jsx(comp, {
|
56
|
+
component,
|
57
|
+
rootRef: ref
|
48
58
|
}, component.id);
|
49
59
|
}
|
50
60
|
throw adapterError(`cannot found view component \`${component.name}\`!`);
|
@@ -66,13 +76,22 @@ class Adapter extends platformBrowser.DomAdapter {
|
|
66
76
|
children.push(this.componentRender(child));
|
67
77
|
}
|
68
78
|
}
|
69
|
-
const props = Object.assign(
|
79
|
+
const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
|
70
80
|
a[b[0]] = b[1];
|
71
81
|
return a;
|
72
|
-
}, {})))
|
82
|
+
}, {})));
|
83
|
+
if (vNode.classes.size) {
|
84
|
+
props.className = Array.from(vNode.classes).join(' ');
|
85
|
+
}
|
86
|
+
if (vNode.styles) {
|
87
|
+
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
73
88
|
a[b[0]] = b[1];
|
74
89
|
return a;
|
75
|
-
}, {})
|
90
|
+
}, {});
|
91
|
+
}
|
92
|
+
if (children.length) {
|
93
|
+
props.children = children;
|
94
|
+
}
|
76
95
|
return core$1.jsx(vNode.tagName, props);
|
77
96
|
};
|
78
97
|
const jsxNode = vNodeToJSX(vElement);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/adapter-viewfly",
|
3
|
-
"version": "4.0.0-alpha.
|
3
|
+
"version": "4.0.0-alpha.1",
|
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": "./bundles/index.js",
|
6
6
|
"module": "./bundles/index.esm.js",
|
@@ -26,9 +26,9 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/stream": "^1.2.0",
|
29
|
-
"@textbus/core": "^4.0.0-alpha.
|
30
|
-
"@textbus/platform-browser": "^4.0.0-alpha.
|
31
|
-
"@viewfly/core": "^0.
|
29
|
+
"@textbus/core": "^4.0.0-alpha.1",
|
30
|
+
"@textbus/platform-browser": "^4.0.0-alpha.1",
|
31
|
+
"@viewfly/core": "^0.2.0"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
34
|
"@rollup/plugin-commonjs": "^23.0.2",
|
@@ -48,5 +48,5 @@
|
|
48
48
|
"bugs": {
|
49
49
|
"url": "https://github.com/textbus/textbus.git/issues"
|
50
50
|
},
|
51
|
-
"gitHead": "
|
51
|
+
"gitHead": "c66a476c5776f8cf719ebb0f9e7adebb391f82c1"
|
52
52
|
}
|