@pdfme/ui 1.0.0-beta.1 → 1.0.0-beta.10
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/README.md +8 -7
- package/coverage/clover.xml +6 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +0 -0
- package/dist/index.js +3 -0
- package/dist/{@pdfme/ui.js.LICENSE.txt → index.js.LICENSE.txt} +3 -1
- package/dist/index.js.map +1 -0
- package/dist/types/{ui/src/Designer.d.ts → Designer.d.ts} +0 -0
- package/dist/types/{ui/src/Form.d.ts → Form.d.ts} +0 -0
- package/dist/types/{ui/src/Viewer.d.ts → Viewer.d.ts} +0 -0
- package/dist/types/{ui/src/class.d.ts → class.d.ts} +5 -4
- package/dist/types/{ui/src/components → components}/Designer/Main/Guides.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/Mask.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/Moveable.d.ts +1 -1
- package/dist/types/{ui/src/components → components}/Designer/Main/Selecto.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/index.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +4 -1
- package/dist/types/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +6 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TextPropEditor.d.ts +4 -1
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +4 -1
- package/dist/types/components/Designer/Sidebar/DetailView/index.d.ts +6 -0
- package/dist/types/components/Designer/Sidebar/ListView/Item.d.ts +25 -0
- package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableContainer.d.ts +3 -0
- package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableItem.d.ts +14 -0
- package/dist/types/{ui/src/components/Designer/Sidebar/ListView.d.ts → components/Designer/Sidebar/ListView/index.d.ts} +2 -2
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/index.d.ts +2 -7
- package/dist/types/{ui/src/components → components}/Designer/index.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Divider.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Error.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Paper.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Preview/Pager/Page.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Preview/Pager/Unit.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Preview/index.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Root.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/BarcodeSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/ImageSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/SchemaUI.d.ts +1 -1
- package/dist/types/{ui/src/components → components}/Schemas/TextSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Spinner.d.ts +0 -0
- package/dist/types/{ui/src/constants.d.ts → constants.d.ts} +1 -0
- package/dist/types/{ui/src/contexts.d.ts → contexts.d.ts} +1 -1
- package/dist/types/{ui/src/helper.d.ts → helper.d.ts} +1 -1
- package/dist/types/{ui/src/hooks.d.ts → hooks.d.ts} +1 -0
- package/dist/types/{ui/src/i18n.d.ts → i18n.d.ts} +4 -2
- package/dist/types/index.d.ts +6 -0
- package/package.json +14 -8
- package/src/Designer.tsx +2 -1
- package/src/Form.tsx +1 -0
- package/src/Viewer.tsx +1 -0
- package/src/assets/icons/align-horizontal-center.svg +1 -0
- package/src/assets/icons/align-horizontal-left.svg +1 -0
- package/src/assets/icons/align-horizontal-right.svg +1 -0
- package/src/assets/icons/align-vertical-bottom.svg +1 -0
- package/src/assets/icons/align-vertical-middle.svg +1 -0
- package/src/assets/icons/align-vertical-top.svg +1 -0
- package/src/assets/icons/close.svg +4 -0
- package/src/assets/icons/horizontal-distribute.svg +1 -0
- package/src/assets/icons/vertical-distribute.svg +1 -0
- package/src/assets/imageExample.png +0 -0
- package/src/class.ts +20 -8
- package/src/components/Designer/Main/Moveable.tsx +1 -1
- package/src/components/Designer/Main/index.tsx +22 -16
- package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +28 -6
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +115 -24
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +36 -6
- package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +14 -6
- package/src/components/Designer/Sidebar/DetailView/index.tsx +21 -16
- package/src/components/Designer/Sidebar/ListView/Item.tsx +113 -0
- package/src/components/Designer/Sidebar/ListView/SelectableSortableContainer.tsx +162 -0
- package/src/components/Designer/Sidebar/ListView/SelectableSortableItem.tsx +78 -0
- package/src/components/Designer/Sidebar/ListView/index.tsx +119 -0
- package/src/components/Designer/Sidebar/index.tsx +30 -14
- package/src/components/Designer/index.tsx +12 -24
- package/src/components/Error.tsx +2 -2
- package/src/components/Paper.tsx +10 -3
- package/src/components/Preview/Pager/Page.tsx +1 -1
- package/src/components/Preview/Pager/Unit.tsx +1 -1
- package/src/components/Preview/index.tsx +3 -4
- package/src/components/Root.tsx +2 -7
- package/src/components/Schemas/BarcodeSchema.tsx +40 -24
- package/src/components/Schemas/ImageSchema.tsx +71 -66
- package/src/components/Schemas/TextSchema.tsx +1 -2
- package/src/constants.ts +2 -0
- package/src/helper.ts +44 -38
- package/src/hooks.ts +11 -0
- package/src/i18n.ts +10 -7
- package/src/index.ts +5 -41
- package/tsconfig.json +2 -1
- package/webpack.config.js +1 -20
- package/dist/@pdfme/ui.js +0 -3
- package/dist/@pdfme/ui.js.map +0 -1
- package/dist/types/common/src/barcode.d.ts +0 -2
- package/dist/types/common/src/constants.d.ts +0 -6
- package/dist/types/common/src/helper.d.ts +0 -15
- package/dist/types/common/src/index.d.ts +0 -4
- package/dist/types/common/src/schema.d.ts +0 -3613
- package/dist/types/common/src/type.d.ts +0 -64
- package/dist/types/common/src/utils.d.ts +0 -12
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +0 -3
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/index.d.ts +0 -3
- package/dist/types/ui/src/index.d.ts +0 -5
- package/dist/types/ui/src/libs/class.d.ts +0 -84
- package/dist/types/ui/src/libs/contexts.d.ts +0 -7
- package/dist/types/ui/src/libs/helper.d.ts +0 -64
- package/dist/types/ui/src/libs/hooks.d.ts +0 -26
- package/dist/types/ui/src/libs/i18n.d.ts +0 -30
- package/dist/types/ui/src/libs/ui.d.ts +0 -64
- package/public/Designer.html +0 -90
- package/public/Form.html +0 -74
- package/public/SauceHanSansJP.ttf +0 -0
- package/public/SauceHanSerifJP.ttf +0 -0
- package/public/Viewer.html +0 -73
- package/public/helper.js +0 -51
- package/public/index.html +0 -54
- package/src/components/Designer/Sidebar/ListView.tsx +0 -180
@@ -13,8 +13,6 @@ import qrcode from '../../assets/barcodeExamples/qrcode.png';
|
|
13
13
|
import upca from '../../assets/barcodeExamples/upca.png';
|
14
14
|
import upce from '../../assets/barcodeExamples/upce.png';
|
15
15
|
|
16
|
-
type Props = SchemaUIProps & { schema: BarcodeSchema };
|
17
|
-
|
18
16
|
const barcodeExampleImageObj: { [key: string]: string } = {
|
19
17
|
qrcode,
|
20
18
|
japanpost,
|
@@ -43,18 +41,18 @@ const SampleBarcode = ({ schema }: { schema: BarcodeSchema }) => (
|
|
43
41
|
|
44
42
|
const ErrorBarcode = () => (
|
45
43
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
|
46
|
-
<
|
44
|
+
<span
|
47
45
|
style={{
|
48
46
|
color: 'white',
|
49
47
|
background: 'red',
|
50
48
|
padding: '0.25rem',
|
51
49
|
fontSize: '12pt',
|
52
50
|
fontWeight: 'bold',
|
53
|
-
borderRadius:
|
51
|
+
borderRadius: 2,
|
54
52
|
}}
|
55
53
|
>
|
56
54
|
ERROR
|
57
|
-
</
|
55
|
+
</span>
|
58
56
|
</div>
|
59
57
|
);
|
60
58
|
|
@@ -65,12 +63,30 @@ const ErrorOrSampleBarcode = ({ schema, value }: { schema: BarcodeSchema; value:
|
|
65
63
|
<ErrorBarcode />
|
66
64
|
);
|
67
65
|
|
66
|
+
type Props = SchemaUIProps & { schema: BarcodeSchema };
|
67
|
+
|
68
68
|
const BarcodeSchemaUI = (
|
69
69
|
{ schema, editable, placeholder, tabIndex, onChange }: Props,
|
70
70
|
ref: Ref<HTMLInputElement>
|
71
71
|
) => {
|
72
72
|
const value = schema.data;
|
73
73
|
|
74
|
+
const style: React.CSSProperties = {
|
75
|
+
textAlign: 'center',
|
76
|
+
position: 'absolute',
|
77
|
+
zIndex: 2,
|
78
|
+
fontSize: '1rem',
|
79
|
+
color: '#000',
|
80
|
+
height: Number(schema.height) * ZOOM,
|
81
|
+
width: Number(schema.width) * ZOOM,
|
82
|
+
background: editable || value ? 'rgba(255, 255, 255, 0.8)' : 'none',
|
83
|
+
border: 'none',
|
84
|
+
display: 'flex',
|
85
|
+
alignItems: 'center',
|
86
|
+
justifyContent: 'center',
|
87
|
+
overflow: 'auto',
|
88
|
+
};
|
89
|
+
|
74
90
|
return (
|
75
91
|
<div
|
76
92
|
style={{
|
@@ -79,30 +95,30 @@ const BarcodeSchemaUI = (
|
|
79
95
|
display: 'flex',
|
80
96
|
alignItems: 'center',
|
81
97
|
justifyContent: 'center',
|
98
|
+
fontFamily: "'Open Sans', sans-serif",
|
82
99
|
}}
|
83
100
|
>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
value={value}
|
100
|
-
onChange={(e) => onChange(e.target.value)}
|
101
|
-
/>
|
101
|
+
{editable ? (
|
102
|
+
<input
|
103
|
+
ref={ref}
|
104
|
+
tabIndex={tabIndex}
|
105
|
+
placeholder={placeholder}
|
106
|
+
style={style}
|
107
|
+
value={value}
|
108
|
+
onChange={(e) => onChange(e.target.value)}
|
109
|
+
/>
|
110
|
+
) : (
|
111
|
+
<div style={style}>
|
112
|
+
<span>{value}</span>
|
113
|
+
</div>
|
114
|
+
)}
|
115
|
+
|
102
116
|
{value ? (
|
103
117
|
<ErrorOrSampleBarcode value={value} schema={schema} />
|
104
|
-
) : (
|
118
|
+
) : editable ? (
|
105
119
|
<SampleBarcode schema={schema} />
|
120
|
+
) : (
|
121
|
+
<ErrorBarcode />
|
106
122
|
)}
|
107
123
|
</div>
|
108
124
|
);
|
@@ -1,81 +1,86 @@
|
|
1
|
-
import React, { forwardRef, ChangeEvent, useContext, Ref } from 'react';
|
1
|
+
import React, { useState, forwardRef, ChangeEvent, useContext, Ref } from 'react';
|
2
2
|
import { ImageSchema } from '@pdfme/common';
|
3
3
|
import { SchemaUIProps } from './SchemaUI';
|
4
4
|
import { readFiles } from '../../helper';
|
5
|
-
import { I18nContext } from '../../contexts';
|
6
5
|
import { ZOOM } from '../../constants';
|
7
|
-
import
|
6
|
+
import closeIcon from '../../assets/icons/close.svg';
|
8
7
|
|
9
8
|
type Props = SchemaUIProps & { schema: ImageSchema };
|
10
9
|
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
const ImageSchemaUI = (props: Props, ref: Ref<HTMLInputElement>) => {
|
11
|
+
const { editable, placeholder, tabIndex, schema, onChange } = props;
|
12
|
+
const [fileName, setFileName] = useState<string>('');
|
13
|
+
const hasData = Boolean(schema.data);
|
14
|
+
|
15
|
+
const size: React.CSSProperties = { width: schema.width * ZOOM, height: schema.height * ZOOM };
|
16
|
+
|
17
|
+
return (
|
18
|
+
<>
|
19
|
+
<div
|
16
20
|
style={{
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
...size,
|
22
|
+
opacity: hasData ? 1 : 0.5,
|
23
|
+
backgroundImage: hasData || !editable ? 'none' : `url(${placeholder})`,
|
24
|
+
backgroundSize: `${size.width}px ${size.height}px`,
|
25
|
+
}}
|
26
|
+
onClick={(e) => {
|
27
|
+
if (editable) {
|
28
|
+
e.stopPropagation();
|
29
|
+
}
|
20
30
|
}}
|
21
|
-
onClick={() => onChange('')}
|
22
31
|
>
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
32
|
+
{hasData && <img style={{ ...size, borderRadius: 0 }} src={schema.data} />}
|
33
|
+
{hasData && editable && (
|
34
|
+
<button
|
35
|
+
tabIndex={tabIndex}
|
36
|
+
style={{
|
37
|
+
position: 'absolute',
|
38
|
+
top: 0,
|
39
|
+
left: 0,
|
40
|
+
zIndex: 1,
|
41
|
+
display: 'flex',
|
42
|
+
justifyContent: 'center',
|
43
|
+
alignItems: 'center',
|
44
|
+
color: '#333',
|
45
|
+
background: '#f2f2f2',
|
46
|
+
borderRadius: 2,
|
47
|
+
border: '1px solid #767676',
|
48
|
+
cursor: 'pointer',
|
49
|
+
height: 20,
|
50
|
+
width: 20,
|
51
|
+
}}
|
52
|
+
aria-label="close"
|
53
|
+
onClick={() => {
|
54
|
+
setFileName('');
|
55
|
+
onChange('');
|
56
|
+
}}
|
57
|
+
>
|
58
|
+
<img src={closeIcon} alt="Close icon" width={10} />
|
59
|
+
</button>
|
60
|
+
)}
|
61
|
+
</div>
|
62
|
+
<label
|
63
|
+
style={{
|
64
|
+
display: editable ? 'flex' : 'none',
|
65
|
+
position: 'absolute',
|
66
|
+
top: '50%',
|
67
|
+
width: '100%',
|
68
|
+
cursor: 'pointer',
|
54
69
|
}}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
height: schema.height * ZOOM,
|
69
|
-
backgroundImage: `url(${placeholder || imageExample})`,
|
70
|
-
backgroundSize: 'cover',
|
71
|
-
backgroundPosition: 'center',
|
72
|
-
backgroundRepeat: 'no-repeat',
|
73
|
-
}}
|
74
|
-
></div>
|
70
|
+
>
|
71
|
+
<input
|
72
|
+
ref={ref}
|
73
|
+
tabIndex={tabIndex}
|
74
|
+
value={fileName}
|
75
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) =>
|
76
|
+
readFiles(event.target.files, 'dataURL').then((result) => onChange(result as string))
|
77
|
+
}
|
78
|
+
type="file"
|
79
|
+
accept="image/jpeg, image/png"
|
80
|
+
/>
|
81
|
+
</label>
|
82
|
+
</>
|
75
83
|
);
|
76
84
|
};
|
77
85
|
|
78
|
-
const ImageSchemaUI = (props: Props, ref: Ref<HTMLInputElement>) =>
|
79
|
-
props.schema.data ? <FilledImage {...props} /> : <BlankImage {...props} inputRef={ref} />;
|
80
|
-
|
81
86
|
export default forwardRef<HTMLInputElement, Props>(ImageSchemaUI);
|
@@ -24,13 +24,12 @@ const TextSchemaUI = (
|
|
24
24
|
textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
|
25
25
|
fontSize: `${schema.fontSize ?? DEFAULT_FONT_SIZE}pt`,
|
26
26
|
letterSpacing: `${schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING}pt`,
|
27
|
-
fontFeatureSettings: `"palt"`,
|
28
27
|
lineHeight: `${schema.lineHeight ?? DEFAULT_LINE_HEIGHT}em`,
|
29
28
|
whiteSpace: 'pre-line',
|
30
29
|
wordBreak: 'break-all',
|
31
30
|
background: 'transparent',
|
32
31
|
border: 'none',
|
33
|
-
color: schema.fontColor
|
32
|
+
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
34
33
|
};
|
35
34
|
|
36
35
|
return editable ? (
|
package/src/constants.ts
CHANGED
package/src/helper.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-ignore
|
2
2
|
import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry';
|
3
|
-
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist';
|
3
|
+
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/legacy/build/pdf.js';
|
4
4
|
GlobalWorkerOptions.workerSrc = PDFJSWorker;
|
5
5
|
import hotkeys from 'hotkeys-js';
|
6
6
|
import {
|
@@ -61,15 +61,6 @@ export const round = (number: number, precision: number) => {
|
|
61
61
|
return shift(Math.round(shift(number, precision, false)), precision, true);
|
62
62
|
};
|
63
63
|
|
64
|
-
export const arrayMove = <T>(array: T[], from: number, to: number): T[] => {
|
65
|
-
array = array.slice();
|
66
|
-
const startIndex = to < 0 ? array.length + to : to;
|
67
|
-
const [item] = array.splice(from, 1);
|
68
|
-
array.splice(startIndex, 0, item);
|
69
|
-
|
70
|
-
return array;
|
71
|
-
};
|
72
|
-
|
73
64
|
export const cloneDeep = <T>(value: T): T => JSON.parse(JSON.stringify(value));
|
74
65
|
|
75
66
|
export const flatten = <T>(arr: T[][]): T[] => ([] as T[]).concat(...arr);
|
@@ -96,6 +87,8 @@ const undoWin = 'ctrl+z';
|
|
96
87
|
const undoMac = 'command+z';
|
97
88
|
const saveWin = 'ctrl+s';
|
98
89
|
const saveMac = 'command+s';
|
90
|
+
const selectAllWin = 'ctrl+a';
|
91
|
+
const selectAllMac = 'command+a';
|
99
92
|
|
100
93
|
const keys = [
|
101
94
|
up,
|
@@ -119,6 +112,8 @@ const keys = [
|
|
119
112
|
undoMac,
|
120
113
|
saveWin,
|
121
114
|
saveMac,
|
115
|
+
selectAllWin,
|
116
|
+
selectAllMac,
|
122
117
|
];
|
123
118
|
|
124
119
|
export const initShortCuts = (arg: {
|
@@ -130,6 +125,7 @@ export const initShortCuts = (arg: {
|
|
130
125
|
redo: () => void;
|
131
126
|
undo: () => void;
|
132
127
|
save: () => void;
|
128
|
+
selectAll: () => void;
|
133
129
|
}) => {
|
134
130
|
hotkeys(keys.join(), (e, handler) => {
|
135
131
|
switch (handler.shortcut) {
|
@@ -181,6 +177,11 @@ export const initShortCuts = (arg: {
|
|
181
177
|
e.preventDefault();
|
182
178
|
arg.save();
|
183
179
|
break;
|
180
|
+
case selectAllWin:
|
181
|
+
case selectAllMac:
|
182
|
+
e.preventDefault();
|
183
|
+
arg.selectAll();
|
184
|
+
break;
|
184
185
|
default:
|
185
186
|
break;
|
186
187
|
}
|
@@ -225,33 +226,6 @@ export const readFiles = (files: FileList | null, type: 'text' | 'dataURL' | 'ar
|
|
225
226
|
});
|
226
227
|
};
|
227
228
|
|
228
|
-
const sortSchemasList = (template: Template, pageNum: number): SchemaForUI[][] =>
|
229
|
-
new Array(pageNum).fill('').reduce((acc, _, i) => {
|
230
|
-
acc.push(
|
231
|
-
template.schemas[i]
|
232
|
-
? Object.entries(template.schemas[i])
|
233
|
-
.sort((a, b) => {
|
234
|
-
const aIndex = (template.columns ?? []).findIndex((c) => c === a[0]);
|
235
|
-
const bIndex = (template.columns ?? []).findIndex((c) => c === b[0]);
|
236
|
-
|
237
|
-
return aIndex > bIndex ? 1 : -1;
|
238
|
-
})
|
239
|
-
.map((e) => {
|
240
|
-
const [key, value] = e;
|
241
|
-
const data = template.sampledata ? template.sampledata[0][key] : '';
|
242
|
-
|
243
|
-
return Object.assign(value, {
|
244
|
-
key,
|
245
|
-
data,
|
246
|
-
id: uuid(),
|
247
|
-
});
|
248
|
-
})
|
249
|
-
: []
|
250
|
-
);
|
251
|
-
|
252
|
-
return acc;
|
253
|
-
}, [] as SchemaForUI[][]);
|
254
|
-
|
255
229
|
const pt2mm = (pt: number) => {
|
256
230
|
// https://www.ddc.co.jp/words/archives/20090701114500.html
|
257
231
|
const mmRatio = 0.3527;
|
@@ -316,6 +290,33 @@ export const b64toBlob = (base64: string) => {
|
|
316
290
|
return new Blob([uniy8Array.buffer], { type: mimeType });
|
317
291
|
};
|
318
292
|
|
293
|
+
const sortSchemasList = (template: Template, pageNum: number): SchemaForUI[][] =>
|
294
|
+
new Array(pageNum).fill('').reduce((acc, _, i) => {
|
295
|
+
acc.push(
|
296
|
+
template.schemas[i]
|
297
|
+
? Object.entries(template.schemas[i])
|
298
|
+
.sort((a, b) => {
|
299
|
+
const aIndex = (template.columns ?? []).findIndex((c) => c === a[0]);
|
300
|
+
const bIndex = (template.columns ?? []).findIndex((c) => c === b[0]);
|
301
|
+
|
302
|
+
return aIndex > bIndex ? 1 : -1;
|
303
|
+
})
|
304
|
+
.map((e) => {
|
305
|
+
const [key, value] = e;
|
306
|
+
const data = template.sampledata ? template.sampledata[0][key] : '';
|
307
|
+
|
308
|
+
return Object.assign(value, {
|
309
|
+
key,
|
310
|
+
data,
|
311
|
+
id: uuid(),
|
312
|
+
});
|
313
|
+
})
|
314
|
+
: []
|
315
|
+
);
|
316
|
+
|
317
|
+
return acc;
|
318
|
+
}, [] as SchemaForUI[][]);
|
319
|
+
|
319
320
|
export const templateSchemas2SchemasList = async (_template: Template) => {
|
320
321
|
const template = cloneDeep(_template);
|
321
322
|
const sortedSchemasList = sortSchemasList(template, template.schemas.length);
|
@@ -351,6 +352,7 @@ export const templateSchemas2SchemasList = async (_template: Template) => {
|
|
351
352
|
|
352
353
|
export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): Template => {
|
353
354
|
const schemaAddedTemplate: Template = {
|
355
|
+
...template,
|
354
356
|
schemas: cloneDeep(schemasList).map((schema) =>
|
355
357
|
schema.reduce((acc, cur) => {
|
356
358
|
const k = cur.key;
|
@@ -400,6 +402,9 @@ export const getInitialSchema = (): SchemaForUI => ({
|
|
400
402
|
|
401
403
|
export const getSampleByType = (type: string) => {
|
402
404
|
const defaultValue: { [key: string]: string } = {
|
405
|
+
text: 'text',
|
406
|
+
image:
|
407
|
+
'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',
|
403
408
|
qrcode: 'https://pdfme.com/',
|
404
409
|
japanpost: '6540123789-A-K-Z',
|
405
410
|
ean13: '2112345678900',
|
@@ -417,6 +422,7 @@ export const getSampleByType = (type: string) => {
|
|
417
422
|
|
418
423
|
export const getKeepRatioHeightByWidth = (type: string, width: number) => {
|
419
424
|
const raito: { [key: string]: number } = {
|
425
|
+
image: 1,
|
420
426
|
qrcode: 1,
|
421
427
|
japanpost: 0.09,
|
422
428
|
ean13: 0.4,
|
@@ -499,7 +505,7 @@ export const moveCommandToChangeSchemasArg = (props: {
|
|
499
505
|
break;
|
500
506
|
}
|
501
507
|
|
502
|
-
return value;
|
508
|
+
return value > 0 ? value : 0;
|
503
509
|
};
|
504
510
|
|
505
511
|
return activeSchemas.map((as) => {
|
package/src/hooks.ts
CHANGED
@@ -105,3 +105,14 @@ export const useScrollPageCursor = ({
|
|
105
105
|
};
|
106
106
|
}, [rootRef, onScroll]);
|
107
107
|
};
|
108
|
+
|
109
|
+
export const useMountStatus = () => {
|
110
|
+
const [isMounted, setIsMounted] = useState(false);
|
111
|
+
|
112
|
+
useEffect(() => {
|
113
|
+
const timeout = setTimeout(() => setIsMounted(true), 500);
|
114
|
+
return () => clearTimeout(timeout);
|
115
|
+
}, []);
|
116
|
+
|
117
|
+
return isMounted;
|
118
|
+
};
|
package/src/i18n.ts
CHANGED
@@ -4,6 +4,7 @@ import { DEFAULT_LANG } from './constants';
|
|
4
4
|
type DictEn = typeof dictEn;
|
5
5
|
|
6
6
|
const dictEn = {
|
7
|
+
cancel: 'Cancel',
|
7
8
|
field: 'field',
|
8
9
|
fieldName: 'Name',
|
9
10
|
require: 'Required',
|
@@ -20,18 +21,20 @@ const dictEn = {
|
|
20
21
|
addNewField: 'Add new field',
|
21
22
|
editField: 'Edit Field',
|
22
23
|
type: 'Type',
|
23
|
-
previewWarnMsg: 'Preview is not available on iOS devices.',
|
24
|
-
previewErrMsg:
|
25
|
-
'An error occurred during the PDF creation process. (Characters that are not in the Helvetica font are not available)',
|
26
24
|
goToFirst: 'Go to first',
|
27
25
|
goToPrevious: 'Back',
|
28
26
|
goToNext: 'Next',
|
29
27
|
goToEnd: 'Go to end',
|
30
28
|
select: 'Select',
|
31
|
-
errorOccurred: 'An error occurred
|
29
|
+
errorOccurred: 'An error occurred',
|
30
|
+
errorBulkUpdateFieldName:
|
31
|
+
'Cannot commit the change because the number of items has been changed.',
|
32
|
+
commitBulkUpdateFieldName: 'Commit Changes',
|
33
|
+
bulkUpdateFieldName: 'Bulk update field names',
|
32
34
|
};
|
33
35
|
|
34
36
|
const dictJa: { [key in keyof DictEn]: string } = {
|
37
|
+
cancel: 'キャンセル',
|
35
38
|
field: '入力項目',
|
36
39
|
fieldName: '項目名',
|
37
40
|
require: '必須',
|
@@ -48,15 +51,15 @@ const dictJa: { [key in keyof DictEn]: string } = {
|
|
48
51
|
addNewField: '入力項目を追加',
|
49
52
|
editField: '入力項目を編集',
|
50
53
|
type: 'タイプ',
|
51
|
-
previewWarnMsg: 'iOS端末ではプレビューができません。',
|
52
|
-
previewErrMsg:
|
53
|
-
'PDF作成処理でエラーが発生しました。お手数ですがコンタクトからお問い合わせください。',
|
54
54
|
goToFirst: '最初に戻る',
|
55
55
|
goToPrevious: '1つ戻る',
|
56
56
|
goToNext: '1つ進む',
|
57
57
|
goToEnd: '最後に進む',
|
58
58
|
select: '選択',
|
59
59
|
errorOccurred: 'エラーが発生しました',
|
60
|
+
errorBulkUpdateFieldName: '項目数が変更されているため変更をコミットできません。',
|
61
|
+
commitBulkUpdateFieldName: '変更を反映',
|
62
|
+
bulkUpdateFieldName: '項目名を一括変更',
|
60
63
|
};
|
61
64
|
|
62
65
|
const i18n = (lang: Lang, key: keyof DictEn) => (lang === DEFAULT_LANG ? dictEn[key] : dictJa[key]);
|
package/src/index.ts
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
import Designer from './Designer';
|
2
2
|
import Form from './Form';
|
3
3
|
import Viewer from './Viewer';
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
export { Designer, Viewer, Form };
|
6
|
+
|
7
|
+
export type {
|
6
8
|
Lang,
|
7
9
|
Size,
|
8
10
|
Alignment,
|
9
11
|
SchemaType,
|
10
|
-
schemaTypes,
|
11
12
|
BarCodeType,
|
12
13
|
TextSchema,
|
13
|
-
isTextSchema,
|
14
14
|
ImageSchema,
|
15
|
-
isImageSchema,
|
16
15
|
BarcodeSchema,
|
17
|
-
isBarcodeSchema,
|
18
16
|
Schema,
|
19
17
|
SchemaForUI,
|
20
18
|
Font,
|
@@ -26,52 +24,18 @@ import {
|
|
26
24
|
UIOptions,
|
27
25
|
UIProps,
|
28
26
|
PreviewProps,
|
29
|
-
PreviewReactProps,
|
30
27
|
DesignerProps,
|
31
|
-
DesignerReactProps,
|
32
|
-
checkTemplate,
|
33
|
-
checkUIProps,
|
34
|
-
checkPreviewProps,
|
35
|
-
checkDesignerProps,
|
36
|
-
checkGenerateProps,
|
37
|
-
validateBarcodeInput,
|
38
28
|
} from '@pdfme/common';
|
39
29
|
|
40
30
|
export {
|
41
|
-
Designer,
|
42
|
-
Viewer,
|
43
|
-
Form,
|
44
31
|
BLANK_PDF,
|
45
|
-
Lang,
|
46
|
-
Size,
|
47
|
-
Alignment,
|
48
|
-
SchemaType,
|
49
|
-
schemaTypes,
|
50
|
-
BarCodeType,
|
51
|
-
TextSchema,
|
52
32
|
isTextSchema,
|
53
|
-
ImageSchema,
|
54
33
|
isImageSchema,
|
55
|
-
BarcodeSchema,
|
56
34
|
isBarcodeSchema,
|
57
|
-
Schema,
|
58
|
-
SchemaForUI,
|
59
|
-
Font,
|
60
|
-
BasePdf,
|
61
|
-
Template,
|
62
|
-
CommonProps,
|
63
|
-
GeneratorOptions,
|
64
|
-
GenerateProps,
|
65
|
-
UIOptions,
|
66
|
-
UIProps,
|
67
|
-
PreviewProps,
|
68
|
-
PreviewReactProps,
|
69
|
-
DesignerProps,
|
70
|
-
DesignerReactProps,
|
71
35
|
checkTemplate,
|
72
36
|
checkUIProps,
|
73
37
|
checkPreviewProps,
|
74
38
|
checkDesignerProps,
|
75
39
|
checkGenerateProps,
|
76
40
|
validateBarcodeInput,
|
77
|
-
};
|
41
|
+
} from '@pdfme/common';
|
package/tsconfig.json
CHANGED
package/webpack.config.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
const path = require('path');
|
2
2
|
const webpack = require('webpack');
|
3
3
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
4
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
5
4
|
const pkg = require('./package.json');
|
6
5
|
|
7
6
|
const isProduction = process.env.NODE_ENV === 'production';
|
@@ -28,32 +27,14 @@ const config = {
|
|
28
27
|
banner: BANNER,
|
29
28
|
entryOnly: true,
|
30
29
|
}),
|
31
|
-
new HtmlWebpackPlugin({
|
32
|
-
template: './public/Designer.html',
|
33
|
-
filename: 'Designer.html',
|
34
|
-
}),
|
35
|
-
new HtmlWebpackPlugin({
|
36
|
-
template: './public/Viewer.html',
|
37
|
-
filename: 'Viewer.html',
|
38
|
-
}),
|
39
|
-
new HtmlWebpackPlugin({
|
40
|
-
template: './public/Form.html',
|
41
|
-
filename: 'Form.html',
|
42
|
-
}),
|
43
30
|
],
|
44
31
|
devtool: 'source-map',
|
45
|
-
devServer: {
|
46
|
-
historyApiFallback: false,
|
47
|
-
host: '0.0.0.0',
|
48
|
-
},
|
49
32
|
entry: './src/index.ts',
|
50
33
|
output: {
|
51
34
|
path: path.resolve(__dirname, 'dist'),
|
52
|
-
filename:
|
53
|
-
libraryTarget: 'umd',
|
35
|
+
filename: 'index.js',
|
54
36
|
globalObject: 'this',
|
55
37
|
library: {
|
56
|
-
name: pkg.name,
|
57
38
|
type: 'umd',
|
58
39
|
},
|
59
40
|
},
|