@pdfme/ui 5.3.8-dev.57 → 5.3.8-dev.58
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 +127 -60
- package/dist/types/src/components/Designer/LeftSidebar.d.ts +1 -1
- package/dist/types/src/components/Designer/PluginIcon.d.ts +1 -1
- package/package.json +1 -1
- package/src/Designer.tsx +4 -4
- package/src/Form.tsx +1 -3
- package/src/Viewer.tsx +1 -1
- package/src/components/AppContextProvider.tsx +1 -1
- package/src/components/CtlBar.tsx +1 -1
- package/src/components/Designer/Canvas/Guides.tsx +1 -1
- package/src/components/Designer/Canvas/Moveable.tsx +2 -2
- package/src/components/Designer/Canvas/Padding.tsx +10 -8
- package/src/components/Designer/Canvas/index.tsx +27 -14
- package/src/components/Designer/LeftSidebar.tsx +57 -49
- package/src/components/Designer/PluginIcon.tsx +21 -8
- package/src/components/Designer/RightSidebar/DetailView/AlignWidget.tsx +44 -44
- package/src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx +3 -3
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +51 -23
- package/src/components/Designer/RightSidebar/ListView/Item.tsx +4 -4
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +56 -47
- package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +2 -3
- package/src/components/Designer/RightSidebar/ListView/index.tsx +10 -3
- package/src/components/Designer/index.tsx +41 -19
- package/src/components/Preview.tsx +25 -14
- package/src/components/Renderer.tsx +35 -22
- package/src/components/Root.tsx +1 -1
- package/src/components/Spinner.tsx +1 -1
- package/src/components/StaticSchema.tsx +39 -21
- package/src/constants.ts +1 -1
- package/src/helper.ts +7 -7
- package/src/hooks.ts +3 -3
- package/src/types/react-guides.d.ts +1 -1
@@ -21,13 +21,13 @@ import { PluginsRegistry } from '../../../../contexts.js';
|
|
21
21
|
import Item from './Item.js';
|
22
22
|
import SelectableSortableItem from './SelectableSortableItem.js';
|
23
23
|
import { theme } from 'antd';
|
24
|
-
import PluginIcon from
|
24
|
+
import PluginIcon from '../../PluginIcon.js';
|
25
25
|
|
26
26
|
const SelectableSortableContainer = (
|
27
27
|
props: Pick<
|
28
28
|
SidebarProps,
|
29
29
|
'schemas' | 'onEdit' | 'onSortEnd' | 'hoveringSchemaId' | 'onChangeHoveringSchemaId'
|
30
|
-
|
30
|
+
>,
|
31
31
|
) => {
|
32
32
|
const { token } = theme.useToken();
|
33
33
|
const { schemas, onEdit, onSortEnd, hoveringSchemaId, onChangeHoveringSchemaId } = props;
|
@@ -37,7 +37,7 @@ const SelectableSortableContainer = (
|
|
37
37
|
const pluginsRegistry = useContext(PluginsRegistry);
|
38
38
|
const sensors = useSensors(
|
39
39
|
useSensor(PointerSensor, { activationConstraint: { distance: 15 } }),
|
40
|
-
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
|
40
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
41
41
|
);
|
42
42
|
|
43
43
|
const isItemSelected = (itemId: string): boolean =>
|
@@ -59,17 +59,25 @@ const SelectableSortableContainer = (
|
|
59
59
|
};
|
60
60
|
|
61
61
|
const getPluginIcon = (inSchema: string | SchemaForUI): ReactNode => {
|
62
|
-
const thisSchema =
|
62
|
+
const thisSchema =
|
63
|
+
typeof inSchema === 'string' ? schemas.find((schema) => schema.id === inSchema) : inSchema;
|
63
64
|
|
64
65
|
const [pluginLabel, activePlugin] = Object.entries(pluginsRegistry).find(
|
65
|
-
([label, plugin]) => plugin?.propPanel.defaultSchema.type === thisSchema?.type
|
66
|
+
([label, plugin]) => plugin?.propPanel.defaultSchema.type === thisSchema?.type,
|
66
67
|
)!;
|
67
68
|
|
68
69
|
if (!activePlugin) {
|
69
|
-
return
|
70
|
+
return <></>;
|
70
71
|
}
|
71
72
|
|
72
|
-
return
|
73
|
+
return (
|
74
|
+
<PluginIcon
|
75
|
+
plugin={activePlugin}
|
76
|
+
label={pluginLabel}
|
77
|
+
size={20}
|
78
|
+
styles={{ marginRight: '0.5rem' }}
|
79
|
+
/>
|
80
|
+
);
|
73
81
|
};
|
74
82
|
|
75
83
|
return (
|
@@ -90,7 +98,7 @@ const SelectableSortableContainer = (
|
|
90
98
|
return ret;
|
91
99
|
}
|
92
100
|
return ret.filter((schema) => schema !== selectedItem);
|
93
|
-
}, schemas)
|
101
|
+
}, schemas),
|
94
102
|
);
|
95
103
|
}
|
96
104
|
}}
|
@@ -106,7 +114,7 @@ const SelectableSortableContainer = (
|
|
106
114
|
newSchemas.splice(
|
107
115
|
overIndex + 1,
|
108
116
|
0,
|
109
|
-
...selectedSchemas.filter((item) => item.id !== activeId)
|
117
|
+
...selectedSchemas.filter((item) => item.id !== activeId),
|
110
118
|
);
|
111
119
|
onSortEnd(newSchemas);
|
112
120
|
setSelectedSchemas([]);
|
@@ -133,8 +141,9 @@ const SelectableSortableContainer = (
|
|
133
141
|
<SelectableSortableItem
|
134
142
|
key={schema.id}
|
135
143
|
style={{
|
136
|
-
border: `1px solid ${
|
137
|
-
|
144
|
+
border: `1px solid ${
|
145
|
+
schema.id === hoveringSchemaId ? token.colorPrimary : 'transparent'
|
146
|
+
}`,
|
138
147
|
}}
|
139
148
|
schema={schema}
|
140
149
|
schemas={schemas}
|
@@ -150,43 +159,43 @@ const SelectableSortableContainer = (
|
|
150
159
|
</div>
|
151
160
|
{createPortal(
|
152
161
|
<DragOverlay adjustScale>
|
153
|
-
{activeId
|
154
|
-
(() => {
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
162
|
+
{activeId
|
163
|
+
? (() => {
|
164
|
+
const activeSchema = schemas.find((schema) => schema.id === activeId);
|
165
|
+
if (!activeSchema) return null;
|
166
|
+
return (
|
167
|
+
<>
|
168
|
+
<ul style={{ margin: 0, padding: 0, listStyle: 'none' }}>
|
169
|
+
<Item
|
170
|
+
icon={getPluginIcon(activeId)}
|
171
|
+
value={activeSchema.name}
|
172
|
+
required={activeSchema.required}
|
173
|
+
readOnly={activeSchema.readOnly}
|
174
|
+
style={{ background: token.colorPrimary }}
|
175
|
+
dragOverlay
|
176
|
+
/>
|
177
|
+
</ul>
|
178
|
+
<ul style={{ margin: 0, padding: 0, listStyle: 'none' }}>
|
179
|
+
{selectedSchemas
|
180
|
+
.filter((item) => item.id !== activeId)
|
181
|
+
.map((item) => (
|
182
|
+
<Item
|
183
|
+
icon={getPluginIcon(item)}
|
184
|
+
key={item.id}
|
185
|
+
value={item.name}
|
186
|
+
required={item.required}
|
187
|
+
readOnly={item.readOnly}
|
188
|
+
style={{ background: token.colorPrimary }}
|
189
|
+
dragOverlay
|
190
|
+
/>
|
191
|
+
))}
|
192
|
+
</ul>
|
193
|
+
</>
|
194
|
+
);
|
195
|
+
})()
|
196
|
+
: null}
|
188
197
|
</DragOverlay>,
|
189
|
-
document.body
|
198
|
+
document.body,
|
190
199
|
)}
|
191
200
|
</>
|
192
201
|
</DndContext>
|
@@ -5,7 +5,7 @@ import { PluginsRegistry, I18nContext } from '../../../../contexts.js';
|
|
5
5
|
import Item from './Item.js';
|
6
6
|
import { useMountStatus } from '../../../../hooks.js';
|
7
7
|
import { theme } from 'antd';
|
8
|
-
import PluginIcon from
|
8
|
+
import PluginIcon from '../../PluginIcon.js';
|
9
9
|
|
10
10
|
interface Props {
|
11
11
|
isSelected: boolean;
|
@@ -43,10 +43,9 @@ const SelectableSortableItem = ({
|
|
43
43
|
};
|
44
44
|
|
45
45
|
const [pluginLabel, thisPlugin] = Object.entries(pluginsRegistry).find(
|
46
|
-
([label, plugin]) => plugin?.propPanel.defaultSchema.type === schema.type
|
46
|
+
([label, plugin]) => plugin?.propPanel.defaultSchema.type === schema.type,
|
47
47
|
)!;
|
48
48
|
|
49
|
-
|
50
49
|
let status: undefined | 'is-warning' | 'is-danger';
|
51
50
|
if (!schema.name) {
|
52
51
|
status = 'is-warning';
|
@@ -21,7 +21,7 @@ const ListView = (
|
|
21
21
|
| 'hoveringSchemaId'
|
22
22
|
| 'onChangeHoveringSchemaId'
|
23
23
|
| 'changeSchemas'
|
24
|
-
|
24
|
+
>,
|
25
25
|
) => {
|
26
26
|
const {
|
27
27
|
schemas,
|
@@ -48,7 +48,7 @@ const ListView = (
|
|
48
48
|
key: 'name',
|
49
49
|
value,
|
50
50
|
schemaId: schemas[index].id,
|
51
|
-
}))
|
51
|
+
})),
|
52
52
|
);
|
53
53
|
setIsBulkUpdateFieldNamesMode(false);
|
54
54
|
}
|
@@ -89,7 +89,14 @@ const ListView = (
|
|
89
89
|
onEdit={onEdit}
|
90
90
|
/>
|
91
91
|
)}
|
92
|
-
<div
|
92
|
+
<div
|
93
|
+
style={{
|
94
|
+
paddingTop: '0.5rem',
|
95
|
+
display: 'flex',
|
96
|
+
alignItems: 'center',
|
97
|
+
justifyContent: 'flex-end',
|
98
|
+
}}
|
99
|
+
>
|
93
100
|
{isBulkUpdateFieldNamesMode ? (
|
94
101
|
<>
|
95
102
|
<Button size="small" type="text" onClick={commitBulk}>
|
@@ -40,7 +40,7 @@ const scaleDragPosAdjustment = (adjustment: number, scale: number): number => {
|
|
40
40
|
if (scale > 1) return adjustment * (scale - 1);
|
41
41
|
if (scale < 1) return adjustment * -(1 - scale);
|
42
42
|
return 0;
|
43
|
-
}
|
43
|
+
};
|
44
44
|
|
45
45
|
const TemplateEditor = ({
|
46
46
|
template,
|
@@ -53,8 +53,8 @@ const TemplateEditor = ({
|
|
53
53
|
onSaveTemplate: (t: Template) => void;
|
54
54
|
onChangeTemplate: (t: Template) => void;
|
55
55
|
} & {
|
56
|
-
onChangeTemplate: (t: Template) => void
|
57
|
-
onPageCursorChange: (newPageCursor: number) => void
|
56
|
+
onChangeTemplate: (t: Template) => void;
|
57
|
+
onPageCursorChange: (newPageCursor: number) => void;
|
58
58
|
}) => {
|
59
59
|
const past = useRef<SchemaForUI[][]>([]);
|
60
60
|
const future = useRef<SchemaForUI[][]>([]);
|
@@ -74,8 +74,12 @@ const TemplateEditor = ({
|
|
74
74
|
const [sidebarOpen, setSidebarOpen] = useState(true);
|
75
75
|
const [prevTemplate, setPrevTemplate] = useState<Template | null>(null);
|
76
76
|
|
77
|
-
const { backgrounds, pageSizes, scale, error, refresh } =
|
78
|
-
|
77
|
+
const { backgrounds, pageSizes, scale, error, refresh } = useUIPreProcessor({
|
78
|
+
template,
|
79
|
+
size,
|
80
|
+
zoomLevel,
|
81
|
+
maxZoom,
|
82
|
+
});
|
79
83
|
|
80
84
|
const onEdit = (targets: HTMLElement[]) => {
|
81
85
|
setActiveElements(targets);
|
@@ -94,7 +98,7 @@ const TemplateEditor = ({
|
|
94
98
|
pageCursor,
|
95
99
|
onChangePageCursor: (p) => {
|
96
100
|
setPageCursor(p);
|
97
|
-
onPageCursorChange(p)
|
101
|
+
onPageCursorChange(p);
|
98
102
|
onEditEnd();
|
99
103
|
},
|
100
104
|
});
|
@@ -108,7 +112,7 @@ const TemplateEditor = ({
|
|
108
112
|
setSchemasList(_schemasList);
|
109
113
|
onChangeTemplate(schemasList2template(_schemasList, template.basePdf));
|
110
114
|
},
|
111
|
-
[template, schemasList, pageCursor, onChangeTemplate]
|
115
|
+
[template, schemasList, pageCursor, onChangeTemplate],
|
112
116
|
);
|
113
117
|
|
114
118
|
const removeSchemas = useCallback(
|
@@ -116,7 +120,7 @@ const TemplateEditor = ({
|
|
116
120
|
commitSchemas(schemasList[pageCursor].filter((schema) => !ids.includes(schema.id)));
|
117
121
|
onEditEnd();
|
118
122
|
},
|
119
|
-
[schemasList, pageCursor, commitSchemas]
|
123
|
+
[schemasList, pageCursor, commitSchemas],
|
120
124
|
);
|
121
125
|
|
122
126
|
const changeSchemas: ChangeSchemas = useCallback(
|
@@ -130,7 +134,7 @@ const TemplateEditor = ({
|
|
130
134
|
commitSchemas,
|
131
135
|
});
|
132
136
|
},
|
133
|
-
[commitSchemas, pageCursor, schemasList, pluginsRegistry, pageSizes, template.basePdf]
|
137
|
+
[commitSchemas, pageCursor, schemasList, pluginsRegistry, pageSizes, template.basePdf],
|
134
138
|
);
|
135
139
|
|
136
140
|
useInitEvents({
|
@@ -161,29 +165,42 @@ const TemplateEditor = ({
|
|
161
165
|
}, []);
|
162
166
|
|
163
167
|
const addSchema = (defaultSchema: Schema) => {
|
164
|
-
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isBlankPdf(template.basePdf)
|
168
|
+
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isBlankPdf(template.basePdf)
|
169
|
+
? template.basePdf.padding
|
170
|
+
: [0, 0, 0, 0];
|
165
171
|
const pageSize = pageSizes[pageCursor];
|
166
172
|
|
167
173
|
const newSchemaName = (prefix: string) => {
|
168
174
|
let index = schemasList.reduce((acc, page) => acc + page.length, 1);
|
169
175
|
let newName = prefix + index;
|
170
|
-
while (schemasList.some(page => page.find((s) => s.name === newName))) {
|
176
|
+
while (schemasList.some((page) => page.find((s) => s.name === newName))) {
|
171
177
|
index++;
|
172
178
|
newName = prefix + index;
|
173
179
|
}
|
174
180
|
return newName;
|
175
181
|
};
|
176
|
-
const ensureMiddleValue = (min: number, value: number, max: number) =>
|
182
|
+
const ensureMiddleValue = (min: number, value: number, max: number) =>
|
183
|
+
Math.min(Math.max(min, value), max);
|
177
184
|
|
178
185
|
const s = {
|
179
186
|
id: uuid(),
|
180
187
|
...defaultSchema,
|
181
188
|
name: newSchemaName(i18n('field')),
|
182
189
|
position: {
|
183
|
-
x: ensureMiddleValue(
|
184
|
-
|
190
|
+
x: ensureMiddleValue(
|
191
|
+
paddingLeft,
|
192
|
+
defaultSchema.position.x,
|
193
|
+
pageSize.width - paddingRight - defaultSchema.width,
|
194
|
+
),
|
195
|
+
y: ensureMiddleValue(
|
196
|
+
paddingTop,
|
197
|
+
defaultSchema.position.y,
|
198
|
+
pageSize.height - paddingBottom - defaultSchema.height,
|
199
|
+
),
|
185
200
|
},
|
186
|
-
required: defaultSchema.readOnly
|
201
|
+
required: defaultSchema.readOnly
|
202
|
+
? false
|
203
|
+
: options.requiredByDefault || defaultSchema.required || false,
|
187
204
|
} as SchemaForUI;
|
188
205
|
|
189
206
|
if (defaultSchema.position.y === 0) {
|
@@ -213,7 +230,8 @@ const TemplateEditor = ({
|
|
213
230
|
setTimeout(
|
214
231
|
() =>
|
215
232
|
canvasRef.current &&
|
216
|
-
((canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, newPageCursor, scale)),
|
233
|
+
((canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, newPageCursor, scale)),
|
234
|
+
0),
|
217
235
|
);
|
218
236
|
};
|
219
237
|
|
@@ -262,13 +280,17 @@ const TemplateEditor = ({
|
|
262
280
|
const dragStartLeft = active.rect.current.initial?.left || 0;
|
263
281
|
const dragStartTop = active.rect.current.initial?.top || 0;
|
264
282
|
|
265
|
-
const canvasLeftOffsetFromPageCorner =
|
283
|
+
const canvasLeftOffsetFromPageCorner =
|
284
|
+
pageRect.left - dragStartLeft + scaleDragPosAdjustment(20, scale);
|
266
285
|
const canvasTopOffsetFromPageCorner = pageRect.top - dragStartTop;
|
267
286
|
|
268
287
|
const moveY = (event.delta.y - canvasTopOffsetFromPageCorner) / scale;
|
269
288
|
const moveX = (event.delta.x - canvasLeftOffsetFromPageCorner) / scale;
|
270
289
|
|
271
|
-
const position = {
|
290
|
+
const position = {
|
291
|
+
x: round(px2mm(Math.max(0, moveX)), 2),
|
292
|
+
y: round(px2mm(Math.max(0, moveY)), 2),
|
293
|
+
};
|
272
294
|
|
273
295
|
addSchema({ ...(active.data.current as Schema), position });
|
274
296
|
}}
|
@@ -307,7 +329,7 @@ const TemplateEditor = ({
|
|
307
329
|
schemas={schemasList[pageCursor] ?? []}
|
308
330
|
changeSchemas={changeSchemas}
|
309
331
|
onSortEnd={onSortEnd}
|
310
|
-
onEdit={id => {
|
332
|
+
onEdit={(id) => {
|
311
333
|
const editingElem = document.getElementById(id);
|
312
334
|
editingElem && onEdit([editingElem]);
|
313
335
|
}}
|
@@ -1,5 +1,12 @@
|
|
1
1
|
import React, { useRef, useState, useEffect, useContext } from 'react';
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
Template,
|
4
|
+
SchemaForUI,
|
5
|
+
PreviewProps,
|
6
|
+
Size,
|
7
|
+
getDynamicTemplate,
|
8
|
+
replacePlaceholders,
|
9
|
+
} from '@pdfme/common';
|
3
10
|
import { getDynamicHeightsForTable } from '@pdfme/schemas/utils';
|
4
11
|
import UnitPager from './UnitPager.js';
|
5
12
|
import Root from './Root.js';
|
@@ -37,8 +44,12 @@ const Preview = ({
|
|
37
44
|
const [zoomLevel, setZoomLevel] = useState(1);
|
38
45
|
const [schemasList, setSchemasList] = useState<SchemaForUI[][]>([[]] as SchemaForUI[][]);
|
39
46
|
|
40
|
-
const { backgrounds, pageSizes, scale, error, refresh } =
|
41
|
-
|
47
|
+
const { backgrounds, pageSizes, scale, error, refresh } = useUIPreProcessor({
|
48
|
+
template,
|
49
|
+
size,
|
50
|
+
zoomLevel,
|
51
|
+
maxZoom,
|
52
|
+
});
|
42
53
|
|
43
54
|
const isForm = Boolean(onChangeInput);
|
44
55
|
|
@@ -87,7 +98,7 @@ const Preview = ({
|
|
87
98
|
const handleChangeInput = ({ name, value }: { name: string; value: string }) =>
|
88
99
|
onChangeInput && onChangeInput({ index: unitCursor, name, value });
|
89
100
|
|
90
|
-
const handleOnChangeRenderer = (args: { key: string; value: any
|
101
|
+
const handleOnChangeRenderer = (args: { key: string; value: any }[], schema: SchemaForUI) => {
|
91
102
|
let isNeedInit = false;
|
92
103
|
args.forEach(({ key: _key, value }) => {
|
93
104
|
if (_key === 'content') {
|
@@ -98,9 +109,7 @@ const Preview = ({
|
|
98
109
|
// TODO Improve this to allow schema types to determine whether the execution of getDynamicTemplate is required.
|
99
110
|
if (schema.type === 'table') isNeedInit = true;
|
100
111
|
} else {
|
101
|
-
const targetSchema = schemasList[pageCursor].find(
|
102
|
-
(s) => s.id === schema.id
|
103
|
-
) as SchemaForUI;
|
112
|
+
const targetSchema = schemasList[pageCursor].find((s) => s.id === schema.id) as SchemaForUI;
|
104
113
|
if (!targetSchema) return;
|
105
114
|
|
106
115
|
// @ts-ignore
|
@@ -110,8 +119,8 @@ const Preview = ({
|
|
110
119
|
if (isNeedInit) {
|
111
120
|
init(template);
|
112
121
|
}
|
113
|
-
setSchemasList([...schemasList])
|
114
|
-
}
|
122
|
+
setSchemasList([...schemasList]);
|
123
|
+
};
|
115
124
|
|
116
125
|
if (error) {
|
117
126
|
return <ErrorScreen size={size} error={error} />;
|
@@ -146,11 +155,13 @@ const Preview = ({
|
|
146
155
|
pageSizes={pageSizes}
|
147
156
|
backgrounds={backgrounds}
|
148
157
|
renderSchema={({ schema, index }) => {
|
149
|
-
const value = schema.readOnly
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
158
|
+
const value = schema.readOnly
|
159
|
+
? replacePlaceholders({
|
160
|
+
content: schema.content || '',
|
161
|
+
variables: { ...input, totalPages: schemasList.length, currentPage: index + 1 },
|
162
|
+
schemas: schemasList,
|
163
|
+
})
|
164
|
+
: String((input && input[schema.name]) || '');
|
154
165
|
return (
|
155
166
|
<Renderer
|
156
167
|
key={schema.id}
|
@@ -1,5 +1,16 @@
|
|
1
1
|
import React, { useEffect, useContext, ReactNode, useRef, useMemo } from 'react';
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
Dict,
|
4
|
+
Mode,
|
5
|
+
ZOOM,
|
6
|
+
UIRenderProps,
|
7
|
+
SchemaForUI,
|
8
|
+
BasePdf,
|
9
|
+
Schema,
|
10
|
+
Plugin,
|
11
|
+
UIOptions,
|
12
|
+
cloneDeep,
|
13
|
+
} from '@pdfme/common';
|
3
14
|
import { theme as antdTheme } from 'antd';
|
4
15
|
import { SELECTABLE_CLASSNAME } from '../constants.js';
|
5
16
|
import { PluginsRegistry, OptionsContext, I18nContext, CacheContext } from '../contexts.js';
|
@@ -18,13 +29,13 @@ type RendererProps = Omit<
|
|
18
29
|
};
|
19
30
|
|
20
31
|
type ReRenderCheckProps = {
|
21
|
-
plugin: Plugin<any
|
22
|
-
value: string
|
23
|
-
mode: Mode
|
24
|
-
scale: number
|
25
|
-
schema: SchemaForUI
|
26
|
-
options: UIOptions
|
27
|
-
}
|
32
|
+
plugin: Plugin<any>;
|
33
|
+
value: string;
|
34
|
+
mode: Mode;
|
35
|
+
scale: number;
|
36
|
+
schema: SchemaForUI;
|
37
|
+
options: UIOptions;
|
38
|
+
};
|
28
39
|
|
29
40
|
export const useRerenderDependencies = (arg: ReRenderCheckProps) => {
|
30
41
|
const { plugin, value, mode, scale, schema, options } = arg;
|
@@ -45,13 +56,12 @@ export const useRerenderDependencies = (arg: ReRenderCheckProps) => {
|
|
45
56
|
}, [plugin.uninterruptedEditMode, value, mode, scale, schema, optionStr]);
|
46
57
|
};
|
47
58
|
|
48
|
-
|
49
59
|
const Wrapper = ({
|
50
60
|
children,
|
51
61
|
outline,
|
52
62
|
onChangeHoveringSchemaId,
|
53
63
|
schema,
|
54
|
-
selectable = true
|
64
|
+
selectable = true,
|
55
65
|
}: RendererProps & { children: ReactNode }) => (
|
56
66
|
<div
|
57
67
|
title={schema.name}
|
@@ -71,16 +81,20 @@ const Wrapper = ({
|
|
71
81
|
outline,
|
72
82
|
}}
|
73
83
|
>
|
74
|
-
{schema.required &&
|
75
|
-
<span
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
{schema.required && (
|
85
|
+
<span
|
86
|
+
style={{
|
87
|
+
color: 'red',
|
88
|
+
position: 'absolute',
|
89
|
+
top: -12,
|
90
|
+
left: -12,
|
91
|
+
fontSize: 18,
|
92
|
+
fontWeight: 700,
|
93
|
+
}}
|
94
|
+
>
|
95
|
+
*
|
96
|
+
</span>
|
97
|
+
)}
|
84
98
|
{children}
|
85
99
|
</div>
|
86
100
|
);
|
@@ -94,11 +108,10 @@ const Renderer = (props: RendererProps) => {
|
|
94
108
|
const i18n = useContext(I18nContext) as (key: keyof Dict | string) => string;
|
95
109
|
const { token: theme } = antdTheme.useToken();
|
96
110
|
|
97
|
-
|
98
111
|
const ref = useRef<HTMLDivElement>(null);
|
99
112
|
const _cache = useContext(CacheContext);
|
100
113
|
const plugin = Object.values(pluginsRegistry || {}).find(
|
101
|
-
(plugin) => plugin?.propPanel.defaultSchema.type === schema.type
|
114
|
+
(plugin) => plugin?.propPanel.defaultSchema.type === schema.type,
|
102
115
|
) as Plugin<any> | undefined;
|
103
116
|
|
104
117
|
if (!plugin || !plugin.ui) {
|
package/src/components/Root.tsx
CHANGED
@@ -15,7 +15,7 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
|
15
15
|
([key, { data }]) =>
|
16
16
|
new FontFace(key, typeof data === 'string' ? `url(${data})` : data, {
|
17
17
|
display: 'swap',
|
18
|
-
})
|
18
|
+
}),
|
19
19
|
);
|
20
20
|
const newFontFaces = fontFaces.filter((fontFace) => !document.fonts.has(fontFace));
|
21
21
|
|
@@ -3,26 +3,44 @@ import { isBlankPdf, replacePlaceholders, Template } from '@pdfme/common';
|
|
3
3
|
import Renderer from './Renderer.js';
|
4
4
|
import { uuid } from '../helper.js';
|
5
5
|
|
6
|
-
const StaticSchema = (props: {
|
7
|
-
|
6
|
+
const StaticSchema = (props: {
|
7
|
+
template: Template;
|
8
|
+
input: Record<string, string>;
|
9
|
+
scale: number;
|
10
|
+
totalPages: number;
|
11
|
+
currentPage: number;
|
12
|
+
}) => {
|
13
|
+
const {
|
14
|
+
template: { schemas, basePdf },
|
15
|
+
input,
|
16
|
+
scale,
|
17
|
+
totalPages,
|
18
|
+
currentPage,
|
19
|
+
} = props;
|
8
20
|
if (!isBlankPdf(basePdf) || !basePdf.staticSchema) return null;
|
9
|
-
return
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
21
|
+
return (
|
22
|
+
<>
|
23
|
+
{basePdf.staticSchema.map((schema) => (
|
24
|
+
<Renderer
|
25
|
+
key={schema.name}
|
26
|
+
schema={{ ...schema, id: uuid() }}
|
27
|
+
basePdf={basePdf}
|
28
|
+
value={replacePlaceholders({
|
29
|
+
content: schema.content || '',
|
30
|
+
variables: { ...input, totalPages, currentPage },
|
31
|
+
schemas,
|
32
|
+
})}
|
33
|
+
onChangeHoveringSchemaId={() => {
|
34
|
+
void 0;
|
35
|
+
}}
|
36
|
+
mode={'viewer'}
|
37
|
+
outline={`none`}
|
38
|
+
scale={scale}
|
39
|
+
selectable={false}
|
40
|
+
/>
|
41
|
+
))}
|
42
|
+
</>
|
43
|
+
);
|
44
|
+
};
|
27
45
|
|
28
|
-
export default StaticSchema;
|
46
|
+
export default StaticSchema;
|
package/src/constants.ts
CHANGED