@vertz/ui 0.2.0 → 0.2.1

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.
Files changed (35) hide show
  1. package/README.md +339 -857
  2. package/dist/css/public.d.ts +24 -27
  3. package/dist/css/public.js +5 -1
  4. package/dist/form/public.d.ts +94 -38
  5. package/dist/form/public.js +5 -3
  6. package/dist/index.d.ts +696 -167
  7. package/dist/index.js +461 -84
  8. package/dist/internals.d.ts +192 -23
  9. package/dist/internals.js +151 -102
  10. package/dist/jsx-runtime/index.d.ts +44 -17
  11. package/dist/jsx-runtime/index.js +26 -7
  12. package/dist/query/public.d.ts +62 -7
  13. package/dist/query/public.js +12 -4
  14. package/dist/router/public.d.ts +186 -26
  15. package/dist/router/public.js +22 -7
  16. package/dist/shared/{chunk-f1ynwam4.js → chunk-0p5f7gmg.js} +155 -32
  17. package/dist/shared/{chunk-j8vzvne3.js → chunk-9e92w0wt.js} +4 -1
  18. package/dist/shared/{chunk-xd9d7q5p.js → chunk-cq7xg4xe.js} +59 -10
  19. package/dist/shared/chunk-g4rch80a.js +33 -0
  20. package/dist/shared/{chunk-pgymxpn1.js → chunk-hrd0mft1.js} +136 -34
  21. package/dist/shared/chunk-nmjyj8p9.js +290 -0
  22. package/dist/shared/chunk-pp3a6xbn.js +483 -0
  23. package/dist/shared/chunk-prj7nm08.js +67 -0
  24. package/dist/shared/chunk-q6cpe5k7.js +230 -0
  25. package/dist/shared/chunk-ryb49346.js +374 -0
  26. package/dist/shared/chunk-v3yyf79g.js +48 -0
  27. package/dist/shared/chunk-vx0kzack.js +103 -0
  28. package/dist/shared/chunk-wv6kkj1w.js +464 -0
  29. package/dist/test/index.d.ts +67 -6
  30. package/dist/test/index.js +4 -3
  31. package/package.json +13 -8
  32. package/dist/shared/chunk-bp3v6s9j.js +0 -62
  33. package/dist/shared/chunk-d8h2eh8d.js +0 -141
  34. package/dist/shared/chunk-tsdpgmks.js +0 -98
  35. package/dist/shared/chunk-zbbvx05f.js +0 -202
@@ -1,14 +1,18 @@
1
+ /** A raw CSS declaration: { property, value } for styles that can't be expressed as shorthands. */
2
+ interface RawDeclaration {
3
+ property: string;
4
+ value: string;
5
+ }
6
+ /** A value within a nested selector array: shorthand string or raw declaration. */
7
+ type StyleValue = string | RawDeclaration;
1
8
  /** A style entry in the array: either a shorthand string or an object for nested selectors. */
2
- type StyleEntry = string | Record<string, string[]>;
9
+ type StyleEntry = string | Record<string, StyleValue[]>;
3
10
  /** Input to css(): a record of named style blocks. */
4
11
  type CSSInput = Record<string, StyleEntry[]>;
5
- /** Output of css(): a record of block names to class names, plus extracted CSS. */
6
- interface CSSOutput {
7
- /** Map of block name → generated class name. */
8
- classNames: Record<string, string>;
9
- /** The extracted CSS string. */
10
- css: string;
11
- }
12
+ /** Output of css(): block names as top-level properties, plus non-enumerable `css`. */
13
+ type CSSOutput<T extends CSSInput = CSSInput> = { readonly [K in keyof T & string] : string } & {
14
+ readonly css: string;
15
+ };
12
16
  /**
13
17
  * Process a css() call and produce class names + extracted CSS.
14
18
  *
@@ -20,9 +24,9 @@ interface CSSOutput {
20
24
  *
21
25
  * @param input - Named style blocks.
22
26
  * @param filePath - Source file path for deterministic hashing.
23
- * @returns Class names map and extracted CSS.
27
+ * @returns Object with block names as keys (class name strings) and non-enumerable `css` property.
24
28
  */
