@wix/form-public 0.47.0 → 0.49.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.
@@ -421,10 +421,12 @@ declare interface ChoiceOption {
421
421
  default: boolean;
422
422
  }
423
423
 
424
- export declare type Currency = {
424
+ declare type Currency = {
425
425
  sign?: string;
426
426
  code?: string;
427
427
  };
428
+ export { Currency }
429
+ export { Currency as Currency_alias_1 }
428
430
 
429
431
  declare interface CustomOption {
430
432
  label: string;
@@ -862,10 +864,15 @@ declare interface FormError {
862
864
  export { FormError }
863
865
  export { FormError as FormError_alias_1 }
864
866
 
865
- declare const FormProvider: ({ children }: Props) => JSX_2.Element;
867
+ declare const FormProvider: ({ children, currency }: FormProviderProps) => JSX_2.Element;
866
868
  export { FormProvider }
867
869
  export { FormProvider as FormProvider_alias_1 }
868
870
 
871
+ declare interface FormProviderProps {
872
+ currency: Currency;
873
+ children: React_2.ReactNode;
874
+ }
875
+
869
876
  declare type FormValues = {
870
877
  [target: string]: PossibleValues;
871
878
  };
@@ -1382,10 +1389,6 @@ export declare type ProductValue = {
1382
1389
  quantity: number;
1383
1390
  };
1384
1391
 
1385
- declare type Props = {
1386
- children: React_2.ReactNode;
1387
- };
1388
-
1389
1392
  export declare type PropsMapper = (props: any) => FieldProps;
1390
1393
 
1391
1394
  export declare const RadioGroupMapper: PropsMapper;
@@ -421,10 +421,12 @@ declare interface ChoiceOption {
421
421
  default: boolean;
422
422
  }
423
423
 
424
- export declare type Currency = {
424
+ declare type Currency = {
425
425
  sign?: string;
426
426
  code?: string;
427
427
  };
428
+ export { Currency }
429
+ export { Currency as Currency_alias_1 }
428
430
 
429
431
  declare interface CustomOption {
430
432
  label: string;
@@ -862,10 +864,15 @@ declare interface FormError {
862
864
  export { FormError }
863
865
  export { FormError as FormError_alias_1 }
864
866
 
865
- declare const FormProvider: ({ children }: Props) => JSX_2.Element;
867
+ declare const FormProvider: ({ children, currency }: FormProviderProps) => JSX_2.Element;
866
868
  export { FormProvider }
867
869
  export { FormProvider as FormProvider_alias_1 }
868
870
 
871
+ declare interface FormProviderProps {
872
+ currency: Currency;
873
+ children: React_2.ReactNode;
874
+ }
875
+
869
876
  declare type FormValues = {
870
877
  [target: string]: PossibleValues;
871
878
  };
@@ -1382,10 +1389,6 @@ export declare type ProductValue = {
1382
1389
  quantity: number;
1383
1390
  };
1384
1391
 
1385
- declare type Props = {
1386
- children: React_2.ReactNode;
1387
- };
1388
-
1389
1392
  export declare type PropsMapper = (props: any) => FieldProps;
1390
1393
 
1391
1394
  export declare const RadioGroupMapper: PropsMapper;
package/dist/index.cjs CHANGED
@@ -16139,7 +16139,18 @@ function useBi() {
16139
16139
  }
16140
16140
  return context;
16141
16141
  }
16142
+ var ForcedState = /* @__PURE__ */ (function(ForcedState2) {
16143
+ ForcedState2["BUTTONS_HOVER"] = "BUTTONS_HOVER";
16144
+ ForcedState2["NEXT_BUTTON_HOVER"] = "NEXT_BUTTON_HOVER";
16145
+ ForcedState2["PREVIOUS_BUTTON_HOVER"] = "PREVIOUS_BUTTON_HOVER";
16146
+ ForcedState2["SUBMIT_BUTTON_HOVER"] = "SUBMIT_BUTTON_HOVER";
16147
+ ForcedState2["INPUT_FIELDS_HOVER"] = "INPUT_FIELDS_HOVER";
16148
+ ForcedState2["INPUT_FIELDS_FOCUS"] = "INPUT_FIELDS_FOCUS";
16149
+ ForcedState2["INPUT_FIELDS_ERROR"] = "INPUT_FIELDS_ERROR";
16150
+ return ForcedState2;
16151
+ })({});
16142
16152
  var ForcedStateContext = /* @__PURE__ */ React14.createContext([]);
16153
+ var useForcedState = () => React14.useContext(ForcedStateContext) || [];
16143
16154
  var FALLBACK = {};
16144
16155
  var ExternalDataContext = /* @__PURE__ */ React14.createContext(void 0);
16145
16156
  var ExternalDataProvider = (_ref) => {
@@ -16193,8 +16204,214 @@ function formFieldFocus(params) {
16193
16204
  var FieldValidationContext = /* @__PURE__ */ React14.createContext(null);
16194
16205
  var useFieldValidation = () => React14.useContext(FieldValidationContext) || {};
16195
16206
 
16207
+ // ../form-fields/dist/esm/field-error/error-types.js
16208
+ init_esm();
16209
+
16210
+ // ../form-fields/dist/esm/constants/locale.js
16211
+ var TRANSLATIONS_NAMESPACE = "form-viewer";
16212
+
16213
+ // ../form-fields/dist/esm/field-error/get-translated-error.js
16214
+ var defaultErrorKeys = {
16215
+ [ErrorType.UNKNOWN_ERROR]: "input.error.message.unknown-error",
16216
+ [ErrorType.TYPE_ERROR]: "input.error.message.type-error",
16217
+ [ErrorType.REQUIRED_VALUE_ERROR]: "input.error.message.required-error",
16218
+ [ErrorType.UNKNOWN_VALUE_ERROR]: "input.error.message.unknown-value-error",
16219
+ [ErrorType.MAX_LENGTH_ERROR]: "input.error.message.max-length-error",
16220
+ [ErrorType.MIN_LENGTH_ERROR]: "input.error.message.min-length-error",
16221
+ [ErrorType.PATTERN_ERROR]: "input.error.message.pattern-error",
16222
+ [ErrorType.FORMAT_ERROR]: "input.error.message.format-error",
16223
+ [ErrorType.MAX_VALUE_ERROR]: "input.error.message.max-value-error",
16224
+ [ErrorType.MIN_VALUE_ERROR]: "input.error.message.min-value-error",
16225
+ [ErrorType.MULTIPLE_OF_VALUE_ERROR]: "input.error.message.multiple-of-value-error",
16226
+ [ErrorType.MIN_ITEMS_ERROR]: "input.error.message.min-items-error",
16227
+ [ErrorType.MAX_ITEMS_ERROR]: "input.error.message.max-items-error",
16228
+ [ErrorType.NOT_ALLOWED_VALUE_ERROR]: "input.error.message.not-allowed-value",
16229
+ [ErrorType.FIELDS_COMPATIBILITY_ERROR]: "input.error.fields-compatibility-error",
16230
+ [ErrorType.FIELDS_COUNT_RESTRICTIONS_ERROR]: "input.error.fields-count-restrictions-error",
16231
+ [ErrorType.FORMS_COUNT_RESTRICTIONS_ERROR]: "input.error.forms-count-restrictions-error",
16232
+ [ErrorType.STEPS_COUNT_RESTRICTIONS_ERROR]: "input.error.steps-count-restrictions-error",
16233
+ [ErrorType.RULES_COUNT_RESTRICTIONS_ERROR]: "input.error.rules-count-restrictions-error",
16234
+ [ErrorType.FILE_UPLOAD_RESTRICTIONS_ERROR]: "input.error.file-upload-restrictions-error",
16235
+ [ErrorType.DISABLED_FORM_ERROR]: "input.error.disabled-form-error",
16236
+ [ErrorType.INVALID_PHONE_COUNTRY_CODE_ERROR]: "input.error.message.invalid-phone-country-code-error",
16237
+ [ErrorType.INVALID_STAFF_ID_ERROR]: "input.error.message.invalid-staff-id-error",
16238
+ [ErrorType.INVALID_LOCATION_ID_ERROR]: "input.error.message.invalid-location-id-error",
16239
+ [ErrorType.MISSING_SERVICE_OPTION_ERROR]: "TBD",
16240
+ [ErrorType.INVALID_SERVICE_OPTIONS_ERROR]: "TBD",
16241
+ [ErrorType.NO_AVAILABLE_SERVICE_OPTIONS_ERROR]: "TBD",
16242
+ [ErrorType.EXACT_CHARACTER_LENGTH_ERROR]: "input.error.message.exact-character-length-error",
16243
+ [ErrorType.CHARACTER_LENGTH_RANGE_ERROR]: "input.error.message.character-length-range-error",
16244
+ [ErrorType.VALUE_RANGE_ERROR]: "input.error.message.value-range-error",
16245
+ [ErrorType.EXACT_ITEMS_NUMBER_ERROR]: "input.error.message.exact-items-number-error",
16246
+ [ErrorType.DECIMAL_POINT_ERROR]: "input.error.message.decimal_point_error",
16247
+ [ErrorType.INCOMPLETE_DATE_ERROR]: "input.error.message.incomplete-date-error",
16248
+ [ErrorType.INVALID_VALUE_FOR_PATTERN_ERROR]: "input.error.message.invalid-value-for-pattern"
16249
+ };
16250
+ var getTranslatedError = (_ref) => {
16251
+ let {
16252
+ translation,
16253
+ error,
16254
+ fieldType,
16255
+ suffix,
16256
+ currency
16257
+ } = _ref;
16258
+ const {
16259
+ t,
16260
+ i18n
16261
+ } = translation;
16262
+ const formattedFieldType = getFormattedFieldType(fieldType ?? "");
16263
+ const errorKey = defaultErrorKeys[error.errorType];
16264
+ const params = {
16265
+ ...error.params,
16266
+ currency
16267
+ };
16268
+ const fieldErrorKey = `${formattedFieldType}.${errorKey}`;
16269
+ if (suffix) {
16270
+ const fieldErrorKeyWithSuffix = `${fieldErrorKey}.${suffix}`;
16271
+ const errorKeyWithSuffix = `${errorKey}.${suffix}`;
16272
+ if (i18n.exists(`${TRANSLATIONS_NAMESPACE}:${fieldErrorKeyWithSuffix}`)) {
16273
+ return t(fieldErrorKeyWithSuffix, params);
16274
+ }
16275
+ if (i18n.exists(`${TRANSLATIONS_NAMESPACE}:${errorKeyWithSuffix}`)) {
16276
+ return t(errorKeyWithSuffix, params);
16277
+ }
16278
+ }
16279
+ if (i18n.exists(`${TRANSLATIONS_NAMESPACE}:${fieldErrorKey}`)) {
16280
+ return t(fieldErrorKey, params);
16281
+ }
16282
+ return t(defaultErrorKeys[error.errorType], params);
16283
+ };
16284
+ var getFormattedFieldType = (string) => string.toLowerCase().replace(/_/g, "-");
16285
+
16286
+ // ../form-fields/dist/esm/ui/date-field/date-field-utils.js
16287
+ var isDateFieldValidationError2 = (error) => {
16288
+ return (error == null ? void 0 : error.errorType) === ErrorType.INCOMPLETE_DATE_ERROR;
16289
+ };
16290
+ var getDateValidationErrorSuffix = (error) => isDateFieldValidationError2(error) ? error.params.suffix : void 0;
16291
+
16292
+ // ../form-fields/dist/esm/ui/date-time-field/date-time-field-utils.js
16293
+ var isDateTimeFieldValidationError2 = (error) => {
16294
+ return (error == null ? void 0 : error.errorType) === ErrorType.INCOMPLETE_DATE_ERROR;
16295
+ };
16296
+ var getDateTimeValidationErrorSuffix = (error) => isDateTimeFieldValidationError2(error) ? error.params.suffix : void 0;
16297
+
16298
+ // ../form-fields/dist/esm/field-error/use-error.js
16299
+ var getErrorSuffix = (_ref) => {
16300
+ let {
16301
+ fieldType,
16302
+ error,
16303
+ properties
16304
+ } = _ref;
16305
+ switch (fieldType) {
16306
+ case INPUT_FIELD_TYPES.DATE_TIME_INPUT:
16307
+ return getDateTimeValidationErrorSuffix(error);
16308
+ case INPUT_FIELD_TYPES.CONTACTS_BIRTHDATE:
16309
+ case INPUT_FIELD_TYPES.DATE_INPUT:
16310
+ return getDateValidationErrorSuffix(error);
16311
+ case INPUT_FIELD_TYPES.TEXT_INPUT:
16312
+ case INPUT_FIELD_TYPES.QUIZ_SHORT_TEXT:
16313
+ case INPUT_FIELD_TYPES.DEXT_TEXT_INPUT:
16314
+ case INPUT_FIELD_TYPES.DEXT_EMAIL:
16315
+ case INPUT_FIELD_TYPES.CONTACTS_TAX_ID:
16316
+ case INPUT_FIELD_TYPES.CONTACTS_POSITION:
16317
+ case INPUT_FIELD_TYPES.CONTACTS_LAST_NAME:
16318
+ case INPUT_FIELD_TYPES.CONTACTS_FIRST_NAME:
16319
+ case INPUT_FIELD_TYPES.CONTACTS_EMAIL:
16320
+ case INPUT_FIELD_TYPES.CONTACTS_COMPANY:
16321
+ case INPUT_FIELD_TYPES.CONTACTS_ADDRESS:
16322
+ case INPUT_FIELD_TYPES.BOOKINGS_LAST_NAME:
16323
+ case INPUT_FIELD_TYPES.BOOKINGS_FIRST_NAME:
16324
+ case INPUT_FIELD_TYPES.BOOKINGS_EMAIL:
16325
+ case INPUT_FIELD_TYPES.ECOM_PHONE:
16326
+ case INPUT_FIELD_TYPES.ECOM_EMAIL:
16327
+ case INPUT_FIELD_TYPES.ECOM_COMPANY_NAME:
16328
+ case INPUT_FIELD_TYPES.ECOM_ADDITIONAL_INFO:
16329
+ case INPUT_FIELD_TYPES.FULL_NAME_LAST_NAME:
16330
+ case INPUT_FIELD_TYPES.FULL_NAME_FIRST_NAME:
16331
+ case INPUT_FIELD_TYPES.MLA_STREET_NAME:
16332
+ case INPUT_FIELD_TYPES.MLA_ADDRESS_LINE:
16333
+ case INPUT_FIELD_TYPES.MLA_STREET_NUMBER:
16334
+ case INPUT_FIELD_TYPES.MLA_POSTAL_CODE:
16335
+ case INPUT_FIELD_TYPES.MLA_CITY:
16336
+ case INPUT_FIELD_TYPES.MLA_APARTMENT:
16337
+ case INPUT_FIELD_TYPES.MLA_ADDRESS_LINE_2:
16338
+ case INPUT_FIELD_TYPES.IDENTITY_PASSWORD:
16339
+ case INPUT_FIELD_TYPES.RATING_INPUT:
16340
+ case INPUT_FIELD_TYPES.DEXT_RATING_INPUT:
16341
+ case INPUT_FIELD_TYPES.MLA_COUNTRY:
16342
+ case INPUT_FIELD_TYPES.MLA_SUBDIVISION:
16343
+ if (properties && "countryCode" in properties) {
16344
+ const countryCode = properties.countryCode;
16345
+ return typeof countryCode === "string" ? countryCode.toLocaleLowerCase() : void 0;
16346
+ }
16347
+ return void 0;
16348
+ case INPUT_FIELD_TYPES.VAT_ID:
16349
+ if (properties && "country" in properties) {
16350
+ const country = properties.country;
16351
+ return typeof country === "string" ? country.toLocaleLowerCase() : void 0;
16352
+ }
16353
+ return void 0;
16354
+ case INPUT_FIELD_TYPES.SIGNATURE:
16355
+ if (properties && "uploadEnabled" in properties) {
16356
+ return properties.uploadEnabled ? "with-upload" : void 0;
16357
+ }
16358
+ return void 0;
16359
+ default:
16360
+ return void 0;
16361
+ }
16362
+ };
16363
+ var useError = (_ref2) => {
16364
+ let {
16365
+ error,
16366
+ customErrors,
16367
+ fieldType,
16368
+ properties,
16369
+ validationError
16370
+ } = _ref2;
16371
+ const {
16372
+ currency
16373
+ } = useConfig();
16374
+ const {
16375
+ t,
16376
+ i18n
16377
+ } = useTranslation();
16378
+ const forcedState = useForcedState();
16379
+ if (forcedState.includes(ForcedState.INPUT_FIELDS_ERROR)) {
16380
+ return {
16381
+ hasError: true,
16382
+ errorMessage: t("input.error.message.required-error-forced")
16383
+ };
16384
+ }
16385
+ if (!error) {
16386
+ return {
16387
+ hasError: false
16388
+ };
16389
+ }
16390
+ const customErrorMessage = (error == null ? void 0 : error.useCustomErrorMessage) && (error == null ? void 0 : error.errorMessage) || (customErrors == null ? void 0 : customErrors[error.errorType]);
16391
+ const suffix = fieldType ? getErrorSuffix({
16392
+ fieldType,
16393
+ error: validationError,
16394
+ properties
16395
+ }) : void 0;
16396
+ const errorMessage = customErrorMessage ?? getTranslatedError({
16397
+ translation: {
16398
+ i18n,
16399
+ t
16400
+ },
16401
+ error,
16402
+ fieldType,
16403
+ suffix,
16404
+ currency: currency == null ? void 0 : currency.sign
16405
+ });
16406
+ return {
16407
+ hasError: true,
16408
+ errorMessage
16409
+ };
16410
+ };
16411
+
16196
16412
  // ../form-fields/dist/esm/ui/form/components/form/input-field.js
16197
16413
  var InputField = (_ref) => {
16414
+ var _field$properties;
16198
16415
  let {
16199
16416
  field,
16200
16417
  errors,
@@ -16249,6 +16466,16 @@ var InputField = (_ref) => {
16249
16466
  }
16250
16467
  onFieldChange == null || onFieldChange(field.target, value);
16251
16468
  }, [onFieldChange, field, fieldError, validateFields2]);
16469
+ const {
16470
+ hasError,
16471
+ errorMessage
16472
+ } = useError({
16473
+ error: fieldError,
16474
+ customErrors: (_field$properties = field.properties) == null ? void 0 : _field$properties.customErrors,
16475
+ fieldType: field.fieldType,
16476
+ properties: field.properties,
16477
+ validationError: fieldError
16478
+ });
16252
16479
  const FieldComponent = componentsById[field.fieldType];
16253
16480
  if (!FieldComponent) {
16254
16481
  return null;
@@ -16257,6 +16484,8 @@ var InputField = (_ref) => {
16257
16484
  onChange: handleChange,
16258
16485
  onBlur: _onBlur,
16259
16486
  onFocus: _onFocus,
16487
+ hasError,
16488
+ errorMessage,
16260
16489
  error: fieldError,
16261
16490
  errors: fieldErrors,
16262
16491
  value: fieldValue,
@@ -21783,7 +22012,7 @@ var useForm3 = ({
21783
22012
  fieldsLayout
21784
22013
  } : null;
21785
22014
  };
21786
- var FormProvider = ({ children }) => {
22015
+ var FormProvider = ({ children, currency }) => {
21787
22016
  return /* @__PURE__ */ jsxRuntime.jsx(
21788
22017
  FormViewerProvider,
21789
22018
  {
@@ -21792,6 +22021,7 @@ var FormProvider = ({ children }) => {
21792
22021
  form: {},
21793
22022
  locale: "en",
21794
22023
  regionalFormat: "en",
22024
+ currency,
21795
22025
  WixRicosViewer: () => null,
21796
22026
  children: /* @__PURE__ */ jsxRuntime.jsx(ExternalDataProvider, { externalData: {}, children: /* @__PURE__ */ jsxRuntime.jsx(FormStatusProvider, { children }) })
21797
22027
  }