@nolwenture/formik-jsonschema-form 0.7.1 → 0.9.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.
Files changed (82) hide show
  1. package/README.md +176 -1
  2. package/dist/Form.js +2 -1
  3. package/dist/Form.stories.d.ts +2 -0
  4. package/dist/Form.stories.js +15 -0
  5. package/dist/Form.test.d.ts +1 -1
  6. package/dist/Form.test.js +3 -1
  7. package/dist/fields/ArrayField.js +2 -1
  8. package/dist/fields/MultipleChoiceField.d.ts +3 -0
  9. package/dist/fields/MultipleChoiceField.js +13 -0
  10. package/dist/fields/ObjectField.js +3 -1
  11. package/dist/fields/SchemaField.js +7 -5
  12. package/dist/fields/StringField.js +1 -1
  13. package/dist/fields/index.d.ts +1 -0
  14. package/dist/fields/index.js +1 -0
  15. package/dist/fields/stories/AnyField.stories.d.ts +5 -0
  16. package/dist/fields/stories/AnyField.stories.js +79 -0
  17. package/dist/fields/stories/ArrayField.stories.d.ts +7 -0
  18. package/dist/fields/stories/ArrayField.stories.js +191 -0
  19. package/dist/fields/stories/BooleanField.stories.d.ts +5 -0
  20. package/dist/fields/stories/BooleanField.stories.js +36 -0
  21. package/dist/fields/stories/DateField.stories.d.ts +5 -0
  22. package/dist/fields/stories/DateField.stories.js +34 -0
  23. package/dist/fields/stories/NullField.stories.d.ts +5 -0
  24. package/dist/fields/stories/NullField.stories.js +38 -0
  25. package/dist/fields/stories/NumberField.stories.d.ts +5 -0
  26. package/dist/fields/stories/NumberField.stories.js +33 -0
  27. package/dist/fields/stories/ObjectField.stories.d.ts +5 -0
  28. package/dist/fields/stories/ObjectField.stories.js +76 -0
  29. package/dist/fields/stories/RadioField.stories.d.ts +5 -0
  30. package/dist/fields/stories/RadioField.stories.js +42 -0
  31. package/dist/fields/stories/SchemaField.stories.d.ts +1716 -0
  32. package/dist/fields/stories/SchemaField.stories.js +85 -0
  33. package/dist/fields/stories/SearchMultiTagSelectField.stories.d.ts +5 -0
  34. package/dist/fields/stories/SearchMultiTagSelectField.stories.js +58 -0
  35. package/dist/fields/stories/StringField.stories.d.ts +7 -0
  36. package/dist/fields/stories/StringField.stories.js +75 -0
  37. package/dist/fields/stories/ToggleField.stories.d.ts +5 -0
  38. package/dist/fields/stories/ToggleField.stories.js +34 -0
  39. package/dist/formEditorSchemas.js +177 -21
  40. package/dist/hooks/__tests__/useExtractUiSchema.test.d.ts +1 -0
  41. package/dist/hooks/__tests__/useExtractUiSchema.test.js +45 -0
  42. package/dist/hooks/__tests__/useSetDefault.test.d.ts +1 -0
  43. package/dist/hooks/__tests__/useSetDefault.test.js +65 -0
  44. package/dist/hooks/useExtractUiSchema.js +7 -3
  45. package/dist/sampleData/ageFieldDefinition.d.ts +2 -0
  46. package/dist/sampleData/ageFieldDefinition.js +5 -0
  47. package/dist/sampleData/multipleChoiceSchema.d.ts +3 -0
  48. package/dist/sampleData/multipleChoiceSchema.js +112 -0
  49. package/dist/sampleData/refDefSchema.d.ts +3 -0
  50. package/dist/sampleData/refDefSchema.js +219 -0
  51. package/dist/sampleData/requiredInputSchema.js +0 -5
  52. package/dist/styledComponents.d.ts +2 -1
  53. package/dist/styledComponents.js +8 -0
  54. package/dist/types.d.ts +19 -2
  55. package/dist/utils/__tests/createInitialValues.test.d.ts +1 -0
  56. package/dist/utils/__tests/createInitialValues.test.js +72 -0
  57. package/dist/utils/__tests/deepOverlap.test.d.ts +1 -0
  58. package/dist/utils/__tests/deepOverlap.test.js +41 -0
  59. package/dist/utils/__tests/getEnums.test.js +11 -16
  60. package/dist/utils/__tests/getTitleAndDescription.test.d.ts +1 -0
  61. package/dist/utils/__tests/getTitleAndDescription.test.js +53 -0
  62. package/dist/utils/__tests/getTypes.test.d.ts +1 -0
  63. package/dist/utils/__tests/getTypes.test.js +62 -0
  64. package/dist/utils/__tests/mergeSchemas.test.d.ts +1 -0
  65. package/dist/utils/__tests/mergeSchemas.test.js +40 -0
  66. package/dist/utils/__tests/resolveSchema.test.js +43 -33
  67. package/dist/utils/__tests/solveReferences.test.d.ts +1 -0
  68. package/dist/utils/__tests/solveReferences.test.js +12 -0
  69. package/dist/utils/__tests/testSchemas.d.ts +4 -0
  70. package/dist/utils/__tests/testSchemas.js +67 -0
  71. package/dist/utils/createInitialValues.d.ts +4 -0
  72. package/dist/utils/createInitialValues.js +27 -0
  73. package/dist/utils/getStyle.d.ts +5 -0
  74. package/dist/utils/getStyle.js +18 -0
  75. package/dist/utils/getTypes.js +1 -1
  76. package/dist/utils/index.d.ts +2 -0
  77. package/dist/utils/index.js +2 -0
  78. package/dist/utils/resolveSchema.d.ts +1 -1
  79. package/dist/utils/resolveSchema.js +88 -39
  80. package/dist/utils/solveReferences.d.ts +2 -0
  81. package/dist/utils/solveReferences.js +8 -0
  82. package/package.json +5 -2
