@chamn/render 0.0.7 → 0.0.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chamn/render",
3
3
  "private": false,
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -11,13 +11,15 @@
11
11
  "scripts": {
12
12
  "start": "build-script",
13
13
  "build": "build-script --build",
14
+ "build:analyze": "build-script --build --analyze",
14
15
  "build:w": "build-script --build --watch",
15
16
  "lint": "eslint --ext .tsx,.ts src/",
16
17
  "prettier": "prettier --write ./src",
17
18
  "test": "jest"
18
19
  },
19
20
  "dependencies": {
20
- "@chamn/model": "0.0.7",
21
+ "@chamn/model": "0.0.9",
22
+ "cross-env": "^7.0.3",
21
23
  "html-tag-names": "^2.0.1",
22
24
  "loadjs": "4.3.0-rc1",
23
25
  "lodash-es": "^4.17.21",
@@ -27,9 +29,9 @@
27
29
  "zustand": "^4.1.5"
28
30
  },
29
31
  "devDependencies": {
30
- "@chamn/build-script": "0.0.7",
31
- "@chamn/demo-page": "0.0.7",
32
- "@chamn/material": "0.0.7",
32
+ "@chamn/build-script": "0.0.9",
33
+ "@chamn/demo-page": "0.0.9",
34
+ "@chamn/material": "0.0.9",
33
35
  "@types/loadjs": "^4.0.1",
34
36
  "@types/lodash-es": "^4.17.6",
35
37
  "@types/react": "^18.0.15",
@@ -38,5 +40,5 @@
38
40
  "react-router-dom": "^6.6.1"
39
41
  },
40
42
  "config": {},
41
- "gitHead": "0c7375f745549dc8f9903c725a209165907a7833"
43
+ "gitHead": "f073439ea704830a6f62146c916c2f0348c2e531"
42
44
  }
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './core/adapterReact';
3
3
  export * from './core/render';
4
4
  export * from './core/designReactRender';
5
5
  export * from './util/assetsLoader';
6
+ export * from './util';
@@ -45,19 +45,20 @@ export class AssetLoader {
45
45
  this._onSuccessList.forEach((el) => el());
46
46
  return;
47
47
  }
48
- // 在下一个事件循环执行,确保 onSuccess 和 onError 被注册
49
- setTimeout(() => {
48
+
49
+ return new Promise((resolve, reject) => {
50
+ // 在下一个事件循环执行,确保 onSuccess 和 onError 被注册
50
51
  loadjs.ready(ids, {
51
52
  success: () => {
52
53
  this._onSuccessList.forEach((el) => el());
54
+ resolve('');
53
55
  },
54
56
  error: (depsNotFound) => {
55
57
  this._onErrorList.forEach((el) => el(depsNotFound));
58
+ reject(depsNotFound);
56
59
  },
57
60
  });
58
- }, 0);
59
-
60
- return this;
61
+ });
61
62
  }
62
63
 
63
64
  onSuccess(cb: () => void) {
package/src/util/index.ts CHANGED
@@ -2,6 +2,7 @@ import { capitalize } from 'lodash-es';
2
2
  import { Component, createElement } from 'react';
3
3
  import { ContextType } from '../core/adapter';
4
4
  import { StoreManager } from '../core/storeManager';
5
+ import { AssetPackage } from '@chamn/model';
5
6
 
6
7
  export const isClass = function (val: any) {
7
8
  if (!val) {
@@ -127,3 +128,37 @@ export const getCSSTextValue = (cssObj: Record<string, string>) => {
127
128
  });
128
129
  return res;
129
130
  };
131
+
132
+ export const collectVariable = (assetPackages: AssetPackage[], win: Window) => {
133
+ const res: Record<string, any> = {};
134
+ assetPackages.forEach((el) => {
135
+ if (el.globalName) {
136
+ const target = (win as any)[el.globalName];
137
+ if (target) {
138
+ res[el.globalName] = target;
139
+ }
140
+ }
141
+ });
142
+ return res;
143
+ };
144
+
145
+ export const flatObject = (obj: Record<string, any>, level = 1) => {
146
+ let count = 0;
147
+ let currentObj = obj;
148
+ let newObj: Record<string, any> = {};
149
+ let res = {};
150
+ while (count < level) {
151
+ Object.keys(currentObj).forEach((key) => {
152
+ newObj = {
153
+ ...newObj,
154
+ ...currentObj[key],
155
+ };
156
+ });
157
+ res = newObj;
158
+ currentObj = newObj;
159
+ newObj = {};
160
+ count += 1;
161
+ }
162
+
163
+ return res;
164
+ };