@foormjs/vue 0.2.3 → 0.2.5

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.
package/dist/index.d.ts CHANGED
@@ -1,180 +1,488 @@
1
- import { TAtscriptAnnotatedType } from '@atscript/typescript/utils';
2
- import { TAtscriptTypeObject } from '@atscript/typescript/utils';
3
- import { TFoormEntryOptions } from 'foorm';
4
- import { TFoormField } from 'foorm';
1
+ import { AllowedComponentProps } from 'vue';
2
+ import { Component } from 'vue';
3
+ import { ComponentCustomProps } from 'vue';
4
+ import { ComponentOptionsMixin } from 'vue';
5
+ import { ComponentProvideOptions } from 'vue';
6
+ import { ComputedRef } from 'vue';
7
+ import { DefineComponent } from 'vue';
8
+ import { PublicProps } from 'vue';
9
+ import { Ref } from 'vue';
10
+ import { ShallowUnwrapRef } from 'vue';
11
+ import { TAtscriptAnnotatedType } from '@atscript/typescript';
12
+ import { TAtscriptDataType } from '@atscript/typescript';
13
+ import { UnwrapRef } from 'vue';
14
+ import { VNode } from 'vue';
15
+ import { VNodeProps } from 'vue';
5
16
 
6
- export declare const OoField: <TFormData = any, TFormContext = any>(__VLS_props: any, __VLS_ctx?: {
7
- attrs: any;
8
- emit: any;
9
- slots: {
10
- default?(_: {
11
- onBlur: any;
12
- error: any;
13
- model: any;
14
- formData: any;
15
- formContext: any;
16
- label: any;
17
- description: any;
18
- hint: any;
19
- placeholder: any;
20
- classes: any;
21
- styles: any;
22
- optional: any;
23
- disabled: any;
24
- hidden: any;
25
- readonly: any;
26
- type: any;
27
- altAction: any;
28
- component: any;
29
- vName: any;
30
- field: any;
31
- options: any;
32
- maxLength: any;
33
- required: any;
34
- autocomplete: any;
35
- attrs: any;
36
- }): any;
37
- };
38
- }, __VLS_expose?: (exposed: any) => void, __VLS_setup?: Promise<{
39
- props: any;
40
- expose(exposed: any): void;
17
+ declare type __VLS_PrettifyLocal<T> = {
18
+ [K in keyof T]: T[K];
19
+ } & {};
20
+
21
+ declare type __VLS_PrettifyLocal_2<T> = {
22
+ [K in keyof T]: T[K];
23
+ } & {};
24
+
25
+ declare type __VLS_Props = {
26
+ def: FoormDef;
27
+ pathPrefix?: string;
28
+ onRemove?: () => void;
29
+ canRemove?: boolean;
30
+ removeLabel?: string;
31
+ };
32
+
33
+ declare type __VLS_Props_10 = TFoormComponentProps;
34
+
35
+ declare type __VLS_Props_11 = TFoormComponentProps;
36
+
37
+ declare type __VLS_Props_2 = TFoormComponentProps;
38
+
39
+ declare type __VLS_Props_3 = TFoormComponentProps;
40
+
41
+ declare type __VLS_Props_4 = TFoormComponentProps;
42
+
43
+ declare type __VLS_Props_5 = TFoormComponentProps;
44
+
45
+ declare type __VLS_Props_6 = TFoormComponentProps;
46
+
47
+ declare type __VLS_Props_7 = TFoormComponentProps;
48
+
49
+ declare type __VLS_Props_8 = TFoormComponentProps;
50
+
51
+ declare type __VLS_Props_9 = TFoormComponentProps;
52
+
53
+ /**
54
+ * Returns a fresh type-to-component map pre-filled with all built-in defaults.
55
+ *
56
+ * Spread or assign additional entries to extend with custom field types:
57
+ * ```ts
58
+ * const types = { ...createDefaultTypes(), rating: MyRatingComponent }
59
+ * ```
60
+ */
61
+ export declare function createDefaultTypes(): TFoormTypeComponents;
62
+
63
+ /** Extended field def for array-typed fields. */
64
+ declare interface FoormArrayFieldDef extends FoormFieldDef {
65
+ /** ATScript annotated type of array items (from TAtscriptTypeArray.of) */
66
+ itemType: TAtscriptAnnotatedType;
67
+ /** Pre-built template field def for items (path=''). Clone with path/name override per index. */
68
+ itemField: FoormFieldDef;
69
+ }
70
+
71
+ /**
72
+ * Complete form definition — produced by createFoormDef().
73
+ * Form-level metadata (title, submit) resolved on demand via resolveFormProp.
74
+ */
75
+ declare interface FoormDef {
76
+ type: TAtscriptAnnotatedType;
77
+ /** Root field representing the entire form. For interface types this is `type='object'`; for single-type forms it is a leaf field (e.g. `type='text'`). */
78
+ rootField: FoormFieldDef;
79
+ fields: FoormFieldDef[];
80
+ flatMap: Map<string, TAtscriptAnnotatedType>;
81
+ }
82
+
83
+ /**
84
+ * A single form field definition — thin pointer to the ATScript prop.
85
+ *
86
+ * All metadata (label, disabled, options, etc.) lives in `prop.metadata`
87
+ * and is resolved on demand via resolve utilities.
88
+ */
89
+ declare interface FoormFieldDef {
90
+ /** Dot-separated path relative to the parent data context. `''` = root (value IS the data at the path prefix level, e.g. primitive array items). */
91
+ path: string;
92
+ prop: TAtscriptAnnotatedType;
93
+ type: string;
94
+ phantom: boolean;
95
+ name: string;
96
+ /** True when no foorm.fn.* metadata keys exist. Vue perf flag. */
97
+ allStatic: boolean;
98
+ }
99
+
100
+ /** Extended field def for union fields — standalone union props and union array items. */
101
+ declare interface FoormUnionFieldDef extends FoormFieldDef {
102
+ /** Available union branches. */
103
+ unionVariants: FoormUnionVariant[];
104
+ }
105
+
106
+ /** One branch of a union type — used by union fields and union array items. */
107
+ declare interface FoormUnionVariant {
108
+ /** Display label — from @meta.label or auto-generated (e.g. "1. String") */
109
+ label: string;
110
+ /** The annotated type for this variant */
111
+ type: TAtscriptAnnotatedType;
112
+ /** Pre-built FoormDef for object variants (undefined for primitives) */
113
+ def?: FoormDef;
114
+ /** Pre-built field def for primitive variants (undefined for objects) */
115
+ itemField?: FoormFieldDef;
116
+ /** Design type for primitive variants ('string', 'number', 'boolean') */
117
+ designType?: string;
118
+ }
119
+
120
+ /**
121
+ * Format a label/title with an array-index prefix.
122
+ *
123
+ * When `arrayIndex` is defined, prepends `#<index+1>` to the label.
124
+ * Used by field-shell (label) and object (title) components for array items.
125
+ */
126
+ export declare function formatIndexedLabel(label: string | undefined, arrayIndex: number | undefined): string | undefined;
127
+
128
+ export declare const OoAction: DefineComponent<__VLS_Props_7, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
129
+ action: (name: string) => any;
130
+ }, string, PublicProps, Readonly<__VLS_Props_7> & Readonly<{
131
+ onAction?: ((name: string) => any) | undefined;
132
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
133
+
134
+ export declare const OoArray: DefineComponent<__VLS_Props_9, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_9> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {
135
+ addDropdownRef: HTMLDivElement;
136
+ }, HTMLDivElement>;
137
+
138
+ export declare const OoCheckbox: DefineComponent<__VLS_Props_5, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_5> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
139
+
140
+ export declare const OoField: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal_2<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
141
+ props: __VLS_PrettifyLocal_2<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & {
142
+ field: FoormFieldDef;
143
+ error?: string;
144
+ onRemove?: () => void;
145
+ canRemove?: boolean;
146
+ removeLabel?: string;
147
+ arrayIndex?: number;
148
+ } & Partial<{}>> & PublicProps;
149
+ expose(exposed: ShallowUnwrapRef< {}>): void;
41
150
  attrs: any;
42
- slots: {
43
- default?(_: {
44
- onBlur: any;
45
- error: any;
46
- model: any;
47
- formData: any;
48
- formContext: any;
49
- label: any;
50
- description: any;
51
- hint: any;
52
- placeholder: any;
53
- classes: any;
54
- styles: any;
55
- optional: any;
56
- disabled: any;
57
- hidden: any;
58
- readonly: any;
59
- type: any;
60
- altAction: any;
61
- component: any;
62
- vName: any;
63
- field: any;
64
- options: any;
65
- maxLength: any;
66
- required: any;
67
- autocomplete: any;
68
- attrs: any;
69
- }): any;
70
- };
71
- emit: any;
72
- }>) => any;
151
+ slots: {};
152
+ emit: {};
153
+ }>) => VNode & {
154
+ __ctx?: Awaited<typeof __VLS_setup>;
155
+ };
73
156
 
