@react-typed-forms/schemas 1.0.0-dev.3 → 1.0.0-dev.4

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "files": {
3
3
  "packages/schemas/.rush/temp/shrinkwrap-deps.json": "5ce6417fae765db5c61e400f851ecafe0ce756f0",
4
- "packages/schemas/package.json": "38baed2ed08306a8db8dbeb4649adb4f294fe615",
5
- "packages/schemas/src/controlRender.tsx": "340cfc1f2fedb77b3e456c2cf8bf50f40b808c36",
6
- "packages/schemas/src/hooks.ts": "982c0ee0c7749fc3c58f01ac8c44b8174f898861",
7
- "packages/schemas/src/index.ts": "b15fbb6de132cd912cf8141d5c4d2329e947546e",
4
+ "packages/schemas/package.json": "3fc4e26d218ceacae3452eccb3749fa9fc874c38",
5
+ "packages/schemas/src/controlRender.tsx": "5ce85ef4ee97307d9131d066655c133eb1b9bf48",
6
+ "packages/schemas/src/hooks.ts": "4eb4946f7b1c685e0b51cd011b4d39a1fdd6aa2e",
7
+ "packages/schemas/src/index.ts": "67f656f1d7f717bce7e933b9f4d7dc5dc50274dc",
8
8
  "packages/schemas/src/schemaBuilder.ts": "bfe74d3fb1cc2a4d5226051a58e025e107c32b11",
9
- "packages/schemas/src/types.ts": "2ff2a346d753da0eca2fe4acbe1b709f72034e5c",
9
+ "packages/schemas/src/types.ts": "01bba36475e368ee273871358458caf60b36dad5",
10
10
  "packages/schemas/tsconfig.json": "52e4f044fa580f4e0ad5830f3cfca574e2788372"
11
11
  },
12
12
  "arguments": "rimraf ./lib/ && tsc "
@@ -13,7 +13,7 @@ export interface DataControlProperties {
13
13
  readonly: boolean;
14
14
  defaultValue: any;
15
15
  required: boolean;
16
- options: FieldOption[] | undefined;
16
+ options: FieldOption[] | undefined | null;
17
17
  customRender?: (props: DataRendererProps) => ReactElement;
18
18
  }
