@cloudbase/framework-plugin-low-code 0.7.0 → 0.7.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.
- package/package.json +1 -1
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/weapps-api.js +3 -1
- package/template/mp/common/util.js +46 -0
- package/template/mp/common/weapp-page.js +14 -1
- package/template/mp/package.json +2 -2
- package/template/mp/page/index.js +3 -1
- package/template/package.json +2 -2
- package/template/src/app/global-api.js +5 -2
- package/template/src/handlers/FieldMiddleware/renderer.jsx +411 -321
- package/template/src/handlers/render.jsx +114 -97
- package/template/src/handlers/utils/common.js +1 -1
- package/template/src/pages/app.tpl +26 -25
- package/template/src/utils/formatEnum.js +42 -0
|
@@ -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 { generateSlotMetaMap } from '../render';
|
|
10
|
+
import { getComponentChildren, generateSlotMetaMap } from '../render';
|
|
11
11
|
|
|
12
12
|
export const ForContext = createContext({});
|
|
13
13
|
|
|
@@ -35,275 +35,434 @@ function generateSlotMap(slots, forContext = undefined) {
|
|
|
35
35
|
return map;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
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;
|
|
51
|
-
|
|
52
|
-
const indexRef = useRef();
|
|
53
|
-
const typeRef = useRef();
|
|
38
|
+
function getSafeComponentProps({ style, classNameList }) {
|
|
39
|
+
const componentProps = {};
|
|
54
40
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const widgetsData = !isInComposite
|
|
58
|
-
? $page.widgets[compId]
|
|
59
|
-
: codeContext.$WEAPPS_COMP.widgets[compId];
|
|
60
|
-
|
|
61
|
-
if (!xProps) {
|
|
62
|
-
return props.children;
|
|
41
|
+
if (classNameList.length) {
|
|
42
|
+
componentProps.className = classNameList.join(' ');
|
|
63
43
|
}
|
|
64
44
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
};
|
|
45
|
+
if (style && Object.keys(style).length) {
|
|
46
|
+
componentProps.style = style;
|
|
47
|
+
}
|
|
48
|
+
return componentProps;
|
|
49
|
+
}
|
|
85
50
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
51
|
+
// TODO: 需要不断移除 dataBinds(style/classList)
|
|
52
|
+
function getBindData({
|
|
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));
|
|
66
|
+
}
|
|
67
|
+
widgetData = widgetData || {};
|
|
68
|
+
const fieldData = { ...widgetData };
|
|
69
|
+
|
|
70
|
+
const isRootNode = widgetData && !widgetData.parent;
|
|
71
|
+
const isInComposite = !!codeContext;
|
|
72
|
+
|
|
73
|
+
// 再次计算 scope value
|
|
74
|
+
for (let key in fieldData) {
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
|
|
76
|
+
const value = fieldData[key];
|
|
77
|
+
if (value && value.__type === 'scopedValue') {
|
|
78
|
+
try {
|
|
79
|
+
fieldData[key] = value.getValue(scopeContext);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.warn(`Error computing data bind '${key}' error:`, e);
|
|
82
|
+
fieldData[key] = '';
|
|
83
|
+
}
|
|
106
84
|
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
107
87
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
124
|
-
},
|
|
125
|
-
[props]
|
|
126
|
-
);
|
|
127
|
-
|
|
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]
|
|
155
|
-
);
|
|
88
|
+
// bindStyle
|
|
89
|
+
let bindStyle = fieldData.style || {};
|
|
90
|
+
// 复合组件第一层需要将最外层样式 style 挂到节点上
|
|
91
|
+
let cssStyle = commonStyle || {};
|
|
92
|
+
if (isInComposite && isRootNode) {
|
|
93
|
+
cssStyle = {
|
|
94
|
+
...cssStyle,
|
|
95
|
+
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
96
|
+
};
|
|
97
|
+
bindStyle = {
|
|
98
|
+
...bindStyle,
|
|
99
|
+
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const finalStyle = getFinalStyle(cssStyle, bindStyle);
|
|
156
103
|
|
|
157
|
-
|
|
158
|
-
|
|
104
|
+
// bindClassList
|
|
105
|
+
const bindClassList = fieldData.classList || [];
|
|
106
|
+
const finalClassNameList = getFinalClassNameList(
|
|
159
107
|
classNameList,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const componentProps = {};
|
|
163
|
-
if (classNameList.length) {
|
|
164
|
-
componentProps.className = classNameList.join(' ');
|
|
165
|
-
}
|
|
108
|
+
bindClassList
|
|
109
|
+
);
|
|
166
110
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
111
|
+
// 当前在复合组件中,且当前节点为根节点
|
|
112
|
+
if (isInComposite && isRootNode) {
|
|
113
|
+
if (widgetData.ownerWidget) {
|
|
114
|
+
Object.keys(widgetData.ownerWidget).forEach((propName) => {
|
|
115
|
+
if (
|
|
116
|
+
propName === 'role' ||
|
|
117
|
+
['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))
|
|
118
|
+
) {
|
|
119
|
+
widgetData[propName] = widgetData.ownerWidget[propName];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
172
122
|
}
|
|
173
|
-
return componentProps;
|
|
174
123
|
}
|
|
175
124
|
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
125
|
+
// 防止渲染时 data 的 style 与实际的 style 冲突
|
|
126
|
+
delete fieldData.style;
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
fieldData,
|
|
130
|
+
finalStyle,
|
|
131
|
+
finalClassNameList: Array.from(new Set(finalClassNameList)),
|
|
182
132
|
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getForList(compId, dataBinds, parentForItems, dataContext) {
|
|
136
|
+
/**
|
|
137
|
+
* For循环渲染
|
|
138
|
+
* @important
|
|
139
|
+
* @default undfined // 代表没有进行for循环绑定
|
|
140
|
+
*/
|
|
141
|
+
let forList = undefined;
|
|
183
142
|
|
|
184
|
-
// For循环渲染
|
|
185
|
-
let forList;
|
|
186
143
|
try {
|
|
187
144
|
// 绑定了 for 变量,但计算值错误时,应当空数组兜底
|
|
188
145
|
forList =
|
|
189
146
|
dataBinds &&
|
|
190
147
|
dataBinds._waFor &&
|
|
191
|
-
(dataBinds._waFor(parentForItems, undefined,
|
|
148
|
+
(dataBinds._waFor(parentForItems, undefined, dataContext) || []);
|
|
192
149
|
} catch (e) {
|
|
193
150
|
// 计算值出错则使用空数组兜底
|
|
194
151
|
forList = [];
|
|
195
152
|
console.warn('_waFor data', e);
|
|
196
153
|
}
|
|
154
|
+
|
|
155
|
+
// 绑定了for 并且计算了值,但是不是数组类型,应该进行兜底
|
|
197
156
|
if (forList) {
|
|
198
157
|
if (!Array.isArray(forList)) {
|
|
199
158
|
console.warn(`${compId}循环绑定非数组值:`, forList);
|
|
200
159
|
forList = [];
|
|
201
160
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return forList;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function FieldWrapper({
|
|
167
|
+
Field,
|
|
168
|
+
componentSchema,
|
|
169
|
+
id,
|
|
170
|
+
data,
|
|
171
|
+
style = {},
|
|
172
|
+
className = '',
|
|
173
|
+
events,
|
|
174
|
+
compositeParent,
|
|
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
|
+
});
|
|
216
209
|
}
|
|
217
210
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
if (injectContext?.emit) {
|
|
212
|
+
return injectContext.emit(
|
|
213
|
+
trigger,
|
|
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,
|
|
221
235
|
{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
236
|
+
event,
|
|
237
|
+
customEventData: event,
|
|
238
|
+
forItems,
|
|
239
|
+
domEvent,
|
|
226
240
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
)
|
|
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
|
-
});
|
|
258
|
-
|
|
259
|
-
// 判断为容器组件,则增加一个onDataChange事件
|
|
260
|
-
if (
|
|
261
|
-
componentSchema?.compConfig?.isDataContainer &&
|
|
262
|
-
!emitEvents?.includes('onDataChange')
|
|
263
|
-
) {
|
|
264
|
-
emitEvents.push('onDataChange');
|
|
241
|
+
scopeContext,
|
|
242
|
+
dataContext
|
|
243
|
+
);
|
|
265
244
|
}
|
|
245
|
+
},
|
|
246
|
+
[widgetsData]
|
|
247
|
+
);
|
|
266
248
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
});
|
|
249
|
+
const currentWidget = Array.isArray(widgetsData)
|
|
250
|
+
? get(widgetsData, forIndexes)
|
|
251
|
+
: widgetsData;
|
|
252
|
+
|
|
253
|
+
if (!Array.isArray(staticResourceAttribute)) {
|
|
254
|
+
staticResourceAttribute = [];
|
|
289
255
|
}
|
|
290
256
|
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}
|
|
275
|
+
},
|
|
276
|
+
events:
|
|
277
|
+
componentSchema?.selectableBlock?.events.map((item) => item.name) ||
|
|
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
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
events={events}
|
|
306
|
+
compositeParent={compositeParent}
|
|
307
|
+
forIndexes={forIndexes}
|
|
308
|
+
$node={currentWidget}
|
|
309
|
+
domRef={setGetDomApi(currentWidget, { codeContext })}
|
|
310
|
+
style={style}
|
|
311
|
+
className={className}
|
|
312
|
+
staticResourceAttribute={staticResourceAttribute}
|
|
313
|
+
>
|
|
314
|
+
{children}
|
|
315
|
+
</Field>
|
|
295
316
|
);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export const CompRenderer = observer(function (props) {
|
|
320
|
+
return getComponentRenderList({
|
|
321
|
+
...props,
|
|
322
|
+
forContext: React.createContext(ForContext),
|
|
323
|
+
injectContext: {},
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
export function getComponentRenderList(props) {
|
|
328
|
+
const {
|
|
329
|
+
key = undefined,
|
|
330
|
+
id: compId,
|
|
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,
|
|
305
348
|
};
|
|
306
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
|
+
}
|
|
400
|
+
|
|
401
|
+
const slotMap = generateSlotMap(
|
|
402
|
+
generateSlotMetaMap(
|
|
403
|
+
componentSchema,
|
|
404
|
+
{
|
|
405
|
+
..._context,
|
|
406
|
+
forContext: forItems,
|
|
407
|
+
virtualFields,
|
|
408
|
+
updateContext,
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
renderSlot,
|
|
412
|
+
}
|
|
413
|
+
)
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
return (
|
|
417
|
+
<ForContext.Provider key={index} value={forItems}>
|
|
418
|
+
<FieldWrapper
|
|
419
|
+
Field={Field}
|
|
420
|
+
componentSchema={componentSchema}
|
|
421
|
+
context={{
|
|
422
|
+
..._context,
|
|
423
|
+
widgetsData,
|
|
424
|
+
forContext: forItems,
|
|
425
|
+
forIndexes: forItemsIndexes,
|
|
426
|
+
}}
|
|
427
|
+
id={compId}
|
|
428
|
+
updateContext={updateContext}
|
|
429
|
+
data={{
|
|
430
|
+
...forItemData,
|
|
431
|
+
...slotMap,
|
|
432
|
+
}}
|
|
433
|
+
{...getSafeComponentProps({
|
|
434
|
+
style: forItemStyle,
|
|
435
|
+
classNameList: forItemClassNameList,
|
|
436
|
+
})}
|
|
437
|
+
events={emitEvents}
|
|
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);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// 修正 forIndexes
|
|
454
|
+
const forIndexes = getForIndexes(parentForItems, widgetsData);
|
|
455
|
+
|
|
456
|
+
// 单节点渲染
|
|
457
|
+
const { fieldData, finalClassNameList, finalStyle } = getBindData({
|
|
458
|
+
widgetData: widgetsData,
|
|
459
|
+
forItems: parentForItems,
|
|
460
|
+
scopeContext,
|
|
461
|
+
codeContext,
|
|
462
|
+
commonStyle,
|
|
463
|
+
classNameList,
|
|
464
|
+
});
|
|
465
|
+
|
|
307
466
|
// false 或空字符串时
|
|
308
467
|
if (!checkVisible(fieldData)) {
|
|
309
468
|
return null;
|
|
@@ -324,106 +483,37 @@ export const CompRenderer = observer(function (props) {
|
|
|
324
483
|
)
|
|
325
484
|
);
|
|
326
485
|
|
|
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
|
-
|
|
353
486
|
return (
|
|
354
|
-
<
|
|
487
|
+
<FieldWrapper
|
|
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}
|
|
355
498
|
data={{
|
|
356
499
|
...fieldData,
|
|
357
500
|
...slotMap,
|
|
358
|
-
_selectableBlockEvents: _selectableBlockEventsWithItem,
|
|
359
501
|
}}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
502
|
+
{...getSafeComponentProps({
|
|
503
|
+
style: finalStyle,
|
|
504
|
+
classNameList: finalClassNameList,
|
|
505
|
+
})}
|
|
363
506
|
events={emitEvents}
|
|
364
507
|
compositeParent={codeContext}
|
|
365
|
-
forIndexes={forIndexes}
|
|
366
|
-
$node={currentWidget}
|
|
367
|
-
domRef={domRef}
|
|
368
508
|
>
|
|
369
|
-
{
|
|
370
|
-
|
|
509
|
+
{getComponentChildren(componentSchema, {
|
|
510
|
+
..._context,
|
|
511
|
+
virtualFields,
|
|
512
|
+
updateContext,
|
|
513
|
+
})}
|
|
514
|
+
</FieldWrapper>
|
|
371
515
|
);
|
|
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
|
-
});
|
|
516
|
+
}
|
|
427
517
|
|
|
428
518
|
export function getFinalStyle(
|
|
429
519
|
commonStyle = {},
|