@cloudbase/lowcode-builder 1.8.58 → 1.8.60

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
3
+ exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.generateArgsDynamicValueFromData = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
4
4
  const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
5
5
  const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
6
6
  const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
@@ -8,6 +8,7 @@ const wxml_1 = require("./wxml");
8
8
  const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
9
9
  const cals_1 = require("@cloudbase/cals");
10
10
  const config_1 = require("../config");
11
+ const lodash_1 = require("lodash");
11
12
  function extractWidgetProps(props, compInfo, processCssUnit = 'rpx') {
12
13
  var _a, _b, _c;
13
14
  const { classList, staticResourceAttribute = [], data = {}, style } = props;
@@ -177,10 +178,10 @@ function createEventHandlers(ctx, widgets, componentApi, page) {
177
178
  if ((_a = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _a === void 0 ? void 0 : _a.isDataContainer) {
178
179
  listeners.unshift(...generateDataContainerListeners());
179
180
  }
180
- eventHandlers = Object.assign(eventHandlers, getListenersHandlers(listeners, id, componentApi));
181
+ eventHandlers = Object.assign(eventHandlers, getListenersHandlers(ctx, listeners, id, componentApi));
181
182
  });
182
183
  // 增加页面事件节点 handlers
183
- eventHandlers = Object.assign(eventHandlers, getListenersHandlers(pageListeners, pageId, componentApi));
184
+ eventHandlers = Object.assign(eventHandlers, getListenersHandlers(ctx, pageListeners, pageId, componentApi));
184
185
  return eventHandlers;
185
186
  }
186
187
  exports.createEventHandlers = createEventHandlers;
@@ -219,14 +220,14 @@ function generateDataContainerListeners() {
219
220
  exports.generateDataContainerListeners = generateDataContainerListeners;
220
221
  function createTemplateQuery(ctx, query = {}) {
221
222
  return Object.entries(query).reduce((map, [key, item]) => {
222
- const { listeners = [], handler, data, ...rest } = item;
223
- const { staticProps, boundProps } = generatedDynamicData(data || {}, undefined, false);
223
+ const { listeners = [], handler, data, args, ...rest } = item;
224
+ const { staticProps, boundProps } = generatedDynamicData(generateArgsDynamicValueFromData(args, data) || {}, undefined, false);
224
225
  map[key] = {
225
226
  ...rest,
226
227
  handler: `(...args) => $app.${handler === null || handler === void 0 ? void 0 : handler.name}(...args)`,
227
228
  data: staticProps,
228
229
  dataBinds: boundProps,
229
- eventHandlers: getListenersHandlers(listeners, item.id, 'this'),
230
+ eventHandlers: getListenersHandlers(ctx, listeners, item.id, 'this'),
230
231
  };
231
232
  return map;
232
233
  }, {});
@@ -237,7 +238,7 @@ function createTemplateEventFlows(ctx, eventFlows = []) {
237
238
  const { listeners = [], ...rest } = item;
238
239
  return {
239
240
  ...rest,
240
- eventHandlers: getListenersHandlers(listeners, item.id, 'this'),
241
+ eventHandlers: getListenersHandlers(ctx, listeners, item.id, 'this'),
241
242
  };
242
243
  });
243
244
  }
@@ -248,16 +249,17 @@ exports.createTemplateEventFlows = createTemplateEventFlows;
248
249
  * @param id {string}
249
250
  * @param componentApi {string}
250
251
  */
