@cloudbase/lowcode-builder 1.8.86 → 1.8.88

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.8.86",
3
+ "version": "1.8.88",
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",
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@babel/core": "7.21.4",
49
49
  "@babel/preset-env": "7.21.4",
50
- "@cloudbase/cals": "^1.0.69",
50
+ "@cloudbase/cals": "^1.0.70",
51
51
  "@cloudbase/lowcode-generator": "^1.8.25",
52
52
  "axios": "^0.21.0",
53
53
  "browserfs": "^1.4.3",
@@ -23,17 +23,19 @@
23
23
  <% })%> <% if(cdnEndpoints.aegis){ %>
24
24
  <script crossorigin="anonymous" src="<%= cdnEndpoints.aegis %>/aegis-sdk/latest/aegis.min.js"></script>
25
25
  <script>
26
- const _aegis = new Aegis({
27
- id: 'lXHFsBpTjIzNADiczY', // 项目ID,即上报key
28
- reportApiSpeed: true, // 接口测速
29
- reportAssetSpeed: true, // 静态资源测速
30
- spa: true,
31
- ext1: '<%=appId%>',
32
- ext3: '<%=ext3%>',
33
- version: '<%= !isAdminPortal? "0.0.2" : "0.0.3" %>',
34
- env: '<%= mode !== "production"? "pre" : "production" %>',
35
- });
36
- window._aegis = _aegis;
26
+ if (Aegis) {
27
+ const _aegis = new Aegis({
28
+ id: 'lXHFsBpTjIzNADiczY', // 项目ID,即上报key
29
+ reportApiSpeed: true, // 接口测速
30
+ reportAssetSpeed: true, // 静态资源测速
31
+ spa: true,
32
+ ext1: '<%=appId%>',
33
+ ext3: '<%=ext3%>',
34
+ version: '<%= !isAdminPortal? "0.0.2" : "0.0.3" %>',
35
+ env: '<%= mode !== "production"? "pre" : "production" %>',
36
+ });
37
+ window._aegis = _aegis;
38
+ }
37
39
  window._aegis_inited = Date.now();
38
40
  </script>
39
41
  <% }%>
@@ -543,7 +545,7 @@
543
545
  crossorigin
544
546
  src="<%=
545
547
  cdnEndpoints.cdngo
546
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.e1085a387b7fdbc5b299.bundle.js"
548
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.4b74407996a537f4d5a6.bundle.js"
547
549
  ></script>
548
550
  </body>
549
551
  </html>
