@pdfme/ui 5.4.2 → 5.4.3-dev.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/dist/index.es.js +21049 -20508
- package/dist/index.umd.js +150 -149
- package/dist/types/__tests__/components/PluginIcon.test.d.ts +1 -0
- package/package.json +3 -1
- package/src/components/Designer/PluginIcon.tsx +42 -21
@@ -0,0 +1 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/ui",
|
3
|
-
"version": "5.4.2",
|
3
|
+
"version": "5.4.3-dev.2",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -41,6 +41,7 @@
|
|
41
41
|
"@pdfme/converter": "*",
|
42
42
|
"@scena/react-guides": "^0.28.2",
|
43
43
|
"antd": "^5.26.3",
|
44
|
+
"dompurify": "^3.2.6",
|
44
45
|
"form-render": "^2.5.3",
|
45
46
|
"globrex": "^0.1.2",
|
46
47
|
"hotkeys-js": "^3.13.14",
|
@@ -56,6 +57,7 @@
|
|
56
57
|
"@pdfme/schemas": "*",
|
57
58
|
"@testing-library/jest-dom": "^6.6.3",
|
58
59
|
"@testing-library/react": "^12.1.2",
|
60
|
+
"@types/dompurify": "^3.0.5",
|
59
61
|
"@types/jest": "^30.0.0",
|
60
62
|
"@types/react": "^17.0.52",
|
61
63
|
"@types/react-dom": "^17.0.18",
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import React, { useContext } from 'react';
|
1
|
+
import React, { useContext, useMemo } from 'react';
|
2
2
|
import { Plugin, Schema } from '@pdfme/common';
|
3
3
|
import { OptionsContext } from '../../contexts.js';
|
4
4
|
import { theme } from 'antd';
|
5
|
+
import DOMPurify from 'dompurify';
|
5
6
|
|
6
7
|
interface PluginIconProps {
|
7
8
|
plugin: Plugin<Schema>;
|
@@ -10,27 +11,50 @@ interface PluginIconProps {
|
|
10
11
|
styles?: React.CSSProperties;
|
11
12
|
}
|
12
13
|
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
) => {
|
19
|
-
const
|
20
|
-
|
14
|
+
const SVGIcon = ({ svgString, size, styles, label }: {
|
15
|
+
svgString: string;
|
16
|
+
size?: number;
|
17
|
+
styles?: React.CSSProperties;
|
18
|
+
label: string;
|
19
|
+
}) => {
|
20
|
+
const processedSVG = useMemo(() => {
|
21
|
+
// First sanitize the SVG string using DOMPurify with SVG profile
|
22
|
+
const sanitizedSVG = DOMPurify.sanitize(svgString, {
|
23
|
+
USE_PROFILES: { svg: true, svgFilters: true },
|
24
|
+
ALLOWED_TAGS: ['svg', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline', 'ellipse', 'g', 'defs', 'title', 'desc', 'metadata'],
|
25
|
+
ALLOWED_ATTR: ['class', 'id', 'fill', 'stroke', 'stroke-width', 'viewBox', 'width', 'height', 'd', 'cx', 'cy', 'r', 'x', 'y', 'x1', 'y1', 'x2', 'y2', 'points', 'rx', 'ry', 'transform'],
|
26
|
+
FORBID_TAGS: ['script', 'foreignObject', 'use', 'embed', 'iframe', 'object', 'link', 'style'],
|
27
|
+
FORBID_ATTR: ['onload', 'onerror', 'onclick', 'onmouseover', 'onfocus', 'onblur', 'href', 'xlink:href', 'src', 'action', 'formaction'],
|
28
|
+
KEEP_CONTENT: false
|
29
|
+
});
|
21
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
const parser = new DOMParser();
|
32
|
+
const doc = parser.parseFromString(sanitizedSVG, 'image/svg+xml');
|
33
|
+
|
34
|
+
const svgElement = doc.querySelector('svg');
|
35
|
+
if (!svgElement) {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Apply size attributes if specified
|
40
|
+
if (size) {
|
41
|
+
svgElement.setAttribute('width', size.toString());
|
42
|
+
svgElement.setAttribute('height', size.toString());
|
26
43
|
}
|
27
|
-
Array.from(node.children).forEach((child) => modifyNode(child as HTMLElement));
|
28
|
-
};
|
29
44
|
|
30
|
-
|
45
|
+
return svgElement.outerHTML;
|
46
|
+
}, [svgString, size]);
|
47
|
+
|
48
|
+
if (!processedSVG) {
|
49
|
+
return null;
|
50
|
+
}
|
31
51
|
|
32
52
|
return (
|
33
|
-
<div
|
53
|
+
<div
|
54
|
+
style={styles}
|
55
|
+
title={label}
|
56
|
+
dangerouslySetInnerHTML={{ __html: processedSVG }}
|
57
|
+
/>
|
34
58
|
);
|
35
59
|
};
|
36
60
|
|
@@ -50,10 +74,7 @@ const PluginIcon = (props: PluginIconProps) => {
|
|
50
74
|
};
|
51
75
|
|
52
76
|
if (icon) {
|
53
|
-
|
54
|
-
return getWithModifiedSize(icon, label, size, iconStyles);
|
55
|
-
}
|
56
|
-
return <div style={iconStyles} title={label} dangerouslySetInnerHTML={{ __html: icon }} />;
|
77
|
+
return <SVGIcon svgString={icon} size={size} styles={iconStyles} label={label} />;
|
57
78
|
}
|
58
79
|
|
59
80
|
return (
|