@pdfme/ui 2.2.0 → 3.0.0-beta.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.
Files changed (94) hide show
  1. package/README.md +33 -35
  2. package/__mocks__/form-render.js +7 -0
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.LICENSE.txt +42 -4
  5. package/dist/index.js.map +1 -1
  6. package/dist/types/Designer.d.ts +3 -0
  7. package/dist/types/builtInPropPanel.d.ts +3 -0
  8. package/dist/types/builtInRenderer.d.ts +3 -0
  9. package/dist/types/class.d.ts +18 -38
  10. package/dist/types/components/CtlBar/Pager.d.ts +3 -2
  11. package/dist/types/components/CtlBar/Zoom.d.ts +3 -2
  12. package/dist/types/components/CtlBar/index.d.ts +3 -2
  13. package/dist/types/components/Designer/{Main → Canvas}/Guides.d.ts +2 -2
  14. package/dist/types/components/Designer/Canvas/Mask.d.ts +4 -0
  15. package/dist/types/components/Designer/Canvas/Moveable.d.ts +37 -0
  16. package/dist/types/components/Designer/{Main → Canvas}/Selecto.d.ts +2 -1
  17. package/dist/types/components/Designer/{Main → Canvas}/index.d.ts +3 -6
  18. package/dist/types/components/Designer/Sidebar/DetailView/AlignWidget.d.ts +4 -0
  19. package/dist/types/components/Designer/Sidebar/DetailView/WidgetRenderer.d.ts +7 -0
  20. package/dist/types/components/Designer/Sidebar/DetailView/index.d.ts +5 -4
  21. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableContainer.d.ts +3 -2
  22. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableItem.d.ts +1 -1
  23. package/dist/types/components/Designer/Sidebar/ListView/index.d.ts +3 -2
  24. package/dist/types/components/Designer/Sidebar/index.d.ts +3 -23
  25. package/dist/types/components/Designer/index.d.ts +6 -107
  26. package/dist/types/components/Divider.d.ts +2 -1
  27. package/dist/types/components/ErrorScreen.d.ts +7 -0
  28. package/dist/types/components/Paper.d.ts +3 -2
  29. package/dist/types/components/Preview.d.ts +10 -2
  30. package/dist/types/components/Renderer.d.ts +10 -0
  31. package/dist/types/components/Root.d.ts +1 -1
  32. package/dist/types/components/Spinner.d.ts +2 -1
  33. package/dist/types/components/UnitPager.d.ts +3 -2
  34. package/dist/types/constants.d.ts +3 -3
  35. package/dist/types/contexts.d.ts +4 -1
  36. package/dist/types/helper.d.ts +4 -46
  37. package/dist/types/hooks.d.ts +2 -2
  38. package/dist/types/i18n.d.ts +4 -2
  39. package/dist/types/index.d.ts +1 -4
  40. package/dist/types/types.d.ts +25 -0
  41. package/package.json +19 -8
  42. package/src/Designer.tsx +69 -21
  43. package/src/Form.tsx +18 -14
  44. package/src/Viewer.tsx +6 -2
  45. package/src/builtInPropPanel.ts +5 -0
  46. package/src/builtInRenderer.ts +5 -0
  47. package/src/class.ts +25 -2
  48. package/src/components/CtlBar/index.tsx +4 -7
  49. package/src/components/Designer/{Main → Canvas}/Guides.tsx +2 -2
  50. package/src/components/Designer/{Main → Canvas}/Moveable.tsx +23 -19
  51. package/src/components/Designer/{Main → Canvas}/index.tsx +77 -30
  52. package/src/components/Designer/Sidebar/DetailView/AlignWidget.tsx +182 -0
  53. package/src/components/Designer/Sidebar/DetailView/WidgetRenderer.tsx +28 -0
  54. package/src/components/Designer/Sidebar/DetailView/index.tsx +153 -22
  55. package/src/components/Designer/Sidebar/ListView/Item.tsx +1 -1
  56. package/src/components/Designer/Sidebar/ListView/SelectableSortableContainer.tsx +6 -6
  57. package/src/components/Designer/Sidebar/ListView/index.tsx +1 -4
  58. package/src/components/Designer/Sidebar/index.tsx +26 -60
  59. package/src/components/Designer/index.tsx +53 -32
  60. package/src/components/{Error.tsx → ErrorScreen.tsx} +2 -2
  61. package/src/components/Paper.tsx +35 -9
  62. package/src/components/Preview.tsx +48 -50
  63. package/src/components/Renderer.tsx +90 -0
  64. package/src/components/Root.tsx +5 -1
  65. package/src/constants.ts +4 -4
  66. package/src/contexts.ts +7 -0
  67. package/src/helper.ts +19 -122
  68. package/src/hooks.ts +6 -5
  69. package/src/i18n.ts +48 -11
  70. package/src/index.ts +1 -76
  71. package/src/types.ts +36 -0
  72. package/tsconfig.json +2 -1
  73. package/webpack.config.js +6 -1
  74. package/dist/types/components/Designer/Main/Mask.d.ts +0 -3
  75. package/dist/types/components/Designer/Main/Moveable.d.ts +0 -31
  76. package/dist/types/components/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +0 -6
  77. package/dist/types/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +0 -6
  78. package/dist/types/components/Designer/Sidebar/DetailView/TextPropEditor.d.ts +0 -6
  79. package/dist/types/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +0 -6
  80. package/dist/types/components/Error.d.ts +0 -6
  81. package/dist/types/components/Schemas/BarcodeSchema.d.ts +0 -15
  82. package/dist/types/components/Schemas/ImageSchema.d.ts +0 -15
  83. package/dist/types/components/Schemas/SchemaUI.d.ts +0 -15
  84. package/dist/types/components/Schemas/TextSchema.d.ts +0 -28
  85. package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +0 -85
  86. package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +0 -275
  87. package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +0 -357
  88. package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +0 -87
  89. package/src/components/Schemas/BarcodeSchema.tsx +0 -124
  90. package/src/components/Schemas/ImageSchema.tsx +0 -87
  91. package/src/components/Schemas/SchemaUI.tsx +0 -62
  92. package/src/components/Schemas/TextSchema.tsx +0 -175
  93. /package/src/components/Designer/{Main → Canvas}/Mask.tsx +0 -0
  94. /package/src/components/Designer/{Main → Canvas}/Selecto.tsx +0 -0
