@cloudbase/framework-plugin-low-code 0.7.24 → 1.0.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.
Files changed (47) hide show
  1. package/lib/generate.d.ts +1 -2
  2. package/lib/generate.d.ts.map +1 -1
  3. package/lib/generate.js +4 -5
  4. package/lib/index.d.ts +4 -7
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +78 -125
  7. package/lib/utils/dataSource.d.ts +0 -4
  8. package/lib/utils/dataSource.d.ts.map +1 -1
  9. package/lib/utils/dataSource.js +12 -27
  10. package/lib/utils/postProcess.d.ts.map +1 -1
  11. package/package.json +4 -3
  12. package/template/html/index.html.ejs +1 -1
  13. package/template/mp/app/app-global.js +0 -4
  14. package/template/mp/app/common.js +0 -26
  15. package/template/mp/app/handlers.js +0 -15
  16. package/template/mp/app/weapps-api.js +0 -89
  17. package/template/mp/app.js +0 -114
  18. package/template/mp/app.json +0 -1
  19. package/template/mp/app.wxss +0 -15
  20. package/template/mp/common/data-patch-test.js +0 -60
  21. package/template/mp/common/data-patch.js +0 -44
  22. package/template/mp/common/merge-renderer.js +0 -67
  23. package/template/mp/common/process.js +0 -1
  24. package/template/mp/common/style.js +0 -34
  25. package/template/mp/common/url.js +0 -21
  26. package/template/mp/common/util.js +0 -395
  27. package/template/mp/common/utils.wxs +0 -11
  28. package/template/mp/common/weapp-component.js +0 -250
  29. package/template/mp/common/weapp-page.js +0 -204
  30. package/template/mp/common/weapp-sdk.js +0 -76
  31. package/template/mp/common/widget.js +0 -381
  32. package/template/mp/common/wx_yypt_report_v2.js +0 -460
  33. package/template/mp/component/index.js +0 -66
  34. package/template/mp/component/index.json +0 -4
  35. package/template/mp/component/index.wxml +0 -1
  36. package/template/mp/component/index.wxss +0 -1
  37. package/template/mp/datasources/config.js.tpl +0 -25
  38. package/template/mp/datasources/dataset-profiles.js.tpl +0 -5
  39. package/template/mp/datasources/datasource-profiles.js.tpl +0 -4
  40. package/template/mp/datasources/index.js +0 -31
  41. package/template/mp/package.json +0 -17
  42. package/template/mp/page/api.js +0 -1
  43. package/template/mp/page/index.js +0 -42
  44. package/template/mp/page/index.json +0 -3
  45. package/template/mp/page/index.wxml +0 -1
  46. package/template/mp/page/index.wxss +0 -3
  47. package/template/mp/project.config.json +0 -1
@@ -3,29 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getDatasetProfiles = exports.getDataVarProfiles = exports.getDatasourceProfiles = exports.standardizeDataSource = exports.lowercaseKey = exports.mergeDependencies = exports.getDatasourceDatabaseName = exports.getAppDatasourceResourceName = exports.getDatasourceResourceName = exports.DATABASE_TYPE = exports.EXTERNAL_FUNCTION_TYPE = exports.CLOUD_FUNCTION_TYPE = void 0;
6
+ exports.getDatasetProfiles = exports.getDatasourceProfiles = exports.standardizeDataSource = exports.lowercaseKey = exports.mergeDependencies = exports.getDatasourceDatabaseName = exports.getAppDatasourceResourceName = exports.getDatasourceResourceName = exports.DATABASE_TYPE = exports.EXTERNAL_FUNCTION_TYPE = exports.CLOUD_FUNCTION_TYPE = void 0;
7
7
  const merge_package_json_1 = __importDefault(require("merge-package-json"));
8
- const types_1 = require("../types");
9
- const expression_1 = require("@cloudbase/cals/lib/parser/expression");
10
- const util_1 = require("../builder/mp/util");
11
- const config_1 = require("../builder/config");
8
+ const lowcode_builder_1 = require("@cloudbase/lowcode-builder");
9
+ const cals_1 = require("@cloudbase/cals");
10
+ const util_1 = require("@cloudbase/lowcode-builder/lib/builder/mp/util");
11
+ const index_1 = require("@cloudbase/lowcode-builder/lib/builder/config/index");
12
12
  exports.CLOUD_FUNCTION_TYPE = 'cloud-function';
