@pdfme/ui 5.3.8 → 5.3.9
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/__mocks__/lucide-react.js +19 -0
- package/dist/index.es.js +110046 -107269
- package/dist/index.umd.js +585 -556
- package/dist/types/__tests__/assets/helper.d.ts +3 -0
- package/dist/types/__tests__/components/Designer.test.d.ts +1 -0
- package/dist/types/__tests__/components/Preview.test.d.ts +1 -0
- package/dist/types/__tests__/helper.test.d.ts +1 -0
- package/dist/types/{Designer.d.ts → src/Designer.d.ts} +1 -1
- package/dist/types/{Form.d.ts → src/Form.d.ts} +1 -1
- package/dist/types/{Viewer.d.ts → src/Viewer.d.ts} +1 -1
- package/dist/types/{class.d.ts → src/class.d.ts} +2 -2
- package/dist/types/src/components/Designer/Canvas/Guides.d.ts +15 -0
- package/dist/types/{components → src/components}/Designer/Canvas/Moveable.d.ts +48 -1
- package/dist/types/src/components/Designer/Canvas/Selecto.d.ts +21 -0
- package/dist/types/{components → src/components}/Designer/LeftSidebar.d.ts +1 -1
- package/dist/types/{components → src/components}/Designer/PluginIcon.d.ts +1 -1
- package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/index.d.ts +1 -1
- package/dist/types/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.d.ts +4 -0
- package/dist/types/src/components/Designer/RightSidebar/ListView/index.d.ts +4 -0
- package/dist/types/{components → src/components}/Designer/RightSidebar/index.d.ts +1 -1
- package/dist/types/{components → src/components}/Paper.d.ts +1 -1
- package/dist/types/{components → src/components}/Preview.d.ts +2 -2
- package/dist/types/src/contexts.d.ts +10 -0
- package/dist/types/{helper.d.ts → src/helper.d.ts} +2 -4
- package/dist/types/src/index.d.ts +4 -0
- package/eslint.config.mjs +41 -0
- package/package.json +21 -15
- package/src/Designer.tsx +7 -7
- package/src/Form.tsx +4 -6
- package/src/Viewer.tsx +4 -4
- package/src/components/AppContextProvider.tsx +4 -4
- package/src/components/CtlBar.tsx +4 -2
- package/src/components/Designer/Canvas/Guides.tsx +18 -9
- package/src/components/Designer/Canvas/Mask.tsx +1 -1
- package/src/components/Designer/Canvas/Moveable.tsx +66 -7
- package/src/components/Designer/Canvas/Padding.tsx +10 -8
- package/src/components/Designer/Canvas/Selecto.tsx +21 -6
- package/src/components/Designer/Canvas/index.tsx +95 -28
- package/src/components/Designer/LeftSidebar.tsx +60 -52
- package/src/components/Designer/PluginIcon.tsx +22 -9
- package/src/components/Designer/RightSidebar/DetailView/AlignWidget.tsx +45 -45
- package/src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx +3 -3
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +62 -31
- package/src/components/Designer/RightSidebar/ListView/Item.tsx +5 -5
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +60 -51
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +5 -6
- package/src/components/Designer/RightSidebar/ListView/index.tsx +15 -8
- package/src/components/Designer/RightSidebar/index.tsx +4 -4
- package/src/components/Designer/index.tsx +51 -29
- package/src/components/ErrorScreen.tsx +2 -2
- package/src/components/Paper.tsx +2 -2
- package/src/components/Preview.tsx +35 -24
- package/src/components/Renderer.tsx +42 -29
- package/src/components/Root.tsx +4 -6
- package/src/components/Spinner.tsx +1 -1
- package/src/components/StaticSchema.tsx +41 -23
- package/src/constants.ts +1 -1
- package/src/contexts.ts +2 -2
- package/src/helper.ts +37 -17
- package/src/hooks.ts +16 -8
- package/src/index.ts +3 -3
- package/src/types/react-guides.d.ts +22 -0
- package/src/types/react-selecto.d.ts +35 -0
- package/tsconfig.json +10 -12
- package/.eslintrc.cjs +0 -16
- package/dist/types/components/Designer/Canvas/Guides.d.ts +0 -9
- package/dist/types/components/Designer/Canvas/Selecto.d.ts +0 -10
- package/dist/types/components/Designer/RightSidebar/ListView/SelectableSortableContainer.d.ts +0 -4
- package/dist/types/components/Designer/RightSidebar/ListView/index.d.ts +0 -4
- package/dist/types/contexts.d.ts +0 -85
- package/dist/types/index.d.ts +0 -4
- /package/dist/types/{components → src/components}/AppContextProvider.d.ts +0 -0
- /package/dist/types/{components → src/components}/CtlBar.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/Canvas/Mask.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/Canvas/Padding.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/Canvas/index.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/AlignWidget.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/ButtonGroupWidget.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/WidgetRenderer.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/RightSidebar/ListView/Item.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/RightSidebar/ListView/SelectableSortableItem.d.ts +0 -0
- /package/dist/types/{components → src/components}/Designer/index.d.ts +0 -0
- /package/dist/types/{components → src/components}/ErrorScreen.d.ts +0 -0
- /package/dist/types/{components → src/components}/Renderer.d.ts +0 -0
- /package/dist/types/{components → src/components}/Root.d.ts +0 -0
- /package/dist/types/{components → src/components}/Spinner.d.ts +0 -0
- /package/dist/types/{components → src/components}/StaticSchema.d.ts +0 -0
- /package/dist/types/{components → src/components}/UnitPager.d.ts +0 -0
- /package/dist/types/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/dist/types/{hooks.d.ts → src/hooks.d.ts} +0 -0
- /package/dist/types/{i18n.d.ts → src/i18n.d.ts} +0 -0
- /package/dist/types/{theme.d.ts → src/theme.d.ts} +0 -0
- /package/dist/types/{types.d.ts → src/types.d.ts} +0 -0
- /package/{vite.config.ts → vite.config.mts} +0 -0
@@ -1,7 +1,65 @@
|
|
1
1
|
import React, { useEffect, forwardRef, Ref } from 'react';
|
2
|
-
import
|
2
|
+
import MoveableComponent 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
|
+
|
5
63
|
type Props = {
|
6
64
|
target: HTMLElement[];
|
7
65
|
bounds: { left: number; top: number; bottom: number; right: number };
|
@@ -28,18 +86,19 @@ const _Moveable = (props: Props, ref: Ref<any>) => {
|
|
28
86
|
useEffect(() => {
|
29
87
|
const containerElement = document.querySelector(`.${className}`) as HTMLElement | null;
|
30
88
|
const containerElement2 = document.querySelectorAll(
|
31
|
-
`.${className} .moveable-line
|
89
|
+
`.${className} .moveable-line`,
|
32
90
|
) as NodeListOf<HTMLElement>;
|
33
91
|
if (containerElement) {
|
34
92
|
containerElement.style.setProperty('--moveable-color', token.colorPrimary);
|
35
93
|
Array.from(containerElement2).map((e) =>
|
36
|
-
e.style.setProperty('--moveable-color', token.colorPrimary)
|
94
|
+
e.style.setProperty('--moveable-color', token.colorPrimary),
|
37
95
|
);
|
38
96
|
}
|
39
97
|
}, [props.target]);
|
40
98
|
|
41
99
|
return (
|
42
|
-
|
100
|
+
// @ts-ignore
|
101
|
+
<MoveableComponent
|
43
102
|
style={{ zIndex: 1 }}
|
44
103
|
className={className}
|
45
104
|
rootContainer={document ? document.body : undefined}
|
@@ -59,18 +118,18 @@ const _Moveable = (props: Props, ref: Ref<any>) => {
|
|
59
118
|
keepRatio={props.keepRatio}
|
60
119
|
onRotate={props.onRotate}
|
61
120
|
onRotateEnd={props.onRotateEnd}
|
62
|
-
onRotateGroup={({ events }) => {
|
121
|
+
onRotateGroup={({ events }: { events: any[] }) => {
|
63
122
|
events.forEach(props.onRotate);
|
64
123
|
}}
|
65
124
|
onRotateGroupEnd={props.onRotateGroupEnd}
|
66
125
|
onDrag={props.onDrag}
|
67
|
-
onDragGroup={({ events }) => {
|
126
|
+
onDragGroup={({ events }: { events: any[] }) => {
|
68
127
|
events.forEach(props.onDrag);
|
69
128
|
}}
|
70
129
|
onDragEnd={props.onDragEnd}
|
71
130
|
onDragGroupEnd={props.onDragGroupEnd}
|
72
131
|
onResize={props.onResize}
|
73
|
-
onResizeGroup={({ events }) => {
|
132
|
+
onResizeGroup={({ events }: { events: any[] }) => {
|
74
133
|
events.forEach(props.onResize);
|
75
134
|
}}
|
76
135
|
onResizeEnd={props.onResizeEnd}
|
@@ -43,12 +43,14 @@ const getPaddingStyle = (i: number, p: number, color: string): CSS.Properties =>
|
|
43
43
|
};
|
44
44
|
|
45
45
|
const Padding = ({ basePdf }: { basePdf: BasePdf }) => {
|
46
|
-
return
|
47
|
-
|
48
|
-
basePdf
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
return (
|
47
|
+
<>
|
48
|
+
{isBlankPdf(basePdf) &&
|
49
|
+
basePdf.padding.map((p, i) => (
|
50
|
+
<div key={String(i)} style={getPaddingStyle(i, p, theme.useToken().token.colorError)} />
|
51
|
+
))}
|
52
|
+
</>
|
53
|
+
);
|
54
|
+
};
|
53
55
|
|
54
|
-
export default Padding;
|
56
|
+
export default Padding;
|
@@ -1,13 +1,28 @@
|
|
1
1
|
import React, { useEffect } from 'react';
|
2
|
-
import
|
3
|
-
import { SELECTABLE_CLASSNAME } from '../../../constants';
|
2
|
+
import SelectoComponent from 'react-selecto';
|
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
|
+
|
6
21
|
type Props = {
|
7
22
|
container: HTMLElement | null;
|
8
23
|
continueSelect: boolean;
|
9
|
-
onDragStart: (e:
|
10
|
-
onSelect: (e:
|
24
|
+
onDragStart: (e: OnDragStart) => void;
|
25
|
+
onSelect: (e: OnSelect) => void;
|
11
26
|
};
|
12
27
|
|
13
28
|
const className = 'pdfme-selecto';
|
@@ -24,7 +39,7 @@ const _Selecto = (props: Props) => {
|
|
24
39
|
}, [props.container]);
|
25
40
|
|
26
41
|
return (
|
27
|
-
<
|
42
|
+
<SelectoComponent
|
28
43
|
className={className}
|
29
44
|
selectFromInside={false}
|
30
45
|
selectByClick
|
@@ -34,7 +49,7 @@ const _Selecto = (props: Props) => {
|
|
34
49
|
container={props.container}
|
35
50
|
continueSelect={props.continueSelect}
|
36
51
|
onDragStart={props.onDragStart}
|
37
|
-
onSelect={props.onSelect}
|
52
|
+
onSelect={(e: any) => props.onSelect(e as OnSelect)}
|
38
53
|
/>
|
39
54
|
);
|
40
55
|
};
|
@@ -10,25 +10,84 @@ import React, {
|
|
10
10
|
useCallback,
|
11
11
|
} from 'react';
|
12
12
|
import { theme, Button } from 'antd';
|
13
|
-
import {
|
14
|
-
|
15
|
-
|
13
|
+
import {
|
14
|
+
ZOOM,
|
15
|
+
SchemaForUI,
|
16
|
+
Size,
|
17
|
+
ChangeSchemas,
|
18
|
+
BasePdf,
|
19
|
+
isBlankPdf,
|
20
|
+
replacePlaceholders,
|
21
|
+
} from '@pdfme/common';
|
22
|
+
import { PluginsRegistry } from '../../../contexts.js';
|
16
23
|
import { X } from 'lucide-react';
|
17
|
-
import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH } from '../../../constants';
|
18
|
-
import { usePrevious } from '../../../hooks';
|
19
|
-
import { uuid, round, flatten } from '../../../helper';
|
20
|
-
import Paper from '../../Paper';
|
21
|
-
import Renderer from '../../Renderer';
|
22
|
-
import Selecto from './Selecto';
|
23
|
-
import Moveable from './Moveable';
|
24
|
-
import Guides from './Guides';
|
25
|
-
import Mask from './Mask';
|
26
|
-
import Padding from './Padding';
|
27
|
-
import StaticSchema from '../../StaticSchema';
|
24
|
+
import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH } from '../../../constants.js';
|
25
|
+
import { usePrevious } from '../../../hooks.js';
|
26
|
+
import { uuid, round, flatten } from '../../../helper.js';
|
27
|
+
import Paper from '../../Paper.js';
|
28
|
+
import Renderer from '../../Renderer.js';
|
29
|
+
import Selecto from './Selecto.js';
|
30
|
+
import Moveable from './Moveable.js';
|
31
|
+
import Guides from './Guides.js';
|
32
|
+
import Mask from './Mask.js';
|
33
|
+
import Padding from './Padding.js';
|
34
|
+
import StaticSchema from '../../StaticSchema.js';
|
35
|
+
|
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
|
+
}
|
28
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
|
+
}
|
29
64
|
|
30
|
-
|
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
|
+
}
|
31
89
|
|
90
|
+
const mm2px = (mm: number) => mm * 3.7795275591;
|
32
91
|
|
33
92
|
const DELETE_BTN_ID = uuid();
|
34
93
|
const fmt4Num = (prop: string) => Number(prop.replace('px', ''));
|
@@ -321,16 +380,16 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
321
380
|
|
322
381
|
const rotatable = useMemo(() => {
|
323
382
|
const selectedSchemas = (schemasList[pageCursor] || []).filter((s) =>
|
324
|
-
activeElements.map((ae) => ae.id).includes(s.id)
|
383
|
+
activeElements.map((ae) => ae.id).includes(s.id),
|
325
384
|
);
|
326
385
|
const schemaTypes = selectedSchemas.map((s) => s.type);
|
327
386
|
const uniqueSchemaTypes = [...new Set(schemaTypes)];
|
328
387
|
const defaultSchemas = Object.values(pluginsRegistry).map(
|
329
|
-
(plugin) => plugin?.propPanel.defaultSchema
|
388
|
+
(plugin) => plugin?.propPanel.defaultSchema,
|
330
389
|
);
|
331
390
|
|
332
391
|
return uniqueSchemaTypes.every(
|
333
|
-
(type) => defaultSchemas.find((ds) => ds.type === type)?.rotate !== undefined
|
392
|
+
(type) => defaultSchemas.find((ds) => ds.type === type)?.rotate !== undefined,
|
334
393
|
);
|
335
394
|
}, [activeElements, pageCursor, schemasList, pluginsRegistry]);
|
336
395
|
|
@@ -357,7 +416,9 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
357
416
|
if (paperRefs.current[pageCursor] === inputEvent.target) {
|
358
417
|
onEdit([]);
|
359
418
|
}
|
360
|
-
if
|
419
|
+
// Check if the target is an HTMLElement and has an id property
|
420
|
+
const targetElement = inputEvent.target as HTMLElement;
|
421
|
+
if (targetElement && targetElement.id === DELETE_BTN_ID) {
|
361
422
|
removeSchemas(activeElements.map((ae) => ae.id));
|
362
423
|
}
|
363
424
|
}}
|
@@ -398,7 +459,7 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
398
459
|
<StaticSchema
|
399
460
|
template={{ schemas: schemasList, basePdf }}
|
400
461
|
input={Object.fromEntries(
|
401
|
-
schemasList.flat().map(({ name, content = '' }) => [name, content])
|
462
|
+
schemasList.flat().map(({ name, content = '' }) => [name, content]),
|
402
463
|
)}
|
403
464
|
scale={scale}
|
404
465
|
totalPages={schemasList.length}
|
@@ -447,17 +508,20 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
447
508
|
const mode =
|
448
509
|
editing && activeElements.map((ae) => ae.id).includes(schema.id)
|
449
510
|
? 'designer'
|
450
|
-
: 'viewer'
|
511
|
+
: 'viewer';
|
451
512
|
|
452
513
|
const content = schema.content || '';
|
453
514
|
let value = content;
|
454
515
|
|
455
516
|
if (mode !== 'designer' && schema.readOnly) {
|
456
517
|
const variables = {
|
457
|
-
...schemasList.flat().reduce(
|
458
|
-
acc
|
459
|
-
|
460
|
-
|
518
|
+
...schemasList.flat().reduce(
|
519
|
+
(acc, currSchema) => {
|
520
|
+
acc[currSchema.name] = currSchema.content || '';
|
521
|
+
return acc;
|
522
|
+
},
|
523
|
+
{} as Record<string, string>,
|
524
|
+
),
|
461
525
|
totalPages: schemasList.length,
|
462
526
|
currentPage: index + 1,
|
463
527
|
};
|
@@ -478,11 +542,14 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
478
542
|
changeSchemas(args.map(({ key, value }) => ({ key, value, schemaId: schema.id })));
|
479
543
|
}}
|
480
544
|
stopEditing={() => setEditing(false)}
|
481
|
-
outline={`1px ${hoveringSchemaId === schema.id ? 'solid' : 'dashed'} ${
|
482
|
-
|
545
|
+
outline={`1px ${hoveringSchemaId === schema.id ? 'solid' : 'dashed'} ${
|
546
|
+
schema.readOnly && hoveringSchemaId !== schema.id
|
547
|
+
? 'transparent'
|
548
|
+
: token.colorPrimary
|
549
|
+
}`}
|
483
550
|
scale={scale}
|
484
551
|
/>
|
485
|
-
)
|
552
|
+
);
|
486
553
|
}}
|
487
554
|
/>
|
488
555
|
</div>
|
@@ -1,49 +1,57 @@
|
|
1
1
|
import React, { useContext, useState, useEffect } from 'react';
|
2
|
-
import {
|
3
|
-
Schema,
|
4
|
-
Plugin,
|
5
|
-
BasePdf,
|
6
|
-
} from '@pdfme/common';
|
2
|
+
import { Schema, Plugin, BasePdf } from '@pdfme/common';
|
7
3
|
import { theme, Button } from 'antd';
|
8
4
|
import { useDraggable } from '@dnd-kit/core';
|
9
|
-
import { CSS } from
|
10
|
-
import Renderer from '../Renderer';
|
11
|
-
import { LEFT_SIDEBAR_WIDTH } from '../../constants';
|
12
|
-
import { PluginsRegistry } from '../../contexts';
|
13
|
-
import PluginIcon from
|
5
|
+
import { CSS } from '@dnd-kit/utilities';
|
6
|
+
import Renderer from '../Renderer.js';
|
7
|
+
import { LEFT_SIDEBAR_WIDTH } from '../../constants.js';
|
8
|
+
import { PluginsRegistry } from '../../contexts.js';
|
9
|
+
import PluginIcon from './PluginIcon.js';
|
14
10
|
|
15
|
-
|
16
|
-
|
11
|
+
const Draggable = (props: {
|
12
|
+
plugin: Plugin<any>;
|
13
|
+
scale: number;
|
14
|
+
basePdf: BasePdf;
|
15
|
+
children: React.ReactNode;
|
16
|
+
}) => {
|
17
17
|
const { scale, basePdf, plugin } = props;
|
18
18
|
const { token } = theme.useToken();
|
19
19
|
const defaultSchema = plugin.propPanel.defaultSchema as Schema;
|
20
20
|
const draggable = useDraggable({ id: defaultSchema.type, data: defaultSchema });
|
21
21
|
const { listeners, setNodeRef, attributes, transform, isDragging } = draggable;
|
22
|
-
const style = { transform: CSS.Translate.toString(transform) }
|
22
|
+
const style = { transform: CSS.Translate.toString(transform) };
|
23
23
|
|
24
24
|
return (
|
25
25
|
<div ref={setNodeRef} style={style} {...listeners} {...attributes}>
|
26
|
-
{isDragging &&
|
26
|
+
{isDragging && (
|
27
27
|
<div style={{ transform: `scale(${scale})` }}>
|
28
28
|
<Renderer
|
29
29
|
schema={{ ...defaultSchema, id: defaultSchema.type }}
|
30
30
|
basePdf={basePdf}
|
31
31
|
value={defaultSchema.content || ''}
|
32
|
-
onChangeHoveringSchemaId={() => {
|
32
|
+
onChangeHoveringSchemaId={() => {
|
33
|
+
void 0;
|
34
|
+
}}
|
33
35
|
mode={'viewer'}
|
34
36
|
outline={`1px solid ${token.colorPrimary}`}
|
35
37
|
scale={scale}
|
36
38
|
/>
|
37
39
|
</div>
|
38
|
-
}
|
39
|
-
<div style={{ visibility: isDragging ? 'hidden' : 'visible' }}>
|
40
|
-
{props.children}
|
41
|
-
</div>
|
40
|
+
)}
|
41
|
+
<div style={{ visibility: isDragging ? 'hidden' : 'visible' }}>{props.children}</div>
|
42
42
|
</div>
|
43
43
|
);
|
44
|
-
}
|
44
|
+
};
|
45
45
|
|
46
|
-
const LeftSidebar = ({
|
46
|
+
const LeftSidebar = ({
|
47
|
+
height,
|
48
|
+
scale,
|
49
|
+
basePdf,
|
50
|
+
}: {
|
51
|
+
height: number;
|
52
|
+
scale: number;
|
53
|
+
basePdf: BasePdf;
|
54
|
+
}) => {
|
47
55
|
const { token } = theme.useToken();
|
48
56
|
const pluginsRegistry = useContext(PluginsRegistry);
|
49
57
|
const [isDragging, setIsDragging] = useState(false);
|
@@ -62,36 +70,36 @@ const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number
|
|
62
70
|
};
|
63
71
|
}, [isDragging]);
|
64
72
|
|
65
|
-
return
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
return (
|
74
|
+
<div
|
75
|
+
style={{
|
76
|
+
left: 0,
|
77
|
+
right: 0,
|
78
|
+
position: 'absolute',
|
79
|
+
zIndex: 1,
|
80
|
+
height,
|
81
|
+
width: LEFT_SIDEBAR_WIDTH,
|
82
|
+
background: token.colorBgLayout,
|
83
|
+
textAlign: 'center',
|
84
|
+
overflow: isDragging ? 'visible' : 'auto',
|
85
|
+
}}
|
86
|
+
>
|
87
|
+
{Object.entries(pluginsRegistry).map(([label, plugin]) => {
|
88
|
+
if (!plugin?.propPanel.defaultSchema) return null;
|
80
89
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
}
|
90
|
+
return (
|
91
|
+
<Draggable key={label} scale={scale} basePdf={basePdf} plugin={plugin}>
|
92
|
+
<Button
|
93
|
+
onMouseDown={() => setIsDragging(true)}
|
94
|
+
style={{ width: 35, height: 35, marginTop: '0.25rem', padding: '0.25rem' }}
|
95
|
+
>
|
96
|
+
<PluginIcon plugin={plugin} label={label} />
|
97
|
+
</Button>
|
98
|
+
</Draggable>
|
99
|
+
);
|
100
|
+
})}
|
101
|
+
</div>
|
102
|
+
);
|
103
|
+
};
|
96
104
|
|
97
|
-
export default LeftSidebar
|
105
|
+
export default LeftSidebar;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import React, { useContext } from 'react';
|
2
|
-
import { Plugin } from
|
3
|
-
import { OptionsContext } from '../../contexts';
|
2
|
+
import { Plugin } from '@pdfme/common';
|
3
|
+
import { OptionsContext } from '../../contexts.js';
|
4
4
|
import { theme } from 'antd';
|
5
5
|
|
6
|
-
|
7
6
|
interface PluginIconProps {
|
8
7
|
plugin: Plugin<any>;
|
9
8
|
label: string;
|
@@ -11,7 +10,12 @@ interface PluginIconProps {
|
|
11
10
|
styles?: React.CSSProperties;
|
12
11
|
}
|
13
12
|
|
14
|
-
const getWithModifiedSize = (
|
13
|
+
const getWithModifiedSize = (
|
14
|
+
htmlString: string,
|
15
|
+
label: string,
|
16
|
+
size: number,
|
17
|
+
styles?: React.CSSProperties,
|
18
|
+
) => {
|
15
19
|
const parser = new DOMParser();
|
16
20
|
const doc = parser.parseFromString(htmlString, 'text/html');
|
17
21
|
|
@@ -20,10 +24,10 @@ const getWithModifiedSize = (htmlString: string, label: string, size: number, st
|
|
20
24
|
node.setAttribute('width', size.toString());
|
21
25
|
node.setAttribute('height', size.toString());
|
22
26
|
}
|
23
|
-
Array.from(node.children).forEach(child => modifyNode(child as HTMLElement));
|
27
|
+
Array.from(node.children).forEach((child) => modifyNode(child as HTMLElement));
|
24
28
|
};
|
25
29
|
|
26
|
-
Array.from(doc.body.children).forEach(child => modifyNode(child as HTMLElement));
|
30
|
+
Array.from(doc.body.children).forEach((child) => modifyNode(child as HTMLElement));
|
27
31
|
|
28
32
|
return (
|
29
33
|
<div style={styles} title={label} dangerouslySetInnerHTML={{ __html: doc.body.innerHTML }} />
|
@@ -35,16 +39,25 @@ const PluginIcon = (props: PluginIconProps) => {
|
|
35
39
|
const { token } = theme.useToken();
|
36
40
|
const options = useContext(OptionsContext);
|
37
41
|
const icon = options.icons?.[plugin.propPanel.defaultSchema.type] ?? plugin.icon;
|
38
|
-
const iconStyles = {
|
42
|
+
const iconStyles = {
|
43
|
+
...styles,
|
44
|
+
color: token.colorText,
|
45
|
+
display: 'flex',
|
46
|
+
justifyContent: 'center',
|
47
|
+
};
|
39
48
|
|
40
49
|
if (icon) {
|
41
50
|
if (size) {
|
42
51
|
return getWithModifiedSize(icon, label, size, iconStyles);
|
43
52
|
}
|
44
|
-
return <div style={iconStyles} title={label} dangerouslySetInnerHTML={{ __html: icon }}
|
53
|
+
return <div style={iconStyles} title={label} dangerouslySetInnerHTML={{ __html: icon }} />;
|
45
54
|
}
|
46
55
|
|
47
|
-
return
|
56
|
+
return (
|
57
|
+
<div style={{ ...styles, overflow: 'hidden', fontSize: 10 }} title={label}>
|
58
|
+
{label}
|
59
|
+
</div>
|
60
|
+
);
|
48
61
|
};
|
49
62
|
|
50
63
|
export default PluginIcon;
|