@pdfme/ui 3.1.2-dev.1 → 3.1.2-dev.3

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.
@@ -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,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;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "3.1.2-dev.1",
3
+ "version": "3.1.2-dev.3",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -58,16 +58,31 @@ const DetailView = (
58
58
  }, [activeSchema, activeElements, pluginsRegistry, JSON.stringify(options)]);
59
59
 
60
60
  useEffect(() => {
61
- form.resetFields();
62
- form.setValues({ ...activeSchema });
63
- }, [activeSchema]);
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]);
64
74
 
65
75
  const handleWatch = (newSchema: any) => {
66
76
  const changes = [];
67
- for (const key in newSchema) {
77
+ for (let key in newSchema) {
68
78
  if (['id', 'data'].includes(key)) continue;
69
79
  if (newSchema[key] !== (activeSchema as any)[key]) {
70
- changes.push({ key, value: newSchema[key], schemaId: activeSchema.id });
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 });
71
86
  }
72
87
  }
73
88
  if (changes.length) {
@@ -85,6 +100,12 @@ const DetailView = (
85
100
  Check this document: https://pdfme.com/docs/custom-schemas`);
86
101
  }
87
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
+
88
109
  const propPanelSchema: PropPanelSchema = {
89
110
  type: 'object',
90
111
  column: 2,
@@ -93,34 +114,49 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
93
114
  title: i18n('type'),
94
115
  type: 'string',
95
116
  widget: 'select',
96
- props: {
97
- options: Object.entries(pluginsRegistry).map(([label, value]) => ({
98
- label,
99
- value: value?.propPanel.defaultSchema.type,
100
- })),
101
- },
102
- },
103
- key: { title: i18n('fieldName'), type: 'string', widget: 'input' },
104
- '-': { type: 'void', widget: 'Divider', cellSpan: 2 },
105
- align: { title: i18n('align'), type: 'void', widget: 'AlignWidget', cellSpan: 2 },
106
- position: {
107
- type: 'object',
108
- widget: 'card',
109
- properties: {
110
- x: { title: 'X', type: 'number', widget: 'inputNumber' },
111
- y: { title: 'Y', type: 'number', widget: 'inputNumber' },
112
- },
117
+ props: { options: typeOptions },
118
+ required: true,
119
+ span: 10,
113
120
  },
114
- width: { title: i18n('width'), type: 'number', widget: 'inputNumber', span: 8 },
115
- height: { title: i18n('height'), type: 'number', widget: 'inputNumber', span: 8 },
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 },
116
126
  rotate: {
117
127
  title: i18n('rotate'),
118
128
  type: 'number',
119
129
  widget: 'inputNumber',
120
- span: 8,
121
- disabled: activePlugin.propPanel.defaultSchema?.rotate === undefined,
130
+ disabled: defaultSchema?.rotate === undefined,
122
131
  max: 360,
123
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,
124
160
  },
125
161
  },
126
162
  };
@@ -135,18 +171,14 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
135
171
  }) || {};
136
172
  propPanelSchema.properties = {
137
173
  ...propPanelSchema.properties,
138
- ...(Object.keys(apps).length === 0
139
- ? {}
140
- : { '--': { type: 'void', widget: 'Divider', cellSpan: 2 } }),
174
+ ...(Object.keys(apps).length === 0 ? {} : { '--': { type: 'void', widget: 'Divider' } }),
141
175
  ...apps,
142
176
  };
143
177
  } else {
144
178
  const apps = activePropPanelSchema || {};
145
179
  propPanelSchema.properties = {
146
180
  ...propPanelSchema.properties,
147
- ...(Object.keys(apps).length === 0
148
- ? {}
149
- : { '--': { type: 'void', widget: 'Divider', cellSpan: 2 } }),
181
+ ...(Object.keys(apps).length === 0 ? {} : { '--': { type: 'void', widget: 'Divider' } }),
150
182
  ...apps,
151
183
  };
152
184
  }
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',