@cloudbase/framework-plugin-low-code 0.6.30 → 0.6.33

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 (82) hide show
  1. package/lib/builder/config/index.js +2 -5
  2. package/lib/builder/core/copy.d.ts.map +1 -1
  3. package/lib/builder/mp/materials.d.ts.map +1 -1
  4. package/lib/builder/mp/materials.js +21 -5
  5. package/package.json +5 -3
  6. package/template/src/handlers/FieldMiddleware/renderer.jsx +11 -6
  7. package/template/src/handlers/actionHandler/utils.js +41 -17
  8. package/template/webpack/web.prod.js +65 -85
  9. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/cookie.js +0 -286
  10. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/history.js +0 -133
  11. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/local-storage.js +0 -103
  12. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/location.js +0 -588
  13. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/miniprogram.js +0 -101
  14. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/navigator.js +0 -80
  15. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/performance.js +0 -28
  16. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/screen.js +0 -31
  17. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/session-storage.js +0 -96
  18. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/xml-http-request.js +0 -290
  19. package/template/dist/mp/miniprogram_npm/miniprogram-render/document.js +0 -396
  20. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/custom-event.js +0 -12
  21. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event-target.js +0 -389
  22. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event.js +0 -186
  23. package/template/dist/mp/miniprogram_npm/miniprogram-render/index.js +0 -41
  24. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/attribute.js +0 -226
  25. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/class-list.js +0 -153
  26. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/comment.js +0 -80
  27. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/a.js +0 -165
  28. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/canvas.js +0 -138
  29. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/image.js +0 -177
  30. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/input.js +0 -181
  31. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/not-support.js +0 -60
  32. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/option.js +0 -126
  33. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/select.js +0 -155
  34. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/textarea.js +0 -178
  35. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/video.js +0 -165
  36. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-component.js +0 -84
  37. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-custom-component.js +0 -64
  38. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element.js +0 -970
  39. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/node.js +0 -140
  40. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style-list.js +0 -28
  41. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style.js +0 -158
  42. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/text-node.js +0 -127
  43. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/parser.js +0 -269
  44. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/query-selector.js +0 -420
  45. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/tree.js +0 -130
  46. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/cache.js +0 -95
  47. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/pool.js +0 -24
  48. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/tool.js +0 -131
  49. package/template/dist/mp/miniprogram_npm/miniprogram-render/window.js +0 -651
  50. package/template/generator/app/common.js +0 -17
  51. package/template/generator/app/global-api.js +0 -163
  52. package/template/generator/app/handlers.js +0 -13
  53. package/template/generator/datasources/config.js.tpl +0 -21
  54. package/template/generator/datasources/dataset-profiles.js.tpl +0 -5
  55. package/template/generator/datasources/datasource-profiles.js.tpl +0 -4
  56. package/template/generator/datasources/index.js.tpl +0 -14
  57. package/template/generator/handlers/NodeRenderer.jsx +0 -471
  58. package/template/generator/handlers/RenderWrapper.jsx +0 -145
  59. package/template/generator/index.jsx +0 -116
  60. package/template/generator/index.less +0 -120
  61. package/template/generator/pages/app.tpl +0 -181
  62. package/template/generator/pages/composite.tpl +0 -267
  63. package/template/generator/router/index.tpl +0 -49
  64. package/template/generator/store/computed.js +0 -11
  65. package/template/generator/store/index.js +0 -5
  66. package/template/generator/utils/ScanCodeComponent.js +0 -345
  67. package/template/generator/utils/actionHandler.js +0 -119
  68. package/template/generator/utils/common.js +0 -225
  69. package/template/generator/utils/computed.js +0 -9
  70. package/template/generator/utils/date.js +0 -324
  71. package/template/generator/utils/error.jsx +0 -14
  72. package/template/generator/utils/eventProxy.js +0 -64
  73. package/template/generator/utils/history.js +0 -35
  74. package/template/generator/utils/hooks.js +0 -10
  75. package/template/generator/utils/index.js +0 -41
  76. package/template/generator/utils/initGlobalVar.js +0 -14
  77. package/template/generator/utils/lifecycle.js +0 -158
  78. package/template/generator/utils/monitor-jssdk.min.js +0 -881
  79. package/template/generator/utils/page.js +0 -10
  80. package/template/generator/utils/scan-code-action.js +0 -27
  81. package/template/generator/utils/style.js +0 -81
  82. package/template/generator/utils/widgets.js +0 -343
