@@ -6,27 +6,27 @@ import {
66 withDefault ,
77 NameConfig ,
88 jsonValueExposingStateControl ,
9- } from " lowcoder-sdk" ;
10- import { Excalidraw } from " @excalidraw/excalidraw" ;
11- import { useState , useRef } from " react" ;
12- import { trans } from " ./i18n/comps" ;
9+ } from ' lowcoder-sdk' ;
10+ import { Excalidraw } from ' @excalidraw/excalidraw' ;
11+ import { useState , useRef , useEffect } from ' react' ;
12+ import { trans } from ' ./i18n/comps' ;
1313
14- import { useResizeDetector } from " react-resize-detector" ;
14+ import { useResizeDetector } from ' react-resize-detector' ;
1515const defaultData = {
1616 elements : [
1717 {
18- id : " kInUXcNd249GomID2BShG" ,
19- type : " rectangle" ,
18+ id : ' kInUXcNd249GomID2BShG' ,
19+ type : ' rectangle' ,
2020 x : 276.696533203125 ,
2121 y : 200.4761962890625 ,
2222 width : 291.8367919921875 ,
2323 height : 143.3603515625 ,
2424 angle : 0 ,
25- strokeColor : " #1e1e1e" ,
26- backgroundColor : " transparent" ,
27- fillStyle : " solid" ,
25+ strokeColor : ' #1e1e1e' ,
26+ backgroundColor : ' transparent' ,
27+ fillStyle : ' solid' ,
2828 strokeWidth : 2 ,
29- strokeStyle : " solid" ,
29+ strokeStyle : ' solid' ,
3030 roughness : 1 ,
3131 opacity : 100 ,
3232 groupIds : [ ] ,
@@ -46,20 +46,20 @@ const defaultData = {
4646 ] ,
4747 appState : {
4848 gridSize : null ,
49- viewBackgroundColor : "#ffffff" ,
49+ viewBackgroundColor : '#fff' ,
5050 } ,
5151 files : { } ,
5252} ;
5353let ExcalidrawCompBase = ( function ( ) {
5454 const childrenMap = {
55- autoHeight : withDefault ( AutoHeightControl , " auto" ) ,
56- data : jsonValueExposingStateControl ( " data" , defaultData )
55+ autoHeight : withDefault ( AutoHeightControl , ' auto' ) ,
56+ data : jsonValueExposingStateControl ( ' data' , defaultData ) ,
5757 } ;
5858
5959 return new UICompBuilder ( childrenMap , ( props : any ) => {
6060 const previousDrawRef = useRef ( { } ) ;
61-
62- const [ dimensions , setDimensions ] = useState ( { width : 480 , height : 600 } ) ;
61+ const [ excalidrawAPI , setExcalidrawAPI ] = useState < any > ( null ) ;
62+ const [ dimensions , setDimensions ] = useState ( { width : 480 , height : 600 } ) ;
6363 const {
6464 width,
6565 height,
@@ -83,7 +83,11 @@ let ExcalidrawCompBase = (function () {
8383 } ) ;
8484 } ,
8585 } ) ;
86-
86+ useEffect ( ( ) => {
87+ if ( excalidrawAPI ) {
88+ excalidrawAPI . updateScene ( props . data . value ) ;
89+ }
90+ } , [ JSON . stringify ( props . data ) ] ) ;
8791 return (
8892 < div
8993 ref = { conRef }
@@ -92,10 +96,11 @@ let ExcalidrawCompBase = (function () {
9296 width : `100%` ,
9397 } }
9498 >
95- < div style = { { height : dimensions . height , width : dimensions . width } } >
99+ < div style = { { height : dimensions . height , width : dimensions . width } } >
96100 < Excalidraw
97101 isCollaborating = { false }
98102 initialData = { props . data . value }
103+ excalidrawAPI = { ( api ) => setExcalidrawAPI ( api ) }
99104 onChange = { ( excalidrawElements , appState , files ) => {
100105 let draw = {
101106 elements : excalidrawElements ,
@@ -119,7 +124,7 @@ let ExcalidrawCompBase = (function () {
119124 return (
120125 < >
121126 < Section name = "Basic" >
122- { children . data . propertyView ( { label : " Data" } ) }
127+ { children . data . propertyView ( { label : ' Data' } ) }
123128 </ Section >
124129 < Section name = "Styles" >
125130 { children . autoHeight . getPropertyView ( ) }
@@ -137,5 +142,5 @@ ExcalidrawCompBase = class extends ExcalidrawCompBase {
137142} ;
138143
139144export default withExposingConfigs ( ExcalidrawCompBase , [
140- new NameConfig ( " data" , trans ( " component.data" ) ) ,
145+ new NameConfig ( ' data' , trans ( ' component.data' ) ) ,
141146] ) ;
0 commit comments