@remoteoss/json-schema-form 0.4.1-dev.20230703195833 → 0.4.1-dev.20230703203242

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) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703195833
5
- Generated: Mon, 03 Jul 2023 19:58:43 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703203242
5
+ Generated: Mon, 03 Jul 2023 20:32:50 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().oneOf(options, ({ value }) => {
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 getOptionsAllowed = (field) => {
424
- const onlyValues = field.options?.map((option) => option.value);
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
- if (isOptionalWithNull) {
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 optionsAllowed = getOptionsAllowed(field);
454
- return yupSchemas.radioOrSelect(optionsAllowed);
442
+ const optionValues = getOptions(field);
443
+ return yupSchemas.radioOrSelect(optionValues);
455
444
  }
456
445
  return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
457
446
  };
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.4.1-dev.20230703195833
5
- Generated: Mon, 03 Jul 2023 19:58:43 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703203242
5
+ Generated: Mon, 03 Jul 2023 20:32:50 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().oneOf(options, ({ value }) => {
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 getOptionsAllowed = (field) => {
388
- const onlyValues = field.options?.map((option) => option.value);
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
- if (isOptionalWithNull) {
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 optionsAllowed = getOptionsAllowed(field);
418
- return yupSchemas.radioOrSelect(optionsAllowed);
406
+ const optionValues = getOptions(field);
407
+ return yupSchemas.radioOrSelect(optionValues);
419
408
  }
420
409
  return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
421
410
  };
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703195833
5
- Generated: Mon, 03 Jul 2023 19:58:43 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703203242
5
+ Generated: Mon, 03 Jul 2023 20:32:50 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().oneOf(options, ({ value }) => {
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 getOptionsAllowed = (field) => {
11364
- const onlyValues = field.options?.map((option) => option.value);
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
- if (isOptionalWithNull) {
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 optionsAllowed = getOptionsAllowed(field);
11394
- return yupSchemas.radioOrSelect(optionsAllowed);
11382
+ const optionValues = getOptions(field);
11383
+ return yupSchemas.radioOrSelect(optionValues);
11395
11384
  }
11396
11385
  return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
11397
11386
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.4.1-dev.20230703195833",
3
+ "version": "0.4.1-dev.20230703203242",
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",