@remoteoss/json-schema-form 0.4.1-dev.20230703195833 → 0.5.0-dev.20230705093926
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 +7 -0
- package/dist/index.cjs +18 -31
- package/dist/index.js +18 -31
- package/dist/standalone.js +18 -31
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +6 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
#### 0.4.1-beta.0 (2023-07-03)
|
|
2
|
+
|
|
3
|
+
##### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **fieldset:** support root conditionals for fieldsets ([#23](https://github.com/remoteoss/json-schema-form/pull/23)) ([65d87b3a](https://github.com/remoteoss/json-schema-form/commit/65d87b3a93018f0729aed565000eb2a2ce1f2ce7))
|
|
6
|
+
* **select/radio:** Accept just the values in options (plus `''` and `null` for backward-compatibility) ([#18](https://github.com/remoteoss/json-schema-form/pull/18)) ([37501d2d](https://github.com/remoteoss/json-schema-form/commit/37501d2ddafdd5e207b34d2ca3f6b7b7a1006e9d))
|
|
7
|
+
|
|
1
8
|
#### 0.4.0-beta.0 (2023-06-22)
|
|
2
9
|
|
|
3
10
|
##### New Features
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230705093926
|
|
5
|
+
Generated: Wed, 05 Jul 2023 09:39:42 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -383,7 +383,15 @@ var validateOnlyStrings = (0, import_yup.string)().trim().nullable().test(
|
|
|
383
383
|
);
|
|
384
384
|
var yupSchemas = {
|
|
385
385
|
text: validateOnlyStrings,
|
|
386
|
-
radioOrSelect: (options) => (0, import_yup.string)().nullable().
|
|
386
|
+
radioOrSelect: (options) => (0, import_yup.string)().nullable().transform((value) => {
|
|
387
|
+
if (value === "") {
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
if (options?.includes(null)) {
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
return value === null ? void 0 : value;
|
|
394
|
+
}).oneOf(options, ({ value }) => {
|
|
387
395
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
388
396
|
}),
|
|
389
397
|
date: (0, import_yup.string)().nullable().trim().matches(
|
|
@@ -420,38 +428,19 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
420
428
|
return "Required field";
|
|
421
429
|
}
|
|
422
430
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
423
|
-
var
|
|
424
|
-
const
|
|
425
|
-
const optionsBroken = [
|
|
426
|
-
...onlyValues,
|
|
427
|
-
""
|
|
428
|
-
// [1]
|
|
429
|
-
];
|
|
430
|
-
if (field.required) {
|
|
431
|
-
return [
|
|
432
|
-
...optionsBroken,
|
|
433
|
-
null
|
|
434
|
-
// [2]
|
|
435
|
-
];
|
|
436
|
-
}
|
|
431
|
+
var getOptions = (field) => {
|
|
432
|
+
const allValues = field.options?.map((option) => option.value);
|
|
437
433
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
438
434
|
// option but we don't have direct access at this point.
|
|
439
435
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
440
436
|
field.jsonType.includes("null");
|
|
441
|
-
|
|
442
|
-
return [...optionsBroken, null];
|
|
443
|
-
}
|
|
444
|
-
return [
|
|
445
|
-
...optionsBroken,
|
|
446
|
-
null
|
|
447
|
-
// [3]
|
|
448
|
-
];
|
|
437
|
+
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
449
438
|
};
|
|
450
439
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
451
440
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
452
441
|
if (field.options?.length > 0) {
|
|
453
|
-
const
|
|
454
|
-
return yupSchemas.radioOrSelect(
|
|
442
|
+
const optionValues = getOptions(field);
|
|
443
|
+
return yupSchemas.radioOrSelect(optionValues);
|
|
455
444
|
}
|
|
456
445
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
457
446
|
};
|
|
@@ -925,10 +914,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
925
914
|
},
|
|
926
915
|
// Handle [name].presentation
|
|
927
916
|
...presentation,
|
|
928
|
-
description
|
|
929
|
-
|
|
930
|
-
}) : description,
|
|
931
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
917
|
+
description,
|
|
918
|
+
extra: presentation.extra,
|
|
932
919
|
statement: presentation.statement && {
|
|
933
920
|
...presentation.statement,
|
|
934
921
|
description: statementDescription
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230705093926
|
|
5
|
+
Generated: Wed, 05 Jul 2023 09:39:42 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -347,7 +347,15 @@ var validateOnlyStrings = string().trim().nullable().test(
|
|
|
347
347
|
);
|
|
348
348
|
var yupSchemas = {
|
|
349
349
|
text: validateOnlyStrings,
|
|
350
|
-
radioOrSelect: (options) => string().nullable().
|
|
350
|
+
radioOrSelect: (options) => string().nullable().transform((value) => {
|
|
351
|
+
if (value === "") {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
if (options?.includes(null)) {
|
|
355
|
+
return value;
|
|
356
|
+
}
|
|
357
|
+
return value === null ? void 0 : value;
|
|
358
|
+
}).oneOf(options, ({ value }) => {
|
|
351
359
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
352
360
|
}),
|
|
353
361
|
date: string().nullable().trim().matches(
|
|
@@ -384,38 +392,19 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
384
392
|
return "Required field";
|
|
385
393
|
}
|
|
386
394
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
387
|
-
var
|
|
388
|
-
const
|
|
389
|
-
const optionsBroken = [
|
|
390
|
-
...onlyValues,
|
|
391
|
-
""
|
|
392
|
-
// [1]
|
|
393
|
-
];
|
|
394
|
-
if (field.required) {
|
|
395
|
-
return [
|
|
396
|
-
...optionsBroken,
|
|
397
|
-
null
|
|
398
|
-
// [2]
|
|
399
|
-
];
|
|
400
|
-
}
|
|
395
|
+
var getOptions = (field) => {
|
|
396
|
+
const allValues = field.options?.map((option) => option.value);
|
|
401
397
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
402
398
|
// option but we don't have direct access at this point.
|
|
403
399
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
404
400
|
field.jsonType.includes("null");
|
|
405
|
-
|
|
406
|
-
return [...optionsBroken, null];
|
|
407
|
-
}
|
|
408
|
-
return [
|
|
409
|
-
...optionsBroken,
|
|
410
|
-
null
|
|
411
|
-
// [3]
|
|
412
|
-
];
|
|
401
|
+
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
413
402
|
};
|
|
414
403
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
415
404
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
416
405
|
if (field.options?.length > 0) {
|
|
417
|
-
const
|
|
418
|
-
return yupSchemas.radioOrSelect(
|
|
406
|
+
const optionValues = getOptions(field);
|
|
407
|
+
return yupSchemas.radioOrSelect(optionValues);
|
|
419
408
|
}
|
|
420
409
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
421
410
|
};
|
|
@@ -889,10 +878,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
889
878
|
},
|
|
890
879
|
// Handle [name].presentation
|
|
891
880
|
...presentation,
|
|
892
|
-
description
|
|
893
|
-
|
|
894
|
-
}) : description,
|
|
895
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
881
|
+
description,
|
|
882
|
+
extra: presentation.extra,
|
|
896
883
|
statement: presentation.statement && {
|
|
897
884
|
...presentation.statement,
|
|
898
885
|
description: statementDescription
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230705093926
|
|
5
|
+
Generated: Wed, 05 Jul 2023 09:39:42 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11323,7 +11323,15 @@ var validateOnlyStrings = StringSchema().trim().nullable().test(
|
|
|
11323
11323
|
);
|
|
11324
11324
|
var yupSchemas = {
|
|
11325
11325
|
text: validateOnlyStrings,
|
|
11326
|
-
radioOrSelect: (options) => StringSchema().nullable().
|
|
11326
|
+
radioOrSelect: (options) => StringSchema().nullable().transform((value) => {
|
|
11327
|
+
if (value === "") {
|
|
11328
|
+
return void 0;
|
|
11329
|
+
}
|
|
11330
|
+
if (options?.includes(null)) {
|
|
11331
|
+
return value;
|
|
11332
|
+
}
|
|
11333
|
+
return value === null ? void 0 : value;
|
|
11334
|
+
}).oneOf(options, ({ value }) => {
|
|
11327
11335
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
11328
11336
|
}),
|
|
11329
11337
|
date: StringSchema().nullable().trim().matches(
|
|
@@ -11360,38 +11368,19 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
11360
11368
|
return "Required field";
|
|
11361
11369
|
}
|
|
11362
11370
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
11363
|
-
var
|
|
11364
|
-
const
|
|
11365
|
-
const optionsBroken = [
|
|
11366
|
-
...onlyValues,
|
|
11367
|
-
""
|
|
11368
|
-
// [1]
|
|
11369
|
-
];
|
|
11370
|
-
if (field.required) {
|
|
11371
|
-
return [
|
|
11372
|
-
...optionsBroken,
|
|
11373
|
-
null
|
|
11374
|
-
// [2]
|
|
11375
|
-
];
|
|
11376
|
-
}
|
|
11371
|
+
var getOptions = (field) => {
|
|
11372
|
+
const allValues = field.options?.map((option) => option.value);
|
|
11377
11373
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
11378
11374
|
// option but we don't have direct access at this point.
|
|
11379
11375
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
11380
11376
|
field.jsonType.includes("null");
|
|
11381
|
-
|
|
11382
|
-
return [...optionsBroken, null];
|
|
11383
|
-
}
|
|
11384
|
-
return [
|
|
11385
|
-
...optionsBroken,
|
|
11386
|
-
null
|
|
11387
|
-
// [3]
|
|
11388
|
-
];
|
|
11377
|
+
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
11389
11378
|
};
|
|
11390
11379
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11391
11380
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
11392
11381
|
if (field.options?.length > 0) {
|
|
11393
|
-
const
|
|
11394
|
-
return yupSchemas.radioOrSelect(
|
|
11382
|
+
const optionValues = getOptions(field);
|
|
11383
|
+
return yupSchemas.radioOrSelect(optionValues);
|
|
11395
11384
|
}
|
|
11396
11385
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
11397
11386
|
};
|
|
@@ -11865,10 +11854,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11865
11854
|
},
|
|
11866
11855
|
// Handle [name].presentation
|
|
11867
11856
|
...presentation,
|
|
11868
|
-
description
|
|
11869
|
-
|
|
11870
|
-
}) : description,
|
|
11871
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
11857
|
+
description,
|
|
11858
|
+
extra: presentation.extra,
|
|
11872
11859
|
statement: presentation.statement && {
|
|
11873
11860
|
...presentation.statement,
|
|
11874
11861
|
description: statementDescription
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-dev.20230705093926",
|
|
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",
|
|
@@ -439,23 +439,15 @@ describe('createHeadlessForm', () => {
|
|
|
439
439
|
|
|
440
440
|
// All allowed options are valid
|
|
441
441
|
validOptions.forEach((value) => {
|
|
442
|
-
expect(
|
|
443
|
-
validateForm({
|
|
444
|
-
[fieldName]: value,
|
|
445
|
-
})
|
|
446
|
-
).toBeUndefined();
|
|
442
|
+
expect(validateForm({ [fieldName]: value })).toBeUndefined();
|
|
447
443
|
});
|
|
448
444
|
|
|
449
445
|
// Any other arbitrary value is not valid.
|
|
450
|
-
expect(
|
|
451
|
-
validateForm({
|
|
452
|
-
[fieldName]: 'blah-blah',
|
|
453
|
-
})
|
|
454
|
-
).toEqual({
|
|
446
|
+
expect(validateForm({ [fieldName]: 'blah-blah' })).toEqual({
|
|
455
447
|
[fieldName]: 'The option "blah-blah" is not valid.',
|
|
456
448
|
});
|
|
457
449
|
|
|
458
|
-
//
|
|
450
|
+
// Given undefined, it says it's a required field.
|
|
459
451
|
expect(validateForm({})).toEqual({
|
|
460
452
|
[fieldName]: 'Required field',
|
|
461
453
|
});
|
|
@@ -831,6 +823,9 @@ describe('createHeadlessForm', () => {
|
|
|
831
823
|
|
|
832
824
|
describe('support "radio" optional field - more examples @BUG RMT-518', () => {
|
|
833
825
|
function assertCommonBehavior(validateForm) {
|
|
826
|
+
// Note: Very similar to assertOptionsAllowed()
|
|
827
|
+
// We could reuse it in a next iteration.
|
|
828
|
+
|
|
834
829
|
// Happy path
|
|
835
830
|
expect(validateForm({ has_car: 'yes' })).toBeUndefined();
|
|
836
831
|
|