@viewfly/platform-browser 1.1.4 → 1.1.6

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 TanBo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 TanBo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,58 +1,58 @@
1
- Viewfly
2
- ================================
3
-
4
- Viewfly 是一个简单、数据驱动的前端框架。此项目为内核运行在浏览器上的支持层。
5
-
6
- ## 安装
7
-
8
- ```
9
- npm install @viewfly/platform-browser
10
- ```
11
-
12
- ## API
13
-
14
- ### createApp()
15
-
16
- createApp 用于创建一个独立的应用。
17
-
18
- ```js
19
- import { createApp } from '@viewfly/platform-browser'
20
-
21
- function App() {
22
- return () => {
23
- return <div>App!</div>
24
- }
25
- }
26
-
27
- const app = createApp(<App/>)
28
- app.mount(document.getElementById('app'))
29
-
30
- // 销毁 app 实例
31
- app.destroy()
32
- ```
33
-
34
- ### fork()
35
-
36
- 可以在任意组件内创建一个子应用,并可以继承当前组件的上下文(特指当前组件的依赖注入树),常用于创建一个弹窗或对话框。
37
-
38
- ```jsx
39
- function App() {
40
- function Modal() {
41
- return () => {
42
- return <div>modal</div>
43
- }
44
- }
45
- // 创建子应用
46
- const childApp = fork(<Modal/>)
47
- // 启动子应用
48
- childApp.mount(document.getElementById('modal'))
49
- // 销毁子应用
50
- childApp.destroy()
51
-
52
- return () => {
53
- return <div>App!</div>
54
- }
55
- }
56
- ```
57
-
58
- 完整文档请参考官方网站:[viewfly.org](https://viewfly.org)
1
+ Viewfly
2
+ ================================
3
+
4
+ Viewfly 是一个简单、数据驱动的前端框架。此项目为内核运行在浏览器上的支持层。
5
+
6
+ ## 安装
7
+
8
+ ```
9
+ npm install @viewfly/platform-browser
10
+ ```
11
+
12
+ ## API
13
+
14
+ ### createApp()
15
+
16
+ createApp 用于创建一个独立的应用。
17
+
18
+ ```js
19
+ import { createApp } from '@viewfly/platform-browser'
20
+
21
+ function App() {
22
+ return () => {
23
+ return <div>App!</div>
24
+ }
25
+ }
26
+
27
+ const app = createApp(<App/>)
28
+ app.mount(document.getElementById('app'))
29
+
30
+ // 销毁 app 实例
31
+ app.destroy()
32
+ ```
33
+
34
+ ### fork()
35
+
36
+ 可以在任意组件内创建一个子应用,并可以继承当前组件的上下文(特指当前组件的依赖注入树),常用于创建一个弹窗或对话框。
37
+
38
+ ```jsx
39
+ function App() {
40
+ function Modal() {
41
+ return () => {
42
+ return <div>modal</div>
43
+ }
44
+ }
45
+ // 创建子应用
46
+ const childApp = fork(<Modal/>)
47
+ // 启动子应用
48
+ childApp.mount(document.getElementById('modal'))
49
+ // 销毁子应用
50
+ childApp.destroy()
51
+
52
+ return () => {
53
+ return <div>App!</div>
54
+ }
55
+ }
56
+ ```
57
+
58
+ 完整文档请参考官方网站:[viewfly.org](https://viewfly.org)
@@ -48,13 +48,14 @@ class DomRenderer extends NativeRenderer {
48
48
  }
49
49
  setProperty(node, key, value, namespace) {
50
50
  if (namespace) {
51
- const NAMESPACE = DomRenderer.NAMESPACES;
52
- const [prefix, ...unqualifiedName] = key.split(/(?=[A-Z])/);
53
- let ns = DomRenderer.NAMESPACES[namespace];
54
- if (prefix === 'xmlns' || unqualifiedName.length && NAMESPACE[prefix]) {
55
- ns = NAMESPACE[prefix];
51
+ const prefix = 'xlink:';
52
+ if (key.startsWith(prefix)) {
53
+ const ns = key.substring(prefix.length);
54
+ node.setAttributeNS(ns, key, String(value));
55
+ }
56
+ else {
57
+ node.setAttribute(key, String(value));
56
58
  }
57
- node.setAttributeNS(ns, key, String(value));
58
59
  return;
59
60
  }
60
61
  const map = this.propMap[node.tagName];
@@ -73,13 +74,14 @@ class DomRenderer extends NativeRenderer {
73
74
  }
74
75
  removeProperty(node, key, namespace) {
75
76
  if (namespace) {
76
- const NAMESPACE = DomRenderer.NAMESPACES;
77
- const [prefix, ...unqualifiedName] = key.split(/(?=[A-Z])/);
78
- let ns = DomRenderer.NAMESPACES[namespace];
79
- if (prefix === 'xmlns' || unqualifiedName.length && NAMESPACE[prefix]) {
80
- ns = NAMESPACE[prefix];
77
+ const prefix = 'xlink:';
78
+ if (key.startsWith(prefix)) {
79
+ const ns = key.substring(prefix.length);
80
+ node.removeAttributeNS(ns, key.substring(prefix.length));
81
+ }
82
+ else {
83
+ node.removeAttribute(key);
81
84
  }
82
- node.removeAttributeNS(ns, key);
83
85
  return;
84
86
  }
85
87
  if (key in node) {
@@ -93,9 +95,17 @@ class DomRenderer extends NativeRenderer {
93
95
  target.setAttribute('class', className);
94
96
  }
95
97
  setStyle(target, key, value) {
98
+ if (key.startsWith('--')) {
99
+ target.style.setProperty(key, value);
100
+ return;
101
+ }
96
102
  target.style[key] = value !== null && value !== void 0 ? value : '';
97
103
  }
98
104
  removeStyle(target, key) {
105
+ if (key.startsWith('--')) {
106
+ target.style.removeProperty(key);
107
+ return;
108
+ }
99
109
  target.style[key] = '';
100
110
  }
101
111
  listen(node, type, callback) {
package/bundles/index.js CHANGED
@@ -50,13 +50,14 @@ class DomRenderer extends core.NativeRenderer {
50
50
  }
51
51
  setProperty(node, key, value, namespace) {
52
52
  if (namespace) {
53
- const NAMESPACE = DomRenderer.NAMESPACES;
54
- const [prefix, ...unqualifiedName] = key.split(/(?=[A-Z])/);
55
- let ns = DomRenderer.NAMESPACES[namespace];
56
- if (prefix === 'xmlns' || unqualifiedName.length && NAMESPACE[prefix]) {
57
- ns = NAMESPACE[prefix];
53
+ const prefix = 'xlink:';
54
+ if (key.startsWith(prefix)) {
55
+ const ns = key.substring(prefix.length);
56
+ node.setAttributeNS(ns, key, String(value));
57
+ }
58
+ else {
59
+ node.setAttribute(key, String(value));
58
60
  }
59
- node.setAttributeNS(ns, key, String(value));
60
61
  return;
61
62
  }
62
63
  const map = this.propMap[node.tagName];
@@ -75,13 +76,14 @@ class DomRenderer extends core.NativeRenderer {
75
76
  }
76
77
  removeProperty(node, key, namespace) {
77
78
  if (namespace) {
78
- const NAMESPACE = DomRenderer.NAMESPACES;
79
- const [prefix, ...unqualifiedName] = key.split(/(?=[A-Z])/);
80
- let ns = DomRenderer.NAMESPACES[namespace];
81
- if (prefix === 'xmlns' || unqualifiedName.length && NAMESPACE[prefix]) {
82
- ns = NAMESPACE[prefix];
79
+ const prefix = 'xlink:';
80
+ if (key.startsWith(prefix)) {
81
+ const ns = key.substring(prefix.length);
82
+ node.removeAttributeNS(ns, key.substring(prefix.length));
83
+ }
84
+ else {
85
+ node.removeAttribute(key);
83
86
  }
84
- node.removeAttributeNS(ns, key);
85
87
  return;
86
88
  }
87
89
  if (key in node) {
@@ -95,9 +97,17 @@ class DomRenderer extends core.NativeRenderer {
95
97
  target.setAttribute('class', className);
96
98
  }
97
99
  setStyle(target, key, value) {
100
+ if (key.startsWith('--')) {
101
+ target.style.setProperty(key, value);
102
+ return;
103
+ }
98
104
  target.style[key] = value !== null && value !== void 0 ? value : '';
99
105
  }
100
106
  removeStyle(target, key) {
107
+ if (key.startsWith('--')) {
108
+ target.style.removeProperty(key);
109
+ return;
110
+ }
101
111
  target.style[key] = '';
102
112
  }
103
113
  listen(node, type, callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/platform-browser",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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",
@@ -14,7 +14,7 @@
14
14
  "license": "MIT",
15
15
  "keywords": [],
16
16
  "dependencies": {
17
- "@viewfly/core": "^1.1.2",
17
+ "@viewfly/core": "^1.1.6",
18
18
  "csstype": "^3.1.2"
19
19
  },
20
20
  "devDependencies": {
@@ -36,5 +36,5 @@
36
36
  "bugs": {
37
37
  "url": "https://github.com/viewfly/viewfly.git/issues"
38
38
  },
39
- "gitHead": "df4511ea7b631c5291da71b094c9da7d6d2d617f"
39
+ "gitHead": "381f112dffa12664d95ddc2c27603990c8f5c3ab"
40
40
  }
@@ -1,14 +1,14 @@
1
- import dts from 'rollup-plugin-dts'
2
-
3
- export default {
4
- input: 'src/public-api.ts',
5
- output: [
6
- {
7
- file: './bundles/index.d.ts',
8
- format: 'es'
9
- }
10
- ],
11
- plugins: [
12
- dts(),
13
- ]
14
- }
1
+ import dts from 'rollup-plugin-dts'
2
+
3
+ export default {
4
+ input: 'src/public-api.ts',
5
+ output: [
6
+ {
7
+ file: './bundles/index.d.ts',
8
+ format: 'es'
9
+ }
10
+ ],
11
+ plugins: [
12
+ dts(),
13
+ ]
14
+ }