@remoteoss/json-schema-form 0.11.3-dev.20240819123216 → 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 +12 -4
- package/dist/index.js +12 -4
- package/dist/standalone.js +12 -4
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +28 -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
|
|
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -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",
|
|
@@ -852,8 +852,7 @@ describe('createHeadlessForm', () => {
|
|
|
852
852
|
handleValidation,
|
|
853
853
|
fieldName: 'siblings_count',
|
|
854
854
|
validOptions: [1, 2, 3],
|
|
855
|
-
type:
|
|
856
|
-
type: schemaInputTypeRadioBoolean.properties.siblings_count.type,
|
|
855
|
+
type: schemaInputTypeRadioNumber.properties.siblings_count.type,
|
|
857
856
|
});
|
|
858
857
|
|
|
859
858
|
expect(validateForm({ siblings_count: '3' })).toEqual({
|
|
@@ -1799,15 +1798,22 @@ describe('createHeadlessForm', () => {
|
|
|
1799
1798
|
// Then the fieldset perks.food changes (the "no" option gets removed)
|
|
1800
1799
|
|
|
1801
1800
|
// Setup (arrange)
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
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
|
+
});
|
|
1811
1817
|
|
|
1812
1818
|
it('by default, the Perks.food has 4 options', () => {
|
|
1813
1819
|
expect(originalFood.options).toHaveLength(4);
|
|
@@ -2734,7 +2740,7 @@ describe('createHeadlessForm', () => {
|
|
|
2734
2740
|
);
|
|
2735
2741
|
fields = result.fields;
|
|
2736
2742
|
});
|
|
2737
|
-
describe('and file is of
|
|
2743
|
+
describe('and file is of incorrect format', () => {
|
|
2738
2744
|
const file = new File(['foo'], 'file.txt', {
|
|
2739
2745
|
type: 'text/plain',
|
|
2740
2746
|
});
|
|
@@ -2783,6 +2789,16 @@ describe('createHeadlessForm', () => {
|
|
|
2783
2789
|
.validate({ fileInput: [file] })
|
|
2784
2790
|
).resolves.toEqual(assertObj));
|
|
2785
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
|
+
});
|
|
2786
2802
|
});
|
|
2787
2803
|
|
|
2788
2804
|
describe('when a field has conditional presentation properties', () => {
|