@dmitryvim/form-builder 0.2.3 → 0.2.4
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/README.md +7 -0
- package/dist/browser/formbuilder.min.js +29 -29
- package/dist/browser/{formbuilder.v0.2.3.min.js → formbuilder.v0.2.4.min.js} +29 -29
- package/dist/cjs/index.cjs +16 -19
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +16 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +29 -29
- package/dist/types/instance/FormBuilderInstance.d.ts +1 -0
- package/dist/types/types/config.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -2719,6 +2719,7 @@ var defaultConfig = {
|
|
|
2719
2719
|
onUploadError: null,
|
|
2720
2720
|
onDownloadError: null,
|
|
2721
2721
|
debounceMs: 300,
|
|
2722
|
+
verboseErrors: false,
|
|
2722
2723
|
enableFilePreview: true,
|
|
2723
2724
|
maxPreviewSize: "200px",
|
|
2724
2725
|
readonly: false,
|
|
@@ -3018,15 +3019,7 @@ var FormBuilderInstance = class {
|
|
|
3018
3019
|
constructor(config) {
|
|
3019
3020
|
this.instanceId = generateInstanceId();
|
|
3020
3021
|
this.state = createInstanceState(config);
|
|
3021
|
-
if (
|
|
3022
|
-
if (config?.getThumbnail) {
|
|
3023
|
-
const testResult = config.getThumbnail("test-id");
|
|
3024
|
-
if (!(testResult instanceof Promise)) {
|
|
3025
|
-
console.warn(
|
|
3026
|
-
"[form-builder] getThumbnail must be async (return Promise). Wrap your function: async (id) => { ... }"
|
|
3027
|
-
);
|
|
3028
|
-
}
|
|
3029
|
-
}
|
|
3022
|
+
if (this.state.config.verboseErrors) {
|
|
3030
3023
|
if (!globalThis.__formBuilderInstances) {
|
|
3031
3024
|
globalThis.__formBuilderInstances = /* @__PURE__ */ new Set();
|
|
3032
3025
|
}
|
|
@@ -3480,28 +3473,32 @@ var FormBuilderInstance = class {
|
|
|
3480
3473
|
}
|
|
3481
3474
|
const schema = this.state.schema;
|
|
3482
3475
|
const formRoot = this.state.formRoot;
|
|
3476
|
+
const actions = this.state.externalActions;
|
|
3483
3477
|
const emptyPrefill = this.buildHiddenFieldsData(schema.elements);
|
|
3484
|
-
this.renderForm(formRoot, schema, emptyPrefill);
|
|
3478
|
+
this.renderForm(formRoot, schema, emptyPrefill, actions || void 0);
|
|
3485
3479
|
}
|
|
3486
3480
|
/**
|
|
3487
3481
|
* Build prefill data for hidden fields only
|
|
3488
3482
|
* Hidden fields should retain their values when clearing
|
|
3483
|
+
* Builds nested objects instead of flattened dotted keys
|
|
3489
3484
|
*/
|
|
3490
|
-
buildHiddenFieldsData(elements
|
|
3485
|
+
buildHiddenFieldsData(elements) {
|
|
3491
3486
|
const data = {};
|
|
3492
3487
|
for (const element of elements) {
|
|
3493
3488
|
const key = element.key;
|
|
3494
|
-
const fieldPath = parentPath ? `${parentPath}.${key}` : key;
|
|
3495
3489
|
if (element.hidden && element.default !== void 0) {
|
|
3496
|
-
data[
|
|
3490
|
+
data[key] = element.default;
|
|
3497
3491
|
}
|
|
3498
3492
|
if (element.type === "container" || element.type === "group") {
|
|
3499
3493
|
const containerElement = element;
|
|
3500
|
-
const nestedData = this.buildHiddenFieldsData(
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3494
|
+
const nestedData = this.buildHiddenFieldsData(containerElement.elements);
|
|
3495
|
+
if (Object.keys(nestedData).length > 0) {
|
|
3496
|
+
if (!(key in data)) {
|
|
3497
|
+
data[key] = nestedData;
|
|
3498
|
+
} else if (typeof data[key] === "object" && data[key] !== null && !Array.isArray(data[key])) {
|
|
3499
|
+
data[key] = { ...data[key], ...nestedData };
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3505
3502
|
}
|
|
3506
3503
|
}
|
|
3507
3504
|
return data;
|
|
@@ -3582,7 +3579,7 @@ var FormBuilderInstance = class {
|
|
|
3582
3579
|
this.state.formRoot = null;
|
|
3583
3580
|
this.state.schema = null;
|
|
3584
3581
|
this.state.externalActions = null;
|
|
3585
|
-
if (
|
|
3582
|
+
if (this.state.config.verboseErrors) {
|
|
3586
3583
|
globalThis.__formBuilderInstances?.delete(this.instanceId);
|
|
3587
3584
|
}
|
|
3588
3585
|
}
|