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