@react-typed-forms/schemas 1.0.0-dev.2 → 1.0.0-dev.21

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/types.d.ts CHANGED
@@ -1,20 +1,17 @@
1
1
  export interface SchemaField {
2
2
  type: string;
3
3
  field: string;
4
- displayName?: string;
5
- tags?: string[];
6
- system?: boolean;
7
- collection?: boolean;
8
- onlyForTypes?: string[];
9
- required?: boolean;
4
+ displayName?: string | null;
5
+ tags?: string[] | null;
6
+ system?: boolean | null;
7
+ collection?: boolean | null;
8
+ onlyForTypes?: string[] | null;
9
+ required?: boolean | null;
10
10
  defaultValue?: any;
11
- isTypeField?: boolean;
12
- searchable?: boolean;
13
- options?: FieldOption[];
14
- /**
15
- * @deprecated Use options directly
16
- */
17
- restrictions?: SchemaRestrictions | undefined;
11
+ isTypeField?: boolean | null;
12
+ searchable?: boolean | null;
13
+ options?: FieldOption[] | null;
14
+ validators?: SchemaValidator[] | null;
18
15
  }
19
16
  export declare enum FieldType {
20
17
  String = "String",
@@ -26,16 +23,14 @@ export declare enum FieldType {
26
23
  EntityRef = "EntityRef",
27
24
  Compound = "Compound",
28
25
  AutoId = "AutoId",
29
- Image = "Image"
26
+ Image = "Image",
27
+ Any = "Any"
30
28
  }
31
29
  export interface EntityRefField extends SchemaField {
32
30
  type: FieldType.EntityRef;
33
31
  entityRefType: string;
34
32
  parentField: string;
35
33
  }
36
- export interface SchemaRestrictions {
37
- options: FieldOption[] | undefined;
38
- }
39
34
  export interface FieldOption {
40
35
  name: string;
41
36
  value: any;
@@ -48,9 +43,9 @@ export interface CompoundField extends SchemaField {
48
43
  export type AnyControlDefinition = DataControlDefinition | GroupedControlsDefinition | ActionControlDefinition | DisplayControlDefinition;
49
44
  export interface ControlDefinition {
50
45
  type: string;
51
- title?: string;
52
- dynamic?: DynamicProperty[];
53
- adornments?: ControlAdornment[];
46
+ title?: string | null;
47
+ dynamic?: DynamicProperty[] | null;
48
+ adornments?: ControlAdornment[] | null;
54
49
  }
55
50
  export declare enum ControlDefinitionType {
56
51
  Data = "Data",
@@ -59,7 +54,7 @@ export declare enum ControlDefinitionType {
59
54
  Action = "Action"
60
55
  }
61
56
  export interface DynamicProperty {
62
- type: DynamicPropertyType;
57
+ type: string;
63
58
  expr: EntityExpression;
64
59
  }
65
60
  export declare enum DynamicPropertyType {
@@ -67,7 +62,7 @@ export declare enum DynamicPropertyType {
67
62
  DefaultValue = "DefaultValue"
68
63
  }
69
64
  export interface EntityExpression {
70
- type: ExpressionType;
65
+ type: string;
71
66
  }
72
67
  export declare enum ExpressionType {
73
68
  Jsonata = "Jsonata",
@@ -75,36 +70,54 @@ export declare enum ExpressionType {
75
70
  UserMatch = "UserMatch"
76
71
  }
77
72
  export interface JsonataExpression extends EntityExpression {
73
+ type: ExpressionType.Jsonata;
78
74
  expression: string;
79
75
  }
80
76
  export interface FieldValueExpression extends EntityExpression {
77
+ type: ExpressionType.FieldValue;
81
78
  field: string;
82
79
  value: any;
83
80
  }
84
81
  export interface UserMatchExpression extends EntityExpression {
82
+ type: ExpressionType.UserMatch;
85
83
  userMatch: string;
86
84
  }
87
85
  export interface ControlAdornment {
88
- type: ControlAdornmentType;
86
+ type: string;
87
+ }
88
+ export declare enum AdornmentPlacement {
89
+ ControlStart = "ControlStart",
90
+ ControlEnd = "ControlEnd",
91
+ LabelStart = "LabelStart",
92
+ LabelEnd = "LabelEnd"
89
93
  }
90
94
  export declare enum ControlAdornmentType {
91
95
  Tooltip = "Tooltip",
92
- Accordion = "Accordion"
96
+ Accordion = "Accordion",
97
+ HelpText = "HelpText"
93
98
  }
94
99
  export interface TooltipAdornment extends ControlAdornment {
100
+ type: ControlAdornmentType.Tooltip;
95
101
  tooltip: string;
96
102
  }
97
103
  export interface AccordionAdornment extends ControlAdornment {
104
+ type: ControlAdornmentType.Accordion;
98
105
  title: string;
99
106
  defaultExpanded: boolean;
100
107
  }
108
+ export interface HelpTextAdornment extends ControlAdornment {
109
+ type: ControlAdornmentType.HelpText;
110
+ helpText: string;
111
+ placement: AdornmentPlacement;
112
+ }
101
113
  export interface DataControlDefinition extends ControlDefinition {
102
114
  type: ControlDefinitionType.Data;
103
115
  field: string;
104
- required?: boolean;
105
- renderOptions?: RenderOptions;
116
+ required?: boolean | null;
117
+ renderOptions?: RenderOptions | null;
106
118
  defaultValue?: any;
107
- readonly?: boolean;
119
+ readonly?: boolean | null;
120
+ validators?: SchemaValidator[] | null;
108
121
  }
109
122
  export interface RenderOptions {
110
123
  type: string;
@@ -118,28 +131,37 @@ export declare enum DataRenderType {
118
131
  UserSelection = "UserSelection",
119
132
  Synchronised = "Synchronised",
120
133
  IconSelector = "IconSelector",
121
- DateTime = "DateTime"
134
+ DateTime = "DateTime",
135
+ Checkbox = "Checkbox",
136
+ Dropdown = "Dropdown"
122
137
  }
123
138
  export interface RadioButtonRenderOptions extends RenderOptions {
139
+ type: DataRenderType.Radio;
124
140
  }
125
141
  export interface StandardRenderer extends RenderOptions {
142
+ type: DataRenderType.Standard;
126
143
  }
127
144
  export interface HtmlEditorRenderOptions extends RenderOptions {
145
+ type: DataRenderType.HtmlEditor;
128
146
  allowImages: boolean;
129
147
  }
130
148
  export interface DateTimeRenderOptions extends RenderOptions {
131
- format?: string;
149
+ type: DataRenderType.DateTime;
150
+ format?: string | null;
132
151
  }
133
152
  export interface IconListRenderOptions extends RenderOptions {
153
+ type: DataRenderType.IconList;
134
154
  iconMappings: IconMapping[];
135
155
  }
136
156
  export interface IconMapping {
137
157
  value: string;
138
- materialIcon: string | undefined;
158
+ materialIcon?: string | null;
139
159
  }
140
160
  export interface CheckListRenderOptions extends RenderOptions {
161
+ type: DataRenderType.CheckList;
141
162
  }
142
163
  export interface SynchronisedRenderOptions extends RenderOptions {
164
+ type: DataRenderType.Synchronised;
143
165
  fieldToSync: string;
144
166
  syncType: SyncTextType;
145
167
  }
@@ -149,20 +171,22 @@ export declare enum SyncTextType {
149
171
  Pascal = "Pascal"
150
172
  }
151
173
  export interface UserSelectionRenderOptions extends RenderOptions {
174
+ type: DataRenderType.UserSelection;
152
175
  noGroups: boolean;
153
176
  noUsers: boolean;
154
177
  }
155
178
  export interface IconSelectionRenderOptions extends RenderOptions {
179
+ type: DataRenderType.IconSelector;
156
180
  }
157
181
  export interface GroupedControlsDefinition extends ControlDefinition {
158
182
  type: ControlDefinitionType.Group;
159
- children: AnyControlDefinition[];
160
- compoundField?: string;
183
+ children: ControlDefinition[];
184
+ compoundField?: string | null;
161
185
  groupOptions: GroupRenderOptions;
162
186
  }
163
187
  export interface GroupRenderOptions {
164
- type: GroupRenderType;
165
- hideTitle?: boolean;
188
+ type: string;
189
+ hideTitle?: boolean | null;
166
190
  }
167
191
  export declare enum GroupRenderType {
168
192
  Standard = "Standard",
@@ -170,31 +194,72 @@ export declare enum GroupRenderType {
170
194
  GroupElement = "GroupElement"
171
195
  }
172
196
  export interface StandardGroupRenderer extends GroupRenderOptions {
197
+ type: GroupRenderType.Standard;
173
198
  }
174
199
  export interface GroupElementRenderer extends GroupRenderOptions {
200
+ type: GroupRenderType.GroupElement;
175
201
  value: any;
176
202
  }
177
203
  export interface GridRenderer extends GroupRenderOptions {
178
- columns: number | undefined;
204
+ type: GroupRenderType.Grid;
205
+ columns?: number | null;
179
206
  }
180
207
  export interface DisplayControlDefinition extends ControlDefinition {
181
208
  type: ControlDefinitionType.Display;
182
209
  displayData: DisplayData;
183
210
  }
184
211
  export interface DisplayData {
185
- type: DisplayDataType;
212
+ type: string;
186
213
  }
187
214
  export declare enum DisplayDataType {
188
215
  Text = "Text",
189
216
  Html = "Html"
190
217
  }
191
218
  export interface TextDisplay extends DisplayData {
219
+ type: DisplayDataType.Text;
192
220
  text: string;
193
221
  }
194
222
  export interface HtmlDisplay extends DisplayData {
223
+ type: DisplayDataType.Html;
195
224
  html: string;
196
225
  }
197
226
  export interface ActionControlDefinition extends ControlDefinition {
198
227
  type: ControlDefinitionType.Action;
199
228
  actionId: string;
200
229
  }
230
+ export declare enum ValidatorType {
231
+ Jsonata = "Jsonata",
232
+ Date = "Date"
233
+ }
234
+ export interface SchemaValidator {
235
+ type: string;
236
+ }
237
+ export interface JsonataValidator extends SchemaValidator {
238
+ type: ValidatorType.Jsonata;
239
+ expression: string;
240
+ }
241
+ export declare enum DateComparison {
242
+ NotBefore = "NotBefore",
243
+ NotAfter = "NotAfter"
244
+ }
245
+ export interface DateValidator extends SchemaValidator {
246
+ type: ValidatorType.Date;
247
+ comparison: DateComparison;
248
+ fixedDate?: string | null;
249
+ daysFromCurrent?: number | null;
250
+ }
251
+ export declare function isDataControlDefinition(x: ControlDefinition): x is DataControlDefinition;
252
+ export declare function isGroupControlsDefinition(x: ControlDefinition): x is GroupedControlsDefinition;
253
+ export declare function isDisplayControlsDefinition(x: ControlDefinition): x is DisplayControlDefinition;
254
+ export declare function isActionControlsDefinition(x: ControlDefinition): x is ActionControlDefinition;
255
+ export interface ControlVisitor<A> {
256
+ data(d: DataControlDefinition): A;
257
+ group(d: GroupedControlsDefinition): A;
258
+ display(d: DisplayControlDefinition): A;
259
+ action(d: ActionControlDefinition): A;
260
+ }
261
+ export declare function visitControlDefinition<A>(x: ControlDefinition, visitor: ControlVisitor<A>, defaultValue: (c: ControlDefinition) => A): A;
262
+ export declare function dataControl(field: string, options?: Partial<DataControlDefinition>): DataControlDefinition;
263
+ export declare function fieldValueExpr(field: string, value: any): FieldValueExpression;
264
+ export declare function visibility(expr: EntityExpression): DynamicProperty;
265
+ export declare function isGridRenderer(options: GroupRenderOptions): options is GridRenderer;
package/lib/util.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { CompoundField, ControlDefinition, DataControlDefinition, FieldOption, GroupedControlsDefinition, SchemaField } from "./types";
2
+ export declare function applyDefaultValues(v: {
3
+ [k: string]: any;
4
+ } | undefined, fields: SchemaField[]): any;
5
+ export declare function applyDefaultForField(v: any, field: SchemaField, parent: SchemaField[], notElement?: boolean): any;
6
+ export declare function defaultValueForFields(fields: SchemaField[]): any;
7
+ export declare function defaultValueForField(sf: SchemaField): any;
8
+ export declare function elementValueForField(sf: SchemaField): any;
9
+ export declare function findScalarField(fields: SchemaField[], field: string): SchemaField | undefined;
10
+ export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
11
+ export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
12
+ export declare function isScalarField(sf: SchemaField): sf is SchemaField;
13
+ export declare function isCompoundField(sf: SchemaField): sf is CompoundField;
14
+ export declare function isDataControl(c: ControlDefinition): c is DataControlDefinition;
15
+ export declare function isGroupControl(c: ControlDefinition): c is GroupedControlsDefinition;
16
+ export declare function fieldHasTag(field: SchemaField, tag: string): boolean;
17
+ export declare function fieldDisplayName(field: SchemaField): string;
18
+ export declare function hasOptions(o: {
19
+ options: FieldOption[] | undefined | null;
20
+ }): boolean;
21
+ export declare function defaultControlForField(sf: SchemaField): DataControlDefinition | GroupedControlsDefinition;
22
+ export declare function addMissingControls(fields: SchemaField[], controls: ControlDefinition[]): ControlDefinition[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-typed-forms/schemas",
3
- "version": "1.0.0-dev.2",
3
+ "version": "1.0.0-dev.21",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,19 +24,26 @@
24
24
  "material-ui"
25
25
  ],
26
26
  "dependencies": {
27
- "@react-typed-forms/core": "3.0.0-dev.101"
27
+ "@react-typed-forms/core": "^3.0.0-dev.116",
28
+ "clsx": "^1 || ^2",
29
+ "jsonata": "^2.0.3",
30
+ "react": "^18.2.0"
28
31
  },
29
32
  "devDependencies": {
30
- "@types/react": "^18.0.22",
33
+ "@react-typed-forms/transform": "^0.1.0",
34
+ "@types/react": "^18.2.28",
35
+ "microbundle": "^0.15.1",
31
36
  "nswag": "^13.18.2",
32
- "react": "^18.2.0",
33
- "react-dom": "^18.2.0",
34
- "rimraf": "^3.0.2"
37
+ "prettier": "^3.0.3",
38
+ "rimraf": "^3.0.2",
39
+ "typescript": "^5.2.2",
40
+ "markdown-magic": "^2.6.1"
35
41
  },
36
42
  "gitHead": "698e16cd3ab31b7dd0528fc76536f4d3205ce8c6",
37
43
  "scripts": {
38
- "build": "rimraf ./lib/ && tsc",
39
- "watch": "tsc -w",
44
+ "build": "rimraf ./lib/ && microbundle -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
45
+ "watch": "microbundle -w -f cjs --no-compress --jsx React.createElement --jsxFragment React.Fragment",
46
+ "update-readme": "md-magic --path README.md",
40
47
  "gencode": "nswag swagger2tsclient /input:http://localhost:5216/swagger/v1/swagger.json /runtime:Net60 /output:src/types.ts /GenerateClientClasses:false /MarkOptionalProperties:false /Template:Fetch /TypeStyle:Interface /DateTimeType:string"
41
48
  }
42
49
  }