form-builder-pro 1.3.4 → 1.3.5
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 +28 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4442,6 +4442,14 @@ function convertSpanToWidth(span, totalColumns = 12) {
|
|
|
4442
4442
|
const percentage = span / totalColumns * 100;
|
|
4443
4443
|
return Math.max(10, Math.min(100, Math.round(percentage)));
|
|
4444
4444
|
}
|
|
4445
|
+
var EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
4446
|
+
var EMAIL_REGEX_MESSAGE = "Invalid email format";
|
|
4447
|
+
function isEmailLikeField(field) {
|
|
4448
|
+
const label = (field.label || "").toLowerCase();
|
|
4449
|
+
const fieldName = (field.fieldName || field.name || "").toLowerCase();
|
|
4450
|
+
const placeholder = (field.placeholder || "").toLowerCase();
|
|
4451
|
+
return /email/.test(label) || /email/.test(fieldName) || /@/.test(placeholder) || /email/.test(placeholder);
|
|
4452
|
+
}
|
|
4445
4453
|
function normalizeFieldType(type) {
|
|
4446
4454
|
if (!type)
|
|
4447
4455
|
return "text";
|
|
@@ -4460,7 +4468,10 @@ function normalizeFieldType(type) {
|
|
|
4460
4468
|
function transformField(field) {
|
|
4461
4469
|
const fieldId = field.id || field.fieldId;
|
|
4462
4470
|
const fieldType = field.type || field.fieldType;
|
|
4463
|
-
|
|
4471
|
+
let normalizedType = normalizeFieldType(fieldType);
|
|
4472
|
+
if (normalizedType === "text" && isEmailLikeField(field)) {
|
|
4473
|
+
normalizedType = "email";
|
|
4474
|
+
}
|
|
4464
4475
|
const transformed = {
|
|
4465
4476
|
id: fieldId,
|
|
4466
4477
|
type: normalizedType,
|
|
@@ -4783,9 +4794,19 @@ function convertWidthToSpan(width, totalColumns = 12) {
|
|
|
4783
4794
|
return Math.max(1, Math.min(12, Math.round(widthNum / 100 * totalColumns)));
|
|
4784
4795
|
}
|
|
4785
4796
|
function fieldToPayload(field) {
|
|
4797
|
+
let outputType = field.type;
|
|
4798
|
+
let outputValidations = field.validations ? { ...field.validations } : void 0;
|
|
4799
|
+
if (field.type === "text" && isEmailLikeField(field)) {
|
|
4800
|
+
outputType = "email";
|
|
4801
|
+
outputValidations = field.validations ? { ...field.validations } : {};
|
|
4802
|
+
if (!outputValidations.pattern) {
|
|
4803
|
+
outputValidations.pattern = EMAIL_REGEX;
|
|
4804
|
+
outputValidations.customErrorMessages = { ...outputValidations.customErrorMessages, pattern: EMAIL_REGEX_MESSAGE };
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4786
4807
|
const payload = {
|
|
4787
4808
|
id: field.id,
|
|
4788
|
-
type:
|
|
4809
|
+
type: outputType,
|
|
4789
4810
|
label: field.label,
|
|
4790
4811
|
name: field.fieldName || field.id,
|
|
4791
4812
|
// Model key for binding (API / host app)
|
|
@@ -4810,17 +4831,18 @@ function fieldToPayload(field) {
|
|
|
4810
4831
|
span: 12
|
|
4811
4832
|
};
|
|
4812
4833
|
}
|
|
4813
|
-
|
|
4814
|
-
|
|
4834
|
+
const validationsToUse = outputValidations ?? field.validations;
|
|
4835
|
+
if (validationsToUse) {
|
|
4836
|
+
let validations = { ...validationsToUse };
|
|
4815
4837
|
if (validations.validationType === "age") {
|
|
4816
4838
|
validations = { ...validations, validationType: "custom" };
|
|
4817
4839
|
}
|
|
4818
4840
|
payload.validations = validations;
|
|
4819
|
-
if (
|
|
4841
|
+
if (validationsToUse.required) {
|
|
4820
4842
|
payload.required = true;
|
|
4821
4843
|
}
|
|
4822
4844
|
}
|
|
4823
|
-
const baseValidation =
|
|
4845
|
+
const baseValidation = validationsToUse ? validationsToValidationObject(validationsToUse) : convertValidationArrayToObject(field.validation);
|
|
4824
4846
|
payload.validation = baseValidation;
|
|
4825
4847
|
const pattern = baseValidation?.regex ?? field.validations?.pattern;
|
|
4826
4848
|
const patternMsg = baseValidation?.regexMessage ?? field.validations?.customErrorMessages?.pattern;
|