@dmitryvim/form-builder 0.2.2 → 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/dist/esm/index.js CHANGED
@@ -2064,6 +2064,7 @@ function renderMultipleFileElement(element, ctx, wrapper, pathKey) {
2064
2064
  function validateFileElement(element, key, context) {
2065
2065
  const errors = [];
2066
2066
  const { scopeRoot, skipValidation, path } = context;
2067
+ const isMultipleField = element.type === "files" || "multiple" in element && Boolean(element.multiple);
2067
2068
  const validateFileCount = (key2, resourceIds, element2) => {
2068
2069
  if (skipValidation) return;
2069
2070
  const minFiles = "minCount" in element2 ? element2.minCount ?? 0 : 0;
@@ -2078,7 +2079,7 @@ function validateFileElement(element, key, context) {
2078
2079
  errors.push(`${key2}: maximum ${maxFiles} files allowed`);
2079
2080
  }
2080
2081
  };
2081
- if ("multiple" in element && element.multiple) {
2082
+ if (isMultipleField) {
2082
2083
  const fullKey = pathJoin(path, key);
2083
2084
  const pickerInput = scopeRoot.querySelector(
2084
2085
  `input[type="file"][name="${fullKey}"]`
@@ -2718,6 +2719,7 @@ var defaultConfig = {
2718
2719
  onUploadError: null,
2719
2720
  onDownloadError: null,
2720
2721
  debounceMs: 300,
2722
+ verboseErrors: false,
2721
2723
  enableFilePreview: true,
2722
2724
  maxPreviewSize: "200px",
2723
2725
  readonly: false,
@@ -3017,15 +3019,7 @@ var FormBuilderInstance = class {
3017
3019
  constructor(config) {
3018
3020
  this.instanceId = generateInstanceId();
3019
3021
  this.state = createInstanceState(config);
3020
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
3021
- if (config?.getThumbnail) {
3022
- const testResult = config.getThumbnail("test-id");
3023
- if (!(testResult instanceof Promise)) {
3024
- console.warn(
3025
- "[form-builder] getThumbnail must be async (return Promise). Wrap your function: async (id) => { ... }"
3026
- );
3027
- }
3028
- }
3022
+ if (this.state.config.verboseErrors) {
3029
3023
  if (!globalThis.__formBuilderInstances) {
3030
3024
  globalThis.__formBuilderInstances = /* @__PURE__ */ new Set();
3031
3025
  }
@@ -3479,28 +3473,32 @@ var FormBuilderInstance = class {
3479
3473
  }
3480
3474
  const schema = this.state.schema;
3481
3475
  const formRoot = this.state.formRoot;
3476
+ const actions = this.state.externalActions;
3482
3477
  const emptyPrefill = this.buildHiddenFieldsData(schema.elements);
3483
- this.renderForm(formRoot, schema, emptyPrefill);
3478
+ this.renderForm(formRoot, schema, emptyPrefill, actions || void 0);
3484
3479
  }
3485
3480
  /**
3486
3481
  * Build prefill data for hidden fields only
3487
3482
  * Hidden fields should retain their values when clearing
3483
+ * Builds nested objects instead of flattened dotted keys
3488
3484
  */
3489
- buildHiddenFieldsData(elements, parentPath = "") {
3485
+ buildHiddenFieldsData(elements) {
3490
3486
  const data = {};
3491
3487
  for (const element of elements) {
3492
3488
  const key = element.key;
3493
- const fieldPath = parentPath ? `${parentPath}.${key}` : key;
3494
3489
  if (element.hidden && element.default !== void 0) {
3495
- data[fieldPath] = element.default;
3490
+ data[key] = element.default;
3496
3491
  }
3497
3492
  if (element.type === "container" || element.type === "group") {
3498
3493
  const containerElement = element;
3499
- const nestedData = this.buildHiddenFieldsData(
3500
- containerElement.elements,
3501
- fieldPath
3502
- );
3503
- Object.assign(data, nestedData);
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
+ }
3504
3502
  }
3505
3503
  }
3506
3504
  return data;
@@ -3581,7 +3579,7 @@ var FormBuilderInstance = class {
3581
3579
  this.state.formRoot = null;
3582
3580
  this.state.schema = null;
3583
3581
  this.state.externalActions = null;
3584
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
3582
+ if (this.state.config.verboseErrors) {
3585
3583
  globalThis.__formBuilderInstances?.delete(this.instanceId);
3586
3584
  }
3587
3585
  }