@remoteoss/json-schema-form 0.11.0-dev.20240725074901 → 0.11.1-dev.20240726080523
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/CHANGELOG.md +20 -1
- package/dist/index.cjs +6 -5
- package/dist/index.js +6 -5
- package/dist/standalone.js +6 -5
- package/json-schema-form.d.ts +50 -17
- package/package.json +1 -1
- package/src/tests/modify.test.js +53 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
|
+
#### 0.11.0-beta.0 (2024-07-25)
|
|
2
|
+
|
|
3
|
+
##### Breaking changes
|
|
4
|
+
|
|
5
|
+
- **modify:**
|
|
6
|
+
- Change the return result to include warnings ([#83](https://github.com/remoteoss/json-schema-form/pull/83)) ([e07fcec8](https://github.com/remoteoss/json-schema-form/commit/e07fcec8e11cfcba2b477e5e6339cebbcc42038c))
|
|
7
|
+
|
|
8
|
+
##### New Features
|
|
9
|
+
|
|
10
|
+
- **modify:**
|
|
11
|
+
- Allow picking fields ([#79](https://github.com/remoteoss/json-schema-form/pull/79)) ([2e044021](https://github.com/remoteoss/json-schema-form/commit/2e044021f30292be81cede3805eefb4f1ea96dd9))
|
|
12
|
+
- Add x-jsf-presentation shorthand ([#81](https://github.com/remoteoss/json-schema-form/pull/81)) ([7cfaab0b](https://github.com/remoteoss/json-schema-form/commit/7cfaab0bdbb05a1555f6c1d74b26b1e6d7fa8c43))
|
|
13
|
+
- Allow creating fields ([#80](https://github.com/remoteoss/json-schema-form/pull/80)) ([8a82254d](https://github.com/remoteoss/json-schema-form/commit/8a82254d7cf5799471fa0bf2d3d09179f1327187))
|
|
14
|
+
- Allow customize fields order ([#78](https://github.com/remoteoss/json-schema-form/pull/78)) ([adc88179](https://github.com/remoteoss/json-schema-form/commit/adc88179a5d1e5bd85371c0cc581b35964bf6edf))
|
|
15
|
+
|
|
16
|
+
##### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **modify:** Customize attrs as Array now overrides the value ([#82](https://github.com/remoteoss/json-schema-form/pull/82)) ([7cc0853e](https://github.com/remoteoss/json-schema-form/commit/7cc0853e30f0c06ff160d8a3e4c4b4e402a1e520))
|
|
19
|
+
|
|
1
20
|
#### 0.10.1-beta.0 (2024-07-23)
|
|
2
21
|
|
|
3
22
|
##### Chores
|
|
4
23
|
|
|
5
|
-
|
|
24
|
+
- **Text field docs:** Change naming of ID number property ([#74](https://github.com/remoteoss/json-schema-form/pull/74)) ([338ddd2a](https://github.com/remoteoss/json-schema-form/commit/338ddd2a5f008ec089f38db834f075100b856001))
|
|
6
25
|
|
|
7
26
|
#### 0.10.0-beta.0 (2024-06-20)
|
|
8
27
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.1-dev.20240726080523
|
|
5
|
+
Generated: Fri, 26 Jul 2024 08:05:36 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1853,9 +1853,10 @@ function mergeReplaceArray(_, newVal) {
|
|
|
1853
1853
|
return Array.isArray(newVal) ? newVal : void 0;
|
|
1854
1854
|
}
|
|
1855
1855
|
function standardizeAttrs(attrs) {
|
|
1856
|
-
const { errorMessage, properties, ...rest } = attrs;
|
|
1856
|
+
const { errorMessage, presentation, properties, ...rest } = attrs;
|
|
1857
1857
|
return {
|
|
1858
1858
|
...rest,
|
|
1859
|
+
...presentation ? { "x-jsf-presentation": presentation } : {},
|
|
1859
1860
|
...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
|
|
1860
1861
|
};
|
|
1861
1862
|
}
|
|
@@ -2025,9 +2026,9 @@ function pickFields(originalSchema, fieldsToPick) {
|
|
|
2025
2026
|
});
|
|
2026
2027
|
warnings.push({
|
|
2027
2028
|
type: WARNING_TYPES.PICK_MISSED_FIELD,
|
|
2028
|
-
message: `The picked fields
|
|
2029
|
+
message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
|
|
2029
2030
|
missingFields
|
|
2030
|
-
).join(", ")}. Check "meta" for more details.`,
|
|
2031
|
+
).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
|
|
2031
2032
|
meta: missingFields
|
|
2032
2033
|
});
|
|
2033
2034
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.1-dev.20240726080523
|
|
5
|
+
Generated: Fri, 26 Jul 2024 08:05:36 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1816,9 +1816,10 @@ function mergeReplaceArray(_, newVal) {
|
|
|
1816
1816
|
return Array.isArray(newVal) ? newVal : void 0;
|
|
1817
1817
|
}
|
|
1818
1818
|
function standardizeAttrs(attrs) {
|
|
1819
|
-
const { errorMessage, properties, ...rest } = attrs;
|
|
1819
|
+
const { errorMessage, presentation, properties, ...rest } = attrs;
|
|
1820
1820
|
return {
|
|
1821
1821
|
...rest,
|
|
1822
|
+
...presentation ? { "x-jsf-presentation": presentation } : {},
|
|
1822
1823
|
...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
|
|
1823
1824
|
};
|
|
1824
1825
|
}
|
|
@@ -1988,9 +1989,9 @@ function pickFields(originalSchema, fieldsToPick) {
|
|
|
1988
1989
|
});
|
|
1989
1990
|
warnings.push({
|
|
1990
1991
|
type: WARNING_TYPES.PICK_MISSED_FIELD,
|
|
1991
|
-
message: `The picked fields
|
|
1992
|
+
message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
|
|
1992
1993
|
missingFields
|
|
1993
|
-
).join(", ")}. Check "meta" for more details.`,
|
|
1994
|
+
).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
|
|
1994
1995
|
meta: missingFields
|
|
1995
1996
|
});
|
|
1996
1997
|
}
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.1-dev.20240726080523
|
|
5
|
+
Generated: Fri, 26 Jul 2024 08:05:36 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -13332,9 +13332,10 @@ function mergeReplaceArray(_, newVal) {
|
|
|
13332
13332
|
return Array.isArray(newVal) ? newVal : void 0;
|
|
13333
13333
|
}
|
|
13334
13334
|
function standardizeAttrs(attrs) {
|
|
13335
|
-
const { errorMessage, properties, ...rest } = attrs;
|
|
13335
|
+
const { errorMessage, presentation, properties, ...rest } = attrs;
|
|
13336
13336
|
return {
|
|
13337
13337
|
...rest,
|
|
13338
|
+
...presentation ? { "x-jsf-presentation": presentation } : {},
|
|
13338
13339
|
...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
|
|
13339
13340
|
};
|
|
13340
13341
|
}
|
|
@@ -13504,9 +13505,9 @@ function pickFields(originalSchema, fieldsToPick) {
|
|
|
13504
13505
|
});
|
|
13505
13506
|
warnings.push({
|
|
13506
13507
|
type: WARNING_TYPES.PICK_MISSED_FIELD,
|
|
13507
|
-
message: `The picked fields
|
|
13508
|
+
message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
|
|
13508
13509
|
missingFields
|
|
13509
|
-
).join(", ")}. Check "meta" for more details.`,
|
|
13510
|
+
).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
|
|
13510
13511
|
meta: missingFields
|
|
13511
13512
|
});
|
|
13512
13513
|
}
|
package/json-schema-form.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { WARNING_TYPES } from './src/modify';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Shorthand to lookup for keys with `x-jsf-*` preffix.
|
|
3
5
|
*/
|
|
4
6
|
export function pickXKey(node: Object, key: 'presentation' | 'errorMessage'): Object | undefined;
|
|
5
|
-
|
|
6
7
|
type ValidationTypes =
|
|
7
8
|
| 'type'
|
|
8
9
|
| 'minimum'
|
|
@@ -104,7 +105,47 @@ type HeadlessFormOutput = {
|
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
type JSONSchemaObjectType = Record<string, unknown>;
|
|
108
|
+
type FieldName = string;
|
|
109
|
+
type FieldAttrs = Record<string, unknown>;
|
|
110
|
+
|
|
111
|
+
type FieldAttrsCallbackFn = (fieldName: FieldName, fieldAttrs: FieldAttrs) => FieldAttrs;
|
|
112
|
+
|
|
113
|
+
type ModConfigProperties = Record<FieldName, FieldAttrs | FieldAttrsCallbackFn>;
|
|
107
114
|
|
|
115
|
+
type ModifyConfig = {
|
|
116
|
+
/**
|
|
117
|
+
* An object with the fields to be modified with the returned attributes.
|
|
118
|
+
*/
|
|
119
|
+
fields?: ModConfigProperties;
|
|
120
|
+
/**
|
|
121
|
+
* A callback function that runs through all fields, to modify them with the returned attributes.
|
|
122
|
+
*/
|
|
123
|
+
allFields?: FieldAttrsCallbackFn;
|
|
124
|
+
/**
|
|
125
|
+
* An object of new fields to be created with the new attributes.
|
|
126
|
+
*/
|
|
127
|
+
create?: ModConfigProperties;
|
|
128
|
+
/**
|
|
129
|
+
* An array of the fields to keep, removing the remaining fields.
|
|
130
|
+
*/
|
|
131
|
+
pick?: FieldName[];
|
|
132
|
+
/* An array of fieldNames with the new order. Can be an object or callback function */
|
|
133
|
+
orderRoot?: FieldName[] | ((originalOrder: FieldName[]) => FieldName[]);
|
|
134
|
+
/**
|
|
135
|
+
* Mutes any logs or warnings from the library.
|
|
136
|
+
*/
|
|
137
|
+
muteLogging?: boolean;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const warningTypes = WARNING_TYPES satisfies Record<string, string>;
|
|
141
|
+
|
|
142
|
+
type WARNING_TYPES = keyof typeof warningTypes;
|
|
143
|
+
|
|
144
|
+
type Warnings = {
|
|
145
|
+
message: string;
|
|
146
|
+
type: WARNING_TYPES;
|
|
147
|
+
meta?: Record<string, unknown>;
|
|
148
|
+
}[];
|
|
108
149
|
/**
|
|
109
150
|
* Generates the Headless form based on the provided JSON schema
|
|
110
151
|
*/
|
|
@@ -114,20 +155,9 @@ export function createHeadlessForm(
|
|
|
114
155
|
customConfig?: JSFConfig
|
|
115
156
|
): HeadlessFormOutput;
|
|
116
157
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
fields: Record<string, unknown>;
|
|
122
|
-
/**
|
|
123
|
-
* a callback function that applies a mutation to all the fields.
|
|
124
|
-
* @param fieldName
|
|
125
|
-
* @param fieldAttrs
|
|
126
|
-
* @returns
|
|
127
|
-
*/
|
|
128
|
-
allFields: (fieldName: string, fieldAttrs: Record<string, unknown>) => Record<string, unknown>;
|
|
129
|
-
};
|
|
130
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Modifies the JSON schema based on the provided configuration.
|
|
160
|
+
*/
|
|
131
161
|
export function modify(
|
|
132
162
|
/**
|
|
133
163
|
* The original JSON schema to be modified.
|
|
@@ -136,5 +166,8 @@ export function modify(
|
|
|
136
166
|
/**
|
|
137
167
|
* The configuration object containing the fields and allFields properties.
|
|
138
168
|
*/
|
|
139
|
-
config?:
|
|
140
|
-
)
|
|
169
|
+
config?: ModifyConfig
|
|
170
|
+
): {
|
|
171
|
+
schema: JSONSchemaObjectType;
|
|
172
|
+
warnings: Warnings;
|
|
173
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1-dev.20240726080523",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|
package/src/tests/modify.test.js
CHANGED
|
@@ -53,6 +53,9 @@ const schemaPet = {
|
|
|
53
53
|
properties: {
|
|
54
54
|
street: {
|
|
55
55
|
title: 'Street',
|
|
56
|
+
'x-jsf-presentation': {
|
|
57
|
+
inputType: 'text',
|
|
58
|
+
},
|
|
56
59
|
},
|
|
57
60
|
},
|
|
58
61
|
},
|
|
@@ -356,7 +359,7 @@ describe('modify() - basic mutations', () => {
|
|
|
356
359
|
});
|
|
357
360
|
});
|
|
358
361
|
|
|
359
|
-
it('
|
|
362
|
+
it('customize x-jsf-errorMessage (shorthand)', () => {
|
|
360
363
|
const result = modify(schemaPet, {
|
|
361
364
|
fields: {
|
|
362
365
|
pet_age: (fieldAttrs) => {
|
|
@@ -396,6 +399,53 @@ describe('modify() - basic mutations', () => {
|
|
|
396
399
|
},
|
|
397
400
|
});
|
|
398
401
|
});
|
|
402
|
+
|
|
403
|
+
it('customize x-jsf-presentation (shorthand)', () => {
|
|
404
|
+
const result = modify(schemaPet, {
|
|
405
|
+
fields: {
|
|
406
|
+
pet_age: () => {
|
|
407
|
+
return {
|
|
408
|
+
presentation: {
|
|
409
|
+
'data-foo': 123,
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
'pet_address.street': {
|
|
414
|
+
presentation: {
|
|
415
|
+
'data-foo': 456,
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const originalPetAgePresentation = schemaPet.properties.pet_age['x-jsf-presentation'];
|
|
422
|
+
expect(originalPetAgePresentation).toBeDefined();
|
|
423
|
+
|
|
424
|
+
const originalPetStreetPresentation =
|
|
425
|
+
schemaPet.properties.pet_address.properties.street['x-jsf-presentation'];
|
|
426
|
+
expect(originalPetStreetPresentation).toBeDefined();
|
|
427
|
+
|
|
428
|
+
expect(result.schema).toMatchObject({
|
|
429
|
+
properties: {
|
|
430
|
+
pet_age: {
|
|
431
|
+
'x-jsf-presentation': {
|
|
432
|
+
...originalPetAgePresentation,
|
|
433
|
+
'data-foo': 123,
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
pet_address: {
|
|
437
|
+
properties: {
|
|
438
|
+
street: {
|
|
439
|
+
'x-jsf-presentation': {
|
|
440
|
+
...originalPetStreetPresentation,
|
|
441
|
+
'data-foo': 456,
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
});
|
|
399
449
|
});
|
|
400
450
|
|
|
401
451
|
const schemaTickets = {
|
|
@@ -700,7 +750,7 @@ describe('modify() - pick fields', () => {
|
|
|
700
750
|
{
|
|
701
751
|
type: 'PICK_MISSED_FIELD',
|
|
702
752
|
message:
|
|
703
|
-
'The picked fields
|
|
753
|
+
'The picked fields are in conditionals that refeer other fields. They added automatically: "premium_id", "reason". Check "meta" for more details.',
|
|
704
754
|
meta: { premium_id: { path: 'allOf[1].then' }, reason: { path: 'allOf[2].then' } },
|
|
705
755
|
},
|
|
706
756
|
]);
|
|
@@ -729,7 +779,7 @@ describe('modify() - pick fields', () => {
|
|
|
729
779
|
{
|
|
730
780
|
type: 'PICK_MISSED_FIELD',
|
|
731
781
|
message:
|
|
732
|
-
'The picked fields
|
|
782
|
+
'The picked fields are in conditionals that refeer other fields. They added automatically: "has_premium". Check "meta" for more details.',
|
|
733
783
|
meta: { has_premium: { path: 'allOf[1].if' } },
|
|
734
784
|
},
|
|
735
785
|
]);
|