@wix/form-public 0.526.0 → 0.528.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
@@ -38271,7 +38271,9 @@ var READONLY_FIELD_TYPES = {
38271
38271
  // ../form-fields/dist/esm/constants/field-types.js
38272
38272
  var FIELD_TYPES = {
38273
38273
  ...INPUT_FIELD_TYPES,
38274
- ...READONLY_FIELD_TYPES};
38274
+ ...READONLY_FIELD_TYPES,
38275
+ SUBMIT_BUTTON: "SUBMIT_BUTTON"
38276
+ };
38275
38277
 
38276
38278
  // ../form-fields/dist/esm/constants/empty-values.js
38277
38279
  var EMPTY_VALUE = null;
@@ -47244,6 +47246,52 @@ function makeInputValidation(identifier, inputOptions) {
47244
47246
  };
47245
47247
  }
47246
47248
 
47249
+ // ../form-fields/dist/esm/services/grid-defaults.js
47250
+ var GRID_DEFAULTS = {
47251
+ columns: 12,
47252
+ rowHeight: 24,
47253
+ margin: {
47254
+ vertical: 24,
47255
+ horizontal: 24
47256
+ },
47257
+ padding: {
47258
+ vertical: 0,
47259
+ horizontal: 0
47260
+ }
47261
+ };
47262
+
47263
+ // ../form-fields/dist/esm/services/complete-small-layout-items.js
47264
+ function completeSmallLayoutItems({ large, small, columns, submitFieldIds = [] }) {
47265
+ const placedFieldIds = new Set(small.map(({ fieldId }) => fieldId));
47266
+ const submitRows = small.filter(({ fieldId }) => fieldId && submitFieldIds.includes(fieldId)).map(({ row: row2 }) => row2 ?? 0);
47267
+ const insertRow = submitRows.length ? Math.max(...submitRows) : Math.max(0, ...small.map(({ row: row2, height }) => (row2 ?? 0) + (height ?? 1)));
47268
+ const unplaced = large.filter(({ fieldId }) => fieldId && !placedFieldIds.has(fieldId)).sort((one, other) => (one.row ?? 0) - (other.row ?? 0) || (one.column ?? 0) - (other.column ?? 0));
47269
+ if (!unplaced.length) {
47270
+ return small;
47271
+ }
47272
+ let row = insertRow;
47273
+ const appended = unplaced.map(({ fieldId, height }) => {
47274
+ const item = {
47275
+ fieldId,
47276
+ row,
47277
+ column: 0,
47278
+ width: columns ?? GRID_DEFAULTS.columns,
47279
+ height: height ?? 1
47280
+ };
47281
+ row += item.height;
47282
+ return item;
47283
+ });
47284
+ const insertedHeight = row - insertRow;
47285
+ const shifted = small.map((item) => (item.row ?? 0) >= insertRow ? {
47286
+ ...item,
47287
+ row: (item.row ?? 0) + insertedHeight
47288
+ } : item);
47289
+ return [
47290
+ ...shifted,
47291
+ ...appended
47292
+ ];
47293
+ }
47294
+
47247
47295
  // ../form-fields/dist/esm/types/image.js
