Skip to content

Commit 0b94808

Browse files
committed
formating removed-77
1 parent 23ed72f commit 0b94808

File tree

1 file changed

+82
-127
lines changed

1 file changed

+82
-127
lines changed

client/packages/lowcoder/src/comps/comps/textInputComp/textInputConstants.tsx

Lines changed: 82 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,80 @@
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";
33
import {
44
BoolCodeControl,
55
CustomRuleControl,
66
NumberControl,
77
RegexControl,
88
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";
2920
import {
3021
ChildrenTypeToDepsKeys,
3122
CommonNameConfig,
3223
depsConfig,
33-
} from '../../generators/withExposing';
34-
import {formDataChildren} from '../formComp/formDataConstants';
24+
} from "../../generators/withExposing";
25+
import { formDataChildren } from "../formComp/formDataConstants";
3526
import {
3627
disabledPropertyView,
3728
maxLengthPropertyView,
3829
minLengthPropertyView,
3930
placeholderPropertyView,
4031
regexPropertyView,
4132
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";
4738
import {
4839
blurMethod,
4940
clickMethod,
5041
focusWithOptions,
5142
selectMethod,
5243
setRangeTextMethod,
5344
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";
5748

5849
export const TextInputValidationOptions = [
5950
{
60-
label: 'Text',
61-
value: 'Text',
51+
label: "Text",
52+
value: "Text",
6253
extra: /.*/,
63-
help: '',
54+
help: "",
6455
},
6556
{
66-
label: 'Email',
67-
value: 'Email',
57+
label: "Email",
58+
value: "Email",
6859
extra: EMAIL_PATTERN,
69-
help: trans('validationDesc.email'),
60+
help: trans("validationDesc.email"),
7061
},
7162
{
72-
label: 'URL',
73-
value: 'URL',
63+
label: "URL",
64+
value: "URL",
7465
extra: URL_PATTERN,
75-
help: trans('validationDesc.url'),
66+
help: trans("validationDesc.url"),
7667
},
7768
{
78-
label: 'Regex',
79-
value: 'Regex',
69+
label: "Regex",
70+
value: "Regex",
8071
extra: undefined,
81-
help: trans('validationDesc.regex'),
72+
help: trans("validationDesc.regex"),
8273
},
8374
] as const;
8475

8576
type ValidationParams = {
86-
value: {value: string};
77+
value: { value: string };
8778
required: boolean;
8879
minLength: number;
8980
maxLength: number;
@@ -99,69 +90,52 @@ const valueInfoMap = _.fromPairs(
9990
export const textInputValidate = (
10091
props: ValidationParams
10192
): {
102-
validateStatus: 'success' | 'warning' | 'error' | '';
93+
validateStatus: "success" | "warning" | "error" | "";
10394
help?: string;
10495
} => {
10596
if (props.customRule) {
106-
return {validateStatus: 'error', help: props.customRule};
97+
return { validateStatus: "error", help: props.customRule };
10798
}
10899
const value = props.value.value;
109100
if (props.required && value.length === 0) {
110-
return {validateStatus: 'error', help: trans('prop.required')};
101+
return { validateStatus: "error", help: trans("prop.required") };
111102
}
112103
if (props.maxLength > 0 && value.length > props.maxLength) {
113104
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 }),
119107
};
120108
}
121109
if (props.minLength > 0 && value.length < props.minLength) {
122110
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 }),
128113
};
129114
}
130115
const optionValue = props.validationType;
131116
const regex: RegExp = valueInfoMap[optionValue]?.extra ?? props.regex; // pass if empty by default
132117
if (value && !regex.test(value)) {
133-
return {validateStatus: 'error', help: valueInfoMap[optionValue].help};
118+
return { validateStatus: "error", help: valueInfoMap[optionValue].help };
134119
}
135-
return {validateStatus: ''};
120+
return { validateStatus: "" };
136121
};
137122

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"],
153127
func: (input) =>
154128
textInputValidate({
155129
...input,
156-
value: {value: input.value},
157-
}).validateStatus !== '',
130+
value: { value: input.value },
131+
}).validateStatus !== "",
158132
});
159133

160134
export const TextInputConfigs = [TextInputInvalidConfig, ...CommonNameConfig];
161135

