form-builder-pro 0.0.10 → 1.0.1
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 +467 -248
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/dist/index.css.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -162,6 +162,7 @@ interface FormActions {
|
|
|
162
162
|
redo: () => void;
|
|
163
163
|
canUndo: () => boolean;
|
|
164
164
|
canRedo: () => boolean;
|
|
165
|
+
addTemplateFields: (targetSectionId: string, template: FormSection, index?: number) => void;
|
|
165
166
|
}
|
|
166
167
|
declare const formStore: zustand_vanilla.StoreApi<FormState & FormActions>;
|
|
167
168
|
|
package/dist/index.d.ts
CHANGED
|
@@ -162,6 +162,7 @@ interface FormActions {
|
|
|
162
162
|
redo: () => void;
|
|
163
163
|
canUndo: () => boolean;
|
|
164
164
|
canRedo: () => boolean;
|
|
165
|
+
addTemplateFields: (targetSectionId: string, template: FormSection, index?: number) => void;
|
|
165
166
|
}
|
|
166
167
|
declare const formStore: zustand_vanilla.StoreApi<FormState & FormActions>;
|
|
167
168
|
|
package/dist/index.js
CHANGED
|
@@ -4355,6 +4355,29 @@ var formStore = createStore((set, get) => ({
|
|
|
4355
4355
|
historyIndex: historyIndex + 1
|
|
4356
4356
|
});
|
|
4357
4357
|
},
|
|
4358
|
+
addTemplateFields: (targetSectionId, template, index2) => {
|
|
4359
|
+
set((state) => {
|
|
4360
|
+
const sectionIndex = state.schema.sections.findIndex((s) => s.id === targetSectionId);
|
|
4361
|
+
if (sectionIndex === -1)
|
|
4362
|
+
return state;
|
|
4363
|
+
const section = state.schema.sections[sectionIndex];
|
|
4364
|
+
const newFields = template.fields.map(cloneField);
|
|
4365
|
+
const currentFields = [...section.fields];
|
|
4366
|
+
if (typeof index2 === "number" && index2 >= 0) {
|
|
4367
|
+
currentFields.splice(index2, 0, ...newFields);
|
|
4368
|
+
} else {
|
|
4369
|
+
currentFields.push(...newFields);
|
|
4370
|
+
}
|
|
4371
|
+
const newSection = { ...section, fields: currentFields };
|
|
4372
|
+
const newSections = [...state.schema.sections];
|
|
4373
|
+
newSections[sectionIndex] = newSection;
|
|
4374
|
+
return {
|
|
4375
|
+
schema: { ...state.schema, sections: newSections },
|
|
4376
|
+
history: [...state.history.slice(0, state.historyIndex + 1), { ...state.schema, sections: newSections }],
|
|
4377
|
+
historyIndex: state.historyIndex + 1
|
|
4378
|
+
};
|
|
4379
|
+
});
|
|
4380
|
+
},
|
|
4358
4381
|
undo: () => {
|
|
4359
4382
|
const { history, historyIndex } = get();
|
|
4360
4383
|
if (historyIndex > 0) {
|
|
@@ -7554,6 +7577,16 @@ var FormBuilder = class {
|
|
|
7554
7577
|
const type = item.getAttribute("data-type");
|
|
7555
7578
|
const sectionId = list.getAttribute("data-section-id");
|
|
7556
7579
|
if (type && sectionId) {
|
|
7580
|
+
if (type === "template-section") {
|
|
7581
|
+
const templateId = item.getAttribute("data-template-id");
|
|
7582
|
+
const templates = formStore.getState().templates;
|
|
7583
|
+
const template = templates.find((t) => t.id === templateId);
|
|
7584
|
+
item.remove();
|
|
7585
|
+
if (template) {
|
|
7586
|
+
formStore.getState().addTemplateFields(sectionId, template, evt.newIndex);
|
|
7587
|
+
}
|
|
7588
|
+
return;
|
|
7589
|
+
}
|
|
7557
7590
|
item.remove();
|
|
7558
7591
|
formStore.getState().addField(sectionId, type, evt.newIndex);
|
|
7559
7592
|
} else if (sectionId) {
|