@viewfly/core 0.0.1-alpha.10 → 0.0.1-alpha.12

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/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  Viewfly
2
2
  ================================
3
3
 
4
- Viewfly 是一个简单、数据驱动的前端视图库,完整文档请参考官方网站:[viewfly.org](https://viewfly.org)
4
+ Viewfly 是一个简单、数据驱动的前端视图库。此包为 Viewfly 的内核实现,要开发完整的应该的应用,还需要结合 `@viewfly/platform-browser` 包,才能在浏览器运行。
5
+
6
+ 完整文档请参考官方网站:[viewfly.org](https://viewfly.org)
@@ -6,3 +6,4 @@ export interface ObjectChanges {
6
6
  export declare const refKey = "ref";
7
7
  export declare function getObjectChanges(newProps?: Record<string, any>, oldProps?: Record<string, any>): ObjectChanges;
8
8
  export declare function classToString(config: unknown): any;
9
+ export declare function styleToObject(style: string | Record<string, any>): Record<string, any>;
@@ -227,7 +227,7 @@ class Component extends ReflectiveInjector {
227
227
  * }
228
228
  * ```
229
229
  */
230
- function onMount(callback) {
230
+ function onMounted(callback) {
231
231
  const component = getSetupContext();
232
232
  component.mountCallbacks.push(callback);
233
233
  }
@@ -601,6 +601,19 @@ function classToString(config) {
601
601
  return classes.join(' ');
602
602
  }
603
603
  }
604
+ function styleToObject(style) {
605
+ if (typeof style !== 'string') {
606
+ return style;
607
+ }
608
+ const obj = {};
609
+ style.split(';').map(s => s.split(':')).forEach(v => {
610
+ if (!v[0] || !v[1]) {
611
+ return;
612
+ }
613
+ obj[v[0].trim()] = v[1].trim();
614
+ });
615
+ return obj;
616
+ }
604
617
 
605
618
  class RootComponentRef {
606
619
  }
@@ -796,7 +809,7 @@ let Renderer = class Renderer {
796
809
  });
797
810
  }
798
811
  };
799
- while (newAtom && !newAtom.nativeNode) {
812
+ while (newAtom) {
800
813
  this.createChanges(newAtom, expectIndex, oldChildren, changeCommits);
801
814
  newAtom = newAtom.sibling;
802
815
  expectIndex++;
@@ -1003,7 +1016,7 @@ let Renderer = class Renderer {
1003
1016
  continue;
1004
1017
  }
1005
1018
  if (key === 'style') {
1006
- const style = props.style;
1019
+ const style = styleToObject(props.style);
1007
1020
  Object.keys(style).forEach(key => {
1008
1021
  this.nativeRenderer.setStyle(nativeNode, key, style[key]);
1009
1022
  });
@@ -1045,7 +1058,7 @@ let Renderer = class Renderer {
1045
1058
  continue;
1046
1059
  }
1047
1060
  if (key === 'style') {
1048
- Object.keys(value).forEach(styleName => {
1061
+ Object.keys(styleToObject(value)).forEach(styleName => {
1049
1062
  this.nativeRenderer.removeStyle(nativeNode, styleName);
1050
1063
  });
1051
1064
  continue;
@@ -1075,7 +1088,7 @@ let Renderer = class Renderer {
1075
1088
  continue;
1076
1089
  }
1077
1090
  if (key === 'style') {
1078
- const styleChanges = getObjectChanges(newValue, oldValue);
1091
+ const styleChanges = getObjectChanges(styleToObject(newValue), styleToObject(oldValue));
1079
1092
  for (const [styleName] of styleChanges.remove) {
1080
1093
  this.nativeRenderer.removeStyle(nativeNode, styleName);
1081
1094
  }
@@ -1110,8 +1123,9 @@ let Renderer = class Renderer {
1110
1123
  continue;
1111
1124
  }
1112
1125
  if (key === 'style') {
1113
- Object.keys(value).forEach(styleName => {
1114
- this.nativeRenderer.setStyle(nativeNode, styleName, value[styleName]);
1126
+ const styleObj = styleToObject(value);
1127
+ Object.keys(styleObj).forEach(styleName => {
1128
+ this.nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName]);
1115
1129
  });
1116
1130
  continue;
1117
1131
  }
@@ -1133,8 +1147,8 @@ let Renderer = class Renderer {
1133
1147
  };
1134
1148
  }
1135
1149
  applyRefs(refs, nativeNode, binding) {
1136
- refs = Array.isArray(refs) ? refs : [refs];
1137
- for (const item of refs) {
1150
+ const refList = Array.isArray(refs) ? refs : [refs];
1151
+ for (const item of refList) {
1138
1152
  if (item instanceof Ref) {
1139
1153
  binding ? item.bind(nativeNode) : item.unBind(nativeNode);
1140
1154
  }
@@ -1160,7 +1174,6 @@ class Viewfly extends ReflectiveInjector {
1160
1174
  provide: RootComponentRef,
1161
1175
  useFactory: () => {
1162
1176
  return {
1163
- host: config.host,
1164
1177
  component: this.rootComponent
1165
1178
  };
1166
1179
  }
@@ -1179,8 +1192,11 @@ class Viewfly extends ReflectiveInjector {
1179
1192
  }
1180
1193
  /**
1181
1194
  * 启动 Viewfly
1195
+ * @param host 应用根节点
1182
1196
  */
1183
- run() {
1197
+ mount(host) {
1198
+ const rootComponentRef = this.get(RootComponentRef);
1199
+ rootComponentRef.host = host;
1184
1200
  const renderer = this.get(Renderer);
1185
1201
  renderer.render();
1186
1202
  if (this.config.autoUpdate === false) {
@@ -1209,4 +1225,4 @@ class Viewfly extends ReflectiveInjector {
1209
1225
  }
1210
1226
  }
1211
1227
 
1212
- export { Component, Fragment, JSXComponent, JSXElement, JSXText, NativeRenderer, Ref, Renderer, RootComponent, RootComponentRef, Viewfly, inject, jsx, jsxs, makeError, onDestroy, onMount, onPropsChanged, onUpdated, provide, useDerived, useEffect, useRef, useSignal };
1228
+ export { Component, Fragment, JSXComponent, JSXElement, JSXText, NativeRenderer, Ref, Renderer, RootComponent, RootComponentRef, Viewfly, inject, jsx, jsxs, makeError, onDestroy, onMounted, onPropsChanged, onUpdated, provide, useDerived, useEffect, useRef, useSignal };
package/bundles/index.js CHANGED
@@ -228,7 +228,7 @@ class Component extends di.ReflectiveInjector {
228
228
  * }
229
229
  * ```
230
230
  */
231
- function onMount(callback) {
231
+ function onMounted(callback) {
232
232
  const component = getSetupContext();
233
233
  component.mountCallbacks.push(callback);
234
234
  }
@@ -602,6 +602,19 @@ function classToString(config) {
602
602
  return classes.join(' ');
603
603
  }
604
604
  }
605
+ function styleToObject(style) {
606
+ if (typeof style !== 'string') {
607
+ return style;
608
+ }
609
+ const obj = {};
610
+ style.split(';').map(s => s.split(':')).forEach(v => {
611
+ if (!v[0] || !v[1]) {
612
+ return;
613
+ }
614
+ obj[v[0].trim()] = v[1].trim();
615
+ });
616
+ return obj;
617
+ }
605
618
 
606
619
  class RootComponentRef {
607
620
  }
@@ -797,7 +810,7 @@ exports.Renderer = class Renderer {
797
810
  });
798
811
  }
799
812
  };
