@wix/form-public 0.515.0 → 0.517.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
@@ -16231,7 +16231,7 @@ var require_classnames = __commonJS({
16231
16231
  "../../node_modules/classnames/index.js"(exports, module) {
16232
16232
  (function() {
16233
16233
  var hasOwn2 = {}.hasOwnProperty;
16234
- function classNames16() {
16234
+ function classNames17() {
16235
16235
  var classes = "";
16236
16236
  for (var i = 0; i < arguments.length; i++) {
16237
16237
  var arg = arguments[i];
@@ -16249,7 +16249,7 @@ var require_classnames = __commonJS({
16249
16249
  return "";
16250
16250
  }
16251
16251
  if (Array.isArray(arg)) {
16252
- return classNames16.apply(null, arg);
16252
+ return classNames17.apply(null, arg);
16253
16253
  }
16254
16254
  if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
16255
16255
  return arg.toString();
@@ -16272,14 +16272,14 @@ var require_classnames = __commonJS({
16272
16272
  return value + newClass;
16273
16273
  }
16274
16274
  if (typeof module !== "undefined" && module.exports) {
16275
- classNames16.default = classNames16;
16276
- module.exports = classNames16;
16275
+ classNames17.default = classNames17;
16276
+ module.exports = classNames17;
16277
16277
  } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
16278
16278
  define("classnames", [], function() {
16279
- return classNames16;
16279
+ return classNames17;
16280
16280
  });
16281
16281
  } else {
16282
- window.classNames = classNames16;
16282
+ window.classNames = classNames17;
16283
16283
  }
16284
16284
  })();
16285
16285
  }
@@ -43121,6 +43121,7 @@ var ForcedState = /* @__PURE__ */ (function(ForcedState2) {
43121
43121
  ForcedState2["INPUT_FIELDS_FOCUS"] = "INPUT_FIELDS_FOCUS";
43122
43122
  ForcedState2["INPUT_FIELDS_ERROR"] = "INPUT_FIELDS_ERROR";
43123
43123
  ForcedState2["SUCCESS_MESSAGE"] = "SUCCESS_MESSAGE";
43124
+ ForcedState2["HIDDEN_FIELDS"] = "HIDDEN_FIELDS";
43124
43125
  return ForcedState2;
43125
43126
  })({});
43126
43127
  var ForcedStateContext = createContext([]);
@@ -43161,6 +43162,203 @@ function useFormView() {
43161
43162
  return context;
43162
43163
  }
43163
43164
 
43165
+ // ../form-fields/dist/esm/field-layout/default-field-layout.js
43166
+ var import_classnames21 = __toESM(require_classnames());
43167
+
43168
+ // ../form-fields/dist/esm/ui/form/components/grid/responsive-grid.module.scss
43169
+ var responsive_grid_module_default = {};
43170
+
43171
+ // ../form-fields/dist/esm/utils/responsive-grid.js
43172
+ function placeResponsiveFields(fields, columns) {
43173
+ const groups = groupByDesktopRow(fields);
43174
+ const hasSmallLayout = fields.some((field) => field.layoutByBreakpoint?.small);
43175
+ const placement = {
43176
+ fields: /* @__PURE__ */ new Map(),
43177
+ rowOrder: /* @__PURE__ */ new Map()
43178
+ };
43179
+ if (!hasSmallLayout) {
43180
+ groups.forEach((group, index2) => {
43181
+ stackGroup(group, columns, placement);
43182
+ placement.rowOrder.set(group.row, index2);
43183
+ });
43184
+ return placement;
43185
+ }
43186
+ const smallLayoutOf = (field) => field.layoutByBreakpoint?.small ?? field.layout;
43187
+ const ranks = denseRanks(fields.map((field) => smallLayoutOf(field).row));
43188
+ const ranges = groups.map((group) => {
43189
+ const groupRanks = group.fields.map((field) => ranks.get(smallLayoutOf(field).row));
43190
+ return {
43191
+ min: Math.min(...groupRanks),
43192
+ max: Math.max(...groupRanks)
43193
+ };
43194
+ });
43195
+ const clusters = clusterOverlappingRanges(ranges);
43196
+ clusters.forEach((cluster) => {
43197
+ if (cluster.length > 1) {
43198
+ cluster.forEach((index3) => stackGroup(groups[index3], columns, placement));
43199
+ return;
43200
+ }
43201
+ const [index2] = cluster;
43202
+ groups[index2].fields.forEach((field) => {
43203
+ const small = smallLayoutOf(field);
43204
+ placement.fields.set(field.id, {
43205
+ large: toLargePlacement(field.layout),
43206
+ small: {
43207
+ ...clampColumns(small, columns),
43208
+ subRow: ranks.get(small.row) - ranges[index2].min
43209
+ }
43210
+ });
43211
+ });
43212
+ });
43213
+ clusters.flatMap((cluster) => [
43214
+ ...cluster
43215
+ ].sort((one, other) => one - other)).forEach((index2, order) => placement.rowOrder.set(groups[index2].row, order));
43216
+ return placement;
43217
+ }
43218
+ function clusterOverlappingRanges(ranges) {
43219
+ const byMin = ranges.map((range3, index2) => ({
43220
+ ...range3,
43221
+ index: index2
43222
+ })).sort((one, other) => one.min - other.min || one.index - other.index);
43223
+ const clusters = [];
43224
+ byMin.forEach(({ min: min4, max: max4, index: index2 }) => {
43225
+ const last6 = clusters.at(-1);
43226
+ if (last6 && min4 <= last6.max) {
43227
+ last6.indices.push(index2);
43228
+ last6.max = Math.max(last6.max, max4);
43229
+ } else {
43230
+ clusters.push({
43231
+ max: max4,
43232
+ indices: [
43233
+ index2
43234
+ ]
43235
+ });
43236
+ }
43237
+ });
43238
+ return clusters.map(({ indices }) => indices);
43239
+ }
43240
+ function toResponsiveGridVariables({ large, small }) {
43241
+ const columnVariables = {
43242
+ "--form-col-lg": toColumn(large),
43243
+ "--form-col-sm": toColumn(small)
43244
+ };
43245
+ const offset = {
43246
+ "--form-row-offset-sm": small.subRow > 0 ? "1" : "0"
43247
+ };
43248
+ return {
43249
+ label: {
43250
+ ...columnVariables,
43251
+ ...offset,
43252
+ "--form-row-lg": toRow(large, 0, 1),
43253
+ "--form-row-sm": toRow(small, 0, 1)
43254
+ },
43255
+ input: {
43256
+ ...columnVariables,
43257
+ "--form-row-offset-sm": "0",
43258
+ "--form-row-lg": toRow(large, 1, 1),
43259
+ "--form-row-sm": toRow(small, 1, 1)
43260
+ },
43261
+ container: {
43262
+ ...columnVariables,
43263
+ ...offset,
43264
+ "--form-row-lg": toRow(large, 0, 2),
43265
+ "--form-row-sm": toRow(small, 0, 2)
43266
+ }
43267
+ };
43268
+ }
43269
+ var responsiveGridCache = /* @__PURE__ */ new WeakMap();
43270
+ function getResponsiveGrid(form) {
43271
+ const cached = responsiveGridCache.get(form);
43272
+ if (cached) {
43273
+ return cached;
43274
+ }
43275
+ const placement = placeResponsiveFields(form.fields, form.grid.columns);
43276
+ const grid = {
43277
+ fields: new Map([
43278
+ ...placement.fields
43279
+ ].map(([fieldId, fieldPlacement]) => [
43280
+ fieldId,
43281
+ toResponsiveGridVariables(fieldPlacement)
43282
+ ])),
43283
+ rows: new Map([
43284
+ ...placement.rowOrder
43285
+ ].map(([row, order]) => [
43286
+ row,
43287
+ {
43288
+ "--form-row-order-sm": String(order)
43289
+ }
43290
+ ]))
43291
+ };
43292
+ responsiveGridCache.set(form, grid);
43293
+ return grid;
43294
+ }
43295
+ function groupByDesktopRow(fields) {
43296
+ const groups = /* @__PURE__ */ new Map();
43297
+ fields.forEach((field) => {
43298
+ const group = groups.get(field.layout.row);
43299
+ if (group) {
43300
+ group.push(field);
43301
+ } else {
43302
+ groups.set(field.layout.row, [
43303
+ field
43304
+ ]);
43305
+ }
43306
+ });
43307
+ return [
43308
+ ...groups
43309
+ ].sort(([one], [other]) => one - other).map(([row, groupFields]) => ({
43310
+ row,
43311
+ fields: groupFields
43312
+ }));
43313
+ }
43314
+ function stackGroup(group, columns, placement) {
43315
+ group.fields.forEach((field, subRow) => {
43316
+ placement.fields.set(field.id, {
43317
+ large: toLargePlacement(field.layout),
43318
+ small: {
43319
+ column: 0,
43320
+ width: columns,
43321
+ subRow
43322
+ }
43323
+ });
43324
+ });
43325
+ }
43326
+ function denseRanks(rows) {
43327
+ return new Map([
43328
+ ...new Set(rows)
43329
+ ].sort((one, other) => one - other).map((row, rank) => [
43330
+ row,
43331
+ rank
43332
+ ]));
43333
+ }
43334
+ function toLargePlacement({ column, width }) {
43335
+ return {
43336
+ column,
43337
+ width,
43338
+ subRow: 0
43339
+ };
43340
+ }
43341
+ function clampColumns({ column, width }, columns) {
43342
+ const clampedColumn = Math.min(Math.max(column, 0), columns - 1);
43343
+ return {
43344
+ column: clampedColumn,
43345
+ width: Math.min(Math.max(width, 1), columns - clampedColumn)
43346
+ };
43347
+ }
43348
+ function toColumn({ column, width }) {
43349
+ return `${column + 1} / span ${width}`;
43350
+ }
43351
+ function toRow({ subRow }, track, span) {
43352
+ return `${subRow * 2 + track + 1} / span ${span}`;
43353
+ }
43354
+
43355
+ // ../form-fields/dist/esm/ui/form/components/grid/use-responsive-grid.js
43356
+ function useResponsiveGrid() {
43357
+ const { cssMobileLayout, isMobile: isMobile2 } = useConfig();
43358
+ const form = useContext(FormViewContext);
43359
+ return cssMobileLayout && !isMobile2 && form ? getResponsiveGrid(form) : void 0;
43360
+ }
43361
+
43164
43362
  // ../form-fields/dist/esm/ui/form/types/form-view.js
43165
43363
  function isInputField2(field) {
43166
43364
  return Boolean(field.target);
@@ -43195,6 +43393,7 @@ function calculateGridStyles(options) {
43195
43393
  // ../form-fields/dist/esm/field-layout/default-field-layout.js
43196
43394
  var DefaultFieldLayout = ({ fieldId, ...rest }) => {
43197
43395
  const fieldView = useFieldView(fieldId);
43396
+ const responsiveGrid = useResponsiveGrid();
43198
43397
  if (!fieldView) {
43199
43398
  return null;
43200
43399
  }
@@ -43204,30 +43403,58 @@ var DefaultFieldLayout = ({ fieldId, ...rest }) => {
43204
43403
  "data-hook": dataHook,
43205
43404
  "data-field-type": fieldType
43206
43405
  };
43207
- const gridStyles = calculateGridStyles({
43208
- layout
43209
- });
43406
+ const cellProps = getCellProps(layout, responsiveGrid?.fields.get(fieldId));
43210
43407
  if ("children" in rest) {
43211
43408
  return /* @__PURE__ */ React172.createElement("div", {
43212
- style: gridStyles.container,
43409
+ ...cellProps.container,
43213
43410
  ...dataAttributes
43214
43411
  }, rest.children);
43215
43412
  }
43216
43413
  const { renderLabel, renderInput, renderDescription } = rest;
43217
- return /* @__PURE__ */ React172.createElement(React172.Fragment, null, /* @__PURE__ */ React172.createElement("div", {
43218
- style: gridStyles.label
43219
- }, renderLabel()), /* @__PURE__ */ React172.createElement("div", {
43220
- style: gridStyles.input,
43414
+ return /* @__PURE__ */ React172.createElement(React172.Fragment, null, /* @__PURE__ */ React172.createElement("div", cellProps.label, renderLabel()), /* @__PURE__ */ React172.createElement("div", {
43415
+ ...cellProps.input,
43221
43416
  ...dataAttributes
43222
43417
  }, renderInput(), renderDescription()));
43223
43418
  };
43419
+ function getCellProps(layout, variables) {
43420
+ if (!variables) {
43421
+ const { label, input, container } = calculateGridStyles({
43422
+ layout
43423
+ });
43424
+ return {
43425
+ label: {
43426
+ style: label
43427
+ },
43428
+ input: {
43429
+ style: input
43430
+ },
43431
+ container: {
43432
+ style: container
43433
+ }
43434
+ };
43435
+ }
43436
+ return {
43437
+ label: {
43438
+ style: variables.label,
43439
+ className: (0, import_classnames21.default)(responsive_grid_module_default.cell, responsive_grid_module_default.label)
43440
+ },
43441
+ input: {
43442
+ style: variables.input,
43443
+ className: responsive_grid_module_default.cell
43444
+ },
43445
+ container: {
43446
+ style: variables.container,
43447
+ className: responsive_grid_module_default.cell
43448
+ }
43449
+ };
43450
+ }
43224
43451
 
43225
43452
  // ../form-fields/dist/esm/ui/form/components/grid/grid.js
43226
- var import_classnames21 = __toESM(require_classnames());
43453
+ var import_classnames22 = __toESM(require_classnames());
43227
43454
 
43228
43455
  // ../form-fields/dist/esm/animations/grid-animations.module.scss
43229
43456
  var grid_animations_module_default = {};
43230
- var Focusable = ({ children, fieldId }) => {
43457
+ var Focusable = ({ children, fieldId, className, style }) => {
43231
43458
  const viewRef = useRef(null);
43232
43459
  const { scrollTo } = useScroll();
43233
43460
  const { focusedFieldId } = useFocusedField();
@@ -43241,17 +43468,21 @@ var Focusable = ({ children, fieldId }) => {
43241
43468
  focusedFieldId
43242
43469
  ]);
43243
43470
  return /* @__PURE__ */ React172.createElement("div", {
43244
- ref: viewRef
43471
+ ref: viewRef,
43472
+ className,
43473
+ style
43245
43474
  }, children);
43246
43475
  };
43247
43476
 
43248
43477
  // ../form-fields/dist/esm/ui/form/components/grid/grid-options.js
43249
- var getGridStyle = ({ layout }) => {
43478
+ var getGridStyle = ({ layout, responsive = false }) => {
43250
43479
  return {
43251
43480
  display: "grid",
43252
43481
  width: "100%",
43253
43482
  gridTemplateColumns: `repeat(${layout.columns}, 1fr)`,
43254
- gridAutoRows: "minmax(min-content, max-content) 1fr"
43483
+ ...responsive ? {} : {
43484
+ gridAutoRows: "minmax(min-content, max-content) 1fr"
43485
+ }
43255
43486
  };
43256
43487
  };
43257
43488
 
@@ -43261,6 +43492,7 @@ var grid_module_default = {};
43261
43492
  // ../form-fields/dist/esm/ui/form/components/grid/grid.js
43262
43493
  var Grid = ({ items, layout, isRTL }) => {
43263
43494
  const { isMobile: isMobile2, enableAnimations } = useConfig();
43495
+ const responsiveGrid = useResponsiveGrid();
43264
43496
  const reactElementsByRow = getReactElementsByRow(items);
43265
43497
  return /* @__PURE__ */ React172.createElement("div", {
43266
43498
  className: grid_module_default.container,
@@ -43268,16 +43500,21 @@ var Grid = ({ items, layout, isRTL }) => {
43268
43500
  }, reactElementsByRow.map((rowData, index2) => {
43269
43501
  const fieldId = rowData.firstFieldId;
43270
43502
  const key = isMobile2 && fieldId || index2;
43503
+ const responsive = Boolean(responsiveGrid);
43271
43504
  return /* @__PURE__ */ React172.createElement(Focusable, {
43272
43505
  key: fieldId,
43273
- fieldId
43506
+ fieldId,
43507
+ className: responsive ? responsive_grid_module_default.row : void 0,
43508
+ style: responsiveGrid?.rows.get(rowData.row)
43274
43509
  }, /* @__PURE__ */ React172.createElement("div", {
43275
43510
  key,
43276
43511
  style: getGridStyle({
43277
- layout
43512
+ layout,
43513
+ responsive
43278
43514
  }),
43279
- className: (0, import_classnames21.default)(grid_module_default.grid, grid_module_default.column, {
43280
- [grid_animations_module_default.animations]: enableAnimations
43515
+ className: (0, import_classnames22.default)(grid_module_default.grid, grid_module_default.column, {
43516
+ [grid_animations_module_default.animations]: enableAnimations,
43517
+ [responsive_grid_module_default.grid]: responsive
43281
43518
  })
43282
43519
  }, rowData.elements));
43283
43520
  }));
@@ -43295,7 +43532,8 @@ function getReactElementsByRow(items) {
43295
43532
  elements: [
43296
43533
  element
43297
43534
  ],
43298
- firstFieldId: item.id
43535
+ firstFieldId: item.id,
43536
+ row
43299
43537
  };
43300
43538
  }
43301
43539
  return result2;
@@ -49908,6 +50146,7 @@ var useFormValues = (form, values, onChange, userData, addressTemplates, enableA
49908
50146
  };
49909
50147
  var useFormView2 = (form, stepId, breakpoint) => {
49910
50148
  const { isMobile: isMobile2 } = useConfig();
50149
+ const includeHiddenFields = useForcedState().includes(ForcedState.HIDDEN_FIELDS);
49911
50150
  const experiments = useExperiments();
49912
50151
  const useFieldsV2App = experiments.isExperimentEnabled(EXPERIMENTS.USE_FIELDS_V2);
49913
50152
  const useFieldsV2Standalone = experiments.isExperimentEnabled(EXPERIMENTS.USE_FIELDS_V2_STANDALONE);
@@ -49922,7 +50161,8 @@ var useFormView2 = (form, stepId, breakpoint) => {
49922
50161
  stepId: step.id,
49923
50162
  isMobile: isMobile2,
49924
50163
  breakpoint,
49925
- useFieldsV2
50164
+ useFieldsV2,
50165
+ includeHiddenFields
49926
50166
  });
49927
50167
  });
49928
50168
  }, [
@@ -49930,7 +50170,8 @@ var useFormView2 = (form, stepId, breakpoint) => {
49930
50170
  stepId,
49931
50171
  isMobile2,
49932
50172
  breakpoint,
49933
- useFieldsV2
50173
+ useFieldsV2,
50174
+ includeHiddenFields
49934
50175
  ]);
49935
50176
  };
49936
50177
  var useReportFieldEdit = (form) => {
@@ -50556,7 +50797,7 @@ var useFormBi = (form, bi2, biFormFillSessionId) => {
50556
50797
  };
50557
50798
 
50558
50799
  // ../form-viewer/dist/esm/components/root/form-viewer-provider.js
50559
- var FormViewerProvider = ({ i18n, bi: bi2, biFormFillSessionId, form, isMobile: isMobile2, isEditor, isComposer, isRTL, compId, PortalContainer, language, regionalFormat, externalData, forcedState, children, panorama, experiments, translationNamespace, currency, userData, WixRicosViewer, addressTemplates, fieldInitialData, enableAnimations, baseUrl }) => {
50800
+ var FormViewerProvider = ({ i18n, bi: bi2, biFormFillSessionId, form, isMobile: isMobile2, isEditor, isComposer, isRTL, compId, PortalContainer, language, regionalFormat, externalData, forcedState, children, panorama, experiments, translationNamespace, currency, userData, WixRicosViewer, addressTemplates, fieldInitialData, enableAnimations, cssMobileLayout, baseUrl }) => {
50560
50801
  const translations = useMemo(() => ({
50561
50802
  t: i18n.getFixedT(language, translationNamespace),
50562
50803
  i18n
@@ -50588,7 +50829,8 @@ var FormViewerProvider = ({ i18n, bi: bi2, biFormFillSessionId, form, isMobile:
50588
50829
  isEditor,
50589
50830
  isComposer,
50590
50831
  isRTL,
50591
- enableAnimations
50832
+ enableAnimations,
50833
+ cssMobileLayout
50592
50834
  }), [
50593
50835
  language,
50594
50836
  regionalFormat,
@@ -50601,7 +50843,8 @@ var FormViewerProvider = ({ i18n, bi: bi2, biFormFillSessionId, form, isMobile:
50601
50843
  isEditor,
50602
50844
  isComposer,
50603
50845
  isRTL,
50604
- enableAnimations
50846
+ enableAnimations,
50847
+ cssMobileLayout
50605
50848
  ]);
50606
50849
  const forcedViewState = useMemo(() => forcedState ?? [], [
50607
50850
  forcedState