@dmitryvim/form-builder 0.2.34 → 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;
@@ -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
  }
@@ -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;
@@ -70,6 +84,12 @@ export interface NumberElement extends BaseElement {
70
84
  minCount?: number;
71
85
  maxCount?: number;
72
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;
73
93
  }
74
94
  export interface SelectElement extends BaseElement {
75
95
  type: "select";
@@ -151,6 +171,25 @@ export interface SwitcherElement extends BaseElement {
151
171
  maxCount?: number;
152
172
  addLabel?: string;
153
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;
192
+ }
154
193
  export interface GroupElement extends BaseElement {
155
194
  type: "group";
156
195
  elements: Element[];
@@ -229,7 +268,7 @@ export interface RichInputElement extends BaseElement {
229
268
  filesKey?: string;
230
269
  flatOutput?: boolean;
231
270
  }
232
- 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;
233
272
  export interface Schema {
234
273
  version?: string;
235
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
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.34",
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",