800
- while (newAtom && !newAtom.nativeNode) {
813
+ while (newAtom) {
801
814
  this.createChanges(newAtom, expectIndex, oldChildren, changeCommits);
802
815
  newAtom = newAtom.sibling;
803
816
  expectIndex++;
@@ -1004,7 +1017,7 @@ exports.Renderer = class Renderer {
1004
1017
  continue;
1005
1018
  }
1006
1019
  if (key === 'style') {
1007
- const style = props.style;
1020
+ const style = styleToObject(props.style);
1008
1021
  Object.keys(style).forEach(key => {
1009
1022
  this.nativeRenderer.setStyle(nativeNode, key, style[key]);
1010
1023
  });
@@ -1046,7 +1059,7 @@ exports.Renderer = class Renderer {
1046
1059
  continue;
1047
1060
  }
1048
1061
  if (key === 'style') {
1049
- Object.keys(value).forEach(styleName => {
1062
+ Object.keys(styleToObject(value)).forEach(styleName => {
1050
1063
  this.nativeRenderer.removeStyle(nativeNode, styleName);
1051
1064
  });
1052
1065
  continue;
@@ -1076,7 +1089,7 @@ exports.Renderer = class Renderer {
1076
1089
  continue;
1077
1090
  }
1078
1091
  if (key === 'style') {
1079
- const styleChanges = getObjectChanges(newValue, oldValue);
1092
+ const styleChanges = getObjectChanges(styleToObject(newValue), styleToObject(oldValue));
1080
1093
  for (const [styleName] of styleChanges.remove) {
1081
1094
  this.nativeRenderer.removeStyle(nativeNode, styleName);
1082
1095
  }
@@ -1111,8 +1124,9 @@ exports.Renderer = class Renderer {
1111
1124
  continue;
1112
1125
  }
1113
1126
  if (key === 'style') {
1114
- Object.keys(value).forEach(styleName => {
1115
- this.nativeRenderer.setStyle(nativeNode, styleName, value[styleName]);
1127
+ const styleObj = styleToObject(value);
1128
+ Object.keys(styleObj).forEach(styleName => {
1129
+ this.nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName]);
1116
1130
  });
1117
1131
  continue;
1118
1132
  }
@@ -1134,8 +1148,8 @@ exports.Renderer = class Renderer {
1134
1148
  };
1135
1149
  }
1136
1150
  applyRefs(refs, nativeNode, binding) {
1137
- refs = Array.isArray(refs) ? refs : [refs];
1138
- for (const item of refs) {
1151
+ const refList = Array.isArray(refs) ? refs : [refs];
1152
+ for (const item of refList) {
1139
1153
  if (item instanceof Ref) {
1140
1154
  binding ? item.bind(nativeNode) : item.unBind(nativeNode);
1141
1155
  }
@@ -1161,7 +1175,6 @@ class Viewfly extends di.ReflectiveInjector {
1161
1175
  provide: RootComponentRef,
1162
1176
  useFactory: () => {
1163
1177
  return {
1164
- host: config.host,
1165
1178
  component: this.rootComponent
1166
1179
  };
1167
1180
  }
@@ -1180,8 +1193,11 @@ class Viewfly extends di.ReflectiveInjector {
1180
1193
  }
1181
1194
  /**
1182
1195
  * 启动 Viewfly
1196
+ * @param host 应用根节点
1183
1197
  */
1184
- run() {
1198
+ mount(host) {
1199
+ const rootComponentRef = this.get(RootComponentRef);
1200
+ rootComponentRef.host = host;
1185
1201
  const renderer = this.get(exports.Renderer);
1186
1202
  renderer.render();
1187
1203
  if (this.config.autoUpdate === false) {
@@ -1225,7 +1241,7 @@ exports.jsx = jsx;
1225
1241
  exports.jsxs = jsxs;
1226
1242
  exports.makeError = makeError;
1227
1243
  exports.onDestroy = onDestroy;
1228
- exports.onMount = onMount;
1244
+ exports.onMounted = onMounted;
1229
1245
  exports.onPropsChanged = onPropsChanged;
1230
1246
  exports.onUpdated = onUpdated;
1231
1247
  exports.provide = provide;
@@ -61,7 +61,7 @@ export interface PropsChangedCallback<T extends Props<any>> {
61
61
  * }
62
62
  * ```
63
63
  */
64
- export declare function onMount(callback: LifeCycleCallback): void;
64
+ export declare function onMounted(callback: LifeCycleCallback): void;
65
65
  /**
66
66
  * 当组件视图更新后调用
67
67
  * @param callback
@@ -6,8 +6,6 @@ export type RootNode = JSXElement | JSXComponent;
6
6
  * Viewfly 配置项
7
7
  */
8
8
  export interface Config {
9
- /** 应用根节点 */
10
- host: NativeNode;
11
9
  /** Viewfly IoC 容器中提供者集合 */
12
10
  providers?: Provider[];
13
11
  /** 是否自动更新视图 */
@@ -28,8 +26,9 @@ export declare class Viewfly extends ReflectiveInjector {
28
26
  constructor(config: Config);
29
27
  /**
30
28
  * 启动 Viewfly
29
+ * @param host 应用根节点
31
30
  */
32
- run(): void;
31
+ mount(host: NativeNode): void;
33
32
  /**
34
33
  * 销毁 Viewfly 实例
35
34
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.12",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -37,5 +37,5 @@
37
37
  "bugs": {
38
38
  "url": "https://github.com/viewfly/viewfly.git/issues"
39
39
  },
40
- "gitHead": "6e542df7602aec6a451b2db9a89928ad8bb9f05a"
40
+ "gitHead": "e5fdc69779bbfd6a1128b98a30d8732dbda7fcd3"
41
41
  }