@remoteoss/json-schema-form 0.3.0-beta.0 → 0.4.0-beta.0

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,22 +1,30 @@
1
+ #### 0.4.0-beta.0 (2023-06-22)
2
+
3
+ ##### New Features
4
+
5
+ BREAKING CHANGES:
6
+
7
+ - **Radio/Select:** In each option, spread `x-jsf-presentation` value to option root ([#17](https://github.com/remoteoss/json-schema-form/pull/17)) ([367688c2](https://github.com/remoteoss/json-schema-form/commit/367688c24e212c1a0a1d2e7b19cbd7efa7021a15))
8
+
1
9
  #### 0.3.0-beta.0 (2023-06-21)
2
10
 
3
11
  ##### Fixes
4
12
 
5
- - Fix validation for text schema to only validate strings ([#12](https://github.com/remoteoss/json-schema-form/pull/12)) ([00017c0](https://github.com/remoteoss/json-schema-form/commit/00017c056d8a3583d56d9fefc4d3c7e0f4c1dd99))
13
+ - **Text:** Fix validation to only accept strings ([#12](https://github.com/remoteoss/json-schema-form/pull/12)) ([00017c0](https://github.com/remoteoss/json-schema-form/commit/00017c056d8a3583d56d9fefc4d3c7e0f4c1dd99))
6
14
 
7
15
  ##### Chores
8
16
 
9
- - Update yup version to v.0.30.0 ([#12](https://github.com/remoteoss/json-schema-form/pull/12)) ([00017c0](https://github.com/remoteoss/json-schema-form/commit/00017c056d8a3583d56d9fefc4d3c7e0f4c1dd99))
17
+ - Update Yup to v.0.30.0 ([#12](https://github.com/remoteoss/json-schema-form/pull/12)) ([00017c0](https://github.com/remoteoss/json-schema-form/commit/00017c056d8a3583d56d9fefc4d3c7e0f4c1dd99))
10
18
 
11
19
  #### 0.2.0-beta.0 (2023-06-20)
12
20
 
13
21
  ##### New Features
14
22
 
15
- - Add typescript declarations to the library ([2404188c](https://github.com/remoteoss/json-schema-form/commit/2404188cba52a5a665f257430a65a0ebb938dd44))
23
+ - Add Typescript declarations to the library ([2404188c](https://github.com/remoteoss/json-schema-form/commit/2404188cba52a5a665f257430a65a0ebb938dd44))
16
24
 
17
25
  ##### Fixes
18
26
 
19
- - Support maximum 0 ([#10](https://github.com/remoteoss/json-schema-form/pull/10)) ([1e9d6cf9](https://github.com/remoteoss/json-schema-form/commit/1e9d6cf96436cf16018e045b351567c643e10dac))
27
+ - **Number:** Support maximum 0 ([#10](https://github.com/remoteoss/json-schema-form/pull/10)) ([1e9d6cf9](https://github.com/remoteoss/json-schema-form/commit/1e9d6cf96436cf16018e045b351567c643e10dac))
20
28
 
21
29
  ##### Chores
22
30
 
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.3.0-beta.0
5
- Generated: Wed, 21 Jun 2023 11:17:55 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.0-beta.0
5
+ Generated: Thu, 22 Jun 2023 10:03:23 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -804,12 +804,26 @@ function updateFieldsProperties(fields, formValues, jsonSchema) {
804
804
  clearValuesIfNotVisible(fields, formValues);
805
805
  }
806
806
  var notNullOption = (opt) => opt.const !== null;
807
+ function flatPresentation(item) {
808
+ return Object.entries(item).reduce((newItem, [key, value]) => {
809
+ if (key === "x-jsf-presentation") {
810
+ return {
811
+ ...newItem,
812
+ ...value
813
+ };
814
+ }
815
+ return {
816
+ ...newItem,
817
+ [key]: value
818
+ };
819
+ }, {});
820
+ }
807
821
  function getFieldOptions(node, presentation) {
808
822
  function convertToOptions(nodeOptions) {
809
823
  return nodeOptions.filter(notNullOption).map(({ title, const: cons, ...item }) => ({
810
824
  label: title,
811
825
  value: cons,
812
- ...item
826
+ ...flatPresentation(item)
813
827
  }));
814
828
  }
815
829
  if (presentation.options) {
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.3.0-beta.0
5
- Generated: Wed, 21 Jun 2023 11:17:55 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.0-beta.0
5
+ Generated: Thu, 22 Jun 2023 10:03:23 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -768,12 +768,26 @@ function updateFieldsProperties(fields, formValues, jsonSchema) {
768
768
  clearValuesIfNotVisible(fields, formValues);
769
769
  }
770
770
  var notNullOption = (opt) => opt.const !== null;
771
+ function flatPresentation(item) {
772
+ return Object.entries(item).reduce((newItem, [key, value]) => {
773
+ if (key === "x-jsf-presentation") {
774
+ return {
775
+ ...newItem,
776
+ ...value
777
+ };
778
+ }
779
+ return {
780
+ ...newItem,
781
+ [key]: value
782
+ };
783
+ }, {});
784
+ }
771
785
  function getFieldOptions(node, presentation) {
772
786
  function convertToOptions(nodeOptions) {
773
787
  return nodeOptions.filter(notNullOption).map(({ title, const: cons, ...item }) => ({
774
788
  label: title,
775
789
  value: cons,
776
- ...item
790
+ ...flatPresentation(item)
777
791
  }));
778
792
  }
779
793
  if (presentation.options) {
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.3.0-beta.0
5
- Generated: Wed, 21 Jun 2023 11:17:55 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.0-beta.0
5
+ Generated: Thu, 22 Jun 2023 10:03:23 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -12172,12 +12172,26 @@ function updateFieldsProperties(fields, formValues, jsonSchema) {
12172
12172
  clearValuesIfNotVisible(fields, formValues);
12173
12173
  }
12174
12174
  var notNullOption = (opt) => opt.const !== null;
12175
+ function flatPresentation(item) {
12176
+ return Object.entries(item).reduce((newItem, [key, value]) => {
12177
+ if (key === "x-jsf-presentation") {
12178
+ return {
12179
+ ...newItem,
12180
+ ...value
12181
+ };
12182
+ }
12183
+ return {
12184
+ ...newItem,
12185
+ [key]: value
12186
+ };
12187
+ }, {});
12188
+ }
12175
12189
  function getFieldOptions(node, presentation) {
12176
12190
  function convertToOptions(nodeOptions) {
12177
12191
  return nodeOptions.filter(notNullOption).map(({ title, const: cons, ...item }) => ({
12178
12192
  label: title,
12179
12193
  value: cons,
12180
- ...item
12194
+ ...flatPresentation(item)
12181
12195
  }));
12182
12196
  }
12183
12197
  if (presentation.options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.4.0-beta.0",
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",
@@ -10,6 +10,7 @@ import {
10
10
  schemaInputTypeRadioDeprecated,
11
11
  schemaInputTypeRadio,
12
12
  schemaInputTypeRadioRequiredAndOptional,
13
+ schemaInputTypeRadioOptionsWithDetails,
13
14
  schemaInputTypeSelectSoloDeprecated,
14
15
  schemaInputTypeSelectSolo,
15
16
  schemaInputTypeSelectMultipleDeprecated,
@@ -757,6 +758,35 @@ describe('createHeadlessForm', () => {
757
758
  expect(() => fieldValidator.validateSync('')).toThrowError('Required field');
758
759
  });
759
760
 
761
+ it('support "radio" field type with extra info inside each option', () => {
762
+ const result = createHeadlessForm(schemaInputTypeRadioOptionsWithDetails);
763
+
764
+ expect(result.fields).toHaveLength(1);
765
+
766
+ const fieldOptions = result.fields[0].options;
767
+
768
+ // The x-jsf-presentation content was spread to the root:
769
+ expect(fieldOptions[0]).not.toHaveProperty('x-jsf-presentation');
770
+ expect(fieldOptions).toEqual([
771
+ {
772
+ label: 'Basic',
773
+ value: 'basic',
774
+ meta: {
775
+ displayCost: '$30.00/mo',
776
+ },
777
+ // Other x-* keywords are kept as it is.
778
+ 'x-another': 'extra-thing',
779
+ },
780
+ {
781
+ label: 'Standard',
782
+ value: 'standard',
783
+ meta: {
784
+ displayCost: '$50.00/mo',
785
+ },
786
+ },
787
+ ]);
788
+ });
789
+
760
790
  it('support "number" field type', () => {
761
791
  const result = createHeadlessForm(schemaInputTypeNumber);
762
792
  expect(result).toMatchObject({
@@ -871,34 +871,70 @@ export const schemaInputDeprecated = JSONSchemaBuilder()
871
871
  .build();
872
872
 
873
873
  /** @deprecated */
874
- export const schemaInputTypeRadioDeprecated = JSONSchemaBuilder()
875
- .addInput({
874
+ export const schemaInputTypeRadioDeprecated = {
875
+ properties: {
876
876
  has_siblings: mockRadioInputDeprecated,
877
- })
878
- .setRequiredFields(['has_siblings'])
879
- .build();
880
- export const schemaInputTypeRadio = JSONSchemaBuilder()
881
- .addInput({
877
+ },
878
+ required: ['has_siblings'],
879
+ };
880
+
881
+ export const schemaInputTypeRadio = {
882
+ properties: {
882
883
  has_siblings: mockRadioInput,
883
- })
884
- .setRequiredFields(['has_siblings'])
885
- .build();
884
+ },
885
+ required: ['has_siblings'],
886
+ };
886
887
 
887
- export const schemaInputTypeRadioRequiredAndOptional = JSONSchemaBuilder()
888
- .addInput({
888
+ export const schemaInputTypeRadioRequiredAndOptional = {
889
+ properties: {
889
890
  has_siblings: mockRadioInput,
890
891
  has_car: mockRadioInputOptional,
891
- })
892
- .setRequiredFields(['has_siblings'])
893
- .build();
892
+ },
893
+ required: ['has_siblings'],
894
+ };
894
895
 
895
- export const schemaInputTypeRadioCard = JSONSchemaBuilder()
896
- .addInput({
896
+ export const schemaInputTypeRadioCard = {
897
+ properties: {
897
898
  experience_level: mockRadioCardExpandableInput,
898
899
  payment_method: mockRadioCardInput,
899
- })
900
- .setRequiredFields(['experience_level'])
901
- .build();
900
+ },
901
+ required: ['experience_level'],
902
+ };
903
+
904
+ export const schemaInputTypeRadioOptionsWithDetails = {
905
+ properties: {
906
+ health_perks: {
907
+ title: 'Health perks',
908
+ description:
909
+ 'This example contains options with more custom details, under the x-jsf-presentation key',
910
+ oneOf: [
911
+ {
912
+ const: 'basic',
913
+ title: 'Basic',
914
+ 'x-jsf-presentation': {
915
+ meta: {
916
+ displayCost: '$30.00/mo',
917
+ },
918
+ },
919
+ 'x-another': 'extra-thing',
920
+ },
921
+ {
922
+ const: 'standard',
923
+ title: 'Standard',
924
+ 'x-jsf-presentation': {
925
+ meta: {
926
+ displayCost: '$50.00/mo',
927
+ },
928
+ },
929
+ },
930
+ ],
931
+ 'x-jsf-presentation': {
932
+ inputType: 'radio',
933
+ },
934
+ type: 'string',
935
+ },
936
+ },
937
+ };
902
938
 
903
939
  /** @deprecated */
904
940
  export const schemaInputTypeSelectSoloDeprecated = JSONSchemaBuilder()