fixed-field-layout.js
858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 将 fixedFields 按 divider 拆成白卡片区块与独立 divider 块。
* @param {Array} fixedFields
* @returns {Array<{ type: 'section'|'divider', fields?: Array, field?: object, blockKey: string }>}
*/
function buildFixedFieldBlocks(fixedFields = []) {
const blocks = []
let section = []
for (const field of fixedFields) {
if (field.type === 'divider') {
if (section.length) {
blocks.push({
type: 'section',
fields: section,
blockKey: `section-${section[0].key}`
})
}
blocks.push({
type: 'divider',
field,
blockKey: `divider-${field.key}`
})
section = []
} else {
section.push(field)
}
}
if (section.length) {
blocks.push({
type: 'section',
fields: section,
blockKey: `section-${section[0].key}`
})
}
return blocks
}
module.exports = {
buildFixedFieldBlocks
}