@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/dist/esm/index.js CHANGED
@@ -1265,8 +1265,22 @@ async function renderFilePreview(container, resourceId, state, options = {}) {
1265
1265
  const thumbnailUrl = await state.config.getThumbnail(resourceId);
1266
1266
  if (thumbnailUrl) {
1267
1267
  clear(container);
1268
- img.src = thumbnailUrl;
1269
- container.appendChild(img);
1268
+ if (meta && meta.type && meta.type.startsWith("video/")) {
1269
+ const video = document.createElement("video");
1270
+ video.className = "w-full h-full object-contain";
1271
+ video.controls = true;
1272
+ video.preload = "metadata";
1273
+ video.muted = true;
1274
+ const source = document.createElement("source");
1275
+ source.src = thumbnailUrl;
1276
+ source.type = meta.type;
1277
+ video.appendChild(source);
1278
+ video.appendChild(document.createTextNode("Your browser does not support the video tag."));
1279
+ container.appendChild(video);
1280
+ } else {
1281
+ img.src = thumbnailUrl;
1282
+ container.appendChild(img);
1283
+ }
1270
1284
  } else {
1271
1285
  setEmptyFileContainer(container, state);
1272
1286
  }
@@ -2719,6 +2733,7 @@ var defaultConfig = {
2719
2733
  onUploadError: null,
2720
2734
  onDownloadError: null,
2721
2735
  debounceMs: 300,
2736
+ verboseErrors: false,
2722
2737
  enableFilePreview: true,
2723
2738
  maxPreviewSize: "200px",
2724
2739
  readonly: false,
@@ -3018,15 +3033,7 @@ var FormBuilderInstance = class {
3018
3033
  constructor(config) {
3019
3034
  this.instanceId = generateInstanceId();
3020
3035
  this.state = createInstanceState(config);
3021
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
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
- }
3036
+ if (this.state.config.verboseErrors) {
3030
3037
  if (!globalThis.__formBuilderInstances) {
3031
3038
  globalThis.__formBuilderInstances = /* @__PURE__ */ new Set();
3032
3039
  }
@@ -3480,28 +3487,32 @@ var FormBuilderInstance = class {
3480
3487
  }
3481
3488
  const schema = this.state.schema;
3482
3489
  const formRoot = this.state.formRoot;
3490
+ const actions = this.state.externalActions;
3483
3491
  const emptyPrefill = this.buildHiddenFieldsData(schema.elements);
3484
- this.renderForm(formRoot, schema, emptyPrefill);
3492
+ this.renderForm(formRoot, schema, emptyPrefill, actions || void 0);
3485
3493
  }
3486
3494
  /**
3487
3495
  * Build prefill data for hidden fields only
3488
3496
  * Hidden fields should retain their values when clearing
3497
+ * Builds nested objects instead of flattened dotted keys
3489
3498
  */
3490
- buildHiddenFieldsData(elements, parentPath = "") {
3499
+ buildHiddenFieldsData(elements) {
3491
3500
  const data = {};
3492
3501
  for (const element of elements) {
3493
3502
  const key = element.key;
3494
- const fieldPath = parentPath ? `${parentPath}.${key}` : key;
3495
3503
  if (element.hidden && element.default !== void 0) {
3496
- data[fieldPath] = element.default;
3504
+ data[key] = element.default;
3497
3505
  }
3498
3506
  if (element.type === "container" || element.type === "group") {
3499
3507
  const containerElement = element;
3500
- const nestedData = this.buildHiddenFieldsData(
3501
- containerElement.elements,
3502
- fieldPath
3503
- );
3504
- Object.assign(data, nestedData);
3508
+ const nestedData = this.buildHiddenFieldsData(containerElement.elements);
3509
+ if (Object.keys(nestedData).length > 0) {
3510
+ if (!(key in data)) {
3511
+ data[key] = nestedData;
3512
+ } else if (typeof data[key] === "object" && data[key] !== null && !Array.isArray(data[key])) {
3513
+ data[key] = { ...data[key], ...nestedData };
3514
+ }
3515
+ }
3505
3516
  }
3506
3517
  }
3507
3518
  return data;
@@ -3582,7 +3593,7 @@ var FormBuilderInstance = class {
3582
3593
  this.state.formRoot = null;
3583
3594
  this.state.schema = null;
3584
3595
  this.state.externalActions = null;
3585
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
3596
+ if (this.state.config.verboseErrors) {
3586
3597
  globalThis.__formBuilderInstances?.delete(this.instanceId);
3587
3598
  }
3588
3599
  }