@nolwenture/formik-jsonschema-form 0.25.2 → 0.26.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.
@@ -1,15 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useContext } from "react";
3
- import { FormPdfRegistry } from "../FormPdf";
4
- import { useSetDefault } from "../hooks";
5
- import { getIn, useFormikContext } from "formik";
6
- import { styled } from "styled-components";
7
- const DateFieldPdf = styled.div ``;
2
+ import { StringField } from "./StringField";
8
3
  export const DateField = (props) => {
9
- const { templates: { FieldTemplate }, } = useContext(FormPdfRegistry);
10
- useSetDefault(props);
11
- const { name } = props;
12
- const { values } = useFormikContext();
13
- const value = getIn(values, name);
14
- return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(DateFieldPdf, { children: value }) })));
4
+ var _a;
5
+ return (_jsx(StringField, Object.assign({}, props, { uiSchema: Object.assign(Object.assign({}, props.uiSchema), { "ui:props": Object.assign({}, (((_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:props"]) || {})) }) })));
15
6
  };
@@ -1,24 +1,35 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useContext } from "react";
2
+ import { useContext, useMemo } from "react";
3
3
  import { useSetDefault } from "../hooks";
4
- import ejs from "ejs";
4
+ import ejs from "ejs-browser";
5
+ import DOMPurify from "dompurify";
5
6
  import { getIn, useFormikContext } from "formik";
6
7
  import { getDescription, getTitle } from "../utils";
7
8
  import { FormPdfRegistry } from "../FormPdf";
8
9
  export const EJSField = (props) => {
9
10
  var _a, _b;
10
- const { components: { EJSField }, } = useContext(FormPdfRegistry);
11
+ const { components: { EJSField: PdfEJSField }, } = useContext(FormPdfRegistry);
11
12
  useSetDefault(props);
12
13
  const { name, uiSchema = {} } = props;
13
14
  const { values } = useFormikContext();
14
- const title = getTitle(props);
15
- const description = getDescription(props);
16
- const template = (_b = (_a = uiSchema["ui:options"]) === null || _a === void 0 ? void 0 : _a.template) !== null && _b !== void 0 ? _b : "";
17
- return (_jsx(EJSField, { dangerouslySetInnerHTML: {
18
- __html: ejs.render(template.toString(), {
15
+ const title = getTitle(props) || "Untitled Field";
16
+ const description = getDescription(props) || "No description available.";
17
+ const template = (_b = (_a = uiSchema["ui:options"]) === null || _a === void 0 ? void 0 : _a.template) !== null && _b !== void 0 ? _b : "No template provided.";
18
+ const renderedTemplate = useMemo(() => {
19
+ try {
20
+ return ejs.render(template.toString(), {
19
21
  title,
20
22
  description,
21
23
  value: getIn(values, name),
22
- }),
24
+ });
25
+ }
26
+ catch (error) {
27
+ console.error("EJS rendering error:", error);
28
+ return "Error rendering template.";
29
+ }
30
+ }, [template, title, description, name, values]);
31
+ const sanitizedHTML = DOMPurify.sanitize(renderedTemplate);
32
+ return (_jsx(PdfEJSField, { dangerouslySetInnerHTML: {
33
+ __html: sanitizedHTML,
23
34
  } }));
24
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "0.25.2",
3
+ "version": "0.26.0",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "Antti Vikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [
@@ -20,6 +20,7 @@
20
20
  "formik",
21
21
  "jsonschema"
22
22
  ],
23
+ "type": "commonjs",
23
24
  "main": "./dist/index.js",
24
25
  "types": "./dist/index.d.ts",
25
26
  "files": [
@@ -35,7 +36,8 @@
35
36
  "test-storybook": "test-storybook"
36
37
  },
37
38
  "dependencies": {
38
- "ejs": "^3.1.10",
39
+ "dompurify": "^3.2.2",
40
+ "ejs-browser": "^3.2.2",
39
41
  "formik": "^2.4.5",
40
42
  "json-schema": "^0.4.0",
41
43
  "react": "^18.2.0",
@@ -58,6 +60,7 @@
58
60
  "@testing-library/jest-dom": "^6.4.2",
59
61
  "@testing-library/react": "^14.2.2",
60
62
  "@testing-library/user-event": "^14.5.2",
63
+ "@types/dompurify": "^3.2.0",
61
64
  "@types/ejs": "^3.1.5",
62
65
  "@types/jest": "^29.5.12",
63
66
  "@types/node": "^20.12.2",