@nolwenture/formik-jsonschema-form 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -211,8 +211,10 @@ The `createValidationSchema` function generates a Yup validation schema from you
211
211
  ```tsx
212
212
  createValidationSchema(
213
213
  { schema, uiSchema }, // Schema and optional UI schema
214
- definitions, // Optional external definitions
215
- { localize } // Optional localization function
214
+ { // Optional options object
215
+ localize, // Localization function i18next t compatible
216
+ definitions, // Use these definitions instead of definitions in schema
217
+ }
216
218
  )
217
219
  ```
218
220
 
@@ -244,7 +246,6 @@ import { useTranslation } from 'react-i18next';
244
246
  const { t } = useTranslation();
245
247
  const validationSchema = createValidationSchema(
246
248
  { schema, uiSchema },
247
- {},
248
249
  { localize: t }
249
250
  );
250
251
  ```
@@ -117,9 +117,9 @@ exports.MultipleChoiceFieldWrapper = styled_components_1.default.div `
117
117
  align-items: start;
118
118
  }
119
119
  padding-left: ${(props) => props.theme.spacing.l};
120
- -webkit-column-break-inside: avoid;
121
- page-break-inside: avoid;
122
- break-inside: avoid;
120
+ -webkit-column-break-inside: auto;
121
+ page-break-inside: auto;
122
+ break-inside: auto;
123
123
  `;
124
124
  const BooleanFieldValue = ({ name, className, value, label, }) => {
125
125
  return ((0, jsx_runtime_1.jsx)("div", { className: className, children: value === true ? ((0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(SelectedBox, { children: (0, jsx_runtime_1.jsx)(exports.SelectedIcon, {}) }), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Selected" })] })) : ((0, jsx_runtime_1.jsxs)(Selected, { children: [(0, jsx_runtime_1.jsx)(NotSelectedBox, {}), (0, jsx_runtime_1.jsx)(styledComponents_1.MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Not selected" })] })) }));
@@ -173,9 +173,9 @@ function getYupType(schema) {
173
173
  throw new Error(`createValidationSchema: Unsupported schema type: ${type}`);
174
174
  }
175
175
  }
176
- function createValidationSchema(schemas, definitions = {}, options) {
176
+ function createValidationSchema(schemas, options) {
177
177
  const { schema, uiSchema = {} } = schemas;
178
- const { localize, conditionsContext = {}, condition } = options ?? {};
178
+ const { localize, definitions, conditionsContext = {}, condition } = options ?? {};
179
179
  if (!schema?.properties) {
180
180
  return Yup.object().shape({});
181
181
  }
@@ -189,10 +189,7 @@ function createValidationSchema(schemas, definitions = {}, options) {
189
189
  const defaultMsg = DEFAULT_ERROR_MESSAGES[key];
190
190
  return typeof defaultMsg === "function" ? defaultMsg(params) : defaultMsg;
191
191
  };
192
- const schemaDefinitions = {
193
- ...definitions,
194
- ...(schema.definitions ?? {}),
195
- };
192
+ const schemaDefinitions = (definitions ?? schema.definitions ?? {});
196
193
  const requiredFields = schema.required;
197
194
  function getValue(givenSchema, key, required) {
198
195
  const { schema } = (0, solveReferences_1.solveReferences)(givenSchema, schemaDefinitions, {}, {});
@@ -204,8 +201,9 @@ function createValidationSchema(schemas, definitions = {}, options) {
204
201
  yupSchema = createValidationSchema({
205
202
  schema,
206
203
  uiSchema: fieldUiSchema
207
- }, schemaDefinitions, {
204
+ }, {
208
205
  localize,
206
+ definitions: schemaDefinitions,
209
207
  conditionsContext,
210
208
  });
211
209
  type = type ?? "object";
@@ -389,8 +387,9 @@ function createValidationSchema(schemas, definitions = {}, options) {
389
387
  return validationSchema.concat(createValidationSchema({
390
388
  schema: solvedSchemas.schema,
391
389
  uiSchema
392
- }, schemaDefinitions, {
390
+ }, {
393
391
  localize,
392
+ definitions: schemaDefinitions,
394
393
  conditionsContext,
395
394
  condition: conditionalValidation.condition
396
395
  }));
@@ -111,9 +111,9 @@ export const MultipleChoiceFieldWrapper = styled.div `
111
111
  align-items: start;
