@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.
@@ -11,9 +11,10 @@ const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
11
11
  const materials_1 = require("./materials");
12
12
  const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
13
13
  const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib/generator/util/name-mangler"));
14
+ const config_1 = require("../config");
15
+ const util_1 = require("./util");
14
16
  const error = chalk_1.default.redBright;
15
- function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, componentGenerics, nodeTransform) {
16
- var _a;
17
+ function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, componentGenerics, nodeTransform) {
17
18
  const nameMangler = ctx.isProduction ? new name_mangler_1.default({ blackList: mp_1.builtinMpTags }) : undefined;
18
19
  const xmlJson = {
19
20
  elements: [
@@ -32,12 +33,6 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
32
33
  };
33
34
  if (ctx.isPage) {
34
35
  const originElements = xmlJson.elements;
35
- if (originElements === null || originElements === void 0 ? void 0 : originElements.length) {
36
- if (!((_a = originElements[0]) === null || _a === void 0 ? void 0 : _a.attributes)) {
37
- originElements[0].attributes = {};
38
- }
39
- originElements[0].attributes['data-weui-theme'] = 'light';
40
- }
41
36
  // 登录校验: 向其最外层包裹一层block
42
37
  xmlJson.elements = [
43
38
  {
@@ -45,6 +40,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
45
40
  name: 'block',
46
41
  attributes: {
47
42
  ['wx:if']: '{{weDaHasLogin}}',
43
+ ['data-weui-theme']: 'light',
48
44
  },
49
45
  elements: originElements,
50
46
  _order: -1,
@@ -55,10 +51,11 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
55
51
  function createXml(widgets, parent = null, parentForNodes = []) {
56
52
  var _a, _b, _c, _d, _e, _f;
57
53
  const elements = [];
54
+ // eslint-disable-next-line no-restricted-syntax
58
55
  for (const id in widgets) {
59
56
  const { xComponent, xProps, properties, xIndex, genericComp } = widgets[id];
60
- const { data: data0 = {}, listeners = [], directives = {}, staticResourceAttribute = ['src'] } = xProps || {};
61
- const data = { ...data0 };
57
+ const { data: _data = {}, listeners = [], directives = {}, staticResourceAttribute = ['src'] } = xProps || {};
58
+ const data = { ..._data };
62
59
  if (directives.waIf && directives.waIf.value === false) {
63
60
  continue;
64
61
  }
@@ -66,9 +63,8 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
66
63
  // slot prop
67
64
  const slotNodes = createXml(properties, parent, parentForNodes);
68
65
  slotNodes.forEach((node) => {
69
- var _a;
70
66
  node.attributes.slot = id;
71
- (_a = parent === null || parent === void 0 ? void 0 : parent.elements) === null || _a === void 0 ? void 0 : _a.push(node);
67
+ elements === null || elements === void 0 ? void 0 : elements.push(node);
72
68
  });
73
69
  if (parent) {
74
70
  delete parent.attributes[id];
@@ -77,21 +73,36 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
77
73
  }
78
74
  const componentKey = `${xComponent.moduleName}:${xComponent.name}`;
79
75
  const helpMsg = `Please check component(${id}) in component tree of ${docTag}.`;
80
- const materialLib = ctx.materialLibs.find((lib) => lib.name === xComponent.moduleName);
81
- const miniprogramPlugin = (_a = ctx.miniprogramPlugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.name === xComponent.moduleName);
82
- if (!materialLib && !miniprogramPlugin) {
83
- console.error(error(`Component lib(${xComponent.moduleName}) not found. ${helpMsg}`));
84
- continue;
85
- }
86
- const componentProto = materialLib
87
- ? materialLib.components.find((comp) => comp.name === xComponent.name)
88
- : miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.componentConfigs.find((comp) => comp.name === xComponent.name);
89
- if (!componentProto) {
90
- console.error(error(`Component(${xComponent.name}) not found in lib(${xComponent.moduleName}). ${helpMsg}`));
91
- continue;
76
+ let tagName, path, componentProto;
77
+ switch (componentKey) {
78
+ case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`: {
79
+ const children = createXml(properties, parent, parentForNodes);
80
+ for (let item of children) {
81
+ item._order = xIndex || 0;
82
+ }
83
+ elements.push(...children);
84
+ continue;
85
+ break;
86
+ }
87
+ case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`: {
88
+ tagName = 'block';
89
+ path = '';
90
+ break;
91
+ }
92
+ default: {
93
+ componentProto = (0, util_1.findComponentInfo)(xComponent, {
94
+ materialLibs: ctx.materialLibs,
95
+ miniprogramPlugins: ctx.miniprogramPlugins,
96
+ });
97
+ if (!componentProto) {
98
+ console.error(error(`Component(${xComponent.name}) not found in lib(${xComponent.moduleName}). ${helpMsg}`));
99
+ continue;
100
+ }
101
+ const meta = (0, materials_1.getWxmlTag)(ctx, xComponent, nameMangler);
102
+ tagName = meta.tagName;
103
+ path = meta.path;
104
+ }
92
105
  }
93
- // eslint-disable-next-line prefer-const
94
- let { tagName, path } = (0, materials_1.getWxmlTag)(xComponent, ctx, nameMangler);
95
106
  if (genericComp === null || genericComp === void 0 ? void 0 : genericComp.propName) {
96
107
  tagName = getGenericCompTagName(genericComp.propName);
97
108
  componentGenerics[tagName] = { default: path || tagName };
@@ -100,50 +111,46 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
100
111
  usingComponents[tagName] = path;
101
112
  }
102
113
  let curForNodes = parentForNodes;
103
- if ((_b = directives.waFor) === null || _b === void 0 ? void 0 : _b.value) {
114
+ if ((_a = directives.waFor) === null || _a === void 0 ? void 0 : _a.value) {
104
115
  curForNodes = [...curForNodes, id];
105
116
  }
106
117
  const attrPrefix = `${wxmlDataPrefix.widgetProp}${id}${curForNodes
107
118
  .map((forNodeId) => `[${wxmlDataPrefix.forIndex}${forNodeId}]`)
108
119
  .join('')}`;
109
- const idAttr = curForNodes.length < 1
110
- ? id
111
- : `{{'${id}'${curForNodes.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`).join('')}}}`;
112
120
  if (tagName === 'slot') {
113
121
  const slotNode = {
114
122
  type: 'element',
115
123
  name: tagName,
116
124
  attributes: {
117
- name: data0.name.type && data0.name.type !== 'static' ? `{{${id}.name}}` : data0.name.value,
125
+ name: data.name.type && data.name.type !== 'static' ? `{{${id}.name}}` : data.name.value,
118
126
  },
119
127
  elements: [],
120
128
  _order: xIndex || 0,
121
129
  _parent: null,
122
130
  };
123
- if ((_c = directives.waIf) === null || _c === void 0 ? void 0 : _c.value) {
131
+ if ((_b = directives.waIf) === null || _b === void 0 ? void 0 : _b.value) {
124
132
  slotNode.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
125
133
  }
126
134
  elements.push(slotNode);
127
135
  continue;
128
136
  }
137
+ const rawTag = ['slot', 'block'].includes(tagName);
129
138
  const node = {
130
139
  type: 'element',
131
140
  name: tagName,
132
141
  attributes: {
133
- id: idAttr,
134
- 'bind:attached': '__mnt__',
135
- 'bind:detached': '__unmnt__',
136
- style: `{{${attrPrefix}.style}}`,
137
- [(0, mp_1.getClassAttrName)(tagName)]: `{{${attrPrefix}.className}}`,
142
+ id: curForNodes.length < 1
143
+ ? id
144
+ : `{{'${id}'${curForNodes
145
+ .map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`)
146
+ .join('')}}}`,
147
+ style: rawTag || ((_c = componentProto === null || componentProto === void 0 ? void 0 : componentProto.meta) === null || _c === void 0 ? void 0 : _c.mustEmptyStyle) ? undefined : `{{${attrPrefix}.style}}`,
148
+ [(0, mp_1.getClassAttrName)(tagName)]: rawTag ? undefined : `{{${attrPrefix}.className}}`,
138
149
  },
139
150
  elements: [],
140
151
  _order: xIndex || 0,
141
152
  _parent: parent,
142
153
  };
143
- const { mustEmptyStyle } = componentProto.meta || {};
144
- if (mustEmptyStyle) {
145
- delete node.attributes.style;
146
- }
147
154
  if ((_d = directives.waIf) === null || _d === void 0 ? void 0 : _d.value) {
148
155
  node.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
149
156
  }
@@ -154,7 +161,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
154
161
  node.attributes['wx:for-index'] = wxmlDataPrefix.forIndex + id;
155
162
  node.attributes['wx:key'] = ((_f = directives.waForKey) === null || _f === void 0 ? void 0 : _f.value) ? '_key' : '$$i';
156
163
  }
157
- const compSchema = componentProto.dataForm;
164
+ const compSchema = componentProto === null || componentProto === void 0 ? void 0 : componentProto.dataForm;
158
165
  for (const prop of Object.keys(data || {})) {
159
166
  if (compSchema) {
160
167
  const fieldDef = compSchema[prop];
@@ -175,7 +182,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
175
182
  // handle generic component, https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/generics.html
176
183
  const passedComp = data[prop].value;
177
184
  const [libName, compName] = passedComp.split(':');
178
- const { tagName, path } = (0, materials_1.getWxmlTag)({ moduleName: libName, name: compName }, ctx, nameMangler);
185
+ const { tagName, path } = (0, materials_1.getWxmlTag)(ctx, { moduleName: libName, name: compName }, nameMangler);
179
186
  node.attributes[`generic:${getGenericCompTagName(prop)}`] = tagName;
180
187
  usingComponents[tagName] = path;
181
188
  continue;
@@ -186,28 +193,28 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
186
193
  : `${attrPrefix}['${prop}']`;
187
194
  xmlJsonSetCustomAttr(node, prop, getAttrBind(data[prop], widgetBind, staticResourceAttribute.includes(prop)), xComponent);
188
195
  }
196
+ /**
197
+ * 来自外部引用的组件,添加系统系别的事件绑定
198
+ */
199
+ if (componentGenerics[tagName] || usingComponents[tagName]) {
200
+ node.attributes['bind:attached'] = '__mnt__';
201
+ node.attributes['bind:detached'] = '__unmnt__';
202
+ }
189
203
  // Event binding
190
- const { inputProps, syncProps } = componentProto.meta || {};
204
+ const { inputProps, syncProps } = (componentProto === null || componentProto === void 0 ? void 0 : componentProto.meta) || {};
191
205
  const syncConfigs = syncProps || inputProps || {};
192
- Object.entries(syncConfigs).map(([prop, config]) => {
193
- const configs = Array.isArray(config) ? config : [config];
194
- configs.forEach(({ changeEvent: evtName }) => {
195
- // 兼容微信 7.0.13 安卓版本 textarea 组件的 bindinput 事件,bind:input 写法,事件会失效
196
- const sep = getEventBindSep(tagName);
197
- node.attributes[`bind${sep}${evtName}`] = getMpEventHanlderName(id, evtName);
198
- });
199
- });
200
- listeners.forEach((l) => {
201
- const evtName = getMpEventName(l.trigger);
202
- const modifiers = l;
203
- node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
204
- });
206
+ const processedListeners = [...(0, util_1.generateSyncListeners)(syncConfigs), ...listeners];
205
207
  // 扩展组件配置
206
- const { compConfig } = componentProto;
208
+ const { compConfig } = componentProto || {};
207
209
  // 如果是数据容器,则增加一个onDataChange事件 bind:onDataChange="onid1$onDataChange"
208
210
  if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
209
- node.attributes['bind:onDataChange'] = getMpEventHanlderName(id, 'onDataChange');
211
+ processedListeners.push(...(0, util_1.generateDataContainerListeners)());
210
212
  }
213
+ processedListeners.forEach((l) => {
214
+ const evtName = getMpEventName(l.trigger);
215
+ const modifiers = l;
216
+ node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
217
+ });
211
218
  if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.pluginConfig) {
212
219
  if (compConfig.pluginConfig.attributes) {
213
220
  Object.assign(node.attributes, compConfig.pluginConfig.attributes);
@@ -233,7 +240,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
233
240
  }*/
234
241
  node.elements = node.elements.concat(createXml(properties, node, curForNodes));
235
242
  // 特殊处理 swiper,对swiper 子节点包裹议程 swiperItem
236
- if (tagName === 'swiper' || componentKey === 'weda:Swiper' || componentKey === 'gsd-h5-react:Swiper') {
243
+ if (tagName === 'swiper' || componentKey === 'weda:Swiper' || componentKey === `${config_1.OFFICIAL_LIB_KEY}:Swiper`) {
237
244
  node.elements = node.elements.map((item, index) => {
238
245
  var _a, _b;
239
246
  let { ['wx:for']: wxFor, ['wx:for-index']: wxForIndex, ['wx:key']: wxKey, ['wx:if']: wxIf, ...itemRestKey } = item.attributes || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
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": "^0.5.2",
42
- "@cloudbase/lowcode-generator": "^1.2.2",
41
+ "@cloudbase/cals": "^0.5.6",
42
+ "@cloudbase/lowcode-generator": "^1.3.0",
43
43
  "axios": "^0.21.0",
44
44
  "browserfs": "^1.4.3",
45
45
  "browserify-zlib": "^0.2.0",
@@ -475,7 +475,7 @@
475
475
  crossorigin
476
476
  src="<%=
477
477
  cdnEndpoints.cdngo
478
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.ccc8cf9b70a10613d046.bundle.js"
478
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.d8ce1d946578756cc8da.bundle.js"
479
479
  ></script>
480
480
  </body>
481
481
  </html>
@@ -1,9 +1,10 @@
1
1
  import { observable } from 'mobx'
2
2
  import { createMpApp } from '@cloudbase/weda-client';
3
3
  import { createComputed, formatEnum, enumOptions } from '<%= subLevelPath %>../common/util'
4
- import process from '<%= subLevelPath %>../common/process'
5
4
  import appGlobal from '<%= subLevelPath %>../app/app-global'
6
5
  import { createDataset } from '<%= subLevelPath %>../datasources/index'
6
+ import lodashGet from 'lodash.get';
7
+
7
8
 
8
9
  <%= importor.state? `import state from '../lowcode/state'` : "const state = {}" %>
9
10
  <%= importor.computed? `import computed from '../lowcode/computed'` : "const computed = {}" %>
@@ -12,7 +13,15 @@ import { createDataset } from '<%= subLevelPath %>../datasources/index'
12
13
  const mainAppKey = '__weappsMainApp'
13
14
 
14
15
  export const app = createGlboalApi()
15
- export { process }
16
+ export const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
17
+ export const $w = new Proxy(
18
+ {},
19
+ {
20
+ get(_, prop) {
21
+ return app.__internal__.$w?.[prop];
22
+ },
23
+ },
24
+ );
16
25
 
17
26
  function createGlboalApi() {
18
27
  const mpApp = createMpApp({
@@ -1,5 +1,5 @@
1
1
  <%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
2
- import { app } from './app/weapps-api'
2
+ import { app, $app } from './app/weapps-api'
3
3
  // 引入数据源管理器并进行初始化
4
4
  import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
5
5
  import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util'
@@ -15,7 +15,6 @@ console.warn = (...args) => {
15
15
  }
16
16
  }
17
17
 
18
- const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});
19
18
  // 设置数据源请求的 loading 及 toast 处理
20
19
  setConfig({
21
20
  beforeDSRequest: (cfg) => {
@@ -0,0 +1 @@
1
+ export const REPEATER = <%= REPEATER %>