@pdfme/ui 3.1.5-dev.6 → 3.1.5-dev.7

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.
@@ -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.5-dev.6",
3
+ "version": "3.1.5-dev.7",
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
 
@@ -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,7 +29,7 @@ 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,
package/src/helper.ts CHANGED
@@ -309,6 +309,45 @@ 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 flatSchemaLength = schemas
316
+ .map((schema) => Object.keys(schema).length)
317
+ .reduce((acc, cur) => acc + cur, 0);
318
+
319
+ const needColumns = !columns || flatSchemaLength !== columns.length;
320
+
321
+ const needSampledata = !sampledata || flatSchemaLength !== Object.keys(sampledata[0]).length;
322
+
323
+ // columns
324
+ if (needColumns) {
325
+ template.columns = flatten(schemas.map((schema) => Object.keys(schema)));
326
+ }
327
+
328
+ // sampledata
329
+ if (needSampledata) {
330
+ template.sampledata = [
331
+ schemas.reduce(
332
+ (acc, cur) =>
333
+ Object.assign(
334
+ acc,
335
+ Object.keys(cur).reduce((a, c) => {
336
+ const { readOnly } = cur[c];
337
+ if (readOnly) {
338
+ return a;
339
+ }
340
+ return Object.assign(a, { [c]: '' });
341
+ }, {} as { [key: string]: string })
342
+ ),
343
+ {} as { [key: string]: string }
344
+ ),
345
+ ];
346
+ }
347
+
348
+ return template;
349
+ };
350
+
312
351
  export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): Template => {
313
352
  const schemaAddedTemplate: Template = {
314
353
  ...template,
@@ -333,6 +372,9 @@ export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): T
333
372
  sampledata: [
334
373
  cloneDeep(schemasList).reduce((acc, cur) => {
335
374
  cur.forEach((c) => {
375
+ if (c.readOnly) {
376
+ return;
377
+ }
336
378
  acc[c.key] = c.data;
337
379
  });
338
380
 
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,7 @@ 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',
274
286
  };
275
287
 
276
288
  const dictDe: { [key in keyof Dict]: string } = {
@@ -296,6 +308,7 @@ const dictDe: { [key in keyof Dict]: string } = {
296
308
  'Die Änderung kann nicht übernommen werden, weil die Anzahl der Elemente geändert wurde.',
297
309
  commitBulkUpdateFieldName: 'Änderungen übernehmen',
298
310
  bulkUpdateFieldName: 'Mehrfachaktualisierung der Feldnamen',
311
+ hexColorPrompt: 'Bitte geben Sie einen gültigen Hex-Farbcode ein.',
299
312
  'schemas.textColor': 'Textfarbe',
300
313
  'schemas.bgColor': 'Hintergrundfarbe',
301
314
  'schemas.horizontal': 'Horizontal',
@@ -317,6 +330,7 @@ const dictDe: { [key in keyof Dict]: string } = {
317
330
  'schemas.text.fit': 'Anpassen',
318
331
  'schemas.text.dynamicFontSize': 'Dynamische Schriftgröße',
319
332
  'schemas.barcodes.barColor': 'Strichcodefarbe',
333
+ 'schemas.line.color': 'Farbe',
320
334
  };
321
335
 
322
336
  const dictionaries: { [key in Lang]: Dict } = {