@pdfme/ui 4.2.4-dev.11 → 4.2.4-dev.12

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.
@@ -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: "type" | "width" | "height" | "rotate" | "opacity" | "required" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "hexColorPrompt" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "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.text.format" | "schemas.mvt.typingInstructions" | "schemas.mvt.sampleField" | "schemas.mvt.variablesSampleData" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle", dict?: {
3
+ export declare const I18nContext: import("react").Context<(key: "type" | "width" | "height" | "rotate" | "opacity" | "required" | "cancel" | "field" | "fieldName" | "align" | "edit" | "plsInputName" | "fieldMustUniq" | "notUniq" | "noKeyName" | "fieldsList" | "editField" | "errorOccurred" | "errorBulkUpdateFieldName" | "commitBulkUpdateFieldName" | "bulkUpdateFieldName" | "addPageAfter" | "removePage" | "removePageConfirm" | "validation.uniqueName" | "validation.hexColor" | "schemas.color" | "schemas.borderWidth" | "schemas.borderColor" | "schemas.backgroundColor" | "schemas.textColor" | "schemas.bgColor" | "schemas.horizontal" | "schemas.vertical" | "schemas.left" | "schemas.center" | "schemas.right" | "schemas.top" | "schemas.middle" | "schemas.bottom" | "schemas.padding" | "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.text.format" | "schemas.mvt.typingInstructions" | "schemas.mvt.sampleField" | "schemas.mvt.variablesSampleData" | "schemas.barcodes.barColor" | "schemas.barcodes.includetext" | "schemas.table.alternateBackgroundColor" | "schemas.table.tableStyle" | "schemas.table.headStyle" | "schemas.table.bodyStyle" | "schemas.table.columnStyle", dict?: {
4
4
  cancel: string;
5
5
  field: string;
6
6
  fieldName: string;
@@ -25,7 +25,8 @@ export declare const I18nContext: import("react").Context<(key: "type" | "width"
25
25
  addPageAfter: string;
26
26
  removePage: string;
27
27
  removePageConfirm: string;
28
- hexColorPrompt: string;
28
+ 'validation.uniqueName': string;
29
+ 'validation.hexColor': string;
29
30
  'schemas.color': string;
30
31
  'schemas.borderWidth': string;
31
32
  'schemas.borderColor': string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/ui",
3
- "version": "4.2.4-dev.11",
3
+ "version": "4.2.4-dev.12",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -1,10 +1,10 @@
1
1
  import FormRender, { useForm } from 'form-render';
2
- import React, { useContext, useState, useEffect } from 'react';
2
+ import React, { useRef, useContext, useState, useEffect } from 'react';
3
3
  import type { ChangeSchemaItem, Dict, SchemaForUI, PropPanelWidgetProps, PropPanelSchema } from '@pdfme/common';
4
4
  import type { SidebarProps } from '../../../../types';
5
5
  import { MenuOutlined } from '@ant-design/icons';
6
6
  import { I18nContext, PluginsRegistry, OptionsContext } from '../../../../contexts';
7
- import { getSidebarContentHeight } from '../../../../helper';
7
+ import { getSidebarContentHeight, debounce } from '../../../../helper';
8
8
  import { theme, Typography, Button, Divider } from 'antd';
9
9
  import AlignWidget from './AlignWidget';
10
10
  import WidgetRenderer from './WidgetRenderer';
@@ -22,7 +22,7 @@ type DetailViewProps = Pick<SidebarProps,
22
22
  const DetailView = (props: DetailViewProps) => {
23
23
  const { token } = theme.useToken();
24
24
 
25
- const { size, changeSchemas, deselectSchema, activeSchema } = props;
25
+ const { size, schemas, changeSchemas, deselectSchema, activeSchema } = props;
26
26
  const form = useForm();
27
27
 
28
28
  const i18n = useContext(I18nContext);
@@ -66,15 +66,28 @@ const DetailView = (props: DetailViewProps) => {
66
66
  values.y = values.position.y;
67
67
  delete values.position;
68
68
 
69
- if (values.key !== (form.getValues() || {}).key) {
70
- form.resetFields();
71
- }
72
-
73
69
  form.setValues(values);
74
70
 
75
71
  }, [activeSchema, form]);
76
72
 
77
- const handleWatch = (formSchema: any) => {
73
+ useEffect(() => form.resetFields(), [activeSchema.id])
74
+
75
+ useEffect(() => {
76
+ uniqueSchemaKey.current = (value: string): boolean => {
77
+ for (const s of Object.values(schemas)) {
78
+ if (s.key === value && s.id !== activeSchema.id) {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ };
84
+ }, [schemas, activeSchema]);
85
+
86
+ const uniqueSchemaKey = useRef((value: string): boolean => true);
87
+
88
+ const validateUniqueSchemaKey = (_: any, value: string): boolean => uniqueSchemaKey.current(value)
89
+
90
+ const handleWatch = debounce((formSchema: any) => {
78
91
  const formAndSchemaValuesDiffer = (formValue: any, schemaValue: any): boolean => {
79
92
  if (typeof formValue === 'object') {
80
93
  return JSON.stringify(formValue) !== JSON.stringify(schemaValue);
@@ -122,7 +135,7 @@ const DetailView = (props: DetailViewProps) => {
122
135
  }
123
136
  });
124
137
  }
125
- };
138
+ }, 500);
126
139
 
127
140
  const activePlugin = Object.values(pluginsRegistry).find(
128
141
  (plugin) => plugin?.propPanel.defaultSchema.type === activeSchema.type
@@ -152,7 +165,17 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
152
165
  required: true,
153
166
  span: 12,
154
167
  },
155
- key: { title: i18n('fieldName'), type: 'string', required: true, span: 12, props: { autocomplete: "off"} },
168
+ key: {
169
+ title: i18n('fieldName'),
170
+ type: 'string',
171
+ required: true,
172
+ span: 12,
173
+ rules: [{
174
+ validator: validateUniqueSchemaKey,
175
+ message: i18n('validation.uniqueName'),
176
+ }],
177
+ props: { autocomplete: "off" }
178
+ },
156
179
  required: { title: i18n('required'), type: 'boolean', span: 8, hidden: defaultSchema?.readOnly },
157
180
  '-': { type: 'void', widget: 'Divider' },
158
181
  align: { title: i18n('align'), type: 'void', widget: 'AlignWidget' },
@@ -255,7 +278,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
255
278
  };
256
279
 
257
280
  const propsAreUnchanged = (prevProps: DetailViewProps, nextProps: DetailViewProps) => {
258
- return JSON.stringify(prevProps.activeSchema) == JSON.stringify(nextProps.activeSchema)
281
+ return JSON.stringify(prevProps.activeSchema) == JSON.stringify(nextProps.activeSchema);
259
282
  };
260
283
 
261
284
  export default React.memo(DetailView, propsAreUnchanged);
@@ -162,11 +162,20 @@ const TemplateEditor = ({
162
162
  const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isBlankPdf(template.basePdf) ? template.basePdf.padding : [0, 0, 0, 0];
163
163
  const pageSize = pageSizes[pageCursor];
164
164
 
165
+ const newSchemaKey = (prefix: string) => {
166
+ let keyNum = schemasList[pageCursor].length + 1;
167
+ let newKey = prefix + keyNum;
168
+ while (schemasList[pageCursor].find((s) => s.key === newKey)) {
169
+ keyNum++;
170
+ newKey = prefix + keyNum;
171
+ }
172
+ return newKey;
173
+ };
165
174
  const ensureMiddleValue = (min: number, value: number, max: number) => Math.min(Math.max(min, value), max)
166
175
 
167
176
  const s = {
168
177
  id: uuid(),
169
- key: `${i18n('field')}${schemasList[pageCursor].length + 1}`,
178
+ key: newSchemaKey(i18n('field')),
170
179
  ...defaultSchema,
171
180
  position: {
172
181
  x: ensureMiddleValue(paddingLeft, defaultSchema.position.x, pageSize.width - paddingRight - defaultSchema.width),
package/src/i18n.ts CHANGED
@@ -27,7 +27,8 @@ const dictEn: { [key in keyof Dict]: string } = {
27
27
  addPageAfter: 'Add Page After',
28
28
  removePage: 'Remove Current Page',
29
29
  removePageConfirm: 'Are you sure you want to delete this page? This action cannot be undone.',
30
- hexColorPrompt: 'Please enter a valid hex color code.',
30
+ 'validation.hexColor': 'Please enter a valid hex color code.',
31
+ 'validation.uniqueName': 'Please enter a unique name.',
31
32
  'schemas.color': 'Color',
32
33
  'schemas.borderWidth': 'Border Width',
33
34
  'schemas.borderColor': 'Border Color',
@@ -91,7 +92,8 @@ const dictZh: { [key in keyof Dict]: string } = {
91
92
  addPageAfter: '在之后添加页面',
92
93
  removePage: '删除当前页面',
93
94
  removePageConfirm: '您确定要删除此页面吗?此操作无法撤销。',
94
- hexColorPrompt: '请输入有效的十六进制颜色代码。',
95
+ 'validation.hexColor': '请输入有效的十六进制颜色代码。',
96
+ 'validation.uniqueName': '请输入一个唯一的名称。',
95
97
  'schemas.color': '颜色',
96
98
  'schemas.borderWidth': '边框宽度',
97
99
  'schemas.borderColor': '边框颜色',
@@ -155,7 +157,8 @@ const dictJa: { [key in keyof Dict]: string } = {
155
157
  addPageAfter: '次にページを追加',
156
158
  removePage: '現在のページを削除',
157
159
  removePageConfirm: 'ページを削除してもよろしいですか?この操作は元に戻せません。',
158
- hexColorPrompt: '有効な16進数のカラーコードを入力してください。',
160
+ 'validation.hexColor': '有効な16進数のカラーコードを入力してください。',
161
+ 'validation.uniqueName': '一意の名前を入力してください。',
159
162
  'schemas.color': '色',
160
163
  'schemas.borderWidth': '枠線の太さ',
161
164
  'schemas.borderColor': '枠線の色',
@@ -219,7 +222,8 @@ const dictKo: { [key in keyof Dict]: string } = {
219
222
  addPageAfter: '다음에 페이지 추가',
220
223
  removePage: '현재 페이지 제거',
221
224
  removePageConfirm: '이 페이지를 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.',
222
- hexColorPrompt: '유효한 16진수 색상 코드를 입력하세요.',
225
+ 'validation.hexColor': '유효한 16진수 색상 코드를 입력하세요.',
226
+ 'validation.uniqueName': '고유한 이름을 입력하세요.',
223
227
  'schemas.color': '색상',
224
228
  'schemas.borderWidth': '테두리 너비',
225
229
  'schemas.borderColor': '테두리 색상',
@@ -283,7 +287,8 @@ const dictAr: { [key in keyof Dict]: string } = {
283
287
  addPageAfter: 'إضافة صفحة بعد',
284
288
  removePage: 'احذف الصفحة الحالية',
285
289
  removePageConfirm: 'هل أنت متأكد من رغبتك في حذف هذه الصفحة؟ لا يمكن التراجع عن هذا الإجراء.',
286
- hexColorPrompt: 'الرجاء إدخال رمز لون سداسي عشري صالح.',
290
+ 'validation.hexColor': 'الرجاء إدخال رمز لون سداسي عشري صالح.',
291
+ 'validation.uniqueName': 'الرجاء إدخال اسم فريد.',
287
292
  'schemas.color': 'اللون',
288
293
  'schemas.borderWidth': 'عرض الحدود',
289
294
  'schemas.borderColor': 'لون الحدود',
@@ -347,7 +352,8 @@ const dictTh: { [key in keyof Dict]: string } = {
347
352
  addPageAfter: 'เพิ่มหน้าถัดไป',
348
353
  removePage: 'ลบหน้าปัจจุบัน',
349
354
  removePageConfirm: 'คุณแน่ใจหรือไม่ว่าต้องการลบหน้านี้? การกระทำนี้ไม่สามารถย้อนกลับได้',
350
- hexColorPrompt: 'กรุณาใส่รหัสสีแบบฐานสิบหกที่ถูกต้อง',
355
+ 'validation.hexColor': 'กรุณาใส่รหัสสีแบบฐานสิบหกที่ถูกต้อง',
356
+ 'validation.uniqueName': 'กรุณาระบุชื่อที่ไม่ซ้ำ',
351
357
  'schemas.color': 'สี',
352
358
  'schemas.borderWidth': 'ความกว้างของเส้นขอบ',
353
359
  'schemas.borderColor': 'สีขอบ',
@@ -413,7 +419,8 @@ const dictIt: { [key in keyof Dict]: string } = {
413
419
  removePage: 'Rimuovi la Pagina Corrente',
414
420
  removePageConfirm:
415
421
  'Sei sicuro di voler eliminare questa pagina? Questa azione non può essere annullata.',
416
- hexColorPrompt: 'Inserisci un codice colore esadecimale valido.',
422
+ 'validation.hexColor': 'Inserisci un codice colore esadecimale valido.',
423
+ 'validation.uniqueName': 'Inserisci un nome univoco.',
417
424
  'schemas.color': 'Colore',
418
425
  'schemas.borderWidth': 'Spessore bordo',
419
426
  'schemas.borderColor': 'Colore bordo',
@@ -477,7 +484,8 @@ const dictPl: { [key in keyof Dict]: string } = {
477
484
  addPageAfter: 'Dodaj stronę po',
478
485
  removePage: 'Usuń Bieżącą Stronę',
479
486
  removePageConfirm: 'Czy na pewno chcesz usunąć tę stronę? Tej operacji nie można cofnąć.',
480
- hexColorPrompt: 'Wprowadź poprawny kod koloru szesnastkowego.',
487
+ 'validation.hexColor': 'Wprowadź poprawny kod koloru szesnastkowego.',
488
+ 'validation.uniqueName': 'Proszę wpisać unikalną nazwę.',
481
489
  'schemas.color': 'Kolor',
482
490
  'schemas.borderWidth': 'Szerokość obramowania',
483
491
  'schemas.borderColor': 'Kolor obramowania',
@@ -543,7 +551,8 @@ const dictDe: { [key in keyof Dict]: string } = {
543
551
  removePage: 'Aktuelle Seite entfernen',
544
552
  removePageConfirm:
545
553
  'Sind Sie sicher, dass Sie diese Seite löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden.',
546
- hexColorPrompt: 'Bitte geben Sie einen gültigen Hex-Farbcode ein.',
554
+ 'validation.hexColor': 'Bitte geben Sie einen gültigen Hex-Farbcode ein.',
555
+ 'validation.uniqueName': 'Bitte geben Sie einen eindeutigen Namen ein.',
547
556
  'schemas.color': 'Farbe',
548
557
  'schemas.borderWidth': 'Rahmenbreite',
549
558
  'schemas.borderColor': 'Rahmenfarbe',
@@ -609,7 +618,8 @@ const dictEs: { [key in keyof Dict]: string } = {
609
618
  removePage: 'Eliminar página actual',
610
619
  removePageConfirm:
611
620
  '¿Estás seguro de que quieres eliminar esta página? Esta acción no se puede deshacer.',
612
- hexColorPrompt: 'Introduce un código de color hexadecimal válido.',
621
+ 'validation.hexColor': 'Introduce un código de color hexadecimal válido.',
622
+ 'validation.uniqueName': 'Por favor, introduzca un nombre único.',
613
623
  'schemas.color': 'Color',
614
624
  'schemas.borderWidth': 'Ancho del borde',
615
625
  'schemas.borderColor': 'Color del borde',
@@ -673,7 +683,8 @@ const dictFr: { [key in keyof Dict]: string } = {
673
683
  addPageAfter: 'Ajouter une page après',
674
684
  removePage: 'Supprimer la page actuelle',
675
685
  removePageConfirm: 'Êtes-vous sûr de vouloir supprimer cette page ? Cette action est irréversible.',
676
- hexColorPrompt: 'Veuillez entrer un code couleur hexadécimal valide.',
686
+ 'validation.hexColor': 'Veuillez entrer un code couleur hexadécimal valide.',
687
+ 'validation.uniqueName': 'Veuillez saisir un nom unique.',
677
688
  'schemas.color': 'Couleur',
678
689
  'schemas.borderWidth': 'Largeur de la bordure',
679
690
  'schemas.borderColor': 'Couleur de la bordure',