@dmitryvim/form-builder 0.5.3 → 0.5.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.
@@ -1,7 +1,7 @@
1
1
  import type { ContainerElement, RenderContext, ComponentContext, ValidationResult, Element } from "../types/index.js";
2
2
  export declare function setRenderElement(fn: (element: any, ctx: RenderContext) => HTMLElement): void;
3
3
  export declare function renderSingleContainerElement(element: ContainerElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
4
- export declare function renderMultipleContainerElement(element: ContainerElement, ctx: RenderContext, wrapper: HTMLElement, _pathKey: string): void;
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
7
  }, customScopeRoot?: HTMLElement | null) => {
@@ -50,9 +50,26 @@ export declare class FormBuilderInstance {
50
50
  /**
51
51
  * Trigger onChange callbacks with debouncing
52
52
  * @param fieldPath - Optional field path for field-specific change events
53
- * @param fieldValue - Optional field value for field-specific change events
53
+ * @param fieldValue - Optional field value for field-specific change events.
54
+ * When omitted while fieldPath is given, the value is read from the
55
+ * freshly extracted form data at debounce time — used by structural
56
+ * changes (multi-item add/remove), where the handler has no cheap
57
+ * current value but the array is trivially derivable after the fact.
54
58
  */
55
59
  triggerOnChange(fieldPath?: string, fieldValue?: any): void;
60
+ /**
61
+ * Resolve a DOM field path against the extracted form data.
62
+ *
63
+ * A plain getValueByPath is wrong for paths inside a multiple container:
64
+ * row markers keep gaps after a deletion (`s[2]` may be the first surviving
65
+ * row) while the extracted array is re-packed contiguously — the naive
66
+ * lookup would read a different row, or nothing. Each `[N]` segment is
67
+ * mapped from its marker to the row's position among the container's
68
+ * rendered rows, the same DOM order extraction used to build the array.
69
+ * A bracketed segment that is not a container marker (a multi-value leaf
70
+ * like `tags[1]`, whose indices are contiguous) falls back to the index.
71
+ */
72
+ private resolveDomPathValue;
56
73
  /**
57
74
  * Register an external action that will be displayed as a button
58
75
  * External actions can be form-level (no related_field) or field-level (with related_field)
@@ -174,4 +191,5 @@ export declare class FormBuilderInstance {
174
191
  */
175
192
  destroy(): void;
176
193
  private disconnectEnableIfObservers;
194
+ private removeTooltipElements;
177
195
  }
@@ -23,4 +23,11 @@ export interface State {
23
23
  * with a torn-down ctx. Reproducible under React StrictMode (double mount).
24
24
  */
25
25
  enableIfObservers: Set<MutationObserver>;
26
+ /**
27
+ * Info-button tooltip nodes created by this instance. They live on
28
+ * document.body (position: fixed, moved there so tile overflow can't clip
29
+ * them), so clearing formRoot does not remove them — destroy() and every
30
+ * renderForm() must, or each render cycle leaks its tooltips.
31
+ */
32
+ tooltipElements: Set<HTMLElement>;
26
33
  }
@@ -7,8 +7,13 @@ export declare function isElementReadonly(element: {
7
7
  }): boolean;
8
8
  export declare function isPlainObject(obj: any): obj is Record<string, any>;
9
9
  /**
10
- * Escape HTML special characters to prevent XSS
11
- * Use when inserting user-controlled or translated content via innerHTML
10
+ * Escape HTML special characters to prevent XSS.
11
+ * Use when inserting user-controlled or translated content via innerHTML.
12
+ *
13
+ * Escapes quotes as well as `&<>` because several call sites interpolate
14
+ * into attribute position (e.g. `alt="${escapeHtml(fileName)}"`) — the
15
+ * previous textContent/innerHTML trick left quotes intact, letting a file
16
+ * named `x" onerror="…` break out of the attribute.
12
17
  */
13
18
  export declare function escapeHtml(text: string): string;
14
19
  /**
@@ -42,12 +47,19 @@ export declare function clear(node: HTMLElement): void;
42
47
  export declare function formatFileSize(bytes: number): string;
43
48
  /**
44
49
  * Serialize a value for storage in a hidden input's value attribute.
45
- * Objects/arrays → JSON string, null/undefined → "", primitivesString().
50
+ * null/undefined → "", everything else JSON.
51
+ *
52
+ * JSON for every type — including strings — so deserialization is exact.
53
+ * The previous String() form was lossy: a hidden text field prefilled with
54
+ * "true" or "123" came back from getFormData() as a boolean/number.
46
55
  */
47
56
  export declare function serializeHiddenValue(value: any): string;
48
57
  /**
49
58
  * Deserialize a hidden input's value attribute back to its original type.
50
- * Empty string → null, JSON-parseable → parsed value, otherwise → raw string.
59
+ * Empty string → null, JSON → parsed value.
60
+ *
61
+ * The raw-string fallback covers values written into the DOM directly
62
+ * (not through serializeHiddenValue) — hosts poking the input by hand.
51
63
  */
52
64
  export declare function deserializeHiddenValue(raw: string): any;
53
65
  /**
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.5.3",
6
+ "version": "0.5.4",
7
7
  "description": "A reusable JSON schema form builder library",
8
8
  "main": "./dist/cjs/index.cjs",
9
9
  "module": "./dist/esm/index.js",