251
- function getListenersHandlers(listeners = [], id, componentApi) {
252
+ function getListenersHandlers(ctx, listeners = [], id, componentApi) {
252
253
  if (!id)
253
254
  return {};
255
+ const { enableAsyncMaterials = false } = ctx;
254
256
  const eventHandlers = {};
255
257
  listeners.forEach((l) => {
256
258
  var _a, _b, _c, _d, _e;
257
259
  const handlerName = (0, wxml_1.getMpEventHandlerName)(id, l.trigger, l);
258
260
  const sourceKey = `${((_a = l.handler) === null || _a === void 0 ? void 0 : _a.moduleName) || ''}:${((_b = l.handler) === null || _b === void 0 ? void 0 : _b.name) || ''}`;
259
261
  eventHandlers[handlerName] = eventHandlers[handlerName] || [];
260
- const { staticProps, boundProps } = generatedDynamicData(l.data, undefined, false);
262
+ const { staticProps, boundProps } = generatedDynamicData(generateArgsDynamicValueFromData(l.args, l.data) || {}, undefined, false);
261
263
  let handler = l.handler ? l.handler.name : l.jsCode;
262
264
  switch (l.type) {
263
265
  case weapps_core_1.ActionType.Platform: {
@@ -280,33 +282,71 @@ function getListenersHandlers(listeners = [], id, componentApi) {
280
282
  break;
281
283
  }
282
284
  default: {
283
- handler = `function({data}){ return $app.${(_c = l.handler) === null || _c === void 0 ? void 0 : _c.name}(data)}`;
285
+ handler = `function({args}){ return $app.${(_c = l.handler) === null || _c === void 0 ? void 0 : _c.name}(...args)}`;
284
286
  break;
285
287
  }
286
288
  }
287
289
  break;
288
290
  }
289
291
  case weapps_core_1.ActionType.DataSource: {
290
- handler = `function({data}){ return $app.cloud.callDataSource(data)}`;
292
+ handler = `function({args}){ return $app.cloud.callDataSource(...args)}`;
291
293
  break;
292
294
  }
293
295
  case weapps_core_1.ActionType.PropEvent: {
294
296
  handler = `function({event, data = {}}){ return ${componentApi}.props.events.${(_d = l.handler) === null || _d === void 0 ? void 0 : _d.name}({...event.detail, ...data}) }`;
295
297
  break;
296
298
  }
299
+ case weapps_core_1.ActionType.Rematch: {
300
+ handler = `handlers.${handler}`;
301
+ break;
302
+ }
303
+ case weapps_core_1.ActionType.GeneralFunc: {
304
+ handler = `function({args}) { return (\n${((_e = l.handler) === null || _e === void 0 ? void 0 : _e.code) || '()=>{}'}\n)(...args) }`;
305
+ break;
306
+ }
297
307
  }
308
+ let generateHandler = l.type === weapps_core_1.ActionType.Material
309
+ ? (subLevelPath) => {
310
+ var _a, _b;
311
+ const path = `${subLevelPath}../../${config_1.materialsDirName}/${(_a = l.handler) === null || _a === void 0 ? void 0 : _a.moduleName}/actions/${(_b = l.handler) === null || _b === void 0 ? void 0 : _b.name}/index`;
312
+ return enableAsyncMaterials
313
+ ? `function(...args) { return require.async('${path}').then(mod=>mod.default(...args)) }`
314
+ : `function(...args) { return require('${path}').default(...args) }`;
315
+ }
316
+ : (subLevelPath) => handler || 'undefined';
298
317
  eventHandlers[handlerName].push({
299
318
  key: l.key || '',
300
- handler,
301
- handlerModule: (_e = l.handler) === null || _e === void 0 ? void 0 : _e.moduleName,
319
+ generateHandler,
302
320
  sourceKey,
303
- data: staticProps,
304
- boundData: boundProps,
321
+ args: staticProps,
322
+ argsBinds: boundProps,
305
323
  type: l.type,
306
324
  });
307
325
  });
308
326
  return eventHandlers;
309
327
  }
