x-ui-design 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/types/components/Checkbox/Checkbox.client.d.ts +9 -9
- package/dist/esm/types/index.d.ts +0 -4
- package/dist/index.d.ts +2 -111
- package/dist/index.esm.js +42 -553
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -555
- package/dist/index.js.map +1 -1
- package/lib/components/Checkbox/Checkbox.client.tsx +1 -1
- package/lib/components/Checkbox/Checkbox.tsx +1 -1
- package/lib/index.ts +4 -4
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React$1, {
|
|
1
|
+
import React$1, { forwardRef, useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function styleInject(css, ref) {
|
|
4
4
|
if (ref === void 0) ref = {};
|
|
@@ -25,531 +25,13 @@ function styleInject(css, ref) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
var css_248z$
|
|
29
|
-
styleInject(css_248z$
|
|
30
|
-
|
|
31
|
-
function _extends() {
|
|
32
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
33
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
34
|
-
var t = arguments[e];
|
|
35
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
36
|
-
}
|
|
37
|
-
return n;
|
|
38
|
-
}, _extends.apply(null, arguments);
|
|
39
|
-
}
|
|
28
|
+
var css_248z$3 = ":root{--xui-color-hover:#f5f5f5;--xui-color-disabled:#e6e6e6;--xui-primary-color:#1677ff;--xui-primary-color-light:#40a9ff;--xui-text-color:rgba(0,0,0,.88);--xui-text-color-light:rgba(0,0,0,.5);--xui-error-color:#ff4d4f;--xui-error-color-light:#ff6668;--xui-success-color:#52c41a;--xui-background-color:#fff;--xui-font-size-xs:12px;--xui-font-size-sm:14px;--xui-font-size-md:14px;--xui-font-size-lg:16px;--xui-border-radius-sm:4px;--xui-border-radius-md:4px;--xui-border-radius-lg:6px;--xui-border-color:#d9d9d9;--xui-select-primary-color:var(--xui-primary-color);--xui-select-background-color:var(--xui-background-color)}html{font-family:sans-serif}.globalEllipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
|
|
29
|
+
styleInject(css_248z$3);
|
|
40
30
|
|
|
41
|
-
const prefixClsForm = 'xUi-form';
|
|
42
|
-
const prefixClsFormItem = 'xUi-form-item';
|
|
43
31
|
const prefixClsEmpty = 'xUi-empty';
|
|
44
32
|
const prefixClsCheckbox = 'xUi-checkbox';
|
|
45
33
|
const prefixClsButton = 'xUi-button';
|
|
46
34
|
|
|
47
|
-
function clsx(...args) {
|
|
48
|
-
return args.flatMap(arg => {
|
|
49
|
-
if (!arg) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
if (typeof arg === 'string') {
|
|
53
|
-
return [arg];
|
|
54
|
-
}
|
|
55
|
-
if (typeof arg === 'number') {
|
|
56
|
-
return [String(arg)];
|
|
57
|
-
}
|
|
58
|
-
if (Array.isArray(arg)) {
|
|
59
|
-
return clsx(...arg).split(' ');
|
|
60
|
-
}
|
|
61
|
-
if (typeof arg === 'object') {
|
|
62
|
-
return Object.entries(arg).filter(([, value]) => Boolean(value)).map(([key]) => key);
|
|
63
|
-
}
|
|
64
|
-
return [];
|
|
65
|
-
}).filter(Boolean).join(' ');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var css_248z$3 = ".xUi-form-item{display:flex;margin-bottom:10px;position:relative}.xUi-form-item.noStyle{display:inline-flex;margin-bottom:0}.xUi-form-item-label{align-items:center;color:var(--xui-text-color);display:flex;font-size:var(--xui-font-size-md);font-weight:500;line-height:20px;margin-bottom:4px}.xUi-form-item-error{bottom:-6px;color:var(--xui-error-color);font-size:var(--xui-font-size-xs);line-height:16px;position:absolute;right:0;user-select:none}.xUi-form-item-required{color:var(--xui-error-color);display:inline-block;font-size:var(--xui-font-size-md);line-height:1;margin-left:4px;margin-right:4px}.xUi-form-item.horizontal{align-items:center;flex-direction:row;gap:4px}.xUi-form-item.vertical{align-self:flex-start;flex-direction:column}.xUi-form-item .xUi-input-container{margin-bottom:12px!important;width:-webkit-fill-available}.xUi-form-item .xUi-datepicker-container{margin-bottom:10px}";
|
|
69
|
-
styleInject(css_248z$3);
|
|
70
|
-
|
|
71
|
-
const REF_CLIENT_HEIGHT = 24;
|
|
72
|
-
const FormItemClient = ({
|
|
73
|
-
prefixCls = prefixClsFormItem,
|
|
74
|
-
name,
|
|
75
|
-
label,
|
|
76
|
-
rules = [],
|
|
77
|
-
children,
|
|
78
|
-
className = '',
|
|
79
|
-
layout = 'vertical',
|
|
80
|
-
style = {},
|
|
81
|
-
valuePropName,
|
|
82
|
-
dependencies = [],
|
|
83
|
-
initialValue,
|
|
84
|
-
feedbackIcons,
|
|
85
|
-
...props
|
|
86
|
-
}) => {
|
|
87
|
-
const formContext = useContext(FormContext);
|
|
88
|
-
const errorRef = useRef(null);
|
|
89
|
-
if (!formContext) {
|
|
90
|
-
throw new Error('FormItem must be used within a Form');
|
|
91
|
-
}
|
|
92
|
-
const {
|
|
93
|
-
isReseting,
|
|
94
|
-
registerField,
|
|
95
|
-
getFieldError,
|
|
96
|
-
getFieldValue,
|
|
97
|
-
setFieldValue,
|
|
98
|
-
getFieldInstance,
|
|
99
|
-
subscribeToFields,
|
|
100
|
-
validateFields
|
|
101
|
-
} = formContext;
|
|
102
|
-
const childrenList = useMemo(() => (Array.isArray(children) ? children : [children]).filter(Boolean), [children]);
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (name && !getFieldInstance(name)) {
|
|
105
|
-
registerField(name, rules);
|
|
106
|
-
}
|
|
107
|
-
}, [name, rules]);
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
if (initialValue) {
|
|
110
|
-
setFieldValue(name, initialValue);
|
|
111
|
-
}
|
|
112
|
-
}, []);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
if (name && dependencies.length > 0) {
|
|
115
|
-
const unsubscribe = subscribeToFields(dependencies, () => {
|
|
116
|
-
validateFields([name]);
|
|
117
|
-
});
|
|
118
|
-
return () => {
|
|
119
|
-
unsubscribe();
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}, [dependencies, name]);
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (errorRef.current && errorRef.current?.clientHeight >= REF_CLIENT_HEIGHT) {
|
|
125
|
-
errorRef.current.style.position = 'relative';
|
|
126
|
-
errorRef.current.style.marginTop = '-16px';
|
|
127
|
-
}
|
|
128
|
-
}, [errorRef.current]);
|
|
129
|
-
const isRequired = useMemo(() => rules.some(rule => rule.required), [rules]);
|
|
130
|
-
const errorMessage = getFieldError(valuePropName || name)?.[0];
|
|
131
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
132
|
-
style: style,
|
|
133
|
-
className: clsx([`${prefixCls}`, {
|
|
134
|
-
[layout]: layout,
|
|
135
|
-
[className]: className,
|
|
136
|
-
noStyle: props.noStyle
|
|
137
|
-
}])
|
|
138
|
-
}, !props.noStyle && (label || name) && /*#__PURE__*/React.createElement("label", {
|
|
139
|
-
className: `${prefixCls}-label`,
|
|
140
|
-
htmlFor: name
|
|
141
|
-
}, label || name, ":", isRequired && /*#__PURE__*/React.createElement("span", {
|
|
142
|
-
className: `${prefixCls}-required`
|
|
143
|
-
}, "*")), Children.map(childrenList, (child, key) => {
|
|
144
|
-
if (/*#__PURE__*/isValidElement(child) && child.type !== Fragment) {
|
|
145
|
-
const {
|
|
146
|
-
value,
|
|
147
|
-
...childProps
|
|
148
|
-
} = child.props;
|
|
149
|
-
const fieldValue = getFieldValue(valuePropName || name) ?? initialValue;
|
|
150
|
-
return /*#__PURE__*/React.createElement(FormItemChildComponent, _extends({}, childProps, {
|
|
151
|
-
name: name,
|
|
152
|
-
child: child,
|
|
153
|
-
value: value,
|
|
154
|
-
fieldValue: fieldValue,
|
|
155
|
-
noStyle: props.noStyle,
|
|
156
|
-
normalize: props.normalize,
|
|
157
|
-
key: `${key}_${isReseting}`,
|
|
158
|
-
error: Boolean(errorMessage),
|
|
159
|
-
setFieldValue: setFieldValue,
|
|
160
|
-
valuePropName: valuePropName,
|
|
161
|
-
feedbackIcons: feedbackIcons
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
163
|
-
// @ts-expect-error
|
|
164
|
-
,
|
|
165
|
-
size: childProps.size || props.size
|
|
166
|
-
}));
|
|
167
|
-
}
|
|
168
|
-
return child;
|
|
169
|
-
}), !props.noStyle && errorMessage && /*#__PURE__*/React.createElement("span", {
|
|
170
|
-
ref: errorRef,
|
|
171
|
-
className: `${prefixCls}-error`
|
|
172
|
-
}, errorMessage));
|
|
173
|
-
};
|
|
174
|
-
const FormItemChildComponent = ({
|
|
175
|
-
child,
|
|
176
|
-
name,
|
|
177
|
-
error,
|
|
178
|
-
fieldValue,
|
|
179
|
-
setFieldValue,
|
|
180
|
-
onChange,
|
|
181
|
-
valuePropName,
|
|
182
|
-
normalize,
|
|
183
|
-
...props
|
|
184
|
-
}) => {
|
|
185
|
-
const formContext = useContext(FormContext);
|
|
186
|
-
const [wasNormalize, setWasNormalize] = useState(false);
|
|
187
|
-
const {
|
|
188
|
-
getFieldsValue
|
|
189
|
-
} = formContext || {};
|
|
190
|
-
const handleChange = (e, option) => {
|
|
191
|
-
let rawValue = e?.target ? e.target.value : e;
|
|
192
|
-
if (normalize) {
|
|
193
|
-
const prevValue = fieldValue ?? props.value;
|
|
194
|
-
const allValues = getFieldsValue?.();
|
|
195
|
-
rawValue = normalize(rawValue, prevValue, allValues);
|
|
196
|
-
if (rawValue === prevValue) {
|
|
197
|
-
e.target.value = rawValue;
|
|
198
|
-
setWasNormalize(prev => !prev);
|
|
199
|
-
const timeout = setTimeout(() => {
|
|
200
|
-
document.querySelector(`[name='${name}']`)?.focus();
|
|
201
|
-
clearTimeout(timeout);
|
|
202
|
-
}, 0);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
setFieldValue(valuePropName || name, rawValue);
|
|
207
|
-
onChange?.(e, option);
|
|
208
|
-
};
|
|
209
|
-
return /*#__PURE__*/React.createElement(child.type, _extends({}, props, {
|
|
210
|
-
name: name,
|
|
211
|
-
onChange: handleChange
|
|
212
|
-
}, error ? {
|
|
213
|
-
error
|
|
214
|
-
} : {}, {
|
|
215
|
-
key: `${name}_${wasNormalize}`,
|
|
216
|
-
value: fieldValue ?? props.value
|
|
217
|
-
}));
|
|
218
|
-
};
|
|
219
|
-
FormItemClient.displayName = 'FormItemClient';
|
|
220
|
-
|
|
221
|
-
const FormItem = ({
|
|
222
|
-
prefixCls = prefixClsFormItem,
|
|
223
|
-
name,
|
|
224
|
-
label,
|
|
225
|
-
rules = [],
|
|
226
|
-
children,
|
|
227
|
-
className = '',
|
|
228
|
-
layout = 'vertical',
|
|
229
|
-
style = {},
|
|
230
|
-
valuePropName,
|
|
231
|
-
dependencies = [],
|
|
232
|
-
initialValue,
|
|
233
|
-
feedbackIcons,
|
|
234
|
-
...props
|
|
235
|
-
}) => {
|
|
236
|
-
return /*#__PURE__*/React.createElement(FormItemClient, _extends({
|
|
237
|
-
prefixCls: prefixCls,
|
|
238
|
-
name: name,
|
|
239
|
-
label: label,
|
|
240
|
-
rules: rules,
|
|
241
|
-
className: className,
|
|
242
|
-
layout: layout,
|
|
243
|
-
style: style,
|
|
244
|
-
valuePropName: valuePropName,
|
|
245
|
-
dependencies: dependencies,
|
|
246
|
-
initialValue: initialValue,
|
|
247
|
-
feedbackIcons: feedbackIcons
|
|
248
|
-
}, props), children);
|
|
249
|
-
};
|
|
250
|
-
FormItem.displayName = 'FormItem';
|
|
251
|
-
|
|
252
|
-
const useForm = (initialValues = {}, onFieldsChange, onValuesChange) => {
|
|
253
|
-
const touchedFieldsRef = useRef(new Set());
|
|
254
|
-
const rulesRef = useRef({});
|
|
255
|
-
const warningsRef = useRef({});
|
|
256
|
-
const formRef = useRef({
|
|
257
|
-
...initialValues
|
|
258
|
-
});
|
|
259
|
-
const fieldInstancesRef = useRef({});
|
|
260
|
-
const [isReseting, setIsReseting] = useState(false);
|
|
261
|
-
const [errors, setErrors] = useState({});
|
|
262
|
-
const fieldSubscribers = useRef({});
|
|
263
|
-
const formSubscribers = useRef([]);
|
|
264
|
-
function getFieldInstance(name) {
|
|
265
|
-
return fieldInstancesRef.current[name] || null;
|
|
266
|
-
}
|
|
267
|
-
function getFieldValue(name) {
|
|
268
|
-
return formRef.current[name];
|
|
269
|
-
}
|
|
270
|
-
function getFieldsValue(nameList) {
|
|
271
|
-
if (!nameList) {
|
|
272
|
-
return {
|
|
273
|
-
...formRef.current
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
return nameList.reduce((acc, key) => {
|
|
277
|
-
acc[key] = formRef.current[key];
|
|
278
|
-
return acc;
|
|
279
|
-
}, {});
|
|
280
|
-
}
|
|
281
|
-
function getFieldError(name) {
|
|
282
|
-
return errors[name] || [];
|
|
283
|
-
}
|
|
284
|
-
function getFieldWarning(name) {
|
|
285
|
-
return warningsRef.current[name] || [];
|
|
286
|
-
}
|
|
287
|
-
function getFieldsError() {
|
|
288
|
-
return Object.entries(errors).map(([name, err]) => ({
|
|
289
|
-
name,
|
|
290
|
-
errors: err
|
|
291
|
-
}));
|
|
292
|
-
}
|
|
293
|
-
function setFieldValue(name, value, errors, reset) {
|
|
294
|
-
if (!reset && ([undefined, null].includes(value) || formRef.current[name] === value)) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
formRef.current[name] = value;
|
|
298
|
-
touchedFieldsRef.current.add(name);
|
|
299
|
-
if (!errors?.length) {
|
|
300
|
-
validateField(name).then(() => {
|
|
301
|
-
const allValues = getFieldsValue();
|
|
302
|
-
fieldSubscribers.current[name]?.forEach(callback => callback(value));
|
|
303
|
-
formSubscribers.current.forEach(callback => callback(allValues));
|
|
304
|
-
if (onValuesChange) {
|
|
305
|
-
onValuesChange({
|
|
306
|
-
[name]: value
|
|
307
|
-
}, allValues);
|
|
308
|
-
}
|
|
309
|
-
if (onFieldsChange) {
|
|
310
|
-
onFieldsChange([{
|
|
311
|
-
name,
|
|
312
|
-
value
|
|
313
|
-
}]);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
} else {
|
|
317
|
-
setErrors({
|
|
318
|
-
[name]: errors
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function setFieldsValue(values) {
|
|
323
|
-
Object.entries(values).forEach(([name, value]) => setFieldValue(name, value));
|
|
324
|
-
}
|
|
325
|
-
function setFields(fields) {
|
|
326
|
-
fields.forEach(({
|
|
327
|
-
name,
|
|
328
|
-
value,
|
|
329
|
-
errors
|
|
330
|
-
}) => setFieldValue(Array.isArray(name) ? name[0] : name, value, errors));
|
|
331
|
-
}
|
|
332
|
-
function isFieldTouched(name) {
|
|
333
|
-
return touchedFieldsRef.current.has(name);
|
|
334
|
-
}
|
|
335
|
-
function isFieldsTouched(nameList, allFieldsTouched = false) {
|
|
336
|
-
if (!nameList) {
|
|
337
|
-
return touchedFieldsRef.current.size > 0;
|
|
338
|
-
}
|
|
339
|
-
return allFieldsTouched ? nameList.every(name => touchedFieldsRef.current.has(name)) : nameList.some(name => touchedFieldsRef.current.has(name));
|
|
340
|
-
}
|
|
341
|
-
function isFieldValidating(name) {
|
|
342
|
-
return !!name;
|
|
343
|
-
}
|
|
344
|
-
function registerField(name, rules = []) {
|
|
345
|
-
if (!(name in formRef.current)) {
|
|
346
|
-
formRef.current[name] = initialValues?.[name];
|
|
347
|
-
}
|
|
348
|
-
rulesRef.current[name] = rules;
|
|
349
|
-
}
|
|
350
|
-
async function validateField(name) {
|
|
351
|
-
const value = formRef.current[name];
|
|
352
|
-
const rules = rulesRef.current[name] || [];
|
|
353
|
-
const fieldErrors = [];
|
|
354
|
-
const fieldWarnings = [];
|
|
355
|
-
await Promise.all([rules].flat(1).map(async rule => {
|
|
356
|
-
rule = typeof rule === 'function' ? rule(formInstance) : rule;
|
|
357
|
-
if (rule.required && (value === undefined || value === null || value === '' || Array.isArray(value) && !value.length)) {
|
|
358
|
-
fieldErrors.push(rule.message || 'This field is required');
|
|
359
|
-
}
|
|
360
|
-
if ((typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) && rule.min !== undefined && String(value).length < rule.min) {
|
|
361
|
-
fieldErrors.push(rule.message || `Must be at least ${rule.min} characters`);
|
|
362
|
-
}
|
|
363
|
-
if ((typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) && rule.max !== undefined && String(value).length > rule.max) {
|
|
364
|
-
fieldErrors.push(rule.message || `Must be at most ${rule.max} characters`);
|
|
365
|
-
}
|
|
366
|
-
if (rule.pattern && !rule.pattern.test(String(value))) {
|
|
367
|
-
fieldErrors.push(rule.message || 'Invalid format');
|
|
368
|
-
}
|
|
369
|
-
if (rule.warningPattern && !rule.warningPattern.test(String(value))) {
|
|
370
|
-
fieldWarnings.push(rule.warningMessage || 'Invalid format');
|
|
371
|
-
}
|
|
372
|
-
if (rule.validator) {
|
|
373
|
-
try {
|
|
374
|
-
await rule.validator(rule, value, error => error && fieldErrors.push(error));
|
|
375
|
-
} catch (error) {
|
|
376
|
-
fieldErrors.push(error instanceof Error ? error.message : String(error));
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}));
|
|
380
|
-
setErrors(prev => ({
|
|
381
|
-
...prev,
|
|
382
|
-
[name]: fieldErrors
|
|
383
|
-
}));
|
|
384
|
-
warningsRef.current[name] = fieldWarnings;
|
|
385
|
-
return fieldErrors.length === 0;
|
|
386
|
-
}
|
|
387
|
-
async function validateFields(nameList) {
|
|
388
|
-
const fieldsToValidate = nameList || Object.keys(formRef.current);
|
|
389
|
-
const results = await Promise.all(fieldsToValidate.map(name => validateField(name)));
|
|
390
|
-
return results.every(valid => valid);
|
|
391
|
-
}
|
|
392
|
-
function resetFields(nameList) {
|
|
393
|
-
if (nameList?.length) {
|
|
394
|
-
nameList.forEach(name => {
|
|
395
|
-
formRef.current[name] = initialValues[name];
|
|
396
|
-
touchedFieldsRef.current.delete(name);
|
|
397
|
-
delete warningsRef.current[name];
|
|
398
|
-
setErrors(prev => ({
|
|
399
|
-
...prev,
|
|
400
|
-
[name]: []
|
|
401
|
-
}));
|
|
402
|
-
setFieldValue(name, initialValues[name], undefined, true);
|
|
403
|
-
});
|
|
404
|
-
} else {
|
|
405
|
-
touchedFieldsRef.current.clear();
|
|
406
|
-
warningsRef.current = {};
|
|
407
|
-
Object.keys(formRef.current).forEach(name => {
|
|
408
|
-
setFieldValue(name, initialValues[name], undefined, true);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
formSubscribers.current.forEach(callback => callback(getFieldsValue()));
|
|
412
|
-
setIsReseting(prev => !prev);
|
|
413
|
-
}
|
|
414
|
-
async function submit() {
|
|
415
|
-
return (await validateFields()) ? formRef.current : undefined;
|
|
416
|
-
}
|
|
417
|
-
function subscribeToField(name, callback) {
|
|
418
|
-
if (!fieldSubscribers.current[name]) {
|
|
419
|
-
fieldSubscribers.current[name] = [];
|
|
420
|
-
}
|
|
421
|
-
fieldSubscribers.current[name].push(callback);
|
|
422
|
-
return () => {
|
|
423
|
-
fieldSubscribers.current[name] = fieldSubscribers.current[name].filter(cb => cb !== callback);
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
function subscribeToForm(callback) {
|
|
427
|
-
formSubscribers.current.push(callback);
|
|
428
|
-
return () => {
|
|
429
|
-
formSubscribers.current = formSubscribers.current.filter(cb => cb !== callback);
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function subscribeToFields(names, callback) {
|
|
433
|
-
const fieldCallbacks = names.map(name => subscribeToField(name, () => {
|
|
434
|
-
const updatedValues = getFieldsValue(names);
|
|
435
|
-
callback(updatedValues);
|
|
436
|
-
}));
|
|
437
|
-
return () => {
|
|
438
|
-
fieldCallbacks.forEach(unsubscribe => unsubscribe());
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
const formInstance = {
|
|
442
|
-
submit,
|
|
443
|
-
setFields,
|
|
444
|
-
resetFields,
|
|
445
|
-
getFieldError,
|
|
446
|
-
registerField,
|
|
447
|
-
setFieldValue,
|
|
448
|
-
getFieldValue,
|
|
449
|
-
validateFields,
|
|
450
|
-
setFieldsValue,
|
|
451
|
-
getFieldsValue,
|
|
452
|
-
isFieldTouched,
|
|
453
|
-
getFieldsError,
|
|
454
|
-
isFieldsTouched,
|
|
455
|
-
getFieldWarning,
|
|
456
|
-
isFieldValidating,
|
|
457
|
-
subscribeToField,
|
|
458
|
-
subscribeToForm,
|
|
459
|
-
onFieldsChange,
|
|
460
|
-
onValuesChange,
|
|
461
|
-
getFieldInstance,
|
|
462
|
-
subscribeToFields,
|
|
463
|
-
isReseting
|
|
464
|
-
};
|
|
465
|
-
return formInstance;
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
const FormClient = ({
|
|
469
|
-
children,
|
|
470
|
-
form,
|
|
471
|
-
style = {},
|
|
472
|
-
prefixCls,
|
|
473
|
-
className = '',
|
|
474
|
-
onFinish,
|
|
475
|
-
onFinishFailed,
|
|
476
|
-
initialValues = {},
|
|
477
|
-
onValuesChange,
|
|
478
|
-
onFieldsChange,
|
|
479
|
-
layout = 'horizontal',
|
|
480
|
-
onSubmitCapture,
|
|
481
|
-
...rest
|
|
482
|
-
}) => {
|
|
483
|
-
const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
|
|
484
|
-
const formInstance = form || internalForm;
|
|
485
|
-
const formRef = useRef(null);
|
|
486
|
-
const handleSubmit = async e => {
|
|
487
|
-
e.preventDefault();
|
|
488
|
-
if (await formInstance.validateFields()) {
|
|
489
|
-
onFinish?.(formInstance.getFieldsValue());
|
|
490
|
-
} else if (onFinishFailed) {
|
|
491
|
-
const errorFields = formInstance.getFieldsError();
|
|
492
|
-
onFinishFailed({
|
|
493
|
-
values: formInstance.getFieldsValue(),
|
|
494
|
-
errorFields
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
const childrenList = useMemo(() => (Array.isArray(children) ? children : [children]).filter(Boolean), [children]);
|
|
499
|
-
useEffect(() => {
|
|
500
|
-
if (onFieldsChange) {
|
|
501
|
-
formInstance.onFieldsChange = onFieldsChange;
|
|
502
|
-
}
|
|
503
|
-
if (onValuesChange) {
|
|
504
|
-
formInstance.onValuesChange = onValuesChange;
|
|
505
|
-
}
|
|
506
|
-
}, [formInstance, onFieldsChange, onValuesChange]);
|
|
507
|
-
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
508
|
-
value: formInstance
|
|
509
|
-
}, /*#__PURE__*/React.createElement("form", _extends({
|
|
510
|
-
style: style,
|
|
511
|
-
ref: formRef,
|
|
512
|
-
onSubmit: handleSubmit
|
|
513
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
514
|
-
// @ts-expect-error
|
|
515
|
-
,
|
|
516
|
-
onSubmitCapture: onSubmitCapture,
|
|
517
|
-
className: `${prefixCls} ${className}`
|
|
518
|
-
}, rest), Children.map(childrenList, child => {
|
|
519
|
-
if (/*#__PURE__*/isValidElement(child) && child.type !== Fragment) {
|
|
520
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
521
|
-
// @ts-expect-error
|
|
522
|
-
const {
|
|
523
|
-
...childProps
|
|
524
|
-
} = child.props;
|
|
525
|
-
return /*#__PURE__*/React.createElement(child.type, _extends({}, childProps, {
|
|
526
|
-
child: child,
|
|
527
|
-
size: childProps.size || rest.size,
|
|
528
|
-
layout: childProps.layout || layout
|
|
529
|
-
}));
|
|
530
|
-
}
|
|
531
|
-
return child;
|
|
532
|
-
})));
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
const FormContext = /*#__PURE__*/createContext(null);
|
|
536
|
-
const Form = ({
|
|
537
|
-
children,
|
|
538
|
-
style = {},
|
|
539
|
-
prefixCls = prefixClsForm,
|
|
540
|
-
className = '',
|
|
541
|
-
layout = 'horizontal',
|
|
542
|
-
...rest
|
|
543
|
-
}) => {
|
|
544
|
-
return /*#__PURE__*/React.createElement(FormClient, _extends({
|
|
545
|
-
style: style,
|
|
546
|
-
prefixCls: prefixCls,
|
|
547
|
-
className: className,
|
|
548
|
-
layout: layout
|
|
549
|
-
}, rest), children);
|
|
550
|
-
};
|
|
551
|
-
Form.Item = FormItem;
|
|
552
|
-
|
|
553
35
|
var css_248z$2 = ".xUi-empty{align-items:center;display:grid;gap:4px;justify-content:center;padding:14px}.xUi-empty-description{color:var(--xui-text-color);font-size:var(--xui-font-size-md);text-align:center}";
|
|
554
36
|
styleInject(css_248z$2);
|
|
555
37
|
|
|
@@ -590,6 +72,37 @@ const EmptyContent = ({
|
|
|
590
72
|
className: `${prefixCls}-description`
|
|
591
73
|
}, description));
|
|
592
74
|
|
|
75
|
+
function _extends() {
|
|
76
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
77
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
78
|
+
var t = arguments[e];
|
|
79
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
}, _extends.apply(null, arguments);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function clsx(...args) {
|
|
86
|
+
return args.flatMap(arg => {
|
|
87
|
+
if (!arg) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
if (typeof arg === 'string') {
|
|
91
|
+
return [arg];
|
|
92
|
+
}
|
|
93
|
+
if (typeof arg === 'number') {
|
|
94
|
+
return [String(arg)];
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(arg)) {
|
|
97
|
+
return clsx(...arg).split(' ');
|
|
98
|
+
}
|
|
99
|
+
if (typeof arg === 'object') {
|
|
100
|
+
return Object.entries(arg).filter(([, value]) => Boolean(value)).map(([key]) => key);
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
103
|
+
}).filter(Boolean).join(' ');
|
|
104
|
+
}
|
|
105
|
+
|
|
593
106
|
var css_248z$1 = ".xUi-button{border:1px solid transparent;border-radius:6px;cursor:pointer;font-weight:400;line-height:1.5715;transition:all .3s ease;user-select:none;vertical-align:middle;white-space:nowrap}.xUi-button,.xUi-button-content,.xUi-button-icon{align-items:center;display:inline-flex;justify-content:center}.xUi-button-icon{line-height:0;margin-right:.5em}.xUi-button-icon:last-child{margin-left:.5em;margin-right:0}.xUi-button-spinner{animation:xUi-spin 1s linear infinite;border:1px solid transparent;border-radius:50%;border-top:1px solid var(--xui-text-color);height:1em;width:1em}@keyframes xUi-spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.xUi-button-size-small{font-size:12px;height:24px;padding:4px 12px}.xUi-button-size-middle{font-size:14px;height:32px;padding:0 16px}.xUi-button-size-large{font-size:16px;height:40px;padding:8px 20px}.xUi-button-circle{border-radius:50%;justify-content:center;padding:0}.xUi-button-circle.xUi-button-size-small{height:24px;width:24px}.xUi-button-circle.xUi-button-size-large{height:40px;width:40px}.xUi-button-round{border-radius:9999px}.xUi-button-default{background-color:#fff;border-color:var(--xui-border-color);color:rgba(0,0,0,.85)}.xUi-button-default:hover{border-color:var(--xui-primary-color);color:var(--xui-primary-color)}.xUi-button-primary{background-color:var(--xui-primary-color);border-color:var(--xui-primary-color);color:#fff}.xUi-button-primary:hover{background-color:var(--xui-primary-color-light);border-color:var(--xui-primary-color-light);color:#fff}.xUi-button-dashed{background-color:#fff;border-color:var(--xui-border-color);border-style:dashed;color:rgba(0,0,0,.85)}.xUi-button-dashed:hover{border-color:var(--xui-primary-color);color:var(--xui-primary-color)}.xUi-button-text{background-color:transparent;border-color:transparent!important;color:rgba(0,0,0,.88)}.xUi-button-text:hover{background-color:rgba(0,0,0,.04);border-color:transparent;color:rgba(0,0,0,.88)}.xUi-button-link{background-color:transparent;border-color:transparent!important;color:var(--xui-primary-color)}.xUi-button-link:hover{border-color:transparent;color:var(--xui-primary-color-light)}.xUi-button-outlined{color:#fff}.xUi-button-filled,.xUi-button-outlined{background-color:transparent;border-color:var(--xui-border-color)}.xUi-button-filled{color:var(--xui-text-color)}.xUi-button-danger{background-color:transparent;border-color:var(--xui-error-color);color:var(--xui-error-color)}.xUi-button-danger:hover{border-color:var(--xui-error-color-light);color:var(--xui-error-color-light)}.xUi-button-ghost{opacity:0}.xUi-button-ghost:hover{opacity:1}.xUi-button-block{display:flex;width:100%}.xUi-button-disabled,.xUi-button-loading{background-color:var(--xui-color-disabled);border-color:var(--xui-border-color);color:var(--xui-text-color);cursor:not-allowed;opacity:.5;pointer-events:none}.xUi-button-loading{background-color:transparent}";
|
|
594
107
|
styleInject(css_248z$1);
|
|
595
108
|
|
|
@@ -690,9 +203,9 @@ const CheckboxClient = /*#__PURE__*/forwardRef(({
|
|
|
690
203
|
setInternalChecked(checked);
|
|
691
204
|
}
|
|
692
205
|
}, [checked]);
|
|
693
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
206
|
+
return /*#__PURE__*/React$1.createElement("div", {
|
|
694
207
|
className: `${prefixCls}-wrapper`
|
|
695
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
208
|
+
}, /*#__PURE__*/React$1.createElement("div", {
|
|
696
209
|
ref: ref,
|
|
697
210
|
style: style,
|
|
698
211
|
onClick: handleClick,
|
|
@@ -701,7 +214,7 @@ const CheckboxClient = /*#__PURE__*/forwardRef(({
|
|
|
701
214
|
[`${prefixCls}-disabled`]: disabled,
|
|
702
215
|
[`${prefixCls}-checked`]: internalChecked
|
|
703
216
|
}])
|
|
704
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
217
|
+
}, /*#__PURE__*/React$1.createElement("input", {
|
|
705
218
|
id: id,
|
|
706
219
|
type: type,
|
|
707
220
|
name: name,
|
|
@@ -713,14 +226,14 @@ const CheckboxClient = /*#__PURE__*/forwardRef(({
|
|
|
713
226
|
onKeyPress: onKeyPress,
|
|
714
227
|
onMouseEnter: onMouseEnter,
|
|
715
228
|
onMouseLeave: onMouseLeave
|
|
716
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
229
|
+
}), /*#__PURE__*/React$1.createElement("span", {
|
|
717
230
|
className: `${prefixCls}-box`
|
|
718
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
231
|
+
}, /*#__PURE__*/React$1.createElement("span", {
|
|
719
232
|
className: `${prefixCls}-check`,
|
|
720
233
|
style: {
|
|
721
234
|
opacity: Number(internalChecked)
|
|
722
235
|
}
|
|
723
|
-
}))), children && /*#__PURE__*/React.createElement("span", {
|
|
236
|
+
}))), children && /*#__PURE__*/React$1.createElement("span", {
|
|
724
237
|
className: `${prefixCls}-label`
|
|
725
238
|
}, children));
|
|
726
239
|
});
|
|
@@ -749,7 +262,7 @@ const Checkbox = ({
|
|
|
749
262
|
required = false,
|
|
750
263
|
noStyle
|
|
751
264
|
}) => {
|
|
752
|
-
return /*#__PURE__*/React.createElement(CheckboxClient, {
|
|
265
|
+
return /*#__PURE__*/React$1.createElement(CheckboxClient, {
|
|
753
266
|
prefixCls: prefixCls,
|
|
754
267
|
className: className,
|
|
755
268
|
defaultChecked: defaultChecked,
|
|
@@ -774,29 +287,5 @@ const Checkbox = ({
|
|
|
774
287
|
};
|
|
775
288
|
Checkbox.displayName = 'Checkbox';
|
|
776
289
|
|
|
777
|
-
|
|
778
|
-
name,
|
|
779
|
-
defaultValue,
|
|
780
|
-
form
|
|
781
|
-
}) => {
|
|
782
|
-
const formContext = useContext(FormContext);
|
|
783
|
-
const formInstance = form || formContext;
|
|
784
|
-
if (!formInstance) {
|
|
785
|
-
throw new Error('useWatch must be used within a Form or with a form instance.');
|
|
786
|
-
}
|
|
787
|
-
const [value, setValue] = useState(() => {
|
|
788
|
-
return name ? formInstance.getFieldValue(name) ?? defaultValue : formInstance.getFieldsValue() ?? defaultValue;
|
|
789
|
-
});
|
|
790
|
-
useEffect(() => {
|
|
791
|
-
if (!name) {
|
|
792
|
-
const unsubscribe = formInstance.subscribeToForm(setValue);
|
|
793
|
-
return () => unsubscribe();
|
|
794
|
-
}
|
|
795
|
-
const unsubscribe = formInstance.subscribeToField(name, setValue);
|
|
796
|
-
return () => unsubscribe();
|
|
797
|
-
}, [name, formInstance]);
|
|
798
|
-
return value;
|
|
799
|
-
};
|
|
800
|
-
|
|
801
|
-
export { Button, Checkbox, EmptyContent as Empty, Form, FormItem, useForm, useWatch };
|
|
290
|
+
export { Button, Checkbox, EmptyContent as Empty };
|
|
802
291
|
//# sourceMappingURL=index.esm.js.map
|