@wix/form-public 0.521.0 → 0.522.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.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, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, useSlottedContext, PopoverContext, Popover, CollectionRendererContext, DefaultCollectionRenderer, ListBox, 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';
10
+ import { CheckboxField, CheckboxButton, TextField, Input, ListBoxItem, Dialog, OverlayTriggerStateContext, ModalOverlay, Modal, SearchField, Group, RadioGroup as RadioGroup$1, Button, DropZone as DropZone$1, FileTrigger, useSlottedContext, PopoverContext, Popover, CollectionRendererContext, DefaultCollectionRenderer, ListBox, 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, 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;
@@ -61265,6 +61265,18 @@ var SignaturePad = class _SignaturePad extends SignatureEventTarget {
61265
61265
  }
61266
61266
  };
61267
61267
  var useId2 = typeof React173.useId === "function" ? React173.useId : () => useRef(generateUUID()).current;
61268
+ var hasUploadTab = ({ properties }) => properties.uploadEnabled === true;
61269
+ var isForceableSignature = (field, mode) => field.fieldType === FIELD_TYPES.SIGNATURE && !field.properties.hidden && !field.properties.disabled && !field.properties.readOnly && (mode !== "upload" || hasUploadTab(field));
61270
+ var byLayoutPosition2 = (first2, second) => first2.layout.row - second.layout.row || first2.layout.column - second.layout.column;
61271
+ var useForcedSignatureMode = (fieldId) => {
61272
+ const forcedMode = useElementProps().signatureContainer?.signatureMode;
61273
+ const formView = useContext(FormViewContext);
61274
+ const firstSignatureId = useMemo(() => formView && !formView.parentId && forcedMode ? formView.fields.filter((field) => isForceableSignature(field, forcedMode)).sort(byLayoutPosition2)[0]?.id : void 0, [
61275
+ formView,
61276
+ forcedMode
61277
+ ]);
61278
+ return firstSignatureId === fieldId ? forcedMode : void 0;
61279
+ };
61268
61280
 
61269
61281
  // ../form-fields/dist/esm/ui/signature-field/signature-types.js
61270
61282
  var SignatureFormat = /* @__PURE__ */ (function(SignatureFormat2) {
@@ -61795,8 +61807,14 @@ var Signature = ({ children }) => {
61795
61807
  renderDescription: () => /* @__PURE__ */ React173.createElement(React173.Fragment, null, errorElement, descriptionElement)
61796
61808
  });
61797
61809
  };
