@pdfme/ui 1.0.0-beta.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.
- package/.eslintrc.js +45 -0
- package/README.md +280 -0
- package/declaration.d.ts +8 -0
- package/dist/@pdfme/ui.js +3 -0
- package/dist/@pdfme/ui.js.LICENSE.txt +95 -0
- package/dist/@pdfme/ui.js.map +1 -0
- package/dist/types/common/src/barcode.d.ts +2 -0
- package/dist/types/common/src/constants.d.ts +6 -0
- package/dist/types/common/src/helper.d.ts +15 -0
- package/dist/types/common/src/index.d.ts +4 -0
- package/dist/types/common/src/schema.d.ts +3613 -0
- package/dist/types/common/src/type.d.ts +64 -0
- package/dist/types/common/src/utils.d.ts +12 -0
- package/dist/types/ui/src/Designer.d.ts +13 -0
- package/dist/types/ui/src/Form.d.ts +13 -0
- package/dist/types/ui/src/Viewer.d.ts +7 -0
- package/dist/types/ui/src/class.d.ts +72 -0
- package/dist/types/ui/src/components/Designer/Main/Guides.d.ts +9 -0
- package/dist/types/ui/src/components/Designer/Main/Mask.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Main/Moveable.d.ts +31 -0
- package/dist/types/ui/src/components/Designer/Main/Selecto.d.ts +8 -0
- package/dist/types/ui/src/components/Designer/Main/index.d.ts +24 -0
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/TextPropEditor.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/index.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/ListView.d.ts +3 -0
- package/dist/types/ui/src/components/Designer/Sidebar/index.d.ts +26 -0
- package/dist/types/ui/src/components/Designer/index.d.ts +99 -0
- package/dist/types/ui/src/components/Divider.d.ts +2 -0
- package/dist/types/ui/src/components/Error.d.ts +7 -0
- package/dist/types/ui/src/components/Paper.d.ts +19 -0
- package/dist/types/ui/src/components/Preview/Pager/Page.d.ts +8 -0
- package/dist/types/ui/src/components/Preview/Pager/Unit.d.ts +8 -0
- package/dist/types/ui/src/components/Preview/index.d.ts +4 -0
- package/dist/types/ui/src/components/Root.d.ts +9 -0
- package/dist/types/ui/src/components/Schemas/BarcodeSchema.d.ts +15 -0
- package/dist/types/ui/src/components/Schemas/ImageSchema.d.ts +15 -0
- package/dist/types/ui/src/components/Schemas/SchemaUI.d.ts +14 -0
- package/dist/types/ui/src/components/Schemas/TextSchema.d.ts +22 -0
- package/dist/types/ui/src/components/Spinner.d.ts +2 -0
- package/dist/types/ui/src/constants.d.ts +5 -0
- package/dist/types/ui/src/contexts.d.ts +7 -0
- package/dist/types/ui/src/helper.d.ts +91 -0
- package/dist/types/ui/src/hooks.d.ts +26 -0
- package/dist/types/ui/src/i18n.d.ts +30 -0
- package/dist/types/ui/src/index.d.ts +5 -0
- package/dist/types/ui/src/libs/class.d.ts +84 -0
- package/dist/types/ui/src/libs/contexts.d.ts +7 -0
- package/dist/types/ui/src/libs/helper.d.ts +64 -0
- package/dist/types/ui/src/libs/hooks.d.ts +26 -0
- package/dist/types/ui/src/libs/i18n.d.ts +30 -0
- package/dist/types/ui/src/libs/ui.d.ts +64 -0
- package/package.json +80 -0
- package/public/Designer.html +90 -0
- package/public/Form.html +74 -0
- package/public/SauceHanSansJP.ttf +0 -0
- package/public/SauceHanSerifJP.ttf +0 -0
- package/public/Viewer.html +73 -0
- package/public/helper.js +51 -0
- package/public/index.html +54 -0
- package/src/Designer.tsx +72 -0
- package/src/Form.tsx +45 -0
- package/src/Viewer.tsx +27 -0
- package/src/assets/barcodeExamples/code128.png +0 -0
- package/src/assets/barcodeExamples/code39.png +0 -0
- package/src/assets/barcodeExamples/ean13.png +0 -0
- package/src/assets/barcodeExamples/ean8.png +0 -0
- package/src/assets/barcodeExamples/itf14.png +0 -0
- package/src/assets/barcodeExamples/japanpost.png +0 -0
- package/src/assets/barcodeExamples/nw7.png +0 -0
- package/src/assets/barcodeExamples/qrcode.png +0 -0
- package/src/assets/barcodeExamples/upca.png +0 -0
- package/src/assets/barcodeExamples/upce.png +0 -0
- package/src/assets/icons/back.svg +4 -0
- package/src/assets/icons/double-left.svg +11 -0
- package/src/assets/icons/double-right.svg +11 -0
- package/src/assets/icons/drag.svg +3 -0
- package/src/assets/icons/forward.svg +4 -0
- package/src/assets/icons/left.svg +4 -0
- package/src/assets/icons/right.svg +4 -0
- package/src/assets/icons/warning.svg +4 -0
- package/src/assets/imageExample.png +0 -0
- package/src/class.ts +147 -0
- package/src/components/Designer/Main/Guides.tsx +53 -0
- package/src/components/Designer/Main/Mask.tsx +19 -0
- package/src/components/Designer/Main/Moveable.tsx +79 -0
- package/src/components/Designer/Main/Selecto.tsx +29 -0
- package/src/components/Designer/Main/index.tsx +314 -0
- package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +62 -0
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +98 -0
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +178 -0
- package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +79 -0
- package/src/components/Designer/Sidebar/DetailView/index.tsx +39 -0
- package/src/components/Designer/Sidebar/ListView.tsx +180 -0
- package/src/components/Designer/Sidebar/index.tsx +102 -0
- package/src/components/Designer/index.tsx +283 -0
- package/src/components/Divider.tsx +7 -0
- package/src/components/Error.tsx +31 -0
- package/src/components/Paper.tsx +77 -0
- package/src/components/Preview/Pager/Page.tsx +85 -0
- package/src/components/Preview/Pager/Unit.tsx +87 -0
- package/src/components/Preview/index.tsx +102 -0
- package/src/components/Root.tsx +52 -0
- package/src/components/Schemas/BarcodeSchema.tsx +111 -0
- package/src/components/Schemas/ImageSchema.tsx +81 -0
- package/src/components/Schemas/SchemaUI.tsx +64 -0
- package/src/components/Schemas/TextSchema.tsx +62 -0
- package/src/components/Spinner.tsx +37 -0
- package/src/constants.ts +9 -0
- package/src/contexts.ts +8 -0
- package/src/helper.ts +516 -0
- package/src/hooks.ts +107 -0
- package/src/i18n.ts +64 -0
- package/src/index.ts +77 -0
- package/tsconfig.json +21 -0
- package/webpack.config.js +73 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
import { Template, SchemaForUI, Size } from '@pdfme/common';
|
2
|
+
export declare const uuid: () => string;
|
3
|
+
export declare const set: <T extends object>(obj: T, path: string | string[], value: any) => void;
|
4
|
+
export declare const debounce: <T extends Function>(cb: T, wait?: number) => T;
|
5
|
+
export declare const round: (number: number, precision: number) => number;
|
6
|
+
export declare const arrayMove: <T>(array: T[], from: number, to: number) => T[];
|
7
|
+
export declare const cloneDeep: <T>(value: T) => T;
|
8
|
+
export declare const flatten: <T>(arr: T[][]) => T[];
|
9
|
+
declare const esc = "esc";
|
10
|
+
export declare const initShortCuts: (arg: {
|
11
|
+
move: (command: 'up' | 'down' | 'left' | 'right', isShift: boolean) => void;
|
12
|
+
remove: () => void;
|
13
|
+
esc: () => void;
|
14
|
+
copy: () => void;
|
15
|
+
paste: () => void;
|
16
|
+
redo: () => void;
|
17
|
+
undo: () => void;
|
18
|
+
save: () => void;
|
19
|
+
}) => void;
|
20
|
+
export declare const destroyShortCuts: () => void;
|
21
|
+
export declare const readFiles: (files: FileList | null, type: 'text' | 'dataURL' | 'arrayBuffer') => Promise<string | ArrayBuffer>;
|
22
|
+
export declare const getPdfPageSizes: (pdfBlob: Blob) => Promise<{
|
23
|
+
height: number;
|
24
|
+
width: number;
|
25
|
+
}[]>;
|
26
|
+
export declare const pdf2Pngs: (pdfBlob: Blob, width: number) => Promise<string[]>;
|
27
|
+
export declare const b64toBlob: (base64: string) => Blob;
|
28
|
+
export declare const templateSchemas2SchemasList: (_template: Template) => Promise<({
|
29
|
+
rotate?: number | undefined;
|
30
|
+
alignment?: "left" | "center" | "right" | undefined;
|
31
|
+
fontSize?: number | undefined;
|
32
|
+
fontName?: string | undefined;
|
33
|
+
fontColor?: string | undefined;
|
34
|
+
backgroundColor?: string | undefined;
|
35
|
+
characterSpacing?: number | undefined;
|
36
|
+
lineHeight?: number | undefined;
|
37
|
+
type: "text";
|
38
|
+
position: {
|
39
|
+
x: number;
|
40
|
+
y: number;
|
41
|
+
};
|
42
|
+
data: string;
|
43
|
+
width: number;
|
44
|
+
height: number;
|
45
|
+
id: string;
|
46
|
+
key: string;
|
47
|
+
} | {
|
48
|
+
rotate?: number | undefined;
|
49
|
+
type: "image";
|
50
|
+
position: {
|
51
|
+
x: number;
|
52
|
+
y: number;
|
53
|
+
};
|
54
|
+
data: string;
|
55
|
+
width: number;
|
56
|
+
height: number;
|
57
|
+
id: string;
|
58
|
+
key: string;
|
59
|
+
} | {
|
60
|
+
rotate?: number | undefined;
|
61
|
+
type: "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce";
|
62
|
+
position: {
|
63
|
+
x: number;
|
64
|
+
y: number;
|
65
|
+
};
|
66
|
+
data: string;
|
67
|
+
width: number;
|
68
|
+
height: number;
|
69
|
+
id: string;
|
70
|
+
key: string;
|
71
|
+
})[][]>;
|
72
|
+
export declare const fmtTemplate: (template: Template, schemasList: SchemaForUI[][]) => Template;
|
73
|
+
export declare const getInitialSchema: () => SchemaForUI;
|
74
|
+
export declare const getSampleByType: (type: string) => string;
|
75
|
+
export declare const getKeepRatioHeightByWidth: (type: string, width: number) => number;
|
76
|
+
export declare const getUniqSchemaKey: (arg: {
|
77
|
+
copiedSchemaKey: string;
|
78
|
+
schema: SchemaForUI[];
|
79
|
+
stackUniqSchemaKeys: string[];
|
80
|
+
}) => string;
|
81
|
+
export declare const moveCommandToChangeSchemasArg: (props: {
|
82
|
+
command: 'up' | 'down' | 'left' | 'right';
|
83
|
+
activeSchemas: SchemaForUI[];
|
84
|
+
isShift: boolean;
|
85
|
+
pageSize: Size;
|
86
|
+
}) => {
|
87
|
+
key: string;
|
88
|
+
value: number;
|
89
|
+
schemaId: string;
|
90
|
+
}[];
|
91
|
+
export {};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { RefObject } from 'react';
|
2
|
+
import { Template, Size } from '@pdfme/common';
|
3
|
+
export declare const usePrevious: <T>(value: T) => T | null;
|
4
|
+
declare type UIPreProcessorProps = {
|
5
|
+
template: Template;
|
6
|
+
size: Size;
|
7
|
+
offset?: number;
|
8
|
+
};
|
9
|
+
export declare const useUIPreProcessor: ({ template, size, offset }: UIPreProcessorProps) => {
|
10
|
+
backgrounds: string[];
|
11
|
+
pageSizes: {
|
12
|
+
width: number;
|
13
|
+
height: number;
|
14
|
+
}[];
|
15
|
+
scale: number;
|
16
|
+
error: Error | null;
|
17
|
+
};
|
18
|
+
declare type ScrollPageCursorProps = {
|
19
|
+
rootRef: RefObject<HTMLDivElement>;
|
20
|
+
pageSizes: Size[];
|
21
|
+
scale: number;
|
22
|
+
pageCursor: number;
|
23
|
+
onChangePageCursor: (page: number) => void;
|
24
|
+
};
|
25
|
+
export declare const useScrollPageCursor: ({ rootRef, pageSizes, scale, pageCursor, onChangePageCursor, }: ScrollPageCursorProps) => void;
|
26
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { Lang } from '@pdfme/common';
|
2
|
+
declare type DictEn = typeof dictEn;
|
3
|
+
declare const dictEn: {
|
4
|
+
field: string;
|
5
|
+
fieldName: string;
|
6
|
+
require: string;
|
7
|
+
uniq: string;
|
8
|
+
inputExample: string;
|
9
|
+
edit: string;
|
10
|
+
plsSelect: string;
|
11
|
+
plsInputName: string;
|
12
|
+
plsAddNewField: string;
|
13
|
+
fieldMustUniq: string;
|
14
|
+
notUniq: string;
|
15
|
+
noKeyName: string;
|
16
|
+
fieldsList: string;
|
17
|
+
addNewField: string;
|
18
|
+
editField: string;
|
19
|
+
type: string;
|
20
|
+
previewWarnMsg: string;
|
21
|
+
previewErrMsg: string;
|
22
|
+
goToFirst: string;
|
23
|
+
goToPrevious: string;
|
24
|
+
goToNext: string;
|
25
|
+
goToEnd: string;
|
26
|
+
select: string;
|
27
|
+
errorOccurred: string;
|
28
|
+
};
|
29
|
+
export declare const curriedI18n: (lang: Lang) => (key: keyof DictEn) => string;
|
30
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import Designer from './Designer';
|
2
|
+
import Form from './Form';
|
3
|
+
import Viewer from './Viewer';
|
4
|
+
import { BLANK_PDF, Lang, Size, Alignment, SchemaType, schemaTypes, BarCodeType, TextSchema, isTextSchema, ImageSchema, isImageSchema, BarcodeSchema, isBarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from '@pdfme/common';
|
5
|
+
export { Designer, Viewer, Form, BLANK_PDF, Lang, Size, Alignment, SchemaType, schemaTypes, BarCodeType, TextSchema, isTextSchema, ImageSchema, isImageSchema, BarcodeSchema, isBarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import { Template, Size, UIProps, PreviewProps, UIOptions } from '../../../common/src/type';
|
2
|
+
interface CommonConstructor {
|
3
|
+
domContainer: HTMLElement;
|
4
|
+
template: Template;
|
5
|
+
options?: UIOptions;
|
6
|
+
}
|
7
|
+
export declare type DesignerConstructor = CommonConstructor;
|
8
|
+
export declare type PreviewUIConstructor = CommonConstructor & {
|
9
|
+
inputs: {
|
10
|
+
[key: string]: string;
|
11
|
+
}[];
|
12
|
+
};
|
13
|
+
export declare abstract class BaseUIClass {
|
14
|
+
protected domContainer: HTMLElement | null;
|
15
|
+
protected template: Template;
|
16
|
+
protected size: Size;
|
17
|
+
private readonly lang;
|
18
|
+
private readonly font;
|
19
|
+
private readonly setSize;
|
20
|
+
constructor(props: UIProps);
|
21
|
+
protected getI18n(): (key: "type" | "field" | "fieldName" | "require" | "uniq" | "inputExample" | "edit" | "plsSelect" | "plsInputName" | "plsAddNewField" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "previewWarnMsg" | "previewErrMsg" | "goToFirst" | "goToPrevious" | "goToNext" | "goToEnd" | "select" | "errorOccurred") => string;
|
22
|
+
protected getFont(): Record<string, {
|
23
|
+
fallback?: boolean | undefined;
|
24
|
+
subset?: boolean | undefined;
|
25
|
+
data: ArrayBuffer | Uint8Array;
|
26
|
+
}>;
|
27
|
+
getTemplate(): {
|
28
|
+
sampledata?: Record<string, string>[] | undefined;
|
29
|
+
columns?: string[] | undefined;
|
30
|
+
schemas: Record<string, {
|
31
|
+
rotate?: number | undefined;
|
32
|
+
alignment?: "left" | "center" | "right" | undefined;
|
33
|
+
fontSize?: number | undefined;
|
34
|
+
fontName?: string | undefined;
|
35
|
+
fontColor?: string | undefined;
|
36
|
+
backgroundColor?: string | undefined;
|
37
|
+
characterSpacing?: number | undefined;
|
38
|
+
lineHeight?: number | undefined;
|
39
|
+
type: "text";
|
40
|
+
height: number;
|
41
|
+
width: number;
|
42
|
+
position: {
|
43
|
+
x: number;
|
44
|
+
y: number;
|
45
|
+
};
|
46
|
+
} | {
|
47
|
+
rotate?: number | undefined;
|
48
|
+
type: "image";
|
49
|
+
height: number;
|
50
|
+
width: number;
|
51
|
+
position: {
|
52
|
+
x: number;
|
53
|
+
y: number;
|
54
|
+
};
|
55
|
+
} | {
|
56
|
+
rotate?: number | undefined;
|
57
|
+
type: "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce";
|
58
|
+
height: number;
|
59
|
+
width: number;
|
60
|
+
position: {
|
61
|
+
x: number;
|
62
|
+
y: number;
|
63
|
+
};
|
64
|
+
}>[];
|
65
|
+
basePdf: string | ArrayBuffer | Uint8Array;
|
66
|
+
};
|
67
|
+
updateTemplate(template: Template): void;
|
68
|
+
destroy(): void;
|
69
|
+
protected abstract render(): void;
|
70
|
+
}
|
71
|
+
export declare abstract class PreviewUI extends BaseUIClass {
|
72
|
+
protected inputs: {
|
73
|
+
[key: string]: string;
|
74
|
+
}[];
|
75
|
+
constructor(props: PreviewProps);
|
76
|
+
getInputs(): {
|
77
|
+
[key: string]: string;
|
78
|
+
}[];
|
79
|
+
setInputs(inputs: {
|
80
|
+
[key: string]: string;
|
81
|
+
}[]): void;
|
82
|
+
protected abstract render(): void;
|
83
|
+
}
|
84
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare const I18nContext: import("react").Context<(key: "type" | "field" | "fieldName" | "require" | "uniq" | "inputExample" | "edit" | "plsSelect" | "plsInputName" | "plsAddNewField" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "previewWarnMsg" | "previewErrMsg" | "goToFirst" | "goToPrevious" | "goToNext" | "goToEnd" | "select" | "errorOccurred") => string>;
|
3
|
+
export declare const FontContext: import("react").Context<Record<string, {
|
4
|
+
fallback?: boolean | undefined;
|
5
|
+
subset?: boolean | undefined;
|
6
|
+
data: ArrayBuffer | Uint8Array;
|
7
|
+
}>>;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { Template } from '../../../common/src/type';
|
2
|
+
declare const esc = "esc";
|
3
|
+
export declare const initShortCuts: (arg: {
|
4
|
+
move: (command: 'up' | 'down' | 'left' | 'right', isShift: boolean) => void;
|
5
|
+
remove: () => void;
|
6
|
+
esc: () => void;
|
7
|
+
copy: () => void;
|
8
|
+
paste: () => void;
|
9
|
+
redo: () => void;
|
10
|
+
undo: () => void;
|
11
|
+
save: () => void;
|
12
|
+
}) => void;
|
13
|
+
export declare const destroyShortCuts: () => void;
|
14
|
+
export declare const readFiles: (files: FileList | null, type: 'text' | 'dataURL' | 'arrayBuffer') => Promise<string | ArrayBuffer>;
|
15
|
+
export declare const getPdfPageSizes: (pdfBlob: Blob) => Promise<{
|
16
|
+
height: number;
|
17
|
+
width: number;
|
18
|
+
}[]>;
|
19
|
+
export declare const pdf2Pngs: (pdfBlob: Blob, width: number) => Promise<string[]>;
|
20
|
+
export declare const templateSchemas2SchemasList: (_template: Template) => Promise<({
|
21
|
+
rotate?: number | undefined;
|
22
|
+
alignment?: "left" | "center" | "right" | undefined;
|
23
|
+
fontSize?: number | undefined;
|
24
|
+
fontName?: string | undefined;
|
25
|
+
fontColor?: string | undefined;
|
26
|
+
backgroundColor?: string | undefined;
|
27
|
+
characterSpacing?: number | undefined;
|
28
|
+
lineHeight?: number | undefined;
|
29
|
+
type: "text";
|
30
|
+
height: number;
|
31
|
+
width: number;
|
32
|
+
position: {
|
33
|
+
x: number;
|
34
|
+
y: number;
|
35
|
+
};
|
36
|
+
data: string;
|
37
|
+
id: string;
|
38
|
+
key: string;
|
39
|
+
} | {
|
40
|
+
rotate?: number | undefined;
|
41
|
+
type: "image";
|
42
|
+
height: number;
|
43
|
+
width: number;
|
44
|
+
position: {
|
45
|
+
x: number;
|
46
|
+
y: number;
|
47
|
+
};
|
48
|
+
data: string;
|
49
|
+
id: string;
|
50
|
+
key: string;
|
51
|
+
} | {
|
52
|
+
rotate?: number | undefined;
|
53
|
+
type: "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce";
|
54
|
+
height: number;
|
55
|
+
width: number;
|
56
|
+
position: {
|
57
|
+
x: number;
|
58
|
+
y: number;
|
59
|
+
};
|
60
|
+
data: string;
|
61
|
+
id: string;
|
62
|
+
key: string;
|
63
|
+
})[][]>;
|
64
|
+
export {};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { RefObject } from 'react';
|
2
|
+
import { Template, Size } from '../../../common/src/type';
|
3
|
+
export declare const usePrevious: <T>(value: T) => T | null;
|
4
|
+
declare type UIPreProcessorProps = {
|
5
|
+
template: Template;
|
6
|
+
size: Size;
|
7
|
+
offset?: number;
|
8
|
+
};
|
9
|
+
export declare const useUIPreProcessor: ({ template, size, offset }: UIPreProcessorProps) => {
|
10
|
+
backgrounds: string[];
|
11
|
+
pageSizes: {
|
12
|
+
height: number;
|
13
|
+
width: number;
|
14
|
+
}[];
|
15
|
+
scale: number;
|
16
|
+
error: Error | null;
|
17
|
+
};
|
18
|
+
declare type ScrollPageCursorProps = {
|
19
|
+
rootRef: RefObject<HTMLDivElement>;
|
20
|
+
pageSizes: Size[];
|
21
|
+
scale: number;
|
22
|
+
pageCursor: number;
|
23
|
+
onChangePageCursor: (page: number) => void;
|
24
|
+
};
|
25
|
+
export declare const useScrollPageCursor: ({ rootRef, pageSizes, scale, pageCursor, onChangePageCursor, }: ScrollPageCursorProps) => void;
|
26
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { Lang } from '../../../common/src/type';
|
2
|
+
declare type DictEn = typeof dictEn;
|
3
|
+
declare const dictEn: {
|
4
|
+
field: string;
|
5
|
+
fieldName: string;
|
6
|
+
require: string;
|
7
|
+
uniq: string;
|
8
|
+
inputExample: string;
|
9
|
+
edit: string;
|
10
|
+
plsSelect: string;
|
11
|
+
plsInputName: string;
|
12
|
+
plsAddNewField: string;
|
13
|
+
fieldMustUniq: string;
|
14
|
+
notUniq: string;
|
15
|
+
noKeyName: string;
|
16
|
+
fieldsList: string;
|
17
|
+
addNewField: string;
|
18
|
+
editField: string;
|
19
|
+
type: string;
|
20
|
+
previewWarnMsg: string;
|
21
|
+
previewErrMsg: string;
|
22
|
+
goToFirst: string;
|
23
|
+
goToPrevious: string;
|
24
|
+
goToNext: string;
|
25
|
+
goToEnd: string;
|
26
|
+
select: string;
|
27
|
+
errorOccurred: string;
|
28
|
+
};
|
29
|
+
export declare const curriedI18n: (lang: Lang) => (key: keyof DictEn) => string;
|
30
|
+
export {};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { Template } from '../../../common/src/type';
|
2
|
+
declare const esc = "esc";
|
3
|
+
export declare const initShortCuts: (arg: {
|
4
|
+
move: (command: 'up' | 'down' | 'left' | 'right', isShift: boolean) => void;
|
5
|
+
remove: () => void;
|
6
|
+
esc: () => void;
|
7
|
+
copy: () => void;
|
8
|
+
paste: () => void;
|
9
|
+
redo: () => void;
|
10
|
+
undo: () => void;
|
11
|
+
save: () => void;
|
12
|
+
}) => void;
|
13
|
+
export declare const destroyShortCuts: () => void;
|
14
|
+
export declare const readFiles: (files: FileList | null, type: 'text' | 'dataURL' | 'arrayBuffer') => Promise<string | ArrayBuffer>;
|
15
|
+
export declare const templateSchemas2SchemasList: (_template: Template) => Promise<({
|
16
|
+
rotate?: number | undefined;
|
17
|
+
alignment?: "left" | "center" | "right" | undefined;
|
18
|
+
fontSize?: number | undefined;
|
19
|
+
fontName?: string | undefined;
|
20
|
+
fontColor?: string | undefined;
|
21
|
+
backgroundColor?: string | undefined;
|
22
|
+
characterSpacing?: number | undefined;
|
23
|
+
lineHeight?: number | undefined;
|
24
|
+
type: "text";
|
25
|
+
height: number;
|
26
|
+
width: number;
|
27
|
+
position: {
|
28
|
+
x: number;
|
29
|
+
y: number;
|
30
|
+
};
|
31
|
+
data: string;
|
32
|
+
id: string;
|
33
|
+
key: string;
|
34
|
+
} | {
|
35
|
+
rotate?: number | undefined;
|
36
|
+
type: "image";
|
37
|
+
height: number;
|
38
|
+
width: number;
|
39
|
+
position: {
|
40
|
+
x: number;
|
41
|
+
y: number;
|
42
|
+
};
|
43
|
+
data: string;
|
44
|
+
id: string;
|
45
|
+
key: string;
|
46
|
+
} | {
|
47
|
+
rotate?: number | undefined;
|
48
|
+
type: "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce";
|
49
|
+
height: number;
|
50
|
+
width: number;
|
51
|
+
position: {
|
52
|
+
x: number;
|
53
|
+
y: number;
|
54
|
+
};
|
55
|
+
data: string;
|
56
|
+
id: string;
|
57
|
+
key: string;
|
58
|
+
})[][]>;
|
59
|
+
export declare const getPdfPageSizes: (pdfBlob: Blob) => Promise<{
|
60
|
+
height: number;
|
61
|
+
width: number;
|
62
|
+
}[]>;
|
63
|
+
export declare const pdf2Pngs: (pdfBlob: Blob, width: number) => Promise<string[]>;
|
64
|
+
export {};
|
package/package.json
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pdfme/ui",
|
3
|
+
"version": "1.0.0-beta.1",
|
4
|
+
"author": "hand-dot",
|
5
|
+
"license": "MIT",
|
6
|
+
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
7
|
+
"homepage": "https://pdfme.com",
|
8
|
+
"repository": "git@github.com:pdfme/pdfme.git",
|
9
|
+
"bugs": {
|
10
|
+
"url": "https://github.com/pdfme/pdfme/issues"
|
11
|
+
},
|
12
|
+
"main": "dist/@pdfme/ui.js",
|
13
|
+
"module": "src/index.ts",
|
14
|
+
"types": "dist/types/index.d.ts",
|
15
|
+
"engines": {
|
16
|
+
"node": ">=14"
|
17
|
+
},
|
18
|
+
"scripts": {
|
19
|
+
"develop": "webpack-dev-server --mode development",
|
20
|
+
"build": "NODE_ENV=production webpack --mode production",
|
21
|
+
"clean": "rimraf dist",
|
22
|
+
"lint": "tsc --noEmit",
|
23
|
+
"test": "jest",
|
24
|
+
"lint:watch": "tsc -w --noEmit",
|
25
|
+
"test:watch": "jest --coverage --watch",
|
26
|
+
"prune": "ts-prune src"
|
27
|
+
},
|
28
|
+
"dependencies": {
|
29
|
+
"@pdfme/common": "^1.0.0-beta.1",
|
30
|
+
"@scena/react-guides": "^0.16.0",
|
31
|
+
"hotkeys-js": "^3.8.7",
|
32
|
+
"pdfjs-dist": "^2.12.313",
|
33
|
+
"react": "^17.0.2",
|
34
|
+
"react-dom": "^17.0.2",
|
35
|
+
"react-moveable": "^0.30.3",
|
36
|
+
"react-selecto": "^1.12.0",
|
37
|
+
"react-sortable-hoc": "^2.0.0",
|
38
|
+
"worker-loader": "^3.0.8"
|
39
|
+
},
|
40
|
+
"devDependencies": {
|
41
|
+
"@testing-library/jest-dom": "^5.16.1",
|
42
|
+
"@testing-library/react": "^12.1.2",
|
43
|
+
"@types/css-font-loading-module": "^0.0.7",
|
44
|
+
"@types/pdfjs-dist": "^2.7.4",
|
45
|
+
"@types/react": "^17.0.38",
|
46
|
+
"@types/react-dom": "^17.0.9",
|
47
|
+
"eslint-plugin-react": "^7.28.0",
|
48
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
49
|
+
"html-webpack-plugin": "^5.3.2",
|
50
|
+
"jest-canvas-mock": "^2.3.1",
|
51
|
+
"process": "^0.11.10"
|
52
|
+
},
|
53
|
+
"jest": {
|
54
|
+
"setupFiles": [
|
55
|
+
"jest-canvas-mock"
|
56
|
+
],
|
57
|
+
"moduleNameMapper": {
|
58
|
+
"\\.(png|svg)$": "<rootDir>/../../assetsTransformer.js",
|
59
|
+
"\\.(ttf)$": "<rootDir>/../../fontTransformer.js"
|
60
|
+
},
|
61
|
+
"moduleFileExtensions": [
|
62
|
+
"js",
|
63
|
+
"ts",
|
64
|
+
"tsx"
|
65
|
+
],
|
66
|
+
"transform": {
|
67
|
+
"^.+\\.ts$": "ts-jest",
|
68
|
+
"^.+\\.tsx$": "ts-jest"
|
69
|
+
},
|
70
|
+
"globals": {
|
71
|
+
"ts-jest": {
|
72
|
+
"tsconfig": "tsconfig.json"
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"testMatch": [
|
76
|
+
"**/*.test.ts",
|
77
|
+
"**/*.test.tsx"
|
78
|
+
]
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Webpack App</title>
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
7
|
+
</head>
|
8
|
+
<body style="margin: 0">
|
9
|
+
<div>
|
10
|
+
<a href="./">Back</a>
|
11
|
+
/
|
12
|
+
<button onclick="init()">init</button>
|
13
|
+
/
|
14
|
+
<button onclick="destroy()">destroy</button>
|
15
|
+
/
|
16
|
+
<button onclick="saveTemplate()">saveTemplate</button>
|
17
|
+
/
|
18
|
+
<button onclick="updateTemplate()">updateTemplate</button>
|
19
|
+
/
|
20
|
+
<button onclick="generate()">generate</button>
|
21
|
+
/
|
22
|
+
<label>
|
23
|
+
loadTemplate
|
24
|
+
<input type="file" accept="application/json" onchange="loadTemplate(this.files[0])" />
|
25
|
+
</label>
|
26
|
+
</div>
|
27
|
+
<div id="app"></div>
|
28
|
+
<script src="./helper.js"></script>
|
29
|
+
<script>
|
30
|
+
let editor = null;
|
31
|
+
|
32
|
+
async function init() {
|
33
|
+
const font = await getFont();
|
34
|
+
editor = new Designer({
|
35
|
+
domContainer,
|
36
|
+
template: getTemplate(),
|
37
|
+
options: {
|
38
|
+
font,
|
39
|
+
},
|
40
|
+
});
|
41
|
+
|
42
|
+
editor.onSaveTemplate((t) => {
|
43
|
+
console.log({ ...t });
|
44
|
+
const tj = JSON.stringify(t, null, 2);
|
45
|
+
localStorage.setItem('template', tj);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
|
49
|
+
function destroy() {
|
50
|
+
editor.destroy();
|
51
|
+
}
|
52
|
+
|
53
|
+
function saveTemplate() {
|
54
|
+
editor.saveTemplate();
|
55
|
+
}
|
56
|
+
|
57
|
+
function updateTemplate() {
|
58
|
+
editor.updateTemplate(getSampleTemplate());
|
59
|
+
}
|
60
|
+
|
61
|
+
function loadTemplate(file) {
|
62
|
+
const reader = new FileReader();
|
63
|
+
reader.onload = () => {
|
64
|
+
editor.updateTemplate(JSON.parse(reader.result));
|
65
|
+
};
|
66
|
+
reader.readAsText(file);
|
67
|
+
}
|
68
|
+
|
69
|
+
async function generate() {
|
70
|
+
const font = await getFont();
|
71
|
+
const template = editor.getTemplate();
|
72
|
+
const inputs = template.sampledata;
|
73
|
+
pdfme
|
74
|
+
.generate({
|
75
|
+
inputs,
|
76
|
+
template,
|
77
|
+
options: {
|
78
|
+
font,
|
79
|
+
},
|
80
|
+
})
|
81
|
+
.then((pdf) => {
|
82
|
+
const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
|
83
|
+
window.open(URL.createObjectURL(blob));
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
window.onload = init;
|
88
|
+
</script>
|
89
|
+
</body>
|
90
|
+
</html>
|
package/public/Form.html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Webpack App</title>
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
7
|
+
</head>
|
8
|
+
<body style="margin: 0">
|
9
|
+
<div>
|
10
|
+
<a href="./">Back</a>
|
11
|
+
/
|
12
|
+
<button onclick="init()">init</button>
|
13
|
+
/
|
14
|
+
<button onclick="destroy()">destroy</button>
|
15
|
+
/
|
16
|
+
<button onclick="getInputs()">getInputs</button>
|
17
|
+
/
|
18
|
+
<button onclick="setInputs()">setInputs</button>
|
19
|
+
/
|
20
|
+
<button onclick="generate()">generate</button>
|
21
|
+
</div>
|
22
|
+
<div id="app"></div>
|
23
|
+
<script src="./helper.js"></script>
|
24
|
+
<script>
|
25
|
+
let form = null;
|
26
|
+
|
27
|
+
async function init() {
|
28
|
+
const font = await getFont();
|
29
|
+
form = new pdfme.Form({
|
30
|
+
domContainer,
|
31
|
+
template: getTemplate(),
|
32
|
+
inputs: [
|
33
|
+
{ field1: 'bb', field2: 'aaaaaaaaaaaa' },
|
34
|
+
{ field1: 'bb', field2: 'aaaaaaaaaaaa' },
|
35
|
+
{ field1: 'bb', field2: 'aaaaaaaaaaaa' },
|
36
|
+
],
|
37
|
+
options: {
|
38
|
+
font,
|
39
|
+
},
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
function destroy() {
|
44
|
+
form.destroy();
|
45
|
+
}
|
46
|
+
|
47
|
+
function getInputs() {
|
48
|
+
console.log(form.getInputs());
|
49
|
+
}
|
50
|
+
|
51
|
+
function setInputs() {
|
52
|
+
form.setInputs([{ field1: 'wwwww', field2: 'wwwww' }]);
|
53
|
+
}
|
54
|
+
|
55
|
+
async function generate() {
|
56
|
+
const font = await getFont();
|
57
|
+
pdfme
|
58
|
+
.generate({
|
59
|
+
inputs: form.getInputs(),
|
60
|
+
template: getTemplate(),
|
61
|
+
options: {
|
62
|
+
font,
|
63
|
+
},
|
64
|
+
})
|
65
|
+
.then((pdf) => {
|
66
|
+
const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
|
67
|
+
window.open(URL.createObjectURL(blob));
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
window.onload = init;
|
72
|
+
</script>
|
73
|
+
</body>
|
74
|
+
</html>
|
Binary file
|
Binary file
|