@cloudbase/lowcode-builder 1.2.4 → 1.3.0

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,9 +1,10 @@
1
1
  import { observable, autorun, untracked } from 'mobx';
2
2
  import { styleToCss } from './style';
3
3
  import { getDeep, generateDataContext } from './util';
4
- import { compLowcodes, create$comp } from './weapp-component';
4
+ import { compLowcodes } from './weapp-component';
5
5
  import EventEmitter from './event-emitter';
6
6
  import lodashSet from 'lodash.set';
7
+ import { REPEATER } from './constant'
7
8
 
8
9
  function basePullAt(array, indexes) {
9
10
  let length = array ? indexes.length : 0;
@@ -58,16 +59,18 @@ function resolveWidgetProp(props) {
58
59
  data.className = classList.join ? classList.join(' ') : classList;
59
60
  const extraProps = [
60
61
  'classList',
61
- '_forItems',
62
+ '_forContext',
62
63
  '_disposers',
63
64
  'children',
64
65
  'parent',
65
66
  '_parentId',
67
+ '_ancestorId',
68
+ '_descendants',
66
69
  'id',
67
70
  '_order',
68
71
  '_scope',
72
+ '_userWidget',
69
73
  'widgetType',
70
- '$comp',
71
74
  ];
72
75
  extraProps.map((prop) => {
73
76
  delete data[prop];
@@ -113,22 +116,22 @@ function createSubWidgetTree(
113
116
  dataBinds,
114
117
  ownerMpInst,
115
118
  widgetHolder = {},
116
- forItems = {},
119
+ forContext = {},
117
120
  ownerForWidgetHolder = null,
118
121
  failedBinds = [],
119
122
  defaultParent = { children: observable([]), _disposers: [] },
120
123
  ) {
121
- const indexPostfix = (forItems.lists || [])
124
+ const indexPostfix = (forContext.lists || [])
122
125
  .slice()
123
126
  .reverse()
124
- .map((list) => ID_SEPARATOR + list.currentIndex)
127
+ .map(({ currentIndex }) => ID_SEPARATOR + currentIndex)
125
128
  .join('');
126
129
 
127
130
  // traverse down the tree to set up all widgets
128
131
  dfsTree(curForNode, (node, parentNode, cache) => {
129
132
  const parentForWidgetArr = ownerForWidgetHolder?.[node.id] || [];
130
133
  const { _waForKey } = node.value;
131
- const key = forItems.itemsById?.[node.id]?.[_waForKey];
134
+ const key = forContext.forItems?.[node.id]?.[_waForKey];
132
135
  const index = cache[parentNode?.id]
133
136
  ? cache[parentNode.id].index
134
137
  : parentForWidgetArr.findIndex((widget) => key && widget._key === key);
@@ -149,8 +152,9 @@ function createSubWidgetTree(
149
152
  if (parentNode) {
150
153
  parentWidget = widgetHolder[parentNode.id] || ownerForWidgetHolder[parentNode.id];
151
154
  }
152
- w = createAWidget(widgetProps[node.id], node.id, indexPostfix, parentWidget, ownerMpInst);
155
+ w = createWidget(widgetProps[node.id], node.id, indexPostfix, parentWidget, ownerMpInst, forContext.forItems?.[node.id]);
153
156
  w._key = key;
157
+
154
158
  if (!parentWidget) {
155
159
  defaultParent.children.push(w);
156
160
  }
@@ -158,8 +162,14 @@ function createSubWidgetTree(
158
162
  } else {
159
163
  disposeWidget(existedWidget, true);
160
164
  }
161
- setUpWidgetDataBinds(w, dataBinds[node.id], forItems, failedBinds, ownerMpInst.getWeAppInst());
165
+ setUpWidgetDataBinds(w, dataBinds[node.id], forContext, failedBinds, ownerMpInst._getInstance());
162
166
  widgetHolder[node.id] = w;
167
+ if (widgetHolder?.[node._ancestorId]) {
168
+ // 在虚拟项 RepeaterItem 下挂载所有的子孙 __descendants
169
+ // 这里不要用 lodashSet,否则会出现刷新几次,出现 Error: [mobx.array] Index out of bounds 的错误,原因暂不明
170
+ widgetHolder[node._ancestorId]._descendants = widgetHolder[node._ancestorId]._descendants || {};
171
+ widgetHolder[node._ancestorId]._descendants[node.id] = widgetHolder[node.id];
172
+ }
163
173
  } else if (!existedWidget) {
164
174
  const len = parentForWidgetArr.push(observable([]));
165
175
  widgetHolder[node.id] = parentForWidgetArr[len - 1];
@@ -174,7 +184,7 @@ function createSubWidgetTree(
174
184
  if (node.forCount === curForNode.forCount + 1 && dataBinds[node.id] && dataBinds[node.id]._waFor) {
175
185
  // find the node bound with next level for
176
186
  const parent = node.parent ? widgetHolder[node.parent.id] : defaultParent;
177
- const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent);
187
+ const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forContext, widgetHolder, failedBinds, parent);
178
188
  parent._disposers.push(dispose); // Add the for bind dispose to the parent node of forNode
179
189
  }
180
190
  });
@@ -196,7 +206,7 @@ function retryFailedBinds(failedBinds, finalTry) {
196
206
  /**
197
207
  *
198
208
  * @param {*} curForNode
199
- * @param {*} forItems
209
+ * @param {*} forContext
200
210
  * @param {*} parentForWidgets
201
211
  * @param {*} parentWidget
202
212
  * @returns top level widgets or for dispose
@@ -207,7 +217,7 @@ function runFor(
207
217
  widgetProps,
208
218
  dataBinds,
209
219
  ownerMpInst,
210
- forItems,
220
+ forContext,
211
221
  ownerForWidgetHolder,
212
222
  failedBinds,
213
223
  defaultParent,
@@ -217,19 +227,22 @@ function runFor(
217
227
 
218
228
  const dispose = autorun(() => {
219
229
  let forList = [];
230
+ const currentForParentWidget = ownerForWidgetHolder[curForNode.parent?.id];
220
231
  try {
221
232
  clearTimeout(_FOR_ERROR_CACHE_MAP[nodeId]);
222
233
 
223
- const $instance = ownerMpInst.getWeAppInst();
224
- const dataContext = untracked(()=>generateDataContext(defaultParent));
234
+ const $instance = ownerMpInst._getInstance();
235
+ const dataContext = untracked(() => generateDataContext(defaultParent));
236
+ const $w = untracked(() => generateWidgetAPIContext($instance?.__internal__?.$w, currentForParentWidget, forContext));
225
237
 
226
238
  forList = dataBinds[nodeId]._waFor.call(
227
239
  $instance,
228
240
  $instance,
229
- forItems.lists,
230
- forItems.itemsById,
241
+ forContext.lists,
242
+ forContext.forItems,
231
243
  undefined,
232
244
  dataContext,
245
+ $w,
233
246
  );
234
247
  if (!Array.isArray(forList)) {
235
248
  forList = [];
@@ -288,11 +301,21 @@ function runFor(
288
301
  // w.parent = null
289
302
  });
290
303
 
304
+ const isInRepeaterChild =
305
+ currentForParentWidget?.widgetType === `${REPEATER.MODULE_NAME}:${REPEATER.REPEATER_NAME}`;
291
306
  forList.forEach((item, index) => {
292
- let { lists = [], itemsById = {} } = forItems;
293
- const _forItems = {
294
- lists: [{ currentItem: item, currentIndex: index }, ...lists],
295
- itemsById: { ...itemsById, [nodeId]: item },
307
+ let forContextListAlias;
308
+ let { lists = [], forItems = {} } = forContext;
309
+ const listMeta = { currentItem: item, currentIndex: index };
310
+ if (isInRepeaterChild) {
311
+ forContextListAlias = {
312
+ [`${currentForParentWidget.forIndex}` || 'currentIndex']: listMeta.currentIndex,
313
+ [`${currentForParentWidget.forItem}` || 'currentItem']: listMeta.currentItem,
314
+ };
315
+ }
316
+ const _forContext = {
317
+ lists: [{ ...listMeta, alias: forContextListAlias }, ...lists],
318
+ forItems: { ...forItems, [nodeId]: item },
296
319
  };
297
320
  const { rootWidget } = createSubWidgetTree(
298
321
  curForNode,
@@ -300,12 +323,12 @@ function runFor(
300
323
  dataBinds,
301
324
  ownerMpInst,
302
325
  {},
303
- _forItems,
326
+ _forContext,
304
327
  ownerForWidgetHolder,
305
328
  failedBinds,
306
329
  defaultParent,
307
330
  );
308
- rootWidget._forItems = _forItems;
331
+ rootWidget._forContext = _forContext;
309
332
  });
310
333
  });
311
334
  });
@@ -313,20 +336,19 @@ function runFor(
313
336
  return dispose;
314
337
  }
315
338
 
316
- function createAWidget(props, nodeId, indexPostfix, parent, ownerMpInst) {
317
- const w = observable(props);
339
+ function createWidget(props, nodeId, indexPostfix, parent, ownerMpInst, forContext) {
340
+ const { widgetType, _parentId, ...restProps } = props;
341
+ const w = observable(restProps);
318
342
  const id = `${nodeId}${indexPostfix}`;
319
343
 
320
344
  // Builtin props
321
345
  Object.defineProperty(w, 'id', { value: id });
322
- const { widgetType } = w;
323
- delete w.widgetType;
324
346
  Object.defineProperty(w, 'widgetType', { value: widgetType });
325
347
  Object.defineProperty(w, '_scope', {
326
348
  value: observable({
327
349
  id: nodeId,
328
- _parent: null,
329
350
  dataContext: {},
351
+ forContext
330
352
  }),
331
353
  });
332
354
 
@@ -338,17 +360,33 @@ function createAWidget(props, nodeId, indexPostfix, parent, ownerMpInst) {
338
360
  if (parent) {
339
361
  // w.parent = parent
340
362
  Object.defineProperty(w, 'parent', { value: parent });
341
- w._scope.parent = parent._scope;
342
363
  parent.children.push(w);
343
364
  }
344
- delete w._parentId;
345
365
 
346
- Object.defineProperty(w, '$comp', { value: create$comp(w) });
366
+ switch (widgetType) {
367
+ case `${REPEATER.MODULE_NAME}:${REPEATER.REPEATER_NAME}`: {
368
+ if (!w.items) {
369
+ Object.defineProperty(w, 'items', {
370
+ get() {
371
+ return (w.children || []).map((item) => {
372
+ const descendants = {};
373
+ Object.keys(item?._descendants || {}).forEach((key) => {
374
+ descendants[key] = item._descendants[key]._userWidget;
375
+ });
376
+ return descendants;
377
+ });
378
+ },
379
+ });
380
+ }
381
+ break;
382
+ }
383
+ }
384
+
347
385
  mountBuiltinWigetsAPI(w, ownerMpInst);
348
386
  return w;
349
387
  }
350
388
 
351
- function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
389
+ function setUpWidgetDataBinds(w, dataBinds, forContext, failedBinds, ctx) {
352
390
  Object.keys(dataBinds || {})
353
391
  .sort((a, b) => {
354
392
  return a.length - b.length > 0 ? 1 : -1;
@@ -364,10 +402,19 @@ function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
364
402
  try {
365
403
  clearTimeout(timer);
366
404
 
367
- const dataContext = untracked(()=>generateDataContext(w));
405
+ const dataContext = untracked(() => generateDataContext(w));
406
+ const $w = untracked(() => generateWidgetAPIContext(ctx?.__internal__?.$w, w, forContext));
368
407
 
369
408
  // Computed data bind in the next tick since data bind may read widgets data
370
- const value = dataBinds[prop].call(ctx, ctx, forItems.lists, forItems.itemsById, undefined, dataContext);
409
+ const value = dataBinds[prop].call(
410
+ ctx,
411
+ ctx,
412
+ forContext.lists,
413
+ forContext.forItems,
414
+ undefined,
415
+ dataContext,
416
+ $w,
417
+ );
371
418
  const paths = prop.split('.').filter((key) => !!key);
372
419
  if (paths.length > 1) {
373
420
  // 一定要 untracked 不然爆栈了
@@ -399,10 +446,10 @@ function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
399
446
  });
400
447
  }
401
448
 
402
- export function findForItemsOfWidget(widget) {
403
- const forItems = widget._forItems;
404
- if (forItems) return forItems;
405
- if (widget.parent) return findForItemsOfWidget(widget.parent);
449
+ export function generateForContextOfWidget(widget) {
450
+ const forContext = widget._forContext;
451
+ if (forContext) return forContext;
452
+ if (widget.parent) return generateForContextOfWidget(widget.parent);
406
453
  }
407
454
 
408
455
  export const ID_SEPARATOR = '-';
@@ -445,6 +492,16 @@ function createWidgetDataTree(widgets, dataBinds) {
445
492
  function addForCount(node) {
446
493
  if (node.parent) {
447
494
  node.forCount = node.parent.forCount;
495
+ const { widgetType } = node.parent.value;
496
+ if (widgetType === `${REPEATER.MODULE_NAME}:${REPEATER.REPEATER_ITEM_NAME}`) {
497
+ node._ancestorId = node.parent.id;
498
+ }
499
+ if (node.parent?._ancestorId) {
500
+ // Repeater 作用域内的所有子孙(排除里面的 Repeater 组件,它本身又产生深一层的作用域)继承父级的循环信息
501
+ if (!node._ancestorId) {
502
+ node._ancestorId = node.parent._ancestorId;
503
+ }
504
+ }
448
505
  }
449
506
  if (dataBinds[node.id]?._waFor) {
450
507
  node.forCount += 1;
@@ -517,7 +574,7 @@ function mountBuiltinWigetsAPI(widget, owner) {
517
574
  * Similar to selectOwnerComponent of WX MP: https://developers.weixin.qq.com/miniprogram/dev/reference/api/Component.html
518
575
  */
519
576
  widget.getOwnerWidget = function () {
520
- return owner?.getWeAppInst?.()?.node;
577
+ return owner?._getInstance?.()?.node;
521
578
  };
522
579
 
523
580
  // Will be overwritten by composited component
@@ -545,29 +602,150 @@ function mountBuiltinWigetsAPI(widget, owner) {
545
602
 
546
603
  const lowcode = compLowcodes[widget.widgetType];
547
604
  if (lowcode) {
548
- const { index = {}, config } = lowcode;
549
- const builtinProps = Object.keys(widget.$comp);
550
-
605
+ const { config } = lowcode;
551
606
  widget.getConfig = () => config;
607
+ }
552
608
 
553
- // #2 User defined APIs
554
- const { publicMethods = {} } = index;
555
- Object.keys(publicMethods).map((name) => {
556
- if (builtinProps.indexOf(name) > -1) {
557
- console.error(
558
- `Invalid publicMethod name(${name}) of Component(${widget.widgetType}), builtin name can't be used, please rename this method.`,
559
- );
560
- return;
561
- }
562
- const method = publicMethods[name];
563
- if (method instanceof Function) {
564
- Object.defineProperty(widget, name, { value: method.bind(widget.$comp) });
565
- Object.defineProperty(widget.$comp, name, { value: method });
566
- } else {
567
- console.error(`Component(${widget.widgetType}) method(${name}) is not a function.`);
568
- }
609
+ widget._getInstanceRef = () => null;
610
+
611
+ /**
612
+ * @deprecated
613
+ */
614
+ widget._methods = {};
615
+
616
+ widget._userWidget = untracked(() => {
617
+ return new UserWidget(widget);
618
+ });
619
+ }
620
+
621
+ /**
622
+ * 对外(用户)的 Widget
623
+ */
624
+ class UserWidget {
625
+ _widget = null;
626
+
627
+ get description() {
628
+ const { id } = this._widget;
629
+ return `
630
+ 使用说明:
631
+ 1. w 命名空间下为内置方法,可通过 $w.${id}.w.<成员> 或 $w.${id}.<成员> 访问。
632
+ 访问 id 示例: $w.${id}.id 或 $w.${id}.w.id
633
+ 2. custom 命名空间下为用户自定义对外暴露的成员,可通过 $w.${id}.custom.<成员> 或 $w.${id}.<成员> 访问。
634
+ 访问自定义方法 hello 示例: $w.${id}.hello() 或 $w.${id}.custom.hello()
635
+ 3. 通过 $w.${id}.<成员> 访问时,如果自定义成员与内置成员重名,则自定义成员覆盖内置成员。
636
+ 4. [注意]: 请不要直接访问 _widget,它里面的成员为内部实现,随时可能进行调整
637
+ `;
638
+ }
639
+
640
+ constructor(widget) {
641
+ this._widget = widget;
642
+ return new Proxy(this, {
643
+ get(target, prop) {
644
+ if (prop in target) {
645
+ return target[prop];
646
+ }
647
+
648
+ // 优先 custom
649
+ if (target.custom[prop]) {
650
+ return target.custom[prop];
651
+ }
652
+
653
+ // 再尝试内置的方法和属性
654
+ const buildinMember = target.sys[prop];
655
+ if (buildinMember) return buildinMember;
656
+
657
+ // 兼容原来的 widget。最后直接代理到 widget 上,主要是访问组件的属性
658
+ return target._widget[prop];
659
+ },
569
660
  });
570
661
  }
571
662
 
572
- widget._methods = {};
663
+ // 内置属性和方法命名空间
664
+ get sys() {
665
+ const widget = this._widget;
666
+ return {
667
+ /**
668
+ * 内置属性
669
+ */
670
+
671
+ get id() {
672
+ return widget.id;
673
+ },
674
+
675
+ get name() {
676
+ return widget.widgetType;
677
+ },
678
+
679
+ get parent() {
680
+ return widget.parent?._userWidget;
681
+ },
682
+
683
+ get children() {
684
+ return widget.children?.map((item) => item._userWidget) || [];
685
+ },
686
+
687
+ /**
688
+ * 内置方法
689
+ */
690
+
691
+ closest(filter) {
692
+ let { parent } = this;
693
+ if (!filter) return parent;
694
+
695
+ while (parent) {
696
+ const matched = filter(parent);
697
+ if (matched) return parent;
698
+
699
+ parent = parent.parent;
700
+ }
701
+
702
+ return null;
703
+ },
704
+ };
705
+ }
706
+
707
+ get custom() {
708
+ const { methods = {}, ...restInstance } = this._widget._getInstanceRef?.()?.current || {};
709
+
710
+ const userCustomMember = {
711
+ ...this._widget._methods,
712
+ ...restInstance,
713
+ ...methods,
714
+ };
715
+
716
+ return userCustomMember;
717
+ }
718
+ }
719
+
720
+ export function generateWidgetAPIContext($w = {}, widget, forContext) {
721
+ return new Proxy($w, {
722
+ get(target, prop) {
723
+ // debugger;
724
+
725
+ /**
726
+ * for context 变量优先
727
+ */
728
+ const { lists = [] } = forContext;
729
+ for (const meta of lists) {
730
+ const map = meta.alias || {};
731
+ if (prop in map) {
732
+ return map[prop];
733
+ }
734
+ }
735
+
736
+ // 尝试代理同级 widget
737
+ if (widget) {
738
+ let { parent } = widget;
739
+ while (parent) {
740
+ if (parent._descendants?.[prop]) {
741
+ return parent._descendants[prop]._userWidget;
742
+ }
743
+ parent = parent.parent;
744
+ }
745
+ }
746
+
747
+ // 尝试代理到全局的 $w
748
+ return target[prop];
749
+ },
750
+ });
573
751
  }
@@ -1,7 +1,7 @@
1
1
  import { observable } from 'mobx';
2
2
  import { createComponent } from '../../../common/weapp-component'
3
3
  import { concatClassList, px2rpx } from '../../../common/style'
4
- import { app } from '../../../app/weapps-api'
4
+ import { app, $app } from '../../../app/weapps-api'
5
5
  <%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
6
6
  <%= importor.state? "import stateFn from './lowcode/state'" : "const stateFn = {}" %>
7
7
  <%= importor.computed? "import computedFuncs from './lowcode/computed'" : "const computedFuncs = {}" %>
@@ -11,7 +11,6 @@ import * as constObj from '../libCommonRes/const'
11
11
  import * as toolsObj from '../libCommonRes/tools'
12
12
 
13
13
  const libCode = '<%= materialName %>'
14
- const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
15
14
 
16
15
  const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
17
16
 
@@ -19,9 +18,9 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
19
18
  <%= handlerName%>: [
20
19
  <%listeners.map(l=> { %>{
21
20
  key: '<%= l.key %>',
22
- handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems, $context}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
21
+ handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else {%> <%= l.handler %> <%} %>,
23
22
  data: <%= stringifyObj(l.data, {depth: null}) %>,
24
- boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($comp, lists, forItems, event, $context) => {<%= bindMeta.imports %> return (
23
+ boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($comp, lists, forItems, event, $context, $w) => {<%= bindMeta.imports %> return (
25
24
  <%= bindMeta.expression === '' ? 'undefined': bindMeta.expression %>
26
25
  )},
27
26
  <%}) %>}
@@ -51,7 +50,7 @@ const handler = {<% handlers.forEach(h => {%>
51
50
 
52
51
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
53
52
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, bindMeta]) => { %>
54
- "<%= prop %>": function ($comp, lists, forItems, event, $context) {<%= bindMeta.imports %> return (
53
+ "<%= prop %>": function ($comp, lists, forItems, event, $context, $w) {<%= bindMeta.imports %> return (
55
54
  <%= bindMeta.expression === '' ? 'undefined': bindMeta.expression %>
56
55
  ); },<% }) %>
57
56
  },<%}) %>
@@ -5,7 +5,7 @@
5
5
  "dependencies": {<% if(importJSSDK) {%>
6
6
  "@cloudbase/js-sdk": "2.5.6-beta.1",<% } %>
7
7
  "@cloudbase/oauth": "0.1.1-alpha.5",
8
- "@cloudbase/weda-client": "0.2.36",
8
+ "@cloudbase/weda-client": "0.2.38",
9
9
  "@cloudbase/weda-cloud-sdk": "1.0.26",
10
10
  "mobx": "^5.15.4",
11
11
  "lodash.get": "^4.4.2",
@@ -1 +1,21 @@
1
- export const $page = {}
1
+ import { $w as baseAPI } from '<%= subLevelPath %>../../app/weapps-api'
2
+
3
+ export const $page = {
4
+ __internal__: {}
5
+ };
6
+
7
+ export const $w = new Proxy(
8
+ baseAPI,
9
+ {
10
+ get(target, prop) {
11
+ // 尝试代理页面级别组件实例
12
+ const pageWidget = $page.widgets?.[prop];
13
+ if (pageWidget) {
14
+ return pageWidget._userWidget;
15
+ }
16
+ return target[prop]
17
+ },
18
+ },
19
+ );
20
+
21
+ $page.__internal__.$w = $w
@@ -1,24 +1,22 @@
1
1
  import { observable } from 'mobx';
2
2
  import { createPage } from '<%= subLevelPath %>../../common/weapp-page'
3
3
  import { concatClassList, px2rpx } from '<%= subLevelPath %>../../common/style'
4
- import { app } from '<%= subLevelPath %>../../app/weapps-api'
4
+ import { app, $app } from '<%= subLevelPath %>../../app/weapps-api'
5
5
  import { $$<%= pageName %> as handlers } from '../../app/handlers'
6
6
  <%= importor.lifecycle? `import lifecyle from '../../lowcode/${pageName}/lifecycle'` : "const lifecyle = {}" %>
7
7
  <%= importor.state? `import state from '../../lowcode/${pageName}/state'` : "const state = {}" %>
8
8
  <%= importor.computed? `import computed from '../../lowcode/${pageName}/computed'` : "const computed = {}" %>
9
9
  import { $page } from './api'
10
10
 
11
- const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
12
-
13
11
  const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
14
12
  /** widget event listeners **/
15
13
  const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listeners])=>{%>
16
14
  <%= handlerName%>: [
17
15
  <%listeners.map(l=> { %>{
18
16
  key: '<%= l.key %>',
19
- handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems, $context}){const $for = forItems; const $index=lists?.[0]?.currentIndex; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
17
+ handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else {%> <%= l.handler %> <%} %>,
20
18
  data: <%= stringifyObj(l.data, {depth: null}) %>,
21
- boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($page, lists, forItems, event, $context) => {<%= bindMeta.imports %> return (
19
+ boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($page, lists, forItems, event, $context, $w) => {<%= bindMeta.imports %> return (
22
20
  <%= bindMeta.expression === '' ? 'undefined': bindMeta.expression %>
23
21
  )},
24
22
  <%}) %>}
@@ -28,7 +26,7 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
28
26
 
29
27
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
30
28
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, bindMeta]) => { %>
31
- "<%= prop %>": function ($page, lists, forItems, event, $context) {<%= bindMeta.imports %> return (
29
+ "<%= prop %>": function ($page, lists, forItems, event, $context, $w) {<%= bindMeta.imports %> return (
32
30
  <%= bindMeta.expression === '' ? 'undefined': bindMeta.expression %>
33
31
  ); },<% }) %>
34
32
  },<%}) %>
@@ -1,3 +1,3 @@
1
1
  {
2
- "usingComponents": <%= JSON.stringify(usingComponents)%><%= extra %>
2
+ "usingComponents": <%= JSON.stringify(usingComponents, undefined, 2)%><%= extra %>
3
3
  }
@@ -1 +0,0 @@
1
- export default { env: { buildType: 'mp' } }