47248
47296
  var ImagePosition4 = /* @__PURE__ */ (function(ImagePosition5) {
47249
47297
  ImagePosition5["TOP"] = "top";
@@ -47284,19 +47332,19 @@ function toFieldLabelMediaSettings(view) {
47284
47332
  return Object.keys(mediaSettings).length ? mediaSettings : void 0;
47285
47333
  }
47286
47334
 
47335
+ // ../form-fields/dist/esm/services/submit-field-ids.js
47336
+ function getSubmitFieldIds(fields = []) {
47337
+ return fields.flatMap(({ id: id6, view }) => id6 && view?.fieldType === FIELD_TYPES.SUBMIT_BUTTON ? [
47338
+ id6
47339
+ ] : []);
47340
+ }
47341
+ function getSubmitFieldIdsV2(fields = []) {
47342
+ return fields.flatMap(({ id: id6, identifier }) => id6 && identifier === FIELD_TYPES.SUBMIT_BUTTON ? [
47343
+ id6
47344
+ ] : []);
47345
+ }
47346
+
47287
47347
  // ../form-fields/dist/esm/services/form-view.js
47288
- var GRID_DEFAULTS = {
47289
- columns: 12,
47290
- rowHeight: 24,
47291
- margin: {
47292
- vertical: 24,
47293
- horizontal: 24
47294
- },
47295
- padding: {
47296
- vertical: 0,
47297
- horizontal: 0
47298
- }
47299
- };
47300
47348
  function createFormView({ form, path = "", stepId, recursive = true, includeHiddenFields = false, isMobile: isMobile2 = false, breakpoint = DEFAULT_BREAKPOINT, useFieldsV2 = false, parentId = "" }) {
47301
47349
  const step = stepId ? form.steps?.find(({ id: id6 }) => id6 === stepId) : form.steps?.[0];
47302
47350
  const layout = step?.layout ?? {};
@@ -47308,11 +47356,24 @@ function createFormView({ form, path = "", stepId, recursive = true, includeHidd
47308
47356
  } else if ("name" in form) {
47309
47357
  nameView = form.name ?? "";
47310
47358
  }
47311
- const hasSmallLayout = layout.small?.items;
47359
+ const smallItems = layout.small?.items ?? [];
47360
+ const hasSmallLayout = smallItems.length > 0;
47312
47361
  const isSmallBreakpoint = isMobile2 && hasSmallLayout;
47362
+ const effectiveLayout = hasSmallLayout ? {
47363
+ ...layout,
47364
+ small: {
47365
+ ...layout.small,
47366
+ items: completeSmallLayoutItems({
47367
+ large: layout.large?.items ?? [],
47368
+ small: smallItems,
47369
+ columns: layout.large?.columns,
47370
+ submitFieldIds: useFieldsV2 && platformizedFields ? getSubmitFieldIdsV2(platformizedFields) : getSubmitFieldIds(fields)
47371
+ })
47372
+ }
47373
+ } : layout;
47313
47374
  const fieldViews = (useFieldsV2 && platformizedFields ? platformizedFields : fields).filter((field) => includeHiddenFields || !field.hidden).filter((field) => layout?.large?.items?.find((item) => field.id === item.fieldId)).reduce((result2, field) => {
47314
47375
  const _field = useFieldsV2 && platformizedFields ? transformFieldToV1(field) : field;
47315
- const fieldView = createFieldView(_field, layout, path, recursive, isMobile2, isSmallBreakpoint ? Breakpoint.SMALL : breakpoint);
47376
+ const fieldView = createFieldView(_field, effectiveLayout, path, recursive, isMobile2, isSmallBreakpoint ? Breakpoint.SMALL : breakpoint);
47316
47377
  if (fieldView) {
47317
47378
  result2.push(fieldView);
47318
47379
  }
@@ -52085,9 +52146,10 @@ var CheckboxContainer = ({ children, className }) => {
52085
52146
  }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.CheckboxButton, {
52086
52147
  ref,
52087
52148
  className
52088
- }, ({ isSelected, isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
52149
+ }, ({ isSelected, isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
52089
52150
  isSelected,
52090
- isHovered
52151
+ isHovered,
52152
+ isFocused
52091
52153
  }), labelElement)));
52092
52154
  };
52093
52155
  CheckboxContainer.RichTextLabel = RichTextLabel;
@@ -52275,9 +52337,10 @@ var Checkbox2 = ({ children, className, ...internal }) => {
52275
52337
  ref: checkboxRef,
52276
52338
  className,
52277
52339
  "data-hook": `checkbox-${label}`
52278
- }, ({ isSelected, isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
52340
+ }, ({ isSelected, isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
52279
52341
  isSelected,
52280
- isHovered
52342
+ isHovered,
52343
+ isFocused
52281
52344
  }), applyInternalProps(labelElement, {
52282
52345
  label
52283
52346
  }))));
@@ -55954,9 +56017,10 @@ var GuestToggle = ({ children, className, ...internal }) => {
55954
56017
  onFocus
55955
56018
  }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.CheckboxButton, {
55956
56019
  className
55957
- }, ({ isSelected, isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
56020
+ }, ({ isSelected, isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(inputElement, {
55958
56021
  isSelected,
55959
- isHovered
56022
+ isHovered,
56023
+ isFocused
55960
56024
  }), applyInternalProps(labelElement, {
55961
56025
  label
55962
56026
  }))));
@@ -56113,9 +56177,10 @@ var Option4 = ({ children, className, ...internal }) => {
56113
56177
  }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioButton, {
56114
56178
  ref: radioRef,
56115
56179
  className: radioClassName
56116
- }, ({ isSelected, isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(controlElement, {
56180
+ }, ({ isSelected, isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, applyInternalProps(controlElement, {
56117
56181
  isSelected,
56118
- isHovered
56182
+ isHovered,
56183
+ isFocused
56119
56184
  }), applyInternalProps(labelElement, {
56120
56185
  label
56121
56186
  })))), isOther && isThisOptionSelected && otherInputElement);
@@ -56456,7 +56521,7 @@ var DropZoneSubtitle = ({ className, children }) => {
56456
56521
  limitReached
56457
56522
  }));
56458
56523
  };