25
- declare function css(input: CSSInput, filePath?: string): CSSOutput;
29
+ declare function css<T extends CSSInput>(input: T & { [K in keyof T & "css"]? : never }, filePath?: string): CSSOutput<T>;
26
30
  /** Input to globalCss(): selector → property-value map. */
27
31
  type GlobalCSSInput = Record<string, Record<string, string>>;
28
32
  /** Output of globalCss(): extracted CSS string. */
@@ -94,34 +98,27 @@ declare function defineTheme(input: ThemeInput): Theme;
94
98
  * @returns Compiled CSS and token list.
95
99
  */
96
100
  declare function compileTheme(theme: Theme): CompiledTheme;
97
- /**
98
- * ThemeProvider — Sets `data-theme` attribute for contextual token switching.
99
- *
100
- * Creates a wrapper div element with the appropriate `data-theme` attribute
101
- * so that contextual CSS custom properties (generated by compileTheme) resolve
102
- * to the correct variant values.
103
- *
104
- * Usage:
105
- * ```ts
106
- * ThemeProvider({ theme: 'dark', children: [myApp] });
107
- * ```
108
- */
109
101
  /** A child node: either a DOM Node or a string (text content). */
110
102
  type ThemeChild = Node | string;
111
103
  /** Props for ThemeProvider. */
112
104
  interface ThemeProviderProps {
113
105
  /** The theme variant name (e.g., 'light', 'dark'). Defaults to 'light'. */
114
106
  theme?: string;
115
- /** Child elements to render inside the provider. */
116
- children: ThemeChild[];
107
+ /**
108
+ * Child elements to render inside the provider.
109
+ *
110
+ * Accepts a single child (what TypeScript sees in JSX), an array, or a
111
+ * thunk (what the compiler produces after wrapping JSX children).
112
+ */
113
+ children: ThemeChild | ThemeChild[] | (() => ThemeChild | ThemeChild[]);
117
114
  }
118
115
  /**
119
116
  * Create a wrapper div with `data-theme` attribute for theme switching.
120
117
  *
121
- * @param props - Theme and children.
122
- * @returns A div element with `data-theme` set and children appended.
118
+ * Uses __element() directly (instead of jsx()) so the hydration cursor
119
+ * walker can claim the existing SSR node during mount().
123
120
  */
124
- declare function ThemeProvider(props: ThemeProviderProps): HTMLDivElement;
121
+ declare function ThemeProvider({ theme, children }: ThemeProviderProps): HTMLElement;
125
122
  /** A record of variant names to their possible values (each value maps to style entries). */
126
123
  type VariantDefinitions = Record<string, Record<string, StyleEntry[]>>;
127
124
  /** Extract the variant props type from a variant definitions object. */
