@pdfme/ui 3.1.2 → 3.1.3-dev.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 +184 -184
- package/dist/types/class.d.ts +1 -0
- package/dist/types/components/Renderer.d.ts +1 -1
- package/dist/types/contexts.d.ts +2 -1
- package/dist/types/helper.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/Designer/Sidebar/DetailView/index.tsx +64 -31
- package/src/components/Renderer.tsx +4 -1
- package/src/i18n.ts +6 -0
- package/vite.config.ts +1 -1
package/dist/types/class.d.ts
CHANGED
@@ -34,6 +34,7 @@ export declare abstract class BaseUIClass {
|
|
34
34
|
width: import("zod").ZodNumber;
|
35
35
|
height: import("zod").ZodNumber;
|
36
36
|
rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
37
|
+
opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
|
37
38
|
}, import("zod").ZodTypeAny, "passthrough">>[];
|
38
39
|
basePdf: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
|
39
40
|
sampledata?: Record<string, string>[] | undefined;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { UIRenderProps, SchemaForUI, Schema } from '@pdfme/common';
|
3
|
-
type RendererProps = Omit<UIRenderProps<Schema>, 'value' | 'schema' | 'onChange' | 'rootElement' | 'options' | 'theme' | 'i18n'> & {
|
3
|
+
type RendererProps = Omit<UIRenderProps<Schema>, 'value' | 'schema' | 'onChange' | 'rootElement' | 'options' | 'theme' | 'i18n' | '_cache'> & {
|
4
4
|
schema: SchemaForUI;
|
5
5
|
onChange: (value: string) => void;
|
6
6
|
outline: string;
|
package/dist/types/contexts.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { Plugins, UIOptions } from '@pdfme/common';
|
3
|
-
export declare const I18nContext: import("react").Context<(key: "height" | "width" | "type" | "rotate" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor", dict?: {
|
3
|
+
export declare const I18nContext: import("react").Context<(key: "height" | "width" | "type" | "rotate" | "opacity" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "addNewField" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.text.fontName" | "schemas.text.size" | "schemas.text.spacing" | "schemas.text.textAlign" | "schemas.text.verticalAlign" | "schemas.text.lineHeight" | "schemas.text.min" | "schemas.text.max" | "schemas.text.fit" | "schemas.text.dynamicFontSize" | "schemas.barcodes.barColor", dict?: {
|
4
4
|
cancel: string;
|
5
5
|
field: string;
|
6
6
|
fieldName: string;
|
7
7
|
align: string;
|
8
8
|
width: string;
|
9
|
+
opacity: string;
|
9
10
|
height: string;
|
10
11
|
rotate: string;
|
11
12
|
edit: string;
|
package/dist/types/helper.d.ts
CHANGED
@@ -35,6 +35,7 @@ export declare const templateSchemas2SchemasList: (_template: Template) => Promi
|
|
35
35
|
data: string;
|
36
36
|
id: string;
|
37
37
|
key: string;
|
38
|
+
opacity?: number | undefined;
|
38
39
|
rotate?: number | undefined;
|
39
40
|
}[][]>;
|
40
41
|
export declare const fmtTemplate: (template: Template, schemasList: SchemaForUI[][]) => Template;
|
package/package.json
CHANGED
@@ -58,15 +58,31 @@ const DetailView = (
|
|
58
58
|
}, [activeSchema, activeElements, pluginsRegistry, JSON.stringify(options)]);
|
59
59
|
|
60
60
|
useEffect(() => {
|
61
|
-
|
62
|
-
|
61
|
+
const values: any = { ...activeSchema };
|
62
|
+
|
63
|
+
// [position] Change the nested position object into a flat, as a three-column layout is difficult to implement
|
64
|
+
values.x = values.position.x;
|
65
|
+
values.y = values.position.y;
|
66
|
+
delete values.position;
|
67
|
+
|
68
|
+
if (values.key !== (form.getValues() || {}).key) {
|
69
|
+
form.resetFields();
|
70
|
+
}
|
71
|
+
|
72
|
+
form.setValues(values);
|
73
|
+
}, [form, activeSchema]);
|
63
74
|
|
64
75
|
const handleWatch = (newSchema: any) => {
|
65
76
|
const changes = [];
|
66
|
-
for (
|
77
|
+
for (let key in newSchema) {
|
67
78
|
if (['id', 'data'].includes(key)) continue;
|
68
79
|
if (newSchema[key] !== (activeSchema as any)[key]) {
|
69
|
-
|
80
|
+
const value = newSchema[key] || undefined;
|
81
|
+
|
82
|
+
// [position] Return the flattened position to its original form.
|
83
|
+
if (key === 'x') key = 'position.x';
|
84
|
+
if (key === 'y') key = 'position.y';
|
85
|
+
changes.push({ key, value, schemaId: activeSchema.id });
|
70
86
|
}
|
71
87
|
}
|
72
88
|
if (changes.length) {
|
@@ -84,6 +100,12 @@ const DetailView = (
|
|
84
100
|
Check this document: https://pdfme.com/docs/custom-schemas`);
|
85
101
|
}
|
86
102
|
|
103
|
+
const typeOptions = Object.entries(pluginsRegistry).map(([label, value]) => ({
|
104
|
+
label,
|
105
|
+
value: value?.propPanel.defaultSchema.type,
|
106
|
+
}));
|
107
|
+
const defaultSchema = activePlugin.propPanel.defaultSchema;
|
108
|
+
|
87
109
|
const propPanelSchema: PropPanelSchema = {
|
88
110
|
type: 'object',
|
89
111
|
column: 2,
|
@@ -92,34 +114,49 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
92
114
|
title: i18n('type'),
|
93
115
|
type: 'string',
|
94
116
|
widget: 'select',
|
95
|
-
props: {
|
96
|
-
|
97
|
-
|
98
|
-
value: value?.propPanel.defaultSchema.type,
|
99
|
-
})),
|
100
|
-
},
|
101
|
-
},
|
102
|
-
key: { title: i18n('fieldName'), type: 'string', widget: 'input' },
|
103
|
-
'-': { type: 'void', widget: 'Divider', cellSpan: 2 },
|
104
|
-
align: { title: i18n('align'), type: 'void', widget: 'AlignWidget', cellSpan: 2 },
|
105
|
-
position: {
|
106
|
-
type: 'object',
|
107
|
-
widget: 'card',
|
108
|
-
properties: {
|
109
|
-
x: { title: 'X', type: 'number', widget: 'inputNumber' },
|
110
|
-
y: { title: 'Y', type: 'number', widget: 'inputNumber' },
|
111
|
-
},
|
117
|
+
props: { options: typeOptions },
|
118
|
+
required: true,
|
119
|
+
span: 10,
|
112
120
|
},
|
113
|
-
|
114
|
-
|
121
|
+
key: { title: i18n('fieldName'), type: 'string', required: true, span: 14 },
|
122
|
+
'-': { type: 'void', widget: 'Divider' },
|
123
|
+
align: { title: i18n('align'), type: 'void', widget: 'AlignWidget' },
|
124
|
+
x: { title: 'X', type: 'number', widget: 'inputNumber', required: true, span: 8 },
|
125
|
+
y: { title: 'Y', type: 'number', widget: 'inputNumber', required: true, span: 8 },
|
115
126
|
rotate: {
|
116
127
|
title: i18n('rotate'),
|
117
128
|
type: 'number',
|
118
129
|
widget: 'inputNumber',
|
119
|
-
|
120
|
-
disabled: activePlugin.propPanel.defaultSchema?.rotate === undefined,
|
130
|
+
disabled: defaultSchema?.rotate === undefined,
|
121
131
|
max: 360,
|
122
132
|
min: 0,
|
133
|
+
span: 8,
|
134
|
+
},
|
135
|
+
width: {
|
136
|
+
title: i18n('width'),
|
137
|
+
type: 'number',
|
138
|
+
widget: 'inputNumber',
|
139
|
+
required: true,
|
140
|
+
span: 8,
|
141
|
+
},
|
142
|
+
height: {
|
143
|
+
title: i18n('height'),
|
144
|
+
type: 'number',
|
145
|
+
widget: 'inputNumber',
|
146
|
+
required: true,
|
147
|
+
span: 8,
|
148
|
+
},
|
149
|
+
opacity: {
|
150
|
+
title: i18n('opacity'),
|
151
|
+
type: 'number',
|
152
|
+
widget: 'inputNumber',
|
153
|
+
disabled: defaultSchema?.opacity === undefined,
|
154
|
+
props: {
|
155
|
+
step: 0.1,
|
156
|
+
},
|
157
|
+
max: 1,
|
158
|
+
min: 0,
|
159
|
+
span: 8,
|
123
160
|
},
|
124
161
|
},
|
125
162
|
};
|
@@ -134,18 +171,14 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
134
171
|
}) || {};
|
135
172
|
propPanelSchema.properties = {
|
136
173
|
...propPanelSchema.properties,
|
137
|
-
...(Object.keys(apps).length === 0
|
138
|
-
? {}
|
139
|
-
: { '--': { type: 'void', widget: 'Divider', cellSpan: 2 } }),
|
174
|
+
...(Object.keys(apps).length === 0 ? {} : { '--': { type: 'void', widget: 'Divider' } }),
|
140
175
|
...apps,
|
141
176
|
};
|
142
177
|
} else {
|
143
178
|
const apps = activePropPanelSchema || {};
|
144
179
|
propPanelSchema.properties = {
|
145
180
|
...propPanelSchema.properties,
|
146
|
-
...(Object.keys(apps).length === 0
|
147
|
-
? {}
|
148
|
-
: { '--': { type: 'void', widget: 'Divider', cellSpan: 2 } }),
|
181
|
+
...(Object.keys(apps).length === 0 ? {} : { '--': { type: 'void', widget: 'Divider' } }),
|
149
182
|
...apps,
|
150
183
|
};
|
151
184
|
}
|
@@ -6,7 +6,7 @@ import { PluginsRegistry, OptionsContext, I18nContext } from '../contexts';
|
|
6
6
|
|
7
7
|
type RendererProps = Omit<
|
8
8
|
UIRenderProps<Schema>,
|
9
|
-
'value' | 'schema' | 'onChange' | 'rootElement' | 'options' | 'theme' | 'i18n'
|
9
|
+
'value' | 'schema' | 'onChange' | 'rootElement' | 'options' | 'theme' | 'i18n' | '_cache'
|
10
10
|
> & {
|
11
11
|
schema: SchemaForUI;
|
12
12
|
onChange: (value: string) => void;
|
@@ -51,6 +51,7 @@ const Renderer = (props: RendererProps) => {
|
|
51
51
|
const { schema, mode, onChange, stopEditing, tabIndex, placeholder, scale } = props;
|
52
52
|
|
53
53
|
const ref = useRef<HTMLDivElement>(null);
|
54
|
+
const _cache = useRef<Map<any, any>>(new Map());
|
54
55
|
|
55
56
|
useEffect(() => {
|
56
57
|
if (ref.current && schema.type) {
|
@@ -69,6 +70,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
69
70
|
const editable = mode === 'form' || mode === 'designer';
|
70
71
|
|
71
72
|
render({
|
73
|
+
key: schema.key,
|
72
74
|
value: schema.data,
|
73
75
|
schema,
|
74
76
|
rootElement: ref.current,
|
@@ -80,6 +82,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
80
82
|
options,
|
81
83
|
theme,
|
82
84
|
i18n,
|
85
|
+
_cache: _cache.current,
|
83
86
|
});
|
84
87
|
}
|
85
88
|
return () => {
|
package/src/i18n.ts
CHANGED
@@ -8,6 +8,7 @@ const dictEn: { [key in keyof Dict]: string } = {
|
|
8
8
|
align: 'Align',
|
9
9
|
width: 'Width',
|
10
10
|
height: 'Height',
|
11
|
+
opacity: 'Opacity',
|
11
12
|
rotate: 'Rotate',
|
12
13
|
edit: 'Edit',
|
13
14
|
plsInputName: 'Please input name',
|
@@ -53,6 +54,7 @@ const dictJa: { [key in keyof Dict]: string } = {
|
|
53
54
|
align: '整列',
|
54
55
|
width: '幅',
|
55
56
|
height: '高さ',
|
57
|
+
opacity: '不透明度',
|
56
58
|
rotate: '回転',
|
57
59
|
edit: '編集する',
|
58
60
|
plsInputName: '項目名を入力してください',
|
@@ -97,6 +99,7 @@ const dictAr: { [key in keyof Dict]: string } = {
|
|
97
99
|
align: 'محاذاة',
|
98
100
|
width: 'العرض',
|
99
101
|
height: 'الارتفاع',
|
102
|
+
opacity: 'الشفافية',
|
100
103
|
rotate: 'تدوير',
|
101
104
|
edit: 'تعديل',
|
102
105
|
plsInputName: 'الرجاء إدخال الاسم',
|
@@ -141,6 +144,7 @@ const dictTh: { [key in keyof Dict]: string } = {
|
|
141
144
|
align: 'จัดเรียง',
|
142
145
|
width: 'ความกว้าง',
|
143
146
|
height: 'ความสูง',
|
147
|
+
opacity: 'ความทึบ',
|
144
148
|
rotate: 'หมุน',
|
145
149
|
edit: 'แก้ไข',
|
146
150
|
plsInputName: 'กรุณาใส่ชื่อ',
|
@@ -185,6 +189,7 @@ const dictIt: { [key in keyof Dict]: string } = {
|
|
185
189
|
align: 'Allinea',
|
186
190
|
width: 'Larghezza',
|
187
191
|
height: 'Altezza',
|
192
|
+
opacity: 'Opacità',
|
188
193
|
rotate: 'Ruota',
|
189
194
|
edit: 'Modifica',
|
190
195
|
plsInputName: 'Inserisci il nome per favore',
|
@@ -230,6 +235,7 @@ const dictPl: { [key in keyof Dict]: string } = {
|
|
230
235
|
align: 'Wyrównanie',
|
231
236
|
width: 'Szerokość',
|
232
237
|
height: 'Wysokość',
|
238
|
+
opacity: 'przezroczystość',
|
233
239
|
rotate: 'Obrót',
|
234
240
|
edit: 'Edytuj',
|
235
241
|
plsInputName: 'Wymagane wprowadzenie klucza pola',
|
package/vite.config.ts
CHANGED