@cuipengyu5/bling-renderer-core 0.0.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.
Files changed (93) hide show
  1. package/es/adapter/index.d.ts +24 -0
  2. package/es/adapter/index.js +95 -0
  3. package/es/components/Div.d.ts +2 -0
  4. package/es/components/Div.js +19 -0
  5. package/es/components/VisualDom/index.css +19 -0
  6. package/es/components/VisualDom/index.d.ts +3 -0
  7. package/es/components/VisualDom/index.js +44 -0
  8. package/es/context/index.d.ts +1 -0
  9. package/es/context/index.js +11 -0
  10. package/es/hoc/index.d.ts +7 -0
  11. package/es/hoc/index.js +90 -0
  12. package/es/hoc/leaf.d.ts +32 -0
  13. package/es/hoc/leaf.js +521 -0
  14. package/es/index.d.ts +7 -0
  15. package/es/index.js +9 -0
  16. package/es/renderer/addon.d.ts +2 -0
  17. package/es/renderer/addon.js +107 -0
  18. package/es/renderer/base.d.ts +13 -0
  19. package/es/renderer/base.js +1120 -0
  20. package/es/renderer/block.d.ts +2 -0
  21. package/es/renderer/block.js +43 -0
  22. package/es/renderer/component.d.ts +2 -0
  23. package/es/renderer/component.js +59 -0
  24. package/es/renderer/index.d.ts +8 -0
  25. package/es/renderer/index.js +8 -0
  26. package/es/renderer/page.d.ts +2 -0
  27. package/es/renderer/page.js +91 -0
  28. package/es/renderer/renderer.d.ts +2 -0
  29. package/es/renderer/renderer.js +230 -0
  30. package/es/renderer/temp.d.ts +2 -0
  31. package/es/renderer/temp.js +139 -0
  32. package/es/style.js +1 -0
  33. package/es/types/index.d.ts +275 -0
  34. package/es/types/index.js +1 -0
  35. package/es/utils/common.d.ts +119 -0
  36. package/es/utils/common.js +378 -0
  37. package/es/utils/data-helper.d.ts +74 -0
  38. package/es/utils/data-helper.js +300 -0
  39. package/es/utils/index.d.ts +3 -0
  40. package/es/utils/index.js +3 -0
  41. package/es/utils/is-use-loop.d.ts +2 -0
  42. package/es/utils/is-use-loop.js +16 -0
  43. package/es/utils/logger.d.ts +3 -0
  44. package/es/utils/logger.js +5 -0
  45. package/es/utils/request.d.ts +54 -0
  46. package/es/utils/request.js +209 -0
  47. package/lib/adapter/index.d.ts +24 -0
  48. package/lib/adapter/index.js +99 -0
  49. package/lib/components/Div.d.ts +2 -0
  50. package/lib/components/Div.js +24 -0
  51. package/lib/components/VisualDom/index.css +19 -0
  52. package/lib/components/VisualDom/index.d.ts +3 -0
  53. package/lib/components/VisualDom/index.js +49 -0
  54. package/lib/context/index.d.ts +1 -0
  55. package/lib/context/index.js +16 -0
  56. package/lib/hoc/index.d.ts +7 -0
  57. package/lib/hoc/index.js +95 -0
  58. package/lib/hoc/leaf.d.ts +32 -0
  59. package/lib/hoc/leaf.js +526 -0
  60. package/lib/index.d.ts +7 -0
  61. package/lib/index.js +34 -0
  62. package/lib/renderer/addon.d.ts +2 -0
  63. package/lib/renderer/addon.js +112 -0
  64. package/lib/renderer/base.d.ts +13 -0
  65. package/lib/renderer/base.js +1126 -0
  66. package/lib/renderer/block.d.ts +2 -0
  67. package/lib/renderer/block.js +48 -0
  68. package/lib/renderer/component.d.ts +2 -0
  69. package/lib/renderer/component.js +64 -0
  70. package/lib/renderer/index.d.ts +8 -0
  71. package/lib/renderer/index.js +18 -0
  72. package/lib/renderer/page.d.ts +2 -0
  73. package/lib/renderer/page.js +96 -0
  74. package/lib/renderer/renderer.d.ts +2 -0
  75. package/lib/renderer/renderer.js +235 -0
  76. package/lib/renderer/temp.d.ts +2 -0
  77. package/lib/renderer/temp.js +144 -0
  78. package/lib/style.js +1 -0
  79. package/lib/types/index.d.ts +275 -0
  80. package/lib/types/index.js +3 -0
  81. package/lib/utils/common.d.ts +119 -0
  82. package/lib/utils/common.js +409 -0
  83. package/lib/utils/data-helper.d.ts +74 -0
  84. package/lib/utils/data-helper.js +306 -0
  85. package/lib/utils/index.d.ts +3 -0
  86. package/lib/utils/index.js +21 -0
  87. package/lib/utils/is-use-loop.d.ts +2 -0
  88. package/lib/utils/is-use-loop.js +19 -0
  89. package/lib/utils/logger.d.ts +3 -0
  90. package/lib/utils/logger.js +9 -0
  91. package/lib/utils/request.d.ts +54 -0
  92. package/lib/utils/request.js +217 -0
  93. package/package.json +64 -0
