form-builder-pro 1.1.2 → 1.1.3

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.d.mts CHANGED
@@ -68,7 +68,11 @@ interface FormField {
68
68
  customOptionsEnabled?: boolean;
69
69
  multiselect?: boolean;
70
70
  multiSelect?: boolean;
71
- optionSource?: 'STATIC' | 'MASTER';
71
+ optionSource?: 'STATIC' | 'MASTER' | 'LOOKUP';
72
+ lookupSourceType?: 'MODULE' | 'MASTER_TYPE';
73
+ lookupSource?: string;
74
+ lookupValueField?: string;
75
+ lookupLabelField?: string;
72
76
  isd?: ISDConfig;
73
77
  }
74
78
  /**
@@ -226,6 +230,7 @@ interface FormBuilderOptions {
226
230
  value: string;
227
231
  }[];
228
232
  };
233
+ moduleList?: string[];
229
234
  onGroupSelectionChange?: (event: {
230
235
  fieldId: string;
231
236
  groupEnumName: string;
package/dist/index.d.ts CHANGED
@@ -68,7 +68,11 @@ interface FormField {
68
68
  customOptionsEnabled?: boolean;
69
69
  multiselect?: boolean;
70
70
  multiSelect?: boolean;
71
- optionSource?: 'STATIC' | 'MASTER';
71
+ optionSource?: 'STATIC' | 'MASTER' | 'LOOKUP';
72
+ lookupSourceType?: 'MODULE' | 'MASTER_TYPE';
73
+ lookupSource?: string;
74
+ lookupValueField?: string;
75
+ lookupLabelField?: string;
72
76
  isd?: ISDConfig;
73
77
  }
74
78
  /**
@@ -226,6 +230,7 @@ interface FormBuilderOptions {
226
230
  value: string;
227
231
  }[];
228
232
  };
233
+ moduleList?: string[];
229
234
  onGroupSelectionChange?: (event: {
230
235
  fieldId: string;
231
236
  groupEnumName: string;
package/dist/index.js CHANGED
@@ -4404,6 +4404,14 @@ function transformField(field) {
4404
4404
  }
4405
4405
  }
4406
4406
  }
4407
+ if (field.lookupSourceType !== void 0)
4408
+ transformed.lookupSourceType = field.lookupSourceType;
4409
+ if (field.lookupSource !== void 0)
4410
+ transformed.lookupSource = field.lookupSource;
4411
+ if (field.lookupValueField !== void 0)
4412
+ transformed.lookupValueField = field.lookupValueField;
4413
+ if (field.lookupLabelField !== void 0)
4414
+ transformed.lookupLabelField = field.lookupLabelField;
4407
4415
  if (field.placeholder !== void 0)
4408
4416
  transformed.placeholder = field.placeholder;
4409
4417
  if (field.description !== void 0)
@@ -4548,6 +4556,14 @@ function fieldToPayload(field) {
4548
4556
  payload.groupName = field.groupName;
4549
4557
  if (field.masterTypeName !== void 0)
4550
4558
  payload.masterTypeName = field.masterTypeName;
4559
+ if (field.lookupSourceType !== void 0)
4560
+ payload.lookupSourceType = field.lookupSourceType;
4561
+ if (field.lookupSource !== void 0)
4562
+ payload.lookupSource = field.lookupSource;
4563
+ if (field.lookupValueField !== void 0)
4564
+ payload.lookupValueField = field.lookupValueField;
4565
+ if (field.lookupLabelField !== void 0)
4566
+ payload.lookupLabelField = field.lookupLabelField;
4551
4567
  if (field.isd !== void 0)
4552
4568
  payload.isd = field.isd;
4553
4569
  if ((field.type === "select" || field.type === "radio" || field.type === "checkbox") && field.options) {
@@ -8552,8 +8568,28 @@ var FormBuilder = class {
8552
8568
  }
8553
8569
  });
8554
8570
  if (extractedSections.length > 0) {
8571
+ const sectionMap = /* @__PURE__ */ new Map();
8572
+ extractedSections.forEach((section) => {
8573
+ const existingSection = sectionMap.get(section.title);
8574
+ if (existingSection) {
8575
+ const fieldIds = new Set(existingSection.fields.map((f) => f.id));
8576
+ section.fields.forEach((field) => {
8577
+ if (!fieldIds.has(field.id)) {
8578
+ existingSection.fields.push(field);
8579
+ fieldIds.add(field.id);
8580
+ }
8581
+ });
8582
+ } else {
8583
+ sectionMap.set(section.title, {
8584
+ ...section,
8585
+ fields: [...section.fields]
8586
+ });
8587
+ }
8588
+ });
8589
+ const deduplicatedSections = Array.from(sectionMap.values());
8590
+ console.log(`[FormBuilder] Loaded ${options.formTemplates.length} form templates, extracted ${extractedSections.length} sections, deduplicated to ${deduplicatedSections.length} unique templates`);
8555
8591
  const existingTemplates = options.reusableSections || [];