162136
export const textInputChildren = {
163-
defaultValue: stringExposingStateControl('defaultValue'),
164-
value: stringExposingStateControl('value'),
137+
defaultValue: stringExposingStateControl("defaultValue"),
138+
value: stringExposingStateControl("value"),
165139
disabled: BoolCodeControl,
166140
label: LabelControl,
167141
placeholder: StringControl,
@@ -172,41 +146,36 @@ export const textInputChildren = {
172146
required: BoolControl,
173147
minLength: NumberControl,
174148
maxLength: NumberControl,
175-
validationType: dropdownControl(TextInputValidationOptions, 'Text'),
149+
validationType: dropdownControl(TextInputValidationOptions, "Text"),
176150
regex: RegexControl,
177151
customRule: CustomRuleControl,
178152

179153
...formDataChildren,
180154
};
181155

182-
export const textInputProps = (
183-
props: RecordConstructorToView<typeof textInputChildren>
184-
) => ({
156+
export const textInputProps = (props: RecordConstructorToView<typeof textInputChildren>) => ({
185157
disabled: props.disabled,
186158
readOnly: props.readOnly,
187159
placeholder: props.placeholder,
188160
defaultValue: props.defaultValue.value,
189161
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"),
193165
});
194166

195-
export const useTextInputProps = (
196-
props: RecordConstructorToView<typeof textInputChildren>
197-
) => {
167+
export const useTextInputProps = (props: RecordConstructorToView<typeof textInputChildren>) => {
198168
const [validateState, setValidateState] = useState({});
199-
const changeRef = useRef(false);
169+
const changeRef = useRef(false)
200170

201-
const propsRef =
202-
useRef<RecordConstructorToView<typeof textInputChildren>>(props);
171+
const propsRef = useRef<RecordConstructorToView<typeof textInputChildren>>(props);
203172
propsRef.current = props;
204173

205-
const defaultValue = {...props.defaultValue}.value;
206-
const inputValue = {...props.value}.value;
174+
const defaultValue = { ...props.defaultValue }.value;
175+
const inputValue = { ...props.value }.value;
207176

208177
useEffect(() => {
209-
props.value.onChange(defaultValue);
178+
props.value.onChange(defaultValue)
210179
}, [defaultValue]);
211180

212181
useEffect(() => {
@@ -220,7 +189,7 @@ export const useTextInputProps = (
220189
},
221190
})
222191
);
223-
propsRef.current.onEvent('change');
192+
propsRef.current.onEvent("change");
224193
changeRef.current = false;
225194
}, [inputValue]);
226195

@@ -242,7 +211,7 @@ type TextInputComp = RecordConstructorToComp<typeof textInputChildren>;
242211

243212
export const TextInputBasicSection = (children: TextInputComp) => (
244213
<Section name={sectionNames.basic}>
245-
{children.defaultValue.propertyView({label: trans('prop.defaultValue')})}
214+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
246215
{placeholderPropertyView(children)}
247216
</Section>
248217
);
@@ -257,7 +226,7 @@ export const TextInputInteractionSection = (children: TextInputComp) => (
257226
export const TextInputValidationSection = (children: TextInputComp) => (
258227
<Section name={sectionNames.validation}>
259228
{requiredPropertyView(children)}
260-
{children.validationType.propertyView({label: trans('prop.textType')})}
229+
{children.validationType.propertyView({ label: trans("prop.textType") })}
261230
{valueInfoMap[children.validationType.getView()]?.extra === undefined &&
262231
regexPropertyView(children)}
263232
{minLengthPropertyView(children)}
@@ -266,25 +235,21 @@ export const TextInputValidationSection = (children: TextInputComp) => (
266235
</Section>
267236
);
268237

269-
export function getStyle(
270-
style: InputLikeStyleType,
271-
labelStyle?: LabelStyleType
272-
) {
238+
export function getStyle(style: InputLikeStyleType, labelStyle?: LabelStyleType) {
273239
return css`
274240
border-radius: ${style.radius};
275241
border-width: ${style.borderWidth};
276-
padding: ${style.padding};
277-
rotate: ${style.rotation};
242+
padding: ${style.padding};
278243
// still use antd style when disabled
279244
&:not(.ant-input-disabled, .ant-input-affix-wrapper-disabled),
280245
input {
281246
color: ${style.text};
282247
font-size: ${style.textSize};
283248
font-weight: ${style.textWeight};
284249
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};
288253
background-color: ${style.background};
289254
border-color: ${style.border};
290255
@@ -317,38 +282,28 @@ export function getStyle(
317282
}
318283

319284
export const inputRefMethods = [
320-
...refMethods<InputRef>([
321-
focusWithOptions,
322-
blurMethod,
323-
selectMethod,
324-
setSelectionRangeMethod,
325-
]),
285+
...refMethods<InputRef>([focusWithOptions, blurMethod, selectMethod, setSelectionRangeMethod]),
326286
{
327287
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(),
332290
},
333291
{
334292
method: setRangeTextMethod,
335-
execute: (
336-
comp: MultiBaseComp<{viewRef: RefControl<InputRef>}>,
337-
params: EvalParamType[]
338-
) =>
293+
execute: (comp: MultiBaseComp<{ viewRef: RefControl<InputRef> }>, params: EvalParamType[]) =>
339294
(comp.children.viewRef.viewRef?.input?.setRangeText as any)?.(...params),
340295
},
341296
];
342297

343298
export function checkMentionListData(data: any) {
344-
if (data === '') return {};
299+
if (data === "") return {}
345300
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+
})
350305
}
351-
return data;
306+
return data
352307
}
353308

354309
// separate defaultValue and value for old components

0 commit comments

Comments
 (0)