@dmitryvim/form-builder 0.2.3 → 0.2.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/README.md +7 -0
- package/dist/browser/formbuilder.min.js +31 -31
- package/dist/browser/{formbuilder.v0.2.3.min.js → formbuilder.v0.2.5.min.js} +31 -31
- package/dist/cjs/index.cjs +32 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +32 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +31 -31
- 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/cjs/index.cjs
CHANGED
|
@@ -1289,8 +1289,22 @@ async function renderFilePreview(container, resourceId, state, options = {}) {
|
|
|
1289
1289
|
const thumbnailUrl = await state.config.getThumbnail(resourceId);
|
|
1290
1290
|
if (thumbnailUrl) {
|
|
1291
1291
|
clear(container);
|
|
1292
|
-
|
|
1293
|
-
|
|
1292
|
+
if (meta && meta.type && meta.type.startsWith("video/")) {
|
|
1293
|
+
const video = document.createElement("video");
|
|
1294
|
+
video.className = "w-full h-full object-contain";
|
|
1295
|
+
video.controls = true;
|
|
1296
|
+
video.preload = "metadata";
|
|
1297
|
+
video.muted = true;
|
|
1298
|
+
const source = document.createElement("source");
|
|
1299
|
+
source.src = thumbnailUrl;
|
|
1300
|
+
source.type = meta.type;
|
|
1301
|
+
video.appendChild(source);
|
|
1302
|
+
video.appendChild(document.createTextNode("Your browser does not support the video tag."));
|
|
1303
|
+
container.appendChild(video);
|
|
1304
|
+
} else {
|
|
1305
|
+
img.src = thumbnailUrl;
|
|
1306
|
+
container.appendChild(img);
|
|
1307
|
+
}
|
|
1294
1308
|
} else {
|
|
1295
1309
|
setEmptyFileContainer(container, state);
|
|
1296
1310
|
}
|
|
@@ -2762,6 +2776,7 @@ var defaultConfig = {
|
|
|
2762
2776
|
onUploadError: null,
|
|
2763
2777
|
onDownloadError: null,
|
|
2764
2778
|
debounceMs: 300,
|
|
2779
|
+
verboseErrors: false,
|
|
2765
2780
|
enableFilePreview: true,
|
|
2766
2781
|
maxPreviewSize: "200px",
|
|
2767
2782
|
readonly: false,
|
|
@@ -3061,15 +3076,7 @@ var FormBuilderInstance = class {
|
|
|
3061
3076
|
constructor(config) {
|
|
3062
3077
|
this.instanceId = generateInstanceId();
|
|
3063
3078
|
this.state = createInstanceState(config);
|
|
3064
|
-
if (
|
|
3065
|
-
if (config == null ? void 0 : config.getThumbnail) {
|
|
3066
|
-
const testResult = config.getThumbnail("test-id");
|
|
3067
|
-
if (!(testResult instanceof Promise)) {
|
|
3068
|
-
console.warn(
|
|
3069
|
-
"[form-builder] getThumbnail must be async (return Promise). Wrap your function: async (id) => { ... }"
|
|
3070
|
-
);
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3079
|
+
if (this.state.config.verboseErrors) {
|
|
3073
3080
|
if (!globalThis.__formBuilderInstances) {
|
|
3074
3081
|
globalThis.__formBuilderInstances = /* @__PURE__ */ new Set();
|
|
3075
3082
|
}
|
|
@@ -3523,28 +3530,32 @@ var FormBuilderInstance = class {
|
|
|
3523
3530
|
}
|
|
3524
3531
|
const schema = this.state.schema;
|
|
3525
3532
|
const formRoot = this.state.formRoot;
|
|
3533
|
+
const actions = this.state.externalActions;
|
|
3526
3534
|
const emptyPrefill = this.buildHiddenFieldsData(schema.elements);
|
|
3527
|
-
this.renderForm(formRoot, schema, emptyPrefill);
|
|
3535
|
+
this.renderForm(formRoot, schema, emptyPrefill, actions || void 0);
|
|
3528
3536
|
}
|
|
3529
3537
|
/**
|
|
3530
3538
|
* Build prefill data for hidden fields only
|
|
3531
3539
|
* Hidden fields should retain their values when clearing
|
|
3540
|
+
* Builds nested objects instead of flattened dotted keys
|
|
3532
3541
|
*/
|
|
3533
|
-
buildHiddenFieldsData(elements
|
|
3542
|
+
buildHiddenFieldsData(elements) {
|
|
3534
3543
|
const data = {};
|
|
3535
3544
|
for (const element of elements) {
|
|
3536
3545
|
const key = element.key;
|
|
3537
|
-
const fieldPath = parentPath ? `${parentPath}.${key}` : key;
|
|
3538
3546
|
if (element.hidden && element.default !== void 0) {
|
|
3539
|
-
data[
|
|
3547
|
+
data[key] = element.default;
|
|
3540
3548
|
}
|
|
3541
3549
|
if (element.type === "container" || element.type === "group") {
|
|
3542
3550
|
const containerElement = element;
|
|
3543
|
-
const nestedData = this.buildHiddenFieldsData(
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3551
|
+
const nestedData = this.buildHiddenFieldsData(containerElement.elements);
|
|
3552
|
+
if (Object.keys(nestedData).length > 0) {
|
|
3553
|
+
if (!(key in data)) {
|
|
3554
|
+
data[key] = nestedData;
|
|
3555
|
+
} else if (typeof data[key] === "object" && data[key] !== null && !Array.isArray(data[key])) {
|
|
3556
|
+
data[key] = { ...data[key], ...nestedData };
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3548
3559
|
}
|
|
3549
3560
|
}
|
|
3550
3561
|
return data;
|
|
@@ -3626,7 +3637,7 @@ var FormBuilderInstance = class {
|
|
|
3626
3637
|
this.state.formRoot = null;
|
|
3627
3638
|
this.state.schema = null;
|
|
3628
3639
|
this.state.externalActions = null;
|
|
3629
|
-
if (
|
|
3640
|
+
if (this.state.config.verboseErrors) {
|
|
3630
3641
|
(_a = globalThis.__formBuilderInstances) == null ? void 0 : _a.delete(this.instanceId);
|
|
3631
3642
|
}
|
|
3632
3643
|
}
|