@cloudbase/framework-plugin-low-code 0.6.67 → 0.7.0
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/lib/builder/core/generate.d.ts.map +1 -1
- package/lib/builder/core/generate.js +8 -3
- package/lib/builder/mp/index.d.ts.map +1 -1
- package/lib/builder/mp/index.js +11 -6
- package/lib/builder/service/builder/generate.d.ts.map +1 -1
- package/lib/builder/service/builder/generate.js +2 -0
- package/lib/generator/core/generate.d.ts.map +1 -1
- package/lib/generator/core/generate.js +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -46
- package/lib/weapps-core/types/app.d.ts +1 -0
- package/lib/weapps-core/types/app.d.ts.map +1 -1
- package/lib/weapps-core/types/web.d.ts +1 -0
- package/lib/weapps-core/types/web.d.ts.map +1 -1
- package/package.json +1 -1
- package/template/html/index.html.ejs +2 -15
- package/template/mp/app/weapps-api.js +4 -3
- package/template/mp/app.js +69 -24
- package/template/mp/common/util.js +121 -69
- package/template/mp/common/weapp-page.js +2 -15
- package/template/mp/datasources/config.js.tpl +2 -0
- package/template/mp/package.json +10 -8
- package/template/mp/page/index.js +1 -3
- package/template/package.json +2 -2
- package/template/src/app/global-api.js +3 -3
- package/template/src/datasources/config.js.tpl +2 -0
- package/template/src/handlers/FieldMiddleware/renderer.jsx +321 -411
- package/template/src/handlers/render.jsx +97 -114
- package/template/src/handlers/utils/common.js +132 -29
- package/template/src/index.jsx +45 -1
- package/template/src/pages/app.tpl +31 -31
- package/template/src/utils/formatEnum.js +0 -42
|
@@ -7,7 +7,7 @@ import { get, set } from 'lodash';
|
|
|
7
7
|
import { $page } from '../../app/global-api';
|
|
8
8
|
import { getDom } from '../utils/widgets';
|
|
9
9
|
import { checkVisible } from '../../utils/index';
|
|
10
|
-
import {
|
|
10
|
+
import { generateSlotMetaMap } from '../render';
|
|
11
11
|
|
|
12
12
|
export const ForContext = createContext({});
|
|
13
13
|
|
|
@@ -35,433 +35,274 @@ function generateSlotMap(slots, forContext = undefined) {
|
|
|
35
35
|
return map;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
const
|
|
38
|
+
export const CompRenderer = observer(function (props) {
|
|
39
|
+
const {
|
|
40
|
+
id: compId,
|
|
41
|
+
xProps,
|
|
42
|
+
virtualFields,
|
|
43
|
+
renderSlot,
|
|
44
|
+
codeContext,
|
|
45
|
+
scopeContext,
|
|
46
|
+
context = {},
|
|
47
|
+
updateContext,
|
|
48
|
+
emitEvents = [],
|
|
49
|
+
componentSchema = {},
|
|
50
|
+
} = props;
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
52
|
+
const indexRef = useRef();
|
|
53
|
+
const typeRef = useRef();
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
const isInComposite = !!props.codeContext;
|
|
56
|
+
// 判断 widgets 是从 page 来的,还是组件来的
|
|
57
|
+
const widgetsData = !isInComposite
|
|
58
|
+
? $page.widgets[compId]
|
|
59
|
+
: codeContext.$WEAPPS_COMP.widgets[compId];
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
widgetData,
|
|
54
|
-
forItems,
|
|
55
|
-
scopeContext,
|
|
56
|
-
codeContext,
|
|
57
|
-
commonStyle = {},
|
|
58
|
-
classNameList = [],
|
|
59
|
-
}) {
|
|
60
|
-
// bindData
|
|
61
|
-
if (Array.isArray(widgetData)) {
|
|
62
|
-
widgetData =
|
|
63
|
-
forItems.forIndexes === void 0 || widgetData.length === 0
|
|
64
|
-
? {}
|
|
65
|
-
: get(widgetData, getForIndexes(forItems, widgetData));
|
|
61
|
+
if (!xProps) {
|
|
62
|
+
return props.children;
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
|
|
65
|
+
const {
|
|
66
|
+
commonStyle = {},
|
|
67
|
+
sourceKey,
|
|
68
|
+
data = {},
|
|
69
|
+
dataBinds,
|
|
70
|
+
listenerInstances,
|
|
71
|
+
styleBind,
|
|
72
|
+
classNameList = [],
|
|
73
|
+
classNameListBind,
|
|
74
|
+
staticResourceAttribute = [],
|
|
75
|
+
} = xProps;
|
|
76
|
+
const Field = virtualFields[sourceKey];
|
|
77
|
+
const parentForItems = useContext(ForContext);
|
|
78
|
+
|
|
79
|
+
const _context = {
|
|
80
|
+
scopeContext,
|
|
81
|
+
forContext: parentForItems,
|
|
82
|
+
codeContext,
|
|
83
|
+
dataContext: context,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// 组件最终用于执行的事件函数
|
|
87
|
+
const emit = useCallback(
|
|
88
|
+
(trigger, eventDetail, forItems, scopeContext) => {
|
|
89
|
+
const listeners = listenerInstances || [];
|
|
90
|
+
|
|
91
|
+
// 如果是数据容器,则将传过来的data,赋值给容器上下文context
|
|
92
|
+
if (
|
|
93
|
+
componentSchema?.compConfig?.isDataContainer &&
|
|
94
|
+
!listeners?.some((listener) => listener.trigger === 'onDataChange')
|
|
95
|
+
) {
|
|
96
|
+
listeners?.push({
|
|
97
|
+
key: `wa${Date.now().toString().slice(-8)}`,
|
|
98
|
+
trigger: 'onDataChange',
|
|
99
|
+
isCapturePhase: false,
|
|
100
|
+
data: {},
|
|
101
|
+
dataBinds: {},
|
|
102
|
+
instanceFunction: ({ event }) => {
|
|
103
|
+
return updateContext(compId, event?.detail?.data);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
84
106
|
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
107
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
let event = { detail: eventDetail, name: trigger };
|
|
109
|
+
forItems = {
|
|
110
|
+
...forItems,
|
|
111
|
+
forIndexes: getForIndexes(forItems, widgetsData),
|
|
112
|
+
};
|
|
113
|
+
emitEvent(
|
|
114
|
+
trigger,
|
|
115
|
+
listeners,
|
|
116
|
+
{
|
|
117
|
+
event,
|
|
118
|
+
customEventData: event,
|
|
119
|
+
forItems,
|
|
120
|
+
},
|
|
121
|
+
scopeContext,
|
|
122
|
+
context
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
[props]
|
|
126
|
+
);
|
|
103
127
|
|
|
104
|
-
//
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
// 选区最终用于执行的事件函数
|
|
129
|
+
const emitSB = useCallback(
|
|
130
|
+
(trigger, eventDetail, forItems, scopeContext, fieldData) => {
|
|
131
|
+
const listeners =
|
|
132
|
+
indexRef?.current !== undefined &&
|
|
133
|
+
typeRef?.current &&
|
|
134
|
+
fieldData?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.[
|
|
135
|
+
'x-props'
|
|
136
|
+
]?.listenerInstances;
|
|
137
|
+
let event = { detail: eventDetail, name: trigger };
|
|
138
|
+
forItems = {
|
|
139
|
+
...forItems,
|
|
140
|
+
forIndexes: getForIndexes(forItems, widgetsData),
|
|
141
|
+
};
|
|
142
|
+
emitEvent(
|
|
143
|
+
trigger,
|
|
144
|
+
listeners,
|
|
145
|
+
{
|
|
146
|
+
event,
|
|
147
|
+
customEventData: event,
|
|
148
|
+
forItems,
|
|
149
|
+
},
|
|
150
|
+
scopeContext,
|
|
151
|
+
context
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
[props]
|
|
109
155
|
);
|
|
110
156
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
widgetData[propName] = widgetData.ownerWidget[propName];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
157
|
+
function getSafeComponentProps({
|
|
158
|
+
style,
|
|
159
|
+
classNameList,
|
|
160
|
+
staticResourceAttribute,
|
|
161
|
+
}) {
|
|
162
|
+
const componentProps = {};
|
|
163
|
+
if (classNameList.length) {
|
|
164
|
+
componentProps.className = classNameList.join(' ');
|
|
122
165
|
}
|
|
123
|
-
}
|
|
124
166
|
|
|
125
|
-
|
|
126
|
-
|
|
167
|
+
if (style && Object.keys(style).length) {
|
|
168
|
+
componentProps.style = style;
|
|
169
|
+
}
|
|
170
|
+
if (staticResourceAttribute && staticResourceAttribute.length > 0) {
|
|
171
|
+
componentProps.staticResourceAttribute = staticResourceAttribute;
|
|
172
|
+
}
|
|
173
|
+
return componentProps;
|
|
174
|
+
}
|
|
127
175
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
176
|
+
// 选区的预览的click事件
|
|
177
|
+
const onCustomEvent = ({ order: index, blockKey }) => {
|
|
178
|
+
if (index !== undefined) {
|
|
179
|
+
indexRef.current = index;
|
|
180
|
+
typeRef.current = blockKey;
|
|
181
|
+
}
|
|
132
182
|
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function getForList(compId, dataBinds, parentForItems, dataContext) {
|
|
136
|
-
/**
|
|
137
|
-
* For循环渲染
|
|
138
|
-
* @important
|
|
139
|
-
* @default undfined // 代表没有进行for循环绑定
|
|
140
|
-
*/
|
|
141
|
-
let forList = undefined;
|
|
142
183
|
|
|
184
|
+
// For循环渲染
|
|
185
|
+
let forList;
|
|
143
186
|
try {
|
|
144
187
|
// 绑定了 for 变量,但计算值错误时,应当空数组兜底
|
|
145
188
|
forList =
|
|
146
189
|
dataBinds &&
|
|
147
190
|
dataBinds._waFor &&
|
|
148
|
-
(dataBinds._waFor(parentForItems, undefined,
|
|
191
|
+
(dataBinds._waFor(parentForItems, undefined, context) || []);
|
|
149
192
|
} catch (e) {
|
|
150
193
|
// 计算值出错则使用空数组兜底
|
|
151
194
|
forList = [];
|
|
152
195
|
console.warn('_waFor data', e);
|
|
153
196
|
}
|
|
154
|
-
|
|
155
|
-
// 绑定了for 并且计算了值,但是不是数组类型,应该进行兜底
|
|
156
197
|
if (forList) {
|
|
157
198
|
if (!Array.isArray(forList)) {
|
|
158
199
|
console.warn(`${compId}循环绑定非数组值:`, forList);
|
|
159
200
|
forList = [];
|
|
160
201
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
context,
|
|
176
|
-
children,
|
|
177
|
-
updateContext,
|
|
178
|
-
}) {
|
|
179
|
-
const {
|
|
180
|
-
scopeContext,
|
|
181
|
-
forContext,
|
|
182
|
-
forIndexes,
|
|
183
|
-
widgetsData,
|
|
184
|
-
codeContext,
|
|
185
|
-
dataContext,
|
|
186
|
-
} = context;
|
|
187
|
-
|
|
188
|
-
const injectContext = {};
|
|
189
|
-
const indexRef = React.useRef();
|
|
190
|
-
const typeRef = React.useRef();
|
|
191
|
-
const { 'x-props': xProps } = componentSchema;
|
|
192
|
-
let { staticResourceAttribute = [], listenerInstances = [] } = xProps;
|
|
193
|
-
|
|
194
|
-
// 组件最终用于执行的事件函数
|
|
195
|
-
const emit = React.useCallback(
|
|
196
|
-
(trigger, listeners, eventData, forItems, domEvent, scopeContext) => {
|
|
197
|
-
// 当组件是数据容器并且listeners未含有onDataChange事件时,增加一个onDataChange事件
|
|
198
|
-
if (componentSchema?.compConfig?.isDataContainer) {
|
|
199
|
-
listeners = listeners.concat({
|
|
200
|
-
key: `wa${Date.now().toString().slice(-8)}`,
|
|
201
|
-
trigger: 'onDataChange',
|
|
202
|
-
isCapturePhase: false,
|
|
203
|
-
data: {},
|
|
204
|
-
dataBinds: {},
|
|
205
|
-
instanceFunction: ({ event }) => {
|
|
206
|
-
return updateContext(id, event?.detail?.data);
|
|
207
|
-
},
|
|
208
|
-
});
|
|
202
|
+
return forList.map((item, index) => {
|
|
203
|
+
const forItemsIndexes = (parentForItems.forIndexes || []).concat(index);
|
|
204
|
+
const forItems = {
|
|
205
|
+
...parentForItems,
|
|
206
|
+
[compId]: item,
|
|
207
|
+
forIndexes: forItemsIndexes,
|
|
208
|
+
};
|
|
209
|
+
const {
|
|
210
|
+
fieldData: forItemData,
|
|
211
|
+
finalStyle: forItemStyle,
|
|
212
|
+
finalClassNameList: forItemClassNameList,
|
|
213
|
+
} = getBindData(forItems, scopeContext);
|
|
214
|
+
if (!checkVisible(forItemData)) {
|
|
215
|
+
return null;
|
|
209
216
|
}
|
|
210
217
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
listeners,
|
|
215
|
-
eventData,
|
|
216
|
-
forItems,
|
|
217
|
-
domEvent,
|
|
218
|
-
scopeContext
|
|
219
|
-
);
|
|
220
|
-
} else {
|
|
221
|
-
const event = {
|
|
222
|
-
detail: eventData,
|
|
223
|
-
name: trigger,
|
|
224
|
-
target: widgetsData,
|
|
225
|
-
currentTarget: widgetsData,
|
|
226
|
-
domEvent,
|
|
227
|
-
};
|
|
228
|
-
forItems = {
|
|
229
|
-
...forItems,
|
|
230
|
-
forIndexes: getForIndexes(forItems, widgetsData),
|
|
231
|
-
};
|
|
232
|
-
emitEvent(
|
|
233
|
-
trigger,
|
|
234
|
-
listeners,
|
|
218
|
+
const slotMap = generateSlotMap(
|
|
219
|
+
generateSlotMetaMap(
|
|
220
|
+
componentSchema,
|
|
235
221
|
{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
},
|
|
241
|
-
scopeContext,
|
|
242
|
-
dataContext
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
[widgetsData]
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const currentWidget = Array.isArray(widgetsData)
|
|
250
|
-
? get(widgetsData, forIndexes)
|
|
251
|
-
: widgetsData;
|
|
252
|
-
|
|
253
|
-
if (!Array.isArray(staticResourceAttribute)) {
|
|
254
|
-
staticResourceAttribute = [];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// 判断为容器组件,则增加一个onDataChange事件
|
|
258
|
-
if (
|
|
259
|
-
componentSchema?.compConfig?.isDataContainer &&
|
|
260
|
-
!events?.includes('onDataChange')
|
|
261
|
-
) {
|
|
262
|
-
events.push('onDataChange');
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return (
|
|
266
|
-
<Field
|
|
267
|
-
data={{
|
|
268
|
-
...data,
|
|
269
|
-
_selectableBlockEvents: {
|
|
270
|
-
onCustomEvent: ({ order: index, blockKey }) => {
|
|
271
|
-
if (index !== undefined) {
|
|
272
|
-
indexRef.current = index;
|
|
273
|
-
typeRef.current = blockKey;
|
|
274
|
-
}
|
|
222
|
+
..._context,
|
|
223
|
+
forContext: forItems,
|
|
224
|
+
virtualFields,
|
|
225
|
+
updateContext,
|
|
275
226
|
},
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
emit: (trigger, evt, domEvent) =>
|
|
280
|
-
emit(
|
|
281
|
-
trigger,
|
|
282
|
-
indexRef?.current !== undefined &&
|
|
283
|
-
typeRef?.current &&
|
|
284
|
-
data?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.[
|
|
285
|
-
'x-props'
|
|
286
|
-
]?.listenerInstances,
|
|
287
|
-
evt,
|
|
288
|
-
forContext,
|
|
289
|
-
domEvent,
|
|
290
|
-
scopeContext
|
|
291
|
-
),
|
|
292
|
-
},
|
|
293
|
-
}}
|
|
294
|
-
id={id}
|
|
295
|
-
emit={(trigger, eventData, domEvent) =>
|
|
296
|
-
emit(
|
|
297
|
-
trigger,
|
|
298
|
-
listenerInstances,
|
|
299
|
-
eventData,
|
|
300
|
-
forContext,
|
|
301
|
-
domEvent,
|
|
302
|
-
scopeContext
|
|
227
|
+
{
|
|
228
|
+
renderSlot,
|
|
229
|
+
}
|
|
303
230
|
)
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
xProps,
|
|
332
|
-
virtualFields,
|
|
333
|
-
renderSlot,
|
|
334
|
-
codeContext,
|
|
335
|
-
scopeContext,
|
|
336
|
-
context = {},
|
|
337
|
-
updateContext,
|
|
338
|
-
emitEvents = [],
|
|
339
|
-
componentSchema = {},
|
|
340
|
-
forContext: parentForItems = {},
|
|
341
|
-
} = props;
|
|
342
|
-
|
|
343
|
-
const _context = {
|
|
344
|
-
scopeContext,
|
|
345
|
-
forContext: parentForItems,
|
|
346
|
-
codeContext,
|
|
347
|
-
dataContext: context,
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
const isInComposite = !!codeContext;
|
|
351
|
-
// 判断 widgets 是从 page 来的,还是组件来的
|
|
352
|
-
const widgetsData = !isInComposite
|
|
353
|
-
? $page.widgets[compId]
|
|
354
|
-
: codeContext.$WEAPPS_COMP.widgets[compId];
|
|
355
|
-
|
|
356
|
-
if (!xProps) {
|
|
357
|
-
return (
|
|
358
|
-
<>
|
|
359
|
-
{getComponentChildren(componentSchema, {
|
|
360
|
-
..._context,
|
|
361
|
-
virtualFields,
|
|
362
|
-
updateContext,
|
|
363
|
-
})}
|
|
364
|
-
</>
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const { commonStyle = {}, sourceKey, dataBinds, classNameList = [] } = xProps;
|
|
369
|
-
const Field = virtualFields[sourceKey];
|
|
370
|
-
|
|
371
|
-
// For循环渲染
|
|
372
|
-
let forList = getForList(compId, dataBinds, parentForItems, context);
|
|
373
|
-
|
|
374
|
-
if (forList) {
|
|
375
|
-
return forList
|
|
376
|
-
.map((item, index) => {
|
|
377
|
-
const forItemsIndexes = (parentForItems['forIndexes'] || []).concat(
|
|
378
|
-
index
|
|
379
|
-
);
|
|
380
|
-
const forItems = {
|
|
381
|
-
...parentForItems,
|
|
382
|
-
[compId]: item,
|
|
383
|
-
forIndexes: forItemsIndexes,
|
|
384
|
-
};
|
|
385
|
-
const {
|
|
386
|
-
fieldData: forItemData,
|
|
387
|
-
finalStyle: forItemStyle,
|
|
388
|
-
finalClassNameList: forItemClassNameList,
|
|
389
|
-
} = getBindData({
|
|
390
|
-
widgetData: widgetsData,
|
|
391
|
-
forItems,
|
|
392
|
-
scopeContext,
|
|
393
|
-
codeContext,
|
|
394
|
-
commonStyle,
|
|
395
|
-
classNameList,
|
|
396
|
-
});
|
|
397
|
-
if (!checkVisible(forItemData)) {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const emitWithForItems = (trigger, evt) =>
|
|
234
|
+
emit(trigger, evt, forItems, scopeContext);
|
|
235
|
+
|
|
236
|
+
const _selectableBlockEventsForItems = {
|
|
237
|
+
onCustomEvent,
|
|
238
|
+
events:
|
|
239
|
+
componentSchema?.selectableBlock?.events.map((item) => item.name) ||
|
|
240
|
+
[],
|
|
241
|
+
emit: (trigger, evt) =>
|
|
242
|
+
emitSB(trigger, evt, forItems, scopeContext, forItemData),
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
delete forItemData.style;
|
|
246
|
+
|
|
247
|
+
// 获取当前元素的 ref
|
|
248
|
+
const currentWidget = Array.isArray(widgetsData)
|
|
249
|
+
? get(widgetsData, forItemsIndexes)
|
|
250
|
+
: widgetsData;
|
|
251
|
+
const domRef = setGetDomApi(currentWidget, isInComposite);
|
|
252
|
+
|
|
253
|
+
const componentProps = getSafeComponentProps({
|
|
254
|
+
style: forItemStyle,
|
|
255
|
+
classNameList: forItemClassNameList,
|
|
256
|
+
staticResourceAttribute,
|
|
257
|
+
});
|
|
400
258
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
updateContext,
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
renderSlot,
|
|
412
|
-
}
|
|
413
|
-
)
|
|
414
|
-
);
|
|
259
|
+
// 判断为容器组件,则增加一个onDataChange事件
|
|
260
|
+
if (
|
|
261
|
+
componentSchema?.compConfig?.isDataContainer &&
|
|
262
|
+
!emitEvents?.includes('onDataChange')
|
|
263
|
+
) {
|
|
264
|
+
emitEvents.push('onDataChange');
|
|
265
|
+
}
|
|
415
266
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
compositeParent={codeContext}
|
|
439
|
-
>
|
|
440
|
-
{getComponentChildren(componentSchema, {
|
|
441
|
-
..._context,
|
|
442
|
-
forContext: forItems,
|
|
443
|
-
virtualFields,
|
|
444
|
-
updateContext,
|
|
445
|
-
})}
|
|
446
|
-
</FieldWrapper>
|
|
447
|
-
</ForContext.Provider>
|
|
448
|
-
);
|
|
449
|
-
})
|
|
450
|
-
.filter((item) => !!item);
|
|
267
|
+
return (
|
|
268
|
+
<ForContext.Provider key={index} value={forItems}>
|
|
269
|
+
<Field
|
|
270
|
+
data={{
|
|
271
|
+
...forItemData,
|
|
272
|
+
...slotMap,
|
|
273
|
+
_selectableBlockEvents: _selectableBlockEventsForItems,
|
|
274
|
+
}}
|
|
275
|
+
id={compId}
|
|
276
|
+
{...componentProps}
|
|
277
|
+
emit={emitWithForItems}
|
|
278
|
+
events={emitEvents}
|
|
279
|
+
compositeParent={codeContext}
|
|
280
|
+
forIndexes={forItemsIndexes}
|
|
281
|
+
$node={currentWidget}
|
|
282
|
+
domRef={domRef}
|
|
283
|
+
>
|
|
284
|
+
{props.children}
|
|
285
|
+
</Field>
|
|
286
|
+
</ForContext.Provider>
|
|
287
|
+
);
|
|
288
|
+
});
|
|
451
289
|
}
|
|
452
290
|
|
|
453
|
-
// 修正 forIndexes
|
|
454
|
-
const forIndexes = getForIndexes(parentForItems, widgetsData);
|
|
455
|
-
|
|
456
291
|
// 单节点渲染
|
|
457
|
-
const { fieldData, finalClassNameList, finalStyle } = getBindData(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
292
|
+
const { fieldData, finalClassNameList, finalStyle } = getBindData(
|
|
293
|
+
parentForItems,
|
|
294
|
+
scopeContext
|
|
295
|
+
);
|
|
296
|
+
const emitWithForItems = (trigger, evt) =>
|
|
297
|
+
emit(trigger, evt, parentForItems, scopeContext);
|
|
298
|
+
|
|
299
|
+
const _selectableBlockEventsWithItem = {
|
|
300
|
+
onCustomEvent,
|
|
301
|
+
events:
|
|
302
|
+
componentSchema?.selectableBlock?.events.map((item) => item.name) || [],
|
|
303
|
+
emit: (trigger, evt) =>
|
|
304
|
+
emitSB(trigger, evt, parentForItems, scopeContext, fieldData),
|
|
305
|
+
};
|
|
465
306
|
|
|
466
307
|
// false 或空字符串时
|
|
467
308
|
if (!checkVisible(fieldData)) {
|
|
@@ -483,37 +324,106 @@ export function getComponentRenderList(props) {
|
|
|
483
324
|
)
|
|
484
325
|
);
|
|
485
326
|
|
|
327
|
+
// 防止渲染时 data 的 style 与实际的 style 冲突
|
|
328
|
+
delete fieldData.style;
|
|
329
|
+
|
|
330
|
+
// 修正 forIndexes
|
|
331
|
+
const forIndexes = getForIndexes(parentForItems, widgetsData);
|
|
332
|
+
|
|
333
|
+
// 获取 Element Ref
|
|
334
|
+
const currentWidget = Array.isArray(widgetsData)
|
|
335
|
+
? get(widgetsData, forIndexes)
|
|
336
|
+
: widgetsData;
|
|
337
|
+
const domRef = setGetDomApi(currentWidget, props);
|
|
338
|
+
|
|
339
|
+
const componentProps = getSafeComponentProps({
|
|
340
|
+
style: finalStyle,
|
|
341
|
+
classNameList: finalClassNameList,
|
|
342
|
+
staticResourceAttribute,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// 判断为容器组件,则增加一个onDataChange事件
|
|
346
|
+
if (
|
|
347
|
+
componentSchema?.compConfig?.isDataContainer &&
|
|
348
|
+
!emitEvents?.includes('onDataChange')
|
|
349
|
+
) {
|
|
350
|
+
emitEvents.push('onDataChange');
|
|
351
|
+
}
|
|
352
|
+
|
|
486
353
|
return (
|
|
487
|
-
<
|
|
488
|
-
key={key}
|
|
489
|
-
Field={Field}
|
|
490
|
-
componentSchema={componentSchema}
|
|
491
|
-
context={{
|
|
492
|
-
..._context,
|
|
493
|
-
forIndexes: forIndexes,
|
|
494
|
-
widgetsData,
|
|
495
|
-
}}
|
|
496
|
-
id={compId}
|
|
497
|
-
updateContext={updateContext}
|
|
354
|
+
<Field
|
|
498
355
|
data={{
|
|
499
356
|
...fieldData,
|
|
500
357
|
...slotMap,
|
|
358
|
+
_selectableBlockEvents: _selectableBlockEventsWithItem,
|
|
501
359
|
}}
|
|
502
|
-
{
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
})}
|
|
360
|
+
id={compId}
|
|
361
|
+
{...componentProps}
|
|
362
|
+
emit={emitWithForItems}
|
|
506
363
|
events={emitEvents}
|
|
507
364
|
compositeParent={codeContext}
|
|
365
|
+
forIndexes={forIndexes}
|
|
366
|
+
$node={currentWidget}
|
|
367
|
+
domRef={domRef}
|
|
508
368
|
>
|
|
509
|
-
{
|
|
510
|
-
|
|
511
|
-
virtualFields,
|
|
512
|
-
updateContext,
|
|
513
|
-
})}
|
|
514
|
-
</FieldWrapper>
|
|
369
|
+
{props.children}
|
|
370
|
+
</Field>
|
|
515
371
|
);
|
|
516
|
-
|
|
372
|
+
|
|
373
|
+
// TODO: 需要不断移除 dataBinds(style/classList)
|
|
374
|
+
function getBindData(forItems, scopeContext) {
|
|
375
|
+
// bindData
|
|
376
|
+
let wData = widgetsData;
|
|
377
|
+
if (Array.isArray(wData)) {
|
|
378
|
+
wData =
|
|
379
|
+
forItems.forIndexes === void 0 || wData.length === 0
|
|
380
|
+
? {}
|
|
381
|
+
: get(wData, getForIndexes(forItems, wData));
|
|
382
|
+
}
|
|
383
|
+
wData = wData || {};
|
|
384
|
+
const fieldData = { ...wData };
|
|
385
|
+
|
|
386
|
+
// 再次计算 scope value
|
|
387
|
+
for (let key in fieldData) {
|
|
388
|
+
if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
|
|
389
|
+
const value = fieldData[key];
|
|
390
|
+
if (value && value.__type === 'scopedValue') {
|
|
391
|
+
try {
|
|
392
|
+
fieldData[key] = value.getValue(scopeContext);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
console.warn(`Error computing data bind '${key}' error:`, e);
|
|
395
|
+
fieldData[key] = '';
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// bindStyle
|
|
402
|
+
let bindStyle = fieldData.style || {};
|
|
403
|
+
// 复合组件第一层需要将最外层样式 style 挂到节点上
|
|
404
|
+
let cssStyle = commonStyle;
|
|
405
|
+
if (isInComposite && wData && !wData.parent) {
|
|
406
|
+
cssStyle = {
|
|
407
|
+
...cssStyle,
|
|
408
|
+
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
409
|
+
};
|
|
410
|
+
bindStyle = {
|
|
411
|
+
...bindStyle,
|
|
412
|
+
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
const finalStyle = getFinalStyle(cssStyle, bindStyle);
|
|
416
|
+
|
|
417
|
+
// bindClassList
|
|
418
|
+
const bindClassList = fieldData.classList || [];
|
|
419
|
+
const finalClassNameList = getFinalClassNameList(
|
|
420
|
+
classNameList,
|
|
421
|
+
bindClassList
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
return { fieldData, finalStyle, finalClassNameList };
|
|
425
|
+
}
|
|
426
|
+
});
|
|
517
427
|
|
|
518
428
|
export function getFinalStyle(
|
|
519
429
|
commonStyle = {},
|