13
13
  exports.EXTERNAL_FUNCTION_TYPE = 'http';
14
14
  exports.DATABASE_TYPE = 'database';
15
15
  function getDatasourceResourceName(datasrouce, mode) {
16
- let suffix = mode === types_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
16
+ let suffix = mode === lowcode_builder_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
17
17
  return `lcap-${datasrouce.id}-${datasrouce.name}${suffix}`;
18
18
  }
19
19
  exports.getDatasourceResourceName = getDatasourceResourceName;
20
20
  function getAppDatasourceResourceName(appId, datasrouce, mode) {
21
- let suffix = mode === types_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
21
+ let suffix = mode === lowcode_builder_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
22
22
  return `lcap-${datasrouce.id}-${datasrouce.name}-${appId}${suffix}`;
23
23
  }
24
24
  exports.getAppDatasourceResourceName = getAppDatasourceResourceName;
25
25
  function getDatasourceDatabaseName(dsConfig, mode) {
26
- return dsConfig.type === exports.DATABASE_TYPE
27
- ? getDatasourceResourceName(dsConfig, mode)
28
- : null;
26
+ return dsConfig.type === exports.DATABASE_TYPE ? getDatasourceResourceName(dsConfig, mode) : null;
29
27
  }
30
28
  exports.getDatasourceDatabaseName = getDatasourceDatabaseName;
31
29
  function mergeDependencies(...pkgs) {
@@ -35,9 +33,7 @@ function mergeDependencies(...pkgs) {
35
33
  const formated = getDependencies(pkg);
36
34
  for (let key in formated.dependencies) {
37
35
  formated.dependencies[key] =
38
- formated.dependencies[key] === '*' && ((_a = acc === null || acc === void 0 ? void 0 : acc.dependencies) === null || _a === void 0 ? void 0 : _a[key]) === '*'
39
- ? 'latest'
40
- : formated.dependencies[key];
36
+ formated.dependencies[key] === '*' && ((_a = acc === null || acc === void 0 ? void 0 : acc.dependencies) === null || _a === void 0 ? void 0 : _a[key]) === '*' ? 'latest' : formated.dependencies[key];
41
37
  }
42
38
  const merged = (0, merge_package_json_1.default)(formated, acc);
43
39
  return JSON.parse(merged);
@@ -113,17 +109,6 @@ function getDatasourceProfiles(datasources) {
113
109
  })) || []);
114
110
  }
115
111
  exports.getDatasourceProfiles = getDatasourceProfiles;
