-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtree-node-renderer.js
More file actions
170 lines (155 loc) · 4.69 KB
/
tree-node-renderer.js
File metadata and controls
170 lines (155 loc) · 4.69 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { Children, cloneElement } from 'react'
import PropTypes from 'prop-types'
import useStyles from './tree-node-renderer-style'
function FileThemeTreeNodeRenderer(props) {
const {
children,
listIndex,
swapFrom,
swapLength,
swapDepth,
scaffoldBlockPxWidth,
lowerSiblingCounts,
connectDropTarget,
isOver,
draggedNode,
canDrop,
treeIndex
// treeId, // Delete from otherProps
// getPrevRow, // Delete from otherProps
// node, // Delete from otherProps
// path, // Delete from otherProps
// rowDirection
// ...otherProps
} = props
const classes = useStyles()
const scaffold = []
const scaffoldBlockCount = lowerSiblingCounts.length
lowerSiblingCounts.forEach((lowerSiblingCount, i) => {
let lineClass = ''
if(lowerSiblingCount > 0)
if(listIndex === 0) {
// Top-left corner of the tree
// +-----+
// | |
// | +--+
// | | |
// +--+--+
lineClass = `${classes.lineHalfHorizontalRight} ${classes.lineHalfVerticalBottom}`
} else if(i === scaffoldBlockCount - 1) {
// Last scaffold block in the row, right before the row content
// +--+--+
// | | |
// | +--+
// | | |
// +--+--+
lineClass = `${classes.lineHalfHorizontalRight} ${classes.lineFullVertical}`
} else {
// Simply connecting the line extending down to the next sibling on this level
// +--+--+
// | | |
// | | |
// | | |
// +--+--+
lineClass = classes.lineFullVertical
}
else if(listIndex === 0)
// Top-left corner of the tree, but has no siblings
// +-----+
// | |
// | +--+
// | |
// +-----+
lineClass = classes.lineHalfHorizontalRight
else if(i === scaffoldBlockCount - 1)
// The last or only node in this level of the tree
// +--+--+
// | | |
// | +--+
// | |
// +-----+
lineClass = `${classes.lineHalfVerticalTop} ${classes.lineHalfHorizontalRight}`
scaffold.push(
<div
className={`${classes.lineBlock} ${lineClass}`}
// className={('lineBlock', lineClass, rowDirectionClass)}
key={`pre_${1 + i}`}
style={{ width: scaffoldBlockPxWidth }} />
)
// if(treeIndex !== listIndex && i === swapDepth) {
// let highlightLineClass = ''
// if(listIndex === swapFrom + swapLength - 1)
// // This block is on the bottom (target) line
// // This block points at the target block (where the row will go when released)
// highlightLineClass = 'rst__highlightBottomLeftCorner'
// else if(treeIndex === swapFrom)
// // This block is on the top (source) line
// highlightLineClass = 'rst__highlightTopLeftCorner'
// else
// // This block is between the bottom and top
// highlightLineClass = 'rst__highlightLineVertical'
// scaffold.push(
// <div
// className={classnames(
// 'rst__absoluteLineBlock',
// highlightLineClass,
// rowDirectionClass
// )}
// key={i}
// style={style} />
// )
// }
})
return connectDropTarget(
<div className={classes.root}>
<div>
{scaffold}
</div>
{
Children.map(children, child =>
cloneElement(child, {
canDrop,
draggedNode,
isOver,
listIndex,
lowerSiblingCounts,
swapDepth,
swapFrom,
swapLength
})
)
}
</div>
)
}
FileThemeTreeNodeRenderer.defaultProps = {
canDrop : false,
draggedNode: null,
swapDepth : null,
swapFrom : null,
swapLength : null
}
FileThemeTreeNodeRenderer.propTypes = {
canDrop : PropTypes.bool,
children : PropTypes.node.isRequired,
connectDropTarget: PropTypes.func.isRequired,
draggedNode : PropTypes.shape({}),
getPrevRow : PropTypes.func.isRequired,
isOver : PropTypes.bool.isRequired,
listIndex : PropTypes.number.isRequired,
lowerSiblingCounts: PropTypes.arrayOf(PropTypes.number).isRequired,
node : PropTypes.shape({}).isRequired,
// Drop target
path: PropTypes.arrayOf(
PropTypes.oneOfType([ PropTypes.string, PropTypes.number ])
).isRequired,
rowDirection : PropTypes.string.isRequired,
scaffoldBlockPxWidth: PropTypes.number.isRequired,
swapDepth : PropTypes.number,
// used in dndManager
swapFrom : PropTypes.number,
swapLength: PropTypes.number,
treeId : PropTypes.string.isRequired,
treeIndex : PropTypes.number.isRequired
}
export default FileThemeTreeNodeRenderer