@wix/form-public 0.513.0 → 0.515.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 CHANGED
@@ -55724,9 +55724,9 @@ function useFileUploadController({ valueSliderLimit, value, explanationText, tar
55724
55724
  setFormStatus,
55725
55725
  target
55726
55726
  ]);
55727
- const getExplanationText = React172.useCallback(() => {
55727
+ const getStatusText = React172.useCallback(() => {
55728
55728
  if (!files.length) {
55729
- return explanationText;
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 explanationText || t(`form.file-upload.explanation-text`, {
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?.focus();
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?.focus();
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
- }), descriptionElement, explanationElement, filesElement)
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", {
@@ -59244,11 +59290,11 @@ var PhoneInput = ({ children }) => {
59244
59290
  }));
59245
59291
  };
59246
59292
  var CountryButton = ({ children, className }) => {
59247
- const { inputId, labelId } = useFieldAttributes();
59293
+ const { labelId } = useFieldAttributes();
59248
59294
  const { hasError, disabled, readOnly } = useFieldPropsV2();
59249
59295
  const { t } = useTranslation2();
59250
59296
  const { selectedCountryCode, countries } = usePhoneInputContext();
59251
- const buttonId = `${inputId}-country`;
59297
+ const buttonId = React172.useId();
59252
59298
  const selectedCountry = selectedCountryCode ? countries.find((c) => c.shortCountryCode === selectedCountryCode) : void 0;
59253
59299
  const dialingCode = selectedCountry ? getCallingCode2(selectedCountry.longCountryCode) || "" : "";
59254
59300
  const countryCodeLabel = t("field.phone.country-code.aria-label");
@@ -59286,9 +59332,12 @@ var CountryButtonEmptyState = ({ children, className }) => {
59286
59332
  CountryButton.Flag = CountryButtonFlag;
59287
59333
  CountryButton.EmptyState = CountryButtonEmptyState;
59288
59334
  var CountryOptions = ({ children, className, "aria-label": ariaLabel, placement, offset, ...internal }) => {
59289
- const { triggerRef, optionsRef, isForcedOpen } = internal;
59335
+ const { triggerRef, optionsRef, isForcedOpen, isOpen } = internal;
59290
59336
  const { popoverContainer } = usePhoneInputContext();
59291
59337
  const searchElement = findChildOfType(children, CountryOptions.Search);
59338
+ if (!isOpen) {
59339
+ return null;
59340
+ }
59292
59341
  const content = /* @__PURE__ */ React172__default.default.createElement(CountryOptionsContent, {
59293
59342
  isForcedOpen
59294
59343
  }, children);
@@ -59446,24 +59495,54 @@ var PhoneNumber2 = ({ className }) => {
59446
59495
  className
59447
59496
  });
59448
59497
  };
59498
+ var CountryPopover = ({ children, ...internal }) => {
59499
+ const pickerProps = internal;
59500
+ const { isForcedOpen } = pickerProps;
59501
+ const { disabled, readOnly, required, hasError } = useFieldPropsV2();
59502
+ const [isOpen, setIsOpen] = React172.useState(false);
59503
+ const { t } = useTranslation2();
59504
+ const { selectedCountryCode, handleCountryCodeChange } = usePhoneInputContext();
59505
+ const isPopoverOpen = isForcedOpen || isOpen && !disabled && !readOnly;
59506
+ return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Select, {
59507
+ "aria-label": t("field.phone.country-code.aria-label"),
59508
+ value: selectedCountryCode ?? null,
59509
+ onChange: (key) => handleCountryCodeChange(key),
59510
+ isDisabled: disabled || readOnly,
59511
+ isInvalid: hasError,
59512
+ isRequired: required,
59513
+ placeholder: "",
59514
+ isOpen: isPopoverOpen,
59515
+ allowsEmptyCollection: true,
59516
+ onOpenChange: isForcedOpen ? void 0 : setIsOpen
59517
+ }, findChildOfType(children, PhoneInput.CountryButton), applyInternalProps(findChildOfType(children, PhoneInput.CountryOptions.Popover), {
59518
+ ...pickerProps,
59519
+ isOpen: isPopoverOpen
59520
+ }));
59521
+ };
59522
+ var CountryDrawer = ({ children, ...internal }) => {
59523
+ const pickerProps = internal;
59524
+ return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.DialogTrigger, null, findChildOfType(children, PhoneInput.CountryButton), applyInternalProps(findChildOfType(children, PhoneInput.CountryOptions.Modal), pickerProps));
59525
+ };
59449
59526
  var Control7 = ({ children, className }) => {
59450
59527
  const controlRef = React172.useRef(null);
59451
59528
  const optionsRef = React172.useRef(null);
59452
59529
  const isFocused = React172.useRef(false);
59453
- const { id: id6, disabled, readOnly, required, hasError, showFlag, onFocus, onBlur } = useFieldPropsV2();
59454
- const [isOpen, setIsOpen] = React172.useState(false);
59530
+ const { id: id6, disabled, hasError, showFlag, onFocus, onBlur } = useFieldPropsV2();
59455
59531
  const invokeBlur = useInvokeCallback(onBlur);
59456
- const { t } = useTranslation2();
59457
- const { selectedCountryCode, handleCountryCodeChange, countries } = usePhoneInputContext();
59458
- const countryButtonElement = findChildOfType(children, PhoneInput.CountryButton);
59459
- const modalElement = findChildOfType(children, PhoneInput.CountryOptions.Modal);
59460
- const countryOptionsElement = modalElement ?? findChildOfType(children, PhoneInput.CountryOptions.Popover);
59532
+ const { countries } = usePhoneInputContext();
59533
+ const drawerElement = findChildOfType(children, PhoneInput.CountryDrawer);
59534
+ const popoverElement = findChildOfType(children, PhoneInput.CountryPopover);
59461
59535
  const phoneNumberElement = findChildOfType(children, PhoneInput.PhoneNumber);
59462
59536
  const hasCountryOptions2 = countries.length > 1;
59463
- const isForcedOpen = useIsForcedOpenDropdown(id6) && !modalElement && hasCountryOptions2;
59537
+ const isForcedOpen = useIsForcedOpenDropdown(id6) && !!popoverElement && hasCountryOptions2;
59464
59538
  const controlClassName = typeof className === "function" ? className({
59465
59539
  hasCountryOptions: hasCountryOptions2
59466
59540
  }) : className;
59541
+ const pickerProps = {
59542
+ triggerRef: controlRef,
59543
+ optionsRef,
59544
+ isForcedOpen
59545
+ };
59467
59546
  const focusHandlers = {
59468
59547
  onFocus: () => {
59469
59548
  if (!isFocused.current) {
@@ -59490,32 +59569,19 @@ var Control7 = ({ children, className }) => {
59490
59569
  longCountryCode: countries[0].longCountryCode
59491
59570
  }), phoneNumberElement);
59492
59571
  }
59493
- const selector = /* @__PURE__ */ React172__default.default.createElement(React172__default.default.Fragment, null, countryButtonElement, applyInternalProps(countryOptionsElement, {
59494
- triggerRef: controlRef,
59495
- optionsRef,
59496
- isForcedOpen
59497
- }));
59498
59572
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Group, {
59499
59573
  ref: controlRef,
59500
59574
  className: controlClassName,
59501
59575
  isDisabled: disabled,
59502
59576
  isInvalid: hasError,
59503
59577
  ...focusHandlers
59504
- }, modalElement ? /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.DialogTrigger, null, selector) : /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Select, {
59505
- "aria-label": t("field.phone.country-code.aria-label"),
59506
- value: selectedCountryCode ?? null,
59507
- onChange: (key) => handleCountryCodeChange(key),
59508
- isDisabled: disabled || readOnly,
59509
- isInvalid: hasError,
59510
- isRequired: required,
59511
- placeholder: "",
59512
- isOpen: isForcedOpen || isOpen && !disabled && !readOnly,
59513
- onOpenChange: isForcedOpen ? void 0 : setIsOpen
59514
- }, selector), phoneNumberElement);
59578
+ }, !isForcedOpen && applyInternalProps(drawerElement, pickerProps), applyInternalProps(popoverElement, pickerProps), phoneNumberElement);
59515
59579
  };