8556
- formStore.getState().setTemplates([...existingTemplates, ...extractedSections]);
8592
+ formStore.getState().setTemplates([...existingTemplates, ...deduplicatedSections]);
8557
8593
  }
8558
8594
  }
8559
8595
  if (options.formJson) {
@@ -8635,8 +8671,28 @@ var FormBuilder = class {
8635
8671
  }
8636
8672
  });
8637
8673
  if (extractedSections.length > 0) {
8674
+ const sectionMap = /* @__PURE__ */ new Map();
8675
+ extractedSections.forEach((section) => {
8676
+ const existingSection = sectionMap.get(section.title);
8677
+ if (existingSection) {
8678
+ const fieldIds = new Set(existingSection.fields.map((f) => f.id));
8679
+ section.fields.forEach((field) => {
8680
+ if (!fieldIds.has(field.id)) {
8681
+ existingSection.fields.push(field);
8682
+ fieldIds.add(field.id);
8683
+ }
8684
+ });
8685
+ } else {
8686
+ sectionMap.set(section.title, {
8687
+ ...section,
8688
+ fields: [...section.fields]
8689
+ });
8690
+ }
8691
+ });
8692
+ const deduplicatedSections = Array.from(sectionMap.values());
8693
+ console.log(`[FormBuilder] loadFormTemplates: extracted ${extractedSections.length} sections, deduplicated to ${deduplicatedSections.length} unique templates`);
8638
8694
  const currentTemplates = formStore.getState().templates;
8639
- formStore.getState().setTemplates([...currentTemplates, ...extractedSections]);
8695
+ formStore.getState().setTemplates([...currentTemplates, ...deduplicatedSections]);
8640
8696
  this.render();
8641
8697
  }
8642
8698
  }
@@ -9258,6 +9314,10 @@ var FormBuilder = class {
9258
9314
  const updates = { optionSource: source };
9259
9315
  if (source === "MASTER" && !selectedField.masterTypeName && !selectedField.groupName) ; else if (source === "STATIC") {
9260
9316
  updates.customOptionsEnabled = true;
9317
+ } else if (source === "LOOKUP") {
9318
+ if (!selectedField.lookupSourceType) {
9319
+ updates.lookupSourceType = "MODULE";
9320
+ }
9261
9321
  }
9262
9322
  formStore.getState().updateField(selectedField.id, updates);
9263
9323
  this.render();
@@ -9265,8 +9325,131 @@ var FormBuilder = class {
9265
9325
  });
9266
9326
  optionSourceSelect.appendChild(createElement("option", { value: "STATIC", text: "STATIC (Custom Options)", selected: (selectedField.optionSource || "STATIC") === "STATIC" }));
9267
9327
  optionSourceSelect.appendChild(createElement("option", { value: "MASTER", text: "MASTER (From Master Types)", selected: selectedField.optionSource === "MASTER" }));
9328
+ if (selectedField.type === "select") {
9329
+ optionSourceSelect.appendChild(createElement("option", { value: "LOOKUP", text: "Lookup (Entity Fields)", selected: selectedField.optionSource === "LOOKUP" }));
9330
+ }
9268
9331
  optionSourceGroup.appendChild(optionSourceSelect);
9269
9332
  body.appendChild(optionSourceGroup);
