@nolwenture/formik-jsonschema-form 1.0.0-beta.34 → 1.0.0-beta.35

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.
@@ -3,25 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Form = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const formik_1 = require("formik");
6
- const utils_1 = require("../utils");
7
6
  const FormRegistry_1 = require("./FormRegistry");
8
7
  const components_1 = require("./components");
9
8
  const fields_1 = require("./fields");
10
9
  const templates_1 = require("./templates");
11
10
  const Form = (props) => {
12
- (0, utils_1.warnFromUnsupportedKeys)("Form", props, [
13
- "schema",
14
- "onSubmit",
15
- "uiSchema",
16
- "className",
17
- "formData",
18
- "className",
19
- "children",
20
- "fields",
21
- "formContext",
22
- "components",
23
- "hideUnmarkedAdditionalProperties",
24
- ]);
25
11
  const { isSubmitting } = (0, formik_1.useFormikContext)();
26
12
  const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
27
13
  const schemaDefinitions = schema.definitions;
@@ -58,7 +58,7 @@ const ObjectField = (props) => {
58
58
  (props.uiSchema?.["ui:options"]?.isCollapsible
59
59
  ? templates.CollapsibleObjectFieldTemplate
60
60
  : templates.ObjectFieldTemplate);
61
- return ((0, jsx_runtime_1.jsx)(styledComponents_1.ObjectFieldWrapper, { children: (0, jsx_runtime_1.jsxs)(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name, children: [orderedProperties
61
+ return ((0, jsx_runtime_1.jsx)(styledComponents_1.ObjectFieldWrapper, { children: (0, jsx_runtime_1.jsxs)(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name || "ROOT", "data-fjsf-level": !name ? 0 : name.split(".").length, children: [orderedProperties
62
62
  .map((child) => {
63
63
  if (typeof child === "string") {
64
64
  const childSchema = properties?.[child];
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FormView = exports.FormWrapper = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const styled_components_1 = __importDefault(require("styled-components"));
9
- const utils_1 = require("../utils");
10
9
  const fields_1 = require("./fields");
11
10
  const components_1 = require("./components");
12
11
  const templates_1 = require("./templates");
@@ -16,19 +15,6 @@ exports.FormWrapper = styled_components_1.default.div `
16
15
  //padding: ${(props) => props.theme.spacing.xxxxxl};
17
16
  `;
18
17
  const FormView = (props) => {
19
- (0, utils_1.warnFromUnsupportedKeys)("Form", props, [
20
- "schema",
21
- "onSubmit",
22
- "uiSchema",
23
- "className",
24
- "formData",
25
- "className",
26
- "children",
27
- "fields",
28
- "formContext",
29
- "components",
30
- "hideUnmarkedAdditionalProperties",
31
- ]);
32
18
  const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
33
19
  const schemaDefinitions = schema.definitions;
34
20
  const uiSchemaDefinitions = uiSchema.definitions;
@@ -34,7 +34,7 @@ const ObjectField = (props) => {
34
34
  const SelectedObjectFieldTemplate = (props.uiSchema?.["ui:template"] &&
35
35
  templates[props.uiSchema?.["ui:template"]]) ??
36
36
  templates.ObjectFieldTemplate;
37
- return ((0, jsx_runtime_1.jsx)(SelectedObjectFieldTemplate, { ...props, children: orderedProperties
37
+ return ((0, jsx_runtime_1.jsx)(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name || "ROOT", "data-fjsf-level": !name ? 0 : name.split(".").length, children: orderedProperties
38
38
  .map((child, index) => {
39
39
  if (typeof child === "string") {
40
40
  const childSchema = properties?.[child];
@@ -9,12 +9,22 @@ const styledComponents_1 = require("./styledComponents");
9
9
  const ObjectFieldTemplate = (props) => {
10
10
  const { components } = (0, react_1.useContext)(FormViewRegistry_1.FormViewRegistry);
11
11
  const { Wrapper, Title, Description } = (0, styledComponents_1.getComponents)(components);
12
- const { children, uiSchema } = props;
12
+ const { children, uiSchema, ...otherProps } = props;
13
13
  const title = (0, utils_1.getTitle)(props);
14
14
  const description = (0, utils_1.getDescription)(props);
15
15
  const { help, info,
16
16
  //TODO: This is not right
17
17
  props: { wrapper: wrapperProps, title: titleProps, description: descriptionProps, help: helpProps, } = {}, } = (0, react_1.useMemo)(() => (0, utils_1.extractUiSchema)(uiSchema), [uiSchema]);
18
- return ((0, jsx_runtime_1.jsxs)(Wrapper, { ...wrapperProps, children: [title && (0, jsx_runtime_1.jsx)(Title, { ...titleProps, children: title }), description && ((0, jsx_runtime_1.jsx)(Description, { ...descriptionProps, children: description })), children] }));
18
+ const dataAttributes = Object.keys(otherProps)
19
+ .filter((key) => key.startsWith("data-"))
20
+ .reduce((acc, key) => {
21
+ acc[key] = otherProps[key];
22
+ return acc;
23
+ }, {});
24
+ const mergedWrapperProps = {
25
+ ...wrapperProps,
26
+ ...dataAttributes,
27
+ };
28
+ return ((0, jsx_runtime_1.jsxs)(Wrapper, { ...mergedWrapperProps, children: [title && (0, jsx_runtime_1.jsx)(Title, { ...titleProps, children: title }), description && ((0, jsx_runtime_1.jsx)(Description, { ...descriptionProps, children: description })), children] }));
19
29
  };
20
30
  exports.ObjectFieldTemplate = ObjectFieldTemplate;
@@ -8,12 +8,25 @@ exports.getComponents = getComponents;
8
8
  const styled_components_1 = __importDefault(require("styled-components"));
9
9
  exports.ObjectFieldTemplateWrapper = styled_components_1.default.div ``;
10
10
  exports.ObjectFieldTemplateTitle = styled_components_1.default.div `
11
- break-before: avoid;
12
- color: ${(props) => props.theme.color.text.default};
13
- font-family: ${(props) => props.theme.typography.fontFamily.heading};
14
- font-size: ${(props) => props.theme.typography.size.base};
15
- font-weight: ${(props) => props.theme.typography.weight.bold};
16
- margin: ${(props) => `${props.theme.spacing.s} 0`};
11
+ break-before: avoid;
12
+ color: ${(props) => props.theme.color.text.default};
13
+ font-family: ${(props) => props.theme.typography.fontFamily.heading};
14
+ font-size: ${(props) => props.theme.typography.size.base};
15
+ font-weight: ${(props) => props.theme.typography.weight.bold};
16
+ margin: ${(props) => `${props.theme.spacing.s} 0`};
17
+
18
+ /* ${exports.ObjectFieldTemplateWrapper}[data-fjsf-level] > & {
19
+ font-size: ${(props) => props.theme.typography.size.h4};
20
+ } */
21
+ ${exports.ObjectFieldTemplateWrapper}[data-fjsf-level="0"] > & {
22
+ font-size: ${(props) => props.theme.typography.size.h1};
23
+ }
24
+ /* ${exports.ObjectFieldTemplateWrapper}[data-fjsf-level="1"] > & {
25
+ font-size: ${(props) => props.theme.typography.size.h2};
26
+ }
27
+ ${exports.ObjectFieldTemplateWrapper}[data-fjsf-level="2"] > & {
28
+ font-size: ${(props) => props.theme.typography.size.h3};
29
+ } */
17
30
  `;
18
31
  exports.ObjectFieldTemplateDescription = undefined;
19
32
  function getComponents(components) {
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.warnFromUnsupportedKeys = void 0;
18
17
  __exportStar(require("./deepOverlap"), exports);
19
18
  __exportStar(require("./extractUiSchema"), exports);
20
19
  __exportStar(require("./getEnums"), exports);
@@ -28,12 +27,3 @@ __exportStar(require("./createValidationSchema"), exports);
28
27
  __exportStar(require("./orderByUiSchema"), exports);
29
28
  __exportStar(require("./orderAdditionalProperties"), exports);
30
29
  __exportStar(require("./setTitleValues"), exports);
31
- //TODO: REMOVE WHEN ALL SUPPORTED
32
- const warnFromUnsupportedKeys = (componentName, data, supportedKeys) => {
33
- Object.keys(data).forEach((key) => {
34
- if (!supportedKeys.includes(key)) {
35
- console.warn(`Component "${componentName}" does not support (yet) key "${key}"`);
36
- }
37
- });
38
- };
39
- exports.warnFromUnsupportedKeys = warnFromUnsupportedKeys;
@@ -1,24 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useFormikContext } from "formik";
3
- import { warnFromUnsupportedKeys } from "../utils";
4
3
  import { FormRegistry } from "./FormRegistry";
5
4
  import { components as defaultComponents } from "./components";
6
5
  import { fields as defaultFields } from "./fields";
7
6
  import { templates as defaultTemplates } from "./templates";
8
7
  export const Form = (props) => {
9
- warnFromUnsupportedKeys("Form", props, [
10
- "schema",
11
- "onSubmit",
12
- "uiSchema",
13
- "className",
14
- "formData",
15
- "className",
16
- "children",
17
- "fields",
18
- "formContext",
19
- "components",
20
- "hideUnmarkedAdditionalProperties",
21
- ]);
22
8
  const { isSubmitting } = useFormikContext();
23
9
  const { schema, uiSchema = {}, className, children, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, hideSubmit = false, } = props;
24
10
  const schemaDefinitions = schema.definitions;
@@ -55,7 +55,7 @@ export const ObjectField = (props) => {
55
55
  (props.uiSchema?.["ui:options"]?.isCollapsible
56
56
  ? templates.CollapsibleObjectFieldTemplate
57
57
  : templates.ObjectFieldTemplate);
58
- return (_jsx(ObjectFieldWrapper, { children: _jsxs(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name, children: [orderedProperties
58
+ return (_jsx(ObjectFieldWrapper, { children: _jsxs(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name || "ROOT", "data-fjsf-level": !name ? 0 : name.split(".").length, children: [orderedProperties
59
59
  .map((child) => {
60
60
  if (typeof child === "string") {
61
61
  const childSchema = properties?.[child];
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import styled from "styled-components";
3
- import { warnFromUnsupportedKeys } from "../utils";
4
3
  import { fields as defaultFields } from "./fields";
5
4
  import { components as defaultComponents } from "./components";
6
5
  import { templates as defaultTemplates } from "./templates";
@@ -10,19 +9,6 @@ export const FormWrapper = styled.div `
10
9
  //padding: ${(props) => props.theme.spacing.xxxxxl};
11
10
  `;
12
11
  export const FormView = (props) => {
13
- warnFromUnsupportedKeys("Form", props, [
14
- "schema",
15
- "onSubmit",
16
- "uiSchema",
17
- "className",
18
- "formData",
19
- "className",
20
- "children",
21
- "fields",
22
- "formContext",
23
- "components",
24
- "hideUnmarkedAdditionalProperties",
25
- ]);
26
12
  const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, } = props;
27
13
  const schemaDefinitions = schema.definitions;
28
14
  const uiSchemaDefinitions = uiSchema.definitions;
@@ -31,7 +31,7 @@ export const ObjectField = (props) => {
31
31
  const SelectedObjectFieldTemplate = (props.uiSchema?.["ui:template"] &&
32
32
  templates[props.uiSchema?.["ui:template"]]) ??
33
33
  templates.ObjectFieldTemplate;
34
- return (_jsx(SelectedObjectFieldTemplate, { ...props, children: orderedProperties
34
+ return (_jsx(SelectedObjectFieldTemplate, { ...props, "data-fjsf-object": name || "ROOT", "data-fjsf-level": !name ? 0 : name.split(".").length, children: orderedProperties
35
35
  .map((child, index) => {
36
36
  if (typeof child === "string") {
37
37
  const childSchema = properties?.[child];
@@ -6,11 +6,21 @@ import { getComponents } from "./styledComponents";
6
6
  export const ObjectFieldTemplate = (props) => {
7
7
  const { components } = useContext(FormViewRegistry);
8
8
  const { Wrapper, Title, Description } = getComponents(components);
9
- const { children, uiSchema } = props;
9
+ const { children, uiSchema, ...otherProps } = props;
10
10
  const title = getTitle(props);
11
11
  const description = getDescription(props);
12
12
  const { help, info,
13
13
  //TODO: This is not right
14
14
  props: { wrapper: wrapperProps, title: titleProps, description: descriptionProps, help: helpProps, } = {}, } = useMemo(() => extractUiSchema(uiSchema), [uiSchema]);
15
- return (_jsxs(Wrapper, { ...wrapperProps, children: [title && _jsx(Title, { ...titleProps, children: title }), description && (_jsx(Description, { ...descriptionProps, children: description })), children] }));
15
+ const dataAttributes = Object.keys(otherProps)
16
+ .filter((key) => key.startsWith("data-"))
17
+ .reduce((acc, key) => {
18
+ acc[key] = otherProps[key];
19
+ return acc;
20
+ }, {});
21
+ const mergedWrapperProps = {
22
+ ...wrapperProps,
23
+ ...dataAttributes,
24
+ };
25
+ return (_jsxs(Wrapper, { ...mergedWrapperProps, children: [title && _jsx(Title, { ...titleProps, children: title }), description && (_jsx(Description, { ...descriptionProps, children: description })), children] }));
16
26
  };
@@ -1,12 +1,25 @@
1
1
  import styled from "styled-components";
2
2
  export const ObjectFieldTemplateWrapper = styled.div ``;
3
3
  export const ObjectFieldTemplateTitle = styled.div `
4
- break-before: avoid;
5
- color: ${(props) => props.theme.color.text.default};
6
- font-family: ${(props) => props.theme.typography.fontFamily.heading};
7
- font-size: ${(props) => props.theme.typography.size.base};
8
- font-weight: ${(props) => props.theme.typography.weight.bold};
9
- margin: ${(props) => `${props.theme.spacing.s} 0`};
4
+ break-before: avoid;
5
+ color: ${(props) => props.theme.color.text.default};
6
+ font-family: ${(props) => props.theme.typography.fontFamily.heading};
7
+ font-size: ${(props) => props.theme.typography.size.base};
8
+ font-weight: ${(props) => props.theme.typography.weight.bold};
9
+ margin: ${(props) => `${props.theme.spacing.s} 0`};
10
+
11
+ /* ${ObjectFieldTemplateWrapper}[data-fjsf-level] > & {
12
+ font-size: ${(props) => props.theme.typography.size.h4};
13
+ } */
14
+ ${ObjectFieldTemplateWrapper}[data-fjsf-level="0"] > & {
15
+ font-size: ${(props) => props.theme.typography.size.h1};
16
+ }
17
+ /* ${ObjectFieldTemplateWrapper}[data-fjsf-level="1"] > & {
18
+ font-size: ${(props) => props.theme.typography.size.h2};
19
+ }
20
+ ${ObjectFieldTemplateWrapper}[data-fjsf-level="2"] > & {
21
+ font-size: ${(props) => props.theme.typography.size.h3};
22
+ } */
10
23
  `;
11
24
  export const ObjectFieldTemplateDescription = undefined;
12
25
  export function getComponents(components) {
@@ -11,11 +11,3 @@ export * from "./createValidationSchema";
11
11
  export * from "./orderByUiSchema";
12
12
  export * from "./orderAdditionalProperties";
13
13
  export * from "./setTitleValues";
14
- //TODO: REMOVE WHEN ALL SUPPORTED
15
- export const warnFromUnsupportedKeys = (componentName, data, supportedKeys) => {
16
- Object.keys(data).forEach((key) => {
17
- if (!supportedKeys.includes(key)) {
18
- console.warn(`Component "${componentName}" does not support (yet) key "${key}"`);
19
- }
20
- });
21
- };
@@ -11,4 +11,3 @@ export * from "./createValidationSchema";
11
11
  export * from "./orderByUiSchema";
12
12
  export * from "./orderAdditionalProperties";
13
13
  export * from "./setTitleValues";
14
- export declare const warnFromUnsupportedKeys: (componentName: string, data: Record<string, any>, supportedKeys: string[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "1.0.0-beta.34",
3
+ "version": "1.0.0-beta.35",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "anttivikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [