@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.
Files changed (94) hide show
  1. package/__mocks__/lucide-react.js +19 -0
  2. package/dist/index.es.js +110046 -107269
  3. package/dist/index.umd.js +585 -556
  4. package/dist/types/__tests__/assets/helper.d.ts +3 -0
  5. package/dist/types/__tests__/components/Designer.test.d.ts +1 -0
  6. package/dist/types/__tests__/components/Preview.test.d.ts +1 -0
  7. package/dist/types/__tests__/helper.test.d.ts +1 -0
  8. package/dist/types/{Designer.d.ts → src/Designer.d.ts} +1 -1
  9. package/dist/types/{Form.d.ts → src/Form.d.ts} +1 -1
  10. package/dist/types/{Viewer.d.ts → src/Viewer.d.ts} +1 -1
  11. package/dist/types/{class.d.ts → src/class.d.ts} +2 -2
  12. package/dist/types/src/components/Designer/Canvas/Guides.d.ts +15 -0
  13. package/dist/types/{components → src/components}/Designer/Canvas/Moveable.d.ts +48 -1
  14. package/dist/types/src/components/Designer/Canvas/Selecto.d.ts +21 -0
  15. package/dist/types/{components → src/components}/Designer/LeftSidebar.d.ts +1 -1
  16. package/dist/types/{components → src/components}/Designer/PluginIcon.d.ts +1 -1
  17. package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/index.d.ts +1 -1
  18. package/dist/types/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.d.ts +4 -0
  19. package/dist/types/src/components/Designer/RightSidebar/ListView/index.d.ts +4 -0
  20. package/dist/types/{components → src/components}/Designer/RightSidebar/index.d.ts +1 -1
  21. package/dist/types/{components → src/components}/Paper.d.ts +1 -1
  22. package/dist/types/{components → src/components}/Preview.d.ts +2 -2
  23. package/dist/types/src/contexts.d.ts +10 -0
  24. package/dist/types/{helper.d.ts → src/helper.d.ts} +2 -4
  25. package/dist/types/src/index.d.ts +4 -0
  26. package/eslint.config.mjs +41 -0
  27. package/package.json +21 -15
  28. package/src/Designer.tsx +7 -7
  29. package/src/Form.tsx +4 -6
  30. package/src/Viewer.tsx +4 -4
  31. package/src/components/AppContextProvider.tsx +4 -4
  32. package/src/components/CtlBar.tsx +4 -2
  33. package/src/components/Designer/Canvas/Guides.tsx +18 -9
  34. package/src/components/Designer/Canvas/Mask.tsx +1 -1
  35. package/src/components/Designer/Canvas/Moveable.tsx +66 -7
  36. package/src/components/Designer/Canvas/Padding.tsx +10 -8
  37. package/src/components/Designer/Canvas/Selecto.tsx +21 -6
  38. package/src/components/Designer/Canvas/index.tsx +95 -28
  39. package/src/components/Designer/LeftSidebar.tsx +60 -52
  40. package/src/components/Designer/PluginIcon.tsx +22 -9
  41. package/src/components/Designer/RightSidebar/DetailView/AlignWidget.tsx +45 -45
  42. package/src/components/Designer/RightSidebar/DetailView/ButtonGroupWidget.tsx +3 -3
  43. package/src/components/Designer/RightSidebar/DetailView/index.tsx +62 -31
  44. package/src/components/Designer/RightSidebar/ListView/Item.tsx +5 -5
  45. package/src/components/Designer/RightSidebar/ListView/SelectableSortableContainer.tsx +60 -51
  46. package/src/components/Designer/RightSidebar/ListView/SelectableSortableItem.tsx +5 -6
  47. package/src/components/Designer/RightSidebar/ListView/index.tsx +15 -8
  48. package/src/components/Designer/RightSidebar/index.tsx +4 -4
  49. package/src/components/Designer/index.tsx +51 -29
  50. package/src/components/ErrorScreen.tsx +2 -2
  51. package/src/components/Paper.tsx +2 -2
  52. package/src/components/Preview.tsx +35 -24
  53. package/src/components/Renderer.tsx +42 -29
  54. package/src/components/Root.tsx +4 -6
  55. package/src/components/Spinner.tsx +1 -1
  56. package/src/components/StaticSchema.tsx +41 -23
  57. package/src/constants.ts +1 -1
  58. package/src/contexts.ts +2 -2
  59. package/src/helper.ts +37 -17
  60. package/src/hooks.ts +16 -8
  61. package/src/index.ts +3 -3
  62. package/src/types/react-guides.d.ts +22 -0
  63. package/src/types/react-selecto.d.ts +35 -0
  64. package/tsconfig.json +10 -12
  65. package/.eslintrc.cjs +0 -16
  66. package/dist/types/components/Designer/Canvas/Guides.d.ts +0 -9
  67. package/dist/types/components/Designer/Canvas/Selecto.d.ts +0 -10
  68. package/dist/types/components/Designer/RightSidebar/ListView/SelectableSortableContainer.d.ts +0 -4
  69. package/dist/types/components/Designer/RightSidebar/ListView/index.d.ts +0 -4
  70. package/dist/types/contexts.d.ts +0 -85
  71. package/dist/types/index.d.ts +0 -4
  72. /package/dist/types/{components → src/components}/AppContextProvider.d.ts +0 -0
  73. /package/dist/types/{components → src/components}/CtlBar.d.ts +0 -0
  74. /package/dist/types/{components → src/components}/Designer/Canvas/Mask.d.ts +0 -0
  75. /package/dist/types/{components → src/components}/Designer/Canvas/Padding.d.ts +0 -0
  76. /package/dist/types/{components → src/components}/Designer/Canvas/index.d.ts +0 -0
  77. /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/AlignWidget.d.ts +0 -0
  78. /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/ButtonGroupWidget.d.ts +0 -0
  79. /package/dist/types/{components → src/components}/Designer/RightSidebar/DetailView/WidgetRenderer.d.ts +0 -0
  80. /package/dist/types/{components → src/components}/Designer/RightSidebar/ListView/Item.d.ts +0 -0
  81. /package/dist/types/{components → src/components}/Designer/RightSidebar/ListView/SelectableSortableItem.d.ts +0 -0
  82. /package/dist/types/{components → src/components}/Designer/index.d.ts +0 -0
  83. /package/dist/types/{components → src/components}/ErrorScreen.d.ts +0 -0
  84. /package/dist/types/{components → src/components}/Renderer.d.ts +0 -0
  85. /package/dist/types/{components → src/components}/Root.d.ts +0 -0
  86. /package/dist/types/{components → src/components}/Spinner.d.ts +0 -0
  87. /package/dist/types/{components → src/components}/StaticSchema.d.ts +0 -0
  88. /package/dist/types/{components → src/components}/UnitPager.d.ts +0 -0
  89. /package/dist/types/{constants.d.ts → src/constants.d.ts} +0 -0
  90. /package/dist/types/{hooks.d.ts → src/hooks.d.ts} +0 -0
  91. /package/dist/types/{i18n.d.ts → src/i18n.d.ts} +0 -0
  92. /package/dist/types/{theme.d.ts → src/theme.d.ts} +0 -0
  93. /package/dist/types/{types.d.ts → src/types.d.ts} +0 -0
  94. /package/{vite.config.ts → vite.config.mts} +0 -0
