@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.cjs
CHANGED
|
@@ -55724,9 +55724,9 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55724
55724
|
setFormStatus,
|
|
55725
55725
|
target
|
|
55726
55726
|
]);
|
|
55727
|
-
const
|
|
55727
|
+
const getStatusText = React172.useCallback(() => {
|
|
55728
55728
|
if (!files.length) {
|
|
55729
|
-
return
|
|
55729
|
+
return void 0;
|
|
55730
55730
|
}
|
|
55731
55731
|
const uploadingCount = files.filter((f) => f.state === "uploading").length;
|
|
55732
55732
|
if (uploadingCount) {
|
|
@@ -55736,14 +55736,27 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55736
55736
|
count: Math.round(progress * 100)
|
|
55737
55737
|
});
|
|
55738
55738
|
}
|
|
55739
|
-
return
|
|
55739
|
+
return t(`form.file-upload.explanation-text`, {
|
|
55740
55740
|
count: files.length
|
|
55741
55741
|
});
|
|
55742
55742
|
}, [
|
|
55743
55743
|
files,
|
|
55744
|
-
explanationText,
|
|
55745
55744
|
t
|
|
55746
55745
|
]);
|
|
55746
|
+
const getExplanationText = React172.useCallback(() => {
|
|
55747
|
+
if (!files.length) {
|
|
55748
|
+
return explanationText;
|
|
55749
|
+
}
|
|
55750
|
+
const isUploading = files.some((f) => f.state === "uploading");
|
|
55751
|
+
if (isUploading) {
|
|
55752
|
+
return getStatusText();
|
|
55753
|
+
}
|
|
55754
|
+
return explanationText || getStatusText();
|
|
55755
|
+
}, [
|
|
55756
|
+
files,
|
|
55757
|
+
explanationText,
|
|
55758
|
+
getStatusText
|
|
55759
|
+
]);
|
|
55747
55760
|
const _uploadFiles = React172.useCallback(async (filesToUpload) => {
|
|
55748
55761
|
await uploadFiles(filesToUpload, ({ file, uploadedFile }) => {
|
|
55749
55762
|
setFiles((previousFiles) => previousFiles.map((f) => f.file === file ? {
|
|
@@ -55826,6 +55839,7 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
|
|
|
55826
55839
|
limitError,
|
|
55827
55840
|
hover,
|
|
55828
55841
|
getExplanationText,
|
|
55842
|
+
getStatusText,
|
|
55829
55843
|
handleChange,
|
|
55830
55844
|
handleDelete,
|
|
55831
55845
|
accept,
|
|
@@ -55863,7 +55877,10 @@ function useFileUploadContext() {
|
|
|
55863
55877
|
var DropZone = ({ children, className }) => {
|
|
55864
55878
|
const { ariaDescribedBy } = useFieldAttributes();
|
|
55865
55879
|
const { disabled, hasError } = useFieldPropsV2();
|
|
55866
|
-
const { handleFileChange } = useFileUploadContext();
|
|
55880
|
+
const { handleFileChange, limitReached } = useFileUploadContext();
|
|
55881
|
+
if (limitReached) {
|
|
55882
|
+
return null;
|
|
55883
|
+
}
|
|
55867
55884
|
const titleElement = findChildOfType(children, DropZone.Title);
|
|
55868
55885
|
const subtitleElement = findChildOfType(children, DropZone.Subtitle);
|
|
55869
55886
|
const buttonElement = findChildOfType(children, DropZone.Button);
|
|
@@ -55902,13 +55919,14 @@ var DropZoneTitle = ({ className, children }) => {
|
|
|
55902
55919
|
};
|
|
55903
55920
|
var DropZoneSubtitle = ({ className, children }) => {
|
|
55904
55921
|
const { limitReached } = useFileUploadContext();
|
|
55922
|
+
const { explanationText } = useFieldPropsV2();
|
|
55905
55923
|
return /* @__PURE__ */ React172__default.default.createElement("p", {
|
|
55906
55924
|
className
|
|
55907
|
-
}, children({
|
|
55925
|
+
}, explanationText || children({
|
|
55908
55926
|
limitReached
|
|
55909
55927
|
}));
|
|
55910
55928
|
};
|
|
55911
|
-
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription }) => {
|
|
55929
|
+
var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription, onHoverStart, onHoverEnd }) => {
|
|
55912
55930
|
const { ariaDescribedBy, inputId, labelId, errorId } = useFieldAttributes();
|
|
55913
55931
|
const { disabled, required, onFocus, hasError, errorMessage } = useFieldPropsV2();
|
|
55914
55932
|
const { handleFileChange, accept, multiple, buttonRef, handleBlur, limitError, files } = useFileUploadContext();
|
|
@@ -55942,7 +55960,9 @@ var DropZoneButton = ({ className, children, "aria-roledescription": roleDescrip
|
|
|
55942
55960
|
isDisabled: disabled,
|
|
55943
55961
|
className,
|
|
55944
55962
|
onFocus,
|
|
55945
|
-
onBlur: handleBlur
|
|
55963
|
+
onBlur: handleBlur,
|
|
55964
|
+
onHoverStart,
|
|
55965
|
+
onHoverEnd
|
|
55946
55966
|
}, children));
|
|
55947
55967
|
};
|
|
55948
55968
|
var DropZoneButtonText = ({ className }) => {
|
|
@@ -56055,13 +56075,19 @@ Files.File = File2;
|
|
|
56055
56075
|
// ../form-fields/dist/esm/ui/file-upload/file-upload-headless/file-upload-headless.js
|
|
56056
56076
|
var fileKey = (f) => f.file.name;
|
|
56057
56077
|
var FileUpload = ({ children }) => {
|
|
56078
|
+
const { t } = useTranslation2();
|
|
56058
56079
|
const { id: id6, value, onChange, uploadFileFormats, valueSliderLimit, target, explanationText, onBlur, hasError, errorMessage, FieldLayout } = useFieldPropsV2();
|
|
56059
56080
|
const buttonRef = React172.useRef(null);
|
|
56060
56081
|
const fileRemoveButtonRefs = React172.useRef({});
|
|
56082
|
+
const pendingUploadButtonFocus = React172.useRef(false);
|
|
56061
56083
|
const handleFilesCleared = React172.useCallback(() => {
|
|
56062
|
-
buttonRef.current
|
|
56084
|
+
if (buttonRef.current) {
|
|
56085
|
+
buttonRef.current.focus();
|
|
56086
|
+
} else {
|
|
56087
|
+
pendingUploadButtonFocus.current = true;
|
|
56088
|
+
}
|
|
56063
56089
|
}, []);
|
|
56064
|
-
const { files, limitError, hover, getExplanationText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56090
|
+
const { files, limitError, hover, getExplanationText, getStatusText, handleBlur, handleChange, handleDelete: _handleDelete, accept } = useFileUploadController({
|
|
56065
56091
|
valueSliderLimit,
|
|
56066
56092
|
value,
|
|
56067
56093
|
explanationText,
|
|
@@ -56083,6 +56109,14 @@ var FileUpload = ({ children }) => {
|
|
|
56083
56109
|
_handleDelete,
|
|
56084
56110
|
files
|
|
56085
56111
|
]);
|
|
56112
|
+
React172.useEffect(() => {
|
|
56113
|
+
if (pendingUploadButtonFocus.current && buttonRef.current) {
|
|
56114
|
+
pendingUploadButtonFocus.current = false;
|
|
56115
|
+
buttonRef.current.focus();
|
|
56116
|
+
}
|
|
56117
|
+
}, [
|
|
56118
|
+
files
|
|
56119
|
+
]);
|
|
56086
56120
|
const multiple = valueSliderLimit > 1;
|
|
56087
56121
|
const limitReached = files.length >= valueSliderLimit;
|
|
56088
56122
|
const contextValue = React172.useMemo(() => ({
|
|
@@ -56094,6 +56128,7 @@ var FileUpload = ({ children }) => {
|
|
|
56094
56128
|
limitReached,
|
|
56095
56129
|
multiple,
|
|
56096
56130
|
getExplanationText,
|
|
56131
|
+
getStatusText,
|
|
56097
56132
|
hover,
|
|
56098
56133
|
limitError,
|
|
56099
56134
|
buttonRef,
|
|
@@ -56107,6 +56142,7 @@ var FileUpload = ({ children }) => {
|
|
|
56107
56142
|
limitReached,
|
|
56108
56143
|
multiple,
|
|
56109
56144
|
getExplanationText,
|
|
56145
|
+
getStatusText,
|
|
56110
56146
|
hover,
|
|
56111
56147
|
limitError
|
|
56112
56148
|
]);
|
|
@@ -56118,7 +56154,11 @@ var FileUpload = ({ children }) => {
|
|
|
56118
56154
|
const descriptionElement = findChildOfType(children, FileUpload.Description);
|
|
56119
56155
|
const errorElement = findChildOfType(children, FileUpload.Error);
|
|
56120
56156
|
useFocusFieldEvent(() => {
|
|
56121
|
-
buttonRef.current
|
|
56157
|
+
if (buttonRef.current) {
|
|
56158
|
+
buttonRef.current.focus();
|
|
56159
|
+
return;
|
|
56160
|
+
}
|
|
56161
|
+
files.map((f) => fileRemoveButtonRefs.current[fileKey(f)]).find((ref) => ref?.current)?.current?.focus();
|
|
56122
56162
|
}, id6);
|
|
56123
56163
|
return /* @__PURE__ */ React172__default.default.createElement(FileUploadContext.Provider, {
|
|
56124
56164
|
value: contextValue
|
|
@@ -56129,13 +56169,19 @@ var FileUpload = ({ children }) => {
|
|
|
56129
56169
|
renderDescription: () => /* @__PURE__ */ React172__default.default.createElement(React172__default.default.Fragment, null, applyInternalProps(errorElement, {
|
|
56130
56170
|
hasError: Boolean(hasError || limitError),
|
|
56131
56171
|
errorMessage: limitError ?? errorMessage
|
|
56132
|
-
}),
|
|
56172
|
+
}), /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.VisuallyHidden, {
|
|
56173
|
+
role: "status",
|
|
56174
|
+
"aria-live": "polite",
|
|
56175
|
+
"aria-atomic": "true"
|
|
56176
|
+
}, t("form.file-upload.explanation-text", {
|
|
56177
|
+
count: files.length
|
|
56178
|
+
})), explanationElement, filesElement, descriptionElement)
|
|
56133
56179
|
}));
|
|
56134
56180
|
};
|
|
56135
|
-
var Explanation = ({ className }) => {
|
|
56136
|
-
const { getExplanationText } = useFileUploadContext();
|
|
56137
|
-
const displayText = getExplanationText();
|
|
56138
|
-
if (!displayText) {
|
|
56181
|
+
var Explanation = ({ className, showUploadStatusOnly }) => {
|
|
56182
|
+
const { files, getExplanationText, getStatusText } = useFileUploadContext();
|
|
56183
|
+
const displayText = showUploadStatusOnly ? getStatusText() : getExplanationText();
|
|
56184
|
+
if (files.length === 1 || !displayText) {
|
|
56139
56185
|
return null;
|
|
56140
56186
|
}
|
|
56141
56187
|
return /* @__PURE__ */ React172__default.default.createElement("p", {
|