formspec 0.1.0-alpha.26 → 0.1.0-alpha.28
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/LICENSE +21 -0
- package/README.md +9 -3
- package/dist/formspec-alpha.d.ts +32 -481
- package/dist/formspec-beta.d.ts +32 -481
- package/dist/formspec-internal.d.ts +32 -481
- package/dist/formspec.d.ts +32 -481
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mike North
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -65,7 +65,6 @@ const resolvers = defineResolvers(OrderForm, {});
|
|
|
65
65
|
- `generateJsonSchema`
|
|
66
66
|
- `generateUiSchema`
|
|
67
67
|
- `writeSchemas`
|
|
68
|
-
- `buildMixedAuthoringSchemas`
|
|
69
68
|
|
|
70
69
|
### Runtime
|
|
71
70
|
|
|
@@ -76,14 +75,21 @@ const resolvers = defineResolvers(OrderForm, {});
|
|
|
76
75
|
- `InferSchema`
|
|
77
76
|
- `InferFormSchema`
|
|
78
77
|
- core field, layout, and state types
|
|
78
|
+
- resolver and validation helper types
|
|
79
|
+
|
|
80
|
+
### Utilities
|
|
81
|
+
|
|
82
|
+
- `createInitialFieldState`
|
|
83
|
+
- `validateForm`
|
|
84
|
+
- `logValidationIssues`
|
|
79
85
|
|
|
80
86
|
## When To Use Individual Packages
|
|
81
87
|
|
|
82
|
-
- Use `@formspec/build` directly for `generateSchemas()` and static TypeScript analysis.
|
|
88
|
+
- Use `@formspec/build` directly for `generateSchemas()`, `generateSchemasFromClass()`, `generateSchemasFromProgram()`, `buildMixedAuthoringSchemas()`, and static TypeScript analysis.
|
|
83
89
|
- Use `@formspec/eslint-plugin` for lint rules.
|
|
84
90
|
- Use `@formspec/cli` for build-time artifact generation from files.
|
|
85
91
|
- Use `@formspec/validator` for runtime JSON Schema validation.
|
|
86
92
|
|
|
87
93
|
## License
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
This package is part of the FormSpec monorepo and is released under the MIT License. See [LICENSE](./LICENSE) for details.
|
package/dist/formspec-alpha.d.ts
CHANGED
|
@@ -59,13 +59,6 @@
|
|
|
59
59
|
*/
|
|
60
60
|
export declare type AnyField = TextField<string> | NumberField<string> | BooleanField<string> | StaticEnumField<string, readonly EnumOptionValue[]> | DynamicEnumField<string, string> | DynamicSchemaField<string> | ArrayField<string, readonly FormElement[]> | ObjectField<string, readonly FormElement[]>;
|
|
61
61
|
|
|
62
|
-
/**
|
|
63
|
-
* Union of all field types.
|
|
64
|
-
*
|
|
65
|
-
* @public
|
|
66
|
-
*/
|
|
67
|
-
declare type AnyField_2 = TextField_2<string> | NumberField_2<string> | BooleanField_2<string> | StaticEnumField_2<string, readonly EnumOptionValue_2[]> | DynamicEnumField_2<string, string> | DynamicSchemaField_2<string> | ArrayField_2<string, readonly FormElement_2[]> | ObjectField_2<string, readonly FormElement_2[]>;
|
|
68
|
-
|
|
69
62
|
/**
|
|
70
63
|
* An array field containing repeating items.
|
|
71
64
|
*
|
|
@@ -95,35 +88,6 @@ export declare interface ArrayField<N extends string, Items extends readonly For
|
|
|
95
88
|
readonly maxItems?: number;
|
|
96
89
|
}
|
|
97
90
|
|
|
98
|
-
/**
|
|
99
|
-
* An array field containing repeating items.
|
|
100
|
-
*
|
|
101
|
-
* Use this for lists of values (e.g., multiple addresses, line items).
|
|
102
|
-
*
|
|
103
|
-
* @typeParam N - The field name (string literal type)
|
|
104
|
-
* @typeParam Items - The form elements that define each array item
|
|
105
|
-
*
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
declare interface ArrayField_2<N extends string, Items extends readonly FormElement_2[]> {
|
|
109
|
-
/** Type discriminator for form elements */
|
|
110
|
-
readonly _type: "field";
|
|
111
|
-
/** Field type discriminator - identifies this as an array field */
|
|
112
|
-
readonly _field: "array";
|
|
113
|
-
/** Unique field identifier used as the schema key */
|
|
114
|
-
readonly name: N;
|
|
115
|
-
/** Form elements that define the schema for each array item */
|
|
116
|
-
readonly items: Items;
|
|
117
|
-
/** Display label for the field */
|
|
118
|
-
readonly label?: string;
|
|
119
|
-
/** Whether this field is required for form submission */
|
|
120
|
-
readonly required?: boolean;
|
|
121
|
-
/** Minimum number of items required */
|
|
122
|
-
readonly minItems?: number;
|
|
123
|
-
/** Maximum number of items allowed */
|
|
124
|
-
readonly maxItems?: number;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
91
|
/**
|
|
128
92
|
* A boolean checkbox field.
|
|
129
93
|
*
|
|
@@ -144,26 +108,6 @@ export declare interface BooleanField<N extends string> {
|
|
|
144
108
|
readonly required?: boolean;
|
|
145
109
|
}
|
|
146
110
|
|
|
147
|
-
/**
|
|
148
|
-
* A boolean checkbox field.
|
|
149
|
-
*
|
|
150
|
-
* @typeParam N - The field name (string literal type)
|
|
151
|
-
*
|
|
152
|
-
* @public
|
|
153
|
-
*/
|
|
154
|
-
declare interface BooleanField_2<N extends string> {
|
|
155
|
-
/** Type discriminator for form elements */
|
|
156
|
-
readonly _type: "field";
|
|
157
|
-
/** Field type discriminator - identifies this as a boolean field */
|
|
158
|
-
readonly _field: "boolean";
|
|
159
|
-
/** Unique field identifier used as the schema key */
|
|
160
|
-
readonly name: N;
|
|
161
|
-
/** Display label for the field */
|
|
162
|
-
readonly label?: string;
|
|
163
|
-
/** Whether this field is required for form submission */
|
|
164
|
-
readonly required?: boolean;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
111
|
/**
|
|
168
112
|
* Builds both JSON Schema and UI Schema from a FormSpec.
|
|
169
113
|
*
|
|
@@ -260,26 +204,6 @@ export declare interface Conditional<FieldName extends string, Value, Elements e
|
|
|
260
204
|
readonly elements: Elements;
|
|
261
205
|
}
|
|
262
206
|
|
|
263
|
-
/**
|
|
264
|
-
* A conditional wrapper that shows/hides elements based on another field's value.
|
|
265
|
-
*
|
|
266
|
-
* @typeParam FieldName - The field to check
|
|
267
|
-
* @typeParam Value - The value that triggers the condition
|
|
268
|
-
* @typeParam Elements - Tuple of contained form elements
|
|
269
|
-
*
|
|
270
|
-
* @public
|
|
271
|
-
*/
|
|
272
|
-
declare interface Conditional_2<FieldName extends string, Value, Elements extends readonly FormElement_2[]> {
|
|
273
|
-
/** Type discriminator - identifies this as a conditional element */
|
|
274
|
-
readonly _type: "conditional";
|
|
275
|
-
/** Name of the field whose value determines visibility */
|
|
276
|
-
readonly field: FieldName;
|
|
277
|
-
/** Value that triggers the condition (shows nested elements) */
|
|
278
|
-
readonly value: Value;
|
|
279
|
-
/** Form elements shown when condition is met */
|
|
280
|
-
readonly elements: Elements;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
207
|
/**
|
|
284
208
|
* A Control element that binds to a JSON Schema property.
|
|
285
209
|
*
|
|
@@ -391,31 +315,6 @@ export declare interface DynamicEnumField<N extends string, Source extends strin
|
|
|
391
315
|
readonly params?: readonly string[];
|
|
392
316
|
}
|
|
393
317
|
|
|
394
|
-
/**
|
|
395
|
-
* A field with dynamic enum options (fetched from a data source at runtime).
|
|
396
|
-
*
|
|
397
|
-
* @typeParam N - The field name (string literal type)
|
|
398
|
-
* @typeParam Source - The data source key (from DataSourceRegistry)
|
|
399
|
-
*
|
|
400
|
-
* @public
|
|
401
|
-
*/
|
|
402
|
-
declare interface DynamicEnumField_2<N extends string, Source extends string> {
|
|
403
|
-
/** Type discriminator for form elements */
|
|
404
|
-
readonly _type: "field";
|
|
405
|
-
/** Field type discriminator - identifies this as a dynamic enum field */
|
|
406
|
-
readonly _field: "dynamic_enum";
|
|
407
|
-
/** Unique field identifier used as the schema key */
|
|
408
|
-
readonly name: N;
|
|
409
|
-
/** Data source key for fetching options at runtime */
|
|
410
|
-
readonly source: Source;
|
|
411
|
-
/** Display label for the field */
|
|
412
|
-
readonly label?: string;
|
|
413
|
-
/** Whether this field is required for form submission */
|
|
414
|
-
readonly required?: boolean;
|
|
415
|
-
/** Field names whose values are needed to fetch options */
|
|
416
|
-
readonly params?: readonly string[];
|
|
417
|
-
}
|
|
418
|
-
|
|
419
318
|
/**
|
|
420
319
|
* A field that loads its schema dynamically (e.g., from an extension).
|
|
421
320
|
*
|
|
@@ -440,30 +339,6 @@ export declare interface DynamicSchemaField<N extends string> {
|
|
|
440
339
|
readonly params?: readonly string[];
|
|
441
340
|
}
|
|
442
341
|
|
|
443
|
-
/**
|
|
444
|
-
* A field that loads its schema dynamically (e.g., from an extension).
|
|
445
|
-
*
|
|
446
|
-
* @typeParam N - The field name (string literal type)
|
|
447
|
-
*
|
|
448
|
-
* @public
|
|
449
|
-
*/
|
|
450
|
-
declare interface DynamicSchemaField_2<N extends string> {
|
|
451
|
-
/** Type discriminator for form elements */
|
|
452
|
-
readonly _type: "field";
|
|
453
|
-
/** Field type discriminator - identifies this as a dynamic schema field */
|
|
454
|
-
readonly _field: "dynamic_schema";
|
|
455
|
-
/** Unique field identifier used as the schema key */
|
|
456
|
-
readonly name: N;
|
|
457
|
-
/** Identifier for the schema source */
|
|
458
|
-
readonly schemaSource: string;
|
|
459
|
-
/** Display label for the field */
|
|
460
|
-
readonly label?: string;
|
|
461
|
-
/** Whether this field is required for form submission */
|
|
462
|
-
readonly required?: boolean;
|
|
463
|
-
/** Field names whose values are needed to configure the schema */
|
|
464
|
-
readonly params?: readonly string[];
|
|
465
|
-
}
|
|
466
|
-
|
|
467
342
|
/**
|
|
468
343
|
* An enum option with a separate ID and display label.
|
|
469
344
|
*
|
|
@@ -478,20 +353,6 @@ export declare interface EnumOption {
|
|
|
478
353
|
readonly label: string;
|
|
479
354
|
}
|
|
480
355
|
|
|
481
|
-
/**
|
|
482
|
-
* An enum option with a separate ID and display label.
|
|
483
|
-
*
|
|
484
|
-
* Use this when the stored value (id) should differ from the display text (label).
|
|
485
|
-
*
|
|
486
|
-
* @public
|
|
487
|
-
*/
|
|
488
|
-
declare interface EnumOption_2 {
|
|
489
|
-
/** Stored enum value written into submitted data. */
|
|
490
|
-
readonly id: string;
|
|
491
|
-
/** Human-readable label shown to end users. */
|
|
492
|
-
readonly label: string;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
356
|
/**
|
|
496
357
|
* Valid enum option types: either plain strings or objects with id/label.
|
|
497
358
|
*
|
|
@@ -499,13 +360,6 @@ declare interface EnumOption_2 {
|
|
|
499
360
|
*/
|
|
500
361
|
export declare type EnumOptionValue = string | EnumOption;
|
|
501
362
|
|
|
502
|
-
/**
|
|
503
|
-
* Valid enum option types: either plain strings or objects with id/label.
|
|
504
|
-
*
|
|
505
|
-
* @public
|
|
506
|
-
*/
|
|
507
|
-
declare type EnumOptionValue_2 = string | EnumOption_2;
|
|
508
|
-
|
|
509
363
|
/**
|
|
510
364
|
* Predicate types for conditional logic.
|
|
511
365
|
*
|
|
@@ -604,178 +458,11 @@ export declare interface FetchOptionsResponse<T = unknown> {
|
|
|
604
458
|
}
|
|
605
459
|
|
|
606
460
|
/**
|
|
607
|
-
* Field builder
|
|
608
|
-
*
|
|
609
|
-
* @example
|
|
610
|
-
* ```typescript
|
|
611
|
-
* import { field } from "@formspec/dsl";
|
|
612
|
-
*
|
|
613
|
-
* field.text("name", { label: "Full Name" });
|
|
614
|
-
* field.number("age", { min: 0, max: 150 });
|
|
615
|
-
* field.enum("status", ["draft", "sent", "paid"]);
|
|
616
|
-
* field.dynamicEnum("country", "countries", { label: "Country" });
|
|
617
|
-
* ```
|
|
461
|
+
* Field builder helpers that preserve this package's exported type identities.
|
|
618
462
|
*
|
|
619
463
|
* @public
|
|
620
464
|
*/
|
|
621
|
-
export declare const field:
|
|
622
|
-
/**
|
|
623
|
-
* Creates a text input field.
|
|
624
|
-
*
|
|
625
|
-
* @param name - The field name (used as the schema key)
|
|
626
|
-
* @param config - Optional configuration for label, placeholder, etc.
|
|
627
|
-
* @returns A TextField descriptor
|
|
628
|
-
*/
|
|
629
|
-
text: <const N extends string>(name: N, config?: Omit<TextField_2<N>, "_type" | "_field" | "name">) => TextField_2<N>;
|
|
630
|
-
/**
|
|
631
|
-
* Creates a numeric input field.
|
|
632
|
-
*
|
|
633
|
-
* @param name - The field name (used as the schema key)
|
|
634
|
-
* @param config - Optional configuration for label, min, max, etc.
|
|
635
|
-
* @returns A NumberField descriptor
|
|
636
|
-
*/
|
|
637
|
-
number: <const N extends string>(name: N, config?: Omit<NumberField_2<N>, "_type" | "_field" | "name">) => NumberField_2<N>;
|
|
638
|
-
/**
|
|
639
|
-
* Creates a boolean checkbox field.
|
|
640
|
-
*
|
|
641
|
-
* @param name - The field name (used as the schema key)
|
|
642
|
-
* @param config - Optional configuration for label, etc.
|
|
643
|
-
* @returns A BooleanField descriptor
|
|
644
|
-
*/
|
|
645
|
-
boolean: <const N extends string>(name: N, config?: Omit<BooleanField_2<N>, "_type" | "_field" | "name">) => BooleanField_2<N>;
|
|
646
|
-
/**
|
|
647
|
-
* Creates a field with static enum options (known at compile time).
|
|
648
|
-
*
|
|
649
|
-
* Literal types are automatically inferred - no `as const` needed:
|
|
650
|
-
* ```typescript
|
|
651
|
-
* field.enum("status", ["draft", "sent", "paid"])
|
|
652
|
-
* // Schema type: "draft" | "sent" | "paid"
|
|
653
|
-
* ```
|
|
654
|
-
*
|
|
655
|
-
* Options can be strings or objects with `id` and `label`:
|
|
656
|
-
* ```typescript
|
|
657
|
-
* field.enum("priority", [
|
|
658
|
-
* { id: "low", label: "Low Priority" },
|
|
659
|
-
* { id: "high", label: "High Priority" },
|
|
660
|
-
* ])
|
|
661
|
-
* ```
|
|
662
|
-
*
|
|
663
|
-
* **Note:** All options must be of the same type (all strings OR all objects).
|
|
664
|
-
* Mixing strings and objects will throw a runtime error.
|
|
665
|
-
*
|
|
666
|
-
* @param name - The field name (used as the schema key)
|
|
667
|
-
* @param options - Array of allowed string values or objects with `id` and `label` properties
|
|
668
|
-
* @param config - Optional configuration for label, etc.
|
|
669
|
-
* @returns A StaticEnumField descriptor
|
|
670
|
-
* @throws Error if options array contains mixed types (strings and objects)
|
|
671
|
-
*/
|
|
672
|
-
enum: <const N extends string, const O extends readonly EnumOptionValue_2[]>(name: N, options: O, config?: Omit<StaticEnumField_2<N, O>, "_type" | "_field" | "name" | "options">) => StaticEnumField_2<N, O>;
|
|
673
|
-
/**
|
|
674
|
-
* Creates a field with dynamic enum options (fetched from a data source at runtime).
|
|
675
|
-
*
|
|
676
|
-
* The data source must be registered in DataSourceRegistry via module augmentation:
|
|
677
|
-
* ```typescript
|
|
678
|
-
* declare module "@formspec/core" {
|
|
679
|
-
* interface DataSourceRegistry {
|
|
680
|
-
* countries: { id: string; code: string; name: string };
|
|
681
|
-
* }
|
|
682
|
-
* }
|
|
683
|
-
*
|
|
684
|
-
* field.dynamicEnum("country", "countries", { label: "Country" })
|
|
685
|
-
* ```
|
|
686
|
-
*
|
|
687
|
-
* @param name - The field name (used as the schema key)
|
|
688
|
-
* @param source - The data source key (must be in DataSourceRegistry)
|
|
689
|
-
* @param config - Optional configuration for label, params, etc.
|
|
690
|
-
* @returns A DynamicEnumField descriptor
|
|
691
|
-
*/
|
|
692
|
-
dynamicEnum: <const N extends string, const Source extends string>(name: N, source: Source, config?: Omit<DynamicEnumField_2<N, Source>, "_type" | "_field" | "name" | "source">) => DynamicEnumField_2<N, Source>;
|
|
693
|
-
/**
|
|
694
|
-
* Creates a field that loads its schema dynamically (e.g., from an extension).
|
|
695
|
-
*
|
|
696
|
-
* @param name - The field name (used as the schema key)
|
|
697
|
-
* @param schemaSource - Identifier for the schema source
|
|
698
|
-
* @param config - Optional configuration for label, etc.
|
|
699
|
-
* @returns A DynamicSchemaField descriptor
|
|
700
|
-
*/
|
|
701
|
-
dynamicSchema: <const N extends string>(name: N, schemaSource: string, config?: Omit<DynamicSchemaField_2<N>, "_type" | "_field" | "name" | "schemaSource">) => DynamicSchemaField_2<N>;
|
|
702
|
-
/**
|
|
703
|
-
* Creates an array field containing repeating items.
|
|
704
|
-
*
|
|
705
|
-
* Use this for lists of values (e.g., multiple addresses, line items).
|
|
706
|
-
*
|
|
707
|
-
* @example
|
|
708
|
-
* ```typescript
|
|
709
|
-
* field.array("addresses",
|
|
710
|
-
* field.text("street", { label: "Street" }),
|
|
711
|
-
* field.text("city", { label: "City" }),
|
|
712
|
-
* field.text("zip", { label: "ZIP Code" }),
|
|
713
|
-
* )
|
|
714
|
-
* ```
|
|
715
|
-
*
|
|
716
|
-
* @param name - The field name (used as the schema key)
|
|
717
|
-
* @param items - The form elements that define each array item
|
|
718
|
-
* @returns An ArrayField descriptor
|
|
719
|
-
*/
|
|
720
|
-
array: <const N extends string, const Items extends readonly FormElement_2[]>(name: N, ...items: Items) => ArrayField_2<N, Items>;
|
|
721
|
-
/**
|
|
722
|
-
* Creates an array field with additional configuration options.
|
|
723
|
-
*
|
|
724
|
-
* @example
|
|
725
|
-
* ```typescript
|
|
726
|
-
* field.arrayWithConfig("lineItems", {
|
|
727
|
-
* label: "Line Items",
|
|
728
|
-
* minItems: 1,
|
|
729
|
-
* maxItems: 10,
|
|
730
|
-
* },
|
|
731
|
-
* field.text("description"),
|
|
732
|
-
* field.number("quantity"),
|
|
733
|
-
* )
|
|
734
|
-
* ```
|
|
735
|
-
*
|
|
736
|
-
* @param name - The field name (used as the schema key)
|
|
737
|
-
* @param config - Configuration for label, minItems, maxItems, etc.
|
|
738
|
-
* @param items - The form elements that define each array item
|
|
739
|
-
* @returns An ArrayField descriptor
|
|
740
|
-
*/
|
|
741
|
-
arrayWithConfig: <const N extends string, const Items extends readonly FormElement_2[]>(name: N, config: Omit<ArrayField_2<N, Items>, "_type" | "_field" | "name" | "items">, ...items: Items) => ArrayField_2<N, Items>;
|
|
742
|
-
/**
|
|
743
|
-
* Creates an object field containing nested properties.
|
|
744
|
-
*
|
|
745
|
-
* Use this for grouping related fields under a single key in the schema.
|
|
746
|
-
*
|
|
747
|
-
* @example
|
|
748
|
-
* ```typescript
|
|
749
|
-
* field.object("address",
|
|
750
|
-
* field.text("street", { label: "Street" }),
|
|
751
|
-
* field.text("city", { label: "City" }),
|
|
752
|
-
* field.text("zip", { label: "ZIP Code" }),
|
|
753
|
-
* )
|
|
754
|
-
* ```
|
|
755
|
-
*
|
|
756
|
-
* @param name - The field name (used as the schema key)
|
|
757
|
-
* @param properties - The form elements that define the object's properties
|
|
758
|
-
* @returns An ObjectField descriptor
|
|
759
|
-
*/
|
|
760
|
-
object: <const N extends string, const Properties extends readonly FormElement_2[]>(name: N, ...properties: Properties) => ObjectField_2<N, Properties>;
|
|
761
|
-
/**
|
|
762
|
-
* Creates an object field with additional configuration options.
|
|
763
|
-
*
|
|
764
|
-
* @example
|
|
765
|
-
* ```typescript
|
|
766
|
-
* field.objectWithConfig("billingAddress", { label: "Billing Address", required: true },
|
|
767
|
-
* field.text("street"),
|
|
768
|
-
* field.text("city"),
|
|
769
|
-
* )
|
|
770
|
-
* ```
|
|
771
|
-
*
|
|
772
|
-
* @param name - The field name (used as the schema key)
|
|
773
|
-
* @param config - Configuration for label, required, etc.
|
|
774
|
-
* @param properties - The form elements that define the object's properties
|
|
775
|
-
* @returns An ObjectField descriptor
|
|
776
|
-
*/
|
|
777
|
-
objectWithConfig: <const N extends string, const Properties extends readonly FormElement_2[]>(name: N, config: Omit<ObjectField_2<N, Properties>, "_type" | "_field" | "name" | "properties">, ...properties: Properties) => ObjectField_2<N, Properties>;
|
|
778
|
-
};
|
|
465
|
+
export declare const field: FormSpecFieldBuilder;
|
|
779
466
|
|
|
780
467
|
/**
|
|
781
468
|
* Represents the runtime state of a single form field.
|
|
@@ -811,13 +498,6 @@ export declare type FlattenIntersection<T> = { [K in keyof T]: T[K] } & {};
|
|
|
811
498
|
*/
|
|
812
499
|
export declare type FormElement = AnyField | Group<readonly FormElement[]> | Conditional<string, unknown, readonly FormElement[]>;
|
|
813
500
|
|
|
814
|
-
/**
|
|
815
|
-
* Union of all form element types (fields and structural elements).
|
|
816
|
-
*
|
|
817
|
-
* @public
|
|
818
|
-
*/
|
|
819
|
-
declare type FormElement_2 = AnyField_2 | Group_2<readonly FormElement_2[]> | Conditional_2<string, unknown, readonly FormElement_2[]>;
|
|
820
|
-
|
|
821
501
|
/**
|
|
822
502
|
* A complete form specification.
|
|
823
503
|
*
|
|
@@ -837,6 +517,34 @@ export declare interface FormSpec<Elements extends readonly FormElement[]> {
|
|
|
837
517
|
*/
|
|
838
518
|
export declare function formspec<const Elements extends readonly FormElement[]>(...elements: Elements): FormSpec<Elements>;
|
|
839
519
|
|
|
520
|
+
/**
|
|
521
|
+
* Field builder helpers re-exported by the top-level `formspec` package.
|
|
522
|
+
*
|
|
523
|
+
* @public
|
|
524
|
+
*/
|
|
525
|
+
export declare interface FormSpecFieldBuilder {
|
|
526
|
+
/** Creates a text field. */
|
|
527
|
+
text<const N extends string>(name: N, config?: Omit<TextField<N>, "_field" | "_type" | "name">): TextField<N>;
|
|
528
|
+
/** Creates a number field. */
|
|
529
|
+
number<const N extends string>(name: N, config?: Omit<NumberField<N>, "_field" | "_type" | "name">): NumberField<N>;
|
|
530
|
+
/** Creates a boolean field. */
|
|
531
|
+
boolean<const N extends string>(name: N, config?: Omit<BooleanField<N>, "_field" | "_type" | "name">): BooleanField<N>;
|
|
532
|
+
/** Creates a static enum field from a fixed options list. */
|
|
533
|
+
enum<const N extends string, const O extends readonly EnumOptionValue[]>(name: N, options: O, config?: Omit<StaticEnumField<N, O>, "_field" | "_type" | "name" | "options">): StaticEnumField<N, O>;
|
|
534
|
+
/** Creates a dynamic enum field backed by an external option source. */
|
|
535
|
+
dynamicEnum<const N extends string, const Source extends string>(name: N, source: Source, config?: Omit<DynamicEnumField<N, Source>, "_field" | "_type" | "name" | "source">): DynamicEnumField<N, Source>;
|
|
536
|
+
/** Creates a field whose schema is resolved from an external source at runtime. */
|
|
537
|
+
dynamicSchema<const N extends string>(name: N, schemaSource: string, config?: Omit<DynamicSchemaField<N>, "_field" | "_type" | "name" | "schemaSource">): DynamicSchemaField<N>;
|
|
538
|
+
/** Creates an array field from a list of item elements. */
|
|
539
|
+
array<const N extends string, const Items extends readonly FormElement[]>(name: N, ...items: Items): ArrayField<N, Items>;
|
|
540
|
+
/** Creates an array field with explicit configuration and item elements. */
|
|
541
|
+
arrayWithConfig<const N extends string, const Items extends readonly FormElement[]>(name: N, config: Omit<ArrayField<N, Items>, "_field" | "_type" | "items" | "name">, ...items: Items): ArrayField<N, Items>;
|
|
542
|
+
/** Creates an object field from a list of property elements. */
|
|
543
|
+
object<const N extends string, const Properties extends readonly FormElement[]>(name: N, ...properties: Properties): ObjectField<N, Properties>;
|
|
544
|
+
/** Creates an object field with explicit configuration and property elements. */
|
|
545
|
+
objectWithConfig<const N extends string, const Properties extends readonly FormElement[]>(name: N, config: Omit<ObjectField<N, Properties>, "_field" | "_type" | "name" | "properties">, ...properties: Properties): ObjectField<N, Properties>;
|
|
546
|
+
}
|
|
547
|
+
|
|
840
548
|
/**
|
|
841
549
|
* Options for creating a form specification.
|
|
842
550
|
*
|
|
@@ -937,24 +645,6 @@ export declare interface Group<Elements extends readonly FormElement[]> {
|
|
|
937
645
|
*/
|
|
938
646
|
export declare function group<const Elements extends readonly FormElement[]>(label: string, ...elements: Elements): Group<Elements>;
|
|
939
647
|
|
|
940
|
-
/**
|
|
941
|
-
* A visual grouping of form elements.
|
|
942
|
-
*
|
|
943
|
-
* Groups provide visual organization and can be rendered as fieldsets or sections.
|
|
944
|
-
*
|
|
945
|
-
* @typeParam Elements - Tuple of contained form elements
|
|
946
|
-
*
|
|
947
|
-
* @public
|
|
948
|
-
*/
|
|
949
|
-
declare interface Group_2<Elements extends readonly FormElement_2[]> {
|
|
950
|
-
/** Type discriminator - identifies this as a group element */
|
|
951
|
-
readonly _type: "group";
|
|
952
|
-
/** Display label for the group */
|
|
953
|
-
readonly label: string;
|
|
954
|
-
/** Form elements contained within this group */
|
|
955
|
-
readonly elements: Elements;
|
|
956
|
-
}
|
|
957
|
-
|
|
958
648
|
/**
|
|
959
649
|
* A group element with a label.
|
|
960
650
|
*
|
|
@@ -1223,32 +913,6 @@ export declare interface NumberField<N extends string> {
|
|
|
1223
913
|
readonly multipleOf?: number;
|
|
1224
914
|
}
|
|
1225
915
|
|
|
1226
|
-
/**
|
|
1227
|
-
* A numeric input field.
|
|
1228
|
-
*
|
|
1229
|
-
* @typeParam N - The field name (string literal type)
|
|
1230
|
-
*
|
|
1231
|
-
* @public
|
|
1232
|
-
*/
|
|
1233
|
-
declare interface NumberField_2<N extends string> {
|
|
1234
|
-
/** Type discriminator for form elements */
|
|
1235
|
-
readonly _type: "field";
|
|
1236
|
-
/** Field type discriminator - identifies this as a number field */
|
|
1237
|
-
readonly _field: "number";
|
|
1238
|
-
/** Unique field identifier used as the schema key */
|
|
1239
|
-
readonly name: N;
|
|
1240
|
-
/** Display label for the field */
|
|
1241
|
-
readonly label?: string;
|
|
1242
|
-
/** Minimum allowed value */
|
|
1243
|
-
readonly min?: number;
|
|
1244
|
-
/** Maximum allowed value */
|
|
1245
|
-
readonly max?: number;
|
|
1246
|
-
/** Whether this field is required for form submission */
|
|
1247
|
-
readonly required?: boolean;
|
|
1248
|
-
/** Value must be a multiple of this number (use 1 for integer semantics) */
|
|
1249
|
-
readonly multipleOf?: number;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
916
|
/**
|
|
1253
917
|
* An object field containing nested properties.
|
|
1254
918
|
*
|
|
@@ -1274,31 +938,6 @@ export declare interface ObjectField<N extends string, Properties extends readon
|
|
|
1274
938
|
readonly required?: boolean;
|
|
1275
939
|
}
|
|
1276
940
|
|
|
1277
|
-
/**
|
|
1278
|
-
* An object field containing nested properties.
|
|
1279
|
-
*
|
|
1280
|
-
* Use this for grouping related fields under a single key in the schema.
|
|
1281
|
-
*
|
|
1282
|
-
* @typeParam N - The field name (string literal type)
|
|
1283
|
-
* @typeParam Properties - The form elements that define the object's properties
|
|
1284
|
-
*
|
|
1285
|
-
* @public
|
|
1286
|
-
*/
|
|
1287
|
-
declare interface ObjectField_2<N extends string, Properties extends readonly FormElement_2[]> {
|
|
1288
|
-
/** Type discriminator for form elements */
|
|
1289
|
-
readonly _type: "field";
|
|
1290
|
-
/** Field type discriminator - identifies this as an object field */
|
|
1291
|
-
readonly _field: "object";
|
|
1292
|
-
/** Unique field identifier used as the schema key */
|
|
1293
|
-
readonly name: N;
|
|
1294
|
-
/** Form elements that define the properties of this object */
|
|
1295
|
-
readonly properties: Properties;
|
|
1296
|
-
/** Display label for the field */
|
|
1297
|
-
readonly label?: string;
|
|
1298
|
-
/** Whether this field is required for form submission */
|
|
1299
|
-
readonly required?: boolean;
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
941
|
/**
|
|
1303
942
|
* Union of all predicate types.
|
|
1304
943
|
*
|
|
@@ -1453,31 +1092,6 @@ export declare interface StaticEnumField<N extends string, O extends readonly En
|
|
|
1453
1092
|
readonly required?: boolean;
|
|
1454
1093
|
}
|
|
1455
1094
|
|
|
1456
|
-
/**
|
|
1457
|
-
* A field with static enum options (known at compile time).
|
|
1458
|
-
*
|
|
1459
|
-
* Options can be plain strings or objects with `id` and `label` properties.
|
|
1460
|
-
*
|
|
1461
|
-
* @typeParam N - The field name (string literal type)
|
|
1462
|
-
* @typeParam O - Tuple of option values (strings or EnumOption objects)
|
|
1463
|
-
*
|
|
1464
|
-
* @public
|
|
1465
|
-
*/
|
|
1466
|
-
declare interface StaticEnumField_2<N extends string, O extends readonly EnumOptionValue_2[]> {
|
|
1467
|
-
/** Type discriminator for form elements */
|
|
1468
|
-
readonly _type: "field";
|
|
1469
|
-
/** Field type discriminator - identifies this as an enum field */
|
|
1470
|
-
readonly _field: "enum";
|
|
1471
|
-
/** Unique field identifier used as the schema key */
|
|
1472
|
-
readonly name: N;
|
|
1473
|
-
/** Array of allowed option values */
|
|
1474
|
-
readonly options: O;
|
|
1475
|
-
/** Display label for the field */
|
|
1476
|
-
readonly label?: string;
|
|
1477
|
-
/** Whether this field is required for form submission */
|
|
1478
|
-
readonly required?: boolean;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
1095
|
/**
|
|
1482
1096
|
* Form element type definitions.
|
|
1483
1097
|
*
|
|
@@ -1512,40 +1126,6 @@ export declare interface TextField<N extends string> {
|
|
|
1512
1126
|
readonly pattern?: string;
|
|
1513
1127
|
}
|
|
1514
1128
|
|
|
1515
|
-
/**
|
|
1516
|
-
* Form element type definitions.
|
|
1517
|
-
*
|
|
1518
|
-
* These types define the structure of form specifications.
|
|
1519
|
-
* The structure IS the definition - nesting implies layout and conditional logic.
|
|
1520
|
-
*/
|
|
1521
|
-
/**
|
|
1522
|
-
* A text input field.
|
|
1523
|
-
*
|
|
1524
|
-
* @typeParam N - The field name (string literal type)
|
|
1525
|
-
*
|
|
1526
|
-
* @public
|
|
1527
|
-
*/
|
|
1528
|
-
declare interface TextField_2<N extends string> {
|
|
1529
|
-
/** Type discriminator for form elements */
|
|
1530
|
-
readonly _type: "field";
|
|
1531
|
-
/** Field type discriminator - identifies this as a text field */
|
|
1532
|
-
readonly _field: "text";
|
|
1533
|
-
/** Unique field identifier used as the schema key */
|
|
1534
|
-
readonly name: N;
|
|
1535
|
-
/** Display label for the field */
|
|
1536
|
-
readonly label?: string;
|
|
1537
|
-
/** Placeholder text shown when field is empty */
|
|
1538
|
-
readonly placeholder?: string;
|
|
1539
|
-
/** Whether this field is required for form submission */
|
|
1540
|
-
readonly required?: boolean;
|
|
1541
|
-
/** Minimum string length */
|
|
1542
|
-
readonly minLength?: number;
|
|
1543
|
-
/** Maximum string length */
|
|
1544
|
-
readonly maxLength?: number;
|
|
1545
|
-
/** Regular expression pattern the value must match */
|
|
1546
|
-
readonly pattern?: string;
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
1129
|
/**
|
|
1550
1130
|
* Root UI Schema (always a layout — not a Control, Category, or Label).
|
|
1551
1131
|
*
|
|
@@ -1561,40 +1141,11 @@ export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout |
|
|
|
1561
1141
|
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout | Categorization | Category | LabelElement;
|
|
1562
1142
|
|
|
1563
1143
|
/**
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
* @public
|
|
1567
|
-
*/
|
|
1568
|
-
export declare type UISchemaElementType = "Control" | "VerticalLayout" | "HorizontalLayout" | "Group" | "Categorization" | "Category" | "Label";
|
|
1569
|
-
|
|
1570
|
-
/**
|
|
1571
|
-
* Validates a form specification for common issues.
|
|
1572
|
-
*
|
|
1573
|
-
* Checks for:
|
|
1574
|
-
* - Duplicate field names at the root level (warning)
|
|
1575
|
-
* - References to non-existent fields in conditionals (error)
|
|
1576
|
-
*
|
|
1577
|
-
* @example
|
|
1578
|
-
* ```typescript
|
|
1579
|
-
* const form = formspec(
|
|
1580
|
-
* field.text("name"),
|
|
1581
|
-
* field.text("name"), // Duplicate!
|
|
1582
|
-
* when("nonExistent", "value", // Reference to non-existent field!
|
|
1583
|
-
* field.text("extra"),
|
|
1584
|
-
* ),
|
|
1585
|
-
* );
|
|
1586
|
-
*
|
|
1587
|
-
* const result = validateForm(form.elements);
|
|
1588
|
-
* // result.valid === false
|
|
1589
|
-
* // result.issues contains duplicate and reference errors
|
|
1590
|
-
* ```
|
|
1591
|
-
*
|
|
1592
|
-
* @param elements - The form elements to validate
|
|
1593
|
-
* @returns Validation result with any issues found
|
|
1144
|
+
* Validates a list of form elements for duplicate names and structural issues.
|
|
1594
1145
|
*
|
|
1595
1146
|
* @public
|
|
1596
1147
|
*/
|
|
1597
|
-
export declare function validateForm(elements: readonly
|
|
1148
|
+
export declare function validateForm(elements: readonly FormElement[]): ValidationResult;
|
|
1598
1149
|
|
|
1599
1150
|
/**
|
|
1600
1151
|
* A validation issue found in a form specification.
|