@dmitryvim/form-builder 0.2.22 → 0.2.24

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.
@@ -4,7 +4,10 @@ export declare function renderSingleContainerElement(element: ContainerElement,
4
4
  export declare function renderMultipleContainerElement(element: ContainerElement, ctx: RenderContext, wrapper: HTMLElement, _pathKey: string): void;
5
5
  export declare function setValidateElement(fn: (element: Element, ctx: {
6
6
  path: string;
7
- }, customScopeRoot?: HTMLElement | null) => any): void;
7
+ }, customScopeRoot?: HTMLElement | null) => {
8
+ value: any;
9
+ spread: boolean;
10
+ }): void;
8
11
  /**
9
12
  * Validate container field and return extracted value with errors
10
13
  */
@@ -5,6 +5,11 @@ interface FileDeps {
5
5
  fileUploadHandler: () => void;
6
6
  dragHandler: (files: FileList) => void;
7
7
  }
8
+ export declare function getAllowedExtensions(accept: string | {
9
+ extensions: string[];
10
+ } | undefined): string[];
11
+ export declare function isFileExtensionAllowed(fileName: string, allowedExtensions: string[]): boolean;
12
+ export declare function isFileSizeAllowed(file: File, maxSizeMB: number): boolean;
8
13
  export declare function renderFilePreview(container: HTMLElement, resourceId: string, state: State, options?: {
9
14
  fileName?: string;
10
15
  isReadonly?: boolean;
@@ -120,6 +120,11 @@ export declare class FormBuilderInstance {
120
120
  * Builds nested objects instead of flattened dotted keys
121
121
  */
122
122
  private buildHiddenFieldsData;
123
+ /**
124
+ * Build a map from flat output keys (textKey/filesKey) to the richinput schema element info.
125
+ * Used by setFormData to detect flat richinput keys and remap them to their composite values.
126
+ */
127
+ private buildFlatKeyMap;
123
128
  /**
124
129
  * Set form data - update multiple fields without full re-render
125
130
  * @param data - Object with field paths and their values
@@ -24,6 +24,8 @@ export interface ValidationResult {
24
24
  value: any;
25
25
  /** Validation errors encountered */
26
26
  errors: string[];
27
+ /** When true, value is spread into parent data instead of nested under element.key */
28
+ spread?: boolean;
27
29
  }
28
30
  /**
29
31
  * Component validator function type
@@ -40,6 +40,9 @@ export interface Translations {
40
40
  invalidHexColour: string;
41
41
  minFiles: string;
42
42
  maxFiles: string;
43
+ invalidFileExtension: string;
44
+ fileTooLarge: string;
45
+ filesLimitExceeded: string;
43
46
  unsupportedFieldType: string;
44
47
  invalidOption: string;
45
48
  tableAddRow: string;
@@ -171,6 +171,13 @@ export interface TableElement extends BaseElement {
171
171
  /** File extensions accepted for import (e.g. ["csv", "xlsx"]) */
172
172
  importAccept?: string[];
173
173
  }
174
+ /**
175
+ * Legacy hidden field type — use `hidden: true` on any field instead.
176
+ * Kept for backward compatibility with schemas that use `type: "hidden"`.
177
+ */
178
+ export interface HiddenElement extends BaseElement {
179
+ type: "hidden";
180
+ }
174
181
  export interface RichInputElement extends BaseElement {
175
182
  type: "richinput";
176
183
  placeholder?: string;
@@ -183,8 +190,9 @@ export interface RichInputElement extends BaseElement {
183
190
  maxFiles?: number;
184
191
  textKey?: string;
185
192
  filesKey?: string;
193
+ flatOutput?: boolean;
186
194
  }
187
- export type Element = TextElement | TextareaElement | NumberElement | SelectElement | SwitcherElement | FileElement | FilesElement | ColourElement | SliderElement | ContainerElement | GroupElement | TableElement | RichInputElement;
195
+ export type Element = TextElement | TextareaElement | NumberElement | SelectElement | SwitcherElement | FileElement | FilesElement | HiddenElement | ColourElement | SliderElement | ContainerElement | GroupElement | TableElement | RichInputElement;
188
196
  export interface Schema {
189
197
  version?: string;
190
198
  elements: Element[];
@@ -8,4 +8,5 @@ export interface State {
8
8
  version: string;
9
9
  config: Config;
10
10
  debounceTimer: number | null;
11
+ prefill: Record<string, any>;
11
12
  }
@@ -12,3 +12,17 @@ export declare function clear(node: HTMLElement): void;
12
12
  * e.g. 2400000 -> "2.3 MB", 512 -> "512 B"
13
13
  */
14
14
  export declare function formatFileSize(bytes: number): string;
15
+ /**
16
+ * Serialize a value for storage in a hidden input's value attribute.
17
+ * Objects/arrays → JSON string, null/undefined → "", primitives → String().
18
+ */
19
+ export declare function serializeHiddenValue(value: any): string;
20
+ /**
21
+ * Deserialize a hidden input's value attribute back to its original type.
22
+ * Empty string → null, JSON-parseable → parsed value, otherwise → raw string.
23
+ */
24
+ export declare function deserializeHiddenValue(raw: string): any;
25
+ /**
26
+ * Create a hidden input element for a hidden form field.
27
+ */
28
+ export declare function createHiddenInput(name: string, value: any): HTMLInputElement;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.22",
6
+ "version": "0.2.24",
7
7
  "description": "A reusable JSON schema form builder library",
8
8
  "main": "./dist/cjs/index.cjs",
9
9
  "module": "./dist/esm/index.js",