@@ -0,0 +1,112 @@
1
+ export const multipleChoiceSchema = {
2
+ title: "TITLE",
3
+ required: ["lastName", "requiredNestedObject", "requiredArray"],
4
+ properties: {
5
+ weather: {
6
+ type: "string",
7
+ title: "What is the weather like today? (no style given)",
8
+ oneOf: [
9
+ { const: "sunny", title: "Sunny" },
10
+ { const: "cloudy", title: "Cloudy" },
11
+ { const: "rainy", title: "Rainy" },
12
+ { const: "windy", title: "Windy" },
13
+ ],
14
+ },
15
+ feeling: {
16
+ type: "string",
17
+ title: "How are you feeling today? (style: inline)",
18
+ oneOf: [
19
+ { const: "happy", title: "Happy" },
20
+ { const: "creative", title: "Creative" },
21
+ { const: "tired", title: "Tired" },
22
+ { const: "nope", title: "Please don't even ask..." },
23
+ ],
24
+ },
25
+ food: {
26
+ type: "string",
27
+ title: "What would you like to eat today? (style: oneColumn)",
28
+ anyOf: [
29
+ { const: "breakfast", title: "Breakfast" },
30
+ { const: "secondBreakfast", title: "What about second breakfast?" },
31
+ { const: "elevenses", title: "Elevenses" },
32
+ { const: "luncheon", title: "Luncheon" },
33
+ { const: "afternoonTea", title: "Afternoon tea" },
34
+ { const: "dinner", title: "Dinner" },
35
+ { const: "supper", title: "Supper" },
36
+ ],
37
+ },
38
+ drinks: {
39
+ type: "string",
40
+ title: "What would you like to drink today? (style: twoColumns)",
41
+ anyOf: [
42
+ { const: "water", title: "Water" },
43
+ { const: "coffee", title: "Coffee" },
44
+ { const: "tea", title: "Tea" },
45
+ { const: "milk", title: "Milk" },
46
+ { const: "nonMilk", title: "Non-dairy milk" },
47
+ { const: "juice", title: "Juice" },
48
+ { const: "beer", title: "Beer" },
49
+ { const: "wine", title: "Wine" },
50
+ { const: "cocktail", title: "Cocktail" },
51
+ { const: "mocktail", title: "Mocktail" },
52
+ { const: "somethingElse", title: "Something else" },
53
+ ],
54
+ },
55
+ flowers: {
56
+ type: "string",
57
+ title: "Pick some flowers (style: threeColumns)",
58
+ anyOf: [
59
+ { const: "lily", title: "Lily" },
60
+ { const: "rose", title: "Rose" },
61
+ { const: "iris", title: "Iris" },
62
+ { const: "tulip", title: "Tulip" },
63
+ { const: "dahlia", title: "Dahlia" },
64
+ { const: "daisy", title: "Daisy" },
65
+ { const: "sunflower", title: "Sunflower" },
66
+ { const: "orchid", title: "Orchid" },
67
+ { const: "carnation", title: "Carnation" },
68
+ { const: "poppy", title: "Poppy" },
69
+ { const: "gerbera", title: "Gerbera" },
70
+ { const: "camellia", title: "Camellia" },
71
+ { const: "aster", title: "Aster" },
72
+ { const: "marigold", title: "Marigold" },
73
+ { const: "calendula", title: "Calendula" },
74
+ { const: "lilac", title: "Lilac" },
75
+ { const: "primrose", title: "Primrose" },
76
+ { const: "daffodil", title: "Daffodil" },
77
+ { const: "oleander", title: "Oleander" },
78
+ { const: "buttercups", title: "Buttercups" },
79
+ { const: "lotus", title: "Lotus" },
80
+ ],
81
+ },
82
+ },
83
+ };
84
+ export const multipleChoiceUiSchema = {
85
+ weather: {
86
+ "ui:field": "MultipleChoiceField",
87
+ },
88
+ feeling: {
89
+ "ui:field": "MultipleChoiceField",
90
+ "ui:option": {
91
+ style: "inline",
92
+ },
93
+ },
94
+ food: {
95
+ "ui:field": "MultipleChoiceField",
96
+ "ui:option": {
97
+ style: "oneColumn",
98
+ },
99
+ },
100
+ drinks: {
101
+ "ui:field": "MultipleChoiceField",
102
+ "ui:option": {
103
+ style: "twoColumns",
104
+ },
105
+ },
106
+ flowers: {
107
+ "ui:field": "MultipleChoiceField",
108
+ "ui:option": {
109
+ style: "threeColumns",
110
+ },
111
+ },
112
+ };
@@ -0,0 +1,3 @@
1
+ import type { Schema, UiSchema } from "../types";
2
+ export declare const refDefSchema: Schema;
3
+ export declare const refDefUiSchema: UiSchema;
@@ -0,0 +1,219 @@
1
+ import { ageFieldDefinition } from "./ageFieldDefinition";
2
+ export const refDefSchema = {
3
+ title: "References and Definitions",
4
+ type: "object",
5
+ required: ["name", "field"],
6
+ properties: {
7
+ name: {
8
+ $ref: "#/definitions/name",
9
+ },
10
+ age: {
11
+ $ref: "#/definitions/age",
12
+ },
13
+ creditCard: {
14
+ type: "number",
15
+ title: "Credit card number",
16
+ description: "Giving input to this field will trigger its dependent field 'billing_address'",
17
+ },
18
+ fieldType: {
19
+ type: "string",
20
+ description: "Selecting an option in this field will render the correct dependent field from the provided oneOf-array",
21
+ enum: ["no type", "string", "object", "array", "object and string"],
22
+ },
23
+ boolean: {
24
+ type: "boolean",
25
+ title: "I already had coffee today",
26
+ },
27
+ animal: {
28
+ type: "string",
29
+ oneOf: [
30
+ { const: "cat", title: "Cat" },
31
+ { const: "fish", title: "Fish" },
32
+ { const: "dog", title: "Dog" },
33
+ { const: "horse", title: "Horse" },
34
+ { const: "hamster", title: "Hamster" },
35
+ ],
36
+ },
37
+ },
38
+ dependencies: {
39
+ creditCard: {
40
+ properties: {
41
+ billing_address: {
42
+ type: "object",
43
+ description: "This object depends on creditCard field input",
44
+ properties: {
45
+ street: { type: "string", title: "Street" },
46
+ city: { type: "string", title: "City" },
47
+ postalCode: { type: "number", title: "Postal code" },
48
+ },
49
+ },
50
+ },
51
+ required: ["billing_address"],
52
+ },
53
+ fieldType: {
54
+ oneOf: [
55
+ {
56
+ properties: {
57
+ fieldType: {
58
+ enum: ["no type"],
59
+ },
60
+ },
61
+ },
62
+ {
63
+ properties: {
64
+ fieldType: {
65
+ enum: ["string"],
66
+ },
67
+ stringField: {
68
+ type: "string",
69
+ title: "StringField",
70
+ },
71
+ },
72
+ },
73
+ {
74
+ properties: {
75
+ fieldType: {
76
+ enum: ["object"],
77
+ },
78
+ objectField: {
79
+ type: "object",
80
+ properties: {
81
+ objectString: {
82
+ type: "string",
83
+ title: "StringField in Object",
84
+ },
85
+ },
86
+ },
87
+ },
88
+ },
89
+ {
90
+ properties: {
91
+ fieldType: {
92
+ enum: ["array"],
93
+ },
94
+ arrayField: {
95
+ type: "array",
96
+ additionalItems: { type: "string" },
97
+ },
98
+ },
99
+ },
100
+ {
101
+ properties: {
102
+ fieldType: {
103
+ enum: ["object and string"],
104
+ },
105
+ stringField: {
106
+ type: "string",
107
+ title: "StringField",
108
+ },
109
+ objectField: {
110
+ type: "object",
111
+ properties: {
112
+ objectString: {
113
+ type: "string",
114
+ title: "StringField in Object",
115
+ },
116
+ },
117
+ },
118
+ },
119
+ },
120
+ ],
121
+ },
122
+ boolean: {
123
+ oneOf: [
124
+ {
125
+ properties: { boolean: false },
126
+ },
127
+ {
128
+ properties: {
129
+ boolean: true,
130
+ something: { type: "string" },
131
+ },
132
+ },
133
+ ],
134
+ },
135
+ },
136
+ allOf: [
137
+ {
138
+ if: {
139
+ properties: {
140
+ animal: {
141
+ const: "cat",
142
+ },
143
+ },
144
+ },
145
+ then: {
146
+ properties: {
147
+ food: {
148
+ type: "string",
149
+ enum: ["meat", "grass", "fish"],
150
+ },
151
+ },
152
+ required: ["food"],
153
+ },
154
+ },
155
+ {
156
+ if: {
157
+ properties: {
158
+ animal: {
159
+ const: "fish",
160
+ },
161
+ },
162
+ },
163
+ then: {
164
+ properties: {
165
+ food: {
166
+ type: "string",
167
+ enum: ["insect", "worms"],
168
+ },
169
+ water: {
170
+ type: "string",
171
+ enum: ["lake", "sea"],
172
+ },
173
+ },
174
+ required: ["food", "water"],
175
+ },
176
+ // else: {
177
+ // properties: {
178
+ // likesWalkiesWhere: {
179
+ // type: "string",
180
+ // enum: ["park", "forest", "garden"],
181
+ // },
182
+ // },
183
+ // },
184
+ },
185
+ {
186
+ required: ["animal"],
187
+ },
188
+ ],
189
+ definitions: {
190
+ name: {
191
+ type: "string",
192
+ title: "Name",
193
+ description: "The schema for this field comes from the 'definitions' object inside the main schema",
194
+ },
195
+ age: ageFieldDefinition,
196
+ },
197
+ };
198
+ export const refDefUiSchema = {
199
+ "ui:order": [
200
+ "name",
201
+ "age",
202
+ "creditCard",
203
+ "billing_address",
204
+ "fieldType",
205
+ "stringField",
206
+ "objectField",
207
+ "arrayField",
208
+ "boolean",
209
+ "something",
210
+ "animal",
211
+ "food",
212
+ "water",
213
+ ],
214
+ fieldType: {
215
+ "ui:placeholderOptionOptions": {
216
+ props: { disabled: false, hidden: false },
217
+ },
218
+ },
219
+ };
@@ -4,7 +4,6 @@ export const requiredInputSchema = {
4
4
  properties: {
5
5
  firstName: { type: "string", title: "First name" },
6
6
  lastName: { type: "string", title: "Last name" },
7
- feeling: { type: "boolean", title: "Feeling happy today?" },
8
7
  vibes: { type: "boolean", title: "Turn on the good vibes" },
9
8
  arrayOfObject: {
10
9
  type: "array",
@@ -62,10 +61,6 @@ export const requiredInputSchema = {
62
61
  },
63
62
  };
64
63
  export const requiredInputUiSchema = {
65
- feeling: {
66
- "ui:field": "RadioField",
67
- "ui:label": { true: "yes", false: "no" },
68
- },
69
64
  vibes: {
70
65
  "ui:field": "ToggleField",
71
66
  },
@@ -1,5 +1,5 @@
1
1
  /// <reference types="hoist-non-react-statics" />
2
- import type { ArrayFieldButtonProps, InfoFieldButtonProps, ObjectFieldButtonProps, RadioButtonFieldProps, ToggleSwitchFieldProps, SelectFieldProps } from "./types";
2
+ import type { ArrayFieldButtonProps, InfoFieldButtonProps, ObjectFieldButtonProps, RadioButtonFieldProps, ToggleSwitchFieldProps, SelectFieldProps, MultipleChoiceFieldProps } from "./types";
3
3
  import React from "react";
4
4
  import * as formik from "formik";
5
5
  export declare const Form: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<Omit<Omit<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & React.RefAttributes<HTMLFormElement>, "ref"> & {
@@ -166,6 +166,7 @@ export declare const RadioButtonField: {
166
166
  }, never>> & Omit<import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>>, keyof React.Component<any, {}, any>>;
167
167
  };
168
168
  };
169
+ export declare const MultipleChoiceField: ({ inputProps, name, className, enums, style, }: MultipleChoiceFieldProps) => import("react/jsx-runtime").JSX.Element;
169
170
  export declare const MultiSelectContainer: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
170
171
  export declare const MultiSelectInput: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<Omit<import("styled-components/dist/types").FastOmit<Omit<Omit<any, "as">, "ref"> & {
171
172
  ref?: unknown;
@@ -15,6 +15,7 @@ import styled from "styled-components";
15
15
  import * as formik from "formik";
16
16
  import { FormRegistry } from "./Form";
17
17
  import { ArrayFieldButtonPurpose, ObjectFieldButtonPurpose } from "./types";
18
+ import { getStyle } from "./utils/getStyle";
18
19
  export const Form = styled(formik.Form) ``;
19
20
  export const FormButtonWrapper = styled.div ``;
20
21
  export const FormButton = styled.button ``;
@@ -289,6 +290,13 @@ export const RadioButtonField = ({ label, inputProps, name, className, }) => {
289
290
  var _a, _b;
290
291
  return (_jsxs(RadioButtonFieldContainer, { className: className, children: [_jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, Object.assign({}, inputProps, { name: name, type: "radio", value: "true" })), _jsx(ButtonLabelTrue, { children: (_a = label === null || label === void 0 ? void 0 : label.true) !== null && _a !== void 0 ? _a : "true" })] }), _jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, Object.assign({}, inputProps, { name: name, type: "radio", value: "false" })), _jsx(ButtonLabelFalse, { children: (_b = label === null || label === void 0 ? void 0 : label.false) !== null && _b !== void 0 ? _b : "false" })] })] }));
