@pdfme/ui 5.1.7 → 5.2.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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: (string | ArrayBuffer | Uint8Array) & (string | ArrayBuffer | Uint8Array | undefined);
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?: ((arg: {
10
+ renderPaper: (arg: {
11
11
  index: number;
12
12
  paperSize: Size;
13
- }) => ReactNode) | undefined;
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;
@@ -3,5 +3,6 @@ export declare const DESTROYED_ERR_MSG = "[@pdfme/ui] this instance is already d
3
3
  export declare const SELECTABLE_CLASSNAME = "selectable";
4
4
  export declare const RULER_HEIGHT = 30;
5
5
  export declare const PAGE_GAP = 10;
6
+ export declare const LEFT_SIDEBAR_WIDTH = 45;
6
7
  export declare const RIGHT_SIDEBAR_WIDTH = 400;
7
8
  export declare const BACKGROUND_COLOR = "rgb(74, 74, 74)";
@@ -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: (string | ArrayBuffer | Uint8Array) & (string | ArrayBuffer | Uint8Array | undefined);
73
+ data: string | ArrayBuffer | Uint8Array;
74
74
  fallback?: boolean | undefined;
75
75
  subset?: boolean | undefined;
76
76
  }>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "5.1.7",
3
+ "version": "5.2.0-dev.1",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -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
- <Renderer
438
- key={schema.id}
439
- schema={schema}
440
- basePdf={basePdf}
441
- value={schema.content || ''}
442
- onChangeHoveringSchemaId={onChangeHoveringSchemaId}
443
- mode={
444
- editing && activeElements.map((ae) => ae.id).includes(schema.id)
445
- ? 'designer'
446
- : 'viewer'
447
- }
448
- onChange={(arg) => {
449
- const args = Array.isArray(arg) ? arg : [arg];
450
- changeSchemas(args.map(({ key, value }) => ({ key, value, schemaId: schema.id })));
451
- }}
452
- stopEditing={() => setEditing(false)}
453
- outline={`1px ${hoveringSchemaId === schema.id ? 'solid' : 'dashed'} ${schema.readOnly && hoveringSchemaId !== schema.id ? 'transparent' : token.colorPrimary
454
- }`}
455
- scale={scale}
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
  );
@@ -8,9 +8,11 @@ import { theme, Button } from 'antd';
8
8
  import { useDraggable } from '@dnd-kit/core';
9
9
  import { CSS } from "@dnd-kit/utilities";
10
10
  import Renderer from '../Renderer';
11
+ import { LEFT_SIDEBAR_WIDTH } from '../../constants';
11
12
  import { PluginsRegistry } from '../../contexts';
12
13
  import PluginIcon from "./PluginIcon";
13
14
 
15
+
14
16
  const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf, children: React.ReactNode }) => {
15
17
  const { scale, basePdf, plugin } = props;
16
18
  const { token } = theme.useToken();
@@ -24,7 +26,6 @@ const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf
24
26
  {isDragging &&
25
27
  <div style={{ transform: `scale(${scale})` }}>
26
28
  <Renderer
27
- key={defaultSchema.type}
28
29
  schema={{ ...defaultSchema, id: defaultSchema.type }}
29
30
  basePdf={basePdf}
30
31
  value={defaultSchema.content || ''}
@@ -68,7 +69,7 @@ const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number
68
69
  position: 'absolute',
69
70
  zIndex: 1,
70
71
  height,
71
- width: 45,
72
+ width: LEFT_SIDEBAR_WIDTH,
72
73
  background: token.colorBgLayout,
73
74
  textAlign: 'center',
74
75
  overflow: isDragging ? 'visible' : 'auto',
@@ -15,7 +15,7 @@ import { DndContext } from '@dnd-kit/core';
15
15
  import RightSidebar from './RightSidebar/index';
16
16
  import LeftSidebar from './LeftSidebar';
17
17
  import Canvas from './Canvas/index';
18
- import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH } from '../../constants';
18
+ import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH, LEFT_SIDEBAR_WIDTH } from '../../constants';
19
19
  import { I18nContext, OptionsContext, PluginsRegistry } from '../../contexts';
