@cloudbase/framework-plugin-low-code 1.0.3-beta.7 → 1.0.3

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 (59) hide show
  1. package/lib/builder/mp/lowcode.d.ts.map +1 -1
  2. package/lib/builder/mp/lowcode.js +3 -7
  3. package/lib/builder/service/builder/generate.d.ts.map +1 -1
  4. package/lib/builder/service/builder/generate.js +3 -0
  5. package/lib/generator/core/generate.d.ts.map +1 -1
  6. package/lib/generator/core/generate.js +11 -17
  7. package/lib/utils/dataSource.d.ts +4 -0
  8. package/lib/utils/dataSource.d.ts.map +1 -1
  9. package/lib/utils/dataSource.js +27 -12
  10. package/lib/weapps-core/utils/file.d.ts +1 -1
  11. package/package.json +3 -3
  12. package/template/src/app/common.js +0 -13
  13. package/template/src/app/global-api.js +0 -132
  14. package/template/src/app/handlers.js +0 -13
  15. package/template/src/app/material-actions.js +0 -16
  16. package/template/src/app/mountAppApis.js +0 -25
  17. package/template/src/app/mountMpApis.js +0 -4
  18. package/template/src/datasources/config.js.tpl +0 -27
  19. package/template/src/datasources/dataset-profiles.js.tpl +0 -5
  20. package/template/src/datasources/datasource-profiles.js.tpl +0 -4
  21. package/template/src/datasources/index.js.tpl +0 -27
  22. package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -536
  23. package/template/src/handlers/HotAreas.js +0 -36
  24. package/template/src/handlers/PositionHandler.jsx +0 -8
  25. package/template/src/handlers/actionHandler/utils.js +0 -154
  26. package/template/src/handlers/componentEventActionEmitter.js +0 -29
  27. package/template/src/handlers/componentNodeMap.js +0 -24
  28. package/template/src/handlers/controller.js +0 -5
  29. package/template/src/handlers/emitComponentEvent.js +0 -8
  30. package/template/src/handlers/eventListener/componentEventListener.js +0 -15
  31. package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
  32. package/template/src/handlers/eventListener/index.js +0 -29
  33. package/template/src/handlers/eventListener/pageEventListener.js +0 -11
  34. package/template/src/handlers/eventListener/types.js +0 -32
  35. package/template/src/handlers/hooks/index.js +0 -15
  36. package/template/src/handlers/initWebEnv.js +0 -4
  37. package/template/src/handlers/injectStyle.js +0 -14
  38. package/template/src/handlers/instanceMap.js +0 -39
  39. package/template/src/handlers/lifecycle.js +0 -222
  40. package/template/src/handlers/render.jsx +0 -170
  41. package/template/src/handlers/utils/common.js +0 -298
  42. package/template/src/handlers/utils/eventProxy.js +0 -64
  43. package/template/src/handlers/utils/events.js +0 -8
  44. package/template/src/handlers/utils/index.js +0 -4
  45. package/template/src/handlers/utils/widgets.js +0 -307
  46. package/template/src/index.jsx +0 -185
  47. package/template/src/index.less +0 -119
  48. package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
  49. package/template/src/pages/app.tpl +0 -200
  50. package/template/src/pages/composite.tpl +0 -171
  51. package/template/src/router/index.tpl +0 -29
  52. package/template/src/store/computed.js +0 -11
  53. package/template/src/store/index.js +0 -40
  54. package/template/src/utils/formatEnum.js +0 -42
  55. package/template/src/utils/history.js +0 -66
  56. package/template/src/utils/index.js +0 -82
  57. package/template/src/utils/kbone.js +0 -18
  58. package/template/src/utils/monitor-jssdk.min.js +0 -763
  59. package/template/src/utils/request.js +0 -5
