@remoteoss/json-schema-form 0.11.11-dev.20250220174843 → 1.0.0-beta.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.
@@ -1,175 +0,0 @@
1
- /**
2
- * Shorthand to lookup for keys with `x-jsf-*` preffix.
3
- */
4
- export function pickXKey(node: Object, key: 'presentation' | 'errorMessage'): Object | undefined;
5
- type ValidationTypes =
6
- | 'type'
7
- | 'minimum'
8
- | 'maximum'
9
- | 'minLength'
10
- | 'maxLength'
11
- | 'pattern'
12
- | 'maxFileSize'
13
- | 'accept'
14
- | 'required';
15
-
16
- type JSFConfig = {
17
- /**
18
- * Initial json values to prefill the form fields.
19
- * This influences the initial visibility of conditional fields.
20
- */
21
- initialValues?: Record<string, unknown>;
22
- /**
23
- * It inforces all json properties (fields) to have x-jsf-presentation.inputType.
24
- @default true
25
- */
26
- strictInputType?: boolean;
27
- /**
28
- * Customize the output of a given named Field.
29
- * Useful if you want to enhance the UI/UX of a particular field.
30
- * @example
31
- * { has_pet: { "optionsDirection": "horizontal" } }
32
- */
33
- customProperties?: {
34
- description?: (description: string, field: $TSFixMe) => string | string;
35
- [key: string]: unknown;
36
- };
37
- /**
38
- * Customize the config for each inputType
39
- */
40
- inputTypes?: {
41
- /**
42
- * Customize the error error message of this input type.
43
- * @example
44
- * { required: "This number is required." }
45
- */
46
- errorMessage?: Partial<Record<ValidationTypes, string>>;
47
- };
48
- };
49
- type Fields = Record<string, unknown>[]; //TODO: Type the field based on the given JSON Schema properties.
50
-
51
- type $TSFixMe = any;
52
-
53
- /**
54
- * Returns the Yup schema structure of given fields.
55
- * These fields must be the same from
56
- * const { fields } = createHeadlessForm()
57
- */
58
- export function buildCompleteYupSchema(fields: Fields, config: JSFConfig): $TSFixMe; //TODO: We need to update Yup to 1.0 which supports TS.
59
-
60
- type HeadlessFormOutput = {
61
- /**
62
- * List of Fields. Each Field corresponds to a form input from the json schema.
63
- * @example
64
- * [
65
- {
66
- name: "has_pet",
67
- label: "Has Pet",
68
- options: [
69
- { label: "Yes", value: "yes" },
70
- { label: "No", value: "no" }
71
- ],
72
- required: true,
73
- inputType: "radio",
74
- jsonType: "string",
75
- description: "Do you have a pet?",
76
- errorMessage: {},
77
- isVisible: true
78
- },
79
- {
80
- type: "text",
81
- label: "Pet's name",
82
- description: "What's your pet's name?",
83
- required: false,
84
- inputType: "text",
85
- jsonType: "string",
86
- isVisible: false
87
- }
88
- * ]
89
- */
90
- fields: Fields;
91
- /**
92
- * Validates given values and returns the respective errors.
93
- * @example
94
- * const { formErrors } = handleValidation({ has_pet: "yes" });
95
- * console.log(formErrors) // { pet_name: "Required field." }
96
- */
97
- handleValidation: (values: Record<string, unknown>) => {
98
- yupError: $TSFixMe;
99
- formErrors: $TSFixMe;
100
- };
101
- isError: boolean;
102
- error?: Error;
103
- };
104
-
105
- type JSONSchemaObjectType = Record<string, unknown>;
106
- type FieldName = string;
107
- type FieldAttrs = Record<string, unknown>;
108
-
109
- type ModifyConfig = {
110
- /**
111
- * An object with the fields to be modified with the returned attributes.
112
- */
113
- fields?: Record<FieldName, FieldAttrs | ((fieldAttrs: FieldAttrs) => FieldAttrs)>;
114
- /**
115
- * A callback function that runs through all fields, to modify them with the returned attributes.
116
- */
117
- allFields?: (fieldName: FieldName, fieldAttrs: FieldAttrs) => FieldAttrs;
118
- /**
119
- * An object of new fields to be created with the new attributes.
120
- */
121
- create?: Record<FieldName, FieldAttrs>;
122
- /**
123
- * An array of the fields to keep, removing the remaining fields.
124
- */
125
- pick?: FieldName[];
126
- /**
127
- * An array of fieldNames with the new order. Can be an object or callback function
128
- * */
129
- orderRoot?: FieldName[] | ((originalOrder: FieldName[]) => FieldName[]);
130
- /**
131
- * Mutes any logs or warnings from the library.
132
- */
133
- muteLogging?: boolean;
134
- };
135
-
136
- type WarningType =
137
- | 'FIELD_TO_CHANGE_NOT_FOUND'
138
- | 'ORDER_MISSING_FIELDS'
139
- | 'FIELD_TO_CREATE_EXISTS'
140
- | 'PICK_MISSED_FIELD';
141
-
142
- type Warning = {
143
- message: string;
144
- type: WarningType;
145
- meta?: Record<string, unknown>;
146
- };
147
-
148
- type ModifyOutput = {
149
- schema: JSONSchemaObjectType;
150
- warnings: Warning[];
151
- };
152
-
153
- /**
154
- * Generates the Headless form based on the provided JSON schema
155
- */
156
- export function createHeadlessForm(
157
- /** A JSON Schema of type object */
158
- jsonSchema: JSONSchemaObjectType,
159
- customConfig?: JSFConfig
160
- ): HeadlessFormOutput;
161
-
162
- /**
163
- * Returns a new JSON Schema modified based a given configuration.
164
- * This does not mutate the original JSON Schema.
165
- */
166
- export function modify(
167
- /**
168
- * The original JSON schema as base to the modifications.
169
- */
170
- originalSchema: JSONSchemaObjectType,
171
- /**
172
- * The configuration object to create a new JSON Schema based on the originalSchema.
173
- */
174
- config?: ModifyConfig
175
- ): ModifyOutput;
@@ -1,188 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "JSON json-schema-form-Schema",
4
- "definitions": {
5
- "schemaArray": {
6
- "allOf": [
7
- {
8
- "$ref": "http://json-schema.org/draft-07/schema#/definitions/schemaArray"
9
- },
10
- {
11
- "items": { "$ref": "#" }
12
- }
13
- ]
14
- }
15
- },
16
- "allOf": [{ "$ref": "http://json-schema.org/draft-07/schema#" }],
17
- "properties": {
18
- "additionalItems": { "$ref": "#" },
19
- "additionalProperties": { "$ref": "#" },
20
- "dependencies": {
21
- "additionalProperties": {
22
- "anyOf": [{ "$ref": "#" }, { "type": "array" }]
23
- }
24
- },
25
- "items": {
26
- "anyOf": [{ "$ref": "#" }, { "$ref": "#/definitions/schemaArray" }]
27
- },
28
- "definitions": {
29
- "additionalProperties": { "$ref": "#" }
30
- },
31
- "patternProperties": {
32
- "additionalProperties": { "$ref": "#" }
33
- },
34
- "properties": {
35
- "additionalProperties": { "$ref": "#" }
36
- },
37
- "if": { "$ref": "#" },
38
- "then": { "$ref": "#" },
39
- "else": { "$ref": "#" },
40
- "allOf": { "$ref": "#/definitions/schemaArray" },
41
- "anyOf": { "$ref": "#/definitions/schemaArray" },
42
- "oneOf": { "$ref": "#/definitions/schemaArray" },
43
- "not": { "$ref": "#" },
44
- "contains": { "$ref": "#" },
45
- "propertyNames": { "$ref": "#" },
46
- "x-jsf-order": {
47
- "description": "This keyword defines the order of fields for a given form or fieldset. It's placed at the schema root and inside of each fieldset.",
48
- "$ref": "http://json-schema.org/draft-07/schema#/definitions/stringArray"
49
- },
50
- "x-jsf-errorMessage": {
51
- "type": "object",
52
- "additionalProperties": false,
53
- "properties": {
54
- "type": {
55
- "type": "string",
56
- "description": "Message shown when the value is not of the correct type."
57
- },
58
- "required": {
59
- "type": "string",
60
- "description": "Message shown when the value is required and not provided."
61
- },
62
- "minimum": {
63
- "type": "string",
64
- "description": "Message shown when the value is less than the minimum value."
65
- },
66
- "minLength": {
67
- "type": "string",
68
- "description": "Message shown when the value is less than the minimum length."
69
- },
70
- "maximum": {
71
- "type": "string",
72
- "description": "Message shown when the value is greater than the maximum value."
73
- },
74
- "maxLength": {
75
- "type": "string",
76
- "description": "Message shown when the value is greater than the maximum length."
77
- },
78
- "pattern": {
79
- "type": "string",
80
- "description": "Message shown when the value is not the correct format and does not match the pattern property."
81
- },
82
- "maxFileSize": {
83
- "type": "string",
84
- "description": "Message shown when the file size is greater than the maximum file size."
85
- },
86
- "accept": {
87
- "type": "string",
88
- "description": "Message shown when the file type is not accepted."
89
- }
90
- }
91
- },
92
- "x-jsf-presentation": {
93
- "type": "object",
94
- "description": "Presentation overrides for the schema",
95
- "properties": {
96
- "inputType": {
97
- "description": "Input type for the generated UI field",
98
- "type": "string",
99
- "anyOf": [
100
- {
101
- "const": "text",
102
- "description": "Similar to the native HTML input with text type."
103
- },
104
- {
105
- "const": "select",
106
- "description": "Similar to the native HTML select element."
107
- },
108
- {
109
- "const": "radio",
110
- "description": "Similar to a native HTML input with radio type."
111
- },
112
- {
113
- "const": "number",
114
- "description": "Similar to the native HTML input with number type."
115
- },
116
- {
117
- "const": "date",
118
- "description": "Expects a value with format YYY-MM-DD."
119
- },
120
- {
121
- "const": "checkbox",
122
- "description": "Similar to the native HTML input with checkbox type."
123
- },
124
- {
125
- "const": "email",
126
- "description": "Similar to the native HTML input with email type."
127
- },
128
- {
129
- "const": "file",
130
- "description": "Similar to the native HTML input with file type."
131
- },
132
- {
133
- "const": "fieldset",
134
- "description": "Groups multiple Fields inside. Its expected value is a nested object."
135
- },
136
- {
137
- "const": "group-array",
138
- "description": "A list of inputs that can be repeated. Its expected value is an array."
139
- },
140
- {
141
- "type": "string",
142
- "description": "Any arbitrary custom inputType you might want to represent your UI Field."
143
- }
144
- ]
145
- },
146
- "accept": {
147
- "description": "For `inputType: \"file\"`. The accepted file types, as a comma separated string.",
148
- "type": "string"
149
- },
150
- "description": {
151
- "description": "Field description with HTML. If you don't need HTML, please use the native description keyword.",
152
- "type": "string"
153
- },
154
- "statement": {
155
- "description": "Special message about the field. Useful in cases where this message is based on the field value.",
156
- "type": "object",
157
- "properties": {
158
- "title": {
159
- "type": "string"
160
- },
161
- "description": {
162
- "description": "The sentence itself. Might include HTML.",
163
- "type": "string"
164
- },
165
- "severity": {
166
- "description": "Defines the type of message.",
167
- "anyOf": [
168
- { "type": "string", "const": "info" },
169
- { "type": "string", "const": "warning" },
170
- { "type": "string", "const": "error" },
171
- { "type": "string", "const": "success" },
172
- {}
173
- ]
174
- }
175
- }
176
- },
177
- "maxFileSize": {
178
- "description": "For `inputType: \"file\"`. The maximum file size in KB. It's used to enhanced Yup validation.",
179
- "type": "number"
180
- },
181
- "addFieldText": {
182
- "description": "Used in `group-array` fields. The button text to add a new field.",
183
- "type": "string"
184
- }
185
- }
186
- }
187
- }
188
- }
@@ -1,65 +0,0 @@
1
- import { checkIfConditionMatchesProperties } from '@/internals/checkIfConditionMatches';
2
-
3
- describe('checkIfConditionMatchesProperties()', () => {
4
- it('True if is always going to be true', () => {
5
- expect(checkIfConditionMatchesProperties({ if: true })).toBe(true);
6
- });
7
-
8
- it('False if is always going to be false', () => {
9
- expect(checkIfConditionMatchesProperties({ if: false })).toBe(false);
10
- });
11
-
12
- it('Empty if is always going to be true', () => {
13
- expect(checkIfConditionMatchesProperties({ if: { properties: {} } })).toBe(true);
14
- });
15
-
16
- it('Basic if check passes with correct value', () => {
17
- expect(
18
- checkIfConditionMatchesProperties(
19
- { if: { properties: { a: { const: 'hello' } } } },
20
- {
21
- a: 'hello',
22
- }
23
- )
24
- ).toBe(true);
25
- });
26
-
27
- it('Basic if check fails with incorrect value', () => {
28
- expect(
29
- checkIfConditionMatchesProperties(
30
- { if: { properties: { a: { const: 'hello' } } } },
31
- {
32
- a: 'goodbye',
33
- }
34
- )
35
- ).toBe(false);
36
- });
37
-
38
- it('Nested properties check passes with correct value', () => {
39
- expect(
40
- checkIfConditionMatchesProperties(
41
- {
42
- if: { properties: { parent: { properties: { child: { const: 'hello from child' } } } } },
43
- },
44
- {
45
- parent: { child: 'hello from child' },
46
- },
47
- [{ name: 'parent', fields: [] }]
48
- )
49
- ).toBe(true);
50
- });
51
-
52
- it('Nested properties check passes with correct value', () => {
53
- expect(
54
- checkIfConditionMatchesProperties(
55
- {
56
- if: { properties: { parent: { properties: { child: { const: 'hello from child' } } } } },
57
- },
58
- {
59
- parent: { child: 'goodbye from child' },
60
- },
61
- [{ name: 'parent', fields: [] }]
62
- )
63
- ).toBe(false);
64
- });
65
- });