1
1
import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
2
- import React , { ReactNode , useContext , useEffect , useRef , useState } from "react" ;
2
+ import React , { ReactNode , useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
3
3
import { ExternalEditorContext } from "util/context/ExternalEditorContext" ;
4
4
import { Comp , CompParams , MultiBaseComp } from "lowcoder-core" ;
5
5
import {
@@ -28,7 +28,7 @@ import { BoolControl } from "../controls/boolControl";
28
28
import { valueComp , withDefault } from "./simpleGenerators" ;
29
29
import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils" ;
30
30
import { EditorContext } from "../editorState" ;
31
- import { values } from "lodash" ;
31
+ import { isEqual , values } from "lodash" ;
32
32
import { UICompType , uiCompRegistry } from "../uiCompRegistry" ;
33
33
import { getNpmPackageMeta } from "../utils/remote" ;
34
34
import { compPluginsList } from "constants/compPluginConstants" ;
@@ -289,44 +289,34 @@ const UIView = React.memo((props: {
289
289
childrenProps [ 'disabled' ] = disabled || parentDisabled ;
290
290
}
291
291
292
- //ADDED BY FRED
293
- if ( childrenProps . events ) {
294
- const events = childrenProps . events as { value ?: any [ ] } ;
295
- if ( ! events . value || events . value . length === 0 ) {
296
- events . value = [ ] ;
297
- }
298
- }
299
- //END ADD BY FRED
300
-
301
292
useMergeCompStyles (
302
293
childrenJsonProps as Record < string , any > ,
303
294
comp . dispatch
304
295
) ;
305
296
306
- // render condition for modal and drawer as we are not getting compType here
307
- if ( comp . children . hasOwnProperty ( 'showMask' ) && comp . children . hasOwnProperty ( 'maskClosable' ) ) {
308
- return (
309
- < HidableView hidden = { childrenProps . hidden as boolean } >
310
- { props . viewFn (
311
- childrenProps ,
312
- comp . dispatch
313
- ) }
314
- </ HidableView >
315
- ) ;
316
- }
297
+ const defaultChildren = useMemo ( ( ) => comp . children , [ comp . children ] ) ;
298
+ const isNotContainer = useMemo ( ( ) => Boolean ( defaultChildren . style ) , [ defaultChildren . style ] ) ;
299
+ const restrictPaddingOnRotation = useMemo ( ( ) => Boolean ( defaultChildren . restrictPaddingOnRotation ) , [ defaultChildren . restrictPaddingOnRotation ] ) ;
300
+ const rotationVal = useMemo ( ( ) => {
301
+ if ( isNotContainer ) {
302
+ return defaultChildren . style . children ?. rotation ?. valueAndMsg . value
303
+ }
304
+ return null ;
305
+ } , [ isNotContainer , defaultChildren . style . children ?. rotation ?. valueAndMsg . value ] ) ;
306
+ const boxShadowVal = useMemo ( ( ) => {
307
+ if ( isNotContainer ) {
308
+ return defaultChildren . style ?. children ?. boxShadow ?. valueAndMsg ?. value ;
309
+ }
310
+ return null ;
311
+ } , [ isNotContainer , defaultChildren . style ?. children ?. boxShadow ?. valueAndMsg ?. value ] ) ;
312
+ const restrictPaddingOnRotationVal = useMemo ( ( ) => {
313
+ if ( isNotContainer ) {
314
+ return defaultChildren ?. restrictPaddingOnRotation ?. valueAndMsg ?. value
315
+ }
316
+ return null ;
317
+ } , [ isNotContainer , defaultChildren ?. restrictPaddingOnRotation ?. valueAndMsg ?. value ] ) ;
317
318
318
- let defaultChildren = comp . children ;
319
- const isNotContainer = defaultChildren . hasOwnProperty ( 'style' ) ;
320
- const restrictPaddingOnRotation = defaultChildren . hasOwnProperty ( 'restrictPaddingOnRotation' ) ;
321
- let rotationVal :any = null
322
- let boxShadowVal :any = null ;
323
- let restrictPaddingOnRotationVal :any = null ;
324
- if ( isNotContainer ) {
325
- rotationVal = defaultChildren . style . children ?. rotation ?. valueAndMsg . value ;
326
- boxShadowVal = defaultChildren . style ?. children ?. boxShadow ?. valueAndMsg ?. value ;
327
- restrictPaddingOnRotationVal = defaultChildren ?. restrictPaddingOnRotation ?. valueAndMsg ?. value ;
328
- }
329
- const getPadding = ( ) => {
319
+ const getPadding = useCallback ( ( ) => {
330
320
if (
331
321
( rotationVal === null ||
332
322
rotationVal === undefined ||
@@ -386,9 +376,22 @@ const UIView = React.memo((props: {
386
376
} else {
387
377
return '0px' ; // Default value if neither rotation nor box-shadow is applied
388
378
}
389
- } ;
379
+ } , [
380
+ rotationVal ,
381
+ boxShadowVal ,
382
+ restrictPaddingOnRotationVal ,
383
+ restrictPaddingOnRotation ,
384
+ ] ) ;
390
385
391
- return (
386
+ // render condition for modal and drawer as we are not getting compType here
387
+
388
+ const uiCompRender = useMemo ( ( ) => props . viewFn ( childrenProps , comp . dispatch ) , [
389
+ childrenProps ,
390
+ comp . dispatch
391
+ ] ) ;
392
+
393
+ const uiCompRenderWithWrapper = useMemo ( ( ) => {
394
+ return (
392
395
< div
393
396
ref = { props . innerRef }
394
397
className = { childrenProps . className as string }
@@ -400,9 +403,27 @@ const UIView = React.memo((props: {
400
403
padding : getPadding ( )
401
404
} }
402
405
>
403
- < HidableView hidden = { childrenProps . hidden as boolean } >
404
- { props . viewFn ( childrenProps , comp . dispatch ) }
405
- </ HidableView >
406
+ { uiCompRender }
406
407
</ div >
407
- ) ;
408
+ ) } , [
409
+ uiCompRender ,
410
+ props . innerRef ,
411
+ childrenProps . className ,
412
+ childrenProps . dataTestId ,
413
+ getPadding ,
414
+ ] ) ;
415
+
416
+ const renderView = useMemo ( ( ) => {
417
+ if (
418
+ comp . children . hasOwnProperty ( 'showMask' )
419
+ && comp . children . hasOwnProperty ( 'maskClosable' )
420
+ ) {
421
+ return uiCompRender ;
422
+ }
423
+ return uiCompRenderWithWrapper ;
424
+ } , [ comp . children ] ) ;
425
+
426
+ return renderView ;
427
+ } , ( prevProps , nextProps ) => {
428
+ return isEqual ( prevProps , nextProps ) ;
408
429
} ) ;
0 commit comments