61798
- var Input14 = ({ children }) => {
61799
- const { value, onChange, target, readOnly } = useFieldPropsV2();
61810
+ var VIEW_BY_FORCED_MODE = {
61811
+ [SignatureMode.DRAW]: SignatureView.DRAW,
61812
+ [SignatureMode.TYPE]: SignatureView.TYPE,
61813
+ [SignatureMode.UPLOAD]: SignatureView.UPLOAD
61814
+ };
61815
+ var Input14 = ({ children, className }) => {
61816
+ const { id: id6, value, onChange, target, readOnly } = useFieldPropsV2();
61817
+ const forcedMode = useForcedSignatureMode(id6);
61800
61818
  const { signatureMode, setSignatureMode, handleClear, clearable, signatureView, signatureValueForView, handleChange, handleBeforeChange } = useSignatureField({
61801
61819
  target,
61802
61820
  value,
@@ -61805,16 +61823,19 @@ var Input14 = ({ children }) => {
61805
61823
  const headerElement = findChildOfType(children, Input14.Header);
61806
61824
  const valueElement = findChildOfType(children, Input14.Value);
61807
61825
  const internalProps = {
61808
- signatureMode,
61826
+ signatureMode: forcedMode ?? signatureMode,
61809
61827
  setSignatureMode,
61810
61828
  handleClear,
61811
61829
  clearable,
61812
- signatureView,
61813
- signatureValueForView,
61830
+ signatureView: forcedMode ? VIEW_BY_FORCED_MODE[forcedMode] : signatureView,
61831
+ signatureValueForView: forcedMode ? void 0 : signatureValueForView,
61814
61832
  handleChange,
61815
61833
  handleBeforeChange
61816
61834
  };
61817
- return /* @__PURE__ */ React173.createElement(React173.Fragment, null, !readOnly && applyInternalProps(headerElement, internalProps), applyInternalProps(valueElement, internalProps));
61835
+ return /* @__PURE__ */ React173.createElement("div", {
61836
+ className,
61837
+ "data-hook": "signature-container"
61838
+ }, !readOnly && applyInternalProps(headerElement, internalProps), applyInternalProps(valueElement, internalProps));
61818
61839
  };
61819
61840
  var Header = ({ children, className, ...internal }) => {
61820
61841
  const { signatureMode, setSignatureMode, clearable, handleClear } = internal;
@@ -62117,51 +62138,67 @@ var TypeValue = ({ className, placeholder, ...internal }) => {
62117
62138
  className
62118
62139
  });
62119
62140
  };
62120
- var HIDDEN_FILE_INPUT_STYLE = {
62121
- display: "none"
62122
- };
62123
- var Upload = ({ children, className, imageAlt, ...internal }) => {
62141
+ var Upload = ({ children, className, ...internal }) => {
62124
62142
  const { value, onChange, disabled, readOnly, onBlur, onFocus } = internal;
62125
- const { inputId } = useFieldAttributes();
62126
- const surfaceProps = useSurfaceProps();
62143
+ const { labelId, ariaDescribedBy } = useFieldAttributes();
62127
62144
  const buttonElement = findChildOfType(children, Upload.Button);
62128
- const fileInputRef = useRef(null);
62129
- const handleFileChange = useCallback((event) => {
62130
- const files = event.target.files;
62131
- if (!files || files.length === 0) {
62145
+ const previewElement = findChildOfType(children, Upload.Preview);
62146
+ const handleFiles = useCallback((files) => {
62147
+ const file = files[0];
62148
+ if (!file) {
62132
62149
  onChange(null);
62133
62150
  return;
62134
62151
  }
62135
- const file = files[0];
62136
62152
  const fileReader = new FileReader();
62137
- fileReader.onload = function() {
62138
- onChange(dataUrlToWixFile(this.result, file.name));
62153
+ fileReader.onload = () => {
62154
+ onChange(dataUrlToWixFile(fileReader.result, file.name));
62139
62155
  };
62140
62156
  fileReader.readAsDataURL(file);
62141
62157
  }, [
62142
62158
  onChange
62143
62159
  ]);
62144
62160
  const hasUploadedImage = value && isExternalImage(value);
62145
- return /* @__PURE__ */ React173.createElement("div", {
62161
+ if (hasUploadedImage) {
62162
+ return applyInternalProps(previewElement, {
62163
+ value
62164
+ }) ?? null;
62165
+ }
62166
+ return /* @__PURE__ */ React173.createElement(DropZone$1, {
62146
62167
  className,
62147
- "data-has-value": hasUploadedImage || void 0,
62148
- ...surfaceProps
62149
- }, /* @__PURE__ */ React173.createElement("input", {
62150
- ref: fileInputRef,
62151
- type: "file",
62152
- accept: "image/*",
62153
- onChange: handleFileChange,
62154
- disabled: disabled || readOnly,
62155
- style: HIDDEN_FILE_INPUT_STYLE,
62156
- "aria-hidden": "true",
62157
- tabIndex: -1
62158
- }), !hasUploadedImage && applyInternalProps(buttonElement, {
62159
- fileInputRef,
62168
+ isDisabled: disabled || readOnly,
62169
+ "aria-labelledby": labelId,
62170
+ "aria-describedby": ariaDescribedBy,
62171
+ "data-hook": "signature-upload-drop-zone",
62172
+ onDrop: async (event) => {
62173
+ for (const item of event.items) {
62174
+ if (item.kind === "file" && item.type.startsWith("image/")) {
62175
+ const file = await item.getFile();
62176
+ if (file) {
62177
+ handleFiles([
62178
+ file
62179
+ ]);
62180
+ return;
62181
+ }
62182
+ }
62183
+ }
62184
+ }
62185
+ }, applyInternalProps(buttonElement, {
62186
+ onSelectFiles: handleFiles,
62160
62187
  disabled,
62161
62188
  readOnly,
62162
62189
  onBlur,
62163
62190
  onFocus
62164
- }), hasUploadedImage && (value.url ? /* @__PURE__ */ React173.createElement("img", {
62191
+ }));
62192
+ };
62193
+ var UploadPreview = ({ className, imageAlt, ...internal }) => {
62194
+ const { value } = internal;
62195
+ const { inputId } = useFieldAttributes();
62196
+ const surfaceProps = useSurfaceProps();
62197
+ return /* @__PURE__ */ React173.createElement("div", {
62198
+ className,
62199
+ "data-has-value": true,
62200
+ ...surfaceProps
62201
+ }, value.url ? /* @__PURE__ */ React173.createElement("img", {
62165
62202
  id: inputId,
62166
62203
  src: value.url,
62167
62204
  alt: value.displayName || imageAlt,
@@ -62169,30 +62206,44 @@ var Upload = ({ children, className, imageAlt, ...internal }) => {
62169
62206
  }) : /* @__PURE__ */ React173.createElement("span", {
62170
62207
  id: inputId,
62171
62208
  "data-hook": "signature-image"
62172
- }, value.displayName || imageAlt)));
62209
+ }, value.displayName || imageAlt));
62173
62210
  };
62174
- var UploadButton = ({ children, className, ...internal }) => {
62175
- const { fileInputRef, disabled, readOnly, onBlur, onFocus } = internal;
62211
+ var UploadButton = ({ children, className, onHoverStart, onHoverEnd, ...internal }) => {
62212
+ const { onSelectFiles, disabled, readOnly, onBlur, onFocus } = internal;
62176
62213
  const { inputId, ariaDescribedBy, labelId } = useFieldAttributes();
62177
62214
  const textId = useId2();
62178
- const handlePress = useCallback(() => {
62179
- fileInputRef.current?.click();
62180
- }, [
62181
- fileInputRef
62182
- ]);
62183
- return /* @__PURE__ */ React173.createElement(Button, {
62215
+ const hasTextElement = Boolean(findChildOfType(children, UploadButton.Text));
62216
+ const content = hasTextElement ? Children.map(children, (child) => /* @__PURE__ */ isValidElement(child) && child.type === UploadButton.Text ? applyInternalProps(child, {
62217
+ textId
62218
+ }) : child) : /* @__PURE__ */ React173.createElement("span", {
62219
+ id: textId
62220
+ }, children);
62221
+ return /* @__PURE__ */ React173.createElement(FileTrigger, {
62222
+ acceptedFileTypes: [
62223
+ "image/*"
62224
+ ],
62225
+ onSelect: (fileList) => {
62226
+ onSelectFiles(fileList ? Array.from(fileList) : []);
62227
+ }
62228
+ }, /* @__PURE__ */ React173.createElement(Button, {
62184
62229
  id: inputId,
62185
- onPress: handlePress,
62186
62230
  onBlur,
62187
62231
  onFocus,
62188
62232
  isDisabled: disabled || readOnly,
62189
62233
  "aria-labelledby": `${labelId} ${textId}`,
62190
62234
  "aria-describedby": ariaDescribedBy,
62191
62235
  "data-hook": "signature-upload",
62236
+ className,
62237
+ onHoverStart,
62238
+ onHoverEnd
62239
+ }, content));
62240
+ };
62241
+ var UploadButtonText = ({ children, className, ...internal }) => {
62242
+ const { textId } = internal;
62243
+ return /* @__PURE__ */ React173.createElement("span", {
62244
+ id: textId,
62192
62245
  className
62193
- }, /* @__PURE__ */ React173.createElement("span", {
62194
- id: textId
62195
- }, children));
62246
+ }, children);
62196
62247
  };
62197
62248
  Signature.Label = Label;
62198
62249
  Signature.Input = Input14;
@@ -62209,7 +62260,9 @@ Value2.Canvas = Canvas;
62209
62260
  Value2.Type = Type4;
62210
62261
  Value2.Upload = Upload;
62211
62262
  Type4.Value = TypeValue;
62263
+ Upload.Preview = UploadPreview;
62212
62264
  Upload.Button = UploadButton;
62265
+ UploadButton.Text = UploadButtonText;
62213
62266
  function ProgressCircle(props2) {
62214
62267
  const strokeWidth = 4;
62215
62268
  const radius = `calc(50% - ${strokeWidth / 2}px)`;