@pdfme/ui 1.2.6 → 2.0.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/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Designer/Main/index.tsx +11 -1
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +11 -4
- package/src/components/Schemas/TextSchema.tsx +28 -22
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/ui",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.1",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"module": "dist/index.js",
|
26
26
|
"types": "dist/types/index.d.ts",
|
27
27
|
"engines": {
|
28
|
-
"node": ">=
|
28
|
+
"node": ">=16"
|
29
29
|
},
|
30
30
|
"scripts": {
|
31
31
|
"develop": "webpack --watch --mode development",
|
@@ -41,7 +41,7 @@
|
|
41
41
|
"@dnd-kit/core": "^5.0.1",
|
42
42
|
"@dnd-kit/sortable": "^6.0.0",
|
43
43
|
"@heroicons/react": "^2.0.13",
|
44
|
-
"@pdfme/common": "
|
44
|
+
"@pdfme/common": "file:../common",
|
45
45
|
"@scena/react-guides": "^0.16.0",
|
46
46
|
"hotkeys-js": "^3.8.7",
|
47
47
|
"pdfjs-dist": "2.12.313",
|
@@ -195,6 +195,14 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
195
195
|
changeSchemas(flatten(arg));
|
196
196
|
};
|
197
197
|
|
198
|
+
const currentlyEditingThisTextSchema = (target: EventTarget | null) => {
|
199
|
+
if (!target) return false;
|
200
|
+
if (target instanceof HTMLTextAreaElement) {
|
201
|
+
return activeElements.map((ae) => ae.id).includes(target.parentElement?.id || '');
|
202
|
+
}
|
203
|
+
return false;
|
204
|
+
}
|
205
|
+
|
198
206
|
const onResize = ({ target, width, height, direction }: OnResize) => {
|
199
207
|
if (!target) return;
|
200
208
|
const s = target.style;
|
@@ -235,7 +243,9 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
235
243
|
ref={ref}
|
236
244
|
onClick={(e) => {
|
237
245
|
e.stopPropagation();
|
238
|
-
|
246
|
+
if (!currentlyEditingThisTextSchema(e.target)) {
|
247
|
+
setEditing(false);
|
248
|
+
}
|
239
249
|
}}
|
240
250
|
style={{ overflow: 'overlay' }}
|
241
251
|
>
|
@@ -165,9 +165,7 @@ const TextPropEditor = (
|
|
165
165
|
value={activeSchema.fontName ?? fallbackFontName}
|
166
166
|
options={Object.keys(font)}
|
167
167
|
onChange={(e) => {
|
168
|
-
changeSchemas([
|
169
|
-
{ key: 'fontName', value: e.target.value, schemaId: activeSchema.id, },
|
170
|
-
]);
|
168
|
+
changeSchemas([{ key: 'fontName', value: e.target.value, schemaId: activeSchema.id }]);
|
171
169
|
}}
|
172
170
|
/>
|
173
171
|
|
@@ -194,8 +192,17 @@ const TextPropEditor = (
|
|
194
192
|
value={activeSchema.fontSize ?? DEFAULT_FONT_SIZE}
|
195
193
|
onChange={(e) => {
|
196
194
|
const currentFontSize = Number(e.target.value);
|
195
|
+
const dynamincFontSizeMinAdjust = activeSchema.dynamicFontSize && activeSchema.dynamicFontSize.min > currentFontSize;
|
196
|
+
|
197
197
|
changeSchemas([
|
198
|
-
{ key: 'fontSize', value: currentFontSize, schemaId: activeSchema.id
|
198
|
+
{ key: 'fontSize', value: currentFontSize, schemaId: activeSchema.id },
|
199
|
+
...(dynamincFontSizeMinAdjust
|
200
|
+
? [{
|
201
|
+
key: 'dynamicFontSize.min',
|
202
|
+
value: currentFontSize,
|
203
|
+
schemaId: activeSchema.id,
|
204
|
+
}]
|
205
|
+
: []),
|
199
206
|
]);
|
200
207
|
}}
|
201
208
|
/>
|
@@ -7,12 +7,13 @@ import {
|
|
7
7
|
DEFAULT_FONT_COLOR,
|
8
8
|
TextSchema,
|
9
9
|
calculateDynamicFontSize,
|
10
|
+
getFontKitFont,
|
11
|
+
getFontAlignmentValue,
|
10
12
|
} from '@pdfme/common';
|
11
13
|
import { SchemaUIProps } from './SchemaUI';
|
12
14
|
import { ZOOM } from '../../constants';
|
13
15
|
import { FontContext } from '../../contexts';
|
14
16
|
|
15
|
-
|
16
17
|
type Props = SchemaUIProps & { schema: TextSchema };
|
17
18
|
|
18
19
|
const TextSchemaUI = (
|
@@ -20,9 +21,9 @@ const TextSchemaUI = (
|
|
20
21
|
ref: Ref<HTMLTextAreaElement>
|
21
22
|
) => {
|
22
23
|
const font = useContext(FontContext);
|
23
|
-
|
24
|
-
|
25
24
|
const [dynamicFontSize, setDynamicFontSize] = useState<number | undefined>(undefined);
|
25
|
+
const [fontAlignmentValue, setFontAlignmentValue] = useState<number>(0);
|
26
|
+
|
26
27
|
|
27
28
|
useEffect(() => {
|
28
29
|
if (schema.dynamicFontSize && schema.data) {
|
@@ -30,25 +31,33 @@ const TextSchemaUI = (
|
|
30
31
|
} else {
|
31
32
|
setDynamicFontSize(undefined);
|
32
33
|
}
|
33
|
-
|
34
|
+
getFontKitFont(schema, font).then(fontKitFont => {
|
35
|
+
const fav = getFontAlignmentValue(fontKitFont, dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE);
|
36
|
+
setFontAlignmentValue(fav);
|
37
|
+
});
|
38
|
+
}, [schema.data, schema.width, schema.fontName, schema.fontSize, schema.dynamicFontSize, schema.dynamicFontSize?.max, schema.dynamicFontSize?.min, schema.characterSpacing, font]);
|
39
|
+
|
34
40
|
|
35
41
|
const style: React.CSSProperties = {
|
42
|
+
position: 'absolute',
|
43
|
+
top: 0,
|
36
44
|
padding: 0,
|
45
|
+
height: fontAlignmentValue < 0 ? schema.height * ZOOM + Math.abs(fontAlignmentValue) : schema.height * ZOOM,
|
46
|
+
width: schema.width * ZOOM,
|
37
47
|
resize: 'none',
|
38
|
-
|
48
|
+
marginTop: fontAlignmentValue < 0 ? fontAlignmentValue : 0,
|
49
|
+
paddingTop: fontAlignmentValue >= 0 ? fontAlignmentValue : 0,
|
39
50
|
fontFamily: schema.fontName ? `'${schema.fontName}'` : 'inherit',
|
40
|
-
|
41
|
-
width: schema.width * ZOOM,
|
42
|
-
textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
|
51
|
+
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
43
52
|
fontSize: `${dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE}pt`,
|
44
53
|
letterSpacing: `${schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING}pt`,
|
45
54
|
lineHeight: `${schema.lineHeight ?? DEFAULT_LINE_HEIGHT}em`,
|
55
|
+
textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
|
46
56
|
whiteSpace: 'pre-line',
|
47
57
|
wordBreak: 'break-word',
|
48
|
-
border: 'none',
|
49
|
-
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
50
58
|
backgroundColor:
|
51
59
|
schema.data && schema.backgroundColor ? schema.backgroundColor : 'rgb(242 244 255 / 75%)',
|
60
|
+
border: 'none',
|
52
61
|
};
|
53
62
|
|
54
63
|
return editable ? (
|
@@ -61,18 +70,15 @@ const TextSchemaUI = (
|
|
61
70
|
value={schema.data}
|
62
71
|
></textarea>
|
63
72
|
) : (
|
64
|
-
<div style={style}>
|
65
|
-
{
|
66
|
-
|
67
|
-
|
68
|
-
key={i}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
{l}
|
74
|
-
</span>
|
75
|
-
))}
|
73
|
+
<div style={{ ...style, height: schema.height * ZOOM, marginTop: 0, paddingTop: 0 }}>
|
74
|
+
<div style={{ marginTop: style.marginTop, paddingTop: style.paddingTop }}>
|
75
|
+
{/* Set the letterSpacing of the last character to 0. */}
|
76
|
+
{schema.data.split('').map((l, i) => (
|
77
|
+
<span key={i} style={{ letterSpacing: String(schema.data).length === i + 1 ? 0 : 'inherit', }} >
|
78
|
+
{l}
|
79
|
+
</span>
|
80
|
+
))}
|
81
|
+
</div>
|
76
82
|
</div>
|
77
83
|
);
|
78
84
|
};
|