@react-typed-forms/schemas 13.3.1 → 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 -135
- 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/controlBuilder.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { AccordionAdornment, CheckListRenderOptions, ControlAdornmentType, ControlDefinition, DataControlDefinition,
|
|
1
|
+
import { AccordionAdornment, ActionControlDefinition, CheckListRenderOptions, ControlAdornmentType, ControlDefinition, DataControlDefinition, DataRenderType, DisplayControlDefinition, DisplayOnlyRenderOptions, DynamicProperty, GroupedControlsDefinition, JsonataRenderOptions, RadioButtonRenderOptions, RenderOptions, TextfieldRenderOptions } from "./controlDefinition";
|
|
2
2
|
import { ActionRendererProps } from "./controlRender";
|
|
3
|
-
import {
|
|
3
|
+
import { DateValidator, JsonataValidator, LengthValidator, ValidatorType } from "./schemaValidator";
|
|
4
|
+
import { SchemaField, SchemaMap } from "./schemaField";
|
|
5
|
+
import { DataExpression, DataMatchExpression, EntityExpression, JsonataExpression } from "./entityExpression";
|
|
4
6
|
export declare function dataControl(field: string, title?: string | null, options?: Partial<DataControlDefinition>): DataControlDefinition;
|
|
5
7
|
export declare function validatorOptions<A extends {
|
|
6
8
|
type: string;
|
|
@@ -1,77 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SchemaDataNode, SchemaNode } from "./
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Bool = "Bool",
|
|
24
|
-
Int = "Int",
|
|
25
|
-
Date = "Date",
|
|
26
|
-
DateTime = "DateTime",
|
|
27
|
-
Time = "Time",
|
|
28
|
-
Double = "Double",
|
|
29
|
-
EntityRef = "EntityRef",
|
|
30
|
-
Compound = "Compound",
|
|
31
|
-
AutoId = "AutoId",
|
|
32
|
-
Image = "Image",
|
|
33
|
-
Any = "Any"
|
|
34
|
-
}
|
|
35
|
-
export interface EntityRefField extends SchemaField {
|
|
36
|
-
type: FieldType.EntityRef;
|
|
37
|
-
entityRefType: string;
|
|
38
|
-
parentField: string;
|
|
39
|
-
}
|
|
40
|
-
export interface FieldOption {
|
|
41
|
-
name: string;
|
|
42
|
-
value: any;
|
|
43
|
-
description?: string | null;
|
|
44
|
-
group?: string | null;
|
|
45
|
-
disabled?: boolean | null;
|
|
46
|
-
}
|
|
47
|
-
export interface CompoundField extends SchemaField {
|
|
48
|
-
type: FieldType.Compound;
|
|
49
|
-
children: SchemaField[];
|
|
50
|
-
treeChildren?: boolean;
|
|
51
|
-
schemaRef?: string;
|
|
52
|
-
}
|
|
1
|
+
import { SchemaValidator } from "./schemaValidator";
|
|
2
|
+
import { FieldOption, SchemaDataNode, SchemaField, SchemaInterface, SchemaNode } from "./schemaField";
|
|
3
|
+
import { EntityExpression } from "./entityExpression";
|
|
4
|
+
/**
|
|
5
|
+
* Interface representing the form context data.
|
|
6
|
+
*/
|
|
7
|
+
export interface FormContextData {
|
|
8
|
+
option?: FieldOption;
|
|
9
|
+
optionSelected?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface representing the control data context.
|
|
13
|
+
*/
|
|
14
|
+
export interface ControlDataContext {
|
|
15
|
+
schemaInterface: SchemaInterface;
|
|
16
|
+
dataNode: SchemaDataNode | undefined;
|
|
17
|
+
parentNode: SchemaDataNode;
|
|
18
|
+
formData: FormContextData;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents any control definition.
|
|
22
|
+
*/
|
|
53
23
|
export type AnyControlDefinition = DataControlDefinition | GroupedControlsDefinition | ActionControlDefinition | DisplayControlDefinition;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
MaxLength = "MaxLength",
|
|
58
|
-
NotAfterDate = "NotAfterDate",
|
|
59
|
-
NotBeforeDate = "NotBeforeDate"
|
|
60
|
-
}
|
|
61
|
-
export interface SchemaInterface {
|
|
62
|
-
isEmptyValue(field: SchemaField, value: any): boolean;
|
|
63
|
-
textValue(field: SchemaField, value: any, element?: boolean): string | undefined;
|
|
64
|
-
controlLength(field: SchemaField, control: Control<any>): number;
|
|
65
|
-
valueLength(field: SchemaField, value: any): number;
|
|
66
|
-
getDataOptions(node: SchemaDataNode): FieldOption[] | null | undefined;
|
|
67
|
-
getNodeOptions(node: SchemaNode): FieldOption[] | null | undefined;
|
|
68
|
-
getOptions(field: SchemaField): FieldOption[] | undefined | null;
|
|
69
|
-
getFilterOptions(array: SchemaDataNode, field: SchemaNode): FieldOption[] | undefined | null;
|
|
70
|
-
parseToMillis(field: SchemaField, v: string): number;
|
|
71
|
-
validationMessageText(field: SchemaField, messageType: ValidationMessageType, actual: any, expected: any): string;
|
|
72
|
-
compareValue(field: SchemaField, v1: unknown, v2: unknown): number;
|
|
73
|
-
searchText(field: SchemaField, value: any): string;
|
|
74
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a control definition.
|
|
26
|
+
*/
|
|
75
27
|
export interface ControlDefinition {
|
|
76
28
|
type: string;
|
|
77
29
|
title?: string | null;
|
|
@@ -104,38 +56,6 @@ export declare enum DynamicPropertyType {
|
|
|
104
56
|
Label = "Label",
|
|
105
57
|
ActionData = "ActionData"
|
|
106
58
|
}
|
|
107
|
-
export interface EntityExpression {
|
|
108
|
-
type: string;
|
|
109
|
-
}
|
|
110
|
-
export declare enum ExpressionType {
|
|
111
|
-
Jsonata = "Jsonata",
|
|
112
|
-
Data = "Data",
|
|
113
|
-
DataMatch = "FieldValue",
|
|
114
|
-
UserMatch = "UserMatch",
|
|
115
|
-
NotEmpty = "NotEmpty",
|
|
116
|
-
UUID = "UUID"
|
|
117
|
-
}
|
|
118
|
-
export interface JsonataExpression extends EntityExpression {
|
|
119
|
-
type: ExpressionType.Jsonata;
|
|
120
|
-
expression: string;
|
|
121
|
-
}
|
|
122
|
-
export interface DataExpression extends EntityExpression {
|
|
123
|
-
type: ExpressionType.Data;
|
|
124
|
-
field: string;
|
|
125
|
-
}
|
|
126
|
-
export interface DataMatchExpression extends EntityExpression {
|
|
127
|
-
type: ExpressionType.DataMatch;
|
|
128
|
-
field: string;
|
|
129
|
-
value: any;
|
|
130
|
-
}
|
|
131
|
-
export interface NotEmptyExpression extends EntityExpression {
|
|
132
|
-
type: ExpressionType.DataMatch;
|
|
133
|
-
field: string;
|
|
134
|
-
}
|
|
135
|
-
export interface UserMatchExpression extends EntityExpression {
|
|
136
|
-
type: ExpressionType.UserMatch;
|
|
137
|
-
userMatch: string;
|
|
138
|
-
}
|
|
139
59
|
export interface ControlAdornment {
|
|
140
60
|
type: string;
|
|
141
61
|
}
|
|
@@ -372,33 +292,6 @@ export interface ActionControlDefinition extends ControlDefinition {
|
|
|
372
292
|
actionId: string;
|
|
373
293
|
actionData?: string | null;
|
|
374
294
|
}
|
|
375
|
-
export declare enum ValidatorType {
|
|
376
|
-
Jsonata = "Jsonata",
|
|
377
|
-
Date = "Date",
|
|
378
|
-
Length = "Length"
|
|
379
|
-
}
|
|
380
|
-
export interface SchemaValidator {
|
|
381
|
-
type: string;
|
|
382
|
-
}
|
|
383
|
-
export interface JsonataValidator extends SchemaValidator {
|
|
384
|
-
type: ValidatorType.Jsonata;
|
|
385
|
-
expression: string;
|
|
386
|
-
}
|
|
387
|
-
export interface LengthValidator extends SchemaValidator {
|
|
388
|
-
type: ValidatorType.Length;
|
|
389
|
-
min?: number | null;
|
|
390
|
-
max?: number | null;
|
|
391
|
-
}
|
|
392
|
-
export declare enum DateComparison {
|
|
393
|
-
NotBefore = "NotBefore",
|
|
394
|
-
NotAfter = "NotAfter"
|
|
395
|
-
}
|
|
396
|
-
export interface DateValidator extends SchemaValidator {
|
|
397
|
-
type: ValidatorType.Date;
|
|
398
|
-
comparison: DateComparison;
|
|
399
|
-
fixedDate?: string | null;
|
|
400
|
-
daysFromCurrent?: number | null;
|
|
401
|
-
}
|
|
402
295
|
export declare function isDataControlDefinition(x: ControlDefinition): x is DataControlDefinition;
|
|
403
296
|
export declare function isGroupControlsDefinition(x: ControlDefinition): x is GroupedControlsDefinition;
|
|
404
297
|
export declare function isDisplayControlsDefinition(x: ControlDefinition): x is DisplayControlDefinition;
|
|
@@ -417,10 +310,30 @@ export declare function isDisplayOnlyRenderer(options: RenderOptions): options i
|
|
|
417
310
|
export declare function isTextfieldRenderer(options: RenderOptions): options is TextfieldRenderOptions;
|
|
418
311
|
export declare function isDataGroupRenderer(options?: RenderOptions | null): options is DataGroupRenderOptions;
|
|
419
312
|
export declare function isArrayRenderer(options: RenderOptions): options is ArrayRenderOptions;
|
|
420
|
-
export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
|
|
421
|
-
export declare function isScalarField(sf: SchemaField): sf is SchemaField;
|
|
422
|
-
export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
|
|
423
313
|
export declare function isDataControl(c: ControlDefinition): c is DataControlDefinition;
|
|
424
314
|
export declare function isGroupControl(c: ControlDefinition): c is GroupedControlsDefinition;
|
|
425
315
|
export type ControlActionHandler = (actionId: string, actionData: any, ctx: ControlDataContext) => (() => void) | undefined;
|
|
426
316
|
export declare function isCheckEntryClasses(options?: RenderOptions | null): options is CheckEntryClasses & RenderOptions;
|
|
317
|
+
export interface FormNode {
|
|
318
|
+
definition: ControlDefinition;
|
|
319
|
+
getChildNodes(): FormNode[];
|
|
320
|
+
parent?: FormNode;
|
|
321
|
+
}
|
|
322
|
+
export interface FormTreeLookup<A = string> {
|
|
323
|
+
getForm(formId: A): FormTreeNode | undefined;
|
|
324
|
+
}
|
|
325
|
+
export interface FormTreeNode extends FormTreeLookup {
|
|
326
|
+
rootNode: FormNode;
|
|
327
|
+
}
|
|
328
|
+
export declare function createFormLookup<A extends Record<string, ControlDefinition[]>>(formMap: A): FormTreeLookup<keyof A>;
|
|
329
|
+
export declare function fieldPathForDefinition(c: ControlDefinition): string[] | undefined;
|
|
330
|
+
export declare function lookupDataNode(c: ControlDefinition, parentNode: SchemaDataNode): SchemaDataNode | undefined;
|
|
331
|
+
export declare function traverseParents<A, B extends {
|
|
332
|
+
parent?: B | undefined;
|
|
333
|
+
}>(current: B | undefined, get: (b: B) => A, until?: (b: B) => boolean): A[];
|
|
334
|
+
export declare function getRootDataNode(dataNode: SchemaDataNode): SchemaDataNode;
|
|
335
|
+
export declare function getJsonPath(dataNode: SchemaDataNode): (string | number)[];
|
|
336
|
+
export declare function getSchemaPath(schemaNode: SchemaNode): SchemaField[];
|
|
337
|
+
export declare function getSchemaFieldList(schema: SchemaNode): SchemaField[];
|
|
338
|
+
export declare function visitControlDataArray<A>(controls: ControlDefinition[] | undefined | null, context: SchemaDataNode, cb: (definition: DataControlDefinition, node: SchemaDataNode) => A | undefined): A | undefined;
|
|
339
|
+
export declare function visitControlData<A>(definition: ControlDefinition, ctx: SchemaDataNode, cb: (definition: DataControlDefinition, field: SchemaDataNode) => A | undefined): A | undefined;
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,20 +1,76 @@
|
|
|
1
1
|
import React, { FC, Key, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { Control } from "@react-typed-forms/core";
|
|
3
|
-
import { AdornmentPlacement, ArrayActionOptions, ControlActionHandler, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayData,
|
|
4
|
-
import { ControlClasses,
|
|
3
|
+
import { AdornmentPlacement, ArrayActionOptions, ControlActionHandler, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayData, GroupRenderOptions, RenderOptions, ControlDataContext, FormContextData } from "./controlDefinition";
|
|
4
|
+
import { ControlClasses, JsonPath } from "./util";
|
|
5
5
|
import { EvalExpressionHook, UseEvalExpressionHook } from "./hooks";
|
|
6
6
|
import { ValidationContext } from "./validators";
|
|
7
|
-
import {
|
|
7
|
+
import { SchemaValidator } from "./schemaValidator";
|
|
8
|
+
import { FieldOption, SchemaDataNode, SchemaField, SchemaInterface } from "./schemaField";
|
|
9
|
+
/**
|
|
10
|
+
* Interface for rendering different types of form controls.
|
|
11
|
+
*/
|
|
8
12
|
export interface FormRenderer {
|
|
13
|
+
/**
|
|
14
|
+
* Renders data control.
|
|
15
|
+
* @param props - Properties for data renderer.
|
|
16
|
+
* @returns A function that takes layout properties and returns layout properties.
|
|
17
|
+
*/
|
|
9
18
|
renderData: (props: DataRendererProps) => (layout: ControlLayoutProps) => ControlLayoutProps;
|
|
19
|
+
/**
|
|
20
|
+
* Renders group control.
|
|
21
|
+
* @param props - Properties for group renderer.
|
|
22
|
+
* @returns A function that takes layout properties and returns layout properties.
|
|
23
|
+
*/
|
|
10
24
|
renderGroup: (props: GroupRendererProps) => (layout: ControlLayoutProps) => ControlLayoutProps;
|
|
25
|
+
/**
|
|
26
|
+
* Renders display control.
|
|
27
|
+
* @param props - Properties for display renderer.
|
|
28
|
+
* @returns A React node.
|
|
29
|
+
*/
|
|
11
30
|
renderDisplay: (props: DisplayRendererProps) => ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Renders action control.
|
|
33
|
+
* @param props - Properties for action renderer.
|
|
34
|
+
* @returns A React node.
|
|
35
|
+
*/
|
|
12
36
|
renderAction: (props: ActionRendererProps) => ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Renders array control.
|
|
39
|
+
* @param props - Properties for array renderer.
|
|
40
|
+
* @returns A React node.
|
|
41
|
+
*/
|
|
13
42
|
renderArray: (props: ArrayRendererProps) => ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Renders adornment.
|
|
45
|
+
* @param props - Properties for adornment renderer.
|
|
46
|
+
* @returns An adornment renderer.
|
|
47
|
+
*/
|
|
14
48
|
renderAdornment: (props: AdornmentProps) => AdornmentRenderer;
|
|
49
|
+
/**
|
|
50
|
+
* Renders label.
|
|
51
|
+
* @param props - Properties for label renderer.
|
|
52
|
+
* @param labelStart - React node to render at the start of the label.
|
|
53
|
+
* @param labelEnd - React node to render at the end of the label.
|
|
54
|
+
* @returns A React node.
|
|
55
|
+
*/
|
|
15
56
|
renderLabel: (props: LabelRendererProps, labelStart: ReactNode, labelEnd: ReactNode) => ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Renders layout.
|
|
59
|
+
* @param props - Properties for control layout.
|
|
60
|
+
* @returns A rendered control.
|
|
61
|
+
*/
|
|
16
62
|
renderLayout: (props: ControlLayoutProps) => RenderedControl;
|
|
63
|
+
/**
|
|
64
|
+
* Renders visibility control.
|
|
65
|
+
* @param props - Properties for visibility renderer.
|
|
66
|
+
* @returns A React node.
|
|
67
|
+
*/
|
|
17
68
|
renderVisibility: (props: VisibilityRendererProps) => ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Renders label text.
|
|
71
|
+
* @param props - React node for label text.
|
|
72
|
+
* @returns A React node.
|
|
73
|
+
*/
|
|
18
74
|
renderLabelText: (props: ReactNode) => ReactNode;
|
|
19
75
|
}
|
|
20
76
|
export interface AdornmentProps {
|
|
@@ -76,24 +132,76 @@ export interface ControlLayoutProps {
|
|
|
76
132
|
className?: string | null;
|
|
77
133
|
style?: React.CSSProperties;
|
|
78
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Enum representing the types of labels that can be rendered.
|
|
137
|
+
*/
|
|
79
138
|
export declare enum LabelType {
|
|
139
|
+
/**
|
|
140
|
+
* Label for a control.
|
|
141
|
+
*/
|
|
80
142
|
Control = 0,
|
|
143
|
+
/**
|
|
144
|
+
* Label for a group.
|
|
145
|
+
*/
|
|
81
146
|
Group = 1,
|
|
147
|
+
/**
|
|
148
|
+
* Label for text.
|
|
149
|
+
*/
|
|
82
150
|
Text = 2
|
|
83
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Properties for label renderers.
|
|
154
|
+
*/
|
|
84
155
|
export interface LabelRendererProps {
|
|
156
|
+
/**
|
|
157
|
+
* The type of the label.
|
|
158
|
+
*/
|
|
85
159
|
type: LabelType;
|
|
160
|
+
/**
|
|
161
|
+
* Whether to hide the label.
|
|
162
|
+
*/
|
|
86
163
|
hide?: boolean | null;
|
|
164
|
+
/**
|
|
165
|
+
* The content of the label.
|
|
166
|
+
*/
|
|
87
167
|
label: ReactNode;
|
|
168
|
+
/**
|
|
169
|
+
* Whether to show the label as being required.
|
|
170
|
+
* E.g. show an asterisk next to the label.
|
|
171
|
+
*/
|
|
88
172
|
required?: boolean | null;
|
|
173
|
+
/**
|
|
174
|
+
* The ID of the element the label is for.
|
|
175
|
+
*/
|
|
89
176
|
forId?: string;
|
|
177
|
+
/**
|
|
178
|
+
* The CSS class name for the label.
|
|
179
|
+
*/
|
|
90
180
|
className?: string;
|
|
91
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Properties for display renderers.
|
|
184
|
+
*/
|
|
92
185
|
export interface DisplayRendererProps {
|
|
186
|
+
/**
|
|
187
|
+
* The data to be displayed.
|
|
188
|
+
*/
|
|
93
189
|
data: DisplayData;
|
|
190
|
+
/**
|
|
191
|
+
* A control with dynamic value for display.
|
|
192
|
+
*/
|
|
94
193
|
display?: Control<string | undefined>;
|
|
194
|
+
/**
|
|
195
|
+
* The context for the control data.
|
|
196
|
+
*/
|
|
95
197
|
dataContext: ControlDataContext;
|
|
198
|
+
/**
|
|
199
|
+
* The CSS class name for the display renderer.
|
|
200
|
+
*/
|
|
96
201
|
className?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The CSS styles for the display renderer.
|
|
204
|
+
*/
|
|
97
205
|
style?: React.CSSProperties;
|
|
98
206
|
}
|
|
99
207
|
export type ChildVisibilityFunc = (child: ControlDefinition, parentNode?: SchemaDataNode, dontOverride?: boolean) => EvalExpressionHook<boolean>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { FieldOption, SchemaField, SchemaInterface, ValidationMessageType } from "./types";
|
|
2
1
|
import { Control } from "@react-typed-forms/core";
|
|
3
|
-
import { SchemaDataNode, SchemaNode } from "./
|
|
2
|
+
import { FieldOption, SchemaDataNode, SchemaField, SchemaInterface, SchemaNode, ValidationMessageType } from "./schemaField";
|
|
4
3
|
export declare class DefaultSchemaInterface implements SchemaInterface {
|
|
5
4
|
protected boolStrings: [string, string];
|
|
6
5
|
protected parseDateTime: (s: string) => number;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing a hook dependency, which can be a string, number, undefined, or null.
|
|
3
|
+
*/
|
|
4
|
+
export type HookDep = string | number | undefined | null;
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing a dynamic hook generator.
|
|
7
|
+
* @template A - The type of the hook result.
|
|
8
|
+
* @template P - The type of the hook context.
|
|
9
|
+
*/
|
|
10
|
+
export interface DynamicHookGenerator<A, P> {
|
|
11
|
+
deps: HookDep;
|
|
12
|
+
state: any;
|
|
13
|
+
runHook(ctx: P, state: any): A;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a dynamic hook generator.
|
|
17
|
+
* @template A - The type of the hook result.
|
|
18
|
+
* @template P - The type of the hook context.
|
|
19
|
+
* @template S - The type of the hook state.
|
|
20
|
+
* @param runHook - The function to run the hook.
|
|
21
|
+
* @param state - The initial state of the hook.
|
|
22
|
+
* @param deps - The dependencies of the hook.
|
|
23
|
+
* @returns The dynamic hook generator.
|
|
24
|
+
*/
|
|
25
|
+
export declare function makeHook<A, P, S = undefined>(runHook: (ctx: P, state: S) => A, state: S, deps?: HookDep): DynamicHookGenerator<A, P>;
|
|
26
|
+
/**
|
|
27
|
+
* Type representing the value of a dynamic hook.
|
|
28
|
+
* @template A - The type of the dynamic hook generator.
|
|
29
|
+
*/
|
|
30
|
+
export type DynamicHookValue<A> = A extends DynamicHookGenerator<infer V, any> ? V : never;
|
|
31
|
+
/**
|
|
32
|
+
* Converts an array of dependencies to a dependency string.
|
|
33
|
+
* @template A - The type of the dependencies.
|
|
34
|
+
* @param deps - The array of dependencies.
|
|
35
|
+
* @param asHookDep - The function to convert a dependency to a hook dependency.
|
|
36
|
+
* @returns The dependency string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function makeHookDepString<A>(deps: A[], asHookDep: (a: A) => HookDep): string;
|
|
39
|
+
/**
|
|
40
|
+
* Custom hook to use dynamic hooks.
|
|
41
|
+
* @template P - The type of the hook context.
|
|
42
|
+
* @template Hooks - The type of the hooks.
|
|
43
|
+
* @param hooks - The hooks to use.
|
|
44
|
+
* @returns A function that takes the hook context and returns the hook values.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useDynamicHooks<P, Hooks extends Record<string, DynamicHookGenerator<any, P>>>(hooks: Hooks): (p: P) => {
|
|
47
|
+
[K in keyof Hooks]: DynamicHookValue<Hooks[K]>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Converts a value to a dependency string.
|
|
51
|
+
* @param x - The value to convert.
|
|
52
|
+
* @returns The dependency string.
|
|
53
|
+
*/
|
|
54
|
+
export declare function toDepString(x: any): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface EntityExpression {
|
|
2
|
+
type: string;
|
|
3
|
+
}
|
|
4
|
+
export declare enum ExpressionType {
|
|
5
|
+
Jsonata = "Jsonata",
|
|
6
|
+
Data = "Data",
|
|
7
|
+
DataMatch = "FieldValue",
|
|
8
|
+
UserMatch = "UserMatch",
|
|
9
|
+
NotEmpty = "NotEmpty",
|
|
10
|
+
UUID = "UUID"
|
|
11
|
+
}
|
|
12
|
+
export interface JsonataExpression extends EntityExpression {
|
|
13
|
+
type: ExpressionType.Jsonata;
|
|
14
|
+
expression: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DataExpression extends EntityExpression {
|
|
17
|
+
type: ExpressionType.Data;
|
|
18
|
+
field: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DataMatchExpression extends EntityExpression {
|
|
21
|
+
type: ExpressionType.DataMatch;
|
|
22
|
+
field: string;
|
|
23
|
+
value: any;
|
|
24
|
+
}
|
|
25
|
+
export interface NotEmptyExpression extends EntityExpression {
|
|
26
|
+
type: ExpressionType.DataMatch;
|
|
27
|
+
field: string;
|
|
28
|
+
}
|
|
29
|
+
export interface UserMatchExpression extends EntityExpression {
|
|
30
|
+
type: ExpressionType.UserMatch;
|
|
31
|
+
userMatch: string;
|
|
32
|
+
}
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ControlDefinition, DynamicPropertyType,
|
|
1
|
+
import { ControlDefinition, DynamicPropertyType, ControlDataContext } from "./controlDefinition";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { Control } from "@react-typed-forms/core";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { JsonPath } from "./util";
|
|
5
|
+
import { DynamicHookGenerator } from "./dynamicHooks";
|
|
6
|
+
import { SchemaDataNode, SchemaInterface } from "./schemaField";
|
|
7
|
+
import { EntityExpression } from "./entityExpression";
|
|
6
8
|
export type EvalExpressionHook<A = any> = DynamicHookGenerator<Control<A | undefined>, ControlDataContext>;
|
|
7
9
|
export type UseEvalExpressionHook = (expr: EntityExpression | undefined | null, coerce: (v: any) => any) => DynamicHookGenerator<Control<any> | undefined, ControlDataContext>;
|
|
8
10
|
export declare function useEvalVisibilityHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition, overrideDataNode?: SchemaDataNode): EvalExpressionHook<boolean>;
|