59516
59580
  PhoneInput.Label = Label;
59517
59581
  PhoneInput.Control = Control7;
59518
59582
  PhoneInput.CountryButton = CountryButton;
59583
+ PhoneInput.CountryDrawer = CountryDrawer;
59584
+ PhoneInput.CountryPopover = CountryPopover;
59519
59585
  PhoneInput.CountryOptions = CountryOptions;
59520
59586
  PhoneInput.PhoneNumber = PhoneNumber2;
59521
59587
  PhoneInput.Description = Description;
@@ -60676,7 +60742,7 @@ var SignaturePad = class _SignaturePad extends SignatureEventTarget {
60676
60742
  return svg.outerHTML;
60677
60743
  }
60678
60744
  };
60679
- var useId = typeof React172__default.default.useId === "function" ? React172__default.default.useId : () => React172.useRef(generateUUID()).current;
60745
+ var useId2 = typeof React172__default.default.useId === "function" ? React172__default.default.useId : () => React172.useRef(generateUUID()).current;
60680
60746
 
60681
60747
  // ../form-fields/dist/esm/ui/signature-field/signature-types.js
60682
60748
  var SignatureFormat = /* @__PURE__ */ (function(SignatureFormat2) {
@@ -61586,7 +61652,7 @@ var Upload = ({ children, className, imageAlt, ...internal }) => {
61586
61652
  var UploadButton = ({ children, className, ...internal }) => {
61587
61653
  const { fileInputRef, disabled, readOnly, onBlur, onFocus } = internal;
61588
61654
  const { inputId, ariaDescribedBy, labelId } = useFieldAttributes();
61589
- const textId = useId();
61655
+ const textId = useId2();
61590
61656
  const handlePress = React172.useCallback(() => {
61591
61657
  fileInputRef.current?.click();
61592
61658
  }, [