@wix/form-public 0.527.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.js CHANGED
@@ -38261,7 +38261,9 @@ var READONLY_FIELD_TYPES = {
38261
38261
  // ../form-fields/dist/esm/constants/field-types.js
38262
38262
  var FIELD_TYPES = {
38263
38263
  ...INPUT_FIELD_TYPES,
38264
- ...READONLY_FIELD_TYPES};
38264
+ ...READONLY_FIELD_TYPES,
38265
+ SUBMIT_BUTTON: "SUBMIT_BUTTON"
38266
+ };
38265
38267
 
38266
38268
  // ../form-fields/dist/esm/constants/empty-values.js
38267
38269
  var EMPTY_VALUE = null;
@@ -47234,6 +47236,52 @@ function makeInputValidation(identifier, inputOptions) {
47234
47236
  };
47235
47237
  }
47236
47238
 
47239
+ // ../form-fields/dist/esm/services/grid-defaults.js
47240
+ var GRID_DEFAULTS = {
47241
+ columns: 12,
47242
+ rowHeight: 24,
47243
+ margin: {
47244
+ vertical: 24,
47245
+ horizontal: 24
47246
+ },
47247
+ padding: {
47248
+ vertical: 0,
47249
+ horizontal: 0
47250
+ }
47251
+ };
47252
+
47253
+ // ../form-fields/dist/esm/services/complete-small-layout-items.js
47254
+ function completeSmallLayoutItems({ large, small, columns, submitFieldIds = [] }) {
47255
+ const placedFieldIds = new Set(small.map(({ fieldId }) => fieldId));
47256
+ const submitRows = small.filter(({ fieldId }) => fieldId && submitFieldIds.includes(fieldId)).map(({ row: row2 }) => row2 ?? 0);
47257
+ const insertRow = submitRows.length ? Math.max(...submitRows) : Math.max(0, ...small.map(({ row: row2, height }) => (row2 ?? 0) + (height ?? 1)));
47258
+ const unplaced = large.filter(({ fieldId }) => fieldId && !placedFieldIds.has(fieldId)).sort((one, other) => (one.row ?? 0) - (other.row ?? 0) || (one.column ?? 0) - (other.column ?? 0));
47259
+ if (!unplaced.length) {
47260
+ return small;
47261
+ }
47262
+ let row = insertRow;
47263
+ const appended = unplaced.map(({ fieldId, height }) => {
47264
+ const item = {
47265
+ fieldId,
47266
+ row,
47267
+ column: 0,
47268
+ width: columns ?? GRID_DEFAULTS.columns,
47269
+ height: height ?? 1
47270
+ };
47271
+ row += item.height;
47272
+ return item;
47273
+ });
47274
+ const insertedHeight = row - insertRow;
47275
+ const shifted = small.map((item) => (item.row ?? 0) >= insertRow ? {
47276
+ ...item,
47277
+ row: (item.row ?? 0) + insertedHeight
47278
+ } : item);
47279
+ return [
47280
+ ...shifted,
47281
+ ...appended
47282
+ ];
47283
+ }
47284
+
47237
47285
  // ../form-fields/dist/esm/types/image.js
47238
47286
  var ImagePosition4 = /* @__PURE__ */ (function(ImagePosition5) {
47239
47287
  ImagePosition5["TOP"] = "top";
@@ -47274,19 +47322,19 @@ function toFieldLabelMediaSettings(view) {
47274
47322
  return Object.keys(mediaSettings).length ? mediaSettings : void 0;
47275
47323
  }
47276
47324
 
47325
+ // ../form-fields/dist/esm/services/submit-field-ids.js
47326
+ function getSubmitFieldIds(fields = []) {
47327
+ return fields.flatMap(({ id: id6, view }) => id6 && view?.fieldType === FIELD_TYPES.SUBMIT_BUTTON ? [
47328
+ id6
47329
+ ] : []);
47330
+ }
47331
+ function getSubmitFieldIdsV2(fields = []) {
47332
+ return fields.flatMap(({ id: id6, identifier }) => id6 && identifier === FIELD_TYPES.SUBMIT_BUTTON ? [
47333
+ id6
47334
+ ] : []);
47335
+ }
47336
+
47277
47337
  // ../form-fields/dist/esm/services/form-view.js
47278
- var GRID_DEFAULTS = {
47279
- columns: 12,
47280
- rowHeight: 24,
47281
- margin: {
47282
- vertical: 24,
47283
- horizontal: 24
47284
- },
47285
- padding: {
47286
- vertical: 0,
47287
- horizontal: 0
47288
- }
47289
- };
47290
47338
  function createFormView({ form, path = "", stepId, recursive = true, includeHiddenFields = false, isMobile: isMobile2 = false, breakpoint = DEFAULT_BREAKPOINT, useFieldsV2 = false, parentId = "" }) {
47291
47339
  const step = stepId ? form.steps?.find(({ id: id6 }) => id6 === stepId) : form.steps?.[0];
47292
47340
  const layout = step?.layout ?? {};
@@ -47298,11 +47346,24 @@ function createFormView({ form, path = "", stepId, recursive = true, includeHidd
47298
47346
  } else if ("name" in form) {
47299
47347
  nameView = form.name ?? "";
47300
47348
  }
47301
- const hasSmallLayout = layout.small?.items;
47349
+ const smallItems = layout.small?.items ?? [];
47350
+ const hasSmallLayout = smallItems.length > 0;
47302
47351
  const isSmallBreakpoint = isMobile2 && hasSmallLayout;
47352
+ const effectiveLayout = hasSmallLayout ? {
47353
+ ...layout,
47354
+ small: {
47355
+ ...layout.small,
47356
+ items: completeSmallLayoutItems({
47357
+ large: layout.large?.items ?? [],
47358
+ small: smallItems,
47359
+ columns: layout.large?.columns,
47360
+ submitFieldIds: useFieldsV2 && platformizedFields ? getSubmitFieldIdsV2(platformizedFields) : getSubmitFieldIds(fields)
47361
+ })
47362
+ }
47363
+ } : layout;
47303
47364
  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) => {
47304
47365
  const _field = useFieldsV2 && platformizedFields ? transformFieldToV1(field) : field;
47305
- const fieldView = createFieldView(_field, layout, path, recursive, isMobile2, isSmallBreakpoint ? Breakpoint.SMALL : breakpoint);
47366
+ const fieldView = createFieldView(_field, effectiveLayout, path, recursive, isMobile2, isSmallBreakpoint ? Breakpoint.SMALL : breakpoint);
47306
47367
  if (fieldView) {
47307
47368
  result2.push(fieldView);
47308
47369
  }