@@ -1,163 +0,0 @@
1
- import sdk from '@tcwd/weapps-sdk/lib/app-h5-sdk';
2
- import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '../datasources';
3
- import { formatDate } from '../utils/date';
4
- import { getter, setter, _isMobile } from '../utils';
5
- import { scanCodeApi } from '../utils/scan-code-action';
6
-
7
- export const subPackageName = '<%= subPackageName %>';
8
- export const app = createGlboalApi();
9
- mountAPIs(sdk);
10
- function createGlboalApi() {
11
- const globalAPI = {
12
- id: '<%= appId %>',
13
- domain: '<%= domain %>',
14
- platform: 'WEB',
15
-
16
- formActions: {},
17
- pages: {},
18
- state: {},
19
- computed: {},
20
- common: {},
21
- // i18n,
22
- dataSources: DS_SDK,
23
- utils: {
24
- formatDate,
25
- get: getter,
26
- set: setter,
27
- },
28
- };
29
-
30
- const dataset = createDataset('$global');
31
- globalAPI.dataset = dataset;
32
- globalAPI.state.dataset = dataset;
33
- globalAPI.setState = (userSetState) => {
34
- Object.keys(userSetState).forEach((keyPath) => {
35
- globalAPI.utils.set(
36
- globalAPI.dataset.state,
37
- keyPath,
38
- userSetState[keyPath]
39
- );
40
- });
41
- };
42
- /**
43
- * 内部通用的设置状态变量值的方法
44
- * varPath 结构为 $global.<变量名> 即全局变量
45
- * $page.<变量名> 即当前页面变量
46
- * <pageId>.<变量名> 指定页面 pageId 的变量 (应当避免修改非当前页面的变量值)
47
- */
48
- globalAPI._setStateVal = (config) => {
49
- EXTRA_API.setState(config.varPath, config.val);
50
- };
51
- // 给全局挂上 mainApp/subApp
52
- // The global api exposed to lowcode
53
- if (subPackageName) {
54
- globalAPI.mainApp = window[`$$app`];
55
- window[`$$subapp_${subPackageName}`] = globalAPI;
56
- } else {
57
- window['app'] = globalAPI;
58
- window[`$$app`] = globalAPI;
59
- }
60
-
61
- // 挂运营平台上报对象到app里
62
- globalAPI.yyptReport = window.yyptReport;
63
-
64
- // 预览区调试栏可调试
65
- // 暴露给复合组件,代码组件来引用
66
- window.app = window.app || globalAPI;
67
-
68
- // 避免被wx.cloud 覆盖
69
- globalAPI.cloud = CLOUD_SDK;
70
- return globalAPI;
71
- }
72
-
73
- export function createPageApi() {
74
- const $page = {
75
- state: {},
76
- computed: {},
77
- handler: {},
78
- props: {},
79
- widgets: {},
80
- // 页面数据源变量存储位置
81
- dataVar: {},
82
- };
83
- return $page;
84
- }
85
-
86
- // 分app 和 wx 挂载app
87
- function mountAPIs(sdks) {
88
- Object.keys(sdks).forEach((item) => {
89
- let action = sdks[item];
90
-
91
- switch (item) {
92
- case 'showToast': {
93
- action = function (obj) {
94
- if (obj.icon === 'error' && !obj.image) {
95
- return sdks[item]({
96
- ...obj,
97
- image:
98
- 'data:image/svg+xml,%3Csvg%20width%3D%22120%22%20height%3D%22120%22%20viewBox%3D%220,0,24,24%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2010.586l5.657-5.657%201.414%201.414L13.414%2012l5.657%205.657-1.414%201.414L12%2013.414l-5.657%205.657-1.414-1.414L10.586%2012%204.929%206.343%206.343%204.93%2012%2010.586z%22%20fill-rule%3D%22evenodd%22%20fill%3D%22white%22%2F%3E%3C%2Fsvg%3E',
99
- });
100
- }
101
- return sdks[item](obj);
102
- };
103
- break;
104
- }
105
- case 'showModal': {
106
- const LIB_KEY = `@weapps-materials-main-gsd-h5-react`;
107
- const showModal =
108
- window[LIB_KEY] &&
109
- window[LIB_KEY].actions &&
110
- window[LIB_KEY].actions.showModal;
111
-
112
- if (!_isMobile() && showModal) {
113
- action = function (params) {
114
- return showModal({ data: params });
115
- };
116
- }
117
- break;
118
- }
119
- case 'scanCode': {
120
- action = (options) => {
121
- if (
122
- !options ||
123
- (!options.success && !options.fail && !options.complete)
124
- ) {
125
- return new Promise((resolve, reject) => {
126
- scanCodeApi({
127
- ...options,
128
- success: resolve,
129
- fail: reject,
130
- });
131
- });
132
- }
133
- scanCodeApi(options);
134
- };
135
- break;
136
- }
137
- case 'navigateTo':
138
- case 'reLaunch':
139
- case 'redirectTo': {
140
- action = function (obj) {
141
- const { url, ...restOpts } = obj;
142
- if (obj.mode === 'web') {
143
- if (item === 'navigateTo') {
144
- window.open(url);
145
- } else {
146
- window.location.href = url;
147
- }
148
- } else {
149
- return sdks[item]({
150
- ...restOpts,
151
- pageId: restOpts.pageId
152
- ? restOpts.pageId.replace(/^(\.)?\//, '')
153
- : restOpts.pageId,
154
- });
155
- }
156
- };
157
- break;
158
- }
159
- }
160
- app[item] = action;
161
- });
162
- return app;
163
- }
@@ -1,13 +0,0 @@
1
- <%for(const pageId in pageModules) {
2
- pageModules[pageId].filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
3
- import <%= pageId%>_<%= mod.name%> from '../lowcode/<%= pageId%>/handler/<%= mod.name%>'<%
4
- })
5
- }%>
6
-
7
- <% for(const pageId in pageModules) {%>
8
- export const $$_<%=pageId %> = {<%
9
- pageModules[pageId].filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
10
- ['<%= mod.name%>']: <%= pageId%>_<%= mod.name%>,<%
11
- }) %>
12
- }
13
- <%}%>
@@ -1,21 +0,0 @@
1
- import dataSourceProfiles from './datasource-profiles'
2
- import datasetProfiles from './dataset-profiles'
3
-
4
- /**
5
- * 数据源基本配置
6
- */
7
- export default {
8
- /** 当前是否处于正式发布模式 */
9
- isProd: <%= isProd %>,
10
- /** 低码应用ID */
11
- appID: '<%= appID %>',
12
- /** 云开发环境ID */
13
- envID: '<%= envID %>',
14
- /** 数据源描述对象数组 */
15
- dataSourceProfiles: dataSourceProfiles,
16
- /**
17
- * 新的dataset变量配置对象
18
- * key 为页面ID(全局为$global), val 为变量配置数组
19
- */
20
- datasetProfiles: datasetProfiles,
21
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * 全局及页面的数据源变量定义文件
3
- */
4
-
5
- export default <%= datasetProfiles %>
@@ -1,4 +0,0 @@
1
- /**
2
- * 数据源摘要描述数组
3
- */
4
- export default <%= datasourceProfiles %>
@@ -1,14 +0,0 @@
1
- import { setConfig, initTcb, CLOUD_SDK } from '@cloudbase/weda-cloud-sdk/dist/h5';
2
- import config from './config';
3
- export {
4
- createDataset,
5
- createStateDataSourceVar,
6
- generateParamsParser,
7
- EXTRA_API,
8
- CLOUD_SDK,
9
- DS_API,
10
- DS_SDK,
11
- } from '@cloudbase/weda-cloud-sdk/dist/h5';
12
-
13
- setConfig(config);
14
- initTcb();
@@ -1,471 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- useContext,
4
- useCallback,
5
- createContext,
6
- useState,
7
- useRef,
8
- } from 'react';
9
- import { observer } from 'mobx-react-lite';
10
- import { emitEvent, translateStyleToRem, checkVisible } from '../utils';
11
- import { get, set } from 'lodash';
12
- import { getDom } from '../utils/widgets';
13
-
14
- export const ForContext = createContext({});
15
-
16
- export const CompRenderer = observer(function (props) {
17
- const {
18
- id: compId,
19
- xProps,
20
- virtualFields,
21
- slots = {},
22
- codeContext = {},
23
- scopeContext = {},
24
- genericComp = {},
25
- emitEvents = [],
26
- componentSchema = {},
27
- context = {},
28
- updateContext,
29
- } = props;
30
-
31
- const [blockIndex, setBlockIndex] = useState();
32
- const [blockType, setBlockType] = useState();
33
- const indexRef = useRef();
34
- const typeRef = useRef();
35
- indexRef.current = blockIndex;
36
- typeRef.current = blockType;
37
-
38
- const isInComposite = !!codeContext.$WEAPPS_COMP;
39
- // 判断 widgets 是从 page 来的,还是组件来的
40
- const widgetsData = !isInComposite
41
- ? codeContext.$page.widgets[compId]
42
- : codeContext.$WEAPPS_COMP.widgets[compId];
43
-
44
- const isRootNode = widgetsData && !widgetsData.parent;
45
-
46
- if (!xProps) {
47
- return props.children;
48
- }
49
-
50
- const {
51
- commonStyle = {},
52
- sourceKey,
53
- listenerInstances,
54
- classNameList = [],
55
- staticResourceAttribute = [],
56
- } = xProps;
57
- const dataBinds =
58
- (codeContext._dataBinds && codeContext._dataBinds[compId]) || {};
59
- const FieldKey = genericComp.propName
60
- ? codeContext.node[genericComp.propName]
61
- : sourceKey;
62
- const Field = virtualFields[FieldKey];
63
- const parentForItems = useContext(ForContext);
64
-
65
- // 组件最终用于执行的事件函数
66
- const emit = useCallback(
67
- (trigger, eventData, forItems, domEvent, scopeContext) => {
68
- // 如果是数据容器,则将传过来的data,赋值给容器上下文context
69
- if (
70
- trigger === 'onDataChange' &&
71
- componentSchema?.compConfig?.isDataContainer
72
- ) {
73
- updateContext(compId, eventData?.data);
74
- }
75
-
76
- const listeners = listenerInstances;
77
- const event = {
78
- detail: eventData,
79
- name: trigger,
80
- target: widgetsData,
81
- currentTarget: widgetsData,
82
- domEvent,
83
- };
84
- forItems = {
85
- ...forItems,
86
- forIndexes: getForIndexes(forItems, widgetsData),
87
- };
88
- emitEvent(
89
- trigger,
90
- listeners,
91
- {
92
- event,
93
- customEventData: event,
94
- forItems,
95
- domEvent,
96
- },
97
- scopeContext
98
- );
99
- },
100
- [props]
101
- );
102
-
103
- // 选区最终用于执行的事件函数
104
- const emitSB = useCallback(
105
- (trigger, eventData, forItems, domEvent, scopeContext, fieldData) => {
106
- const listeners =
107
- typeRef?.current &&
108
- indexRef?.current !== undefined &&
109
- fieldData?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.[
110
- 'x-props'
111
- ]?.listenerInstances;
112
- const event = {
113
- detail: eventData,
114
- name: trigger,
115
- target: widgetsData,
116
- currentTarget: widgetsData,
117
- domEvent,
118
- };
119
- forItems = {
120
- ...forItems,
121
- forIndexes: getForIndexes(forItems, widgetsData),
122
- };
123
- emitEvent(
124
- trigger,
125
- listeners,
126
- {
127
- event,
128
- customEventData: event,
129
- forItems,
130
- domEvent,
131
- },
132
- scopeContext
133
- );
134
- },
135
- [props]
136
- );
137
-
138
- function getSafeComponentProps({
139
- style,
140
- classNameList,
141
- staticResourceAttribute,
142
- }) {
143
- const componentProps = {};
144
- if (classNameList.length) {
145
- componentProps.className = classNameList.join(' ');
146
- }
147
-
148
- if (style && Object.keys(style).length) {
149
- componentProps.style = style;
150
- }
151
-
152
- if (staticResourceAttribute && staticResourceAttribute.length > 0) {
153
- componentProps.staticResourceAttribute = staticResourceAttribute;
154
- }
155
- return componentProps;
156
- }
157
-
158
- // 选区的预览的click事件
159
- const onCustomEvent = ({ order: index, blockKey }) => {
160
- if (index !== undefined) {
161
- setBlockIndex(index);
162
- setBlockType(blockKey);
163
- }
164
- };
165
-
166
- // For循环渲染
167
- let forList;
168
- try {
169
- forList = dataBinds && dataBinds._waFor && dataBinds._waFor(parentForItems, undefined, context);
170
- } catch (e) {
171
- forList = [];
172
- console.error('_waFor data', e);
173
- }
174
- if (forList) {
175
- if (!Array.isArray(forList)) {
176
- console.warn(`${compId}循环绑定非数组值:`, forList);
177
- forList = [];
178
- }
179
- return forList.map((item, index) => {
180
- const forItemsIndexes = (parentForItems.forIndexes || []).concat(index);
181
- const forItems = {
182
- ...parentForItems,
183
- [compId]: item,
184
- forIndexes: forItemsIndexes,
185
- };
186
- const {
187
- fieldData: forItemData,
188
- finalStyle: forItemStyle,
189
- finalClassNameList: forItemClassNameList,
190
- } = getBindData(forItems, scopeContext);
191
- if (!checkVisible(forItemData)) {
192
- return null;
193
- }
194
- // 多个组件的 slot 属性
195
- Object.keys(slots).forEach((slotProp) => {
196
- set(forItemData, slotProp, slots[slotProp]);
197
- });
198
- const emitWithForItems = (trigger, eventData, domEvent) =>
199
- emit(trigger, eventData, forItems, domEvent, scopeContext);
200
-
201
- const _selectableBlockEventsForItems = {
202
- onCustomEvent,
203
- events:
204
- componentSchema?.selectableBlock?.events.map((item) => item.name) ||
205
- [],
206
- emit: (trigger, eventData, domEvent) =>
207
- emitSB(
208
- trigger,
209
- eventData,
210
- forItems,
211
- domEvent,
212
- scopeContext,
213
- forItemData
214
- ),
215
- };
216
-
217
- delete forItemData.style;
218
-
219
- // 获取当前元素的 ref
220
- const currentWidget = Array.isArray(widgetsData)
221
- ? get(widgetsData, forItemsIndexes)
222
- : widgetsData;
223
- const domRef = setGetDomApi(currentWidget, props);
224
-
225
- // 判断为容器组件,则增加一个onDataChange事件
226
- if (
227
- componentSchema?.compConfig?.isDataContainer &&
228
- !emitEvents?.includes('onDataChange')
229
- ) {
230
- emitEvents.push('onDataChange');
231
- }
232
-
233
- return (
234
- <ForContext.Provider key={index} value={forItems}>
235
- <Field
236
- data={{
237
- ...forItemData,
238
- _selectableBlockEvents: _selectableBlockEventsForItems,
239
- }}
240
- id={compId}
241
- {...getSafeComponentProps({
242
- style: forItemStyle,
243
- classNameList: forItemClassNameList,
244
- staticResourceAttribute,
245
- })}
246
- emit={emitWithForItems}
247
- events={emitEvents}
248
- compositeParent={codeContext}
249
- forIndexes={forItemsIndexes}
250
- $node={currentWidget}
251
- domRef={domRef}
252
- >
253
- {props.children}
254
- </Field>
255
- </ForContext.Provider>
256
- );
257
- });
258
- }
259
-
260
- // 单节点渲染
261
- const { fieldData, finalClassNameList, finalStyle } = getBindData(
262
- parentForItems,
263
- scopeContext
264
- );
265
- const emitWithFiedle = (trigger, eventData, domEvent) =>
266
- emit(trigger, eventData, parentForItems, domEvent, scopeContext);
267
-
268
- const _selectableBlockEventsWithFiedle = {
269
- onCustomEvent,
270
- events:
271
- componentSchema?.selectableBlock?.events.map((item) => item.name) || [],
272
- emit: (trigger, eventData, domEvent) =>
273
- emitSB(
274
- trigger,
275
- eventData,
276
- parentForItems,
277
- domEvent,
278
- scopeContext,
279
- fieldData
280
- ),
281
- };
282
-
283
- // false 或空字符串时
284
- if (!checkVisible(fieldData)) {
285
- return null;
286
- }
287
-
288
- // 单个组件的 slot 属性
289
- Object.keys(slots).forEach((slotProp) => {
290
- set(fieldData, slotProp, slots[slotProp]);
291
- });
292
-
293
- // 防止渲染时 data 的 style 与实际的 style 冲突
294
- delete fieldData.style;
295
-
296
- // 修正 forIndexes
297
- const forIndexes = getForIndexes(parentForItems, widgetsData);
298
-
299
- // 获取 Element Ref
300
- const currentWidget = Array.isArray(widgetsData)
301
- ? get(widgetsData, forIndexes)
302
- : widgetsData;
303
- const domRef = setGetDomApi(currentWidget, props);
304
-
305
- // 判断为容器组件,则增加一个onDataChange事件
306
- if (
307
- componentSchema?.compConfig?.isDataContainer &&
308
- !emitEvents?.includes('onDataChange')
309
- ) {
310
- emitEvents.push('onDataChange');
311
- }
312
-
313
- return (
314
- <Field
315
- data={{
316
- ...fieldData,
317
- _selectableBlockEvents: _selectableBlockEventsWithFiedle,
318
- }}
319
- id={compId}
320
- {...getSafeComponentProps({
321
- style: finalStyle,
322
- classNameList: finalClassNameList,
323
- staticResourceAttribute,
324
- })}
325
- emit={emitWithFiedle}
326
- events={emitEvents}
327
- compositeParent={codeContext}
328
- forIndexes={forIndexes}
329
- $node={currentWidget}
330
- domRef={domRef}
331
- >
332
- {props.children}
333
- </Field>
334
- );
335
-
336
- // TODO: 需要不断移除 dataBinds(style/classList)
337
- function getBindData(forItems, scopeContext) {
338
- // bindData
339
- let wData = widgetsData;
340
- if (Array.isArray(wData)) {
341
- wData =
342
- forItems.forIndexes === void 0 || wData.length === 0
343
- ? {}
344
- : get(wData, getForIndexes(forItems, wData));
345
- }
346
- wData = wData || {};
347
- const fieldData = { ...wData };
348
-
349
- // 再次计算 scope value
350
- for (let key in fieldData) {
351
- if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
352
- const value = fieldData[key];
353
- if (value && value.__type === 'scopedValue') {
354
- try {
355
- fieldData[key] = value.getValue(scopeContext);
356
- } catch (e) {
357
- console.warn(`Error computing data bind '${key}' error:`, e);
358
- fieldData[key] = '';
359
- }
360
- }
361
- }
362
- }
363
-
364
- // bindStyle
365
- let bindStyle = fieldData.style || {};
366
- // 复合组件第一层需要将最外层样式 style 挂到节点上
367
- let cssStyle = commonStyle;
368
- if (isInComposite && wData && !wData.parent) {
369
- cssStyle = {
370
- ...cssStyle,
371
- ...(codeContext.$WEAPPS_COMP.props?.style || {}),
372
- };
373
- bindStyle = {
374
- ...bindStyle,
375
- ...(codeContext.$WEAPPS_COMP.props?.style || {}),
376
- };
377
- }
378
- const finalStyle = getFinalStyle(cssStyle, bindStyle);
379
-
380
- // bindClassList
381
- const bindClassList = fieldData.classList || [];
382
- const finalClassNameList = getFinalClassNameList(
383
- classNameList,
384
- bindClassList
385
- );
386
-
387
- // 当前在复合组件中,且当前节点为根节点
388
- if (isInComposite && isRootNode) {
389
- if (wData.ownerWidget) {
390
- Object.keys(wData.ownerWidget).forEach((propName) => {
391
- if (
392
- propName === 'role' ||
393
- ['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))
394
- ) {
395
- wData[propName] = wData.ownerWidget[propName];
396
- }
397
- });
398
- }
399
- }
400
-
401
- return { fieldData, finalStyle, finalClassNameList };
402
- }
403
- });
404
-
405
- export function getFinalStyle(
406
- commonStyle = {},
407
- bindStyle = {},
408
- widgetStyle = {}
409
- ) {
410
- const remBindStyle =
411
- typeof bindStyle === 'object' ? translateStyleToRem(bindStyle) : {};
412
-
413
- return {
414
- ...(translateStyleToRem(commonStyle) || {}),
415
- ...(translateStyleToRem(widgetStyle) || {}),
416
- ...remBindStyle,
417
- };
418
- }
419
-
420
- export function getFinalClassNameList(
421
- classNameList = [],
422
- bindClassList = [],
423
- widgetClassList = []
424
- ) {
425
- return [].concat(classNameList, bindClassList, widgetClassList);
426
- }
427
-
428
- // HACK: 从后向前保证循环的深度与 forIndexes 一致
429
- // 后续需要将 For 循环迁移到外层
430
- function getForIndexes(parentForItems, widgetsData) {
431
- return Array.isArray(widgetsData) && widgetsData.length > 0
432
- ? (parentForItems.forIndexes || []).slice(0 - getDeepArrLen(widgetsData))
433
- : undefined;
434
- }
435
-
436
- function getDeepArrLen(arr, len = 0) {
437
- if (Array.isArray(arr)) {
438
- return getDeepArrLen(arr[0], len + 1);
439
- } else {
440
- return len;
441
- }
442
- }
443
-
444
- function setGetDomApi(currentWidget, props) {
445
- if (!currentWidget) return React.createRef();
446
- const isComposite = !currentWidget.widgetType.startsWith('gsd-h5-react');
447
- const isInComposite = !!(props.codeContext || {}).$WEAPPS_COMP;
448
-
449
- // 如果当前是复合组件,不做 getDom 的挂载
450
- if (!isComposite) {
451
- if (!currentWidget.domRef) {
452
- currentWidget.domRef = React.createRef();
453
- }
454
- if (!currentWidget.getDom) {
455
- currentWidget.getDom = (options) =>
456
- getDom(currentWidget.domRef.current, options);
457
- }
458
-
459
- if (
460
- isInComposite && // 当前在复合组件内
461
- !currentWidget.parent && // 当前节点为复合组件的根节点
462
- props.codeContext.node && // 复合组件的 node 已经创建
463
- !props.codeContext.node.getDom // 复合组件的 node 未挂载 getDom 方法
464
- ) {
465
- props.codeContext.node.domRef = currentWidget.domRef;
466
- props.codeContext.node.getDom = currentWidget.getDom;
467
- }
468
- }
469
-
470
- return currentWidget.domRef;
471
- }