@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,52 @@
|
|
1
|
+
import type {} from 'css-font-loading-module';
|
2
|
+
import React, { useContext, forwardRef, ReactNode, Ref, useEffect } from 'react';
|
3
|
+
import { Size } from '@pdfme/common';
|
4
|
+
import { RULER_HEIGHT } from '../constants';
|
5
|
+
import { FontContext } from '../contexts';
|
6
|
+
import Spinner from './Spinner';
|
7
|
+
|
8
|
+
type Props = { size: Size; scale: number; children: ReactNode };
|
9
|
+
|
10
|
+
const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
11
|
+
const font = useContext(FontContext);
|
12
|
+
|
13
|
+
useEffect(() => {
|
14
|
+
const fontFaces = Object.entries(font).map((entry) => {
|
15
|
+
const [key, value] = entry;
|
16
|
+
const fontFace = new FontFace(key, value.data);
|
17
|
+
|
18
|
+
return fontFace.load();
|
19
|
+
});
|
20
|
+
Promise.all(fontFaces).then((loadedFontFaces) => {
|
21
|
+
loadedFontFaces.forEach((loadedFontFace) => {
|
22
|
+
if (document && document.fonts && document.fonts.add) {
|
23
|
+
document.fonts.add(loadedFontFace);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
});
|
27
|
+
}, [font]);
|
28
|
+
|
29
|
+
return (
|
30
|
+
<div
|
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
|
+
}}
|
39
|
+
>
|
40
|
+
<div
|
41
|
+
style={{
|
42
|
+
width: size.width - RULER_HEIGHT * scale,
|
43
|
+
height: size.height - RULER_HEIGHT * scale,
|
44
|
+
}}
|
45
|
+
>
|
46
|
+
{scale === 0 ? <Spinner /> : children}
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
);
|
50
|
+
};
|
51
|
+
|
52
|
+
export default forwardRef<HTMLDivElement, Props>(Root);
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import React, { forwardRef, Ref } from 'react';
|
2
|
+
import { validateBarcodeInput, BarCodeType, BarcodeSchema } from '@pdfme/common';
|
3
|
+
import { ZOOM } from '../../constants';
|
4
|
+
import { SchemaUIProps } from './SchemaUI';
|
5
|
+
import ean8 from '../../assets/barcodeExamples/ean8.png';
|
6
|
+
import ean13 from '../../assets/barcodeExamples/ean13.png';
|
7
|
+
import code39 from '../../assets/barcodeExamples/code39.png';
|
8
|
+
import code128 from '../../assets/barcodeExamples/code128.png';
|
9
|
+
import nw7 from '../../assets/barcodeExamples/nw7.png';
|
10
|
+
import itf14 from '../../assets/barcodeExamples/itf14.png';
|
11
|
+
import japanpost from '../../assets/barcodeExamples/japanpost.png';
|
12
|
+
import qrcode from '../../assets/barcodeExamples/qrcode.png';
|
13
|
+
import upca from '../../assets/barcodeExamples/upca.png';
|
14
|
+
import upce from '../../assets/barcodeExamples/upce.png';
|
15
|
+
|
16
|
+
type Props = SchemaUIProps & { schema: BarcodeSchema };
|
17
|
+
|
18
|
+
const barcodeExampleImageObj: { [key: string]: string } = {
|
19
|
+
qrcode,
|
20
|
+
japanpost,
|
21
|
+
ean13,
|
22
|
+
ean8,
|
23
|
+
code39,
|
24
|
+
code128,
|
25
|
+
nw7,
|
26
|
+
itf14,
|
27
|
+
upca,
|
28
|
+
upce,
|
29
|
+
};
|
30
|
+
|
31
|
+
const SampleBarcode = ({ schema }: { schema: BarcodeSchema }) => (
|
32
|
+
<img
|
33
|
+
style={{
|
34
|
+
width: schema.width * ZOOM,
|
35
|
+
height: schema.height * ZOOM,
|
36
|
+
position: 'absolute',
|
37
|
+
borderRadius: 0,
|
38
|
+
opacity: 0.5,
|
39
|
+
}}
|
40
|
+
src={barcodeExampleImageObj[schema.type]}
|
41
|
+
/>
|
42
|
+
);
|
43
|
+
|
44
|
+
const ErrorBarcode = () => (
|
45
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
|
46
|
+
<p
|
47
|
+
style={{
|
48
|
+
color: 'white',
|
49
|
+
background: 'red',
|
50
|
+
padding: '0.25rem',
|
51
|
+
fontSize: '12pt',
|
52
|
+
fontWeight: 'bold',
|
53
|
+
borderRadius: 3,
|
54
|
+
}}
|
55
|
+
>
|
56
|
+
ERROR
|
57
|
+
</p>
|
58
|
+
</div>
|
59
|
+
);
|
60
|
+
|
61
|
+
const ErrorOrSampleBarcode = ({ schema, value }: { schema: BarcodeSchema; value: string }) =>
|
62
|
+
validateBarcodeInput(schema.type as BarCodeType, value) ? (
|
63
|
+
<SampleBarcode schema={schema} />
|
64
|
+
) : (
|
65
|
+
<ErrorBarcode />
|
66
|
+
);
|
67
|
+
|
68
|
+
const BarcodeSchemaUI = (
|
69
|
+
{ schema, editable, placeholder, tabIndex, onChange }: Props,
|
70
|
+
ref: Ref<HTMLInputElement>
|
71
|
+
) => {
|
72
|
+
const value = schema.data;
|
73
|
+
|
74
|
+
return (
|
75
|
+
<div
|
76
|
+
style={{
|
77
|
+
width: '100%',
|
78
|
+
height: '100%',
|
79
|
+
display: 'flex',
|
80
|
+
alignItems: 'center',
|
81
|
+
justifyContent: 'center',
|
82
|
+
}}
|
83
|
+
>
|
84
|
+
<input
|
85
|
+
ref={ref}
|
86
|
+
disabled={!editable}
|
87
|
+
tabIndex={tabIndex}
|
88
|
+
placeholder={placeholder}
|
89
|
+
style={{
|
90
|
+
textAlign: 'center',
|
91
|
+
position: 'absolute',
|
92
|
+
zIndex: 2,
|
93
|
+
fontSize: 'inherit',
|
94
|
+
height: Number(schema.height) * ZOOM,
|
95
|
+
width: Number(schema.width) * ZOOM,
|
96
|
+
background: editable || value ? 'rgba(255, 255, 255, 0.8)' : 'none',
|
97
|
+
border: 'none',
|
98
|
+
}}
|
99
|
+
value={value}
|
100
|
+
onChange={(e) => onChange(e.target.value)}
|
101
|
+
/>
|
102
|
+
{value ? (
|
103
|
+
<ErrorOrSampleBarcode value={value} schema={schema} />
|
104
|
+
) : (
|
105
|
+
<SampleBarcode schema={schema} />
|
106
|
+
)}
|
107
|
+
</div>
|
108
|
+
);
|
109
|
+
};
|
110
|
+
|
111
|
+
export default forwardRef<HTMLInputElement, Props>(BarcodeSchemaUI);
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import React, { forwardRef, ChangeEvent, useContext, Ref } from 'react';
|
2
|
+
import { ImageSchema } from '@pdfme/common';
|
3
|
+
import { SchemaUIProps } from './SchemaUI';
|
4
|
+
import { readFiles } from '../../helper';
|
5
|
+
import { I18nContext } from '../../contexts';
|
6
|
+
import { ZOOM } from '../../constants';
|
7
|
+
import imageExample from '../../assets/imageExample.png';
|
8
|
+
|
9
|
+
type Props = SchemaUIProps & { schema: ImageSchema };
|
10
|
+
|
11
|
+
const FilledImage = ({ editable, tabIndex, schema, onChange }: Omit<Props, 'placeholder'>) => (
|
12
|
+
<div style={{ margin: '0 auto' }}>
|
13
|
+
{editable && (
|
14
|
+
<button
|
15
|
+
tabIndex={tabIndex}
|
16
|
+
style={{
|
17
|
+
position: 'absolute',
|
18
|
+
left: 0,
|
19
|
+
top: 0,
|
20
|
+
}}
|
21
|
+
onClick={() => onChange('')}
|
22
|
+
>
|
23
|
+
x
|
24
|
+
</button>
|
25
|
+
)}
|
26
|
+
<img
|
27
|
+
style={{ width: schema.width * ZOOM, height: schema.height * ZOOM, borderRadius: 0 }}
|
28
|
+
src={schema.data}
|
29
|
+
/>
|
30
|
+
</div>
|
31
|
+
);
|
32
|
+
|
33
|
+
const BlankImage = (props: Props & { inputRef: Ref<HTMLInputElement> }) => {
|
34
|
+
const { editable, placeholder, tabIndex, schema, onChange, inputRef } = props;
|
35
|
+
const i18n = useContext(I18nContext);
|
36
|
+
|
37
|
+
return editable ? (
|
38
|
+
<label
|
39
|
+
style={{
|
40
|
+
height: Number(schema.height) * ZOOM,
|
41
|
+
width: Number(schema.width) * ZOOM,
|
42
|
+
display: 'flex',
|
43
|
+
justifyContent: 'center',
|
44
|
+
alignItems: 'center',
|
45
|
+
}}
|
46
|
+
>
|
47
|
+
<input
|
48
|
+
ref={inputRef}
|
49
|
+
tabIndex={tabIndex}
|
50
|
+
style={{ display: 'none' }}
|
51
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
52
|
+
const { files } = event.target;
|
53
|
+
readFiles(files, 'dataURL').then((result) => onChange(result as string));
|
54
|
+
}}
|
55
|
+
type="file"
|
56
|
+
accept="image/jpeg, image/png"
|
57
|
+
/>
|
58
|
+
<span style={{ zIndex: 1 }}>{i18n('select')}</span>
|
59
|
+
</label>
|
60
|
+
) : (
|
61
|
+
<div
|
62
|
+
style={{
|
63
|
+
position: 'absolute',
|
64
|
+
opacity: 0.5,
|
65
|
+
top: 0,
|
66
|
+
left: 0,
|
67
|
+
width: schema.width * ZOOM,
|
68
|
+
height: schema.height * ZOOM,
|
69
|
+
backgroundImage: `url(${placeholder || imageExample})`,
|
70
|
+
backgroundSize: 'cover',
|
71
|
+
backgroundPosition: 'center',
|
72
|
+
backgroundRepeat: 'no-repeat',
|
73
|
+
}}
|
74
|
+
></div>
|
75
|
+
);
|
76
|
+
};
|
77
|
+
|
78
|
+
const ImageSchemaUI = (props: Props, ref: Ref<HTMLInputElement>) =>
|
79
|
+
props.schema.data ? <FilledImage {...props} /> : <BlankImage {...props} inputRef={ref} />;
|
80
|
+
|
81
|
+
export default forwardRef<HTMLInputElement, Props>(ImageSchemaUI);
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import React, { forwardRef, RefObject, Ref, ReactNode } from 'react';
|
2
|
+
import { SchemaForUI, isTextSchema, isImageSchema, isBarcodeSchema } from '@pdfme/common';
|
3
|
+
import { ZOOM, SELECTABLE_CLASSNAME } from '../../constants';
|
4
|
+
import TextSchema from './TextSchema';
|
5
|
+
import ImageSchema from './ImageSchema';
|
6
|
+
import BarcodeSchema from './BarcodeSchema';
|
7
|
+
|
8
|
+
export interface SchemaUIProps {
|
9
|
+
schema: SchemaForUI;
|
10
|
+
editable: boolean;
|
11
|
+
onChange: (value: string) => void;
|
12
|
+
tabIndex?: number;
|
13
|
+
placeholder?: string;
|
14
|
+
}
|
15
|
+
|
16
|
+
type Props = SchemaUIProps & {
|
17
|
+
border: string;
|
18
|
+
onChangeHoveringSchemaId?: (id: string | null) => void;
|
19
|
+
};
|
20
|
+
|
21
|
+
const getBgc = (schema: SchemaForUI) =>
|
22
|
+
schema.type === 'text' && schema.backgroundColor ? schema.backgroundColor : 'transparent';
|
23
|
+
|
24
|
+
const Wrapper = ({
|
25
|
+
children,
|
26
|
+
border,
|
27
|
+
onChangeHoveringSchemaId,
|
28
|
+
schema,
|
29
|
+
}: Props & { children: ReactNode }) => (
|
30
|
+
<div
|
31
|
+
title={schema.key}
|
32
|
+
onMouseEnter={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(schema.id)}
|
33
|
+
onMouseLeave={() => onChangeHoveringSchemaId && onChangeHoveringSchemaId(null)}
|
34
|
+
className={SELECTABLE_CLASSNAME}
|
35
|
+
id={schema.id}
|
36
|
+
style={{
|
37
|
+
position: 'absolute',
|
38
|
+
height: schema.height * ZOOM,
|
39
|
+
width: schema.width * ZOOM,
|
40
|
+
top: schema.position.y * ZOOM,
|
41
|
+
left: schema.position.x * ZOOM,
|
42
|
+
border,
|
43
|
+
backgroundColor: getBgc(schema),
|
44
|
+
}}
|
45
|
+
>
|
46
|
+
{children}
|
47
|
+
</div>
|
48
|
+
);
|
49
|
+
|
50
|
+
const SchemaUI = (props: Props, ref: Ref<HTMLTextAreaElement | HTMLInputElement>) => {
|
51
|
+
const r = {
|
52
|
+
[props.editable ? 'ref' : '']: ref as RefObject<HTMLTextAreaElement | HTMLInputElement>,
|
53
|
+
};
|
54
|
+
const { schema } = props;
|
55
|
+
|
56
|
+
return (
|
57
|
+
<Wrapper {...props}>
|
58
|
+
{isTextSchema(schema) && <TextSchema {...r} {...props} schema={schema} />}
|
59
|
+
{isImageSchema(schema) && <ImageSchema {...r} {...props} schema={schema} />}
|
60
|
+
{isBarcodeSchema(schema) && <BarcodeSchema {...r} {...props} schema={schema} />}
|
61
|
+
</Wrapper>
|
62
|
+
);
|
63
|
+
};
|
64
|
+
export default forwardRef<HTMLTextAreaElement | HTMLInputElement, Props>(SchemaUI);
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import React, { forwardRef, Ref } from 'react';
|
2
|
+
import {
|
3
|
+
DEFAULT_FONT_SIZE,
|
4
|
+
DEFAULT_ALIGNMENT,
|
5
|
+
DEFAULT_LINE_HEIGHT,
|
6
|
+
DEFAULT_CHARACTER_SPACING,
|
7
|
+
DEFAULT_FONT_COLOR,
|
8
|
+
TextSchema,
|
9
|
+
} from '@pdfme/common';
|
10
|
+
import { SchemaUIProps } from './SchemaUI';
|
11
|
+
import { ZOOM } from '../../constants';
|
12
|
+
|
13
|
+
type Props = SchemaUIProps & { schema: TextSchema };
|
14
|
+
|
15
|
+
const TextSchemaUI = (
|
16
|
+
{ schema, editable, placeholder, tabIndex, onChange }: Props,
|
17
|
+
ref: Ref<HTMLTextAreaElement>
|
18
|
+
) => {
|
19
|
+
const style: React.CSSProperties = {
|
20
|
+
resize: 'none',
|
21
|
+
fontFamily: schema.fontName ?? 'inherit',
|
22
|
+
height: schema.height * ZOOM,
|
23
|
+
width: schema.width * ZOOM,
|
24
|
+
textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
|
25
|
+
fontSize: `${schema.fontSize ?? DEFAULT_FONT_SIZE}pt`,
|
26
|
+
letterSpacing: `${schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING}pt`,
|
27
|
+
fontFeatureSettings: `"palt"`,
|
28
|
+
lineHeight: `${schema.lineHeight ?? DEFAULT_LINE_HEIGHT}em`,
|
29
|
+
whiteSpace: 'pre-line',
|
30
|
+
wordBreak: 'break-all',
|
31
|
+
background: 'transparent',
|
32
|
+
border: 'none',
|
33
|
+
color: schema.fontColor ?? DEFAULT_FONT_COLOR,
|
34
|
+
};
|
35
|
+
|
36
|
+
return editable ? (
|
37
|
+
<textarea
|
38
|
+
ref={ref}
|
39
|
+
placeholder={placeholder}
|
40
|
+
tabIndex={tabIndex}
|
41
|
+
style={style}
|
42
|
+
onChange={(e) => onChange(e.target.value)}
|
43
|
+
value={schema.data}
|
44
|
+
></textarea>
|
45
|
+
) : (
|
46
|
+
<div style={style}>
|
47
|
+
{/* Set the letterSpacing of the last character to 0. */}
|
48
|
+
{schema.data.split('').map((l, i) => (
|
49
|
+
<span
|
50
|
+
key={i}
|
51
|
+
style={{
|
52
|
+
letterSpacing: String(schema.data).length === i + 1 ? 0 : 'inherit',
|
53
|
+
}}
|
54
|
+
>
|
55
|
+
{l}
|
56
|
+
</span>
|
57
|
+
))}
|
58
|
+
</div>
|
59
|
+
);
|
60
|
+
};
|
61
|
+
|
62
|
+
export default forwardRef<HTMLTextAreaElement, Props>(TextSchemaUI);
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
const Spinner = () => (
|
4
|
+
<>
|
5
|
+
<style>
|
6
|
+
{`
|
7
|
+
@keyframes spin {
|
8
|
+
0% { transform: rotate(0deg) }
|
9
|
+
|
10
|
+
100% { transform: rotate(359deg) }
|
11
|
+
}
|
12
|
+
`}
|
13
|
+
</style>
|
14
|
+
<div
|
15
|
+
style={{
|
16
|
+
width: '100%',
|
17
|
+
height: '100%',
|
18
|
+
display: 'flex',
|
19
|
+
alignItems: 'center',
|
20
|
+
justifyContent: 'center',
|
21
|
+
}}
|
22
|
+
>
|
23
|
+
<div
|
24
|
+
style={{
|
25
|
+
width: 65,
|
26
|
+
height: 65,
|
27
|
+
borderRadius: '50%',
|
28
|
+
border: '4px solid',
|
29
|
+
borderColor: '#4285f4 rgba(0,0,0,0.1) rgba(0,0,0,0.1)',
|
30
|
+
animation: 'spin 1s ease infinite',
|
31
|
+
}}
|
32
|
+
></div>
|
33
|
+
</div>
|
34
|
+
</>
|
35
|
+
);
|
36
|
+
|
37
|
+
export default Spinner;
|
package/src/constants.ts
ADDED
package/src/contexts.ts
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
import { createContext } from 'react';
|
2
|
+
import { curriedI18n } from './i18n';
|
3
|
+
import { DEFAULT_LANG } from './constants';
|
4
|
+
import { getDefaultFont } from '@pdfme/common';
|
5
|
+
|
6
|
+
export const I18nContext = createContext(curriedI18n(DEFAULT_LANG));
|
7
|
+
|
8
|
+
export const FontContext = createContext(getDefaultFont());
|