@pdfme/ui 5.1.6-dev.2 → 5.1.7-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 +76717 -72801
- package/dist/index.umd.js +411 -417
- package/dist/types/class.d.ts +159 -1
- package/dist/types/components/Paper.d.ts +2 -2
- package/dist/types/components/Renderer.d.ts +1 -0
- package/dist/types/components/StaticSchema.d.ts +10 -0
- package/dist/types/contexts.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/Designer/Canvas/index.tsx +52 -23
- package/src/components/Designer/LeftSidebar.tsx +0 -1
- package/src/components/Paper.tsx +2 -2
- package/src/components/Preview.tsx +44 -27
- package/src/components/Renderer.tsx +5 -3
- package/src/components/StaticSchema.tsx +28 -0
- /package/dist/{__vite-browser-external-jWVCDlBL.mjs → __vite-browser-external-DYxpcVy9.mjs} +0 -0
package/dist/types/class.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare abstract class BaseUIClass {
|
|
|
12
12
|
constructor(props: UIProps);
|
|
13
13
|
protected getLang(): "en" | "th" | "pl" | "zh" | "ja" | "ko" | "ar" | "it" | "de" | "es" | "fr";
|
|
14
14
|
protected getFont(): Record<string, {
|
|
15
|
-
data:
|
|
15
|
+
data: string | ArrayBuffer | Uint8Array;
|
|
16
16
|
fallback?: boolean | undefined;
|
|
17
17
|
subset?: boolean | undefined;
|
|
18
18
|
}>;
|
|
@@ -117,14 +117,172 @@ export declare abstract class BaseUIClass {
|
|
|
117
117
|
width: import("zod").ZodNumber;
|
|
118
118
|
height: import("zod").ZodNumber;
|
|
119
119
|
padding: import("zod").ZodTuple<[import("zod").ZodNumber, import("zod").ZodNumber, import("zod").ZodNumber, import("zod").ZodNumber], null>;
|
|
120
|
+
staticSchema: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
121
|
+
name: import("zod").ZodString;
|
|
122
|
+
type: import("zod").ZodString;
|
|
123
|
+
content: import("zod").ZodOptional<import("zod").ZodString>;
|
|
124
|
+
position: import("zod").ZodObject<{
|
|
125
|
+
x: import("zod").ZodNumber;
|
|
126
|
+
y: import("zod").ZodNumber;
|
|
127
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
128
|
+
x: number;
|
|
129
|
+
y: number;
|
|
130
|
+
}, {
|
|
131
|
+
x: number;
|
|
132
|
+
y: number;
|
|
133
|
+
}>;
|
|
134
|
+
width: import("zod").ZodNumber;
|
|
135
|
+
height: import("zod").ZodNumber;
|
|
136
|
+
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
137
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
138
|
+
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
139
|
+
required: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
140
|
+
__bodyRange: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
141
|
+
start: import("zod").ZodNumber;
|
|
142
|
+
end: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
143
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
144
|
+
start: number;
|
|
145
|
+
end?: number | undefined;
|
|
146
|
+
}, {
|
|
147
|
+
start: number;
|
|
148
|
+
end?: number | undefined;
|
|
149
|
+
}>>;
|
|
150
|
+
__isSplit: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
151
|
+
}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
|
|
152
|
+
name: import("zod").ZodString;
|
|
153
|
+
type: import("zod").ZodString;
|
|
154
|
+
content: import("zod").ZodOptional<import("zod").ZodString>;
|
|
155
|
+
position: import("zod").ZodObject<{
|
|
156
|
+
x: import("zod").ZodNumber;
|
|
157
|
+
y: import("zod").ZodNumber;
|
|
158
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
}, {
|
|
162
|
+
x: number;
|
|
163
|
+
y: number;
|
|
164
|
+
}>;
|
|
165
|
+
width: import("zod").ZodNumber;
|
|
166
|
+
height: import("zod").ZodNumber;
|
|
167
|
+
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
168
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
169
|
+
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
170
|
+
required: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
171
|
+
__bodyRange: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
172
|
+
start: import("zod").ZodNumber;
|
|
173
|
+
end: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
174
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
175
|
+
start: number;
|
|
176
|
+
end?: number | undefined;
|
|
177
|
+
}, {
|
|
178
|
+
start: number;
|
|
179
|
+
end?: number | undefined;
|
|
180
|
+
}>>;
|
|
181
|
+
__isSplit: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
182
|
+
}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
|
|
183
|
+
name: import("zod").ZodString;
|
|
184
|
+
type: import("zod").ZodString;
|
|
185
|
+
content: import("zod").ZodOptional<import("zod").ZodString>;
|
|
186
|
+
position: import("zod").ZodObject<{
|
|
187
|
+
x: import("zod").ZodNumber;
|
|
188
|
+
y: import("zod").ZodNumber;
|
|
189
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
190
|
+
x: number;
|
|
191
|
+
y: number;
|
|
192
|
+
}, {
|
|
193
|
+
x: number;
|
|
194
|
+
y: number;
|
|
195
|
+
}>;
|
|
196
|
+
width: import("zod").ZodNumber;
|
|
197
|
+
height: import("zod").ZodNumber;
|
|
198
|
+
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
199
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
200
|
+
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
201
|
+
required: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
202
|
+
__bodyRange: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
203
|
+
start: import("zod").ZodNumber;
|
|
204
|
+
end: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
205
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
206
|
+
start: number;
|
|
207
|
+
end?: number | undefined;
|
|
208
|
+
}, {
|
|
209
|
+
start: number;
|
|
210
|
+
end?: number | undefined;
|
|
211
|
+
}>>;
|
|
212
|
+
__isSplit: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
213
|
+
}, import("zod").ZodTypeAny, "passthrough">>, "many">>;
|
|
120
214
|
}, "strip", import("zod").ZodTypeAny, {
|
|
121
215
|
width: number;
|
|
122
216
|
height: number;
|
|
123
217
|
padding: [number, number, number, number];
|
|
218
|
+
staticSchema?: import("zod").objectOutputType<{
|
|
219
|
+
name: import("zod").ZodString;
|
|
220
|
+
type: import("zod").ZodString;
|
|
221
|
+
content: import("zod").ZodOptional<import("zod").ZodString>;
|
|
222
|
+
position: import("zod").ZodObject<{
|
|
223
|
+
x: import("zod").ZodNumber;
|
|
224
|
+
y: import("zod").ZodNumber;
|
|
225
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
226
|
+
x: number;
|
|
227
|
+
y: number;
|
|
228
|
+
}, {
|
|
229
|
+
x: number;
|
|
230
|
+
y: number;
|
|
231
|
+
}>;
|
|
232
|
+
width: import("zod").ZodNumber;
|
|
233
|
+
height: import("zod").ZodNumber;
|
|
234
|
+
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
235
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
236
|
+
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
237
|
+
required: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
238
|
+
__bodyRange: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
239
|
+
start: import("zod").ZodNumber;
|
|
240
|
+
end: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
241
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
242
|
+
start: number;
|
|
243
|
+
end?: number | undefined;
|
|
244
|
+
}, {
|
|
245
|
+
start: number;
|
|
246
|
+
end?: number | undefined;
|
|
247
|
+
}>>;
|
|
248
|
+
__isSplit: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
249
|
+
}, import("zod").ZodTypeAny, "passthrough">[] | undefined;
|
|
124
250
|
}, {
|
|
125
251
|
width: number;
|
|
126
252
|
height: number;
|
|
127
253
|
padding: [number, number, number, number];
|
|
254
|
+
staticSchema?: import("zod").objectInputType<{
|
|
255
|
+
name: import("zod").ZodString;
|
|
256
|
+
type: import("zod").ZodString;
|
|
257
|
+
content: import("zod").ZodOptional<import("zod").ZodString>;
|
|
258
|
+
position: import("zod").ZodObject<{
|
|
259
|
+
x: import("zod").ZodNumber;
|
|
260
|
+
y: import("zod").ZodNumber;
|
|
261
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
262
|
+
x: number;
|
|
263
|
+
y: number;
|
|
264
|
+
}, {
|
|
265
|
+
x: number;
|
|
266
|
+
y: number;
|
|
267
|
+
}>;
|
|
268
|
+
width: import("zod").ZodNumber;
|
|
269
|
+
height: import("zod").ZodNumber;
|
|
270
|
+
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
271
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
272
|
+
readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
273
|
+
required: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
274
|
+
__bodyRange: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
275
|
+
start: import("zod").ZodNumber;
|
|
276
|
+
end: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
277
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
278
|
+
start: number;
|
|
279
|
+
end?: number | undefined;
|
|
280
|
+
}, {
|
|
281
|
+
start: number;
|
|
282
|
+
end?: number | undefined;
|
|
283
|
+
}>>;
|
|
284
|
+
__isSplit: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
285
|
+
}, import("zod").ZodTypeAny, "passthrough">[] | undefined;
|
|
128
286
|
}>]>;
|
|
129
287
|
pdfmeVersion: import("zod").ZodOptional<import("zod").ZodString>;
|
|
130
288
|
}, import("zod").ZodTypeAny, "passthrough">;
|
|
@@ -7,10 +7,10 @@ declare const Paper: (props: {
|
|
|
7
7
|
schemasList: SchemaForUI[][];
|
|
8
8
|
pageSizes: Size[];
|
|
9
9
|
backgrounds: string[];
|
|
10
|
-
renderPaper
|
|
10
|
+
renderPaper: (arg: {
|
|
11
11
|
index: number;
|
|
12
12
|
paperSize: Size;
|
|
13
|
-
}) => ReactNode
|
|
13
|
+
}) => ReactNode;
|
|
14
14
|
renderSchema: (arg: {
|
|
15
15
|
index: number;
|
|
16
16
|
schema: SchemaForUI;
|
|
@@ -7,6 +7,7 @@ type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'opt
|
|
|
7
7
|
outline: string;
|
|
8
8
|
onChangeHoveringSchemaId?: (id: string | null) => void;
|
|
9
9
|
scale: number;
|
|
10
|
+
selectable?: boolean;
|
|
10
11
|
};
|
|
11
12
|
declare const Renderer: (props: RendererProps) => React.JSX.Element;
|
|
12
13
|
export default Renderer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Template } from '@pdfme/common';
|
|
3
|
+
declare const StaticSchema: (props: {
|
|
4
|
+
template: Template;
|
|
5
|
+
input: Record<string, string>;
|
|
6
|
+
scale: number;
|
|
7
|
+
totalPages: number;
|
|
8
|
+
currentPage: number;
|
|
9
|
+
}) => React.JSX.Element | null;
|
|
10
|
+
export default StaticSchema;
|
package/dist/types/contexts.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare const I18nContext: import("react").Context<(key: "type" | "width"
|
|
|
70
70
|
'schemas.select.optionPlaceholder': string;
|
|
71
71
|
} | undefined) => string>;
|
|
72
72
|
export declare const FontContext: import("react").Context<Record<string, {
|
|
73
|
-
data:
|
|
73
|
+
data: string | ArrayBuffer | Uint8Array;
|
|
74
74
|
fallback?: boolean | undefined;
|
|
75
75
|
subset?: boolean | undefined;
|
|
76
76
|
}>>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import React, {
|
|
|
11
11
|
} from 'react';
|
|
12
12
|
import { theme, Button } from 'antd';
|
|
13
13
|
import { OnDrag, OnResize, OnClick, OnRotate } from 'react-moveable';
|
|
14
|
-
import { ZOOM, SchemaForUI, Size, ChangeSchemas, BasePdf, isBlankPdf } from '@pdfme/common';
|
|
14
|
+
import { ZOOM, SchemaForUI, Size, ChangeSchemas, BasePdf, isBlankPdf, replacePlaceholders } from '@pdfme/common';
|
|
15
15
|
import { PluginsRegistry } from '../../../contexts';
|
|
16
16
|
import { CloseOutlined } from '@ant-design/icons';
|
|
17
17
|
import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH } from '../../../constants';
|
|
@@ -24,6 +24,7 @@ import Moveable from './Moveable';
|
|
|
24
24
|
import Guides from './Guides';
|
|
25
25
|
import Mask from './Mask';
|
|
26
26
|
import Padding from './Padding';
|
|
27
|
+
import StaticSchema from '../../StaticSchema';
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
const mm2px = (mm: number) => mm * 3.7795275591;
|
|
@@ -394,6 +395,15 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
|
394
395
|
<DeleteButton activeElements={activeElements} />
|
|
395
396
|
)}
|
|
396
397
|
<Padding basePdf={basePdf} />
|
|
398
|
+
<StaticSchema
|
|
399
|
+
template={{ schemas: schemasList, basePdf }}
|
|
400
|
+
input={Object.fromEntries(
|
|
401
|
+
schemasList.flat().map(({ name, content = '' }) => [name, content])
|
|
402
|
+
)}
|
|
403
|
+
scale={scale}
|
|
404
|
+
totalPages={schemasList.length}
|
|
405
|
+
currentPage={index + 1}
|
|
406
|
+
/>
|
|
397
407
|
<Guides
|
|
398
408
|
paperSize={paperSize}
|
|
399
409
|
horizontalRef={(e) => {
|
|
@@ -433,28 +443,47 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
|
433
443
|
)}
|
|
434
444
|
</>
|
|
435
445
|
)}
|
|
436
|
-
renderSchema={({ schema }) =>
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
446
|
+
renderSchema={({ schema, index }) => {
|
|
447
|
+
const mode =
|
|
448
|
+
editing && activeElements.map((ae) => ae.id).includes(schema.id)
|
|
449
|
+
? 'designer'
|
|
450
|
+
: 'viewer'
|
|
451
|
+
|
|
452
|
+
const content = schema.content || '';
|
|
453
|
+
let value = content;
|
|
454
|
+
|
|
455
|
+
if (mode !== 'designer' && schema.readOnly) {
|
|
456
|
+
const variables = {
|
|
457
|
+
...schemasList.flat().reduce((acc, currSchema) => {
|
|
458
|
+
acc[currSchema.name] = currSchema.content || '';
|
|
459
|
+
return acc;
|
|
460
|
+
}, {} as Record<string, string>),
|
|
461
|
+
totalPages: schemasList.length,
|
|
462
|
+
currentPage: index + 1,
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
value = replacePlaceholders({ content, variables, schemas: schemasList });
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return (
|
|
469
|
+
<Renderer
|
|
470
|
+
key={schema.id}
|
|
471
|
+
schema={schema}
|
|
472
|
+
basePdf={basePdf}
|
|
473
|
+
value={value}
|
|
474
|
+
onChangeHoveringSchemaId={onChangeHoveringSchemaId}
|
|
475
|
+
mode={mode}
|
|
476
|
+
onChange={(arg) => {
|
|
477
|
+
const args = Array.isArray(arg) ? arg : [arg];
|
|
478
|
+
changeSchemas(args.map(({ key, value }) => ({ key, value, schemaId: schema.id })));
|
|
479
|
+
}}
|
|
480
|
+
stopEditing={() => setEditing(false)}
|
|
481
|
+
outline={`1px ${hoveringSchemaId === schema.id ? 'solid' : 'dashed'} ${schema.readOnly && hoveringSchemaId !== schema.id ? 'transparent' : token.colorPrimary
|
|
482
|
+
}`}
|
|
483
|
+
scale={scale}
|
|
484
|
+
/>
|
|
485
|
+
)
|
|
486
|
+
}}
|
|
458
487
|
/>
|
|
459
488
|
</div>
|
|
460
489
|
);
|
|
@@ -24,7 +24,6 @@ const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf
|
|
|
24
24
|
{isDragging &&
|
|
25
25
|
<div style={{ transform: `scale(${scale})` }}>
|
|
26
26
|
<Renderer
|
|
27
|
-
key={defaultSchema.type}
|
|
28
27
|
schema={{ ...defaultSchema, id: defaultSchema.type }}
|
|
29
28
|
basePdf={basePdf}
|
|
30
29
|
value={defaultSchema.content || ''}
|
package/src/components/Paper.tsx
CHANGED
|
@@ -10,7 +10,7 @@ const Paper = (props: {
|
|
|
10
10
|
schemasList: SchemaForUI[][];
|
|
11
11
|
pageSizes: Size[];
|
|
12
12
|
backgrounds: string[];
|
|
13
|
-
renderPaper
|
|
13
|
+
renderPaper: (arg: { index: number; paperSize: Size }) => ReactNode;
|
|
14
14
|
renderSchema: (arg: { index: number; schema: SchemaForUI }) => ReactNode;
|
|
15
15
|
hasRulers?: boolean;
|
|
16
16
|
}) => {
|
|
@@ -93,7 +93,7 @@ const Paper = (props: {
|
|
|
93
93
|
...paperSize,
|
|
94
94
|
}}
|
|
95
95
|
>
|
|
96
|
-
{renderPaper
|
|
96
|
+
{renderPaper({ paperSize, index: paperIndex })}
|
|
97
97
|
{schemasList[paperIndex].map((schema, schemaIndex) => {
|
|
98
98
|
return (
|
|
99
99
|
<div key={schema.id}>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useRef, useState, useEffect, useContext } from 'react';
|
|
2
|
-
import { Template, SchemaForUI, PreviewProps, Size, getDynamicTemplate } from '@pdfme/common';
|
|
2
|
+
import { Template, SchemaForUI, PreviewProps, Size, getDynamicTemplate, replacePlaceholders } from '@pdfme/common';
|
|
3
3
|
import { getDynamicHeightsForTable } from '@pdfme/schemas/utils';
|
|
4
4
|
import UnitPager from './UnitPager';
|
|
5
5
|
import Root from './Root';
|
|
6
|
+
import StaticSchema from './StaticSchema';
|
|
6
7
|
import ErrorScreen from './ErrorScreen';
|
|
7
8
|
import CtlBar from './CtlBar';
|
|
8
9
|
import Paper from './Paper';
|
|
@@ -85,6 +86,32 @@ const Preview = ({
|
|
|
85
86
|
const handleChangeInput = ({ name, value }: { name: string; value: string }) =>
|
|
86
87
|
onChangeInput && onChangeInput({ index: unitCursor, name, value });
|
|
87
88
|
|
|
89
|
+
const handleOnChangeRenderer = (args: { key: string; value: any; }[], schema: SchemaForUI) => {
|
|
90
|
+
let isNeedInit = false;
|
|
91
|
+
args.forEach(({ key: _key, value }) => {
|
|
92
|
+
if (_key === 'content') {
|
|
93
|
+
const newValue = value as string;
|
|
94
|
+
const oldValue = (input?.[schema.name] as string) || '';
|
|
95
|
+
if (newValue === oldValue) return;
|
|
96
|
+
handleChangeInput({ name: schema.name, value: newValue });
|
|
97
|
+
// TODO Improve this to allow schema types to determine whether the execution of getDynamicTemplate is required.
|
|
98
|
+
if (schema.type === 'table') isNeedInit = true;
|
|
99
|
+
} else {
|
|
100
|
+
const targetSchema = schemasList[pageCursor].find(
|
|
101
|
+
(s) => s.id === schema.id
|
|
102
|
+
) as SchemaForUI;
|
|
103
|
+
if (!targetSchema) return;
|
|
104
|
+
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
targetSchema[_key] = value as string;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (isNeedInit) {
|
|
110
|
+
init(template);
|
|
111
|
+
}
|
|
112
|
+
setSchemasList([...schemasList])
|
|
113
|
+
}
|
|
114
|
+
|
|
88
115
|
if (error) {
|
|
89
116
|
return <ErrorScreen size={size} error={error} />;
|
|
90
117
|
}
|
|
@@ -118,42 +145,23 @@ const Preview = ({
|
|
|
118
145
|
pageSizes={pageSizes}
|
|
119
146
|
backgrounds={backgrounds}
|
|
120
147
|
renderSchema={({ schema, index }) => {
|
|
121
|
-
const
|
|
122
|
-
|
|
148
|
+
const value = schema.readOnly ? replacePlaceholders({
|
|
149
|
+
content: schema.content || '',
|
|
150
|
+
variables: { ...input, totalPages: schemasList.length, currentPage: index + 1, },
|
|
151
|
+
schemas: schemasList
|
|
152
|
+
}) : String(input && input[schema.name] || '');
|
|
123
153
|
return (
|
|
124
154
|
<Renderer
|
|
125
155
|
key={schema.id}
|
|
126
156
|
schema={schema}
|
|
127
157
|
basePdf={template.basePdf}
|
|
128
|
-
value={
|
|
158
|
+
value={value}
|
|
129
159
|
mode={isForm ? 'form' : 'viewer'}
|
|
130
160
|
placeholder={schema.content}
|
|
131
161
|
tabIndex={index + 100}
|
|
132
162
|
onChange={(arg) => {
|
|
133
163
|
const args = Array.isArray(arg) ? arg : [arg];
|
|
134
|
-
|
|
135
|
-
args.forEach(({ key: _key, value }) => {
|
|
136
|
-
if (_key === 'content') {
|
|
137
|
-
const newValue = value as string;
|
|
138
|
-
const oldValue = (input?.[name] as string) || '';
|
|
139
|
-
if (newValue === oldValue) return;
|
|
140
|
-
handleChangeInput({ name, value: newValue });
|
|
141
|
-
// TODO Improve this to allow schema types to determine whether the execution of getDynamicTemplate is required.
|
|
142
|
-
if (schema.type === 'table') isNeedInit = true;
|
|
143
|
-
} else {
|
|
144
|
-
const targetSchema = schemasList[pageCursor].find(
|
|
145
|
-
(s) => s.id === schema.id
|
|
146
|
-
) as SchemaForUI;
|
|
147
|
-
if (!targetSchema) return;
|
|
148
|
-
|
|
149
|
-
// @ts-ignore
|
|
150
|
-
targetSchema[_key] = value as string;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
if (isNeedInit) {
|
|
154
|
-
init(template);
|
|
155
|
-
}
|
|
156
|
-
setSchemasList([...schemasList])
|
|
164
|
+
handleOnChangeRenderer(args, schema);
|
|
157
165
|
}}
|
|
158
166
|
outline={
|
|
159
167
|
isForm && !schema.readOnly ? `1px dashed ${token.colorPrimary}` : 'transparent'
|
|
@@ -162,6 +170,15 @@ const Preview = ({
|
|
|
162
170
|
/>
|
|
163
171
|
);
|
|
164
172
|
}}
|
|
173
|
+
renderPaper={({ index }) => (
|
|
174
|
+
<StaticSchema
|
|
175
|
+
template={template}
|
|
176
|
+
scale={scale}
|
|
177
|
+
input={input}
|
|
178
|
+
totalPages={schemasList.length}
|
|
179
|
+
currentPage={index + 1}
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
165
182
|
/>
|
|
166
183
|
</div>
|
|
167
184
|
</Root>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useContext, ReactNode, useRef } from 'react';
|
|
2
|
-
import {Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions} from '@pdfme/common';
|
|
2
|
+
import { Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions } from '@pdfme/common';
|
|
3
3
|
import { theme as antdTheme } from 'antd';
|
|
4
4
|
import { SELECTABLE_CLASSNAME } from '../constants';
|
|
5
5
|
import { PluginsRegistry, OptionsContext, I18nContext } from '../contexts';
|
|
@@ -15,6 +15,7 @@ type RendererProps = Omit<
|
|
|
15
15
|
outline: string;
|
|
16
16
|
onChangeHoveringSchemaId?: (id: string | null) => void;
|
|
17
17
|
scale: number;
|
|
18
|
+
selectable?: boolean;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
type ReRenderCheckProps = {
|
|
@@ -43,12 +44,13 @@ const Wrapper = ({
|
|
|
43
44
|
outline,
|
|
44
45
|
onChangeHoveringSchemaId,
|
|
45
46
|
schema,
|
|
47
|
+
selectable = true
|
|
46
48
|
}: RendererProps & { children: ReactNode }) => (
|
|
47
49
|
<div
|
|
48
50
|
title={schema.name}
|
|
49
51
|
onMouseEnter={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(schema.id)}
|
|
50
52
|
onMouseLeave={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(null)}
|
|
51
|
-
className={SELECTABLE_CLASSNAME}
|
|
53
|
+
className={selectable ? SELECTABLE_CLASSNAME : ''}
|
|
52
54
|
id={schema.id}
|
|
53
55
|
style={{
|
|
54
56
|
position: 'absolute',
|
|
@@ -97,7 +99,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
|
97
99
|
return <></>;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
const reRenderDependencies = useRerenderDependencies({plugin, value, mode, scale, schema, options});
|
|
102
|
+
const reRenderDependencies = useRerenderDependencies({ plugin, value, mode, scale, schema, options });
|
|
101
103
|
|
|
102
104
|
useEffect(() => {
|
|
103
105
|
if (ref.current && schema.type) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isBlankPdf, replacePlaceholders, Template } from '@pdfme/common';
|
|
3
|
+
import Renderer from './Renderer';
|
|
4
|
+
import { uuid } from '../helper'
|
|
5
|
+
|
|
6
|
+
const StaticSchema = (props: { template: Template, input: Record<string, string>, scale: number, totalPages: number, currentPage: number }) => {
|
|
7
|
+
const { template: { schemas, basePdf }, input, scale, totalPages, currentPage } = props;
|
|
8
|
+
if (!isBlankPdf(basePdf) || !basePdf.staticSchema) return null;
|
|
9
|
+
return <>{basePdf.staticSchema.map((schema) => (
|
|
10
|
+
<Renderer
|
|
11
|
+
key={schema.name}
|
|
12
|
+
schema={{ ...schema, id: uuid() }}
|
|
13
|
+
basePdf={basePdf}
|
|
14
|
+
value={replacePlaceholders({
|
|
15
|
+
content: schema.content || '',
|
|
16
|
+
variables: { ...input, totalPages, currentPage },
|
|
17
|
+
schemas
|
|
18
|
+
})}
|
|
19
|
+
onChangeHoveringSchemaId={() => { void 0 }}
|
|
20
|
+
mode={'viewer'}
|
|
21
|
+
outline={`none`}
|
|
22
|
+
scale={scale}
|
|
23
|
+
selectable={false}
|
|
24
|
+
/>
|
|
25
|
+
))}</>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default StaticSchema;
|
|
File without changes
|