112
112
  }
113
113
  padding-left: ${(props) => props.theme.spacing.l};
114
- -webkit-column-break-inside: avoid;
115
- page-break-inside: avoid;
116
- break-inside: avoid;
114
+ -webkit-column-break-inside: auto;
115
+ page-break-inside: auto;
116
+ break-inside: auto;
117
117
  `;
118
118
  export const BooleanFieldValue = ({ name, className, value, label, }) => {
119
119
  return (_jsx("div", { className: className, children: value === true ? (_jsxs(Selected, { children: [_jsx(SelectedBox, { children: _jsx(SelectedIcon, {}) }), _jsx(MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Selected" })] })) : (_jsxs(Selected, { children: [_jsx(NotSelectedBox, {}), _jsx(MultipleChoiceFieldLabel, { children: label !== undefined ? label : "Not selected" })] })) }));
@@ -137,9 +137,9 @@ function getYupType(schema) {
137
137
  throw new Error(`createValidationSchema: Unsupported schema type: ${type}`);
138
138
  }
139
139
  }
140
- export function createValidationSchema(schemas, definitions = {}, options) {
140
+ export function createValidationSchema(schemas, options) {
141
141
  const { schema, uiSchema = {} } = schemas;
142
- const { localize, conditionsContext = {}, condition } = options ?? {};
142
+ const { localize, definitions, conditionsContext = {}, condition } = options ?? {};
143
143
  if (!schema?.properties) {
144
144
  return Yup.object().shape({});
145
145
  }
@@ -153,10 +153,7 @@ export function createValidationSchema(schemas, definitions = {}, options) {
153
153
  const defaultMsg = DEFAULT_ERROR_MESSAGES[key];
154
154
  return typeof defaultMsg === "function" ? defaultMsg(params) : defaultMsg;
155
155
  };
156
- const schemaDefinitions = {
157
- ...definitions,
158
- ...(schema.definitions ?? {}),
159
- };
156
+ const schemaDefinitions = (definitions ?? schema.definitions ?? {});
160
157
  const requiredFields = schema.required;
161
158
  function getValue(givenSchema, key, required) {
162
159
  const { schema } = solveReferences(givenSchema, schemaDefinitions, {}, {});
@@ -168,8 +165,9 @@ export function createValidationSchema(schemas, definitions = {}, options) {
168
165
  yupSchema = createValidationSchema({
169
166
  schema,
170
167
  uiSchema: fieldUiSchema
171
- }, schemaDefinitions, {
168
+ }, {
172
169
  localize,
170
+ definitions: schemaDefinitions,
173
171
  conditionsContext,
174
172
  });
175
173
  type = type ?? "object";
@@ -353,8 +351,9 @@ export function createValidationSchema(schemas, definitions = {}, options) {
353
351
  return validationSchema.concat(createValidationSchema({
354
352
  schema: solvedSchemas.schema,
355
353
  uiSchema
356
- }, schemaDefinitions, {
354
+ }, {
357
355
  localize,
356
+ definitions: schemaDefinitions,
358
357
  conditionsContext,
359
358
  condition: conditionalValidation.condition
360
359
  }));
@@ -22,8 +22,9 @@ type ConditionsContext = {
22
22
  export declare function createValidationSchema(schemas: {
23
23
  schema: Schema;
24
24
  uiSchema?: UiSchema;
25
- }, definitions?: Schema, options?: {
25
+ }, options?: {
26
26
  localize?: LocalizeType;
27
+ definitions?: Schema;
27
28
  conditionsContext?: Record<string, ConditionsContext[]>;
28
29
  condition?: Condition;
29
30
  }): Yup.ObjectSchema<{}, Yup.AnyObject, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "anttivikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [