@formspec/core 0.1.0-alpha.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,13 @@
1
+ /**
2
+ * `@formspec/core` - Core type definitions for FormSpec
3
+ *
4
+ * This package provides the foundational types used throughout the FormSpec ecosystem:
5
+ * - Form element types (fields, groups, conditionals)
6
+ * - Field and form state types
7
+ * - Data source registry for dynamic enums
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ export type { Validity, FieldState, FormState, DataSourceRegistry, DataSourceOption, FetchOptionsResponse, DataSourceValueType, TextField, NumberField, BooleanField, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, AnyField, Group, Conditional, FormElement, FormSpec, EqualsPredicate, Predicate, } from "./types/index.js";
12
+ export { createInitialFieldState } from "./types/index.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,YAAY,EAEV,QAAQ,EAGR,UAAU,EAGV,SAAS,EAGT,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EAGnB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EAGR,eAAe,EACf,SAAS,GACV,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@formspec/core` - Core type definitions for FormSpec
3
+ *
4
+ * This package provides the foundational types used throughout the FormSpec ecosystem:
5
+ * - Form element types (fields, groups, conditionals)
6
+ * - Field and form state types
7
+ * - Data source registry for dynamic enums
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ // Re-export functions
12
+ export { createInitialFieldState } from "./types/index.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAuCH,sBAAsB;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Registry for dynamic data sources.
3
+ *
4
+ * Extend this interface via module augmentation to register your data sources:
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * declare module "@formspec/core" {
9
+ * interface DataSourceRegistry {
10
+ * countries: { id: string; code: string; name: string };
11
+ * templates: { id: string; name: string; category: string };
12
+ * }
13
+ * }
14
+ * ```
15
+ */
16
+ export interface DataSourceRegistry {
17
+ }
18
+ /**
19
+ * A single option returned by a data source resolver.
20
+ *
21
+ * @typeParam T - The data type for additional option metadata
22
+ */
23
+ export interface DataSourceOption<T = unknown> {
24
+ /** The value stored when this option is selected */
25
+ readonly value: string;
26
+ /** The display label for this option */
27
+ readonly label: string;
28
+ /** Optional additional data associated with this option */
29
+ readonly data?: T;
30
+ }
31
+ /**
32
+ * Response from a data source resolver function.
33
+ *
34
+ * @typeParam T - The data type for option metadata
35
+ */
36
+ export interface FetchOptionsResponse<T = unknown> {
37
+ /** The available options */
38
+ readonly options: readonly DataSourceOption<T>[];
39
+ /** Validity state of the fetch operation */
40
+ readonly validity: "valid" | "invalid" | "unknown";
41
+ /** Optional message (e.g., error description) */
42
+ readonly message?: string;
43
+ }
44
+ /**
45
+ * Gets the value type for a registered data source.
46
+ *
47
+ * If the source has an `id` property, that becomes the value type.
48
+ * Otherwise, defaults to `string`.
49
+ */
50
+ export type DataSourceValueType<Source extends string> = Source extends keyof DataSourceRegistry ? DataSourceRegistry[Source] extends {
51
+ id: infer ID;
52
+ } ? ID : string : string;
53
+ //# sourceMappingURL=data-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/types/data-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,kBAAkB;CAElC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjD,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IAEnD,iDAAiD;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,IACnD,MAAM,SAAS,MAAM,kBAAkB,GACnC,kBAAkB,CAAC,MAAM,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,EAAE,CAAA;CAAE,GACjD,EAAE,GACF,MAAM,GACR,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-source.js","sourceRoot":"","sources":["../../src/types/data-source.ts"],"names":[],"mappings":""}
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Form element type definitions.
3
+ *
4
+ * These types define the structure of form specifications.
5
+ * The structure IS the definition - nesting implies layout and conditional logic.
6
+ */
7
+ /**
8
+ * A text input field.
9
+ *
10
+ * @typeParam N - The field name (string literal type)
11
+ */
12
+ export interface TextField<N extends string> {
13
+ /** Type discriminator for form elements */
14
+ readonly _type: "field";
15
+ /** Field type discriminator - identifies this as a text field */
16
+ readonly _field: "text";
17
+ /** Unique field identifier used as the schema key */
18
+ readonly name: N;
19
+ /** Display label for the field */
20
+ readonly label?: string;
21
+ /** Placeholder text shown when field is empty */
22
+ readonly placeholder?: string;
23
+ /** Whether this field is required for form submission */
24
+ readonly required?: boolean;
25
+ }
26
+ /**
27
+ * A numeric input field.
28
+ *
29
+ * @typeParam N - The field name (string literal type)
30
+ */
31
+ export interface NumberField<N extends string> {
32
+ /** Type discriminator for form elements */
33
+ readonly _type: "field";
34
+ /** Field type discriminator - identifies this as a number field */
35
+ readonly _field: "number";
36
+ /** Unique field identifier used as the schema key */
37
+ readonly name: N;
38
+ /** Display label for the field */
39
+ readonly label?: string;
40
+ /** Minimum allowed value */
41
+ readonly min?: number;
42
+ /** Maximum allowed value */
43
+ readonly max?: number;
44
+ /** Whether this field is required for form submission */
45
+ readonly required?: boolean;
46
+ }
47
+ /**
48
+ * A boolean checkbox field.
49
+ *
50
+ * @typeParam N - The field name (string literal type)
51
+ */
52
+ export interface BooleanField<N extends string> {
53
+ /** Type discriminator for form elements */
54
+ readonly _type: "field";
55
+ /** Field type discriminator - identifies this as a boolean field */
56
+ readonly _field: "boolean";
57
+ /** Unique field identifier used as the schema key */
58
+ readonly name: N;
59
+ /** Display label for the field */
60
+ readonly label?: string;
61
+ /** Whether this field is required for form submission */
62
+ readonly required?: boolean;
63
+ }
64
+ /**
65
+ * A field with static enum options (known at compile time).
66
+ *
67
+ * @typeParam N - The field name (string literal type)
68
+ * @typeParam O - Tuple of option string literals
69
+ */
70
+ export interface StaticEnumField<N extends string, O extends readonly string[]> {
71
+ /** Type discriminator for form elements */
72
+ readonly _type: "field";
73
+ /** Field type discriminator - identifies this as an enum field */
74
+ readonly _field: "enum";
75
+ /** Unique field identifier used as the schema key */
76
+ readonly name: N;
77
+ /** Array of allowed option values */
78
+ readonly options: O;
79
+ /** Display label for the field */
80
+ readonly label?: string;
81
+ /** Whether this field is required for form submission */
82
+ readonly required?: boolean;
83
+ }
84
+ /**
85
+ * A field with dynamic enum options (fetched from a data source at runtime).
86
+ *
87
+ * @typeParam N - The field name (string literal type)
88
+ * @typeParam Source - The data source key (from DataSourceRegistry)
89
+ */
90
+ export interface DynamicEnumField<N extends string, Source extends string> {
91
+ /** Type discriminator for form elements */
92
+ readonly _type: "field";
93
+ /** Field type discriminator - identifies this as a dynamic enum field */
94
+ readonly _field: "dynamic_enum";
95
+ /** Unique field identifier used as the schema key */
96
+ readonly name: N;
97
+ /** Data source key for fetching options at runtime */
98
+ readonly source: Source;
99
+ /** Display label for the field */
100
+ readonly label?: string;
101
+ /** Whether this field is required for form submission */
102
+ readonly required?: boolean;
103
+ /** Field names whose values are needed to fetch options */
104
+ readonly params?: readonly string[];
105
+ }
106
+ /**
107
+ * A field that loads its schema dynamically (e.g., from an extension).
108
+ *
109
+ * @typeParam N - The field name (string literal type)
110
+ */
111
+ export interface DynamicSchemaField<N extends string> {
112
+ /** Type discriminator for form elements */
113
+ readonly _type: "field";
114
+ /** Field type discriminator - identifies this as a dynamic schema field */
115
+ readonly _field: "dynamic_schema";
116
+ /** Unique field identifier used as the schema key */
117
+ readonly name: N;
118
+ /** Identifier for the schema source */
119
+ readonly schemaSource: string;
120
+ /** Display label for the field */
121
+ readonly label?: string;
122
+ /** Whether this field is required for form submission */
123
+ readonly required?: boolean;
124
+ }
125
+ /**
126
+ * An array field containing repeating items.
127
+ *
128
+ * Use this for lists of values (e.g., multiple addresses, line items).
129
+ *
130
+ * @typeParam N - The field name (string literal type)
131
+ * @typeParam Items - The form elements that define each array item
132
+ */
133
+ export interface ArrayField<N extends string, Items extends readonly FormElement[]> {
134
+ /** Type discriminator for form elements */
135
+ readonly _type: "field";
136
+ /** Field type discriminator - identifies this as an array field */
137
+ readonly _field: "array";
138
+ /** Unique field identifier used as the schema key */
139
+ readonly name: N;
140
+ /** Form elements that define the schema for each array item */
141
+ readonly items: Items;
142
+ /** Display label for the field */
143
+ readonly label?: string;
144
+ /** Whether this field is required for form submission */
145
+ readonly required?: boolean;
146
+ /** Minimum number of items required */
147
+ readonly minItems?: number;
148
+ /** Maximum number of items allowed */
149
+ readonly maxItems?: number;
150
+ }
151
+ /**
152
+ * An object field containing nested properties.
153
+ *
154
+ * Use this for grouping related fields under a single key in the schema.
155
+ *
156
+ * @typeParam N - The field name (string literal type)
157
+ * @typeParam Properties - The form elements that define the object's properties
158
+ */
159
+ export interface ObjectField<N extends string, Properties extends readonly FormElement[]> {
160
+ /** Type discriminator for form elements */
161
+ readonly _type: "field";
162
+ /** Field type discriminator - identifies this as an object field */
163
+ readonly _field: "object";
164
+ /** Unique field identifier used as the schema key */
165
+ readonly name: N;
166
+ /** Form elements that define the properties of this object */
167
+ readonly properties: Properties;
168
+ /** Display label for the field */
169
+ readonly label?: string;
170
+ /** Whether this field is required for form submission */
171
+ readonly required?: boolean;
172
+ }
173
+ /**
174
+ * Union of all field types.
175
+ */
176
+ export type AnyField = TextField<string> | NumberField<string> | BooleanField<string> | StaticEnumField<string, readonly string[]> | DynamicEnumField<string, string> | DynamicSchemaField<string> | ArrayField<string, readonly FormElement[]> | ObjectField<string, readonly FormElement[]>;
177
+ /**
178
+ * A visual grouping of form elements.
179
+ *
180
+ * Groups provide visual organization and can be rendered as fieldsets or sections.
181
+ *
182
+ * @typeParam Elements - Tuple of contained form elements
183
+ */
184
+ export interface Group<Elements extends readonly FormElement[]> {
185
+ /** Type discriminator - identifies this as a group element */
186
+ readonly _type: "group";
187
+ /** Display label for the group */
188
+ readonly label: string;
189
+ /** Form elements contained within this group */
190
+ readonly elements: Elements;
191
+ }
192
+ /**
193
+ * A conditional wrapper that shows/hides elements based on another field's value.
194
+ *
195
+ * @typeParam FieldName - The field to check
196
+ * @typeParam Value - The value that triggers the condition
197
+ * @typeParam Elements - Tuple of contained form elements
198
+ */
199
+ export interface Conditional<FieldName extends string, Value, Elements extends readonly FormElement[]> {
200
+ /** Type discriminator - identifies this as a conditional element */
201
+ readonly _type: "conditional";
202
+ /** Name of the field whose value determines visibility */
203
+ readonly field: FieldName;
204
+ /** Value that triggers the condition (shows nested elements) */
205
+ readonly value: Value;
206
+ /** Form elements shown when condition is met */
207
+ readonly elements: Elements;
208
+ }
209
+ /**
210
+ * Union of all form element types (fields and structural elements).
211
+ */
212
+ export type FormElement = AnyField | Group<readonly FormElement[]> | Conditional<string, unknown, readonly FormElement[]>;
213
+ /**
214
+ * A complete form specification.
215
+ *
216
+ * @typeParam Elements - Tuple of top-level form elements
217
+ */
218
+ export interface FormSpec<Elements extends readonly FormElement[]> {
219
+ /** Top-level form elements */
220
+ readonly elements: Elements;
221
+ }
222
+ //# sourceMappingURL=elements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../src/types/elements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM;IACzC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM;IAC3C,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,q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KAAK,EAAE,OAAO,CAAC;IACxB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW,CAC1B,SAAS,SAAS,MAAM,EACxB,KAAK,EACL,QAAQ,SAAS,SAAS,WAAW,EAAE;IAEvC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,KAAK,CAAC,SAAS,WAAW,EAAE,CAAC,GAC7B,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC;AAMzD;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,QAAQ,SAAS,SAAS,WAAW,EAAE;IAC/D,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Form element type definitions.
3
+ *
4
+ * These types define the structure of form specifications.
5
+ * The structure IS the definition - nesting implies layout and conditional logic.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../../src/types/elements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,27 @@
1
+ import type { Validity } from "./validity.js";
2
+ /**
3
+ * Represents the runtime state of a single form field.
4
+ *
5
+ * @typeParam T - The value type of the field
6
+ */
7
+ export interface FieldState<T> {
8
+ /** Current value of the field */
9
+ readonly value: T;
10
+ /** Whether the field has been modified by the user */
11
+ readonly dirty: boolean;
12
+ /** Whether the field has been focused and blurred */
13
+ readonly touched: boolean;
14
+ /** Current validity state */
15
+ readonly validity: Validity;
16
+ /** Validation error messages, if any */
17
+ readonly errors: readonly string[];
18
+ }
19
+ /**
20
+ * Creates initial field state with default values.
21
+ *
22
+ * @typeParam T - The value type of the field
23
+ * @param value - The initial value for the field
24
+ * @returns Initial field state
25
+ */
26
+ export declare function createInitialFieldState<T>(value: T): FieldState<T>;
27
+ //# sourceMappingURL=field-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-state.d.ts","sourceRoot":"","sources":["../../src/types/field-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAElB,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,6BAA6B;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAQlE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Creates initial field state with default values.
3
+ *
4
+ * @typeParam T - The value type of the field
5
+ * @param value - The initial value for the field
6
+ * @returns Initial field state
7
+ */
8
+ export function createInitialFieldState(value) {
9
+ return {
10
+ value,
11
+ dirty: false,
12
+ touched: false,
13
+ validity: "unknown",
14
+ errors: [],
15
+ };
16
+ }
17
+ //# sourceMappingURL=field-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-state.js","sourceRoot":"","sources":["../../src/types/field-state.ts"],"names":[],"mappings":"AAwBA;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAI,KAAQ;IACjD,OAAO;QACL,KAAK;QACL,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { FieldState } from "./field-state.js";
2
+ import type { Validity } from "./validity.js";
3
+ /**
4
+ * Represents the runtime state of an entire form.
5
+ *
6
+ * @typeParam Schema - The form schema type (maps field names to value types)
7
+ */
8
+ export interface FormState<Schema extends Record<string, unknown>> {
9
+ /** State for each field, keyed by field name */
10
+ readonly fields: {
11
+ readonly [K in keyof Schema]: FieldState<Schema[K]>;
12
+ };
13
+ /** Whether any field has been modified */
14
+ readonly dirty: boolean;
15
+ /** Whether the form is currently being submitted */
16
+ readonly submitting: boolean;
17
+ /** Overall form validity (derived from all field validities) */
18
+ readonly validity: Validity;
19
+ }
20
+ //# sourceMappingURL=form-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-state.d.ts","sourceRoot":"","sources":["../../src/types/form-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/D,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,EAAE,CAAC,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACpD,CAAC;IAEF,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=form-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-state.js","sourceRoot":"","sources":["../../src/types/form-state.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export type { Validity } from "./validity.js";
2
+ export type { FieldState } from "./field-state.js";
3
+ export { createInitialFieldState } from "./field-state.js";
4
+ export type { FormState } from "./form-state.js";
5
+ export type { DataSourceRegistry, DataSourceOption, FetchOptionsResponse, DataSourceValueType, } from "./data-source.js";
6
+ export type { TextField, NumberField, BooleanField, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, AnyField, Group, Conditional, FormElement, FormSpec, } from "./elements.js";
7
+ export type { EqualsPredicate, Predicate } from "./predicate.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,GACT,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Re-export all types from the types directory
2
+ export { createInitialFieldState } from "./field-state.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAK/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Predicate types for conditional logic.
3
+ *
4
+ * Predicates are used with `when()` to define conditions in a readable way.
5
+ */
6
+ /**
7
+ * An equality predicate that checks if a field equals a specific value.
8
+ *
9
+ * @typeParam K - The field name to check
10
+ * @typeParam V - The value to compare against
11
+ */
12
+ export interface EqualsPredicate<K extends string, V> {
13
+ /** Predicate type discriminator */
14
+ readonly _predicate: "equals";
15
+ /** Name of the field to check */
16
+ readonly field: K;
17
+ /** Value that the field must equal */
18
+ readonly value: V;
19
+ }
20
+ /**
21
+ * Union of all predicate types.
22
+ *
23
+ * Currently only supports equality, but can be extended with:
24
+ * - `OneOfPredicate` - field value is one of several options
25
+ * - `NotPredicate` - negation of another predicate
26
+ * - `AndPredicate` / `OrPredicate` - logical combinations
27
+ */
28
+ export type Predicate<K extends string = string, V = unknown> = EqualsPredicate<K, V>;
29
+ //# sourceMappingURL=predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../src/types/predicate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC;IAClD,mCAAmC;IACnC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Predicate types for conditional logic.
3
+ *
4
+ * Predicates are used with `when()` to define conditions in a readable way.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=predicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicate.js","sourceRoot":"","sources":["../../src/types/predicate.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Represents the validity state of a field or form.
3
+ *
4
+ * - `"valid"` - All validations pass
5
+ * - `"invalid"` - One or more validations failed
6
+ * - `"unknown"` - Validation state not yet determined (e.g., async validation pending)
7
+ */
8
+ export type Validity = "valid" | "invalid" | "unknown";
9
+ //# sourceMappingURL=validity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.d.ts","sourceRoot":"","sources":["../../src/types/validity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validity.js","sourceRoot":"","sources":["../../src/types/validity.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@formspec/core",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Core utilities for formspec",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/core.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/core.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "keywords": [],
21
+ "license": "UNLICENSED",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "clean": "rm -rf dist temp",
25
+ "typecheck": "tsc --noEmit",
26
+ "api-extractor": "api-extractor run",
27
+ "api-extractor:local": "api-extractor run --local",
28
+ "api-documenter": "api-documenter markdown -i temp -o docs"
29
+ }
30
+ }