@pdfme/ui 4.2.3 → 4.2.4-dev.1
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 +9049 -9039
- package/dist/index.umd.js +182 -182
- package/dist/types/class.d.ts +0 -3
- package/dist/types/components/Designer/RightSidebar/DetailView/index.d.ts +4 -3
- package/dist/types/helper.d.ts +0 -1
- package/package.json +1 -1
- package/src/components/Designer/LeftSidebar.tsx +6 -3
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +22 -24
- package/src/components/Designer/index.tsx +3 -2
- package/src/helper.ts +1 -1
package/dist/types/class.d.ts
CHANGED
@@ -21,7 +21,6 @@ export declare abstract class BaseUIClass {
|
|
21
21
|
getTemplate(): import("zod").objectOutputType<{
|
22
22
|
schemas: import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
23
23
|
type: import("zod").ZodString;
|
24
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
25
24
|
content: import("zod").ZodOptional<import("zod").ZodString>;
|
26
25
|
position: import("zod").ZodObject<{
|
27
26
|
x: import("zod").ZodNumber;
|
@@ -40,7 +39,6 @@ export declare abstract class BaseUIClass {
|
|
40
39
|
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
41
40
|
}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
|
42
41
|
type: import("zod").ZodString;
|
43
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
44
42
|
content: import("zod").ZodOptional<import("zod").ZodString>;
|
45
43
|
position: import("zod").ZodObject<{
|
46
44
|
x: import("zod").ZodNumber;
|
@@ -59,7 +57,6 @@ export declare abstract class BaseUIClass {
|
|
59
57
|
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
60
58
|
}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
|
61
59
|
type: import("zod").ZodString;
|
62
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
63
60
|
content: import("zod").ZodOptional<import("zod").ZodString>;
|
64
61
|
position: import("zod").ZodObject<{
|
65
62
|
x: import("zod").ZodNumber;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import type { SchemaForUI } from '@pdfme/common';
|
3
3
|
import type { SidebarProps } from '../../../../types';
|
4
|
-
|
4
|
+
type DetailViewProps = Pick<SidebarProps, 'size' | 'schemas' | 'pageSize' | 'changeSchemas' | 'activeElements' | 'deselectSchema'> & {
|
5
5
|
activeSchema: SchemaForUI;
|
6
|
-
}
|
7
|
-
|
6
|
+
};
|
7
|
+
declare const _default: React.MemoExoticComponent<(props: DetailViewProps) => React.JSX.Element>;
|
8
|
+
export default _default;
|
package/dist/types/helper.d.ts
CHANGED
@@ -36,7 +36,6 @@ export declare const template2SchemasList: (_template: Template) => Promise<{
|
|
36
36
|
key: string;
|
37
37
|
opacity?: number | undefined;
|
38
38
|
rotate?: number | undefined;
|
39
|
-
icon?: string | undefined;
|
40
39
|
content?: string | undefined;
|
41
40
|
readOnly?: boolean | undefined;
|
42
41
|
}[][]>;
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@ import { theme, Button } from 'antd';
|
|
8
8
|
import { useDraggable } from '@dnd-kit/core';
|
9
9
|
import { CSS } from "@dnd-kit/utilities";
|
10
10
|
import Renderer from '../Renderer';
|
11
|
-
import { PluginsRegistry } from '../../contexts';
|
11
|
+
import { PluginsRegistry, OptionsContext } from '../../contexts';
|
12
12
|
|
13
13
|
const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf, children: React.ReactNode }) => {
|
14
14
|
const { scale, basePdf, plugin } = props;
|
@@ -44,6 +44,7 @@ const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf
|
|
44
44
|
const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number, basePdf: BasePdf }) => {
|
45
45
|
const { token } = theme.useToken();
|
46
46
|
const pluginsRegistry = useContext(PluginsRegistry);
|
47
|
+
const options = useContext(OptionsContext);
|
47
48
|
|
48
49
|
const [isDragging, setIsDragging] = useState(false);
|
49
50
|
|
@@ -76,6 +77,8 @@ const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number
|
|
76
77
|
>
|
77
78
|
{Object.entries(pluginsRegistry).map(([label, plugin]) => {
|
78
79
|
if (!plugin?.propPanel.defaultSchema) return null;
|
80
|
+
const icon = options.icons?.[plugin.propPanel.defaultSchema.type] ?? plugin.icon;
|
81
|
+
|
79
82
|
return <Draggable
|
80
83
|
key={label}
|
81
84
|
scale={scale}
|
@@ -87,8 +90,8 @@ const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number
|
|
87
90
|
setIsDragging(true);
|
88
91
|
}}
|
89
92
|
style={{ width: 35, height: 35, marginTop: '0.25rem', padding: '0.25rem' }}>
|
90
|
-
{
|
91
|
-
<div dangerouslySetInnerHTML={{ __html:
|
93
|
+
{icon ?
|
94
|
+
<div dangerouslySetInnerHTML={{ __html: icon }} />
|
92
95
|
:
|
93
96
|
<div style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</div>
|
94
97
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import FormRender, { useForm } from 'form-render';
|
2
|
-
import React, { useContext,
|
2
|
+
import React, { useContext, useState, useEffect } from 'react';
|
3
3
|
import type { ChangeSchemaItem, Dict, SchemaForUI, PropPanelWidgetProps, PropPanelSchema } from '@pdfme/common';
|
4
4
|
import type { SidebarProps } from '../../../../types';
|
5
5
|
import { MenuOutlined } from '@ant-design/icons';
|
@@ -13,17 +13,16 @@ import { InternalNamePath, ValidateErrorEntity } from "rc-field-form/es/interfac
|
|
13
13
|
|
14
14
|
const { Text } = Typography;
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
) => {
|
16
|
+
type DetailViewProps = Pick<SidebarProps,
|
17
|
+
'size' | 'schemas' | 'pageSize' | 'changeSchemas' | 'activeElements' | 'deselectSchema'
|
18
|
+
> & {
|
19
|
+
activeSchema: SchemaForUI;
|
20
|
+
};
|
21
|
+
|
22
|
+
const DetailView = (props: DetailViewProps) => {
|
24
23
|
const { token } = theme.useToken();
|
25
24
|
|
26
|
-
const { size, changeSchemas, deselectSchema, activeSchema
|
25
|
+
const { size, changeSchemas, deselectSchema, activeSchema } = props;
|
27
26
|
const form = useForm();
|
28
27
|
|
29
28
|
const i18n = useContext(I18nContext);
|
@@ -58,22 +57,17 @@ const DetailView = (
|
|
58
57
|
});
|
59
58
|
}
|
60
59
|
setWidgets(newWidgets);
|
61
|
-
}, [activeSchema,
|
60
|
+
}, [activeSchema, pluginsRegistry, JSON.stringify(options)]);
|
62
61
|
|
63
62
|
useEffect(() => {
|
64
63
|
const values: any = { ...activeSchema };
|
65
|
-
|
66
64
|
// [position] Change the nested position object into a flat, as a three-column layout is difficult to implement
|
67
65
|
values.x = values.position.x;
|
68
66
|
values.y = values.position.y;
|
69
67
|
delete values.position;
|
70
|
-
|
71
|
-
if (values.key !== (form.getValues() || {}).key) {
|
72
|
-
form.resetFields();
|
73
|
-
}
|
74
|
-
|
75
68
|
form.setValues(values);
|
76
|
-
|
69
|
+
|
70
|
+
}, [activeSchema, form]);
|
77
71
|
|
78
72
|
const handleWatch = (formSchema: any) => {
|
79
73
|
const formAndSchemaValuesDiffer = (formValue: any, schemaValue: any): boolean => {
|
@@ -102,7 +96,7 @@ const DetailView = (
|
|
102
96
|
// FIXME memo: https://github.com/pdfme/pdfme/pull/367#issuecomment-1857468274
|
103
97
|
if (value === null && ['rotate', 'opacity'].includes(key)) value = undefined;
|
104
98
|
|
105
|
-
changes.push({key, value, schemaId: activeSchema.id});
|
99
|
+
changes.push({ key, value, schemaId: activeSchema.id });
|
106
100
|
}
|
107
101
|
}
|
108
102
|
|
@@ -111,11 +105,11 @@ const DetailView = (
|
|
111
105
|
form.validateFields()
|
112
106
|
.then(() => changeSchemas(changes))
|
113
107
|
.catch((reason: ValidateErrorEntity) => {
|
114
|
-
if (reason.errorFields.length)
|
108
|
+
if (reason.errorFields.length) {
|
115
109
|
changes = changes.filter((change: ChangeSchemaItem) => !reason.errorFields.find((field: {
|
116
|
-
|
117
|
-
|
118
|
-
|
110
|
+
name: InternalNamePath;
|
111
|
+
errors: string[];
|
112
|
+
}) => field.name.includes(change.key)
|
119
113
|
));
|
120
114
|
}
|
121
115
|
if (changes.length) {
|
@@ -254,4 +248,8 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
254
248
|
);
|
255
249
|
};
|
256
250
|
|
257
|
-
|
251
|
+
const propsAreUnchanged = (prevProps: DetailViewProps, nextProps: DetailViewProps) => {
|
252
|
+
return JSON.stringify(prevProps.activeSchema) == JSON.stringify(nextProps.activeSchema)
|
253
|
+
};
|
254
|
+
|
255
|
+
export default React.memo(DetailView, propsAreUnchanged);
|
@@ -19,6 +19,7 @@ import { I18nContext, PluginsRegistry } from '../../contexts';
|
|
19
19
|
import {
|
20
20
|
schemasList2template,
|
21
21
|
uuid,
|
22
|
+
round,
|
22
23
|
cloneDeep,
|
23
24
|
template2SchemasList,
|
24
25
|
getPagesScrollTopByIndex,
|
@@ -51,7 +52,7 @@ const TemplateEditor = ({
|
|
51
52
|
onSaveTemplate: (t: Template) => void;
|
52
53
|
onChangeTemplate: (t: Template) => void;
|
53
54
|
} & {
|
54
|
-
onChangeTemplate: (t: Template) => void
|
55
|
+
onChangeTemplate: (t: Template) => void
|
55
56
|
onPageCursorChange: (newPageCursor: number) => void
|
56
57
|
}) => {
|
57
58
|
const past = useRef<SchemaForUI[][]>([]);
|
@@ -253,7 +254,7 @@ const TemplateEditor = ({
|
|
253
254
|
const moveY = (event.delta.y - canvasTopOffsetFromPageCorner) / scale;
|
254
255
|
const moveX = (event.delta.x - canvasLeftOffsetFromPageCorner) / scale;
|
255
256
|
|
256
|
-
const position = { x: px2mm(Math.max(0, moveX)), y: px2mm(Math.max(0, moveY)) }
|
257
|
+
const position = { x: round(px2mm(Math.max(0, moveX)), 2), y: round(px2mm(Math.max(0, moveY)), 2) }
|
257
258
|
|
258
259
|
addSchema({ ...(active.data.current as Schema), position });
|
259
260
|
}}
|
package/src/helper.ts
CHANGED