@cloudbase/lowcode-builder 1.8.18 → 1.8.19

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.
@@ -0,0 +1,3 @@
1
+ export declare function BabelTransform(code: any, options?: {
2
+ IIFE?: boolean;
3
+ }): any;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BabelTransform = void 0;
4
+ const core_1 = require("@babel/core");
5
+ function BabelTransform(code, options = {}) {
6
+ var _a;
7
+ const { IIFE = false } = options;
8
+ try {
9
+ const simpleWrapped = `(\n${code || 'undefined'}\n)`;
10
+ const { code: expression } = (0, core_1.transformSync)(IIFE ? `(()=>${simpleWrapped})()` : simpleWrapped, {
11
+ // plugins: ['transform-modules-commonjs', 'transform-react-jsx'],
12
+ cwd: __dirname,
13
+ sourceType: 'script',
14
+ comments: false,
15
+ // minified: true,
16
+ presets: [
17
+ [
18
+ '@babel/preset-env',
19
+ {
20
+ targets: {
21
+ // esmodules: true,
22
+ browsers: ['defaults', 'iOS >= 10', 'safari >= 10'],
23
+ },
24
+ },
25
+ ],
26
+ ],
27
+ }) || {};
28
+ return ((_a = expression === null || expression === void 0 ? void 0 : expression.replace) === null || _a === void 0 ? void 0 : _a.call(expression, /;$/, '')) || code;
29
+ }
30
+ catch (e) {
31
+ console.error(`transform [${code}] fail:`, e === null || e === void 0 ? void 0 : e.message);
32
+ return code;
33
+ }
34
+ }
35
+ exports.BabelTransform = BabelTransform;
@@ -0,0 +1,17 @@
1
+ export declare function createPage({ app, id, widgetProps, index, lifecycle, state, computed, evtListeners, dataBinds, handlers, query: datasetQuery, eventFlows, pageContext, pageAttributes, enableShare, }: {
2
+ app: any;
3
+ id: any;
4
+ widgetProps: any;
5
+ index?: {} | undefined;
6
+ lifecycle: any;
7
+ state: any;
8
+ computed: any;
9
+ evtListeners: any;
10
+ dataBinds: any;
11
+ handlers: any;
12
+ query?: {} | undefined;
13
+ eventFlows?: never[] | undefined;
14
+ pageContext?: {} | undefined;
15
+ pageAttributes?: {} | undefined;
16
+ enableShare?: boolean | undefined;
17
+ }): string;
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createPage = void 0;
7
+ const mobx_1 = require("mobx");
8
+ const util_1 = require("./util");
9
+ const widget_1 = require("./widget");
10
+ const merge_renderer_1 = __importDefault(require("./merge-renderer"));
11
+ const index_1 = require("../datasources/index");
12
+ const watch_1 = require("./watch");
13
+ const weapps_api_1 = require("../app/weapps-api");
14
+ const event_emitter_1 = require("./event-emitter");
15
+ const weda_client_1 = require("@cloudbase/weda-client");
16
+ const wxApp = getApp();
17
+ function extractLifecycles(ctx, lifecycle, appShareMessage, enableShare = false) {
18
+ const result = {};
19
+ Object.keys(lifecycle).map((name) => {
20
+ result[name] = function () {
21
+ return lifecycle[name].apply(this._getInstance(), arguments);
22
+ };
23
+ });
24
+ if (enableShare) {
25
+ result['onShareAppMessage'] = (res) => {
26
+ var _a, _b, _c, _d, _e, _f, _g, _h;
27
+ if ((res === null || res === void 0 ? void 0 : res.from) === 'button' && ((_b = (_a = res === null || res === void 0 ? void 0 : res.target) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.weda_share_info)) {
28
+ return (_d = (_c = res === null || res === void 0 ? void 0 : res.target) === null || _c === void 0 ? void 0 : _c.dataset) === null || _d === void 0 ? void 0 : _d.weda_share_info;
29
+ }
30
+ else if ((res === null || res === void 0 ? void 0 : res.from) === 'menu' && (appShareMessage === null || appShareMessage === void 0 ? void 0 : appShareMessage.enable)) {
31
+ let { pageId, params, imageUrl, title, packageName } = appShareMessage || {};
32
+ return {
33
+ path: (0, weda_client_1.generatePageUrl)({
34
+ pageId,
35
+ packageName,
36
+ params,
37
+ }),
38
+ imageUrl: ((_g = (_f = (_e = ctx.app) === null || _e === void 0 ? void 0 : _e.__internal__) === null || _f === void 0 ? void 0 : _f.resolveStaticResourceUrl) === null || _g === void 0 ? void 0 : _g.call(_f, imageUrl)) || imageUrl,
39
+ title,
40
+ };
41
+ }
42
+ try {
43
+ return ((_h = lifecycle === null || lifecycle === void 0 ? void 0 : lifecycle['onShareAppMessage']) === null || _h === void 0 ? void 0 : _h.call(lifecycle)) || {};
44
+ }
45
+ catch (error) {
46
+ console.log(error);
47
+ return {};
48
+ }
49
+ };
50
+ }
51
+ // 更新设备信息 窗口信息
52
+ result['onResize'] = (res) => {
53
+ var _a, _b, _c, _d;
54
+ let device = weapps_api_1.$w.device;
55
+ if (!device) {
56
+ return;
57
+ }
58
+ const width = (_a = res === null || res === void 0 ? void 0 : res.size) === null || _a === void 0 ? void 0 : _a.windowWidth;
59
+ const height = (_b = res === null || res === void 0 ? void 0 : res.size) === null || _b === void 0 ? void 0 : _b.windowHeight;
60
+ if (width !== ((_c = device === null || device === void 0 ? void 0 : device.viewport) === null || _c === void 0 ? void 0 : _c.width) || height !== ((_d = device === null || device === void 0 ? void 0 : device.viewport) === null || _d === void 0 ? void 0 : _d.height)) {
61
+ device.viewport = {
62
+ width,
63
+ height,
64
+ };
65
+ }
66
+ };
67
+ return result;
68
+ }
69
+ function createPage({ app, id, widgetProps, index = {}, lifecycle, state, computed, evtListeners, dataBinds, handlers, query: datasetQuery = {}, eventFlows = [], pageContext = {}, pageAttributes = {}, enableShare = false, }) {
70
+ const evtHandlers = (0, util_1.createEventHandlers)(evtListeners);
71
+ return Component({
72
+ _componentType: 'page',
73
+ data: {
74
+ ...(0, widget_1.createInitData)(widgetProps, dataBinds),
75
+ _isCheckingAtuh: false,
76
+ weDaHasLogin: false,
77
+ },
78
+ lifetimes: {
79
+ attached() {
80
+ this._disposers = [];
81
+ const $page = this._getInstance();
82
+ this._pageActive = true;
83
+ /**
84
+ * @deprecated
85
+ * 使用 behavior 的方式挂载methods
86
+ */
87
+ this.__mnt__ = (e) => {
88
+ const widget = (0, widget_1.getWidget)($page.widgets, e.target.id);
89
+ widget._methods = e.detail.methods;
90
+ };
91
+ /**
92
+ * @deprecated
93
+ * 使用 behavior 的方式挂载methods
94
+ */
95
+ this.__unmnt__ = (e) => {
96
+ const widget = (0, widget_1.getWidget)($page.widgets, e.target.id);
97
+ widget._methods = {};
98
+ };
99
+ this._disposers.push(...this.initMergeRenderer($page.widgets));
100
+ },
101
+ detached() {
102
+ const $page = this._getInstance();
103
+ this._pageActive = false;
104
+ $page.__internal__.active = this._pageActive;
105
+ (0, widget_1.disposeWidget)($page._rootWidget);
106
+ this._disposers.forEach((dispose) => dispose());
107
+ },
108
+ },
109
+ pageLifetimes: {
110
+ // 组件所在页面的生命周期函数,定义下给运营平台上报用
111
+ show: function () { },
112
+ hide: function () { },
113
+ },
114
+ methods: {
115
+ _pageActive: true,
116
+ _beforePageCustomLaunchPromise: null,
117
+ _query: {},
118
+ _disposers: [],
119
+ /** page lifecycles **/
120
+ ...extractLifecycles({ app }, lifecycle, pageAttributes === null || pageAttributes === void 0 ? void 0 : pageAttributes.appShareMessage, enableShare),
121
+ ...evtHandlers,
122
+ ...merge_renderer_1.default,
123
+ async beforePageCustomLaunch(query) {
124
+ if (!this._beforePageCustomLaunchPromise) {
125
+ this._beforePageCustomLaunchPromise = new Promise(async (resolve) => {
126
+ var _a, _b, _c, _d, _e;
127
+ await ((_a = wxApp.globaldata) === null || _a === void 0 ? void 0 : _a._beforePageCustomLaunchPromise);
128
+ const $page = this._getInstance();
129
+ if (query) {
130
+ index_1.EXTRA_API.setParams($page.uuid, query);
131
+ }
132
+ try {
133
+ this.setData({ _isCheckingAtuh: true });
134
+ const auth = await (0, util_1.checkAuth)(app, app.id, $page);
135
+ if (auth) {
136
+ this.setData({
137
+ weDaHasLogin: true,
138
+ });
139
+ (0, index_1.createStateDataSourceVar)($page.uuid, (0, index_1.generateParamsParser)({ app, $page, $w: (_b = $page.__internal__) === null || _b === void 0 ? void 0 : _b.$w }));
140
+ }
141
+ }
142
+ finally {
143
+ this.setData({ _isCheckingAtuh: false });
144
+ }
145
+ // eslint-disable-next-line no-restricted-syntax
146
+ for (const queryId in ((_c = $page.dataset) === null || _c === void 0 ? void 0 : _c.query) || {}) {
147
+ if (((_e = (_d = $page.dataset.query[queryId]) === null || _d === void 0 ? void 0 : _d._schema) === null || _e === void 0 ? void 0 : _e.trigger) === 'auto') {
148
+ try {
149
+ $page.dataset.query[queryId].trigger();
150
+ this._disposers.push(() => $page.dataset.query[queryId].destroy());
151
+ }
152
+ catch (e) {
153
+ console.error(`query ${queryId} 初始化失败:`, e);
154
+ }
155
+ }
156
+ }
157
+ resolve();
158
+ });
159
+ }
160
+ return this._beforePageCustomLaunchPromise;
161
+ },
162
+ async onLoad(options) {
163
+ var _a, _b;
164
+ const $page = this._getInstance();
165
+ (0, index_1.setConfig)({ currentPageId: $page.uuid });
166
+ this._pageActive = true;
167
+ $page.__internal__.active = this._pageActive;
168
+ app.__internal__.activePage = $page;
169
+ this._query = decodePageQuery(options || {});
170
+ await ((_a = this.beforePageCustomLaunch) === null || _a === void 0 ? void 0 : _a.call(this, this._query));
171
+ const hook = lifecycle.onLoad || lifecycle.onPageLoad;
172
+ await ((_b = hook === null || hook === void 0 ? void 0 : hook.call) === null || _b === void 0 ? void 0 : _b.call(hook, $page, this._query));
173
+ this._invokeEventHandler('load', { query: this._query });
174
+ },
175
+ async onReady() {
176
+ var _a;
177
+ const $page = this._getInstance();
178
+ this._disposers.push(...(0, watch_1.runWatchers)(index, this));
179
+ const hook = lifecycle.onReady || lifecycle.onPageReady;
180
+ await ((_a = hook === null || hook === void 0 ? void 0 : hook.call) === null || _a === void 0 ? void 0 : _a.call(hook, $page));
181
+ this._invokeEventHandler('ready');
182
+ },
183
+ onUnload() {
184
+ var _a;
185
+ const $page = this._getInstance();
186
+ const hook = lifecycle.onUnload || lifecycle.onPageUnload;
187
+ (_a = hook === null || hook === void 0 ? void 0 : hook.call) === null || _a === void 0 ? void 0 : _a.call(hook, $page);
188
+ this._invokeEventHandler('unload');
189
+ },
190
+ async onShow() {
191
+ var _a, _b;
192
+ const $page = this._getInstance();
193
+ (0, index_1.setConfig)({ currentPageId: $page.uuid });
194
+ this._pageActive = true;
195
+ $page.__internal__.active = this._pageActive;
196
+ app.__internal__.activePage = $page;
197
+ await ((_a = this.beforePageCustomLaunch) === null || _a === void 0 ? void 0 : _a.call(this, this._query));
198
+ const hook = lifecycle.onShow || lifecycle.onPageShow;
199
+ await ((_b = hook === null || hook === void 0 ? void 0 : hook.call) === null || _b === void 0 ? void 0 : _b.call(hook, $page));
200
+ this._invokeEventHandler('show');
201
+ },
202
+ onHide() {
203
+ var _a;
204
+ const $page = this._getInstance();
205
+ const hook = lifecycle.onHide || lifecycle.onPageHide;
206
+ (_a = hook === null || hook === void 0 ? void 0 : hook.call) === null || _a === void 0 ? void 0 : _a.call(hook, $page);
207
+ this._pageActive = false;
208
+ // 触发页面节点事件
209
+ this._invokeEventHandler('hide');
210
+ $page.__internal__.active = this._pageActive;
211
+ },
212
+ _invokeEventHandler(triggerName, params = {}) {
213
+ var _a, _b;
214
+ const keyName = (0, util_1.getMpEventHandlerName)(id, triggerName);
215
+ const event = new event_emitter_1.Event({
216
+ type: triggerName,
217
+ detail: params,
218
+ });
219
+ return (_b = (_a = this[keyName]) === null || _a === void 0 ? void 0 : _a.call) === null || _b === void 0 ? void 0 : _b.call(_a, this, event);
220
+ },
221
+ _getInstance() {
222
+ let $page = this.$WEAPPS_PAGE;
223
+ if ($page) {
224
+ return $page;
225
+ }
226
+ Object.assign(pageContext, {
227
+ id,
228
+ state: (0, mobx_1.observable)(state),
229
+ path: this.route,
230
+ widgets: {},
231
+ });
232
+ $page = pageContext;
233
+ this.$WEAPPS_PAGE = $page;
234
+ $page.handler = Object.keys(handlers).reduce((result, key) => {
235
+ try {
236
+ result[key] = handlers[key].bind($page);
237
+ }
238
+ catch (e) {
239
+ console.error('添加页面handler失败', e);
240
+ }
241
+ return result;
242
+ }, {});
243
+ $page.computed = (0, util_1.createComputed)(computed, $page);
244
+ let dataset = (0, index_1.createDataset)($page.uuid);
245
+ dataset.query = (0, util_1.generateDatasetQuery)(datasetQuery, {
246
+ $w: $page.__internal__.$w,
247
+ $app: app,
248
+ $page,
249
+ });
250
+ $page.dataset = dataset;
251
+ $page.state.dataset = dataset;
252
+ $page.setState = (userSetState) => {
253
+ Object.keys(userSetState).forEach((keyPath) => {
254
+ app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
255
+ });
256
+ };
257
+ const { widgets, rootWidget } = (0, widget_1.createWidgets)(widgetProps, dataBinds, this, $page.widgets);
258
+ $page.widgets = widgets;
259
+ $page._rootWidget = rootWidget;
260
+ $page.invokeComponentMethod = ({ component, method, params }) => {
261
+ var _a;
262
+ const components = $page.widgets[component];
263
+ let componentInstance = undefined;
264
+ if (Array.isArray(components)) {
265
+ if (components.length > 1) {
266
+ throw new Error(`调用方法失败:id为${component}的组件拥有多个实例`);
267
+ }
268
+ componentInstance = components[0];
269
+ }
270
+ else {
271
+ componentInstance = components;
272
+ }
273
+ const currentInstanceRef = ((_a = componentInstance === null || componentInstance === void 0 ? void 0 : componentInstance._getInstanceRef()) === null || _a === void 0 ? void 0 : _a.current) || {};
274
+ const { methods = {}, ...restInstanceRef } = currentInstanceRef;
275
+ const readonlyMap = {
276
+ ...componentInstance === null || componentInstance === void 0 ? void 0 : componentInstance._methods,
277
+ ...restInstanceRef,
278
+ ...methods,
279
+ };
280
+ if (typeof readonlyMap[method] !== 'function') {
281
+ throw new Error(`调用方法失败:未找到id为${component}下的方法${method}`);
282
+ }
283
+ return readonlyMap[method](params);
284
+ };
285
+ $page.__internal__.eventFlows = (0, util_1.generateEventFlows)(eventFlows, {
286
+ $w: $page.__internal__.$w,
287
+ $app: app,
288
+ $page,
289
+ });
290
+ return $page;
291
+ },
292
+ },
293
+ });
294
+ }
295
+ exports.createPage = createPage;
296
+ function decodePageQuery(query) {
297
+ return Object.keys(query).reduce((decoded, key) => {
298
+ decoded[key] = decodeURIComponent(query[key]);
299
+ return decoded;
300
+ }, {});
301
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.8.18",
3
+ "version": "1.8.19",
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",
@@ -32,14 +32,17 @@
32
32
  "test": "jest",
33
33
  "test:build": "ts-node ./__tests__/build.ts",
34
34
  "dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
35
- "build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js"
35
+ "build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js",
36
+ "build:template": "./scripts/buildTemplate.sh"
36
37
  },
37
38
  "bugs": {
38
39
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
39
40
  },
40
41
  "dependencies": {
41
- "@cloudbase/cals": "^1.0.14",
42
- "@cloudbase/lowcode-generator": "^1.8.8",
42
+ "@babel/core": "^7.11.6",
43
+ "@babel/preset-env": "^7.4.4",
44
+ "@cloudbase/cals": "^1.0.15",
45
+ "@cloudbase/lowcode-generator": "^1.8.9",
43
46
  "axios": "^0.21.0",
44
47
  "browserfs": "^1.4.3",
45
48
  "browserify-zlib": "^0.2.0",
Binary file
@@ -525,7 +525,7 @@
525
525
  crossorigin="anonymous"
526
526
  src="<%=
527
527
  cdnEndpoints.cdngo
528
- %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.39/dist/h5.browser.js"
528
+ %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.42/dist/h5.browser.js"
529
529
  ></script>
530
530
  <script
531
531
  crossorigin
@@ -551,7 +551,7 @@
551
551
  crossorigin
552
552
  src="<%=
553
553
  cdnEndpoints.cdngo
554
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.8bdf2bc04fec833b06b7.bundle.js"
554
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.f12ad33da9108405a333.bundle.js"
555
555
  ></script>
556
556
  </body>
557
557
  </html>
Binary file
Binary file
@@ -96,7 +96,9 @@ export function createEventHandlers(
96
96
  * 取消判断待兼容
97
97
  */
98
98
  if (pageId !== id /* || (__internal__ && !__internal__.active)*/) {
99
- console.error(`Action error: [${name}] 页面生命周期结束,链式调用中断`);
99
+ if (!name?.includes?.('onDataChange')) {
100
+ console.error(`Action error: [${name}] 页面生命周期结束,链式调用中断`);
101
+ }
100
102
  return false;
101
103
  }
102
104
  }
@@ -160,7 +162,7 @@ export function createEventHandlers(
160
162
  }
161
163
  } catch (e) {
162
164
  if (e.message) {
163
- e.message = `${currentTarget?.id || ''}[${trigger}:${l.key}]: ${e.message}`;
165
+ e._target = `${currentTarget?.id || ''}[${trigger}:${l.key}]`
164
166
  }
165
167
  nextEventHandles[0].handlerName = l.key ? `${prefix}$${l.key}_fail` : '';
166
168
  nextEventHandles[0].event.detail = isIfAction ? event.detail : e;
@@ -175,12 +177,12 @@ export function createEventHandlers(
175
177
  const nextHandler = nextEventHandles[0];
176
178
 
177
179
  if (!self[nextHandler.handlerName] && error) {
178
- console.error(`Action error:`, error);
180
+ console.error(`Action error:`, generateErrorDebugMessage(error), error?.stack);
179
181
  if (!looseError) {
180
182
  if (app.__internal__?.env?.type !== 'production') {
181
183
  app.showModal({
182
184
  title: `事件响应失败`,
183
- content: error.message || error.errMsg || '',
185
+ content: generateErrorDebugMessage(error) || error.errMsg || '',
184
186
  showCancel: false,
185
187
  });
186
188
  } else {
@@ -231,6 +233,12 @@ export function createEventHandlers(
231
233
 
232
234
  return evtHandlers;
233
235
  }
236
+
237
+ function generateErrorDebugMessage(error) {
238
+ return `${error?._target ? `${error?._target}:` : ''}${error?.message || ''}`;
239
+ }
240
+
241
+
234
242
  export function getDeep(target, key, keySeparator = '.') {
235
243
  if (key == null) {
236
244
  return target;