@@ -0,0 +1,378 @@
1
+ /* eslint-disable no-console */
2
+ /* eslint-disable no-new-func */
3
+ import logger from './logger';
4
+ import { isI18nData, isJSExpression } from '@alilc/lowcode-utils';
5
+ import { isEmpty } from 'lodash';
6
+ import IntlMessageFormat from 'intl-messageformat';
7
+ import pkg from '../../package.json';
8
+ window.sdkVersion = pkg.version;
9
+ export { pick, isEqualWith as deepEqual, cloneDeep as clone, isEmpty, throttle, debounce } from 'lodash';
10
+ var EXPRESSION_TYPE = {
11
+ JSEXPRESSION: 'JSExpression',
12
+ JSFUNCTION: 'JSFunction',
13
+ JSSLOT: 'JSSlot',
14
+ JSBLOCK: 'JSBlock',
15
+ I18N: 'i18n'
16
+ };
17
+
18
+ /**
19
+ * check if schema passed in is a valid schema
20
+ * @name isSchema
21
+ * @returns boolean
22
+ */
23
+ export function isSchema(schema) {
24
+ if (isEmpty(schema)) {
25
+ return false;
26
+ }
27
+ // Leaf and Slot should be valid
28
+ if (schema.componentName === 'Leaf' || schema.componentName === 'Slot') {
29
+ return true;
30
+ }
31
+ if (Array.isArray(schema)) {
32
+ return schema.every(function (item) {
33
+ return isSchema(item);
34
+ });
35
+ }
36
+ // check if props is valid
37
+ var isValidProps = function isValidProps(props) {
38
+ if (!props) {
39
+ return false;
40
+ }
41
+ if (isJSExpression(props)) {
42
+ return true;
43
+ }
44
+ return typeof schema.props === 'object' && !Array.isArray(props);
45
+ };
46
+ return !!(schema.componentName && isValidProps(schema.props));
47
+ }
48
+
49
+ /**
50
+ * check if schema passed in is a container type, including : Component Block Page
51
+ * @param schema
52
+ * @returns boolean
53
+ */
54
+ export function isFileSchema(schema) {
55
+ if (!isSchema(schema)) {
56
+ return false;
57
+ }
58
+ return ['Page', 'Block', 'Component'].includes(schema.componentName);
59
+ }
60
+
61
+ /**
62
+ * check if current page is nested within another page with same host
63
+ * @returns boolean
64
+ */
65
+ export function inSameDomain() {
66
+ try {
67
+ return window.parent !== window && window.parent.location.host === window.location.host;
68
+ } catch (e) {
69
+ return false;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * get css styled name from schema`s fileName
75
+ * FileName -> lce-file-name
76
+ * @returns string
77
+ */
78
+ export function getFileCssName(fileName) {
79
+ if (!fileName) {
80
+ return;
81
+ }
82
+ var name = fileName.replace(/([A-Z])/g, '-$1').toLowerCase();
83
+ return ("lce-" + name).split('-').filter(function (p) {
84
+ return !!p;
85
+ }).join('-');
86
+ }
87
+
88
+ /**
89
+ * check if a object is type of JSSlot
90
+ * @returns string
91
+ */
92
+ export function isJSSlot(obj) {
93
+ if (!obj) {
94
+ return false;
95
+ }
96
+ if (typeof obj !== 'object' || Array.isArray(obj)) {
97
+ return false;
98
+ }
99
+
100
+ // Compatible with the old protocol JSBlock
101
+ return [EXPRESSION_TYPE.JSSLOT, EXPRESSION_TYPE.JSBLOCK].includes(obj.type);
102
+ }
103
+
104
+ /**
105
+ * get value from an object
106
+ * @returns string
107
+ */
108
+ export function getValue(obj, path, defaultValue) {
109
+ if (defaultValue === void 0) {
110
+ defaultValue = {};
111
+ }
112
+ // array is not valid type, return default value
113
+ if (Array.isArray(obj)) {
114
+ return defaultValue;
115
+ }
116
+ if (isEmpty(obj) || typeof obj !== 'object') {
117
+ return defaultValue;
118
+ }
119
+ var res = path.split('.').reduce(function (pre, cur) {
120
+ return pre && pre[cur];
121
+ }, obj);
122
+ if (res === undefined) {
123
+ return defaultValue;
124
+ }
125
+ return res;
126
+ }
127
+
128
+ /**
129
+ * 用于处理国际化字符串
130
+ * @param {*} key 语料标识
131
+ * @param {*} values 字符串模版变量
132
+ * @param {*} locale 国际化标识,例如 zh-CN、en-US
133
+ * @param {*} messages 国际化语言包
134
+ */
135
+ export function getI18n(key, values, locale, messages) {
136
+ if (values === void 0) {
137
+ values = {};
138
+ }
139
+ if (locale === void 0) {
140
+ locale = 'zh-CN';
141
+ }
142
+ if (messages === void 0) {
143
+ messages = {};
144
+ }
145
+ if (!messages || !messages[locale] || !messages[locale][key]) {
146
+ return '';
147
+ }
148
+ var formater = new IntlMessageFormat(messages[locale][key], locale);
149
+ return formater.format(values);
150
+ }
151
+
152
+ /**
153
+ * 判断当前组件是否能够设置ref
154
+ * @param {*} Comp 需要判断的组件
155
+ */
156
+ export function canAcceptsRef(Comp) {
157
+ var _Comp$prototype, _Comp$prototype2;
158
+ var hasSymbol = typeof Symbol === 'function' && Symbol["for"];
159
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol["for"]('react.forward_ref') : 0xead0;
160
+ // eslint-disable-next-line max-len
161
+ return (Comp === null || Comp === void 0 ? void 0 : Comp.$$typeof) === REACT_FORWARD_REF_TYPE || (Comp === null || Comp === void 0 ? void 0 : (_Comp$prototype = Comp.prototype) === null || _Comp$prototype === void 0 ? void 0 : _Comp$prototype.isReactComponent) || (Comp === null || Comp === void 0 ? void 0 : (_Comp$prototype2 = Comp.prototype) === null || _Comp$prototype2 === void 0 ? void 0 : _Comp$prototype2.setState) || Comp._forwardRef;
162
+ }
163
+
164
+ /**
165
+ * transform array to a object
166
+ * @param arr array to be transformed
167
+ * @param key key of array item, which`s value will be used as key in result map
168
+ * @param overwrite overwrite existing item in result or not
169
+ * @returns object result map
170
+ */
171
+ export function transformArrayToMap(arr, key, overwrite) {
172
+ if (overwrite === void 0) {
173
+ overwrite = true;
174
+ }
175
+ if (isEmpty(arr) || !Array.isArray(arr)) {
176
+ return {};
177
+ }
178
+ var res = {};
179
+ arr.forEach(function (item) {
180
+ var curKey = item[key];
181
+ if (item[key] === undefined) {
182
+ return;
183
+ }
184
+ if (res[curKey] && !overwrite) {
185
+ return;
186
+ }
187
+ res[curKey] = item;
188
+ });
189
+ return res;
190
+ }
191
+
192
+ /**
193
+ * transform string to a function
194
+ * @param str function in string form
195
+ * @returns funtion
196
+ */
197
+ export function transformStringToFunction(str) {
198
+ if (typeof str !== 'string') {
199
+ return str;
200
+ }
201
+ if (inSameDomain() && window.parent.__newFunc) {
202
+ return window.parent.__newFunc("\"use strict\"; return " + str)();
203
+ } else {
204
+ return new Function("\"use strict\"; return " + str)();
205
+ }
206
+ }
207
+
208
+ /**
209
+ * 对象类型JSExpression,支持省略this
210
+ * @param str expression in string form
211
+ * @param self scope object
212
+ * @returns funtion
213
+ */
214
+
215
+ function parseExpression(a, b, c) {
216
+ if (c === void 0) {
217
+ c = false;
218
+ }
219
+ var str;
220
+ var self;
221
+ var thisRequired;
222
+ var logScope;
223
+ if (typeof a === 'object' && b === undefined) {
224
+ str = a.str;
225
+ self = a.self;
226
+ thisRequired = a.thisRequired;
227
+ logScope = a.logScope;
228
+ } else {
229
+ str = a;
230
+ self = b;
231
+ thisRequired = c;
232
+ }
233
+ try {
234
+ var contextArr = ['"use strict";', 'var __self = arguments[0];'];
235
+ contextArr.push('return ');
236
+ var tarStr;
237
+ tarStr = (str.value || '').trim();
238
+
239
+ // NOTE: use __self replace 'this' in the original function str
240
+ // may be wrong in extreme case which contains '__self' already
241
+ tarStr = tarStr.replace(/this(\W|$)/g, function (_a, b) {
242
+ return "__self" + b;
243
+ });
244
+ tarStr = contextArr.join('\n') + tarStr;
245
+
246
+ // 默认调用顶层窗口的parseObj, 保障new Function的window对象是顶层的window对象
247
+ if (inSameDomain() && window.parent.__newFunc) {
248
+ return window.parent.__newFunc(tarStr)(self);
249
+ }
250
+ var code = "with(" + (thisRequired ? '{}' : '$scope || {}') + ") { " + tarStr + " }";
251
+ return new Function('$scope', code)(self);
252
+ } catch (err) {
253
+ var _self$__self, _self;
254
+ logger.error((logScope || '') + " parseExpression.error", err, str, (_self$__self = (_self = self) === null || _self === void 0 ? void 0 : _self.__self) !== null && _self$__self !== void 0 ? _self$__self : self);
255
+ return undefined;
256
+ }
257
+ }
258
+ export { parseExpression };
259
+ export function parseThisRequiredExpression(str, self) {
260
+ return parseExpression(str, self, true);
261
+ }
262
+
263
+ /**
264
+ * capitalize first letter
265
+ * @param word string to be proccessed
266
+ * @returns string capitalized string
267
+ */
268
+ export function capitalizeFirstLetter(word) {
269
+ if (!word || !isString(word) || word.length === 0) {
270
+ return word;
271
+ }
272
+ return word[0].toUpperCase() + word.slice(1);
273
+ }
274
+
275
+ /**
276
+ * check str passed in is a string type of not
277
+ * @param str obj to be checked
278
+ * @returns boolean
279
+ */
280
+ export function isString(str) {
281
+ return {}.toString.call(str) === '[object String]';
282
+ }
283
+
284
+ /**
285
+ * check if obj is type of variable structure
286
+ * @param obj object to be checked
287
+ * @returns boolean
288
+ */
289
+ export function isVariable(obj) {
290
+ if (!obj || Array.isArray(obj)) {
291
+ return false;
292
+ }
293
+ return typeof obj === 'object' && (obj === null || obj === void 0 ? void 0 : obj.type) === 'variable';
294
+ }
295
+
296
+ /**
297
+ * 将 i18n 结构,降级解释为对 i18n 接口的调用
298
+ * @param i18nInfo object
299
+ * @param self context
300
+ */
301
+ export function parseI18n(i18nInfo, self) {
302
+ return parseExpression({
303
+ type: EXPRESSION_TYPE.JSEXPRESSION,
304
+ value: "this.i18n('" + i18nInfo.key + "')"
305
+ }, self);
306
+ }
307
+
308
+ /**
309
+ * for each key in targetObj, run fn with the value of the value, and the context paased in.
310
+ * @param targetObj object that keys will be for each
311
+ * @param fn function that process each item
312
+ * @param context
313
+ */
314
+ export function forEach(targetObj, fn, context) {
315
+ if (!targetObj || Array.isArray(targetObj) || isString(targetObj) || typeof targetObj !== 'object') {
316
+ return;
317
+ }
318
+ Object.keys(targetObj).forEach(function (key) {
319
+ return fn.call(context, targetObj[key], key);
320
+ });
321
+ }
322
+ export function parseData(schema, self, options) {
323
+ if (options === void 0) {
324
+ options = {};
325
+ }
326
+ if (isJSExpression(schema)) {
327
+ return parseExpression({
328
+ str: schema,
329
+ self: self,
330
+ thisRequired: options.thisRequiredInJSE,
331
+ logScope: options.logScope
332
+ });
333
+ } else if (isI18nData(schema)) {
334
+ return parseI18n(schema, self);
335
+ } else if (typeof schema === 'string') {
336
+ return schema.trim();
337
+ } else if (Array.isArray(schema)) {
338
+ return schema.map(function (item) {
339
+ return parseData(item, self, options);
340
+ });
341
+ } else if (typeof schema === 'function') {
342
+ return schema.bind(self);
343
+ } else if (typeof schema === 'object') {
344
+ // 对于undefined及null直接返回
345
+ if (!schema) {
346
+ return schema;
347
+ }
348
+ var res = {};
349
+ forEach(schema, function (val, key) {
350
+ if (key.startsWith('__')) {
351
+ return;
352
+ }
353
+ res[key] = parseData(val, self, options);
354
+ });
355
+ return res;
356
+ }
357
+ return schema;
358
+ }
359
+
360
+ /**
361
+ * process params for using in a url query
362
+ * @param obj params to be processed
363
+ * @returns string
364
+ */
365
+ export function serializeParams(obj) {
366
+ var result = [];
367
+ forEach(obj, function (val, key) {
368
+ if (val === null || val === undefined || val === '') {
369
+ return;
370
+ }
371
+ if (typeof val === 'object') {
372
+ result.push(key + "=" + encodeURIComponent(JSON.stringify(val)));
373
+ } else {
374
+ result.push(key + "=" + encodeURIComponent(val));
375
+ }
376
+ });
377
+ return result.join('&');
378
+ }
@@ -0,0 +1,74 @@
1
+ import { DataSource, IRendererAppHelper } from '../types';
2
+ type DataSourceType = 'fetch' | 'jsonp';
3
+ /**
4
+ * do request for standard DataSourceType
5
+ * @param {DataSourceType} type type of DataSourceItem
6
+ * @param {any} options
7
+ */
8
+ export declare function doRequest(type: DataSourceType, options: any): Promise<unknown>;
9
+ export declare class DataHelper {
10
+ /**
11
+ * host object that will be "this" object when excuting dataHandler
12
+ *
13
+ * @type {*}
14
+ * @memberof DataHelper
15
+ */
16
+ host: any;
17
+ /**
18
+ * data source config
19
+ *
20
+ * @type {DataSource}
21
+ * @memberof DataHelper
22
+ */
23
+ config: DataSource;
24
+ /**
25
+ * a parser function which will be called to process config data
26
+ * which eventually will call common/utils.processData() to process data
27
+ * (originalConfig) => parsedConfig
28
+ * @type {*}
29
+ * @memberof DataHelper
30
+ */
31
+ parser: any;
32
+ /**
33
+ * config.list
34
+ *
35
+ * @type {any[]}
36
+ * @memberof DataHelper
37
+ */
38
+ ajaxList: any[];
39
+ ajaxMap: any;
40
+ dataSourceMap: any;
41
+ appHelper: IRendererAppHelper;
42
+ constructor(comp: any, config: DataSource, appHelper: IRendererAppHelper, parser: any);
43
+ updateConfig(config?: {}): any;
44
+ generateDataSourceMap(): any;
45
+ updateDataSourceMap(id: string, data: any, error: any): void;
46
+ /**
47
+ * get all dataSourceItems which marked as isInit === true
48
+ * @private
49
+ * @returns
50
+ * @memberof DataHelper
51
+ */
52
+ getInitDataSourseConfigs(): any;
53
+ /**
54
+ * process all dataSourceItems which marked as isInit === true, and get dataSource request results.
55
+ * @public
56
+ * @returns
57
+ * @memberof DataHelper
58
+ */
59
+ getInitData(): Promise<any>;
60
+ getDataSource(id: string, params: any, otherOptions: any, callback: any): Promise<any>;
61
+ asyncDataHandler(asyncDataList: any[]): Promise<unknown>;
62
+ /**
63
+ * process data using dataHandler
64
+ *
65
+ * @param {(string | null)} id request id, will be used in error message, can be null
66
+ * @param {*} dataHandler
67
+ * @param {*} data
68
+ * @param {*} error
69
+ * @returns
70
+ * @memberof DataHelper
71
+ */
72
+ handleData(id: string | null, dataHandler: any, data: any, error: any): any;
73
+ }
74
+ export {};