@tempots/beatui 0.69.0 → 0.71.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.
- package/dist/{ar-aMLQTGVh.js → ar-BbgpGwJp.js} +1 -1
- package/dist/auth/index.cjs.js +1 -1
- package/dist/auth/index.es.js +106 -105
- package/dist/beatui.css +401 -0
- package/dist/beatui.tailwind.css +401 -0
- package/dist/{de-DBFOC44R.js → de-R7lPfyZ4.js} +1 -1
- package/dist/deep-merge-CQQCMLwG.js +1636 -0
- package/dist/deep-merge-DZxfgKqX.cjs +1 -0
- package/dist/duration-input-D-SIoDoo.cjs +1 -0
- package/dist/duration-input-DKxZ6OCa.js +277 -0
- package/dist/{es-C4xOThaT.js → es-DV0Jr_BZ.js} +1 -1
- package/dist/{fa-B7X_xydY.js → fa-DXvHejs9.js} +1 -1
- package/dist/{fr-AmjzbxN_.js → fr-D8FOMX0o.js} +1 -1
- package/dist/{he-DY-9yiOC.js → he-B19Qsx-u.js} +1 -1
- package/dist/{hi-Clkyp5Fu.js → hi-DozFnE3b.js} +1 -1
- package/dist/{index-GLoRnI6r.js → index-CYb1YxDX.js} +1 -1
- package/dist/{index-CzuXAuLZ.js → index-DdpYvBeh.js} +3 -3
- package/dist/index.cjs.js +4 -4
- package/dist/index.es.js +2852 -3104
- package/dist/{it-BC32WmGF.js → it-But8uzNi.js} +1 -1
- package/dist/{ja-JNSZS_Hv.js → ja-DkwTnFdU.js} +1 -1
- package/dist/json-schema/index.cjs.js +6 -6
- package/dist/json-schema/index.es.js +3099 -2961
- package/dist/json-structure/index.cjs.js +1 -0
- package/dist/json-structure/index.es.js +3157 -0
- package/dist/{ko-B8l0TJp0.js → ko-Cqv-IjhX.js} +1 -1
- package/dist/modal-5P9mU_a4.cjs +1 -0
- package/dist/{modal-DJWj5M5e.js → modal-MofsfmAe.js} +2 -2
- package/dist/{nl-BpYESHP8.js → nl-YSiU3rFI.js} +1 -1
- package/dist/notice-Cqq8g17n.js +209 -0
- package/dist/notice-DP209Ed8.cjs +1 -0
- package/dist/{pl-_sWhGdrs.js → pl-DXmHc2Nh.js} +1 -1
- package/dist/prosemirror/index.es.js +1 -1
- package/dist/{pt-BmiQvHUz.js → pt-Bf3z_-26.js} +1 -1
- package/dist/{ru-DacnqexG.js → ru-Sy00qUeG.js} +1 -1
- package/dist/tailwind/vite-plugin.es.js +1 -0
- package/dist/{toolbar-Bk5-22ln.js → toolbar-C_Ec0_XC.js} +1 -1
- package/dist/{tr-BSS5b_v6.js → tr-BDxG3qd6.js} +1 -1
- package/dist/{translations-zGwuSQWQ.js → translations-BmsRhth7.js} +1 -1
- package/dist/{translations-BUTBIDsS.js → translations-DQxouiBG.js} +24 -24
- package/dist/types/components/form/index.d.ts +1 -0
- package/dist/types/components/form/utils/deep-merge.d.ts +27 -0
- package/dist/types/components/form/utils/index.d.ts +1 -0
- package/dist/types/components/json-schema/index.d.ts +1 -0
- package/dist/types/components/json-schema/json-schema-form.d.ts +22 -3
- package/dist/types/components/json-schema/schema-defaults.d.ts +39 -0
- package/dist/types/components/json-structure/controls/any-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/array-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/binary-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/boolean-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/choice-control.d.ts +19 -0
- package/dist/types/components/json-structure/controls/decimal-control.d.ts +17 -0
- package/dist/types/components/json-structure/controls/deprecation-utils.d.ts +14 -0
- package/dist/types/components/json-structure/controls/enum-const-controls.d.ts +22 -0
- package/dist/types/components/json-structure/controls/generic-control.d.ts +31 -0
- package/dist/types/components/json-structure/controls/index.d.ts +21 -0
- package/dist/types/components/json-structure/controls/integer-control.d.ts +18 -0
- package/dist/types/components/json-structure/controls/map-control.d.ts +17 -0
- package/dist/types/components/json-structure/controls/object-control.d.ts +17 -0
- package/dist/types/components/json-structure/controls/set-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/string-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/temporal-control.d.ts +18 -0
- package/dist/types/components/json-structure/controls/tuple-control.d.ts +19 -0
- package/dist/types/components/json-structure/controls/union-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/uri-control.d.ts +15 -0
- package/dist/types/components/json-structure/controls/uuid-control.d.ts +15 -0
- package/dist/types/components/json-structure/extends-utils.d.ts +36 -0
- package/dist/types/components/json-structure/index.d.ts +25 -0
- package/dist/types/components/json-structure/json-structure-form.d.ts +96 -0
- package/dist/types/components/json-structure/ref-utils.d.ts +55 -0
- package/dist/types/components/json-structure/structure-context.d.ts +176 -0
- package/dist/types/components/json-structure/structure-defaults.d.ts +46 -0
- package/dist/types/components/json-structure/structure-types.d.ts +173 -0
- package/dist/types/components/json-structure/validation/error-transform.d.ts +56 -0
- package/dist/types/components/json-structure/validation/index.d.ts +5 -0
- package/dist/types/components/json-structure/validation/sdk-validator.d.ts +46 -0
- package/dist/types/components/json-structure/widgets/default-widgets.d.ts +27 -0
- package/dist/types/components/json-structure/widgets/index.d.ts +6 -0
- package/dist/types/components/json-structure/widgets/widget-registry.d.ts +143 -0
- package/dist/types/components/json-structure/widgets/widget-utils.d.ts +79 -0
- package/dist/types/json-structure/index.d.ts +9 -0
- package/dist/{ur-C6Ky6OCl.js → ur-55zdT2TQ.js} +1 -1
- package/dist/{notice-Um1LwKBF.js → use-form-B7A865EM.js} +329 -532
- package/dist/use-form-DVJXMMoN.cjs +2 -0
- package/dist/{vi-Bx2gx2S0.js → vi-C7K7W0hM.js} +1 -1
- package/dist/widget-customization-29Hl2gKT.js +1171 -0
- package/dist/widget-customization-BXiewbt-.cjs +1 -0
- package/dist/{zh-eixtg-Ce.js → zh-DvJBV9D8.js} +1 -1
- package/package.json +10 -2
- package/dist/modal-D_paG9Sr.cjs +0 -1
- package/dist/notice-CgT9ma2m.cjs +0 -2
- package/dist/widget-customization-BcbRhAAR.cjs +0 -1
- package/dist/widget-customization-D6Y_Qm7o.js +0 -2788
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Structure Default Value Extraction
|
|
3
|
+
*
|
|
4
|
+
* Utilities to recursively extract default values from JSON Structure schema definitions.
|
|
5
|
+
* Priority order:
|
|
6
|
+
* 1. Explicit `default` property (highest)
|
|
7
|
+
* 2. First item of `examples` array
|
|
8
|
+
* 3. `const` value
|
|
9
|
+
* 4. First `enum` value
|
|
10
|
+
* 5. Smart type-based defaults (computed)
|
|
11
|
+
*/
|
|
12
|
+
import type { JSONStructureSchema } from './structure-types';
|
|
13
|
+
/**
|
|
14
|
+
* Extract default values from a JSON Structure schema.
|
|
15
|
+
*
|
|
16
|
+
* Recursively walks the schema and builds an object containing all defined defaults.
|
|
17
|
+
* For object types, extracts defaults only for required properties.
|
|
18
|
+
* For nullable types (union with null), returns null.
|
|
19
|
+
* For arrays/sets with minItems, generates the minimum required items.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - The JSON Structure schema
|
|
22
|
+
* @returns The extracted default value, or undefined if none found
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const schema = {
|
|
27
|
+
* $schema: 'https://json-structure.org/draft/2024-12/schema',
|
|
28
|
+
* $id: 'example',
|
|
29
|
+
* name: 'Example',
|
|
30
|
+
* $root: 'Root',
|
|
31
|
+
* definitions: {
|
|
32
|
+
* Root: {
|
|
33
|
+
* type: 'object',
|
|
34
|
+
* properties: {
|
|
35
|
+
* name: { type: 'string' },
|
|
36
|
+
* age: { type: 'int32', minimum: 0, maximum: 120 }
|
|
37
|
+
* },
|
|
38
|
+
* required: ['name', 'age']
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* const defaults = extractStructureDefaults(schema)
|
|
43
|
+
* // { name: '', age: 60 } // only required props, smart defaults
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractStructureDefaults(schema: JSONStructureSchema): unknown;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Structure Schema Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Based on JSON Structure Core specification
|
|
5
|
+
* https://json-structure.org/
|
|
6
|
+
*/
|
|
7
|
+
export type PrimitiveType = 'string' | 'boolean' | 'null' | 'int8' | 'int16' | 'int32' | 'int64' | 'int128' | 'uint8' | 'uint16' | 'uint32' | 'uint64' | 'uint128' | 'float' | 'double' | 'decimal' | 'date' | 'datetime' | 'time' | 'duration' | 'uuid' | 'uri' | 'binary';
|
|
8
|
+
export type CompoundType = 'object' | 'array' | 'set' | 'map' | 'tuple' | 'choice' | 'any';
|
|
9
|
+
export type TypeKeyword = PrimitiveType | CompoundType;
|
|
10
|
+
/** Integer types that require BigInt for full precision */
|
|
11
|
+
export type BigIntType = 'int64' | 'int128' | 'uint64' | 'uint128';
|
|
12
|
+
/** Check if a type requires BigInt handling */
|
|
13
|
+
export declare function isBigIntType(type: string): type is BigIntType;
|
|
14
|
+
/** All signed integer types */
|
|
15
|
+
export type SignedIntegerType = 'int8' | 'int16' | 'int32' | 'int64' | 'int128';
|
|
16
|
+
/** All unsigned integer types */
|
|
17
|
+
export type UnsignedIntegerType = 'uint8' | 'uint16' | 'uint32' | 'uint64' | 'uint128';
|
|
18
|
+
/** All integer types */
|
|
19
|
+
export type IntegerType = SignedIntegerType | UnsignedIntegerType;
|
|
20
|
+
/** Check if a type is an integer type */
|
|
21
|
+
export declare function isIntegerType(type: string): type is IntegerType;
|
|
22
|
+
/** All floating-point types */
|
|
23
|
+
export type FloatType = 'float' | 'double' | 'decimal';
|
|
24
|
+
/** Check if a type is a floating-point type */
|
|
25
|
+
export declare function isFloatType(type: string): type is FloatType;
|
|
26
|
+
/** All numeric types */
|
|
27
|
+
export type NumericType = IntegerType | FloatType;
|
|
28
|
+
/** Check if a type is numeric */
|
|
29
|
+
export declare function isNumericType(type: string): type is NumericType;
|
|
30
|
+
/** All temporal types */
|
|
31
|
+
export type TemporalType = 'date' | 'datetime' | 'time' | 'duration';
|
|
32
|
+
/** Check if a type is temporal */
|
|
33
|
+
export declare function isTemporalType(type: string): type is TemporalType;
|
|
34
|
+
/** Check if a type is primitive */
|
|
35
|
+
export declare function isPrimitiveType(type: string): type is PrimitiveType;
|
|
36
|
+
/** Check if a type is compound/complex */
|
|
37
|
+
export declare function isCompoundType(type: string): type is CompoundType;
|
|
38
|
+
export interface TypeReference {
|
|
39
|
+
$ref: string;
|
|
40
|
+
}
|
|
41
|
+
export type TypeSpecifier = TypeKeyword | TypeKeyword[] | TypeReference;
|
|
42
|
+
/** Check if a value is a type reference */
|
|
43
|
+
export declare function isTypeReference(value: unknown): value is TypeReference;
|
|
44
|
+
export interface StringValidation {
|
|
45
|
+
minLength?: number;
|
|
46
|
+
maxLength?: number;
|
|
47
|
+
pattern?: string;
|
|
48
|
+
format?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface NumericValidation {
|
|
51
|
+
minimum?: number | string;
|
|
52
|
+
maximum?: number | string;
|
|
53
|
+
exclusiveMinimum?: number | string;
|
|
54
|
+
exclusiveMaximum?: number | string;
|
|
55
|
+
multipleOf?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ArrayValidation {
|
|
58
|
+
minItems?: number;
|
|
59
|
+
maxItems?: number;
|
|
60
|
+
uniqueItems?: boolean;
|
|
61
|
+
contains?: TypeDefinition;
|
|
62
|
+
minContains?: number;
|
|
63
|
+
maxContains?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface ObjectValidation {
|
|
66
|
+
minProperties?: number;
|
|
67
|
+
maxProperties?: number;
|
|
68
|
+
dependentRequired?: Record<string, string[]>;
|
|
69
|
+
}
|
|
70
|
+
export interface Altnames {
|
|
71
|
+
json?: string;
|
|
72
|
+
[key: `lang:${string}`]: string | undefined;
|
|
73
|
+
}
|
|
74
|
+
export interface TypeMetadata {
|
|
75
|
+
name?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
examples?: unknown[];
|
|
78
|
+
deprecated?: boolean;
|
|
79
|
+
abstract?: boolean;
|
|
80
|
+
altnames?: Altnames;
|
|
81
|
+
unit?: string;
|
|
82
|
+
currency?: string;
|
|
83
|
+
default?: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface BaseTypeDefinition extends TypeMetadata {
|
|
86
|
+
type?: TypeSpecifier;
|
|
87
|
+
$extends?: string | string[];
|
|
88
|
+
enum?: unknown[];
|
|
89
|
+
const?: unknown;
|
|
90
|
+
}
|
|
91
|
+
export interface ObjectTypeDefinition extends BaseTypeDefinition, ObjectValidation {
|
|
92
|
+
type: 'object';
|
|
93
|
+
properties: Record<string, TypeDefinition>;
|
|
94
|
+
required?: string[] | string[][];
|
|
95
|
+
additionalProperties?: boolean | TypeDefinition;
|
|
96
|
+
}
|
|
97
|
+
export interface ArrayTypeDefinition extends BaseTypeDefinition, ArrayValidation {
|
|
98
|
+
type: 'array';
|
|
99
|
+
items: TypeDefinition;
|
|
100
|
+
}
|
|
101
|
+
export interface SetTypeDefinition extends BaseTypeDefinition, ArrayValidation {
|
|
102
|
+
type: 'set';
|
|
103
|
+
items: TypeDefinition;
|
|
104
|
+
}
|
|
105
|
+
export interface MapTypeDefinition extends BaseTypeDefinition, ObjectValidation {
|
|
106
|
+
type: 'map';
|
|
107
|
+
values: TypeDefinition;
|
|
108
|
+
}
|
|
109
|
+
export interface TupleTypeDefinition extends BaseTypeDefinition {
|
|
110
|
+
type: 'tuple';
|
|
111
|
+
properties: Record<string, TypeDefinition>;
|
|
112
|
+
tuple: string[];
|
|
113
|
+
}
|
|
114
|
+
export interface ChoiceTypeDefinition extends BaseTypeDefinition {
|
|
115
|
+
type: 'choice';
|
|
116
|
+
choices: Record<string, TypeDefinition>;
|
|
117
|
+
selector?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface DecimalTypeDefinition extends BaseTypeDefinition, NumericValidation {
|
|
120
|
+
type: 'decimal';
|
|
121
|
+
precision?: number;
|
|
122
|
+
scale?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface StringTypeDefinition extends BaseTypeDefinition, StringValidation {
|
|
125
|
+
type: 'string';
|
|
126
|
+
}
|
|
127
|
+
export interface IntegerTypeDefinition extends BaseTypeDefinition, NumericValidation {
|
|
128
|
+
type: IntegerType;
|
|
129
|
+
}
|
|
130
|
+
export interface FloatTypeDefinition extends BaseTypeDefinition, NumericValidation {
|
|
131
|
+
type: 'float' | 'double';
|
|
132
|
+
}
|
|
133
|
+
export type TypeDefinition = BaseTypeDefinition | ObjectTypeDefinition | ArrayTypeDefinition | SetTypeDefinition | MapTypeDefinition | TupleTypeDefinition | ChoiceTypeDefinition | DecimalTypeDefinition | StringTypeDefinition | IntegerTypeDefinition | FloatTypeDefinition;
|
|
134
|
+
export interface JSONStructureSchema extends BaseTypeDefinition, ObjectValidation {
|
|
135
|
+
$schema: string;
|
|
136
|
+
$id: string;
|
|
137
|
+
name: string;
|
|
138
|
+
$root?: string;
|
|
139
|
+
definitions?: Record<string, TypeDefinition | Namespace>;
|
|
140
|
+
$uses?: string[];
|
|
141
|
+
properties?: Record<string, TypeDefinition>;
|
|
142
|
+
required?: string[] | string[][];
|
|
143
|
+
}
|
|
144
|
+
export interface Namespace {
|
|
145
|
+
[key: string]: TypeDefinition | Namespace;
|
|
146
|
+
}
|
|
147
|
+
/** Check if a value is a namespace (contains nested definitions but isn't a type itself) */
|
|
148
|
+
export declare function isNamespace(value: unknown): value is Namespace;
|
|
149
|
+
/** Check if a value is a type definition */
|
|
150
|
+
export declare function isTypeDefinition(value: unknown): value is TypeDefinition;
|
|
151
|
+
export declare function isObjectTypeDefinition(def: TypeDefinition): def is ObjectTypeDefinition;
|
|
152
|
+
export declare function isArrayTypeDefinition(def: TypeDefinition): def is ArrayTypeDefinition;
|
|
153
|
+
export declare function isSetTypeDefinition(def: TypeDefinition): def is SetTypeDefinition;
|
|
154
|
+
export declare function isMapTypeDefinition(def: TypeDefinition): def is MapTypeDefinition;
|
|
155
|
+
export declare function isTupleTypeDefinition(def: TypeDefinition): def is TupleTypeDefinition;
|
|
156
|
+
export declare function isChoiceTypeDefinition(def: TypeDefinition): def is ChoiceTypeDefinition;
|
|
157
|
+
export declare function hasEnumValue(def: TypeDefinition): def is TypeDefinition & {
|
|
158
|
+
enum: unknown[];
|
|
159
|
+
};
|
|
160
|
+
export declare function hasConstValue(def: TypeDefinition): def is TypeDefinition & {
|
|
161
|
+
const: unknown;
|
|
162
|
+
};
|
|
163
|
+
/** Get the resolved type from a type specifier, handling arrays and references */
|
|
164
|
+
export declare function getResolvedType(specifier: TypeSpecifier | undefined): string | string[] | null;
|
|
165
|
+
/** Check if a type specifier includes null (making the type nullable) */
|
|
166
|
+
export declare function isNullableType(specifier: TypeSpecifier | undefined): boolean;
|
|
167
|
+
/** Get non-null types from a type specifier array */
|
|
168
|
+
export declare function getNonNullTypes(specifier: TypeSpecifier): TypeKeyword[];
|
|
169
|
+
/** Integer type bounds */
|
|
170
|
+
export declare const INTEGER_BOUNDS: Record<IntegerType, {
|
|
171
|
+
min: bigint;
|
|
172
|
+
max: bigint;
|
|
173
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Error Transformation
|
|
3
|
+
*
|
|
4
|
+
* Transforms raw validation errors into user-friendly messages.
|
|
5
|
+
*/
|
|
6
|
+
import type { TypeDefinition } from '../structure-types';
|
|
7
|
+
/**
|
|
8
|
+
* Validation error from the JSON Structure validator
|
|
9
|
+
*/
|
|
10
|
+
export interface RawValidationError {
|
|
11
|
+
/** JSON Pointer path to error location */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Error type/code */
|
|
14
|
+
type: string;
|
|
15
|
+
/** Expected value/constraint */
|
|
16
|
+
expected?: unknown;
|
|
17
|
+
/** Actual value */
|
|
18
|
+
actual?: unknown;
|
|
19
|
+
/** Additional context */
|
|
20
|
+
context?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* User-friendly validation error
|
|
24
|
+
*/
|
|
25
|
+
export interface FormattedValidationError {
|
|
26
|
+
/** JSON Pointer path to error location */
|
|
27
|
+
path: string;
|
|
28
|
+
/** Human-readable error message */
|
|
29
|
+
message: string;
|
|
30
|
+
/** Original error type for programmatic handling */
|
|
31
|
+
code: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Transform a raw validation error into a user-friendly message
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatValidationError(error: RawValidationError, definition?: TypeDefinition): FormattedValidationError;
|
|
37
|
+
/**
|
|
38
|
+
* Transform multiple validation errors
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatValidationErrors(errors: RawValidationError[], definitions?: Map<string, TypeDefinition>): FormattedValidationError[];
|
|
41
|
+
/**
|
|
42
|
+
* Group errors by path for display
|
|
43
|
+
*/
|
|
44
|
+
export declare function groupErrorsByPath(errors: FormattedValidationError[]): Map<string, FormattedValidationError[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Get errors for a specific path
|
|
47
|
+
*/
|
|
48
|
+
export declare function getErrorsForPath(errors: FormattedValidationError[], path: string): FormattedValidationError[];
|
|
49
|
+
/**
|
|
50
|
+
* Check if a path has errors
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasErrorsAtPath(errors: FormattedValidationError[], path: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get child errors for a path (errors with paths that start with the given path)
|
|
55
|
+
*/
|
|
56
|
+
export declare function getChildErrors(errors: FormattedValidationError[], parentPath: string): FormattedValidationError[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Validator Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps the JSON Structure SDK validator (when available)
|
|
5
|
+
* or provides a basic fallback validator.
|
|
6
|
+
*
|
|
7
|
+
* Note: This is a placeholder implementation. When @json-structure/sdk
|
|
8
|
+
* becomes available, this should be updated to use the official validator.
|
|
9
|
+
*/
|
|
10
|
+
import type { JSONStructureSchema } from '../structure-types';
|
|
11
|
+
import type { RawValidationError } from './error-transform';
|
|
12
|
+
/**
|
|
13
|
+
* Validation result
|
|
14
|
+
*/
|
|
15
|
+
export interface ValidationResult {
|
|
16
|
+
/** Overall validity */
|
|
17
|
+
isValid: boolean;
|
|
18
|
+
/** List of validation errors */
|
|
19
|
+
errors: RawValidationError[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validator options
|
|
23
|
+
*/
|
|
24
|
+
export interface ValidatorOptions {
|
|
25
|
+
/** Stop at first error */
|
|
26
|
+
stopOnFirstError?: boolean;
|
|
27
|
+
/** Coerce types where possible */
|
|
28
|
+
coerceTypes?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* JSON Structure validator
|
|
32
|
+
*/
|
|
33
|
+
export interface StructureValidator {
|
|
34
|
+
/** Validate a value against the schema */
|
|
35
|
+
validate(value: unknown): ValidationResult;
|
|
36
|
+
/** Validate a value at a specific path */
|
|
37
|
+
validateAt(value: unknown, path: string): ValidationResult;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a validator for a schema
|
|
41
|
+
*/
|
|
42
|
+
export declare function createValidator(schema: JSONStructureSchema, options?: ValidatorOptions): StructureValidator;
|
|
43
|
+
/**
|
|
44
|
+
* Validate a value against a schema (convenience function)
|
|
45
|
+
*/
|
|
46
|
+
export declare function validate(schema: JSONStructureSchema, value: unknown, options?: ValidatorOptions): ValidationResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default Widget Registrations
|
|
3
|
+
*
|
|
4
|
+
* Registers default widgets for all JSON Structure types.
|
|
5
|
+
*/
|
|
6
|
+
import type { WidgetRegistry } from './widget-registry';
|
|
7
|
+
/**
|
|
8
|
+
* Register all default widgets for JSON Structure types
|
|
9
|
+
*
|
|
10
|
+
* @param registry - Widget registry to register to (defaults to global)
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerDefaultWidgets(registry?: WidgetRegistry): void;
|
|
13
|
+
/**
|
|
14
|
+
* Check if default widgets have been registered
|
|
15
|
+
*
|
|
16
|
+
* @param registry - Registry to check (defaults to global)
|
|
17
|
+
* @returns True if default widgets are registered
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasDefaultWidgets(registry?: WidgetRegistry): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Ensure default widgets are registered
|
|
22
|
+
*
|
|
23
|
+
* Only registers if not already registered.
|
|
24
|
+
*
|
|
25
|
+
* @param registry - Registry to ensure (defaults to global)
|
|
26
|
+
*/
|
|
27
|
+
export declare function ensureDefaultWidgets(registry?: WidgetRegistry): void;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget Registry for JSON Structure Forms
|
|
3
|
+
*
|
|
4
|
+
* Manages custom widget registrations and resolution.
|
|
5
|
+
*/
|
|
6
|
+
import type { Renderable } from '@tempots/dom';
|
|
7
|
+
import type { Controller } from '../../form';
|
|
8
|
+
import type { StructureContext } from '../structure-context';
|
|
9
|
+
/**
|
|
10
|
+
* Props passed to widget factories
|
|
11
|
+
*/
|
|
12
|
+
export interface WidgetProps<T = unknown> {
|
|
13
|
+
/** Controller for this field's value */
|
|
14
|
+
controller: Controller<T>;
|
|
15
|
+
/** Current structure context */
|
|
16
|
+
ctx: StructureContext;
|
|
17
|
+
/** Widget-specific options */
|
|
18
|
+
options?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Factory function to create a widget
|
|
22
|
+
*/
|
|
23
|
+
export interface WidgetFactory<T = unknown> {
|
|
24
|
+
(props: WidgetProps<T>): Renderable;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Widget registration entry
|
|
28
|
+
*/
|
|
29
|
+
export interface WidgetRegistration {
|
|
30
|
+
/** Factory function to create the widget */
|
|
31
|
+
factory: WidgetFactory;
|
|
32
|
+
/** Human-readable display name */
|
|
33
|
+
displayName: string;
|
|
34
|
+
/** Optional description */
|
|
35
|
+
description?: string;
|
|
36
|
+
/** JSON Structure types this widget handles */
|
|
37
|
+
supportedTypes?: string[];
|
|
38
|
+
/** JSON Structure formats this widget handles */
|
|
39
|
+
supportedFormats?: string[];
|
|
40
|
+
/** Resolution priority (higher = preferred) */
|
|
41
|
+
priority?: number;
|
|
42
|
+
/** Whether this can be used as fallback */
|
|
43
|
+
canFallback?: boolean;
|
|
44
|
+
/** Custom matching logic */
|
|
45
|
+
matcher?: (ctx: StructureContext) => boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolved widget ready for use
|
|
49
|
+
*/
|
|
50
|
+
export interface ResolvedWidget {
|
|
51
|
+
name: string;
|
|
52
|
+
registration: WidgetRegistration;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Widget registry interface
|
|
56
|
+
*/
|
|
57
|
+
export interface WidgetRegistry {
|
|
58
|
+
/** Register a widget */
|
|
59
|
+
register(name: string, registration: WidgetRegistration): void;
|
|
60
|
+
/** Unregister a widget */
|
|
61
|
+
unregister(name: string): void;
|
|
62
|
+
/** Get all registrations for a type */
|
|
63
|
+
getForType(type: string): WidgetRegistration[];
|
|
64
|
+
/** Get all registrations for a format */
|
|
65
|
+
getForFormat(format: string): WidgetRegistration[];
|
|
66
|
+
/** Find best matching widget for context */
|
|
67
|
+
findBestWidget(ctx: StructureContext): ResolvedWidget | null;
|
|
68
|
+
/** Get registration by name */
|
|
69
|
+
get(name: string): WidgetRegistration | undefined;
|
|
70
|
+
/** Check if a widget is registered */
|
|
71
|
+
has(name: string): boolean;
|
|
72
|
+
/** Get all widget names */
|
|
73
|
+
names(): string[];
|
|
74
|
+
/** Create a child registry that inherits from this one */
|
|
75
|
+
createChild(): WidgetRegistry;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Default implementation of WidgetRegistry
|
|
79
|
+
*/
|
|
80
|
+
export declare class DefaultWidgetRegistry implements WidgetRegistry {
|
|
81
|
+
private readonly registrations;
|
|
82
|
+
private readonly parent;
|
|
83
|
+
constructor(parent?: WidgetRegistry);
|
|
84
|
+
register(name: string, registration: WidgetRegistration): void;
|
|
85
|
+
unregister(name: string): void;
|
|
86
|
+
get(name: string): WidgetRegistration | undefined;
|
|
87
|
+
has(name: string): boolean;
|
|
88
|
+
names(): string[];
|
|
89
|
+
getForType(type: string): WidgetRegistration[];
|
|
90
|
+
getForFormat(format: string): WidgetRegistration[];
|
|
91
|
+
findBestWidget(ctx: StructureContext): ResolvedWidget | null;
|
|
92
|
+
/**
|
|
93
|
+
* Score how well a widget matches the context
|
|
94
|
+
*/
|
|
95
|
+
private scoreWidget;
|
|
96
|
+
createChild(): WidgetRegistry;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the global widget registry
|
|
100
|
+
*/
|
|
101
|
+
export declare function getGlobalWidgetRegistry(): WidgetRegistry;
|
|
102
|
+
/**
|
|
103
|
+
* Set the global widget registry
|
|
104
|
+
*/
|
|
105
|
+
export declare function setGlobalWidgetRegistry(registry: WidgetRegistry): void;
|
|
106
|
+
/**
|
|
107
|
+
* Create a new widget registry
|
|
108
|
+
*/
|
|
109
|
+
export declare function createWidgetRegistry(parent?: WidgetRegistry): WidgetRegistry;
|
|
110
|
+
export interface WidgetRegistrationOptions {
|
|
111
|
+
displayName?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
priority?: number;
|
|
114
|
+
canFallback?: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a widget registration for a specific type
|
|
118
|
+
*/
|
|
119
|
+
export declare function forType(type: string, factory: WidgetFactory, options?: WidgetRegistrationOptions): {
|
|
120
|
+
name: string;
|
|
121
|
+
registration: WidgetRegistration;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Create a widget registration for a specific format
|
|
125
|
+
*/
|
|
126
|
+
export declare function forFormat(format: string, factory: WidgetFactory, options?: WidgetRegistrationOptions): {
|
|
127
|
+
name: string;
|
|
128
|
+
registration: WidgetRegistration;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Create a widget registration for a type+format combination
|
|
132
|
+
*/
|
|
133
|
+
export declare function forTypeAndFormat(type: string, format: string, factory: WidgetFactory, options?: WidgetRegistrationOptions): {
|
|
134
|
+
name: string;
|
|
135
|
+
registration: WidgetRegistration;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Create a widget registration with custom matcher
|
|
139
|
+
*/
|
|
140
|
+
export declare function forMatcher(name: string, matcher: (ctx: StructureContext) => boolean, factory: WidgetFactory, options?: WidgetRegistrationOptions): {
|
|
141
|
+
name: string;
|
|
142
|
+
registration: WidgetRegistration;
|
|
143
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget Resolution Utilities
|
|
3
|
+
*
|
|
4
|
+
* Utilities for resolving and configuring widgets based on structure context.
|
|
5
|
+
*/
|
|
6
|
+
import type { StructureContext } from '../structure-context';
|
|
7
|
+
import type { WidgetRegistry, ResolvedWidget } from './widget-registry';
|
|
8
|
+
/**
|
|
9
|
+
* Options extracted from widget configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface WidgetOptions {
|
|
12
|
+
/** Widget-specific options from definition */
|
|
13
|
+
options?: Record<string, unknown>;
|
|
14
|
+
/** Priority override */
|
|
15
|
+
priority?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the best widget for a given context
|
|
19
|
+
*
|
|
20
|
+
* Resolution order:
|
|
21
|
+
* 1. Form-scoped registry (if provided in context)
|
|
22
|
+
* 2. Global registry
|
|
23
|
+
* 3. Returns null if no matching widget found
|
|
24
|
+
*
|
|
25
|
+
* @param ctx - Structure context containing type information
|
|
26
|
+
* @param registry - Optional form-scoped registry (overrides global)
|
|
27
|
+
* @returns Resolved widget or null if no match
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveWidget(ctx: StructureContext, registry?: WidgetRegistry): ResolvedWidget | null;
|
|
30
|
+
/**
|
|
31
|
+
* Extract widget options from context definition
|
|
32
|
+
*
|
|
33
|
+
* Looks for widget configuration in:
|
|
34
|
+
* - `x:ui` extension field
|
|
35
|
+
* - `widget` field (legacy)
|
|
36
|
+
* - Direct widget options
|
|
37
|
+
*
|
|
38
|
+
* @param ctx - Structure context
|
|
39
|
+
* @returns Widget options if found
|
|
40
|
+
*/
|
|
41
|
+
export declare function getWidgetOptions(ctx: StructureContext): WidgetOptions | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Get widget name from explicit definition override
|
|
44
|
+
*
|
|
45
|
+
* Checks for explicit widget name in:
|
|
46
|
+
* - `x:ui.widget` (if string)
|
|
47
|
+
* - `widget.type` (legacy)
|
|
48
|
+
*
|
|
49
|
+
* @param ctx - Structure context
|
|
50
|
+
* @returns Explicit widget name or undefined
|
|
51
|
+
*/
|
|
52
|
+
export declare function getExplicitWidgetName(ctx: StructureContext): string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a context has a custom widget override
|
|
55
|
+
*
|
|
56
|
+
* @param ctx - Structure context
|
|
57
|
+
* @returns True if an explicit widget is specified
|
|
58
|
+
*/
|
|
59
|
+
export declare function hasCustomWidget(ctx: StructureContext): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve widget with explicit name override
|
|
62
|
+
*
|
|
63
|
+
* If the context specifies an explicit widget name, tries to resolve
|
|
64
|
+
* that widget directly. Otherwise, falls back to automatic resolution.
|
|
65
|
+
*
|
|
66
|
+
* @param ctx - Structure context
|
|
67
|
+
* @param registry - Optional form-scoped registry
|
|
68
|
+
* @returns Resolved widget or null
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveWidgetWithOverride(ctx: StructureContext, registry?: WidgetRegistry): ResolvedWidget | null;
|
|
71
|
+
/**
|
|
72
|
+
* Merge widget options from multiple sources
|
|
73
|
+
*
|
|
74
|
+
* @param baseOptions - Base options from widget registration
|
|
75
|
+
* @param contextOptions - Options from context definition
|
|
76
|
+
* @param userOptions - User-provided options
|
|
77
|
+
* @returns Merged options (user > context > base)
|
|
78
|
+
*/
|
|
79
|
+
export declare function mergeWidgetOptions(baseOptions?: Record<string, unknown>, contextOptions?: Record<string, unknown>, userOptions?: Record<string, unknown>): Record<string, unknown>;
|