@@ -0,0 +1,90 @@
1
+ import React, { useEffect, useContext, ReactNode, useRef } from 'react';
2
+ import { ZOOM, UIRenderProps, SchemaForUI, Schema } from '@pdfme/common';
3
+ import { SELECTABLE_CLASSNAME } from '../constants';
4
+ import { RendererRegistry, OptionsContext } from '../contexts';
5
+
6
+ type RendererProps = Omit<
7
+ UIRenderProps<Schema>,
8
+ 'value' | 'schema' | 'onChange' | 'rootElement' | 'options'
9
+ > & {
10
+ schema: SchemaForUI;
11
+ onChange: (value: string) => void;
12
+ outline: string;
13
+ onChangeHoveringSchemaId?: (id: string | null) => void;
14
+ };
15
+
16
+ const Wrapper = ({
17
+ children,
18
+ outline,
19
+ onChangeHoveringSchemaId,
20
+ schema,
21
+ }: RendererProps & { children: ReactNode }) => (
22
+ <div
23
+ title={schema.key}
24
+ onMouseEnter={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(schema.id)}
25
+ onMouseLeave={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(null)}
26
+ className={SELECTABLE_CLASSNAME}
27
+ id={schema.id}
28
+ style={{
29
+ position: 'absolute',
30
+ cursor: 'pointer',
31
+ height: schema.height * ZOOM,
32
+ width: schema.width * ZOOM,
33
+ top: schema.position.y * ZOOM,
34
+ left: schema.position.x * ZOOM,
35
+ transform: `rotate(${schema.rotate ?? 0}deg)`,
36
+ outline,
37
+ }}
38
+ >
39
+ {children}
40
+ </div>
41
+ );
42
+
43
+ const Renderer = (props: RendererProps) => {
44
+ const rendererRegistry = useContext(RendererRegistry);
45
+ const options = useContext(OptionsContext);
46
+
47
+ const { schema, mode, onChange, stopEditing, tabIndex, placeholder } = props;
48
+
49
+ const ref = useRef<HTMLDivElement>(null);
50
+
51
+ useEffect(() => {
52
+ if (ref.current && schema.type) {
53
+ const schemaType = schema.type as string;
54
+ const render = rendererRegistry[schemaType];
55
+ if (!render) {
56
+ console.error(`[@pdfme/ui] Renderer for type ${schema.type} not found.
57
+ Check this document: https://pdfme.com/docs/custom-schemas`);
58
+ return;
59
+ }
60
+
61
+ ref.current.innerHTML = '';
62
+
63
+ const editable = mode === 'form' || mode === 'designer';
64
+
65
+ render({
66
+ value: schema.data,
67
+ schema,
68
+ rootElement: ref.current,
69
+ mode,
70
+ onChange: editable ? onChange : undefined,
71
+ stopEditing: editable ? stopEditing : undefined,
72
+ tabIndex,
73
+ placeholder,
74
+ options,
75
+ });
76
+ }
77
+ return () => {
78
+ if (ref.current) {
79
+ ref.current.innerHTML = '';
80
+ }
81
+ };
82
+ }, [JSON.stringify(schema), mode, options]);
83
+
84
+ return (
85
+ <Wrapper {...props}>
86
+ <div style={{ height: '100%', width: '100%' }} ref={ref} />
87
+ </Wrapper>
88
+ );
89
+ };
90
+ export default Renderer;
@@ -32,7 +32,11 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
32
32
  return (
33
33
  <div
34
34
  ref={ref}
35
- style={{ position: 'relative', background: 'rgb(74, 74, 74)', overflow: 'overlay', ...size }}
35
+ style={{
36
+ position: 'relative',
37
+ background: 'rgb(74, 74, 74)',
38
+ ...size,
39
+ }}
36
40
  >
37
41
  <div style={{ margin: '0 auto', ...size }}>{scale === 0 ? <Spinner /> : children}</div>
38
42
  </div>
package/src/constants.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export const DEFAULT_LANG = 'en' as const;
2
2
 
3
- export const DESTROYED_ERR_MSG = 'this instance is already destroyed';
4
-
5
- export const ZOOM = 3.7795275591;
3
+ export const DESTROYED_ERR_MSG = '[@pdfme/ui] this instance is already destroyed';
6
4
 
7
5
  export const SELECTABLE_CLASSNAME = 'selectable';
8
6
 
9
7
  export const RULER_HEIGHT = 30;
10
8
 
11
- export const SIDEBAR_WIDTH = 300;
9
+ export const PAGE_GAP = 10;
10
+
11
+ export const SIDEBAR_WIDTH = 350;
package/src/contexts.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  import { createContext } from 'react';
2
2
  import { curriedI18n } from './i18n';
3
3
  import { DEFAULT_LANG } from './constants';
4
+ import builtInRenderer from './builtInRenderer';
5
+ import builtInPropPanel from './builtInPropPanel';
4
6
  import { getDefaultFont } from '@pdfme/common';
5
7
 
6
8
  export const I18nContext = createContext(curriedI18n(DEFAULT_LANG));
7
9
 
8
10
  export const FontContext = createContext(getDefaultFont());
11
+
12
+ export const RendererRegistry = createContext(builtInRenderer);
13
+ export const PropPanelRegistry = createContext(builtInPropPanel);
14
+
15
+ export const OptionsContext = createContext({});
package/src/helper.ts CHANGED
@@ -5,20 +5,16 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/legacy/build/pdf.js
5
5
  GlobalWorkerOptions.workerSrc = PDFJSWorker;
6
6
  import hotkeys from 'hotkeys-js';
7
7
  import {
8
+ ZOOM,
8
9
  getB64BasePdf,
9
10
  b64toUint8Array,
11
+ pt2mm,
10
12
  Template,
11
13
  SchemaForUI,
12
14
  Schema,
13
- SchemaType,
14
- BarCodeType,
15
15
  Size,
16
- DEFAULT_ALIGNMENT,
17
- DEFAULT_FONT_SIZE,
18
- DEFAULT_CHARACTER_SPACING,
19
- DEFAULT_LINE_HEIGHT,
20
16
  } from '@pdfme/common';
21
- import { ZOOM, RULER_HEIGHT } from './constants';
17
+ import { RULER_HEIGHT } from './constants';
22
18
 
23
19
  export const uuid = () =>
24
20
  'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
@@ -196,54 +192,6 @@ export const destroyShortCuts = () => {
196
192
  hotkeys.unbind(keys.join());
197
193
  };
198
194
 
199
- const readFile = (file: File | null, type: 'text' | 'dataURL' | 'arrayBuffer') => {
200
- return new Promise<string | ArrayBuffer>((r) => {
201
- const fileReader = new FileReader();
202
- fileReader.addEventListener('load', (e) => {
203
- if (e && e.target && e.target.result && file !== null) {
204
- r(e.target.result);
205
- }
206
- });
207
- if (file !== null) {
208
- if (type === 'text') {
209
- fileReader.readAsText(file);
210
- } else if (type === 'dataURL') {
211
- fileReader.readAsDataURL(file);
212
- } else if (type === 'arrayBuffer') {
213
- fileReader.readAsArrayBuffer(file);
214
- }
215
- }
216
- });
217
- };
218
-
219
- export const readFiles = (files: FileList | null, type: 'text' | 'dataURL' | 'arrayBuffer') => {
220
- return new Promise<string | ArrayBuffer>((r) => {
221
- const fileReader = new FileReader();
222
- fileReader.addEventListener('load', (e) => {
223
- if (e && e.target && e.target.result && files !== null) {
224
- r(e.target.result);
225
- }
226
- });
227
- if (files !== null && files[0]) {
228
- readFile(files[0], type).then((data) => r(data));
229
- }
230
- });
231
- };
232
-
233
- const pt2mm = (pt: number) => {
234
- // https://www.ddc.co.jp/words/archives/20090701114500.html
235
- const mmRatio = 0.3527;
236
-
237
- return parseFloat(String(pt)) * mmRatio;
238
- };
239
-
240
- export const px2mm = (px: number) => {
241
- // http://www.unitconversion.org/typography/millimeters-to-pixels-y-conversion.html
242
- const mmRatio = 0.264583333;
243
-
244
- return parseFloat(String(px)) * mmRatio;
245
- };
246
-
247
195
  export const getPdfPageSizes = async (pdfBlob: Blob) => {
248
196
  const url = URL.createObjectURL(pdfBlob);
249
197
  const pdfDoc = await getDocument({ url }).promise;
@@ -306,22 +254,22 @@ const sortSchemasList = (template: Template, pageNum: number): SchemaForUI[][] =
306
254
  acc.push(
307
255
  template.schemas[i]
308
256
  ? Object.entries(template.schemas[i])
309
- .sort((a, b) => {
310
- const aIndex = (template.columns ?? []).findIndex((c) => c === a[0]);
311
- const bIndex = (template.columns ?? []).findIndex((c) => c === b[0]);
312
-
313
- return aIndex > bIndex ? 1 : -1;
314
- })
315
- .map((e) => {
316
- const [key, value] = e;
317
- const data = template.sampledata?.[0]?.[key] ?? '';
318
-
319
- return Object.assign(value, {
320
- key,
321
- data,
322
- id: uuid(),
323
- });
324
- })
257
+ .sort((a, b) => {
258
+ const aIndex = (template.columns ?? []).findIndex((c) => c === a[0]);
259
+ const bIndex = (template.columns ?? []).findIndex((c) => c === b[0]);
260
+
261
+ return aIndex > bIndex ? 1 : -1;
262
+ })
263
+ .map((e) => {
264
+ const [key, value] = e;
265
+ const data = template.sampledata?.[0]?.[key] ?? '';
266
+
267
+ return Object.assign(value, {
268
+ key,
269
+ data,
270
+ id: uuid(),
271
+ });
272
+ })
325
273
  : []
326
274
  );
327
275
 
@@ -397,57 +345,6 @@ export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): T
397
345
  return schemaAddedTemplate;
398
346
  };
