form-builder-pro 1.0.4 → 1.0.6
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +113 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4166,12 +4166,88 @@ var formStore = createStore((set, get) => ({
|
|
|
4166
4166
|
existingForms: [],
|
|
4167
4167
|
templates: [],
|
|
4168
4168
|
masterTypes: [],
|
|
4169
|
-
setSchema: (schema) =>
|
|
4169
|
+
setSchema: (schema) => {
|
|
4170
|
+
const convertIndexesToOptions = (indexes) => {
|
|
4171
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
4172
|
+
return [];
|
|
4173
|
+
}
|
|
4174
|
+
return indexes.map((item, index2) => {
|
|
4175
|
+
if (typeof item === "string") {
|
|
4176
|
+
return { label: item, value: item };
|
|
4177
|
+
}
|
|
4178
|
+
if (typeof item === "object" && item !== null) {
|
|
4179
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4180
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
4181
|
+
return { label, value };
|
|
4182
|
+
}
|
|
4183
|
+
return { label: String(item), value: String(item) };
|
|
4184
|
+
});
|
|
4185
|
+
};
|
|
4186
|
+
const state = get();
|
|
4187
|
+
if (state.masterTypes && state.masterTypes.length > 0 && schema.sections) {
|
|
4188
|
+
const updatedSections = schema.sections.map((section) => ({
|
|
4189
|
+
...section,
|
|
4190
|
+
fields: section.fields.map((field) => {
|
|
4191
|
+
if (field.type === "select" && field.groupName && (!field.options || field.options.length === 0)) {
|
|
4192
|
+
const masterType = state.masterTypes.find(
|
|
4193
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4194
|
+
);
|
|
4195
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4196
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
4197
|
+
return { ...field, options };
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
return field;
|
|
4201
|
+
})
|
|
4202
|
+
}));
|
|
4203
|
+
set({ schema: { ...schema, sections: updatedSections } });
|
|
4204
|
+
} else {
|
|
4205
|
+
set({ schema });
|
|
4206
|
+
}
|
|
4207
|
+
},
|
|
4170
4208
|
togglePreview: () => set((state) => ({ isPreviewMode: !state.isPreviewMode })),
|
|
4171
4209
|
// New Actions
|
|
4172
4210
|
setExistingForms: (forms) => set({ existingForms: forms }),
|
|
4173
4211
|
setTemplates: (templates) => set({ templates }),
|
|
4174
|
-
setMasterTypes: (masterTypes) =>
|
|
4212
|
+
setMasterTypes: (masterTypes) => {
|
|
4213
|
+
set({ masterTypes });
|
|
4214
|
+
const state = get();
|
|
4215
|
+
if (state.schema && state.schema.sections) {
|
|
4216
|
+
const updatedSections = state.schema.sections.map((section) => ({
|
|
4217
|
+
...section,
|
|
4218
|
+
fields: section.fields.map((field) => {
|
|
4219
|
+
if (field.type === "select" && field.groupName && (!field.options || field.options.length === 0)) {
|
|
4220
|
+
const masterType = masterTypes.find(
|
|
4221
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4222
|
+
);
|
|
4223
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4224
|
+
const options = masterType.indexes.map((item, index2) => {
|
|
4225
|
+
if (typeof item === "string") {
|
|
4226
|
+
return { label: item, value: item };
|
|
4227
|
+
}
|
|
4228
|
+
if (typeof item === "object" && item !== null) {
|
|
4229
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4230
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
4231
|
+
return { label, value };
|
|
4232
|
+
}
|
|
4233
|
+
return { label: String(item), value: String(item) };
|
|
4234
|
+
});
|
|
4235
|
+
return { ...field, options };
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
return field;
|
|
4239
|
+
})
|
|
4240
|
+
}));
|
|
4241
|
+
const hasChanges = updatedSections.some(
|
|
4242
|
+
(section, idx) => section.fields.some(
|
|
4243
|
+
(field, fieldIdx) => field !== state.schema.sections[idx]?.fields[fieldIdx]
|
|
4244
|
+
)
|
|
4245
|
+
);
|
|
4246
|
+
if (hasChanges) {
|
|
4247
|
+
set({ schema: { ...state.schema, sections: updatedSections } });
|
|
4248
|
+
}
|
|
4249
|
+
}
|
|
4250
|
+
},
|
|
4175
4251
|
loadForm: (formId) => {
|
|
4176
4252
|
const { existingForms, history, historyIndex } = get();
|
|
4177
4253
|
const found = existingForms.find((f) => f.id === formId);
|
|
@@ -7613,6 +7689,22 @@ var FormBuilder = class {
|
|
|
7613
7689
|
if (selectedField.type === "select") {
|
|
7614
7690
|
const masterTypes = formStore.getState().masterTypes;
|
|
7615
7691
|
const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
|
|
7692
|
+
const convertIndexesToOptions = (indexes) => {
|
|
7693
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
7694
|
+
return [];
|
|
7695
|
+
}
|
|
7696
|
+
return indexes.map((item, index2) => {
|
|
7697
|
+
if (typeof item === "string") {
|
|
7698
|
+
return { label: item, value: item };
|
|
7699
|
+
}
|
|
7700
|
+
if (typeof item === "object" && item !== null) {
|
|
7701
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
7702
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
7703
|
+
return { label, value };
|
|
7704
|
+
}
|
|
7705
|
+
return { label: String(item), value: String(item) };
|
|
7706
|
+
});
|
|
7707
|
+
};
|
|
7616
7708
|
if (activeMasterTypes.length > 0) {
|
|
7617
7709
|
const groupNameGroup = createElement("div", { className: "mb-4" });
|
|
7618
7710
|
groupNameGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Group Name" }));
|
|
@@ -7623,15 +7715,21 @@ var FormBuilder = class {
|
|
|
7623
7715
|
if (selectedValue) {
|
|
7624
7716
|
const selectedMasterType = activeMasterTypes.find((mt) => mt.id === selectedValue || mt.name === selectedValue);
|
|
7625
7717
|
if (selectedMasterType) {
|
|
7718
|
+
const options = convertIndexesToOptions(selectedMasterType.indexes || []);
|
|
7626
7719
|
formStore.getState().updateField(selectedField.id, {
|
|
7627
7720
|
groupName: {
|
|
7628
7721
|
id: selectedMasterType.id,
|
|
7629
7722
|
name: selectedMasterType.name
|
|
7630
|
-
}
|
|
7723
|
+
},
|
|
7724
|
+
options: options.length > 0 ? options : void 0
|
|
7631
7725
|
});
|
|
7632
7726
|
}
|
|
7633
7727
|
} else {
|
|
7634
|
-
formStore.getState().updateField(selectedField.id, {
|
|
7728
|
+
formStore.getState().updateField(selectedField.id, {
|
|
7729
|
+
groupName: void 0,
|
|
7730
|
+
options: void 0
|
|
7731
|
+
// Clear options when groupName is cleared
|
|
7732
|
+
});
|
|
7635
7733
|
}
|
|
7636
7734
|
}
|
|
7637
7735
|
});
|
|
@@ -7650,6 +7748,17 @@ var FormBuilder = class {
|
|
|
7650
7748
|
});
|
|
7651
7749
|
groupNameGroup.appendChild(groupNameSelect);
|
|
7652
7750
|
body.appendChild(groupNameGroup);
|
|
7751
|
+
if (selectedField.groupName && (!selectedField.options || selectedField.options.length === 0)) {
|
|
7752
|
+
const currentMasterType = activeMasterTypes.find(
|
|
7753
|
+
(mt) => mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name
|
|
7754
|
+
);
|
|
7755
|
+
if (currentMasterType && currentMasterType.indexes && currentMasterType.indexes.length > 0) {
|
|
7756
|
+
const options = convertIndexesToOptions(currentMasterType.indexes);
|
|
7757
|
+
if (options.length > 0) {
|
|
7758
|
+
formStore.getState().updateField(selectedField.id, { options });
|
|
7759
|
+
}
|
|
7760
|
+
}
|
|
7761
|
+
}
|
|
7653
7762
|
}
|
|
7654
7763
|
}
|
|
7655
7764
|
const validationHeader = createElement("h3", { className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6", text: "Validation Rules" });
|