19
19
  export interface GroupControlProperties {
@@ -87,10 +87,9 @@ export declare function elementValueForField(sf: SchemaField): any;
87
87
  export declare function findScalarField(fields: SchemaField[], field: string): SchemaField | undefined;
88
88
  export declare function findCompoundField(fields: SchemaField[], field: string): CompoundField | undefined;
89
89
  export declare function findField(fields: SchemaField[], field: string): SchemaField | undefined;
90
- export declare function fieldDisplayName(sf: SchemaField): string;
91
- export declare function controlTitle(title: string | undefined, field: SchemaField): string;
90
+ export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
92
91
  export declare function renderControl(definition: AnyControlDefinition, formState: FormEditState, hooks: FormEditHooks, key: Key, wrapChild?: (key: Key, db: ReactElement) => ReactElement): ReactElement;
93
92
  export declare function controlForField(field: string, formState: FormEditState): Control<any>;
94
- export declare function fieldForControl(c: ControlDefinition): string | undefined;
93
+ export declare function fieldForControl(c: ControlDefinition): string | null | undefined;
95
94
  export declare function isDataControl(c: ControlDefinition): c is DataControlDefinition;
96
95
  export declare function isGroupControl(c: ControlDefinition): c is GroupedControlsDefinition;
@@ -23,10 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isGroupControl = exports.isDataControl = exports.fieldForControl = exports.controlForField = exports.renderControl = exports.controlTitle = exports.fieldDisplayName = exports.findField = exports.findCompoundField = exports.findScalarField = exports.elementValueForField = exports.defaultValueForField = exports.defaultValueForFields = exports.applyDefaultForField = exports.applyDefaultValues = exports.isCompoundField = exports.isScalarField = exports.useFormRendererComponents = exports.FormRendererComponentsContext = void 0;
26
+ exports.isGroupControl = exports.isDataControl = exports.fieldForControl = exports.controlForField = exports.renderControl = exports.controlTitle = exports.findField = exports.findCompoundField = exports.findScalarField = exports.elementValueForField = exports.defaultValueForField = exports.defaultValueForFields = exports.applyDefaultForField = exports.applyDefaultValues = exports.isCompoundField = exports.isScalarField = exports.useFormRendererComponents = exports.FormRendererComponentsContext = void 0;
27
27
  const types_1 = require("./types");
28
28
  const react_1 = __importStar(require("react"));
29
29
  const core_1 = require("@react-typed-forms/core");
30
+ const index_1 = require("./index");
30
31
  exports.FormRendererComponentsContext = (0, react_1.createContext)(undefined);
31
32
  function useFormRendererComponents() {
32
33
  const c = (0, react_1.useContext)(exports.FormRendererComponentsContext);
@@ -109,12 +110,8 @@ function findField(fields, field) {
109
110
  return fields.find((x) => x.field === field);
110
111
  }
111
112
  exports.findField = findField;
112
- function fieldDisplayName(sf) {
113
- return sf.displayName ? sf.displayName : sf.field;
114
- }
115
- exports.fieldDisplayName = fieldDisplayName;
116
113
  function controlTitle(title, field) {
117
- return title ? title : fieldDisplayName(field);
114
+ return title ? title : (0, index_1.fieldDisplayName)(field);
118
115
  }
119
116
  exports.controlTitle = controlTitle;
120
117
  function renderControl(definition, formState, hooks, key, wrapChild) {
package/lib/hooks.d.ts CHANGED
@@ -5,6 +5,6 @@ export type ExpressionHook = (expr: EntityExpression, formState: FormEditState)
5
5
  export declare function useDefaultValue(definition: DataControlDefinition, field: SchemaField, formState: FormEditState, useExpression: ExpressionHook): any;
6
6
  export declare function useIsControlVisible(definition: ControlDefinition, formState: FormEditState, useExpression: ExpressionHook): boolean;
7
7
  export declare function getDefaultScalarControlProperties(definition: DataControlDefinition, field: SchemaField, visible: boolean, defaultValue: any, control: Control<any>, readonly?: boolean): DataControlProperties;
8
- export declare function getOptionsForScalarField(field: SchemaField): FieldOption[] | undefined;
8
+ export declare function getOptionsForScalarField(field: SchemaField): FieldOption[] | undefined | null;
9
9
  export declare const defaultExpressionHook: ExpressionHook;
10
10
  export declare function createFormEditHooks(useExpression: ExpressionHook): FormEditHooks;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
+ import { SchemaField } from "./types";
1
2
  export * from "./types";
2
3
  export * from "./schemaBuilder";
3
4
  export * from "./controlRender";
4
5
  export * from "./hooks";
6
+ export declare function fieldHasTag(field: SchemaField, tag: string): boolean;
7
+ export declare function fieldDisplayName(field: SchemaField): string;
package/lib/index.js CHANGED
@@ -14,7 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.fieldDisplayName = exports.fieldHasTag = void 0;
17
18
  __exportStar(require("./types"), exports);
18
19
  __exportStar(require("./schemaBuilder"), exports);
19
20
  __exportStar(require("./controlRender"), exports);
20
21
  __exportStar(require("./hooks"), exports);
22
+ function fieldHasTag(field, tag) {
23
+ var _a;
24
+ return Boolean((_a = field.tags) === null || _a === void 0 ? void 0 : _a.includes(tag));
25
+ }
26
+ exports.fieldHasTag = fieldHasTag;
27
+ function fieldDisplayName(field) {
28
+ var _a;
29
+ return (_a = field.displayName) !== null && _a !== void 0 ? _a : field.field;
30
+ }
31
+ exports.fieldDisplayName = fieldDisplayName;
@@ -18,17 +18,17 @@ export declare function buildSchema<T>(def: {
18
18
  }): SchemaField[];
19
19
  export declare function stringField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
20
20
  field?: string | undefined;
21
- displayName: string;
22
- tags?: string[] | undefined;
23
- system?: boolean | undefined;
24
- collection?: boolean | undefined;
25
- onlyForTypes?: string[] | undefined;
26
- required?: boolean | undefined;
21
+ displayName: string | null;
22
+ tags?: string[] | null | undefined;
23
+ system?: boolean | null | undefined;
24
+ collection?: boolean | null | undefined;
25
+ onlyForTypes?: string[] | null | undefined;
26
+ required?: boolean | null | undefined;
27
27
  defaultValue?: any;
28
- isTypeField?: boolean | undefined;
29
- searchable?: boolean | undefined;
30
- options?: FieldOption[] | undefined;
31
- restrictions?: import("./types").SchemaRestrictions | undefined;
28
+ isTypeField?: boolean | null | undefined;
29
+ searchable?: boolean | null | undefined;
30
+ options?: FieldOption[] | null | undefined;
31
+ restrictions?: import("./types").SchemaRestrictions | null | undefined;
32
32
  type: FieldType.String;
33
33
  };
34
34
  export declare function stringOptionsField(displayName: string, ...options: FieldOption[]): (name: string) => SchemaField & {
@@ -43,32 +43,32 @@ export declare function makeCompoundField<S extends Partial<CompoundField>>(opti
43
43
  } & S;
44
44
  export declare function intField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
45
45
  field?: string | undefined;
46
- displayName: string;
47
- tags?: string[] | undefined;
48
- system?: boolean | undefined;
49
- collection?: boolean | undefined;
50
- onlyForTypes?: string[] | undefined;
51
- required?: boolean | undefined;
46
+ displayName: string | null;
47
+ tags?: string[] | null | undefined;
48
+ system?: boolean | null | undefined;
49
+ collection?: boolean | null | undefined;
50
+ onlyForTypes?: string[] | null | undefined;
51
+ required?: boolean | null | undefined;
52
52
  defaultValue?: any;
53
- isTypeField?: boolean | undefined;
54
- searchable?: boolean | undefined;
55
- options?: FieldOption[] | undefined;
56
- restrictions?: import("./types").SchemaRestrictions | undefined;
53
+ isTypeField?: boolean | null | undefined;
54
+ searchable?: boolean | null | undefined;
55
+ options?: FieldOption[] | null | undefined;
56
+ restrictions?: import("./types").SchemaRestrictions | null | undefined;
57
57
  type: FieldType.Int;
58
58
  };
59
59
  export declare function boolField(displayName: string, options?: Partial<Omit<SchemaField, "type">>): (name: string) => SchemaField & {
60
60
  field?: string | undefined;
61
- displayName: string;
62
- tags?: string[] | undefined;
63
- system?: boolean | undefined;
64
- collection?: boolean | undefined;
65
- onlyForTypes?: string[] | undefined;
66
- required?: boolean | undefined;
61
+ displayName: string | null;
62
+ tags?: string[] | null | undefined;
63
+ system?: boolean | null | undefined;
64
+ collection?: boolean | null | undefined;
65
+ onlyForTypes?: string[] | null | undefined;
66
+ required?: boolean | null | undefined;
67
67
  defaultValue?: any;
68
- isTypeField?: boolean | undefined;
69
- searchable?: boolean | undefined;
70
- options?: FieldOption[] | undefined;
71
- restrictions?: import("./types").SchemaRestrictions | undefined;
68
+ isTypeField?: boolean | null | undefined;
69
+ searchable?: boolean | null | undefined;
70
+ options?: FieldOption[] | null | undefined;
71
+ restrictions?: import("./types").SchemaRestrictions | null | undefined;
72
72
  type: FieldType.Bool;
73
73
  };
74
74
  export declare function compoundField<Other extends Partial<Omit<CompoundField, "type" | "schemaType">>>(displayName: string, fields: SchemaField[], other: Other): (name: string) => CompoundField & {
package/lib/types.d.ts CHANGED
@@ -1,20 +1,20 @@
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[];
11
+ isTypeField?: boolean | null;
12
+ searchable?: boolean | null;
13
+ options?: FieldOption[] | null;
14
14
  /**
15
15
  * @deprecated Use options directly
16
16
  */
17
- restrictions?: SchemaRestrictions | undefined;
17
+ restrictions?: SchemaRestrictions | undefined | null;
18
18
  }
19
19
  export declare enum FieldType {
20
20
  String = "String",
@@ -34,7 +34,7 @@ export interface EntityRefField extends SchemaField {
34
34
  parentField: string;
35
35
  }
36
36
  export interface SchemaRestrictions {
37
- options: FieldOption[] | undefined;
37
+ options?: FieldOption[] | null;
38
38
  }
39
39
  export interface FieldOption {
40
40
  name: string;
@@ -48,9 +48,9 @@ export interface CompoundField extends SchemaField {
48
48
  export type AnyControlDefinition = DataControlDefinition | GroupedControlsDefinition | ActionControlDefinition | DisplayControlDefinition;
49
49
  export interface ControlDefinition {
50
50
  type: string;
51
- title?: string;
52
- dynamic?: DynamicProperty[];
53
- adornments?: ControlAdornment[];
51
+ title?: string | null;
52
+ dynamic?: DynamicProperty[] | null;
53
+ adornments?: ControlAdornment[] | null;
54
54
  }
55
55
  export declare enum ControlDefinitionType {
56
56
  Data = "Data",
@@ -101,10 +101,10 @@ export interface AccordionAdornment extends ControlAdornment {
101
101
  export interface DataControlDefinition extends ControlDefinition {
102
102
  type: ControlDefinitionType.Data;
103
103
  field: string;
104
- required?: boolean;
105
- renderOptions?: RenderOptions;
104
+ required?: boolean | null;
105
+ renderOptions?: RenderOptions | null;
106
106
  defaultValue?: any;
107
- readonly?: boolean;
107
+ readonly?: boolean | null;
108
108
  }
109
109
  export interface RenderOptions {
110
110
  type: string;
@@ -128,14 +128,14 @@ export interface HtmlEditorRenderOptions extends RenderOptions {
128
128
  allowImages: boolean;
129
129
  }
130
130
  export interface DateTimeRenderOptions extends RenderOptions {
131
- format?: string;
131
+ format?: string | null;
132
132
  }
133
133
  export interface IconListRenderOptions extends RenderOptions {
134
134
  iconMappings: IconMapping[];
135
135
  }
136
136
  export interface IconMapping {
137
137
  value: string;
138
- materialIcon: string | undefined;
138
+ materialIcon?: string | null;
139
139
  }
140
140
  export interface CheckListRenderOptions extends RenderOptions {
141
141
  }
@@ -157,12 +157,12 @@ export interface IconSelectionRenderOptions extends RenderOptions {
157
157
  export interface GroupedControlsDefinition extends ControlDefinition {
158
158
  type: ControlDefinitionType.Group;
159
159
  children: AnyControlDefinition[];
160
- compoundField?: string;
160
+ compoundField?: string | null;
161
161
  groupOptions: GroupRenderOptions;
162
162
  }
163
163
  export interface GroupRenderOptions {
164
164
  type: GroupRenderType;
165
- hideTitle?: boolean;
165
+ hideTitle?: boolean | null;
166
166
  }
167
167
  export declare enum GroupRenderType {
168
168
  Standard = "Standard",
@@ -175,7 +175,7 @@ export interface GroupElementRenderer extends GroupRenderOptions {
175
175
  value: any;
176
176
  }
177
177
  export interface GridRenderer extends GroupRenderOptions {
178
- columns: number | undefined;
178
+ columns?: number | null;
179
179
  }
180
180
  export interface DisplayControlDefinition extends ControlDefinition {
181
181
  type: ControlDefinitionType.Display;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-typed-forms/schemas",
3
- "version": "1.0.0-dev.3",
3
+ "version": "1.0.0-dev.4",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/schemas.build.log CHANGED
@@ -1,2 +0,0 @@
1
- Invoking: rimraf ./lib/ && tsc
2
-
@@ -12,7 +12,8 @@ import {
12
12
  SchemaField,
13
13
  } from "./types";
14
14
  import React, { createContext, Key, ReactElement, useContext } from "react";
15
- import { Control, newControl, useControlEffect } from "@react-typed-forms/core";
15
+ import { Control, newControl } from "@react-typed-forms/core";
16
+ import { fieldDisplayName } from "./index";
16
17
 
17
18
  export interface FormEditHooks {
18
19
  useDataProperties(
@@ -41,7 +42,7 @@ export interface DataControlProperties {
41
42
  readonly: boolean;
42
43
  defaultValue: any;
43
44
  required: boolean;
44
- options: FieldOption[] | undefined;
45
+ options: FieldOption[] | undefined | null;
45
46
  customRender?: (props: DataRendererProps) => ReactElement;
46
47
  }
47
48
 
@@ -233,12 +234,10 @@ export function findField(
233
234
  ): SchemaField | undefined {
234
235
  return fields.find((x) => x.field === field);
235
236
  }
236
-
237
- export function fieldDisplayName(sf: SchemaField): string {
238
- return sf.displayName ? sf.displayName : sf.field;
239
- }
240
-
241
- export function controlTitle(title: string | undefined, field: SchemaField) {
237
+ export function controlTitle(
238
+ title: string | undefined | null,
239
+ field: SchemaField
240
+ ) {
242
241
  return title ? title : fieldDisplayName(field);
243
242
  }
244
243
 
package/src/hooks.ts CHANGED
@@ -102,7 +102,7 @@ export function getDefaultScalarControlProperties(
102
102
 
103
103
  export function getOptionsForScalarField(
104
104
  field: SchemaField
105
- ): FieldOption[] | undefined {
105
+ ): FieldOption[] | undefined | null {
106
106
  const opts = field.options ?? field.restrictions?.options;
107
107
  if (opts?.length ?? 0 > 0) {
108
108
  return opts;
package/src/index.ts CHANGED
@@ -1,4 +1,14 @@
1
+ import { SchemaField } from "./types";
2
+
1
3
  export * from "./types";
2
4
  export * from "./schemaBuilder";
3
5
  export * from "./controlRender";
4
6
  export * from "./hooks";
7
+
8
+ export function fieldHasTag(field: SchemaField, tag: string) {
9
+ return Boolean(field.tags?.includes(tag));
10
+ }
11
+
12
+ export function fieldDisplayName(field: SchemaField) {
13
+ return field.displayName ?? field.field;
14
+ }
package/src/types.ts CHANGED
@@ -1,20 +1,20 @@
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[];
11
+ isTypeField?: boolean | null;
12
+ searchable?: boolean | null;
13
+ options?: FieldOption[] | null;
14
14
  /**
15
15
  * @deprecated Use options directly
16
16
  */
17
- restrictions?: SchemaRestrictions | undefined;
17
+ restrictions?: SchemaRestrictions | undefined | null;
18
18
  }
19
19
 
20
20
  export enum FieldType {
@@ -37,7 +37,7 @@ export interface EntityRefField extends SchemaField {
37
37
  }
38
38
 
39
39
  export interface SchemaRestrictions {
40
- options: FieldOption[] | undefined;
40
+ options?: FieldOption[] | null;
41
41
  }
42
42
 
43
43
  export interface FieldOption {
@@ -59,9 +59,9 @@ export type AnyControlDefinition =
59
59
 
60
60
  export interface ControlDefinition {
61
61
  type: string;
62
- title?: string;
63
- dynamic?: DynamicProperty[];
64
- adornments?: ControlAdornment[];
62
+ title?: string | null;
63
+ dynamic?: DynamicProperty[] | null;
64
+ adornments?: ControlAdornment[] | null;
65
65
  }
66
66
 
67
67
  export enum ControlDefinitionType {
@@ -125,10 +125,10 @@ export interface AccordionAdornment extends ControlAdornment {
125
125
  export interface DataControlDefinition extends ControlDefinition {
126
126
  type: ControlDefinitionType.Data;
127
127
  field: string;
128
- required?: boolean;
129
- renderOptions?: RenderOptions;
128
+ required?: boolean | null;
129
+ renderOptions?: RenderOptions | null;
130
130
  defaultValue?: any;
131
- readonly?: boolean;
131
+ readonly?: boolean | null;
132
132
  }
133
133
 
134
134
  export interface RenderOptions {
@@ -156,7 +156,7 @@ export interface HtmlEditorRenderOptions extends RenderOptions {
156
156
  }
157
157
 
158
158
  export interface DateTimeRenderOptions extends RenderOptions {
159
- format?: string;
159
+ format?: string | null;
160
160
  }
161
161
 
162
162
  export interface IconListRenderOptions extends RenderOptions {
@@ -165,7 +165,7 @@ export interface IconListRenderOptions extends RenderOptions {
165
165
 
166
166
  export interface IconMapping {
167
167
  value: string;
168
- materialIcon: string | undefined;
168
+ materialIcon?: string | null;
169
169
  }
170
170
 
171
171
  export interface CheckListRenderOptions extends RenderOptions {}
@@ -191,13 +191,13 @@ export interface IconSelectionRenderOptions extends RenderOptions {}
191
191
  export interface GroupedControlsDefinition extends ControlDefinition {
192
192
  type: ControlDefinitionType.Group;
193
193
  children: AnyControlDefinition[];
194
- compoundField?: string;
194
+ compoundField?: string | null;
195
195
  groupOptions: GroupRenderOptions;
196
196
  }
197
197
 
198
198
  export interface GroupRenderOptions {
199
199
  type: GroupRenderType;
200
- hideTitle?: boolean;
200
+ hideTitle?: boolean | null;
201
201
  }
202
202
 
203
203
  export enum GroupRenderType {
@@ -213,7 +213,7 @@ export interface GroupElementRenderer extends GroupRenderOptions {
213
213
  }
214
214
 
215
215
  export interface GridRenderer extends GroupRenderOptions {
216
- columns: number | undefined;
216
+ columns?: number | null;
217
217
  }
218
218
 
219
219
  export interface DisplayControlDefinition extends ControlDefinition {