11import { 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" ;
33import { ExternalEditorContext } from "util/context/ExternalEditorContext" ;
44import { Comp , CompParams , MultiBaseComp } from "lowcoder-core" ;
55import {
@@ -28,7 +28,7 @@ import { BoolControl } from "../controls/boolControl";
2828import { valueComp , withDefault } from "./simpleGenerators" ;
2929import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils" ;
3030import { EditorContext } from "../editorState" ;
31- import { values } from "lodash" ;
31+ import { isEqual , values } from "lodash" ;
3232import { UICompType , uiCompRegistry } from "../uiCompRegistry" ;
3333import { getNpmPackageMeta } from "../utils/remote" ;
3434import { compPluginsList } from "constants/compPluginConstants" ;
@@ -289,44 +289,34 @@ const UIView = React.memo((props: {
289289childrenProps [ 'disabled' ] = disabled || parentDisabled ;
290290}
291291
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-
301292useMergeCompStyles (
302293childrenJsonProps as Record < string , any > ,
303294comp . dispatch
304295) ;
305296
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 ] ) ;
317318
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 ( ( ) => {
330320if (
331321( rotationVal === null ||
332322rotationVal === undefined ||
@@ -386,9 +376,22 @@ const UIView = React.memo((props: {
386376} else {
387377return '0px' ; // Default value if neither rotation nor box-shadow is applied
388378}
389- } ;
379+ } , [
380+ rotationVal ,
381+ boxShadowVal ,
382+ restrictPaddingOnRotationVal ,
383+ restrictPaddingOnRotation ,
384+ ] ) ;
390385
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 (
392395< div
393396ref = { props . innerRef }
394397className = { childrenProps . className as string }
@@ -400,9 +403,27 @@ const UIView = React.memo((props: {
400403padding :getPadding ( )
401404} }
402405>
403- < HidableView hidden = { childrenProps . hidden as boolean } >
404- { props . viewFn ( childrenProps , comp . dispatch ) }
405- </ HidableView >
406+ { uiCompRender }
406407</ 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 ) ;
408429} ) ;