form-builder-pro 1.2.5 → 1.2.7
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 +43 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4615,6 +4615,8 @@ function fieldToPayload(field) {
|
|
|
4615
4615
|
payload.css = field.css;
|
|
4616
4616
|
if (field.optionSource !== void 0)
|
|
4617
4617
|
payload.optionSource = field.optionSource;
|
|
4618
|
+
if (field.customOptionsEnabled !== void 0)
|
|
4619
|
+
payload.customOptionsEnabled = field.customOptionsEnabled;
|
|
4618
4620
|
if (field.groupName !== void 0)
|
|
4619
4621
|
payload.groupName = field.groupName;
|
|
4620
4622
|
if (field.masterTypeName !== void 0)
|
|
@@ -4629,8 +4631,8 @@ function fieldToPayload(field) {
|
|
|
4629
4631
|
payload.lookupLabelField = field.lookupLabelField;
|
|
4630
4632
|
if (field.isd !== void 0)
|
|
4631
4633
|
payload.isd = field.isd;
|
|
4632
|
-
if ((field.type === "select" || field.type === "radio" || field.type === "checkbox") && field.options) {
|
|
4633
|
-
payload.options = field.options;
|
|
4634
|
+
if ((field.type === "select" || field.type === "radio" || field.type === "checkbox") && field.options && Array.isArray(field.options)) {
|
|
4635
|
+
payload.options = field.options.map((opt) => ({ label: opt.label, value: opt.value }));
|
|
4634
4636
|
}
|
|
4635
4637
|
return payload;
|
|
4636
4638
|
}
|
|
@@ -8620,6 +8622,8 @@ var SectionList = class {
|
|
|
8620
8622
|
|
|
8621
8623
|
// src/builder/FormBuilder.ts
|
|
8622
8624
|
var advancedCssPanelState = /* @__PURE__ */ new Map();
|
|
8625
|
+
var LABEL_DEBOUNCE_MS = 300;
|
|
8626
|
+
var labelUpdateTimeouts = /* @__PURE__ */ new Map();
|
|
8623
8627
|
var FormBuilder = class {
|
|
8624
8628
|
// For requestAnimationFrame debouncing
|
|
8625
8629
|
constructor(container, options = {}) {
|
|
@@ -8798,7 +8802,7 @@ var FormBuilder = class {
|
|
|
8798
8802
|
fields: s.fields.map((f) => ({
|
|
8799
8803
|
id: f.id,
|
|
8800
8804
|
type: f.type,
|
|
8801
|
-
|
|
8805
|
+
label: f.label,
|
|
8802
8806
|
layout: f.layout,
|
|
8803
8807
|
width: f.width,
|
|
8804
8808
|
css: f.css
|
|
@@ -8823,6 +8827,8 @@ var FormBuilder = class {
|
|
|
8823
8827
|
cancelAnimationFrame(this.pendingRenderId);
|
|
8824
8828
|
this.pendingRenderId = null;
|
|
8825
8829
|
}
|
|
8830
|
+
labelUpdateTimeouts.forEach((id) => clearTimeout(id));
|
|
8831
|
+
labelUpdateTimeouts.clear();
|
|
8826
8832
|
this.unsubscribe();
|
|
8827
8833
|
this.container.innerHTML = "";
|
|
8828
8834
|
}
|
|
@@ -9254,7 +9260,16 @@ var FormBuilder = class {
|
|
|
9254
9260
|
value: selectedField.label,
|
|
9255
9261
|
"data-focus-id": `field-label-${selectedField.id}`,
|
|
9256
9262
|
oninput: (e) => {
|
|
9257
|
-
|
|
9263
|
+
const fieldId2 = selectedField.id;
|
|
9264
|
+
const value = e.target.value;
|
|
9265
|
+
const existing = labelUpdateTimeouts.get(fieldId2);
|
|
9266
|
+
if (existing)
|
|
9267
|
+
clearTimeout(existing);
|
|
9268
|
+
const timeoutId = setTimeout(() => {
|
|
9269
|
+
labelUpdateTimeouts.delete(fieldId2);
|
|
9270
|
+
formStore.getState().updateField(fieldId2, { label: value });
|
|
9271
|
+
}, LABEL_DEBOUNCE_MS);
|
|
9272
|
+
labelUpdateTimeouts.set(fieldId2, timeoutId);
|
|
9258
9273
|
}
|
|
9259
9274
|
}));
|
|
9260
9275
|
body.appendChild(labelGroup);
|
|
@@ -9687,6 +9702,11 @@ var FormBuilder = class {
|
|
|
9687
9702
|
const shouldShowOptions = selectedField.type === "select" ? selectedField.customOptionsEnabled && (selectedField.optionSource === "STATIC" || !selectedField.optionSource) : true;
|
|
9688
9703
|
if (shouldShowOptions) {
|
|
9689
9704
|
const options = selectedField.options || [];
|
|
9705
|
+
const fieldId2 = selectedField.id;
|
|
9706
|
+
const getCurrentOptions = () => {
|
|
9707
|
+
const field = formStore.getState().schema.sections.flatMap((s) => s.fields).find((f) => f.id === fieldId2);
|
|
9708
|
+
return field?.options || [];
|
|
9709
|
+
};
|
|
9690
9710
|
const optionsList = createElement("div", { className: "space-y-2 mb-3" });
|
|
9691
9711
|
options.forEach((opt, index2) => {
|
|
9692
9712
|
const optionRow = createElement("div", { className: "flex gap-2 items-center" });
|
|
@@ -9697,9 +9717,12 @@ var FormBuilder = class {
|
|
|
9697
9717
|
placeholder: "Option label",
|
|
9698
9718
|
"data-focus-id": `field-option-label-${selectedField.id}-${index2}`,
|
|
9699
9719
|
oninput: (e) => {
|
|
9700
|
-
const
|
|
9701
|
-
newOptions
|
|
9702
|
-
|
|
9720
|
+
const currentOptions = getCurrentOptions();
|
|
9721
|
+
const newOptions = [...currentOptions];
|
|
9722
|
+
if (newOptions[index2]) {
|
|
9723
|
+
newOptions[index2] = { ...newOptions[index2], label: e.target.value };
|
|
9724
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9725
|
+
}
|
|
9703
9726
|
}
|
|
9704
9727
|
});
|
|
9705
9728
|
const valueInput = createElement("input", {
|
|
@@ -9709,17 +9732,21 @@ var FormBuilder = class {
|
|
|
9709
9732
|
placeholder: "Option value",
|
|
9710
9733
|
"data-focus-id": `field-option-value-${selectedField.id}-${index2}`,
|
|
9711
9734
|
oninput: (e) => {
|
|
9712
|
-
const
|
|
9713
|
-
newOptions
|
|
9714
|
-
|
|
9735
|
+
const currentOptions = getCurrentOptions();
|
|
9736
|
+
const newOptions = [...currentOptions];
|
|
9737
|
+
if (newOptions[index2]) {
|
|
9738
|
+
newOptions[index2] = { ...newOptions[index2], value: e.target.value };
|
|
9739
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9740
|
+
}
|
|
9715
9741
|
}
|
|
9716
9742
|
});
|
|
9717
9743
|
const deleteBtn = createElement("button", {
|
|
9718
9744
|
className: "p-1.5 text-red-600 hover:bg-red-50 rounded transition-colors",
|
|
9719
9745
|
title: "Delete option",
|
|
9720
9746
|
onclick: () => {
|
|
9721
|
-
const
|
|
9722
|
-
|
|
9747
|
+
const currentOptions = getCurrentOptions();
|
|
9748
|
+
const newOptions = currentOptions.filter((_, i) => i !== index2);
|
|
9749
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9723
9750
|
}
|
|
9724
9751
|
}, [getIcon("Trash2", 14)]);
|
|
9725
9752
|
optionRow.appendChild(labelInput);
|
|
@@ -9733,8 +9760,10 @@ var FormBuilder = class {
|
|
|
9733
9760
|
className: "w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-700 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",
|
|
9734
9761
|
text: "Add Option",
|
|
9735
9762
|
onclick: () => {
|
|
9736
|
-
const
|
|
9737
|
-
|
|
9763
|
+
const currentOptions = getCurrentOptions();
|
|
9764
|
+
const newOption = { label: `Option ${currentOptions.length + 1}`, value: `opt${currentOptions.length + 1}` };
|
|
9765
|
+
const newOptions = [...currentOptions, newOption];
|
|
9766
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9738
9767
|
this.render();
|
|
9739
9768
|
}
|
|
9740
9769
|
});
|