@cloudbase/framework-plugin-low-code 0.7.22 → 0.7.25
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/mp/index.d.ts +2 -2
- package/lib/builder/mp/index.d.ts.map +1 -1
- package/lib/builder/mp/index.js +3 -3
- package/lib/generate.d.ts +1 -2
- package/lib/generate.d.ts.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -13
- package/lib/utils/dataSource.d.ts +0 -4
- package/lib/utils/dataSource.d.ts.map +1 -1
- package/lib/utils/dataSource.js +4 -20
- package/package.json +3 -2
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/app-global.js +0 -4
- package/template/mp/app/common.js +0 -26
- package/template/mp/app/handlers.js +0 -15
- package/template/mp/app/weapps-api.js +0 -89
- package/template/mp/app.js +0 -114
- package/template/mp/app.json +0 -1
- package/template/mp/app.wxss +0 -15
- package/template/mp/common/data-patch-test.js +0 -60
- package/template/mp/common/data-patch.js +0 -44
- package/template/mp/common/merge-renderer.js +0 -67
- package/template/mp/common/process.js +0 -1
- package/template/mp/common/style.js +0 -34
- package/template/mp/common/url.js +0 -21
- package/template/mp/common/util.js +0 -395
- package/template/mp/common/utils.wxs +0 -11
- package/template/mp/common/weapp-component.js +0 -250
- package/template/mp/common/weapp-page.js +0 -204
- package/template/mp/common/weapp-sdk.js +0 -76
- package/template/mp/common/widget.js +0 -381
- package/template/mp/common/wx_yypt_report_v2.js +0 -460
- package/template/mp/component/index.js +0 -66
- package/template/mp/component/index.json +0 -4
- package/template/mp/component/index.wxml +0 -1
- package/template/mp/component/index.wxss +0 -1
- package/template/mp/datasources/config.js.tpl +0 -25
- package/template/mp/datasources/dataset-profiles.js.tpl +0 -5
- package/template/mp/datasources/datasource-profiles.js.tpl +0 -4
- package/template/mp/datasources/index.js +0 -31
- package/template/mp/package.json +0 -17
- package/template/mp/page/api.js +0 -1
- package/template/mp/page/index.js +0 -42
- package/template/mp/page/index.json +0 -3
- package/template/mp/page/index.wxml +0 -1
- package/template/mp/page/index.wxss +0 -3
- package/template/mp/project.config.json +0 -1
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { observable, autorun, untracked } from 'mobx'
|
|
2
|
-
import { styleToCss } from './style'
|
|
3
|
-
import { getDeep } from './util'
|
|
4
|
-
import { compLowcodes, create$comp } from './weapp-component'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* convert widget prop to data for wxml
|
|
8
|
-
* @param {*} props
|
|
9
|
-
*/
|
|
10
|
-
function resolveWidgetProp(props) {
|
|
11
|
-
let { classList = [] } = props
|
|
12
|
-
const data = {}
|
|
13
|
-
Object.keys(props).forEach(key => {
|
|
14
|
-
if (props[key] instanceof Function || props[key] === undefined) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
data[key] = props[key]
|
|
18
|
-
})
|
|
19
|
-
data.style = styleToCss(props.style)
|
|
20
|
-
data.className = classList.join ? classList.join(' ') : classList
|
|
21
|
-
const extraProps = ['classList', '_forItems', '_disposers', 'children', 'parent', '_parentId', 'id', '_order', 'widgetType', '$comp']
|
|
22
|
-
extraProps.map(prop => {
|
|
23
|
-
delete data[prop]
|
|
24
|
-
})
|
|
25
|
-
return data
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// widget prop -> wxml data
|
|
29
|
-
export function resolveWidgetData(props) {
|
|
30
|
-
if (!Array.isArray(props)) {
|
|
31
|
-
return resolveWidgetProp(props)
|
|
32
|
-
}
|
|
33
|
-
return props.map(resolveWidgetData)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export function createWidgets(widgetProps, dataBinds, widgetHolder, context, ownerMpInst) {
|
|
38
|
-
const rootNode = createWidgetDataTree(widgetProps, dataBinds)
|
|
39
|
-
return createSubWidgetTree(rootNode, widgetProps, dataBinds, ownerMpInst, widgetHolder, undefined, undefined, undefined, undefined, undefined, context)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param ownerMpInst The MP page or component instance the widgets belongs to
|
|
44
|
-
* @param ownerForWidgetHolder null for the virtual root node(first run)
|
|
45
|
-
* @param curForNode a component node or a virtual root tree node
|
|
46
|
-
* @returns {widgets: {id1:[], id2}, rootWidget: {children: [], _disposers: [], ...otherProps}}
|
|
47
|
-
*/
|
|
48
|
-
function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, widgetHolder = {},
|
|
49
|
-
index = 0, forItems = {}, ownerForWidgetHolder = null,
|
|
50
|
-
failedBinds = [], defaultParent = { children: observable([]), _disposers: [] }, context = {}) {
|
|
51
|
-
const indexPostfix = (forItems.lists || []).slice().reverse().map(list => idSeparator + list.currentIndex).join('')
|
|
52
|
-
|
|
53
|
-
// traverse down the tree to set up all widgets
|
|
54
|
-
dfsTree(curForNode, (node) => {
|
|
55
|
-
const parentForWidgetArr = ownerForWidgetHolder && ownerForWidgetHolder[node.id] || []
|
|
56
|
-
const existedWidget = index < parentForWidgetArr.length ? parentForWidgetArr[index] : null // try to reuse previous node when rerun for
|
|
57
|
-
|
|
58
|
-
if (node.forCount === curForNode.forCount) { // Leaf node
|
|
59
|
-
let w = existedWidget
|
|
60
|
-
if (!existedWidget) {
|
|
61
|
-
const parentNode = node.parent
|
|
62
|
-
let parentWidget = null
|
|
63
|
-
if (parentNode) {
|
|
64
|
-
parentWidget = widgetHolder[parentNode.id] || ownerForWidgetHolder[parentNode.id]
|
|
65
|
-
}
|
|
66
|
-
w = createAWidget(widgetProps[node.id], node.id + indexPostfix, parentWidget, ownerMpInst)
|
|
67
|
-
if (!parentWidget) {
|
|
68
|
-
defaultParent.children.push(w)
|
|
69
|
-
}
|
|
70
|
-
parentForWidgetArr.push(w)
|
|
71
|
-
} else {
|
|
72
|
-
disposeWidget(existedWidget, true)
|
|
73
|
-
}
|
|
74
|
-
setUpWidateDataBinds(w, dataBinds[node.id], forItems, failedBinds, context)
|
|
75
|
-
widgetHolder[node.id] = w
|
|
76
|
-
} else if (!existedWidget) {
|
|
77
|
-
const len = parentForWidgetArr.push(observable([]))
|
|
78
|
-
widgetHolder[node.id] = parentForWidgetArr[len - 1]
|
|
79
|
-
} else {
|
|
80
|
-
// Reuse existed for widget array
|
|
81
|
-
widgetHolder[node.id] = existedWidget
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// run for of next level
|
|
86
|
-
dfsTree(curForNode, (node) => {
|
|
87
|
-
if (node.forCount === curForNode.forCount + 1 && dataBinds[node.id] && dataBinds[node.id]._waFor) {
|
|
88
|
-
// find the node bound with next level for
|
|
89
|
-
const parent = node.parent ? widgetHolder[node.parent.id] : defaultParent
|
|
90
|
-
const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent, context)
|
|
91
|
-
parent._disposers.push(dispose) // Add the for bind dispose to the parent node of forNode
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
// Retry failed databinds
|
|
96
|
-
const len = failedBinds.length
|
|
97
|
-
for (let i = 0; i < len; i++) {
|
|
98
|
-
const setUpDataBind = failedBinds.shift()
|
|
99
|
-
setUpDataBind()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return { widgets: widgetHolder, rootWidget: widgetHolder[curForNode.id] || defaultParent }
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
* @param {*} curForNode
|
|
108
|
-
* @param {*} forItems
|
|
109
|
-
* @param {*} parentForWidgets
|
|
110
|
-
* @param {*} parentWidget
|
|
111
|
-
* @returns top level widgets or for dispose
|
|
112
|
-
*/
|
|
113
|
-
function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, ownerForWidgetHolder, failedBinds, defaultParent, context) {
|
|
114
|
-
const nodeId = curForNode.id
|
|
115
|
-
const dispose = autorun(() => {
|
|
116
|
-
let forList = []
|
|
117
|
-
try {
|
|
118
|
-
forList = dataBinds[nodeId]._waFor(forItems.lists, forItems.itemsById, undefined, context)
|
|
119
|
-
if (!Array.isArray(forList)) {
|
|
120
|
-
forList = []
|
|
121
|
-
}
|
|
122
|
-
} catch (e) {
|
|
123
|
-
forList = []
|
|
124
|
-
console.warn('For binding error', e)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Track list change (e.g. push)
|
|
128
|
-
forList.forEach(e => { })
|
|
129
|
-
|
|
130
|
-
untracked(() => {
|
|
131
|
-
// dispose widgets before reused instead
|
|
132
|
-
// disposeWidgets(parentForWidgets[curForNode.id])
|
|
133
|
-
|
|
134
|
-
// clean extra widgets of previous for run
|
|
135
|
-
dfsTree(curForNode, (node) => {
|
|
136
|
-
const arr = ownerForWidgetHolder[node.id]
|
|
137
|
-
const extraWidgets = arr.splice(forList.length, arr.length)
|
|
138
|
-
//console.log('@@ delete widgets', node.id, extraWidgets)
|
|
139
|
-
|
|
140
|
-
if (node.id === curForNode.id) { // clean the root widget.children only(recursive)
|
|
141
|
-
extraWidgets.map(w => {
|
|
142
|
-
disposeWidget(w)
|
|
143
|
-
const { children } = w.parent || defaultParent
|
|
144
|
-
children.remove(w)
|
|
145
|
-
// w.parent = null
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
forList.forEach((item, index) => {
|
|
151
|
-
let { lists = [], itemsById = {}, } = forItems
|
|
152
|
-
const _forItems = {
|
|
153
|
-
lists: [{ currentItem: item, currentIndex: index }, ...lists],
|
|
154
|
-
itemsById: { ...itemsById, [nodeId]: item },
|
|
155
|
-
}
|
|
156
|
-
const { rootWidget } = createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, {}, index, _forItems, ownerForWidgetHolder, failedBinds, defaultParent, context)
|
|
157
|
-
rootWidget._forItems = _forItems
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
return dispose
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function createAWidget(props, id, parent, ownerMpInst) {
|
|
166
|
-
|
|
167
|
-
const w = observable(props)
|
|
168
|
-
|
|
169
|
-
// Builtin props
|
|
170
|
-
Object.defineProperty(w, 'id', { value: id })
|
|
171
|
-
const { widgetType } = w
|
|
172
|
-
delete w.widgetType
|
|
173
|
-
Object.defineProperty(w, 'widgetType', { value: widgetType })
|
|
174
|
-
|
|
175
|
-
//w._disposers = []
|
|
176
|
-
//w.children = []
|
|
177
|
-
Object.defineProperty(w, 'children', { value: observable([]) })
|
|
178
|
-
Object.defineProperty(w, '_disposers', { value: observable([]) })
|
|
179
|
-
if (parent) {
|
|
180
|
-
//w.parent = parent
|
|
181
|
-
Object.defineProperty(w, 'parent', { value: parent })
|
|
182
|
-
parent.children.push(w)
|
|
183
|
-
}
|
|
184
|
-
delete w._parentId
|
|
185
|
-
|
|
186
|
-
Object.defineProperty(w, '$comp', { value: create$comp(w) })
|
|
187
|
-
mountBuiltinWigetsAPI(w, ownerMpInst)
|
|
188
|
-
return w
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function setUpWidateDataBinds(w, dataBinds, forItems, failedBinds, context) {
|
|
192
|
-
Object.keys(dataBinds || {}).map(prop => {
|
|
193
|
-
if (prop === '_waFor') { return }
|
|
194
|
-
const setUpDataBind = () => {
|
|
195
|
-
let firstRunError = null
|
|
196
|
-
const dispose = autorun(() => {
|
|
197
|
-
try {
|
|
198
|
-
// Computed data bind in the next tick since data bind may read widgets data
|
|
199
|
-
w[prop] = dataBinds[prop](forItems.lists, forItems.itemsById, undefined, context)
|
|
200
|
-
} catch (e) {
|
|
201
|
-
if(prop === '_waIf'){
|
|
202
|
-
w[prop] = false
|
|
203
|
-
console.warn(`Error computing data bind ${w.id}.${prop}`, e)
|
|
204
|
-
}else {
|
|
205
|
-
// 吞错误,因为部分异步的属性刚开始没有,
|
|
206
|
-
// 要求用户自己容错又要求太高,因此直接吞掉错误,只打印,不阻塞
|
|
207
|
-
// firstRunError = e
|
|
208
|
-
console.error(`Error computing data bind ${w.id}.${prop}`, e)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
if (firstRunError) {
|
|
213
|
-
dispose()
|
|
214
|
-
failedBinds.push(setUpDataBind)
|
|
215
|
-
} else {
|
|
216
|
-
w._disposers.push(dispose)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
setUpDataBind()
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function findForItemsOfWidget(widget) {
|
|
224
|
-
const forItems = widget._forItems
|
|
225
|
-
if (forItems) return forItems
|
|
226
|
-
if (widget.parent) return findForItemsOfWidget(widget.parent)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const idSeparator = '-'
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
*
|
|
233
|
-
* @param {*} owner Mp page or component instance
|
|
234
|
-
* @param {*} comp Mp component instance or event.currentTarget, the component to convert
|
|
235
|
-
*/
|
|
236
|
-
export function mpCompToWidget(owner, comp) {
|
|
237
|
-
const { widgets } = owner.getWeAppInst()
|
|
238
|
-
return getDeep(widgets, comp.id, idSeparator)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Add parent, children to widget
|
|
243
|
-
*/
|
|
244
|
-
function createWidgetDataTree(widgets, dataBinds) {
|
|
245
|
-
const virtualRoot = { children: [], forCount: 0 }
|
|
246
|
-
const nodes = Object.keys(widgets).reduce((result, id) => {
|
|
247
|
-
const w = widgets[id]
|
|
248
|
-
result[id] = { id, value: w, _order: w._order, children: [], parent: null, forCount: 0 }
|
|
249
|
-
delete w._order
|
|
250
|
-
return result
|
|
251
|
-
}, {})
|
|
252
|
-
|
|
253
|
-
// Create widgets tree API
|
|
254
|
-
Object.keys(nodes).map(id => {
|
|
255
|
-
const curNode = nodes[id]
|
|
256
|
-
const parent = nodes[widgets[id]._parentId]
|
|
257
|
-
//delete widgets[id]._parentId
|
|
258
|
-
if (!parent) {
|
|
259
|
-
virtualRoot.children.push(curNode)
|
|
260
|
-
return
|
|
261
|
-
}
|
|
262
|
-
curNode.parent = parent
|
|
263
|
-
parent.children.push(curNode)
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
// Sort children
|
|
267
|
-
Object.keys(nodes).map(id => {
|
|
268
|
-
nodes[id].children.sort((a, b) => a._order - b._order)
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
virtualRoot.children.map(addForCount)
|
|
272
|
-
|
|
273
|
-
// dfs, add forCount
|
|
274
|
-
function addForCount(node) {
|
|
275
|
-
if (node.parent) {
|
|
276
|
-
node.forCount = node.parent.forCount
|
|
277
|
-
}
|
|
278
|
-
if (dataBinds[node.id] && dataBinds[node.id]._waFor) {
|
|
279
|
-
node.forCount++
|
|
280
|
-
}
|
|
281
|
-
node.children.map(addForCount)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return virtualRoot
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function dfsTree(node, fn, parent) {
|
|
288
|
-
node.value && fn(node, parent)
|
|
289
|
-
node.children.map(e => dfsTree(e, fn, node.value ? node : null))
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// dispose autorun, widget can be the virtual root widget
|
|
293
|
-
export function disposeWidget(widget, noRecursive) {
|
|
294
|
-
const disposers = widget._disposers
|
|
295
|
-
disposers.map(dispose => dispose())
|
|
296
|
-
disposers.splice(0, disposers.length)
|
|
297
|
-
!noRecursive && widget.children.forEach(w => disposeWidget(w))
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export function createInitData(widgets, dataBinds, keyPrefix = '') {
|
|
301
|
-
return Object.keys(widgets).reduce((result, id) => {
|
|
302
|
-
if (!isWidgetInFor(id, widgets, dataBinds)) {
|
|
303
|
-
result[keyPrefix + id] = resolveWidgetData(widgets[id])
|
|
304
|
-
}
|
|
305
|
-
return result
|
|
306
|
-
}, {})
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function isWidgetInFor(id, widgets, dataBinds) {
|
|
310
|
-
let curNode = widgets[id]
|
|
311
|
-
let nodeId = id
|
|
312
|
-
while (curNode) {
|
|
313
|
-
if (dataBinds[nodeId] && dataBinds[nodeId]._waFor) {
|
|
314
|
-
return true
|
|
315
|
-
}
|
|
316
|
-
nodeId = curNode._parentId
|
|
317
|
-
curNode = widgets[nodeId]
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function mountBuiltinWigetsAPI(widget, owner) {
|
|
322
|
-
// #1 builtin APIs
|
|
323
|
-
widget.findWidgets = function (filter, includeInvisibleDescendants) {
|
|
324
|
-
let { children = [] } = this
|
|
325
|
-
if (!includeInvisibleDescendants) { // include visible widgets only by default
|
|
326
|
-
children = children.filter(e => e._waIf !== false)
|
|
327
|
-
}
|
|
328
|
-
const matched = []
|
|
329
|
-
children.forEach(w => {
|
|
330
|
-
if (filter(w)) {
|
|
331
|
-
matched.push(w)
|
|
332
|
-
}
|
|
333
|
-
matched.push(...w.findWidgets(filter, includeInvisibleDescendants))
|
|
334
|
-
})
|
|
335
|
-
return matched
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
widget.getWidgetsByType = function (type, includeInvisibleDescendants) {
|
|
339
|
-
return this.findWidgets(w => w.widgetType === type, includeInvisibleDescendants)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Similar to selectOwnerComponent of WX MP: https://developers.weixin.qq.com/miniprogram/dev/reference/api/Component.html
|
|
344
|
-
*/
|
|
345
|
-
widget.getOwnerWidget = function () {
|
|
346
|
-
return owner && owner.getWeAppInst().node
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// Will be overwritten by composited component
|
|
350
|
-
widget.getDom = function (fields) {
|
|
351
|
-
return new Promise((resolve, reject) => {
|
|
352
|
-
const query = (owner || wx).createSelectorQuery()
|
|
353
|
-
query.select('#' + this.id).fields(fields, res => {
|
|
354
|
-
resolve(res)
|
|
355
|
-
}).exec()
|
|
356
|
-
})
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
widget.getConfig = () => ({})
|
|
360
|
-
|
|
361
|
-
const lowcode = compLowcodes[widget.widgetType]
|
|
362
|
-
if (lowcode) {
|
|
363
|
-
const { index = {}, config } = lowcode
|
|
364
|
-
|
|
365
|
-
widget.getConfig = () => config
|
|
366
|
-
|
|
367
|
-
// #2 User defined APIs
|
|
368
|
-
const { publicMethods = {} } = index
|
|
369
|
-
Object.keys(publicMethods).map(name => {
|
|
370
|
-
const method = publicMethods[name]
|
|
371
|
-
if (method instanceof Function) {
|
|
372
|
-
Object.defineProperty(widget, name, { value: method.bind(widget.$comp) })
|
|
373
|
-
Object.defineProperty(widget.$comp, name, { value: method })
|
|
374
|
-
} else {
|
|
375
|
-
console.error(`Component(${widget.widgetType}) method(${name}) is not a function.`)
|
|
376
|
-
}
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
widget._methods = {}
|
|
381
|
-
}
|