399
347
 
400
- export const getInitialSchema = (): SchemaForUI => ({
401
- id: uuid(),
402
- key: '',
403
- data: '',
404
- type: 'text',
405
- position: { x: 0, y: 0 },
406
- width: 35,
407
- height: 7,
408
- alignment: DEFAULT_ALIGNMENT,
409
- fontSize: DEFAULT_FONT_SIZE,
410
- characterSpacing: DEFAULT_CHARACTER_SPACING,
411
- lineHeight: DEFAULT_LINE_HEIGHT,
412
- });
413
-
414
- export const getSampleByType = (type: SchemaType) => {
415
- const defaultValue: { [K in SchemaType]: string } = {
416
- text: 'text',
417
- image:
418
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu4AAALuAQMAAADL0wGJAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURbzAw+rv8fKruy0AAAPoSURBVHja7dwxbtwwEEBRCkKwRQodYftcYk+ROkcJz5NTsEuZK/AIKlIQAUEnke0VqQ0pA5zxWvFnZcD2s0CNuENxPOZBc0QDDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PD/+P8bkxvnTzzjTG0M2b5rh08rHNT518aPOnTt63+aGTd23edPJ2h//ax+/oO6Gzx6c78+cuPu7x01vmwx5/6uLnO/PjO+b/rGifvtWH3VnT9vmh/e3eqx/bc9d79af2YwEPDw8P/6r8r1GVt5VcUoZPtXxGhp9rGYEM72vbEBne1hJ5Gb6ayIvwqZppi/CxmgqL8KGaTIrwc3WDfATeV/ffIryr7r+PwNvq/vsIfH17D5/qbw/gb/mLKp/OqnycFPj14yqcJPm4vfp5VJ0cP6jyzqjy9rr2q/Dr4qzBp3V5E1wxp/V3rl8LXn32qF6fAY31Psv2NXi/5lQaH+Vuzak0eLsmPRppVPa3FPiU3QiFFDZmD4FCAh6yxV+Bn7O9isLmx2d/TGHr5rI7obDxtFkcKWyb89M2+U1/sX7Kv7Io8gaxFy5l2D/faRk++3x6PgsalV52+fwUW4j/+eGhDPuneyH/otHmp9jyfHHMLM6n4phZnI/FObA4H4qDWnF+Lo46xXlflG+I864o3xDnbVG+Ic6X9RXSfCrrK6T5WBZASPOhrFCQ5ufyjF+a92XdkjTvyrolad6WdUvS/KawSI7/sQn7JfDl+O+bsF8CX44fN2FvHnNnIT4Nm7BfAl+ON5uwXwJfjA/LCuk2BXvCvN0U7InxflmAtxV1gvx0U2N3luPtdZOlwj/FoR5vbuq85Pi48F6LD0scOk3+sq1cleP9ohlNfkpq/N9pGaMuH7T4ZVqGWYt/nBavyxstftblfaVIWJU/y72yODCfzJH5oMvPh+adLm+PzCdzZD5U/61ClT9Lnvyo8e7QvFHlE3ydj0zOu5ucickhcpgcJofJedUVk8j5b/nGgIeHh4d/I3x/RwLlhgfNH3DavSwGXf7YjT76uqCEQ/P37p9z7uKVmwspd17S7hul3PXK6fbsmnvWhO6GZlMnn3ri8gXN5GzHnX0B35ydj91814CHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHl+d/A9cKjmiL040TAAAAAElFTkSuQmCC',
419
- qrcode: 'https://pdfme.com/',
420
- japanpost: '6540123789-A-K-Z',
421
- ean13: '2112345678900',
422
- ean8: '02345673',
423
- code39: 'THIS IS CODE 39',
424
- code128: 'This is Code 128!',
425
- nw7: 'A0123456789B',
426
- itf14: '04601234567893',
427
- upca: '416000336108',
428
- upce: '00123457',
429
- gs1datamatrix: '(01)03453120000011(17)191125(10)ABCD1234',
430
- };
431
- return defaultValue[type];
432
- };
433
-
434
- export const getKeepRatioHeightByWidth = (type: BarCodeType, width: number) => {
435
- const ratio: { [K in BarCodeType]: number } = {
436
- qrcode: 1,
437
- japanpost: 0.09,
438
- ean13: 0.4,
439
- ean8: 0.5,
440
- code39: 0.5,
441
- code128: 0.5,
442
- nw7: 0.5,
443
- itf14: 0.3,
444
- upca: 0.4,
445
- upce: 0.5,
446
- gs1datamatrix: 1,
447
- };
448
- return width * ratio[type];
449
- };
450
-
451
348
  export const getUniqSchemaKey = (arg: {
452
349
  copiedSchemaKey: string;
453
350
  schema: SchemaForUI[];
package/src/hooks.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { RefObject, useRef, useState, useCallback, useEffect } from 'react';
2
- import { Template, Size, getB64BasePdf } from '@pdfme/common';
2
+ import { ZOOM, Template, Size, getB64BasePdf } from '@pdfme/common';
3
3
  import { pdf2Pngs, getPdfPageSizes, b64toBlob } from './helper';
4
- import { ZOOM, RULER_HEIGHT } from './constants';
4
+ import { RULER_HEIGHT } from './constants';
5
5
 
6
6
  export const usePrevious = <T>(value: T) => {
7
7
  const ref = useRef<T | null>(null);
@@ -23,7 +23,7 @@ export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorP
23
23
  const [scale, setScale] = useState(0);
24
24
  const [error, setError] = useState<Error | null>(null);
25
25
 
26
- const init = async (prop: { template: Template; size: Size; }) => {
26
+ const init = async (prop: { template: Template; size: Size }) => {
27
27
  const { template, size } = prop;
28
28
  const _basePdf = await getB64BasePdf(template.basePdf);
29
29
  const pdfBlob = b64toBlob(_basePdf);
@@ -44,8 +44,9 @@ export const useUIPreProcessor = ({ template, size, zoomLevel }: UIPreProcessorP
44
44
  .then(({ pageSizes, scale, backgrounds }) => {
45
45
  setPageSizes(pageSizes), setScale(scale), setBackgrounds(backgrounds);
46
46
  })
47
- .catch((e: Error) => {
48
- setError(e);
47
+ .catch((err: Error) => {
48
+ setError(err);
49
+ console.error(`[@pdfme/ui] ${err}`);
49
50
  });
50
51
  }, [template, size]);
51
52
 
package/src/i18n.ts CHANGED
@@ -8,13 +8,12 @@ const dictEn = {
8
8
  fieldName: 'Name',
9
9
  require: 'Required',
10
10
  uniq: 'Unique',
11
- inputExample: 'Input Example',
12
11
  edit: 'Edit',
13
12
  plsInputName: 'Please input name',
14
13
  fieldMustUniq: 'Name of field is not unique',
15
14
  notUniq: '(Not unique name)',
16
15
  noKeyName: 'No name',
17
- fieldsList: 'List of Fields',
16
+ fieldsList: 'Field List',
18
17
  addNewField: 'Add new field',
19
18
  editField: 'Edit Field',
20
19
  type: 'Type',
@@ -23,6 +22,9 @@ const dictEn = {
23
22
  'Cannot commit the change because the number of items has been changed.',
24
23
  commitBulkUpdateFieldName: 'Commit Changes',
25
24
  bulkUpdateFieldName: 'Bulk update field names',
25
+ barColor: 'Bar Color',
26
+ textColor: 'Text Color',
27
+ bgColor: 'Background Color',
26
28
  };
27
29
 
28
30
  const dictJa: { [key in keyof DictEn]: string } = {
@@ -31,7 +33,6 @@ const dictJa: { [key in keyof DictEn]: string } = {
31
33
  fieldName: '項目名',
32
34
  require: '必須',
33
35
  uniq: '他の項目名と同一不可',
34
- inputExample: '記入例',
35
36
  edit: '編集する',
36
37
  plsInputName: '項目名を入力してください',
37
38
  fieldMustUniq: '他の入力項目名と被っています',
@@ -45,6 +46,9 @@ const dictJa: { [key in keyof DictEn]: string } = {
45
46
  errorBulkUpdateFieldName: '項目数が変更されているため変更をコミットできません。',
46
47
  commitBulkUpdateFieldName: '変更を反映',
47
48
  bulkUpdateFieldName: '項目名を一括変更',
49
+ barColor: 'バーの色',
50
+ textColor: 'テキストの色',
51
+ bgColor: '背景色',
48
52
  };
49
53
 
50
54
  const dictAr: { [key in keyof DictEn]: string } = {
@@ -53,7 +57,6 @@ const dictAr: { [key in keyof DictEn]: string } = {
53
57
  fieldName: 'اسم الحقل',
54
58
  require: 'مطلوب',
55
59
  uniq: 'يجب أن يكون فريداً',
56
- inputExample: 'مثال',
57
60
  edit: 'تعديل',
58
61
  plsInputName: 'الرجاء إدخال الاسم',
59
62
  fieldMustUniq: 'يجب أن يكون الحقل فريداً',
@@ -67,6 +70,9 @@ const dictAr: { [key in keyof DictEn]: string } = {
67
70
  errorBulkUpdateFieldName: 'لا يمكن تنفيذ التغيير لأنه تم تغيير عدد العناصر.',
68
71
  commitBulkUpdateFieldName: 'تنفيذ التغييرات',
69
72
  bulkUpdateFieldName: 'تغيير الأسماء',
73
+ barColor: 'لون الشريط',
74
+ textColor: 'لون الخط',
75
+ bgColor: 'لون الخلفية',
70
76
  };
71
77
 
72
78
  const dictTh: { [key in keyof DictEn]: string } = {
@@ -75,7 +81,6 @@ const dictTh: { [key in keyof DictEn]: string } = {
75
81
  fieldName: 'ชื่อฟิลด์',
76
82
  require: 'จำเป็น',
77
83
  uniq: 'ต้องไม่ซ้ำกัน',
78
- inputExample: 'ตัวอย่าง',
79
84
  edit: 'แก้ไข',
80
85
  plsInputName: 'กรุณาใส่ชื่อ',
81
86
  fieldMustUniq: 'ชื่อฟิลด์ต้องไม่ซ้ำกัน',
@@ -89,15 +94,42 @@ const dictTh: { [key in keyof DictEn]: string } = {
89
94
  errorBulkUpdateFieldName: 'ไม่สามารถยืนยันการแก้ไขได้เนื่องจากจำนวนรายการมีการเปลี่ยนแปลง',
90
95
  commitBulkUpdateFieldName: 'ยืนยันการแก้ไข',
91
96
  bulkUpdateFieldName: 'แก้ไขชื่อฟิลด์เป็นชุด',
97
+ barColor: 'สีบาร์',
98
+ textColor: 'สีข้อความ',
99
+ bgColor: 'สีพื้นหลัง',
92
100
  };
93
101
 
94
- const dictPl: {[key in keyof DictEn]: string} = {
102
+ const dictIt: { [key in keyof DictEn]: string } = {
103
+ cancel: 'Annulla',
104
+ field: 'Campo',
105
+ fieldName: 'Nome',
106
+ require: 'Richiesto',
107
+ uniq: 'Univoco',
108
+ edit: 'Modifica',
109
+ plsInputName: 'Inserisci il nome per favore',
110
+ fieldMustUniq: 'Il nome del campo non è univoco',
111
+ notUniq: '(Nome non univoco)',
112
+ noKeyName: 'Nessun nome',
113
+ fieldsList: 'Lista campi',
114
+ addNewField: 'Aggiungi un campo',
115
+ editField: 'Modifica campo',
116
+ type: 'Tipo',
117
+ errorOccurred: 'Riscontrato errore',
118
+ errorBulkUpdateFieldName:
119
+ 'Non è possibile salvare le modifiche perché il numero di elementi è cambiato.',
120
+ commitBulkUpdateFieldName: 'Salva cambiamenti',
121
+ bulkUpdateFieldName: 'Modifica nomi campi in blocco',
122
+ barColor: 'Colore barra',
123
+ textColor: 'Colore testo',
124
+ bgColor: 'Colore sfondo',
125
+ };
126
+
127
+ const dictPl: { [key in keyof DictEn]: string } = {
95
128
  cancel: 'Anuluj',
96
129
  field: 'pole',
97
130
  fieldName: 'Klucz pola',
98
131
  require: 'wymagany',
99
132
  uniq: 'unikalny',
100
- inputExample: 'Przykład',
101
133
  edit: 'Edytuj',
102
134
  plsInputName: 'Wymagane wprowadzenie klucza pola',
103
135
  fieldMustUniq: 'Klucz pola nie jest unikalny',
@@ -108,11 +140,13 @@ const dictPl: {[key in keyof DictEn]: string} = {
108
140
  editField: 'Edytuj pole',
109
141
  type: 'Typ pola',
110
142
  errorOccurred: 'Wystąpił błąd',
111
- errorBulkUpdateFieldName:
112
- 'Nie można wprowadzić zmian ponieważ liczba elementów uległa zmianie.',
143
+ errorBulkUpdateFieldName: 'Nie można wprowadzić zmian ponieważ liczba elementów uległa zmianie.',
113
144
  commitBulkUpdateFieldName: 'Zaakceptuj zmiany',
114
- bulkUpdateFieldName: 'Masowo aktualizuj klucze pól',
115
- }
145
+ bulkUpdateFieldName: 'Masowo aktualizuj klucze pól',
146
+ barColor: 'Kolor paska',
147
+ textColor: 'Kolor tekstu',
148
+ bgColor: 'Kolor tła',
149
+ };
116
150
 
117
151
  const i18n = (lang: Lang, key: keyof DictEn) => {
118
152
  switch (lang) {
@@ -127,6 +161,9 @@ const i18n = (lang: Lang, key: keyof DictEn) => {
127
161
  case 'ja':
128
162
  return dictJa[key];
129
163
 
164
+ case 'it':
165
+ return dictIt[key];
166
+
130
167
  default:
131
168
  return dictEn[key];
132
169
  }
package/src/index.ts CHANGED
@@ -2,79 +2,4 @@ import Designer from './Designer';
2
2
  import Form from './Form';
3
3
  import Viewer from './Viewer';
4
4
 
5
- import {
6
- BLANK_PDF,
7
- DEFAULT_FONT_VALUE,
8
- isTextSchema,
9
- isImageSchema,
10
- isBarcodeSchema,
11
- checkTemplate,
12
- checkUIProps,
13
- checkPreviewProps,
14
- checkDesignerProps,
15
- checkGenerateProps,
16
- validateBarcodeInput,
17
- } from '@pdfme/common';
18
-
19
- import type {
20
- Lang,
21
- Size,
22
- Alignment,
23
- SchemaType,
24
- BarCodeType,
25
- TextSchema,
26
- ImageSchema,
27
- BarcodeSchema,
28
- Schema,
29
- SchemaForUI,
30
- Font,
31
- BasePdf,
32
- Template,
33
- CommonProps,
34
- GeneratorOptions,
35
- GenerateProps,
36
- UIOptions,
37
- UIProps,
38
- PreviewProps,
39
- DesignerProps,
40
- } from '@pdfme/common';
41
-
42
- export {
43
- Designer,
44
- Viewer,
45
- Form,
46
- BLANK_PDF,
47
- DEFAULT_FONT_VALUE,
48
- isTextSchema,
49
- isImageSchema,
50
- isBarcodeSchema,
51
- checkTemplate,
52
- checkUIProps,
53
- checkPreviewProps,
54
- checkDesignerProps,
55
- checkGenerateProps,
56
- validateBarcodeInput,
57
- };
58
-
59
- export type {
60
- Lang,
61
- Size,
62
- Alignment,
63
- SchemaType,
64
- BarCodeType,
65
- TextSchema,
66
- ImageSchema,
67
- BarcodeSchema,
68
- Schema,
69
- SchemaForUI,
70
- Font,
71
- BasePdf,
72
- Template,
73
- CommonProps,
74
- GeneratorOptions,
75
- GenerateProps,
76
- UIOptions,
77
- UIProps,
78
- PreviewProps,
79
- DesignerProps,
80
- };
5
+ export { Designer, Viewer, Form };
package/src/types.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type {
2
+ UIRenderProps,
3
+ SchemaForUI,
4
+ Size,
5
+ Schema,
6
+ ChangeSchemas,
7
+ PropPanel,
8
+ } from '@pdfme/common';
9
+
10
+ export type SidebarProps = {
11
+ height: number;
12
+ hoveringSchemaId: string | null;
13
+ onChangeHoveringSchemaId: (id: string | null) => void;
14
+ size: Size;
15
+ pageSize: Size;
16
+ activeElements: HTMLElement[];
17
+ schemas: SchemaForUI[];
18
+ onSortEnd: (sortedSchemas: SchemaForUI[]) => void;
19
+ onEdit: (id: string) => void;
20
+ onEditEnd: () => void;
21
+ changeSchemas: ChangeSchemas;
22
+ addSchema: () => void;
23
+ deselectSchema: () => void;
24
+ sidebarOpen: boolean;
25
+ setSidebarOpen: (sidebarOpen: boolean) => void;
26
+ };
27
+
28
+ export type UIRender = (arg: UIRenderProps<Schema>) => Promise<void>;
29
+
30
+ export interface UIRenderer {
31
+ [key: string]: UIRender | undefined;
32
+ }
33
+
34
+ export interface PropPanelObject {
35
+ [key: string]: PropPanel<Schema> | undefined;
36
+ }
package/tsconfig.json CHANGED
@@ -17,7 +17,8 @@
17
17
  "sourceMap": true,
18
18
  "baseUrl": "..",
19
19
  "paths": {
20
- "@pdfme/common": ["packages/common/src"]
20
+ "@pdfme/common": ["packages/common/src"],
21
+ "@pdfme/schemas": ["packages/schemas/src"]
21
22
  }
22
23
  },
23
24
  "baseUrl": ".",
package/webpack.config.js CHANGED
@@ -30,6 +30,11 @@ const config = {
30
30
  globalObject: 'this',
31
31
  library: { type: 'umd' },
32
32
  },
33
- module: { rules: [{ test: /\.tsx?$/, use: 'ts-loader' }] },
33
+ module: {
34
+ rules: [
35
+ { test: /\.tsx?$/, use: 'ts-loader' },
36
+ { test: /\.css$/i, use: ['style-loader', 'css-loader'] }
37
+ ]
38
+ },
34
39
  };
35
40
  module.exports = config;
@@ -1,3 +0,0 @@
1
- import { Size } from '@pdfme/common';
2
- declare const Mask: ({ width, height }: Size) => JSX.Element;
3
- export default Mask;
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { OnDrag, OnResize, OnDragEnd, OnDragGroupEnd, OnResizeEnd, OnResizeGroupEnd, OnClick } from 'react-moveable';
3
- declare type Props = {
4
- target: HTMLElement[];
5
- bounds: {
6
- left: number;
7
- top: number;
8
- bottom: number;
9
- right: number;
10
- };
11
- horizontalGuidelines: number[];
12
- verticalGuidelines: number[];
13
- keepRatio: boolean;
14
- onDrag: ((e: OnDrag) => void) & (({ target, left, top }: OnDrag) => void);
15
- onDragEnd: ((e: OnDragEnd) => void) & (({ target }: {
16
- target: HTMLElement | SVGElement;
17
- }) => void);
18
- onDragGroupEnd: ((e: OnDragGroupEnd) => void) & (({ targets }: {
19
- targets: (HTMLElement | SVGElement)[];
20
- }) => void);
21
- onResize: ((e: OnResize) => void) & (({ target, width, height, direction }: OnResize) => void);
22
- onResizeEnd: ((e: OnResizeEnd) => void) & (({ target }: {
23
- target: HTMLElement | SVGElement;
24
- }) => void);
25
- onResizeGroupEnd: ((e: OnResizeGroupEnd) => void) & (({ targets }: {
26
- targets: (HTMLElement | SVGElement)[];
27
- }) => void);
28
- onClick: (e: OnClick) => void;
29
- };
30
- declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<any>>;
31
- export default _default;
@@ -1,6 +0,0 @@
1
- import { SchemaForUI } from '@pdfme/common';
2
- import { SidebarProps } from '..';
3
- declare const ExampleInputEditor: (props: Pick<SidebarProps, 'changeSchemas'> & {
4
- activeSchema: SchemaForUI;
5
- }) => JSX.Element;
6
- export default ExampleInputEditor;
@@ -1,6 +0,0 @@
1
- import { SchemaForUI } from '@pdfme/common';
2
- import { SidebarProps } from '../index';
3
- declare const PositionAndSizeEditor: (props: Pick<SidebarProps, 'pageSize' | 'schemas' | 'changeSchemas' | 'activeElements'> & {
4
- activeSchema: SchemaForUI;
5
- }) => JSX.Element;
6
- export default PositionAndSizeEditor;