@react-typed-forms/schemas 13.3.0 → 13.4.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/lib/controlBuilder.d.ts +4 -2
- package/lib/{types.d.ts → controlDefinition.d.ts} +48 -133
- package/lib/controlRender.d.ts +111 -3
- package/lib/{schemaInterface.d.ts → defaultSchemaInterface.d.ts} +1 -2
- package/lib/dynamicHooks.d.ts +54 -0
- package/lib/entityExpression.d.ts +32 -0
- package/lib/hooks.d.ts +5 -3
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +6 -3
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +1 -1
- package/lib/schemaBuilder.d.ts +1 -1
- package/lib/schemaField.d.ts +230 -0
- package/lib/schemaValidator.d.ts +27 -0
- package/lib/util.d.ts +220 -28
- package/lib/validators.d.ts +3 -2
- package/package.json +1 -1
- package/lib/treeNodes.d.ts +0 -53
package/lib/renderers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from "react";
|
|
2
2
|
import { ActionRendererProps, AdornmentProps, AdornmentRenderer, ArrayRendererProps, ControlLayoutProps, DataRendererProps, DisplayRendererProps, FormRenderer, GroupRendererProps, LabelRendererProps, LabelType, RenderedControl, VisibilityRendererProps } from "./controlRender";
|
|
3
|
-
import { AccordionAdornment, ControlAdornment, IconAdornment, SetFieldAdornment } from "./
|
|
3
|
+
import { AccordionAdornment, ControlAdornment, IconAdornment, SetFieldAdornment } from "./controlDefinition";
|
|
4
4
|
export interface DefaultRenderers {
|
|
5
5
|
data: DataRendererRegistration;
|
|
6
6
|
label: LabelRendererRegistration;
|
package/lib/schemaBuilder.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompoundField, FieldOption, FieldType, SchemaField, SchemaMap } from "./
|
|
1
|
+
import { CompoundField, FieldOption, FieldType, SchemaField, SchemaMap } from "./schemaField";
|
|
2
2
|
export type AllowedSchema<T> = T extends string ? SchemaField & {
|
|
3
3
|
type: FieldType.String | FieldType.Date | FieldType.DateTime | FieldType.Time;
|
|
4
4
|
} : T extends number ? SchemaField & {
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { SchemaValidator } from "./schemaValidator";
|
|
2
|
+
import { Control } from "@react-typed-forms/core";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a schema field with various properties.
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaField {
|
|
7
|
+
/** The type of the field. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** The name of the field. */
|
|
10
|
+
field: string;
|
|
11
|
+
/** The display name of the field, optional. */
|
|
12
|
+
displayName?: string | null;
|
|
13
|
+
/** Tags associated with the field, optional. */
|
|
14
|
+
tags?: string[] | null;
|
|
15
|
+
/** Indicates if the field is a system field, optional. */
|
|
16
|
+
system?: boolean | null;
|
|
17
|
+
/** Indicates if the field is a collection, optional. */
|
|
18
|
+
collection?: boolean | null;
|
|
19
|
+
/** Specifies the types for which the field is applicable, optional. */
|
|
20
|
+
onlyForTypes?: string[] | null;
|
|
21
|
+
/** Indicates if the field is required, optional. */
|
|
22
|
+
required?: boolean | null;
|
|
23
|
+
/** Indicates if the field is not nullable, optional. */
|
|
24
|
+
notNullable?: boolean | null;
|
|
25
|
+
/** The default value of the field, optional. */
|
|
26
|
+
defaultValue?: any;
|
|
27
|
+
/** Indicates if the field is a type field, optional. */
|
|
28
|
+
isTypeField?: boolean | null;
|
|
29
|
+
/** Indicates if the field is searchable, optional. */
|
|
30
|
+
searchable?: boolean | null;
|
|
31
|
+
/** Options for the field, optional. */
|
|
32
|
+
options?: FieldOption[] | null;
|
|
33
|
+
/** Validators for the field, optional. */
|
|
34
|
+
validators?: SchemaValidator[] | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Represents a map of schema fields.
|
|
38
|
+
* The key is a string representing the schema name.
|
|
39
|
+
* The value is an array of SchemaField objects.
|
|
40
|
+
*/
|
|
41
|
+
export type SchemaMap = Record<string, SchemaField[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Enum representing the various field types.
|
|
44
|
+
*/
|
|
45
|
+
export declare enum FieldType {
|
|
46
|
+
String = "String",
|
|
47
|
+
Bool = "Bool",
|
|
48
|
+
Int = "Int",
|
|
49
|
+
Date = "Date",
|
|
50
|
+
DateTime = "DateTime",
|
|
51
|
+
Time = "Time",
|
|
52
|
+
Double = "Double",
|
|
53
|
+
EntityRef = "EntityRef",
|
|
54
|
+
Compound = "Compound",
|
|
55
|
+
AutoId = "AutoId",
|
|
56
|
+
Image = "Image",
|
|
57
|
+
Any = "Any"
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Represents a field that references an entity.
|
|
61
|
+
*/
|
|
62
|
+
export interface EntityRefField extends SchemaField {
|
|
63
|
+
/** The type of the field, which is EntityRef. */
|
|
64
|
+
type: FieldType.EntityRef;
|
|
65
|
+
/** The type of the referenced entity. */
|
|
66
|
+
entityRefType: string;
|
|
67
|
+
/** The parent field of the entity reference. */
|
|
68
|
+
parentField: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Represents an option for a field.
|
|
72
|
+
*/
|
|
73
|
+
export interface FieldOption {
|
|
74
|
+
/** The name of the option. */
|
|
75
|
+
name: string;
|
|
76
|
+
/** The value of the option. */
|
|
77
|
+
value: any;
|
|
78
|
+
/** The description of the option, optional. */
|
|
79
|
+
description?: string | null;
|
|
80
|
+
/** The group of the option, optional. */
|
|
81
|
+
group?: string | null;
|
|
82
|
+
/** Indicates if the option is disabled, optional. */
|
|
83
|
+
disabled?: boolean | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Represents a compound field that contains child fields.
|
|
87
|
+
*/
|
|
88
|
+
export interface CompoundField extends SchemaField {
|
|
89
|
+
/** The type of the field, which is Compound. */
|
|
90
|
+
type: FieldType.Compound;
|
|
91
|
+
/** The child fields of the compound field. */
|
|
92
|
+
children: SchemaField[];
|
|
93
|
+
/** Indicates if the children are tree-structured, optional. */
|
|
94
|
+
treeChildren?: boolean;
|
|
95
|
+
/** The schema reference for the compound field, optional. */
|
|
96
|
+
schemaRef?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Enum representing the various validation message types.
|
|
100
|
+
*/
|
|
101
|
+
export declare enum ValidationMessageType {
|
|
102
|
+
NotEmpty = "NotEmpty",
|
|
103
|
+
MinLength = "MinLength",
|
|
104
|
+
MaxLength = "MaxLength",
|
|
105
|
+
NotAfterDate = "NotAfterDate",
|
|
106
|
+
NotBeforeDate = "NotBeforeDate"
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Interface for schema-related operations.
|
|
110
|
+
*/
|
|
111
|
+
export interface SchemaInterface {
|
|
112
|
+
/**
|
|
113
|
+
* Checks if the value of a field is empty.
|
|
114
|
+
* @param field The schema field.
|
|
115
|
+
* @param value The value to check.
|
|
116
|
+
* @returns True if the value is empty, false otherwise.
|
|
117
|
+
*/
|
|
118
|
+
isEmptyValue(field: SchemaField, value: any): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the text representation of a field's value.
|
|
121
|
+
* @param field The schema field.
|
|
122
|
+
* @param value The value to convert.
|
|
123
|
+
* @param element Indicates if the value is an element, optional.
|
|
124
|
+
* @returns The text representation of the value.
|
|
125
|
+
*/
|
|
126
|
+
textValue(field: SchemaField, value: any, element?: boolean): string | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the length of a control's value.
|
|
129
|
+
* @param field The schema field.
|
|
130
|
+
* @param control The control to check.
|
|
131
|
+
* @returns The length of the control's value.
|
|
132
|
+
*/
|
|
133
|
+
controlLength(field: SchemaField, control: Control<any>): number;
|
|
134
|
+
/**
|
|
135
|
+
* Gets the length of a field's value.
|
|
136
|
+
* @param field The schema field.
|
|
137
|
+
* @param value The value to check.
|
|
138
|
+
* @returns The length of the value.
|
|
139
|
+
*/
|
|
140
|
+
valueLength(field: SchemaField, value: any): number;
|
|
141
|
+
/**
|
|
142
|
+
* Gets the data options for a schema data node.
|
|
143
|
+
* @param node The schema data node.
|
|
144
|
+
* @returns The data options.
|
|
145
|
+
*/
|
|
146
|
+
getDataOptions(node: SchemaDataNode): FieldOption[] | null | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Gets the node options for a schema node.
|
|
149
|
+
* @param node The schema node.
|
|
150
|
+
* @returns The node options.
|
|
151
|
+
*/
|
|
152
|
+
getNodeOptions(node: SchemaNode): FieldOption[] | null | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Gets the options for a schema field.
|
|
155
|
+
* @param field The schema field.
|
|
156
|
+
* @returns The field options.
|
|
157
|
+
*/
|
|
158
|
+
getOptions(field: SchemaField): FieldOption[] | undefined | null;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the filter options for a schema data node and field.
|
|
161
|
+
* @param array The schema data node.
|
|
162
|
+
* @param field The schema node.
|
|
163
|
+
* @returns The filter options.
|
|
164
|
+
*/
|
|
165
|
+
getFilterOptions(array: SchemaDataNode, field: SchemaNode): FieldOption[] | undefined | null;
|
|
166
|
+
/**
|
|
167
|
+
* Parses a string value to milliseconds.
|
|
168
|
+
* @param field The schema field.
|
|
169
|
+
* @param v The string value to parse.
|
|
170
|
+
* @returns The parsed value in milliseconds.
|
|
171
|
+
*/
|
|
172
|
+
parseToMillis(field: SchemaField, v: string): number;
|
|
173
|
+
/**
|
|
174
|
+
* Gets the validation message text for a field.
|
|
175
|
+
* @param field The schema field.
|
|
176
|
+
* @param messageType The type of validation message.
|
|
177
|
+
* @param actual The actual value.
|
|
178
|
+
* @param expected The expected value.
|
|
179
|
+
* @returns The validation message text.
|
|
180
|
+
*/
|
|
181
|
+
validationMessageText(field: SchemaField, messageType: ValidationMessageType, actual: any, expected: any): string;
|
|
182
|
+
/**
|
|
183
|
+
* Compares two values of a field.
|
|
184
|
+
* @param field The schema field.
|
|
185
|
+
* @param v1 The first value.
|
|
186
|
+
* @param v2 The second value.
|
|
187
|
+
* @returns The comparison result.
|
|
188
|
+
*/
|
|
189
|
+
compareValue(field: SchemaField, v1: unknown, v2: unknown): number;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the search text for a field's value.
|
|
192
|
+
* @param field The schema field.
|
|
193
|
+
* @param value The value to search.
|
|
194
|
+
* @returns The search text.
|
|
195
|
+
*/
|
|
196
|
+
searchText(field: SchemaField, value: any): string;
|
|
197
|
+
}
|
|
198
|
+
export interface SchemaTreeLookup<A = string> {
|
|
199
|
+
getSchema(schemaId: A): SchemaNode | undefined;
|
|
200
|
+
}
|
|
201
|
+
export interface SchemaNode extends SchemaTreeLookup {
|
|
202
|
+
field: SchemaField;
|
|
203
|
+
getChildNode(field: string): SchemaNode | undefined;
|
|
204
|
+
getChildNodes(withParent?: SchemaNode): SchemaNode[];
|
|
205
|
+
parent?: SchemaNode;
|
|
206
|
+
}
|
|
207
|
+
export interface SchemaDataNode {
|
|
208
|
+
schema: SchemaNode;
|
|
209
|
+
elementIndex?: number;
|
|
210
|
+
control?: Control<unknown>;
|
|
211
|
+
parent?: SchemaDataNode;
|
|
212
|
+
getChild(node: SchemaNode): SchemaDataNode;
|
|
213
|
+
getChildElement(index: number): SchemaDataNode;
|
|
214
|
+
}
|
|
215
|
+
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
216
|
+
export declare function isScalarField(sf: SchemaField): sf is SchemaField;
|
|
217
|
+
export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
|
|
218
|
+
export declare function createSchemaLookup<A extends Record<string, SchemaField[]>>(schemaMap: A): SchemaTreeLookup<keyof A>;
|
|
219
|
+
export declare function makeSchemaDataNode(schema: SchemaNode, control?: Control<unknown>, parent?: SchemaDataNode, elementIndex?: number): SchemaDataNode;
|
|
220
|
+
export declare function schemaDataForFieldRef(fieldRef: string | undefined, schema: SchemaDataNode): SchemaDataNode;
|
|
221
|
+
export declare function schemaForFieldRef(fieldRef: string | undefined, schema: SchemaNode): SchemaNode;
|
|
222
|
+
export declare function traverseSchemaPath<A>(fieldPath: string[], schema: SchemaNode, acc: A, next: (acc: A, node: SchemaNode) => A): A;
|
|
223
|
+
export declare function traverseData(fieldPath: string[], root: SchemaNode, data: {
|
|
224
|
+
[k: string]: any;
|
|
225
|
+
}): unknown;
|
|
226
|
+
export declare function schemaDataForFieldPath(fieldPath: string[], schema: SchemaDataNode): SchemaDataNode;
|
|
227
|
+
export declare function schemaForFieldPath(fieldPath: string[], schema: SchemaNode): SchemaNode;
|
|
228
|
+
export declare function rootSchemaNode(fields: SchemaField[], lookup?: SchemaTreeLookup): SchemaNode;
|
|
229
|
+
export declare function getSchemaNodePath(node: SchemaNode): string[];
|
|
230
|
+
export declare function isCompoundNode(node: SchemaNode): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum ValidatorType {
|
|
2
|
+
Jsonata = "Jsonata",
|
|
3
|
+
Date = "Date",
|
|
4
|
+
Length = "Length"
|
|
5
|
+
}
|
|
6
|
+
export interface SchemaValidator {
|
|
7
|
+
type: string;
|
|
8
|
+
}
|
|
9
|
+
export interface JsonataValidator extends SchemaValidator {
|
|
10
|
+
type: ValidatorType.Jsonata;
|
|
11
|
+
expression: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LengthValidator extends SchemaValidator {
|
|
14
|
+
type: ValidatorType.Length;
|
|
15
|
+
min?: number | null;
|
|
16
|
+
max?: number | null;
|
|
17
|
+
}
|
|
18
|
+
export declare enum DateComparison {
|
|
19
|
+
NotBefore = "NotBefore",
|
|
20
|
+
NotAfter = "NotAfter"
|
|
21
|
+
}
|
|
22
|
+
export interface DateValidator extends SchemaValidator {
|
|
23
|
+
type: ValidatorType.Date;
|
|
24
|
+
comparison: DateComparison;
|
|
25
|
+
fixedDate?: string | null;
|
|
26
|
+
daysFromCurrent?: number | null;
|
|
27
|
+
}
|
package/lib/util.d.ts
CHANGED
|
@@ -1,74 +1,266 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ControlActionHandler, ControlDefinition, DataControlDefinition, DisplayOnlyRenderOptions, GroupRenderOptions } from "./controlDefinition";
|
|
2
2
|
import { MutableRefObject } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { CompoundField, FieldOption, SchemaField, SchemaNode } from "./schemaField";
|
|
4
|
+
/**
|
|
5
|
+
* Interface representing the classes for a control.
|
|
6
|
+
*/
|
|
4
7
|
export interface ControlClasses {
|
|
5
8
|
styleClass?: string;
|
|
6
9
|
layoutClass?: string;
|
|
7
10
|
labelClass?: string;
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Type representing a JSON path, which can be a string or a number.
|
|
14
|
+
*/
|
|
9
15
|
export type JsonPath = string | number;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
parentNode: SchemaDataNode;
|
|
18
|
-
formData: FormContextData;
|
|
19
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Applies default values to the given record based on the provided schema fields.
|
|
18
|
+
* @param v - The record to apply default values to.
|
|
19
|
+
* @param fields - The schema fields to use for applying default values.
|
|
20
|
+
* @param doneSet - A set to keep track of processed records.
|
|
21
|
+
* @returns The record with default values applied.
|
|
22
|
+
*/
|
|
20
23
|
export declare function applyDefaultValues(v: Record<string, any> | undefined, fields: SchemaField[], doneSet?: Set<Record<string, any>>): any;
|
|
24
|
+
/**
|
|
25
|
+
* Applies default values to a specific field based on the provided schema field.
|
|
26
|
+
* @param v - The value to apply default values to.
|
|
27
|
+
* @param field - The schema field to use for applying default values.
|
|
28
|
+
* @param parent - The parent schema fields.
|
|
29
|
+
* @param notElement - Flag indicating if the field is not an element.
|
|
30
|
+
* @param doneSet - A set to keep track of processed records.
|
|
31
|
+
* @returns The value with default values applied.
|
|
32
|
+
*/
|
|
21
33
|
export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean, doneSet?: Set<Record<string, any>>): any;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the default values for the provided schema fields.
|
|
36
|
+
* @param fields - The schema fields to get default values for.
|
|
37
|
+
* @returns The default values for the schema fields.
|
|
38
|
+
*/
|
|
22
39
|
export declare function defaultValueForFields(fields: SchemaField[]): any;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the default value for a specific schema field.
|
|
42
|
+
* @param sf - The schema field to get the default value for.
|
|
43
|
+
* @param required - Flag indicating if the field is required.
|
|
44
|
+
* @param forceNotNull - Flag indicating if the field should not be null.
|
|
45
|
+
* @returns The default value for the schema field.
|
|
46
|
+
*/
|
|
23
47
|
export declare function defaultValueForField(sf: SchemaField, required?: boolean | null, forceNotNull?: boolean): any;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the element value for a specific schema field.
|
|
50
|
+
* @param sf - The schema field to get the element value for.
|
|
51
|
+
* @returns The element value for the schema field.
|
|
52
|
+
*/
|
|
24
53
|
export declare function elementValueForField(sf: SchemaField): any;
|
|
54
|
+
/**
|
|
55
|
+
* Finds a scalar field in the provided schema fields.
|
|
56
|
+
* @param fields - The schema fields to search in.
|
|
57
|
+
* @param field - The field name to search for.
|
|
58
|
+
* @returns The found scalar field, or undefined if not found.
|
|
59
|
+
*/
|
|
25
60
|
export declare function findScalarField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Finds a compound field in the provided schema fields.
|
|
63
|
+
* @param fields - The schema fields to search in.
|
|
64
|
+
* @param field - The field name to search for.
|
|
65
|
+
* @returns The found compound field, or undefined if not found.
|
|
66
|
+
*/
|
|
26
67
|
export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a field has a specific tag.
|
|
70
|
+
* @param field - The field to check.
|
|
71
|
+
* @param tag - The tag to check for.
|
|
72
|
+
* @returns True if the field has the tag, false otherwise.
|
|
73
|
+
*/
|
|
27
74
|
export declare function fieldHasTag(field: SchemaField, tag: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the display name for a specific field.
|
|
77
|
+
* @param field - The field to get the display name for.
|
|
78
|
+
* @returns The display name for the field.
|
|
79
|
+
*/
|
|
28
80
|
export declare function fieldDisplayName(field: SchemaField): string;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if an object has options.
|
|
83
|
+
* @param o - The object to check.
|
|
84
|
+
* @returns True if the object has options, false otherwise.
|
|
85
|
+
*/
|
|
29
86
|
export declare function hasOptions(o: {
|
|
30
87
|
options: FieldOption[] | undefined | null;
|
|
31
88
|
}): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the default control definition for a specific schema field.
|
|
91
|
+
* @param sf - The schema field to get the default control definition for.
|
|
92
|
+
* @returns The default control definition for the schema field.
|
|
93
|
+
*/
|
|
32
94
|
export declare function defaultControlForField(sf: SchemaField): DataControlDefinition;
|
|
33
|
-
export declare function findControlsForCompound(compound:
|
|
95
|
+
export declare function findControlsForCompound(compound: SchemaNode, definition: ControlDefinition): ControlDefinition[];
|
|
96
|
+
/**
|
|
97
|
+
* Interface representing a control group lookup.
|
|
98
|
+
*/
|
|
34
99
|
export interface ControlGroupLookup {
|
|
35
100
|
groups: ControlDefinition[];
|
|
36
101
|
children: Record<string, ControlGroupLookup>;
|
|
37
102
|
}
|
|
38
|
-
|
|
39
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Finds compound groups in the provided schema fields and control definitions.
|
|
105
|
+
* @param fields - The schema fields to search in.
|
|
106
|
+
* @param controls - The control definitions to search in.
|
|
107
|
+
* @returns A record of found compound groups.
|
|
108
|
+
*/
|
|
109
|
+
export declare function findCompoundGroups(fields: SchemaNode[], controls: ControlDefinition[]): Record<string, ControlGroupLookup>;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if a field exists in the provided control group lookup.
|
|
112
|
+
* @param field - The field to check.
|
|
113
|
+
* @param lookup - The control group lookup to check in.
|
|
114
|
+
* @returns An array of tuples containing the field and the control group lookup.
|
|
115
|
+
*/
|
|
116
|
+
export declare function existsInGroups(field: SchemaNode, lookup: ControlGroupLookup): [SchemaNode, ControlGroupLookup][];
|
|
117
|
+
/**
|
|
118
|
+
* Finds non-data groups in the provided control definitions.
|
|
119
|
+
* @param controls - The control definitions to search in.
|
|
120
|
+
* @returns An array of found non-data groups.
|
|
121
|
+
*/
|
|
40
122
|
export declare function findNonDataGroups(controls: ControlDefinition[]): ControlDefinition[];
|
|
123
|
+
/**
|
|
124
|
+
* Adds missing controls to the provided control definitions based on the schema fields.
|
|
125
|
+
* @param fields - The schema fields to use for adding missing controls.
|
|
126
|
+
* @param controls - The control definitions to add missing controls to.
|
|
127
|
+
* @returns The control definitions with missing controls added.
|
|
128
|
+
*/
|
|
41
129
|
export declare function addMissingControls(fields: SchemaField[], controls: ControlDefinition[]): ControlDefinition[];
|
|
130
|
+
/**
|
|
131
|
+
* Adds missing controls to the provided control definitions based on the schema fields.
|
|
132
|
+
* @param schema - The root schema node to use for adding missing controls.
|
|
133
|
+
* @param controls - The control definitions to add missing controls to.
|
|
134
|
+
* @returns The control definitions with missing controls added.
|
|
135
|
+
*/
|
|
136
|
+
export declare function addMissingControlsForSchema(schema: SchemaNode, controls: ControlDefinition[]): ControlDefinition[];
|
|
137
|
+
/**
|
|
138
|
+
* Custom hook to use an updated reference.
|
|
139
|
+
* @param a - The value to create a reference for.
|
|
140
|
+
* @returns A mutable reference object.
|
|
141
|
+
*/
|
|
42
142
|
export declare function useUpdatedRef<A>(a: A): MutableRefObject<A>;
|
|
143
|
+
/**
|
|
144
|
+
* Checks if a control definition is readonly.
|
|
145
|
+
* @param c - The control definition to check.
|
|
146
|
+
* @returns True if the control definition is readonly, false otherwise.
|
|
147
|
+
*/
|
|
43
148
|
export declare function isControlReadonly(c: ControlDefinition): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a control definition is disabled.
|
|
151
|
+
* @param c - The control definition to check.
|
|
152
|
+
* @returns True if the control definition is disabled, false otherwise.
|
|
153
|
+
*/
|
|
44
154
|
export declare function isControlDisabled(c: ControlDefinition): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the display-only render options for a control definition.
|
|
157
|
+
* @param d - The control definition to get the display-only render options for.
|
|
158
|
+
* @returns The display-only render options, or undefined if not applicable.
|
|
159
|
+
*/
|
|
45
160
|
export declare function getDisplayOnlyOptions(d: ControlDefinition): DisplayOnlyRenderOptions | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Cleans data for a schema based on the provided schema fields.
|
|
163
|
+
* @param v - The data to clean.
|
|
164
|
+
* @param fields - The schema fields to use for cleaning the data.
|
|
165
|
+
* @param removeIfDefault - Flag indicating if default values should be removed.
|
|
166
|
+
* @returns The cleaned data.
|
|
167
|
+
*/
|
|
46
168
|
export declare function cleanDataForSchema(v: {
|
|
47
169
|
[k: string]: any;
|
|
48
170
|
} | undefined, fields: SchemaField[], removeIfDefault?: boolean): any;
|
|
171
|
+
/**
|
|
172
|
+
* Returns all referenced classes for a control definition.
|
|
173
|
+
* @param c - The control definition to get the referenced classes for.
|
|
174
|
+
* @param collectExtra - Optional function to collect extra classes.
|
|
175
|
+
* @returns An array of referenced classes.
|
|
176
|
+
*/
|
|
49
177
|
export declare function getAllReferencedClasses(c: ControlDefinition, collectExtra?: (c: ControlDefinition) => (string | undefined | null)[]): string[];
|
|
178
|
+
/**
|
|
179
|
+
* Converts a JSON path array to a string.
|
|
180
|
+
* @param jsonPath - The JSON path array to convert.
|
|
181
|
+
* @param customIndex - Optional function to customize the index format.
|
|
182
|
+
* @returns The JSON path string.
|
|
183
|
+
*/
|
|
50
184
|
export declare function jsonPathString(jsonPath: JsonPath[], customIndex?: (n: number) => string): string;
|
|
185
|
+
/**
|
|
186
|
+
* Finds a child control definition within a parent control definition.
|
|
187
|
+
* @param parent - The parent control definition.
|
|
188
|
+
* @param childPath - The path to the child control definition, either as a single index or an array of indices.
|
|
189
|
+
* @returns The found child control definition.
|
|
190
|
+
*/
|
|
51
191
|
export declare function findChildDefinition(parent: ControlDefinition, childPath: number | number[]): ControlDefinition;
|
|
192
|
+
/**
|
|
193
|
+
* Returns the override class name if the class name starts with "@ ".
|
|
194
|
+
* Otherwise, returns the original class name.
|
|
195
|
+
* @param className - The class name to check and potentially modify.
|
|
196
|
+
* @returns The override class name or the original class name.
|
|
197
|
+
*/
|
|
52
198
|
export declare function getOverrideClass(className?: string | null): string | null | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the appropriate class name for a renderer.
|
|
201
|
+
* If the global class name starts with "@ ", it overrides the control class name.
|
|
202
|
+
* Otherwise, it combines the control class name and the global class name.
|
|
203
|
+
*
|
|
204
|
+
* @param controlClass - The class name for the control.
|
|
205
|
+
* @param globalClass - The global class name.
|
|
206
|
+
* @returns The appropriate class name for the renderer.
|
|
207
|
+
*/
|
|
53
208
|
export declare function rendererClass(controlClass?: string | null, globalClass?: string | null): string | undefined;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
export declare function toDepString(x: any): string;
|
|
209
|
+
/**
|
|
210
|
+
* Applies length restrictions to a value.
|
|
211
|
+
* @template Min - The type of the minimum value.
|
|
212
|
+
* @template Max - The type of the maximum value.
|
|
213
|
+
* @param {number} length - The length to check.
|
|
214
|
+
* @param {number | null | undefined} min - The minimum length.
|
|
215
|
+
* @param {number | null | undefined} max - The maximum length.
|
|
216
|
+
* @param {Min} minValue - The value to return if the length is greater than the minimum.
|
|
217
|
+
* @param {Max} maxValue - The value to return if the length is less than the maximum.
|
|
218
|
+
* @returns {[Min | undefined, Max | undefined]} - An array containing the minimum and maximum values if the length restrictions are met.
|
|
219
|
+
*/
|
|
67
220
|
export declare function applyLengthRestrictions<Min, Max>(length: number, min: number | null | undefined, max: number | null | undefined, minValue: Min, maxValue: Max): [Min | undefined, Max | undefined];
|
|
221
|
+
/**
|
|
222
|
+
* Finds the path to a field in the schema fields.
|
|
223
|
+
* @param {SchemaField[]} fields - The schema fields to search in.
|
|
224
|
+
* @param {string | undefined} fieldPath - The path to the field.
|
|
225
|
+
* @returns {SchemaField[] | undefined} - An array of schema fields representing the path, or undefined if not found.
|
|
226
|
+
*/
|
|
68
227
|
export declare function findFieldPath(fields: SchemaField[], fieldPath: string | undefined): SchemaField[] | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Merges two objects.
|
|
230
|
+
* @template A - The type of the objects to merge.
|
|
231
|
+
* @param {A} o1 - The first object.
|
|
232
|
+
* @param {A} o2 - The second object.
|
|
233
|
+
* @param {(k: keyof NonNullable<A>, v1: unknown, v2: unknown) => unknown} [doMerge] - Optional function to merge values.
|
|
234
|
+
* @returns {A} - The merged object.
|
|
235
|
+
*/
|
|
69
236
|
export declare function mergeObjects<A extends Record<string, any> | undefined>(o1: A, o2: A, doMerge?: (k: keyof NonNullable<A>, v1: unknown, v2: unknown) => unknown): A;
|
|
237
|
+
/**
|
|
238
|
+
* Coerces a value to a string.
|
|
239
|
+
* @param {unknown} v - The value to coerce.
|
|
240
|
+
* @returns {string} - The coerced string.
|
|
241
|
+
*/
|
|
70
242
|
export declare function coerceToString(v: unknown): string;
|
|
243
|
+
/**
|
|
244
|
+
* Returns the group renderer options for a control definition.
|
|
245
|
+
* @param {ControlDefinition} def - The control definition to get the group renderer options for.
|
|
246
|
+
* @returns {GroupRenderOptions | undefined} - The group renderer options, or undefined if not applicable.
|
|
247
|
+
*/
|
|
71
248
|
export declare function getGroupRendererOptions(def: ControlDefinition): GroupRenderOptions | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Returns the group class overrides for a control definition.
|
|
251
|
+
* @param {ControlDefinition} def - The control definition to get the group class overrides for.
|
|
252
|
+
* @returns {ControlClasses} - The group class overrides.
|
|
253
|
+
*/
|
|
72
254
|
export declare function getGroupClassOverrides(def: ControlDefinition): ControlClasses;
|
|
255
|
+
/**
|
|
256
|
+
* Checks if a control definition is display-only.
|
|
257
|
+
* @param {ControlDefinition} def - The control definition to check.
|
|
258
|
+
* @returns {boolean} - True if the control definition is display-only, false otherwise.
|
|
259
|
+
*/
|
|
73
260
|
export declare function isControlDisplayOnly(def: ControlDefinition): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Combines multiple action handlers into a single handler.
|
|
263
|
+
* @param {...(ControlActionHandler | undefined)[]} handlers - The action handlers to combine.
|
|
264
|
+
* @returns {ControlActionHandler} - The combined action handler.
|
|
265
|
+
*/
|
|
74
266
|
export declare function actionHandlers(...handlers: (ControlActionHandler | undefined)[]): ControlActionHandler;
|
package/lib/validators.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ControlDefinition, DataControlDefinition,
|
|
1
|
+
import { ControlDefinition, DataControlDefinition, ControlDataContext } from "./controlDefinition";
|
|
2
2
|
import { Control } from "@react-typed-forms/core";
|
|
3
|
-
import {
|
|
3
|
+
import { DateValidator, JsonataValidator, LengthValidator, SchemaValidator } from "./schemaValidator";
|
|
4
|
+
import { SchemaField } from "./schemaField";
|
|
4
5
|
interface ValidationHookContext {
|
|
5
6
|
hiddenControl: Control<boolean | null | undefined>;
|
|
6
7
|
dataContext: ControlDataContext;
|
package/package.json
CHANGED
package/lib/treeNodes.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Control } from "@react-typed-forms/core";
|
|
2
|
-
import { ControlDefinition, SchemaField, DataControlDefinition } from "./types";
|
|
3
|
-
export interface FormNode {
|
|
4
|
-
definition: ControlDefinition;
|
|
5
|
-
getChildNodes(): FormNode[];
|
|
6
|
-
parent?: FormNode;
|
|
7
|
-
}
|
|
8
|
-
export interface FormTreeLookup<A = string> {
|
|
9
|
-
getForm(formId: A): FormTreeNode | undefined;
|
|
10
|
-
}
|
|
11
|
-
export interface FormTreeNode extends FormTreeLookup {
|
|
12
|
-
rootNode: FormNode;
|
|
13
|
-
}
|
|
14
|
-
export interface SchemaTreeLookup<A = string> {
|
|
15
|
-
getSchema(schemaId: A): SchemaNode | undefined;
|
|
16
|
-
}
|
|
17
|
-
export interface SchemaNode extends SchemaTreeLookup {
|
|
18
|
-
field: SchemaField;
|
|
19
|
-
getChildNode(field: string): SchemaNode | undefined;
|
|
20
|
-
getChildNodes(): SchemaNode[];
|
|
21
|
-
parent?: SchemaNode;
|
|
22
|
-
}
|
|
23
|
-
export interface SchemaDataNode {
|
|
24
|
-
schema: SchemaNode;
|
|
25
|
-
elementIndex?: number;
|
|
26
|
-
control?: Control<unknown>;
|
|
27
|
-
parent?: SchemaDataNode;
|
|
28
|
-
getChild(node: SchemaNode): SchemaDataNode;
|
|
29
|
-
getChildElement(index: number): SchemaDataNode;
|
|
30
|
-
}
|
|
31
|
-
export declare function createSchemaLookup<A extends Record<string, SchemaField[]>>(schemaMap: A): SchemaTreeLookup<keyof A>;
|
|
32
|
-
export declare function createFormLookup<A extends Record<string, ControlDefinition[]>>(formMap: A): FormTreeLookup<keyof A>;
|
|
33
|
-
export declare function makeSchemaDataNode(schema: SchemaNode, control?: Control<unknown>, parent?: SchemaDataNode, elementIndex?: number): SchemaDataNode;
|
|
34
|
-
export declare function fieldPathForDefinition(c: ControlDefinition): string[] | undefined;
|
|
35
|
-
export declare function lookupDataNode(c: ControlDefinition, parentNode: SchemaDataNode): SchemaDataNode | undefined;
|
|
36
|
-
export declare function schemaDataForFieldRef(fieldRef: string | undefined, schema: SchemaDataNode): SchemaDataNode;
|
|
37
|
-
export declare function schemaForFieldRef(fieldRef: string | undefined, schema: SchemaNode): SchemaNode;
|
|
38
|
-
export declare function traverseSchemaPath<A>(fieldPath: string[], schema: SchemaNode, acc: A, next: (acc: A, node: SchemaNode) => A): A;
|
|
39
|
-
export declare function traverseData(fieldPath: string[], root: SchemaNode, data: {
|
|
40
|
-
[k: string]: any;
|
|
41
|
-
}): unknown;
|
|
42
|
-
export declare function schemaDataForFieldPath(fieldPath: string[], schema: SchemaDataNode): SchemaDataNode;
|
|
43
|
-
export declare function schemaForFieldPath(fieldPath: string[], schema: SchemaNode): SchemaNode;
|
|
44
|
-
export declare function traverseParents<A, B extends {
|
|
45
|
-
parent?: B | undefined;
|
|
46
|
-
}>(current: B | undefined, get: (b: B) => A, until?: (b: B) => boolean): A[];
|
|
47
|
-
export declare function getRootDataNode(dataNode: SchemaDataNode): SchemaDataNode;
|
|
48
|
-
export declare function getJsonPath(dataNode: SchemaDataNode): (string | number)[];
|
|
49
|
-
export declare function getSchemaPath(schemaNode: SchemaNode): SchemaField[];
|
|
50
|
-
export declare function getSchemaFieldList(schema: SchemaNode): SchemaField[];
|
|
51
|
-
export declare function rootSchemaNode(fields: SchemaField[], lookup?: SchemaTreeLookup): SchemaNode;
|
|
52
|
-
export declare function visitControlDataArray<A>(controls: ControlDefinition[] | undefined | null, context: SchemaDataNode, cb: (definition: DataControlDefinition, node: SchemaDataNode) => A | undefined): A | undefined;
|
|
53
|
-
export declare function visitControlData<A>(definition: ControlDefinition, ctx: SchemaDataNode, cb: (definition: DataControlDefinition, field: SchemaDataNode) => A | undefined): A | undefined;
|