@pdfme/ui 4.0.0-alpha.0 → 4.0.0

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 (38) hide show
  1. package/README.md +1 -0
  2. package/dist/index.es.js +55912 -55715
  3. package/dist/index.umd.js +93 -94
  4. package/dist/types/Designer.d.ts +2 -0
  5. package/dist/types/class.d.ts +4 -1
  6. package/dist/types/components/Designer/LeftSidebar.d.ts +8 -0
  7. package/dist/types/components/Designer/index.d.ts +4 -1
  8. package/dist/types/components/Renderer.d.ts +1 -1
  9. package/dist/types/constants.d.ts +1 -1
  10. package/dist/types/contexts.d.ts +1 -2
  11. package/dist/types/helper.d.ts +1 -0
  12. package/dist/types/types.d.ts +0 -1
  13. package/package.json +1 -1
  14. package/src/Designer.tsx +8 -0
  15. package/src/components/Designer/Canvas/index.tsx +4 -3
  16. package/src/components/Designer/LeftSidebar.tsx +81 -0
  17. package/src/components/Designer/{Sidebar → RightSidebar}/DetailView/index.tsx +1 -2
  18. package/src/components/Designer/{Sidebar → RightSidebar}/ListView/index.tsx +3 -11
  19. package/src/components/Designer/{Sidebar → RightSidebar}/index.tsx +5 -20
  20. package/src/components/Designer/index.tsx +123 -76
  21. package/src/components/Renderer.tsx +3 -1
  22. package/src/constants.ts +1 -1
  23. package/src/helper.ts +1 -1
  24. package/src/i18n.ts +122 -7
  25. package/src/types.ts +0 -1
  26. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/DetailView/AlignWidget.d.ts +0 -0
  27. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/DetailView/WidgetRenderer.d.ts +0 -0
  28. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/DetailView/index.d.ts +0 -0
  29. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/ListView/Item.d.ts +0 -0
  30. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/ListView/SelectableSortableContainer.d.ts +0 -0
  31. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/ListView/SelectableSortableItem.d.ts +0 -0
  32. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/ListView/index.d.ts +0 -0
  33. /package/dist/types/components/Designer/{Sidebar → RightSidebar}/index.d.ts +0 -0
  34. /package/src/components/Designer/{Sidebar → RightSidebar}/DetailView/AlignWidget.tsx +0 -0
  35. /package/src/components/Designer/{Sidebar → RightSidebar}/DetailView/WidgetRenderer.tsx +0 -0
  36. /package/src/components/Designer/{Sidebar → RightSidebar}/ListView/Item.tsx +0 -0
  37. /package/src/components/Designer/{Sidebar → RightSidebar}/ListView/SelectableSortableContainer.tsx +0 -0
  38. /package/src/components/Designer/{Sidebar → RightSidebar}/ListView/SelectableSortableItem.tsx +0 -0
@@ -3,11 +3,13 @@ import { BaseUIClass } from './class';
3
3
  declare class Designer extends BaseUIClass {
4
4
  private onSaveTemplateCallback?;
5
5
  private onChangeTemplateCallback?;
6
+ private pageCursor;
6
7
  constructor(props: DesignerProps);
7
8
  saveTemplate(): void;
8
9
  updateTemplate(template: Template): void;
9
10
  onSaveTemplate(cb: (template: Template) => void): void;
10
11
  onChangeTemplate(cb: (template: Template) => void): void;
12
+ getPageCursor(): number;
11
13
  protected render(): void;
12
14
  }
13
15
  export default Designer;