@@ -1,536 +0,0 @@
1
- import * as React from 'react';
2
- import { useContext, useCallback, createContext, useRef } from 'react';
3
- import { observer } from 'mobx-react-lite';
4
- import { emitEvent } from '../actionHandler/utils';
5
- import { translateStyleToRem } from '@tcwd/weapps-core';
6
- import { get, set } from 'lodash';
7
- import { $page } from '../../app/global-api';
8
- import { getDom } from '../utils/widgets';
9
- import { checkVisible } from '../../utils/index';
10
- import { getComponentChildren, generateSlotMetaMap } from '../render';
11
-
12
- export const ForContext = createContext({});
13
-
14
- function generateSlotMap(slots, forContext = undefined) {
15
- let map = {};
16
- Object.keys(slots).forEach((slotProp) => {
17
- let meta = slots[slotProp];
18
- if (meta.type === 'HOC') {
19
- set(map, slotProp, meta.node);
20
- } else {
21
- const Element = meta.node;
22
- if (forContext) {
23
- set(
24
- map,
25
- slotProp,
26
- <ForContext.Provider value={forContext}>
27
- <Element />
28
- </ForContext.Provider>,
29
- );
30
- } else {
31
- set(map, slotProp, <Element />);
32
- }
33
- }
34
- });
35
- return map;
36
- }
37
-
38
- function getSafeComponentProps({ style, classNameList }) {
39
- const componentProps = {};
40
-
41
- if (classNameList.length) {
42
- componentProps.className = classNameList.join(' ');
43
- }
44
-
45
- if (style && Object.keys(style).length) {
46
- componentProps.style = style;
47
- }
48
- return componentProps;
49
- }
50
-
51
- // TODO: 需要不断移除 dataBinds(style/classList)
52
- function getBindData({ widgetData, forItems, scopeContext, codeContext, commonStyle = {}, classNameList = [] }) {
53
- // bindData
54
- if (Array.isArray(widgetData)) {
55
- widgetData =
56
- forItems.forIndexes === void 0 || widgetData.length === 0
57
- ? {}
58
- : get(widgetData, getForIndexes(forItems, widgetData));
59
- }
60
- widgetData = widgetData || {};
61
- const fieldData = { ...widgetData };
62
-
63
- const isRootNode = widgetData && !widgetData.parent;
64
- const isInComposite = !!codeContext;
65
-
66
- // 再次计算 scope value
67
- for (let key in fieldData) {
68
- if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
69
- const value = fieldData[key];
70
- if (value && value.__type === 'scopedValue') {
71
- try {
72
- fieldData[key] = value.getValue(scopeContext);
73
- } catch (e) {
74
- console.warn(`Error computing data bind '${key}' error:`, e);
75
- fieldData[key] = '';
76
- }
77
- }
78
- }
79
- }
80
-
81
- // bindStyle
82
- let bindStyle = fieldData.style || {};
83
- // 复合组件第一层需要将最外层样式 style 挂到节点上
84
- let cssStyle = commonStyle || {};
85
- if (isInComposite && isRootNode) {
86
- cssStyle = {
87
- ...cssStyle,
88
- ...(codeContext.$WEAPPS_COMP.props?.style || {}),
89
- };
90
- bindStyle = {
91
- ...bindStyle,
92
- ...(codeContext.$WEAPPS_COMP.props?.style || {}),
93
- };
94
- }
95
- const finalStyle = getFinalStyle(cssStyle, bindStyle);
96
-
97
- // bindClassList
98
- const bindClassList = fieldData.classList || [];
99
- const finalClassNameList = getFinalClassNameList(classNameList, bindClassList);
100
-
101
- // 当前在复合组件中,且当前节点为根节点
102
- if (isInComposite && isRootNode) {
103
- if (widgetData.ownerWidget) {
104
- Object.keys(widgetData.ownerWidget).forEach((propName) => {
105
- if (propName === 'role' || ['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))) {
106
- widgetData[propName] = widgetData.ownerWidget[propName];
107
- }
108
- });
109
- }
110
- }
111
-
112
- // 防止渲染时 data 的 style 与实际的 style 冲突
113
- delete fieldData.style;
114
-
115
- return {
116
- fieldData,
117
- finalStyle,
118
- finalClassNameList: Array.from(new Set(finalClassNameList)),
119
- };
120
- }
121
-
122
- function getForList(compId, dataBinds, parentForItems, dataContext) {
123
- /**
124
- * For循环渲染
125
- * @important
126
- * @default undfined // 代表没有进行for循环绑定
127
- */
128
- let forList = undefined;
129
-
130
- try {
131
- // 绑定了 for 变量,但计算值错误时,应当空数组兜底
132
- forList = dataBinds && dataBinds._waFor && (dataBinds._waFor(parentForItems, undefined, dataContext) || []);
133
- } catch (e) {
134
- // 计算值出错则使用空数组兜底
135
- forList = [];
136
- console.warn('_waFor data', e);
137
- }
138
-
139
- // 绑定了for 并且计算了值,但是不是数组类型,应该进行兜底
140
- if (forList) {
141
- if (!Array.isArray(forList)) {
142
- console.warn(`${compId}循环绑定非数组值:`, forList);
143
- forList = [];
144
- }
145
- }
146
-
147
- return forList;
148
- }
149
-
150
- function FieldWrapper({
151
- Field,
152
- componentSchema,
153
- id,
154
- data,
155
- style = {},
156
- className = '',
157
- events,
158
- compositeParent,
159
- context,
160
- children,
161
- updateContext,
162
- }) {
163
- const { scopeContext, forContext, forIndexes, widgetsData, codeContext, dataContext } = context;
164
-
165
- const injectContext = {};
166
- const indexRef = React.useRef();
167
- const typeRef = React.useRef();
168
- const instanceRef = React.useRef();
169
- const { 'x-props': xProps } = componentSchema;
170
- let { staticResourceAttribute = [], listenerInstances = [] } = xProps;
171
-
172
- // 组件最终用于执行的事件函数
173
- const emit = React.useCallback(
174
- (trigger, listeners, eventData, forItems, domEvent, scopeContext) => {
175
- // 当组件是数据容器并且listeners未含有onDataChange事件时,增加一个onDataChange事件
176
- if (componentSchema?.compConfig?.isDataContainer) {
177
- listeners = listeners.concat({
178
- key: `wa${Date.now().toString().slice(-8)}`,
179
- trigger: 'onDataChange',
180
- isCapturePhase: false,
181
- data: {},
182
- dataBinds: {},
183
- instanceFunction: ({ event }) => {
184
- return updateContext(id, event?.detail?.data);
185
- },
186
- });
187
- }
188
-
189
- if (injectContext?.emit) {
190
- return injectContext.emit(trigger, listeners, eventData, forItems, domEvent, scopeContext);
191
- } else {
192
- const event = {
193
- detail: eventData,
194
- name: trigger,
195
- target: widgetsData,
196
- currentTarget: widgetsData,
197
- domEvent,
198
- };
199
- forItems = {
200
- ...forItems,
201
- forIndexes: getForIndexes(forItems, widgetsData),
202
- };
203
- emitEvent(
204
- trigger,
205
- listeners,
206
- {
207
- event,
208
- customEventData: event,
209
- forItems,
210
- domEvent,
211
- },
212
- scopeContext,
213
- dataContext,
214
- );
215
- }
216
- },
217
- [widgetsData],
218
- );
219
-
220
- const currentWidget = Array.isArray(widgetsData) ? get(widgetsData, forIndexes) : widgetsData;
221
-
222
- React.useLayoutEffect(() => {
223
- return () => {
224
- instanceRef.current = undefined;
225
- };
226
- }, []);
227
-
228
- React.useLayoutEffect(() => {
229
- currentWidget._getInstanceRef = () => instanceRef;
230
- }, [currentWidget, instanceRef]);
231
-
232
- if (!Array.isArray(staticResourceAttribute)) {
233
- staticResourceAttribute = [];
234
- }
235
-
236
- // 判断为容器组件,则增加一个onDataChange事件
237
- if (componentSchema?.compConfig?.isDataContainer && !events?.includes('onDataChange')) {
238
- events.push('onDataChange');
239
- }
240
-
241
- return (
242
- <Field
243
- ref={instanceRef}
244
- data={{
245
- ...data,
246
- _selectableBlockEvents: {
247
- onCustomEvent: ({ order: index, blockKey }) => {
248
- if (index !== undefined) {
249
- indexRef.current = index;
250
- typeRef.current = blockKey;
251
- }
252
- },
253
- events: componentSchema?.selectableBlock?.events.map((item) => item.name) || [],
254
- emit: (trigger, evt, domEvent) =>
255
- emit(
256
- trigger,
257
- indexRef?.current !== undefined &&
258
- typeRef?.current &&
259
- data?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.['x-props']?.listenerInstances,
260
- evt,
261
- forContext,
262
- domEvent,
263
- scopeContext,
264
- ),
265
- },
266
- }}
267
- id={id}
268
- emit={(trigger, eventData, domEvent) =>
269
- emit(trigger, listenerInstances, eventData, forContext, domEvent, scopeContext)
270
- }
271
- events={events}
272
- compositeParent={compositeParent}
273
- forIndexes={forIndexes}
274
- $node={currentWidget}
275
- domRef={setGetDomApi(currentWidget, { codeContext })}
276
- style={style}
277
- className={className}
278
- staticResourceAttribute={staticResourceAttribute}
279
- >
280
- {children}
281
- </Field>
282
- );
283
- }
284
-
285
- export const CompRenderer = observer(function (props) {
286
- return getComponentRenderList({
287
- ...props,
288
- forContext: React.createContext(ForContext),
289
- injectContext: {},
290
- });
291
- });
292
-
293
- export function getComponentRenderList(props) {
294
- const {
295
- key = undefined,
296
- id: compId,
297
- xProps,
298
- virtualFields,
299
- renderSlot,
300
- codeContext,
301
- scopeContext,
302
- context = {},
303
- updateContext,
304
- emitEvents = [],
305
- componentSchema = {},
306
- forContext: parentForItems = {},
307
- } = props;
308
-
309
- const _context = {
310
- scopeContext,
311
- forContext: parentForItems,
312
- codeContext,
313
- dataContext: context,
314
- };
315
-
316
- const isInComposite = !!codeContext;
317
- // 判断 widgets 是从 page 来的,还是组件来的
318
- const widgetsData = !isInComposite ? $page.widgets[compId] : codeContext.$WEAPPS_COMP.widgets[compId];
319
-
320
- if (!xProps) {
321
- return (
322
- <>
323
- {getComponentChildren(componentSchema, {
324
- ..._context,
325
- virtualFields,
326
- updateContext,
327
- })}
328
- </>
329
- );
330
- }
331
-
332
- const { commonStyle = {}, sourceKey, dataBinds, classNameList = [] } = xProps;
333
- const Field = virtualFields[sourceKey];
334
-
335
- // For循环渲染
336
- let forList = getForList(compId, dataBinds, parentForItems, context);
337
-
338
- if (forList) {
339
- return forList
340
- .map((item, index) => {
341
- const forItemsIndexes = (parentForItems['forIndexes'] || []).concat(index);
342
- const forItems = {
343
- ...parentForItems,
344
- [compId]: item,
345
- forIndexes: forItemsIndexes,
346
- };
347
- const {
348
- fieldData: forItemData,
349
- finalStyle: forItemStyle,
350
- finalClassNameList: forItemClassNameList,
351
- } = getBindData({
352
- widgetData: widgetsData,
353
- forItems,
354
- scopeContext,
355
- codeContext,
356
- commonStyle,
357
- classNameList,
358
- });
359
- if (!checkVisible(forItemData)) {
360
- return null;
361
- }
362
-
363
- const slotMap = generateSlotMap(
364
- generateSlotMetaMap(
365
- componentSchema,
366
- {
367
- ..._context,
368
- forContext: forItems,
369
- virtualFields,
370
- updateContext,
371
- },
372
- {
373
- renderSlot,
374
- },
375
- ),
376
- );
377
-
378
- return (
379
- <ForContext.Provider key={index} value={forItems}>
380
- <FieldWrapper
381
- Field={Field}
382
- componentSchema={componentSchema}
383
- context={{
384
- ..._context,
385
- widgetsData,
386
- forContext: forItems,
387
- forIndexes: forItemsIndexes,
388
- }}
389
- id={compId}
390
- updateContext={updateContext}
391
- data={{
392
- ...forItemData,
393
- ...slotMap,
394
- }}
395
- {...getSafeComponentProps({
396
- style: forItemStyle,
397
- classNameList: forItemClassNameList,
398
- })}
399
- events={emitEvents}
400
- compositeParent={codeContext}
401
- >
402
- {getComponentChildren(componentSchema, {
403
- ..._context,
404
- forContext: forItems,
405
- virtualFields,
406
- updateContext,
407
- })}
408
- </FieldWrapper>
409
- </ForContext.Provider>
410
- );
411
- })
412
- .filter((item) => !!item);
413
- }
414
-
415
- // 修正 forIndexes
416
- const forIndexes = getForIndexes(parentForItems, widgetsData);
417
-
418
- // 单节点渲染
419
- const { fieldData, finalClassNameList, finalStyle } = getBindData({
420
- widgetData: widgetsData,
421
- forItems: parentForItems,
422
- scopeContext,
423
- codeContext,
424
- commonStyle,
425
- classNameList,
426
- });
427
-
428
- // false 或空字符串时
429
- if (!checkVisible(fieldData)) {
430
- return null;
431
- }
432
-
433
- // 单个组件的 slot 属性
434
- const slotMap = generateSlotMap(
435
- generateSlotMetaMap(
436
- componentSchema,
437
- {
438
- ..._context,
439
- virtualFields,
440
- updateContext,
441
- },
442
- {
443
- renderSlot,
444
- },
445
- ),
446
- );
447
-
448
- return (
449
- <FieldWrapper
450
- key={key}
451
- Field={Field}
452
- componentSchema={componentSchema}
453
- context={{
454
- ..._context,
455
- forIndexes: forIndexes,
456
- widgetsData,
457
- }}
458
- id={compId}
459
- updateContext={updateContext}
460
- data={{
461
- ...fieldData,
462
- ...slotMap,
463
- }}
464
- {...getSafeComponentProps({
465
- style: finalStyle,
466
- classNameList: finalClassNameList,
467
- })}
468
- events={emitEvents}
469
- compositeParent={codeContext}
470
- >
471
- {getComponentChildren(componentSchema, {
472
- ..._context,
473
- virtualFields,
474
- updateContext,
475
- })}
476
- </FieldWrapper>
477
- );
478
- }
479
-
480
- export function getFinalStyle(commonStyle = {}, bindStyle = {}, widgetStyle = {}) {
481
- const remBindStyle = typeof bindStyle === 'object' ? translateStyleToRem(bindStyle) : {};
482
-
483
- return {
484
- ...(translateStyleToRem(commonStyle) || {}),
485
- ...(translateStyleToRem(widgetStyle) || {}),
486
- ...remBindStyle,
487
- };
488
- }
489
-
490
- export function getFinalClassNameList(classNameList = [], bindClassList = [], widgetClassList = []) {
491
- return [].concat(classNameList, bindClassList, widgetClassList);
492
- }
493
-
494
- // HACK: 从后向前保证循环的深度与 forIndexes 一致
495
- // 后续需要将 For 循环迁移到外层
496
- function getForIndexes(parentForItems, widgetsData) {
497
- return Array.isArray(widgetsData) && widgetsData.length > 0
498
- ? (parentForItems.forIndexes || []).slice(0 - getDeepArrLen(widgetsData))
499
- : undefined;
500
- }
501
-
502
- function getDeepArrLen(arr, len = 0) {
503
- if (Array.isArray(arr)) {
504
- return getDeepArrLen(arr[0], len + 1);
505
- } else {
506
- return len;
507
- }
508
- }
509
-
510
- function setGetDomApi(currentWidget, props) {
511
- if (!currentWidget) return React.createRef();
512
- const isComposite = !currentWidget.widgetType.startsWith('gsd-h5-react');
513
- const isInComposite = !!props.codeContext;
514
-
515
- // 如果当前是复合组件,不做 getDom 的挂载
516
- if (!isComposite) {
517
- if (!currentWidget.domRef) {
518
- currentWidget.domRef = React.createRef();
519
- }
520
- if (!currentWidget.getDom) {
521
- currentWidget.getDom = (options) => getDom(currentWidget.domRef.current, options);
522
- }
523
-
524
- if (
525
- isInComposite && // 当前在复合组件内
526
- !currentWidget.parent && // 当前节点为复合组件的根节点
527
- props.codeContext.node && // 复合组件的 node 已经创建
528
- !props.codeContext.node.getDom // 复合组件的 node 未挂载 getDom 方法
529
- ) {
530
- props.codeContext.node.domRef = currentWidget.domRef;
531
- props.codeContext.node.getDom = currentWidget.getDom;
532
- }
533
- }
534
-
535
- return currentWidget.domRef;
536
- }
@@ -1,36 +0,0 @@
1
- import * as React from 'react';
2
- import { HotAreaActionHandler } from './actionHandler';
3
-
4
- function percent(p) {
5
- return `${p}%`;
6
- }
7
-
8
- export function HotAreas({ instance, global, meta }) {
9
- const { hotAreas } = instance.data;
10
- if (!hotAreas || !hotAreas.length) {
11
- return null;
12
- }
13
-
14
- return hotAreas.map((hotArea, index) => {
15
- const { size, position } = hotArea;
16
-
17
- return (
18
- <HotAreaActionHandler
19
- key={index} // eslint-disable-line
20
- instance={instance}
21
- hotArea={hotArea}
22
- meta={meta}
23
- global={global}
24
- style={{
25
- width: percent(size.width),
26
- height: percent(size.height),
27
- left: percent(position.x),
28
- top: percent(position.y),
29
- cursor: 'pointer',
30
- position: 'absolute',
31
- zIndex: 20,
32
- }}
33
- />
34
- );
35
- });
36
- }
@@ -1,8 +0,0 @@
1
- /*
2
- eslint-disable
3
- */
4
- import * as React from 'react';
5
-
6
- export function PositionHandler({ positionStyle, children }) {
7
- return <div style={{ ...positionStyle, width: '100%', zIndex: 999 }}>{children}</div>;
8
- }