form-builder-pro 1.0.3 → 1.0.5
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.css +43 -0
- package/dist/index.d.mts +54 -36
- package/dist/index.d.ts +54 -36
- package/dist/index.js +507 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +507 -211
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4112,17 +4112,17 @@ var FIELD_TYPES = [
|
|
|
4112
4112
|
{ type: "file", label: "File Upload", icon: "Upload" }
|
|
4113
4113
|
];
|
|
4114
4114
|
var DEFAULT_FIELD_CONFIG = {
|
|
4115
|
-
text: { label: "Text Input", placeholder: "Enter text...", width: "100%" },
|
|
4116
|
-
textarea: { label: "Text Area", placeholder: "Enter description...", width: "100%" },
|
|
4117
|
-
number: { label: "Number", placeholder: "0", width: "50%" },
|
|
4118
|
-
email: { label: "Email", placeholder: "example@email.com", width: "100%", validation: [{ type: "email", message: "Invalid email" }] },
|
|
4119
|
-
phone: { label: "Phone", placeholder: "+1 234 567 8900", width: "100%" },
|
|
4120
|
-
date: { label: "Date", width: "50%" },
|
|
4121
|
-
select: { label: "Dropdown", options: [{ label: "Option 1", value: "opt1" }, { label: "Option 2", value: "opt2" }], width: "100%" },
|
|
4122
|
-
checkbox: { label: "Checkbox", width: "100%" },
|
|
4123
|
-
radio: { label: "Radio Group", options: [{ label: "Option 1", value: "opt1" }, { label: "Option 2", value: "opt2" }], width: "100%" },
|
|
4124
|
-
toggle: { label: "Toggle", width: "50%" },
|
|
4125
|
-
file: { label: "File Upload", width: "100%" }
|
|
4115
|
+
text: { label: "Text Input", placeholder: "Enter text...", width: "100%", enabled: true, visible: true },
|
|
4116
|
+
textarea: { label: "Text Area", placeholder: "Enter description...", width: "100%", enabled: true, visible: true },
|
|
4117
|
+
number: { label: "Number", placeholder: "0", width: "50%", enabled: true, visible: true },
|
|
4118
|
+
email: { label: "Email", placeholder: "example@email.com", width: "100%", validation: [{ type: "email", message: "Invalid email" }], enabled: true, visible: true },
|
|
4119
|
+
phone: { label: "Phone", placeholder: "+1 234 567 8900", width: "100%", enabled: true, visible: true },
|
|
4120
|
+
date: { label: "Date", width: "50%", enabled: true, visible: true },
|
|
4121
|
+
select: { label: "Dropdown", options: [{ label: "Option 1", value: "opt1" }, { label: "Option 2", value: "opt2" }], width: "100%", enabled: true, visible: true },
|
|
4122
|
+
checkbox: { label: "Checkbox", width: "100%", enabled: true, visible: true },
|
|
4123
|
+
radio: { label: "Radio Group", options: [{ label: "Option 1", value: "opt1" }, { label: "Option 2", value: "opt2" }], width: "100%", enabled: true, visible: true },
|
|
4124
|
+
toggle: { label: "Toggle", width: "50%", enabled: true, visible: true },
|
|
4125
|
+
file: { label: "File Upload", width: "100%", enabled: true, visible: true }
|
|
4126
4126
|
};
|
|
4127
4127
|
|
|
4128
4128
|
// src/utils/clone.ts
|
|
@@ -4157,13 +4157,7 @@ var INITIAL_SCHEMA = {
|
|
|
4157
4157
|
id: "form_1",
|
|
4158
4158
|
title: "My New Form",
|
|
4159
4159
|
formName: "myNewForm",
|
|
4160
|
-
sections: [
|
|
4161
|
-
{
|
|
4162
|
-
id: generateId(),
|
|
4163
|
-
title: "Section 1",
|
|
4164
|
-
fields: []
|
|
4165
|
-
}
|
|
4166
|
-
]
|
|
4160
|
+
sections: []
|
|
4167
4161
|
};
|
|
4168
4162
|
var formStore = createStore((set, get) => ({
|
|
4169
4163
|
schema: INITIAL_SCHEMA,
|
|
@@ -4173,11 +4167,89 @@ var formStore = createStore((set, get) => ({
|
|
|
4173
4167
|
isPreviewMode: false,
|
|
4174
4168
|
existingForms: [],
|
|
4175
4169
|
templates: [],
|
|
4176
|
-
|
|
4170
|
+
masterTypes: [],
|
|
4171
|
+
setSchema: (schema) => {
|
|
4172
|
+
const convertIndexesToOptions = (indexes) => {
|
|
4173
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
4174
|
+
return [];
|
|
4175
|
+
}
|
|
4176
|
+
return indexes.map((item, index2) => {
|
|
4177
|
+
if (typeof item === "string") {
|
|
4178
|
+
return { label: item, value: item };
|
|
4179
|
+
}
|
|
4180
|
+
if (typeof item === "object" && item !== null) {
|
|
4181
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
4182
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
4183
|
+
return { label, value };
|
|
4184
|
+
}
|
|
4185
|
+
return { label: String(item), value: String(item) };
|
|
4186
|
+
});
|
|
4187
|
+
};
|
|
4188
|
+
const state = get();
|
|
4189
|
+
if (state.masterTypes && state.masterTypes.length > 0 && schema.sections) {
|
|
4190
|
+
const updatedSections = schema.sections.map((section) => ({
|
|
4191
|
+
...section,
|
|
4192
|
+
fields: section.fields.map((field) => {
|
|
4193
|
+
if (field.type === "select" && field.groupName && (!field.options || field.options.length === 0)) {
|
|
4194
|
+
const masterType = state.masterTypes.find(
|
|
4195
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4196
|
+
);
|
|
4197
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4198
|
+
const options = convertIndexesToOptions(masterType.indexes);
|
|
4199
|
+
return { ...field, options };
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
return field;
|
|
4203
|
+
})
|
|
4204
|
+
}));
|
|
4205
|
+
set({ schema: { ...schema, sections: updatedSections } });
|
|
4206
|
+
} else {
|
|
4207
|
+
set({ schema });
|
|
4208
|
+
}
|
|
4209
|
+
},
|
|
4177
4210
|
togglePreview: () => set((state) => ({ isPreviewMode: !state.isPreviewMode })),
|
|
4178
4211
|
// New Actions
|
|
4179
4212
|
setExistingForms: (forms) => set({ existingForms: forms }),
|
|
4180
4213
|
setTemplates: (templates) => set({ templates }),
|
|
4214
|
+
setMasterTypes: (masterTypes) => {
|
|
4215
|
+
set({ masterTypes });
|
|
4216
|
+
const state = get();
|
|
4217
|
+
if (state.schema && state.schema.sections) {
|
|
4218
|
+
const updatedSections = state.schema.sections.map((section) => ({
|
|
4219
|
+
...section,
|
|
4220
|
+
fields: section.fields.map((field) => {
|
|
4221
|
+
if (field.type === "select" && field.groupName && (!field.options || field.options.length === 0)) {
|
|
4222
|
+
const masterType = masterTypes.find(
|
|
4223
|
+
(mt) => mt.active === true && (mt.id === field.groupName?.id || mt.name === field.groupName?.name)
|
|
4224
|
+
);
|
|
4225
|
+
if (masterType && masterType.indexes && masterType.indexes.length > 0) {
|
|
4226
|
+
const options = masterType.indexes.map((item, index2) => {
|
|
4227
|
+
if (typeof item === "string") {
|
|
4228
|
+
return { label: item, value: item };
|
|
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 };
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
return field;
|
|
4241
|
+
})
|
|
4242
|
+
}));
|
|
4243
|
+
const hasChanges = updatedSections.some(
|
|
4244
|
+
(section, idx) => section.fields.some(
|
|
4245
|
+
(field, fieldIdx) => field !== state.schema.sections[idx]?.fields[fieldIdx]
|
|
4246
|
+
)
|
|
4247
|
+
);
|
|
4248
|
+
if (hasChanges) {
|
|
4249
|
+
set({ schema: { ...state.schema, sections: updatedSections } });
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4252
|
+
},
|
|
4181
4253
|
loadForm: (formId) => {
|
|
4182
4254
|
const { existingForms, history, historyIndex } = get();
|
|
4183
4255
|
const found = existingForms.find((f) => f.id === formId);
|
|
@@ -4272,20 +4344,39 @@ var formStore = createStore((set, get) => ({
|
|
|
4272
4344
|
type,
|
|
4273
4345
|
...DEFAULT_FIELD_CONFIG[type]
|
|
4274
4346
|
};
|
|
4347
|
+
let newSections = [...schema.sections];
|
|
4348
|
+
if (newSections.length === 0 || sectionId === null) {
|
|
4349
|
+
const defaultSection = {
|
|
4350
|
+
id: generateId(),
|
|
4351
|
+
title: "Default Section",
|
|
4352
|
+
fields: [],
|
|
4353
|
+
columns: 1
|
|
4354
|
+
};
|
|
4355
|
+
newSections.push(defaultSection);
|
|
4356
|
+
sectionId = defaultSection.id;
|
|
4357
|
+
}
|
|
4358
|
+
const sectionIndex = newSections.findIndex((s) => s.id === sectionId);
|
|
4359
|
+
if (sectionIndex !== -1) {
|
|
4360
|
+
const section = newSections[sectionIndex];
|
|
4361
|
+
const newFields = [...section.fields];
|
|
4362
|
+
if (typeof index2 === "number") {
|
|
4363
|
+
newFields.splice(index2, 0, newField);
|
|
4364
|
+
} else {
|
|
4365
|
+
newFields.push(newField);
|
|
4366
|
+
}
|
|
4367
|
+
newSections[sectionIndex] = { ...section, fields: newFields };
|
|
4368
|
+
} else {
|
|
4369
|
+
const defaultSection = {
|
|
4370
|
+
id: generateId(),
|
|
4371
|
+
title: "Default Section",
|
|
4372
|
+
fields: [newField],
|
|
4373
|
+
columns: 1
|
|
4374
|
+
};
|
|
4375
|
+
newSections.push(defaultSection);
|
|
4376
|
+
}
|
|
4275
4377
|
const newSchema = {
|
|
4276
4378
|
...schema,
|
|
4277
|
-
sections:
|
|
4278
|
-
if (s.id === sectionId) {
|
|
4279
|
-
const newFields = [...s.fields];
|
|
4280
|
-
if (typeof index2 === "number") {
|
|
4281
|
-
newFields.splice(index2, 0, newField);
|
|
4282
|
-
} else {
|
|
4283
|
-
newFields.push(newField);
|
|
4284
|
-
}
|
|
4285
|
-
return { ...s, fields: newFields };
|
|
4286
|
-
}
|
|
4287
|
-
return s;
|
|
4288
|
-
})
|
|
4379
|
+
sections: newSections
|
|
4289
4380
|
};
|
|
4290
4381
|
set({
|
|
4291
4382
|
schema: newSchema,
|
|
@@ -4341,6 +4432,16 @@ var formStore = createStore((set, get) => ({
|
|
|
4341
4432
|
});
|
|
4342
4433
|
if (!field)
|
|
4343
4434
|
return;
|
|
4435
|
+
if (targetSectionId === null || newSections.length === 0) {
|
|
4436
|
+
const defaultSection = {
|
|
4437
|
+
id: generateId(),
|
|
4438
|
+
title: "Default Section",
|
|
4439
|
+
fields: [],
|
|
4440
|
+
columns: 1
|
|
4441
|
+
};
|
|
4442
|
+
newSections.push(defaultSection);
|
|
4443
|
+
targetSectionId = defaultSection.id;
|
|
4444
|
+
}
|
|
4344
4445
|
const targetSectionIndex = newSections.findIndex((s) => s.id === targetSectionId);
|
|
4345
4446
|
if (targetSectionIndex !== -1) {
|
|
4346
4447
|
const targetSection = newSections[targetSectionIndex];
|
|
@@ -4499,6 +4600,7 @@ function getIcon(name, size = 20) {
|
|
|
4499
4600
|
var FieldRenderer = class {
|
|
4500
4601
|
static render(field, value, onChange, readOnly = false) {
|
|
4501
4602
|
const wrapper = createElement("div", { className: "w-full" });
|
|
4603
|
+
const isEnabled = field.enabled !== false && !readOnly;
|
|
4502
4604
|
if (field.type !== "checkbox") {
|
|
4503
4605
|
const label = createElement("label", {
|
|
4504
4606
|
className: "text-xs sm:text-sm font-medium leading-none mb-2 block text-gray-900 dark:text-gray-100",
|
|
@@ -4525,7 +4627,7 @@ var FieldRenderer = class {
|
|
|
4525
4627
|
className: "flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm sm:text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
4526
4628
|
placeholder: field.placeholder,
|
|
4527
4629
|
value: value || "",
|
|
4528
|
-
disabled:
|
|
4630
|
+
disabled: !isEnabled,
|
|
4529
4631
|
oninput: (e) => onChange?.(e.target.value)
|
|
4530
4632
|
});
|
|
4531
4633
|
break;
|
|
@@ -4533,7 +4635,7 @@ var FieldRenderer = class {
|
|
|
4533
4635
|
input = createElement("select", {
|
|
4534
4636
|
className: "flex min-h-touch w-full rounded-md border border-input bg-background px-3 py-2 text-sm sm:text-base ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
4535
4637
|
value: value || "",
|
|
4536
|
-
disabled:
|
|
4638
|
+
disabled: !isEnabled,
|
|
4537
4639
|
onchange: (e) => onChange?.(e.target.value)
|
|
4538
4640
|
});
|
|
4539
4641
|
input.appendChild(createElement("option", { value: "", text: "Select an option", disabled: true, selected: !value }));
|
|
@@ -4547,7 +4649,7 @@ var FieldRenderer = class {
|
|
|
4547
4649
|
type: "checkbox",
|
|
4548
4650
|
className: "h-5 w-5 sm:h-6 sm:w-6 rounded border-gray-300 text-primary focus:ring-primary cursor-pointer",
|
|
4549
4651
|
checked: !!value,
|
|
4550
|
-
disabled:
|
|
4652
|
+
disabled: !isEnabled,
|
|
4551
4653
|
onchange: (e) => onChange?.(e.target.checked)
|
|
4552
4654
|
});
|
|
4553
4655
|
input.appendChild(checkbox);
|
|
@@ -4561,7 +4663,7 @@ var FieldRenderer = class {
|
|
|
4561
4663
|
name: field.id,
|
|
4562
4664
|
value: opt.value,
|
|
4563
4665
|
checked: value === opt.value,
|
|
4564
|
-
disabled:
|
|
4666
|
+
disabled: !isEnabled,
|
|
4565
4667
|
className: "aspect-square h-4 w-4 sm:h-5 sm:w-5 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
4566
4668
|
onchange: (e) => onChange?.(e.target.value)
|
|
4567
4669
|
});
|
|
@@ -4580,7 +4682,7 @@ var FieldRenderer = class {
|
|
|
4580
4682
|
className: "flex min-h-touch w-full rounded-md border border-input bg-background px-3 py-2 text-sm sm:text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
4581
4683
|
placeholder: field.placeholder,
|
|
4582
4684
|
value: value || "",
|
|
4583
|
-
disabled:
|
|
4685
|
+
disabled: !isEnabled,
|
|
4584
4686
|
oninput: (e) => onChange?.(e.target.value)
|
|
4585
4687
|
});
|
|
4586
4688
|
}
|
|
@@ -4617,6 +4719,10 @@ var FormRenderer = class {
|
|
|
4617
4719
|
sectionEl.appendChild(createElement("h2", { className: "text-lg md:text-xl font-semibold text-gray-800 dark:text-gray-200 border-b pb-2", text: section.title }));
|
|
4618
4720
|
const grid = createElement("div", { className: "form-builder-grid" });
|
|
4619
4721
|
section.fields.forEach((field) => {
|
|
4722
|
+
const isVisible = field.visible !== false;
|
|
4723
|
+
if (!isVisible) {
|
|
4724
|
+
return;
|
|
4725
|
+
}
|
|
4620
4726
|
const fieldWrapper = createElement("div");
|
|
4621
4727
|
let spanClass = "col-span-12";
|
|
4622
4728
|
if (field.width === "50%")
|
|
@@ -6902,6 +7008,266 @@ Sortable.mount(new AutoScrollPlugin());
|
|
|
6902
7008
|
Sortable.mount(Remove, Revert);
|
|
6903
7009
|
var sortable_esm_default = Sortable;
|
|
6904
7010
|
|
|
7011
|
+
// src/builder/FieldWrapper.ts
|
|
7012
|
+
var FieldWrapper = class {
|
|
7013
|
+
static render(field, isSelected) {
|
|
7014
|
+
const isVisible = field.visible !== false;
|
|
7015
|
+
let spanClass = "col-span-12";
|
|
7016
|
+
if (field.width === "50%")
|
|
7017
|
+
spanClass = "col-span-6";
|
|
7018
|
+
else if (field.width === "33%")
|
|
7019
|
+
spanClass = "col-span-4";
|
|
7020
|
+
else if (field.width === "25%")
|
|
7021
|
+
spanClass = "col-span-3";
|
|
7022
|
+
else if (field.width === "66%")
|
|
7023
|
+
spanClass = "col-span-8";
|
|
7024
|
+
else if (field.width === "75%")
|
|
7025
|
+
spanClass = "col-span-9";
|
|
7026
|
+
const fieldWrapper = createElement("div", {
|
|
7027
|
+
className: `form-builder-field-wrapper ${isSelected ? "selected-field" : ""} ${spanClass} relative group border border-transparent hover:border-blue-200 rounded-md transition-all ${!isVisible ? "hidden" : ""}`,
|
|
7028
|
+
"data-id": field.id,
|
|
7029
|
+
onclick: (e) => {
|
|
7030
|
+
e.stopPropagation();
|
|
7031
|
+
formStore.getState().selectField(field.id);
|
|
7032
|
+
}
|
|
7033
|
+
});
|
|
7034
|
+
if (isSelected) {
|
|
7035
|
+
fieldWrapper.classList.add("ring-2", "ring-blue-500", "bg-blue-50", "dark:bg-blue-900/20");
|
|
7036
|
+
}
|
|
7037
|
+
fieldWrapper.appendChild(createElement("div", {
|
|
7038
|
+
className: `absolute top-2 left-2 cursor-move p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity field-handle z-10 ${isSelected ? "opacity-100" : ""}`
|
|
7039
|
+
}, [getIcon("GripVertical", 16)]));
|
|
7040
|
+
fieldWrapper.appendChild(createElement("button", {
|
|
7041
|
+
className: `absolute top-2 right-2 p-1 rounded hover:bg-red-50 text-red-400 hover:text-red-600 opacity-0 group-hover:opacity-100 transition-opacity z-10 ${isSelected ? "opacity-100" : ""}`,
|
|
7042
|
+
onclick: (e) => {
|
|
7043
|
+
e.stopPropagation();
|
|
7044
|
+
if (confirm("Delete this field?")) {
|
|
7045
|
+
formStore.getState().removeField(field.id);
|
|
7046
|
+
}
|
|
7047
|
+
}
|
|
7048
|
+
}, [getIcon("Trash2", 16)]));
|
|
7049
|
+
const content = createElement("div", { className: "p-4 pointer-events-none" });
|
|
7050
|
+
content.appendChild(FieldRenderer.render(field, null, void 0, true));
|
|
7051
|
+
fieldWrapper.appendChild(content);
|
|
7052
|
+
return fieldWrapper;
|
|
7053
|
+
}
|
|
7054
|
+
};
|
|
7055
|
+
|
|
7056
|
+
// src/builder/Section.ts
|
|
7057
|
+
var Section = class {
|
|
7058
|
+
constructor(section, isSelectedField) {
|
|
7059
|
+
__publicField(this, "container");
|
|
7060
|
+
__publicField(this, "section");
|
|
7061
|
+
__publicField(this, "isSelectedField");
|
|
7062
|
+
this.section = section;
|
|
7063
|
+
this.isSelectedField = isSelectedField;
|
|
7064
|
+
this.container = this.render();
|
|
7065
|
+
}
|
|
7066
|
+
getElement() {
|
|
7067
|
+
return this.container;
|
|
7068
|
+
}
|
|
7069
|
+
render() {
|
|
7070
|
+
const sectionEl = createElement("div", {
|
|
7071
|
+
className: "mb-6 rounded-lg border bg-white dark:bg-gray-900 shadow-sm transition-all border-gray-200 dark:border-gray-800",
|
|
7072
|
+
"data-id": this.section.id
|
|
7073
|
+
});
|
|
7074
|
+
const header = createElement("div", { className: "flex items-center justify-between p-2 border-b border-gray-100 dark:border-gray-800 bg-gray-50 dark:bg-gray-800/50 rounded-t-lg" });
|
|
7075
|
+
const headerLeft = createElement("div", { className: "flex items-center flex-1" });
|
|
7076
|
+
headerLeft.appendChild(createElement("div", { className: "cursor-move mr-3 text-gray-400 hover:text-gray-600 section-handle" }, [getIcon("GripVertical", 20)]));
|
|
7077
|
+
headerLeft.appendChild(createElement("input", {
|
|
7078
|
+
className: "bg-transparent font-semibold text-gray-700 dark:text-gray-200 focus:outline-none focus:border-b border-blue-500",
|
|
7079
|
+
value: this.section.title,
|
|
7080
|
+
"data-focus-id": `section-title-${this.section.id}`,
|
|
7081
|
+
oninput: (e) => formStore.getState().updateSection(this.section.id, { title: e.target.value })
|
|
7082
|
+
}));
|
|
7083
|
+
header.appendChild(headerLeft);
|
|
7084
|
+
const actions = createElement("div", { className: "flex items-center space-x-1" });
|
|
7085
|
+
const colSelect = createElement("select", {
|
|
7086
|
+
className: "text-xs border rounded bg-transparent mr-2 p-1 text-gray-600",
|
|
7087
|
+
title: "Section Columns",
|
|
7088
|
+
onchange: (e) => {
|
|
7089
|
+
formStore.getState().updateSection(this.section.id, { columns: parseInt(e.target.value) });
|
|
7090
|
+
}
|
|
7091
|
+
});
|
|
7092
|
+
[1, 2, 3].forEach((c) => {
|
|
7093
|
+
colSelect.appendChild(createElement("option", { value: c.toString(), text: `${c} Col`, selected: (this.section.columns || 1) === c }));
|
|
7094
|
+
});
|
|
7095
|
+
actions.appendChild(colSelect);
|
|
7096
|
+
actions.appendChild(createElement("button", {
|
|
7097
|
+
className: "text-gray-600 hover:text-red-500 transition-colors p-1",
|
|
7098
|
+
onclick: () => {
|
|
7099
|
+
if (confirm("Delete this section and all its fields?")) {
|
|
7100
|
+
formStore.getState().removeSection(this.section.id);
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
}, [getIcon("Trash2", 18)]));
|
|
7104
|
+
header.appendChild(actions);
|
|
7105
|
+
sectionEl.appendChild(header);
|
|
7106
|
+
const fieldsGrid = createElement("div", {
|
|
7107
|
+
className: "form-builder-grid p-4 min-h-[100px] fields-list",
|
|
7108
|
+
"data-section-id": this.section.id
|
|
7109
|
+
});
|
|
7110
|
+
if (this.section.fields.length === 0) {
|
|
7111
|
+
fieldsGrid.classList.add("flex", "justify-center", "items-center", "border-2", "border-dashed", "border-gray-100", "dark:border-gray-800", "m-4", "rounded");
|
|
7112
|
+
fieldsGrid.appendChild(createElement("div", { className: "text-gray-400 text-sm py-4", text: "Drop fields here" }));
|
|
7113
|
+
}
|
|
7114
|
+
this.section.fields.forEach((field) => {
|
|
7115
|
+
const isSelected = this.isSelectedField(field.id);
|
|
7116
|
+
fieldsGrid.appendChild(FieldWrapper.render(field, isSelected));
|
|
7117
|
+
});
|
|
7118
|
+
sectionEl.appendChild(fieldsGrid);
|
|
7119
|
+
this.initFieldSortable(fieldsGrid);
|
|
7120
|
+
return sectionEl;
|
|
7121
|
+
}
|
|
7122
|
+
initFieldSortable(element) {
|
|
7123
|
+
new sortable_esm_default(element, {
|
|
7124
|
+
group: {
|
|
7125
|
+
name: "shared-fields",
|
|
7126
|
+
put: ["shared-fields", "shared-templates"]
|
|
7127
|
+
// Allow dropping templates to merge fields
|
|
7128
|
+
},
|
|
7129
|
+
handle: ".field-handle",
|
|
7130
|
+
animation: 150,
|
|
7131
|
+
ghostClass: "bg-blue-50",
|
|
7132
|
+
// Class to apply to the drag ghost
|
|
7133
|
+
onAdd: (evt) => {
|
|
7134
|
+
const item = evt.item;
|
|
7135
|
+
const type = item.getAttribute("data-type");
|
|
7136
|
+
evt.from.getAttribute("data-section-id");
|
|
7137
|
+
const toSectionId = this.section.id;
|
|
7138
|
+
if (type && !item.hasAttribute("data-id")) {
|
|
7139
|
+
item.remove();
|
|
7140
|
+
if (type === "template-section") {
|
|
7141
|
+
const templateId = item.getAttribute("data-template-id");
|
|
7142
|
+
const templates = formStore.getState().templates;
|
|
7143
|
+
const template = templates.find((t) => t.id === templateId);
|
|
7144
|
+
if (template) {
|
|
7145
|
+
formStore.getState().addTemplateFields(toSectionId, template, evt.newIndex);
|
|
7146
|
+
}
|
|
7147
|
+
return;
|
|
7148
|
+
}
|
|
7149
|
+
formStore.getState().addField(toSectionId, type, evt.newIndex);
|
|
7150
|
+
} else {
|
|
7151
|
+
const fieldId = item.getAttribute("data-id");
|
|
7152
|
+
if (fieldId) {
|
|
7153
|
+
formStore.getState().moveField(fieldId, toSectionId, evt.newIndex);
|
|
7154
|
+
item.remove();
|
|
7155
|
+
}
|
|
7156
|
+
}
|
|
7157
|
+
},
|
|
7158
|
+
onUpdate: (evt) => {
|
|
7159
|
+
const item = evt.item;
|
|
7160
|
+
const fieldId = item.getAttribute("data-id");
|
|
7161
|
+
if (fieldId && evt.newIndex !== void 0) {
|
|
7162
|
+
formStore.getState().moveField(fieldId, this.section.id, evt.newIndex);
|
|
7163
|
+
}
|
|
7164
|
+
}
|
|
7165
|
+
});
|
|
7166
|
+
}
|
|
7167
|
+
};
|
|
7168
|
+
|
|
7169
|
+
// src/builder/SectionList.ts
|
|
7170
|
+
var SectionList = class {
|
|
7171
|
+
constructor(schema, selectedFieldId) {
|
|
7172
|
+
__publicField(this, "container");
|
|
7173
|
+
__publicField(this, "schema");
|
|
7174
|
+
__publicField(this, "selectedFieldId");
|
|
7175
|
+
this.schema = schema;
|
|
7176
|
+
this.selectedFieldId = selectedFieldId;
|
|
7177
|
+
this.container = this.render();
|
|
7178
|
+
}
|
|
7179
|
+
getElement() {
|
|
7180
|
+
return this.container;
|
|
7181
|
+
}
|
|
7182
|
+
render() {
|
|
7183
|
+
const listContainer = createElement("div", {
|
|
7184
|
+
className: "space-y-6 min-h-[200px] pb-20",
|
|
7185
|
+
// pb-20 for extra scrolling space
|
|
7186
|
+
id: "sections-list",
|
|
7187
|
+
"data-drop-zone": "sections"
|
|
7188
|
+
});
|
|
7189
|
+
const hasNoSections = this.schema.sections.length === 0;
|
|
7190
|
+
if (hasNoSections) {
|
|
7191
|
+
const placeholder = createElement("div", {
|
|
7192
|
+
className: "border-2 border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-8 text-center text-gray-500 flex flex-col items-center justify-center min-h-[200px] bg-gray-50 dark:bg-gray-800/50 empty-fields-dropzone",
|
|
7193
|
+
id: "empty-fields-dropzone"
|
|
7194
|
+
});
|
|
7195
|
+
placeholder.appendChild(createElement("div", { className: "font-medium mb-2", text: "Start Building Your Form" }));
|
|
7196
|
+
placeholder.appendChild(createElement("div", { className: "text-sm text-gray-400", text: 'Drag fields from the sidebar or click "Add Section" below.' }));
|
|
7197
|
+
listContainer.appendChild(placeholder);
|
|
7198
|
+
}
|
|
7199
|
+
this.schema.sections.forEach((section) => {
|
|
7200
|
+
const sectionComponent = new Section(section, (id) => id === this.selectedFieldId);
|
|
7201
|
+
listContainer.appendChild(sectionComponent.getElement());
|
|
7202
|
+
});
|
|
7203
|
+
this.initSectionSortable(listContainer, hasNoSections);
|
|
7204
|
+
return listContainer;
|
|
7205
|
+
}
|
|
7206
|
+
initSectionSortable(element, hasNoSections) {
|
|
7207
|
+
if (hasNoSections) {
|
|
7208
|
+
const emptyDropzone = element.querySelector("#empty-fields-dropzone");
|
|
7209
|
+
if (emptyDropzone) {
|
|
7210
|
+
new sortable_esm_default(emptyDropzone, {
|
|
7211
|
+
group: {
|
|
7212
|
+
name: "shared-fields",
|
|
7213
|
+
put: ["shared-fields", "shared-templates"]
|
|
7214
|
+
},
|
|
7215
|
+
animation: 150,
|
|
7216
|
+
ghostClass: "bg-blue-50",
|
|
7217
|
+
onAdd: (evt) => {
|
|
7218
|
+
const item = evt.item;
|
|
7219
|
+
const type = item.getAttribute("data-type");
|
|
7220
|
+
const templateId = item.getAttribute("data-template-id");
|
|
7221
|
+
item.remove();
|
|
7222
|
+
if (templateId) {
|
|
7223
|
+
const templates = formStore.getState().templates;
|
|
7224
|
+
const template = templates.find((t) => t.id === templateId);
|
|
7225
|
+
if (template) {
|
|
7226
|
+
formStore.getState().importSection(template);
|
|
7227
|
+
}
|
|
7228
|
+
} else if (type && !item.hasAttribute("data-id")) {
|
|
7229
|
+
formStore.getState().addField(null, type, evt.newIndex);
|
|
7230
|
+
} else {
|
|
7231
|
+
const fieldId = item.getAttribute("data-id");
|
|
7232
|
+
if (fieldId) {
|
|
7233
|
+
formStore.getState().moveField(fieldId, null, evt.newIndex || 0);
|
|
7234
|
+
}
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
});
|
|
7238
|
+
}
|
|
7239
|
+
} else {
|
|
7240
|
+
new sortable_esm_default(element, {
|
|
7241
|
+
group: {
|
|
7242
|
+
name: "shared-sections",
|
|
7243
|
+
put: ["shared-templates"]
|
|
7244
|
+
// Allow dropping templates here
|
|
7245
|
+
},
|
|
7246
|
+
handle: ".section-handle",
|
|
7247
|
+
animation: 150,
|
|
7248
|
+
ghostClass: "opacity-50",
|
|
7249
|
+
onAdd: (evt) => {
|
|
7250
|
+
const item = evt.item;
|
|
7251
|
+
const templateId = item.getAttribute("data-template-id");
|
|
7252
|
+
if (templateId) {
|
|
7253
|
+
const templates = formStore.getState().templates;
|
|
7254
|
+
const template = templates.find((t) => t.id === templateId);
|
|
7255
|
+
item.remove();
|
|
7256
|
+
if (template) {
|
|
7257
|
+
formStore.getState().importSection(template);
|
|
7258
|
+
}
|
|
7259
|
+
}
|
|
7260
|
+
},
|
|
7261
|
+
onUpdate: (evt) => {
|
|
7262
|
+
if (evt.oldIndex !== void 0 && evt.newIndex !== void 0) {
|
|
7263
|
+
formStore.getState().moveSection(evt.oldIndex, evt.newIndex);
|
|
7264
|
+
}
|
|
7265
|
+
}
|
|
7266
|
+
});
|
|
7267
|
+
}
|
|
7268
|
+
}
|
|
7269
|
+
};
|
|
7270
|
+
|
|
6905
7271
|
// src/builder/FormBuilder.ts
|
|
6906
7272
|
var FormBuilder = class {
|
|
6907
7273
|
constructor(container, options = {}) {
|
|
@@ -6935,6 +7301,9 @@ var FormBuilder = class {
|
|
|
6935
7301
|
if (options.formJson) {
|
|
6936
7302
|
formStore.getState().setSchema(options.formJson);
|
|
6937
7303
|
} else if (options.mode === "create") ;
|
|
7304
|
+
if (options.data?.masterTypes) {
|
|
7305
|
+
formStore.getState().setMasterTypes(options.data.masterTypes);
|
|
7306
|
+
}
|
|
6938
7307
|
this.render();
|
|
6939
7308
|
this.setupSubscriptions();
|
|
6940
7309
|
}
|
|
@@ -7039,7 +7408,7 @@ var FormBuilder = class {
|
|
|
7039
7408
|
}, 0);
|
|
7040
7409
|
}
|
|
7041
7410
|
if (!state.isPreviewMode) {
|
|
7042
|
-
this.
|
|
7411
|
+
this.initSidebarSortables();
|
|
7043
7412
|
}
|
|
7044
7413
|
}
|
|
7045
7414
|
renderToolbar(state) {
|
|
@@ -7236,98 +7605,8 @@ var FormBuilder = class {
|
|
|
7236
7605
|
oninput: (e) => formStore.getState().setSchema({ ...state.schema, formName: e.target.value })
|
|
7237
7606
|
});
|
|
7238
7607
|
inner.appendChild(formNameInput);
|
|
7239
|
-
const
|
|
7240
|
-
|
|
7241
|
-
id: "sections-list",
|
|
7242
|
-
"data-drop-zone": "sections"
|
|
7243
|
-
});
|
|
7244
|
-
state.schema.sections.forEach((section) => {
|
|
7245
|
-
const sectionEl = createElement("div", {
|
|
7246
|
-
className: "mb-6 rounded-lg border bg-white dark:bg-gray-900 shadow-sm transition-all border-gray-200 dark:border-gray-800",
|
|
7247
|
-
"data-id": section.id
|
|
7248
|
-
});
|
|
7249
|
-
const header = createElement("div", { className: "flex items-center justify-between p-2 border-b border-gray-100 dark:border-gray-800 bg-gray-50 dark:bg-gray-800/50 rounded-t-lg" });
|
|
7250
|
-
const headerLeft = createElement("div", { className: "flex items-center flex-1" });
|
|
7251
|
-
headerLeft.appendChild(createElement("div", { className: "cursor-move mr-3 text-gray-400 hover:text-gray-600 section-handle" }, [getIcon("GripVertical", 20)]));
|
|
7252
|
-
headerLeft.appendChild(createElement("input", {
|
|
7253
|
-
className: "bg-transparent font-semibold text-gray-700 dark:text-gray-200 focus:outline-none focus:border-b border-blue-500",
|
|
7254
|
-
value: section.title,
|
|
7255
|
-
"data-focus-id": `section-title-${section.id}`,
|
|
7256
|
-
oninput: (e) => formStore.getState().updateSection(section.id, { title: e.target.value })
|
|
7257
|
-
}));
|
|
7258
|
-
header.appendChild(headerLeft);
|
|
7259
|
-
const actions = createElement("div", { className: "flex items-center space-x-1" });
|
|
7260
|
-
const colSelect = createElement("select", {
|
|
7261
|
-
className: "text-xs border rounded bg-transparent mr-2 p-1 text-gray-600",
|
|
7262
|
-
title: "Section Columns",
|
|
7263
|
-
onchange: (e) => {
|
|
7264
|
-
formStore.getState().updateSection(section.id, { columns: parseInt(e.target.value) });
|
|
7265
|
-
}
|
|
7266
|
-
});
|
|
7267
|
-
[1, 2, 3].forEach((c) => {
|
|
7268
|
-
colSelect.appendChild(createElement("option", { value: c.toString(), text: `${c} Col`, selected: (section.columns || 1) === c }));
|
|
7269
|
-
});
|
|
7270
|
-
actions.appendChild(colSelect);
|
|
7271
|
-
actions.appendChild(createElement("button", {
|
|
7272
|
-
className: "text-gray-600 hover:text-blue-500 transition-colors p-1",
|
|
7273
|
-
title: "Save as Template",
|
|
7274
|
-
onclick: () => {
|
|
7275
|
-
const name = prompt("Enter template name:", section.title);
|
|
7276
|
-
if (name) {
|
|
7277
|
-
this.saveSectionAsTemplate({ ...section, title: name });
|
|
7278
|
-
}
|
|
7279
|
-
}
|
|
7280
|
-
}, [getIcon("Save", 18)]));
|
|
7281
|
-
actions.appendChild(createElement("button", {
|
|
7282
|
-
className: "text-gray-600 hover:text-red-500 transition-colors p-1",
|
|
7283
|
-
onclick: () => formStore.getState().removeSection(section.id)
|
|
7284
|
-
}, [getIcon("Trash2", 18)]));
|
|
7285
|
-
header.appendChild(actions);
|
|
7286
|
-
sectionEl.appendChild(header);
|
|
7287
|
-
const fieldsGrid = createElement("div", {
|
|
7288
|
-
className: "form-builder-grid p-4 min-h-[100px] fields-list",
|
|
7289
|
-
"data-section-id": section.id
|
|
7290
|
-
});
|
|
7291
|
-
section.fields.forEach((field) => {
|
|
7292
|
-
const isSelected = state.selectedFieldId === field.id;
|
|
7293
|
-
let spanClass = "col-span-12";
|
|
7294
|
-
if (field.width === "50%")
|
|
7295
|
-
spanClass = "col-span-6";
|
|
7296
|
-
else if (field.width === "33%")
|
|
7297
|
-
spanClass = "col-span-4";
|
|
7298
|
-
else if (field.width === "25%")
|
|
7299
|
-
spanClass = "col-span-3";
|
|
7300
|
-
else if (field.width === "66%")
|
|
7301
|
-
spanClass = "col-span-8";
|
|
7302
|
-
else if (field.width === "75%")
|
|
7303
|
-
spanClass = "col-span-9";
|
|
7304
|
-
const fieldWrapper = createElement("div", {
|
|
7305
|
-
className: `form-builder-field-wrapper ${isSelected ? "selected-field" : ""} ${spanClass}`,
|
|
7306
|
-
"data-id": field.id,
|
|
7307
|
-
onclick: (e) => {
|
|
7308
|
-
e.stopPropagation();
|
|
7309
|
-
formStore.getState().selectField(field.id);
|
|
7310
|
-
}
|
|
7311
|
-
});
|
|
7312
|
-
fieldWrapper.appendChild(createElement("div", {
|
|
7313
|
-
className: `absolute top-2 left-2 cursor-move p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity field-handle ${isSelected ? "opacity-100" : ""}`
|
|
7314
|
-
}, [getIcon("GripVertical", 16)]));
|
|
7315
|
-
fieldWrapper.appendChild(createElement("button", {
|
|
7316
|
-
className: `absolute top-2 right-2 p-1 rounded hover:bg-red-50 text-red-400 hover:text-red-600 opacity-0 group-hover:opacity-100 transition-opacity ${isSelected ? "opacity-100" : ""}`,
|
|
7317
|
-
onclick: (e) => {
|
|
7318
|
-
e.stopPropagation();
|
|
7319
|
-
formStore.getState().removeField(field.id);
|
|
7320
|
-
}
|
|
7321
|
-
}, [getIcon("Trash2", 16)]));
|
|
7322
|
-
const content = createElement("div", { className: "p-4 pointer-events-none" });
|
|
7323
|
-
content.appendChild(FieldRenderer.render(field, null, void 0, true));
|
|
7324
|
-
fieldWrapper.appendChild(content);
|
|
7325
|
-
fieldsGrid.appendChild(fieldWrapper);
|
|
7326
|
-
});
|
|
7327
|
-
sectionEl.appendChild(fieldsGrid);
|
|
7328
|
-
sectionsContainer.appendChild(sectionEl);
|
|
7329
|
-
});
|
|
7330
|
-
inner.appendChild(sectionsContainer);
|
|
7608
|
+
const sectionList = new SectionList(state.schema, state.selectedFieldId);
|
|
7609
|
+
inner.appendChild(sectionList.getElement());
|
|
7331
7610
|
const addSectionBtn = createElement("button", {
|
|
7332
7611
|
className: "w-full mt-6 py-4 border-2 border-dashed border-gray-300 dark:border-gray-700 rounded-lg text-gray-500 hover:border-blue-500 hover:text-blue-500 transition-colors flex items-center justify-center font-medium",
|
|
7333
7612
|
onclick: () => formStore.getState().addSection()
|
|
@@ -7389,6 +7668,101 @@ var FormBuilder = class {
|
|
|
7389
7668
|
onchange: (e) => formStore.getState().updateField(selectedField.id, { required: e.target.checked })
|
|
7390
7669
|
}));
|
|
7391
7670
|
body.appendChild(requiredGroup);
|
|
7671
|
+
const enabledGroup = createElement("div", { className: "flex items-center justify-between mb-4" });
|
|
7672
|
+
enabledGroup.appendChild(createElement("label", { className: "text-sm text-gray-700 dark:text-gray-300", text: "Enabled" }));
|
|
7673
|
+
enabledGroup.appendChild(createElement("input", {
|
|
7674
|
+
type: "checkbox",
|
|
7675
|
+
className: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",
|
|
7676
|
+
checked: selectedField.enabled !== false,
|
|
7677
|
+
// Default to true if not specified
|
|
7678
|
+
onchange: (e) => formStore.getState().updateField(selectedField.id, { enabled: e.target.checked })
|
|
7679
|
+
}));
|
|
7680
|
+
body.appendChild(enabledGroup);
|
|
7681
|
+
const visibleGroup = createElement("div", { className: "flex items-center justify-between mb-4" });
|
|
7682
|
+
visibleGroup.appendChild(createElement("label", { className: "text-sm text-gray-700 dark:text-gray-300", text: "Visible" }));
|
|
7683
|
+
visibleGroup.appendChild(createElement("input", {
|
|
7684
|
+
type: "checkbox",
|
|
7685
|
+
className: "h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",
|
|
7686
|
+
checked: selectedField.visible !== false,
|
|
7687
|
+
// Default to true if not specified
|
|
7688
|
+
onchange: (e) => formStore.getState().updateField(selectedField.id, { visible: e.target.checked })
|
|
7689
|
+
}));
|
|
7690
|
+
body.appendChild(visibleGroup);
|
|
7691
|
+
if (selectedField.type === "select") {
|
|
7692
|
+
const masterTypes = formStore.getState().masterTypes;
|
|
7693
|
+
const activeMasterTypes = masterTypes.filter((mt) => mt.active === true);
|
|
7694
|
+
const convertIndexesToOptions = (indexes) => {
|
|
7695
|
+
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
7696
|
+
return [];
|
|
7697
|
+
}
|
|
7698
|
+
return indexes.map((item, index2) => {
|
|
7699
|
+
if (typeof item === "string") {
|
|
7700
|
+
return { label: item, value: item };
|
|
7701
|
+
}
|
|
7702
|
+
if (typeof item === "object" && item !== null) {
|
|
7703
|
+
const label = item.label || item.name || item.displayName || item.text || `Option ${index2 + 1}`;
|
|
7704
|
+
const value = item.value || item.id || item.name || String(index2);
|
|
7705
|
+
return { label, value };
|
|
7706
|
+
}
|
|
7707
|
+
return { label: String(item), value: String(item) };
|
|
7708
|
+
});
|
|
7709
|
+
};
|
|
7710
|
+
if (activeMasterTypes.length > 0) {
|
|
7711
|
+
const groupNameGroup = createElement("div", { className: "mb-4" });
|
|
7712
|
+
groupNameGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Group Name" }));
|
|
7713
|
+
const groupNameSelect = createElement("select", {
|
|
7714
|
+
className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
|
|
7715
|
+
onchange: (e) => {
|
|
7716
|
+
const selectedValue = e.target.value;
|
|
7717
|
+
if (selectedValue) {
|
|
7718
|
+
const selectedMasterType = activeMasterTypes.find((mt) => mt.id === selectedValue || mt.name === selectedValue);
|
|
7719
|
+
if (selectedMasterType) {
|
|
7720
|
+
const options = convertIndexesToOptions(selectedMasterType.indexes || []);
|
|
7721
|
+
formStore.getState().updateField(selectedField.id, {
|
|
7722
|
+
groupName: {
|
|
7723
|
+
id: selectedMasterType.id,
|
|
7724
|
+
name: selectedMasterType.name
|
|
7725
|
+
},
|
|
7726
|
+
options: options.length > 0 ? options : void 0
|
|
7727
|
+
});
|
|
7728
|
+
}
|
|
7729
|
+
} else {
|
|
7730
|
+
formStore.getState().updateField(selectedField.id, {
|
|
7731
|
+
groupName: void 0,
|
|
7732
|
+
options: void 0
|
|
7733
|
+
// Clear options when groupName is cleared
|
|
7734
|
+
});
|
|
7735
|
+
}
|
|
7736
|
+
}
|
|
7737
|
+
});
|
|
7738
|
+
groupNameSelect.appendChild(createElement("option", {
|
|
7739
|
+
value: "",
|
|
7740
|
+
text: "None",
|
|
7741
|
+
selected: !selectedField.groupName
|
|
7742
|
+
}));
|
|
7743
|
+
activeMasterTypes.forEach((mt) => {
|
|
7744
|
+
const isSelected = selectedField.groupName && (selectedField.groupName.id === mt.id || selectedField.groupName.name === mt.name);
|
|
7745
|
+
groupNameSelect.appendChild(createElement("option", {
|
|
7746
|
+
value: mt.id || mt.name,
|
|
7747
|
+
text: mt.displayName || mt.name,
|
|
7748
|
+
selected: !!isSelected
|
|
7749
|
+
}));
|
|
7750
|
+
});
|
|
7751
|
+
groupNameGroup.appendChild(groupNameSelect);
|
|
7752
|
+
body.appendChild(groupNameGroup);
|
|
7753
|
+
if (selectedField.groupName && (!selectedField.options || selectedField.options.length === 0)) {
|
|
7754
|
+
const currentMasterType = activeMasterTypes.find(
|
|
7755
|
+
(mt) => mt.id === selectedField.groupName?.id || mt.name === selectedField.groupName?.name
|
|
7756
|
+
);
|
|
7757
|
+
if (currentMasterType && currentMasterType.indexes && currentMasterType.indexes.length > 0) {
|
|
7758
|
+
const options = convertIndexesToOptions(currentMasterType.indexes);
|
|
7759
|
+
if (options.length > 0) {
|
|
7760
|
+
formStore.getState().updateField(selectedField.id, { options });
|
|
7761
|
+
}
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
}
|
|
7392
7766
|
const validationHeader = createElement("h3", { className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6", text: "Validation Rules" });
|
|
7393
7767
|
body.appendChild(validationHeader);
|
|
7394
7768
|
const validations = selectedField.validation || [];
|
|
@@ -7515,12 +7889,13 @@ var FormBuilder = class {
|
|
|
7515
7889
|
panel.appendChild(body);
|
|
7516
7890
|
return panel;
|
|
7517
7891
|
}
|
|
7518
|
-
|
|
7892
|
+
initSidebarSortables() {
|
|
7519
7893
|
const toolboxList = document.getElementById("toolbox-list");
|
|
7520
7894
|
if (toolboxList) {
|
|
7521
7895
|
new sortable_esm_default(toolboxList, {
|
|
7522
7896
|
group: {
|
|
7523
|
-
name: "shared",
|
|
7897
|
+
name: "shared-fields",
|
|
7898
|
+
// Matches the group in Section.ts
|
|
7524
7899
|
pull: "clone",
|
|
7525
7900
|
put: false
|
|
7526
7901
|
},
|
|
@@ -7532,7 +7907,7 @@ var FormBuilder = class {
|
|
|
7532
7907
|
if (templatesList) {
|
|
7533
7908
|
new sortable_esm_default(templatesList, {
|
|
7534
7909
|
group: {
|
|
7535
|
-
name: "shared",
|
|
7910
|
+
name: "shared-templates",
|
|
7536
7911
|
pull: "clone",
|
|
7537
7912
|
put: false
|
|
7538
7913
|
},
|
|
@@ -7542,85 +7917,6 @@ var FormBuilder = class {
|
|
|
7542
7917
|
forceFallback: true
|
|
7543
7918
|
});
|
|
7544
7919
|
}
|
|
7545
|
-
const sectionsList = document.getElementById("sections-list");
|
|
7546
|
-
if (sectionsList) {
|
|
7547
|
-
new sortable_esm_default(sectionsList, {
|
|
7548
|
-
group: "shared",
|
|
7549
|
-
handle: ".section-handle",
|
|
7550
|
-
animation: 150,
|
|
7551
|
-
onAdd: (evt) => {
|
|
7552
|
-
const item = evt.item;
|
|
7553
|
-
const templateId = item.getAttribute("data-template-id");
|
|
7554
|
-
const isTemplate = item.getAttribute("data-type") === "template-section";
|
|
7555
|
-
if (templateId && isTemplate) {
|
|
7556
|
-
const templates = formStore.getState().templates;
|
|
7557
|
-
const template = templates.find((t) => t.id === templateId);
|
|
7558
|
-
if (template) {
|
|
7559
|
-
item.remove();
|
|
7560
|
-
formStore.getState().importSection(template);
|
|
7561
|
-
return;
|
|
7562
|
-
}
|
|
7563
|
-
}
|
|
7564
|
-
},
|
|
7565
|
-
onEnd: (evt) => {
|
|
7566
|
-
const item = evt.item;
|
|
7567
|
-
const templateId = item.getAttribute("data-template-id");
|
|
7568
|
-
const isTemplate = item.getAttribute("data-type") === "template-section";
|
|
7569
|
-
if (!templateId && !isTemplate && evt.oldIndex !== void 0 && evt.newIndex !== void 0 && evt.oldIndex !== evt.newIndex) {
|
|
7570
|
-
formStore.getState().moveSection(evt.oldIndex, evt.newIndex);
|
|
7571
|
-
}
|
|
7572
|
-
}
|
|
7573
|
-
});
|
|
7574
|
-
}
|
|
7575
|
-
const fieldLists = document.querySelectorAll(".fields-list");
|
|
7576
|
-
fieldLists.forEach((list) => {
|
|
7577
|
-
new sortable_esm_default(list, {
|
|
7578
|
-
group: "shared",
|
|
7579
|
-
handle: ".field-handle",
|
|
7580
|
-
animation: 150,
|
|
7581
|
-
onAdd: (evt) => {
|
|
7582
|
-
const item = evt.item;
|
|
7583
|
-
const type = item.getAttribute("data-type");
|
|
7584
|
-
const sectionId = list.getAttribute("data-section-id");
|
|
7585
|
-
if (type && sectionId) {
|
|
7586
|
-
if (type === "template-section") {
|
|
7587
|
-
const templateId = item.getAttribute("data-template-id");
|
|
7588
|
-
const templates = formStore.getState().templates;
|
|
7589
|
-
const template = templates.find((t) => t.id === templateId);
|
|
7590
|
-
item.remove();
|
|
7591
|
-
if (template) {
|
|
7592
|
-
formStore.getState().addTemplateFields(sectionId, template, evt.newIndex);
|
|
7593
|
-
}
|
|
7594
|
-
return;
|
|
7595
|
-
}
|
|
7596
|
-
item.remove();
|
|
7597
|
-
formStore.getState().addField(sectionId, type, evt.newIndex);
|
|
7598
|
-
} else if (sectionId) {
|
|
7599
|
-
item.getAttribute("data-id");
|
|
7600
|
-
}
|
|
7601
|
-
},
|
|
7602
|
-
onUpdate: (evt) => {
|
|
7603
|
-
const item = evt.item;
|
|
7604
|
-
const fieldId = item.getAttribute("data-id");
|
|
7605
|
-
const sectionId = list.getAttribute("data-section-id");
|
|
7606
|
-
if (fieldId && sectionId && evt.newIndex !== void 0) {
|
|
7607
|
-
formStore.getState().moveField(fieldId, sectionId, evt.newIndex);
|
|
7608
|
-
}
|
|
7609
|
-
},
|
|
7610
|
-
onEnd: (evt) => {
|
|
7611
|
-
const item = evt.item;
|
|
7612
|
-
const fromList = evt.from;
|
|
7613
|
-
const toList = evt.to;
|
|
7614
|
-
if (fromList !== toList && fromList.classList.contains("fields-list") && toList.classList.contains("fields-list")) {
|
|
7615
|
-
const fieldId = item.getAttribute("data-id");
|
|
7616
|
-
const targetSectionId = toList.getAttribute("data-section-id");
|
|
7617
|
-
if (fieldId && targetSectionId && evt.newIndex !== void 0) {
|
|
7618
|
-
formStore.getState().moveField(fieldId, targetSectionId, evt.newIndex);
|
|
7619
|
-
}
|
|
7620
|
-
}
|
|
7621
|
-
}
|
|
7622
|
-
});
|
|
7623
|
-
});
|
|
7624
7920
|
}
|
|
7625
7921
|
};
|
|
7626
7922
|
|