@@ -21,6 +21,9 @@ import { PaddingControl } from "../controls/paddingControl";
2121import React , { useContext , useEffect } from "react" ;
2222import { EditorContext } from "comps/editorState" ;
2323import { clickEvent , eventHandlerControl } from "../controls/eventHandlerControl" ;
24+ import { NewChildren } from "../generators/uiCompBuilder" ;
25+ import { RecordConstructorToComp } from "lowcoder-core" ;
26+ import { ToViewReturn } from "../generators/multi" ;
2427
2528const EventOptions = [ clickEvent ] as const ;
2629
@@ -130,87 +133,95 @@ const VerticalAlignmentOptions = [
130133{ label :< AlignVerticalCenter /> , value :"center" } ,
131134{ label :< AlignBottom /> , value :"flex-end" } ,
132135] as const ;
136+ const childrenMap = {
137+ text :stringExposingStateControl (
138+ "text" ,
139+ trans ( "textShow.text" , { name :"{{currentUser.name}}" } )
140+ ) ,
141+ onEvent :eventHandlerControl ( EventOptions ) ,
142+ autoHeight :AutoHeightControl ,
143+ type :dropdownControl ( typeOptions , "markdown" ) ,
144+ horizontalAlignment :alignWithJustifyControl ( ) ,
145+ verticalAlignment :dropdownControl ( VerticalAlignmentOptions , "center" ) ,
146+ style :styleControl ( TextStyle , 'style' ) ,
147+ animationStyle :styleControl ( AnimationStyle , 'animationStyle' ) ,
148+ margin :MarginControl ,
149+ padding :PaddingControl ,
150+ } ;
133151
134- let TextTmpComp = ( function ( ) {
135- const childrenMap = {
136- text :stringExposingStateControl (
137- "text" ,
138- trans ( "textShow.text" , { name :"{{currentUser.name}}" } )
139- ) ,
140- onEvent :eventHandlerControl ( EventOptions ) ,
141- autoHeight :AutoHeightControl ,
142- type :dropdownControl ( typeOptions , "markdown" ) ,
143- horizontalAlignment :alignWithJustifyControl ( ) ,
144- verticalAlignment :dropdownControl ( VerticalAlignmentOptions , "center" ) ,
145- style :styleControl ( TextStyle , 'style' ) ,
146- animationStyle :styleControl ( AnimationStyle , 'animationStyle' ) ,
147- margin :MarginControl ,
148- padding :PaddingControl ,
149- } ;
150- return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
151- const value = props . text . value ;
152-
153- return (
154- < TextContainer
155- $animationStyle = { props . animationStyle }
156- $type = { props . type }
157- $styleConfig = { props . style }
158- style = { {
159- justifyContent :props . horizontalAlignment ,
160- alignItems :props . autoHeight ?"center" :props . verticalAlignment ,
161- textAlign :props . horizontalAlignment ,
162- rotate :props . style . rotation
163- } }
164- onClick = { ( ) => props . onEvent ( "click" ) }
165- >
166- { props . type === "markdown" ?< TacoMarkDown > { value } </ TacoMarkDown > :value }
167- </ TextContainer >
168- ) ;
169- } )
170- . setPropertyViewFn ( ( children ) => {
171- return (
152+ type ChildrenType = NewChildren < RecordConstructorToComp < typeof childrenMap > > ;
153+
154+ const TextPropertyView = React . memo ( ( props :{
155+ children :ChildrenType
156+ } ) => {
157+ return (
158+ < >
159+ < Section name = { sectionNames . basic } >
160+ { props . children . type . propertyView ( {
161+ label :trans ( "value" ) ,
162+ tooltip :trans ( "textShow.valueTooltip" ) ,
163+ radioButton :true ,
164+ } ) }
165+ { props . children . text . propertyView ( { } ) }
166+ </ Section >
167+
168+ { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
169+ < Section name = { sectionNames . interaction } >
170+ { hiddenPropertyView ( props . children ) }
171+ { props . children . onEvent . getPropertyView ( ) }
172+ </ Section >
173+ ) }
174+
175+ { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
172176< >
173- < Section name = { sectionNames . basic } >
174- { children . type . propertyView ( {
175- label :trans ( "value" ) ,
176- tooltip :trans ( "textShow.valueTooltip" ) ,
177+ < Section name = { sectionNames . layout } >
178+ { props . children . autoHeight . getPropertyView ( ) }
179+ { ! props . children . autoHeight . getView ( ) &&
180+ props . children . verticalAlignment . propertyView ( {
181+ label :trans ( "textShow.verticalAlignment" ) ,
182+ radioButton :true ,
183+ } ) }
184+ { props . children . horizontalAlignment . propertyView ( {
185+ label :trans ( "textShow.horizontalAlignment" ) ,
177186radioButton :true ,
178187} ) }
179- { children . text . propertyView ( { } ) }
180188</ Section >
181-
182- { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
183- < Section name = { sectionNames . interaction } >
184- { hiddenPropertyView ( children ) }
185- { children . onEvent . getPropertyView ( ) }
186- </ Section >
187- ) }
188-
189- { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
190- < >
191- < Section name = { sectionNames . layout } >
192- { children . autoHeight . getPropertyView ( ) }
193- { ! children . autoHeight . getView ( ) &&
194- children . verticalAlignment . propertyView ( {
195- label :trans ( "textShow.verticalAlignment" ) ,
196- radioButton :true ,
197- } ) }
198- { children . horizontalAlignment . propertyView ( {
199- label :trans ( "textShow.horizontalAlignment" ) ,
200- radioButton :true ,
201- } ) }
202- </ Section >
203- < Section name = { sectionNames . style } >
204- { children . style . getPropertyView ( ) }
205- </ Section >
206- < Section name = { sectionNames . animationStyle } hasTooltip = { true } >
207- { children . animationStyle . getPropertyView ( ) }
208- </ Section >
209- </ >
210- ) }
189+ < Section name = { sectionNames . style } >
190+ { props . children . style . getPropertyView ( ) }
191+ </ Section >
192+ < Section name = { sectionNames . animationStyle } hasTooltip = { true } >
193+ { props . children . animationStyle . getPropertyView ( ) }
194+ </ Section >
211195</ >
212- ) ;
213- } )
196+ ) }
197+ </ >
198+ ) ;
199+ } )
200+
201+ const TextView = React . memo ( ( props :ToViewReturn < ChildrenType > ) => {
202+ const value = props . text . value ;
203+
204+ return (
205+ < TextContainer
206+ $animationStyle = { props . animationStyle }
207+ $type = { props . type }
208+ $styleConfig = { props . style }
209+ style = { {
210+ justifyContent :props . horizontalAlignment ,
211+ alignItems :props . autoHeight ?"center" :props . verticalAlignment ,
212+ textAlign :props . horizontalAlignment ,
213+ rotate :props . style . rotation
214+ } }
215+ onClick = { ( ) => props . onEvent ( "click" ) }
216+ >
217+ { props . type === "markdown" ?< TacoMarkDown > { value } </ TacoMarkDown > :value }
218+ </ TextContainer >
219+ ) ;
220+ } , ( prev , next ) => JSON . stringify ( prev ) === JSON . stringify ( next ) ) ;
221+
222+ let TextTmpComp = ( function ( ) {
223+ return new UICompBuilder ( childrenMap , ( props ) => < TextView { ...props } /> )
224+ . setPropertyViewFn ( ( children ) => < TextPropertyView children = { children } /> )
214225. build ( ) ;
215226} ) ( ) ;
216227