@remoteoss/json-schema-form 0.11.3-dev.20240816092154 → 0.11.4-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.
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +17 -9
- package/dist/index.js +17 -9
- package/dist/standalone.js +17 -9
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +41 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
#### 0.11.4-beta.0 (2024-08-20)
|
|
2
|
+
|
|
3
|
+
##### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **file:** Validate the value is an instance of File ([#87](https://github.com/remoteoss/json-schema-form/pull/87)) ([8361df0d](https://github.com/remoteoss/json-schema-form/commit/8361df0d4e9f7d83342cdc91c41efb493e391307))
|
|
6
|
+
|
|
7
|
+
##### Chores
|
|
8
|
+
|
|
9
|
+
* **tests:** Move code in global test scope to inside beforeAll ([#90](https://github.com/remoteoss/json-schema-form/pull/90)) ([88f7d3c9](https://github.com/remoteoss/json-schema-form/commit/88f7d3c95330c828fc2539962b878c43b61ca8a0))
|
|
10
|
+
|
|
11
|
+
#### 0.11.3-beta.0 (2024-08-19)
|
|
12
|
+
|
|
13
|
+
##### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **select/radio:** Add support for options with boolean type ([#89](https://github.com/remoteoss/json-schema-form/pull/89)) ([127f70b3](https://github.com/remoteoss/json-schema-form/commit/127f70b3b19974a404e710548b83d4e4b17e1339))
|
|
16
|
+
|
|
1
17
|
#### 0.11.2-beta.0 (2024-07-30)
|
|
2
18
|
|
|
3
19
|
##### Bug Fixes
|
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.4-beta.0
|
|
5
|
+
Generated: Tue, 20 Aug 2024 17:17:21 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -534,13 +534,13 @@ var yupSchemas = {
|
|
|
534
534
|
return value === null ? void 0 : value;
|
|
535
535
|
}).test(
|
|
536
536
|
"matchesOptionOrPattern",
|
|
537
|
-
({
|
|
538
|
-
return `The option ${JSON.stringify(
|
|
537
|
+
({ originalValue }) => {
|
|
538
|
+
return `The option ${JSON.stringify(originalValue)} is not valid.`;
|
|
539
539
|
},
|
|
540
|
-
(
|
|
541
|
-
if (
|
|
540
|
+
(castValue, { originalValue }) => {
|
|
541
|
+
if (typeof originalValue !== "boolean" && castValue !== void 0)
|
|
542
542
|
return false;
|
|
543
|
-
return validateRadioOrSelectOptions(
|
|
543
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
544
544
|
}
|
|
545
545
|
);
|
|
546
546
|
},
|
|
@@ -668,18 +668,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
668
668
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
669
669
|
);
|
|
670
670
|
}
|
|
671
|
+
function isFile(files) {
|
|
672
|
+
return Array.isArray(files) ? files.every((file) => file instanceof File) : files instanceof File;
|
|
673
|
+
}
|
|
674
|
+
function withFile(yupSchema) {
|
|
675
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isFile);
|
|
676
|
+
}
|
|
671
677
|
function withMaxFileSize(yupSchema) {
|
|
672
678
|
return yupSchema.test(
|
|
673
679
|
"isValidFileSize",
|
|
674
680
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
675
|
-
(files) => !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
681
|
+
(files) => isFile(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
676
682
|
);
|
|
677
683
|
}
|
|
678
684
|
function withFileFormat(yupSchema) {
|
|
679
685
|
return yupSchema.test(
|
|
680
686
|
"isSupportedFormat",
|
|
681
687
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
682
|
-
(files) => files && files
|
|
688
|
+
(files) => isFile(files) && files.length > 0 ? files.some((file) => {
|
|
683
689
|
const fileType = file.name.split(".").pop();
|
|
684
690
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
685
691
|
}) : true
|
|
@@ -734,6 +740,8 @@ function buildYupSchema(field, config, logic) {
|
|
|
734
740
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
735
741
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
736
742
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
743
|
+
} else if (inputType === supportedTypes.FILE) {
|
|
744
|
+
validators.push(withFile);
|
|
737
745
|
}
|
|
738
746
|
if (propertyFields.required) {
|
|
739
747
|
validators.push(withRequired);
|
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.4-beta.0
|
|
5
|
+
Generated: Tue, 20 Aug 2024 17:17:21 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -497,13 +497,13 @@ var yupSchemas = {
|
|
|
497
497
|
return value === null ? void 0 : value;
|
|
498
498
|
}).test(
|
|
499
499
|
"matchesOptionOrPattern",
|
|
500
|
-
({
|
|
501
|
-
return `The option ${JSON.stringify(
|
|
500
|
+
({ originalValue }) => {
|
|
501
|
+
return `The option ${JSON.stringify(originalValue)} is not valid.`;
|
|
502
502
|
},
|
|
503
|
-
(
|
|
504
|
-
if (
|
|
503
|
+
(castValue, { originalValue }) => {
|
|
504
|
+
if (typeof originalValue !== "boolean" && castValue !== void 0)
|
|
505
505
|
return false;
|
|
506
|
-
return validateRadioOrSelectOptions(
|
|
506
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
507
507
|
}
|
|
508
508
|
);
|
|
509
509
|
},
|
|
@@ -631,18 +631,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
631
631
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
632
632
|
);
|
|
633
633
|
}
|
|
634
|
+
function isFile(files) {
|
|
635
|
+
return Array.isArray(files) ? files.every((file) => file instanceof File) : files instanceof File;
|
|
636
|
+
}
|
|
637
|
+
function withFile(yupSchema) {
|
|
638
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isFile);
|
|
639
|
+
}
|
|
634
640
|
function withMaxFileSize(yupSchema) {
|
|
635
641
|
return yupSchema.test(
|
|
636
642
|
"isValidFileSize",
|
|
637
643
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
638
|
-
(files) => !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
644
|
+
(files) => isFile(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
639
645
|
);
|
|
640
646
|
}
|
|
641
647
|
function withFileFormat(yupSchema) {
|
|
642
648
|
return yupSchema.test(
|
|
643
649
|
"isSupportedFormat",
|
|
644
650
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
645
|
-
(files) => files && files
|
|
651
|
+
(files) => isFile(files) && files.length > 0 ? files.some((file) => {
|
|
646
652
|
const fileType = file.name.split(".").pop();
|
|
647
653
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
648
654
|
}) : true
|
|
@@ -697,6 +703,8 @@ function buildYupSchema(field, config, logic) {
|
|
|
697
703
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
698
704
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
699
705
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
706
|
+
} else if (inputType === supportedTypes.FILE) {
|
|
707
|
+
validators.push(withFile);
|
|
700
708
|
}
|
|
701
709
|
if (propertyFields.required) {
|
|
702
710
|
validators.push(withRequired);
|
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.4-beta.0
|
|
5
|
+
Generated: Tue, 20 Aug 2024 17:17:21 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12013,13 +12013,13 @@ var yupSchemas = {
|
|
|
12013
12013
|
return value === null ? void 0 : value;
|
|
12014
12014
|
}).test(
|
|
12015
12015
|
"matchesOptionOrPattern",
|
|
12016
|
-
({
|
|
12017
|
-
return `The option ${JSON.stringify(
|
|
12016
|
+
({ originalValue }) => {
|
|
12017
|
+
return `The option ${JSON.stringify(originalValue)} is not valid.`;
|
|
12018
12018
|
},
|
|
12019
|
-
(
|
|
12020
|
-
if (
|
|
12019
|
+
(castValue, { originalValue }) => {
|
|
12020
|
+
if (typeof originalValue !== "boolean" && castValue !== void 0)
|
|
12021
12021
|
return false;
|
|
12022
|
-
return validateRadioOrSelectOptions(
|
|
12022
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
12023
12023
|
}
|
|
12024
12024
|
);
|
|
12025
12025
|
},
|
|
@@ -12147,18 +12147,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
12147
12147
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
12148
12148
|
);
|
|
12149
12149
|
}
|
|
12150
|
+
function isFile(files) {
|
|
12151
|
+
return Array.isArray(files) ? files.every((file) => file instanceof File) : files instanceof File;
|
|
12152
|
+
}
|
|
12153
|
+
function withFile(yupSchema) {
|
|
12154
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isFile);
|
|
12155
|
+
}
|
|
12150
12156
|
function withMaxFileSize(yupSchema) {
|
|
12151
12157
|
return yupSchema.test(
|
|
12152
12158
|
"isValidFileSize",
|
|
12153
12159
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
12154
|
-
(files) => !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
12160
|
+
(files) => isFile(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
12155
12161
|
);
|
|
12156
12162
|
}
|
|
12157
12163
|
function withFileFormat(yupSchema) {
|
|
12158
12164
|
return yupSchema.test(
|
|
12159
12165
|
"isSupportedFormat",
|
|
12160
12166
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
12161
|
-
(files) => files && files
|
|
12167
|
+
(files) => isFile(files) && files.length > 0 ? files.some((file) => {
|
|
12162
12168
|
const fileType = file.name.split(".").pop();
|
|
12163
12169
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
12164
12170
|
}) : true
|
|
@@ -12213,6 +12219,8 @@ function buildYupSchema(field, config, logic) {
|
|
|
12213
12219
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
12214
12220
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
12215
12221
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
12222
|
+
} else if (inputType === supportedTypes.FILE) {
|
|
12223
|
+
validators.push(withFile);
|
|
12216
12224
|
}
|
|
12217
12225
|
if (propertyFields.required) {
|
|
12218
12226
|
validators.push(withRequired);
|
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.4-beta.0",
|
|
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",
|
|
@@ -783,6 +783,8 @@ describe('createHeadlessForm', () => {
|
|
|
783
783
|
it('support "radio" field boolean type', () => {
|
|
784
784
|
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioBoolean);
|
|
785
785
|
|
|
786
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
787
|
+
|
|
786
788
|
expect(fields).toMatchObject([
|
|
787
789
|
{
|
|
788
790
|
description: 'Are you over 18 years old?',
|
|
@@ -808,13 +810,19 @@ describe('createHeadlessForm', () => {
|
|
|
808
810
|
handleValidation,
|
|
809
811
|
fieldName: 'over_18',
|
|
810
812
|
validOptions: [true, false],
|
|
811
|
-
type:
|
|
813
|
+
type: schemaInputTypeRadioBoolean.properties.over_18.type,
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
expect(validateForm({ over_18: 'true' })).toEqual({
|
|
817
|
+
over_18: 'The option "true" is not valid.',
|
|
812
818
|
});
|
|
813
819
|
});
|
|
814
820
|
|
|
815
821
|
it('support "radio" field number type', () => {
|
|
816
822
|
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioNumber);
|
|
817
823
|
|
|
824
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
825
|
+
|
|
818
826
|
expect(fields).toMatchObject([
|
|
819
827
|
{
|
|
820
828
|
description: 'How many siblings do you have?',
|
|
@@ -844,7 +852,11 @@ describe('createHeadlessForm', () => {
|
|
|
844
852
|
handleValidation,
|
|
845
853
|
fieldName: 'siblings_count',
|
|
846
854
|
validOptions: [1, 2, 3],
|
|
847
|
-
type:
|
|
855
|
+
type: schemaInputTypeRadioNumber.properties.siblings_count.type,
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
expect(validateForm({ siblings_count: '3' })).toEqual({
|
|
859
|
+
siblings_count: 'The option "3" is not valid.',
|
|
848
860
|
});
|
|
849
861
|
});
|
|
850
862
|
|
|
@@ -1786,15 +1798,22 @@ describe('createHeadlessForm', () => {
|
|
|
1786
1798
|
// Then the fieldset perks.food changes (the "no" option gets removed)
|
|
1787
1799
|
|
|
1788
1800
|
// Setup (arrange)
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1801
|
+
let validateForm;
|
|
1802
|
+
let fields;
|
|
1803
|
+
let originalFood;
|
|
1804
|
+
let perksForLowWorkHours;
|
|
1805
|
+
|
|
1806
|
+
beforeAll(() => {
|
|
1807
|
+
const form = createHeadlessForm(schemaWithConditionalToFieldset);
|
|
1808
|
+
fields = form.fields;
|
|
1809
|
+
validateForm = (vals) => friendlyError(form.handleValidation(vals));
|
|
1810
|
+
originalFood = getField(fields, 'perks', 'food');
|
|
1811
|
+
|
|
1812
|
+
perksForLowWorkHours = {
|
|
1813
|
+
food: 'no', // this option will be removed when the condition happens.
|
|
1814
|
+
retirement: 'basic',
|
|
1815
|
+
};
|
|
1816
|
+
});
|
|
1798
1817
|
|
|
1799
1818
|
it('by default, the Perks.food has 4 options', () => {
|
|
1800
1819
|
expect(originalFood.options).toHaveLength(4);
|
|
@@ -2721,7 +2740,7 @@ describe('createHeadlessForm', () => {
|
|
|
2721
2740
|
);
|
|
2722
2741
|
fields = result.fields;
|
|
2723
2742
|
});
|
|
2724
|
-
describe('and file is of
|
|
2743
|
+
describe('and file is of incorrect format', () => {
|
|
2725
2744
|
const file = new File(['foo'], 'file.txt', {
|
|
2726
2745
|
type: 'text/plain',
|
|
2727
2746
|
});
|
|
@@ -2770,6 +2789,16 @@ describe('createHeadlessForm', () => {
|
|
|
2770
2789
|
.validate({ fileInput: [file] })
|
|
2771
2790
|
).resolves.toEqual(assertObj));
|
|
2772
2791
|
});
|
|
2792
|
+
describe('and file is not instance of a File', () => {
|
|
2793
|
+
it('should throw an error', async () =>
|
|
2794
|
+
expect(
|
|
2795
|
+
object()
|
|
2796
|
+
.shape({
|
|
2797
|
+
fileInput: fields[0].schema,
|
|
2798
|
+
})
|
|
2799
|
+
.validate({ fileInput: [{ path: 'foo.txt' }] })
|
|
2800
|
+
).rejects.toMatchObject({ errors: ['Not a valid file.'] }));
|
|
2801
|
+
});
|
|
2773
2802
|
});
|
|
2774
2803
|
|
|
2775
2804
|
describe('when a field has conditional presentation properties', () => {
|