56459
- var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription, onHoverStart, onHoverEnd }) => {
56524
+ var DropZoneButton = ({ className, children, "aria-roledescription": roleDescription, onHoverStart, onHoverEnd, onFocusChange }) => {
56460
56525
  const { ariaDescribedBy, inputId, labelId, errorId } = useFieldAttributes();
56461
56526
  const { disabled, required, onFocus, hasError, errorMessage } = useFieldPropsV2();
56462
56527
  const { handleFileChange, accept, multiple, buttonRef, handleBlur, limitError, files } = useFileUploadContext();
@@ -56492,7 +56557,8 @@ var DropZoneButton = ({ className, children, "aria-roledescription": roleDescrip
56492
56557
  onFocus,
56493
56558
  onBlur: handleBlur,
56494
56559
  onHoverStart,
56495
- onHoverEnd
56560
+ onHoverEnd,
56561
+ onFocusChange
56496
56562
  }, children));
56497
56563
  };
56498
56564
  var DropZoneButtonText = ({ className }) => {
@@ -60072,9 +60138,10 @@ var Control7 = ({ children, className }) => {
60072
60138
  const phoneNumberElement = findChildOfType(children, PhoneInput.PhoneNumber);
60073
60139
  const hasCountryOptions2 = countries.length > 1;
60074
60140
  const isForcedOpen = useIsForcedOpenDropdown(id6) && !!popoverElement && hasCountryOptions2;
60075
- const controlClassName = typeof className === "function" ? ({ isHovered }) => className({
60141
+ const controlClassName = typeof className === "function" ? ({ isHovered, isFocusWithin }) => className({
60076
60142
  hasCountryOptions: hasCountryOptions2,
60077
- isHovered
60143
+ isHovered,
60144
+ isFocusWithin
60078
60145
  }) : className;
60079
60146
  const pickerProps = {
60080
60147
  triggerRef: controlRef,
@@ -60298,7 +60365,7 @@ var ProductOption = ({ children, className, ...internal }) => {
60298
60365
  ref: checkboxRef,
60299
60366
  className,
60300
60367
  "data-hook": "product"
60301
- }, ({ isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, imageElement ? applyInternalProps(imageElement, {
60368
+ }, ({ isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, imageElement ? applyInternalProps(imageElement, {
60302
60369
  option: option2,
60303
60370
  imageResize
60304
60371
  }) : null, labelElement ? applyInternalProps(labelElement, {
@@ -60307,7 +60374,8 @@ var ProductOption = ({ children, className, ...internal }) => {
60307
60374
  price
60308
60375
  }) : null, applyInternalProps(inputElement, {
60309
60376
  isSelected,
60310
- isHovered
60377
+ isHovered,
60378
+ isFocused
60311
60379
  }))));
60312
60380
  };
60313
60381
  var OptionImage2 = ({ className, ...internal }) => {
@@ -60470,15 +60538,17 @@ var Rating = ({ className, children, ...internal }) => {
60470
60538
  return /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioField, {
60471
60539
  value
60472
60540
  }, /* @__PURE__ */ React173__default.default.createElement(reactAriaComponents.RadioButton, {
60473
- className: ({ isHovered }) => typeof className === "function" ? className({
60541
+ className: ({ isHovered, isFocused }) => typeof className === "function" ? className({
60474
60542
  isSelected,
60475
- isHovered
60543
+ isHovered,
60544
+ isFocused
60476
60545
  }) : className ?? "",
60477
60546
  "data-active": isSelected || void 0,
60478
60547
  onHoverChange
60479
- }, ({ isHovered }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, typeof children === "function" ? children({
60548
+ }, ({ isHovered, isFocused }) => /* @__PURE__ */ React173__default.default.createElement(React173__default.default.Fragment, null, typeof children === "function" ? children({
60480
60549
  isSelected,
60481
- isHovered
60550
+ isHovered,
60551
+ isFocused
60482
60552
  }) : children, label ? /* @__PURE__ */ React173__default.default.createElement("span", {
60483
60553
  style: visuallyHiddenStyle
60484
60554
  }, label) : null)));
@@ -62224,7 +62294,7 @@ var UploadPreview = ({ className, imageAlt, ...internal }) => {
62224
62294
  "data-hook": "signature-image"
62225
62295
  }, value.displayName || imageAlt));
62226
62296
  };
62227
- var UploadButton = ({ children, className, onHoverStart, onHoverEnd, ...internal }) => {
62297
+ var UploadButton = ({ children, className, onHoverStart, onHoverEnd, onFocusChange, ...internal }) => {
62228
62298
  const { onSelectFiles, disabled, readOnly, onBlur, onFocus } = internal;
62229
62299
  const { inputId, ariaDescribedBy, labelId } = useFieldAttributes();
62230
62300
  const textId = useId2();
@@ -62251,7 +62321,8 @@ var UploadButton = ({ children, className, onHoverStart, onHoverEnd, ...internal
62251
62321
  "data-hook": "signature-upload",
62252
62322
  className,
62253
62323
  onHoverStart,
62254
- onHoverEnd
62324
+ onHoverEnd,
62325
+ onFocusChange
62255
62326
  }, content));
62256
62327
  };
62257
62328
  var UploadButtonText = ({ children, className, ...internal }) => {