@remoteoss/json-schema-form 0.11.4-beta.0 → 0.11.5-dev.20240821091937

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.11.4-beta.0
5
- Generated: Tue, 20 Aug 2024 17:17:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821091937
5
+ Generated: Wed, 21 Aug 2024 09:19:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -553,7 +553,12 @@ var yupSchemas = {
553
553
  multiple: {
554
554
  select: (0, import_yup.array)().nullable(),
555
555
  "group-array": (0, import_yup.array)().nullable()
556
- }
556
+ },
557
+ null: (0, import_yup.mixed)().typeError("The value must be null").test(
558
+ "matchesNullValue",
559
+ ({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
560
+ (value) => value === void 0 || value === null
561
+ )
557
562
  };
558
563
  var yupSchemasToJsonTypes = {
559
564
  string: yupSchemas.text,
@@ -562,7 +567,7 @@ var yupSchemasToJsonTypes = {
562
567
  object: yupSchemas.fieldset,
563
568
  array: yupSchemas.multiple.select,
564
569
  boolean: yupSchemas.checkboxBool,
565
- null: import_noop.default
570
+ null: yupSchemas.null
566
571
  };
567
572
  function getRequiredErrorMessage(inputType, { inlineError, configError }) {
568
573
  if (inlineError)
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.4-beta.0
5
- Generated: Tue, 20 Aug 2024 17:17:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821091937
5
+ Generated: Wed, 21 Aug 2024 09:19:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -516,7 +516,12 @@ var yupSchemas = {
516
516
  multiple: {
517
517
  select: array().nullable(),
518
518
  "group-array": array().nullable()
519
- }
519
+ },
520
+ null: mixed().typeError("The value must be null").test(
521
+ "matchesNullValue",
522
+ ({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
523
+ (value) => value === void 0 || value === null
524
+ )
520
525
  };
521
526
  var yupSchemasToJsonTypes = {
522
527
  string: yupSchemas.text,
@@ -525,7 +530,7 @@ var yupSchemasToJsonTypes = {
525
530
  object: yupSchemas.fieldset,
526
531
  array: yupSchemas.multiple.select,
527
532
  boolean: yupSchemas.checkboxBool,
528
- null: noop
533
+ null: yupSchemas.null
529
534
  };
530
535
  function getRequiredErrorMessage(inputType, { inlineError, configError }) {
531
536
  if (inlineError)
@@ -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.4-beta.0
5
- Generated: Tue, 20 Aug 2024 17:17:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821091937
5
+ Generated: Wed, 21 Aug 2024 09:19:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -12032,7 +12032,12 @@ var yupSchemas = {
12032
12032
  multiple: {
12033
12033
  select: array_default().nullable(),
12034
12034
  "group-array": array_default().nullable()
12035
- }
12035
+ },
12036
+ null: SchemaType().typeError("The value must be null").test(
12037
+ "matchesNullValue",
12038
+ ({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
12039
+ (value) => value === void 0 || value === null
12040
+ )
12036
12041
  };
12037
12042
  var yupSchemasToJsonTypes = {
12038
12043
  string: yupSchemas.text,
@@ -12041,7 +12046,7 @@ var yupSchemasToJsonTypes = {
12041
12046
  object: yupSchemas.fieldset,
12042
12047
  array: yupSchemas.multiple.select,
12043
12048
  boolean: yupSchemas.checkboxBool,
12044
- null: import_noop.default
12049
+ null: yupSchemas.null
12045
12050
  };
12046
12051
  function getRequiredErrorMessage(inputType, { inlineError, configError }) {
12047
12052
  if (inlineError)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.4-beta.0",
3
+ "version": "0.11.5-dev.20240821091937",
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",
@@ -29,6 +29,7 @@ import {
29
29
  schemaInputWithStatement,
30
30
  schemaInputTypeCheckbox,
31
31
  schemaInputTypeCheckboxBooleans,
32
+ schemaInputTypeNull,
32
33
  schemaWithOrderKeyword,
33
34
  schemaWithPositionDeprecated,
34
35
  schemaDynamicValidationConst,
@@ -1578,6 +1579,48 @@ describe('createHeadlessForm', () => {
1578
1579
  });
1579
1580
  });
1580
1581
 
1582
+ it('supports "null" field type', () => {
1583
+ const { handleValidation, fields } = createHeadlessForm(schemaInputTypeNull, {
1584
+ strictInputType: false,
1585
+ });
1586
+
1587
+ expect(fields).toMatchObject([
1588
+ {
1589
+ name: 'name',
1590
+ label: '(Optional) Name',
1591
+ type: undefined,
1592
+ jsonType: 'null',
1593
+ schema: expect.any(Object),
1594
+ },
1595
+ {
1596
+ name: 'username',
1597
+ label: 'Username',
1598
+ type: 'text',
1599
+ jsonType: 'string',
1600
+ inputType: 'text',
1601
+ maxLength: 4,
1602
+ schema: expect.any(Object),
1603
+ },
1604
+ ]);
1605
+
1606
+ // jsonType `null` fields do not have a corresponding inputType
1607
+ expect(fields[0].inputType).toBeUndefined();
1608
+
1609
+ const validateForm = (vals) => friendlyError(handleValidation(vals));
1610
+
1611
+ expect(validateForm({})).toEqual({
1612
+ username: 'Required field',
1613
+ });
1614
+
1615
+ expect(validateForm({ username: 'hello', name: 'John' })).toEqual({
1616
+ username: 'Please insert up to 4 characters',
1617
+ name: 'The value "John" is not valid.',
1618
+ });
1619
+
1620
+ expect(validateForm({ username: 'john' })).toBeUndefined();
1621
+ expect(validateForm({ username: 'john', name: null })).toBeUndefined();
1622
+ });
1623
+
1581
1624
  it('supports oneOf pattern validation', () => {
1582
1625
  const result = createHeadlessForm(mockTelWithPattern);
1583
1626
 
@@ -1141,6 +1141,23 @@ export const schemaInputTypeCheckboxBooleans = JSONSchemaBuilder()
1141
1141
  .setRequiredFields(['boolean_required'])
1142
1142
  .build();
1143
1143
 
1144
+ export const schemaInputTypeNull = {
1145
+ additionalProperties: false,
1146
+ type: 'object',
1147
+ properties: {
1148
+ name: {
1149
+ type: 'null',
1150
+ title: '(Optional) Name',
1151
+ },
1152
+ username: {
1153
+ type: 'string',
1154
+ title: 'Username',
1155
+ maxLength: 4,
1156
+ },
1157
+ },
1158
+ required: ['username'],
1159
+ };
1160
+
1144
1161
  export const schemaCustomErrorMessageByField = {
1145
1162
  properties: {
1146
1163
  tabs: {