@cloudbase/lowcode-builder 0.1.26 → 1.0.2
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/index.d.ts +1 -3
- package/lib/builder/core/index.js +42 -52
- package/lib/builder/h5/compile.d.ts +1 -1
- package/lib/builder/h5/compile.js +59 -20
- package/lib/builder/h5/copy.js +2 -4
- package/lib/builder/h5/generate.js +3 -3
- package/lib/builder/h5/index.d.ts +5 -4
- package/lib/builder/h5/index.js +25 -14
- package/lib/builder/h5/material.js +6 -11
- package/lib/builder/h5/npm.js +6 -5
- package/lib/builder/mp/index.js +38 -49
- package/lib/builder/mp/materials.js +25 -18
- package/lib/builder/mp/mixMode.js +7 -10
- package/lib/builder/mp/mp_config.js +2 -3
- package/lib/builder/mp/wxml.js +1 -1
- package/lib/builder/service/webpack.d.ts +7 -1
- package/lib/builder/service/webpack.js +97 -24
- package/lib/builder/types/common.d.ts +1 -1
- package/lib/builder/types/common.js +2 -1
- package/lib/builder/util/common.js +1 -4
- package/lib/builder/util/generateFiles.js +12 -10
- package/lib/builder/util/mp.js +2 -8
- package/lib/builder.web.js +71 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +6 -0
- package/lib/types.d.ts +1 -0
- package/lib/types.js +11 -0
- package/package.json +3 -8
- package/template/html/index.html.ejs +59 -29
- package/template/mp/common/weapp-page.js +23 -1
- package/template/mp/common/weapp-sdk.js +35 -0
- package/template/mp/package.json +1 -1
- package/template/mp/page/index.js +2 -1
- package/template/package.json +5 -2
- package/template/webpack/getCSSModuleLocalIdent.js +28 -0
- package/template/webpack/web.prod.js +112 -103
- package/template/src/app/common.js +0 -13
- package/template/src/app/global-api.js +0 -99
- package/template/src/app/handlers.js +0 -13
- package/template/src/app/material-actions.js +0 -16
- package/template/src/app/mountAppApis.js +0 -25
- package/template/src/app/mountMpApis.js +0 -4
- package/template/src/datasources/config.js.tpl +0 -23
- package/template/src/datasources/dataset-profiles.js.tpl +0 -5
- package/template/src/datasources/datasource-profiles.js.tpl +0 -4
- package/template/src/datasources/index.js +0 -31
- package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -331
- package/template/src/handlers/HotAreas.js +0 -36
- package/template/src/handlers/PositionHandler.jsx +0 -8
- package/template/src/handlers/actionHandler/utils.js +0 -149
- package/template/src/handlers/componentEventActionEmitter.js +0 -29
- package/template/src/handlers/componentNodeMap.js +0 -24
- package/template/src/handlers/controller.js +0 -5
- package/template/src/handlers/emitComponentEvent.js +0 -8
- package/template/src/handlers/eventListener/componentEventListener.js +0 -15
- package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
- package/template/src/handlers/eventListener/index.js +0 -29
- package/template/src/handlers/eventListener/pageEventListener.js +0 -11
- package/template/src/handlers/eventListener/types.js +0 -32
- package/template/src/handlers/hooks/index.js +0 -14
- package/template/src/handlers/initWebEnv.js +0 -4
- package/template/src/handlers/injectStyle.js +0 -14
- package/template/src/handlers/instanceMap.js +0 -39
- package/template/src/handlers/lifecycle.js +0 -232
- package/template/src/handlers/render.jsx +0 -131
- package/template/src/handlers/utils/common.js +0 -151
- package/template/src/handlers/utils/eventProxy.js +0 -64
- package/template/src/handlers/utils/events.js +0 -8
- package/template/src/handlers/utils/index.js +0 -4
- package/template/src/handlers/utils/widgets.js +0 -320
- package/template/src/index.jsx +0 -142
- package/template/src/index.less +0 -119
- package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
- package/template/src/pages/app.tpl +0 -124
- package/template/src/router/index.tpl +0 -28
- package/template/src/store/computed.js +0 -11
- package/template/src/store/index.js +0 -40
- package/template/src/utils/ScanCodeComponent.js +0 -396
- package/template/src/utils/date.js +0 -324
- package/template/src/utils/history.js +0 -72
- package/template/src/utils/index.js +0 -67
- package/template/src/utils/kbone.js +0 -18
- package/template/src/utils/monitor-jssdk.min.js +0 -763
- package/template/src/utils/request.js +0 -5
- package/template/src/utils/scan-code-action.js +0 -27
|
@@ -1,331 +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
|
-
|
|
11
|
-
export const ForContext = createContext({});
|
|
12
|
-
|
|
13
|
-
export const CompRenderer = observer(function (props) {
|
|
14
|
-
const {
|
|
15
|
-
id: compId,
|
|
16
|
-
xProps,
|
|
17
|
-
virtualFields,
|
|
18
|
-
slots = {},
|
|
19
|
-
codeContext,
|
|
20
|
-
scopeContext,
|
|
21
|
-
emitEvents = [],
|
|
22
|
-
} = props;
|
|
23
|
-
|
|
24
|
-
const isInComposite = !!props.codeContext;
|
|
25
|
-
// 判断 widgets 是从 page 来的,还是组件来的
|
|
26
|
-
const widgetsData = !isInComposite
|
|
27
|
-
? $page.widgets[compId]
|
|
28
|
-
: codeContext.$WEAPPS_COMP.widgets[compId];
|
|
29
|
-
|
|
30
|
-
if (!xProps) {
|
|
31
|
-
return props.children;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
commonStyle = {},
|
|
36
|
-
sourceKey,
|
|
37
|
-
data = {},
|
|
38
|
-
dataBinds,
|
|
39
|
-
listenerInstances,
|
|
40
|
-
styleBind,
|
|
41
|
-
classNameList = [],
|
|
42
|
-
classNameListBind,
|
|
43
|
-
staticResourceAttribute = [],
|
|
44
|
-
} = xProps;
|
|
45
|
-
const Field = virtualFields[sourceKey];
|
|
46
|
-
const parentForItems = useContext(ForContext);
|
|
47
|
-
|
|
48
|
-
const emit = useCallback(
|
|
49
|
-
(trigger, event, forItems, scopeContext) => {
|
|
50
|
-
const listeners = listenerInstances;
|
|
51
|
-
event = { detail: event, name: trigger };
|
|
52
|
-
forItems = {
|
|
53
|
-
...forItems,
|
|
54
|
-
forIndexes: getForIndexes(forItems, widgetsData),
|
|
55
|
-
};
|
|
56
|
-
emitEvent(
|
|
57
|
-
trigger,
|
|
58
|
-
listeners,
|
|
59
|
-
{
|
|
60
|
-
event,
|
|
61
|
-
customEventData: event,
|
|
62
|
-
forItems,
|
|
63
|
-
},
|
|
64
|
-
scopeContext
|
|
65
|
-
);
|
|
66
|
-
},
|
|
67
|
-
[props]
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
function getSafeComponentProps({
|
|
71
|
-
style,
|
|
72
|
-
classNameList,
|
|
73
|
-
staticResourceAttribute,
|
|
74
|
-
}) {
|
|
75
|
-
const componentProps = {};
|
|
76
|
-
if (classNameList.length) {
|
|
77
|
-
componentProps.className = classNameList.join(' ');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (style && Object.keys(style).length) {
|
|
81
|
-
componentProps.style = style;
|
|
82
|
-
}
|
|
83
|
-
if (staticResourceAttribute && staticResourceAttribute.length > 0) {
|
|
84
|
-
componentProps.staticResourceAttribute = staticResourceAttribute;
|
|
85
|
-
}
|
|
86
|
-
return componentProps;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// For循环渲染
|
|
90
|
-
let forList;
|
|
91
|
-
try {
|
|
92
|
-
// 绑定了 for 变量,但计算值错误时,应当空数组兜底
|
|
93
|
-
forList =
|
|
94
|
-
dataBinds && dataBinds._waFor && (dataBinds._waFor(parentForItems) || []);
|
|
95
|
-
} catch (e) {
|
|
96
|
-
// 计算值出错则使用空数组兜底
|
|
97
|
-
forList = [];
|
|
98
|
-
console.warn('_waFor data', e);
|
|
99
|
-
}
|
|
100
|
-
if (forList) {
|
|
101
|
-
if (!Array.isArray(forList)) {
|
|
102
|
-
console.warn(`${compId}循环绑定非数组值:`, forList);
|
|
103
|
-
forList = [];
|
|
104
|
-
}
|
|
105
|
-
return forList.map((item, index) => {
|
|
106
|
-
const forItemsIndexes = (parentForItems.forIndexes || []).concat(index);
|
|
107
|
-
const forItems = {
|
|
108
|
-
...parentForItems,
|
|
109
|
-
[compId]: item,
|
|
110
|
-
forIndexes: forItemsIndexes,
|
|
111
|
-
};
|
|
112
|
-
const {
|
|
113
|
-
fieldData: forItemData,
|
|
114
|
-
finalStyle: forItemStyle,
|
|
115
|
-
finalClassNameList: forItemClassNameList,
|
|
116
|
-
} = getBindData(forItems, scopeContext);
|
|
117
|
-
if (!checkVisible(forItemData)) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
// 多个组件的 slot 属性
|
|
121
|
-
Object.keys(slots).forEach((slotProp) => {
|
|
122
|
-
set(forItemData, slotProp, slots[slotProp]);
|
|
123
|
-
});
|
|
124
|
-
const emitWithForItems = (trigger, evt) =>
|
|
125
|
-
emit(trigger, evt, forItems, scopeContext);
|
|
126
|
-
delete forItemData.style;
|
|
127
|
-
|
|
128
|
-
// 获取当前元素的 ref
|
|
129
|
-
const currentWidget = Array.isArray(widgetsData)
|
|
130
|
-
? get(widgetsData, forItemsIndexes)
|
|
131
|
-
: widgetsData;
|
|
132
|
-
const domRef = setGetDomApi(currentWidget, isInComposite);
|
|
133
|
-
|
|
134
|
-
const componentProps = getSafeComponentProps({
|
|
135
|
-
style: forItemStyle,
|
|
136
|
-
classNameList: forItemClassNameList,
|
|
137
|
-
staticResourceAttribute,
|
|
138
|
-
});
|
|
139
|
-
return (
|
|
140
|
-
<ForContext.Provider key={index} value={forItems}>
|
|
141
|
-
<Field
|
|
142
|
-
data={forItemData}
|
|
143
|
-
id={compId}
|
|
144
|
-
{...componentProps}
|
|
145
|
-
emit={emitWithForItems}
|
|
146
|
-
events={emitEvents}
|
|
147
|
-
compositeParent={codeContext}
|
|
148
|
-
forIndexes={forItemsIndexes}
|
|
149
|
-
$node={currentWidget}
|
|
150
|
-
domRef={domRef}
|
|
151
|
-
>
|
|
152
|
-
{props.children}
|
|
153
|
-
</Field>
|
|
154
|
-
</ForContext.Provider>
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 单节点渲染
|
|
160
|
-
const { fieldData, finalClassNameList, finalStyle } = getBindData(
|
|
161
|
-
parentForItems,
|
|
162
|
-
scopeContext
|
|
163
|
-
);
|
|
164
|
-
const emitWithForItems = (trigger, evt) =>
|
|
165
|
-
emit(trigger, evt, parentForItems, scopeContext);
|
|
166
|
-
|
|
167
|
-
// false 或空字符串时
|
|
168
|
-
if (!checkVisible(fieldData)) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// 单个组件的 slot 属性
|
|
173
|
-
Object.keys(slots).forEach((slotProp) => {
|
|
174
|
-
set(fieldData, slotProp, slots[slotProp]);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// 防止渲染时 data 的 style 与实际的 style 冲突
|
|
178
|
-
delete fieldData.style;
|
|
179
|
-
|
|
180
|
-
// 修正 forIndexes
|
|
181
|
-
const forIndexes = getForIndexes(parentForItems, widgetsData);
|
|
182
|
-
|
|
183
|
-
// 获取 Element Ref
|
|
184
|
-
const currentWidget = Array.isArray(widgetsData)
|
|
185
|
-
? get(widgetsData, forIndexes)
|
|
186
|
-
: widgetsData;
|
|
187
|
-
const domRef = setGetDomApi(currentWidget, props);
|
|
188
|
-
|
|
189
|
-
const componentProps = getSafeComponentProps({
|
|
190
|
-
style: finalStyle,
|
|
191
|
-
classNameList: finalClassNameList,
|
|
192
|
-
staticResourceAttribute,
|
|
193
|
-
});
|
|
194
|
-
return (
|
|
195
|
-
<Field
|
|
196
|
-
data={fieldData}
|
|
197
|
-
id={compId}
|
|
198
|
-
{...componentProps}
|
|
199
|
-
emit={emitWithForItems}
|
|
200
|
-
events={emitEvents}
|
|
201
|
-
compositeParent={codeContext}
|
|
202
|
-
forIndexes={forIndexes}
|
|
203
|
-
$node={currentWidget}
|
|
204
|
-
domRef={domRef}
|
|
205
|
-
>
|
|
206
|
-
{props.children}
|
|
207
|
-
</Field>
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
// TODO: 需要不断移除 dataBinds(style/classList)
|
|
211
|
-
function getBindData(forItems, scopeContext) {
|
|
212
|
-
// bindData
|
|
213
|
-
let wData = widgetsData;
|
|
214
|
-
if (Array.isArray(wData)) {
|
|
215
|
-
wData =
|
|
216
|
-
forItems.forIndexes === void 0 || wData.length === 0
|
|
217
|
-
? {}
|
|
218
|
-
: get(wData, getForIndexes(forItems, wData));
|
|
219
|
-
}
|
|
220
|
-
wData = wData || {};
|
|
221
|
-
const fieldData = { ...wData };
|
|
222
|
-
|
|
223
|
-
// 再次计算 scope value
|
|
224
|
-
for (let key in fieldData) {
|
|
225
|
-
if (Object.prototype.hasOwnProperty.call(fieldData, key)) {
|
|
226
|
-
const value = fieldData[key];
|
|
227
|
-
if (value && value.__type === 'scopedValue') {
|
|
228
|
-
try {
|
|
229
|
-
fieldData[key] = value.getValue(scopeContext);
|
|
230
|
-
} catch (e) {
|
|
231
|
-
console.warn(`Error computing data bind '${key}' error:`, e);
|
|
232
|
-
fieldData[key] = '';
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// bindStyle
|
|
239
|
-
let bindStyle = fieldData.style || {};
|
|
240
|
-
// 复合组件第一层需要将最外层样式 style 挂到节点上
|
|
241
|
-
let cssStyle = commonStyle;
|
|
242
|
-
if (isInComposite && wData && !wData.parent) {
|
|
243
|
-
cssStyle = {
|
|
244
|
-
...cssStyle,
|
|
245
|
-
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
246
|
-
};
|
|
247
|
-
bindStyle = {
|
|
248
|
-
...bindStyle,
|
|
249
|
-
...(codeContext.$WEAPPS_COMP.props?.style || {}),
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
const finalStyle = getFinalStyle(cssStyle, bindStyle);
|
|
253
|
-
|
|
254
|
-
// bindClassList
|
|
255
|
-
const bindClassList = fieldData.classList || [];
|
|
256
|
-
const finalClassNameList = getFinalClassNameList(
|
|
257
|
-
classNameList,
|
|
258
|
-
bindClassList
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
return { fieldData, finalStyle, finalClassNameList };
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
export function getFinalStyle(
|
|
266
|
-
commonStyle = {},
|
|
267
|
-
bindStyle = {},
|
|
268
|
-
widgetStyle = {}
|
|
269
|
-
) {
|
|
270
|
-
const remBindStyle =
|
|
271
|
-
typeof bindStyle === 'object' ? translateStyleToRem(bindStyle) : {};
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
...(translateStyleToRem(commonStyle) || {}),
|
|
275
|
-
...(translateStyleToRem(widgetStyle) || {}),
|
|
276
|
-
...remBindStyle,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export function getFinalClassNameList(
|
|
281
|
-
classNameList = [],
|
|
282
|
-
bindClassList = [],
|
|
283
|
-
widgetClassList = []
|
|
284
|
-
) {
|
|
285
|
-
return [].concat(classNameList, bindClassList, widgetClassList);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// HACK: 从后向前保证循环的深度与 forIndexes 一致
|
|
289
|
-
// 后续需要将 For 循环迁移到外层
|
|
290
|
-
function getForIndexes(parentForItems, widgetsData) {
|
|
291
|
-
return Array.isArray(widgetsData) && widgetsData.length > 0
|
|
292
|
-
? (parentForItems.forIndexes || []).slice(0 - getDeepArrLen(widgetsData))
|
|
293
|
-
: undefined;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function getDeepArrLen(arr, len = 0) {
|
|
297
|
-
if (Array.isArray(arr)) {
|
|
298
|
-
return getDeepArrLen(arr[0], len + 1);
|
|
299
|
-
} else {
|
|
300
|
-
return len;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function setGetDomApi(currentWidget, props) {
|
|
305
|
-
if (!currentWidget) return React.createRef();
|
|
306
|
-
const isComposite = !currentWidget.widgetType.startsWith('gsd-h5-react');
|
|
307
|
-
const isInComposite = !!props.codeContext;
|
|
308
|
-
|
|
309
|
-
// 如果当前是复合组件,不做 getDom 的挂载
|
|
310
|
-
if (!isComposite) {
|
|
311
|
-
if (!currentWidget.domRef) {
|
|
312
|
-
currentWidget.domRef = React.createRef();
|
|
313
|
-
}
|
|
314
|
-
if (!currentWidget.getDom) {
|
|
315
|
-
currentWidget.getDom = (options) =>
|
|
316
|
-
getDom(currentWidget.domRef.current, options);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
isInComposite && // 当前在复合组件内
|
|
321
|
-
!currentWidget.parent && // 当前节点为复合组件的根节点
|
|
322
|
-
props.codeContext.node && // 复合组件的 node 已经创建
|
|
323
|
-
!props.codeContext.node.getDom // 复合组件的 node 未挂载 getDom 方法
|
|
324
|
-
) {
|
|
325
|
-
props.codeContext.node.domRef = currentWidget.domRef;
|
|
326
|
-
props.codeContext.node.getDom = currentWidget.getDom;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return currentWidget.domRef;
|
|
331
|
-
}
|
|
@@ -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,149 +0,0 @@
|
|
|
1
|
-
import { resolveDataBinds } from '../utils/common';
|
|
2
|
-
import { set as lodashSet } from 'lodash';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_MAX_TIMEOUT = 10 * 1000;
|
|
5
|
-
|
|
6
|
-
export function getMetaInfoBySourceKey(sourceKey) {
|
|
7
|
-
const [materialName, name] = sourceKey.split(':');
|
|
8
|
-
return {
|
|
9
|
-
materialName,
|
|
10
|
-
name,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function emitEvent(trigger, listeners = [], args, scopeContext = {}) {
|
|
15
|
-
const targetListeners = listeners.filter((l) => l.trigger === trigger);
|
|
16
|
-
targetListeners.forEach(async (listener) => {
|
|
17
|
-
// 当前非捕获Event,再判断冒泡行为
|
|
18
|
-
if (
|
|
19
|
-
!args?.customEventData?.detail?.isCapturePhase &&
|
|
20
|
-
listener.noPropagation
|
|
21
|
-
) {
|
|
22
|
-
args?.customEventData?.detail?.stopPropagation();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 判断捕获的执行,只有执行的捕获与配置的捕获一致时。才会执行。
|
|
26
|
-
if (
|
|
27
|
-
(listener?.isCapturePhase || false) ===
|
|
28
|
-
(args?.customEventData?.detail?.isCapturePhase || false)
|
|
29
|
-
) {
|
|
30
|
-
try {
|
|
31
|
-
const res = await invokeListener(listener, args, scopeContext);
|
|
32
|
-
const eventName = `${listener.key}.success`;
|
|
33
|
-
const event = {
|
|
34
|
-
detail: {
|
|
35
|
-
value: res,
|
|
36
|
-
origin: args.event,
|
|
37
|
-
isCapturePhase: !!args.event?.isCapturePhase,
|
|
38
|
-
},
|
|
39
|
-
name: eventName,
|
|
40
|
-
};
|
|
41
|
-
emitEvent(
|
|
42
|
-
eventName,
|
|
43
|
-
listeners,
|
|
44
|
-
{
|
|
45
|
-
...args,
|
|
46
|
-
event,
|
|
47
|
-
customEventData: event,
|
|
48
|
-
},
|
|
49
|
-
scopeContext
|
|
50
|
-
);
|
|
51
|
-
} catch (e) {
|
|
52
|
-
const eventName = `${listener.key}.fail`;
|
|
53
|
-
const event = {
|
|
54
|
-
detail: {
|
|
55
|
-
value: e,
|
|
56
|
-
origin: args.event,
|
|
57
|
-
isCapturePhase: !!args.event?.isCapturePhase,
|
|
58
|
-
},
|
|
59
|
-
name: eventName,
|
|
60
|
-
};
|
|
61
|
-
emitEvent(
|
|
62
|
-
eventName,
|
|
63
|
-
listeners,
|
|
64
|
-
{
|
|
65
|
-
...args,
|
|
66
|
-
event,
|
|
67
|
-
customEventData: event,
|
|
68
|
-
},
|
|
69
|
-
scopeContext
|
|
70
|
-
);
|
|
71
|
-
// 之前 invoke 内部catch 了错误,不会抛错
|
|
72
|
-
// throw e
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function invokeListener(
|
|
79
|
-
{ instanceFunction, data = {}, dataBinds = {} },
|
|
80
|
-
args,
|
|
81
|
-
scopeContext
|
|
82
|
-
) {
|
|
83
|
-
// ToDo resolve databinds
|
|
84
|
-
const action = instanceFunction;
|
|
85
|
-
let maxTimeout = DEFAULT_MAX_TIMEOUT;
|
|
86
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
87
|
-
if (data._maxTimeout === 'Infinity') maxTimeout = data._maxTimeout;
|
|
88
|
-
const resolvedData = {
|
|
89
|
-
...data,
|
|
90
|
-
};
|
|
91
|
-
const resolvedDataBinds = resolveDataBinds(
|
|
92
|
-
dataBinds,
|
|
93
|
-
args.forItems,
|
|
94
|
-
{ event: args.event },
|
|
95
|
-
scopeContext,
|
|
96
|
-
true
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
100
|
-
for (const key in resolvedDataBinds) {
|
|
101
|
-
if (
|
|
102
|
-
resolvedDataBinds[key] &&
|
|
103
|
-
resolvedDataBinds[key].__type === 'scopedValue'
|
|
104
|
-
) {
|
|
105
|
-
try {
|
|
106
|
-
lodashSet(
|
|
107
|
-
resolvedData,
|
|
108
|
-
key,
|
|
109
|
-
resolvedDataBinds[key].getValue(scopeContext)
|
|
110
|
-
);
|
|
111
|
-
} catch (e) {
|
|
112
|
-
lodashSet(resolvedData, key, '');
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
lodashSet(resolvedData, key, resolvedDataBinds[key]);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const params = {
|
|
120
|
-
data: resolvedData,
|
|
121
|
-
...args,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
if (maxTimeout === 'Infinity') {
|
|
126
|
-
return await action(params);
|
|
127
|
-
}
|
|
128
|
-
const p = action(params);
|
|
129
|
-
if (p instanceof Promise) {
|
|
130
|
-
let timeout = null;
|
|
131
|
-
const r = await Promise.race([
|
|
132
|
-
new Promise((resolve, reject) => {
|
|
133
|
-
timeout = setTimeout(() => {
|
|
134
|
-
reject(new Error(`timeout in ${maxTimeout}ms`));
|
|
135
|
-
}, maxTimeout);
|
|
136
|
-
}),
|
|
137
|
-
p,
|
|
138
|
-
]);
|
|
139
|
-
if (timeout) {
|
|
140
|
-
clearTimeout(timeout);
|
|
141
|
-
}
|
|
142
|
-
return r;
|
|
143
|
-
}
|
|
144
|
-
return p;
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.error('Action error: ', e);
|
|
147
|
-
throw e;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const actionCallbackMap = new Map();
|
|
2
|
-
|
|
3
|
-
export function onComponentEventAction({ key }, iEventName, callback) {
|
|
4
|
-
const eventName = `__weapps__component-event-${iEventName}`;
|
|
5
|
-
const map = getCallbackMap(key);
|
|
6
|
-
if (!map) {
|
|
7
|
-
return actionCallbackMap.set(key, new Map([[eventName, [callback]]]));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const callbacks = map.get(eventName);
|
|
11
|
-
if (!callbacks) {
|
|
12
|
-
return map.set(eventName, [callback]);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
callbacks.push(callback);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getCallbackMap(componentKey) {
|
|
19
|
-
return actionCallbackMap.get(componentKey);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getComponentEventActionCallbacks(componentKey, eventName) {
|
|
23
|
-
const map = getCallbackMap(componentKey);
|
|
24
|
-
if (!map) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return map.get(eventName);
|
|
29
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getComponentId } from './utils/common';
|
|
2
|
-
|
|
3
|
-
export const componentNodeMap = new Map();
|
|
4
|
-
|
|
5
|
-
export function setComponentNode(key, node) {
|
|
6
|
-
return componentNodeMap.set(key, node);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function deleteComponentNode(key) {
|
|
10
|
-
return componentNodeMap.delete(key);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getComponentNode(key) {
|
|
14
|
-
return componentNodeMap.get(key) || document.getElementById(getComponentId(key));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
Object.defineProperty(window, '__componentInstanceNodeMap', {
|
|
19
|
-
get() {
|
|
20
|
-
return componentNodeMap;
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getComponentEventActionCallbacks } from './componentEventActionEmitter';
|
|
2
|
-
|
|
3
|
-
export function emitComponentEvent({ data: { actionName }, target }) {
|
|
4
|
-
const callbacks = getComponentEventActionCallbacks(target.key, actionName);
|
|
5
|
-
if (callbacks) {
|
|
6
|
-
callbacks.forEach(callback => callback());
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const componentEvents = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onComponent(eventType, callback) {
|
|
6
|
-
componentEvents.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitComponent(eventType, schema) {
|
|
10
|
-
componentEvents.emit(eventType, {
|
|
11
|
-
key: schema.key,
|
|
12
|
-
sourceKey: schema['x-component']
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const hotAreaEventListeners = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onHotArea(eventType, callback) {
|
|
6
|
-
hotAreaEventListeners.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitHotArea(eventType, hotArea, instance, meta, global) {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
const params = getHotAreaEventListenerCallbackParams(hotArea, instance, global, meta);
|
|
12
|
-
hotAreaEventListeners.emit(eventType, params);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getHotAreaEventListenerCallbackParams(
|
|
16
|
-
{ key, position, size },
|
|
17
|
-
{ key: componentKey, sourceKey },
|
|
18
|
-
global,
|
|
19
|
-
meta
|
|
20
|
-
) {
|
|
21
|
-
return {
|
|
22
|
-
global,
|
|
23
|
-
meta,
|
|
24
|
-
hotArea: {
|
|
25
|
-
key,
|
|
26
|
-
position,
|
|
27
|
-
size,
|
|
28
|
-
},
|
|
29
|
-
sourceKey,
|
|
30
|
-
componentKey
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EventListenerTarget } from './types';
|
|
2
|
-
import { onComponent } from './componentEventListener';
|
|
3
|
-
import { onPage } from './pageEventListener';
|
|
4
|
-
import { onHotArea } from './hotAreaEventListener';
|
|
5
|
-
|
|
6
|
-
export function on(target, eventType, callback) {
|
|
7
|
-
switch (target) {
|
|
8
|
-
case EventListenerTarget.PAGE: {
|
|
9
|
-
return onPage(eventType, callback);
|
|
10
|
-
}
|
|
11
|
-
case EventListenerTarget.COMPONENT: {
|
|
12
|
-
return onComponent(eventType, callback);
|
|
13
|
-
}
|
|
14
|
-
case EventListenerTarget.HOT_AREA: {
|
|
15
|
-
return onHotArea(eventType, callback);
|
|
16
|
-
}
|
|
17
|
-
default: {
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
throw `Invalid [target], must one of '${EventListenerTarget.PAGE}', '${
|
|
20
|
-
EventListenerTarget.COMPONENT
|
|
21
|
-
}', '${EventListenerTarget.HOT_AREA}'`;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export * from './pageEventListener';
|
|
27
|
-
export * from './componentEventListener';
|
|
28
|
-
export * from './hotAreaEventListener';
|
|
29
|
-
export * from './types';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EventProxy } from '../utils/eventProxy';
|
|
2
|
-
|
|
3
|
-
const pageEvents = new EventProxy();
|
|
4
|
-
|
|
5
|
-
export function onPage(eventType, callback) {
|
|
6
|
-
pageEvents.on(eventType, callback);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function emitPage(eventType, params) {
|
|
10
|
-
pageEvents.emit(eventType, params);
|
|
11
|
-
}
|