@remoteoss/json-schema-form 0.7.1-dev.20231025070834 → 0.7.1-dev.20231031082524
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 +19 -13
- package/dist/index.js +19 -13
- package/dist/standalone.js +19 -13
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +65 -22
- package/src/tests/helpers.js +9 -0
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.7.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
|
|
5
|
+
Generated: Tue, 31 Oct 2023 08:25:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -461,17 +461,22 @@ var validateMaxDate = (value, minDate) => {
|
|
|
461
461
|
};
|
|
462
462
|
var yupSchemas = {
|
|
463
463
|
text: validateOnlyStrings,
|
|
464
|
-
radioOrSelect: (options
|
|
465
|
-
if (
|
|
466
|
-
return
|
|
464
|
+
radioOrSelect: (options, isString) => {
|
|
465
|
+
if (isString) {
|
|
466
|
+
return (0, import_yup.string)().nullable();
|
|
467
467
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
468
|
+
return (0, import_yup.string)().nullable().transform((value) => {
|
|
469
|
+
if (value === "") {
|
|
470
|
+
return void 0;
|
|
471
|
+
}
|
|
472
|
+
if (options?.includes(null)) {
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
return value === null ? void 0 : value;
|
|
476
|
+
}).oneOf(options, ({ value }) => {
|
|
477
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
478
|
+
});
|
|
479
|
+
},
|
|
475
480
|
date: ({ minDate, maxDate }) => {
|
|
476
481
|
let dateString = (0, import_yup.string)().nullable().transform((value) => {
|
|
477
482
|
if (value === "") {
|
|
@@ -539,8 +544,9 @@ var getOptions = (field) => {
|
|
|
539
544
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
540
545
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
541
546
|
if (field.options?.length > 0) {
|
|
547
|
+
const isString = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
542
548
|
const optionValues = getOptions(field);
|
|
543
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
549
|
+
return yupSchemas.radioOrSelect(optionValues, isString);
|
|
544
550
|
}
|
|
545
551
|
if (field.format === "date") {
|
|
546
552
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
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.7.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
|
|
5
|
+
Generated: Tue, 31 Oct 2023 08:25:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -425,17 +425,22 @@ var validateMaxDate = (value, minDate) => {
|
|
|
425
425
|
};
|
|
426
426
|
var yupSchemas = {
|
|
427
427
|
text: validateOnlyStrings,
|
|
428
|
-
radioOrSelect: (options
|
|
429
|
-
if (
|
|
430
|
-
return
|
|
428
|
+
radioOrSelect: (options, isString) => {
|
|
429
|
+
if (isString) {
|
|
430
|
+
return string().nullable();
|
|
431
431
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
432
|
+
return string().nullable().transform((value) => {
|
|
433
|
+
if (value === "") {
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
if (options?.includes(null)) {
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
return value === null ? void 0 : value;
|
|
440
|
+
}).oneOf(options, ({ value }) => {
|
|
441
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
442
|
+
});
|
|
443
|
+
},
|
|
439
444
|
date: ({ minDate, maxDate }) => {
|
|
440
445
|
let dateString = string().nullable().transform((value) => {
|
|
441
446
|
if (value === "") {
|
|
@@ -503,8 +508,9 @@ var getOptions = (field) => {
|
|
|
503
508
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
504
509
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
505
510
|
if (field.options?.length > 0) {
|
|
511
|
+
const isString = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
506
512
|
const optionValues = getOptions(field);
|
|
507
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
513
|
+
return yupSchemas.radioOrSelect(optionValues, isString);
|
|
508
514
|
}
|
|
509
515
|
if (field.format === "date") {
|
|
510
516
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
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.7.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
|
|
5
|
+
Generated: Tue, 31 Oct 2023 08:25:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11779,17 +11779,22 @@ var validateMaxDate = (value, minDate) => {
|
|
|
11779
11779
|
};
|
|
11780
11780
|
var yupSchemas = {
|
|
11781
11781
|
text: validateOnlyStrings,
|
|
11782
|
-
radioOrSelect: (options
|
|
11783
|
-
if (
|
|
11784
|
-
return
|
|
11782
|
+
radioOrSelect: (options, isString2) => {
|
|
11783
|
+
if (isString2) {
|
|
11784
|
+
return StringSchema().nullable();
|
|
11785
11785
|
}
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11786
|
+
return StringSchema().nullable().transform((value) => {
|
|
11787
|
+
if (value === "") {
|
|
11788
|
+
return void 0;
|
|
11789
|
+
}
|
|
11790
|
+
if (options?.includes(null)) {
|
|
11791
|
+
return value;
|
|
11792
|
+
}
|
|
11793
|
+
return value === null ? void 0 : value;
|
|
11794
|
+
}).oneOf(options, ({ value }) => {
|
|
11795
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
11796
|
+
});
|
|
11797
|
+
},
|
|
11793
11798
|
date: ({ minDate, maxDate }) => {
|
|
11794
11799
|
let dateString = StringSchema().nullable().transform((value) => {
|
|
11795
11800
|
if (value === "") {
|
|
@@ -11857,8 +11862,9 @@ var getOptions = (field) => {
|
|
|
11857
11862
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11858
11863
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
11859
11864
|
if (field.options?.length > 0) {
|
|
11865
|
+
const isString2 = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
11860
11866
|
const optionValues = getOptions(field);
|
|
11861
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
11867
|
+
return yupSchemas.radioOrSelect(optionValues, isString2);
|
|
11862
11868
|
}
|
|
11863
11869
|
if (field.format === "date") {
|
|
11864
11870
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.7.1-dev.
|
|
3
|
+
"version": "0.7.1-dev.20231031082524",
|
|
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",
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
schemaInputTypeRadioOptionsWithDetails,
|
|
16
16
|
schemaInputTypeSelectSoloDeprecated,
|
|
17
17
|
schemaInputTypeSelectSolo,
|
|
18
|
+
schemaInputTypeSelectString,
|
|
18
19
|
schemaInputTypeSelectMultipleDeprecated,
|
|
19
20
|
schemaInputTypeSelectMultiple,
|
|
20
21
|
schemaInputTypeSelectMultipleOptional,
|
|
@@ -430,7 +431,7 @@ describe('createHeadlessForm', () => {
|
|
|
430
431
|
});
|
|
431
432
|
|
|
432
433
|
describe('field support', () => {
|
|
433
|
-
function assertOptionsAllowed({ handleValidation, fieldName, validOptions }) {
|
|
434
|
+
function assertOptionsAllowed({ handleValidation, fieldName, validOptions, isString = false }) {
|
|
434
435
|
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
435
436
|
|
|
436
437
|
// All allowed options are valid
|
|
@@ -438,27 +439,34 @@ describe('createHeadlessForm', () => {
|
|
|
438
439
|
expect(validateForm({ [fieldName]: value })).toBeUndefined();
|
|
439
440
|
});
|
|
440
441
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
[fieldName]: '
|
|
444
|
-
|
|
442
|
+
if (!isString) {
|
|
443
|
+
// Any other arbitrary value is not valid.
|
|
444
|
+
expect(validateForm({ [fieldName]: 'blah-blah' })).toEqual({
|
|
445
|
+
[fieldName]: 'The option "blah-blah" is not valid.',
|
|
446
|
+
});
|
|
445
447
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
// Given undefined, it says it's a required field.
|
|
449
|
+
expect(validateForm({})).toEqual({
|
|
450
|
+
[fieldName]: 'Required field',
|
|
451
|
+
});
|
|
450
452
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
453
|
+
// As required field, empty string ("") is also considered empty. @BUG RMT-518
|
|
454
|
+
// Expectation: The error to be "The option '' is not valid."
|
|
455
|
+
expect(validateForm({ [fieldName]: '' })).toEqual({
|
|
456
|
+
[fieldName]: 'Required field',
|
|
457
|
+
});
|
|
456
458
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
459
|
+
// As required field, null is also considered empty @BUG RMT-518
|
|
460
|
+
// Expectation: The error to be "The option null is not valid."
|
|
461
|
+
expect(validateForm({ [fieldName]: null })).toEqual({
|
|
462
|
+
[fieldName]: 'Required field',
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (isString) {
|
|
467
|
+
// Any other arbitrary value is valid.
|
|
468
|
+
expect(validateForm({ [fieldName]: 'blah-blah' })).toBeUndefined();
|
|
469
|
+
}
|
|
462
470
|
}
|
|
463
471
|
|
|
464
472
|
it('support "text" field type', () => {
|
|
@@ -630,6 +638,41 @@ describe('createHeadlessForm', () => {
|
|
|
630
638
|
});
|
|
631
639
|
});
|
|
632
640
|
|
|
641
|
+
it('supports "select" field type with string option', () => {
|
|
642
|
+
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeSelectString);
|
|
643
|
+
const fieldSelect = fields[0];
|
|
644
|
+
expect(fieldSelect).toMatchObject({
|
|
645
|
+
name: 'browsers',
|
|
646
|
+
label: 'Browsers (solo)',
|
|
647
|
+
description: 'This solo select also includes a disabled option.',
|
|
648
|
+
options: [
|
|
649
|
+
{
|
|
650
|
+
value: 'chr',
|
|
651
|
+
label: 'Chrome',
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
value: 'ff',
|
|
655
|
+
label: 'Firefox',
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
value: 'ie',
|
|
659
|
+
label: 'Internet Explorer',
|
|
660
|
+
disabled: true,
|
|
661
|
+
},
|
|
662
|
+
{ value: undefined, type: 'string', label: '{Create another}' },
|
|
663
|
+
],
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
expect(fieldSelect).not.toHaveProperty('multiple');
|
|
667
|
+
|
|
668
|
+
assertOptionsAllowed({
|
|
669
|
+
handleValidation,
|
|
670
|
+
fieldName: 'browsers',
|
|
671
|
+
validOptions: ['chr', 'ff', 'ie'],
|
|
672
|
+
isString: true,
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
|
|
633
676
|
it('supports "select" field type with multiple options @deprecated', () => {
|
|
634
677
|
const result = createHeadlessForm(schemaInputTypeSelectMultipleDeprecated);
|
|
635
678
|
expect(result).toMatchObject({
|
|
@@ -1947,9 +1990,9 @@ describe('createHeadlessForm', () => {
|
|
|
1947
1990
|
},
|
|
1948
1991
|
},
|
|
1949
1992
|
{
|
|
1950
|
-
name: '
|
|
1951
|
-
label: '
|
|
1952
|
-
type: '
|
|
1993
|
+
name: 'role',
|
|
1994
|
+
label: 'Role',
|
|
1995
|
+
type: 'text',
|
|
1953
1996
|
statement: {
|
|
1954
1997
|
description: 'This is another statement message, but more severe.',
|
|
1955
1998
|
inputType: 'statement',
|
package/src/tests/helpers.js
CHANGED
|
@@ -238,6 +238,11 @@ export const mockSelectInputSolo = {
|
|
|
238
238
|
},
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
export const mockSelectInputSoloCreatable = {
|
|
242
|
+
...mockSelectInputSolo,
|
|
243
|
+
oneOf: [...mockSelectInputSolo.oneOf, { type: 'string', title: '{Create another}' }],
|
|
244
|
+
};
|
|
245
|
+
|
|
241
246
|
export const mockSelectInputMultiple = {
|
|
242
247
|
title: 'Browsers (multiple)',
|
|
243
248
|
description: 'This multi-select also includes a disabled option.',
|
|
@@ -897,6 +902,10 @@ export const schemaInputTypeSelectSolo = JSONSchemaBuilder()
|
|
|
897
902
|
.setRequiredFields(['browsers'])
|
|
898
903
|
.build();
|
|
899
904
|
|
|
905
|
+
export const schemaInputTypeSelectString = JSONSchemaBuilder().addInput({
|
|
906
|
+
browsers: mockSelectInputSoloCreatable,
|
|
907
|
+
});
|
|
908
|
+
|
|
900
909
|
/** @deprecated */
|
|
901
910
|
export const schemaInputTypeSelectMultipleDeprecated = JSONSchemaBuilder()
|
|
902
911
|
.addInput({
|