74
- export declare const OoForm: <TFormData = any, TFormContext = any>(__VLS_props: any, __VLS_ctx?: {
157
+ export declare const OoForm: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
158
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
159
+ readonly onAction?: ((name: string, data: TFormData) => any) | undefined;
160
+ readonly onError?: ((errors: {
161
+ path: string;
162
+ message: string;
163
+ }[]) => any) | undefined;
164
+ readonly onSubmit?: ((data: TFormData) => any) | undefined;
165
+ readonly "onUnsupported-action"?: ((name: string, data: TFormData) => any) | undefined;
166
+ readonly onChange?: ((type: TFoormChangeType, path: string, value: unknown, formData: TFormData) => any) | undefined;
167
+ } & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, "onAction" | "onChange" | "onSubmit" | "onError" | "onUnsupported-action"> & Props<TFormData, TFormContext> & Partial<{}>> & PublicProps;
168
+ expose(exposed: ShallowUnwrapRef< {}>): void;
75
169
  attrs: any;
76
- emit: any;
77
- slots: Partial<Record<`field:${any}`, (_: any) => any>> & {
78
- "form.header"?(_: {
79
- clearErrors: any;
80
- reset: any;
81
- title: any;
82
- formContext: any;
83
- disabled: any;
170
+ slots: {
171
+ 'form.header'?(_: {
172
+ clearErrors: () => void;
173
+ reset: () => Promise<void>;
174
+ setErrors: (errors: Record<string, string>) => void;
175
+ formContext: TFormContext | undefined;
176
+ disabled: boolean;
84
177
  }): any;
85
- "form.before"?(_: {
86
- clearErrors: any;
87
- reset: any;
178
+ 'form.before'?(_: {
179
+ clearErrors: () => void;
180
+ reset: () => Promise<void>;
181
+ setErrors: (errors: Record<string, string>) => void;
88
182
  }): any;
89
- "form.after"?(_: {
90
- clearErrors: any;
91
- reset: any;
92
- disabled: any;
93
- formContext: any;
183
+ 'form.after'?(_: {
184
+ clearErrors: () => void;
185
+ reset: () => Promise<void>;
186
+ setErrors: (errors: Record<string, string>) => void;
187
+ disabled: boolean;
188
+ formContext: TFormContext | undefined;
94
189
  }): any;
95
- "form.submit"?(_: {
96
- disabled: any;
97
- text: any;
98
- clearErrors: any;
99
- reset: any;
100
- formContext: any;
190
+ 'form.submit'?(_: {
191
+ disabled: boolean;
192
+ text: string;
193
+ clearErrors: () => void;
194
+ reset: () => Promise<void>;
195
+ setErrors: (errors: Record<string, string>) => void;
196
+ formContext: TFormContext | undefined;
101
197
  }): any;
102
- "form.footer"?(_: {
103
- disabled: any;
104
- clearErrors: any;
105
- reset: any;
106
- formContext: any;
198
+ 'form.footer'?(_: {
199
+ disabled: boolean;
200
+ clearErrors: () => void;
201
+ reset: () => Promise<void>;
202
+ setErrors: (errors: Record<string, string>) => void;
203
+ formContext: TFormContext | undefined;
107
204
  }): any;
108
205
  };
109
- }, __VLS_expose?: (exposed: any) => void, __VLS_setup?: Promise<{
110
- props: any;
111
- expose(exposed: any): void;
112
- attrs: any;
113
- slots: Partial<Record<`field:${any}`, (_: any) => any>> & {
114
- "form.header"?(_: {
115
- clearErrors: any;
116
- reset: any;
117
- title: any;
118
- formContext: any;
119
- disabled: any;
120
- }): any;
121
- "form.before"?(_: {
122
- clearErrors: any;
123
- reset: any;
124
- }): any;
125
- "form.after"?(_: {
126
- clearErrors: any;
127
- reset: any;
128
- disabled: any;
129
- formContext: any;
130
- }): any;
131
- "form.submit"?(_: {
132
- disabled: any;
133
- text: any;
134
- clearErrors: any;
135
- reset: any;
136
- formContext: any;
137
- }): any;
138
- "form.footer"?(_: {
139
- disabled: any;
140
- clearErrors: any;
141
- reset: any;
142
- formContext: any;
143
- }): any;
206
+ emit: {
207
+ (e: "submit", data: TFormData): void;
208
+ (e: "error", errors: {
209
+ path: string;
210
+ message: string;
211
+ }[]): void;
212
+ (e: "action", name: string, data: TFormData): void;
213
+ (e: "unsupported-action", name: string, data: TFormData): void;
214
+ (e: "change", type: TFoormChangeType, path: string, value: unknown, formData: TFormData): void;
144
215
  };
145
- emit: any;
146
- }>) => any;
216
+ }>) => VNode & {
217
+ __ctx?: Awaited<typeof __VLS_setup>;
218
+ };
219
+
220
+ export declare const OoInput: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
221
+
222
+ export declare const OoIterator: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
223
+
224
+ export declare const OoObject: DefineComponent<__VLS_Props_8, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_8> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
225
+
226
+ export declare const OoParagraph: DefineComponent<__VLS_Props_6, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_6> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLParagraphElement>;
227
+
228
+ export declare const OoRadio: DefineComponent<__VLS_Props_4, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_4> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
229
+
230
+ export declare const OoSelect: DefineComponent<__VLS_Props_3, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_3> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
231
+
232
+ export declare const OoTuple: DefineComponent<__VLS_Props_11, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_11> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
233
+
234
+ export declare const OoUnion: DefineComponent<__VLS_Props_10, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_10> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {
235
+ dropdownRef: HTMLDivElement;
236
+ }, HTMLDivElement>;
237
+
238
+ declare interface Props<TF, TC> {
239
+ def: FoormDef;
240
+ formData?: TF;
241
+ formContext?: TC;
242
+ firstValidation?: TFoormState['firstValidation'];
243
+ components?: Record<string, Component<TFoormComponentProps>>;
244
+ /**
245
+ * Type-to-component map for field rendering. Maps field types to Vue components.
246
+ * Must include entries for all built-in field types. Use `createDefaultTypes()`
247
+ * for a pre-filled map, or supply your own.
248
+ */
249
+ types: TFoormTypeComponents;
250
+ errors?: Record<string, string | undefined>;
251
+ }
252
+
253
+ /** Alt-action metadata — the action id and display label. */
254
+ declare interface TFoormAltAction {
255
+ id: string;
256
+ label: string;
257
+ }
147
258
 
148
- export declare interface TFoormComponentProps<V, TFormData, TFormContext> {
149
- onBlur: Function;
259
+ /**
260
+ * Shared base props available to all custom foorm components.
261
+ */
262
+ export declare interface TFoormBaseComponentProps {
263
+ /** Whether this component is disabled. */
264
+ disabled?: boolean;
265
+ /** Whether this component is hidden. */
266
+ hidden?: boolean;
267
+ }
268
+
269
+ /**
270
+ * Discriminated type for the `change` event emitted by `OoForm`.
271
+ *
272
+ * - `'update'` — leaf field value committed (blur)
273
+ * - `'array-add'` — array item added
274
+ * - `'array-remove'` — array item removed
275
+ * - `'union-switch'` — union variant switched
276
+ */
277
+ export declare type TFoormChangeType = 'update' | 'array-add' | 'array-remove' | 'union-switch';
278
+
279
+ /**
280
+ * Props contract for custom field components used with `OoForm` / `OoField`.
281
+ *
282
+ * Implement this interface in your UI components so that `OoField` can pass
283
+ * all resolved field state (value, label, validation errors, etc.) as props.
284
+ *
285
+ * @typeParam V - The field value type
286
+ * @typeParam TFormData - The full form data object type
287
+ * @typeParam TFormContext - The external context object type
288
+ */
289
+ export declare interface TFoormComponentProps<V = unknown> extends TFoormBaseComponentProps {
290
+ /** Called on field blur — triggers validation. */
291
+ onBlur: () => void;
292
+ /** Validation error message for this field, if any. */
150
293
  error?: string;
294
+ /** Reactive model wrapping the field value. Bind with `v-model="model.value"`. */
151
295
  model: {
152
296
  value: V;
153
297
  };
154
- formData: TFormData;
155
- formContext?: TFormContext;
298
+ /** Phantom field display value from `@foorm.value` / `@foorm.fn.value` (paragraphs, actions). `undefined` for data fields. */
299
+ value?: unknown;
300
+ /** Resolved field label from `@label` or `@foorm.fn.label`. */
156
301
  label?: string;
302
+ /** Resolved field description from `@description` or `@foorm.fn.description`. */
157
303
  description?: string;
304
+ /** Resolved hint text from `@foorm.hint` or `@foorm.fn.hint`. */
158
305
  hint?: string;
306
+ /** Resolved placeholder from `@foorm.placeholder` or `@foorm.fn.placeholder`. */
159
307
  placeholder?: string;
308
+ /** CSS class(es) from `@foorm.class` or `@foorm.fn.class`. */
160
309
  class?: Record<string, boolean> | string;
310
+ /** Inline styles from `@foorm.style` or `@foorm.fn.style`. */
161
311
  style?: Record<string, string> | string;
312
+ /** Whether the field is optional (not required). */
162
313
  optional?: boolean | undefined;
314
+ /** Toggle an optional field on/off. `true` sets default value; `false` sets `undefined`. Only present when `optional` is true. */
315
+ onToggleOptional?: (enabled: boolean) => void;
316
+ /** Whether the field is required (inverse of optional). */
163
317
  required?: boolean | undefined;
164
- disabled?: boolean | undefined;
165
- hidden?: boolean | undefined;
318
+ /** Whether the field is read-only. */
319
+ readonly?: boolean | undefined;
320
+ /** The resolved field input type (e.g., `'text'`, `'select'`, `'checkbox'`). */
166
321
  type: string;
167
- altAction?: string;
322
+ /** Alternate action from `@foorm.altAction`. Contains the action id and display label. */
323
+ altAction?: TFoormAltAction;
324
+ /** The field name (last segment of the dot-separated path). */
168
325
  name?: string;
169
- field?: TFoormField;
326
+ /** The full FoormFieldDef for advanced use cases. */
327
+ field?: FoormFieldDef;
328
+ /** Resolved options for select/radio/checkbox fields. */
170
329
  options?: TFoormEntryOptions[];
330
+ /** Max length constraint from `@expect.maxLength`. */
171
331
  maxLength?: number;
332
+ /** Autocomplete hint from `@foorm.autocomplete`. */
172
333
  autocomplete?: string;
334
+ /** Resolved title from `@foorm.title` / `@foorm.fn.title` / `@meta.label` for structure/array fields. */
335
+ title?: string;
336
+ /** Nesting level for structure/array fields. Root structure is 0, each nested structure/array increments by 1. */
337
+ level?: number;
338
+ /** Callback to remove this item from its parent array. Present when rendered inside an array. */
339
+ onRemove?: () => void;
340
+ /** Whether removal is allowed (respects minLength constraints). */
341
+ canRemove?: boolean;
342
+ /** Label for the remove button (from `@foorm.array.remove.label`). */
343
+ removeLabel?: string;
344
+ /** Zero-based index when rendered as a direct array item. `undefined` otherwise. */
345
+ arrayIndex?: number;
346
+ }
347
+
348
+ /** An option for select/radio fields — either a plain string or a `{ key, label }` pair. */
349
+ declare type TFoormEntryOptions = {
350
+ key: string;
351
+ label: string;
352
+ } | string;
353
+
354
+ declare interface TFoormFieldCallbacks {
355
+ validate: () => boolean | string;
356
+ clearErrors: () => void;
357
+ reset: () => void;
358
+ setExternalError: (msg?: string) => void;
359
+ }
360
+
361
+ declare interface TFoormFieldRegistration {
362
+ path: () => string;
363
+ callbacks: TFoormFieldCallbacks;
364
+ }
365
+
366
+ declare interface TFoormState {
367
+ firstSubmitHappened: boolean;
368
+ firstValidation: 'on-change' | 'touched-on-blur' | 'on-blur' | 'on-submit' | 'none';
369
+ register: (id: symbol, registration: TFoormFieldRegistration) => void;
370
+ unregister: (id: symbol) => void;
173
371
  }
174
372
 
175
- export declare function useFoorm<T extends TAtscriptAnnotatedType<TAtscriptTypeObject<any, any>>>(type: T): {
176
- form: any;
177
- formData: any;
373
+ /**
374
+ * Union context provided by `OoUnion` via `__foorm_union` inject key.
375
+ * Consumed by header components (OoStructuredHeader, OoFieldShell) to render
376
+ * the variant picker inline with the item's own header.
377
+ */
378
+ /**
379
+ * Type-to-component map for `OoForm`. Lists all built-in field types as
380
+ * required keys and accepts additional custom types via index signature.
381
+ *
382
+ * Use {@link createDefaultTypes} to get a pre-built map with all defaults.
383
+ */
384
+ export declare type TFoormTypeComponents = {
385
+ text: Component;
386
+ select: Component;
387
+ radio: Component;
388
+ checkbox: Component;
389
+ paragraph: Component;
390
+ action: Component;
391
+ object: Component;
392
+ array: Component;
393
+ union: Component;
394
+ tuple: Component;
395
+ } & Record<string, Component>;
396
+
397
+ export declare interface TFoormUnionContext {
398
+ /** All available union variant branches. */
399
+ variants: FoormUnionVariant[];
400
+ /** Reactive index of the currently selected variant. */
401
+ currentIndex: Ref<number>;
402
+ /** Switch to a different variant (rewrites model data). */
403
+ changeVariant: (index: number) => void;
404
+ }
405
+
406
+ /**
407
+ * Consume and clear the `__foorm_union` injection.
408
+ *
409
+ * Structured components (object, tuple, array, field-shell) call this to
410
+ * read the union context provided by `OoUnion` and immediately clear it
411
+ * so nested children don't inherit it.
412
+ */
413
+ export declare function useConsumeUnionContext(): TFoormUnionContext | undefined;
414
+
415
+ /**
416
+ * Creates a reactive form definition and data object from an ATScript annotated type.
417
+ *
418
+ * @param type - An ATScript annotated type (imported from a `.as` file via `@atscript/typescript`).
419
+ * Accepts any type shape: interface/object, primitive, array, union, etc.
420
+ * For non-object types, the data is wrapped in `{ value: ... }`.
421
+ * @param context - Optional context object passed to `foorm.fn.value` functions during data creation
422
+ * @returns `{ def, formData }` — the FoormDef and a Vue reactive data object with defaults applied
423
+ *
424
+ * @example
425
+ * ```vue
426
+ * <script setup lang="ts">
427
+ * import { useFoorm } from '@foormjs/vue'
428
+ * import { MyForm } from './my-form.as'
429
+ *
430
+ * const { def, formData } = useFoorm(MyForm)
431
+ * </script>
432
+ *
433
+ * <template>
434
+ * <OoForm :def="def" :data="formData" />
435
+ * </template>
436
+ * ```
437
+ */
438
+ export declare function useFoorm<T extends TAtscriptAnnotatedType>(type: T, context?: Record<string, unknown>): {
439
+ def: FoormDef;
440
+ formData: {
441
+ value: UnwrapRef<TAtscriptDataType<T>>;
442
+ };
443
+ };
444
+
445
+ /**
446
+ * Composable for managing array field state.
447
+ *
448
+ * Manages stable keys, add/remove with constraints, and item field resolution.
449
+ * Union item types are handled transparently — OoUnion manages variant state locally.
450
+ * Used by the default `OoArray` component and available for custom array components.
451
+ */
452
+ export declare function useFoormArray(field: FoormArrayFieldDef, disabled?: ComputedRef<boolean>): {
453
+ arrayValue: ComputedRef<unknown[]>;
454
+ itemKeys: string[];
455
+ isUnion: boolean;
456
+ unionVariants: FoormUnionVariant[];
457
+ getItemField: (index: number) => FoormFieldDef;
458
+ addItem: (variantIndex?: number) => void;
459
+ removeItem: (index: number) => void;
460
+ canAdd: ComputedRef<boolean>;
461
+ canRemove: ComputedRef<boolean>;
462
+ addLabel: string;
463
+ removeLabel: string;
464
+ };
465
+
466
+ /**
467
+ * Composable for managing union field state.
468
+ *
469
+ * Manages variant switching with data stashing — switching away from a variant
470
+ * saves its data, and switching back restores it instead of creating fresh defaults.
471
+ * Used by the default `OoUnion` component and available for custom union components.
472
+ */
473
+ export declare function useFoormUnion(props: TFoormComponentProps): {
474
+ unionField: ComputedRef<FoormUnionFieldDef | undefined>;
475
+ hasMultipleVariants: ComputedRef<boolean>;
476
+ localUnionIndex: Ref<number, number>;
477
+ currentVariant: ComputedRef<FoormUnionVariant | undefined>;
478
+ innerField: ComputedRef<FoormFieldDef | undefined>;
479
+ changeVariant: (newIndex: number) => void;
480
+ optionalEnabled: ComputedRef<boolean>;
481
+ dropdownRef: Ref<HTMLElement | null, HTMLElement | null>;
482
+ isOpen: Ref<boolean, boolean>;
483
+ toggle: () => void;
484
+ select: (callback: () => void) => void;
485
+ handleNaClick: () => void;
178
486
  };
179
487
 
180
488
  export { }