@@ -12,11 +12,11 @@ import {
12
12
  px2mm,
13
13
  } from '@pdfme/common';
14
14
  import { DndContext } from '@dnd-kit/core';
15
- import RightSidebar from './RightSidebar/index';
16
- import LeftSidebar from './LeftSidebar';
17
- import Canvas from './Canvas/index';
18
- import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH, LEFT_SIDEBAR_WIDTH } from '../../constants';
19
- import { I18nContext, OptionsContext, PluginsRegistry } from '../../contexts';
15
+ import RightSidebar from './RightSidebar/index.js';
16
+ import LeftSidebar from './LeftSidebar.js';
17
+ import Canvas from './Canvas/index.js';
18
+ import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH, LEFT_SIDEBAR_WIDTH } from '../../constants.js';
19
+ import { I18nContext, OptionsContext, PluginsRegistry } from '../../contexts.js';
20
20
  import {
21
21
  schemasList2template,
22
22
  uuid,
@@ -25,11 +25,11 @@ import {
25
25
  getPagesScrollTopByIndex,
26
26
  changeSchemas as _changeSchemas,
27
27
  getMaxZoom,
28
- } from '../../helper';
29
- import { useUIPreProcessor, useScrollPageCursor, useInitEvents } from '../../hooks';
30
- import Root from '../Root';
31
- import ErrorScreen from '../ErrorScreen';
32
- import CtlBar from '../CtlBar';
28
+ } from '../../helper.js';
29
+ import { useUIPreProcessor, useScrollPageCursor, useInitEvents } from '../../hooks.js';
30
+ import Root from '../Root.js';
31
+ import ErrorScreen from '../ErrorScreen.js';
32
+ import CtlBar from '../CtlBar.js';
33
33
 
