@pdfme/ui 3.1.4 → 3.1.5-dev.10

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.
@@ -10,7 +10,7 @@ export declare abstract class BaseUIClass {
10
10
  private readonly setSize;
11
11
  resizeObserver: ResizeObserver;
12
12
  constructor(props: UIProps);
13
- protected getLang(): "en" | "th" | "ja" | "ar" | "pl" | "it";
13
+ protected getLang(): "en" | "th" | "ja" | "ar" | "pl" | "it" | "de";
14
14
  protected getFont(): Record<string, {
15
15
  data: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
16
16
  fallback?: boolean | undefined;
@@ -21,6 +21,7 @@ export declare abstract class BaseUIClass {
21
21
  getTemplate(): {
22
22
  schemas: Record<string, import("zod").objectOutputType<{
23
23
  type: import("zod").ZodString;
24
+ readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
24
25
  position: import("zod").ZodObject<{
25
26
  x: import("zod").ZodNumber;
26
27
  y: import("zod").ZodNumber;
@@ -1,6 +1,6 @@
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" | "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?: {
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" | "hexColorPrompt" | "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" | "schemas.line.color", dict?: {
4
4
  cancel: string;
5
5
  field: string;
6
6
  fieldName: string;
@@ -22,6 +22,7 @@ export declare const I18nContext: import("react").Context<(key: "height" | "widt
22
22
  errorBulkUpdateFieldName: string;
23
23
  commitBulkUpdateFieldName: string;
24
24
  bulkUpdateFieldName: string;
25
+ hexColorPrompt: string;
25
26
  'schemas.textColor': string;
26
27
  'schemas.bgColor': string;
27
28
  'schemas.horizontal': string;
@@ -43,6 +44,7 @@ export declare const I18nContext: import("react").Context<(key: "height" | "widt
43
44
  'schemas.text.fit': string;
44
45
  'schemas.text.dynamicFontSize': string;
45
46
  'schemas.barcodes.barColor': string;
47
+ 'schemas.line.color': string;
46
48
  } | undefined) => string>;
47
49
  export declare const FontContext: import("react").Context<Record<string, {
48
50
  data: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
@@ -37,7 +37,31 @@ export declare const templateSchemas2SchemasList: (_template: Template) => Promi
37
37
  key: string;
38
38
  opacity?: number | undefined;
39
39
  rotate?: number | undefined;
40
+ readOnly?: boolean | undefined;
40
41
  }[][]>;
42
+ export declare const generateColumnsAndSampledataIfNeeded: (template: Template) => {
43
+ schemas: Record<string, import("zod").objectOutputType<{
44
+ type: import("zod").ZodString;
45
+ readOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
46
+ position: import("zod").ZodObject<{
47
+ x: import("zod").ZodNumber;
48
+ y: import("zod").ZodNumber;
49
+ }, "strip", import("zod").ZodTypeAny, {
50
+ x: number;
51
+ y: number;
52
+ }, {
53
+ x: number;
54
+ y: number;
55
+ }>;
56
+ width: import("zod").ZodNumber;
57
+ height: import("zod").ZodNumber;
58
+ rotate: import("zod").ZodOptional<import("zod").ZodNumber>;
59
+ opacity: import("zod").ZodOptional<import("zod").ZodNumber>;
60
+ }, import("zod").ZodTypeAny, "passthrough">>[];
61
+ basePdf: (string | Uint8Array | ArrayBuffer) & (string | Uint8Array | ArrayBuffer | undefined);
62
+ sampledata?: Record<string, string>[] | undefined;
63
+ columns?: string[] | undefined;
64
+ };
41
65
  export declare const fmtTemplate: (template: Template, schemasList: SchemaForUI[][]) => Template;
42
66
  export declare const getUniqSchemaKey: (arg: {
43
67
  copiedSchemaKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "3.1.4",
3
+ "version": "3.1.5-dev.10",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
package/src/class.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ReactDOM from 'react-dom';
2
2
  import { DESTROYED_ERR_MSG, DEFAULT_LANG } from './constants.js';
3
- import { debounce, flatten, cloneDeep } from './helper.js';
3
+ import { debounce, generateColumnsAndSampledataIfNeeded, cloneDeep } from './helper.js';
4
4
  import {
5
5
  Template,
6
6
  Size,
@@ -19,42 +19,6 @@ import {
19
19
  } from '@pdfme/common';
20
20
  import { builtInPlugins } from '@pdfme/schemas';
21
21
 
22
- const generateColumnsAndSampledataIfNeeded = (template: Template) => {
23
- const { schemas, columns, sampledata } = template;
24
-
25
- const flatSchemaLength = schemas
26
- .map((schema) => Object.keys(schema).length)
27
- .reduce((acc, cur) => acc + cur, 0);
28
-
29
- const needColumns = !columns || flatSchemaLength !== columns.length;
30
-
31
- const needSampledata = !sampledata || flatSchemaLength !== Object.keys(sampledata[0]).length;
32
-
33
- // columns
34
- if (needColumns) {
35
- template.columns = flatten(schemas.map((schema) => Object.keys(schema)));
36
- }
37
-
38
- // sampledata
39
- if (needSampledata) {
40
- template.sampledata = [
41
- schemas.reduce(
42
- (acc, cur) =>
43
- Object.assign(
44
- acc,
45
- Object.keys(cur).reduce(
46
- (a, c) => Object.assign(a, { [c]: '' }),
47
- {} as { [key: string]: string }
48
- )
49
- ),
50
- {} as { [key: string]: string }
51
- ),
52
- ];
53
- }
54
-
55
- return template;
56
- };
57
-
58
22
  export abstract class BaseUIClass {
59
23
  protected domContainer!: HTMLElement | null;
60
24
 
@@ -77,7 +77,9 @@ const DetailView = (
77
77
  for (let key in newSchema) {
78
78
  if (['id', 'data'].includes(key)) continue;
79
79
  if (newSchema[key] !== (activeSchema as any)[key]) {
80
- const value = newSchema[key] || undefined;
80
+ let value = newSchema[key];
81
+ // FIXME memo: https://github.com/pdfme/pdfme/pull/367#issuecomment-1857468274
82
+ if (value === null && ['rotate', 'opacity'].includes(key)) value = undefined;
81
83
 
82
84
  // [position] Return the flattened position to its original form.
83
85
  if (key === 'x') key = 'position.x';
@@ -138,6 +140,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
138
140
  widget: 'inputNumber',
139
141
  required: true,
140
142
  span: 8,
143
+ min: 0,
141
144
  },
142
145
  height: {
143
146
  title: i18n('height'),
@@ -145,6 +148,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
145
148
  widget: 'inputNumber',
146
149
  required: true,
147
150
  span: 8,
151
+ min: 0,
148
152
  },
149
153
  opacity: {
150
154
  title: i18n('opacity'),
@@ -104,7 +104,9 @@ const Preview = ({
104
104
  placeholder={template.sampledata?.[0]?.[key] ?? ''}
105
105
  tabIndex={index + 100}
106
106
  onChange={(value) => handleChangeInput({ key, value })}
107
- outline={isForm ? `1px dashed ${token.colorPrimary}` : 'transparent'}
107
+ outline={
108
+ isForm && !schema.readOnly ? `1px dashed ${token.colorPrimary}` : 'transparent'
109
+ }
108
110
  scale={scale}
109
111
  />
110
112
  );
@@ -29,12 +29,13 @@ const Wrapper = ({
29
29
  id={schema.id}
30
30
  style={{
31
31
  position: 'absolute',
32
- cursor: 'pointer',
32
+ cursor: schema.readOnly ? 'initial' : 'pointer',
33
33
  height: schema.height * ZOOM,
34
34
  width: schema.width * ZOOM,
35
35
  top: schema.position.y * ZOOM,
36
36
  left: schema.position.x * ZOOM,
37
37
  transform: `rotate(${schema.rotate ?? 0}deg)`,
38
+ opacity: schema.opacity ?? 1,
38
39
  outline,
39
40
  }}
40
41
  >
package/src/helper.ts CHANGED
@@ -309,6 +309,48 @@ export const templateSchemas2SchemasList = async (_template: Template) => {
309
309
  return schemasList;
310
310
  };
311
311
 
312
+ export const generateColumnsAndSampledataIfNeeded = (template: Template) => {
313
+ const { schemas, columns, sampledata } = template;
314
+
315
+ const flatSchemaLengthForColumns = schemas
316
+ .map((schema) => Object.keys(schema).length)
317
+ .reduce((acc, cur) => acc + cur, 0);
318
+ const needColumns = !columns || flatSchemaLengthForColumns !== columns.length;
319
+
320
+ const flatSchemaLengthForSampleData = schemas
321
+ .map((schema) => Object.keys(schema).filter((key) => !schema[key].readOnly).length)
322
+ .reduce((acc, cur) => acc + cur, 0);
323
+ const needSampledata =
324
+ !sampledata || flatSchemaLengthForSampleData !== Object.keys(sampledata[0]).length;
325
+
326
+ // columns
327
+ if (needColumns) {
328
+ template.columns = flatten(schemas.map((schema) => Object.keys(schema)));
329
+ }
330
+
331
+ // sampledata
332
+ if (needSampledata) {
333
+ template.sampledata = [
334
+ schemas.reduce(
335
+ (acc, cur) =>
336
+ Object.assign(
337
+ acc,
338
+ Object.keys(cur).reduce((a, c) => {
339
+ const { readOnly } = cur[c];
340
+ if (readOnly) {
341
+ return a;
342
+ }
343
+ return Object.assign(a, { [c]: '' });
344
+ }, {} as { [key: string]: string })
345
+ ),
346
+ {} as { [key: string]: string }
347
+ ),
348
+ ];
349
+ }
350
+
351
+ return template;
352
+ };
353
+
312
354
  export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): Template => {
313
355
  const schemaAddedTemplate: Template = {
314
356
  ...template,
@@ -333,6 +375,9 @@ export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): T
333
375
  sampledata: [
334
376
  cloneDeep(schemasList).reduce((acc, cur) => {
335
377
  cur.forEach((c) => {
378
+ if (c.readOnly) {
379
+ return;
380
+ }
336
381
  acc[c.key] = c.data;
337
382
  });
338
383
 
package/src/i18n.ts CHANGED
@@ -24,6 +24,7 @@ const dictEn: { [key in keyof Dict]: string } = {
24
24
  'Cannot commit the change because the number of items has been changed.',
25
25
  commitBulkUpdateFieldName: 'Commit Changes',
26
26
  bulkUpdateFieldName: 'Bulk update field names',
27
+ hexColorPrompt: 'Please enter a valid hex color code.',
27
28
  'schemas.textColor': 'Text Color',
28
29
  'schemas.bgColor': 'Background Color',
29
30
  'schemas.horizontal': 'Horizontal',
@@ -45,6 +46,7 @@ const dictEn: { [key in keyof Dict]: string } = {
45
46
  'schemas.text.fit': 'Fit',
46
47
  'schemas.text.dynamicFontSize': 'Dynamic Font Size',
47
48
  'schemas.barcodes.barColor': 'Bar Color',
49
+ 'schemas.line.color': 'Color',
48
50
  };
49
51
 
50
52
  const dictJa: { [key in keyof Dict]: string } = {
@@ -69,6 +71,7 @@ const dictJa: { [key in keyof Dict]: string } = {
69
71
  errorBulkUpdateFieldName: '項目数が変更されているため変更をコミットできません。',
70
72
  commitBulkUpdateFieldName: '変更を反映',
71
73
  bulkUpdateFieldName: '項目名を一括変更',
74
+ hexColorPrompt: '有効な16進数のカラーコードを入力してください。',
72
75
  'schemas.textColor': 'テキストの色',
73
76
  'schemas.bgColor': '背景色',
74
77
  'schemas.horizontal': '水平',
@@ -90,6 +93,7 @@ const dictJa: { [key in keyof Dict]: string } = {
90
93
  'schemas.text.fit': 'フィット',
91
94
  'schemas.text.dynamicFontSize': '動的フォントサイズ',
92
95
  'schemas.barcodes.barColor': 'バーの色',
96
+ 'schemas.line.color': '色',
93
97
  };
94
98
 
95
99
  const dictAr: { [key in keyof Dict]: string } = {
@@ -114,6 +118,7 @@ const dictAr: { [key in keyof Dict]: string } = {
114
118
  errorBulkUpdateFieldName: 'لا يمكن تنفيذ التغيير لأنه تم تغيير عدد العناصر.',
115
119
  commitBulkUpdateFieldName: 'تنفيذ التغييرات',
116
120
  bulkUpdateFieldName: 'تغيير الأسماء',
121
+ hexColorPrompt: 'الرجاء إدخال رمز لون سداسي عشري صالح.',
117
122
  'schemas.textColor': 'لون الخط',
118
123
  'schemas.bgColor': 'لون الخلفية',
119
124
  'schemas.horizontal': 'أفقي',
@@ -135,6 +140,7 @@ const dictAr: { [key in keyof Dict]: string } = {
135
140
  'schemas.text.fit': 'ملاءمة',
136
141
  'schemas.text.dynamicFontSize': 'حجم الخط الديناميكي',
137
142
  'schemas.barcodes.barColor': 'لون الشريط',
143
+ 'schemas.line.color': 'اللون',
138
144
  };
139
145
 
140
146
  const dictTh: { [key in keyof Dict]: string } = {
@@ -159,6 +165,7 @@ const dictTh: { [key in keyof Dict]: string } = {
159
165
  errorBulkUpdateFieldName: 'ไม่สามารถยืนยันการแก้ไขได้เนื่องจากจำนวนรายการมีการเปลี่ยนแปลง',
160
166
  commitBulkUpdateFieldName: 'ยืนยันการแก้ไข',
161
167
  bulkUpdateFieldName: 'แก้ไขชื่อฟิลด์เป็นชุด',
168
+ hexColorPrompt: 'กรุณาใส่รหัสสีแบบฐานสิบหกที่ถูกต้อง',
162
169
  'schemas.textColor': 'สีข้อความ',
163
170
  'schemas.bgColor': 'สีพื้นหลัง',
164
171
  'schemas.horizontal': 'แนวนอน',
@@ -180,6 +187,7 @@ const dictTh: { [key in keyof Dict]: string } = {
180
187
  'schemas.text.fit': 'พอดี',
181
188
  'schemas.text.dynamicFontSize': 'ขนาดตัวอักษรแบบไดนามิก',
182
189
  'schemas.barcodes.barColor': 'สีบาร์',
190
+ 'schemas.line.color': 'สี',
183
191
  };
184
192
 
185
193
  const dictIt: { [key in keyof Dict]: string } = {
@@ -205,6 +213,7 @@ const dictIt: { [key in keyof Dict]: string } = {
205
213
  'Non è possibile salvare le modifiche perché il numero di elementi è cambiato.',
206
214
  commitBulkUpdateFieldName: 'Salva cambiamenti',
207
215
  bulkUpdateFieldName: 'Modifica nomi campi in blocco',
216
+ hexColorPrompt: 'Inserisci un codice colore esadecimale valido.',
208
217
  'schemas.textColor': 'Colore testo',
209
218
  'schemas.bgColor': 'Colore sfondo',
210
219
  'schemas.horizontal': 'Orizzontale',
@@ -226,6 +235,7 @@ const dictIt: { [key in keyof Dict]: string } = {
226
235
  'schemas.text.fit': 'Adatta',
227
236
  'schemas.text.dynamicFontSize': 'Dimensione font dinamica',
228
237
  'schemas.barcodes.barColor': 'Colore barra',
238
+ 'schemas.line.color': 'Colore',
229
239
  };
230
240
 
231
241
  const dictPl: { [key in keyof Dict]: string } = {
@@ -250,6 +260,7 @@ const dictPl: { [key in keyof Dict]: string } = {
250
260
  errorBulkUpdateFieldName: 'Nie można wprowadzić zmian ponieważ liczba elementów uległa zmianie.',
251
261
  commitBulkUpdateFieldName: 'Zaakceptuj zmiany',
252
262
  bulkUpdateFieldName: 'Masowo aktualizuj klucze pól',
263
+ hexColorPrompt: 'Wprowadź poprawny kod koloru szesnastkowego.',
253
264
  'schemas.textColor': 'Kolor tekstu',
254
265
  'schemas.bgColor': 'Kolor tła',
255
266
  'schemas.horizontal': 'Poziomo',
@@ -271,6 +282,55 @@ const dictPl: { [key in keyof Dict]: string } = {
271
282
  'schemas.text.fit': 'Dopasowanie',
272
283
  'schemas.text.dynamicFontSize': 'Dynamiczny rozmiar czcionki',
273
284
  'schemas.barcodes.barColor': 'Kolor paska',
285
+ 'schemas.line.color': 'Kolor',
286
+ };
287
+
288
+ const dictDe: { [key in keyof Dict]: string } = {
289
+ cancel: 'Abbrechen',
290
+ field: 'Feld',
291
+ fieldName: 'Name',
292
+ align: 'Ausrichten',
293
+ width: 'Breite',
294
+ height: 'Höhe',
295
+ opacity: 'Opazität',
296
+ rotate: 'Drehen',
297
+ edit: 'Bearbeiten',
298
+ plsInputName: 'Bitte geben Sie einen Namen ein',
299
+ fieldMustUniq: 'Feldname ist nicht eindeutig',
300
+ notUniq: '(Nicht eindeutiger Name)',
301
+ noKeyName: 'Kein Name',
302
+ fieldsList: 'Feldliste',
303
+ addNewField: 'Neues Feld hinzufügen',
304
+ editField: 'Feld bearbeiten',
305
+ type: 'Typ',
306
+ errorOccurred: 'Ein Fehler ist aufgetreten',
307
+ errorBulkUpdateFieldName:
308
+ 'Die Änderung kann nicht übernommen werden, weil die Anzahl der Elemente geändert wurde.',
309
+ commitBulkUpdateFieldName: 'Änderungen übernehmen',
310
+ bulkUpdateFieldName: 'Mehrfachaktualisierung der Feldnamen',
311
+ hexColorPrompt: 'Bitte geben Sie einen gültigen Hex-Farbcode ein.',
312
+ 'schemas.textColor': 'Textfarbe',
313
+ 'schemas.bgColor': 'Hintergrundfarbe',
314
+ 'schemas.horizontal': 'Horizontal',
315
+ 'schemas.vertical': 'Vertikal',
316
+ 'schemas.left': 'Links',
317
+ 'schemas.center': 'Zentriert',
318
+ 'schemas.right': 'Rechts',
319
+ 'schemas.top': 'Oben',
320
+ 'schemas.middle': 'Mitte',
321
+ 'schemas.bottom': 'Unten',
322
+ 'schemas.text.fontName': 'Schriftart',
323
+ 'schemas.text.size': 'Größe',
324
+ 'schemas.text.spacing': 'Abstand',
325
+ 'schemas.text.textAlign': 'Ausrichtung',
326
+ 'schemas.text.verticalAlign': 'vert. Ausr.',
327
+ 'schemas.text.lineHeight': 'Zeilenhöhe',
328
+ 'schemas.text.min': 'Min',
329
+ 'schemas.text.max': 'Max',
330
+ 'schemas.text.fit': 'Anpassen',
331
+ 'schemas.text.dynamicFontSize': 'Dynamische Schriftgröße',
332
+ 'schemas.barcodes.barColor': 'Strichcodefarbe',
333
+ 'schemas.line.color': 'Farbe',
274
334
  };
275
335
 
276
336
  const dictionaries: { [key in Lang]: Dict } = {
@@ -280,6 +340,7 @@ const dictionaries: { [key in Lang]: Dict } = {
280
340
  th: dictTh,
281
341
  it: dictIt,
282
342
  pl: dictPl,
343
+ de: dictDe,
283
344
  };
284
345
 
285
346
  export const getDict = (lang: Lang): Dict => dictionaries[lang] || dictionaries[DEFAULT_LANG];