@remoteoss/json-schema-form 0.7.0-dev.20230928101050 → 0.7.1-dev.20231025070834

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 CHANGED
@@ -1,3 +1,26 @@
1
+ #### 0.7.0-beta.0 (2023-10-23)
2
+
3
+ ##### Chores
4
+
5
+ BREAKING CHANGES:
6
+
7
+ - **Description/Extra/Statement fields:** We have removed the sorrounding spans that we output in these fields ([#17](https://github.com/remoteoss/json-schema-form/pull/27)) ([6257533](https://github.com/remoteoss/json-schema-form/commit/6257533bead9c0f7391f240c2e5bacc801a90af7))
8
+
9
+ ```diff
10
+ -description: '<span class="jsf-description">Write in <b>hh:ss</b> format</span>',
11
+ +description: 'Write in <b>hh:ss</b> format',
12
+ ```
13
+
14
+ #### 0.6.6-beta.0 (2023-10-17)
15
+
16
+ ##### Chores
17
+
18
+ - **github:** Add template for issues and pull requests ([#45](https://github.com/remoteoss/json-schema-form/pull/45)) ([621e3338](https://github.com/remoteoss/json-schema-form/commit/621e33389638541e771d2229c91655e430ea7ec4))
19
+
20
+ ##### Bug Fixes
21
+
22
+ - allow 0 in const validation ([#48](https://github.com/remoteoss/json-schema-form/pull/48)) ([cde19fc9](https://github.com/remoteoss/json-schema-form/commit/cde19fc960c4eacdde476ddcdd8c650a4ff5ce96))
23
+
1
24
  #### 0.6.5-beta.0 (2023-09-18)
2
25
 
3
26
  ##### Changes
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.0-dev.20230928101050
5
- Generated: Thu, 28 Sep 2023 10:11:18 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231025070834
5
+ Generated: Wed, 25 Oct 2023 07:08:56 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -694,7 +694,7 @@ function buildYupSchema(field, config, logic) {
694
694
  if (propertyFields.accept) {
695
695
  validators.push(withFileFormat);
696
696
  }
697
- if (propertyFields.const) {
697
+ if (typeof propertyFields.const !== "undefined") {
698
698
  validators.push(withConst);
699
699
  }
700
700
  if (propertyFields.jsonLogicValidations) {
@@ -1323,10 +1323,11 @@ function extractParametersFromNode(schemaNode) {
1323
1323
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
1324
1324
  const description = presentation?.description || node.description;
1325
1325
  const statementDescription = presentation.statement?.description;
1326
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
1326
1327
  return (0, import_omitBy.default)(
1327
1328
  {
1328
1329
  const: node.const,
1329
- ...node.const && node.default ? { value: node.const } : {},
1330
+ ...value,
1330
1331
  label: node.title,
1331
1332
  readOnly: node.readOnly,
1332
1333
  ...node.deprecated && {
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.0-dev.20230928101050
5
- Generated: Thu, 28 Sep 2023 10:11:18 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231025070834
5
+ Generated: Wed, 25 Oct 2023 07:08:56 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -658,7 +658,7 @@ function buildYupSchema(field, config, logic) {
658
658
  if (propertyFields.accept) {
659
659
  validators.push(withFileFormat);
660
660
  }
661
- if (propertyFields.const) {
661
+ if (typeof propertyFields.const !== "undefined") {
662
662
  validators.push(withConst);
663
663
  }
664
664
  if (propertyFields.jsonLogicValidations) {
@@ -1287,10 +1287,11 @@ function extractParametersFromNode(schemaNode) {
1287
1287
  const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
1288
1288
  const description = presentation?.description || node.description;
1289
1289
  const statementDescription = presentation.statement?.description;
1290
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
1290
1291
  return omitBy(
1291
1292
  {
1292
1293
  const: node.const,
1293
- ...node.const && node.default ? { value: node.const } : {},
1294
+ ...value,
1294
1295
  label: node.title,
1295
1296
  readOnly: node.readOnly,
1296
1297
  ...node.deprecated && {
@@ -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.0-dev.20230928101050
5
- Generated: Thu, 28 Sep 2023 10:11:18 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231025070834
5
+ Generated: Wed, 25 Oct 2023 07:08:56 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -12012,7 +12012,7 @@ function buildYupSchema(field, config, logic) {
12012
12012
  if (propertyFields.accept) {
12013
12013
  validators.push(withFileFormat);
12014
12014
  }
12015
- if (propertyFields.const) {
12015
+ if (typeof propertyFields.const !== "undefined") {
12016
12016
  validators.push(withConst);
12017
12017
  }
12018
12018
  if (propertyFields.jsonLogicValidations) {
@@ -12641,10 +12641,11 @@ function extractParametersFromNode(schemaNode) {
12641
12641
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
12642
12642
  const description = presentation?.description || node.description;
12643
12643
  const statementDescription = presentation.statement?.description;
12644
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
12644
12645
  return (0, import_omitBy.default)(
12645
12646
  {
12646
12647
  const: node.const,
12647
- ...node.const && node.default ? { value: node.const } : {},
12648
+ ...value,
12648
12649
  label: node.title,
12649
12650
  readOnly: node.readOnly,
12650
12651
  ...node.deprecated && {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.7.0-dev.20230928101050",
3
+ "version": "0.7.1-dev.20231025070834",
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",
@@ -20,6 +20,25 @@ describe('validations: const', () => {
20
20
  expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
21
21
  });
22
22
 
23
+ it('Should work for when the number is 0', () => {
24
+ const { handleValidation } = createHeadlessForm(
25
+ {
26
+ properties: {
27
+ zero_only: { type: 'number', const: 0 },
28
+ },
29
+ },
30
+ { strictInputType: false }
31
+ );
32
+ expect(handleValidation({}).formErrors).toEqual(undefined);
33
+ expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
34
+ zero_only: 'The only accepted value is 0.',
35
+ });
36
+ expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
37
+ // null is also considered valid until we fix @BUG RMT-518
38
+ // Expectation: To fail with error "The only accepted value is 0."
39
+ expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
40
+ });
41
+
23
42
  it('Should work for text', () => {
24
43
  const { handleValidation } = createHeadlessForm(
25
44
  {
@@ -96,3 +115,45 @@ describe('validations: const', () => {
96
115
  expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
97
116
  });
98
117
  });
118
+
119
+ describe('const/default with forced values', () => {
120
+ it('Should work for when the number is 0', () => {
121
+ const { fields, handleValidation } = createHeadlessForm(
122
+ {
123
+ properties: {
124
+ zero_only: { type: 'number', const: 0, default: 0 },
125
+ },
126
+ },
127
+ { strictInputType: false }
128
+ );
129
+ expect(handleValidation({}).formErrors).toEqual(undefined);
130
+ expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
131
+ zero_only: 'The only accepted value is 0.',
132
+ });
133
+ expect(fields[0]).toMatchObject({ value: 0, const: 0, default: 0 });
134
+ expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
135
+ // null is also considered valid until we fix @BUG RMT-518
136
+ // Expectation: To fail with error "The only accepted value is 0."
137
+ expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
138
+ });
139
+
140
+ it('Should work for number', () => {
141
+ const { fields, handleValidation } = createHeadlessForm(
142
+ {
143
+ properties: {
144
+ ten_only: { type: 'number', const: 10, default: 10 },
145
+ },
146
+ },
147
+ { strictInputType: false }
148
+ );
149
+ expect(handleValidation({}).formErrors).toEqual(undefined);
150
+ expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
151
+ ten_only: 'The only accepted value is 10.',
152
+ });
153
+ expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
154
+ expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
155
+ // null is also considered valid until we fix @BUG RMT-518
156
+ // Expectation: To fail with error "The only accepted value is 10."
157
+ expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
158
+ });
159
+ });
@@ -463,6 +463,12 @@ export const mockCheckboxInput = {
463
463
  })
464
464
  .build();
465
465
  */
466
+
467
+ /**
468
+ * @deprecated in favor of normal JSON schema.
469
+ * Why? This adds extra complexity to read and to
470
+ * copy-paste into the Playground, validators, etc
471
+ * */
466
472
  export function JSONSchemaBuilder() {
467
473
  return {
468
474
  addInput: function addInput(input) {
@@ -658,15 +664,15 @@ export const schemaWithoutTypes = {
658
664
  },
659
665
  };
660
666
 
661
- export const schemaInputTypeText = JSONSchemaBuilder()
662
- .addInput({
667
+ export const schemaInputTypeText = {
668
+ properties: {
663
669
  id_number: mockTextInput,
664
- })
665
- .setRequiredFields(['id_number'])
666
- .build();
670
+ },
671
+ required: ['id_number'],
672
+ };
667
673
 
668
- export const schemaInputWithStatement = JSONSchemaBuilder()
669
- .addInput({
674
+ export const schemaInputWithStatement = {
675
+ properties: {
670
676
  bonus: {
671
677
  title: 'Bonus',
672
678
  'x-jsf-presentation': {
@@ -678,71 +684,10 @@ export const schemaInputWithStatement = JSONSchemaBuilder()
678
684
  },
679
685
  },
680
686
  },
681
- })
682
- .addInput({
683
- a_or_b: {
684
- title: 'A dropdown',
685
- description: 'Some options to chose from',
686
- items: {
687
- enum: ['A', 'B'],
688
- },
687
+ role: {
688
+ title: 'Role',
689
689
  'x-jsf-presentation': {
690
- inputType: 'select',
691
- options: [
692
- {
693
- label: 'A',
694
- value: 'A',
695
- },
696
- {
697
- label: 'B',
698
- value: 'B',
699
- },
700
- ],
701
- placeholder: 'Select...',
702
- statement: {
703
- description: 'This is another statement message, but more severe.',
704
- inputType: 'statement',
705
- severity: 'warning',
706
- },
707
- },
708
- },
709
- })
710
- .build();
711
-
712
- export const schemaInputWithStatementDeprecated = JSONSchemaBuilder()
713
- .addInput({
714
- bonus: {
715
- title: 'Bonus',
716
- presentation: {
717
690
  inputType: 'text',
718
- statement: {
719
- description: 'This is a custom statement message.',
720
- inputType: 'statement',
721
- severity: 'info',
722
- },
723
- },
724
- },
725
- })
726
- .addInput({
727
- a_or_b: {
728
- title: 'A dropdown',
729
- description: 'Some options to chose from',
730
- items: {
731
- enum: ['A', 'B'],
732
- },
733
- presentation: {
734
- inputType: 'select',
735
- options: [
736
- {
737
- label: 'A',
738
- value: 'A',
739
- },
740
- {
741
- label: 'B',
742
- value: 'B',
743
- },
744
- ],
745
- placeholder: 'Select...',
746
691
  statement: {
747
692
  description: 'This is another statement message, but more severe.',
748
693
  inputType: 'statement',
@@ -750,11 +695,11 @@ export const schemaInputWithStatementDeprecated = JSONSchemaBuilder()
750
695
  },
751
696
  },
752
697
  },
753
- })
754
- .build();
698
+ },
699
+ };
755
700
 
756
- export const schemaInputWithExtra = JSONSchemaBuilder()
757
- .addInput({
701
+ export const schemaInputWithExtra = {
702
+ properties: {
758
703
  bonus: {
759
704
  title: 'Bonus',
760
705
  'x-jsf-presentation': {
@@ -772,11 +717,11 @@ export const schemaInputWithExtra = JSONSchemaBuilder()
772
717
  `,
773
718
  },
774
719
  },
775
- })
776
- .build();
720
+ },
721
+ };
777
722
 
778
- export const schemaInputWithCustomDescription = JSONSchemaBuilder()
779
- .addInput({
723
+ export const schemaInputWithCustomDescription = {
724
+ properties: {
780
725
  other: {
781
726
  title: 'Other',
782
727
  'x-jsf-presentation': {
@@ -785,8 +730,8 @@ export const schemaInputWithCustomDescription = JSONSchemaBuilder()
785
730
  },
786
731
  type: 'string',
787
732
  },
788
- })
789
- .build();
733
+ },
734
+ };
790
735
 
791
736
  export const schemaInputDeprecated = JSONSchemaBuilder()
792
737
  .addInput({