@cloudbase/lowcode-builder 0.1.26 → 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 (84) hide show
  1. package/lib/builder/core/index.d.ts +1 -3
  2. package/lib/builder/core/index.js +42 -52
  3. package/lib/builder/h5/compile.d.ts +1 -1
  4. package/lib/builder/h5/compile.js +59 -20
  5. package/lib/builder/h5/copy.js +2 -4
  6. package/lib/builder/h5/generate.js +3 -3
  7. package/lib/builder/h5/index.d.ts +5 -4
  8. package/lib/builder/h5/index.js +25 -14
  9. package/lib/builder/h5/material.js +6 -11
  10. package/lib/builder/h5/npm.js +6 -5
  11. package/lib/builder/mp/index.js +38 -49
  12. package/lib/builder/mp/materials.js +25 -18
  13. package/lib/builder/mp/mixMode.js +7 -10
  14. package/lib/builder/mp/mp_config.js +2 -3
  15. package/lib/builder/mp/wxml.js +1 -1
  16. package/lib/builder/service/webpack.d.ts +7 -1
  17. package/lib/builder/service/webpack.js +97 -24
  18. package/lib/builder/types/common.d.ts +1 -1
  19. package/lib/builder/types/common.js +2 -1
  20. package/lib/builder/util/common.js +1 -4
  21. package/lib/builder/util/generateFiles.js +12 -10
  22. package/lib/builder/util/mp.js +2 -8
  23. package/lib/builder.web.js +71 -0
  24. package/lib/index.d.ts +4 -0
  25. package/lib/index.js +6 -0
  26. package/lib/types.d.ts +1 -0
  27. package/lib/types.js +11 -0
  28. package/package.json +3 -8
  29. package/template/html/index.html.ejs +59 -29
  30. package/template/mp/common/weapp-page.js +23 -1
  31. package/template/mp/package.json +1 -1
  32. package/template/mp/page/index.js +2 -1
  33. package/template/package.json +5 -2
  34. package/template/webpack/getCSSModuleLocalIdent.js +28 -0
  35. package/template/webpack/web.prod.js +112 -103
  36. package/template/src/app/common.js +0 -13
  37. package/template/src/app/global-api.js +0 -99
  38. package/template/src/app/handlers.js +0 -13
  39. package/template/src/app/material-actions.js +0 -16
  40. package/template/src/app/mountAppApis.js +0 -25
  41. package/template/src/app/mountMpApis.js +0 -4
  42. package/template/src/datasources/config.js.tpl +0 -23
  43. package/template/src/datasources/dataset-profiles.js.tpl +0 -5
  44. package/template/src/datasources/datasource-profiles.js.tpl +0 -4
  45. package/template/src/datasources/index.js +0 -31
  46. package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -331
  47. package/template/src/handlers/HotAreas.js +0 -36
  48. package/template/src/handlers/PositionHandler.jsx +0 -8
  49. package/template/src/handlers/actionHandler/utils.js +0 -149
  50. package/template/src/handlers/componentEventActionEmitter.js +0 -29
  51. package/template/src/handlers/componentNodeMap.js +0 -24
  52. package/template/src/handlers/controller.js +0 -5
  53. package/template/src/handlers/emitComponentEvent.js +0 -8
  54. package/template/src/handlers/eventListener/componentEventListener.js +0 -15
  55. package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
  56. package/template/src/handlers/eventListener/index.js +0 -29
  57. package/template/src/handlers/eventListener/pageEventListener.js +0 -11
  58. package/template/src/handlers/eventListener/types.js +0 -32
  59. package/template/src/handlers/hooks/index.js +0 -14
  60. package/template/src/handlers/initWebEnv.js +0 -4
  61. package/template/src/handlers/injectStyle.js +0 -14
  62. package/template/src/handlers/instanceMap.js +0 -39
  63. package/template/src/handlers/lifecycle.js +0 -232
  64. package/template/src/handlers/render.jsx +0 -131
  65. package/template/src/handlers/utils/common.js +0 -151
  66. package/template/src/handlers/utils/eventProxy.js +0 -64
  67. package/template/src/handlers/utils/events.js +0 -8
  68. package/template/src/handlers/utils/index.js +0 -4
  69. package/template/src/handlers/utils/widgets.js +0 -320
  70. package/template/src/index.jsx +0 -142
  71. package/template/src/index.less +0 -119
  72. package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
  73. package/template/src/pages/app.tpl +0 -124
  74. package/template/src/router/index.tpl +0 -28
  75. package/template/src/store/computed.js +0 -11
  76. package/template/src/store/index.js +0 -40
  77. package/template/src/utils/ScanCodeComponent.js +0 -396
  78. package/template/src/utils/date.js +0 -324
  79. package/template/src/utils/history.js +0 -72
  80. package/template/src/utils/index.js +0 -67
  81. package/template/src/utils/kbone.js +0 -18
  82. package/template/src/utils/monitor-jssdk.min.js +0 -763
  83. package/template/src/utils/request.js +0 -5
  84. package/template/src/utils/scan-code-action.js +0 -27
