@wix/form-public 0.566.0 → 0.568.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 +101 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +101 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -174,10 +174,37 @@ var init_errors = __esm({
|
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
// ../form-validator/dist/esm/lib/
|
|
178
|
-
function
|
|
179
|
-
|
|
177
|
+
// ../form-validator/dist/esm/lib/utils/to-decimal.js
|
|
178
|
+
function toDecimal(value) {
|
|
179
|
+
const [mantissa, exponent = "0"] = String(Math.abs(value)).split("e");
|
|
180
|
+
const [integerPart, fractionPart = ""] = mantissa.split(".");
|
|
181
|
+
return {
|
|
182
|
+
unscaledValue: BigInt(integerPart + fractionPart),
|
|
183
|
+
scale: fractionPart.length - Number(exponent)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function toScaledInteger({ unscaledValue, scale }, targetScale) {
|
|
187
|
+
return unscaledValue * 10n ** BigInt(targetScale - scale);
|
|
188
|
+
}
|
|
189
|
+
var init_to_decimal = __esm({
|
|
190
|
+
"../form-validator/dist/esm/lib/utils/to-decimal.js"() {
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// ../form-validator/dist/esm/lib/utils/get-decimal-scale.js
|
|
195
|
+
function getDecimalScale(value) {
|
|
196
|
+
if (!Number.isFinite(value)) {
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
return Math.max(toDecimal(value).scale, 0);
|
|
180
200
|
}
|
|
201
|
+
var init_get_decimal_scale = __esm({
|
|
202
|
+
"../form-validator/dist/esm/lib/utils/get-decimal-scale.js"() {
|
|
203
|
+
init_to_decimal();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// ../form-validator/dist/esm/lib/error-derivation/helpers.js
|
|
181
208
|
function deserializeDate(value) {
|
|
182
209
|
if (!value) {
|
|
183
210
|
return {};
|
|
@@ -341,7 +368,7 @@ function deriveNumericValueError(validation, error) {
|
|
|
341
368
|
if (isMultipleOfValueError) {
|
|
342
369
|
const multipleOf = validation?.number?.multipleOf;
|
|
343
370
|
if (multipleOf) {
|
|
344
|
-
const decimalPlaces =
|
|
371
|
+
const decimalPlaces = getDecimalScale(multipleOf);
|
|
345
372
|
return {
|
|
346
373
|
...error,
|
|
347
374
|
errorType: types.ErrorType.DECIMAL_POINT_ERROR,
|
|
@@ -440,6 +467,7 @@ function deriveDateTimeFieldError(validation, error, value) {
|
|
|
440
467
|
var init_error_derivers = __esm({
|
|
441
468
|
"../form-validator/dist/esm/lib/error-derivation/error-derivers.js"() {
|
|
442
469
|
init_errors();
|
|
470
|
+
init_get_decimal_scale();
|
|
443
471
|
init_helpers();
|
|
444
472
|
init_types();
|
|
445
473
|
}
|
|
@@ -12570,6 +12598,43 @@ var init_max = __esm({
|
|
|
12570
12598
|
init_core();
|
|
12571
12599
|
}
|
|
12572
12600
|
});
|
|
12601
|
+
|
|
12602
|
+
// ../form-validator/dist/esm/lib/utils/compile-is-multiple-of.js
|
|
12603
|
+
function compileIsMultipleOf(multipleOf) {
|
|
12604
|
+
if (!Number.isFinite(multipleOf) || multipleOf <= 0) {
|
|
12605
|
+
return () => false;
|
|
12606
|
+
}
|
|
12607
|
+
const divisor = toDecimal(multipleOf);
|
|
12608
|
+
const maxTolerableNoise = multipleOf * MAX_NOISE_TO_STEP_RATIO;
|
|
12609
|
+
return (value) => {
|
|
12610
|
+
if (!Number.isFinite(value)) {
|
|
12611
|
+
return true;
|
|
12612
|
+
}
|
|
12613
|
+
const dividend = toDecimal(value);
|
|
12614
|
+
const scale = Math.max(dividend.scale, divisor.scale);
|
|
12615
|
+
const scaledDivisor = toScaledInteger(divisor, scale);
|
|
12616
|
+
const remainder = toScaledInteger(dividend, scale) % scaledDivisor;
|
|
12617
|
+
if (remainder === 0n) {
|
|
12618
|
+
return true;
|
|
12619
|
+
}
|
|
12620
|
+
const noise = FLOATING_POINT_NOISE_ULPS * Math.abs(value) * Number.EPSILON;
|
|
12621
|
+
const distanceToNearestMultiple = remainder < scaledDivisor - remainder ? remainder : scaledDivisor - remainder;
|
|
12622
|
+
return isWithinNoise(distanceToNearestMultiple, scale, Math.min(noise, maxTolerableNoise));
|
|
12623
|
+
};
|
|
12624
|
+
}
|
|
12625
|
+
function isWithinNoise(distance, distanceScale, noise) {
|
|
12626
|
+
const noiseDecimal = toDecimal(noise);
|
|
12627
|
+
const scale = Math.max(distanceScale, noiseDecimal.scale);
|
|
12628
|
+
return distance * 10n ** BigInt(scale - distanceScale) <= toScaledInteger(noiseDecimal, scale);
|
|
12629
|
+
}
|
|
12630
|
+
var FLOATING_POINT_NOISE_ULPS, MAX_NOISE_TO_STEP_RATIO;
|
|
12631
|
+
var init_compile_is_multiple_of = __esm({
|
|
12632
|
+
"../form-validator/dist/esm/lib/utils/compile-is-multiple-of.js"() {
|
|
12633
|
+
init_to_decimal();
|
|
12634
|
+
FLOATING_POINT_NOISE_ULPS = 4;
|
|
12635
|
+
MAX_NOISE_TO_STEP_RATIO = 1e-6;
|
|
12636
|
+
}
|
|
12637
|
+
});
|
|
12573
12638
|
function parseLocalDate(value) {
|
|
12574
12639
|
const match4 = LOCAL_DATE_REGEX.exec(value);
|
|
12575
12640
|
if (!match4 || isNaN(new Date(value).getTime())) {
|
|
@@ -12640,6 +12705,16 @@ var init_date_availability = __esm({
|
|
|
12640
12705
|
|
|
12641
12706
|
// ../form-validator/dist/esm/lib/submission-validation/ajv/ajv-custom-keywords.js
|
|
12642
12707
|
function addCustomKeywords(ajv, phoneValidationEnabled, lenientPhoneValidation) {
|
|
12708
|
+
ajv.removeKeyword("multipleOf");
|
|
12709
|
+
ajv.addKeyword({
|
|
12710
|
+
keyword: "multipleOf",
|
|
12711
|
+
type: "number",
|
|
12712
|
+
schemaType: "number",
|
|
12713
|
+
errors: true,
|
|
12714
|
+
compile(multipleOf) {
|
|
12715
|
+
return compileMultipleOfValidation(multipleOf);
|
|
12716
|
+
}
|
|
12717
|
+
});
|
|
12643
12718
|
ajv.addKeyword({
|
|
12644
12719
|
keyword: "dateAvailability",
|
|
12645
12720
|
type: "string",
|
|
@@ -12799,6 +12874,26 @@ function getCallingCode(phoneNumber) {
|
|
|
12799
12874
|
function onlyCallingCode(callingCode, data) {
|
|
12800
12875
|
return data.replace(/^\+/, "") === callingCode;
|
|
12801
12876
|
}
|
|
12877
|
+
function compileMultipleOfValidation(multipleOf) {
|
|
12878
|
+
const isMultipleOf = compileIsMultipleOf(multipleOf);
|
|
12879
|
+
const validate2 = (data) => {
|
|
12880
|
+
if (typeof data !== "number" || isMultipleOf(data)) {
|
|
12881
|
+
return true;
|
|
12882
|
+
}
|
|
12883
|
+
const errors = [
|
|
12884
|
+
{
|
|
12885
|
+
keyword: "multipleOf",
|
|
12886
|
+
message: `must be multiple of ${multipleOf}`,
|
|
12887
|
+
params: {
|
|
12888
|
+
multipleOf
|
|
12889
|
+
}
|
|
12890
|
+
}
|
|
12891
|
+
];
|
|
12892
|
+
validate2.errors = errors;
|
|
12893
|
+
return false;
|
|
12894
|
+
};
|
|
12895
|
+
return validate2;
|
|
12896
|
+
}
|
|
12802
12897
|
function compileDateAvailabilityValidation(availability) {
|
|
12803
12898
|
const validate2 = (data) => {
|
|
12804
12899
|
if (typeof data !== "string") {
|
|
@@ -12825,6 +12920,7 @@ var init_ajv_custom_keywords = __esm({
|
|
|
12825
12920
|
"../form-validator/dist/esm/lib/submission-validation/ajv/ajv-custom-keywords.js"() {
|
|
12826
12921
|
init_max();
|
|
12827
12922
|
init_metadata_max_json();
|
|
12923
|
+
init_compile_is_multiple_of();
|
|
12828
12924
|
init_date_availability();
|
|
12829
12925
|
}
|
|
12830
12926
|
});
|
|
@@ -12833,8 +12929,7 @@ var init_ajv_custom_keywords = __esm({
|
|
|
12833
12929
|
function createAjvSchemaValidatorFactory(formSchemaMapper, phoneValidationEnabled, lenientPhoneValidation) {
|
|
12834
12930
|
return function createAjvSchemaValidator(formsSchemas) {
|
|
12835
12931
|
const ajv = new import_ajv.default({
|
|
12836
|
-
allErrors: true
|
|
12837
|
-
multipleOfPrecision: 8
|
|
12932
|
+
allErrors: true
|
|
12838
12933
|
});
|
|
12839
12934
|
(0, import_ajv_formats.default)(ajv);
|
|
12840
12935
|
addCustomFormats(ajv, phoneValidationEnabled);
|