116
- function getDataVarProfiles(appData) {
117
- const result = {
118
- $global: (appData.vars && appData.vars.data) || [],
119
- };
120
- appData.pageInstanceList.forEach((pageInstance) => {
121
- let p = pageInstance;
122
- result[p.id] = (p.vars && p.vars.data) || [];
123
- });
124
- return result;
125
- }
126
- exports.getDataVarProfiles = getDataVarProfiles;
127
112
  function _generateDynamicDataset(dataset) {
128
113
  var _a;
129
114
  let { state } = dataset;
@@ -136,13 +121,13 @@ function _generateDynamicDataset(dataset) {
136
121
  let processed = {};
137
122
  for (let paramKey in params) {
138
123
  let bind = params[paramKey];
139
- if (!bind.type || bind.type === expression_1.PropBindType.static) {
124
+ if (!bind.type || bind.type === cals_1.PropBindType.static) {
140
125
  let value = bind.value;
141
- processed[paramKey] = `${config_1.REPLACE_SIGN}(app, $page) => (${typeof value === 'string' ? `'${value}'` : JSON.stringify(value)})${config_1.REPLACE_SIGN}`;
126
+ processed[paramKey] = `${index_1.REPLACE_SIGN}(app, $page) => (${typeof value === 'string' ? `'${value}'` : JSON.stringify(value)})${index_1.REPLACE_SIGN}`;
142
127
  }
143
128
  else {
144
129
  let jsExp = (0, util_1.generateDataBind)(bind);
145
- processed[paramKey] = `${config_1.REPLACE_SIGN}(app, $page) => (\n${jsExp || 'undefined'}\n)${config_1.REPLACE_SIGN}`;
130
+ processed[paramKey] = `${index_1.REPLACE_SIGN}(app, $page) => (\n${jsExp || 'undefined'}\n)${index_1.REPLACE_SIGN}`;
146
131
  }
147
132
  }
148
133
  config.initMethod.params = processed;
@@ -1 +1 @@
1
- {"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/utils/postProcess.ts"],"names":[],"mappings":"AAKA,wBAAgB,wBAAwB,CAAC,eAAe,KAAA,EAAE,IAAI,KAAA,QAI7D;AAED,wBAAgB,0BAA0B,CAAC,WAAW,KAAA,EAAE,aAAa,KAAA,QAkBpE"}
1
+ {"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/utils/postProcess.ts"],"names":[],"mappings":"AAIA,wBAAgB,wBAAwB,CAAC,eAAe,KAAA,EAAE,IAAI,KAAA,QAI7D;AAED,wBAAgB,0BAA0B,CAAC,WAAW,KAAA,EAAE,aAAa,KAAA,QAkBpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.7.24",
3
+ "version": "1.0.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",
@@ -35,11 +35,12 @@
35
35
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@cloudbase/cals": "0.3.17",
38
+ "@cloudbase/cals": "^0.3.31",
39
39
  "@cloudbase/framework-core": "^1.8.16",
40
40
  "@cloudbase/framework-plugin-auth": "^1.8.16",
41
41
  "@cloudbase/framework-plugin-mp": "v1.3.6-beta.8",
42
42
  "@cloudbase/framework-plugin-website": "^1.8.17",
43
+ "@cloudbase/lowcode-builder": "^1.0.1",
43
44
  "@formily/react-schema-renderer": "1.1.7",
44
45
  "archiver": "^4.0.1",
45
46
  "axios": "^0.21.0",
@@ -87,4 +88,4 @@
87
88
  "jest": "^26.0.1",
88
89
  "typescript": "^3.8.3"
89
90
  }
90
- }
91
+ }
@@ -450,7 +450,7 @@
450
450
  ></script>
451
451
  <script
452
452
  crossorigin="anonymous"
453
- src="https://qbase.cdn-go.cn//lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-client@0.2.13/dist/web.browser.js"
453
+ src="https://qbase.cdn-go.cn//lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-client@0.2.15/dist/web.browser.js"
454
454
  ></script>
455
455
  </body>
456
456
  </html>