@@ -10,7 +10,7 @@ export declare abstract class BaseUIClass {
10
10
  private readonly setSize;
11
11
  resizeObserver: ResizeObserver;
12
12
  constructor(props: UIProps);
13
- protected getLang(): "en" | "th" | "pl" | "ja" | "ar" | "it" | "de";
13
+ protected getLang(): "en" | "th" | "pl" | "ja" | "ar" | "it" | "de" | "es" | "fr";
14
14
  protected getFont(): Record<string, {
15
15
  data: (string | ArrayBuffer | Uint8Array) & (string | ArrayBuffer | Uint8Array | undefined);
16
16
  fallback?: boolean | undefined;
@@ -21,6 +21,7 @@ export declare abstract class BaseUIClass {
21
21
  getTemplate(): import("zod").objectOutputType<{
22
22
  schemas: import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
23
23
  type: import("zod").ZodString;
24
+ icon: import("zod").ZodOptional<import("zod").ZodString>;
24
25
  content: import("zod").ZodOptional<import("zod").ZodString>;
25
26
  position: import("zod").ZodObject<{
26
27
  x: import("zod").ZodNumber;
@@ -39,6 +40,7 @@ export declare abstract class BaseUIClass {
39
40
  readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
40
41
  }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
41
42
  type: import("zod").ZodString;
43
+ icon: import("zod").ZodOptional<import("zod").ZodString>;
42
44
  content: import("zod").ZodOptional<import("zod").ZodString>;
43
45
  position: import("zod").ZodObject<{
44
46
  x: import("zod").ZodNumber;
@@ -57,6 +59,7 @@ export declare abstract class BaseUIClass {
57
59
  readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
58
60
  }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
59
61
  type: import("zod").ZodString;
62
+ icon: import("zod").ZodOptional<import("zod").ZodString>;
60
63
  content: import("zod").ZodOptional<import("zod").ZodString>;
61
64
  position: import("zod").ZodObject<{
62
65
  x: import("zod").ZodNumber;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { BasePdf } from '@pdfme/common';
3
+ declare const LeftSidebar: ({ height, scale, basePdf }: {
4
+ height: number;
5
+ scale: number;
6
+ basePdf: BasePdf;
7
+ }) => React.JSX.Element;
8
+ export default LeftSidebar;
@@ -1,8 +1,11 @@
1
1
  import React from 'react';
2
2
  import { Template, DesignerProps, Size } from '@pdfme/common';
3
- declare const TemplateEditor: ({ template, size, onSaveTemplate, onChangeTemplate, }: Omit<DesignerProps, "domContainer"> & {
3
+ declare const TemplateEditor: ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, }: Omit<DesignerProps, "domContainer"> & {
4
4
  size: Size;
5
5
  onSaveTemplate: (t: Template) => void;
6
6
  onChangeTemplate: (t: Template) => void;
7
+ } & {
8
+ onChangeTemplate: (t: Template) => void;
9
+ onPageCursorChange: (newPageCursor: number) => void;
7
10
  }) => React.JSX.Element;
8
11
  export default TemplateEditor;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { UIRenderProps, SchemaForUI, BasePdf, Schema } from '@pdfme/common';
3
- type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'options' | 'theme' | 'i18n' | '_cache'> & {
3
+ type RendererProps = Omit<UIRenderProps<Schema>, 'schema' | 'rootElement' | 'options' | 'theme' | 'i18n' | 'pdfJs' | '_cache'> & {
4
4
  basePdf: BasePdf;
5
5
  schema: SchemaForUI;
6
6
  value: string;
@@ -3,5 +3,5 @@ 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 SIDEBAR_WIDTH = 400;
6
+ export declare const RIGHT_SIDEBAR_WIDTH = 400;
7
7
  export declare const BACKGROUND_COLOR = "rgb(74, 74, 74)";
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Plugins, UIOptions } from '@pdfme/common';
3
- export declare const I18nContext: import("react").Context<(key: "type" | "width" | "height" | "rotate" | "opacity" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "hexColorPrompt" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle", dict?: {
3
+ export declare const I18nContext: import("react").Context<(key: "type" | "width" | "height" | "rotate" | "opacity" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "hexColorPrompt" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle", dict?: {
4
4
  cancel: string;
5
5
  field: string;
6
6
  fieldName: string;
@@ -15,7 +15,6 @@ export declare const I18nContext: import("react").Context<(key: "type" | "width"
15
15
  notUniq: string;
16
16
  noKeyName: string;
17
17
  fieldsList: string;
18
- addNewField: string;
19
18
  editField: string;
20
19
  type: string;
21
20
  errorOccurred: string;
@@ -36,6 +36,7 @@ export declare const template2SchemasList: (_template: Template) => Promise<{
36
36
  key: string;
37
37
  opacity?: number | undefined;
38
38
  rotate?: number | undefined;
39
+ icon?: string | undefined;
39
40
  content?: string | undefined;
40
41
  readOnly?: boolean | undefined;
41
42
  }[][]>;
@@ -11,7 +11,6 @@ export type SidebarProps = {
11
11
  onEdit: (id: string) => void;
12
12
  onEditEnd: () => void;
13
13
  changeSchemas: ChangeSchemas;
14
- addSchema: () => void;
15
14
  deselectSchema: () => void;
16
15
  sidebarOpen: boolean;
17
16
  setSidebarOpen: (sidebarOpen: boolean) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "4.0.0-alpha.0",
3
+ "version": "4.0.0",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
package/src/Designer.tsx CHANGED
@@ -16,6 +16,7 @@ import { cloneDeep } from './helper.js';
16
16
  class Designer extends BaseUIClass {
17
17
  private onSaveTemplateCallback?: (template: Template) => void;
18
18
  private onChangeTemplateCallback?: (template: Template) => void;
19
+ private pageCursor: number = 0;
19
20
 
20
21
  constructor(props: DesignerProps) {
21
22
  super(props);
@@ -46,6 +47,10 @@ class Designer extends BaseUIClass {
46
47
  public onChangeTemplate(cb: (template: Template) => void) {
47
48
  this.onChangeTemplateCallback = cb;
48
49
  }
50
+
51
+ public getPageCursor() {
52
+ return this.pageCursor
53
+ }
49
54
 
50
55
  protected render() {
51
56
  if (!this.domContainer) throw Error(DESTROYED_ERR_MSG);
@@ -71,6 +76,9 @@ class Designer extends BaseUIClass {
71
76
  this.onChangeTemplateCallback(template);
72
77
  }
73
78
  }}
79
+ onPageCursorChange={(newPageCursor: number) => {
80
+ this.pageCursor = newPageCursor
81
+ }}
74
82
  size={this.size}
75
83
  />
76
84
  </AppContextProvider>,
@@ -14,7 +14,7 @@ import { OnDrag, OnResize, OnClick, OnRotate } from 'react-moveable';
14
14
  import { ZOOM, SchemaForUI, Size, ChangeSchemas, BasePdf, isBlankPdf } from '@pdfme/common';
15
15
  import { PluginsRegistry } from '../../../contexts';
16
16
  import { CloseOutlined } from '@ant-design/icons';
17
- import { RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants';
17
+ import { RULER_HEIGHT, RIGHT_SIDEBAR_WIDTH } from '../../../constants';
18
18
  import { usePrevious } from '../../../hooks';
19
19
  import { uuid, round, flatten } from '../../../helper';
20
20
  import Paper from '../../Paper';
@@ -25,8 +25,10 @@ import Guides from './Guides';
25
25
  import Mask from './Mask';
26
26
  import Padding from './Padding';
27
27
 
28
+
28
29
  const mm2px = (mm: number) => mm * 3.7795275591;
29
30
 
31
+
30
32
  const DELETE_BTN_ID = uuid();
31
33
  const fmt4Num = (prop: string) => Number(prop.replace('px', ''));
32
34
  const fmt = (prop: string) => round(fmt4Num(prop) / ZOOM, 2);
@@ -111,7 +113,6 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
111
113
  } = props;
112
114
  const { token } = theme.useToken();
113
115
  const pluginsRegistry = useContext(PluginsRegistry);
114
-
115
116
  const verticalGuides = useRef<GuidesInterface[]>([]);
116
117
  const horizontalGuides = useRef<GuidesInterface[]>([]);
117
118
  const moveable = useRef<any>(null);
@@ -337,7 +338,7 @@ const Canvas = (props: Props, ref: Ref<HTMLDivElement>) => {
337
338
  style={{
338
339
  position: 'relative',
339
340
  overflow: 'auto',
340
- marginRight: sidebarOpen ? SIDEBAR_WIDTH : 0,
341
+ marginRight: sidebarOpen ? RIGHT_SIDEBAR_WIDTH : 0,
341
342
  ...size,
342
343
  }}
343
344
  ref={ref}
@@ -0,0 +1,81 @@
1
+ import React, { useContext } from 'react';
2
+ import {
3
+ Schema,
4
+ Plugin,
5
+ BasePdf,
6
+ } from '@pdfme/common';
7
+ import { theme, Button } from 'antd';
8
+ import { useDraggable } from '@dnd-kit/core';
9
+ import { CSS } from "@dnd-kit/utilities";
10
+ import Renderer from '../Renderer';
11
+ import { PluginsRegistry } from '../../contexts';
12
+
13
+ const Draggable = (props: { plugin: Plugin<any>, scale: number, basePdf: BasePdf, children: React.ReactNode }) => {
14
+ const { scale, basePdf, plugin } = props;
15
+ const { token } = theme.useToken();
16
+ const defaultSchema = plugin.propPanel.defaultSchema as Schema;
17
+ const draggable = useDraggable({ id: defaultSchema.type, data: defaultSchema });
18
+ const { listeners, setNodeRef, attributes, transform, isDragging } = draggable;
19
+ const style = { transform: CSS.Translate.toString(transform) }
20
+
21
+ return (
22
+ <div ref={setNodeRef} style={style} {...listeners} {...attributes}>
23
+ {isDragging &&
24
+ <div style={{ transform: `scale(${scale})` }}>
25
+ <Renderer
26
+ key={defaultSchema.type}
27
+ schema={{ ...defaultSchema, id: defaultSchema.type, key: defaultSchema.type }}
28
+ basePdf={basePdf}
29
+ value={defaultSchema.content || ''}
30
+ onChangeHoveringSchemaId={() => { void 0 }}
31
+ mode={'viewer'}
32
+ outline={`1px solid ${token.colorPrimary}`}
33
+ scale={scale}
34
+ />
35
+ </div>
36
+ }
37
+ <div style={{ visibility: isDragging ? 'hidden' : 'visible' }}>
38
+ {props.children}
39
+ </div>
40
+ </div>
41
+ );
42
+ }
43
+
44
+ const LeftSidebar = ({ height, scale, basePdf }: { height: number, scale: number, basePdf: BasePdf }) => {
45
+ const { token } = theme.useToken();
46
+ const pluginsRegistry = useContext(PluginsRegistry);
47
+
48
+ return <div
49
+ style={{
50
+ left: 0,
51
+ position: 'absolute',
52
+ right: 0,
53
+ zIndex: 1,
54
+ height,
55
+ background: token.colorBgLayout,
56
+ textAlign: 'center',
57
+ width: 45,
58
+ }}
59
+ >
60
+ {Object.entries(pluginsRegistry).map(([label, plugin]) => {
61
+ if (!plugin?.propPanel.defaultSchema) return null;
62
+ return <Draggable
63
+ key={label}
64
+ scale={scale}
65
+ basePdf={basePdf}
66
+ plugin={plugin}>
67
+ <Button
68
+ title={label}
69
+ style={{ width: 35, height: 35, marginTop: '0.25rem', padding: '0.25rem' }}>
70
+ {plugin.propPanel.defaultSchema.icon ?
71
+ <div dangerouslySetInnerHTML={{ __html: plugin.propPanel.defaultSchema.icon }} />
72
+ :
73
+ <div style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</div>
74
+ }
75
+ </Button>
76
+ </Draggable>
77
+ })}
78
+ </div>
79
+ }
80
+
81
+ export default LeftSidebar
@@ -206,8 +206,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
206
206
  style={{
207
207
  height: getSidebarContentHeight(size.height),
208
208
  overflowY: 'auto',
209
- overflowX: 'hidden',
210
- borderBottom: `1px solid ${token.colorSplit}`,
209
+ overflowX: 'hidden'
211
210
  }}
212
211
  >
213
212
  <FormRender
@@ -1,6 +1,6 @@
1
1
  import React, { useContext, useState } from 'react';
2
2
  import type { SidebarProps } from '../../../../types';
3
- import { SIDEBAR_WIDTH } from '../../../../constants';
3
+ import { RIGHT_SIDEBAR_WIDTH } from '../../../../constants';
4
4
  import { I18nContext } from '../../../../contexts';
5
5
  import { getSidebarContentHeight } from '../../../../helper';
6
6
  import { theme, Input, Typography, Divider, Button } from 'antd';
@@ -76,7 +76,7 @@ const ListView = (
76
76
  style={{
77
77
  paddingLeft: 30,
78
78
  height: height - headHeight,
79
- width: SIDEBAR_WIDTH - 35,
79
+ width: RIGHT_SIDEBAR_WIDTH - 35,
80
80
  lineHeight: '2.75rem',
81
81
  }}
82
82
  />
@@ -89,15 +89,7 @@ const ListView = (
89
89
  onEdit={onEdit}
90
90
  />
91
91
  )}
92
- <div
93
- style={{
94
- display: 'flex',
95
- alignItems: 'center',
96
- justifyContent: 'flex-end',
97
- height: headHeight,
98
- borderBottom: `1px solid ${token.colorSplit}`,
99
- }}
100
- >
92
+ <div style={{ paddingTop: '0.5rem', display: 'flex', alignItems: 'center', justifyContent: 'flex-end' }}>
101
93
  {isBulkUpdateFieldNamesMode ? (
102
94
  <>
103
95
  <Button size="small" type="text" onClick={commitBulk}>
@@ -1,17 +1,15 @@
1
- import React, { useContext } from 'react';
1
+ import React from 'react';
2
2
  import { theme, Button } from 'antd';
3
3
  import type { SidebarProps } from '../../../types';
4
- import { SIDEBAR_WIDTH } from '../../../constants';
5
- import { I18nContext } from '../../../contexts';
4
+ import { RIGHT_SIDEBAR_WIDTH } from '../../../constants';
6
5
  import { ArrowLeftOutlined, ArrowRightOutlined } from '@ant-design/icons';
7
6
  import ListView from './ListView/index';
8
7
  import DetailView from './DetailView/index';
9
8
 
10
9
  const Sidebar = (props: SidebarProps) => {
11
- const { sidebarOpen, setSidebarOpen, activeElements, schemas, addSchema } = props;
10
+ const { sidebarOpen, setSidebarOpen, activeElements, schemas } = props;
12
11
 
13
12
  const { token } = theme.useToken();
14
- const i18n = useContext(I18nContext);
15
13
  const getActiveSchemas = () =>
16
14
  schemas.filter((s) => activeElements.map((ae) => ae.id).includes(s.id));
17
15
  const getLastActiveSchema = () => {
@@ -26,7 +24,7 @@ const Sidebar = (props: SidebarProps) => {
26
24
  right: 0,
27
25
  zIndex: 1,
28
26
  height: '100%',
29
- width: sidebarOpen ? SIDEBAR_WIDTH : 0,
27
+ width: sidebarOpen ? RIGHT_SIDEBAR_WIDTH : 0,
30
28
  }}
31
29
  >
32
30
  <div>
@@ -45,7 +43,7 @@ const Sidebar = (props: SidebarProps) => {
45
43
  />
46
44
  <div
47
45
  style={{
48
- width: SIDEBAR_WIDTH,
46
+ width: RIGHT_SIDEBAR_WIDTH,
49
47
  height: '100%',
50
48
  display: sidebarOpen ? 'block' : 'none',
51
49
  top: 0,
@@ -65,19 +63,6 @@ const Sidebar = (props: SidebarProps) => {
65
63
  <DetailView {...props} activeSchema={getLastActiveSchema()} />
66
64
  )}
67
65
  </div>
68
- <div
69
- style={{
70
- position: 'absolute',
71
- bottom: '1.5rem',
72
- marginTop: '1rem',
73
- left: '50%',
74
- transform: 'translateX(-50%)',
75
- }}
76
- >
77
- <Button type="primary" style={{ fontWeight: 600 }} onClick={addSchema}>
78
- {i18n('addNewField')}
79
- </Button>
80
- </div>
81
66
  </div>
82
67
  </div>
83
68
  </div>