@pdfme/ui 1.0.0-beta.3 → 1.0.0-beta.8
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/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 +1 -1
- package/dist/index.js.LICENSE.txt +3 -1
- package/dist/index.js.map +1 -1
- 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} +1 -1
- 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 +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TextPropEditor.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/index.d.ts +0 -0
- package/dist/types/components/Designer/Sidebar/ListView.d.ts +3 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/index.d.ts +1 -0
- 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 -0
- package/dist/types/{ui/src/components → components}/Preview/Pager/Unit.d.ts +0 -0
- 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 +0 -0
- 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/contexts.d.ts +7 -0
- package/dist/types/{ui/src/helper.d.ts → helper.d.ts} +0 -0
- package/dist/types/{ui/src/hooks.d.ts → hooks.d.ts} +0 -0
- package/dist/types/{ui/src/i18n.d.ts → i18n.d.ts} +0 -1
- package/dist/types/index.d.ts +6 -0
- package/package.json +11 -6
- package/src/Designer.tsx +2 -1
- package/src/Form.tsx +1 -0
- package/src/Viewer.tsx +1 -0
- package/src/assets/icons/close.svg +4 -0
- package/src/assets/imageExample.png +0 -0
- package/src/class.ts +5 -6
- package/src/components/Designer/Main/Moveable.tsx +1 -1
- package/src/components/Designer/Main/index.tsx +6 -8
- package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +24 -5
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +12 -4
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +32 -5
- package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +12 -4
- package/src/components/Designer/Sidebar/DetailView/index.tsx +15 -13
- package/src/components/Designer/Sidebar/ListView.tsx +47 -25
- package/src/components/Designer/Sidebar/index.tsx +9 -7
- package/src/components/Designer/index.tsx +5 -3
- package/src/components/Paper.tsx +1 -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 +37 -22
- package/src/components/Schemas/ImageSchema.tsx +71 -66
- package/src/components/Schemas/TextSchema.tsx +1 -1
- package/src/constants.ts +2 -0
- package/src/helper.ts +31 -27
- package/src/i18n.ts +0 -2
- package/src/index.ts +5 -41
- package/tsconfig.json +2 -1
- package/webpack.config.js +0 -18
- 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/ui/src/components/Designer/Sidebar/ListView.d.ts +0 -3
- package/dist/types/ui/src/contexts.d.ts +0 -7
- package/dist/types/ui/src/index.d.ts +0 -5
@@ -1,7 +1,7 @@
|
|
1
|
-
import React, { useContext } from 'react';
|
1
|
+
import React, { useContext, useState } from 'react';
|
2
2
|
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
|
3
3
|
import { SchemaForUI, Size } from '@pdfme/common';
|
4
|
-
import { ZOOM, RULER_HEIGHT } from '../../../constants';
|
4
|
+
import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants';
|
5
5
|
import { I18nContext } from '../../../contexts';
|
6
6
|
import Divider from '../../Divider';
|
7
7
|
import dragIcon from '../../../assets/icons/drag.svg';
|
@@ -73,6 +73,7 @@ const SortableItem = SortableElement(
|
|
73
73
|
style={{
|
74
74
|
marginRight: '1rem',
|
75
75
|
width: 180,
|
76
|
+
color: '#333',
|
76
77
|
overflow: 'hidden',
|
77
78
|
whiteSpace: 'nowrap',
|
78
79
|
textOverflow: 'ellipsis',
|
@@ -101,23 +102,29 @@ const SortableItem = SortableElement(
|
|
101
102
|
|
102
103
|
const SortableList = SortableContainer(
|
103
104
|
(props: {
|
105
|
+
scale: number;
|
104
106
|
schemas: SchemaForUI[];
|
105
107
|
onEdit: (id: string) => void;
|
106
108
|
size: Size;
|
107
109
|
hoveringSchemaId: string | null;
|
108
110
|
onChangeHoveringSchemaId: (id: string | null) => void;
|
109
111
|
}) => {
|
110
|
-
const { schemas, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } = props;
|
112
|
+
const { scale, schemas, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } = props;
|
111
113
|
const i18n = useContext(I18nContext);
|
112
114
|
|
113
115
|
return (
|
114
|
-
<div style={{
|
116
|
+
<div style={{ height: size.height - RULER_HEIGHT * ZOOM - 125, overflowY: 'auto' }}>
|
115
117
|
{schemas.length > 0 ? (
|
116
118
|
schemas.map((s, i) => (
|
117
119
|
<div
|
118
120
|
key={s.id}
|
119
121
|
style={{
|
120
122
|
border: `1px solid ${s.id === hoveringSchemaId ? '#18a0fb' : 'transparent'}`,
|
123
|
+
// Reasons for adapting transform
|
124
|
+
// https://github.com/clauderic/react-sortable-hoc/issues/386
|
125
|
+
width: SIDEBAR_WIDTH * scale,
|
126
|
+
transform: `scale(${1 - scale + 1})`,
|
127
|
+
transformOrigin: 'top left',
|
121
128
|
}}
|
122
129
|
onMouseEnter={() => onChangeHoveringSchemaId(s.id)}
|
123
130
|
onMouseLeave={() => onChangeHoveringSchemaId(null)}
|
@@ -142,38 +149,53 @@ const SortableList = SortableContainer(
|
|
142
149
|
const ListView = (
|
143
150
|
props: Pick<
|
144
151
|
SidebarProps,
|
145
|
-
|
152
|
+
| 'scale'
|
153
|
+
| 'schemas'
|
154
|
+
| 'onSortEnd'
|
155
|
+
| 'onEdit'
|
156
|
+
| 'size'
|
157
|
+
| 'hoveringSchemaId'
|
158
|
+
| 'onChangeHoveringSchemaId'
|
146
159
|
>
|
147
160
|
) => {
|
148
|
-
const { schemas, onSortEnd, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } =
|
161
|
+
const { scale, schemas, onSortEnd, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } =
|
162
|
+
props;
|
149
163
|
const i18n = useContext(I18nContext);
|
164
|
+
const [sorting, setSorting] = useState(false);
|
150
165
|
|
151
166
|
return (
|
152
|
-
<
|
167
|
+
<div>
|
153
168
|
<div style={{ height: 40, display: 'flex', alignItems: 'center' }}>
|
154
169
|
<p style={{ textAlign: 'center', width: '100%', fontWeight: 'bold' }}>
|
155
170
|
{i18n('fieldsList')}
|
156
171
|
</p>
|
157
172
|
</div>
|
158
173
|
<Divider />
|
159
|
-
<
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
174
|
+
<div style={{ fontSize: '0.9rem' }}>
|
175
|
+
<SortableList
|
176
|
+
scale={scale}
|
177
|
+
size={size}
|
178
|
+
hoveringSchemaId={sorting ? null : hoveringSchemaId}
|
179
|
+
onChangeHoveringSchemaId={(arg) => !sorting && onChangeHoveringSchemaId(arg)}
|
180
|
+
updateBeforeSortStart={(node: any) => {
|
181
|
+
if (node.node.style) {
|
182
|
+
node.node.style.zIndex = '9999';
|
183
|
+
}
|
184
|
+
}}
|
185
|
+
useDragHandle
|
186
|
+
axis="y"
|
187
|
+
lockAxis="y"
|
188
|
+
schemas={schemas}
|
189
|
+
onSortStart={() => setSorting(true)}
|
190
|
+
onSortEnd={(arg) => {
|
191
|
+
setSorting(false);
|
192
|
+
onSortEnd(arg);
|
193
|
+
}}
|
194
|
+
onEdit={onEdit}
|
195
|
+
/>
|
196
|
+
<Divider />
|
197
|
+
</div>
|
198
|
+
</div>
|
177
199
|
);
|
178
200
|
};
|
179
201
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { useState, useContext } from 'react';
|
2
2
|
import { SchemaForUI, Size } from '@pdfme/common';
|
3
|
-
import { ZOOM, RULER_HEIGHT } from '../../../constants';
|
3
|
+
import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants';
|
4
4
|
import { I18nContext } from '../../../contexts';
|
5
5
|
import backIcon from '../../../assets/icons/back.svg';
|
6
6
|
import forwardIcon from '../../../assets/icons/forward.svg';
|
@@ -8,6 +8,7 @@ import ListView from './ListView';
|
|
8
8
|
import DetailView from './DetailView';
|
9
9
|
|
10
10
|
export type SidebarProps = {
|
11
|
+
scale: number;
|
11
12
|
height: number;
|
12
13
|
hoveringSchemaId: string | null;
|
13
14
|
onChangeHoveringSchemaId: (id: string | null) => void;
|
@@ -28,12 +29,13 @@ const Sidebar = (props: SidebarProps) => {
|
|
28
29
|
|
29
30
|
const i18n = useContext(I18nContext);
|
30
31
|
const [open, setOpen] = useState(true);
|
31
|
-
const sidebarWidth = 300;
|
32
32
|
const top = 0;
|
33
33
|
|
34
34
|
return (
|
35
|
-
<div
|
36
|
-
|
35
|
+
<div
|
36
|
+
style={{ position: 'absolute', right: 0, zIndex: 1, height, width: open ? SIDEBAR_WIDTH : 0 }}
|
37
|
+
>
|
38
|
+
<div style={{ position: 'sticky', top, zIndex: 1, fontSize: '1rem' }}>
|
37
39
|
<button
|
38
40
|
style={{
|
39
41
|
position: 'absolute',
|
@@ -41,7 +43,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
41
43
|
right: '0.5rem',
|
42
44
|
zIndex: 100,
|
43
45
|
border: 'none',
|
44
|
-
borderRadius:
|
46
|
+
borderRadius: 2,
|
45
47
|
padding: '0.5rem',
|
46
48
|
cursor: 'pointer',
|
47
49
|
background: '#eee',
|
@@ -52,7 +54,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
52
54
|
</button>
|
53
55
|
<div
|
54
56
|
style={{
|
55
|
-
width:
|
57
|
+
width: SIDEBAR_WIDTH,
|
56
58
|
height: size.height - RULER_HEIGHT * ZOOM,
|
57
59
|
display: open ? 'block' : 'none',
|
58
60
|
top,
|
@@ -85,7 +87,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
85
87
|
color: '#fff',
|
86
88
|
background: '#18a0fb',
|
87
89
|
border: 'none',
|
88
|
-
borderRadius:
|
90
|
+
borderRadius: 2,
|
89
91
|
cursor: 'pointer',
|
90
92
|
}}
|
91
93
|
onClick={addSchema}
|
@@ -99,11 +99,12 @@ const TemplateEditor = ({
|
|
99
99
|
// Assign to reference
|
100
100
|
set(tgt, key, value);
|
101
101
|
if (key === 'type') {
|
102
|
+
const type = String(value);
|
102
103
|
// set default value, text or barcode
|
103
|
-
set(tgt, 'data',
|
104
|
+
set(tgt, 'data', getSampleByType(type));
|
104
105
|
// For barcodes, adjust the height to get the correct ratio.
|
105
|
-
if (value !== 'text'
|
106
|
-
set(tgt, 'height', getKeepRatioHeightByWidth(
|
106
|
+
if (value !== 'text') {
|
107
|
+
set(tgt, 'height', getKeepRatioHeightByWidth(type, tgt.width));
|
107
108
|
}
|
108
109
|
}
|
109
110
|
|
@@ -240,6 +241,7 @@ const TemplateEditor = ({
|
|
240
241
|
return (
|
241
242
|
<Root ref={rootRef} size={size} scale={scale}>
|
242
243
|
<Sidebar
|
244
|
+
scale={scale}
|
243
245
|
hoveringSchemaId={hoveringSchemaId}
|
244
246
|
onChangeHoveringSchemaId={onChangeHoveringSchemaId}
|
245
247
|
height={mainRef.current ? mainRef.current.scrollHeight : 0}
|
package/src/components/Paper.tsx
CHANGED
@@ -47,9 +47,7 @@ const Paper = (porps: {
|
|
47
47
|
margin: `${RULER_HEIGHT * scale}px auto`,
|
48
48
|
position: 'relative',
|
49
49
|
backgroundImage: `url(${background})`,
|
50
|
-
backgroundSize:
|
51
|
-
backgroundPosition: 'center',
|
52
|
-
backgroundRepeat: 'no-repeat',
|
50
|
+
backgroundSize: `${paperSize.width}px ${paperSize.height}px`,
|
53
51
|
...paperSize,
|
54
52
|
}}
|
55
53
|
>
|
@@ -80,12 +80,11 @@ const Preview = ({ template, inputs, size, onChangeInput }: PreviewReactProps) =
|
|
80
80
|
backgrounds={backgrounds}
|
81
81
|
renderSchema={({ schema, index }) => {
|
82
82
|
const { key } = schema;
|
83
|
-
const data = input[key]
|
84
|
-
|
83
|
+
const data = input[key] || '';
|
85
84
|
return (
|
86
85
|
<SchemaUI
|
87
|
-
key={
|
88
|
-
schema={Object.assign(schema, {
|
86
|
+
key={schema.id}
|
87
|
+
schema={Object.assign(schema, { data })}
|
89
88
|
editable={editable}
|
90
89
|
placeholder={template.sampledata ? template.sampledata[0][key] : ''}
|
91
90
|
tabIndex={index + 100}
|
package/src/components/Root.tsx
CHANGED
@@ -29,16 +29,11 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
|
29
29
|
return (
|
30
30
|
<div
|
31
31
|
ref={ref}
|
32
|
-
style={{
|
33
|
-
fontFamily: 'Arial, Helvetica, sans-serif',
|
34
|
-
position: 'relative',
|
35
|
-
background: 'rgb(74, 74, 74)',
|
36
|
-
overflowY: 'auto',
|
37
|
-
...size,
|
38
|
-
}}
|
32
|
+
style={{ position: 'relative', background: 'rgb(74, 74, 74)', overflowY: 'auto', ...size }}
|
39
33
|
>
|
40
34
|
<div
|
41
35
|
style={{
|
36
|
+
margin: '0 auto',
|
42
37
|
width: size.width - RULER_HEIGHT * scale,
|
43
38
|
height: size.height - RULER_HEIGHT * scale,
|
44
39
|
}}
|
@@ -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,
|
@@ -50,7 +48,7 @@ const ErrorBarcode = () => (
|
|
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
|
@@ -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={{
|
@@ -81,28 +97,27 @@ const BarcodeSchemaUI = (
|
|
81
97
|
justifyContent: 'center',
|
82
98
|
}}
|
83
99
|
>
|
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
|
-
/>
|
100
|
+
{editable ? (
|
101
|
+
<input
|
102
|
+
ref={ref}
|
103
|
+
tabIndex={tabIndex}
|
104
|
+
placeholder={placeholder}
|
105
|
+
style={style}
|
106
|
+
value={value}
|
107
|
+
onChange={(e) => onChange(e.target.value)}
|
108
|
+
/>
|
109
|
+
) : (
|
110
|
+
<div style={style}>
|
111
|
+
<span>{value}</span>
|
112
|
+
</div>
|
113
|
+
)}
|
114
|
+
|
102
115
|
{value ? (
|
103
116
|
<ErrorOrSampleBarcode value={value} schema={schema} />
|
104
|
-
) : (
|
117
|
+
) : editable ? (
|
105
118
|
<SampleBarcode schema={schema} />
|
119
|
+
) : (
|
120
|
+
<ErrorBarcode />
|
106
121
|
)}
|
107
122
|
</div>
|
108
123
|
);
|
@@ -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);
|
package/src/constants.ts
CHANGED
package/src/helper.ts
CHANGED
@@ -225,33 +225,6 @@ export const readFiles = (files: FileList | null, type: 'text' | 'dataURL' | 'ar
|
|
225
225
|
});
|
226
226
|
};
|
227
227
|
|
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
228
|
const pt2mm = (pt: number) => {
|
256
229
|
// https://www.ddc.co.jp/words/archives/20090701114500.html
|
257
230
|
const mmRatio = 0.3527;
|
@@ -316,6 +289,33 @@ export const b64toBlob = (base64: string) => {
|
|
316
289
|
return new Blob([uniy8Array.buffer], { type: mimeType });
|
317
290
|
};
|
318
291
|
|
292
|
+
const sortSchemasList = (template: Template, pageNum: number): SchemaForUI[][] =>
|
293
|
+
new Array(pageNum).fill('').reduce((acc, _, i) => {
|
294
|
+
acc.push(
|
295
|
+
template.schemas[i]
|
296
|
+
? Object.entries(template.schemas[i])
|
297
|
+
.sort((a, b) => {
|
298
|
+
const aIndex = (template.columns ?? []).findIndex((c) => c === a[0]);
|
299
|
+
const bIndex = (template.columns ?? []).findIndex((c) => c === b[0]);
|
300
|
+
|
301
|
+
return aIndex > bIndex ? 1 : -1;
|
302
|
+
})
|
303
|
+
.map((e) => {
|
304
|
+
const [key, value] = e;
|
305
|
+
const data = template.sampledata ? template.sampledata[0][key] : '';
|
306
|
+
|
307
|
+
return Object.assign(value, {
|
308
|
+
key,
|
309
|
+
data,
|
310
|
+
id: uuid(),
|
311
|
+
});
|
312
|
+
})
|
313
|
+
: []
|
314
|
+
);
|
315
|
+
|
316
|
+
return acc;
|
317
|
+
}, [] as SchemaForUI[][]);
|
318
|
+
|
319
319
|
export const templateSchemas2SchemasList = async (_template: Template) => {
|
320
320
|
const template = cloneDeep(_template);
|
321
321
|
const sortedSchemasList = sortSchemasList(template, template.schemas.length);
|
@@ -400,6 +400,9 @@ export const getInitialSchema = (): SchemaForUI => ({
|
|
400
400
|
|
401
401
|
export const getSampleByType = (type: string) => {
|
402
402
|
const defaultValue: { [key: string]: string } = {
|
403
|
+
text: 'text',
|
404
|
+
image:
|
405
|
+
'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
406
|
qrcode: 'https://pdfme.com/',
|
404
407
|
japanpost: '6540123789-A-K-Z',
|
405
408
|
ean13: '2112345678900',
|
@@ -417,6 +420,7 @@ export const getSampleByType = (type: string) => {
|
|
417
420
|
|
418
421
|
export const getKeepRatioHeightByWidth = (type: string, width: number) => {
|
419
422
|
const raito: { [key: string]: number } = {
|
423
|
+
image: 1,
|
420
424
|
qrcode: 1,
|
421
425
|
japanpost: 0.09,
|
422
426
|
ean13: 0.4,
|
package/src/i18n.ts
CHANGED
@@ -27,7 +27,6 @@ const dictEn = {
|
|
27
27
|
goToPrevious: 'Back',
|
28
28
|
goToNext: 'Next',
|
29
29
|
goToEnd: 'Go to end',
|
30
|
-
select: 'Select',
|
31
30
|
errorOccurred: 'An error occurred.',
|
32
31
|
};
|
33
32
|
|
@@ -55,7 +54,6 @@ const dictJa: { [key in keyof DictEn]: string } = {
|
|
55
54
|
goToPrevious: '1つ戻る',
|
56
55
|
goToNext: '1つ進む',
|
57
56
|
goToEnd: '最後に進む',
|
58
|
-
select: '選択',
|
59
57
|
errorOccurred: 'エラーが発生しました',
|
60
58
|
};
|
61
59
|
|