@wix/form-public 0.512.0 → 0.514.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/index.cjs +63 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import ReactDOM from 'react-dom';
|
|
|
7
7
|
import camelCase2 from 'lodash.camelcase';
|
|
8
8
|
import mapKeys from 'lodash.mapkeys';
|
|
9
9
|
import { jsx } from 'react/jsx-runtime';
|
|
10
|
-
import { CheckboxField, CheckboxButton, TextField, Input, ListBoxItem, ListBox, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, useSlottedContext, PopoverContext, Popover, Autocomplete, RadioField, RadioButton, CheckboxGroup as CheckboxGroup$1, I18nProvider, DatePicker as DatePicker$1, Select, NumberField, TimeField, SelectValue, CalendarCell, Calendar as Calendar$1, CalendarMonthPicker, CalendarYearPicker, CalendarGrid, DatePickerStateContext, DateInput as DateInput$1, DateSegment, TimeFieldStateContext, FileTrigger, DropZone as DropZone$1, Text as Text$1, ProgressBar, ComboBox, DialogTrigger, TextArea as TextArea$1, ComboBoxStateContext } from 'react-aria-components';
|
|
10
|
+
import { CheckboxField, CheckboxButton, TextField, Input, ListBoxItem, ListBox, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, useSlottedContext, PopoverContext, Popover, Autocomplete, RadioField, RadioButton, CheckboxGroup as CheckboxGroup$1, I18nProvider, DatePicker as DatePicker$1, Select, VisuallyHidden, NumberField, TimeField, SelectValue, CalendarCell, Calendar as Calendar$1, CalendarMonthPicker, CalendarYearPicker, CalendarGrid, DatePickerStateContext, DateInput as DateInput$1, DateSegment, TimeFieldStateContext, FileTrigger, DropZone as DropZone$1, Text as Text$1, ProgressBar, ComboBox, DialogTrigger, TextArea as TextArea$1, ComboBoxStateContext } from 'react-aria-components';
|
|
11
11
|
|
|
12
12
|
var __create = Object.create;
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
@@ -43120,6 +43120,7 @@ var ForcedState = /* @__PURE__ */ (function(ForcedState2) {
|
|
|
43120
43120
|
ForcedState2["INPUT_FIELDS_HOVER"] = "INPUT_FIELDS_HOVER";
|
|
43121
43121
|
ForcedState2["INPUT_FIELDS_FOCUS"] = "INPUT_FIELDS_FOCUS";
|
|
43122
43122
|
ForcedState2["INPUT_FIELDS_ERROR"] = "INPUT_FIELDS_ERROR";
|
|
43123
|
+
ForcedState2["SUCCESS_MESSAGE"] = "SUCCESS_MESSAGE";
|
|
43123
43124
|
return ForcedState2;
|
|
43124
43125
|
})({});
|
|
43125
43126
|
var ForcedStateContext = createContext([]);
|
|
@@ -55713,9 +55714,9 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55713
55714
|
setFormStatus,
|
|
55714
55715
|
target
|
|
55715
55716
|
]);
|
|
55716
|
-
const
|
|
55717
|
+
const getStatusText = useCallback(() => {
|
|
55717
55718
|
if (!files.length) {
|
|
55718
|
-
return
|
|
55719
|
+
return void 0;
|
|
55719
55720
|
}
|
|
55720
55721
|
const uploadingCount = files.filter((f) => f.state === "uploading").length;
|
|
55721
55722
|
if (uploadingCount) {
|
|
@@ -55725,14 +55726,27 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55725
55726
|
count: Math.round(progress * 100)
|
|
55726
55727
|
});
|
|
55727
55728
|
}
|
|
55728
|
-
return
|
|
55729
|
+
return t(`form.file-upload.explanation-text`, {
|
|
55729
55730
|
count: files.length
|
|
55730
55731
|
});
|
|
55731
55732
|
}, [
|
|
55732
55733
|
files,
|
|
55733
|
-
explanationText,
|
|
55734
55734
|
t
|
|
55735
55735
|
]);
|
|
55736
|
+
const getExplanationText = useCallback(() => {
|
|
55737
|
+
if (!files.length) {
|
|
55738
|
+
return explanationText;
|
|
55739
|
+
}
|
|
55740
|
+
const isUploading = files.some((f) => f.state === "uploading");
|
|
55741
|
+
if (isUploading) {
|
|
55742
|
+
return getStatusText();
|
|
55743
|
+
}
|
|
55744
|
+
return explanationText || getStatusText();
|
|
55745
|
+
}, [
|
|
55746
|
+
files,
|
|
55747
|
+
explanationText,
|
|
55748
|
+
getStatusText
|
|
55749
|
+
]);
|
|
55736
55750
|
const _uploadFiles = useCallback(async (filesToUpload) => {
|
|
55737
55751
|
await uploadFiles(filesToUpload, ({ file, uploadedFile }) => {
|
|
55738
55752
|
setFiles((previousFiles) => previousFiles.map((f) => f.file === file ? {
|
|
@@ -55815,6 +55829,7 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55815
55829
|
limitError,
|
|
55816
55830
|
hover,
|
|
55817
55831
|
getExplanationText,
|
|
55832
|
+
getStatusText,
|
|
55818
55833
|
handleChange,
|
|
55819
55834
|
handleDelete,
|
|
55820
55835
|
accept,
|
|
@@ -55852,7 +55867,10 @@ function useFileUploadContext() {
|
|
|
55852
55867
|
var DropZone = ({ children, className }) => {
|
|
55853
55868
|
const { ariaDescribedBy } = useFieldAttributes();
|
|
55854
55869
|
const { disabled, hasError } = useFieldPropsV2();
|
|
55855
|
-
const { handleFileChange } = useFileUploadContext();
|
|
55870
|
+
const { handleFileChange, limitReached } = useFileUploadContext();
|
|
55871
|
+
if (limitReached) {
|
|
55872
|
+
return null;
|
|
55873
|
+
}
|
|
55856
55874
|
const titleElement = findChildOfType(children, DropZone.Title);
|
|
55857
55875
|
const subtitleElement = findChildOfType(children, DropZone.Subtitle);
|
|
55858
55876
|
const buttonElement = findChildOfType(children, DropZone.Button);
|
|
@@ -55891,13 +55909,14 @@ var DropZoneTitle = ({ className, children }) => {
|
|
|
55891
55909
|
};
|
|
55892
55910
|
var DropZoneSubtitle = ({ className, children }) => {
|
|
55893
55911
|
const { limitReached } = useFileUploadContext();
|
|
55912
|
+
const { explanationText } = useFieldPropsV2();
|
|
55894
55913
|
return /* @__PURE__ */ React172.createElement("p", {
|
|
55895
55914
|
className
|
|
55896
|
-
}, children({
|
|
55915
|
+
}, explanationText || children({
|
|
55897
55916
|
limitReached
|
|
55898
55917
|
}));
|
|
55899
55918
|
};
|
|
55900
|
-
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription }) => {
|
|
55919
|
+
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription, onHoverStart, onHoverEnd }) => {
|
|
55901
55920
|
const { ariaDescribedBy, inputId, labelId, errorId } = useFieldAttributes();
|
|
55902
55921
|
const { disabled, required, onFocus, hasError, errorMessage } = useFieldPropsV2();
|
|
55903
55922
|
const { handleFileChange, accept, multiple, buttonRef, handleBlur, limitError, files } = useFileUploadContext();
|
|
@@ -55931,7 +55950,9 @@ var DropZoneButton = ({ className, children, "aria-roledescription": roleDescrip
|
|
|
55931
55950
|
isDisabled: disabled,
|
|
55932
55951
|
className,
|
|
55933
55952
|
onFocus,
|
|
55934
|
-
onBlur: handleBlur
|
|
55953
|
+
onBlur: handleBlur,
|
|
55954
|
+
onHoverStart,
|
|
55955
|
+
onHoverEnd
|
|
55935
55956
|
}, children));
|
|
55936
55957
|
};
|
|
55937
55958
|
var DropZoneButtonText = ({ className }) => {
|
|
@@ -56044,13 +56065,19 @@ Files.File = File2;
|
|
|
56044
56065
|
// ../form-fields/dist/esm/ui/file-upload/file-upload-headless/file-upload-headless.js
|
|
56045
56066
|
var fileKey = (f) => f.file.name;
|
|
56046
56067
|
var FileUpload = ({ children }) => {
|
|
56068
|
+
const { t } = useTranslation2();
|
|
56047
56069
|
const { id: id6, value, onChange, uploadFileFormats, valueSliderLimit, target, explanationText, onBlur, hasError, errorMessage, FieldLayout } = useFieldPropsV2();
|
|
56048
56070
|
const buttonRef = useRef(null);
|
|
56049
56071
|
const fileRemoveButtonRefs = useRef({});
|
|
56072
|
+
const pendingUploadButtonFocus = useRef(false);
|
|
56050
56073
|
const handleFilesCleared = useCallback(() => {
|
|
56051
|
-
buttonRef.current
|
|
56074
|
+
if (buttonRef.current) {
|
|
56075
|
+
buttonRef.current.focus();
|
|
56076
|
+
} else {
|
|
56077
|
+
pendingUploadButtonFocus.current = true;
|
|
56078
|
+
}
|
|
56052
56079
|
}, []);
|
|
56053
|
-
const { files, limitError, hover, getExplanationText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56080
|
+
const { files, limitError, hover, getExplanationText, getStatusText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56054
56081
|
valueSliderLimit,
|
|
56055
56082
|
value,
|
|
56056
56083
|
explanationText,
|
|
@@ -56072,6 +56099,14 @@ var FileUpload = ({ children }) => {
|
|
|
56072
56099
|
_handleDelete,
|
|
56073
56100
|
files
|
|
56074
56101
|
]);
|
|
56102
|
+
useEffect(() => {
|
|
56103
|
+
if (pendingUploadButtonFocus.current && buttonRef.current) {
|
|
56104
|
+
pendingUploadButtonFocus.current = false;
|
|
56105
|
+
buttonRef.current.focus();
|
|
56106
|
+
}
|
|
56107
|
+
}, [
|
|
56108
|
+
files
|
|
56109
|
+
]);
|
|
56075
56110
|
const multiple = valueSliderLimit > 1;
|
|
56076
56111
|
const limitReached = files.length >= valueSliderLimit;
|
|
56077
56112
|
const contextValue = useMemo(() => ({
|
|
@@ -56083,6 +56118,7 @@ var FileUpload = ({ children }) => {
|
|
|
56083
56118
|
limitReached,
|
|
56084
56119
|
multiple,
|
|
56085
56120
|
getExplanationText,
|
|
56121
|
+
getStatusText,
|
|
56086
56122
|
hover,
|
|
56087
56123
|
limitError,
|
|
56088
56124
|
buttonRef,
|
|
@@ -56096,6 +56132,7 @@ var FileUpload = ({ children }) => {
|
|
|
56096
56132
|
limitReached,
|
|
56097
56133
|
multiple,
|
|
56098
56134
|
getExplanationText,
|
|
56135
|
+
getStatusText,
|
|
56099
56136
|
hover,
|
|
56100
56137
|
limitError
|
|
56101
56138
|
]);
|
|
@@ -56107,7 +56144,11 @@ var FileUpload = ({ children }) => {
|
|
|
56107
56144
|
const descriptionElement = findChildOfType(children, FileUpload.Description);
|
|
56108
56145
|
const errorElement = findChildOfType(children, FileUpload.Error);
|
|
56109
56146
|
useFocusFieldEvent(() => {
|
|
56110
|
-
buttonRef.current
|
|
56147
|
+
if (buttonRef.current) {
|
|
56148
|
+
buttonRef.current.focus();
|
|
56149
|
+
return;
|
|
56150
|
+
}
|
|
56151
|
+
files.map((f) => fileRemoveButtonRefs.current[fileKey(f)]).find((ref) => ref?.current)?.current?.focus();
|
|
56111
56152
|
}, id6);
|
|
56112
56153
|
return /* @__PURE__ */ React172.createElement(FileUploadContext.Provider, {
|
|
56113
56154
|
value: contextValue
|
|
@@ -56118,13 +56159,19 @@ var FileUpload = ({ children }) => {
|
|
|
56118
56159
|
renderDescription: () => /* @__PURE__ */ React172.createElement(React172.Fragment, null, applyInternalProps(errorElement, {
|
|
56119
56160
|
hasError: Boolean(hasError || limitError),
|
|
56120
56161
|
errorMessage: limitError ?? errorMessage
|
|
56121
|
-
}),
|
|
56162
|
+
}), /* @__PURE__ */ React172.createElement(VisuallyHidden, {
|
|
56163
|
+
role: "status",
|
|
56164
|
+
"aria-live": "polite",
|
|
56165
|
+
"aria-atomic": "true"
|
|
56166
|
+
}, t("form.file-upload.explanation-text", {
|
|
56167
|
+
count: files.length
|
|
56168
|
+
})), explanationElement, filesElement, descriptionElement)
|
|
56122
56169
|
}));
|
|
56123
56170
|
};
|
|
56124
|
-
var Explanation = ({ className }) => {
|
|
56125
|
-
const { getExplanationText } = useFileUploadContext();
|
|
56126
|
-
const displayText = getExplanationText();
|
|
56127
|
-
if (!displayText) {
|
|
56171
|
+
var Explanation = ({ className, showUploadStatusOnly }) => {
|
|
56172
|
+
const { files, getExplanationText, getStatusText } = useFileUploadContext();
|
|
56173
|
+
const displayText = showUploadStatusOnly ? getStatusText() : getExplanationText();
|
|
56174
|
+
if (files.length === 1 || !displayText) {
|
|
56128
56175
|
return null;
|
|
56129
56176
|
}
|
|
56130
56177
|
return /* @__PURE__ */ React172.createElement("p", {
|