form-builder-pro 1.1.4 → 1.1.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.css +3 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +84 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.css
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -305,6 +305,7 @@ declare function convertValidationObjectToArray(validationObj: ValidationObject
|
|
|
305
305
|
* - Removes empty options arrays from non-select/radio fields
|
|
306
306
|
* - Preserves masterTypeName for select fields with groupName
|
|
307
307
|
* - Transforms new payload format (layout.span, validation object) to internal format
|
|
308
|
+
* - Handles forms with direct fields array (converts to sections)
|
|
308
309
|
* @param schema
|
|
309
310
|
* @returns Cleaned schema
|
|
310
311
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -305,6 +305,7 @@ declare function convertValidationObjectToArray(validationObj: ValidationObject
|
|
|
305
305
|
* - Removes empty options arrays from non-select/radio fields
|
|
306
306
|
* - Preserves masterTypeName for select fields with groupName
|
|
307
307
|
* - Transforms new payload format (layout.span, validation object) to internal format
|
|
308
|
+
* - Handles forms with direct fields array (converts to sections)
|
|
308
309
|
* @param schema
|
|
309
310
|
* @returns Cleaned schema
|
|
310
311
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4318,10 +4318,21 @@ function convertSpanToWidth(span, totalColumns = 12) {
|
|
|
4318
4318
|
const percentage = span / totalColumns * 100;
|
|
4319
4319
|
return Math.max(10, Math.min(100, Math.round(percentage)));
|
|
4320
4320
|
}
|
|
4321
|
+
function normalizeFieldType(type) {
|
|
4322
|
+
if (!type)
|
|
4323
|
+
return "text";
|
|
4324
|
+
const normalized = String(type).toLowerCase();
|
|
4325
|
+
if (normalized === "decimal")
|
|
4326
|
+
return "number";
|
|
4327
|
+
return normalized;
|
|
4328
|
+
}
|
|
4321
4329
|
function transformField(field) {
|
|
4330
|
+
const fieldId = field.id || field.fieldId;
|
|
4331
|
+
const fieldType = field.type || field.fieldType;
|
|
4332
|
+
const normalizedType = normalizeFieldType(fieldType);
|
|
4322
4333
|
const transformed = {
|
|
4323
|
-
id:
|
|
4324
|
-
type:
|
|
4334
|
+
id: fieldId,
|
|
4335
|
+
type: normalizedType,
|
|
4325
4336
|
label: field.label
|
|
4326
4337
|
};
|
|
4327
4338
|
if (field.layout?.span !== void 0) {
|
|
@@ -4331,6 +4342,19 @@ function transformField(field) {
|
|
|
4331
4342
|
span: field.layout.span
|
|
4332
4343
|
};
|
|
4333
4344
|
transformed.width = convertSpanToWidth(field.layout.span, field.layout.columns || 12);
|
|
4345
|
+
} else if (field.position) {
|
|
4346
|
+
const positionWidth = field.position.width;
|
|
4347
|
+
const span = positionWidth !== void 0 ? Math.max(1, Math.min(12, positionWidth)) : 12;
|
|
4348
|
+
transformed.layout = {
|
|
4349
|
+
row: field.position.row ?? 0,
|
|
4350
|
+
column: field.position.column ?? 0,
|
|
4351
|
+
span
|
|
4352
|
+
};
|
|
4353
|
+
transformed.width = convertSpanToWidth(span, 12);
|
|
4354
|
+
transformed.position = field.position;
|
|
4355
|
+
if (field.position.order !== void 0) {
|
|
4356
|
+
transformed.order = field.position.order;
|
|
4357
|
+
}
|
|
4334
4358
|
} else if (field.width !== void 0) {
|
|
4335
4359
|
const widthNum = parseWidth(field.width);
|
|
4336
4360
|
const span = Math.max(1, Math.min(12, Math.round(widthNum / 100 * 12)));
|
|
@@ -4348,7 +4372,9 @@ function transformField(field) {
|
|
|
4348
4372
|
};
|
|
4349
4373
|
transformed.width = 100;
|
|
4350
4374
|
}
|
|
4351
|
-
transformed.order
|
|
4375
|
+
if (transformed.order === void 0) {
|
|
4376
|
+
transformed.order = field.order !== void 0 ? field.order : 0;
|
|
4377
|
+
}
|
|
4352
4378
|
if (field.validation) {
|
|
4353
4379
|
if (Array.isArray(field.validation)) {
|
|
4354
4380
|
const validationObj = {};
|
|
@@ -4382,7 +4408,7 @@ function transformField(field) {
|
|
|
4382
4408
|
transformed.required = field.required;
|
|
4383
4409
|
transformed.validation = { required: field.required };
|
|
4384
4410
|
}
|
|
4385
|
-
if (
|
|
4411
|
+
if (normalizedType === "select") {
|
|
4386
4412
|
if (field.multiSelect !== void 0) {
|
|
4387
4413
|
transformed.multiSelect = field.multiSelect;
|
|
4388
4414
|
transformed.multiselect = void 0;
|
|
@@ -4393,9 +4419,26 @@ function transformField(field) {
|
|
|
4393
4419
|
transformed.multiSelect = false;
|
|
4394
4420
|
}
|
|
4395
4421
|
}
|
|
4396
|
-
|
|
4422
|
+
let lookupSourceType;
|
|
4423
|
+
let lookupSource;
|
|
4424
|
+
let lookupValueField;
|
|
4425
|
+
let lookupLabelField;
|
|
4426
|
+
if (field.lookup) {
|
|
4427
|
+
lookupSourceType = field.lookup.sourceType;
|
|
4428
|
+
lookupSource = field.lookup.sourceKey || field.lookup.source;
|
|
4429
|
+
lookupValueField = field.lookup.valueField;
|
|
4430
|
+
lookupLabelField = field.lookup.labelField;
|
|
4431
|
+
} else {
|
|
4432
|
+
lookupSourceType = field.lookupSourceType;
|
|
4433
|
+
lookupSource = field.lookupSource;
|
|
4434
|
+
lookupValueField = field.lookupValueField;
|
|
4435
|
+
lookupLabelField = field.lookupLabelField;
|
|
4436
|
+
}
|
|
4437
|
+
if (["select", "radio", "checkbox"].includes(normalizedType)) {
|
|
4397
4438
|
if (field.optionSource) {
|
|
4398
4439
|
transformed.optionSource = field.optionSource;
|
|
4440
|
+
} else if (lookupSourceType || lookupSource) {
|
|
4441
|
+
transformed.optionSource = "LOOKUP";
|
|
4399
4442
|
} else {
|
|
4400
4443
|
if (field.masterTypeName || field.groupName) {
|
|
4401
4444
|
transformed.optionSource = "MASTER";
|
|
@@ -4404,14 +4447,14 @@ function transformField(field) {
|
|
|
4404
4447
|
}
|
|
4405
4448
|
}
|
|
4406
4449
|
}
|
|
4407
|
-
if (
|
|
4408
|
-
transformed.lookupSourceType =
|
|
4409
|
-
if (
|
|
4410
|
-
transformed.lookupSource =
|
|
4411
|
-
if (
|
|
4412
|
-
transformed.lookupValueField =
|
|
4413
|
-
if (
|
|
4414
|
-
transformed.lookupLabelField =
|
|
4450
|
+
if (lookupSourceType !== void 0)
|
|
4451
|
+
transformed.lookupSourceType = lookupSourceType;
|
|
4452
|
+
if (lookupSource !== void 0)
|
|
4453
|
+
transformed.lookupSource = lookupSource;
|
|
4454
|
+
if (lookupValueField !== void 0)
|
|
4455
|
+
transformed.lookupValueField = lookupValueField;
|
|
4456
|
+
if (lookupLabelField !== void 0)
|
|
4457
|
+
transformed.lookupLabelField = lookupLabelField;
|
|
4415
4458
|
if (field.placeholder !== void 0)
|
|
4416
4459
|
transformed.placeholder = field.placeholder;
|
|
4417
4460
|
if (field.description !== void 0)
|
|
@@ -4436,30 +4479,50 @@ function transformField(field) {
|
|
|
4436
4479
|
transformed.groupName = field.groupName;
|
|
4437
4480
|
if (field.masterTypeName !== void 0)
|
|
4438
4481
|
transformed.masterTypeName = field.masterTypeName;
|
|
4439
|
-
if ((
|
|
4482
|
+
if ((normalizedType === "select" || normalizedType === "radio" || normalizedType === "checkbox") && field.options) {
|
|
4440
4483
|
transformed.options = field.options;
|
|
4441
4484
|
}
|
|
4442
4485
|
return transformed;
|
|
4443
4486
|
}
|
|
4444
4487
|
var cleanFormSchema = (schema) => {
|
|
4445
4488
|
const cleanField = transformField;
|
|
4489
|
+
let sections = [];
|
|
4490
|
+
if (schema.fields && Array.isArray(schema.fields) && schema.fields.length > 0) {
|
|
4491
|
+
sections = [{
|
|
4492
|
+
id: schema.id ? `section-${schema.id}` : "section-1",
|
|
4493
|
+
title: schema.formName || schema.title || "Form Fields",
|
|
4494
|
+
fields: schema.fields,
|
|
4495
|
+
order: 0,
|
|
4496
|
+
isExpanded: true
|
|
4497
|
+
}];
|
|
4498
|
+
} else if (schema.sections && Array.isArray(schema.sections)) {
|
|
4499
|
+
sections = schema.sections;
|
|
4500
|
+
} else if (schema.groups && Array.isArray(schema.groups)) {
|
|
4501
|
+
sections = schema.groups.map((group, index2) => ({
|
|
4502
|
+
id: group.id || `section-${index2}`,
|
|
4503
|
+
title: group.title || group.name || `Section ${index2 + 1}`,
|
|
4504
|
+
fields: group.fields || [],
|
|
4505
|
+
order: group.order !== void 0 ? group.order : index2,
|
|
4506
|
+
isExpanded: group.isExpanded !== void 0 ? group.isExpanded : true
|
|
4507
|
+
}));
|
|
4508
|
+
}
|
|
4446
4509
|
return {
|
|
4447
4510
|
id: schema.id,
|
|
4448
|
-
title: schema.title,
|
|
4449
|
-
formName: schema.formName,
|
|
4511
|
+
title: schema.title || schema.formName || "Form",
|
|
4512
|
+
formName: schema.formName || schema.formId || schema.id,
|
|
4450
4513
|
layout: schema.layout || { type: "grid", columns: 12, gap: "16px" },
|
|
4451
4514
|
// Preserve form-level layout or set default
|
|
4452
|
-
sections:
|
|
4453
|
-
id: section.id
|
|
4454
|
-
title: section.title
|
|
4455
|
-
fields: section.fields.map((field, fieldIndex) => {
|
|
4515
|
+
sections: sections.map((section, sectionIndex) => ({
|
|
4516
|
+
id: section.id || `section-${sectionIndex}`,
|
|
4517
|
+
title: section.title || `Section ${sectionIndex + 1}`,
|
|
4518
|
+
fields: (section.fields || []).map((field, fieldIndex) => {
|
|
4456
4519
|
const cleaned = cleanField(field);
|
|
4457
4520
|
if (cleaned.order === void 0) {
|
|
4458
4521
|
cleaned.order = fieldIndex;
|
|
4459
4522
|
}
|
|
4460
4523
|
return cleaned;
|
|
4461
4524
|
}),
|
|
4462
|
-
isExpanded: section.isExpanded,
|
|
4525
|
+
isExpanded: section.isExpanded !== void 0 ? section.isExpanded : true,
|
|
4463
4526
|
columns: section.columns,
|
|
4464
4527
|
// Legacy - prefer layout.columns
|
|
4465
4528
|
order: section.order !== void 0 ? section.order : sectionIndex,
|