@@ -1,4 +0,0 @@
1
- // 空对象,用于存储全局数据
2
- export default {
3
-
4
- }
@@ -1,26 +0,0 @@
1
- <% mods.forEach((mod) => {%>
2
- import * as <%= mod %> from '../lowcode/common/<%= mod %>'<%}) %>
3
-
4
- const _weapps_app_common = {}
5
-
6
- function getDefaultModule(targetModule) {
7
- if (!targetModule) {
8
- return
9
- }
10
- const keys = Object.keys(targetModule)
11
- if (keys.length === 1 && keys[0] === 'default') {
12
- return targetModule.default
13
- }
14
- return targetModule
15
- }
16
-
17
- Object.defineProperties(_weapps_app_common, {
18
- <% mods.forEach((mod) => {%>
19
- <%= mod %>: {
20
- get() {
21
- return getDefaultModule(<%= mod %>)
22
- }
23
- },<%}) %>
24
- })
25
-
26
- export default _weapps_app_common
@@ -1,15 +0,0 @@
1
- <% pageModules.forEach(({id: pageId, lowCodes}) => { %>
2
- <% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
3
- import <%= pageId%>_<%= mod.name%> from '../lowcode/<%= pageId%>/handler/<%= mod.name%>'
4
- <% }) %>
5
- <% }) %>
6
-
7
-
8
-
9
- <% pageModules.forEach(({id: pageId, lowCodes}) => { %>
10
- export const <%=pageId %> = {
11
- <% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
12
- ['<%= mod.name%>']: <%= pageId%>_<%= mod.name%>,
13
- <% }) %>
14
- }
15
- <% }) %>
@@ -1,89 +0,0 @@
1
- import { observable } from 'mobx'
2
- import { createMpApp } from '@cloudbase/weda-client';
3
- import { createComputed, formatEnum, enumOptions} from '<%= subLevelPath %>../common/util'
4
- import process from '<%= subLevelPath %>../common/process'
5
- import appGlobal from '<%= subLevelPath %>../app/app-global'
6
- import { CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
7
-
8
-
9
- <% if (!isBare) {%>
10
- import state from '../lowcode/state'
11
- import computed from '../lowcode/computed'
12
- import common from './common'
13
- <%} else {%>
14
- const state = {}
15
- const computed ={}
16
- const common = {}
17
- <%}%>
18
-
19
- const mainAppKey = '__weappsMainApp'
20
-
21
- export const app = createGlboalApi()
22
- export { process }
23
-
24
- function createGlboalApi() {
25
- const mpApp = createMpApp({
26
- appConfig: <%= appConfig %>
27
- })
28
- const globalAPI = {
29
- id: '<%= appId %>',
30
- domain: '<%= domain %>',
31
- platform: 'MINIPROGRAME',
32
- pages: {},
33
- session: {
34
- //configure: sdk.configure,
35
- //request: sdk.request,
36
- //getSessionId: sdk.getSessionId,
37
- },
38
- state: observable(state),
39
- computed: createComputed(computed),
40
- common,
41
- invoke(params) {
42
- return app.__internal__.activePage.invokeComponentMethod(params)
43
- },
44
- ...mpApp,
45
- } // The global api exposed to lowcode
46
-
47
-
48
- globalAPI.__internal__.enumOptions = enumOptions
49
- globalAPI.utils.formatEnum = formatEnum
50
- /**
51
- * @deprecated utils._getConfig
52
- */
53
- globalAPI.utils._getConfig = () => {
54
- return globalAPI.__internal__.getConfig()
55
- }
56
- globalAPI.utils.getWXContext = async function() {
57
- const { Data } = await globalAPI.cloud.callWedaApi({
58
- action: 'InvokeComponentWxModule',
59
- data: {
60
- Method: 'GetWxContext',
61
- },
62
- });
63
- return typeof Data === 'string' ? JSON.parse(Data) : Data
64
- }
65
-
66
- let dataset = createDataset('$global')
67
- globalAPI.dataset = dataset
68
- globalAPI.state.dataset = dataset
69
- globalAPI.setState = (userSetState) => {
70
- Object.keys(userSetState).forEach((keyPath) => {
71
- globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
72
- });
73
- };
74
-
75
- const subPackageName = '<%= subPackageName %>'
76
- if (subPackageName) {
77
- // is sub app
78
- globalAPI.mainApp = appGlobal[mainAppKey]
79
- const mpApp = getApp()
80
- mpApp && (mpApp.subApp = globalAPI)
81
- } else {
82
- // is mainApp
83
- appGlobal[mainAppKey] = globalAPI
84
- }
85
- // 避免被wx.cloud 覆盖
86
- globalAPI.cloud = CLOUD_SDK
87
-
88
- return globalAPI
89
- }
@@ -1,114 +0,0 @@
1
- import lifeCycle from './lowcode/lifecycle'
2
- import { app } from './app/weapps-api'
3
- // 引入数据源管理器并进行初始化
4
- import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index';
5
- import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
6
-
7
- // 设置数据源请求的 loading 及 toast 处理
8
- setConfig({
9
- beforeDSRequest: (cfg) => {
10
- if (!cfg.options || !cfg.options.showLoading) return
11
- app.showLoading()
12
- },
13
- beforeCallFunction: async (params) => {
14
- try {
15
- const loginPage = findLoginPage();
16
-
17
- let skip = false;
18
- switch (params?.data?.methodName) {
19
- case 'callWedaApi': {
20
- if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
21
- skip = true;
22
- }
23
- break;
24
- }
25
- }
26
-
27
- // 后续做过滤处理
28
- if (!loginPage || (params?.data?.mode === 'c' && skip)) {
29
- return params;
30
- }
31
- // await initTcb();
32
- const { accessToken } = await getAccessToken();
33
- if (accessToken) {
34
- params.data.accessToken = accessToken;
35
- }
36
- } catch (e) {
37
- if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
38
- app.showToast({
39
- title: '登录态失效',
40
- icon: 'error',
41
- });
42
- }
43
- console.error('beforeCallFunction error', e);
44
- }
45
- return params;
46
- },
47
- afterDSRequest: (cfg, error, result) => {
48
- if (!cfg.options) return
49
- if (cfg.options.showLoading) app.hideLoading()
50
- if (!cfg.options.showToast) return
51
- const isSuccess = !error && result && !result.code
52
- app.showToast({ icon: isSuccess ? 'success' : 'error' })
53
- },
54
- async afterCallFunction(params, error, res) {
55
- if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
56
- const loginPage = findLoginPage();
57
- if (loginPage) {
58
- const authConfig = await getAuthConfig();
59
- let isAnonymous = true;
60
- try {
61
- const { accessToken } = await getAccessToken();
62
- isAnonymous = !accessToken;
63
- } catch (e) { }
64
- if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
65
- redirectToLogin();
66
- } else if (authConfig.RejectStrategy == 'show_warning') {
67
- app.showToast({
68
- title: '接口无访问权限',
69
- icon: 'error',
70
- });
71
- }
72
- }
73
- }
74
- }
75
- })
76
-
77
- App({
78
- onLaunch(options) {
79
- this.app = app
80
- const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
81
- let { query = {} } = options
82
- EXTRA_API.setParams('$global', query)
83
- createStateDataSourceVar('$global', generateParamsParser({ app }))
84
-
85
- onLaunch && onLaunch.call(this, options)
86
- <% if (yyptConfig.yyptAppKey) { %>
87
- // 挂运营平台上报对象到app里
88
- app.yyptReport = wxReport
89
- <% }%>
90
- },
91
- onShow(options) {
92
- const fn = lifeCycle.onShow || lifeCycle.onAppShow
93
- fn && fn.call(this, options)
94
- <% if (yyptConfig.yyptAppKey) { %>
95
- wxReport.startReport()
96
- <% }%>
97
- },
98
- onHide() {
99
- const fn = lifeCycle.onHide || lifeCycle.onAppHide
100
- fn && fn.call(this)
101
- },
102
- onError(msg) {
103
- const fn = lifeCycle.onError || lifeCycle.onAppError
104
- fn && fn.call(this, msg)
105
- },
106
- onPageNotFound() {
107
- const fn = lifeCycle.onPageNotFound
108
- fn && fn.call(this)
109
- },
110
- onUnhandledRejection() {
111
- const fn = lifeCycle.onUnhandledRejection
112
- fn && fn.call(this)
113
- },
114
- })
@@ -1 +0,0 @@
1
- <%= JSON.stringify(content, ' ', 2) %>
@@ -1,15 +0,0 @@
1
- /** common.wxss **/
2
- page {
3
- /* 修复小程序 Picker 组件滑动体验问题 */
4
- touch-action: pan-y;
5
- }
6
-
7
- page view, page element, page text, page image {
8
- box-sizing: border-box;
9
- }
10
-
11
- /** import styles specified by material libs*/<% importStyles.map(style => {%>
12
- @import '<%= style %>';<%})%>
13
-
14
- /** import lowcode styles */
15
- @import 'lowcode/style.wxss';
@@ -1,60 +0,0 @@
1
- import assert from 'assert'
2
- import { getDatapatch } from './data-patch.js'
3
-
4
- const cases = [
5
- {
6
- desc: 'New component',
7
- base: {},
8
- data: { id1: { a: 1 } },
9
- patch: { id1: { a: 1 } }
10
- }, {
11
- desc: 'Component prop update',
12
- base: { id1: { a: 1, b: 2 } },
13
- data: { id1: { a: 1, b: 3 } },
14
- patch: { 'id1.b': 3 }
15
- }, {
16
- desc: 'More than 1/3 of props changed',
17
- base: { id1: { a: 1, b: 2, c: 3 } },
18
- data: { id1: { a: 1, b: 4, c: 5 } },
19
- patch: { id1: { a: 1, b: 4, c: 5 } }
20
- }, {
21
- desc: 'New multiple components',
22
- base: {},
23
- data: { id1: { a: 1 }, id2: { c: 2 }, id3: [{ c: 1 }] },
24
- patch: { id1: { a: 1 }, id2: { c: 2 }, id3: [{ c: 1 }] }
25
- },
26
- {
27
- desc: 'Update component prop in array',
28
- base: { id1: [{ a: 1 }, { a: 2 }, { a: 8 }] },
29
- data: { id1: [{ a: 1 }, { a: 3 }, { a: 8 }] },
30
- patch: { 'id1[1].a': 3 }
31
- },
32
- {
33
- desc: 'Update component prop in 2d array',
34
- base: { id1: [[{ a: 1 }, { a: 2 }], [{ a: 1 }]] },
35
- data: { id1: [[{ a: 1 }, { a: 3 }], [{ a: 1 }]] },
36
- patch: { 'id1[0][1].a': 3 }
37
- },
38
- {
39
- desc: 'Add component in array',
40
- base: { id1: [{ a: 1 }, { a: 2 }] },
41
- data: { id1: [{ a: 1 }, { a: 2 }, { a: 9 }] },
42
- patch: { 'id1[2]': { a: 9 } }
43
- },
44
- {
45
- desc: 'Add 2 components in array',
46
- base: { id1: [{ a: 1 }, { a: 2 }] },
47
- data: { id1: [{ a: 1 }, { a: 2 }, { a: 9 }, { a: 8 }] },
48
- patch: { 'id1[2]': { a: 9 }, 'id1[3]': { a: 8 } }
49
- },
50
- {
51
- desc: 'array: delete component',
52
- base: { id1: [{ a: 1 }, { a: 2 }, { a: 2 }] },
53
- data: { id1: [{ a: 1 }, { a: 2 }] },
54
- patch: { id1: [{ a: 1 }, { a: 2 }] }
55
- }
56
- ]
57
-
58
- for (const c of cases) {
59
- assert.deepStrictEqual(getDatapatch(c.base, c.data), c.patch, c.desc)
60
- }
@@ -1,44 +0,0 @@
1
-
2
- export function getDatapatch(base, pendingData) {
3
- const patch = {}
4
- for (const widgetId in pendingData) {
5
- const baseWidget = base[widgetId]
6
- const pendingWidget = pendingData[widgetId]
7
- if (!baseWidget) {
8
- patch[widgetId] = pendingWidget
9
- } else {
10
- patchProp(baseWidget, pendingWidget, patch, widgetId)
11
- }
12
- }
13
- return patch
14
- }
15
-
16
- function patchProp(baseWidget, pendingWidget, patch, prefixes) {
17
- if (Array.isArray(pendingWidget)) {
18
- if (pendingWidget.length < baseWidget.length) { // array element deleted
19
- patch[prefixes] = pendingWidget
20
- return
21
- }
22
- for (let i = 0; i < pendingWidget.length; i++) {
23
- if (!baseWidget[i]) { // new array element
24
- patch[prefixes + '[' + i + ']'] = pendingWidget[i]
25
- } else {
26
- patchProp(baseWidget[i], pendingWidget[i], patch, prefixes + '[' + i + ']')
27
- }
28
- }
29
- } else {
30
- if (pendingWidget._waIf === false && baseWidget._waIf === false) {
31
- return
32
- }
33
- const allProps = Object.keys(pendingWidget)
34
- // Attention: since setData will copy data deeply, if property is object, it should be treated as different
35
- const differentProps = allProps.filter(prop => typeof pendingWidget[prop] === 'object' || pendingWidget[prop] !== baseWidget[prop])
36
- if (differentProps.length === 1 || differentProps.length <= allProps.length / 3) {
37
- differentProps.map(patchProp => {
38
- patch[prefixes + '.' + patchProp] = pendingWidget[patchProp]
39
- })
40
- } else {
41
- patch[prefixes] = pendingWidget
42
- }
43
- }
44
- }
@@ -1,67 +0,0 @@
1
- import { autorun } from 'mobx'
2
- import { touchObj, throttle } from './util'
3
- import { resolveWidgetData } from './widget'
4
- import { getDatapatch } from './data-patch'
5
-
6
- export default {
7
- // Attention, must be called at the end of attached or page load to make sure user init take effect
8
- initMergeRenderer(widgets) {
9
- this.flushPendingData = throttle(this.flushPendingData.bind(this), 18)
10
-
11
- const dataFactory = {
12
- // <%= dataPropNames.pageState %>: () => pageState,
13
- // <%= dataPropNames.pageComputed %>: () => pageComputed,
14
- }
15
- for (const id in widgets) {
16
- const props = widgets[id]
17
- dataFactory['<%= dataPropNames.widgetProp %>' + id] = () => resolveWidgetData(props)
18
- }
19
- const disposers = []
20
- for (const k in dataFactory) {
21
- const disposer = autorun(r => {
22
- this.requestRender({ [k]: dataFactory[k]() })
23
- })
24
- disposers.push(disposer)
25
- }
26
- this.flushPendingData() // Prepare data for first paint
27
- return disposers
28
- },
29
-
30
- // setData merging
31
- pendingData: null,
32
- _settingData: false, // flag to prevent multiple setData at the same time
33
- flushPendingData() {
34
- if (!this.pendingData || this._settingData) { return }
35
- const patch = getDatapatch(this.data, this.pendingData)
36
- this.pendingData = null
37
- const label = `setData ${this.is} ${this.id}(${Object.keys(patch).join(',')})`
38
-
39
- if (Object.keys(patch).length < 1) {
40
- return
41
- }
42
- this._settingData = true
43
- const lastUpdateTime = Date.now()
44
- this.setData(patch, () => {<% if(debug) {%>
45
- const elapsedTime = Date.now() - lastUpdateTime;
46
- if(elapsedTime > 16) {
47
- console.warn(label, elapsedTime)
48
- }else {
49
- console.info(label, elapsedTime)
50
- }<%} %>
51
- this._settingData = false;
52
- this.flushPendingData()
53
- })
54
- },
55
- requestRender(data) {
56
- if(!this._pageActive) {
57
- // The callback of wx.chooseLocation occured when page is inactive
58
- console.warn(`Attention, you're updating widgets(${Object.keys(data).join(',')}) of inactive page(${this.is})`)
59
- }
60
- if (!this.pendingData) {
61
- this.pendingData = {}
62
- }
63
- wx.nextTick(this.flushPendingData)
64
- touchObj(data) // Touch all props to monitor data deeply, FIXME
65
- Object.assign(this.pendingData, data)
66
- },
67
- }
@@ -1 +0,0 @@
1
- export default { env: { buildType: 'mp' } }
@@ -1,34 +0,0 @@
1
- import { toDash } from './util'
2
- /**
3
- * Convert HtmlElement.style object to css declarations
4
- */
5
- export function styleToCss(style) {
6
- const styleDeclars = [] // ['color: red;', 'background-color: green']
7
- for (const key in style) {
8
- styleDeclars.push(toDash(key) + ':' + style[key] + ';')
9
- }
10
- return styleDeclars.join('')
11
- }
12
-
13
- export function concatClassList(classList1 = [], classList2 = []) {
14
- if (!Array.isArray(classList1)) {
15
- classList1 = [classList1]
16
- }
17
- if (!Array.isArray(classList2)) {
18
- classList2 = [classList2]
19
- }
20
- return classList1.concat(classList2)
21
- }
22
-
23
- export function px2rpx(object) {
24
- let reg = /\b(\d+(\.\d+)?)px\b/g
25
- for (const key in object) {
26
- let value = object[key]
27
- if (typeof value === 'string') {
28
- object[key] = value.replace(reg, function (item, value) {
29
- return `${value}rpx`
30
- })
31
- }
32
- }
33
- return object
34
- }
@@ -1,21 +0,0 @@
1
- // 处理url链接,加入params参数
2
- export function urlJoinParams(url, params) {
3
- if (!url || !params || typeof params !== 'object') {
4
- return url
5
- }
6
- const separate = url.indexOf('?') === -1 ? '?' : '&'
7
- const tempStr = Object.keys(params)
8
- .map(key => {
9
- let value = params[key]
10
- if (typeof value === 'object') {
11
- value = JSON.stringify(value)
12
- }
13
- if (value != undefined) {
14
- return `${key}=${encodeURIComponent(value)}`
15
- }
16
- return ''
17
- })
18
- .filter(value => value)
19
- .join('&')
20
- return `${url}${separate}${tempStr}`
21
- }