Skip to content

Commit 6779c03

Browse files
committed
functions updated
1 parent 9a5752e commit 6779c03

File tree

1 file changed

+72
-20
lines changed

1 file changed

+72
-20
lines changed

lowcoder-comp-excalidraw/src/ExcalidrawComp.tsx

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
withDefault,
77
NameConfig,
88
jsonValueExposingStateControl,
9-
withMethodExposing
9+
withMethodExposing,
1010
} from 'lowcoder-sdk';
1111
import {Excalidraw} from '@excalidraw/excalidraw';
1212
import {useState, useRef, useEffect} from 'react';
@@ -59,6 +59,7 @@ let ExcalidrawCompBase = (function () {
5959
};
6060

6161
return new UICompBuilder(childrenMap, (props: any) => {
62+
console.log('🚀 ~ returnnewUICompBuilder ~ props:', props);
6263
const previousDrawRef = useRef({});
6364
const [excalidrawAPI, setExcalidrawAPI] = useState<any>(null);
6465
const [dimensions, setDimensions] = useState({width: 480, height: 600});
@@ -85,16 +86,21 @@ let ExcalidrawCompBase = (function () {
8586
});
8687
},
8788
});
88-
89+
8990
useEffect(() => {
90-
console.log("props.data.value", props.data.value)
91-
console.log("previousDrawRef.current, props.data.value", !isEqual(previousDrawRef.current, props.data.value))
92-
if (excalidrawAPI && !isEqual(previousDrawRef.current, props.data.value)) {
93-
excalidrawAPI.updateScene(props.data.value);
94-
previousDrawRef.current = props.data.value;
91+
if (
92+
excalidrawAPI &&
93+
!isEqual(previousDrawRef.current, props.data.value)
94+
) {
95+
const timeoutId = setTimeout(() => {
96+
excalidrawAPI.updateScene(props.data.value);
97+
previousDrawRef.current = props.data.value;
98+
}, 1000);
99+
100+
return () => clearTimeout(timeoutId);
95101
}
96102
}, [props.data.value, excalidrawAPI]);
97-
103+
98104
return (
99105
<div
100106
ref={conRef}
@@ -111,7 +117,7 @@ let ExcalidrawCompBase = (function () {
111117
if (!excalidrawAPI) {
112118
setExcalidrawAPI(api);
113119
}
114-
}}
120+
}}
115121
onChange={(excalidrawElements, appState, files) => {
116122
let draw = {
117123
elements: excalidrawElements,
@@ -155,24 +161,70 @@ ExcalidrawCompBase = class extends ExcalidrawCompBase {
155161
ExcalidrawCompBase = withMethodExposing(ExcalidrawCompBase, [
156162
{
157163
method: {
158-
name: "setData",
159-
description: "Set Gantt Chart Data",
164+
name: 'setData',
165+
description: 'Set Excalidraw Data',
160166
params: [
161167
{
162-
name: "data",
163-
type: "JSON",
164-
description: "JSON value",
168+
name: 'data',
169+
type: 'JSON',
170+
description: 'JSON value',
165171
},
166172
],
167173
},
168174
execute: (comp: any, values: any[]) => {
169-
console.log("values", values)
170-
console.log("comp.children.data", comp.children.data)
171-
172-
comp.children.data
173-
175+
comp.children.data;
174176
const newTasks = values[0];
175-
comp.children.data.dispatchChangeValueAction(JSON.stringify(newTasks, null, 2));
177+
comp.children.data.dispatchChangeValueAction(
178+
JSON.stringify(newTasks, null, 2)
179+
);
180+
},
181+
},
182+
183+
{
184+
method: {
185+
name: 'clearData',
186+
description: 'Clear Excalidraw Data',
187+
params: [
188+
{
189+
name: 'data',
190+
type: 'JSON',
191+
description: 'JSON value',
192+
},
193+
],
194+
},
195+
execute: (comp: any, values: any[]) => {
196+
comp.children.data.dispatchChangeValueAction(
197+
JSON.stringify(
198+
{
199+
elements: [],
200+
appState: {
201+
gridSize: null,
202+
viewBackgroundColor: '#fff',
203+
},
204+
files: {},
205+
},
206+
null,
207+
2
208+
)
209+
);
210+
},
211+
},
212+
{
213+
method: {
214+
name: 'resetData',
215+
description: 'Reset Excalidraw Data',
216+
params: [
217+
{
218+
name: 'data',
219+
type: 'JSON',
220+
description: 'JSON value',
221+
},
222+
],
223+
},
224+
execute: (comp: any, values: any[]) => {
225+
comp.children.data.dispatchChangeValueAction(
226+
JSON.stringify(defaultData, null, 2)
227+
);
176228
},
177229
},
178230
]);

0 commit comments

Comments
 (0)