@viewfly/platform-browser 0.5.0 → 0.5.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/create-portal.d.ts +31 -0
- package/bundles/dom-renderer.d.ts +1 -1
- package/bundles/html-renderer.d.ts +1 -0
- package/bundles/index.esm.js +52 -5
- package/bundles/index.js +51 -3
- package/bundles/public-api.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { JSXNode, NativeNode } from '@viewfly/core';
|
|
2
|
+
/**
|
|
3
|
+
* 用于创建脱离当前 DOM 树的子节点,常用于弹窗等
|
|
4
|
+
* @param childRender
|
|
5
|
+
* @param host
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* function App() {
|
|
9
|
+
* const number = createSignal(0)
|
|
10
|
+
*
|
|
11
|
+
* setInterval(() => {
|
|
12
|
+
* number.set(number() + 1)
|
|
13
|
+
* }, 1000)
|
|
14
|
+
*
|
|
15
|
+
* const ModalPortal = function (props) {
|
|
16
|
+
* return createPortal(() => {
|
|
17
|
+
* return <div class="modal">parent data is {props.text}</div>
|
|
18
|
+
* }, document.body)
|
|
19
|
+
* }
|
|
20
|
+
* return () => {
|
|
21
|
+
* return (
|
|
22
|
+
* <div>
|
|
23
|
+
* <div>data is {number()}</div>
|
|
24
|
+
* <ModalPortal text={number()}/>
|
|
25
|
+
* </div>
|
|
26
|
+
* )
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPortal<T extends NativeNode>(childRender: () => JSXNode, host: T): () => null;
|
|
@@ -10,6 +10,7 @@ export declare class DomRenderer extends NativeRenderer<HTMLElement, Text> {
|
|
|
10
10
|
propMap: Record<string, Record<string, string>>;
|
|
11
11
|
createElement(name: string, isSvg: boolean): HTMLElement;
|
|
12
12
|
createTextNode(textContent: string): Text;
|
|
13
|
+
appendChild(parent: HTMLElement, newChild: any): void;
|
|
13
14
|
prependChild(parent: HTMLElement, newChild: HTMLElement | Text): void;
|
|
14
15
|
insertAfter(newNode: HTMLElement | Text, ref: HTMLElement | Text): void;
|
|
15
16
|
remove(node: HTMLElement | Text): void;
|
|
@@ -22,5 +23,4 @@ export declare class DomRenderer extends NativeRenderer<HTMLElement, Text> {
|
|
|
22
23
|
unListen(node: HTMLElement, type: string, callback: (ev: any) => any): void;
|
|
23
24
|
syncTextContent(target: Text, content: string): void;
|
|
24
25
|
private insertBefore;
|
|
25
|
-
private appendChild;
|
|
26
26
|
}
|
|
@@ -20,6 +20,7 @@ export declare class HTMLRenderer extends NativeRenderer<VDOMElement, VDomText>
|
|
|
20
20
|
createElement(name: string): VDOMElement;
|
|
21
21
|
createTextNode(textContent: string): VDomText;
|
|
22
22
|
setProperty(node: VDOMElement, key: string, value: any): void;
|
|
23
|
+
appendChild(parent: VDOMElement, newChild: VDOMElement | VDomText): void;
|
|
23
24
|
prependChild(parent: VDOMElement, newChild: VDOMElement | VDomText): void;
|
|
24
25
|
removeProperty(node: VDOMElement, key: string): void;
|
|
25
26
|
setStyle(target: VDOMElement, key: string, value: any): void;
|
package/bundles/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeRenderer, viewfly,
|
|
1
|
+
import { NativeRenderer, viewfly, getCurrentInstance, inject, Component, onPropsChanged, createRenderer, makeError, Injector, THROW_IF_NOT_FOUND, InjectFlags, onUnmounted } from '@viewfly/core';
|
|
2
2
|
|
|
3
3
|
class DomRenderer extends NativeRenderer {
|
|
4
4
|
constructor() {
|
|
@@ -21,6 +21,9 @@ class DomRenderer extends NativeRenderer {
|
|
|
21
21
|
createTextNode(textContent) {
|
|
22
22
|
return document.createTextNode(textContent);
|
|
23
23
|
}
|
|
24
|
+
appendChild(parent, newChild) {
|
|
25
|
+
parent.appendChild(newChild);
|
|
26
|
+
}
|
|
24
27
|
prependChild(parent, newChild) {
|
|
25
28
|
parent.prepend(newChild);
|
|
26
29
|
}
|
|
@@ -96,9 +99,6 @@ class DomRenderer extends NativeRenderer {
|
|
|
96
99
|
insertBefore(newNode, ref) {
|
|
97
100
|
ref.parentNode.insertBefore(newNode, ref);
|
|
98
101
|
}
|
|
99
|
-
appendChild(parent, newChild) {
|
|
100
|
-
parent.appendChild(newChild);
|
|
101
|
-
}
|
|
102
102
|
}
|
|
103
103
|
DomRenderer.NAMESPACES = {
|
|
104
104
|
svg: 'http://www.w3.org/2000/svg',
|
|
@@ -119,6 +119,49 @@ function createApp(root, config = true) {
|
|
|
119
119
|
return viewfly(Object.assign(Object.assign({}, c), { root, nativeRenderer: c.nativeRenderer || new DomRenderer() }));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* 用于创建脱离当前 DOM 树的子节点,常用于弹窗等
|
|
124
|
+
* @param childRender
|
|
125
|
+
* @param host
|
|
126
|
+
* @example
|
|
127
|
+
* ```tsx
|
|
128
|
+
* function App() {
|
|
129
|
+
* const number = createSignal(0)
|
|
130
|
+
*
|
|
131
|
+
* setInterval(() => {
|
|
132
|
+
* number.set(number() + 1)
|
|
133
|
+
* }, 1000)
|
|
134
|
+
*
|
|
135
|
+
* const ModalPortal = function (props) {
|
|
136
|
+
* return createPortal(() => {
|
|
137
|
+
* return <div class="modal">parent data is {props.text}</div>
|
|
138
|
+
* }, document.body)
|
|
139
|
+
* }
|
|
140
|
+
* return () => {
|
|
141
|
+
* return (
|
|
142
|
+
* <div>
|
|
143
|
+
* <div>data is {number()}</div>
|
|
144
|
+
* <ModalPortal text={number()}/>
|
|
145
|
+
* </div>
|
|
146
|
+
* )
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
function createPortal(childRender, host) {
|
|
152
|
+
const instance = getCurrentInstance();
|
|
153
|
+
const nativeRenderer = inject(NativeRenderer);
|
|
154
|
+
const component = new Component(instance, () => childRender, {});
|
|
155
|
+
onPropsChanged(() => {
|
|
156
|
+
component.markAsDirtied();
|
|
157
|
+
});
|
|
158
|
+
const render = createRenderer(component, nativeRenderer);
|
|
159
|
+
return function () {
|
|
160
|
+
render(host);
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
122
165
|
const forkErrorFn = makeError('fork');
|
|
123
166
|
function fork(root, config = true) {
|
|
124
167
|
const c = { autoUpdate: true };
|
|
@@ -171,6 +214,10 @@ class HTMLRenderer extends NativeRenderer {
|
|
|
171
214
|
setProperty(node, key, value) {
|
|
172
215
|
node.props.set(key, value);
|
|
173
216
|
}
|
|
217
|
+
appendChild(parent, newChild) {
|
|
218
|
+
parent.children.push(newChild);
|
|
219
|
+
newChild.parent = parent;
|
|
220
|
+
}
|
|
174
221
|
prependChild(parent, newChild) {
|
|
175
222
|
parent.children.unshift(newChild);
|
|
176
223
|
newChild.parent = parent;
|
|
@@ -309,4 +356,4 @@ OutputTranslator.simpleXSSFilter = {
|
|
|
309
356
|
}
|
|
310
357
|
};
|
|
311
358
|
|
|
312
|
-
export { DomRenderer, HTMLRenderer, OutputTranslator, VDOMElement, VDomText, createApp, fork };
|
|
359
|
+
export { DomRenderer, HTMLRenderer, OutputTranslator, VDOMElement, VDomText, createApp, createPortal, fork };
|
package/bundles/index.js
CHANGED
|
@@ -23,6 +23,9 @@ class DomRenderer extends core.NativeRenderer {
|
|
|
23
23
|
createTextNode(textContent) {
|
|
24
24
|
return document.createTextNode(textContent);
|
|
25
25
|
}
|
|
26
|
+
appendChild(parent, newChild) {
|
|
27
|
+
parent.appendChild(newChild);
|
|
28
|
+
}
|
|
26
29
|
prependChild(parent, newChild) {
|
|
27
30
|
parent.prepend(newChild);
|
|
28
31
|
}
|
|
@@ -98,9 +101,6 @@ class DomRenderer extends core.NativeRenderer {
|
|
|
98
101
|
insertBefore(newNode, ref) {
|
|
99
102
|
ref.parentNode.insertBefore(newNode, ref);
|
|
100
103
|
}
|
|
101
|
-
appendChild(parent, newChild) {
|
|
102
|
-
parent.appendChild(newChild);
|
|
103
|
-
}
|
|
104
104
|
}
|
|
105
105
|
DomRenderer.NAMESPACES = {
|
|
106
106
|
svg: 'http://www.w3.org/2000/svg',
|
|
@@ -121,6 +121,49 @@ function createApp(root, config = true) {
|
|
|
121
121
|
return core.viewfly(Object.assign(Object.assign({}, c), { root, nativeRenderer: c.nativeRenderer || new DomRenderer() }));
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* 用于创建脱离当前 DOM 树的子节点,常用于弹窗等
|
|
126
|
+
* @param childRender
|
|
127
|
+
* @param host
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* function App() {
|
|
131
|
+
* const number = createSignal(0)
|
|
132
|
+
*
|
|
133
|
+
* setInterval(() => {
|
|
134
|
+
* number.set(number() + 1)
|
|
135
|
+
* }, 1000)
|
|
136
|
+
*
|
|
137
|
+
* const ModalPortal = function (props) {
|
|
138
|
+
* return createPortal(() => {
|
|
139
|
+
* return <div class="modal">parent data is {props.text}</div>
|
|
140
|
+
* }, document.body)
|
|
141
|
+
* }
|
|
142
|
+
* return () => {
|
|
143
|
+
* return (
|
|
144
|
+
* <div>
|
|
145
|
+
* <div>data is {number()}</div>
|
|
146
|
+
* <ModalPortal text={number()}/>
|
|
147
|
+
* </div>
|
|
148
|
+
* )
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
function createPortal(childRender, host) {
|
|
154
|
+
const instance = core.getCurrentInstance();
|
|
155
|
+
const nativeRenderer = core.inject(core.NativeRenderer);
|
|
156
|
+
const component = new core.Component(instance, () => childRender, {});
|
|
157
|
+
core.onPropsChanged(() => {
|
|
158
|
+
component.markAsDirtied();
|
|
159
|
+
});
|
|
160
|
+
const render = core.createRenderer(component, nativeRenderer);
|
|
161
|
+
return function () {
|
|
162
|
+
render(host);
|
|
163
|
+
return null;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
124
167
|
const forkErrorFn = core.makeError('fork');
|
|
125
168
|
function fork(root, config = true) {
|
|
126
169
|
const c = { autoUpdate: true };
|
|
@@ -173,6 +216,10 @@ class HTMLRenderer extends core.NativeRenderer {
|
|
|
173
216
|
setProperty(node, key, value) {
|
|
174
217
|
node.props.set(key, value);
|
|
175
218
|
}
|
|
219
|
+
appendChild(parent, newChild) {
|
|
220
|
+
parent.children.push(newChild);
|
|
221
|
+
newChild.parent = parent;
|
|
222
|
+
}
|
|
176
223
|
prependChild(parent, newChild) {
|
|
177
224
|
parent.children.unshift(newChild);
|
|
178
225
|
newChild.parent = parent;
|
|
@@ -317,4 +364,5 @@ exports.OutputTranslator = OutputTranslator;
|
|
|
317
364
|
exports.VDOMElement = VDOMElement;
|
|
318
365
|
exports.VDomText = VDomText;
|
|
319
366
|
exports.createApp = createApp;
|
|
367
|
+
exports.createPortal = createPortal;
|
|
320
368
|
exports.fork = fork;
|
package/bundles/public-api.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/platform-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "This project is used to enable the Viewfly framework to run in a browser.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@viewfly/core": "^0.5.
|
|
15
|
+
"@viewfly/core": "^0.5.1",
|
|
16
16
|
"csstype": "^3.1.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"bugs": {
|
|
34
34
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "343b1bff988837e5e0a2acee63c18c3f4a3e8721"
|
|
37
37
|
}
|