20
20
  import {
21
21
  schemasList2template,
@@ -235,8 +235,9 @@ const TemplateEditor = ({
235
235
  void updateTemplate(template);
236
236
  }
237
237
 
238
- const sizeExcSidebar = {
239
- width: sidebarOpen ? size.width - RIGHT_SIDEBAR_WIDTH : size.width,
238
+ const canvasWidth = size.width - LEFT_SIDEBAR_WIDTH;
239
+ const sizeExcSidebars = {
240
+ width: sidebarOpen ? canvasWidth - RIGHT_SIDEBAR_WIDTH : canvasWidth,
240
241
  height: size.height,
241
242
  };
242
243
 
@@ -271,66 +272,69 @@ const TemplateEditor = ({
271
272
  }}
272
273
  onDragStart={onEditEnd}
273
274
  >
274
- <CtlBar
275
- size={sizeExcSidebar}
276
- pageCursor={pageCursor}
277
- pageNum={schemasList.length}
278
- setPageCursor={(p) => {
279
- if (!canvasRef.current) return;
280
- canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, p, scale);
281
- setPageCursor(p);
282
- onEditEnd();
283
- }}
284
- zoomLevel={zoomLevel}
285
- setZoomLevel={setZoomLevel}
286
- {...pageManipulation}
287
- />
288
275
  <LeftSidebar
289
276
  height={canvasRef.current ? canvasRef.current.clientHeight : 0}
290
277
  scale={scale}
291
278
  basePdf={template.basePdf}
292
279
  />
293
280
 
294
- <RightSidebar
295
- hoveringSchemaId={hoveringSchemaId}
296
- onChangeHoveringSchemaId={onChangeHoveringSchemaId}
297
- height={canvasRef.current ? canvasRef.current.clientHeight : 0}
298
- size={size}
299
- pageSize={pageSizes[pageCursor] ?? []}
300
- activeElements={activeElements}
301
- schemasList={schemasList}
302
- schemas={schemasList[pageCursor] ?? []}
303
- changeSchemas={changeSchemas}
304
- onSortEnd={onSortEnd}
305
- onEdit={id => {
306
- const editingElem = document.getElementById(id);
307
- editingElem && onEdit([editingElem]);
308
- }}
309
- onEditEnd={onEditEnd}
310
- deselectSchema={onEditEnd}
311
- sidebarOpen={sidebarOpen}
312
- setSidebarOpen={setSidebarOpen}
313
- />
314
-
315
- <Canvas
316
- ref={canvasRef}
317
- paperRefs={paperRefs}
318
- basePdf={template.basePdf}
319
- hoveringSchemaId={hoveringSchemaId}
320
- onChangeHoveringSchemaId={onChangeHoveringSchemaId}
321
- height={size.height - RULER_HEIGHT * ZOOM}
322
- pageCursor={pageCursor}
323
- scale={scale}
324
- size={sizeExcSidebar}
325
- pageSizes={pageSizes}
326
- backgrounds={backgrounds}
327
- activeElements={activeElements}
328
- schemasList={schemasList}
329
- changeSchemas={changeSchemas}
330
- removeSchemas={removeSchemas}
331
- sidebarOpen={sidebarOpen}
332
- onEdit={onEdit}
333
- />
281
+ <div style={{ position: 'absolute', width: canvasWidth, marginLeft: LEFT_SIDEBAR_WIDTH }}>
282
+ <CtlBar
283
+ size={sizeExcSidebars}
284
+ pageCursor={pageCursor}
285
+ pageNum={schemasList.length}
286
+ setPageCursor={(p) => {
287
+ if (!canvasRef.current) return;
288
+ canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, p, scale);
289
+ setPageCursor(p);
290
+ onEditEnd();
291
+ }}
292
+ zoomLevel={zoomLevel}
293
+ setZoomLevel={setZoomLevel}
294
+ {...pageManipulation}
295
+ />
296
+
297
+ <RightSidebar
298
+ hoveringSchemaId={hoveringSchemaId}
299
+ onChangeHoveringSchemaId={onChangeHoveringSchemaId}
300
+ height={canvasRef.current ? canvasRef.current.clientHeight : 0}
301
+ size={size}
302
+ pageSize={pageSizes[pageCursor] ?? []}
303
+ activeElements={activeElements}
304
+ schemasList={schemasList}
305
+ schemas={schemasList[pageCursor] ?? []}
306
+ changeSchemas={changeSchemas}
307
+ onSortEnd={onSortEnd}
308
+ onEdit={id => {
309
+ const editingElem = document.getElementById(id);
310
+ editingElem && onEdit([editingElem]);
311
+ }}
312
+ onEditEnd={onEditEnd}
313
+ deselectSchema={onEditEnd}
314
+ sidebarOpen={sidebarOpen}
315
+ setSidebarOpen={setSidebarOpen}
316
+ />
317
+
318
+ <Canvas
319
+ ref={canvasRef}
320
+ paperRefs={paperRefs}
321
+ basePdf={template.basePdf}
322
+ hoveringSchemaId={hoveringSchemaId}
323
+ onChangeHoveringSchemaId={onChangeHoveringSchemaId}
324
+ height={size.height - RULER_HEIGHT * ZOOM}
325
+ pageCursor={pageCursor}
326
+ scale={scale}
327
+ size={sizeExcSidebars}
328
+ pageSizes={pageSizes}
329
+ backgrounds={backgrounds}
330
+ activeElements={activeElements}
331
+ schemasList={schemasList}
332
+ changeSchemas={changeSchemas}
333
+ removeSchemas={removeSchemas}
334
+ sidebarOpen={sidebarOpen}
335
+ onEdit={onEdit}
336
+ />
337
+ </div>
334
338
  </DndContext>
335
339
  </Root>
336
340
  );
@@ -10,7 +10,7 @@ const Paper = (props: {
10
10
  schemasList: SchemaForUI[][];
11
11
  pageSizes: Size[];
12
12
  backgrounds: string[];
13
- renderPaper?: (arg: { index: number; paperSize: Size }) => ReactNode;
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 && renderPaper({ paperSize, index: paperIndex })}
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 { name, readOnly } = schema;
122
- const content = readOnly ? String(schema.content) || '' : String(input && input[name] || '');
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={content}
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
- let isNeedInit = false;
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>