@@ -1,320 +0,0 @@
1
- import * as React from 'react';
2
- import { observable, autorun, untracked } from 'mobx';
3
- import { remove } from 'lodash';
4
- import { checkVisible } from '../../utils/index';
5
-
6
- export const WidgetsContext = React.createContext({ parent: null });
7
-
8
- export function isSlot(comp) {
9
- return !comp['x-props'];
10
- }
11
-
12
- // 实现和小程序一致的 API,以兼容多端
13
- // widget.getDom({ rect: true })
14
- // https://developers.weixin.qq.com/miniprogram/dev/api/wxml/NodesRef.fields.html
15
- export function getDom(element, options) {
16
- if (!element) {
17
- console.warn('getDom 接口未传入有效的 element');
18
- return Promise.resolve({});
19
- }
20
-
21
- let result = {};
22
- if (options.id) result.id = element.id;
23
- if (options.dataset) result.dataset = element.dataset;
24
- if (options.rect) {
25
- const rect = element.getBoundingClientRect();
26
- Object.assign(result, {
27
- left: rect.left,
28
- right: rect.right,
29
- top: rect.top,
30
- bottom: rect.bottom,
31
- });
32
- }
33
- if (options.size) {
34
- const rect = element.getBoundingClientRect();
35
- Object.assign(result, {
36
- width: rect.width,
37
- height: rect.height,
38
- });
39
- }
40
- if (options.scrollOffset) {
41
- Object.assign(result, {
42
- scrollLeft: element.scrollLeft,
43
- scrollTop: element.scrollTop,
44
- });
45
- }
46
- if (options.properties && Array.isArray(options.properties)) {
47
- options.properties.forEach((propName) => {
48
- result[propName] = element.getAttribute(propName);
49
- });
50
- }
51
- if (options.computedStyle && Array.isArray(options.computedStyle)) {
52
- const computedStyle = window.getComputedStyle(element);
53
- options.computedStyle.forEach((propName) => {
54
- result[propName] = computedStyle[propName];
55
- });
56
- }
57
-
58
- return Promise.resolve(result);
59
- }
60
-
61
- export function findWidgets(
62
- widget,
63
- parentType,
64
- filterFn,
65
- includeInvisibleDescendants
66
- ) {
67
- if (!widget) return [];
68
-
69
- let { children = [] } = widget;
70
- let matched = children.filter(filterFn);
71
- if (!includeInvisibleDescendants) {
72
- children = children.filter((item) => checkVisible(item));
73
- matched = matched.filter((item) => checkVisible(item));
74
- }
75
- children.forEach((child) => {
76
- // 如果递归过程中发现了自己,则停止递归
77
- if (child.widgetType === parentType) return;
78
- matched = matched.concat(findWidgets(child, parentType, filterFn));
79
- });
80
- return matched;
81
- }
82
-
83
- const retryQueue = [];
84
- // 递归执行
85
- export function retryDataBinds(tryTime = 10) {
86
- const fn = retryQueue.shift();
87
- if (!fn || tryTime <= 0) return;
88
- try {
89
- fn({ showLog: tryTime <= 1 });
90
- } catch (e) {
91
- console.error('retryDataBinds', e);
92
- }
93
- setTimeout(() => {
94
- retryDataBinds(tryTime - 1);
95
- }, 0);
96
- }
97
- export function createWidgets(widgetProps, dataBinds, scopeContext = {}) {
98
- const nodeTree = createWidgetTree(widgetProps, dataBinds);
99
- const widgets = runFor(nodeTree, {}, null, null, scopeContext);
100
- return widgets;
101
-
102
- /**
103
- *
104
- * @param {*} curForNode
105
- * @param {*} forItems
106
- * @param {*} parentLevelWidgets
107
- * @param {*} parentWidget
108
- * @param {*} scopeContext
109
- * @returns top level widgets or for dispose
110
- */
111
- function runFor(
112
- curForNode,
113
- forItems,
114
- parentLevelWidgets,
115
- parentWidget,
116
- scopeContext
117
- ) {
118
- const nodeId = curForNode.id;
119
- if (!curForNode.value) {
120
- return createSubTree(curForNode, {}, scopeContext);
121
- }
122
- const dispose = autorun(() => {
123
- let forList = [];
124
- try {
125
- forList = dataBinds[nodeId]._waFor(forItems, undefined, scopeContext);
126
- } catch (e) {
127
- console.warn('waFor error', e);
128
- }
129
-
130
- if (!Array.isArray(forList)) {
131
- forList = [];
132
- console.warn(nodeId, 'For 循环绑定的数据并不是数组,请检查');
133
- }
134
-
135
- // 让 forList 进行监听
136
- forList.forEach(() => {});
137
- untracked(() => {
138
- disposeWidgets(parentLevelWidgets[curForNode.id]);
139
-
140
- // clean nodes of previouse for run
141
- dfsTree(curForNode, (node) => {
142
- const arr = parentLevelWidgets[node.id];
143
- arr.splice(0, arr.length);
144
- parentWidget &&
145
- remove(parentWidget.children, ({ id }) => id === node.id);
146
- });
147
-
148
- forList.forEach((item, index) => {
149
- const subForItems = { ...forItems, [nodeId]: item };
150
- createSubTree(curForNode, subForItems, scopeContext);
151
- });
152
-
153
- // 非初始化时遇到需要重新构建 dataBinds
154
- retryDataBinds();
155
- });
156
- });
157
-
158
- return dispose;
159
-
160
- function createSubTree(curForNode, subForItems, scopeContext) {
161
- const widgets = {};
162
-
163
- // traverse down the tree to set all widgets
164
- dfsTree(curForNode, (node, parentNode) => {
165
- if (node.forCount === curForNode.forCount) {
166
- // Leaf node
167
- const w = observable(widgetProps[node.id]);
168
- w.id = node.id;
169
- if (node === curForNode) {
170
- w._disposers = [];
171
- }
172
- widgets[node.id] = w;
173
- w.findWidgets = (type, includeInvisibleDescendants) =>
174
- findWidgets(w, w.widgetType, type, includeInvisibleDescendants);
175
- w.getWidgetsByType = (type, includeInvisibleDescendants) =>
176
- w.findWidgets(
177
- (currentWidget) => currentWidget.widgetType === type,
178
- includeInvisibleDescendants
179
- );
180
- w.getOwnerWidget = () => null; // 寻找父widget,默认返回null, 后续会覆写
181
- // 提供一个给 Node 挂载 API 的方式
182
- untracked(() => {
183
- w.extends = (name, fnOrData) =>
184
- Object.defineProperty(w, name, {
185
- value: fnOrData,
186
- writable: true,
187
- });
188
- });
189
- w.children = [];
190
- const parent = parentNode ? widgets[parentNode.id] : parentWidget;
191
- if (parent) {
192
- w.parent = parent;
193
- // 只有可显示 visible 的才存入 children 里
194
- if (checkVisible(w)) {
195
- parent.children.push(w);
196
- }
197
- }
198
- parentLevelWidgets && parentLevelWidgets[node.id].push(w);
199
-
200
- // Setup data binds
201
- Object.keys(dataBinds[node.id] || {}).map((prop) => {
202
- if (prop === '_waFor') {
203
- return;
204
- }
205
- function getBindData(options = {}) {
206
- let disposeError = false;
207
- const dispose = autorun(() => {
208
- try {
209
- // Computed data bind in the next tick since data bind may read widgets data
210
- w[prop] = dataBinds[node.id][prop](
211
- subForItems,
212
- undefined,
213
- scopeContext
214
- );
215
- disposeError = false;
216
- } catch (e) {
217
- options.showLog && console.error(e);
218
- retryQueue.push(getBindData);
219
- disposeError = true;
220
- }
221
- });
222
- if (!!disposeError && curForNode.id) {
223
- widgets[curForNode.id]._disposers.push(dispose);
224
- }
225
- }
226
- getBindData();
227
- });
228
- } else {
229
- if (parentLevelWidgets) {
230
- const len = parentLevelWidgets[node.id].push([]);
231
- widgets[node.id] = parentLevelWidgets[node.id][len - 1];
232
- } else {
233
- widgets[node.id] = observable([]);
234
- }
235
- }
236
- });
237
-
238
- // run for of next level
239
- dfsTree(curForNode, (node, parentNode) => {
240
- if (
241
- node.forCount === curForNode.forCount + 1 &&
242
- dataBinds[node.id]?._waFor
243
- ) {
244
- widgets[node.id]._disposers = { dataBinds: [] };
245
- const dispose = runFor(
246
- node,
247
- subForItems,
248
- widgets,
249
- node.parent && widgets[node.parent.id],
250
- scopeContext
251
- );
252
- curForNode.id && widgets[curForNode.id]._disposers.push(dispose);
253
- }
254
- });
255
-
256
- return widgets;
257
- }
258
- }
259
- }
260
-
261
- /**
262
- * Add parent, children to widget
263
- */
264
- function createWidgetTree(widgets, dataBinds) {
265
- const virtualRoot = { children: [], forCount: 0 };
266
- const nodes = Object.keys(widgets).reduce((result, id) => {
267
- result[id] = {
268
- id,
269
- value: widgets[id],
270
- children: [],
271
- parent: null,
272
- forCount: 0,
273
- };
274
- return result;
275
- }, {});
276
-
277
- // Create widgets tree API
278
- Object.keys(nodes).map((id) => {
279
- const curNode = nodes[id];
280
- const parent = nodes[widgets[id]._parentId];
281
- if (!parent) {
282
- virtualRoot.children.push(curNode);
283
- return;
284
- }
285
- curNode.parent = parent;
286
- parent.children.push(curNode);
287
- });
288
-
289
- virtualRoot.children.map(addForCount);
290
-
291
- // dfs, add forCount
292
- function addForCount(node) {
293
- if (node.parent) {
294
- node.forCount = node.parent.forCount;
295
- }
296
- if (dataBinds[node.id] && dataBinds[node.id]._waFor) {
297
- node.forCount++;
298
- }
299
- node.children.map(addForCount);
300
- }
301
-
302
- return virtualRoot;
303
- }
304
-
305
- function dfsTree(node, fn, parent) {
306
- node.value && fn(node, parent);
307
- node.children.map((e) => dfsTree(e, fn, node.value ? node : null));
308
- }
309
-
310
- // dispose autorun
311
- function disposeWidgets(widgets = []) {
312
- widgets.forEach((widget) => {
313
- const disposers = widget._disposers;
314
- if (disposers) {
315
- disposers.map((dispose) => dispose());
316
- disposers.splice(0, disposers.length);
317
- }
318
- disposeWidgets(widget.children);
319
- });
320
- }
@@ -1,142 +0,0 @@
1
- /**
2
- * 当本应用是乾坤子应用是,publicPath需要设置为子应用的相对路径
3
- * 这个变量时序重要需要先初始化
4
- */
5
- if (window.__POWERED_BY_QIANKUN__) {
6
- __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
7
- }
8
-
9
-
10
- import * as React from 'react'
11
- import * as ReactDOM from 'react-dom'
12
- import { setConfig } from './datasources/index'
13
- import App from './router'
14
- import './utils/monitor-jssdk.min'
15
- import './index.less'
16
- // 引入数据源管理器并进行初始化
17
- import './datasources'
18
- import { initGlobalVar } from './handlers/initWebEnv'
19
- import '@babel/polyfill/noConflict'
20
- import attachFastClick from 'fastclick'
21
- attachFastClick && attachFastClick.attach && attachFastClick.attach(document.body)
22
- import { app } from './app/global-api'
23
- // app 中注册配置页面以及app的全局配置miniprogram.config,h5里分app以及web页分别处理,使用process.env.isApp 区分判断
24
- if (process.env.isApp) {
25
- import { initWebConfig } from 'handlers/lifecycle'
26
- const AppConfig = require('../webpack/miniprogram.config')
27
- initWebConfig(app, AppConfig);
28
- }
29
-
30
- // 设置数据源请求的 loading 及 toast 处理
31
- setConfig({
32
- beforeDSRequest: (cfg) => {
33
- if (!cfg.options || !cfg.options.showLoading) return
34
- app.showLoading()
35
- },
36
- afterDSRequest: (cfg, error, result) => {
37
- if (!cfg.options) return
38
- if (cfg.options.showLoading) app.hideLoading()
39
- if (!cfg.options.showToast) return
40
- const isSuccess = !error && result && !result.code
41
- app.showToast({icon: isSuccess ? 'success' : 'error'})
42
- }
43
- })
44
- // window.app.yyptReport = window.yyptReport
45
-
46
- if (yyptReport && typeof yyptReport.pgvMain == 'function') {
47
- // report_url,appKey必填
48
- yyptReport.pgvMain({
49
- appKey: '<%= yyptAppKey %>', // 填入你申请的运营平台的应用key(必填)
50
- report_url: '<%= reportUrl %><%= yyptAppKey %>', // 上报url(把后端上报接口需要先挂网关,该url填写网关地址)
51
- autoReportPv: true, // 单页应用监听页面路径改变自动上报Pv,默认为false
52
- stopReport: <%= stopReport %>, // 停止上报
53
- // 其他参数说明
54
- // customUserPrams: null, // 用户自定义的额外属性--对于小马的用户属性,比如用户的部门编码(customUserPrams: { deptno: 1100 })需要在小马系统事先配置好
55
- //userKey: "user_id", // cookie里面用户的唯一标示
56
- //autoWatchClick: true, // 默认开启自动监听hottag
57
- //isWxEnv: false// 是否微信环境,微信环境会通过wx.getNetworkType获取网络环境
58
- // 通过传入函数,可以让业务方写代码传入要上报的属性,比如返回自定义属性,这里主要也是自定义属性,让sdk获取并且进行上报,减少重复编码
59
- //getCusParams: function () {
60
- // return {kv:{money:1}}; //kv:Key-Value,自定义事件Key-Value参数对 map JSON格式,在报表页面的事件参数分析页和页面参数分析页中可以看到上报的kv值
61
- //},
62
- })
63
- }
64
-
65
- initGlobalVar()
66
- ;(function() {
67
- function flex() {
68
- try {
69
- let htmlDom = document.documentElement
70
- let width = window.innerWidth || htmlDom.clientWidth
71
- let fontSize = width / (375 / 14)
72
- if (
73
- !navigator.userAgent.match(
74
- /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|IEMobile)/i
75
- ) &&
76
- fontSize > 14
77
- ) {
78
- htmlDom.style.fontSize = `14px`
79
- } else {
80
- htmlDom.style.fontSize = fontSize + `px`
81
- }
82
- } catch (e) {
83
- console.error(e)
84
- }
85
- }
86
-
87
- flex()
88
- window.addEventListener('resize', flex)
89
- })()
90
-
91
- // 使用HMR
92
- if (process.env.NODE_ENV !== 'production') {
93
- if (module.hot) {
94
- module.hot.accept()
95
- }
96
- }
97
-
98
- function render(props){
99
- ReactDOM.render(
100
- <App />,
101
- props && props.container ? props.container.querySelector('#root') : document.getElementById('root')
102
- )
103
- }
104
-
105
- // if (!process.env.isAdminPortal) {
106
- if (!window.__POWERED_BY_QIANKUN__) {
107
- render()
108
- }
109
-
110
- /**
111
- * bootstrap 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子,不会再重复触发 bootstrap。
112
- * 通常我们可以在这里做一些全局变量的初始化,比如不会在 unmount 阶段被销毁的应用级别的缓存等。
113
- */
114
- async function bootstrap() {
115
- console.log('react app bootstraped')
116
- }
117
-
118
- /**
119
- * 应用每次进入都会调用 mount 方法,通常我们在这里触发应用的渲染方法
120
- */
121
- async function mount(props) {
122
- render(props)
123
- }
124
-
125
- /**
126
- * 应用每次切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
127
- */
128
- async function unmount(props) {
129
- ReactDOM.unmountComponentAtNode(
130
- props.container ? props.container.querySelector('#root') : document.getElementById('root')
131
- )
132
- }
133
-
134
- <% if(adminPortalKey){ %>
135
- ((global) => {
136
- global['<%= adminPortalKey %>'] = {
137
- bootstrap,
138
- mount,
139
- unmount,
140
- };
141
- })(window);
142
- <% } %>
@@ -1,119 +0,0 @@
1
- // 针对小程序样式做适配
2
- // 请注意与weapps/src/pages/editor/components/Main/EditAndPreview/index.iframe.scss的一致性,以确保小程序端样式与
3
- body {
4
- margin: 0;
5
- padding: 0;
6
- }
7
-
8
- #weapp-scancode-video {
9
- width: 100%;
10
- height: 100%;
11
- object-fit: cover;
12
- }
13
-
14
- .weapp-scancode {
15
- &-close-button {
16
- background: white;
17
- color: black;
18
- display: flex;
19
- position: absolute;
20
- top: 14px;
21
- left: 14px;
22
- width: 24px;
23
- height: 24px;
24
- border-radius: 50%;
25
- cursor: pointer;
26
- justify-content: center;
27
- align-items: center;
28
- z-index: 500;
29
- }
30
- &-modal {
31
- position: fixed;
32
- background-color: black;
33
- left: 0px;
34
- right: 0px;
35
- top: 0px;
36
- bottom: 0px;
37
- &-main {
38
- height: 100%;
39
- position: relative;
40
- }
41
- }
42
- &-scan {
43
- &-wrapper {
44
- display: flex;
45
- flex-direction: column;
46
- justify-content: center;
47
- align-items: center;
48
- height: 100%;
49
- width: 100%;
50
- position: absolute;
51
- top: 0;
52
- left: 0;
53
- }
54
- &-square {
55
- --square-size: 16rem;
56
- width: var(--square-size);
57
- height: var(--square-size);
58
- position: relative;
59
- }
60
- &-bar {
61
- position: absolute;
62
- height: 10px;
63
- width: 100%;
64
- background: linear-gradient(90deg, transparent, #07c160 50%, transparent);
65
- top: 0%;
66
- border-top-left-radius: 50%;
67
- border-top-right-radius: 50%;
68
- animation: slideinout-top-down 2s;
69
- animation-direction: normal;
70
- animation-timing-function: linear;
71
- animation-iteration-count: infinite;
72
- }
73
- &-tip {
74
- margin-top: 10rem;
75
- color: white;
76
- }
77
- &-not-found {
78
- color: white;
79
- }
80
- &-not-found + p {
81
- color: #999;
82
- }
83
- }
84
-
85
- &-img-selector {
86
- position: absolute;
87
- bottom: 32px;
88
- right: 32px;
89
- z-index: 500;
90
- }
91
- &-img-picker {
92
- z-index: 500;
93
- padding: 5px;
94
- display: block;
95
- cursor: pointer;
96
- }
97
- }
98
-
99
- @keyframes slideinout-top-down {
100
- // use transform to prevent relayout
101
- 0% {
102
- transform: translateY(0px);
103
- opacity: 0;
104
- }
105
- 50% {
106
- transform: translateY(calc(var(--square-size) / 2));
107
- opacity: 0.5;
108
- }
109
- 100% {
110
- transform: translateY(var(--square-size));
111
- opacity: 0;
112
- }
113
- }
114
-
115
- @media (min-width: 1024px) {
116
- .weda-responsive_flex_flow {
117
- flex-flow: row !important;
118
- }
119
- }