@wix/site-ui 1.102.0 → 1.103.0
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/Field/index.css +9 -0
- package/dist/Field/index.js +584 -6
- package/dist/Select/index.css +4 -25
- package/dist/Select/index.js +1 -3
- package/dist/SelectField/index.js +7 -14
- package/package.json +2 -2
- package/dist/8972.js +0 -576
package/dist/Field/index.css
CHANGED
|
@@ -17,6 +17,15 @@
|
|
|
17
17
|
.error-BUDKWp {
|
|
18
18
|
font: var(--wst-paragraph-3-font);
|
|
19
19
|
color: var(--wst-system-error-color, #df3131);
|
|
20
|
+
align-items: center;
|
|
21
|
+
gap: 4px;
|
|
22
|
+
display: flex;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.error-BUDKWp svg {
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
width: 1lh;
|
|
28
|
+
height: 1lh;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
.description-IVviYU {
|
package/dist/Field/index.js
CHANGED
|
@@ -1,16 +1,483 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { InfoCircle } from "@wix/wix-ui-icons-common";
|
|
2
3
|
import clsx from "clsx";
|
|
3
|
-
import {
|
|
4
|
+
import { useBaseUiId } from "../6046.js";
|
|
5
|
+
import { useRefWithInit, EMPTY_OBJECT, mergeProps, useRenderElement } from "../8272.js";
|
|
6
|
+
import { LabelableContext, FieldRootContext, useFieldRootContext, useLabelableContext, fieldValidityMapping, DEFAULT_VALIDITY_STATE } from "../1477.js";
|
|
7
|
+
import { useStableCallback } from "../7541.js";
|
|
8
|
+
import { useFormContext } from "../5085.js";
|
|
9
|
+
import { useTimeout } from "../42.js";
|
|
10
|
+
import { useIsoLayoutEffect, SafeReact } from "../6499.js";
|
|
11
|
+
import { useFieldsetRootContext } from "../353.js";
|
|
4
12
|
import { useLabel } from "../4143.js";
|
|
5
|
-
import { SafeReact } from "../6499.js";
|
|
6
13
|
import { error } from "../4026.js";
|
|
7
|
-
import {
|
|
14
|
+
import { transitionStatusMapping, useOpenChangeComplete, useTransitionStatus } from "../880.js";
|
|
8
15
|
import { useCheckboxGroupContext } from "../8979.js";
|
|
9
|
-
import { FieldRoot_FieldRoot, FieldDescription_FieldDescription, getCombinedFieldValidityData, LabelableProvider_LabelableProvider, FieldError_FieldError } from "../8972.js";
|
|
10
16
|
import { FieldItemContext } from "../1457.js";
|
|
11
|
-
import { useTransitionStatus } from "../880.js";
|
|
12
17
|
import { Input_module, FieldControl_FieldControl } from "../8685.js";
|
|
13
18
|
import * as __rspack_external_react from "react";
|
|
19
|
+
const LabelableProvider_LabelableProvider = function(props) {
|
|
20
|
+
const defaultId = useBaseUiId();
|
|
21
|
+
const initialControlId = void 0 === props.controlId ? defaultId : props.controlId;
|
|
22
|
+
const [controlId, setControlIdState] = __rspack_external_react.useState(initialControlId);
|
|
23
|
+
const [labelId, setLabelId] = __rspack_external_react.useState(props.labelId);
|
|
24
|
+
const [messageIds, setMessageIds] = __rspack_external_react.useState([]);
|
|
25
|
+
const registrationsRef = useRefWithInit(()=>new Map());
|
|
26
|
+
const { messageIds: parentMessageIds } = useLabelableContext();
|
|
27
|
+
const registerControlId = useStableCallback((source, nextId)=>{
|
|
28
|
+
const registrations = registrationsRef.current;
|
|
29
|
+
if (void 0 === nextId) return void registrations.delete(source);
|
|
30
|
+
registrations.set(source, nextId);
|
|
31
|
+
setControlIdState((prev)=>{
|
|
32
|
+
if (0 === registrations.size) return;
|
|
33
|
+
let nextControlId;
|
|
34
|
+
for (const id of registrations.values()){
|
|
35
|
+
if (void 0 !== prev && id === prev) return prev;
|
|
36
|
+
if (void 0 === nextControlId) nextControlId = id;
|
|
37
|
+
}
|
|
38
|
+
return nextControlId;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
const getDescriptionProps = __rspack_external_react.useCallback((externalProps)=>mergeProps({
|
|
42
|
+
'aria-describedby': parentMessageIds.concat(messageIds).join(' ') || void 0
|
|
43
|
+
}, externalProps), [
|
|
44
|
+
parentMessageIds,
|
|
45
|
+
messageIds
|
|
46
|
+
]);
|
|
47
|
+
const contextValue = __rspack_external_react.useMemo(()=>({
|
|
48
|
+
controlId,
|
|
49
|
+
registerControlId,
|
|
50
|
+
labelId,
|
|
51
|
+
setLabelId,
|
|
52
|
+
messageIds,
|
|
53
|
+
setMessageIds,
|
|
54
|
+
getDescriptionProps
|
|
55
|
+
}), [
|
|
56
|
+
controlId,
|
|
57
|
+
registerControlId,
|
|
58
|
+
labelId,
|
|
59
|
+
setLabelId,
|
|
60
|
+
messageIds,
|
|
61
|
+
setMessageIds,
|
|
62
|
+
getDescriptionProps
|
|
63
|
+
]);
|
|
64
|
+
return /*#__PURE__*/ jsx(LabelableContext.Provider, {
|
|
65
|
+
value: contextValue,
|
|
66
|
+
children: props.children
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
if ("production" !== process.env.NODE_ENV) LabelableProvider_LabelableProvider.displayName = "LabelableProvider";
|
|
70
|
+
function getCombinedFieldValidityData(validityData, invalid) {
|
|
71
|
+
return {
|
|
72
|
+
...validityData,
|
|
73
|
+
state: {
|
|
74
|
+
...validityData.state,
|
|
75
|
+
valid: !invalid && validityData.state.valid
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const validityKeys = Object.keys(DEFAULT_VALIDITY_STATE);
|
|
80
|
+
function isOnlyValueMissing(state) {
|
|
81
|
+
if (!state || state.valid || !state.valueMissing) return false;
|
|
82
|
+
let onlyValueMissing = false;
|
|
83
|
+
for (const key of validityKeys)if ('valid' !== key) {
|
|
84
|
+
if ('valueMissing' === key) onlyValueMissing = state[key];
|
|
85
|
+
if (state[key]) onlyValueMissing = false;
|
|
86
|
+
}
|
|
87
|
+
return onlyValueMissing;
|
|
88
|
+
}
|
|
89
|
+
function useFieldValidation(params) {
|
|
90
|
+
const { formRef, clearErrors } = useFormContext();
|
|
91
|
+
const { setValidityData, validate, validityData, validationDebounceTime, invalid, markedDirtyRef, state, name, shouldValidateOnChange, getRegisteredFieldId } = params;
|
|
92
|
+
const { controlId, getDescriptionProps } = useLabelableContext();
|
|
93
|
+
const timeout = useTimeout();
|
|
94
|
+
const inputRef = __rspack_external_react.useRef(null);
|
|
95
|
+
const commit = useStableCallback(async (value, revalidate = false)=>{
|
|
96
|
+
const element = inputRef.current;
|
|
97
|
+
if (!element) return;
|
|
98
|
+
function updateRegisteredFieldValidity(nextValidityData, externalInvalid = invalid) {
|
|
99
|
+
const fieldId = getRegisteredFieldId() ?? controlId;
|
|
100
|
+
if (null == fieldId) return;
|
|
101
|
+
const currentFieldData = formRef.current.fields.get(fieldId);
|
|
102
|
+
if (!currentFieldData) return;
|
|
103
|
+
const validityDataWithFormErrors = getCombinedFieldValidityData(nextValidityData, externalInvalid);
|
|
104
|
+
formRef.current.fields.set(fieldId, {
|
|
105
|
+
...currentFieldData,
|
|
106
|
+
validityData: validityDataWithFormErrors
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (revalidate) {
|
|
110
|
+
if (false !== state.valid) return;
|
|
111
|
+
const currentNativeValidity = element.validity;
|
|
112
|
+
if (!currentNativeValidity.valueMissing) {
|
|
113
|
+
const nextValidityData = {
|
|
114
|
+
value,
|
|
115
|
+
state: {
|
|
116
|
+
...DEFAULT_VALIDITY_STATE,
|
|
117
|
+
valid: true
|
|
118
|
+
},
|
|
119
|
+
error: '',
|
|
120
|
+
errors: [],
|
|
121
|
+
initialValue: validityData.initialValue
|
|
122
|
+
};
|
|
123
|
+
element.setCustomValidity('');
|
|
124
|
+
updateRegisteredFieldValidity(nextValidityData, false);
|
|
125
|
+
setValidityData(nextValidityData);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const currentNativeValidityObject = validityKeys.reduce((acc, key)=>{
|
|
129
|
+
acc[key] = currentNativeValidity[key];
|
|
130
|
+
return acc;
|
|
131
|
+
}, {});
|
|
132
|
+
if (!currentNativeValidityObject.valid && !isOnlyValueMissing(currentNativeValidityObject)) return;
|
|
133
|
+
}
|
|
134
|
+
function getState(el) {
|
|
135
|
+
const computedState = validityKeys.reduce((acc, key)=>{
|
|
136
|
+
acc[key] = el.validity[key];
|
|
137
|
+
return acc;
|
|
138
|
+
}, {});
|
|
139
|
+
let hasOnlyValueMissingError = false;
|
|
140
|
+
for (const key of validityKeys)if ('valid' !== key) {
|
|
141
|
+
if ('valueMissing' === key && computedState[key]) hasOnlyValueMissingError = true;
|
|
142
|
+
else if (computedState[key]) return computedState;
|
|
143
|
+
}
|
|
144
|
+
if (hasOnlyValueMissingError && !markedDirtyRef.current) {
|
|
145
|
+
computedState.valid = true;
|
|
146
|
+
computedState.valueMissing = false;
|
|
147
|
+
}
|
|
148
|
+
return computedState;
|
|
149
|
+
}
|
|
150
|
+
timeout.clear();
|
|
151
|
+
let result = null;
|
|
152
|
+
let validationErrors = [];
|
|
153
|
+
const nextState = getState(element);
|
|
154
|
+
let defaultValidationMessage;
|
|
155
|
+
const validateOnChange = shouldValidateOnChange();
|
|
156
|
+
if (element.validationMessage && !validateOnChange) {
|
|
157
|
+
defaultValidationMessage = element.validationMessage;
|
|
158
|
+
validationErrors = [
|
|
159
|
+
element.validationMessage
|
|
160
|
+
];
|
|
161
|
+
} else {
|
|
162
|
+
const formValues = Array.from(formRef.current.fields.values()).reduce((acc, field)=>{
|
|
163
|
+
if (field.name) acc[field.name] = field.getValue();
|
|
164
|
+
return acc;
|
|
165
|
+
}, {});
|
|
166
|
+
const resultOrPromise = validate(value, formValues);
|
|
167
|
+
result = 'object' == typeof resultOrPromise && null !== resultOrPromise && 'then' in resultOrPromise ? await resultOrPromise : resultOrPromise;
|
|
168
|
+
if (null !== result) {
|
|
169
|
+
nextState.valid = false;
|
|
170
|
+
nextState.customError = true;
|
|
171
|
+
if (Array.isArray(result)) {
|
|
172
|
+
validationErrors = result;
|
|
173
|
+
element.setCustomValidity(result.join('\n'));
|
|
174
|
+
} else if (result) {
|
|
175
|
+
validationErrors = [
|
|
176
|
+
result
|
|
177
|
+
];
|
|
178
|
+
element.setCustomValidity(result);
|
|
179
|
+
}
|
|
180
|
+
} else if (validateOnChange) {
|
|
181
|
+
element.setCustomValidity('');
|
|
182
|
+
nextState.customError = false;
|
|
183
|
+
if (element.validationMessage) {
|
|
184
|
+
defaultValidationMessage = element.validationMessage;
|
|
185
|
+
validationErrors = [
|
|
186
|
+
element.validationMessage
|
|
187
|
+
];
|
|
188
|
+
} else if (element.validity.valid && !nextState.valid) nextState.valid = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const nextValidityData = {
|
|
192
|
+
value,
|
|
193
|
+
state: nextState,
|
|
194
|
+
error: defaultValidationMessage ?? (Array.isArray(result) ? result[0] : result ?? ''),
|
|
195
|
+
errors: validationErrors,
|
|
196
|
+
initialValue: validityData.initialValue
|
|
197
|
+
};
|
|
198
|
+
updateRegisteredFieldValidity(nextValidityData);
|
|
199
|
+
setValidityData(nextValidityData);
|
|
200
|
+
});
|
|
201
|
+
const getValidationProps = __rspack_external_react.useCallback((externalProps = {})=>mergeProps(getDescriptionProps, false === state.valid ? {
|
|
202
|
+
'aria-invalid': true
|
|
203
|
+
} : EMPTY_OBJECT, externalProps), [
|
|
204
|
+
getDescriptionProps,
|
|
205
|
+
state.valid
|
|
206
|
+
]);
|
|
207
|
+
const getInputValidationProps = __rspack_external_react.useCallback((externalProps = {})=>mergeProps({
|
|
208
|
+
onChange (event) {
|
|
209
|
+
if (event.nativeEvent.defaultPrevented) return;
|
|
210
|
+
clearErrors(name);
|
|
211
|
+
if (!shouldValidateOnChange()) return void commit(event.currentTarget.value, true);
|
|
212
|
+
const element = event.currentTarget;
|
|
213
|
+
if ('' === element.value) return void commit(element.value);
|
|
214
|
+
timeout.clear();
|
|
215
|
+
if (validationDebounceTime) timeout.start(validationDebounceTime, ()=>{
|
|
216
|
+
commit(element.value);
|
|
217
|
+
});
|
|
218
|
+
else commit(element.value);
|
|
219
|
+
}
|
|
220
|
+
}, getValidationProps(externalProps)), [
|
|
221
|
+
getValidationProps,
|
|
222
|
+
clearErrors,
|
|
223
|
+
name,
|
|
224
|
+
timeout,
|
|
225
|
+
commit,
|
|
226
|
+
validationDebounceTime,
|
|
227
|
+
shouldValidateOnChange
|
|
228
|
+
]);
|
|
229
|
+
return __rspack_external_react.useMemo(()=>({
|
|
230
|
+
getValidationProps,
|
|
231
|
+
getInputValidationProps,
|
|
232
|
+
inputRef,
|
|
233
|
+
commit
|
|
234
|
+
}), [
|
|
235
|
+
getValidationProps,
|
|
236
|
+
getInputValidationProps,
|
|
237
|
+
commit
|
|
238
|
+
]);
|
|
239
|
+
}
|
|
240
|
+
function useFieldControlRegistration(params) {
|
|
241
|
+
const { commit, invalid, markedDirtyRef, name, setRegisteredFieldId, setValidityData, validityData } = params;
|
|
242
|
+
const { formRef } = useFormContext();
|
|
243
|
+
const activeFieldControlSourceRef = __rspack_external_react.useRef(null);
|
|
244
|
+
const registrationRef = __rspack_external_react.useRef(null);
|
|
245
|
+
const fallbackControlRef = __rspack_external_react.useRef(null);
|
|
246
|
+
const getValueForForm = useStableCallback(()=>{
|
|
247
|
+
const registration = registrationRef.current;
|
|
248
|
+
if (!registration) return;
|
|
249
|
+
if (registration.getValue) return registration.getValue();
|
|
250
|
+
return registration.value;
|
|
251
|
+
});
|
|
252
|
+
const validate = useStableCallback(()=>{
|
|
253
|
+
const registration = registrationRef.current;
|
|
254
|
+
if (!registration) return;
|
|
255
|
+
let nextValue = registration.value;
|
|
256
|
+
if (void 0 === nextValue) nextValue = getValueForForm();
|
|
257
|
+
markedDirtyRef.current = true;
|
|
258
|
+
commit(nextValue);
|
|
259
|
+
});
|
|
260
|
+
function refreshRegistration() {
|
|
261
|
+
const registration = registrationRef.current;
|
|
262
|
+
if (!registration || !registration.id) return;
|
|
263
|
+
formRef.current.fields.set(registration.id, {
|
|
264
|
+
getValue: getValueForForm,
|
|
265
|
+
name,
|
|
266
|
+
controlRef: registration.controlRef ?? fallbackControlRef,
|
|
267
|
+
validityData: getCombinedFieldValidityData(validityData, invalid),
|
|
268
|
+
validate
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function deleteRegistration(id = registrationRef.current?.id) {
|
|
272
|
+
if (id) formRef.current.fields.delete(id);
|
|
273
|
+
}
|
|
274
|
+
function syncInitialValue() {
|
|
275
|
+
const registration = registrationRef.current;
|
|
276
|
+
if (!registration) return;
|
|
277
|
+
let initialValue = registration.value;
|
|
278
|
+
if (void 0 === initialValue) initialValue = getValueForForm();
|
|
279
|
+
if (null === validityData.initialValue && null !== initialValue) setValidityData((prev)=>({
|
|
280
|
+
...prev,
|
|
281
|
+
initialValue
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
useIsoLayoutEffect(()=>{
|
|
285
|
+
const registration = registrationRef.current;
|
|
286
|
+
if (!registration || !registration.id) return;
|
|
287
|
+
formRef.current.fields.set(registration.id, {
|
|
288
|
+
getValue: getValueForForm,
|
|
289
|
+
name,
|
|
290
|
+
controlRef: registration.controlRef ?? fallbackControlRef,
|
|
291
|
+
validityData: getCombinedFieldValidityData(validityData, invalid),
|
|
292
|
+
validate
|
|
293
|
+
});
|
|
294
|
+
}, [
|
|
295
|
+
formRef,
|
|
296
|
+
getValueForForm,
|
|
297
|
+
invalid,
|
|
298
|
+
name,
|
|
299
|
+
validate,
|
|
300
|
+
validityData
|
|
301
|
+
]);
|
|
302
|
+
useIsoLayoutEffect(()=>{
|
|
303
|
+
const fields = formRef.current.fields;
|
|
304
|
+
return ()=>{
|
|
305
|
+
const id = registrationRef.current?.id;
|
|
306
|
+
if (id) fields.delete(id);
|
|
307
|
+
};
|
|
308
|
+
}, [
|
|
309
|
+
formRef
|
|
310
|
+
]);
|
|
311
|
+
return useStableCallback((source, registration)=>{
|
|
312
|
+
if (!registration) {
|
|
313
|
+
if (activeFieldControlSourceRef.current === source) {
|
|
314
|
+
activeFieldControlSourceRef.current = null;
|
|
315
|
+
deleteRegistration();
|
|
316
|
+
registrationRef.current = null;
|
|
317
|
+
setRegisteredFieldId(void 0);
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const previousId = registrationRef.current?.id;
|
|
322
|
+
activeFieldControlSourceRef.current = source;
|
|
323
|
+
registrationRef.current = registration;
|
|
324
|
+
setRegisteredFieldId(registration.id);
|
|
325
|
+
if (previousId && previousId !== registration.id) deleteRegistration(previousId);
|
|
326
|
+
syncInitialValue();
|
|
327
|
+
refreshRegistration();
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
const FieldRoot_FieldRootInner = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
331
|
+
const { errors, validationMode: formValidationMode, submitAttemptedRef } = useFormContext();
|
|
332
|
+
const { render, className, validate: validateProp, validationDebounceTime = 0, validationMode = formValidationMode, name, disabled: disabledProp = false, invalid: invalidProp, dirty: dirtyProp, touched: touchedProp, actionsRef, style, ...elementProps } = componentProps;
|
|
333
|
+
const { disabled: disabledFieldset } = useFieldsetRootContext();
|
|
334
|
+
const validate = useStableCallback(validateProp || (()=>null));
|
|
335
|
+
const disabled = disabledFieldset || disabledProp;
|
|
336
|
+
const [touchedState, setTouchedUnwrapped] = __rspack_external_react.useState(false);
|
|
337
|
+
const [dirtyState, setDirtyUnwrapped] = __rspack_external_react.useState(false);
|
|
338
|
+
const [filled, setFilled] = __rspack_external_react.useState(false);
|
|
339
|
+
const [focused, setFocused] = __rspack_external_react.useState(false);
|
|
340
|
+
const dirty = dirtyProp ?? dirtyState;
|
|
341
|
+
const touched = touchedProp ?? touchedState;
|
|
342
|
+
const markedDirtyRef = __rspack_external_react.useRef(false);
|
|
343
|
+
const registeredFieldIdRef = __rspack_external_react.useRef(void 0);
|
|
344
|
+
const getRegisteredFieldId = __rspack_external_react.useCallback(()=>registeredFieldIdRef.current, []);
|
|
345
|
+
const setRegisteredFieldId = __rspack_external_react.useCallback((id)=>{
|
|
346
|
+
registeredFieldIdRef.current = id;
|
|
347
|
+
}, []);
|
|
348
|
+
const setDirty = useStableCallback((value)=>{
|
|
349
|
+
if (void 0 !== dirtyProp) return;
|
|
350
|
+
if (value) markedDirtyRef.current = true;
|
|
351
|
+
setDirtyUnwrapped(value);
|
|
352
|
+
});
|
|
353
|
+
const setTouched = useStableCallback((value)=>{
|
|
354
|
+
if (void 0 !== touchedProp) return;
|
|
355
|
+
setTouchedUnwrapped(value);
|
|
356
|
+
});
|
|
357
|
+
const shouldValidateOnChange = useStableCallback(()=>'onChange' === validationMode || 'onSubmit' === validationMode && submitAttemptedRef.current);
|
|
358
|
+
const hasFormError = !!name && Object.hasOwn(errors, name) && void 0 !== errors[name];
|
|
359
|
+
const invalid = true === invalidProp || hasFormError;
|
|
360
|
+
const [validityData, setValidityData] = __rspack_external_react.useState({
|
|
361
|
+
state: DEFAULT_VALIDITY_STATE,
|
|
362
|
+
error: '',
|
|
363
|
+
errors: [],
|
|
364
|
+
value: null,
|
|
365
|
+
initialValue: null
|
|
366
|
+
});
|
|
367
|
+
const valid = !invalid && validityData.state.valid;
|
|
368
|
+
const state = __rspack_external_react.useMemo(()=>({
|
|
369
|
+
disabled,
|
|
370
|
+
touched,
|
|
371
|
+
dirty,
|
|
372
|
+
valid,
|
|
373
|
+
filled,
|
|
374
|
+
focused
|
|
375
|
+
}), [
|
|
376
|
+
disabled,
|
|
377
|
+
touched,
|
|
378
|
+
dirty,
|
|
379
|
+
valid,
|
|
380
|
+
filled,
|
|
381
|
+
focused
|
|
382
|
+
]);
|
|
383
|
+
const validation = useFieldValidation({
|
|
384
|
+
setValidityData,
|
|
385
|
+
validate,
|
|
386
|
+
validityData,
|
|
387
|
+
validationDebounceTime,
|
|
388
|
+
invalid,
|
|
389
|
+
markedDirtyRef,
|
|
390
|
+
state,
|
|
391
|
+
name,
|
|
392
|
+
shouldValidateOnChange,
|
|
393
|
+
getRegisteredFieldId
|
|
394
|
+
});
|
|
395
|
+
const validityValue = validityData.value;
|
|
396
|
+
const handleImperativeValidate = __rspack_external_react.useCallback(()=>{
|
|
397
|
+
markedDirtyRef.current = true;
|
|
398
|
+
validation.commit(validityValue);
|
|
399
|
+
}, [
|
|
400
|
+
validation,
|
|
401
|
+
validityValue
|
|
402
|
+
]);
|
|
403
|
+
const registerFieldControl = useFieldControlRegistration({
|
|
404
|
+
commit: validation.commit,
|
|
405
|
+
invalid,
|
|
406
|
+
markedDirtyRef,
|
|
407
|
+
name,
|
|
408
|
+
setRegisteredFieldId,
|
|
409
|
+
setValidityData,
|
|
410
|
+
validityData
|
|
411
|
+
});
|
|
412
|
+
__rspack_external_react.useImperativeHandle(actionsRef, ()=>({
|
|
413
|
+
validate: handleImperativeValidate
|
|
414
|
+
}), [
|
|
415
|
+
handleImperativeValidate
|
|
416
|
+
]);
|
|
417
|
+
const contextValue = __rspack_external_react.useMemo(()=>({
|
|
418
|
+
invalid,
|
|
419
|
+
name,
|
|
420
|
+
validityData,
|
|
421
|
+
setValidityData,
|
|
422
|
+
disabled,
|
|
423
|
+
touched,
|
|
424
|
+
setTouched,
|
|
425
|
+
dirty,
|
|
426
|
+
setDirty,
|
|
427
|
+
filled,
|
|
428
|
+
setFilled,
|
|
429
|
+
focused,
|
|
430
|
+
setFocused,
|
|
431
|
+
validate,
|
|
432
|
+
validationMode,
|
|
433
|
+
validationDebounceTime,
|
|
434
|
+
shouldValidateOnChange,
|
|
435
|
+
state,
|
|
436
|
+
markedDirtyRef,
|
|
437
|
+
registerFieldControl,
|
|
438
|
+
validation
|
|
439
|
+
}), [
|
|
440
|
+
invalid,
|
|
441
|
+
name,
|
|
442
|
+
validityData,
|
|
443
|
+
disabled,
|
|
444
|
+
touched,
|
|
445
|
+
setTouched,
|
|
446
|
+
dirty,
|
|
447
|
+
setDirty,
|
|
448
|
+
filled,
|
|
449
|
+
setFilled,
|
|
450
|
+
focused,
|
|
451
|
+
setFocused,
|
|
452
|
+
validate,
|
|
453
|
+
validationMode,
|
|
454
|
+
validationDebounceTime,
|
|
455
|
+
shouldValidateOnChange,
|
|
456
|
+
state,
|
|
457
|
+
registerFieldControl,
|
|
458
|
+
validation
|
|
459
|
+
]);
|
|
460
|
+
const element = useRenderElement('div', componentProps, {
|
|
461
|
+
ref: forwardedRef,
|
|
462
|
+
state,
|
|
463
|
+
props: elementProps,
|
|
464
|
+
stateAttributesMapping: fieldValidityMapping
|
|
465
|
+
});
|
|
466
|
+
return /*#__PURE__*/ jsx(FieldRootContext.Provider, {
|
|
467
|
+
value: contextValue,
|
|
468
|
+
children: element
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
if ("production" !== process.env.NODE_ENV) FieldRoot_FieldRootInner.displayName = "FieldRootInner";
|
|
472
|
+
const FieldRoot_FieldRoot = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
473
|
+
return /*#__PURE__*/ jsx(LabelableProvider_LabelableProvider, {
|
|
474
|
+
children: /*#__PURE__*/ jsx(FieldRoot_FieldRootInner, {
|
|
475
|
+
...componentProps,
|
|
476
|
+
ref: forwardedRef
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
if ("production" !== process.env.NODE_ENV) FieldRoot_FieldRoot.displayName = "FieldRoot";
|
|
14
481
|
const FieldLabel_FieldLabel = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
15
482
|
const { render, className, style, id: idProp, nativeLabel = true, ...elementProps } = componentProps;
|
|
16
483
|
const fieldRootContext = useFieldRootContext(false);
|
|
@@ -52,6 +519,108 @@ const FieldLabel_FieldLabel = /*#__PURE__*/ __rspack_external_react.forwardRef(f
|
|
|
52
519
|
return element;
|
|
53
520
|
});
|
|
54
521
|
if ("production" !== process.env.NODE_ENV) FieldLabel_FieldLabel.displayName = "FieldLabel";
|
|
522
|
+
const stateAttributesMapping = {
|
|
523
|
+
...fieldValidityMapping,
|
|
524
|
+
...transitionStatusMapping
|
|
525
|
+
};
|
|
526
|
+
const FieldError_FieldError = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
527
|
+
const { render, id: idProp, className, match, style, ...elementProps } = componentProps;
|
|
528
|
+
const id = useBaseUiId(idProp);
|
|
529
|
+
const { validityData, state: fieldState, name } = useFieldRootContext(false);
|
|
530
|
+
const { setMessageIds } = useLabelableContext();
|
|
531
|
+
const { errors } = useFormContext();
|
|
532
|
+
const formError = name ? errors[name] : null;
|
|
533
|
+
const hasSpecificMatch = 'string' == typeof match;
|
|
534
|
+
let rendered = false;
|
|
535
|
+
rendered = true === match ? true : hasSpecificMatch ? Boolean(validityData.state[match]) : Boolean(formError) || false === validityData.state.valid;
|
|
536
|
+
const { mounted, transitionStatus, setMounted } = useTransitionStatus(rendered);
|
|
537
|
+
useIsoLayoutEffect(()=>{
|
|
538
|
+
if (!rendered || !id) return;
|
|
539
|
+
setMessageIds((v)=>v.concat(id));
|
|
540
|
+
return ()=>{
|
|
541
|
+
setMessageIds((v)=>v.filter((item)=>item !== id));
|
|
542
|
+
};
|
|
543
|
+
}, [
|
|
544
|
+
rendered,
|
|
545
|
+
id,
|
|
546
|
+
setMessageIds
|
|
547
|
+
]);
|
|
548
|
+
const errorRef = __rspack_external_react.useRef(null);
|
|
549
|
+
const [lastRenderedMessage, setLastRenderedMessage] = __rspack_external_react.useState(null);
|
|
550
|
+
const [lastRenderedMessageKey, setLastRenderedMessageKey] = __rspack_external_react.useState(null);
|
|
551
|
+
const clientErrorMessage = validityData.errors.length > 1 ? /*#__PURE__*/ jsx("ul", {
|
|
552
|
+
children: validityData.errors.map((message)=>/*#__PURE__*/ jsx("li", {
|
|
553
|
+
children: message
|
|
554
|
+
}, message))
|
|
555
|
+
}) : validityData.error;
|
|
556
|
+
const errorMessage = hasSpecificMatch ? clientErrorMessage : formError || clientErrorMessage;
|
|
557
|
+
let errorKey = validityData.error;
|
|
558
|
+
if (null != formError) errorKey = Array.isArray(formError) ? JSON.stringify(formError) : formError;
|
|
559
|
+
else if (validityData.errors.length > 1) errorKey = JSON.stringify(validityData.errors);
|
|
560
|
+
if (rendered && errorKey !== lastRenderedMessageKey) {
|
|
561
|
+
setLastRenderedMessageKey(errorKey);
|
|
562
|
+
setLastRenderedMessage(errorMessage);
|
|
563
|
+
}
|
|
564
|
+
useOpenChangeComplete({
|
|
565
|
+
open: rendered,
|
|
566
|
+
ref: errorRef,
|
|
567
|
+
onComplete () {
|
|
568
|
+
if (!rendered) setMounted(false);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
const state = {
|
|
572
|
+
...fieldState,
|
|
573
|
+
transitionStatus
|
|
574
|
+
};
|
|
575
|
+
const element = useRenderElement('div', componentProps, {
|
|
576
|
+
ref: [
|
|
577
|
+
forwardedRef,
|
|
578
|
+
errorRef
|
|
579
|
+
],
|
|
580
|
+
state,
|
|
581
|
+
props: [
|
|
582
|
+
{
|
|
583
|
+
id,
|
|
584
|
+
children: rendered ? errorMessage : lastRenderedMessage
|
|
585
|
+
},
|
|
586
|
+
elementProps
|
|
587
|
+
],
|
|
588
|
+
stateAttributesMapping: stateAttributesMapping,
|
|
589
|
+
enabled: mounted
|
|
590
|
+
});
|
|
591
|
+
if (!mounted) return null;
|
|
592
|
+
return element;
|
|
593
|
+
});
|
|
594
|
+
if ("production" !== process.env.NODE_ENV) FieldError_FieldError.displayName = "FieldError";
|
|
595
|
+
const FieldDescription_FieldDescription = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
596
|
+
const { render, id: idProp, className, style, ...elementProps } = componentProps;
|
|
597
|
+
const id = useBaseUiId(idProp);
|
|
598
|
+
const fieldRootContext = useFieldRootContext(false);
|
|
599
|
+
const { setMessageIds } = useLabelableContext();
|
|
600
|
+
useIsoLayoutEffect(()=>{
|
|
601
|
+
if (!id) return;
|
|
602
|
+
setMessageIds((v)=>v.concat(id));
|
|
603
|
+
return ()=>{
|
|
604
|
+
setMessageIds((v)=>v.filter((item)=>item !== id));
|
|
605
|
+
};
|
|
606
|
+
}, [
|
|
607
|
+
id,
|
|
608
|
+
setMessageIds
|
|
609
|
+
]);
|
|
610
|
+
const element = useRenderElement('p', componentProps, {
|
|
611
|
+
ref: forwardedRef,
|
|
612
|
+
state: fieldRootContext.state,
|
|
613
|
+
props: [
|
|
614
|
+
{
|
|
615
|
+
id
|
|
616
|
+
},
|
|
617
|
+
elementProps
|
|
618
|
+
],
|
|
619
|
+
stateAttributesMapping: fieldValidityMapping
|
|
620
|
+
});
|
|
621
|
+
return element;
|
|
622
|
+
});
|
|
623
|
+
if ("production" !== process.env.NODE_ENV) FieldDescription_FieldDescription.displayName = "FieldDescription";
|
|
55
624
|
const FieldItem_FieldItem = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
56
625
|
const { render, className, style, disabled: disabledProp = false, ...elementProps } = componentProps;
|
|
57
626
|
const { state, disabled: rootDisabled } = useFieldRootContext(false);
|
|
@@ -126,6 +695,15 @@ const Label = /*#__PURE__*/ __rspack_external_react.forwardRef(({ className, var
|
|
|
126
695
|
const Error = /*#__PURE__*/ __rspack_external_react.forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(FieldError_FieldError, {
|
|
127
696
|
ref: ref,
|
|
128
697
|
className: clsx(Field_module.error, className),
|
|
698
|
+
render: ({ children, ...rest })=>/*#__PURE__*/ jsxs("div", {
|
|
699
|
+
...rest,
|
|
700
|
+
children: [
|
|
701
|
+
/*#__PURE__*/ jsx(InfoCircle, {
|
|
702
|
+
"aria-hidden": true
|
|
703
|
+
}),
|
|
704
|
+
children
|
|
705
|
+
]
|
|
706
|
+
}),
|
|
129
707
|
...props
|
|
130
708
|
}));
|
|
131
709
|
const Description = /*#__PURE__*/ __rspack_external_react.forwardRef(({ className, ...props }, ref)=>/*#__PURE__*/ jsx(FieldDescription_FieldDescription, {
|
package/dist/Select/index.css
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
.root-Pyk3SP {
|
|
2
|
-
display: contents;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
1
|
.label-UrIm_f {
|
|
6
2
|
font: var(--wst-paragraph-3-font);
|
|
7
3
|
color: var(--wst-paragraph-2-color, #000);
|
|
@@ -9,6 +5,10 @@
|
|
|
9
5
|
display: block;
|
|
10
6
|
}
|
|
11
7
|
|
|
8
|
+
.label-UrIm_f.fieldLabel-KieHgU {
|
|
9
|
+
padding-bottom: 4px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
12
|
.requiredMarker-ZRoZQT {
|
|
13
13
|
color: var(--wst-system-error-color, #df3131);
|
|
14
14
|
margin-inline-start: 2px;
|
|
@@ -329,27 +329,6 @@ body .item-SBIvtk.item-SBIvtk.item-SBIvtk.item-SBIvtk:focus, body .item-SBIvtk.i
|
|
|
329
329
|
margin-block: 4px;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
.error-rsn7w1 {
|
|
333
|
-
font: var(--wst-paragraph-3-font);
|
|
334
|
-
color: var(--wst-system-error-color, #df3131);
|
|
335
|
-
align-items: center;
|
|
336
|
-
gap: 4px;
|
|
337
|
-
margin: 4px 0 0;
|
|
338
|
-
display: flex;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
.error-rsn7w1 svg {
|
|
342
|
-
flex-shrink: 0;
|
|
343
|
-
width: 1lh;
|
|
344
|
-
height: 1lh;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
.description-WHObss {
|
|
348
|
-
font: var(--wst-paragraph-3-font);
|
|
349
|
-
color: var(--wst-shade-3-color, #767676);
|
|
350
|
-
margin: 4px 0 0;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
332
|
.loadingIndicator-X_6SEg {
|
|
354
333
|
border: 2px solid;
|
|
355
334
|
border-block-start-color: #0000;
|
package/dist/Select/index.js
CHANGED
|
@@ -1804,8 +1804,8 @@ const SelectPortal_SelectPortal = /*#__PURE__*/ __rspack_external_react.forwardR
|
|
|
1804
1804
|
});
|
|
1805
1805
|
if ("production" !== process.env.NODE_ENV) SelectPortal_SelectPortal.displayName = "SelectPortal";
|
|
1806
1806
|
const Select_module = {
|
|
1807
|
-
root: "root-Pyk3SP",
|
|
1808
1807
|
label: "label-UrIm_f",
|
|
1808
|
+
fieldLabel: "fieldLabel-KieHgU",
|
|
1809
1809
|
requiredMarker: "requiredMarker-ZRoZQT",
|
|
1810
1810
|
trigger: "trigger-UPubf5",
|
|
1811
1811
|
value: "value-fKND1Z",
|
|
@@ -1826,8 +1826,6 @@ const Select_module = {
|
|
|
1826
1826
|
scrollUpArrow: "scrollUpArrow-P67Eti",
|
|
1827
1827
|
groupLabel: "groupLabel-GC3RgN",
|
|
1828
1828
|
separator: "separator-XEtOy2",
|
|
1829
|
-
error: "error-rsn7w1",
|
|
1830
|
-
description: "description-WHObss",
|
|
1831
1829
|
loadingIndicator: "loadingIndicator-X_6SEg",
|
|
1832
1830
|
loadingIndicatorSpin: "loadingIndicatorSpin-xPUyVe"
|
|
1833
1831
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ChevronDown
|
|
2
|
+
import { ChevronDown } from "@wix/wix-ui-icons-common";
|
|
3
3
|
import { Select, Select_module } from "../Select/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Field } from "../Field/index.js";
|
|
5
5
|
import * as __rspack_external_react from "react";
|
|
6
6
|
const isDivider = (item)=>'divider' in item;
|
|
7
7
|
const isGroup = (item)=>'groupLabel' in item;
|
|
@@ -41,8 +41,7 @@ function renderOption(option) {
|
|
|
41
41
|
})
|
|
42
42
|
}, value);
|
|
43
43
|
}
|
|
44
|
-
const SelectField = /*#__PURE__*/ __rspack_external_react.forwardRef(({ options, label, 'aria-label': ariaLabel, placeholder, description, error, variant = 'floating', alignment = 'start', invalid = false, loading = false, required = false, disabled = false, readOnly, icon = /*#__PURE__*/ jsx(ChevronDown, {}), outerBorder = false, sideOffset = 4, dir, triggerClassName, popupClassName, ...rootProps }, ref)=>/*#__PURE__*/ jsx(
|
|
45
|
-
className: Select_module.root,
|
|
44
|
+
const SelectField = /*#__PURE__*/ __rspack_external_react.forwardRef(({ options, label, 'aria-label': ariaLabel, placeholder, description, error, variant = 'floating', alignment = 'start', invalid = false, loading = false, required = false, disabled = false, readOnly, icon = /*#__PURE__*/ jsx(ChevronDown, {}), outerBorder = false, sideOffset = 4, dir, triggerClassName, popupClassName, ...rootProps }, ref)=>/*#__PURE__*/ jsx(Field.Root, {
|
|
46
45
|
invalid: invalid,
|
|
47
46
|
disabled: disabled,
|
|
48
47
|
children: /*#__PURE__*/ jsxs(Select.Root, {
|
|
@@ -52,6 +51,7 @@ const SelectField = /*#__PURE__*/ __rspack_external_react.forwardRef(({ options,
|
|
|
52
51
|
...rootProps,
|
|
53
52
|
children: [
|
|
54
53
|
null != label ? /*#__PURE__*/ jsxs(Select.Label, {
|
|
54
|
+
className: Select_module.fieldLabel,
|
|
55
55
|
children: [
|
|
56
56
|
label,
|
|
57
57
|
required ? /*#__PURE__*/ jsx("span", {
|
|
@@ -82,18 +82,11 @@ const SelectField = /*#__PURE__*/ __rspack_external_react.forwardRef(({ options,
|
|
|
82
82
|
})
|
|
83
83
|
]
|
|
84
84
|
}),
|
|
85
|
-
null != error ? /*#__PURE__*/
|
|
86
|
-
className: Select_module.error,
|
|
85
|
+
null != error ? /*#__PURE__*/ jsx(Field.Error, {
|
|
87
86
|
match: invalid,
|
|
88
|
-
children:
|
|
89
|
-
/*#__PURE__*/ jsx(InfoCircle, {
|
|
90
|
-
"aria-hidden": true
|
|
91
|
-
}),
|
|
92
|
-
error
|
|
93
|
-
]
|
|
87
|
+
children: error
|
|
94
88
|
}) : null,
|
|
95
|
-
null != description ? /*#__PURE__*/ jsx(
|
|
96
|
-
className: Select_module.description,
|
|
89
|
+
null != description ? /*#__PURE__*/ jsx(Field.Description, {
|
|
97
90
|
children: description
|
|
98
91
|
}) : null,
|
|
99
92
|
/*#__PURE__*/ jsx(Select.Portal, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/site-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.103.0",
|
|
4
4
|
"description": "Pure UI components for the Wix site builder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"registry": "https://registry.npmjs.org/",
|
|
96
96
|
"access": "public"
|
|
97
97
|
},
|
|
98
|
-
"falconPackageHash": "
|
|
98
|
+
"falconPackageHash": "04dbfc8fad3ed8dba5ecc2545594688558382cb49a23985d1fb81735"
|
|
99
99
|
}
|
package/dist/8972.js
DELETED
|
@@ -1,576 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useBaseUiId } from "./6046.js";
|
|
3
|
-
import { useRefWithInit, EMPTY_OBJECT, mergeProps, useRenderElement } from "./8272.js";
|
|
4
|
-
import { LabelableContext, FieldRootContext, useFieldRootContext, useLabelableContext, fieldValidityMapping, DEFAULT_VALIDITY_STATE } from "./1477.js";
|
|
5
|
-
import { useStableCallback } from "./7541.js";
|
|
6
|
-
import { useFormContext } from "./5085.js";
|
|
7
|
-
import { useTimeout } from "./42.js";
|
|
8
|
-
import { useIsoLayoutEffect } from "./6499.js";
|
|
9
|
-
import { useFieldsetRootContext } from "./353.js";
|
|
10
|
-
import { transitionStatusMapping, useOpenChangeComplete, useTransitionStatus } from "./880.js";
|
|
11
|
-
import * as __rspack_external_react from "react";
|
|
12
|
-
const LabelableProvider_LabelableProvider = function(props) {
|
|
13
|
-
const defaultId = useBaseUiId();
|
|
14
|
-
const initialControlId = void 0 === props.controlId ? defaultId : props.controlId;
|
|
15
|
-
const [controlId, setControlIdState] = __rspack_external_react.useState(initialControlId);
|
|
16
|
-
const [labelId, setLabelId] = __rspack_external_react.useState(props.labelId);
|
|
17
|
-
const [messageIds, setMessageIds] = __rspack_external_react.useState([]);
|
|
18
|
-
const registrationsRef = useRefWithInit(()=>new Map());
|
|
19
|
-
const { messageIds: parentMessageIds } = useLabelableContext();
|
|
20
|
-
const registerControlId = useStableCallback((source, nextId)=>{
|
|
21
|
-
const registrations = registrationsRef.current;
|
|
22
|
-
if (void 0 === nextId) return void registrations.delete(source);
|
|
23
|
-
registrations.set(source, nextId);
|
|
24
|
-
setControlIdState((prev)=>{
|
|
25
|
-
if (0 === registrations.size) return;
|
|
26
|
-
let nextControlId;
|
|
27
|
-
for (const id of registrations.values()){
|
|
28
|
-
if (void 0 !== prev && id === prev) return prev;
|
|
29
|
-
if (void 0 === nextControlId) nextControlId = id;
|
|
30
|
-
}
|
|
31
|
-
return nextControlId;
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
const getDescriptionProps = __rspack_external_react.useCallback((externalProps)=>mergeProps({
|
|
35
|
-
'aria-describedby': parentMessageIds.concat(messageIds).join(' ') || void 0
|
|
36
|
-
}, externalProps), [
|
|
37
|
-
parentMessageIds,
|
|
38
|
-
messageIds
|
|
39
|
-
]);
|
|
40
|
-
const contextValue = __rspack_external_react.useMemo(()=>({
|
|
41
|
-
controlId,
|
|
42
|
-
registerControlId,
|
|
43
|
-
labelId,
|
|
44
|
-
setLabelId,
|
|
45
|
-
messageIds,
|
|
46
|
-
setMessageIds,
|
|
47
|
-
getDescriptionProps
|
|
48
|
-
}), [
|
|
49
|
-
controlId,
|
|
50
|
-
registerControlId,
|
|
51
|
-
labelId,
|
|
52
|
-
setLabelId,
|
|
53
|
-
messageIds,
|
|
54
|
-
setMessageIds,
|
|
55
|
-
getDescriptionProps
|
|
56
|
-
]);
|
|
57
|
-
return /*#__PURE__*/ jsx(LabelableContext.Provider, {
|
|
58
|
-
value: contextValue,
|
|
59
|
-
children: props.children
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
if ("production" !== process.env.NODE_ENV) LabelableProvider_LabelableProvider.displayName = "LabelableProvider";
|
|
63
|
-
function getCombinedFieldValidityData(validityData, invalid) {
|
|
64
|
-
return {
|
|
65
|
-
...validityData,
|
|
66
|
-
state: {
|
|
67
|
-
...validityData.state,
|
|
68
|
-
valid: !invalid && validityData.state.valid
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const validityKeys = Object.keys(DEFAULT_VALIDITY_STATE);
|
|
73
|
-
function isOnlyValueMissing(state) {
|
|
74
|
-
if (!state || state.valid || !state.valueMissing) return false;
|
|
75
|
-
let onlyValueMissing = false;
|
|
76
|
-
for (const key of validityKeys)if ('valid' !== key) {
|
|
77
|
-
if ('valueMissing' === key) onlyValueMissing = state[key];
|
|
78
|
-
if (state[key]) onlyValueMissing = false;
|
|
79
|
-
}
|
|
80
|
-
return onlyValueMissing;
|
|
81
|
-
}
|
|
82
|
-
function useFieldValidation(params) {
|
|
83
|
-
const { formRef, clearErrors } = useFormContext();
|
|
84
|
-
const { setValidityData, validate, validityData, validationDebounceTime, invalid, markedDirtyRef, state, name, shouldValidateOnChange, getRegisteredFieldId } = params;
|
|
85
|
-
const { controlId, getDescriptionProps } = useLabelableContext();
|
|
86
|
-
const timeout = useTimeout();
|
|
87
|
-
const inputRef = __rspack_external_react.useRef(null);
|
|
88
|
-
const commit = useStableCallback(async (value, revalidate = false)=>{
|
|
89
|
-
const element = inputRef.current;
|
|
90
|
-
if (!element) return;
|
|
91
|
-
function updateRegisteredFieldValidity(nextValidityData, externalInvalid = invalid) {
|
|
92
|
-
const fieldId = getRegisteredFieldId() ?? controlId;
|
|
93
|
-
if (null == fieldId) return;
|
|
94
|
-
const currentFieldData = formRef.current.fields.get(fieldId);
|
|
95
|
-
if (!currentFieldData) return;
|
|
96
|
-
const validityDataWithFormErrors = getCombinedFieldValidityData(nextValidityData, externalInvalid);
|
|
97
|
-
formRef.current.fields.set(fieldId, {
|
|
98
|
-
...currentFieldData,
|
|
99
|
-
validityData: validityDataWithFormErrors
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (revalidate) {
|
|
103
|
-
if (false !== state.valid) return;
|
|
104
|
-
const currentNativeValidity = element.validity;
|
|
105
|
-
if (!currentNativeValidity.valueMissing) {
|
|
106
|
-
const nextValidityData = {
|
|
107
|
-
value,
|
|
108
|
-
state: {
|
|
109
|
-
...DEFAULT_VALIDITY_STATE,
|
|
110
|
-
valid: true
|
|
111
|
-
},
|
|
112
|
-
error: '',
|
|
113
|
-
errors: [],
|
|
114
|
-
initialValue: validityData.initialValue
|
|
115
|
-
};
|
|
116
|
-
element.setCustomValidity('');
|
|
117
|
-
updateRegisteredFieldValidity(nextValidityData, false);
|
|
118
|
-
setValidityData(nextValidityData);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const currentNativeValidityObject = validityKeys.reduce((acc, key)=>{
|
|
122
|
-
acc[key] = currentNativeValidity[key];
|
|
123
|
-
return acc;
|
|
124
|
-
}, {});
|
|
125
|
-
if (!currentNativeValidityObject.valid && !isOnlyValueMissing(currentNativeValidityObject)) return;
|
|
126
|
-
}
|
|
127
|
-
function getState(el) {
|
|
128
|
-
const computedState = validityKeys.reduce((acc, key)=>{
|
|
129
|
-
acc[key] = el.validity[key];
|
|
130
|
-
return acc;
|
|
131
|
-
}, {});
|
|
132
|
-
let hasOnlyValueMissingError = false;
|
|
133
|
-
for (const key of validityKeys)if ('valid' !== key) {
|
|
134
|
-
if ('valueMissing' === key && computedState[key]) hasOnlyValueMissingError = true;
|
|
135
|
-
else if (computedState[key]) return computedState;
|
|
136
|
-
}
|
|
137
|
-
if (hasOnlyValueMissingError && !markedDirtyRef.current) {
|
|
138
|
-
computedState.valid = true;
|
|
139
|
-
computedState.valueMissing = false;
|
|
140
|
-
}
|
|
141
|
-
return computedState;
|
|
142
|
-
}
|
|
143
|
-
timeout.clear();
|
|
144
|
-
let result = null;
|
|
145
|
-
let validationErrors = [];
|
|
146
|
-
const nextState = getState(element);
|
|
147
|
-
let defaultValidationMessage;
|
|
148
|
-
const validateOnChange = shouldValidateOnChange();
|
|
149
|
-
if (element.validationMessage && !validateOnChange) {
|
|
150
|
-
defaultValidationMessage = element.validationMessage;
|
|
151
|
-
validationErrors = [
|
|
152
|
-
element.validationMessage
|
|
153
|
-
];
|
|
154
|
-
} else {
|
|
155
|
-
const formValues = Array.from(formRef.current.fields.values()).reduce((acc, field)=>{
|
|
156
|
-
if (field.name) acc[field.name] = field.getValue();
|
|
157
|
-
return acc;
|
|
158
|
-
}, {});
|
|
159
|
-
const resultOrPromise = validate(value, formValues);
|
|
160
|
-
result = 'object' == typeof resultOrPromise && null !== resultOrPromise && 'then' in resultOrPromise ? await resultOrPromise : resultOrPromise;
|
|
161
|
-
if (null !== result) {
|
|
162
|
-
nextState.valid = false;
|
|
163
|
-
nextState.customError = true;
|
|
164
|
-
if (Array.isArray(result)) {
|
|
165
|
-
validationErrors = result;
|
|
166
|
-
element.setCustomValidity(result.join('\n'));
|
|
167
|
-
} else if (result) {
|
|
168
|
-
validationErrors = [
|
|
169
|
-
result
|
|
170
|
-
];
|
|
171
|
-
element.setCustomValidity(result);
|
|
172
|
-
}
|
|
173
|
-
} else if (validateOnChange) {
|
|
174
|
-
element.setCustomValidity('');
|
|
175
|
-
nextState.customError = false;
|
|
176
|
-
if (element.validationMessage) {
|
|
177
|
-
defaultValidationMessage = element.validationMessage;
|
|
178
|
-
validationErrors = [
|
|
179
|
-
element.validationMessage
|
|
180
|
-
];
|
|
181
|
-
} else if (element.validity.valid && !nextState.valid) nextState.valid = true;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
const nextValidityData = {
|
|
185
|
-
value,
|
|
186
|
-
state: nextState,
|
|
187
|
-
error: defaultValidationMessage ?? (Array.isArray(result) ? result[0] : result ?? ''),
|
|
188
|
-
errors: validationErrors,
|
|
189
|
-
initialValue: validityData.initialValue
|
|
190
|
-
};
|
|
191
|
-
updateRegisteredFieldValidity(nextValidityData);
|
|
192
|
-
setValidityData(nextValidityData);
|
|
193
|
-
});
|
|
194
|
-
const getValidationProps = __rspack_external_react.useCallback((externalProps = {})=>mergeProps(getDescriptionProps, false === state.valid ? {
|
|
195
|
-
'aria-invalid': true
|
|
196
|
-
} : EMPTY_OBJECT, externalProps), [
|
|
197
|
-
getDescriptionProps,
|
|
198
|
-
state.valid
|
|
199
|
-
]);
|
|
200
|
-
const getInputValidationProps = __rspack_external_react.useCallback((externalProps = {})=>mergeProps({
|
|
201
|
-
onChange (event) {
|
|
202
|
-
if (event.nativeEvent.defaultPrevented) return;
|
|
203
|
-
clearErrors(name);
|
|
204
|
-
if (!shouldValidateOnChange()) return void commit(event.currentTarget.value, true);
|
|
205
|
-
const element = event.currentTarget;
|
|
206
|
-
if ('' === element.value) return void commit(element.value);
|
|
207
|
-
timeout.clear();
|
|
208
|
-
if (validationDebounceTime) timeout.start(validationDebounceTime, ()=>{
|
|
209
|
-
commit(element.value);
|
|
210
|
-
});
|
|
211
|
-
else commit(element.value);
|
|
212
|
-
}
|
|
213
|
-
}, getValidationProps(externalProps)), [
|
|
214
|
-
getValidationProps,
|
|
215
|
-
clearErrors,
|
|
216
|
-
name,
|
|
217
|
-
timeout,
|
|
218
|
-
commit,
|
|
219
|
-
validationDebounceTime,
|
|
220
|
-
shouldValidateOnChange
|
|
221
|
-
]);
|
|
222
|
-
return __rspack_external_react.useMemo(()=>({
|
|
223
|
-
getValidationProps,
|
|
224
|
-
getInputValidationProps,
|
|
225
|
-
inputRef,
|
|
226
|
-
commit
|
|
227
|
-
}), [
|
|
228
|
-
getValidationProps,
|
|
229
|
-
getInputValidationProps,
|
|
230
|
-
commit
|
|
231
|
-
]);
|
|
232
|
-
}
|
|
233
|
-
function useFieldControlRegistration(params) {
|
|
234
|
-
const { commit, invalid, markedDirtyRef, name, setRegisteredFieldId, setValidityData, validityData } = params;
|
|
235
|
-
const { formRef } = useFormContext();
|
|
236
|
-
const activeFieldControlSourceRef = __rspack_external_react.useRef(null);
|
|
237
|
-
const registrationRef = __rspack_external_react.useRef(null);
|
|
238
|
-
const fallbackControlRef = __rspack_external_react.useRef(null);
|
|
239
|
-
const getValueForForm = useStableCallback(()=>{
|
|
240
|
-
const registration = registrationRef.current;
|
|
241
|
-
if (!registration) return;
|
|
242
|
-
if (registration.getValue) return registration.getValue();
|
|
243
|
-
return registration.value;
|
|
244
|
-
});
|
|
245
|
-
const validate = useStableCallback(()=>{
|
|
246
|
-
const registration = registrationRef.current;
|
|
247
|
-
if (!registration) return;
|
|
248
|
-
let nextValue = registration.value;
|
|
249
|
-
if (void 0 === nextValue) nextValue = getValueForForm();
|
|
250
|
-
markedDirtyRef.current = true;
|
|
251
|
-
commit(nextValue);
|
|
252
|
-
});
|
|
253
|
-
function refreshRegistration() {
|
|
254
|
-
const registration = registrationRef.current;
|
|
255
|
-
if (!registration || !registration.id) return;
|
|
256
|
-
formRef.current.fields.set(registration.id, {
|
|
257
|
-
getValue: getValueForForm,
|
|
258
|
-
name,
|
|
259
|
-
controlRef: registration.controlRef ?? fallbackControlRef,
|
|
260
|
-
validityData: getCombinedFieldValidityData(validityData, invalid),
|
|
261
|
-
validate
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
function deleteRegistration(id = registrationRef.current?.id) {
|
|
265
|
-
if (id) formRef.current.fields.delete(id);
|
|
266
|
-
}
|
|
267
|
-
function syncInitialValue() {
|
|
268
|
-
const registration = registrationRef.current;
|
|
269
|
-
if (!registration) return;
|
|
270
|
-
let initialValue = registration.value;
|
|
271
|
-
if (void 0 === initialValue) initialValue = getValueForForm();
|
|
272
|
-
if (null === validityData.initialValue && null !== initialValue) setValidityData((prev)=>({
|
|
273
|
-
...prev,
|
|
274
|
-
initialValue
|
|
275
|
-
}));
|
|
276
|
-
}
|
|
277
|
-
useIsoLayoutEffect(()=>{
|
|
278
|
-
const registration = registrationRef.current;
|
|
279
|
-
if (!registration || !registration.id) return;
|
|
280
|
-
formRef.current.fields.set(registration.id, {
|
|
281
|
-
getValue: getValueForForm,
|
|
282
|
-
name,
|
|
283
|
-
controlRef: registration.controlRef ?? fallbackControlRef,
|
|
284
|
-
validityData: getCombinedFieldValidityData(validityData, invalid),
|
|
285
|
-
validate
|
|
286
|
-
});
|
|
287
|
-
}, [
|
|
288
|
-
formRef,
|
|
289
|
-
getValueForForm,
|
|
290
|
-
invalid,
|
|
291
|
-
name,
|
|
292
|
-
validate,
|
|
293
|
-
validityData
|
|
294
|
-
]);
|
|
295
|
-
useIsoLayoutEffect(()=>{
|
|
296
|
-
const fields = formRef.current.fields;
|
|
297
|
-
return ()=>{
|
|
298
|
-
const id = registrationRef.current?.id;
|
|
299
|
-
if (id) fields.delete(id);
|
|
300
|
-
};
|
|
301
|
-
}, [
|
|
302
|
-
formRef
|
|
303
|
-
]);
|
|
304
|
-
return useStableCallback((source, registration)=>{
|
|
305
|
-
if (!registration) {
|
|
306
|
-
if (activeFieldControlSourceRef.current === source) {
|
|
307
|
-
activeFieldControlSourceRef.current = null;
|
|
308
|
-
deleteRegistration();
|
|
309
|
-
registrationRef.current = null;
|
|
310
|
-
setRegisteredFieldId(void 0);
|
|
311
|
-
}
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const previousId = registrationRef.current?.id;
|
|
315
|
-
activeFieldControlSourceRef.current = source;
|
|
316
|
-
registrationRef.current = registration;
|
|
317
|
-
setRegisteredFieldId(registration.id);
|
|
318
|
-
if (previousId && previousId !== registration.id) deleteRegistration(previousId);
|
|
319
|
-
syncInitialValue();
|
|
320
|
-
refreshRegistration();
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
const FieldRoot_FieldRootInner = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
324
|
-
const { errors, validationMode: formValidationMode, submitAttemptedRef } = useFormContext();
|
|
325
|
-
const { render, className, validate: validateProp, validationDebounceTime = 0, validationMode = formValidationMode, name, disabled: disabledProp = false, invalid: invalidProp, dirty: dirtyProp, touched: touchedProp, actionsRef, style, ...elementProps } = componentProps;
|
|
326
|
-
const { disabled: disabledFieldset } = useFieldsetRootContext();
|
|
327
|
-
const validate = useStableCallback(validateProp || (()=>null));
|
|
328
|
-
const disabled = disabledFieldset || disabledProp;
|
|
329
|
-
const [touchedState, setTouchedUnwrapped] = __rspack_external_react.useState(false);
|
|
330
|
-
const [dirtyState, setDirtyUnwrapped] = __rspack_external_react.useState(false);
|
|
331
|
-
const [filled, setFilled] = __rspack_external_react.useState(false);
|
|
332
|
-
const [focused, setFocused] = __rspack_external_react.useState(false);
|
|
333
|
-
const dirty = dirtyProp ?? dirtyState;
|
|
334
|
-
const touched = touchedProp ?? touchedState;
|
|
335
|
-
const markedDirtyRef = __rspack_external_react.useRef(false);
|
|
336
|
-
const registeredFieldIdRef = __rspack_external_react.useRef(void 0);
|
|
337
|
-
const getRegisteredFieldId = __rspack_external_react.useCallback(()=>registeredFieldIdRef.current, []);
|
|
338
|
-
const setRegisteredFieldId = __rspack_external_react.useCallback((id)=>{
|
|
339
|
-
registeredFieldIdRef.current = id;
|
|
340
|
-
}, []);
|
|
341
|
-
const setDirty = useStableCallback((value)=>{
|
|
342
|
-
if (void 0 !== dirtyProp) return;
|
|
343
|
-
if (value) markedDirtyRef.current = true;
|
|
344
|
-
setDirtyUnwrapped(value);
|
|
345
|
-
});
|
|
346
|
-
const setTouched = useStableCallback((value)=>{
|
|
347
|
-
if (void 0 !== touchedProp) return;
|
|
348
|
-
setTouchedUnwrapped(value);
|
|
349
|
-
});
|
|
350
|
-
const shouldValidateOnChange = useStableCallback(()=>'onChange' === validationMode || 'onSubmit' === validationMode && submitAttemptedRef.current);
|
|
351
|
-
const hasFormError = !!name && Object.hasOwn(errors, name) && void 0 !== errors[name];
|
|
352
|
-
const invalid = true === invalidProp || hasFormError;
|
|
353
|
-
const [validityData, setValidityData] = __rspack_external_react.useState({
|
|
354
|
-
state: DEFAULT_VALIDITY_STATE,
|
|
355
|
-
error: '',
|
|
356
|
-
errors: [],
|
|
357
|
-
value: null,
|
|
358
|
-
initialValue: null
|
|
359
|
-
});
|
|
360
|
-
const valid = !invalid && validityData.state.valid;
|
|
361
|
-
const state = __rspack_external_react.useMemo(()=>({
|
|
362
|
-
disabled,
|
|
363
|
-
touched,
|
|
364
|
-
dirty,
|
|
365
|
-
valid,
|
|
366
|
-
filled,
|
|
367
|
-
focused
|
|
368
|
-
}), [
|
|
369
|
-
disabled,
|
|
370
|
-
touched,
|
|
371
|
-
dirty,
|
|
372
|
-
valid,
|
|
373
|
-
filled,
|
|
374
|
-
focused
|
|
375
|
-
]);
|
|
376
|
-
const validation = useFieldValidation({
|
|
377
|
-
setValidityData,
|
|
378
|
-
validate,
|
|
379
|
-
validityData,
|
|
380
|
-
validationDebounceTime,
|
|
381
|
-
invalid,
|
|
382
|
-
markedDirtyRef,
|
|
383
|
-
state,
|
|
384
|
-
name,
|
|
385
|
-
shouldValidateOnChange,
|
|
386
|
-
getRegisteredFieldId
|
|
387
|
-
});
|
|
388
|
-
const validityValue = validityData.value;
|
|
389
|
-
const handleImperativeValidate = __rspack_external_react.useCallback(()=>{
|
|
390
|
-
markedDirtyRef.current = true;
|
|
391
|
-
validation.commit(validityValue);
|
|
392
|
-
}, [
|
|
393
|
-
validation,
|
|
394
|
-
validityValue
|
|
395
|
-
]);
|
|
396
|
-
const registerFieldControl = useFieldControlRegistration({
|
|
397
|
-
commit: validation.commit,
|
|
398
|
-
invalid,
|
|
399
|
-
markedDirtyRef,
|
|
400
|
-
name,
|
|
401
|
-
setRegisteredFieldId,
|
|
402
|
-
setValidityData,
|
|
403
|
-
validityData
|
|
404
|
-
});
|
|
405
|
-
__rspack_external_react.useImperativeHandle(actionsRef, ()=>({
|
|
406
|
-
validate: handleImperativeValidate
|
|
407
|
-
}), [
|
|
408
|
-
handleImperativeValidate
|
|
409
|
-
]);
|
|
410
|
-
const contextValue = __rspack_external_react.useMemo(()=>({
|
|
411
|
-
invalid,
|
|
412
|
-
name,
|
|
413
|
-
validityData,
|
|
414
|
-
setValidityData,
|
|
415
|
-
disabled,
|
|
416
|
-
touched,
|
|
417
|
-
setTouched,
|
|
418
|
-
dirty,
|
|
419
|
-
setDirty,
|
|
420
|
-
filled,
|
|
421
|
-
setFilled,
|
|
422
|
-
focused,
|
|
423
|
-
setFocused,
|
|
424
|
-
validate,
|
|
425
|
-
validationMode,
|
|
426
|
-
validationDebounceTime,
|
|
427
|
-
shouldValidateOnChange,
|
|
428
|
-
state,
|
|
429
|
-
markedDirtyRef,
|
|
430
|
-
registerFieldControl,
|
|
431
|
-
validation
|
|
432
|
-
}), [
|
|
433
|
-
invalid,
|
|
434
|
-
name,
|
|
435
|
-
validityData,
|
|
436
|
-
disabled,
|
|
437
|
-
touched,
|
|
438
|
-
setTouched,
|
|
439
|
-
dirty,
|
|
440
|
-
setDirty,
|
|
441
|
-
filled,
|
|
442
|
-
setFilled,
|
|
443
|
-
focused,
|
|
444
|
-
setFocused,
|
|
445
|
-
validate,
|
|
446
|
-
validationMode,
|
|
447
|
-
validationDebounceTime,
|
|
448
|
-
shouldValidateOnChange,
|
|
449
|
-
state,
|
|
450
|
-
registerFieldControl,
|
|
451
|
-
validation
|
|
452
|
-
]);
|
|
453
|
-
const element = useRenderElement('div', componentProps, {
|
|
454
|
-
ref: forwardedRef,
|
|
455
|
-
state,
|
|
456
|
-
props: elementProps,
|
|
457
|
-
stateAttributesMapping: fieldValidityMapping
|
|
458
|
-
});
|
|
459
|
-
return /*#__PURE__*/ jsx(FieldRootContext.Provider, {
|
|
460
|
-
value: contextValue,
|
|
461
|
-
children: element
|
|
462
|
-
});
|
|
463
|
-
});
|
|
464
|
-
if ("production" !== process.env.NODE_ENV) FieldRoot_FieldRootInner.displayName = "FieldRootInner";
|
|
465
|
-
const FieldRoot_FieldRoot = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
466
|
-
return /*#__PURE__*/ jsx(LabelableProvider_LabelableProvider, {
|
|
467
|
-
children: /*#__PURE__*/ jsx(FieldRoot_FieldRootInner, {
|
|
468
|
-
...componentProps,
|
|
469
|
-
ref: forwardedRef
|
|
470
|
-
})
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
if ("production" !== process.env.NODE_ENV) FieldRoot_FieldRoot.displayName = "FieldRoot";
|
|
474
|
-
const stateAttributesMapping = {
|
|
475
|
-
...fieldValidityMapping,
|
|
476
|
-
...transitionStatusMapping
|
|
477
|
-
};
|
|
478
|
-
const FieldError_FieldError = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
479
|
-
const { render, id: idProp, className, match, style, ...elementProps } = componentProps;
|
|
480
|
-
const id = useBaseUiId(idProp);
|
|
481
|
-
const { validityData, state: fieldState, name } = useFieldRootContext(false);
|
|
482
|
-
const { setMessageIds } = useLabelableContext();
|
|
483
|
-
const { errors } = useFormContext();
|
|
484
|
-
const formError = name ? errors[name] : null;
|
|
485
|
-
const hasSpecificMatch = 'string' == typeof match;
|
|
486
|
-
let rendered = false;
|
|
487
|
-
rendered = true === match ? true : hasSpecificMatch ? Boolean(validityData.state[match]) : Boolean(formError) || false === validityData.state.valid;
|
|
488
|
-
const { mounted, transitionStatus, setMounted } = useTransitionStatus(rendered);
|
|
489
|
-
useIsoLayoutEffect(()=>{
|
|
490
|
-
if (!rendered || !id) return;
|
|
491
|
-
setMessageIds((v)=>v.concat(id));
|
|
492
|
-
return ()=>{
|
|
493
|
-
setMessageIds((v)=>v.filter((item)=>item !== id));
|
|
494
|
-
};
|
|
495
|
-
}, [
|
|
496
|
-
rendered,
|
|
497
|
-
id,
|
|
498
|
-
setMessageIds
|
|
499
|
-
]);
|
|
500
|
-
const errorRef = __rspack_external_react.useRef(null);
|
|
501
|
-
const [lastRenderedMessage, setLastRenderedMessage] = __rspack_external_react.useState(null);
|
|
502
|
-
const [lastRenderedMessageKey, setLastRenderedMessageKey] = __rspack_external_react.useState(null);
|
|
503
|
-
const clientErrorMessage = validityData.errors.length > 1 ? /*#__PURE__*/ jsx("ul", {
|
|
504
|
-
children: validityData.errors.map((message)=>/*#__PURE__*/ jsx("li", {
|
|
505
|
-
children: message
|
|
506
|
-
}, message))
|
|
507
|
-
}) : validityData.error;
|
|
508
|
-
const errorMessage = hasSpecificMatch ? clientErrorMessage : formError || clientErrorMessage;
|
|
509
|
-
let errorKey = validityData.error;
|
|
510
|
-
if (null != formError) errorKey = Array.isArray(formError) ? JSON.stringify(formError) : formError;
|
|
511
|
-
else if (validityData.errors.length > 1) errorKey = JSON.stringify(validityData.errors);
|
|
512
|
-
if (rendered && errorKey !== lastRenderedMessageKey) {
|
|
513
|
-
setLastRenderedMessageKey(errorKey);
|
|
514
|
-
setLastRenderedMessage(errorMessage);
|
|
515
|
-
}
|
|
516
|
-
useOpenChangeComplete({
|
|
517
|
-
open: rendered,
|
|
518
|
-
ref: errorRef,
|
|
519
|
-
onComplete () {
|
|
520
|
-
if (!rendered) setMounted(false);
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
const state = {
|
|
524
|
-
...fieldState,
|
|
525
|
-
transitionStatus
|
|
526
|
-
};
|
|
527
|
-
const element = useRenderElement('div', componentProps, {
|
|
528
|
-
ref: [
|
|
529
|
-
forwardedRef,
|
|
530
|
-
errorRef
|
|
531
|
-
],
|
|
532
|
-
state,
|
|
533
|
-
props: [
|
|
534
|
-
{
|
|
535
|
-
id,
|
|
536
|
-
children: rendered ? errorMessage : lastRenderedMessage
|
|
537
|
-
},
|
|
538
|
-
elementProps
|
|
539
|
-
],
|
|
540
|
-
stateAttributesMapping: stateAttributesMapping,
|
|
541
|
-
enabled: mounted
|
|
542
|
-
});
|
|
543
|
-
if (!mounted) return null;
|
|
544
|
-
return element;
|
|
545
|
-
});
|
|
546
|
-
if ("production" !== process.env.NODE_ENV) FieldError_FieldError.displayName = "FieldError";
|
|
547
|
-
const FieldDescription_FieldDescription = /*#__PURE__*/ __rspack_external_react.forwardRef(function(componentProps, forwardedRef) {
|
|
548
|
-
const { render, id: idProp, className, style, ...elementProps } = componentProps;
|
|
549
|
-
const id = useBaseUiId(idProp);
|
|
550
|
-
const fieldRootContext = useFieldRootContext(false);
|
|
551
|
-
const { setMessageIds } = useLabelableContext();
|
|
552
|
-
useIsoLayoutEffect(()=>{
|
|
553
|
-
if (!id) return;
|
|
554
|
-
setMessageIds((v)=>v.concat(id));
|
|
555
|
-
return ()=>{
|
|
556
|
-
setMessageIds((v)=>v.filter((item)=>item !== id));
|
|
557
|
-
};
|
|
558
|
-
}, [
|
|
559
|
-
id,
|
|
560
|
-
setMessageIds
|
|
561
|
-
]);
|
|
562
|
-
const element = useRenderElement('p', componentProps, {
|
|
563
|
-
ref: forwardedRef,
|
|
564
|
-
state: fieldRootContext.state,
|
|
565
|
-
props: [
|
|
566
|
-
{
|
|
567
|
-
id
|
|
568
|
-
},
|
|
569
|
-
elementProps
|
|
570
|
-
],
|
|
571
|
-
stateAttributesMapping: fieldValidityMapping
|
|
572
|
-
});
|
|
573
|
-
return element;
|
|
574
|
-
});
|
|
575
|
-
if ("production" !== process.env.NODE_ENV) FieldDescription_FieldDescription.displayName = "FieldDescription";
|
|
576
|
-
export { FieldDescription_FieldDescription, FieldError_FieldError, FieldRoot_FieldRoot, LabelableProvider_LabelableProvider, getCombinedFieldValidityData };
|