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' ;
33// import findComponentById from '../utils/findComponentById.ts';
44
55class GrandchildRectangle extends Component {
6+ state = {
7+ imageHeight : 0 ,
8+ imageWidth : 0 ,
9+ } ;
10+
611 getComponentColor ( componentId ) {
712 // const color = findComponentById(componentId, this.props.components).color;
8- const color = this . props . components . find ( comp => comp . id === componentId )
9- . color ;
13+ const color = this . props . components . find ( comp => comp . id === componentId ) . color ;
1014 return color ;
1115 }
1216
1317 getPseudoChild ( ) {
14- return this . props . components . find (
15- comp => comp . id === this . props . childComponentId
16- ) ;
18+ return this . props . components . find ( comp => comp . id === this . props . childComponentId ) ;
1719 }
1820
19- setImage = imageSource => {
20- //console.log("IMAGE SOURCE", imageSource);
21+ setImage = ( imageSource ) => {
22+ // console.log("IMAGE SOURCE", imageSource);
2123 if ( ! imageSource ) return ;
2224 const image = new window . Image ( ) ;
2325 image . src = imageSource ;
2426 if ( ! image . height ) return null ;
27+ this . setState ( { imageHeight : image . height , imageWidth : image . width } ) ;
2528 return image ;
2629 } ;
2730
@@ -40,7 +43,7 @@ class GrandchildRectangle extends Component {
4043 height,
4144 focusChild,
4245 components,
43- imageSource
46+ imageSource,
4447 } = this . props ;
4548
4649 // the Group is responsible for dragging of all children
@@ -66,20 +69,20 @@ class GrandchildRectangle extends Component {
6669 scaleY = { 1 }
6770 width = { width }
6871 height = { height }
69- stroke = {
70- childType === "COMP"
71- ? this . getComponentColor ( childComponentId )
72- : "#000000"
73- }
72+ stroke = { childType === 'COMP' ? this . getComponentColor ( childComponentId ) : '#000000' }
7473 fillPatternImage = { imageSource ? this . setImage ( imageSource ) : null }
74+ fillPatternScaleX = { 0.1 }
75+ fillPatternScaleY = { 0.1 }
7576 // fill={color}
7677 // opacity={0.8}
77- strokeWidth = { 4 }
78+ strokeWidth = { 10 }
7879 strokeScaleEnabled = { false }
7980 draggable = { false }
81+ // centerScaling={true}
82+ // enabledAnchors={['top-left', 'top-right', 'bottom-left', 'bottom-right']}
8083 />
81- { childType === " COMP" &&
82- components
84+ { childType === ' COMP'
85+ && components
8386 . find ( comp => comp . title === childComponentName )
8487 . childrenArray . filter ( child => child . childId !== - 1 )
8588 . map ( ( grandchild , i ) => (
@@ -89,7 +92,7 @@ class GrandchildRectangle extends Component {
8992 componentId = { componentId }
9093 childType = { grandchild . childType }
9194 imageSource = {
92- grandchild . htmlElement == " Image" && grandchild . HTMLInfo . Src
95+ grandchild . htmlElement == ' Image' && grandchild . HTMLInfo . Src
9396 ? grandchild . HTMLInfo . Src
9497 : null
9598 }
@@ -103,21 +106,17 @@ class GrandchildRectangle extends Component {
103106 // : null
104107 // }
105108 // test test
106- width = {
107- grandchild . position . width *
108- ( width / this . getPseudoChild ( ) . position . width )
109- }
109+ width = { grandchild . position . width * ( width / this . getPseudoChild ( ) . position . width ) }
110110 height = {
111- grandchild . position . height *
112- ( height / this . getPseudoChild ( ) . position . height )
111+ grandchild . position . height * ( height / this . getPseudoChild ( ) . position . height )
113112 }
114113 x = {
115- ( grandchild . position . x - this . getPseudoChild ( ) . position . x ) *
116- ( width / this . getPseudoChild ( ) . position . width )
114+ ( grandchild . position . x - this . getPseudoChild ( ) . position . x )
115+ * ( width / this . getPseudoChild ( ) . position . width )
117116 }
118117 y = {
119- ( grandchild . position . y - this . getPseudoChild ( ) . position . y ) *
120- ( height / this . getPseudoChild ( ) . position . height )
118+ ( grandchild . position . y - this . getPseudoChild ( ) . position . y )
119+ * ( height / this . getPseudoChild ( ) . position . height )
121120 }
122121 />
123122 ) ) }
0 commit comments