@@ -3,14 +3,39 @@ import PropTypes from 'prop-types';
3
3
import { AutoSizer , List , CellMeasurerCache , CellMeasurer } from 'react-virtualized' ;
4
4
5
5
import { FlattenedNode } from './shapes/nodeShapes' ;
6
+ import TreeState , { State } from './state/TreeState' ;
6
7
7
8
export default class Tree extends React . Component {
8
9
_cache = new CellMeasurerCache ( {
9
10
fixedWidth : true ,
10
11
minHeight : 20 ,
11
12
} ) ;
12
13
13
- rowRenderer = ( { node, key, measure, style, NodeRenderer} ) => {
14
+ getRowCount = ( ) => {
15
+ const { nodes} = this . props ;
16
+
17
+ return nodes instanceof State ? nodes . flattenedTree . length : nodes . length ;
18
+ } ;
19
+
20
+ getNodeDeepness = ( node , index ) => {
21
+ const { nodes} = this . props ;
22
+
23
+ if ( nodes instanceof State ) {
24
+ TreeState . getNodeDeepness ( nodes , index ) ;
25
+ }
26
+
27
+ return nodes instanceof State ? TreeState . getNodeDeepness ( nodes , index ) : node . deepness ;
28
+ } ;
29
+
30
+ getNode = index => {
31
+ const { nodes} = this . props ;
32
+
33
+ return nodes instanceof State
34
+ ? { ...TreeState . getNodeAt ( nodes , index ) , deepness : this . getNodeDeepness ( { } , index ) }
35
+ : nodes [ index ] ;
36
+ } ;
37
+
38
+ rowRenderer = ( { node, key, measure, style, NodeRenderer, index} ) => {
14
39
const { nodeMarginLeft} = this . props ;
15
40
16
41
return (
@@ -25,17 +50,18 @@ export default class Tree extends React.Component {
25
50
node = { node }
26
51
onChange = { this . props . onChange }
27
52
measure = { measure }
53
+ index = { index }
28
54
/>
29
55
) ;
30
56
} ;
31
57
32
58
measureRowRenderer = nodes => ( { key, index, style, parent} ) => {
33
59
const { NodeRenderer} = this . props ;
34
- const node = nodes [ index ] ;
60
+ const node = this . getNode ( index ) ;
35
61
36
62
return (
37
63
< CellMeasurer cache = { this . _cache } columnIndex = { 0 } key = { key } rowIndex = { index } parent = { parent } >
38
- { m => this . rowRenderer ( { ...m , node, key, style, NodeRenderer} ) }
64
+ { m => this . rowRenderer ( { ...m , index , node, key, style, NodeRenderer} ) }
39
65
</ CellMeasurer >
40
66
) ;
41
67
} ;
@@ -50,7 +76,7 @@ export default class Tree extends React.Component {
50
76
deferredMeasurementCache = { this . _cache }
51
77
ref = { r => ( this . _list = r ) }
52
78
height = { height }
53
- rowCount = { nodes . length }
79
+ rowCount = { this . getRowCount ( ) }
54
80
rowHeight = { this . _cache . rowHeight }
55
81
rowRenderer = { this . measureRowRenderer ( nodes ) }
56
82
width = { width || autoWidth }
0 commit comments