@textbus/adapter-viewfly 4.0.0-alpha.53 → 4.0.0-alpha.55
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/index.esm.js +4 -152
- package/bundles/index.js +6 -151
- package/bundles/public-api.d.ts +2 -1
- package/package.json +7 -6
- package/bundles/viewfly-v-dom-adapter.d.ts +0 -18
package/bundles/index.esm.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
export { NodeViewAdapter as ViewflyVDomAdapter } from '@textbus/platform-node';
|
2
|
+
import { makeError, VElement, VTextNode, merge } from '@textbus/core';
|
2
3
|
import { createDynamicRef, DynamicRef, jsx, withAnnotation, getCurrentInstance, onUpdated } from '@viewfly/core';
|
3
4
|
import { DomAdapter } from '@textbus/platform-browser';
|
4
|
-
import { VDOMElement } from '@viewfly/platform-browser';
|
5
5
|
|
6
|
-
const adapterError
|
6
|
+
const adapterError = makeError('ViewflyDOMRenderer');
|
7
7
|
class ViewflyAdapter extends DomAdapter {
|
8
8
|
constructor(components, mount) {
|
9
9
|
super({
|
@@ -53,152 +53,6 @@ class ViewflyAdapter extends DomAdapter {
|
|
53
53
|
vEle.attrs.set('ref', ref);
|
54
54
|
}
|
55
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
|
-
this.componentRootElementCaches.remove(component);
|
65
|
-
};
|
66
|
-
});
|
67
|
-
this.componentRefs.set(component, ref);
|
68
|
-
}
|
69
|
-
return jsx(comp, {
|
70
|
-
component,
|
71
|
-
rootRef: ref
|
72
|
-
}, component.id);
|
73
|
-
}
|
74
|
-
throw adapterError$1(`cannot found view component \`${component.name}\`!`);
|
75
|
-
},
|
76
|
-
vElementToViewElement(vNode, children) {
|
77
|
-
const key = vNode.attrs.get('key');
|
78
|
-
vNode.attrs.delete('key');
|
79
|
-
const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
|
80
|
-
a[b[0]] = b[1];
|
81
|
-
return a;
|
82
|
-
}, {})));
|
83
|
-
if (vNode.classes.size) {
|
84
|
-
props.class = Array.from(vNode.classes).join(' ');
|
85
|
-
}
|
86
|
-
if (vNode.styles) {
|
87
|
-
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
88
|
-
a[b[0]] = b[1];
|
89
|
-
return a;
|
90
|
-
}, {});
|
91
|
-
}
|
92
|
-
if (children.length) {
|
93
|
-
props.children = children;
|
94
|
-
}
|
95
|
-
return jsx(vNode.tagName, props, key);
|
96
|
-
}
|
97
|
-
}, mount);
|
98
|
-
this.components = {};
|
99
|
-
this.componentRefs = new WeakMap();
|
100
|
-
let isRoot = true;
|
101
|
-
Object.entries(components).forEach(([key, viewFlyComponent]) => {
|
102
|
-
this.components[key] = withAnnotation(Object.assign({}, viewFlyComponent.annotation), (props) => {
|
103
|
-
const comp = getCurrentInstance();
|
104
|
-
const textbusComponent = props.component;
|
105
|
-
merge(textbusComponent.changeMarker.onChange, textbusComponent.changeMarker.onForceChange).subscribe(() => {
|
106
|
-
if (textbusComponent.changeMarker.dirty) {
|
107
|
-
comp.markAsDirtied();
|
108
|
-
}
|
109
|
-
});
|
110
|
-
if (isRoot) {
|
111
|
-
onUpdated(() => {
|
112
|
-
this.onViewUpdated.next();
|
113
|
-
});
|
114
|
-
isRoot = false;
|
115
|
-
}
|
116
|
-
onUpdated(() => {
|
117
|
-
const context = this.componentRendingStack[this.componentRendingStack.length - 1];
|
118
|
-
if (context === component) {
|
119
|
-
this.componentRendingStack.pop();
|
120
|
-
}
|
121
|
-
textbusComponent.changeMarker.rendered();
|
122
|
-
if (!this.componentRootElementCaches.get(textbusComponent)) {
|
123
|
-
// eslint-disable-next-line max-len
|
124
|
-
throw adapterError$1(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
|
125
|
-
}
|
126
|
-
});
|
127
|
-
const component = props.component;
|
128
|
-
const instance = viewFlyComponent(props);
|
129
|
-
if (typeof instance === 'function') {
|
130
|
-
return () => {
|
131
|
-
component.__slots__.forEach(i => this.renderedSlotCache.delete(i));
|
132
|
-
component.__slots__.length = 0;
|
133
|
-
this.componentRendingStack.push(component);
|
134
|
-
return instance();
|
135
|
-
};
|
136
|
-
}
|
137
|
-
const self = this;
|
138
|
-
return Object.assign(Object.assign({}, instance), { $render() {
|
139
|
-
component.__slots__.forEach(i => self.renderedSlotCache.delete(i));
|
140
|
-
component.__slots__.length = 0;
|
141
|
-
self.componentRendingStack.push(component);
|
142
|
-
return instance.$render();
|
143
|
-
} });
|
144
|
-
});
|
145
|
-
});
|
146
|
-
}
|
147
|
-
copy() {
|
148
|
-
document.execCommand('copy');
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
const adapterError = makeError('ViewflyHTMLRenderer');
|
153
|
-
class ViewflyVDomAdapter extends Adapter {
|
154
|
-
constructor(components, mount) {
|
155
|
-
super({
|
156
|
-
createCompositionNode(compositionState, updateNativeCompositionNode) {
|
157
|
-
const ref = createDynamicRef(node => {
|
158
|
-
updateNativeCompositionNode(node);
|
159
|
-
return () => {
|
160
|
-
updateNativeCompositionNode(null);
|
161
|
-
};
|
162
|
-
});
|
163
|
-
return new VElement('span', {
|
164
|
-
style: {
|
165
|
-
textDecoration: 'underline'
|
166
|
-
},
|
167
|
-
ref
|
168
|
-
}, [
|
169
|
-
new VTextNode(compositionState.text)
|
170
|
-
]);
|
171
|
-
},
|
172
|
-
getParentNode(node) {
|
173
|
-
return node.parent;
|
174
|
-
},
|
175
|
-
getChildNodes(parentElement) {
|
176
|
-
return parentElement.children.slice();
|
177
|
-
},
|
178
|
-
isNativeElementNode(node) {
|
179
|
-
return node instanceof VDOMElement;
|
180
|
-
},
|
181
|
-
getChildByIndex(parentElement, index) {
|
182
|
-
return parentElement.children[index];
|
183
|
-
},
|
184
|
-
getAndUpdateSlotRootNativeElement(vEle, update) {
|
185
|
-
const currentRef = vEle.attrs.get('ref');
|
186
|
-
const ref = createDynamicRef(nativeNode => {
|
187
|
-
update(nativeNode);
|
188
|
-
return () => {
|
189
|
-
update(null);
|
190
|
-
};
|
191
|
-
});
|
192
|
-
if (currentRef instanceof DynamicRef) {
|
193
|
-
vEle.attrs.set('ref', [currentRef, ref]);
|
194
|
-
}
|
195
|
-
else if (Array.isArray(currentRef)) {
|
196
|
-
currentRef.push(ref);
|
197
|
-
}
|
198
|
-
else {
|
199
|
-
vEle.attrs.set('ref', ref);
|
200
|
-
}
|
201
|
-
},
|
202
56
|
componentRender: (component) => {
|
203
57
|
const comp = this.components[component.name] || this.components['*'];
|
204
58
|
if (comp) {
|
@@ -241,8 +95,6 @@ class ViewflyVDomAdapter extends Adapter {
|
|
241
95
|
return jsx(vNode.tagName, props, key);
|
242
96
|
}
|
243
97
|
}, mount);
|
244
|
-
this.onViewUpdated = new Subject();
|
245
|
-
this.host = new VDOMElement('body');
|
246
98
|
this.components = {};
|
247
99
|
this.componentRefs = new WeakMap();
|
248
100
|
let isRoot = true;
|
@@ -297,4 +149,4 @@ class ViewflyVDomAdapter extends Adapter {
|
|
297
149
|
}
|
298
150
|
}
|
299
151
|
|
300
|
-
export { ViewflyAdapter
|
152
|
+
export { ViewflyAdapter };
|
package/bundles/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
var platformNode = require('@textbus/platform-node');
|
3
4
|
var core = require('@textbus/core');
|
4
5
|
var core$1 = require('@viewfly/core');
|
5
6
|
var platformBrowser = require('@textbus/platform-browser');
|
6
|
-
var platformBrowser$1 = require('@viewfly/platform-browser');
|
7
7
|
|
8
|
-
const adapterError
|
8
|
+
const adapterError = core.makeError('ViewflyDOMRenderer');
|
9
9
|
class ViewflyAdapter extends platformBrowser.DomAdapter {
|
10
10
|
constructor(components, mount) {
|
11
11
|
super({
|
@@ -55,152 +55,6 @@ class ViewflyAdapter extends platformBrowser.DomAdapter {
|
|
55
55
|
vEle.attrs.set('ref', ref);
|
56
56
|
}
|
57
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
|
-
this.componentRootElementCaches.remove(component);
|
67
|
-
};
|
68
|
-
});
|
69
|
-
this.componentRefs.set(component, ref);
|
70
|
-
}
|
71
|
-
return core$1.jsx(comp, {
|
72
|
-
component,
|
73
|
-
rootRef: ref
|
74
|
-
}, component.id);
|
75
|
-
}
|
76
|
-
throw adapterError$1(`cannot found view component \`${component.name}\`!`);
|
77
|
-
},
|
78
|
-
vElementToViewElement(vNode, children) {
|
79
|
-
const key = vNode.attrs.get('key');
|
80
|
-
vNode.attrs.delete('key');
|
81
|
-
const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
|
82
|
-
a[b[0]] = b[1];
|
83
|
-
return a;
|
84
|
-
}, {})));
|
85
|
-
if (vNode.classes.size) {
|
86
|
-
props.class = Array.from(vNode.classes).join(' ');
|
87
|
-
}
|
88
|
-
if (vNode.styles) {
|
89
|
-
props.style = Array.from(vNode.styles).reduce((a, b) => {
|
90
|
-
a[b[0]] = b[1];
|
91
|
-
return a;
|
92
|
-
}, {});
|
93
|
-
}
|
94
|
-
if (children.length) {
|
95
|
-
props.children = children;
|
96
|
-
}
|
97
|
-
return core$1.jsx(vNode.tagName, props, key);
|
98
|
-
}
|
99
|
-
}, mount);
|
100
|
-
this.components = {};
|
101
|
-
this.componentRefs = new WeakMap();
|
102
|
-
let isRoot = true;
|
103
|
-
Object.entries(components).forEach(([key, viewFlyComponent]) => {
|
104
|
-
this.components[key] = core$1.withAnnotation(Object.assign({}, viewFlyComponent.annotation), (props) => {
|
105
|
-
const comp = core$1.getCurrentInstance();
|
106
|
-
const textbusComponent = props.component;
|
107
|
-
core.merge(textbusComponent.changeMarker.onChange, textbusComponent.changeMarker.onForceChange).subscribe(() => {
|
108
|
-
if (textbusComponent.changeMarker.dirty) {
|
109
|
-
comp.markAsDirtied();
|
110
|
-
}
|
111
|
-
});
|
112
|
-
if (isRoot) {
|
113
|
-
core$1.onUpdated(() => {
|
114
|
-
this.onViewUpdated.next();
|
115
|
-
});
|
116
|
-
isRoot = false;
|
117
|
-
}
|
118
|
-
core$1.onUpdated(() => {
|
119
|
-
const context = this.componentRendingStack[this.componentRendingStack.length - 1];
|
120
|
-
if (context === component) {
|
121
|
-
this.componentRendingStack.pop();
|
122
|
-
}
|
123
|
-
textbusComponent.changeMarker.rendered();
|
124
|
-
if (!this.componentRootElementCaches.get(textbusComponent)) {
|
125
|
-
// eslint-disable-next-line max-len
|
126
|
-
throw adapterError$1(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
|
127
|
-
}
|
128
|
-
});
|
129
|
-
const component = props.component;
|
130
|
-
const instance = viewFlyComponent(props);
|
131
|
-
if (typeof instance === 'function') {
|
132
|
-
return () => {
|
133
|
-
component.__slots__.forEach(i => this.renderedSlotCache.delete(i));
|
134
|
-
component.__slots__.length = 0;
|
135
|
-
this.componentRendingStack.push(component);
|
136
|
-
return instance();
|
137
|
-
};
|
138
|
-
}
|
139
|
-
const self = this;
|
140
|
-
return Object.assign(Object.assign({}, instance), { $render() {
|
141
|
-
component.__slots__.forEach(i => self.renderedSlotCache.delete(i));
|
142
|
-
component.__slots__.length = 0;
|
143
|
-
self.componentRendingStack.push(component);
|
144
|
-
return instance.$render();
|
145
|
-
} });
|
146
|
-
});
|
147
|
-
});
|
148
|
-
}
|
149
|
-
copy() {
|
150
|
-
document.execCommand('copy');
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
const adapterError = core.makeError('ViewflyHTMLRenderer');
|
155
|
-
class ViewflyVDomAdapter extends core.Adapter {
|
156
|
-
constructor(components, mount) {
|
157
|
-
super({
|
158
|
-
createCompositionNode(compositionState, updateNativeCompositionNode) {
|
159
|
-
const ref = core$1.createDynamicRef(node => {
|
160
|
-
updateNativeCompositionNode(node);
|
161
|
-
return () => {
|
162
|
-
updateNativeCompositionNode(null);
|
163
|
-
};
|
164
|
-
});
|
165
|
-
return new core.VElement('span', {
|
166
|
-
style: {
|
167
|
-
textDecoration: 'underline'
|
168
|
-
},
|
169
|
-
ref
|
170
|
-
}, [
|
171
|
-
new core.VTextNode(compositionState.text)
|
172
|
-
]);
|
173
|
-
},
|
174
|
-
getParentNode(node) {
|
175
|
-
return node.parent;
|
176
|
-
},
|
177
|
-
getChildNodes(parentElement) {
|
178
|
-
return parentElement.children.slice();
|
179
|
-
},
|
180
|
-
isNativeElementNode(node) {
|
181
|
-
return node instanceof platformBrowser$1.VDOMElement;
|
182
|
-
},
|
183
|
-
getChildByIndex(parentElement, index) {
|
184
|
-
return parentElement.children[index];
|
185
|
-
},
|
186
|
-
getAndUpdateSlotRootNativeElement(vEle, update) {
|
187
|
-
const currentRef = vEle.attrs.get('ref');
|
188
|
-
const ref = core$1.createDynamicRef(nativeNode => {
|
189
|
-
update(nativeNode);
|
190
|
-
return () => {
|
191
|
-
update(null);
|
192
|
-
};
|
193
|
-
});
|
194
|
-
if (currentRef instanceof core$1.DynamicRef) {
|
195
|
-
vEle.attrs.set('ref', [currentRef, ref]);
|
196
|
-
}
|
197
|
-
else if (Array.isArray(currentRef)) {
|
198
|
-
currentRef.push(ref);
|
199
|
-
}
|
200
|
-
else {
|
201
|
-
vEle.attrs.set('ref', ref);
|
202
|
-
}
|
203
|
-
},
|
204
58
|
componentRender: (component) => {
|
205
59
|
const comp = this.components[component.name] || this.components['*'];
|
206
60
|
if (comp) {
|
@@ -243,8 +97,6 @@ class ViewflyVDomAdapter extends core.Adapter {
|
|
243
97
|
return core$1.jsx(vNode.tagName, props, key);
|
244
98
|
}
|
245
99
|
}, mount);
|
246
|
-
this.onViewUpdated = new core.Subject();
|
247
|
-
this.host = new platformBrowser$1.VDOMElement('body');
|
248
100
|
this.components = {};
|
249
101
|
this.componentRefs = new WeakMap();
|
250
102
|
let isRoot = true;
|
@@ -299,5 +151,8 @@ class ViewflyVDomAdapter extends core.Adapter {
|
|
299
151
|
}
|
300
152
|
}
|
301
153
|
|
154
|
+
Object.defineProperty(exports, 'ViewflyVDomAdapter', {
|
155
|
+
enumerable: true,
|
156
|
+
get: function () { return platformNode.NodeViewAdapter; }
|
157
|
+
});
|
302
158
|
exports.ViewflyAdapter = ViewflyAdapter;
|
303
|
-
exports.ViewflyVDomAdapter = ViewflyVDomAdapter;
|
package/bundles/public-api.d.ts
CHANGED
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.55",
|
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,10 +26,11 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/stream": "^1.2.4",
|
29
|
-
"@textbus/core": "^4.0.0-alpha.
|
30
|
-
"@textbus/platform-browser": "^4.0.0-alpha.
|
31
|
-
"@
|
32
|
-
"@viewfly/
|
29
|
+
"@textbus/core": "^4.0.0-alpha.55",
|
30
|
+
"@textbus/platform-browser": "^4.0.0-alpha.55",
|
31
|
+
"@textbus/platform-node": "^4.0.0-alpha.55",
|
32
|
+
"@viewfly/core": "^1.0.0-alpha.6",
|
33
|
+
"@viewfly/platform-browser": "^1.0.0-alpha.6"
|
33
34
|
},
|
34
35
|
"devDependencies": {
|
35
36
|
"@rollup/plugin-commonjs": "^23.0.2",
|
@@ -49,5 +50,5 @@
|
|
49
50
|
"bugs": {
|
50
51
|
"url": "https://github.com/textbus/textbus.git/issues"
|
51
52
|
},
|
52
|
-
"gitHead": "
|
53
|
+
"gitHead": "22e85887dd98c3689799dfd217bfc1f845cb28a8"
|
53
54
|
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { Component, ViewMount, Adapter, Subject } from '@textbus/core';
|
2
|
-
import { VDOMElement, VDOMText } from '@viewfly/platform-browser';
|
3
|
-
import { DynamicRef } from '@viewfly/core';
|
4
|
-
export interface ViewVDomComponentProps<T extends Component> {
|
5
|
-
component: T;
|
6
|
-
rootRef: DynamicRef<VDOMElement>;
|
7
|
-
}
|
8
|
-
export interface ViewflyVDomAdapterComponents {
|
9
|
-
[key: string]: JSXInternal.ComponentSetup<ViewVDomComponentProps<any>>;
|
10
|
-
}
|
11
|
-
export declare class ViewflyVDomAdapter extends Adapter<VDOMElement, VDOMText, JSXInternal.ViewNode, JSXInternal.Element> {
|
12
|
-
onViewUpdated: Subject<void>;
|
13
|
-
host: VDOMElement;
|
14
|
-
private components;
|
15
|
-
private componentRefs;
|
16
|
-
constructor(components: ViewflyVDomAdapterComponents, mount: ViewMount<JSXInternal.ViewNode, VDOMElement>);
|
17
|
-
copy(): void;
|
18
|
-
}
|