@pdfme/ui 5.3.11-dev.7 → 5.3.11-dev.8
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 +5670 -5589
- package/dist/index.umd.js +121 -121
- package/dist/types/src/components/Designer/Canvas/Guides.d.ts +3 -9
- package/dist/types/src/components/Designer/Canvas/Moveable.d.ts +2 -49
- package/dist/types/src/components/Designer/Canvas/Selecto.d.ts +5 -16
- package/dist/types/src/components/Designer/PluginIcon.d.ts +2 -2
- package/dist/types/src/components/Designer/RightSidebar/ListView/Item.d.ts +17 -0
- package/dist/types/src/constants.d.ts +1 -1
- package/dist/types/src/contexts.d.ts +1 -1
- package/dist/types/src/helper.d.ts +3 -3
- package/package.json +1 -1
- package/src/components/AppContextProvider.tsx +17 -10
- package/src/components/CtlBar.tsx +2 -2
- package/src/components/Designer/Canvas/Guides.tsx +4 -13
- package/src/components/Designer/Canvas/Moveable.tsx +15 -74
- package/src/components/Designer/Canvas/Selecto.tsx +9 -24
- package/src/components/Designer/Canvas/index.tsx +3 -56
- package/src/components/Designer/LeftSidebar.tsx +2 -2
- package/src/components/Designer/PluginIcon.tsx +14 -3
- package/src/components/Designer/RightSidebar/DetailView/AlignWidget.tsx +91 -16
- package/src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx +12 -8
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +64 -21
- package/src/components/Designer/RightSidebar/ListView/Item.tsx +30 -2
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +23 -4
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +20 -4
- package/src/components/Designer/index.tsx +14 -9
- package/src/components/Preview.tsx +4 -4
- package/src/components/Renderer.tsx +41 -35
- package/src/components/Root.tsx +1 -1
- package/src/constants.ts +1 -1
- package/src/contexts.ts +1 -1
- package/src/helper.ts +131 -38
- package/src/types/react-guides.d.ts +0 -22
- package/src/types/react-selecto.d.ts +0 -35
@@ -1,15 +1,9 @@
|
|
1
1
|
import React, { Ref } from 'react';
|
2
|
+
import GuidesComponent from '@scena/react-guides';
|
2
3
|
import { Size } from '@pdfme/common';
|
3
|
-
interface GuidesInterface {
|
4
|
-
getGuides(): number[];
|
5
|
-
scroll(pos: number): void;
|
6
|
-
scrollGuides(pos: number): void;
|
7
|
-
loadGuides(guides: number[]): void;
|
8
|
-
resize(): void;
|
9
|
-
}
|
10
4
|
declare const _Guides: ({ paperSize, horizontalRef, verticalRef, }: {
|
11
5
|
paperSize: Size;
|
12
|
-
horizontalRef: Ref<
|
13
|
-
verticalRef: Ref<
|
6
|
+
horizontalRef: Ref<GuidesComponent> | undefined;
|
7
|
+
verticalRef: Ref<GuidesComponent> | undefined;
|
14
8
|
}) => React.JSX.Element;
|
15
9
|
export default _Guides;
|
@@ -1,52 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
3
|
-
target: HTMLElement | SVGElement;
|
4
|
-
left: number;
|
5
|
-
top: number;
|
6
|
-
beforeDelta: any;
|
7
|
-
beforeDist: any;
|
8
|
-
beforeTranslate: any;
|
9
|
-
delta: any;
|
10
|
-
dist: any;
|
11
|
-
transform: any;
|
12
|
-
translate: any;
|
13
|
-
}
|
14
|
-
interface OnResize {
|
15
|
-
target: HTMLElement | SVGElement;
|
16
|
-
width: number;
|
17
|
-
height: number;
|
18
|
-
direction: string;
|
19
|
-
offsetWidth: number;
|
20
|
-
offsetHeight: number;
|
21
|
-
dist: any;
|
22
|
-
delta: any;
|
23
|
-
transform: any;
|
24
|
-
translate: any;
|
25
|
-
}
|
26
|
-
interface OnRotate {
|
27
|
-
target: HTMLElement | SVGElement;
|
28
|
-
rotate: number;
|
29
|
-
beforeDist: any;
|
30
|
-
beforeDelta: any;
|
31
|
-
beforeRotate: any;
|
32
|
-
dist: any;
|
33
|
-
delta: any;
|
34
|
-
transform: any;
|
35
|
-
}
|
36
|
-
interface OnRotateEnd {
|
37
|
-
target: HTMLElement | SVGElement;
|
38
|
-
}
|
39
|
-
interface OnClick {
|
40
|
-
inputEvent: MouseEvent;
|
41
|
-
inputTarget: any;
|
42
|
-
isTarget: boolean;
|
43
|
-
containsTarget: boolean;
|
44
|
-
isDouble: boolean;
|
45
|
-
datas: any;
|
46
|
-
targets: any[];
|
47
|
-
clientX: number;
|
48
|
-
clientY: number;
|
49
|
-
}
|
2
|
+
import MoveableComponent, { OnDrag, OnRotate, OnRotateEnd, OnClick, OnResize } from 'react-moveable';
|
50
3
|
type Props = {
|
51
4
|
target: HTMLElement[];
|
52
5
|
bounds: {
|
@@ -80,5 +33,5 @@ type Props = {
|
|
80
33
|
}) => void;
|
81
34
|
onClick: (e: OnClick) => void;
|
82
35
|
};
|
83
|
-
declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<
|
36
|
+
declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<MoveableComponent<{}>>>;
|
84
37
|
export default _default;
|
@@ -1,21 +1,10 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
3
|
-
inputEvent: MouseEvent;
|
4
|
-
stop: () => void;
|
5
|
-
isTrusted: boolean;
|
6
|
-
}
|
7
|
-
interface OnSelect {
|
8
|
-
selected: Element[];
|
9
|
-
added: Element[];
|
10
|
-
removed: Element[];
|
11
|
-
inputEvent: MouseEvent;
|
12
|
-
rect: DOMRect;
|
13
|
-
}
|
2
|
+
import { OnSelect as SelectoOnSelect, OnDragStart as SelectoOnDragStart } from 'react-selecto';
|
14
3
|
type Props = {
|
15
4
|
container: HTMLElement | null;
|
16
5
|
continueSelect: boolean;
|
17
|
-
onDragStart: (e:
|
18
|
-
onSelect: (e:
|
6
|
+
onDragStart: (e: SelectoOnDragStart) => void;
|
7
|
+
onSelect: (e: SelectoOnSelect) => void;
|
19
8
|
};
|
20
|
-
declare const
|
21
|
-
export default
|
9
|
+
declare const Selecto: (props: Props) => React.JSX.Element;
|
10
|
+
export default Selecto;
|
@@ -1,27 +1,44 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { DraggableSyntheticListeners } from '@dnd-kit/core';
|
3
3
|
interface Props {
|
4
|
+
/** Content to display in the item */
|
4
5
|
value: React.ReactNode;
|
6
|
+
/** Optional icon to display */
|
5
7
|
icon?: React.ReactNode;
|
8
|
+
/** Custom styles for the item */
|
6
9
|
style?: React.CSSProperties;
|
10
|
+
/** Status indicator for the item */
|
7
11
|
status?: 'is-warning' | 'is-danger';
|
12
|
+
/** Title attribute for the item */
|
8
13
|
title?: string;
|
14
|
+
/** Whether the item is required */
|
9
15
|
required?: boolean;
|
16
|
+
/** Whether the item is read-only */
|
10
17
|
readOnly?: boolean;
|
18
|
+
/** Whether the item is being dragged as an overlay */
|
11
19
|
dragOverlay?: boolean;
|
20
|
+
/** Click handler for the item */
|
12
21
|
onClick?: () => void;
|
22
|
+
/** Mouse enter handler */
|
13
23
|
onMouseEnter?: () => void;
|
24
|
+
/** Mouse leave handler */
|
14
25
|
onMouseLeave?: () => void;
|
26
|
+
/** Whether the item is currently being dragged */
|
15
27
|
dragging?: boolean;
|
28
|
+
/** Whether items are being sorted */
|
16
29
|
sorting?: boolean;
|
30
|
+
/** CSS transition value */
|
17
31
|
transition?: string;
|
32
|
+
/** Transform data for the item */
|
18
33
|
transform?: {
|
19
34
|
x: number;
|
20
35
|
y: number;
|
21
36
|
scaleX: number;
|
22
37
|
scaleY: number;
|
23
38
|
} | null;
|
39
|
+
/** Whether to fade the item in */
|
24
40
|
fadeIn?: boolean;
|
41
|
+
/** Drag listeners from dnd-kit */
|
25
42
|
listeners?: DraggableSyntheticListeners;
|
26
43
|
}
|
27
44
|
declare const Item: React.MemoExoticComponent<React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLLIElement>>>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export declare const DEFAULT_LANG
|
1
|
+
export declare const DEFAULT_LANG = "en";
|
2
2
|
export declare const DESTROYED_ERR_MSG = "[@pdfme/ui] this instance is already destroyed";
|
3
3
|
export declare const SELECTABLE_CLASSNAME = "selectable";
|
4
4
|
export declare const RULER_HEIGHT = 30;
|
@@ -7,4 +7,4 @@ export declare const FontContext: import("react").Context<Record<string, {
|
|
7
7
|
}>>;
|
8
8
|
export declare const PluginsRegistry: import("react").Context<Plugins>;
|
9
9
|
export declare const OptionsContext: import("react").Context<UIOptions>;
|
10
|
-
export declare const CacheContext: import("react").Context<Map<
|
10
|
+
export declare const CacheContext: import("react").Context<Map<unknown, unknown>>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Template, BasePdf, SchemaForUI, Size, Plugins } from '@pdfme/common';
|
2
2
|
export declare const uuid: () => string;
|
3
|
-
export declare const debounce: <T extends
|
3
|
+
export declare const debounce: <T extends (...args: unknown[]) => unknown>(cb: T, wait?: number) => T;
|
4
4
|
export declare const round: (number: number, precision: number) => number;
|
5
5
|
export declare const flatten: <T>(arr: T[][]) => T[];
|
6
6
|
export declare const initShortCuts: (arg: {
|
@@ -58,7 +58,7 @@ export declare const getSidebarContentHeight: (sidebarHeight: number) => number;
|
|
58
58
|
export declare const changeSchemas: (args: {
|
59
59
|
objs: {
|
60
60
|
key: string;
|
61
|
-
value:
|
61
|
+
value: unknown;
|
62
62
|
schemaId: string;
|
63
63
|
}[];
|
64
64
|
schemas: SchemaForUI[];
|
@@ -70,4 +70,4 @@ export declare const changeSchemas: (args: {
|
|
70
70
|
};
|
71
71
|
commitSchemas: (newSchemas: SchemaForUI[]) => void;
|
72
72
|
}) => void;
|
73
|
-
export declare const
|
73
|
+
export declare const useMaxZoom: () => number;
|
package/package.json
CHANGED
@@ -13,25 +13,32 @@ type Props = {
|
|
13
13
|
options: UIOptions;
|
14
14
|
};
|
15
15
|
|
16
|
-
const isObject = (item:
|
17
|
-
item && typeof item === 'object' && !Array.isArray(item);
|
16
|
+
const isObject = (item: unknown): item is Record<string, unknown> =>
|
17
|
+
Boolean(item) && typeof item === 'object' && !Array.isArray(item);
|
18
18
|
|
19
|
-
const deepMerge = <T extends Record<string,
|
19
|
+
const deepMerge = <T extends Record<string, unknown>, U extends Record<string, unknown>>(
|
20
20
|
target: T,
|
21
21
|
source: U,
|
22
22
|
): T & U => {
|
23
23
|
let output = { ...target } as T & U;
|
24
24
|
|
25
25
|
if (isObject(target) && isObject(source)) {
|
26
|
-
Object.keys(source).forEach((key
|
27
|
-
|
26
|
+
Object.keys(source).forEach((key) => {
|
27
|
+
const sourceValue = source[key];
|
28
|
+
if (isObject(sourceValue)) {
|
28
29
|
if (!(key in target)) {
|
29
|
-
Object.assign(output, { [key]:
|
30
|
+
Object.assign(output, { [key]: sourceValue });
|
30
31
|
} else {
|
31
|
-
|
32
|
+
const targetValue = target[key];
|
33
|
+
if (isObject(targetValue)) {
|
34
|
+
// Using Record<string, unknown> for recursive type
|
35
|
+
(output as Record<string, unknown>)[key] = deepMerge(targetValue, sourceValue);
|
36
|
+
} else {
|
37
|
+
Object.assign(output, { [key]: sourceValue });
|
38
|
+
}
|
32
39
|
}
|
33
40
|
} else {
|
34
|
-
Object.assign(output, { [key]:
|
41
|
+
Object.assign(output, { [key]: sourceValue });
|
35
42
|
}
|
36
43
|
});
|
37
44
|
}
|
@@ -41,12 +48,12 @@ const deepMerge = <T extends Record<string, any>, U extends Record<string, any>>
|
|
41
48
|
const AppContextProvider = ({ children, lang, font, plugins, options }: Props) => {
|
42
49
|
let theme = defaultTheme;
|
43
50
|
if (options.theme) {
|
44
|
-
theme = deepMerge(theme, options.theme);
|
51
|
+
theme = deepMerge(theme as unknown as Record<string, unknown>, options.theme as unknown as Record<string, unknown>) as typeof theme;
|
45
52
|
}
|
46
53
|
|
47
54
|
let dict = getDict(lang);
|
48
55
|
if (options.labels) {
|
49
|
-
dict = deepMerge(dict, options.labels);
|
56
|
+
dict = deepMerge(dict as unknown as Record<string, unknown>, options.labels as unknown as Record<string, unknown>) as typeof dict;
|
50
57
|
}
|
51
58
|
|
52
59
|
return (
|
@@ -7,7 +7,7 @@ import { Plus, Minus, ChevronLeft, ChevronRight, Ellipsis } from 'lucide-react';
|
|
7
7
|
import type { MenuProps } from 'antd';
|
8
8
|
import { theme, Typography, Button, Dropdown } from 'antd';
|
9
9
|
import { I18nContext } from '../contexts.js';
|
10
|
-
import {
|
10
|
+
import { useMaxZoom } from '../helper.js';
|
11
11
|
|
12
12
|
const { Text } = Typography;
|
13
13
|
|
@@ -20,7 +20,7 @@ type ZoomProps = {
|
|
20
20
|
|
21
21
|
const Zoom = ({ zoomLevel, setZoomLevel, style }: ZoomProps) => {
|
22
22
|
const zoomStep = 0.25;
|
23
|
-
const maxZoom =
|
23
|
+
const maxZoom = useMaxZoom();
|
24
24
|
const minZoom = 0.25;
|
25
25
|
|
26
26
|
const nextZoomOut = zoomLevel - zoomStep;
|
@@ -17,23 +17,14 @@ const guideStyle = (
|
|
17
17
|
background: '#333333',
|
18
18
|
});
|
19
19
|
|
20
|
-
// Define the interface for the Guides component
|
21
|
-
interface GuidesInterface {
|
22
|
-
getGuides(): number[];
|
23
|
-
scroll(pos: number): void;
|
24
|
-
scrollGuides(pos: number): void;
|
25
|
-
loadGuides(guides: number[]): void;
|
26
|
-
resize(): void;
|
27
|
-
}
|
28
|
-
|
29
20
|
const _Guides = ({
|
30
21
|
paperSize,
|
31
22
|
horizontalRef,
|
32
23
|
verticalRef,
|
33
24
|
}: {
|
34
25
|
paperSize: Size;
|
35
|
-
horizontalRef: Ref<
|
36
|
-
verticalRef: Ref<
|
26
|
+
horizontalRef: Ref<GuidesComponent> | undefined;
|
27
|
+
verticalRef: Ref<GuidesComponent> | undefined;
|
37
28
|
}) => (
|
38
29
|
<>
|
39
30
|
<div
|
@@ -44,13 +35,13 @@ const _Guides = ({
|
|
44
35
|
zoom={ZOOM}
|
45
36
|
style={guideStyle(-RULER_HEIGHT, 0, RULER_HEIGHT, paperSize.width)}
|
46
37
|
type="horizontal"
|
47
|
-
ref={horizontalRef
|
38
|
+
ref={horizontalRef}
|
48
39
|
/>
|
49
40
|
<GuidesComponent
|
50
41
|
zoom={ZOOM}
|
51
42
|
style={guideStyle(0, -RULER_HEIGHT, paperSize.height, RULER_HEIGHT)}
|
52
43
|
type="vertical"
|
53
|
-
ref={verticalRef
|
44
|
+
ref={verticalRef}
|
54
45
|
/>
|
55
46
|
</>
|
56
47
|
);
|
@@ -1,65 +1,7 @@
|
|
1
1
|
import React, { useEffect, forwardRef, Ref } from 'react';
|
2
|
-
import MoveableComponent from 'react-moveable';
|
2
|
+
import MoveableComponent, { OnDrag, OnRotate, OnRotateEnd, OnClick, OnResize } from 'react-moveable';
|
3
3
|
import { theme } from 'antd';
|
4
4
|
|
5
|
-
// Define the types locally since they're not exported properly
|
6
|
-
interface OnDrag {
|
7
|
-
target: HTMLElement | SVGElement;
|
8
|
-
left: number;
|
9
|
-
top: number;
|
10
|
-
// Add additional properties that might be used in the original library
|
11
|
-
beforeDelta: any;
|
12
|
-
beforeDist: any;
|
13
|
-
beforeTranslate: any;
|
14
|
-
delta: any;
|
15
|
-
dist: any;
|
16
|
-
transform: any;
|
17
|
-
translate: any;
|
18
|
-
}
|
19
|
-
|
20
|
-
interface OnResize {
|
21
|
-
target: HTMLElement | SVGElement;
|
22
|
-
width: number;
|
23
|
-
height: number;
|
24
|
-
direction: string;
|
25
|
-
// Add additional properties that might be used in the original library
|
26
|
-
offsetWidth: number;
|
27
|
-
offsetHeight: number;
|
28
|
-
dist: any;
|
29
|
-
delta: any;
|
30
|
-
transform: any;
|
31
|
-
translate: any;
|
32
|
-
}
|
33
|
-
|
34
|
-
interface OnRotate {
|
35
|
-
target: HTMLElement | SVGElement;
|
36
|
-
rotate: number;
|
37
|
-
// Add additional properties that might be used in the original library
|
38
|
-
beforeDist: any;
|
39
|
-
beforeDelta: any;
|
40
|
-
beforeRotate: any;
|
41
|
-
dist: any;
|
42
|
-
delta: any;
|
43
|
-
transform: any;
|
44
|
-
}
|
45
|
-
|
46
|
-
interface OnRotateEnd {
|
47
|
-
target: HTMLElement | SVGElement;
|
48
|
-
}
|
49
|
-
|
50
|
-
interface OnClick {
|
51
|
-
inputEvent: MouseEvent;
|
52
|
-
// Add additional properties that might be used in the original library
|
53
|
-
inputTarget: any;
|
54
|
-
isTarget: boolean;
|
55
|
-
containsTarget: boolean;
|
56
|
-
isDouble: boolean;
|
57
|
-
datas: any;
|
58
|
-
targets: any[];
|
59
|
-
clientX: number;
|
60
|
-
clientY: number;
|
61
|
-
}
|
62
|
-
|
63
5
|
type Props = {
|
64
6
|
target: HTMLElement[];
|
65
7
|
bounds: { left: number; top: number; bottom: number; right: number };
|
@@ -81,29 +23,28 @@ type Props = {
|
|
81
23
|
|
82
24
|
const className = 'pdfme-moveable';
|
83
25
|
|
84
|
-
const
|
26
|
+
const Moveable = (props: Props, ref: Ref<MoveableComponent>) => {
|
85
27
|
const { token } = theme.useToken();
|
86
28
|
useEffect(() => {
|
87
|
-
const containerElement = document.querySelector(`.${className}`)
|
29
|
+
const containerElement = document.querySelector(`.${className}`);
|
88
30
|
const containerElement2 = document.querySelectorAll(
|
89
31
|
`.${className} .moveable-line`,
|
90
|
-
)
|
91
|
-
if (containerElement) {
|
32
|
+
);
|
33
|
+
if (containerElement instanceof HTMLElement) {
|
92
34
|
containerElement.style.setProperty('--moveable-color', token.colorPrimary);
|
93
|
-
Array.from(containerElement2).
|
94
|
-
e
|
95
|
-
|
35
|
+
Array.from(containerElement2).forEach((e) => {
|
36
|
+
if (e instanceof HTMLElement) {
|
37
|
+
e.style.setProperty('--moveable-color', token.colorPrimary);
|
38
|
+
}
|
39
|
+
});
|
96
40
|
}
|
97
|
-
}, [props.target]);
|
41
|
+
}, [props.target, token.colorPrimary]);
|
98
42
|
|
99
43
|
return (
|
100
|
-
// @ts-ignore
|
101
44
|
<MoveableComponent
|
102
|
-
style={{ zIndex: 1 }}
|
103
45
|
className={className}
|
104
46
|
rootContainer={document ? document.body : undefined}
|
105
47
|
snappable
|
106
|
-
snapCenter
|
107
48
|
draggable
|
108
49
|
rotatable={props.rotatable}
|
109
50
|
resizable
|
@@ -118,18 +59,18 @@ const _Moveable = (props: Props, ref: Ref<any>) => {
|
|
118
59
|
keepRatio={props.keepRatio}
|
119
60
|
onRotate={props.onRotate}
|
120
61
|
onRotateEnd={props.onRotateEnd}
|
121
|
-
onRotateGroup={({ events }: { events:
|
62
|
+
onRotateGroup={({ events }: { events: OnRotate[] }) => {
|
122
63
|
events.forEach(props.onRotate);
|
123
64
|
}}
|
124
65
|
onRotateGroupEnd={props.onRotateGroupEnd}
|
125
66
|
onDrag={props.onDrag}
|
126
|
-
onDragGroup={({ events }: { events:
|
67
|
+
onDragGroup={({ events }: { events: OnDrag[] }) => {
|
127
68
|
events.forEach(props.onDrag);
|
128
69
|
}}
|
129
70
|
onDragEnd={props.onDragEnd}
|
130
71
|
onDragGroupEnd={props.onDragGroupEnd}
|
131
72
|
onResize={props.onResize}
|
132
|
-
onResizeGroup={({ events }: { events:
|
73
|
+
onResizeGroup={({ events }: { events: OnResize[] }) => {
|
133
74
|
events.forEach(props.onResize);
|
134
75
|
}}
|
135
76
|
onResizeEnd={props.onResizeEnd}
|
@@ -139,4 +80,4 @@ const _Moveable = (props: Props, ref: Ref<any>) => {
|
|
139
80
|
);
|
140
81
|
};
|
141
82
|
|
142
|
-
export default forwardRef<
|
83
|
+
export default forwardRef<MoveableComponent, Props>(Moveable);
|
@@ -1,42 +1,27 @@
|
|
1
1
|
import React, { useEffect } from 'react';
|
2
|
-
import SelectoComponent from 'react-selecto';
|
2
|
+
import SelectoComponent, { OnSelect as SelectoOnSelect, OnDragStart as SelectoOnDragStart } from 'react-selecto';
|
3
3
|
import { SELECTABLE_CLASSNAME } from '../../../constants.js';
|
4
4
|
import { theme } from 'antd';
|
5
5
|
|
6
|
-
// Define the types locally to match what's expected in Canvas/index.tsx
|
7
|
-
interface OnDragStart {
|
8
|
-
inputEvent: MouseEvent;
|
9
|
-
stop: () => void;
|
10
|
-
isTrusted: boolean;
|
11
|
-
}
|
12
|
-
|
13
|
-
interface OnSelect {
|
14
|
-
selected: Element[];
|
15
|
-
added: Element[];
|
16
|
-
removed: Element[];
|
17
|
-
inputEvent: MouseEvent;
|
18
|
-
rect: DOMRect;
|
19
|
-
}
|
20
|
-
|
21
6
|
type Props = {
|
22
7
|
container: HTMLElement | null;
|
23
8
|
continueSelect: boolean;
|
24
|
-
onDragStart: (e:
|
25
|
-
onSelect: (e:
|
9
|
+
onDragStart: (e: SelectoOnDragStart) => void;
|
10
|
+
onSelect: (e: SelectoOnSelect) => void;
|
26
11
|
};
|
27
12
|
|
28
13
|
const className = 'pdfme-selecto';
|
29
14
|
|
30
|
-
const
|
15
|
+
const Selecto = (props: Props) => {
|
31
16
|
const { token } = theme.useToken();
|
32
17
|
useEffect(() => {
|
33
|
-
const containerElement = document.querySelector('.' + className)
|
34
|
-
if (containerElement) {
|
18
|
+
const containerElement = document.querySelector('.' + className);
|
19
|
+
if (containerElement instanceof HTMLElement) {
|
35
20
|
containerElement.style.backgroundColor = token.colorPrimary;
|
36
21
|
containerElement.style.opacity = '0.75';
|
37
22
|
containerElement.style.borderColor = token.colorPrimaryBorder;
|
38
23
|
}
|
39
|
-
}, [props.container]);
|
24
|
+
}, [props.container, token.colorPrimary, token.colorPrimaryBorder]);
|
40
25
|
|
41
26
|
return (
|
42
27
|
<SelectoComponent
|
@@ -49,9 +34,9 @@ const _Selecto = (props: Props) => {
|
|
49
34
|
container={props.container}
|
50
35
|
continueSelect={props.continueSelect}
|
51
36
|
onDragStart={props.onDragStart}
|
52
|
-
onSelect={
|
37
|
+
onSelect={props.onSelect}
|
53
38
|
/>
|
54
39
|
);
|
55
40
|
};
|
56
41
|
|
57
|
-
export default
|
42
|
+
export default Selecto;
|
@@ -10,6 +10,7 @@ import React, {
|
|
10
10
|
useCallback,
|
11
11
|
} from 'react';
|
12
12
|
import { theme, Button } from 'antd';
|
13
|
+
import MoveableComponent, { OnDrag, OnRotate, OnRotateEnd, OnClick, OnResize } from 'react-moveable';
|
13
14
|
import {
|
14
15
|
ZOOM,
|
15
16
|
SchemaForUI,
|
@@ -33,60 +34,6 @@ import Mask from './Mask.js';
|
|
33
34
|
import Padding from './Padding.js';
|
34
35
|
import StaticSchema from '../../StaticSchema.js';
|
35
36
|
|
36
|
-
// Define the interfaces locally since they're not exported properly
|
37
|
-
interface OnDrag {
|
38
|
-
target: HTMLElement | SVGElement;
|
39
|
-
left: number;
|
40
|
-
top: number;
|
41
|
-
// Add additional properties that might be used in the original library
|
42
|
-
beforeDelta: any;
|
43
|
-
beforeDist: any;
|
44
|
-
beforeTranslate: any;
|
45
|
-
delta: any;
|
46
|
-
dist: any;
|
47
|
-
transform: any;
|
48
|
-
translate: any;
|
49
|
-
}
|
50
|
-
|
51
|
-
interface OnResize {
|
52
|
-
target: HTMLElement | SVGElement;
|
53
|
-
width: number;
|
54
|
-
height: number;
|
55
|
-
direction: string;
|
56
|
-
// Add additional properties that might be used in the original library
|
57
|
-
offsetWidth: number;
|
58
|
-
offsetHeight: number;
|
59
|
-
dist: any;
|
60
|
-
delta: any;
|
61
|
-
transform: any;
|
62
|
-
translate: any;
|
63
|
-
}
|
64
|
-
|
65
|
-
interface OnRotate {
|
66
|
-
target: HTMLElement | SVGElement;
|
67
|
-
rotate: number;
|
68
|
-
// Add additional properties that might be used in the original library
|
69
|
-
beforeDist: any;
|
70
|
-
beforeDelta: any;
|
71
|
-
beforeRotate: any;
|
72
|
-
dist: any;
|
73
|
-
delta: any;
|
74
|
-
transform: any;
|
75
|
-
}
|
76
|
-
|
77
|
-
interface OnClick {
|
78
|
-
inputEvent: MouseEvent;
|
79
|
-
// Add additional properties that might be used in the original library
|
80
|
-
inputTarget: any;
|
81
|
-
isTarget: boolean;
|
82
|
-
containsTarget: boolean;
|
83
|
-
isDouble: boolean;
|
84
|
-
datas: any;
|
85
|
-
targets: any[];
|
86
|
-
clientX: number;
|
87
|
-
clientY: number;
|
88
|
-
}
|
89
|
-
|
90
37
|
const mm2px = (mm: number) => mm * 3.7795275591;
|
91
38
|
|
92
39
|
const DELETE_BTN_ID = uuid();
|
@@ -175,7 +122,7 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
175
122
|
const pluginsRegistry = useContext(PluginsRegistry);
|
176
123
|
const verticalGuides = useRef<GuidesInterface[]>([]);
|
177
124
|
const horizontalGuides = useRef<GuidesInterface[]>([]);
|
178
|
-
const moveable = useRef<
|
125
|
+
const moveable = useRef<MoveableComponent>(null);
|
179
126
|
|
180
127
|
const [isPressShiftKey, setIsPressShiftKey] = useState(false);
|
181
128
|
const [editing, setEditing] = useState(false);
|
@@ -408,7 +355,7 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
408
355
|
continueSelect={isPressShiftKey}
|
409
356
|
onDragStart={(e) => {
|
410
357
|
const { inputEvent } = e;
|
411
|
-
const isMoveableElement = moveable.current?.isMoveableElement(inputEvent.target);
|
358
|
+
const isMoveableElement = moveable.current?.isMoveableElement(inputEvent.target as Element);
|
412
359
|
if ((inputEvent.type === 'touchstart' && e.isTrusted) || isMoveableElement) {
|
413
360
|
e.stop();
|
414
361
|
}
|
@@ -9,14 +9,14 @@ import { PluginsRegistry } from '../../contexts.js';
|
|
9
9
|
import PluginIcon from './PluginIcon.js';
|
10
10
|
|
11
11
|
const Draggable = (props: {
|
12
|
-
plugin: Plugin<
|
12
|
+
plugin: Plugin<Schema>;
|
13
13
|
scale: number;
|
14
14
|
basePdf: BasePdf;
|
15
15
|
children: React.ReactNode;
|
16
16
|
}) => {
|
17
17
|
const { scale, basePdf, plugin } = props;
|
18
18
|
const { token } = theme.useToken();
|
19
|
-
const defaultSchema = plugin.propPanel.defaultSchema
|
19
|
+
const defaultSchema = plugin.propPanel.defaultSchema;
|
20
20
|
const draggable = useDraggable({ id: defaultSchema.type, data: defaultSchema });
|
21
21
|
const { listeners, setNodeRef, attributes, transform, isDragging } = draggable;
|
22
22
|
const style = { transform: CSS.Translate.toString(transform) };
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import React, { useContext } from 'react';
|
2
|
-
import { Plugin } from '@pdfme/common';
|
2
|
+
import { Plugin, Schema } from '@pdfme/common';
|
3
3
|
import { OptionsContext } from '../../contexts.js';
|
4
4
|
import { theme } from 'antd';
|
5
5
|
|
6
6
|
interface PluginIconProps {
|
7
|
-
plugin: Plugin<
|
7
|
+
plugin: Plugin<Schema>;
|
8
8
|
label: string;
|
9
9
|
size?: number;
|
10
10
|
styles?: React.CSSProperties;
|
@@ -38,7 +38,18 @@ const PluginIcon = (props: PluginIconProps) => {
|
|
38
38
|
const { plugin, label, size, styles } = props;
|
39
39
|
const { token } = theme.useToken();
|
40
40
|
const options = useContext(OptionsContext);
|
41
|
-
|
41
|
+
|
42
|
+
// Safely access plugin properties with proper type checking
|
43
|
+
const defaultSchemaType = plugin.propPanel &&
|
44
|
+
typeof plugin.propPanel === 'object' &&
|
45
|
+
plugin.propPanel.defaultSchema &&
|
46
|
+
typeof plugin.propPanel.defaultSchema === 'object' &&
|
47
|
+
'type' in plugin.propPanel.defaultSchema &&
|
48
|
+
typeof plugin.propPanel.defaultSchema.type === 'string'
|
49
|
+
? plugin.propPanel.defaultSchema.type
|
50
|
+
: '';
|
51
|
+
|
52
|
+
const icon = options.icons?.[defaultSchemaType] ?? plugin.icon;
|
42
53
|
const iconStyles = {
|
43
54
|
...styles,
|
44
55
|
color: token.colorText,
|