291
292
  };
293
+ const MultipleChoiceFieldContainer = styled(RadioButtonFieldContainer) ``;
294
+ const MultipleChoiceFieldElement = styled(RadioButtonFieldElement) ``;
295
+ const MultipleChoiceFieldInput = styled(RadioButtonFieldInput) ``;
296
+ const MultipleChoiceFieldLabel = styled(ButtonLabel) ``;
297
+ export const MultipleChoiceField = ({ inputProps, name, className, enums, style, }) => {
298
+ return (_jsx(MultipleChoiceFieldContainer, { className: className, style: getStyle(style !== null && style !== void 0 ? style : ""), children: enums.values.map((v) => (_jsxs(MultipleChoiceFieldElement, { children: [_jsx(MultipleChoiceFieldInput, Object.assign({}, inputProps, { name: name, type: enums.type === "multiSelect" ? "checkbox" : "radio", value: typeof v === "string" || typeof v === "number" ? v : v.const })), _jsx(MultipleChoiceFieldLabel, { children: typeof v === "string" || typeof v === "number" ? v : v.title })] }, typeof v === "string" || typeof v === "number" ? v : v.const))) }));
299
+ };
292
300
  RadioButtonField.styles = {
293
301
  RadioButtonFieldContainerStyle: RadioButtonFieldContainer,
294
302
  RadioButtonFieldElementStyle: RadioButtonFieldElement,
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { JSONSchema7 } from "json-schema";
1
+ import type { JSONSchema7, JSONSchema7Definition } from "json-schema";
2
2
  import React from "react";
3
3
  export type FormProps<T> = React.PropsWithChildren<{
4
4
  /** If true, disabled prop is passed down to each field on the form */
@@ -48,7 +48,9 @@ export type FormRegistryContextValue = {
48
48
  fields: Record<string, Field>;
49
49
  templates: TemplatesType;
50
50
  components: ComponentsType;
51
- definitions: Record<string, any>;
51
+ definitions: {
52
+ [key: string]: JSONSchema7Definition;
53
+ } | undefined;
52
54
  formContext: Record<string, any>;
53
55
  useItemsAsAdditionalItems: boolean;
54
56
  hideUnmarkedAdditionalProperties: boolean;
@@ -127,6 +129,7 @@ export type ComponentsType = {
127
129
  FieldInput: React.FunctionComponent<any>;
128
130
  RequiredIndicator: React.FunctionComponent<any>;
129
131
  RadioButtonField: React.FunctionComponent<any>;
132
+ MultipleChoiceField: React.FunctionComponent<any>;
130
133
  ToggleSwitchField: React.FunctionComponent<any>;
131
134
  SearchableMultiTagSelectField: React.FunctionComponent<any>;
132
135
  };
@@ -169,6 +172,20 @@ export type RadioButtonFieldProps = {
169
172
  name?: React.ReactNode;
170
173
  className?: string;
171
174
  };
175
+ type Enum = {
176
+ type: string;
177
+ values: {
178
+ const: number | string;
179
+ title: string;
180
+ }[] | number[] | string[];
181
+ };
182
+ export type MultipleChoiceFieldProps = {
183
+ inputProps?: any;
184
+ name?: React.ReactNode;
185
+ className?: string;
186
+ enums: Enum;
187
+ style?: string;
188
+ };
172
189
  export type ToggleSwitchFieldProps = {
173
190
  inputProps: any;
174
191
  name: React.ReactNode;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { createInitialValues } from "../createInitialValues";
11
+ const exampleSchema = {
12
+ title: "TITLE",
13
+ required: ["lastName", "requiredNestedObject", "requiredArray"],
14
+ properties: {
15
+ name: { type: "string", title: "Full name" },
16
+ number: { type: "number", title: "Phone number" },
17
+ feeling: { type: "boolean", title: "Feeling happy today?" },
18
+ arrayOfObject: {
19
+ type: "array",
20
+ title: "Array of objects",
21
+ items: {
22
+ type: "object",
23
+ title: "Favourites",
24
+ required: ["favouriteFood"],
25
+ properties: {
26
+ favouriteFood: { type: "string", title: "Favourite food" },
27
+ favouriteSong: { type: "string", title: "Favourite song" },
28
+ },
29
+ },
30
+ additionalItems: {
31
+ type: "object",
32
+ title: "Second favourites",
33
+ required: ["secondFavouriteSong"],
34
+ properties: {
35
+ anotherFavouriteFood: {
36
+ type: "string",
37
+ title: "Another favourite food",
38
+ },
39
+ anotherFavouriteSong: {
40
+ type: "string",
41
+ title: "Another favourite song",
42
+ },
43
+ },
44
+ },
45
+ },
46
+ nestedObject: {
47
+ type: "object",
48
+ title: "Nested Object",
49
+ required: ["tasks"],
50
+ properties: {
51
+ hobbies: { type: "string", title: "Hobbies" },
52
+ tasks: { type: "string", title: "Tasks" },
53
+ },
54
+ },
55
+ },
56
+ };
57
+ describe("Create Initial Values", () => {
58
+ it("creates for an object type", () => __awaiter(void 0, void 0, void 0, function* () {
59
+ const result = createInitialValues(exampleSchema);
60
+ const expected = {
61
+ name: "",
62
+ number: 0,
63
+ feeling: false,
64
+ arrayOfObject: [],
65
+ nestedObject: {
66
+ hobbies: "",
67
+ tasks: "",
68
+ },
69
+ };
70
+ expect(result).toEqual(expected);
71
+ }));
72
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { deepOverlap } from "../deepOverlap";
2
+ describe("deepOverlap", () => {
3
+ test("returns true for both empty objects", () => {
4
+ expect(deepOverlap({}, {})).toBe(true);
5
+ });
6
+ test("returns true for identical objects", () => {
7
+ const obj1 = { a: 1, b: 2 };
8
+ const obj2 = { a: 1, b: 2 };
9
+ expect(deepOverlap(obj1, obj2)).toBe(true);
10
+ });
11
+ test("returns true for nested objects that are identical", () => {
12
+ const obj1 = { a: { b: 2 } };
13
+ const obj2 = { a: { b: 2 } };
14
+ expect(deepOverlap(obj1, obj2)).toBe(true);
15
+ });
16
+ test("handles arrays and non-object types correctly", () => {
17
+ const obj1 = { a: [1, 2, 3], b: "string", c: true };
18
+ const obj2 = { a: [1, 2, 3], b: "string", c: true };
19
+ expect(deepOverlap(obj1, obj2)).toBe(true);
20
+ });
21
+ test("returns true for objects with keys in different orders", () => {
22
+ const obj1 = { a: 1, b: { c: 2 } };
23
+ const obj2 = { b: { c: 2 }, a: 1 };
24
+ expect(deepOverlap(obj1, obj2)).toBe(true);
25
+ });
26
+ test("returns false for objects with different values", () => {
27
+ const obj1 = { a: 1 };
28
+ const obj2 = { a: 2 };
29
+ expect(deepOverlap(obj1, obj2)).toBe(false);
30
+ });
31
+ test("returns false for nested objects that do not overlap", () => {
32
+ const obj1 = { a: { b: 1 } };
33
+ const obj2 = { a: { b: 2 } };
34
+ expect(deepOverlap(obj1, obj2)).toBe(false);
35
+ });
36
+ test("returns false when one object is empty", () => {
37
+ const obj1 = { a: 1 };
38
+ const obj2 = {};
39
+ expect(deepOverlap(obj1, obj2)).toBe(false);
40
+ });
41
+ });
@@ -1,5 +1,12 @@
1
1
  import { getEnums } from "../getEnums";
2
2
  describe("getEnums", () => {
3
+ test("returns undefined when no enum types are defined", () => {
4
+ const result = getEnums({ schema: {} });
5
+ expect(result).toBeUndefined();
6
+ });
7
+ test("throws error when more than one enum type is defined", () => {
8
+ expect(() => getEnums({ schema: { enum: [], oneOf: [], anyOf: [] } })).toThrow('Only one of "enum", "oneOf" or "anyOf" can be defined!');
9
+ });
3
10
  test("enum works", () => {
4
11
  const result = getEnums({ schema: { enum: ["one", "two", "three"] } });
5
12
  expect(result).toEqual({
@@ -15,10 +22,7 @@ describe("getEnums", () => {
15
22
  const result = getEnums({
16
23
  schema: {
17
24
  oneOf: [
18
- {
19
- const: "horse",
20
- title: "Horse",
21
- },
25
+ { const: "horse", title: "Horse" },
22
26
  { const: "frog", title: "Frog" },
23
27
  { const: "bird", title: "Bird" },
24
28
  ],
@@ -27,10 +31,7 @@ describe("getEnums", () => {
27
31
  expect(result).toEqual({
28
32
  type: "select",
29
33
  values: [
30
- {
31
- const: "horse",
32
- title: "Horse",
33
- },
34
+ { const: "horse", title: "Horse" },
34
35
  { const: "frog", title: "Frog" },
35
36
  { const: "bird", title: "Bird" },
36
37
  ],
@@ -40,10 +41,7 @@ describe("getEnums", () => {
40
41
  const result = getEnums({
41
42
  schema: {
42
43
  anyOf: [
43
- {
44
- const: "tangerine",
45
- title: "Tangerine",
46
- },
44
+ { const: "tangerine", title: "Tangerine" },
47
45
  { const: "mandarin", title: "Mandarin" },
48
46
  { const: "bruno", title: "Bruno" },
49
47
  ],
@@ -52,10 +50,7 @@ describe("getEnums", () => {
52
50
  expect(result).toEqual({
53
51
  type: "multiSelect",
54
52
  values: [
55
- {
56
- const: "tangerine",
57
- title: "Tangerine",
58
- },
53
+ { const: "tangerine", title: "Tangerine" },
59
54
  { const: "mandarin", title: "Mandarin" },
60
55
  { const: "bruno", title: "Bruno" },
61
56
  ],