form-builder-pro 1.0.6 → 1.0.8
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 +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +262 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +262 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -109,6 +109,12 @@ interface FormState {
|
|
|
109
109
|
existingForms: FormSchema[];
|
|
110
110
|
templates: FormSection[];
|
|
111
111
|
masterTypes: MasterType[];
|
|
112
|
+
dropdownOptionsMap: {
|
|
113
|
+
[groupEnumName: string]: {
|
|
114
|
+
label: string;
|
|
115
|
+
value: string;
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
112
118
|
}
|
|
113
119
|
interface FormActions {
|
|
114
120
|
setSchema: (schema: FormSchema) => void;
|
|
@@ -116,6 +122,12 @@ interface FormActions {
|
|
|
116
122
|
setExistingForms: (forms: FormSchema[]) => void;
|
|
117
123
|
setTemplates: (templates: FormSection[]) => void;
|
|
118
124
|
setMasterTypes: (masterTypes: MasterType[]) => void;
|
|
125
|
+
setDropdownOptionsMap: (map: {
|
|
126
|
+
[groupEnumName: string]: {
|
|
127
|
+
label: string;
|
|
128
|
+
value: string;
|
|
129
|
+
}[];
|
|
130
|
+
}) => void;
|
|
119
131
|
loadForm: (formId: string) => void;
|
|
120
132
|
cloneExistingForm: (formId: string) => void;
|
|
121
133
|
importSection: (section: FormSection) => void;
|
|
@@ -149,6 +161,25 @@ interface FormBuilderOptions {
|
|
|
149
161
|
data?: {
|
|
150
162
|
masterTypes?: MasterType[];
|
|
151
163
|
};
|
|
164
|
+
masterTypeGroups?: {
|
|
165
|
+
id: string;
|
|
166
|
+
displayName: string;
|
|
167
|
+
enumName: string;
|
|
168
|
+
}[];
|
|
169
|
+
dropdownOptionsMap?: {
|
|
170
|
+
[groupEnumName: string]: {
|
|
171
|
+
label: string;
|
|
172
|
+
value: string;
|
|
173
|
+
}[];
|
|
174
|
+
};
|
|
175
|
+
onGroupSelectionChange?: (event: {
|
|
176
|
+
fieldId: string;
|
|
177
|
+
groupEnumName: string;
|
|
178
|
+
}) => void;
|
|
179
|
+
onDropdownValueChange?: (event: {
|
|
180
|
+
fieldId: string;
|
|
181
|
+
value: string;
|
|
182
|
+
}) => void;
|
|
152
183
|
}
|
|
153
184
|
declare class FormBuilder {
|
|
154
185
|
private container;
|
|
@@ -162,6 +193,17 @@ declare class FormBuilder {
|
|
|
162
193
|
applyTemplate(template: FormSection): void;
|
|
163
194
|
updateExistingForms(forms: FormSchema[]): void;
|
|
164
195
|
updateTemplates(templates: FormSection[]): void;
|
|
196
|
+
updateDropdownOptionsMap(dropdownOptionsMap: {
|
|
197
|
+
[groupEnumName: string]: {
|
|
198
|
+
label: string;
|
|
199
|
+
value: string;
|
|
200
|
+
}[];
|
|
201
|
+
}): void;
|
|
202
|
+
updateMasterTypeGroups(masterTypeGroups: {
|
|
203
|
+
id: string;
|
|
204
|
+
displayName: string;
|
|
205
|
+
enumName: string;
|
|
206
|
+
}[]): void;
|
|
165
207
|
loadFormTemplates(formTemplates: FormSchema[]): void;
|
|
166
208
|
private setupSubscriptions;
|
|
167
209
|
destroy(): void;
|
|
@@ -180,7 +222,11 @@ declare class FormRenderer {
|
|
|
180
222
|
private schema;
|
|
181
223
|
private data;
|
|
182
224
|
private onSubmit?;
|
|
183
|
-
|
|
225
|
+
private onDropdownValueChange?;
|
|
226
|
+
constructor(container: HTMLElement, schema: FormSchema, onSubmit?: (data: any) => void, onDropdownValueChange?: (event: {
|
|
227
|
+
fieldId: string;
|
|
228
|
+
value: string;
|
|
229
|
+
}) => void);
|
|
184
230
|
setSchema(schema: FormSchema): void;
|
|
185
231
|
private render;
|
|
186
232
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -109,6 +109,12 @@ interface FormState {
|
|
|
109
109
|
existingForms: FormSchema[];
|
|
110
110
|
templates: FormSection[];
|
|
111
111
|
masterTypes: MasterType[];
|
|
112
|
+
dropdownOptionsMap: {
|
|
113
|
+
[groupEnumName: string]: {
|
|
114
|
+
label: string;
|
|
115
|
+
value: string;
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
112
118
|
}
|
|
113
119
|
interface FormActions {
|
|
114
120
|
setSchema: (schema: FormSchema) => void;
|
|
@@ -116,6 +122,12 @@ interface FormActions {
|
|
|
116
122
|
setExistingForms: (forms: FormSchema[]) => void;
|
|
117
123
|
setTemplates: (templates: FormSection[]) => void;
|
|
118
124
|
setMasterTypes: (masterTypes: MasterType[]) => void;
|
|
125
|
+
setDropdownOptionsMap: (map: {
|
|
126
|
+
[groupEnumName: string]: {
|
|
127
|
+
label: string;
|
|
128
|
+
value: string;
|
|
129
|
+
}[];
|
|
130
|
+
}) => void;
|
|
119
131
|
loadForm: (formId: string) => void;
|
|
120
132
|
cloneExistingForm: (formId: string) => void;
|
|
121
133
|
importSection: (section: FormSection) => void;
|
|
@@ -149,6 +161,25 @@ interface FormBuilderOptions {
|
|
|
149
161
|
data?: {
|
|
150
162
|
masterTypes?: MasterType[];
|
|
151
163
|
};
|
|
164
|
+
masterTypeGroups?: {
|
|
165
|
+
id: string;
|
|
166
|
+
displayName: string;
|
|
167
|
+
enumName: string;
|
|
168
|
+
}[];
|
|
169
|
+
dropdownOptionsMap?: {
|
|
170
|
+
[groupEnumName: string]: {
|
|
171
|
+
label: string;
|
|
172
|
+
value: string;
|
|
173
|
+
}[];
|
|
174
|
+
};
|
|
175
|
+
onGroupSelectionChange?: (event: {
|
|
176
|
+
fieldId: string;
|
|
177
|
+
groupEnumName: string;
|
|
178
|
+
}) => void;
|
|
179
|
+
onDropdownValueChange?: (event: {
|
|
180
|
+
fieldId: string;
|
|
181
|
+
value: string;
|
|
182
|
+
}) => void;
|
|
152
183
|
}
|
|
153
184
|
declare class FormBuilder {
|
|
154
185
|
private container;
|
|
@@ -162,6 +193,17 @@ declare class FormBuilder {
|
|
|
162
193
|
applyTemplate(template: FormSection): void;
|
|
163
194
|
updateExistingForms(forms: FormSchema[]): void;
|
|
164
195
|
updateTemplates(templates: FormSection[]): void;
|
|
196
|
+
updateDropdownOptionsMap(dropdownOptionsMap: {
|
|
197
|
+
[groupEnumName: string]: {
|
|
198
|
+
label: string;
|
|
199
|
+
value: string;
|
|
200
|
+
}[];
|
|
201
|
+
}): void;
|
|
202
|
+
updateMasterTypeGroups(masterTypeGroups: {
|
|
203
|
+
id: string;
|
|
204
|
+
displayName: string;
|
|
205
|
+
enumName: string;
|
|
206
|
+
}[]): void;
|
|
165
207
|
loadFormTemplates(formTemplates: FormSchema[]): void;
|
|
166
208
|
private setupSubscriptions;
|
|
167
209
|
destroy(): void;
|
|
@@ -180,7 +222,11 @@ declare class FormRenderer {
|
|
|
180
222
|
private schema;
|
|
181
223
|
private data;
|
|
182
224
|
private onSubmit?;
|
|
183
|
-
|
|
225
|
+
private onDropdownValueChange?;
|
|
226
|
+
constructor(container: HTMLElement, schema: FormSchema, onSubmit?: (data: any) => void, onDropdownValueChange?: (event: {
|
|
227
|
+
fieldId: string;
|
|
228
|
+
value: string;
|
|
229
|
+
}) => void);
|
|
184
230
|
setSchema(schema: FormSchema): void;
|
|
185
231
|
private render;
|
|
186
232
|
}
|
package/dist/index.js
CHANGED
|
@@ -4168,6 +4168,7 @@ var formStore = createStore((set, get) => ({
|
|
|
4168
4168
|
existingForms: [],
|
|
4169
4169
|
templates: [],
|
|
4170
4170
|
masterTypes: [],
|
|
4171
|
+
dropdownOptionsMap: {},
|
|
4171
4172
|
setSchema: (schema) => {
|
|
4172
4173
|
const convertIndexesToOptions = (indexes) => {
|
|
4173
4174
|
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
@@ -4185,18 +4186,43 @@ var formStore = createStore((set, get) => ({
|
|
|
4185
4186
|
return { label: String(item), value: String(item) };
|
|
4186
4187
|
});
|
|
4187
4188
|
};
|
|
4189
|
+
const areDefaultOptions = (options) => {
|
|
4190
|
+
if (!options || options.length === 0)
|
|
4191
|
+
return true;
|
|
4192
|
+
return options.every(
|
|
4193
|
+
(opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
|
|
4194
|
+
);
|
|
4195
|
+
};
|
|
4188
4196
|
const state = get();
|
|
4189
4197
|
if (state.masterTypes && state.masterTypes.length > 0 && schema.sections) {
|
|
4190
4198
|
const updatedSections = schema.sections.map((section) => ({
|
|
4191
4199
|
...section,
|
|
4192
4200
|
fields: section.fields.map((field) => {
|
|
4193
|
-
if (field.type === "select" && field.groupName
|
|
4201
|
+
if (field.type === "select" && field.groupName) {
|
|
4194
4202
|
const masterType = state.masterTypes.find(
|
|
4195
4203
|
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4196
4204
|
);
|
|
4197
|
-
if (masterType
|
|
4198
|
-
|
|
4199
|
-
|
|
4205
|
+
if (masterType) {
|
|
4206
|
+
if (masterType.enumName && state.dropdownOptionsMap && state.dropdownOptionsMap[masterType.enumName]) {
|
|
4207
|
+
return { ...field, options: state.dropdownOptionsMap[masterType.enumName] };
|
|
4208
|
+
}
|
|
4209
|
+
if (!masterType.indexes || masterType.indexes.length === 0) {
|
|
4210
|
+
console.warn(`[FormBuilder] Master type "${masterType.displayName}" (${masterType.name}) has empty indexes array. Dropdown will have no options. Please ensure the API returns populated indexes.`, {
|
|
4211
|
+
masterTypeId: masterType.id,
|
|
4212
|
+
masterTypeName: masterType.name,
|
|
4213
|
+
enumName: masterType.enumName,
|
|
4214
|
+
indexes: masterType.indexes
|
|
4215
|
+
});
|
|
4216
|
+
}
|
|
4217
|
+
if (masterType.indexes && masterType.indexes.length > 0) {
|
|
4218
|
+
if (!field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
4219
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
4220
|
+
console.log(`[FormBuilder] Populating ${options.length} options from master type "${masterType.displayName}"`);
|
|
4221
|
+
return { ...field, options };
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
} else {
|
|
4225
|
+
console.warn("[FormBuilder] Master type not found for groupName:", field.groupName);
|
|
4200
4226
|
}
|
|
4201
4227
|
}
|
|
4202
4228
|
return field;
|
|
@@ -4207,34 +4233,129 @@ var formStore = createStore((set, get) => ({
|
|
|
4207
4233
|
set({ schema });
|
|
4208
4234
|
}
|
|
4209
4235
|
},
|
|
4210
|
-
togglePreview: () =>
|
|
4236
|
+
togglePreview: () => {
|
|
4237
|
+
const state = get();
|
|
4238
|
+
if (state.masterTypes && state.masterTypes.length > 0 && state.schema.sections) {
|
|
4239
|
+
const convertIndexesToOptions = (indexes) => {
|
|
4240
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
4241
|
+
return [];
|
|
4242
|
+
}
|
|
4243
|
+
return indexes.map((item, index2) => {
|
|
4244
|
+
if (typeof item === "string") {
|
|
4245
|
+
return { label: item, value: item };
|
|
4246
|
+
}
|
|
4247
|
+
if (typeof item === "object" && item !== null) {
|
|
4248
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4249
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
4250
|
+
return { label, value };
|
|
4251
|
+
}
|
|
4252
|
+
return { label: String(item), value: String(item) };
|
|
4253
|
+
});
|
|
4254
|
+
};
|
|
4255
|
+
const areDefaultOptions = (options) => {
|
|
4256
|
+
if (!options || options.length === 0)
|
|
4257
|
+
return true;
|
|
4258
|
+
return options.every(
|
|
4259
|
+
(opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
|
|
4260
|
+
);
|
|
4261
|
+
};
|
|
4262
|
+
const updatedSections = state.schema.sections.map((section) => ({
|
|
4263
|
+
...section,
|
|
4264
|
+
fields: section.fields.map((field) => {
|
|
4265
|
+
if (field.type === "select" && field.groupName) {
|
|
4266
|
+
const masterType = state.masterTypes.find(
|
|
4267
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4268
|
+
);
|
|
4269
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4270
|
+
if (!field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
4271
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
4272
|
+
return { ...field, options };
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
return field;
|
|
4277
|
+
})
|
|
4278
|
+
}));
|
|
4279
|
+
const hasChanges = updatedSections.some(
|
|
4280
|
+
(section, idx) => section.fields.some(
|
|
4281
|
+
(field, fieldIdx) => field !== state.schema.sections[idx]?.fields[fieldIdx]
|
|
4282
|
+
)
|
|
4283
|
+
);
|
|
4284
|
+
if (hasChanges) {
|
|
4285
|
+
set({
|
|
4286
|
+
schema: { ...state.schema, sections: updatedSections },
|
|
4287
|
+
isPreviewMode: !state.isPreviewMode
|
|
4288
|
+
});
|
|
4289
|
+
} else {
|
|
4290
|
+
set({ isPreviewMode: !state.isPreviewMode });
|
|
4291
|
+
}
|
|
4292
|
+
} else {
|
|
4293
|
+
set({ isPreviewMode: !state.isPreviewMode });
|
|
4294
|
+
}
|
|
4295
|
+
},
|
|
4211
4296
|
// New Actions
|
|
4212
4297
|
setExistingForms: (forms) => set({ existingForms: forms }),
|
|
4213
4298
|
setTemplates: (templates) => set({ templates }),
|
|
4299
|
+
setDropdownOptionsMap: (map) => {
|
|
4300
|
+
set({ dropdownOptionsMap: map });
|
|
4301
|
+
const state = get();
|
|
4302
|
+
if (state.schema && state.schema.sections) {
|
|
4303
|
+
const updatedSections = state.schema.sections.map((section) => ({
|
|
4304
|
+
...section,
|
|
4305
|
+
fields: section.fields.map((field) => {
|
|
4306
|
+
if (field.type === "select" && field.groupName) {
|
|
4307
|
+
const masterType = state.masterTypes.find(
|
|
4308
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4309
|
+
);
|
|
4310
|
+
if (masterType && masterType.enumName && map[masterType.enumName]) {
|
|
4311
|
+
return { ...field, options: map[masterType.enumName] };
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
return field;
|
|
4315
|
+
})
|
|
4316
|
+
}));
|
|
4317
|
+
set({ schema: { ...state.schema, sections: updatedSections } });
|
|
4318
|
+
}
|
|
4319
|
+
},
|
|
4214
4320
|
setMasterTypes: (masterTypes) => {
|
|
4215
4321
|
set({ masterTypes });
|
|
4216
4322
|
const state = get();
|
|
4217
4323
|
if (state.schema && state.schema.sections) {
|
|
4324
|
+
const convertIndexesToOptions = (indexes) => {
|
|
4325
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
4326
|
+
return [];
|
|
4327
|
+
}
|
|
4328
|
+
return indexes.map((item, index2) => {
|
|
4329
|
+
if (typeof item === "string") {
|
|
4330
|
+
return { label: item, value: item };
|
|
4331
|
+
}
|
|
4332
|
+
if (typeof item === "object" && item !== null) {
|
|
4333
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4334
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
4335
|
+
return { label, value };
|
|
4336
|
+
}
|
|
4337
|
+
return { label: String(item), value: String(item) };
|
|
4338
|
+
});
|
|
4339
|
+
};
|
|
4340
|
+
const areDefaultOptions = (options) => {
|
|
4341
|
+
if (!options || options.length === 0)
|
|
4342
|
+
return true;
|
|
4343
|
+
return options.every(
|
|
4344
|
+
(opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
|
|
4345
|
+
);
|
|
4346
|
+
};
|
|
4218
4347
|
const updatedSections = state.schema.sections.map((section) => ({
|
|
4219
4348
|
...section,
|
|
4220
4349
|
fields: section.fields.map((field) => {
|
|
4221
|
-
if (field.type === "select" && field.groupName
|
|
4350
|
+
if (field.type === "select" && field.groupName) {
|
|
4222
4351
|
const masterType = masterTypes.find(
|
|
4223
4352
|
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4224
4353
|
);
|
|
4225
4354
|
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
if (typeof item === "object" && item !== null) {
|
|
4231
|
-
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4232
|
-
const value = item.value || item.id || item.name || String(index2);
|
|
4233
|
-
return { label, value };
|
|
4234
|
-
}
|
|
4235
|
-
return { label: String(item), value: String(item) };
|
|
4236
|
-
});
|
|
4237
|
-
return { ...field, options };
|
|
4355
|
+
if (!field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
4356
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
4357
|
+
return { ...field, options };
|
|
4358
|
+
}
|
|
4238
4359
|
}
|
|
4239
4360
|
}
|
|
4240
4361
|
return field;
|
|
@@ -4696,14 +4817,16 @@ var FieldRenderer = class {
|
|
|
4696
4817
|
|
|
4697
4818
|
// src/renderer/FormRenderer.ts
|
|
4698
4819
|
var FormRenderer = class {
|
|
4699
|
-
constructor(container, schema, onSubmit) {
|
|
4820
|
+
constructor(container, schema, onSubmit, onDropdownValueChange) {
|
|
4700
4821
|
__publicField(this, "container");
|
|
4701
4822
|
__publicField(this, "schema");
|
|
4702
4823
|
__publicField(this, "data", {});
|
|
4703
4824
|
__publicField(this, "onSubmit");
|
|
4825
|
+
__publicField(this, "onDropdownValueChange");
|
|
4704
4826
|
this.container = container;
|
|
4705
4827
|
this.schema = schema;
|
|
4706
4828
|
this.onSubmit = onSubmit;
|
|
4829
|
+
this.onDropdownValueChange = onDropdownValueChange;
|
|
4707
4830
|
this.render();
|
|
4708
4831
|
}
|
|
4709
4832
|
setSchema(schema) {
|
|
@@ -4738,6 +4861,12 @@ var FormRenderer = class {
|
|
|
4738
4861
|
fieldWrapper.className = spanClass;
|
|
4739
4862
|
const fieldEl = FieldRenderer.render(field, this.data[field.id], (val) => {
|
|
4740
4863
|
this.data[field.id] = val;
|
|
4864
|
+
if (field.type === "select" && this.onDropdownValueChange) {
|
|
4865
|
+
this.onDropdownValueChange({
|
|
4866
|
+
fieldId: field.id,
|
|
4867
|
+
value: val || ""
|
|
4868
|
+
});
|
|
4869
|
+
}
|
|
4741
4870
|
});
|
|
4742
4871
|
fieldWrapper.appendChild(fieldEl);
|
|
4743
4872
|
grid.appendChild(fieldWrapper);
|
|
@@ -7304,6 +7433,21 @@ var FormBuilder = class {
|
|
|
7304
7433
|
if (options.data?.masterTypes) {
|
|
7305
7434
|
formStore.getState().setMasterTypes(options.data.masterTypes);
|
|
7306
7435
|
}
|
|
7436
|
+
if (options.masterTypeGroups) {
|
|
7437
|
+
const masterTypes = options.masterTypeGroups.map((group) => ({
|
|
7438
|
+
id: group.id,
|
|
7439
|
+
name: group.displayName.toLowerCase().replace(/\s+/g, "-"),
|
|
7440
|
+
// Generate name from displayName
|
|
7441
|
+
displayName: group.displayName,
|
|
7442
|
+
enumName: group.enumName,
|
|
7443
|
+
indexes: [],
|
|
7444
|
+
active: true
|
|
7445
|
+
}));
|
|
7446
|
+
formStore.getState().setMasterTypes(masterTypes);
|
|
7447
|
+
}
|
|
7448
|
+
if (options.dropdownOptionsMap) {
|
|
7449
|
+
formStore.getState().setDropdownOptionsMap(options.dropdownOptionsMap);
|
|
7450
|
+
}
|
|
7307
7451
|
this.render();
|
|
7308
7452
|
this.setupSubscriptions();
|
|
7309
7453
|
}
|
|
@@ -7337,6 +7481,23 @@ var FormBuilder = class {
|
|
|
7337
7481
|
formStore.getState().setTemplates(templates);
|
|
7338
7482
|
this.render();
|
|
7339
7483
|
}
|
|
7484
|
+
updateDropdownOptionsMap(dropdownOptionsMap) {
|
|
7485
|
+
formStore.getState().setDropdownOptionsMap(dropdownOptionsMap);
|
|
7486
|
+
this.render();
|
|
7487
|
+
}
|
|
7488
|
+
updateMasterTypeGroups(masterTypeGroups) {
|
|
7489
|
+
const masterTypes = masterTypeGroups.map((group) => ({
|
|
7490
|
+
id: group.id,
|
|
7491
|
+
name: group.displayName.toLowerCase().replace(/\s+/g, "-"),
|
|
7492
|
+
// Generate name from displayName
|
|
7493
|
+
displayName: group.displayName,
|
|
7494
|
+
enumName: group.enumName,
|
|
7495
|
+
indexes: [],
|
|
7496
|
+
active: true
|
|
7497
|
+
}));
|
|
7498
|
+
formStore.getState().setMasterTypes(masterTypes);
|
|
7499
|
+
this.render();
|
|
7500
|
+
}
|
|
7340
7501
|
loadFormTemplates(formTemplates) {
|
|
7341
7502
|
const extractedSections = [];
|
|
7342
7503
|
formTemplates.forEach((form) => {
|
|
@@ -7378,11 +7539,63 @@ var FormBuilder = class {
|
|
|
7378
7539
|
wrapper.appendChild(this.renderToolbar(state));
|
|
7379
7540
|
const main = createElement("div", { className: "flex flex-col md:flex-row flex-1 overflow-hidden" });
|
|
7380
7541
|
if (state.isPreviewMode) {
|
|
7381
|
-
const
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7542
|
+
const masterTypes = state.masterTypes;
|
|
7543
|
+
if (masterTypes && masterTypes.length > 0 && state.schema.sections) {
|
|
7544
|
+
const convertIndexesToOptions = (indexes) => {
|
|
7545
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
7546
|
+
return [];
|
|
7547
|
+
}
|
|
7548
|
+
return indexes.map((item, index2) => {
|
|
7549
|
+
if (typeof item === "string") {
|
|
7550
|
+
return { label: item, value: item };
|
|
7551
|
+
}
|
|
7552
|
+
if (typeof item === "object" && item !== null) {
|
|
7553
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
7554
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
7555
|
+
return { label, value };
|
|
7556
|
+
}
|
|
7557
|
+
return { label: String(item), value: String(item) };
|
|
7558
|
+
});
|
|
7559
|
+
};
|
|
7560
|
+
const areDefaultOptions = (options) => {
|
|
7561
|
+
if (!options || options.length === 0)
|
|
7562
|
+
return true;
|
|
7563
|
+
return options.every(
|
|
7564
|
+
(opt, idx) => opt.label === `Option ${idx + 1}` && (opt.value === `opt${idx + 1}` || opt.value === `Option ${idx + 1}`)
|
|
7565
|
+
);
|
|
7566
|
+
};
|
|
7567
|
+
const previewSchema = {
|
|
7568
|
+
...state.schema,
|
|
7569
|
+
sections: state.schema.sections.map((section) => ({
|
|
7570
|
+
...section,
|
|
7571
|
+
fields: section.fields.map((field) => {
|
|
7572
|
+
if (field.type === "select" && field.groupName) {
|
|
7573
|
+
const masterType = masterTypes.find(
|
|
7574
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
7575
|
+
);
|
|
7576
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
7577
|
+
if (!field.options || field.options.length === 0 || areDefaultOptions(field.options)) {
|
|
7578
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
7579
|
+
return { ...field, options };
|
|
7580
|
+
}
|
|
7581
|
+
}
|
|
7582
|
+
}
|
|
7583
|
+
return field;
|
|
7584
|
+
})
|
|
7585
|
+
}))
|
|
7586
|
+
};
|
|
7587
|
+
const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
|
|
7588
|
+
const inner = createElement("div", { className: "w-full max-w-3xl" });
|
|
7589
|
+
new FormRenderer(inner, previewSchema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
|
|
7590
|
+
previewContainer.appendChild(inner);
|
|
7591
|
+
main.appendChild(previewContainer);
|
|
7592
|
+
} else {
|
|
7593
|
+
const previewContainer = createElement("div", { className: "flex-1 p-8 overflow-y-auto bg-white dark:bg-gray-900 flex justify-center" });
|
|
7594
|
+
const inner = createElement("div", { className: "w-full max-w-3xl" });
|
|
7595
|
+
new FormRenderer(inner, state.schema, (data) => alert(JSON.stringify(data, null, 2)), this.options.onDropdownValueChange);
|
|
7596
|
+
previewContainer.appendChild(inner);
|
|
7597
|
+
main.appendChild(previewContainer);
|
|
7598
|
+
}
|
|
7386
7599
|
} else {
|
|
7387
7600
|
const toolboxWrapper = createElement("div", { className: "form-builder-toolbox-wrapper w-full md:w-80 bg-white dark:bg-gray-900 border-r md:border-r border-b md:border-b-0 border-gray-200 dark:border-gray-800" });
|
|
7388
7601
|
toolboxWrapper.appendChild(this.renderToolbox());
|
|
@@ -7691,6 +7904,7 @@ var FormBuilder = class {
|
|
|
7691
7904
|
if (selectedField.type === "select") {
|
|
7692
7905
|
const masterTypes = formStore.getState().masterTypes;
|
|
7693
7906
|
const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
|
|
7907
|
+
const dropdownOptionsMap = formStore.getState().dropdownOptionsMap;
|
|
7694
7908
|
const convertIndexesToOptions = (indexes) => {
|
|
7695
7909
|
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
7696
7910
|
return [];
|
|
@@ -7713,11 +7927,16 @@ var FormBuilder = class {
|
|
|
7713
7927
|
const groupNameSelect = createElement("select", {
|
|
7714
7928
|
className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
|
|
7715
7929
|
onchange: (e) => {
|
|
7716
|
-
const
|
|
7717
|
-
if (
|
|
7718
|
-
const selectedMasterType = activeMasterTypes.find((mt) => mt.
|
|
7930
|
+
const selectedEnumName = e.target.value;
|
|
7931
|
+
if (selectedEnumName) {
|
|
7932
|
+
const selectedMasterType = activeMasterTypes.find((mt) => mt.enumName === selectedEnumName);
|
|
7719
7933
|
if (selectedMasterType) {
|
|
7720
|
-
|
|
7934
|
+
let options = [];
|
|
7935
|
+
if (dropdownOptionsMap && dropdownOptionsMap[selectedEnumName]) {
|
|
7936
|
+
options = dropdownOptionsMap[selectedEnumName];
|
|
7937
|
+
} else if (selectedMasterType.indexes && selectedMasterType.indexes.length > 0) {
|
|
7938
|
+
options = convertIndexesToOptions(selectedMasterType.indexes);
|
|
7939
|
+
}
|
|
7721
7940
|
formStore.getState().updateField(selectedField.id, {
|
|
7722
7941
|
groupName: {
|
|
7723
7942
|
id: selectedMasterType.id,
|
|
@@ -7725,6 +7944,12 @@ var FormBuilder = class {
|
|
|
7725
7944
|
},
|
|
7726
7945
|
options: options.length > 0 ? options : void 0
|
|
7727
7946
|
});
|
|
7947
|
+
if (this.options.onGroupSelectionChange) {
|
|
7948
|
+
this.options.onGroupSelectionChange({
|
|
7949
|
+
fieldId: selectedField.id,
|
|
7950
|
+
groupEnumName: selectedEnumName
|
|
7951
|
+
});
|
|
7952
|
+
}
|
|
7728
7953
|
}
|
|
7729
7954
|
} else {
|
|
7730
7955
|
formStore.getState().updateField(selectedField.id, {
|
|
@@ -7742,8 +7967,9 @@ var FormBuilder = class {
|
|
|
7742
7967
|
}));
|
|
7743
7968
|
activeMasterTypes.forEach((mt) => {
|
|
7744
7969
|
const isSelected = selectedField.groupName && (selectedField.groupName.id === mt.id || selectedField.groupName.name === mt.name);
|
|
7970
|
+
const optionValue = mt.enumName || mt.id || mt.name;
|
|
7745
7971
|
groupNameSelect.appendChild(createElement("option", {
|
|
7746
|
-
value:
|
|
7972
|
+
value: optionValue,
|
|
7747
7973
|
text: mt.displayName || mt.name,
|
|
7748
7974
|
selected: !!isSelected
|
|
7749
7975
|
}));
|
|
@@ -7754,8 +7980,13 @@ var FormBuilder = class {
|
|
|
7754
7980
|
const currentMasterType = activeMasterTypes.find(
|
|
7755
7981
|
(mt) => mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name
|
|
7756
7982
|
);
|
|
7757
|
-
if (currentMasterType
|
|
7758
|
-
|
|
7983
|
+
if (currentMasterType) {
|
|
7984
|
+
let options = [];
|
|
7985
|
+
if (currentMasterType.enumName && dropdownOptionsMap && dropdownOptionsMap[currentMasterType.enumName]) {
|
|
7986
|
+
options = dropdownOptionsMap[currentMasterType.enumName];
|
|
7987
|
+
} else if (currentMasterType.indexes && currentMasterType.indexes.length > 0) {
|
|
7988
|
+
options = convertIndexesToOptions(currentMasterType.indexes);
|
|
7989
|
+
}
|
|
7759
7990
|
if (options.length > 0) {
|
|
7760
7991
|
formStore.getState().updateField(selectedField.id, { options });
|
|
7761
7992
|
}
|