@cloudbase/framework-plugin-low-code 0.6.31 → 0.6.34
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/lib/builder/config/index.js +2 -5
- package/lib/builder/core/copy.d.ts.map +1 -1
- package/lib/builder/mp/materials.d.ts.map +1 -1
- package/lib/builder/mp/materials.js +21 -5
- package/lib/generator/template.d.ts +1 -101
- package/lib/generator/template.d.ts.map +1 -1
- package/lib/generator/template.js +1 -101
- package/package.json +5 -3
- package/template/webpack/web.prod.js +66 -85
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/cookie.js +0 -286
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/history.js +0 -133
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/local-storage.js +0 -103
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/location.js +0 -588
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/miniprogram.js +0 -101
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/navigator.js +0 -80
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/performance.js +0 -28
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/screen.js +0 -31
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/session-storage.js +0 -96
- package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/xml-http-request.js +0 -290
- package/template/dist/mp/miniprogram_npm/miniprogram-render/document.js +0 -396
- package/template/dist/mp/miniprogram_npm/miniprogram-render/event/custom-event.js +0 -12
- package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event-target.js +0 -389
- package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event.js +0 -186
- package/template/dist/mp/miniprogram_npm/miniprogram-render/index.js +0 -41
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/attribute.js +0 -226
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/class-list.js +0 -153
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/comment.js +0 -80
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/a.js +0 -165
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/canvas.js +0 -138
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/image.js +0 -177
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/input.js +0 -181
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/not-support.js +0 -60
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/option.js +0 -126
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/select.js +0 -155
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/textarea.js +0 -178
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/video.js +0 -165
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-component.js +0 -84
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-custom-component.js +0 -64
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element.js +0 -970
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/node.js +0 -140
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style-list.js +0 -28
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style.js +0 -158
- package/template/dist/mp/miniprogram_npm/miniprogram-render/node/text-node.js +0 -127
- package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/parser.js +0 -269
- package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/query-selector.js +0 -420
- package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/tree.js +0 -130
- package/template/dist/mp/miniprogram_npm/miniprogram-render/util/cache.js +0 -95
- package/template/dist/mp/miniprogram_npm/miniprogram-render/util/pool.js +0 -24
- package/template/dist/mp/miniprogram_npm/miniprogram-render/util/tool.js +0 -131
- package/template/dist/mp/miniprogram_npm/miniprogram-render/window.js +0 -651
- package/template/generator/app/common.js +0 -17
- package/template/generator/app/global-api.js +0 -163
- package/template/generator/app/handlers.js +0 -13
- package/template/generator/datasources/config.js.tpl +0 -21
- package/template/generator/datasources/dataset-profiles.js.tpl +0 -5
- package/template/generator/datasources/datasource-profiles.js.tpl +0 -4
- package/template/generator/datasources/index.js.tpl +0 -14
- package/template/generator/handlers/NodeRenderer.jsx +0 -471
- package/template/generator/handlers/RenderWrapper.jsx +0 -145
- package/template/generator/index.jsx +0 -116
- package/template/generator/index.less +0 -120
- package/template/generator/pages/app.tpl +0 -181
- package/template/generator/pages/composite.tpl +0 -267
- package/template/generator/router/index.tpl +0 -49
- package/template/generator/store/computed.js +0 -11
- package/template/generator/store/index.js +0 -5
- package/template/generator/utils/ScanCodeComponent.js +0 -345
- package/template/generator/utils/actionHandler.js +0 -119
- package/template/generator/utils/common.js +0 -225
- package/template/generator/utils/computed.js +0 -9
- package/template/generator/utils/date.js +0 -324
- package/template/generator/utils/error.jsx +0 -14
- package/template/generator/utils/eventProxy.js +0 -64
- package/template/generator/utils/history.js +0 -35
- package/template/generator/utils/hooks.js +0 -10
- package/template/generator/utils/index.js +0 -41
- package/template/generator/utils/initGlobalVar.js +0 -14
- package/template/generator/utils/lifecycle.js +0 -158
- package/template/generator/utils/monitor-jssdk.min.js +0 -881
- package/template/generator/utils/page.js +0 -10
- package/template/generator/utils/scan-code-action.js +0 -27
- package/template/generator/utils/style.js +0 -81
- package/template/generator/utils/widgets.js +0 -343
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Suspense } from "react";
|
|
3
|
-
import ReactDOM from 'react-dom';
|
|
4
|
-
|
|
5
|
-
const ScanCode = React.lazy(() => import('./ScanCodeComponent'));
|
|
6
|
-
const WEAPP_SCAN_CODE_ELEMENT_ID = 'weapp-scan-code-modal-root';
|
|
7
|
-
export function scanCodeApi(opts) {
|
|
8
|
-
const options = {
|
|
9
|
-
onlyFromCamera: false,
|
|
10
|
-
scanType: ['barCode', 'qrCode'],
|
|
11
|
-
success: () => {},
|
|
12
|
-
fail: () => {},
|
|
13
|
-
complete: () => {},
|
|
14
|
-
enableDefaultBehavior: true,
|
|
15
|
-
...opts,
|
|
16
|
-
};
|
|
17
|
-
if (typeof options.scanType === 'string') {
|
|
18
|
-
options.scanType = [options.scanType];
|
|
19
|
-
}
|
|
20
|
-
let root = document.getElementById(WEAPP_SCAN_CODE_ELEMENT_ID);
|
|
21
|
-
if (!root) {
|
|
22
|
-
root = document.createElement('div');
|
|
23
|
-
root.id = WEAPP_SCAN_CODE_ELEMENT_ID;
|
|
24
|
-
}
|
|
25
|
-
document.body.appendChild(root);
|
|
26
|
-
ReactDOM.render(<Suspense fallback={<></>}><ScanCode root={root} options={options} /></Suspense>, root);
|
|
27
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { kebabCase, camelcase, isEmptyObj } from './common';
|
|
2
|
-
|
|
3
|
-
const PERCENTAGE_KEY_LIST = [
|
|
4
|
-
'opacity',
|
|
5
|
-
'order',
|
|
6
|
-
'flex',
|
|
7
|
-
'flexGrow',
|
|
8
|
-
'flexShrink',
|
|
9
|
-
'zIndex',
|
|
10
|
-
'fontWeight',
|
|
11
|
-
'borderImage',
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
export function translateStyleToRem(style) {
|
|
15
|
-
return translateStyleByHandler(style, toREM);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function translateStyleByHandler(style, handler) {
|
|
19
|
-
return Object.keys(style).reduce((result, key) => {
|
|
20
|
-
const value = style[key];
|
|
21
|
-
if (PERCENTAGE_KEY_LIST.includes(key)) {
|
|
22
|
-
setStyleValue(result, key, value);
|
|
23
|
-
} else if (value !== undefined && value !== null) {
|
|
24
|
-
setStyleValue(result, key, handler(value));
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}, {});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function setStyleValue(object, key, value) {
|
|
31
|
-
if (value === undefined || value === null || value === '') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// 特殊样式移除
|
|
35
|
-
if (key === 'open') {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (isEmptyObj(value)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
object[camelcase(key)] = value;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function calPxToREM(px) {
|
|
47
|
-
if (Number.isNaN(px / 28)) return px.toString();
|
|
48
|
-
if (+px === 0) {
|
|
49
|
-
return '0';
|
|
50
|
-
}
|
|
51
|
-
return (px / 28).toFixed(4) + 'rem';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function toREM(cssLen) {
|
|
55
|
-
if (typeof cssLen === 'string') {
|
|
56
|
-
const cssLenArr = cssLen.split(' ');
|
|
57
|
-
return cssLenArr
|
|
58
|
-
.map((attr) => {
|
|
59
|
-
const matchResult = attr.match(/^(-?\d+)(px)?$/);
|
|
60
|
-
if (matchResult && matchResult[1]) {
|
|
61
|
-
return calPxToREM(+matchResult[1]);
|
|
62
|
-
}
|
|
63
|
-
return attr;
|
|
64
|
-
})
|
|
65
|
-
.join(' ');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof cssLen === 'number') {
|
|
69
|
-
return calPxToREM(cssLen);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function toCssText(style, className = '.some-class-name') {
|
|
74
|
-
const attrText = Object.keys(style)
|
|
75
|
-
.map((key) => {
|
|
76
|
-
const value = style[key];
|
|
77
|
-
return `${kebabCase(key)}: ${value};`;
|
|
78
|
-
})
|
|
79
|
-
.join('\n');
|
|
80
|
-
return `${className} { ${attrText} }\n`;
|
|
81
|
-
}
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { observable, autorun, untracked } from 'mobx';
|
|
3
|
-
import remove from 'lodash.remove';
|
|
4
|
-
import { EventProxy } from './eventProxy';
|
|
5
|
-
|
|
6
|
-
export const widgetKeys = [
|
|
7
|
-
'getConfig',
|
|
8
|
-
'findWidgets',
|
|
9
|
-
'getWidgetsByType',
|
|
10
|
-
'extends',
|
|
11
|
-
'on',
|
|
12
|
-
'off',
|
|
13
|
-
'getOwnerWidget',
|
|
14
|
-
'getDom',
|
|
15
|
-
'domRef',
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
export const WidgetsContext = React.createContext({ parent: null });
|
|
19
|
-
|
|
20
|
-
export function isSlot(comp) {
|
|
21
|
-
return !comp['x-props'];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function checkVisible({ _visible }) {
|
|
25
|
-
return _visible !== false && _visible !== '';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 实现和小程序一致的 API,以兼容多端
|
|
29
|
-
// widget.getDom({ rect: true })
|
|
30
|
-
// https://developers.weixin.qq.com/miniprogram/dev/api/wxml/NodesRef.fields.html
|
|
31
|
-
export function getDom(element, options) {
|
|
32
|
-
if (!element) {
|
|
33
|
-
console.warn('getDom 接口未传入有效的 element');
|
|
34
|
-
return Promise.resolve({});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let result = {};
|
|
38
|
-
if (options.id) result.id = element.id;
|
|
39
|
-
if (options.dataset) result.dataset = element.dataset;
|
|
40
|
-
if (options.rect) {
|
|
41
|
-
const rect = element.getBoundingClientRect();
|
|
42
|
-
Object.assign(result, {
|
|
43
|
-
left: rect.left,
|
|
44
|
-
right: rect.right,
|
|
45
|
-
top: rect.top,
|
|
46
|
-
bottom: rect.bottom,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (options.size) {
|
|
50
|
-
const rect = element.getBoundingClientRect();
|
|
51
|
-
Object.assign(result, {
|
|
52
|
-
width: rect.width,
|
|
53
|
-
height: rect.height,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (options.scrollOffset) {
|
|
57
|
-
Object.assign(result, {
|
|
58
|
-
scrollLeft: element.scrollLeft,
|
|
59
|
-
scrollTop: element.scrollTop,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (options.properties && Array.isArray(options.properties)) {
|
|
63
|
-
options.properties.forEach((propName) => {
|
|
64
|
-
result[propName] = element.getAttribute(propName);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (options.computedStyle && Array.isArray(options.computedStyle)) {
|
|
68
|
-
const computedStyle = window.getComputedStyle(element);
|
|
69
|
-
options.computedStyle.forEach((propName) => {
|
|
70
|
-
result[propName] = computedStyle[propName];
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return Promise.resolve(result);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function findWidgets(
|
|
78
|
-
widget,
|
|
79
|
-
parentType,
|
|
80
|
-
filterFn,
|
|
81
|
-
includeInvisibleDescendants
|
|
82
|
-
) {
|
|
83
|
-
if (!widget) return [];
|
|
84
|
-
|
|
85
|
-
let { children = [] } = widget;
|
|
86
|
-
let matched = children.filter(filterFn);
|
|
87
|
-
|
|
88
|
-
// 过滤掉不可见后代
|
|
89
|
-
if (!includeInvisibleDescendants) {
|
|
90
|
-
children = children.filter((item) => checkVisible(item));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
children.forEach((child) => {
|
|
94
|
-
// 如果递归过程中发现了自己,则停止递归
|
|
95
|
-
matched = matched.concat(
|
|
96
|
-
findWidgets(child, parentType, filterFn, includeInvisibleDescendants)
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// 过滤掉不可见的匹配项
|
|
101
|
-
if (!includeInvisibleDescendants) {
|
|
102
|
-
matched = matched.filter((item) => checkVisible(item));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return matched;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const retryQueue = [];
|
|
109
|
-
// 递归执行
|
|
110
|
-
export function retryDataBinds(tryTime = 10) {
|
|
111
|
-
const fn = retryQueue.shift();
|
|
112
|
-
if (!fn || tryTime <= 0) return;
|
|
113
|
-
try {
|
|
114
|
-
fn({ showLog: tryTime <= 1 });
|
|
115
|
-
} catch (e) {
|
|
116
|
-
console.error('retryDataBinds', e);
|
|
117
|
-
}
|
|
118
|
-
retryDataBinds(tryTime - 1);
|
|
119
|
-
}
|
|
120
|
-
export function createWidgets(widgetProps, dataBinds, context) {
|
|
121
|
-
const nodeTree = createWidgetTree(widgetProps, dataBinds);
|
|
122
|
-
const widgets = runFor(nodeTree, {}, null, null, context);
|
|
123
|
-
return widgets;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
*
|
|
127
|
-
* @param {*} curForNode
|
|
128
|
-
* @param {*} forItems
|
|
129
|
-
* @param {*} parentLevelWidgets
|
|
130
|
-
* @param {*} parentWidget
|
|
131
|
-
* @param {*} context
|
|
132
|
-
* @returns top level widgets or for dispose
|
|
133
|
-
*/
|
|
134
|
-
function runFor(curForNode, forItems, parentLevelWidgets, parentWidget, context) {
|
|
135
|
-
const nodeId = curForNode.id;
|
|
136
|
-
if (!curForNode.value) {
|
|
137
|
-
return createSubTree(curForNode, {});
|
|
138
|
-
}
|
|
139
|
-
const dispose = autorun(() => {
|
|
140
|
-
let forList = [];
|
|
141
|
-
try {
|
|
142
|
-
forList = dataBinds[nodeId]._waFor(forItems, undefined, context);
|
|
143
|
-
} catch (e) {
|
|
144
|
-
console.error('waFor error', e);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (!Array.isArray(forList)) {
|
|
148
|
-
console.warn(nodeId, 'For 循环绑定的数据并不是数组,请检查');
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 让 forList 进行监听
|
|
153
|
-
forList.forEach(() => {});
|
|
154
|
-
untracked(() => {
|
|
155
|
-
disposeWidgets(parentLevelWidgets[curForNode.id]);
|
|
156
|
-
|
|
157
|
-
// clean nodes of previouse for run
|
|
158
|
-
dfsTree(curForNode, (node) => {
|
|
159
|
-
const arr = parentLevelWidgets[node.id];
|
|
160
|
-
arr.splice(0, arr.length);
|
|
161
|
-
parentWidget &&
|
|
162
|
-
remove(parentWidget.children, ({ id }) => id === node.id);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
forList.forEach((item, index) => {
|
|
166
|
-
const subForItems = { ...forItems, [nodeId]: item };
|
|
167
|
-
createSubTree(curForNode, subForItems);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// 非初始化时遇到需要重新构建 dataBinds
|
|
171
|
-
retryDataBinds();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
return dispose;
|
|
176
|
-
|
|
177
|
-
function createSubTree(curForNode, subForItems) {
|
|
178
|
-
const widgets = {};
|
|
179
|
-
|
|
180
|
-
// traverse down the tree to set all widgets
|
|
181
|
-
dfsTree(curForNode, (node, parentNode) => {
|
|
182
|
-
if (node.forCount === curForNode.forCount) {
|
|
183
|
-
// Leaf node
|
|
184
|
-
const w = observable(widgetProps[node.id]);
|
|
185
|
-
w.id = node.id;
|
|
186
|
-
if (node === curForNode) {
|
|
187
|
-
w._disposers = [];
|
|
188
|
-
}
|
|
189
|
-
widgets[node.id] = w;
|
|
190
|
-
w._listeners = new EventProxy();
|
|
191
|
-
// 提供一个给 Node 挂载 API 的方式
|
|
192
|
-
untracked(() => {
|
|
193
|
-
w.getConfig = () => ({}); // 兼容非复合组件调用 getConfig 能力
|
|
194
|
-
w.findWidgets = (type, includeInvisibleDescendants) =>
|
|
195
|
-
findWidgets(w, w.widgetType, type, includeInvisibleDescendants);
|
|
196
|
-
w.getWidgetsByType = (type, includeInvisibleDescendants) =>
|
|
197
|
-
w.findWidgets(
|
|
198
|
-
(currentWidget) => currentWidget.widgetType === type,
|
|
199
|
-
includeInvisibleDescendants
|
|
200
|
-
);
|
|
201
|
-
w.extends = (name, fnOrData) =>
|
|
202
|
-
Object.defineProperty(w, name, {
|
|
203
|
-
value: fnOrData,
|
|
204
|
-
writable: true,
|
|
205
|
-
});
|
|
206
|
-
w.on = (name, listener) => w._listeners.on(name, listener);
|
|
207
|
-
w.off = (name, listener) => w._listeners.cancel(name, listener);
|
|
208
|
-
w.getOwnerWidget = () => null; // 默认带上一个 widget
|
|
209
|
-
});
|
|
210
|
-
w.children = [];
|
|
211
|
-
const parent = parentNode ? widgets[parentNode.id] : parentWidget;
|
|
212
|
-
if (parent) {
|
|
213
|
-
w.parent = parent;
|
|
214
|
-
// 只有可显示 visible 的才存入 children 里
|
|
215
|
-
if (checkVisible(w)) {
|
|
216
|
-
parent.children.push(w);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
parentLevelWidgets && parentLevelWidgets[node.id].push(w);
|
|
220
|
-
|
|
221
|
-
// Setup data binds
|
|
222
|
-
Object.keys(dataBinds[node.id] || {}).map((prop) => {
|
|
223
|
-
if (prop === '_waFor') {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
function getBindData(options = {}) {
|
|
227
|
-
let disposeError = false;
|
|
228
|
-
const dispose = autorun(() => {
|
|
229
|
-
try {
|
|
230
|
-
// Computed data bind in the next tick since data bind may read widgets data
|
|
231
|
-
w[prop] = dataBinds[node.id][prop](subForItems);
|
|
232
|
-
disposeError = false;
|
|
233
|
-
} catch (e) {
|
|
234
|
-
console.warn(`Error computing data bind ${w.id}.${prop}`, e);
|
|
235
|
-
if (prop === '_waIf') {
|
|
236
|
-
w[prop] = false;
|
|
237
|
-
} else {
|
|
238
|
-
options.showLog && console.warn(e);
|
|
239
|
-
retryQueue.push(getBindData);
|
|
240
|
-
disposeError = true;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
if (!disposeError && curForNode.id) {
|
|
245
|
-
widgets[curForNode.id]._disposers.push(dispose);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
getBindData();
|
|
249
|
-
});
|
|
250
|
-
} else {
|
|
251
|
-
if (parentLevelWidgets) {
|
|
252
|
-
const len = parentLevelWidgets[node.id].push([]);
|
|
253
|
-
widgets[node.id] = parentLevelWidgets[node.id][len - 1];
|
|
254
|
-
} else {
|
|
255
|
-
widgets[node.id] = observable([]);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// run for of next level
|
|
261
|
-
dfsTree(curForNode, (node, parentNode) => {
|
|
262
|
-
if (
|
|
263
|
-
node.forCount === curForNode.forCount + 1 &&
|
|
264
|
-
dataBinds[node.id] &&
|
|
265
|
-
dataBinds[node.id]._waFor
|
|
266
|
-
) {
|
|
267
|
-
widgets[node.id]._disposers = { dataBinds: [] };
|
|
268
|
-
const dispose = runFor(
|
|
269
|
-
node,
|
|
270
|
-
subForItems,
|
|
271
|
-
widgets,
|
|
272
|
-
node.parent && widgets[node.parent.id],
|
|
273
|
-
context
|
|
274
|
-
);
|
|
275
|
-
curForNode.id && widgets[curForNode.id]._disposers.push(dispose);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
return widgets;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Add parent, children to widget
|
|
286
|
-
*/
|
|
287
|
-
function createWidgetTree(widgets, dataBinds) {
|
|
288
|
-
const virtualRoot = { children: [], forCount: 0 };
|
|
289
|
-
const nodes = Object.keys(widgets).reduce((result, id) => {
|
|
290
|
-
result[id] = {
|
|
291
|
-
id,
|
|
292
|
-
value: widgets[id],
|
|
293
|
-
children: [],
|
|
294
|
-
parent: null,
|
|
295
|
-
forCount: 0,
|
|
296
|
-
};
|
|
297
|
-
return result;
|
|
298
|
-
}, {});
|
|
299
|
-
|
|
300
|
-
// Create widgets tree API
|
|
301
|
-
Object.keys(nodes).map((id) => {
|
|
302
|
-
const curNode = nodes[id];
|
|
303
|
-
const parent = nodes[widgets[id]._parentId];
|
|
304
|
-
if (!parent) {
|
|
305
|
-
virtualRoot.children.push(curNode);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
curNode.parent = parent;
|
|
309
|
-
parent.children.push(curNode);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
virtualRoot.children.map(addForCount);
|
|
313
|
-
|
|
314
|
-
// dfs, add forCount
|
|
315
|
-
function addForCount(node) {
|
|
316
|
-
if (node.parent) {
|
|
317
|
-
node.forCount = node.parent.forCount;
|
|
318
|
-
}
|
|
319
|
-
if (dataBinds[node.id] && dataBinds[node.id]._waFor) {
|
|
320
|
-
node.forCount++;
|
|
321
|
-
}
|
|
322
|
-
node.children.map(addForCount);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return virtualRoot;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function dfsTree(node, fn, parent) {
|
|
329
|
-
node.value && fn(node, parent);
|
|
330
|
-
node.children.map((e) => dfsTree(e, fn, node.value ? node : null));
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// dispose autorun
|
|
334
|
-
function disposeWidgets(widgets = []) {
|
|
335
|
-
widgets.forEach((widget) => {
|
|
336
|
-
const disposers = widget._disposers;
|
|
337
|
-
if (disposers) {
|
|
338
|
-
disposers.map((dispose) => dispose());
|
|
339
|
-
disposers.splice(0, disposers.length);
|
|
340
|
-
}
|
|
341
|
-
disposeWidgets(widget.children);
|
|
342
|
-
});
|
|
343
|
-
}
|