@cloudbase/lowcode-builder 1.7.1 → 1.8.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.
@@ -6,9 +6,10 @@ import { BuildType } from '../types/common';
6
6
  * 该函数从 @govcloud/generate 取到需要的模版文件
7
7
  */
8
8
  export declare function generateProjectFiles(buildData: BuildAppProps): Promise<void>;
9
- export declare function generateHTML({ appId, envId, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
9
+ export declare function generateHTML({ appId, envId, description, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
10
10
  appId: string;
11
11
  envId: string;
12
+ description?: string;
12
13
  externalResources: Required<IPlatformApp>['externalResources'];
13
14
  appBuildDir: string;
14
15
  mode: string;
@@ -25,7 +25,7 @@ async function generateProjectFiles(buildData) {
25
25
  }));
26
26
  }
27
27
  exports.generateProjectFiles = generateProjectFiles;
28
- async function generateHTML({ appId, envId, appBuildDir, externalResources = [], mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }) {
28
+ async function generateHTML({ appId, envId, description = '', appBuildDir, externalResources = [], mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }) {
29
29
  const templatePath = path_1.default.join(config_1.appTemplateDir, 'html', 'index.html.ejs');
30
30
  const dstFilePath = path_1.default.join(appBuildDir, 'index.html');
31
31
  const packageTpl = await fs_extra_1.default.readFile(templatePath, { encoding: 'utf8' });
@@ -46,7 +46,7 @@ async function generateHTML({ appId, envId, appBuildDir, externalResources = [],
46
46
  await fs_extra_1.default.writeFile(dstFilePath, (0, lodash_1.template)(packageTpl)({
47
47
  appId,
48
48
  title: '',
49
- desc: 'WeDa构建的应用',
49
+ desc: description,
50
50
  canUseVite: (0, util_1.canUseVite)(mode, devTool),
51
51
  jsApis: Array.from(new Set(jsApis.filter((item) => !!item))),
52
52
  cssStyles: Array.from(new Set(cssStyles.filter((item) => !!item))),
@@ -29,6 +29,7 @@ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir,
29
29
  await (0, generate_1.generateHTML)({
30
30
  appId: mainAppData.id || appKey,
31
31
  envId: mainAppData.envId || '',
32
+ description: cals.description || '',
32
33
  appBuildDir,
33
34
  externalResources: (cals.externalResources || []).concat(assets.map((url) => ({
34
35
  type: cals_1.EExternalResourceType.CSSUrl,
@@ -118,11 +118,13 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
118
118
  debug: buildContext.debugMode,
119
119
  },
120
120
  'common/data-patch.js': {},
121
- 'common/event-emitter.js': {},
121
+ 'common/event-emitter.ts': {},
122
122
  'common/watch.js': {},
123
123
  'common/constant.js': {
124
124
  REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
125
125
  },
126
+ 'common/query.ts': {},
127
+ 'common/flow.ts': {},
126
128
  /**
127
129
  * 调试用
128
130
  */
@@ -311,7 +313,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
311
313
  console.log(`Generating ${em('page')} files`);
312
314
  (0, generateFiles_1.cleanDir)(path_1.default.join(appRoot, 'pages'), []);
313
315
  await Promise.all(weapp.pageInstanceList.map(async (page) => {
314
- var _a, _b, _c, _d, _e, _f;
316
+ var _a, _b, _c, _d, _e, _f, _g;
315
317
  // # Generating page
316
318
  const rootPath = weapp.rootPath || '';
317
319
  const usingComponents = {};
@@ -323,17 +325,17 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
323
325
  const pageFileData = {
324
326
  [`api.js|api.js`]: {
325
327
  subLevelPath: rootPath ? `${path_1.default.posix.relative(rootPath, '')}/` : '',
328
+ uuid: rootPath ? `${rootPath}/${page.id}` : page.id,
329
+ label: ((_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.navigationBarTitleText) === null || _b === void 0 ? void 0 : _b.value) || ((_d = (_c = page === null || page === void 0 ? void 0 : page.data) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.value),
326
330
  },
327
331
  [`data.js|data.js`]: {
328
332
  widgetProps: (0, util_2.createWidgetProps)(ctx, componentInstances),
329
333
  stringifyObj: util_1.inspect,
330
334
  },
331
335
  [`index.js|${pageFileName}.js`]: {
332
- pageUUID: rootPath ? `${rootPath}/${page.id}` : page.id,
333
336
  pageName: page.id,
334
- pageTitle: ((_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.navigationBarTitleText) === null || _b === void 0 ? void 0 : _b.value) || ((_d = (_c = page === null || page === void 0 ? void 0 : page.data) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.value),
335
337
  pageSource: page.data.src || '',
336
- eventHanlders: (0, util_2.createEventHanlders)(ctx, componentInstances, 'this', page),
338
+ eventHandlers: (0, util_2.createEventHandlers)(ctx, componentInstances, 'this', page),
337
339
  dataBinds: (0, util_2.createDataBinds)(ctx, componentInstances),
338
340
  pageAttributes: {
339
341
  ...(((_e = page.data) === null || _e === void 0 ? void 0 : _e.appShareMessage) ? { appShareMessage: page.data.appShareMessage.value } : {}),
@@ -342,6 +344,8 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
342
344
  stringifyObj: util_1.inspect,
343
345
  subLevelPath: rootPath ? `${path_1.default.posix.relative(rootPath, '')}/` : '',
344
346
  importor,
347
+ query: (0, util_2.createTemplateQuery)(ctx, (_f = page.dataset) === null || _f === void 0 ? void 0 : _f.query),
348
+ eventFlows: (0, util_2.createTemplateEventFlows)(ctx, page.eventFlows),
345
349
  },
346
350
  [`index.json|${pageFileName}.json`]: {
347
351
  usingComponents,
@@ -352,7 +356,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
352
356
  content: wxml,
353
357
  },
354
358
  [`index.wxss|${pageFileName}.wxss`]: {
355
- subWxss: rootPath && !((_f = ctx.mainAppData) === null || _f === void 0 ? void 0 : _f.mpPkgUrl)
359
+ subWxss: rootPath && !((_g = ctx.mainAppData) === null || _g === void 0 ? void 0 : _g.mpPkgUrl)
356
360
  ? `@import "${path_1.default.posix.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
357
361
  : '',
358
362
  content: (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
@@ -369,7 +373,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
369
373
  }
370
374
  }
371
375
  async function generateFramework(ctx, appData, outDir, options) {
372
- var _a;
376
+ var _a, _b;
373
377
  let fileData = {};
374
378
  if (appData.mpPkgUrl) {
375
379
  if (!appData.rootPath) {
@@ -382,6 +386,8 @@ async function generateFramework(ctx, appData, outDir, options) {
382
386
  subPackageName: '',
383
387
  importor: (0, util_3.generateLowcodeImportor)([]),
384
388
  appConfig: JSON.stringify({}),
389
+ appQuery: {},
390
+ stringifyObj: util_1.inspect,
385
391
  },
386
392
  };
387
393
  }
@@ -421,6 +427,8 @@ async function generateFramework(ctx, appData, outDir, options) {
421
427
  type: item.data.isCustomLoginPage ? 'login' : '',
422
428
  })),
423
429
  }),
430
+ appQuery: (0, util_2.createTemplateQuery)(ctx, (_b = appData.dataset) === null || _b === void 0 ? void 0 : _b.query),
431
+ stringifyObj: util_1.inspect,
424
432
  },
425
433
  'app/common.js': {
426
434
  mods: appData.lowCodes
@@ -535,12 +543,12 @@ async function cleanPkg(pkg, miniprogramRoot) {
535
543
  else {
536
544
  // #2 clean deleted handlers
537
545
  const handlersDir = path_1.default.join(lowcodeDir, 'handler');
538
- const handlers = ((_d = (_c = (_b = (_a = pkg === null || pkg === void 0 ? void 0 : pkg.pageInstanceList) === null || _a === void 0 ? void 0 : _a.find((p) => p.id === pageName)) === null || _b === void 0 ? void 0 : _b.lowCodes) === null || _c === void 0 ? void 0 : _c.filter((m) => m.type === 'handler-fn')) === null || _d === void 0 ? void 0 : _d.map((m) => `${m.name}.js`)) || [];
546
+ const handlers = ((_d = (_c = (_b = (_a = pkg === null || pkg === void 0 ? void 0 : pkg.pageInstanceList) === null || _a === void 0 ? void 0 : _a.find((p) => p.id === pageName)) === null || _b === void 0 ? void 0 : _b.lowCodes) === null || _c === void 0 ? void 0 : _c.filter((m) => m.type === cals_1.ECodeType.HANDLER_FN)) === null || _d === void 0 ? void 0 : _d.map((m) => `${m.name}.js`)) || [];
539
547
  (0, generateFiles_1.cleanDir)(handlersDir, handlers);
540
548
  }
541
549
  });
542
550
  // #3 clean deleted common modules
543
- const commonModules = pkg.lowCodes.filter((m) => m.type === 'normal-module').map((m) => `${m.name}.js`);
551
+ const commonModules = pkg.lowCodes.filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE).map((m) => `${m.name}.js`);
544
552
  const commonDir = path_1.default.join(lowcodesDir, 'common');
545
553
  (0, generateFiles_1.cleanDir)(commonDir, commonModules);
546
554
  }
@@ -287,7 +287,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
287
287
  handlers: compositedComp.lowCodes
288
288
  .filter((m) => m.type === cals_1.ECodeType.HANDLER_FN && m.name !== cals_1.ECodeName.PLACEHOLDER)
289
289
  .map((m) => m.name),
290
- eventHandlers: (0, util_3.createEventHanlders)(compositeCtx, componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
290
+ eventHandlers: (0, util_3.createEventHandlers)(compositeCtx, componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
291
291
  // protectEventKeys: builtinMpEvents,
292
292
  emitEvents: compositedComp.emitEvents.map((evt) => evt.eventName),
293
293
  widgetProps: (0, util_3.createWidgetProps)(compositeCtx, componentInstances),
@@ -304,8 +304,6 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
304
304
  },
305
305
  'index.json': { usingComponents, componentGenerics },
306
306
  'index.wxml': {
307
- // raw: JSON.stringify(page.componentInstances),
308
- // wrapperClass: getCompositedComponentClass(compositedComp),
309
307
  content: wxml,
310
308
  },
311
309
  'index.wxss': {
@@ -1,15 +1,15 @@
1
- import { IDynamicValue, IWeAppComponentInstance, ActionType, ICompositedComponent, IWeAppPage, IEventListener } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { IDynamicValue, IWeAppComponentInstance, ActionType, ICompositedComponent, IWeAppPage, IEventListener, IQueryData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { IBuildContext } from './BuildContext';
3
3
  export declare function generatedDynamicData(data: {
4
4
  [key: string]: IDynamicValue;
5
- }, compInfo?: ICompositedComponent): {
5
+ }, compInfo?: ICompositedComponent, filterBuiltInProps?: boolean): {
6
6
  staticProps: {};
7
7
  boundProps: {};
8
8
  };
9
9
  export declare function createWidgetProps(ctx: IBuildContext, widgets: {
10
10
  [key: string]: IWeAppComponentInstance;
11
11
  }): {};
12
- export declare function createEventHanlders(ctx: IBuildContext, widgets: {
12
+ export declare function createEventHandlers(ctx: IBuildContext, widgets: {
13
13
  [key: string]: IWeAppComponentInstance;
14
14
  }, componentApi: string, page?: IWeAppPage): {};
15
15
  export declare function generateSyncListeners(syncConfigs: any): IEventListener[];
@@ -19,6 +19,10 @@ export declare function generateDataContainerListeners(): {
19
19
  type: ActionType;
20
20
  data: {};
21
21
  }[];
22
+ export declare function createTemplateQuery(ctx: IBuildContext, query?: {
23
+ [key: string]: IQueryData;
24
+ }): {};
25
+ export declare function createTemplateEventFlows(ctx: IBuildContext, eventFlows?: any[]): any[];
22
26
  export declare function createDataBinds(ctx: IBuildContext, widgets: {
23
27
  [key: string]: IWeAppComponentInstance;
24
28
  }): {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findComponentInfo = exports.processRepeaterSchema = exports.createDataBinds = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHanlders = exports.createWidgetProps = exports.generatedDynamicData = void 0;
3
+ exports.findComponentInfo = exports.processRepeaterSchema = exports.createDataBinds = 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");
@@ -24,11 +24,11 @@ function extractWidgetProps(props, compInfo, processCssUnit = 'rpx') {
24
24
  }
25
25
  return staticProps;
26
26
  }
27
- function generatedDynamicData(data, compInfo) {
27
+ function generatedDynamicData(data, compInfo, filterBuiltInProps = true) {
28
28
  const staticProps = {};
29
29
  const boundProps = {};
30
30
  for (const key of Object.keys(data)) {
31
- if (mp_1.builtinWigetProps.indexOf(key) > -1)
31
+ if (filterBuiltInProps && mp_1.builtinWigetProps.indexOf(key) > -1)
32
32
  continue;
33
33
  const { type, value } = data[key];
34
34
  if (!type || type === 'static') {
@@ -138,7 +138,7 @@ function createWidgetProps(ctx, widgets) {
138
138
  return widgetProps;
139
139
  }
140
140
  exports.createWidgetProps = createWidgetProps;
141
- function createEventHanlders(ctx, widgets, componentApi, page) {
141
+ function createEventHandlers(ctx, widgets, componentApi, page) {
142
142
  let eventHandlers = {};
143
143
  const { listeners: pageListeners = [], id: pageId = '' } = page || {};
144
144
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
@@ -177,7 +177,7 @@ function createEventHanlders(ctx, widgets, componentApi, page) {
177
177
  eventHandlers = Object.assign(eventHandlers, getListenersHandlers(pageListeners, pageId, componentApi));
178
178
  return eventHandlers;
179
179
  }
180
- exports.createEventHanlders = createEventHanlders;
180
+ exports.createEventHandlers = createEventHandlers;
181
181
  function generateSyncListeners(syncConfigs) {
182
182
  const listeners = [];
183
183
  for (const valuProp in syncConfigs) {
@@ -201,8 +201,8 @@ function generateDataContainerListeners() {
201
201
  trigger: 'onDataChange',
202
202
  jsCode: `({event})=>{
203
203
  if(event.currentTarget) {
204
- app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
205
- app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
204
+ $app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
205
+ $app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
206
206
  }
207
207
  }`,
208
208
  type: weapps_core_1.ActionType.Inline,
@@ -211,6 +211,31 @@ function generateDataContainerListeners() {
211
211
  ];
212
212
  }
213
213
  exports.generateDataContainerListeners = generateDataContainerListeners;
214
+ function createTemplateQuery(ctx, query = {}) {
215
+ return Object.entries(query).reduce((map, [key, item]) => {
216
+ const { method, listeners, ...rest } = item;
217
+ const { staticProps, boundProps } = generatedDynamicData(method.params || {}, undefined, false);
218
+ map[key] = {
219
+ ...rest,
220
+ methodName: method.name,
221
+ data: staticProps,
222
+ dataBinds: boundProps,
223
+ eventHandlers: getListenersHandlers(listeners, item.id, 'this'),
224
+ };
225
+ return map;
226
+ }, {});
227
+ }
228
+ exports.createTemplateQuery = createTemplateQuery;
229
+ function createTemplateEventFlows(ctx, eventFlows = []) {
230
+ return eventFlows.map((item) => {
231
+ const { listeners = [], ...rest } = item;
232
+ return {
233
+ ...rest,
234
+ eventHandlers: getListenersHandlers(listeners, item.id, 'this'),
235
+ };
236
+ });
237
+ }
238
+ exports.createTemplateEventFlows = createTemplateEventFlows;
214
239
  /**
215
240
  * 根据 listeners 创建 handlers
216
241
  * @param listeners {IEventListener[]}
@@ -223,31 +248,46 @@ function getListenersHandlers(listeners, id, componentApi) {
223
248
  const eventHandlers = {};
224
249
  listeners.forEach((l) => {
225
250
  var _a, _b, _c, _d, _e;
226
- const handlerName = (0, wxml_1.getMpEventHanlderName)(id, l.trigger, l);
251
+ const handlerName = (0, wxml_1.getMpEventHandlerName)(id, l.trigger, l);
252
+ const sourceKey = `${((_a = l.handler) === null || _a === void 0 ? void 0 : _a.moduleName) || ''}:${((_b = l.handler) === null || _b === void 0 ? void 0 : _b.name) || ''}`;
227
253
  eventHandlers[handlerName] = eventHandlers[handlerName] || [];
228
- const params = generatedDynamicData(l.data);
254
+ const { staticProps, boundProps } = generatedDynamicData(l.data, undefined, false);
229
255
  let handler = l.handler ? l.handler.name : l.jsCode;
230
256
  switch (l.type) {
231
257
  case weapps_core_1.ActionType.Platform: {
232
- handler = `function({data}){ return app.${(_a = l.handler) === null || _a === void 0 ? void 0 : _a.name}(data)}`;
258
+ handler = '';
259
+ switch (sourceKey) {
260
+ case `${weapps_core_1.ActionType.Platform}:callNanoFlow`: {
261
+ handler = `function({data}){ return $w[data.id]?.trigger?.(data.data)}`;
262
+ break;
263
+ }
264
+ case `${weapps_core_1.ActionType.Platform}:callQuery`: {
265
+ handler = `function({data}){ return $w[data.id]?.trigger?.()}`;
266
+ break;
267
+ }
268
+ default: {
269
+ handler = `function({data}){ return $app.${(_c = l.handler) === null || _c === void 0 ? void 0 : _c.name}(data)}`;
270
+ break;
271
+ }
272
+ }
233
273
  break;
234
274
  }
235
275
  case weapps_core_1.ActionType.DataSource: {
236
- handler = `function({data}){ return app.cloud.callDataSource(data)}`;
276
+ handler = `function({data}){ return $app.cloud.callDataSource(data)}`;
237
277
  break;
238
278
  }
239
279
  case weapps_core_1.ActionType.PropEvent: {
240
- handler = `function({event, data = {}}){ return ${componentApi}.props.events.${(_b = l.handler) === null || _b === void 0 ? void 0 : _b.name}({...event.detail, ...data}) }`;
280
+ handler = `function({event, data = {}}){ return ${componentApi}.props.events.${(_d = l.handler) === null || _d === void 0 ? void 0 : _d.name}({...event.detail, ...data}) }`;
241
281
  break;
242
282
  }
243
283
  }
244
284
  eventHandlers[handlerName].push({
245
285
  key: l.key || '',
246
286
  handler,
247
- handlerModule: (_c = l.handler) === null || _c === void 0 ? void 0 : _c.moduleName,
248
- sourceKey: `${((_d = l.handler) === null || _d === void 0 ? void 0 : _d.moduleName) || ''}:${((_e = l.handler) === null || _e === void 0 ? void 0 : _e.name) || ''}`,
249
- data: params.staticProps,
250
- boundData: params.boundProps,
287
+ handlerModule: (_e = l.handler) === null || _e === void 0 ? void 0 : _e.moduleName,
288
+ sourceKey,
289
+ data: staticProps,
290
+ boundData: boundProps,
251
291
  type: l.type,
252
292
  });
253
293
  });
@@ -5,7 +5,7 @@ export declare function generateWxml(ctx: IBuildContext & {
5
5
  }, widgets: {
6
6
  [key: string]: IWeAppComponentInstance;
7
7
  }, docTag: string, wxmlDataPrefix: any, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
8
- export declare function getMpEventHanlderName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
8
+ export declare function getMpEventHandlerName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
9
9
  export declare function getUsedComponents(widgets: {
10
10
  [key: string]: IWeAppComponentInstance;
11
11
  }, usedCmps?: {
@@ -3,7 +3,7 @@ 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.getMpEventHanlderName = exports.generateWxml = void 0;
6
+ exports.getUsedComponents = exports.getMpEventHandlerName = exports.generateWxml = 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");
@@ -249,7 +249,7 @@ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, com
249
249
  processedListeners.forEach((l) => {
250
250
  const evtName = getMpEventName(l.trigger);
251
251
  const modifiers = l;
252
- node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
252
+ node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHandlerName(id, evtName, modifiers);
253
253
  });
254
254
  if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.pluginConfig) {
255
255
  if (compConfig.pluginConfig.attributes) {
@@ -345,14 +345,14 @@ function getMpEventName(originalName) {
345
345
  // 模板中也有部分依赖保持相同的连字符(_),更改时注意同步修改
346
346
  return evtNameMap[originalName] || originalName.replace(/\./g, '_');
347
347
  }
348
- function getMpEventHanlderName(widgetId, evtName, modifier = {}) {
348
+ function getMpEventHandlerName(widgetId, evtName, modifier = {}) {
349
349
  // Only builtin events have will bubble
350
350
  if (mp_1.builtinMpEvents.indexOf(evtName) === -1) {
351
351
  modifier = {};
352
352
  }
353
353
  return `on${widgetId}$${getMpEventName(evtName)}${modifier.isCapturePhase ? '$cap' : ''}${modifier.noPropagation ? '$cat' : ''}`;
354
354
  }
355
- exports.getMpEventHanlderName = getMpEventHanlderName;
355
+ exports.getMpEventHandlerName = getMpEventHandlerName;
356
356
  /* onid3click, */
357
357
  function getMpEventAttr(evtName, modifier, tagName) {
358
358
  // Only builtin events have will bubble
package/lib/flow.d.ts CHANGED
@@ -19,12 +19,14 @@ export declare class EventFlow {
19
19
  /**
20
20
  * 预处理后 event handler listeners
21
21
  */
22
- listeners?: any[];
22
+ eventHandlers?: Record<string, any>;
23
23
  };
24
24
  context: IEventFlowContext;
25
25
  options?: IMPEventFlowGenerateOptions;
26
26
  });
27
27
  trigger(additionalScope: any, options?: Partial<IEventFlowContext>): any;
28
28
  }
29
- export declare function generateEventFlows(flows: never[] | undefined, context: IEventFlowContext, options?: IMPEventFlowGenerateOptions): {};
29
+ export declare function generateEventFlows(flows: {
30
+ id: string;
31
+ }[] | undefined, context: IEventFlowContext, options?: IMPEventFlowGenerateOptions): {};
30
32
  export {};
package/lib/flow.js CHANGED
@@ -7,12 +7,10 @@ class EventFlow {
7
7
  constructor({ schema, context, options, }) {
8
8
  this._eventHandlerMap = {};
9
9
  this._context = context;
10
- const { id, description, listeners = [] } = schema || {};
11
- const startNode = listeners[0];
12
- const [_, eventFlowId] = (startNode === null || startNode === void 0 ? void 0 : startNode.eventName.match(/(.*?)\.start/)) || [];
13
- this.id = id || eventFlowId;
14
- this.description = description || (startNode === null || startNode === void 0 ? void 0 : startNode.description) || '';
15
- const handlers = (0, util_1.createEventHandlers)(listeners, {
10
+ const { id, description, eventHandlers = {} } = schema || {};
11
+ this.id = id || '';
12
+ this.description = description || '';
13
+ const handlers = (0, util_1.createEventHandlers)(eventHandlers, {
16
14
  looseError: (options === null || options === void 0 ? void 0 : options.looseError) || false,
17
15
  isComposite: (options === null || options === void 0 ? void 0 : options.isComposite) || false,
18
16
  });
@@ -54,7 +52,6 @@ class EventFlow {
54
52
  exports.EventFlow = EventFlow;
55
53
  function generateEventFlows(flows = [], context, options) {
56
54
  const result = {};
57
- return result;
58
55
  for (let flow of flows) {
59
56
  result[flow.id] = new EventFlow({ schema: flow, context, options });
60
57
  }
package/lib/query.d.ts CHANGED
@@ -11,7 +11,7 @@ interface IMPDataSourceQuery {
11
11
  /**
12
12
  * 预处理后 event handler listeners
13
13
  */
14
- listeners?: any[];
14
+ eventHandlers?: Record<string, any>;
15
15
  }
16
16
  declare type IQueryContext = any;
17
17
  declare type IGenerateOptions = any;
@@ -26,6 +26,7 @@ export declare class Query {
26
26
  private _currentRequestKey;
27
27
  private _observableValue;
28
28
  private _eventHandlerMap;
29
+ private _timer;
29
30
  constructor({ schema, context, options, }: {
30
31
  schema: IMPDataSourceQuery;
31
32
  context: IQueryContext;
package/lib/query.js CHANGED
@@ -5,7 +5,7 @@ const mobx_1 = require("mobx");
5
5
  const util_1 = require("./util");
6
6
  const event_emitter_1 = require("./event-emitter");
7
7
  class Query {
8
- constructor({ schema, context, options, }) {
8
+ constructor({ schema, context, options = {}, }) {
9
9
  var _a, _b;
10
10
  this._disposes = [];
11
11
  this._dataBinds = {};
@@ -14,17 +14,6 @@ class Query {
14
14
  this._currentRequestKey = null;
15
15
  this._observableValue = (0, mobx_1.observable)({ data: null, error: null });
16
16
  this._eventHandlerMap = {};
17
- this._debounceTrigger = (function () {
18
- let timer = null;
19
- return function (...args) {
20
- if (timer) {
21
- clearTimeout(timer);
22
- }
23
- timer = setTimeout(() => {
24
- this._innerTrigger(...args);
25
- }, 300);
26
- };
27
- })();
28
17
  const { looseError = false, useScopeWidgetData = false } = options;
29
18
  const { $w, $app, $page } = context;
30
19
  this._schema = schema;
@@ -59,7 +48,7 @@ class Query {
59
48
  params: data,
60
49
  });
61
50
  };
62
- this._eventHandlerMap = Object.entries((0, util_1.createEventHandlers)(this._schema.listeners || [], {
51
+ this._eventHandlerMap = Object.entries((0, util_1.createEventHandlers)(this._schema.eventHandlers || {}, {
63
52
  looseError: looseError,
64
53
  isComposite: false,
65
54
  })).reduce((map, [key, fn]) => {
@@ -132,6 +121,14 @@ class Query {
132
121
  throw e;
133
122
  }
134
123
  }
124
+ _debounceTrigger(...args) {
125
+ if (this._timer) {
126
+ clearTimeout(this._timer);
127
+ }
128
+ this._timer = setTimeout(() => {
129
+ this._innerTrigger(...args);
130
+ }, 300);
131
+ }
135
132
  destroy() {
136
133
  this._disposes.forEach((dispose) => dispose());
137
134
  }
@@ -166,7 +163,6 @@ class Query {
166
163
  exports.Query = Query;
167
164
  function generateDatasetQuery(schema, context, options) {
168
165
  const result = {};
169
- return result;
170
166
  for (const key in schema) {
171
167
  result[key] = new Query({ schema: schema[key], context, options });
172
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
@@ -38,8 +38,8 @@
38
38
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
39
39
  },
40
40
  "dependencies": {
41
- "@cloudbase/cals": "^1.0.5",
42
- "@cloudbase/lowcode-generator": "^1.7.1",
41
+ "@cloudbase/cals": "^1.0.6",
42
+ "@cloudbase/lowcode-generator": "^1.8.0",
43
43
  "axios": "^0.21.0",
44
44
  "browserfs": "^1.4.3",
45
45
  "browserify-zlib": "^0.2.0",
@@ -549,7 +549,7 @@
549
549
  crossorigin
550
550
  src="<%=
551
551
  cdnEndpoints.cdngo
552
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.bd132ac7897700329255.bundle.js"
552
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.ca44c59c8e73e409892e.bundle.js"
553
553
  ></script>
554
554
  </body>
555
555
  </html>
@@ -3,8 +3,10 @@ import { createMpApp } from '@cloudbase/weda-client';
3
3
  import { createComputed, formatEnum, enumOptions } from '<%= subLevelPath %>../common/util'
4
4
  import appGlobal from '<%= subLevelPath %>../app/app-global'
5
5
  import { createDataset } from '<%= subLevelPath %>../datasources/index'
6
+
6
7
  import lodashGet from 'lodash.get';
7
8
  import config from '<%= subLevelPath %>../common/config';
9
+ import { generateDatasetQuery } from '../common/util';
8
10
 
9
11
 
10
12
  <%= importor.state? `import state from '../lowcode/state'` : "const state = {}" %>
@@ -13,6 +15,54 @@ import config from '<%= subLevelPath %>../common/config';
13
15
 
14
16
  const mainAppKey = '__weappsMainApp'
15
17
 
18
+ <% function printBoundData(boundData={}) {
19
+ /**
20
+ * TODO: copy 过来的代码
21
+ * 一些模板层面的工具应该如何复用?
22
+ */
23
+ const list = []
24
+ Object.entries(boundData).map(([prop, bindMeta])=>{
25
+ const str = `'${prop}': ($app, lists, forItems, event, $context, $w) => {${bindMeta.imports} return(
26
+ ${bindMeta.expression === '' ? 'undefined': bindMeta.expression}
27
+ )}`
28
+ list.push(str)
29
+ })
30
+ return list.join(',')
31
+ }%>
32
+ <% function printEventHandler(eventHandlers) {
33
+ /**
34
+ * TODO: copy 过来的代码
35
+ * 一些模板层面的工具应该如何复用?
36
+ */
37
+ Object.entries(eventHandlers).map(([handlerName, listeners])=>{
38
+ print(`"${handlerName}": [
39
+ ${listeners.map(l=>{
40
+ let handler = 'undefined'
41
+ switch(l.type){
42
+ case 'rematch': {
43
+ handler = `handlers.${l.handler}`
44
+ break;
45
+ }
46
+ case 'material': {
47
+ handler = `function(...args) { return require('/materials/${l.handlerModule}/actions/${l.handler}/index').default(...args) }`
48
+ break;
49
+ }
50
+ default: {
51
+ handler = l.handler
52
+ }
53
+ }
54
+ return `{
55
+ key: '${l.key||''}',
56
+ sourceKey: '${ l.sourceKey||"" }',
57
+ handler: ${handler},
58
+ data: ${stringifyObj(l.data||{}, {depth: null})},
59
+ boundData: {${printBoundData(l.boundData)}}
60
+ }`
61
+ }).join(',')}
62
+ ],`)
63
+ })
64
+ }%>
65
+
16
66
  export const app = createGlboalApi()
17
67
  export const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
18
68
  export const $w = new Proxy(
@@ -60,6 +110,16 @@ function createGlboalApi() {
60
110
  }
61
111
 
62
112
  let dataset = createDataset('$global')
113
+ dataset.query = generateDatasetQuery({<% Object.entries(appQuery).map(([id, item])=>{%>
114
+ <%= id %>: { <% const { dataBinds, eventHandlers, ...rest } = item %>
115
+ ...(<%= stringifyObj(rest, {depth: null}) %>),
116
+ dataBinds: {<%= printBoundData(dataBinds) %>},
117
+ eventHandlers: {<% printEventHandler(eventHandlers) %>}
118
+ },<%}) %>
119
+ }, {
120
+ $app: globalAPI,
121
+ $w: globalAPI.__internal__.$w,
122
+ })
63
123
  globalAPI.dataset = dataset
64
124
  globalAPI.state.dataset = dataset
65
125
  globalAPI.setState = (userSetState) => {
@@ -103,6 +103,15 @@ App({
103
103
  } catch (e) {
104
104
  throw e;
105
105
  } finally {
106
+ for (const queryId in app.dataset?.query||{}) {
107
+ if (app.dataset.query[queryId]?._schema?.trigger === 'auto') {
108
+ try {
109
+ app.dataset?.query?.[queryId]?.trigger?.();
110
+ } catch (e) {
111
+ console.error(`query ${queryId} 初始化失败:`, e);
112
+ }
113
+ }
114
+ }
106
115
  resolve()
107
116
  }
108
117
  })