9333
+ if (selectedField.type === "select" && selectedField.optionSource === "LOOKUP") {
9334
+ const lookupSourceTypeGroup = createElement("div", { className: "mb-4" });
9335
+ lookupSourceTypeGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Source Type" }));
9336
+ const lookupSourceTypeSelect = createElement("select", {
9337
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
9338
+ value: selectedField.lookupSourceType || "MODULE",
9339
+ onchange: (e) => {
9340
+ const lookupSourceType = e.target.value;
9341
+ const updates = { lookupSourceType };
9342
+ if (lookupSourceType !== selectedField.lookupSourceType) {
9343
+ updates.lookupSource = void 0;
9344
+ }
9345
+ formStore.getState().updateField(selectedField.id, updates);
9346
+ this.render();
9347
+ }
9348
+ });
9349
+ lookupSourceTypeSelect.appendChild(createElement("option", { value: "MODULE", text: "Module", selected: (selectedField.lookupSourceType || "MODULE") === "MODULE" }));
9350
+ lookupSourceTypeSelect.appendChild(createElement("option", { value: "MASTER_TYPE", text: "Master Type", selected: selectedField.lookupSourceType === "MASTER_TYPE" }));
9351
+ lookupSourceTypeGroup.appendChild(lookupSourceTypeSelect);
9352
+ body.appendChild(lookupSourceTypeGroup);
9353
+ if (selectedField.lookupSourceType === "MODULE") {
9354
+ const moduleList = this.options.moduleList || [];
9355
+ const lookupSourceGroup = createElement("div", { className: "mb-4" });
9356
+ lookupSourceGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Source" }));
9357
+ const lookupSourceSelect = createElement("select", {
9358
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
9359
+ value: selectedField.lookupSource || "",
9360
+ onchange: (e) => {
9361
+ const lookupSource = e.target.value;
9362
+ formStore.getState().updateField(selectedField.id, { lookupSource: lookupSource || void 0 });
9363
+ }
9364
+ });
9365
+ lookupSourceSelect.appendChild(createElement("option", { value: "", text: "Select Module", selected: !selectedField.lookupSource }));
9366
+ moduleList.forEach((module) => {
9367
+ lookupSourceSelect.appendChild(createElement("option", {
9368
+ value: module,
9369
+ text: module,
9370
+ selected: selectedField.lookupSource === module
9371
+ }));
9372
+ });
9373
+ lookupSourceGroup.appendChild(lookupSourceSelect);
9374
+ body.appendChild(lookupSourceGroup);
9375
+ } else if (selectedField.lookupSourceType === "MASTER_TYPE") {
9376
+ const masterTypes = formStore.getState().masterTypes;
9377
+ const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
9378
+ const lookupSourceGroup = createElement("div", { className: "mb-4" });
9379
+ lookupSourceGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Source" }));
9380
+ const lookupSourceSelect = createElement("select", {
9381
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
9382
+ value: selectedField.lookupSource || "",
9383
+ onchange: (e) => {
9384
+ const lookupSource = e.target.value;
9385
+ formStore.getState().updateField(selectedField.id, { lookupSource: lookupSource || void 0 });
9386
+ }
9387
+ });
9388
+ lookupSourceSelect.appendChild(createElement("option", { value: "", text: "Select Master Type", selected: !selectedField.lookupSource }));
9389
+ activeMasterTypes.forEach((mt) => {
9390
+ const optionValue = mt.enumName || mt.id || mt.name;
9391
+ lookupSourceSelect.appendChild(createElement("option", {
9392
+ value: optionValue,
9393
+ text: mt.displayName || mt.name,
9394
+ selected: selectedField.lookupSource === optionValue
9395
+ }));
9396
+ });
9397
+ lookupSourceGroup.appendChild(lookupSourceSelect);
9398
+ body.appendChild(lookupSourceGroup);
9399
+ }
9400
+ const lookupValueFieldGroup = createElement("div", { className: "mb-4" });
9401
+ lookupValueFieldGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Value Field" }));
9402
+ lookupValueFieldGroup.appendChild(createElement("input", {
9403
+ type: "text",
9404
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
9405
+ value: selectedField.lookupValueField || "",
9406
+ placeholder: "Enter value field name",
9407
+ oninput: (e) => {
9408
+ const lookupValueField = e.target.value;
9409
+ formStore.getState().updateField(selectedField.id, { lookupValueField: lookupValueField || void 0 });
9410
+ }
9411
+ }));
9412
+ body.appendChild(lookupValueFieldGroup);
9413
+ const lookupLabelFieldGroup = createElement("div", { className: "mb-4" });
9414
+ lookupLabelFieldGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Lookup Label Field" }));
9415
+ lookupLabelFieldGroup.appendChild(createElement("input", {
9416
+ type: "text",
9417
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
9418
+ value: selectedField.lookupLabelField || "",
9419
+ placeholder: "Enter label field name",
9420
+ oninput: (e) => {
9421
+ const lookupLabelField = e.target.value;
9422
+ formStore.getState().updateField(selectedField.id, { lookupLabelField: lookupLabelField || void 0 });
9423
+ }
9424
+ }));
9425
+ body.appendChild(lookupLabelFieldGroup);
9426
+ const visibilityGroup = createElement("div", { className: "flex items-center justify-between mb-4" });
9427
+ visibilityGroup.appendChild(createElement("label", { className: "text-sm text-gray-700 dark:text-gray-300", text: "Visibility" }));
9428
+ visibilityGroup.appendChild(createElement("input", {
9429
+ type: "checkbox",
9430
+ className: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",
9431
+ checked: selectedField.visible !== false,
9432
+ // Default to true if not set
9433
+ onchange: (e) => {
9434
+ const visible = e.target.checked;
9435
+ formStore.getState().updateField(selectedField.id, { visible });
9436
+ }
9437
+ }));
9438
+ body.appendChild(visibilityGroup);
9439
+ const enabledGroup2 = createElement("div", { className: "flex items-center justify-between mb-4" });
9440
+ enabledGroup2.appendChild(createElement("label", { className: "text-sm text-gray-700 dark:text-gray-300", text: "Enabled" }));
9441
+ enabledGroup2.appendChild(createElement("input", {
9442
+ type: "checkbox",
9443
+ className: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",
9444
+ checked: selectedField.enabled !== false,
9445
+ // Default to true if not set
9446
+ onchange: (e) => {
9447
+ const enabled = e.target.checked;
9448
+ formStore.getState().updateField(selectedField.id, { enabled });
9449
+ }
9450
+ }));
9451
+ body.appendChild(enabledGroup2);
9452
+ }
9270
9453
  }
9271
9454
  if (selectedField.type === "select") {
9272
9455
  const multiSelectGroup = createElement("div", { className: "flex items-center justify-between mb-4" });