form-builder-pro 1.4.2 → 1.4.4

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.mjs CHANGED
@@ -4081,6 +4081,7 @@ var LOOKUP_SOURCE_TYPE_OPTIONS = [
4081
4081
  { value: "SETTINGS", label: "Settings Entity" }
4082
4082
  ];
4083
4083
  var generateId = () => Math.random().toString(36).substring(2, 9);
4084
+ var generateFieldName = () => `field_${Date.now()}_${Math.random().toString(36).substring(2, 5)}`;
4084
4085
  var FIELD_TYPES = [
4085
4086
  { type: "text", label: "Text Input", icon: "Type" },
4086
4087
  { type: "textarea", label: "Text Area", icon: "DocumentText" },
@@ -4355,6 +4356,8 @@ var cloneField = (field) => {
4355
4356
  return {
4356
4357
  ...field,
4357
4358
  id: generateId(),
4359
+ fieldName: generateFieldName(),
4360
+ // Always generate a fresh unique name on clone
4358
4361
  // Ensure options are also cloned if present
4359
4362
  options: field.options ? field.options.map((opt) => ({ ...opt })) : void 0,
4360
4363
  validation: field.validation ? field.validation.map((v) => ({ ...v })) : void 0,
@@ -4782,6 +4785,13 @@ function transformField(field) {
4782
4785
  transformed.nameGeneratorSuffix = field.nameGeneratorSuffix;
4783
4786
  if (field.nameGeneratorIdPadding !== void 0)
4784
4787
  transformed.nameGeneratorIdPadding = field.nameGeneratorIdPadding;
4788
+ if (field.autoPopulateFields !== void 0 && field.autoPopulateFields !== null) {
4789
+ const apf = field.autoPopulateFields;
4790
+ transformed.autoPopulateFields = {
4791
+ enabled: typeof apf.enabled === "boolean" ? apf.enabled : false,
4792
+ fields: Array.isArray(apf.fields) ? apf.fields : []
4793
+ };
4794
+ }
4785
4795
  if (field.css !== void 0)
4786
4796
  transformed.css = field.css;
4787
4797
  if (field.optionsSource !== void 0)
@@ -5040,6 +5050,12 @@ function fieldToPayload(field, opts) {
5040
5050
  parentFieldName: field.lookupParentFieldName ?? null
5041
5051
  };
5042
5052
  }
5053
+ if (field.optionSource === "LOOKUP" && field.autoPopulateFields !== void 0 && field.autoPopulateFields !== null) {
5054
+ payload.autoPopulateFields = {
5055
+ enabled: field.autoPopulateFields.enabled,
5056
+ fields: Array.isArray(field.autoPopulateFields.fields) ? field.autoPopulateFields.fields : []
5057
+ };
5058
+ }
5043
5059
  if (field.isd !== void 0)
5044
5060
  payload.isd = field.isd;
5045
5061
  if (field.imageUrl !== void 0)
@@ -5739,6 +5755,7 @@ var formStore = createStore((set, get) => ({
5739
5755
  const baseField = {
5740
5756
  id: generateId(),
5741
5757
  type,
5758
+ fieldName: generateFieldName(),
5742
5759
  ...DEFAULT_FIELD_CONFIG[type]
5743
5760
  };
5744
5761
  let newField = { ...baseField };
@@ -12400,6 +12417,35 @@ var FormBuilder = class {
12400
12417
  }, [getIcon("X", 20)]));
12401
12418
  panel.appendChild(header);
12402
12419
  const body = createElement("div", { className: "flex-1 overflow-y-auto p-4 px-2 space-y-3", id: "config-panel-body" });
12420
+ const nameGroup = createElement("div");
12421
+ nameGroup.appendChild(createElement("label", { className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1", text: "Name" }));
12422
+ const currentFieldName = selectedField.fieldName || generateFieldName();
12423
+ if (!selectedField.fieldName) {
12424
+ formStore.getState().updateField(selectedField.id, { fieldName: currentFieldName });
12425
+ }
12426
+ const nameInput = createElement("input", {
12427
+ className: "w-full px-3 py-2 border border-gray-200 dark:border-gray-700 rounded-md bg-transparent font-mono text-xs",
12428
+ value: currentFieldName,
12429
+ "data-focus-id": `field-name-${selectedField.id}`,
12430
+ placeholder: "field_...",
12431
+ oninput: (e) => {
12432
+ const fieldId2 = selectedField.id;
12433
+ const value = e.target.value.trim();
12434
+ const key = `fieldname-${fieldId2}`;
12435
+ const existing = labelUpdateTimeouts.get(key);
12436
+ if (existing)
12437
+ clearTimeout(existing);
12438
+ const timeoutId = setTimeout(() => {
12439
+ labelUpdateTimeouts.delete(key);
12440
+ if (value) {
12441
+ formStore.getState().updateField(fieldId2, { fieldName: value });
12442
+ }
12443
+ }, LABEL_DEBOUNCE_MS);
12444
+ labelUpdateTimeouts.set(key, timeoutId);
12445
+ }
12446
+ });
12447
+ nameGroup.appendChild(nameInput);
12448
+ body.appendChild(nameGroup);
12403
12449
  const labelGroup = createElement("div");
12404
12450
  labelGroup.appendChild(createElement("label", { className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1", text: "Label" }));
12405
12451
  labelGroup.appendChild(createElement("input", {
@@ -13561,6 +13607,84 @@ var FormBuilder = class {
13561
13607
  });
13562
13608
  parentFieldGroup.appendChild(parentFieldSelect);
13563
13609
  body.appendChild(parentFieldGroup);
13610
+ const autoPopHeader = createElement("h3", {
13611
+ className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6",
13612
+ text: "Auto Populate Fields"
13613
+ });
13614
+ body.appendChild(autoPopHeader);
13615
+ const autoPopEnabled = selectedField.autoPopulateFields?.enabled === true;
13616
+ body.appendChild(this.createCheckboxField(
13617
+ "Enable automation for selected records",
13618
+ autoPopEnabled,
13619
+ (checked) => {
13620
+ const current = formStore.getState().schema.sections.flatMap((s) => s.fields).find((f) => f.id === selectedField.id);
13621
+ formStore.getState().updateField(selectedField.id, {
13622
+ autoPopulateFields: {
13623
+ enabled: checked,
13624
+ fields: current?.autoPopulateFields?.fields ?? []
13625
+ }
13626
+ });
13627
+ this.render();
13628
+ },
13629
+ `auto-populate-enabled-${selectedField.id}`
13630
+ ));
13631
+ {
13632
+ const autoPopFieldsGroup = createElement("div", { className: "mb-4 mt-2" });
13633
+ autoPopFieldsGroup.appendChild(createElement("label", {
13634
+ className: "block text-sm font-normal text-gray-700 dark:text-gray-300 mb-1",
13635
+ text: "Fields to auto-populate"
13636
+ }));
13637
+ const lookupFieldOptionsMapForAP = formStore.getState().lookupFieldOptionsMap;
13638
+ const availableAutoPopFields = selectedField.lookupSource ? lookupFieldOptionsMapForAP[selectedField.lookupSource] || [] : [];
13639
+ const selectedAutoPopFields = selectedField.autoPopulateFields?.fields ?? [];
13640
+ const isAutoPopDisabled = !autoPopEnabled || !selectedField.lookupSource;
13641
+ if (availableAutoPopFields.length === 0) {
13642
+ const emptyNote = createElement("p", {
13643
+ className: "text-xs text-gray-400 dark:text-gray-500 mt-1",
13644
+ text: selectedField.lookupSource ? "No fields available for this lookup source." : "Select a Lookup Source first."
13645
+ });
13646
+ autoPopFieldsGroup.appendChild(emptyNote);
13647
+ } else {
13648
+ const fieldList = createElement("div", {
13649
+ className: `border border-gray-200 dark:border-gray-700 rounded-md divide-y divide-gray-100 dark:divide-gray-700 overflow-y-auto max-h-40 ${isAutoPopDisabled ? "opacity-50 pointer-events-none" : ""}`
13650
+ });
13651
+ availableAutoPopFields.forEach((fieldKey) => {
13652
+ const isChecked = selectedAutoPopFields.includes(fieldKey);
13653
+ const row = createElement("label", {
13654
+ className: "flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 text-sm text-gray-700 dark:text-gray-300"
13655
+ });
13656
+ const cb = createElement("input", {
13657
+ type: "checkbox",
13658
+ className: "w-4 h-4 accent-blue-600",
13659
+ checked: isChecked,
13660
+ disabled: isAutoPopDisabled,
13661
+ onchange: (e) => {
13662
+ const target = e.target;
13663
+ const latestField = formStore.getState().schema.sections.flatMap((s) => s.fields).find((f) => f.id === selectedField.id);
13664
+ const latestSelected = latestField?.autoPopulateFields?.fields ?? [];
13665
+ const updatedFields = target.checked ? [.../* @__PURE__ */ new Set([...latestSelected, fieldKey])] : latestSelected.filter((k) => k !== fieldKey);
13666
+ formStore.getState().updateField(selectedField.id, {
13667
+ autoPopulateFields: {
13668
+ enabled: latestField?.autoPopulateFields?.enabled ?? true,
13669
+ fields: updatedFields
13670
+ }
13671
+ });
13672
+ }
13673
+ });
13674
+ row.appendChild(cb);
13675
+ row.appendChild(createElement("span", { text: fieldKey }));
13676
+ fieldList.appendChild(row);
13677
+ });
13678
+ autoPopFieldsGroup.appendChild(fieldList);
13679
+ if (selectedAutoPopFields.length > 0) {
13680
+ autoPopFieldsGroup.appendChild(createElement("p", {
13681
+ className: "text-xs text-gray-400 dark:text-gray-500 mt-1",
13682
+ text: `${selectedAutoPopFields.length} field(s) selected`
13683
+ }));
13684
+ }
13685
+ }
13686
+ body.appendChild(autoPopFieldsGroup);
13687
+ }
13564
13688
  body.appendChild(this.createCheckboxField(
13565
13689
  "Visibility",
13566
13690
  selectedField.visible !== false,