@cloudbase/framework-plugin-low-code 0.6.59-alpha.0 → 0.6.61

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/README.md CHANGED
@@ -102,3 +102,24 @@ cloudbase framework:deploy
102
102
  - 云开发官网地址: [https://cloudbase.net/](https://cloudbase.net/)
103
103
  - 云开发静态网站开通指南:[https://docs.cloudbase.net/hosting/](https://docs.cloudbase.net/hosting/)
104
104
  - 云开发控制台地址: [https://console.cloud.tencent.com/tcb](https://console.cloud.tencent.com/tcb)
105
+
106
+ ## 本地测试
107
+
108
+ 1. 需要先 link framework。简单可以 clone http://git.code.oa.com/QBase/cloudbase-framework-plugin-low-code.git,切换 release/cals_v2 分支,执行命令,完成 framework-core 的 link;
109
+
110
+ ```bash
111
+ yarn
112
+ yarn run bootstrap
113
+ yarn run build
114
+ yarn run link
115
+
116
+ ```
117
+
118
+ 1. link low-code-plugin。在本目录执行命令,完成 framework 的 link
119
+ ```
120
+ yarn
121
+ yarn run build
122
+ yarn run link
123
+ ```
124
+ 1. 本地开发 通过 `yarn run dev` 监听文件变化并 ts 编译。
125
+ 1. `__test__/sample` 目录中有测试项目,通过添加 `.env` 文件可指定 mpAppId /ENV_ID 以及 SECRET 等环境变量。`input.json` 为低码配置,`yarn run dev` 进行文件生成及发布。
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/builder/core/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAkBnD,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,kBAAkB,EAC3B,cAAc,kCAA2B,EACzC,YAAY,6BAAsB,EAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,SAAS,EAAE,EAC1B,UAAU,EAAE,WAAW,EACvB,OAAO,qBAAwB,EAC/B,aAAa,qBAAiB,EAC9B,SAAS;iBACM,OAAO;eACT,GAAG;aAIf,EACD,MAAM,EAAE,MAAM,iBAsGf;AACD,wBAAsB,mBAAmB,CACvC,YAAY,oBAAa,EACzB,WAAW,EAAE,MAAM,EACnB,MAAM,KAAA,iBASP"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/builder/core/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAkBnD,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,kBAAkB,EAC3B,cAAc,kCAA2B,EACzC,YAAY,6BAAsB,EAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,SAAS,EAAE,EAC1B,UAAU,EAAE,WAAW,EACvB,OAAO,qBAAwB,EAC/B,aAAa,qBAAiB,EAC9B,SAAS;iBACM,OAAO;eACT,GAAG;aAIf,EACD,MAAM,EAAE,MAAM,iBAyGf;AACD,wBAAsB,mBAAmB,CACvC,YAAY,oBAAa,EACzB,WAAW,EAAE,MAAM,EACnB,MAAM,KAAA,iBASP"}
@@ -67,6 +67,8 @@ function runGenerateCore(appBuildDir, appData, subAppDataList = [], dependencies
67
67
  domain: domain,
68
68
  appConfig: util_1.JsonToStringWithVariableName({
69
69
  id: appKey,
70
+ staticResourceDomain: domain || '',
71
+ envVersion: deployMode === types_1.DEPLOY_MODE.UPLOAD ? 'production' : 'preview',
70
72
  pages: pageInstanceList
71
73
  .sort((item) => (item.isHome ? -1 : 1))
72
74
  .map((item) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,aAAa,EACb,UAAU,EAEV,OAAO,EAIR,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAkB/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAEL,SAAS,EACT,YAAY,EACZ,UAAU,EACX,MAAM,iBAAiB,CAAC;AAUzB,wBAAsB,YAAY,CAAC,EACjC,MAAM,EACN,OAAO,EACP,KAAK,EACL,MAAM,EACN,SAAS,EACT,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,OAAO,EACP,aAAa,GACd,EAAE;IACD,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE;QACP,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B,GAAG,OAAO,CAAC;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC,CAuSvC;AA4KD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,aAAa,iBAgCnB;AAYD,wBAAgB,oBAAoB,CAAC,EACnC,YAAY,EACZ,MAAM,EACN,SAAS,GACV,EAAE;IACD,YAAY,EAA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wBAAgB,oBAAoB,CAAC,EACnC,YAAY,EACZ,MAAM,EACN,SAAS,GACV,EAAE;IACD,YAAY,EAAE,aAAa,CAAC;IAC5B,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,SAAS,EAAE,aAAa,EAAE,CAAC;CAC5B;;;EA0CA"}
@@ -328,6 +328,8 @@ function generateFramework(appData, outDir, ctx) {
328
328
  isBare: false,
329
329
  appConfig: util_3.JsonToStringWithVariableName({
330
330
  id: ctx.appId,
331
+ staticResourceDomain: ctx.domain || '',
332
+ envVersion: (ctx === null || ctx === void 0 ? void 0 : ctx.isProduction) ? 'production' : 'preview',
331
333
  pages: appData.pageInstanceList
332
334
  .sort((item) => (item.isHome ? -1 : 1))
333
335
  .map((item) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.6.59-alpha.0",
3
+ "version": "0.6.61",
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",
@@ -87,4 +87,4 @@
87
87
  "jest": "^26.0.1",
88
88
  "typescript": "^3.8.3"
89
89
  }
90
- }
90
+ }
@@ -459,20 +459,10 @@
459
459
  src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js?v=1"
460
460
  crossorigin="anonymous"
461
461
  ></script>
462
- <script>
463
- (function () {
464
- const _isPrivate = window._isPrivate || false;
465
- if (_isPrivate === true) {
466
- document.write(
467
- `<script crossorigin="anonymous" src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.8-alpha.7/dist/h5.browser.js?v=1"><\/script>`
468
- );
469
- } else {
470
- document.write(
471
- `<script crossorigin="anonymous" src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.5/dist/h5.browser.js?v=1"><\/script>`
472
- );
473
- }
474
- })();
475
- </script>
462
+ <script
463
+ crossorigin="anonymous"
464
+ src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.5/dist/h5.browser.js?v=1"
465
+ ></script>
476
466
  <script>
477
467
  // zxing polifill
478
468
  if (!this.globalThis) {
@@ -51,7 +51,7 @@ export function createEventHandlers(evtListeners, context) {
51
51
  detail: res
52
52
  })
53
53
  } catch (e) {
54
- let eventName = l.key ? `${l.key}_fail` : ''
54
+ let eventName = l.key ? `${prefix}$${l.key}_fail` : ''
55
55
  if(self[eventName]){
56
56
  await self[eventName]({
57
57
  ...event,
@@ -1,10 +1,5 @@
1
1
  import * as React from 'react';
2
- import {
3
- useContext,
4
- useCallback,
5
- createContext,
6
- useRef
7
- } from 'react';
2
+ import { useContext, useCallback, createContext, useRef } from 'react';
8
3
  import { observer } from 'mobx-react-lite';
9
4
  import { emitEvent } from '../actionHandler/utils';
10
5
  import { translateStyleToRem } from '@tcwd/weapps-core';
@@ -12,15 +7,40 @@ import { get, set } from 'lodash';
12
7
  import { $page } from '../../app/global-api';
13
8
  import { getDom } from '../utils/widgets';
14
9
  import { checkVisible } from '../../utils/index';
10
+ import { generateSlotMetaMap } from '../render';
15
11
 
16
12
  export const ForContext = createContext({});
17
13
 
14
+ function generateSlotMap(slots, forContext = undefined) {
15
+ let map = {};
16
+ Object.keys(slots).forEach((slotProp) => {
17
+ let meta = slots[slotProp];
18
+ if (meta.type === 'HOC') {
19
+ set(map, slotProp, meta.node);
20
+ } else {
21
+ const Element = meta.node;
22
+ if (forContext) {
23
+ set(
24
+ map,
25
+ slotProp,
26
+ <ForContext.Provider value={forContext}>
27
+ <Element />
28
+ </ForContext.Provider>
29
+ );
30
+ } else {
31
+ set(map, slotProp, <Element />);
32
+ }
33
+ }
34
+ });
35
+ return map;
36
+ }
37
+
18
38
  export const CompRenderer = observer(function (props) {
19
39
  const {
20
40
  id: compId,
21
41
  xProps,
22
42
  virtualFields,
23
- slots = {},
43
+ renderSlot,
24
44
  codeContext,
25
45
  scopeContext,
26
46
  context = {},
@@ -56,6 +76,13 @@ export const CompRenderer = observer(function (props) {
56
76
  const Field = virtualFields[sourceKey];
57
77
  const parentForItems = useContext(ForContext);
58
78
 
79
+ const _context = {
80
+ scopeContext,
81
+ forContext: parentForItems,
82
+ codeContext,
83
+ dataContext: context,
84
+ };
85
+
59
86
  // 组件最终用于执行的事件函数
60
87
  const emit = useCallback(
61
88
  (trigger, eventDetail, forItems, scopeContext) => {
@@ -187,10 +214,22 @@ export const CompRenderer = observer(function (props) {
187
214
  if (!checkVisible(forItemData)) {
188
215
  return null;
189
216
  }
190
- // 多个组件的 slot 属性
191
- Object.keys(slots).forEach((slotProp) => {
192
- set(forItemData, slotProp, slots[slotProp]);
193
- });
217
+
218
+ const slotMap = generateSlotMap(
219
+ generateSlotMetaMap(
220
+ componentSchema,
221
+ {
222
+ ..._context,
223
+ forContext: forItems,
224
+ virtualFields,
225
+ updateContext,
226
+ },
227
+ {
228
+ renderSlot,
229
+ }
230
+ )
231
+ );
232
+
194
233
  const emitWithForItems = (trigger, evt) =>
195
234
  emit(trigger, evt, forItems, scopeContext);
196
235
 
@@ -230,6 +269,7 @@ export const CompRenderer = observer(function (props) {
230
269
  <Field
231
270
  data={{
232
271
  ...forItemData,
272
+ ...slotMap,
233
273
  _selectableBlockEvents: _selectableBlockEventsForItems,
234
274
  }}
235
275
  id={compId}
@@ -270,9 +310,19 @@ export const CompRenderer = observer(function (props) {
270
310
  }
271
311
 
272
312
  // 单个组件的 slot 属性
273
- Object.keys(slots).forEach((slotProp) => {
274
- set(fieldData, slotProp, slots[slotProp]);
275
- });
313
+ const slotMap = generateSlotMap(
314
+ generateSlotMetaMap(
315
+ componentSchema,
316
+ {
317
+ ..._context,
318
+ virtualFields,
319
+ updateContext,
320
+ },
321
+ {
322
+ renderSlot,
323
+ }
324
+ )
325
+ );
276
326
 
277
327
  // 防止渲染时 data 的 style 与实际的 style 冲突
278
328
  delete fieldData.style;
@@ -304,6 +354,7 @@ export const CompRenderer = observer(function (props) {
304
354
  <Field
305
355
  data={{
306
356
  ...fieldData,
357
+ ...slotMap,
307
358
  _selectableBlockEvents: _selectableBlockEventsWithItem,
308
359
  }}
309
360
  id={compId}
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useRef } from 'react';
3
3
  import * as _ from 'lodash';
4
- import { CompRenderer } from './FieldMiddleware/renderer';
4
+ import { CompRenderer, ForContext } from './FieldMiddleware/renderer';
5
5
  import { isScopeSlot } from '../utils/index';
6
6
 
7
7
  function getComponentChildren(component) {
@@ -14,6 +14,68 @@ function getComponentChildren(component) {
14
14
  );
15
15
  }
16
16
 
17
+ export function generateSlotMetaMap(componentSchema, context, options = {}) {
18
+ const slots = {};
19
+ const { properties = {} } = componentSchema;
20
+ const {
21
+ scopeContext,
22
+ codeContext,
23
+ virtualFields,
24
+ dataContext,
25
+ updateContext,
26
+ forContext,
27
+ } = context;
28
+ // eslint-disable-next-line guard-for-in
29
+ for (const key in properties) {
30
+ const child = properties[key];
31
+ if (!child['x-props'] && child.properties) {
32
+ const isHOC = isScopeSlot(componentSchema, key);
33
+
34
+ slots[key] = {
35
+ type: isHOC ? 'HOC' : 'ELEMENT',
36
+ node: isHOC
37
+ ? (props) => {
38
+ let clonedScopeContext = _.cloneDeep(scopeContext);
39
+ _.set(
40
+ clonedScopeContext,
41
+ `${componentSchema.key}.${child.key}`,
42
+ props
43
+ );
44
+ return (
45
+ <AppRender
46
+ key={child.key}
47
+ componentSchema={child}
48
+ renderSlot={options?.renderSlot}
49
+ virtualFields={virtualFields}
50
+ codeContext={codeContext}
51
+ scopeContext={clonedScopeContext}
52
+ context={dataContext}
53
+ updateContext={updateContext}
54
+ />
55
+ );
56
+ }
57
+ : () => {
58
+ return (
59
+ <ForContext.Provider value={forContext}>
60
+ <AppRender
61
+ key={child.key}
62
+ componentSchema={child}
63
+ renderSlot={options?.renderSlot}
64
+ virtualFields={virtualFields}
65
+ codeContext={codeContext}
66
+ scopeContext={scopeContext}
67
+ context={dataContext}
68
+ updateContext={updateContext}
69
+ />
70
+ </ForContext.Provider>
71
+ );
72
+ },
73
+ };
74
+ }
75
+ }
76
+ return slots;
77
+ }
78
+
17
79
  export function AppRender(props) {
18
80
  const {
19
81
  className,
@@ -70,46 +132,6 @@ export function AppRender(props) {
70
132
  }
71
133
 
72
134
  const children = getComponentChildren(componentSchema);
73
- const slots = {};
74
- // eslint-disable-next-line guard-for-in
75
- for (const key in properties) {
76
- const child = properties[key];
77
- if (!child['x-props'] && child.properties) {
78
- slots[key] = isScopeSlot(componentSchema, key) ? (
79
- (props) => {
80
- let clonedScopeContext = _.cloneDeep(scopeContext);
81
- _.set(
82
- clonedScopeContext,
83
- `${componentSchema.key}.${child.key}`,
84
- props
85
- );
86
- return (
87
- <AppRender
88
- key={child.key}
89
- componentSchema={child}
90
- renderSlot
91
- virtualFields={virtualFields}
92
- codeContext={codeContext}
93
- scopeContext={clonedScopeContext}
94
- context={context}
95
- updateContext={updateContext}
96
- />
97
- );
98
- }
99
- ) : (
100
- <AppRender
101
- key={child.key}
102
- componentSchema={child}
103
- renderSlot
104
- virtualFields={virtualFields}
105
- codeContext={codeContext}
106
- scopeContext={scopeContext}
107
- context={context}
108
- updateContext={updateContext}
109
- />
110
- );
111
- }
112
- }
113
135
 
114
136
  return (
115
137
  <CompRenderer
@@ -118,7 +140,7 @@ export function AppRender(props) {
118
140
  emitEvents={componentSchema.emitEvents || []}
119
141
  componentSchema={componentSchema}
120
142
  virtualFields={virtualFields}
121
- slots={slots}
143
+ renderSlot={renderSlot}
122
144
  codeContext={codeContext}
123
145
  scopeContext={scopeContext}
124
146
  context={context}