1
- import React , { Component } from ' react' ;
2
- import { Rect , Group } from ' react-konva' ;
1
+ import React , { Component } from " react" ;
2
+ import { Rect , Group } from " react-konva" ;
3
3
4
4
class GrandchildRectangle extends Component {
5
5
getComponentColor ( componentId ) {
6
- const color = this . props . components . find ( comp => comp . id == componentId ) . color ;
6
+ const color = this . props . components . find ( comp => comp . id == componentId )
7
+ . color ;
7
8
return color ;
8
9
}
9
10
10
11
getPseudoChild ( ) {
11
- return this . props . components . find ( comp => comp . id === this . props . childComponentId ) ;
12
+ return this . props . components . find (
13
+ comp => comp . id === this . props . childComponentId
14
+ ) ;
12
15
}
13
16
14
17
render ( ) {
@@ -25,6 +28,7 @@ class GrandchildRectangle extends Component {
25
28
height,
26
29
focusChild,
27
30
components,
31
+ childType
28
32
} = this . props ;
29
33
30
34
// the Group is responsible for dragging of all children
@@ -49,41 +53,52 @@ class GrandchildRectangle extends Component {
49
53
scaleY = { 1 }
50
54
width = { width }
51
55
height = { height }
52
- stroke = { this . getComponentColor ( childComponentId ) }
56
+ stroke = {
57
+ childType === "COMP"
58
+ ? this . getComponentColor ( childComponentId )
59
+ : "#000000"
60
+ }
53
61
// fill={color}
54
62
// opacity={0.8}
55
63
strokeWidth = { 4 }
56
64
strokeScaleEnabled = { false }
57
65
draggable = { false }
58
66
/>
59
- { components
60
- . find ( comp => comp . title === childComponentName )
61
- . childrenArray . filter ( child => child . childId !== '-1' )
62
- . map ( ( grandchild , i ) => (
63
- < GrandchildRectangle
64
- key = { i }
65
- components = { components }
66
- componentId = { componentId }
67
- childComponentName = { grandchild . componentName }
68
- childComponentId = { grandchild . childComponentId }
69
- focusChild = { focusChild }
70
- childId = { childId }
71
- // x={grandchild.position.x * (width / window.innerWidth)}
72
- // y={grandchild.position.y * (height / window.innerHeight)}
73
- // width={grandchild.position.width * (width / window.innerWidth)}
74
- // height={grandchild.position.height * (height / window.innerHeight)}
75
- width = { grandchild . position . width * ( width / this . getPseudoChild ( ) . position . width ) }
76
- height = { grandchild . position . height * ( height / this . getPseudoChild ( ) . position . height ) }
77
- x = {
78
- ( grandchild . position . x - this . getPseudoChild ( ) . position . x )
79
- * ( width / this . getPseudoChild ( ) . position . width )
80
- }
81
- y = {
82
- ( grandchild . position . y - this . getPseudoChild ( ) . position . y )
83
- * ( height / this . getPseudoChild ( ) . position . height )
84
- }
85
- />
86
- ) ) }
67
+ { childType === "COMP" &&
68
+ components
69
+ . find ( comp => comp . title === childComponentName )
70
+ . childrenArray . filter ( child => child . childId !== "-1" )
71
+ . map ( ( grandchild , i ) => (
72
+ < GrandchildRectangle
73
+ key = { i }
74
+ components = { components }
75
+ componentId = { componentId }
76
+ childComponentName = { grandchild . componentName }
77
+ childComponentId = { grandchild . childComponentId }
78
+ focusChild = { focusChild }
79
+ childId = { childId }
80
+ // x={grandchild.position.x * (width / window.innerWidth)}
81
+ // y={grandchild.position.y * (height / window.innerHeight)}
82
+ // width={grandchild.position.width * (width / window.innerWidth)}
83
+ // height={grandchild.position.height * (height / window.innerHeight)}
84
+ width = {
85
+ grandchild . position . width *
86
+ ( width / this . getPseudoChild ( ) . position . width )
87
+ }
88
+ height = {
89
+ grandchild . position . height *
90
+ ( height / this . getPseudoChild ( ) . position . height )
91
+ }
92
+ x = {
93
+ ( grandchild . position . x - this . getPseudoChild ( ) . position . x ) *
94
+ ( width / this . getPseudoChild ( ) . position . width )
95
+ }
96
+ y = {
97
+ ( grandchild . position . y - this . getPseudoChild ( ) . position . y ) *
98
+ ( height / this . getPseudoChild ( ) . position . height )
99
+ }
100
+ />
101
+ ) ) }
87
102
</ Group >
88
103
) ;
89
104
}
0 commit comments