@dmitryvim/form-builder 0.2.32 → 0.3.0

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.
@@ -0,0 +1,4 @@
1
+ import type { BooleanElement, RenderContext, ComponentContext, ValidationResult, Element } from "../types/index.js";
2
+ export declare function renderBooleanElement(element: BooleanElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
3
+ export declare function validateBooleanElement(element: Element, key: string, context: ComponentContext): ValidationResult;
4
+ export declare function updateBooleanField(_element: Element, fieldPath: string, value: any, context: ComponentContext): void;
@@ -5,6 +5,7 @@ export interface ColourElement extends BaseElement {
5
5
  multiple?: boolean;
6
6
  minCount?: number;
7
7
  maxCount?: number;
8
+ addLabel?: string;
8
9
  }
9
10
  export declare function renderColourElement(element: ColourElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
10
11
  export declare function renderMultipleColourElement(element: ColourElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
@@ -27,5 +27,9 @@ export interface HandleFileSelectOptions {
27
27
  maxSizeMB?: number;
28
28
  }
29
29
  export declare function handleFileSelect(opts: HandleFileSelectOptions): Promise<void>;
30
+ export interface UploadBatchFailure {
31
+ file: File;
32
+ error: Error;
33
+ }
30
34
  export declare function setupFilesDropHandler(filesContainer: HTMLElement, resourceIds: string[], state: State, updateCallback: () => void, constraints: FileUploadConstraints, pathKey?: string, instance?: FormBuilderInstance | null): void;
31
35
  export declare function setupFilesPickerHandler(filesPicker: HTMLInputElement, resourceIds: string[], state: State, updateCallback: () => void, constraints: FileUploadConstraints, pathKey?: string, instance?: FormBuilderInstance | null): void;
@@ -1,6 +1,6 @@
1
1
  import type { FileElement, FilesElement, RenderContext, ComponentContext, Element } from "../types/index.js";
2
- export { getAllowedExtensions, isFileExtensionAllowed, isFileSizeAllowed } from "./file/constraints.js";
3
- export { renderFilePreview, renderFilePreviewReadonly } from "./file/preview.js";
2
+ export { getAllowedExtensions, isFileExtensionAllowed, isFileSizeAllowed, } from "./file/constraints.js";
3
+ export { renderFilePreview, renderFilePreviewReadonly, } from "./file/preview.js";
4
4
  export { renderResourcePills } from "./file/render-edit.js";
5
5
  export { validateFileElement } from "./file/validate.js";
6
6
  export declare function renderFileElement(element: FileElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
@@ -1,6 +1,17 @@
1
1
  import type { TextElement, RenderContext, ComponentContext, ValidationResult } from "../types/index.js";
2
- export declare function createCharCounter(element: TextElement, input: HTMLInputElement | HTMLTextAreaElement, isTextarea?: boolean): HTMLElement;
2
+ export declare function createCharCounter(element: TextElement, input: HTMLInputElement | HTMLTextAreaElement): HTMLElement;
3
3
  export declare function renderTextElement(element: TextElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
4
+ /**
5
+ * `text.multiple` is always rendered as a vertical list of chip rows:
6
+ * [● input 🗑]
7
+ * Each chip = colored dot marker + single-line input + trash button that
8
+ * fades in on hover. Tint and dot color are pure CSS via --fb-chip-* vars;
9
+ * per-field overrides go through `[data-field-key="..."]` (see theming.md).
10
+ *
11
+ * Why no character-counter / no soft-wrap textarea like single-text:
12
+ * - chip rows are deliberately one-line; long values are unusual here.
13
+ * - min/max length still validate at field level via `validateTextElement`.
14
+ */
4
15
  export declare function renderMultipleTextElement(element: TextElement, ctx: RenderContext, wrapper: HTMLElement, pathKey: string): void;
5
16
  /**
6
17
  * Validate text input field and return extracted value with errors
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { FormBuilderInstance } from "./instance/FormBuilderInstance.js";
7
7
  import { validateSchema } from "./utils/validation.js";
8
- export type { SelectOption, ElementAction, BaseElement, TextElement, TextareaElement, NumberElement, SelectElement, FileElement, FilesElement, ContainerElement, GroupElement, MarkdownElement, RichInputElement, Element, Schema, ExternalAction, FormData, RenderContext, Translations, Locale, Config, ResourceMetadata, PickedResource, State, } from "./types/index.js";
8
+ export type { SelectOption, ElementAction, BaseElement, TextElement, TextareaElement, NumberElement, SelectElement, BooleanElement, FileElement, FilesElement, ContainerElement, GroupElement, MarkdownElement, RichInputElement, Element, Schema, ExternalAction, FormData, RenderContext, Translations, Locale, Config, ResourceMetadata, PickedResource, State, } from "./types/index.js";
9
9
  export type { Theme } from "./styles/theme.js";
10
10
  export { defaultTheme, exampleThemes } from "./styles/theme.js";
11
11
  /**
@@ -60,7 +60,20 @@ export declare class FormBuilderInstance {
60
60
  */
61
61
  registerAction(action: ExternalAction): void;
62
62
  /**
63
- * Find the DOM element corresponding to a field path (instance-scoped)
63
+ * Find the DOM element corresponding to a field path (instance-scoped).
64
+ *
65
+ * Strategy:
66
+ * 1. Try a `[name="…"]` lookup first — works for any field that renders
67
+ * an input/hidden with the path as its name, in either mode. Some
68
+ * readonly renderers still emit a hidden input (boolean, switcher),
69
+ * so this path must run regardless of `state.config.readonly`. A
70
+ * prior version gated this on edit mode only, which made
71
+ * `updateField` / `setFormData` silently miss readonly boolean
72
+ * fields whose component also opts out of the standard label row
73
+ * (`ownsLabel: true`).
74
+ * 2. If no input matched, fall back to locating the field wrapper by
75
+ * its visible label text — needed for readonly previews that don't
76
+ * emit any `name=` attribute (e.g. file/markdown previews).
64
77
  */
65
78
  private findFormElementByFieldPath;
66
79
  /**
@@ -1,17 +1,41 @@
1
1
  export interface Theme {
2
2
  primaryColor: string;
3
3
  primaryHoverColor: string;
4
+ /** Light tint of primary — used for chip backgrounds, hover surfaces, focused-state backgrounds. */
5
+ primarySoftColor: string;
6
+ /** Slightly stronger tint of primary — used for chip borders and hovered soft surfaces. */
7
+ primarySoftHoverColor: string;
4
8
  errorColor: string;
5
9
  errorHoverColor: string;
6
10
  successColor: string;
11
+ /** Secondary accent color (e.g. amber) used for highlights distinct from primary. */
12
+ accentColor: string;
13
+ /** Soft tint of accent for chip/badge backgrounds. */
14
+ accentSoftColor: string;
15
+ /** Border color paired with accentSoftColor. */
16
+ accentBorderColor: string;
17
+ /** Text color used on accent-tinted surfaces. */
18
+ accentTextColor: string;
7
19
  borderColor: string;
8
20
  borderHoverColor: string;
9
21
  borderFocusColor: string;
22
+ /** Stronger border for inputs/dropzones that need more contrast. */
23
+ borderStrongColor: string;
10
24
  backgroundColor: string;
11
25
  backgroundHoverColor: string;
12
26
  backgroundReadonlyColor: string;
27
+ /** Page-level background (the surface the form card sits on). */
28
+ pageBackgroundColor: string;
29
+ /** Soft tinted surface (mix of primary and white) for inset blocks. */
30
+ surfaceSoftColor: string;
31
+ /** Subtle tinted surface for very-light backgrounds. */
32
+ surfaceTintColor: string;
13
33
  textColor: string;
14
34
  textSecondaryColor: string;
35
+ /** Lighter text tone (between secondary and disabled). */
36
+ textMutedColor: string;
37
+ /** Faintest text tone, used for small uppercase group labels. */
38
+ textFaintColor: string;
15
39
  textPlaceholderColor: string;
16
40
  textDisabledColor: string;
17
41
  buttonBgColor: string;
@@ -31,6 +55,12 @@ export interface Theme {
31
55
  inputPaddingX: string;
32
56
  inputPaddingY: string;
33
57
  borderRadius: string;
58
+ /** Smaller corner radius (e.g. for chips and compact controls). */
59
+ borderRadiusSmall: string;
60
+ /** Larger corner radius for cards and dropzones. */
61
+ borderRadiusLarge: string;
62
+ /** Extra-large corner radius for section cards. */
63
+ borderRadiusXLarge: string;
34
64
  borderWidth: string;
35
65
  fontSize: string;
36
66
  fontSizeSmall: string;
@@ -38,10 +68,26 @@ export interface Theme {
38
68
  fontFamily: string;
39
69
  fontWeightNormal: string;
40
70
  fontWeightMedium: string;
71
+ /** Line height applied to text inputs and textarea/chip inputs. */
72
+ lineHeight: string;
73
+ /** Subtle card shadow. */
74
+ shadowCard: string;
75
+ /** Elevated popover/hover shadow. */
76
+ shadowPopover: string;
41
77
  focusRingWidth: string;
42
78
  focusRingColor: string;
43
79
  focusRingOpacity: string;
44
80
  transitionDuration: string;
81
+ slideCardBg: string;
82
+ slideCardShadow: string;
83
+ slideCardRadius: string;
84
+ /** Minimum card height — useful when content varies wildly across slides. */
85
+ slideCardMinHeight: string;
86
+ /** Inner padding of each slide card. Default sits a bit roomier than stack-mode. */
87
+ slideCardPadding: string;
88
+ labelSectionFontSize: string;
89
+ labelSectionLetterSpacing: string;
90
+ labelSectionTextTransform: string;
45
91
  }
46
92
  export declare const defaultTheme: Theme;
47
93
  /**
@@ -60,4 +106,5 @@ export declare const exampleThemes: {
60
106
  default: Theme;
61
107
  dark: Theme;
62
108
  klein: Theme;
109
+ picaz: Theme;
63
110
  };
@@ -49,4 +49,11 @@ export type ComponentUpdater = (element: Element, fieldPath: string, value: any,
49
49
  export interface ComponentOperations {
50
50
  validate: ComponentValidator;
51
51
  update: ComponentUpdater;
52
+ /**
53
+ * Set to true when the component renders its own title/label inline
54
+ * (e.g. boolean's `.toggle-row` puts the label next to the pill). When
55
+ * true, the main dispatcher skips `createLabelContainer` and lets the
56
+ * component own the entire field row.
57
+ */
58
+ ownsLabel?: boolean;
52
59
  }
@@ -65,6 +65,7 @@ export interface Translations {
65
65
  invalidFileExtension: string;
66
66
  invalidFileMime: string;
67
67
  fileTooLarge: string;
68
+ uploadFailed: string;
68
69
  filesLimitExceeded: string;
69
70
  unsupportedFieldType: string;
70
71
  invalidOption: string;
@@ -1,4 +1,4 @@
1
- export type { SelectOption, ElementAction, EnableCondition, BaseElement, TextElement, TextareaElement, NumberElement, SelectElement, SwitcherElement, FileElement, FilesElement, ColourElement, SliderElement, ContainerElement, GroupElement, TableElement, TableMerge, TableData, RichInputElement, MarkdownElement, Element, Schema, ExternalAction, FormData, RenderContext, } from "./schema.js";
1
+ export type { SelectOption, ElementAction, EnableCondition, BaseElement, TextElement, TextareaElement, NumberElement, SelectElement, SwitcherElement, BooleanElement, FileElement, FilesElement, ColourElement, SliderElement, ContainerElement, GroupElement, TableElement, TableMerge, TableData, RichInputElement, MarkdownElement, Element, Schema, ExternalAction, FormData, RenderContext, } from "./schema.js";
2
2
  export type { Translations, Locale, Config, ResourceMetadata, PickedResource, } from "./config.js";
3
3
  export type { State } from "./state.js";
4
4
  export type { ComponentContext, ValidationResult, ComponentValidator, ComponentUpdater, ComponentOperations, } from "./component-operations.js";
@@ -1,6 +1,20 @@
1
1
  export interface SelectOption {
2
2
  value: string;
3
3
  label: string;
4
+ /**
5
+ * Optional secondary line under the label.
6
+ * Used by `switcher` to render preset-pill buttons (icon + name + subtitle).
7
+ * Ignored by `select` (native <option> shows label only).
8
+ */
9
+ subtitle?: string;
10
+ /**
11
+ * Optional image URL rendered to the left of the label.
12
+ * Accepts any `<img src>` value — typically a small SVG/PNG icon, or a
13
+ * `data:image/...;base64,...` URI for inline assets without a network round-trip.
14
+ * Used by `switcher` to show a visual preview (e.g. an aspect-ratio
15
+ * sketch for size presets). Ignored by `select`.
16
+ */
17
+ iconUrl?: string;
4
18
  }
5
19
  export interface ElementAction {
6
20
  key: string;
@@ -44,6 +58,7 @@ export interface TextElement extends BaseElement {
44
58
  multiple?: boolean;
45
59
  minCount?: number;
46
60
  maxCount?: number;
61
+ addLabel?: string;
47
62
  }
48
63
  export interface TextareaElement extends BaseElement {
49
64
  type: "textarea";
@@ -56,6 +71,7 @@ export interface TextareaElement extends BaseElement {
56
71
  minCount?: number;
57
72
  maxCount?: number;
58
73
  autoExpand?: boolean;
74
+ addLabel?: string;
59
75
  }
60
76
  export interface NumberElement extends BaseElement {
61
77
  type: "number";
@@ -67,6 +83,13 @@ export interface NumberElement extends BaseElement {
67
83
  multiple?: boolean;
68
84
  minCount?: number;
69
85
  maxCount?: number;
86
+ addLabel?: string;
87
+ /**
88
+ * When true, renders a compact pill: `−` button, narrow input, `+` button.
89
+ * Native browser spinner arrows are hidden; range-hint chip is hidden.
90
+ * Clamped to `min`/`max`; uses `step` (default 1).
91
+ */
92
+ stepper?: boolean;
70
93
  }
71
94
  export interface SelectElement extends BaseElement {
72
95
  type: "select";
@@ -75,6 +98,7 @@ export interface SelectElement extends BaseElement {
75
98
  multiple?: boolean;
76
99
  minCount?: number;
77
100
  maxCount?: number;
101
+ addLabel?: string;
78
102
  }
79
103
  /**
80
104
  * File accept constraint — either a legacy comma-separated string (e.g. ".jpg,.png")
@@ -118,6 +142,7 @@ export interface ContainerElement extends BaseElement {
118
142
  * Ignored when `multiple: false`.
119
143
  */
120
144
  displayMode?: "stack" | "slides";
145
+ addLabel?: string;
121
146
  }
122
147
  export interface ColourElement extends BaseElement {
123
148
  type: "colour";
@@ -125,6 +150,7 @@ export interface ColourElement extends BaseElement {
125
150
  multiple?: boolean;
126
151
  minCount?: number;
127
152
  maxCount?: number;
153
+ addLabel?: string;
128
154
  }
129
155
  export interface SliderElement extends BaseElement {
130
156
  type: "slider";
@@ -135,6 +161,7 @@ export interface SliderElement extends BaseElement {
135
161
  multiple?: boolean;
136
162
  minCount?: number;
137
163
  maxCount?: number;
164
+ addLabel?: string;
138
165
  }
139
166
  export interface SwitcherElement extends BaseElement {
140
167
  type: "switcher";
@@ -142,6 +169,26 @@ export interface SwitcherElement extends BaseElement {
142
169
  multiple?: boolean;
143
170
  minCount?: number;
144
171
  maxCount?: number;
172
+ addLabel?: string;
173
+ }
174
+ /**
175
+ * Boolean / toggle element. Renders as a `.toggle-row` card: pill switch
176
+ * on the left, label + hint stacked to the right. Form data value is a
177
+ * real boolean (`true` / `false`).
178
+ *
179
+ * Field-text layout (matches the design reference):
180
+ * - `label` → bold title (t1) inside the row, replacing the standard
181
+ * label that other field types render above.
182
+ * - `hint` → grey subtitle (t2) directly under the title.
183
+ * - `description` → text shown via a small info-icon tooltip next to the
184
+ * title (use a longer explanation here; keep `hint`
185
+ * short).
186
+ *
187
+ * `required` is ignored — `false` is a valid value.
188
+ */
189
+ export interface BooleanElement extends BaseElement {
190
+ type: "boolean";
191
+ default?: boolean;
145
192
  }
146
193
  export interface GroupElement extends BaseElement {
147
194
  type: "group";
@@ -221,7 +268,7 @@ export interface RichInputElement extends BaseElement {
221
268
  filesKey?: string;
222
269
  flatOutput?: boolean;
223
270
  }
224
- export type Element = TextElement | TextareaElement | NumberElement | SelectElement | SwitcherElement | FileElement | FilesElement | HiddenElement | ColourElement | SliderElement | ContainerElement | GroupElement | TableElement | RichInputElement | MarkdownElement;
271
+ export type Element = TextElement | TextareaElement | NumberElement | SelectElement | SwitcherElement | BooleanElement | FileElement | FilesElement | HiddenElement | ColourElement | SliderElement | ContainerElement | GroupElement | TableElement | RichInputElement | MarkdownElement;
225
272
  export interface Schema {
226
273
  version?: string;
227
274
  elements: Element[];
@@ -1,4 +1,43 @@
1
1
  import type { State } from "../types/index.js";
2
+ /**
3
+ * Strip the `.error-message` node paired with an input by id convention
4
+ * (markValidity creates `error-${input.name}` across text/select/slider/
5
+ * colour/switcher). Called from updateField paths so a programmatic update
6
+ * to a valid value clears any stale error surface left over from the
7
+ * previous validation pass — otherwise the field stays visibly "invalid"
8
+ * until the next validate cycle.
9
+ */
10
+ export declare function clearFieldError(input: HTMLElement): void;
11
+ /**
12
+ * Shared trash-can icon used by every per-item remove button (multi-text
13
+ * chips, multi-container items, etc.). Stays as one inline SVG so a single
14
+ * style sweep affects all remove affordances at once.
15
+ */
16
+ export declare const BIN_ICON_SVG = "<svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><polyline points=\"3 6 5 6 21 6\"/><path d=\"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6\"/><path d=\"M10 11v6\"/><path d=\"M14 11v6\"/><path d=\"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2\"/></svg>";
17
+ /**
18
+ * Inject the theming-hook stylesheet: rules that map `data-fb-*` attributes
19
+ * to their CSS-variable counterparts. Without this, themes that set
20
+ * `Theme.slideCardBg` etc. have no effect — defaults live in `defaultTheme`,
21
+ * so the rules below pick them up automatically for every form instance.
22
+ *
23
+ * - `[data-fb-slide-card]` — items inside `container.displayMode:"slides"`
24
+ * - `[data-fb-label-row]` — every standard field-label container
25
+ *
26
+ * Idempotent via a flag attribute on the document head.
27
+ */
28
+ export declare function ensureThemingHooks(doc: Document): void;
29
+ /**
30
+ * Make a textarea grow vertically with its content. Starts at the height
31
+ * required by the current value; on each input, sets height to scrollHeight.
32
+ */
33
+ export declare function applyAutoExpand(textarea: HTMLTextAreaElement): void;
34
+ /**
35
+ * Enforce single-line semantics on a textarea: block the Enter key and
36
+ * strip newlines from pasted content. Used to render <textarea rows=1> as
37
+ * a soft-wrapping single-line input — text wraps visually but the value
38
+ * never contains a newline.
39
+ */
40
+ export declare function applySingleLineMode(textarea: HTMLTextAreaElement): void;
2
41
  /**
3
42
  * Apply themed input styles to an HTMLInputElement, HTMLTextAreaElement, or HTMLSelectElement
4
43
  */
@@ -7,6 +46,48 @@ export declare function applyInputStyles(element: HTMLInputElement | HTMLTextAre
7
46
  * Apply themed hint/description styles to a paragraph element
8
47
  */
9
48
  export declare function applyHintStyles(element: HTMLParagraphElement): void;
49
+ /**
50
+ * Mount a counter element into the field's label row so it sits inline with
51
+ * the heading (e.g. `Tags 3/5`) instead of below the field. The label row is
52
+ * marked with `[data-fb-label-row]` by `createLabelContainer` — the data
53
+ * attribute is the stable hook; layout utility classes may change.
54
+ *
55
+ * No-op when the wrapper has no label row (e.g. nested anonymous wrappers).
56
+ */
57
+ export declare function mountCounterInLabel(wrapper: HTMLElement, counter: HTMLElement): void;
58
+ /**
59
+ * Visual: full-width dashed pill button, optional `+ {label}` centered.
60
+ * Used by every multi-value field type.
61
+ *
62
+ * The counter is returned separately so callers can place it inline with the
63
+ * field label (saving a row). At maxCount both the button and the row are
64
+ * hidden — the counter stays visible wherever the caller mounted it.
65
+ *
66
+ * `classNameSuffix` becomes `add-{suffix}-btn` to preserve test-targetable
67
+ * class names that the existing test suite already queries.
68
+ */
69
+ export interface AddItemRowHandle {
70
+ row: HTMLDivElement;
71
+ button: HTMLButtonElement;
72
+ counter: HTMLSpanElement;
73
+ update: (current: number, max: number) => void;
74
+ }
75
+ export declare function createAddItemRow(classNameSuffix: string, onClick: () => void, options?: {
76
+ label?: string;
77
+ showCounter?: boolean;
78
+ }): AddItemRowHandle;
79
+ /**
80
+ * Slide-sized add tile rendered inside a slides-displayMode container grid.
81
+ * Sits as another grid cell next to existing slides at the same dimensions.
82
+ */
83
+ export interface SlideAddTileHandle {
84
+ tile: HTMLButtonElement;
85
+ counter: HTMLSpanElement;
86
+ update: (current: number, max: number) => void;
87
+ }
88
+ export declare function createSlideAddTile(onClick: () => void, options?: {
89
+ label?: string;
90
+ }): SlideAddTileHandle;
10
91
  /**
11
92
  * Create a styled add button with theme support
12
93
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.32",
6
+ "version": "0.3.0",
7
7
  "description": "A reusable JSON schema form builder library",
8
8
  "main": "./dist/cjs/index.cjs",
9
9
  "module": "./dist/esm/index.js",