@@ -6,7 +6,11 @@ import {
6
6
  globalCss,
7
7
  s,
8
8
  variants
9
- } from "../shared/chunk-f1ynwam4.js";
9
+ } from "../shared/chunk-0p5f7gmg.js";
10
+ import"../shared/chunk-ryb49346.js";
11
+ import"../shared/chunk-g4rch80a.js";
12
+ import"../shared/chunk-hrd0mft1.js";
13
+ import"../shared/chunk-prj7nm08.js";
10
14
  export {
11
15
  variants,
12
16
  s,
@@ -12,11 +12,36 @@ interface Signal<T> {
12
12
  notify(): void;
13
13
  }
14
14
  /**
15
+ * A read-only reactive value derived from other signals.
16
+ */
17
+ interface ReadonlySignal<T> {
18
+ /** Get the current value and subscribe to changes. */
19
+ readonly value: T;
20
+ /** Read the current value without subscribing. */
21
+ peek(): T;
22
+ }
23
+ interface FieldState<T = unknown> {
24
+ error: Signal<string | undefined>;
25
+ dirty: Signal<boolean>;
26
+ touched: Signal<boolean>;
27
+ value: Signal<T>;
28
+ setValue: (value: T) => void;
29
+ reset: () => void;
30
+ }
31
+ declare function createFieldState<T>(_name: string, initialValue?: T): FieldState<T>;
32
+ import { Result } from "@vertz/fetch";
33
+ /**
15
34
  * Minimal schema interface compatible with @vertz/schema.
16
- * Any object with a `parse(data: unknown): T` method satisfies this.
35
+ * Any object with a `parse(data: unknown): Result` method satisfies this.
17
36
  */
18
37
  interface FormSchema<T> {
19
- parse(data: unknown): T;
38
+ parse(data: unknown): {
39
+ ok: true;
40
+ data: T;
41
+ } | {
42
+ ok: false;
43
+ error: unknown;
44
+ };
20
45
  }
21
46
  /** Result of a validation attempt. */
22
47
  type ValidationResult<T> = {
@@ -44,56 +69,87 @@ interface SdkMethod<
44
69
  TBody,
45
70
  TResult
46
71
  > {
47
- (body: TBody): Promise<TResult>;
72
+ (body: TBody): PromiseLike<Result<TResult, Error>>;
48
73
  url: string;
49
74
  method: string;
75
+ meta?: {
76
+ bodySchema?: FormSchema<TBody>;
77
+ };
50
78
  }
51
- /** Options for creating a form instance. */
52
- interface FormOptions<TBody> {
53
- /** Explicit schema for client-side validation before submission. */
54
- schema: FormSchema<TBody>;
79
+ /**
80
+ * An SDK method with embedded schema metadata.
81
+ * Generated by `@vertz/codegen` — carries `.meta.bodySchema` for auto-validation.
82
+ */
83
+ interface SdkMethodWithMeta<
84
+ TBody,
85
+ TResult
86
+ > extends SdkMethod<TBody, TResult> {
87
+ meta: {
88
+ bodySchema: FormSchema<TBody>;
89
+ };
55
90
  }
56
- /** Callbacks for form submission. Both are optional per spec. */
57
- interface SubmitCallbacks<TResult> {
58
- onSuccess?: (result: TResult) => void;
59
- onError?: (errors: Record<string, string>) => void;
91
+ /** Reserved property names that cannot be used as field names on FormInstance. */
92
+ type ReservedFormNames = "submitting" | "dirty" | "valid" | "action" | "method" | "onSubmit" | "reset" | "setFieldError" | "submit" | "__bindElement";
93
+ /** Mapped type providing FieldState for each field in TBody. */
94
+ type FieldAccessors<TBody> = { [K in keyof TBody] : FieldState<TBody[K]> };
95
+ /** Base properties available on every form instance. */
96
+ interface FormBaseProperties<TBody> {
97
+ action: string;
98
+ method: string;
99
+ onSubmit: (e: Event) => Promise<void>;
100
+ reset: () => void;
101
+ setFieldError: (field: keyof TBody & string, message: string) => void;
102
+ submit: (formData?: FormData) => Promise<void>;
103
+ submitting: Signal<boolean>;
104
+ dirty: ReadonlySignal<boolean>;
105
+ valid: ReadonlySignal<boolean>;
106
+ __bindElement: (el: HTMLFormElement) => void;
60
107
  }
61
- /** A form instance bound to an SDK method. */
62
- interface FormInstance<
108
+ /**
109
+ * A form instance bound to an SDK method.
110
+ * Combines base properties with per-field reactive state via Proxy.
111
+ * If TBody has any key that conflicts with ReservedFormNames, it produces a type error.
112
+ * TResult is used by form() overloads for return type inference.
113
+ */
114
+ type FormInstance<
115
+ TBody,
116
+ _TResult
117
+ > = keyof TBody & ReservedFormNames extends never ? FormBaseProperties<TBody> & FieldAccessors<TBody> : {
118
+ __error: `Field name conflicts with reserved form property: ${keyof TBody & ReservedFormNames & string}`;
119
+ };
120
+ /** Options for creating a form instance. */
121
+ interface FormOptions<
63
122
  TBody,
64
123
  TResult
65
124
  > {
66
- /** Returns `{ action, method }` for progressive enhancement in HTML forms. */
67
- attrs(): {
68
- action: string;
69
- method: string;
70
- };
71
- /** Reactive signal indicating whether a submission is in progress. */
72
- submitting: Signal<boolean>;
73
- /**
74
- * Returns an event handler that extracts FormData, validates, and submits.
75
- * Assignable to onSubmit: `onSubmit={userForm.handleSubmit({ onSuccess })}`.
76
- *
77
- * Can also be called directly with FormData for non-DOM usage:
78
- * `userForm.handleSubmit({ onSuccess })(formData)`.
79
- */
80
- handleSubmit(callbacks?: SubmitCallbacks<TResult>): (formDataOrEvent: FormData | Event) => Promise<void>;
81
- /** Returns the error message for a field reactively, or undefined if no error. Type-safe field names. */
82
- error(field: keyof TBody & string): string | undefined;
125
+ /** Explicit schema for client-side validation before submission. */
126
+ schema?: FormSchema<TBody>;
127
+ /** Initial values for form fields. */
128
+ initial?: Partial<TBody> | (() => Partial<TBody>);
129
+ /** Callback invoked after a successful submission. */
130
+ onSuccess?: (result: TResult) => void;
131
+ /** Callback invoked when validation or submission fails. */
132
+ onError?: (errors: Record<string, string>) => void;
133
+ /** When true, reset the form after a successful submission. */
134
+ resetOnSuccess?: boolean;
83
135
  }
84
136
  /**
85
- * Create a form instance bound to an SDK method with schema validation.
137
+ * Create a form instance bound to an SDK method.
86
138
  *
87
- * The form provides:
88
- * - `attrs()` for progressive enhancement (returns action/method from SDK metadata)
89
- * - `handleSubmit()` returns an event handler for FormData extraction, validation, and SDK submission
90
- * - `error()` for reactive field-level error access
91
- * - `submitting` signal for loading state
139
+ * The form provides direct properties for progressive enhancement (action, method, onSubmit),
140
+ * per-field reactive state via Proxy, and submission handling with validation.
141
+ *
142
+ * When the SDK method has `.meta.bodySchema` (generated by `@vertz/codegen`),
143
+ * the schema option is optional. When the SDK method lacks `.meta`, the schema option is required.
92
144
  */
93
145
  declare function form<
94
146
  TBody,
95
147
  TResult
96
- >(sdkMethod: SdkMethod<TBody, TResult>, options: FormOptions<TBody>): FormInstance<TBody, TResult>;
148
+ >(sdkMethod: SdkMethodWithMeta<TBody, TResult>, options?: FormOptions<TBody, TResult>): FormInstance<TBody, TResult>;
149
+ declare function form<
150
+ TBody,
151
+ TResult
152
+ >(sdkMethod: SdkMethod<TBody, TResult>, options: Required<Pick<FormOptions<TBody, TResult>, "schema">> & FormOptions<TBody, TResult>): FormInstance<TBody, TResult>;
97
153
  /** Options for formDataToObject conversion. */
98
154
  interface FormDataOptions {
99
155
  /** When true, coerces numeric strings to numbers and "true"/"false" to booleans. */
@@ -108,4 +164,4 @@ interface FormDataOptions {
108
164
  * "true"/"false" become booleans.
109
165
  */
110
166
  declare function formDataToObject(formData: FormData, options?: FormDataOptions): Record<string, unknown>;
111
- export { validate, formDataToObject, form, ValidationResult, SubmitCallbacks, SdkMethod, FormSchema, FormOptions, FormInstance, FormDataOptions };
167
+ export { validate, formDataToObject, form, createFieldState, ValidationResult, SdkMethodWithMeta, SdkMethod, FormSchema, FormOptions, FormInstance, FormDataOptions, FieldState };
@@ -1,11 +1,13 @@
1
1
  import {
2
+ createFieldState,
2
3
  form,
3
4
  formDataToObject,
4
5
  validate
5
- } from "../shared/chunk-tsdpgmks.js";
6
- import"../shared/chunk-pgymxpn1.js";
6
+ } from "../shared/chunk-q6cpe5k7.js";
7
+ import"../shared/chunk-hrd0mft1.js";
7
8
  export {
8
9
  validate,
9
10
  formDataToObject,
10
- form
11
+ form,
12
+ createFieldState
11
13
  };