@@ -16,6 +16,11 @@ export class Query {
16
16
  #observableValue = observable({ data: null, error: null, isFetching: false });
17
17
  #eventHandlerMap = {};
18
18
  #action = () => {};
19
+ #runQueryMap = {
20
+ sql: { QueryResource: 'mysql-plugin', QueryPath: '/WeDa/Query/V1/RunPluginQuery' },
21
+ sqlserver: { QueryResource: 'mssql-plugin', QueryPath: '/WeDa/Query/V1/RunPluginQuery' },
22
+ 'cloud-connector': { QueryResource: 'apis-plugin', QueryPath: '/WeDa/Connector/v1/RunApisQuery' },
23
+ };
19
24
  constructor({ schema, context, options = {} }) {
20
25
  const { looseError = false } = options;
21
26
  this.#schema = schema;
@@ -33,7 +38,7 @@ export class Query {
33
38
  autorun(
34
39
  (r) => {
35
40
  try {
36
- const data = this.#resolveParams();
41
+ const data = this.#resolveParams({}, { combainErrors: true });
37
42
  if (this.#triggered) {
38
43
  this.#debounceTrigger(data);
39
44
  }
@@ -59,76 +64,85 @@ export class Query {
59
64
 
60
65
  const { $w } = this.#context;
61
66
 
62
- this.#action =
63
- this.#schema.type === 'sql' || this.#schema.type === 'sqlserver'
64
- ? async function (data) {
65
- const requestData = {
66
- EnvId: $w.env.envId,
67
- Name: data.sqlTemplateId,
68
- Parameter: JSON.stringify(
69
- Object.entries(data.params || {}).reduce((list, [key, value]) => {
70
- if (value !== undefined) {
71
- let type = 'OBJECT';
72
- const typeofValue = typeof value;
73
- switch (typeofValue) {
74
- case 'boolean': {
75
- type = 'BOOLEAN';
76
- break;
77
- }
78
- case 'number': {
79
- type = 'NUMBER';
80
- break;
81
- }
82
- case 'string': {
83
- type = 'STRING';
84
- break;
85
- }
86
- default: {
87
- if (Array.isArray(value)) {
88
- type = 'ARRAY';
89
- } else {
90
- type = 'OBJECT';
91
- }
67
+ this.#action = this.#isRunQueryType
68
+ ? async function (data) {
69
+ const requestData = {
70
+ EnvId: $w.env.envId,
71
+ Name: data.sqlTemplateId,
72
+ Parameter: JSON.stringify(
73
+ Object.entries(data.params || {}).reduce((list, [key, value]) => {
74
+ if (value !== undefined) {
75
+ let type = 'OBJECT';
76
+ const typeofValue = typeof value;
77
+ switch (typeofValue) {
78
+ case 'boolean': {
79
+ type = 'BOOLEAN';
80
+ break;
81
+ }
82
+ case 'number': {
83
+ type = 'NUMBER';
84
+ break;
85
+ }
86
+ case 'string': {
87
+ type = 'STRING';
88
+ break;
89
+ }
90
+ default: {
91
+ if (Array.isArray(value)) {
92
+ type = 'ARRAY';
93
+ } else {
94
+ type = 'OBJECT';
92
95
  }
93
96
  }
94
-
95
- list.push({
96
- Key: key,
97
- Type: type,
98
- Value: type === 'STRING' ? value : JSON.stringify(value),
99
- });
100
97
  }
101
98
 
102
- return list;
103
- }, []) || [],
104
- ),
105
- };
99
+ list.push({
100
+ Key: key,
101
+ Type: type,
102
+ Value: type === 'STRING' ? value : JSON.stringify(value),
103
+ });
104
+ }
105
+
106
+ return list;
107
+ }, []) || [],
108
+ ),
109
+ };
110
+
111
+ const Data = await $w.cloud.callWedaApi({
112
+ action: 'RunQuery',
113
+ CallQuery: true,
114
+ ...(this.#runQueryMap[this.#schema.type] || this.#runQueryMap['sql']),
115
+ EnvId: requestData.EnvId,
116
+ QueryName: requestData.Name,
117
+ data: requestData,
118
+ });
106
119
 
107
- const Data = await $w.cloud.callWedaApi({
108
- action: 'RunQuery',
109
- CallQuery: true,
110
- QueryResource: this.#schema.type === 'sql' ? 'mysql-plugin' : 'mssql-plugin',
111
- QueryPath: '/WeDa/Query/V1/RunPluginQuery',
112
- EnvId: requestData.EnvId,
113
- QueryName: requestData.Name,
114
- data: requestData,
115
- });
120
+ // const Data = await $w.cloud.callWedaApi({
121
+ // action: 'RunPluginQuery',
122
+ // data: {
123
+ // MainAppId: $w.app.id,
124
+ // ...requestData
125
+ // },
126
+ // });
116
127
 
117
- // const Data = await $w.cloud.callWedaApi({
118
- // action: 'RunPluginQuery',
119
- // data: {
120
- // MainAppId: $w.app.id,
121
- // ...requestData
122
- // },
123
- // });
128
+ const { ExecuteResultList = [], Total, Payload } = Data || {};
124
129
 
125
- const { ExecuteResultList = [], Total } = Data || {};
126
- return {
127
- records: ExecuteResultList.map((item) => JSON.parse(item)),
128
- total: Total || ExecuteResultList.length,
129
- };
130
- }
131
- : this.#schema.handler;
130
+ let payload = Payload;
131
+ try {
132
+ if (Payload) {
133
+ payload = JSON.parse(Payload);
134
+ }
135
+ } catch (e) {}
136
+ return {
137
+ ...(this.#schema.type === 'cloud-connector'
138
+ ? payload
139
+ : {
140
+ records: ExecuteResultList.map((item) => JSON.parse(item)),
141
+ total: Total || ExecuteResultList.length,
142
+ }),
143
+ };
144
+ }
145
+ : this.#schema.handler;
132
146
  this.#eventHandlerMap = Object.entries(
133
147
  createEventHandlers(this.#schema.eventHandlers || {}, {
134
148
  looseError: looseError,
@@ -164,6 +178,9 @@ export class Query {
164
178
  get isFetching() {
165
179
  return this.#observableValue.isFetching;
166
180
  }
181
+ get #isRunQueryType() {
182
+ return !!this.#runQueryMap[this.#schema.type];
183
+ }
167
184
  async trigger(additionalScope, options = {}) {
168
185
  this.#triggered = true;
169
186
  return this.#innerTrigger(this.#resolveParams(additionalScope), options);
@@ -217,7 +234,7 @@ export class Query {
217
234
  }, 300);
218
235
  }
219
236
 
220
- #resolveParams(additionalScope = {}) {
237
+ #resolveParams(additionalScope = {}, options = {}) {
221
238
  /**
222
239
  * 这里万一其中某个字段计算失败
223
240
  * 好像会阻塞其他字段的计算
@@ -227,7 +244,7 @@ export class Query {
227
244
  mergeDynamic2StaticData(toJS(this.#paramsRef.current), this.#dataBinds, {
228
245
  $w: this.#context.$w,
229
246
  paramsContext: additionalScope,
230
- }) || {};
247
+ }, options?.combainErrors) || {};
231
248
 
232
249
  return params;
233
250
  }
@@ -714,6 +714,7 @@ export function mergeDynamic2StaticData(
714
714
  dataContext?: Record<string,any>;
715
715
  paramsContext?: Record<string,any>;
716
716
  }*/,
717
+ combainErrors = false,
717
718
  ) {
718
719
  const { forContext = {}, codeContext = {}, dataContext = {}, $w, paramsContext = {} } = context;
719
720
  const { lists = [], forItems = {} } = forContext;
@@ -721,22 +722,34 @@ export function mergeDynamic2StaticData(
721
722
  const resolvedData = {
722
723
  ...staticData,
723
724
  };
725
+ let error = null;
724
726
 
725
727
  for (const key in dataBinds) {
726
- set(
727
- resolvedData,
728
- key,
729
- dataBinds[key].call(
730
- codeContext.instance,
731
- codeContext.instance,
732
- lists,
733
- forItems,
734
- codeContext.event,
735
- dataContext,
736
- $w,
737
- paramsContext,
738
- ),
739
- );
728
+ try {
729
+ set(
730
+ resolvedData,
731
+ key,
732
+ dataBinds[key].call(
733
+ codeContext.instance,
734
+ codeContext.instance,
735
+ lists,
736
+ forItems,
737
+ codeContext.event,
738
+ dataContext,
739
+ $w,
740
+ paramsContext,
741
+ ),
742
+ );
743
+ } catch(e) {
744
+ if(combainErrors) {
745
+ error = e
746
+ } else {
747
+ throw e
748
+ }
749
+ }
750
+ }
751
+ if(error) {
752
+ throw error
740
753
  }
741
754
 
742
755
  return resolvedData;
@@ -4,7 +4,7 @@ import { createWidgets, getWidget, disposeWidget } from './widget'
4
4
  import mergeRenderer from './merge-renderer'
5
5
  import { runWatchers } from './watch'
6
6
  import lodashGet from 'lodash.get';
7
- import { createInitData } from './widget';
7
+ import { createInitData, createWidget } from './widget';
8
8
  import { commonCompBehavior } from '@cloudbase/weda-client';
9
9
  import { $w as baseAPI } from '../app/weapps-api'
10
10
 
@@ -13,7 +13,7 @@ import { $w as baseAPI } from '../app/weapps-api'
13
13
  */
14
14
  export const compLowcodes = {}
15
15
 
16
- export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, libCode) {
16
+ export function createComponent(key, behaviors, properties={}, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, libCode) {
17
17
  widgetProps = patchWdigetPropsWithEvtListeners(widgetProps, evtListeners)
18
18
 
19
19
  compLowcodes[key] = {
@@ -53,6 +53,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
53
53
  created() {
54
54
  this._pageActive = true
55
55
  this._disposers = []
56
+ this._nativeObserver = false
56
57
  },
57
58
  attached() {
58
59
  const $comp = this._getInstance()
@@ -60,7 +61,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
60
61
  $comp.__internal__.active = this._pageActive
61
62
 
62
63
  $comp.props.events = createPropEvents(events, this)
63
- const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, this, $comp.widgets)
64
+ const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, this, $comp.widgets)
64
65
  $comp.widgets = widgets
65
66
  this._virtualRootWidget = virtualRootWidget
66
67
 
@@ -98,7 +99,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
98
99
  $comp.__internal__.active = this._pageActive
99
100
 
100
101
  $comp.widgets = null
101
- $comp.node._eventListeners.clear();
102
+ $comp.node._eventListeners?.clear?.();
102
103
  disposeWidget(this._virtualRootWidget)
103
104
  this._disposers.forEach(dispose => dispose())
104
105
  lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
@@ -130,19 +131,34 @@ export function createComponent(key, behaviors, properties, events, handler, dat
130
131
  ...createEventHandlers(evtListeners, { looseError: true, isComposite: true }),
131
132
  ...mergeRenderer,
132
133
  _getInstance() {
133
- if(!this.$WEAPPS_COMP){
134
- const widget = this.$node
134
+ if (!this.$WEAPPS_COMP) {
135
+ let widget = this.$node
135
136
  if (!widget) {
136
- console.error('Fatal error: weapps component instance not created', this.is, this.id)
137
- }else {
138
- widget.getDom = (fields) => this._virtualRootWidget.children[0].getDom(fields)
139
- this.$WEAPPS_COMP = create$comp(widget)
137
+ if(this.selectOwnerComponent && !this.selectOwnerComponent?.()) {
138
+ const widgetValue = {}
139
+ for (const key in properties) {
140
+ if (properties[key]?.value !== undefined) {
141
+ widgetValue[key] = properties[key]?.value
142
+ }
143
+ if (this.data[key] !== undefined) {
144
+ widgetValue[key] = this.data[key]
145
+ }
146
+ }
147
+ this.$node = createWidget({ widgetType: key, ...widgetValue }, this.id || `id${Date.now()}`, '', undefined, {})
148
+ widget = this.$node
149
+ this._nativeObserver = true;
150
+ } else {
151
+ console.error('Fatal error: weapps component instance not created', this.is, this.id);
152
+ return
153
+ }
140
154
  }
155
+ widget.getDom = (fields) => this._virtualRootWidget.children[0].getDom(fields)
156
+ this.$WEAPPS_COMP = create$comp(widget)
141
157
  }
142
158
  return this.$WEAPPS_COMP
143
159
  },
144
160
  },
145
- // observers: createObservers(Object.keys(properties))
161
+ observers: createObservers(Object.keys(properties))
146
162
  })
147
163
  }
148
164
 
@@ -152,7 +168,6 @@ export function create$comp(w) {
152
168
  if (!lowcode) {
153
169
  return
154
170
  }
155
- const libCode = w.widgetType.split(':')[0]
156
171
  const { stateFn, computedFuncs, handler, lib } = lowcode
157
172
 
158
173
  const $comp = {
@@ -161,21 +176,15 @@ export function create$comp(w) {
161
176
  state: {},
162
177
  computed: {},
163
178
  widgets: {},
164
- node: w,
179
+ node: w || {},
165
180
  props: {
166
- data: w,
181
+ data: w || {},
167
182
  events: {},
168
183
  get style() { return w.style },
169
184
  get classList() { return w.classList },
170
185
  },
171
186
  handler: {},
172
- lib,
173
- // i18n: {
174
- // t(key, data) {
175
- // const ns = libCode;
176
- // return sdk.i18n.t(`${ns}:${key}`, data)
177
- // },
178
- // }
187
+ lib
179
188
  }
180
189
  $comp.$WEAPPS_COMP = $comp // TODO $comp will replaced to this.$WEAPPS_COMP
181
190
  $comp.computed = createComputed(computedFuncs, $comp)
@@ -190,7 +199,7 @@ export function create$comp(w) {
190
199
  baseAPI,
191
200
  {
192
201
  get(target, prop) {
193
- if(prop === '$comp'){
202
+ if (prop === '$comp') {
194
203
  return $comp
195
204
  }
196
205
  // 尝试代理组件级别组件实例
@@ -207,13 +216,29 @@ export function create$comp(w) {
207
216
  }
208
217
 
209
218
  function createObservers(props) {
219
+ const MAP = {
220
+ className: {
221
+ alias: 'classList',
222
+ format: function(value='') {
223
+ return Array.from(new Set(value.split(' ').filter(item=>!!item)))
224
+ }
225
+ },
226
+ }
210
227
  return props.reduce((observers, prop) => {
211
- observers[prop] = function (newVal) {
212
- const data = this._getInstance().props.data
213
- if (!deepEqual(data[prop], newVal)) {
214
- data[prop] = newVal
215
- } else {
216
- // console.log('Same comp prop will not trigger observer', prop, newVal)
228
+ observers[prop] = function (value) {
229
+ if (!this._nativeObserver) {
230
+ return;
231
+ }
232
+ const $comp = this._getInstance()
233
+ if ($comp) {
234
+ const data = $comp.props.data || {}
235
+ const dataKey = MAP[prop]?.alias || prop;
236
+ const formatValue = MAP[prop]?.format ? MAP[prop].format(value) : value;
237
+ // if (!deepEqual(data[prop], formatValue)) {
238
+ data[dataKey] = formatValue
239
+ // } else {
240
+ // // console.log(`Same comp prop will not trigger observer. ${prop}->${dataKey}`, formatValue)
241
+ // }
217
242
  }
218
243
  }
219
244
  return observers
@@ -256,7 +281,7 @@ function createPropEvents(events, mpInst) {
256
281
  mpInst.setData({ value: evt.getValueFromEvent({ detail: evtDetail }) })
257
282
  }
258
283
  mpInst.triggerEvent(evt.name, evtDetail)
259
- mpInst._getInstance().node._eventListeners.emit(evt.name, evtDetail)
284
+ mpInst._getInstance().node?._eventListeners?.emit?.(evt.name, evtDetail)
260
285
  }
261
286
  }
262
287
  })
@@ -377,7 +377,7 @@ function runFor(curForNode, dataBinds, ownerMpInst, forContext, ownerForWidgetHo
377
377
  return dispose;
378
378
  }
379
379
 
380
- function createWidget(props, nodeId, indexPostfix, parent, ownerMpInst, forContext) {
380
+ export function createWidget(props, nodeId, indexPostfix, parent, ownerMpInst, forContext) {
381
381
  const { widgetType, _parentId, ...restProps } = props;
382
382
  const w = observable(restProps);
383
383
  const id = `${nodeId}${indexPostfix}`;