@wix/form-public 0.513.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 +62 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +63 -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;
|
|
@@ -55714,9 +55714,9 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55714
55714
|
setFormStatus,
|
|
55715
55715
|
target
|
|
55716
55716
|
]);
|
|
55717
|
-
const
|
|
55717
|
+
const getStatusText = useCallback(() => {
|
|
55718
55718
|
if (!files.length) {
|
|
55719
|
-
return
|
|
55719
|
+
return void 0;
|
|
55720
55720
|
}
|
|
55721
55721
|
const uploadingCount = files.filter((f) => f.state === "uploading").length;
|
|
55722
55722
|
if (uploadingCount) {
|
|
@@ -55726,14 +55726,27 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55726
55726
|
count: Math.round(progress * 100)
|
|
55727
55727
|
});
|
|
55728
55728
|
}
|
|
55729
|
-
return
|
|
55729
|
+
return t(`form.file-upload.explanation-text`, {
|
|
55730
55730
|
count: files.length
|
|
55731
55731
|
});
|
|
55732
55732
|
}, [
|
|
55733
55733
|
files,
|
|
55734
|
-
explanationText,
|
|
55735
55734
|
t
|
|
55736
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
|
+
]);
|
|
55737
55750
|
const _uploadFiles = useCallback(async (filesToUpload) => {
|
|
55738
55751
|
await uploadFiles(filesToUpload, ({ file, uploadedFile }) => {
|
|
55739
55752
|
setFiles((previousFiles) => previousFiles.map((f) => f.file === file ? {
|
|
@@ -55816,6 +55829,7 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55816
55829
|
limitError,
|
|
55817
55830
|
hover,
|
|
55818
55831
|
getExplanationText,
|
|
55832
|
+
getStatusText,
|
|
55819
55833
|
handleChange,
|
|
55820
55834
|
handleDelete,
|
|
55821
55835
|
accept,
|
|
@@ -55853,7 +55867,10 @@ function useFileUploadContext() {
|
|
|
55853
55867
|
var DropZone = ({ children, className }) => {
|
|
55854
55868
|
const { ariaDescribedBy } = useFieldAttributes();
|
|
55855
55869
|
const { disabled, hasError } = useFieldPropsV2();
|
|
55856
|
-
const { handleFileChange } = useFileUploadContext();
|
|
55870
|
+
const { handleFileChange, limitReached } = useFileUploadContext();
|
|
55871
|
+
if (limitReached) {
|
|
55872
|
+
return null;
|
|
55873
|
+
}
|
|
55857
55874
|
const titleElement = findChildOfType(children, DropZone.Title);
|
|
55858
55875
|
const subtitleElement = findChildOfType(children, DropZone.Subtitle);
|
|
55859
55876
|
const buttonElement = findChildOfType(children, DropZone.Button);
|
|
@@ -55892,13 +55909,14 @@ var DropZoneTitle = ({ className, children }) => {
|
|
|
55892
55909
|
};
|
|
55893
55910
|
var DropZoneSubtitle = ({ className, children }) => {
|
|
55894
55911
|
const { limitReached } = useFileUploadContext();
|
|
55912
|
+
const { explanationText } = useFieldPropsV2();
|
|
55895
55913
|
return /* @__PURE__ */ React172.createElement("p", {
|
|
55896
55914
|
className
|
|
55897
|
-
}, children({
|
|
55915
|
+
}, explanationText || children({
|
|
55898
55916
|
limitReached
|
|
55899
55917
|
}));
|
|
55900
55918
|
};
|
|
55901
|
-
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription }) => {
|
|
55919
|
+
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription, onHoverStart, onHoverEnd }) => {
|
|
55902
55920
|
const { ariaDescribedBy, inputId, labelId, errorId } = useFieldAttributes();
|
|
55903
55921
|
const { disabled, required, onFocus, hasError, errorMessage } = useFieldPropsV2();
|
|
55904
55922
|
const { handleFileChange, accept, multiple, buttonRef, handleBlur, limitError, files } = useFileUploadContext();
|
|
@@ -55932,7 +55950,9 @@ var DropZoneButton = ({ className, children, "aria-roledescription": roleDescrip
|
|
|
55932
55950
|
isDisabled: disabled,
|
|
55933
55951
|
className,
|
|
55934
55952
|
onFocus,
|
|
55935
|
-
onBlur: handleBlur
|
|
55953
|
+
onBlur: handleBlur,
|
|
55954
|
+
onHoverStart,
|
|
55955
|
+
onHoverEnd
|
|
55936
55956
|
}, children));
|
|
55937
55957
|
};
|
|
55938
55958
|
var DropZoneButtonText = ({ className }) => {
|
|
@@ -56045,13 +56065,19 @@ Files.File = File2;
|
|
|
56045
56065
|
// ../form-fields/dist/esm/ui/file-upload/file-upload-headless/file-upload-headless.js
|
|
56046
56066
|
var fileKey = (f) => f.file.name;
|
|
56047
56067
|
var FileUpload = ({ children }) => {
|
|
56068
|
+
const { t } = useTranslation2();
|
|
56048
56069
|
const { id: id6, value, onChange, uploadFileFormats, valueSliderLimit, target, explanationText, onBlur, hasError, errorMessage, FieldLayout } = useFieldPropsV2();
|
|
56049
56070
|
const buttonRef = useRef(null);
|
|
56050
56071
|
const fileRemoveButtonRefs = useRef({});
|
|
56072
|
+
const pendingUploadButtonFocus = useRef(false);
|
|
56051
56073
|
const handleFilesCleared = useCallback(() => {
|
|
56052
|
-
buttonRef.current
|
|
56074
|
+
if (buttonRef.current) {
|
|
56075
|
+
buttonRef.current.focus();
|
|
56076
|
+
} else {
|
|
56077
|
+
pendingUploadButtonFocus.current = true;
|
|
56078
|
+
}
|
|
56053
56079
|
}, []);
|
|
56054
|
-
const { files, limitError, hover, getExplanationText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56080
|
+
const { files, limitError, hover, getExplanationText, getStatusText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56055
56081
|
valueSliderLimit,
|
|
56056
56082
|
value,
|
|
56057
56083
|
explanationText,
|
|
@@ -56073,6 +56099,14 @@ var FileUpload = ({ children }) => {
|
|
|
56073
56099
|
_handleDelete,
|
|
56074
56100
|
files
|
|
56075
56101
|
]);
|
|
56102
|
+
useEffect(() => {
|
|
56103
|
+
if (pendingUploadButtonFocus.current && buttonRef.current) {
|
|
56104
|
+
pendingUploadButtonFocus.current = false;
|
|
56105
|
+
buttonRef.current.focus();
|
|
56106
|
+
}
|
|
56107
|
+
}, [
|
|
56108
|
+
files
|
|
56109
|
+
]);
|
|
56076
56110
|
const multiple = valueSliderLimit > 1;
|
|
56077
56111
|
const limitReached = files.length >= valueSliderLimit;
|
|
56078
56112
|
const contextValue = useMemo(() => ({
|
|
@@ -56084,6 +56118,7 @@ var FileUpload = ({ children }) => {
|
|
|
56084
56118
|
limitReached,
|
|
56085
56119
|
multiple,
|
|
56086
56120
|
getExplanationText,
|
|
56121
|
+
getStatusText,
|
|
56087
56122
|
hover,
|
|
56088
56123
|
limitError,
|
|
56089
56124
|
buttonRef,
|
|
@@ -56097,6 +56132,7 @@ var FileUpload = ({ children }) => {
|
|
|
56097
56132
|
limitReached,
|
|
56098
56133
|
multiple,
|
|
56099
56134
|
getExplanationText,
|
|
56135
|
+
getStatusText,
|
|
56100
56136
|
hover,
|
|
56101
56137
|
limitError
|
|
56102
56138
|
]);
|
|
@@ -56108,7 +56144,11 @@ var FileUpload = ({ children }) => {
|
|
|
56108
56144
|
const descriptionElement = findChildOfType(children, FileUpload.Description);
|
|
56109
56145
|
const errorElement = findChildOfType(children, FileUpload.Error);
|
|
56110
56146
|
useFocusFieldEvent(() => {
|
|
56111
|
-
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();
|
|
56112
56152
|
}, id6);
|
|
56113
56153
|
return /* @__PURE__ */ React172.createElement(FileUploadContext.Provider, {
|
|
56114
56154
|
value: contextValue
|
|
@@ -56119,13 +56159,19 @@ var FileUpload = ({ children }) => {
|
|
|
56119
56159
|
renderDescription: () => /* @__PURE__ */ React172.createElement(React172.Fragment, null, applyInternalProps(errorElement, {
|
|
56120
56160
|
hasError: Boolean(hasError || limitError),
|
|
56121
56161
|
errorMessage: limitError ?? errorMessage
|
|
56122
|
-
}),
|
|
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)
|
|
56123
56169
|
}));
|
|
56124
56170
|
};
|
|
56125
|
-
var Explanation = ({ className }) => {
|
|
56126
|
-
const { getExplanationText } = useFileUploadContext();
|
|
56127
|
-
const displayText = getExplanationText();
|
|
56128
|
-
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) {
|
|
56129
56175
|
return null;
|
|
56130
56176
|
}
|
|
56131
56177
|
return /* @__PURE__ */ React172.createElement("p", {
|