1
- import { BoolControl } from ' comps/controls/boolControl' ;
2
- import { check } from ' util/convertUtils' ;
1
+ import { BoolControl } from " comps/controls/boolControl" ;
2
+ import { check } from " util/convertUtils" ;
3
3
import {
4
4
BoolCodeControl ,
5
5
CustomRuleControl ,
6
6
NumberControl ,
7
7
RegexControl ,
8
8
StringControl ,
9
- } from 'comps/controls/codeControl' ;
10
- import { stringExposingStateControl } from 'comps/controls/codeStateControl' ;
11
- import { LabelControl } from 'comps/controls/labelControl' ;
12
- import {
13
- InputLikeStyleType ,
14
- LabelStyleType ,
15
- heightCalculator ,
16
- widthCalculator ,
17
- } from 'comps/controls/styleControlConstants' ;
18
- import { Section , sectionNames , ValueFromOption } from 'lowcoder-design' ;
19
- import _ from 'lodash' ;
20
- import { css } from 'styled-components' ;
21
- import { EMAIL_PATTERN , URL_PATTERN } from 'util/stringUtils' ;
22
- import {
23
- MultiBaseComp ,
24
- RecordConstructorToComp ,
25
- RecordConstructorToView ,
26
- } from 'lowcoder-core' ;
27
- import { dropdownControl } from '../../controls/dropdownControl' ;
28
- import { InputEventHandlerControl } from '../../controls/eventHandlerControl' ;
9
+ } from "comps/controls/codeControl" ;
10
+ import { stringExposingStateControl } from "comps/controls/codeStateControl" ;
11
+ import { LabelControl } from "comps/controls/labelControl" ;
12
+ import { InputLikeStyleType , LabelStyleType , heightCalculator , widthCalculator } from "comps/controls/styleControlConstants" ;
13
+ import { Section , sectionNames , ValueFromOption } from "lowcoder-design" ;
14
+ import _ from "lodash" ;
15
+ import { css } from "styled-components" ;
16
+ import { EMAIL_PATTERN , URL_PATTERN } from "util/stringUtils" ;
17
+ import { MultiBaseComp , RecordConstructorToComp , RecordConstructorToView } from "lowcoder-core" ;
18
+ import { dropdownControl } from "../../controls/dropdownControl" ;
19
+ import { InputEventHandlerControl } from "../../controls/eventHandlerControl" ;
29
20
import {
30
21
ChildrenTypeToDepsKeys ,
31
22
CommonNameConfig ,
32
23
depsConfig ,
33
- } from ' ../../generators/withExposing' ;
34
- import { formDataChildren } from ' ../formComp/formDataConstants' ;
24
+ } from " ../../generators/withExposing" ;
25
+ import { formDataChildren } from " ../formComp/formDataConstants" ;
35
26
import {
36
27
disabledPropertyView ,
37
28
maxLengthPropertyView ,
38
29
minLengthPropertyView ,
39
30
placeholderPropertyView ,
40
31
regexPropertyView ,
41
32
requiredPropertyView ,
42
- } from ' comps/utils/propertyUtils' ;
43
- import { trans } from ' i18n' ;
44
- import { ChangeEvent , useEffect , useRef , useState } from ' react' ;
45
- import { refMethods } from ' comps/generators/withMethodExposing' ;
46
- import { InputRef } from ' antd/es/input' ;
33
+ } from " comps/utils/propertyUtils" ;
34
+ import { trans } from " i18n" ;
35
+ import { ChangeEvent , useEffect , useRef , useState } from " react" ;
36
+ import { refMethods } from " comps/generators/withMethodExposing" ;
37
+ import { InputRef } from " antd/es/input" ;
47
38
import {
48
39
blurMethod ,
49
40
clickMethod ,
50
41
focusWithOptions ,
51
42
selectMethod ,
52
43
setRangeTextMethod ,
53
44
setSelectionRangeMethod ,
54
- } from ' comps/utils/methodUtils' ;
55
- import { RefControl } from ' comps/controls/refControl' ;
56
- import { EvalParamType } from ' comps/controls/actionSelector/executeCompTypes' ;
45
+ } from " comps/utils/methodUtils" ;
46
+ import { RefControl } from " comps/controls/refControl" ;
47
+ import { EvalParamType } from " comps/controls/actionSelector/executeCompTypes" ;
57
48
58
49
export const TextInputValidationOptions = [
59
50
{
60
- label : ' Text' ,
61
- value : ' Text' ,
51
+ label : " Text" ,
52
+ value : " Text" ,
62
53
extra : / .* / ,
63
- help : '' ,
54
+ help : "" ,
64
55
} ,
65
56
{
66
- label : ' Email' ,
67
- value : ' Email' ,
57
+ label : " Email" ,
58
+ value : " Email" ,
68
59
extra : EMAIL_PATTERN ,
69
- help : trans ( ' validationDesc.email' ) ,
60
+ help : trans ( " validationDesc.email" ) ,
70
61
} ,
71
62
{
72
- label : ' URL' ,
73
- value : ' URL' ,
63
+ label : " URL" ,
64
+ value : " URL" ,
74
65
extra : URL_PATTERN ,
75
- help : trans ( ' validationDesc.url' ) ,
66
+ help : trans ( " validationDesc.url" ) ,
76
67
} ,
77
68
{
78
- label : ' Regex' ,
79
- value : ' Regex' ,
69
+ label : " Regex" ,
70
+ value : " Regex" ,
80
71
extra : undefined ,
81
- help : trans ( ' validationDesc.regex' ) ,
72
+ help : trans ( " validationDesc.regex" ) ,
82
73
} ,
83
74
] as const ;
84
75
85
76
type ValidationParams = {
86
- value : { value : string } ;
77
+ value : { value : string } ;
87
78
required : boolean ;
88
79
minLength : number ;
89
80
maxLength : number ;
@@ -99,69 +90,52 @@ const valueInfoMap = _.fromPairs(
99
90
export const textInputValidate = (
100
91
props : ValidationParams
101
92
) : {
102
- validateStatus : ' success' | ' warning' | ' error' | '' ;
93
+ validateStatus : " success" | " warning" | " error" | "" ;
103
94
help ?: string ;
104
95
} => {
105
96
if ( props . customRule ) {
106
- return { validateStatus : ' error' , help : props . customRule } ;
97
+ return { validateStatus : " error" , help : props . customRule } ;
107
98
}
108
99
const value = props . value . value ;
109
100
if ( props . required && value . length === 0 ) {
110
- return { validateStatus : ' error' , help : trans ( ' prop.required' ) } ;
101
+ return { validateStatus : " error" , help : trans ( " prop.required" ) } ;
111
102
}
112
103
if ( props . maxLength > 0 && value . length > props . maxLength ) {
113
104
return {
114
- validateStatus : 'error' ,
115
- help : trans ( 'validationDesc.maxLength' , {
116
- length : value . length ,
117
- maxLength : props . maxLength ,
118
- } ) ,
105
+ validateStatus : "error" ,
106
+ help : trans ( "validationDesc.maxLength" , { length : value . length , maxLength : props . maxLength } ) ,
119
107
} ;
120
108
}
121
109
if ( props . minLength > 0 && value . length < props . minLength ) {
122
110
return {
123
- validateStatus : 'error' ,
124
- help : trans ( 'validationDesc.minLength' , {
125
- length : value . length ,
126
- minLength : props . minLength ,
127
- } ) ,
111
+ validateStatus : "error" ,
112
+ help : trans ( "validationDesc.minLength" , { length : value . length , minLength : props . minLength } ) ,
128
113
} ;
129
114
}
130
115
const optionValue = props . validationType ;
131
116
const regex : RegExp = valueInfoMap [ optionValue ] ?. extra ?? props . regex ; // pass if empty by default
132
117
if ( value && ! regex . test ( value ) ) {
133
- return { validateStatus : ' error' , help : valueInfoMap [ optionValue ] . help } ;
118
+ return { validateStatus : " error" , help : valueInfoMap [ optionValue ] . help } ;
134
119
}
135
- return { validateStatus : '' } ;
120
+ return { validateStatus : "" } ;
136
121
} ;
137
122
138
- const TextInputInvalidConfig = depsConfig <
139
- TextInputComp ,
140
- ChildrenTypeToDepsKeys < TextInputComp >
141
- > ( {
142
- name : 'invalid' ,
143
- desc : trans ( 'export.invalidDesc' ) ,
144
- depKeys : [
145
- 'value' ,
146
- 'required' ,
147
- 'minLength' ,
148
- 'maxLength' ,
149
- 'validationType' ,
150
- 'regex' ,
151
- 'customRule' ,
152
- ] ,
123
+ const TextInputInvalidConfig = depsConfig < TextInputComp , ChildrenTypeToDepsKeys < TextInputComp > > ( {
124
+ name : "invalid" ,
125
+ desc : trans ( "export.invalidDesc" ) ,
126
+ depKeys : [ "value" , "required" , "minLength" , "maxLength" , "validationType" , "regex" , "customRule" ] ,
153
127
func : ( input ) =>
154
128
textInputValidate ( {
155
129
...input ,
156
- value : { value : input . value } ,
157
- } ) . validateStatus !== '' ,
130
+ value : { value : input . value } ,
131
+ } ) . validateStatus !== "" ,
158
132
} ) ;
159
133
160
134
export const TextInputConfigs = [ TextInputInvalidConfig , ...CommonNameConfig ] ;
161
135
162
136
export const textInputChildren = {
163
- defaultValue : stringExposingStateControl ( ' defaultValue' ) ,
164
- value : stringExposingStateControl ( ' value' ) ,
137
+ defaultValue : stringExposingStateControl ( " defaultValue" ) ,
138
+ value : stringExposingStateControl ( " value" ) ,
165
139
disabled : BoolCodeControl ,
166
140
label : LabelControl ,
167
141
placeholder : StringControl ,
@@ -172,41 +146,36 @@ export const textInputChildren = {
172
146
required : BoolControl ,
173
147
minLength : NumberControl ,
174
148
maxLength : NumberControl ,
175
- validationType : dropdownControl ( TextInputValidationOptions , ' Text' ) ,
149
+ validationType : dropdownControl ( TextInputValidationOptions , " Text" ) ,
176
150
regex : RegexControl ,
177
151
customRule : CustomRuleControl ,
178
152
179
153
...formDataChildren ,
180
154
} ;
181
155
182
- export const textInputProps = (
183
- props : RecordConstructorToView < typeof textInputChildren >
184
- ) => ( {
156
+ export const textInputProps = ( props : RecordConstructorToView < typeof textInputChildren > ) => ( {
185
157
disabled : props . disabled ,
186
158
readOnly : props . readOnly ,
187
159
placeholder : props . placeholder ,
188
160
defaultValue : props . defaultValue . value ,
189
161
value : props . value . value ,
190
- onFocus : ( ) => props . onEvent ( ' focus' ) ,
191
- onBlur : ( ) => props . onEvent ( ' blur' ) ,
192
- onPressEnter : ( ) => props . onEvent ( ' submit' ) ,
162
+ onFocus : ( ) => props . onEvent ( " focus" ) ,
163
+ onBlur : ( ) => props . onEvent ( " blur" ) ,
164
+ onPressEnter : ( ) => props . onEvent ( " submit" ) ,
193
165
} ) ;
194
166
195
- export const useTextInputProps = (
196
- props : RecordConstructorToView < typeof textInputChildren >
197
- ) => {
167
+ export const useTextInputProps = ( props : RecordConstructorToView < typeof textInputChildren > ) => {
198
168
const [ validateState , setValidateState ] = useState ( { } ) ;
199
- const changeRef = useRef ( false ) ;
169
+ const changeRef = useRef ( false )
200
170
201
- const propsRef =
202
- useRef < RecordConstructorToView < typeof textInputChildren > > ( props ) ;
171
+ const propsRef = useRef < RecordConstructorToView < typeof textInputChildren > > ( props ) ;
203
172
propsRef . current = props ;
204
173
205
- const defaultValue = { ...props . defaultValue } . value ;
206
- const inputValue = { ...props . value } . value ;
174
+ const defaultValue = { ...props . defaultValue } . value ;
175
+ const inputValue = { ...props . value } . value ;
207
176
208
177
useEffect ( ( ) => {
209
- props . value . onChange ( defaultValue ) ;
178
+ props . value . onChange ( defaultValue )
210
179
} , [ defaultValue ] ) ;
211
180
212
181
useEffect ( ( ) => {
@@ -220,7 +189,7 @@ export const useTextInputProps = (
220
189
} ,
221
190
} )
222
191
) ;
223
- propsRef . current . onEvent ( ' change' ) ;
192
+ propsRef . current . onEvent ( " change" ) ;
224
193
changeRef . current = false ;
225
194
} , [ inputValue ] ) ;
226
195
@@ -242,7 +211,7 @@ type TextInputComp = RecordConstructorToComp<typeof textInputChildren>;
242
211
243
212
export const TextInputBasicSection = ( children : TextInputComp ) => (
244
213
< Section name = { sectionNames . basic } >
245
- { children . defaultValue . propertyView ( { label : trans ( ' prop.defaultValue' ) } ) }
214
+ { children . defaultValue . propertyView ( { label : trans ( " prop.defaultValue" ) } ) }
246
215
{ placeholderPropertyView ( children ) }
247
216
</ Section >
248
217
) ;
@@ -257,7 +226,7 @@ export const TextInputInteractionSection = (children: TextInputComp) => (
257
226
export const TextInputValidationSection = ( children : TextInputComp ) => (
258
227
< Section name = { sectionNames . validation } >
259
228
{ requiredPropertyView ( children ) }
260
- { children . validationType . propertyView ( { label : trans ( ' prop.textType' ) } ) }
229
+ { children . validationType . propertyView ( { label : trans ( " prop.textType" ) } ) }
261
230
{ valueInfoMap [ children . validationType . getView ( ) ] ?. extra === undefined &&
262
231
regexPropertyView ( children ) }
263
232
{ minLengthPropertyView ( children ) }
@@ -266,25 +235,21 @@ export const TextInputValidationSection = (children: TextInputComp) => (
266
235
</ Section >
267
236
) ;
268
237
269
- export function getStyle (
270
- style : InputLikeStyleType ,
271
- labelStyle ?: LabelStyleType
272
- ) {
238
+ export function getStyle ( style : InputLikeStyleType , labelStyle ?: LabelStyleType ) {
273
239
return css `
274
240
border-radius : ${ style . radius } ;
275
241
border-width : ${ style . borderWidth } ;
276
- padding : ${ style . padding } ;
277
- rotate : ${ style . rotation } ;
242
+ padding : ${ style . padding } ;
278
243
// still use antd style when disabled
279
244
& : not (.ant-input-disabled , .ant-input-affix-wrapper-disabled ),
280
245
input {
281
246
color : ${ style . text } ;
282
247
font-size : ${ style . textSize } ;
283
248
font-weight : ${ style . textWeight } ;
284
249
font-family : ${ style . fontFamily } ;
285
- font-style : ${ style . fontStyle } ;
286
- text-transform : ${ style . textTransform } ;
287
- text-decoration : ${ style . textDecoration } ;
250
+ font-style : ${ style . fontStyle } ;
251
+ text-transform : ${ style . textTransform } ;
252
+ text-decoration : ${ style . textDecoration } ;
288
253
background-color : ${ style . background } ;
289
254
border-color : ${ style . border } ;
290
255
@@ -317,38 +282,28 @@ export function getStyle(
317
282
}
318
283
319
284
export const inputRefMethods = [
320
- ...refMethods < InputRef > ( [
321
- focusWithOptions ,
322
- blurMethod ,
323
- selectMethod ,
324
- setSelectionRangeMethod ,
325
- ] ) ,
285
+ ...refMethods < InputRef > ( [ focusWithOptions , blurMethod , selectMethod , setSelectionRangeMethod ] ) ,
326
286
{
327
287
method : clickMethod ,
328
- execute : (
329
- comp : MultiBaseComp < { viewRef : RefControl < InputRef > } > ,
330
- params : EvalParamType [ ]
331
- ) => comp . children . viewRef . viewRef ?. input ?. click ( ) ,
288
+ execute : ( comp : MultiBaseComp < { viewRef : RefControl < InputRef > } > , params : EvalParamType [ ] ) =>
289
+ comp . children . viewRef . viewRef ?. input ?. click ( ) ,
332
290
} ,
333
291
{
334
292
method : setRangeTextMethod ,
335
- execute : (
336
- comp : MultiBaseComp < { viewRef : RefControl < InputRef > } > ,
337
- params : EvalParamType [ ]
338
- ) =>
293
+ execute : ( comp : MultiBaseComp < { viewRef : RefControl < InputRef > } > , params : EvalParamType [ ] ) =>
339
294
( comp . children . viewRef . viewRef ?. input ?. setRangeText as any ) ?.( ...params ) ,
340
295
} ,
341
296
] ;
342
297
343
298
export function checkMentionListData ( data : any ) {
344
- if ( data === '' ) return { } ;
299
+ if ( data === "" ) return { }
345
300
for ( const key in data ) {
346
- check ( data [ key ] , [ ' array' ] , key , ( node ) => {
347
- check ( node , [ ' string' ] ) ;
348
- return node ;
349
- } ) ;
301
+ check ( data [ key ] , [ " array" ] , key , ( node ) => {
302
+ check ( node , [ " string" ] , ) ;
303
+ return node
304
+ } )
350
305
}
351
- return data ;
306
+ return data
352
307
}
353
308
354
309
// separate defaultValue and value for old components
0 commit comments