@remoteoss/json-schema-form 0.9.1-dev.20240320153711 → 0.9.1-dev.20240321210726

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 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.9.1-dev.20240320153711
5
- Generated: Wed, 20 Mar 2024 15:37:34 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240321210726
5
+ Generated: Thu, 21 Mar 2024 21:07:37 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -509,12 +509,21 @@ var yupSchemas = {
509
509
  }
510
510
  return dateString;
511
511
  },
512
- radioOrSelectNumber: (options) => (0, import_yup.number)().strict().typeError("The value must be a number").test(
512
+ radioOrSelectNumber: (options) => (0, import_yup.mixed)().typeError("The value must be a number").transform((value) => {
513
+ if (options?.some((option) => option.value === null)) {
514
+ return value;
515
+ }
516
+ return value === null ? void 0 : value;
517
+ }).test(
513
518
  "matchesOptionOrPattern",
514
519
  ({ value }) => {
515
520
  return `The option ${JSON.stringify(value)} is not valid.`;
516
521
  },
517
- (value) => validateRadioOrSelectOptions(value, options)
522
+ (value) => {
523
+ if (value !== void 0 && typeof value !== "number")
524
+ return false;
525
+ return validateRadioOrSelectOptions(value, options);
526
+ }
518
527
  ).nullable(),
519
528
  number: (0, import_yup.number)().typeError("The value must be a number").nullable(),
520
529
  file: (0, import_yup.array)().nullable(),
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.9.1-dev.20240320153711
5
- Generated: Wed, 20 Mar 2024 15:37:34 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240321210726
5
+ Generated: Thu, 21 Mar 2024 21:07:37 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -386,7 +386,7 @@ import jsonLogic from "json-logic-js";
386
386
  import flow from "lodash/flow";
387
387
  import noop from "lodash/noop";
388
388
  import { randexp } from "randexp";
389
- import { string, number, boolean, object, array } from "yup";
389
+ import { string, number, boolean, object, array, mixed } from "yup";
390
390
  var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
391
391
  var baseString = string().trim();
392
392
  var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
@@ -473,12 +473,21 @@ var yupSchemas = {
473
473
  }
474
474
  return dateString;
475
475
  },
476
- radioOrSelectNumber: (options) => number().strict().typeError("The value must be a number").test(
476
+ radioOrSelectNumber: (options) => mixed().typeError("The value must be a number").transform((value) => {
477
+ if (options?.some((option) => option.value === null)) {
478
+ return value;
479
+ }
480
+ return value === null ? void 0 : value;
481
+ }).test(
477
482
  "matchesOptionOrPattern",
478
483
  ({ value }) => {
479
484
  return `The option ${JSON.stringify(value)} is not valid.`;
480
485
  },
481
- (value) => validateRadioOrSelectOptions(value, options)
486
+ (value) => {
487
+ if (value !== void 0 && typeof value !== "number")
488
+ return false;
489
+ return validateRadioOrSelectOptions(value, options);
490
+ }
482
491
  ).nullable(),
483
492
  number: number().typeError("The value must be a number").nullable(),
484
493
  file: array().nullable(),
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240320153711
5
- Generated: Wed, 20 Mar 2024 15:37:34 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240321210726
5
+ Generated: Thu, 21 Mar 2024 21:07:37 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11827,12 +11827,21 @@ var yupSchemas = {
11827
11827
  }
11828
11828
  return dateString;
11829
11829
  },
11830
- radioOrSelectNumber: (options) => NumberSchema().strict().typeError("The value must be a number").test(
11830
+ radioOrSelectNumber: (options) => SchemaType().typeError("The value must be a number").transform((value) => {
11831
+ if (options?.some((option) => option.value === null)) {
11832
+ return value;
11833
+ }
11834
+ return value === null ? void 0 : value;
11835
+ }).test(
11831
11836
  "matchesOptionOrPattern",
11832
11837
  ({ value }) => {
11833
11838
  return `The option ${JSON.stringify(value)} is not valid.`;
11834
11839
  },
11835
- (value) => validateRadioOrSelectOptions(value, options)
11840
+ (value) => {
11841
+ if (value !== void 0 && typeof value !== "number")
11842
+ return false;
11843
+ return validateRadioOrSelectOptions(value, options);
11844
+ }
11836
11845
  ).nullable(),
11837
11846
  number: NumberSchema().typeError("The value must be a number").nullable(),
11838
11847
  file: array_default().nullable(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.9.1-dev.20240320153711",
3
+ "version": "0.9.1-dev.20240321210726",
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",
@@ -210,7 +210,7 @@ describe('OneOf const', () => {
210
210
  });
211
211
  expect(handleValidation({ number: 2 }).formErrors).toBeUndefined();
212
212
  expect(handleValidation({ number: '2' }).formErrors).toEqual({
213
- number: 'The value must be a number',
213
+ number: 'The option "2" is not valid.',
214
214
  });
215
215
  });
216
216
 
@@ -229,7 +229,8 @@ describe('OneOf const', () => {
229
229
  });
230
230
  expect(handleValidation({ number: 2 }).formErrors).toBeUndefined();
231
231
  expect(handleValidation({ number: '2' }).formErrors).toEqual({
232
- number: 'The value must be a number',
232
+ number: 'The option "2" is not valid.',
233
233
  });
234
+ expect(handleValidation({ number: null }).formErrors).toEqual(undefined);
234
235
  });
235
236
  });
@@ -2028,6 +2028,45 @@ describe('createHeadlessForm', () => {
2028
2028
  });
2029
2029
  });
2030
2030
 
2031
+ it('supports oneOf number const', () => {
2032
+ const result = createHeadlessForm({
2033
+ type: 'object',
2034
+ additionalProperties: false,
2035
+ properties: {
2036
+ pets: {
2037
+ title: 'How many pets?',
2038
+ oneOf: [
2039
+ {
2040
+ title: 'One',
2041
+ const: 0,
2042
+ },
2043
+ {
2044
+ title: 'Two',
2045
+ const: 2,
2046
+ },
2047
+ {
2048
+ title: 'null',
2049
+ const: 1,
2050
+ },
2051
+ ],
2052
+ 'x-jsf-presentation': {
2053
+ inputType: 'select',
2054
+ },
2055
+ type: ['number', 'null'],
2056
+ },
2057
+ },
2058
+ required: [],
2059
+ 'x-jsf-order': ['pets'],
2060
+ });
2061
+
2062
+ const fieldValidator = result.fields[0].schema;
2063
+
2064
+ expect(fieldValidator.isValidSync(0)).toBe(true);
2065
+ expect(fieldValidator.isValidSync(1)).toBe(true);
2066
+ expect(() => fieldValidator.validateSync('2')).toThrowError('The option "2" is not valid.');
2067
+ expect(fieldValidator.isValidSync(null)).toBe(true);
2068
+ });
2069
+
2031
2070
  describe('x-jsf-presentation attribute', () => {
2032
2071
  it('support field with "x-jsf-presentation.statement"', () => {
2033
2072
  const result = createHeadlessForm(schemaInputWithStatement);