34
34
  /**
35
35
  * When the canvas scales there is a displacement of the starting position of the dragged schema.
@@ -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
- useUIPreProcessor({ template, size, zoomLevel, maxZoom });
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) ? template.basePdf.padding : [0, 0, 0, 0];
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) => Math.min(Math.max(min, value), max)
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(paddingLeft, defaultSchema.position.x, pageSize.width - paddingRight - defaultSchema.width),
184
- y: ensureMiddleValue(paddingTop, defaultSchema.position.y, pageSize.height - paddingBottom - defaultSchema.height),
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 ? false : options.requiredByDefault || defaultSchema.required || false,
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)), 0)
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 = pageRect.left - dragStartLeft + scaleDragPosAdjustment(20, scale);
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 = { x: round(px2mm(Math.max(0, moveX)), 2), y: round(px2mm(Math.max(0, moveY)), 2) }
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,7 +1,7 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { Size } from '@pdfme/common';
3
- import { I18nContext } from '../contexts';
4
- import { BACKGROUND_COLOR } from '../constants';
3
+ import { I18nContext } from '../contexts.js';
4
+ import { BACKGROUND_COLOR } from '../constants.js';
5
5
  import { theme, Result } from 'antd';
6
6
 
7
7
  const ErrorScreen = ({ size, error }: { size: Size; error: Error }) => {
@@ -1,7 +1,7 @@
1
1
  import React, { MutableRefObject, ReactNode, useContext } from 'react';
2
2
  import { ZOOM, SchemaForUI, Size, getFallbackFontName } from '@pdfme/common';
3
- import { FontContext } from '../contexts';
4
- import { RULER_HEIGHT, PAGE_GAP } from '../constants';
3
+ import { FontContext } from '../contexts.js';
4
+ import { RULER_HEIGHT, PAGE_GAP } from '../constants.js';
5
5
 
6
6
  const Paper = (props: {
7
7
  paperRefs: MutableRefObject<HTMLDivElement[]>;
@@ -1,16 +1,23 @@
1
1
  import React, { useRef, useState, useEffect, useContext } from 'react';
2
- import { Template, SchemaForUI, PreviewProps, Size, getDynamicTemplate, replacePlaceholders } from '@pdfme/common';
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
- import UnitPager from './UnitPager';
5
- import Root from './Root';
6
- import StaticSchema from './StaticSchema';
7
- import ErrorScreen from './ErrorScreen';
8
- import CtlBar from './CtlBar';
9
- import Paper from './Paper';
10
- import Renderer from './Renderer';
11
- import { useUIPreProcessor, useScrollPageCursor } from '../hooks';
12
- import { FontContext } from '../contexts';
13
- import { template2SchemasList, getPagesScrollTopByIndex, getMaxZoom } from '../helper';
11
+ import UnitPager from './UnitPager.js';
12
+ import Root from './Root.js';
13
+ import StaticSchema from './StaticSchema.js';
14
+ import ErrorScreen from './ErrorScreen.js';
15
+ import CtlBar from './CtlBar.js';
16
+ import Paper from './Paper.js';
17
+ import Renderer from './Renderer.js';
18
+ import { useUIPreProcessor, useScrollPageCursor } from '../hooks.js';
19
+ import { FontContext } from '../contexts.js';
20
+ import { template2SchemasList, getPagesScrollTopByIndex, getMaxZoom } from '../helper.js';
14
21
  import { theme } from 'antd';
15
22
 
16
23
  const _cache = new Map();
@@ -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
- useUIPreProcessor({ template, size, zoomLevel, maxZoom });
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; }[], schema: SchemaForUI) => {
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 ? replacePlaceholders({
150
- content: schema.content || '',
151
- variables: { ...input, totalPages: schemasList.length, currentPage: index + 1, },
152
- schemas: schemasList
153
- }) : String(input && input[schema.name] || '');
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,8 +1,19 @@
1
1
  import React, { useEffect, useContext, ReactNode, useRef, useMemo } from 'react';
2
- import { Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions, cloneDeep } from '@pdfme/common';
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
- import { SELECTABLE_CLASSNAME } from '../constants';
5
- import { PluginsRegistry, OptionsContext, I18nContext, CacheContext } from '../contexts';
15
+ import { SELECTABLE_CLASSNAME } from '../constants.js';
16
+ import { PluginsRegistry, OptionsContext, I18nContext, CacheContext } from '../contexts.js';
6
17
 
7
18
  type RendererProps = Omit<
8
19
  UIRenderProps<Schema>,
@@ -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 style={{
76
- color: 'red',
77
- position: 'absolute',
78
- top: -12,
79
- left: -12,
80
- fontSize: 18,
81
- fontWeight: 700,
82
- }}>*</span>
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,12 +108,11 @@ 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
- const plugin = Object.values(pluginsRegistry).find(
101
- (plugin) => plugin?.propPanel.defaultSchema.type === schema.type
102
- ) as Plugin<any>;
113
+ const plugin = Object.values(pluginsRegistry || {}).find(
114
+ (plugin) => plugin?.propPanel.defaultSchema.type === schema.type,
115
+ ) as Plugin<any> | undefined;
103
116
 
104
117
  if (!plugin || !plugin.ui) {
105
118
  console.error(`[@pdfme/ui] Renderer for type ${schema.type} not found.
@@ -112,7 +125,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
112
125
  mode,
113
126
  scale,
114
127
  schema,
115
- options,
128
+ options: options as UIOptions,
116
129
  });
117
130
 
118
131
  useEffect(() => {
@@ -130,10 +143,10 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
130
143
  stopEditing,
131
144
  tabIndex,
132
145
  placeholder,
133
- options,
146
+ options: options as UIOptions,
134
147
  theme,
135
148
  i18n,
136
- _cache,
149
+ _cache: _cache as Map<any, any>,
137
150
  });
138
151
  }
139
152
  return () => {
@@ -1,8 +1,8 @@
1
1
  import React, { useContext, forwardRef, ReactNode, Ref, useEffect } from 'react';
2
2
  import { Size } from '@pdfme/common';
3
- import { FontContext } from '../contexts';
4
- import { BACKGROUND_COLOR } from '../constants';
5
- import Spinner from './Spinner';
3
+ import { FontContext } from '../contexts.js';
4
+ import { BACKGROUND_COLOR } from '../constants.js';
5
+ import Spinner from './Spinner.js';
6
6
 
7
7
  type Props = { size: Size; scale: number; children: ReactNode };
8
8
 
@@ -15,15 +15,13 @@ 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
- // @ts-ignore
21
20
  const newFontFaces = fontFaces.filter((fontFace) => !document.fonts.has(fontFace));
22
21
 
23
22
  Promise.allSettled(newFontFaces.map((f) => f.load())).then((loadedFontFaces) => {
24
23
  loadedFontFaces.forEach((loadedFontFace) => {
25
24
  if (loadedFontFace.status === 'fulfilled') {
26
- // @ts-ignore
27
25
  document.fonts.add(loadedFontFace.value);
28
26
  }
29
27
  });
@@ -14,7 +14,7 @@ const Spinner: React.FC = () => {
14
14
  alignItems: 'center',
15
15
  justifyContent: 'center',
16
16
  borderRadius: '50%',
17
- color: token.colorPrimary
17
+ color: token.colorPrimary,
18
18
  };
19
19
 
20
20
  const loaderStyle: React.CSSProperties = {
@@ -1,28 +1,46 @@
1
1
  import React from 'react';
2
2
  import { isBlankPdf, replacePlaceholders, Template } from '@pdfme/common';
3
- import Renderer from './Renderer';
4
- import { uuid } from '../helper'
3
+ import Renderer from './Renderer.js';
4
+ import { uuid } from '../helper.js';
5
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;
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 <>{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
- }
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
@@ -14,4 +14,4 @@ export const RIGHT_SIDEBAR_WIDTH = 400;
14
14
 
15
15
  export const BACKGROUND_COLOR = 'rgb(74, 74, 74)';
16
16
 
17
- export const DEFAULT_MAX_ZOOM = 2;
17
+ export const DEFAULT_MAX_ZOOM = 2;
package/src/contexts.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext } from 'react';
2
- import { i18n } from './i18n';
2
+ import { i18n } from './i18n.js';
3
3
  import { getDefaultFont, Plugins, UIOptions } from '@pdfme/common';
4
4
  import { builtInPlugins } from '@pdfme/schemas';
5
5
 
@@ -11,4 +11,4 @@ export const PluginsRegistry = createContext<Plugins>(builtInPlugins);
11
11
 
12
12
  export const OptionsContext = createContext<UIOptions>({});
13
13
 
14
- export const CacheContext = createContext<Map<any, any>>(new Map());
14
+ export const CacheContext = createContext<Map<any, any>>(new Map());