form-builder-pro 1.0.7 → 1.0.9
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 +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +75 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4150,6 +4150,64 @@ var cloneField = (field) => {
|
|
|
4150
4150
|
};
|
|
4151
4151
|
};
|
|
4152
4152
|
|
|
4153
|
+
// src/utils/mapper.ts
|
|
4154
|
+
var cleanFormSchema = (schema) => {
|
|
4155
|
+
const cleanField = (field) => {
|
|
4156
|
+
const cleaned = {
|
|
4157
|
+
id: field.id,
|
|
4158
|
+
type: field.type === "decimal" ? "number" : field.type,
|
|
4159
|
+
// Convert decimal to number
|
|
4160
|
+
label: field.label,
|
|
4161
|
+
width: field.width
|
|
4162
|
+
};
|
|
4163
|
+
if (field.placeholder !== void 0)
|
|
4164
|
+
cleaned.placeholder = field.placeholder;
|
|
4165
|
+
if (field.description !== void 0)
|
|
4166
|
+
cleaned.description = field.description;
|
|
4167
|
+
if (field.required !== void 0)
|
|
4168
|
+
cleaned.required = field.required;
|
|
4169
|
+
if (field.defaultValue !== void 0)
|
|
4170
|
+
cleaned.defaultValue = field.defaultValue;
|
|
4171
|
+
if (field.validation !== void 0)
|
|
4172
|
+
cleaned.validation = field.validation;
|
|
4173
|
+
if (field.hidden !== void 0)
|
|
4174
|
+
cleaned.hidden = field.hidden;
|
|
4175
|
+
if (field.position !== void 0)
|
|
4176
|
+
cleaned.position = field.position;
|
|
4177
|
+
if (field.enabled !== void 0)
|
|
4178
|
+
cleaned.enabled = field.enabled;
|
|
4179
|
+
if (field.visible !== void 0)
|
|
4180
|
+
cleaned.visible = field.visible;
|
|
4181
|
+
if (field.optionsSource !== void 0)
|
|
4182
|
+
cleaned.optionsSource = field.optionsSource;
|
|
4183
|
+
if ((field.type === "select" || field.type === "radio") && field.options) {
|
|
4184
|
+
cleaned.options = field.options;
|
|
4185
|
+
}
|
|
4186
|
+
if (field.type === "select" && field.groupName) {
|
|
4187
|
+
cleaned.groupName = field.groupName;
|
|
4188
|
+
}
|
|
4189
|
+
return cleaned;
|
|
4190
|
+
};
|
|
4191
|
+
return {
|
|
4192
|
+
id: schema.id,
|
|
4193
|
+
title: schema.title,
|
|
4194
|
+
formName: schema.formName,
|
|
4195
|
+
sections: schema.sections.map((section) => ({
|
|
4196
|
+
id: section.id,
|
|
4197
|
+
title: section.title,
|
|
4198
|
+
fields: section.fields.map(cleanField),
|
|
4199
|
+
isExpanded: section.isExpanded,
|
|
4200
|
+
columns: section.columns
|
|
4201
|
+
}))
|
|
4202
|
+
};
|
|
4203
|
+
};
|
|
4204
|
+
var builderToPlatform = (builderSchema) => {
|
|
4205
|
+
return builderSchema;
|
|
4206
|
+
};
|
|
4207
|
+
var platformToBuilder = (platformSchema) => {
|
|
4208
|
+
return cleanFormSchema(platformSchema);
|
|
4209
|
+
};
|
|
4210
|
+
|
|
4153
4211
|
// src/core/useFormStore.ts
|
|
4154
4212
|
var INITIAL_SCHEMA = {
|
|
4155
4213
|
id: "form_1",
|
|
@@ -4168,6 +4226,7 @@ var formStore = createStore((set, get) => ({
|
|
|
4168
4226
|
masterTypes: [],
|
|
4169
4227
|
dropdownOptionsMap: {},
|
|
4170
4228
|
setSchema: (schema) => {
|
|
4229
|
+
const cleanedSchema = cleanFormSchema(schema);
|
|
4171
4230
|
const convertIndexesToOptions = (indexes) => {
|
|
4172
4231
|
if (!indexes || !Array.isArray(indexes) || indexes.length === 0) {
|
|
4173
4232
|
return [];
|
|
@@ -4192,8 +4251,8 @@ var formStore = createStore((set, get) => ({
|
|
|
4192
4251
|
);
|
|
4193
4252
|
};
|
|
4194
4253
|
const state = get();
|
|
4195
|
-
if (state.masterTypes && state.masterTypes.length > 0 &&
|
|
4196
|
-
const updatedSections =
|
|
4254
|
+
if (state.masterTypes && state.masterTypes.length > 0 && cleanedSchema.sections) {
|
|
4255
|
+
const updatedSections = cleanedSchema.sections.map((section) => ({
|
|
4197
4256
|
...section,
|
|
4198
4257
|
fields: section.fields.map((field) => {
|
|
4199
4258
|
if (field.type === "select" && field.groupName) {
|
|
@@ -4226,9 +4285,9 @@ var formStore = createStore((set, get) => ({
|
|
|
4226
4285
|
return field;
|
|
4227
4286
|
})
|
|
4228
4287
|
}));
|
|
4229
|
-
set({ schema: { ...
|
|
4288
|
+
set({ schema: { ...cleanedSchema, sections: updatedSections } });
|
|
4230
4289
|
} else {
|
|
4231
|
-
set({ schema });
|
|
4290
|
+
set({ schema: cleanedSchema });
|
|
4232
4291
|
}
|
|
4233
4292
|
},
|
|
4234
4293
|
togglePreview: () => {
|
|
@@ -7992,8 +8051,6 @@ var FormBuilder = class {
|
|
|
7992
8051
|
}
|
|
7993
8052
|
}
|
|
7994
8053
|
}
|
|
7995
|
-
const validationHeader = createElement("h3", { className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6", text: "Validation Rules" });
|
|
7996
|
-
body.appendChild(validationHeader);
|
|
7997
8054
|
const validations = selectedField.validation || [];
|
|
7998
8055
|
const updateValidation = (rule) => {
|
|
7999
8056
|
const newValidations = validations.filter((v) => v.type !== rule.type);
|
|
@@ -8003,6 +8060,7 @@ var FormBuilder = class {
|
|
|
8003
8060
|
formStore.getState().updateField(selectedField.id, { validation: newValidations });
|
|
8004
8061
|
};
|
|
8005
8062
|
const getRuleValue = (type) => validations.find((v) => v.type === type)?.value || "";
|
|
8063
|
+
const validationElements = [];
|
|
8006
8064
|
if (["text", "textarea", "email", "password"].includes(selectedField.type)) {
|
|
8007
8065
|
const minLenGroup = createElement("div", { className: "mb-3" });
|
|
8008
8066
|
minLenGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Min Length" }));
|
|
@@ -8013,7 +8071,7 @@ var FormBuilder = class {
|
|
|
8013
8071
|
placeholder: "e.g. 3",
|
|
8014
8072
|
onchange: (e) => updateValidation({ type: "minLength", value: parseInt(e.target.value) })
|
|
8015
8073
|
}));
|
|
8016
|
-
|
|
8074
|
+
validationElements.push(minLenGroup);
|
|
8017
8075
|
const maxLenGroup = createElement("div", { className: "mb-3" });
|
|
8018
8076
|
maxLenGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Max Length" }));
|
|
8019
8077
|
maxLenGroup.appendChild(createElement("input", {
|
|
@@ -8023,7 +8081,7 @@ var FormBuilder = class {
|
|
|
8023
8081
|
placeholder: "e.g. 100",
|
|
8024
8082
|
onchange: (e) => updateValidation({ type: "maxLength", value: parseInt(e.target.value) })
|
|
8025
8083
|
}));
|
|
8026
|
-
|
|
8084
|
+
validationElements.push(maxLenGroup);
|
|
8027
8085
|
const regexGroup = createElement("div", { className: "mb-3" });
|
|
8028
8086
|
regexGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Regex Pattern" }));
|
|
8029
8087
|
regexGroup.appendChild(createElement("input", {
|
|
@@ -8041,7 +8099,7 @@ var FormBuilder = class {
|
|
|
8041
8099
|
formStore.getState().updateField(selectedField.id, { validation: newValidations });
|
|
8042
8100
|
}
|
|
8043
8101
|
}));
|
|
8044
|
-
|
|
8102
|
+
validationElements.push(regexGroup);
|
|
8045
8103
|
}
|
|
8046
8104
|
if (selectedField.type === "number") {
|
|
8047
8105
|
const minValGroup = createElement("div", { className: "mb-3" });
|
|
@@ -8052,7 +8110,7 @@ var FormBuilder = class {
|
|
|
8052
8110
|
value: getRuleValue("min"),
|
|
8053
8111
|
onchange: (e) => updateValidation({ type: "min", value: parseInt(e.target.value) })
|
|
8054
8112
|
}));
|
|
8055
|
-
|
|
8113
|
+
validationElements.push(minValGroup);
|
|
8056
8114
|
const maxValGroup = createElement("div", { className: "mb-3" });
|
|
8057
8115
|
maxValGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Max Value" }));
|
|
8058
8116
|
maxValGroup.appendChild(createElement("input", {
|
|
@@ -8061,59 +8119,12 @@ var FormBuilder = class {
|
|
|
8061
8119
|
value: getRuleValue("max"),
|
|
8062
8120
|
onchange: (e) => updateValidation({ type: "max", value: parseInt(e.target.value) })
|
|
8063
8121
|
}));
|
|
8064
|
-
|
|
8065
|
-
}
|
|
8066
|
-
if (
|
|
8067
|
-
const
|
|
8068
|
-
body.appendChild(
|
|
8069
|
-
|
|
8070
|
-
sourceGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "Source Type" }));
|
|
8071
|
-
const sourceSelect = createElement("select", {
|
|
8072
|
-
className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
|
|
8073
|
-
onchange: (e) => {
|
|
8074
|
-
const isAsync2 = e.target.value === "api";
|
|
8075
|
-
if (isAsync2) {
|
|
8076
|
-
formStore.getState().updateField(selectedField.id, {
|
|
8077
|
-
optionsSource: { api: "https://", method: "GET", labelKey: "name", valueKey: "id" }
|
|
8078
|
-
});
|
|
8079
|
-
} else {
|
|
8080
|
-
formStore.getState().updateField(selectedField.id, { optionsSource: void 0 });
|
|
8081
|
-
}
|
|
8082
|
-
this.render();
|
|
8083
|
-
}
|
|
8084
|
-
});
|
|
8085
|
-
sourceSelect.appendChild(createElement("option", { value: "static", text: "Static Options", selected: !selectedField.optionsSource }));
|
|
8086
|
-
sourceSelect.appendChild(createElement("option", { value: "api", text: "API Endpoint", selected: !!selectedField.optionsSource }));
|
|
8087
|
-
sourceGroup.appendChild(sourceSelect);
|
|
8088
|
-
body.appendChild(sourceGroup);
|
|
8089
|
-
if (selectedField.optionsSource) {
|
|
8090
|
-
const apiGroup = createElement("div", { className: "mb-3" });
|
|
8091
|
-
apiGroup.appendChild(createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", text: "API URL" }));
|
|
8092
|
-
apiGroup.appendChild(createElement("input", {
|
|
8093
|
-
className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent",
|
|
8094
|
-
value: selectedField.optionsSource.api,
|
|
8095
|
-
oninput: (e) => formStore.getState().updateField(selectedField.id, { optionsSource: { ...selectedField.optionsSource, api: e.target.value } })
|
|
8096
|
-
}));
|
|
8097
|
-
body.appendChild(apiGroup);
|
|
8098
|
-
const keysRow = createElement("div", { className: "flex gap-2 mb-3" });
|
|
8099
|
-
const labelKeyGroup = createElement("div", { className: "flex-1" });
|
|
8100
|
-
labelKeyGroup.appendChild(createElement("label", { className: "block text-xs font-medium text-gray-500 mb-1", text: "Label Key" }));
|
|
8101
|
-
labelKeyGroup.appendChild(createElement("input", {
|
|
8102
|
-
className: "w-full px-2 py-1 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent text-sm",
|
|
8103
|
-
value: selectedField.optionsSource.labelKey,
|
|
8104
|
-
oninput: (e) => formStore.getState().updateField(selectedField.id, { optionsSource: { ...selectedField.optionsSource, labelKey: e.target.value } })
|
|
8105
|
-
}));
|
|
8106
|
-
const valueKeyGroup = createElement("div", { className: "flex-1" });
|
|
8107
|
-
valueKeyGroup.appendChild(createElement("label", { className: "block text-xs font-medium text-gray-500 mb-1", text: "Value Key" }));
|
|
8108
|
-
valueKeyGroup.appendChild(createElement("input", {
|
|
8109
|
-
className: "w-full px-2 py-1 border border-gray-300 dark:border-gray-700 rounded-md bg-transparent text-sm",
|
|
8110
|
-
value: selectedField.optionsSource.valueKey,
|
|
8111
|
-
oninput: (e) => formStore.getState().updateField(selectedField.id, { optionsSource: { ...selectedField.optionsSource, valueKey: e.target.value } })
|
|
8112
|
-
}));
|
|
8113
|
-
keysRow.appendChild(labelKeyGroup);
|
|
8114
|
-
keysRow.appendChild(valueKeyGroup);
|
|
8115
|
-
body.appendChild(keysRow);
|
|
8116
|
-
}
|
|
8122
|
+
validationElements.push(maxValGroup);
|
|
8123
|
+
}
|
|
8124
|
+
if (validationElements.length > 0) {
|
|
8125
|
+
const validationHeader = createElement("h3", { className: "text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 mt-6", text: "Validation Rules" });
|
|
8126
|
+
body.appendChild(validationHeader);
|
|
8127
|
+
validationElements.forEach((el) => body.appendChild(el));
|
|
8117
8128
|
}
|
|
8118
8129
|
panel.appendChild(body);
|
|
8119
8130
|
return panel;
|
|
@@ -8149,14 +8160,6 @@ var FormBuilder = class {
|
|
|
8149
8160
|
}
|
|
8150
8161
|
};
|
|
8151
8162
|
|
|
8152
|
-
// src/utils/mapper.ts
|
|
8153
|
-
var builderToPlatform = (builderSchema) => {
|
|
8154
|
-
return builderSchema;
|
|
8155
|
-
};
|
|
8156
|
-
var platformToBuilder = (platformSchema) => {
|
|
8157
|
-
return platformSchema;
|
|
8158
|
-
};
|
|
8159
|
-
|
|
8160
8163
|
// src/index.ts
|
|
8161
8164
|
var initFormBuilder = (options) => {
|
|
8162
8165
|
const container = document.getElementById(options.containerId);
|
|
@@ -8176,6 +8179,6 @@ sortablejs/modular/sortable.esm.js:
|
|
|
8176
8179
|
*)
|
|
8177
8180
|
*/
|
|
8178
8181
|
|
|
8179
|
-
export { FormBuilder, FormRenderer, FormSchemaValidation, builderToPlatform, formStore, initFormBuilder, platformToBuilder };
|
|
8182
|
+
export { FormBuilder, FormRenderer, FormSchemaValidation, builderToPlatform, cleanFormSchema, formStore, initFormBuilder, platformToBuilder };
|
|
8180
8183
|
//# sourceMappingURL=out.js.map
|
|
8181
8184
|
//# sourceMappingURL=index.mjs.map
|