form-builder-pro 1.0.14 → 1.0.15
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 +94 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7719,102 +7719,105 @@ var FormBuilder = class {
|
|
|
7719
7719
|
wrapper.appendChild(this.renderToolbar(state));
|
|
7720
7720
|
const main = createElement("div", { className: "flex flex-col md:flex-row flex-1 overflow-hidden" });
|
|
7721
7721
|
if (state.isPreviewMode) {
|
|
7722
|
-
const masterTypes = state.masterTypes;
|
|
7722
|
+
const masterTypes = state.masterTypes || [];
|
|
7723
7723
|
const dropdownOptionsMap = state.dropdownOptionsMap;
|
|
7724
|
-
if (
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
if (typeof item === "string") {
|
|
7731
|
-
return { label: item, value: item };
|
|
7732
|
-
}
|
|
7733
|
-
if (typeof item === "object" && item !== null) {
|
|
7734
|
-
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
7735
|
-
const value = item.value || item.id || item.name || String(index2);
|
|
7736
|
-
return { label, value };
|
|
7724
|
+
if (state.schema.sections) {
|
|
7725
|
+
let previewSchema = state.schema;
|
|
7726
|
+
if (masterTypes && masterTypes.length > 0) {
|
|
7727
|
+
const convertIndexesToOptions = (indexes) => {
|
|
7728
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
7729
|
+
return [];
|
|
7737
7730
|
}
|
|
7738
|
-
return
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7731
|
+
return indexes.map((item, index2) => {
|
|
7732
|
+
if (typeof item === "string") {
|
|
7733
|
+
return { label: item, value: item };
|
|
7734
|
+
}
|
|
7735
|
+
if (typeof item === "object" && item !== null) {
|
|
7736
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
7737
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
7738
|
+
return { label, value };
|
|
7739
|
+
}
|
|
7740
|
+
return { label: String(item), value: String(item) };
|
|
7741
|
+
});
|
|
7742
|
+
};
|
|
7743
|
+
const areDefaultOptions = (options) => {
|
|
7744
|
+
if (!options || options.length === 0)
|
|
7745
|
+
return true;
|
|
7746
|
+
return options.every(
|
|
7747
|
+
(opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
|
|
7748
|
+
);
|
|
7749
|
+
};
|
|
7750
|
+
const fieldsNeedingApiCall = [];
|
|
7751
|
+
previewSchema = {
|
|
7752
|
+
...state.schema,
|
|
7753
|
+
sections: state.schema.sections.map((section) => ({
|
|
7754
|
+
...section,
|
|
7755
|
+
fields: section.fields.map((field) => {
|
|
7756
|
+
if (field.type === "select") {
|
|
7757
|
+
let masterType;
|
|
7758
|
+
if (field.masterTypeName) {
|
|
7759
|
+
masterType = masterTypes.find(
|
|
7760
|
+
(mt) => mt.active === true && mt.enumName === field.masterTypeName
|
|
7761
|
+
);
|
|
7762
|
+
if (masterType && masterType.enumName) {
|
|
7763
|
+
const hasOptionsInMap = dropdownOptionsMap && dropdownOptionsMap[masterType.enumName] && dropdownOptionsMap[masterType.enumName].length > 0;
|
|
7764
|
+
const hasOptionsInIndexes = masterType.indexes && masterType.indexes.length > 0;
|
|
7765
|
+
const alreadyRequested = this.requestedMasterTypesCache.has(masterType.enumName);
|
|
7766
|
+
if (!hasOptionsInMap && !hasOptionsInIndexes && !alreadyRequested) {
|
|
7767
|
+
this.requestedMasterTypesCache.add(masterType.enumName);
|
|
7768
|
+
fieldsNeedingApiCall.push({
|
|
7769
|
+
fieldId: field.id,
|
|
7770
|
+
groupEnumName: masterType.enumName
|
|
7771
|
+
});
|
|
7772
|
+
}
|
|
7770
7773
|
}
|
|
7774
|
+
} else if (field.groupName) {
|
|
7775
|
+
masterType = masterTypes.find(
|
|
7776
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
7777
|
+
);
|
|
7771
7778
|
}
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
(
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
}
|
|
7784
|
-
if (options.length > 0) {
|
|
7785
|
-
if (field.masterTypeName || !field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
7786
|
-
return { ...field, options };
|
|
7779
|
+
if (masterType) {
|
|
7780
|
+
let options = [];
|
|
7781
|
+
if (masterType.enumName && dropdownOptionsMap && dropdownOptionsMap[masterType.enumName]) {
|
|
7782
|
+
options = dropdownOptionsMap[masterType.enumName];
|
|
7783
|
+
} else if (masterType.indexes && masterType.indexes.length > 0) {
|
|
7784
|
+
options = convertIndexesToOptions(masterType.indexes);
|
|
7785
|
+
}
|
|
7786
|
+
if (options.length > 0) {
|
|
7787
|
+
if (field.masterTypeName || !field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
7788
|
+
return { ...field, options };
|
|
7789
|
+
}
|
|
7787
7790
|
}
|
|
7788
7791
|
}
|
|
7789
7792
|
}
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
})
|
|
7793
|
-
}
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
this.isTriggeringApiCalls = true;
|
|
7797
|
-
setTimeout(() => {
|
|
7798
|
-
const uniqueApiCalls = /* @__PURE__ */ new Map();
|
|
7799
|
-
fieldsNeedingApiCall.forEach(({ fieldId, groupEnumName }) => {
|
|
7800
|
-
if (!uniqueApiCalls.has(groupEnumName)) {
|
|
7801
|
-
uniqueApiCalls.set(groupEnumName, []);
|
|
7802
|
-
}
|
|
7803
|
-
uniqueApiCalls.get(groupEnumName).push(fieldId);
|
|
7804
|
-
});
|
|
7805
|
-
uniqueApiCalls.forEach((fieldIds, groupEnumName) => {
|
|
7806
|
-
if (process.env.NODE_ENV === "development") {
|
|
7807
|
-
console.log(`[FormBuilder] Preview: Triggering API call for masterTypeName "${groupEnumName}" (affects ${fieldIds.length} field(s))`);
|
|
7808
|
-
}
|
|
7809
|
-
this.options.onGroupSelectionChange({
|
|
7810
|
-
fieldId: fieldIds[0],
|
|
7811
|
-
groupEnumName
|
|
7812
|
-
});
|
|
7813
|
-
});
|
|
7793
|
+
return field;
|
|
7794
|
+
})
|
|
7795
|
+
}))
|
|
7796
|
+
};
|
|
7797
|
+
if (fieldsNeedingApiCall.length > 0 && this.options.onGroupSelectionChange && !this.isTriggeringApiCalls) {
|
|
7798
|
+
this.isTriggeringApiCalls = true;
|
|
7814
7799
|
setTimeout(() => {
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7800
|
+
const uniqueApiCalls = /* @__PURE__ */ new Map();
|
|
7801
|
+
fieldsNeedingApiCall.forEach(({ fieldId, groupEnumName }) => {
|
|
7802
|
+
if (!uniqueApiCalls.has(groupEnumName)) {
|
|
7803
|
+
uniqueApiCalls.set(groupEnumName, []);
|
|
7804
|
+
}
|
|
7805
|
+
uniqueApiCalls.get(groupEnumName).push(fieldId);
|
|
7806
|
+
});
|
|
7807
|
+
uniqueApiCalls.forEach((fieldIds, groupEnumName) => {
|
|
7808
|
+
if (process.env.NODE_ENV === "development") {
|
|
7809
|
+
console.log(`[FormBuilder] Preview: Triggering API call for masterTypeName "${groupEnumName}" (affects ${fieldIds.length} field(s))`);
|
|
7810
|
+
}
|
|
7811
|
+
this.options.onGroupSelectionChange({
|
|
7812
|
+
fieldId: fieldIds[0],
|
|
7813
|
+
groupEnumName
|
|
7814
|
+
});
|
|
7815
|
+
});
|
|
7816
|
+
setTimeout(() => {
|
|
7817
|
+
this.isTriggeringApiCalls = false;
|
|
7818
|
+
}, 100);
|
|
7819
|
+
}, 0);
|
|
7820
|
+
}
|
|
7818
7821
|
}
|
|
7819
7822
|
const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
|
|
7820
7823
|
const inner = createElement("div", { className: "w-full max-w-3xl" });
|
|
@@ -7839,21 +7842,12 @@ var FormBuilder = class {
|
|
|
7839
7842
|
} else {
|
|
7840
7843
|
const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
|
|
7841
7844
|
const inner = createElement("div", { className: "w-full max-w-3xl" });
|
|
7842
|
-
|
|
7843
|
-
if (!this.previewRenderer || structureChanged) {
|
|
7844
|
-
if (this.previewRenderer) {
|
|
7845
|
-
inner.innerHTML = "";
|
|
7846
|
-
}
|
|
7845
|
+
if (!this.previewRenderer) {
|
|
7847
7846
|
this.previewRenderer = new FormRenderer(inner, state.schema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
|
|
7848
7847
|
this.lastPreviewSchema = state.schema;
|
|
7849
7848
|
} else {
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
if (optionsChanged && this.previewRenderer) {
|
|
7853
|
-
this.previewRenderer.setSchema(state.schema);
|
|
7854
|
-
this.lastPreviewSchema = state.schema;
|
|
7855
|
-
}
|
|
7856
|
-
}
|
|
7849
|
+
this.previewRenderer.setSchema(state.schema);
|
|
7850
|
+
this.lastPreviewSchema = state.schema;
|
|
7857
7851
|
}
|
|
7858
7852
|
previewContainer.appendChild(inner);
|
|
7859
7853
|
main.appendChild(previewContainer);
|