@remoteoss/json-schema-form 0.4.4-dev.20230829102031 → 0.4.4-dev.20230830125207
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/dist/index.cjs +12 -14
- package/dist/index.js +12 -14
- package/dist/standalone.js +12 -14
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +25 -0
- package/src/tests/helpers.js +5 -5
- package/src/tests/const.test.js +0 -78
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230830125207
|
|
5
|
+
Generated: Wed, 30 Aug 2023 12:52:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -606,13 +606,6 @@ function buildYupSchema(field, config) {
|
|
|
606
606
|
}) : true
|
|
607
607
|
);
|
|
608
608
|
}
|
|
609
|
-
function withConst(yupSchema) {
|
|
610
|
-
return yupSchema.test(
|
|
611
|
-
"isConst",
|
|
612
|
-
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
613
|
-
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
614
|
-
);
|
|
615
|
-
}
|
|
616
609
|
function withBaseSchema() {
|
|
617
610
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
618
611
|
if (customErrorMsg) {
|
|
@@ -680,9 +673,6 @@ function buildYupSchema(field, config) {
|
|
|
680
673
|
if (propertyFields.accept) {
|
|
681
674
|
validators.push(withFileFormat);
|
|
682
675
|
}
|
|
683
|
-
if (propertyFields.const) {
|
|
684
|
-
validators.push(withConst);
|
|
685
|
-
}
|
|
686
676
|
return (0, import_flow.default)(validators);
|
|
687
677
|
}
|
|
688
678
|
function getNoSortEdges(fields = []) {
|
|
@@ -759,7 +749,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
|
|
|
759
749
|
initialValue[field.name] = subFieldValues;
|
|
760
750
|
}
|
|
761
751
|
} else {
|
|
762
|
-
|
|
752
|
+
if (typeof initialValue !== "object") {
|
|
753
|
+
console.warn(
|
|
754
|
+
`Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
|
|
755
|
+
);
|
|
756
|
+
initialValue = getPrefillValues([field], {
|
|
757
|
+
// TODO nested fieldsets are not handled
|
|
758
|
+
});
|
|
759
|
+
} else {
|
|
760
|
+
initialValue = getPrefillValues([field], initialValue);
|
|
761
|
+
}
|
|
763
762
|
}
|
|
764
763
|
return initialValue;
|
|
765
764
|
}
|
|
@@ -944,7 +943,6 @@ function extractParametersFromNode(schemaNode) {
|
|
|
944
943
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
945
944
|
return (0, import_omitBy.default)(
|
|
946
945
|
{
|
|
947
|
-
const: node.const,
|
|
948
946
|
label: node.title,
|
|
949
947
|
readOnly: node.readOnly,
|
|
950
948
|
...node.deprecated && {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230830125207
|
|
5
|
+
Generated: Wed, 30 Aug 2023 12:52:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -570,13 +570,6 @@ function buildYupSchema(field, config) {
|
|
|
570
570
|
}) : true
|
|
571
571
|
);
|
|
572
572
|
}
|
|
573
|
-
function withConst(yupSchema) {
|
|
574
|
-
return yupSchema.test(
|
|
575
|
-
"isConst",
|
|
576
|
-
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
577
|
-
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
573
|
function withBaseSchema() {
|
|
581
574
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
582
575
|
if (customErrorMsg) {
|
|
@@ -644,9 +637,6 @@ function buildYupSchema(field, config) {
|
|
|
644
637
|
if (propertyFields.accept) {
|
|
645
638
|
validators.push(withFileFormat);
|
|
646
639
|
}
|
|
647
|
-
if (propertyFields.const) {
|
|
648
|
-
validators.push(withConst);
|
|
649
|
-
}
|
|
650
640
|
return flow(validators);
|
|
651
641
|
}
|
|
652
642
|
function getNoSortEdges(fields = []) {
|
|
@@ -723,7 +713,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
|
|
|
723
713
|
initialValue[field.name] = subFieldValues;
|
|
724
714
|
}
|
|
725
715
|
} else {
|
|
726
|
-
|
|
716
|
+
if (typeof initialValue !== "object") {
|
|
717
|
+
console.warn(
|
|
718
|
+
`Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
|
|
719
|
+
);
|
|
720
|
+
initialValue = getPrefillValues([field], {
|
|
721
|
+
// TODO nested fieldsets are not handled
|
|
722
|
+
});
|
|
723
|
+
} else {
|
|
724
|
+
initialValue = getPrefillValues([field], initialValue);
|
|
725
|
+
}
|
|
727
726
|
}
|
|
728
727
|
return initialValue;
|
|
729
728
|
}
|
|
@@ -908,7 +907,6 @@ function extractParametersFromNode(schemaNode) {
|
|
|
908
907
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
909
908
|
return omitBy(
|
|
910
909
|
{
|
|
911
|
-
const: node.const,
|
|
912
910
|
label: node.title,
|
|
913
911
|
readOnly: node.readOnly,
|
|
914
912
|
...node.deprecated && {
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230830125207
|
|
5
|
+
Generated: Wed, 30 Aug 2023 12:52:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11546,13 +11546,6 @@ function buildYupSchema(field, config) {
|
|
|
11546
11546
|
}) : true
|
|
11547
11547
|
);
|
|
11548
11548
|
}
|
|
11549
|
-
function withConst(yupSchema) {
|
|
11550
|
-
return yupSchema.test(
|
|
11551
|
-
"isConst",
|
|
11552
|
-
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
11553
|
-
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
11554
|
-
);
|
|
11555
|
-
}
|
|
11556
11549
|
function withBaseSchema() {
|
|
11557
11550
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
11558
11551
|
if (customErrorMsg) {
|
|
@@ -11620,9 +11613,6 @@ function buildYupSchema(field, config) {
|
|
|
11620
11613
|
if (propertyFields.accept) {
|
|
11621
11614
|
validators.push(withFileFormat);
|
|
11622
11615
|
}
|
|
11623
|
-
if (propertyFields.const) {
|
|
11624
|
-
validators.push(withConst);
|
|
11625
|
-
}
|
|
11626
11616
|
return (0, import_flow.default)(validators);
|
|
11627
11617
|
}
|
|
11628
11618
|
function getNoSortEdges(fields = []) {
|
|
@@ -11699,7 +11689,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
|
|
|
11699
11689
|
initialValue[field.name] = subFieldValues;
|
|
11700
11690
|
}
|
|
11701
11691
|
} else {
|
|
11702
|
-
|
|
11692
|
+
if (typeof initialValue !== "object") {
|
|
11693
|
+
console.warn(
|
|
11694
|
+
`Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
|
|
11695
|
+
);
|
|
11696
|
+
initialValue = getPrefillValues([field], {
|
|
11697
|
+
// TODO nested fieldsets are not handled
|
|
11698
|
+
});
|
|
11699
|
+
} else {
|
|
11700
|
+
initialValue = getPrefillValues([field], initialValue);
|
|
11701
|
+
}
|
|
11703
11702
|
}
|
|
11704
11703
|
return initialValue;
|
|
11705
11704
|
}
|
|
@@ -11884,7 +11883,6 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11884
11883
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
11885
11884
|
return (0, import_omitBy.default)(
|
|
11886
11885
|
{
|
|
11887
|
-
const: node.const,
|
|
11888
11886
|
label: node.title,
|
|
11889
11887
|
readOnly: node.readOnly,
|
|
11890
11888
|
...node.deprecated && {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.4.4-dev.
|
|
3
|
+
"version": "0.4.4-dev.20230830125207",
|
|
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",
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
schemaInputTypeSelectMultipleDeprecated,
|
|
19
19
|
schemaInputTypeSelectMultiple,
|
|
20
20
|
schemaInputTypeSelectMultipleOptional,
|
|
21
|
+
schemaInputTypeFieldset,
|
|
21
22
|
schemaInputTypeNumber,
|
|
22
23
|
schemaInputTypeNumberZeroMaximum,
|
|
23
24
|
schemaInputTypeDate,
|
|
@@ -92,12 +93,15 @@ const getField = (fields, name, ...subNames) => {
|
|
|
92
93
|
};
|
|
93
94
|
|
|
94
95
|
beforeEach(() => {
|
|
96
|
+
jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
95
97
|
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
96
98
|
});
|
|
97
99
|
|
|
98
100
|
afterEach(() => {
|
|
99
101
|
expect(console.error).not.toHaveBeenCalled();
|
|
100
102
|
console.error.mockRestore();
|
|
103
|
+
expect(console.warn).not.toHaveBeenCalled();
|
|
104
|
+
console.warn.mockRestore();
|
|
101
105
|
});
|
|
102
106
|
|
|
103
107
|
describe('createHeadlessForm', () => {
|
|
@@ -3446,6 +3450,27 @@ describe('createHeadlessForm', () => {
|
|
|
3446
3450
|
],
|
|
3447
3451
|
});
|
|
3448
3452
|
});
|
|
3453
|
+
|
|
3454
|
+
it('should ignore initial values that do not match the field type (eg string vs object)', () => {
|
|
3455
|
+
const result = createHeadlessForm(schemaInputTypeFieldset, {
|
|
3456
|
+
initialValues: {
|
|
3457
|
+
a_fieldset: 'foo', // should be an object instead of string
|
|
3458
|
+
},
|
|
3459
|
+
});
|
|
3460
|
+
|
|
3461
|
+
// It returns fields without errors
|
|
3462
|
+
expect(result.fields).toBeDefined();
|
|
3463
|
+
expect(result.fields[0].fields[0].name).toBe('id_number');
|
|
3464
|
+
expect(result.fields[0].fields[1].name).toBe('tabs');
|
|
3465
|
+
|
|
3466
|
+
// Warn about those missmatched values
|
|
3467
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
3468
|
+
`Field "a_fieldset"'s value is "foo", but should be type object.`
|
|
3469
|
+
);
|
|
3470
|
+
console.warn.mockClear();
|
|
3471
|
+
|
|
3472
|
+
expect(console.error).not.toHaveBeenCalled();
|
|
3473
|
+
});
|
|
3449
3474
|
});
|
|
3450
3475
|
});
|
|
3451
3476
|
|
package/src/tests/helpers.js
CHANGED
|
@@ -1020,12 +1020,12 @@ export const schemaInputTypeFileWithSkippable = JSONSchemaBuilder()
|
|
|
1020
1020
|
})
|
|
1021
1021
|
.build();
|
|
1022
1022
|
|
|
1023
|
-
export const schemaInputTypeFieldset =
|
|
1024
|
-
|
|
1023
|
+
export const schemaInputTypeFieldset = {
|
|
1024
|
+
properties: {
|
|
1025
1025
|
a_fieldset: mockFieldset,
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1026
|
+
},
|
|
1027
|
+
required: ['a_fieldset'],
|
|
1028
|
+
};
|
|
1029
1029
|
|
|
1030
1030
|
export const schemaInputTypeFocusedFieldset = JSONSchemaBuilder()
|
|
1031
1031
|
.addInput({
|
package/src/tests/const.test.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { createHeadlessForm } from '../createHeadlessForm';
|
|
2
|
-
|
|
3
|
-
it('Should work for number', () => {
|
|
4
|
-
const { handleValidation } = createHeadlessForm(
|
|
5
|
-
{
|
|
6
|
-
properties: {
|
|
7
|
-
ten_only: { type: 'number', const: 10 },
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
{ strictInputType: false }
|
|
11
|
-
);
|
|
12
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
13
|
-
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
14
|
-
ten_only: 'The only accepted value is 10.',
|
|
15
|
-
});
|
|
16
|
-
expect(handleValidation({ ten_only: 10 }).formErrors).toEqual(undefined);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('Should work for text', () => {
|
|
20
|
-
const { handleValidation } = createHeadlessForm(
|
|
21
|
-
{
|
|
22
|
-
properties: {
|
|
23
|
-
hello_only: { type: 'string', const: 'hello' },
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
{ strictInputType: false }
|
|
27
|
-
);
|
|
28
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
29
|
-
expect(handleValidation({ hello_only: 'what' }).formErrors).toEqual({
|
|
30
|
-
hello_only: 'The only accepted value is hello.',
|
|
31
|
-
});
|
|
32
|
-
expect(handleValidation({ hello_only: 'hello' }).formErrors).toEqual(undefined);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('Should work for a conditionally applied const', () => {
|
|
36
|
-
const { handleValidation } = createHeadlessForm(
|
|
37
|
-
{
|
|
38
|
-
properties: {
|
|
39
|
-
answer: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] },
|
|
40
|
-
amount: { description: 'If you select yes, this needs to be exactly 10.', type: 'number' },
|
|
41
|
-
},
|
|
42
|
-
allOf: [
|
|
43
|
-
{
|
|
44
|
-
if: { properties: { answer: { const: 'yes' } }, required: ['answer'] },
|
|
45
|
-
then: { properties: { amount: { const: 10 } }, required: ['amount'] },
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{ strictInputType: false }
|
|
50
|
-
);
|
|
51
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
52
|
-
expect(handleValidation({ answer: 'no' }).formErrors).toEqual(undefined);
|
|
53
|
-
expect(handleValidation({ answer: 'yes' }).formErrors).toEqual({ amount: 'Required field' });
|
|
54
|
-
expect(handleValidation({ answer: 'yes', amount: 1 }).formErrors).toEqual({
|
|
55
|
-
amount: 'The only accepted value is 10.',
|
|
56
|
-
});
|
|
57
|
-
expect(handleValidation({ answer: 'yes', amount: 10 }).formErrors).toEqual(undefined);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Should show the custom error message', () => {
|
|
61
|
-
const { handleValidation } = createHeadlessForm(
|
|
62
|
-
{
|
|
63
|
-
properties: {
|
|
64
|
-
string: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
const: 'hello',
|
|
67
|
-
'x-jsf-errorMessage': { const: 'You must say hello!!!' },
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
{ strictInputType: false }
|
|
72
|
-
);
|
|
73
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
74
|
-
expect(handleValidation({ string: 'hi' }).formErrors).toEqual({
|
|
75
|
-
string: 'You must say hello!!!',
|
|
76
|
-
});
|
|
77
|
-
expect(handleValidation({ string: 'hello' }).formErrors).toEqual(undefined);
|
|
78
|
-
});
|