328
+ function generateArgsDynamicValueFromData(args, data) {
329
+ if (!args && data) {
330
+ const arg0 = {};
331
+ args = {};
332
+ Object.entries(data || {}).forEach(([key, value]) => {
333
+ if (!value.type || value.type === 'static') {
334
+ (0, lodash_1.set)(arg0, key, value.value);
335
+ }
336
+ else {
337
+ args[`params.0.${key}`] = value;
338
+ }
339
+ });
340
+ if (Object.keys(data || {})) {
341
+ args.params = {
342
+ type: 'static',
343
+ value: [arg0],
344
+ };
345
+ }
346
+ }
347
+ return args;
348
+ }
349
+ exports.generateArgsDynamicValueFromData = generateArgsDynamicValueFromData;
310
350
  function createDataBinds(ctx, widgets) {
311
351
  const dataBinds = {};
312
352
  const { processCssUnit = 'rpx' } = ctx;
@@ -495,9 +535,9 @@ function generateScopedStyleText(widgets) {
495
535
  // 移除换行及其前后的空白符
496
536
  .replace(/\s*\n\s*/g, '')
497
537
  // 添加 `#wd-page-root` 前缀以增加样式权重
498
- .replace(/(:root.*?{)/g, '\n#wd-page-root $1')
499
- // 替换 `:root`
500
- .replace(/:root/g, `.wd-comp-id-${id}`)
538
+ .replace(/(:scope.*?{)/g, '\n#wd-page-root $1')
539
+ // 替换 `:scope`
540
+ .replace(/:scope/g, `.wd-comp-id-${id}`)
501
541
  // `: ` => `:`
502
542
  .replace(/\s*:\s*/g, ':')
503
543
  // ` {` => `{`
@@ -8,10 +8,3 @@ export declare function generateWxml(ctx: IBuildContext & {
8
8
  [key: string]: IWeAppComponentInstance;
9
9
  }, docTag: string, wxmlDataPrefix: any, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
10
10
  export declare function getMpEventHandlerName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
11
- export declare function getUsedComponents(widgets: {
12
- [key: string]: IWeAppComponentInstance;
13
- }, usedCmps?: {
14
- [libName: string]: Set<string>;
15
- }): {
16
- [libName: string]: Set<string>;
17
- };
@@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUsedComponents = exports.getMpEventHandlerName = exports.generateWxml = exports.WD_RUNTIME_TAG = exports.WD_EMPTY_PLACEHOLDER = void 0;
6
+ exports.getMpEventHandlerName = exports.generateWxml = exports.WD_RUNTIME_TAG = exports.WD_EMPTY_PLACEHOLDER = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
9
9
  const xml_js_1 = require("xml-js");
10
10
  const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
11
11
  const materials_1 = require("./materials");
12
- const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
13
12
  const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib/generator/util/name-mangler"));
14
13
  const config_1 = require("../config");
15
14
  const util_1 = require("./util");
@@ -24,14 +23,25 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
24
23
  };
25
24
  if (ctx.pageUUID) {
26
25
  const { enablePageRoot, disabled, enableAsyncMaterials } = ctx;
26
+ const pageMeta = {
27
+ name: 'page-meta',
28
+ type: 'element',
29
+ attributes: {
30
+ ['page-style']: '{{pageStyle}}',
31
+ },
32
+ elements: [],
33
+ _order: Infinity,
34
+ _parent: null,
35
+ };
27
36
  const originElements = xmlJson.elements;
37
+ xmlJson.elements = [pageMeta];
28
38
  // usingComponents['wd-privacy'] = '/common/privacyModal/index';
29
39
  usingComponents[WD_INFO] = '/common/info/index';
30
40
  if (enableAsyncMaterials) {
31
41
  usingComponents[exports.WD_EMPTY_PLACEHOLDER] = '/common/placeholder/index';
32
42
  }
33
43
  if (disabled && ctx.pageUUID !== ctx.statusPageId) {
34
- xmlJson.elements = [
44
+ pageMeta.elements = [
35
45
  {
36
46
  type: 'element',
37
47
  name: WD_INFO,
@@ -49,14 +59,14 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
49
59
  }
50
60
  else {
51
61
  // 登录校验: 向其最外层包裹一层block
52
- xmlJson.elements = [
62
+ pageMeta.elements = [
53
63
  // {
54
64
  // type: 'element',
55
65
  // name: 'wd-privacy',
56
66
  // attributes: {},
57
67
  // elements: [],
58
68
  // _order: -Infinity,
59
- // _parent: null,
69
+ // _parent: pageMeta,
60
70
  // },
61
71
  {
62
72
  type: 'element',
@@ -100,11 +110,11 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
100
110
  },
101
111
  elements: [],
102
112
  _order: Infinity,
103
- _parent: null,
113
+ _parent: pageMeta,
104
114
  },
105
115
  ];
106
116
  if (ctx.enableExpiredTag) {
107
- xmlJson.elements.push({
117
+ pageMeta.elements.push({
108
118
  type: 'element',
109
119
  name: WD_INFO,
110
120
  attributes: {
@@ -114,11 +124,11 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
114
124
  },
115
125
  elements: [],
116
126
  _order: Infinity,
117
- _parent: null,
127
+ _parent: pageMeta,
118
128
  });
119
129
  }
120
130
  if (ctx.enableLoading) {
121
- xmlJson.elements.push({
131
+ pageMeta.elements.push({
122
132
  type: 'element',
123
133
  name: WD_INFO,
124
134
  attributes: {
@@ -127,7 +137,7 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
127
137
  },
128
138
  elements: [],
129
139
  _order: Infinity,
130
- _parent: null,
140
+ _parent: pageMeta,
131
141
  });
132
142
  }
133
143
  }
@@ -433,32 +443,6 @@ function getEventBindSep(tagName) {
433
443
  // bind:input => bindinput 兼容微信 7.0.13 安卓版本 textarea 组件,bind:input 写法会导致事件失效
434
444
  return mp_1.nativeCompWhiteList.includes(tagName.toLowerCase()) ? '' : ':';
435
445
  }
436
- function getUsedComponents(widgets, usedCmps = {}) {
437
- (0, weapp_1.walkThroughWidgets)(widgets, (id, widget) => {
438
- const { xComponent, xProps = { data: null } } = widget;
439
- if (!xComponent)
440
- return;
441
- const { moduleName, name } = xComponent;
442
- if (!usedCmps[moduleName]) {
443
- usedCmps[moduleName] = new Set();
444
- }
445
- usedCmps[moduleName].add(name);
446
- // Handle generic component props
447
- Object.keys(xProps.data || {}).map((p) => {
448
- var _a;
449
- const { value } = (_a = xProps.data) === null || _a === void 0 ? void 0 : _a[p];
450
- if (/^\w+:\w+$/.test(value)) {
451
- const [libName, name] = value.split(':');
452
- if (!usedCmps[libName]) {
453
- usedCmps[libName] = new Set();
454
- }
455
- usedCmps[libName].add(name);
456
- }
457
- });
458
- });
459
- return usedCmps;
460
- }
461
- exports.getUsedComponents = getUsedComponents;
462
446
  function getAttrBind(dVale, widgetBind, isStaticResource, neg) {
463
447
  const { type, value } = dVale;
464
448
  const attrVal = type === weapps_core_1.PropBindType.prop ? value : widgetBind;