@pdfme/ui 4.1.0-dev.6 → 4.1.1-dev.2
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.es.js +138 -86
- package/dist/index.umd.js +6 -6
- package/dist/types/contexts.d.ts +4 -1
- package/package.json +1 -1
- package/src/components/Designer/RightSidebar/DetailView/index.tsx +26 -8
- package/src/components/Renderer.tsx +37 -14
- package/src/i18n.ts +34 -1
package/dist/types/contexts.d.ts
CHANGED
@@ -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" | "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.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" | "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?: {
|
4
4
|
cancel: string;
|
5
5
|
field: string;
|
6
6
|
fieldName: string;
|
@@ -51,6 +51,9 @@ export declare const I18nContext: import("react").Context<(key: "type" | "width"
|
|
51
51
|
'schemas.text.fit': string;
|
52
52
|
'schemas.text.dynamicFontSize': string;
|
53
53
|
'schemas.text.format': string;
|
54
|
+
'schemas.mvt.typingInstructions': string;
|
55
|
+
'schemas.mvt.sampleField': string;
|
56
|
+
'schemas.mvt.variablesSampleData': string;
|
54
57
|
'schemas.barcodes.barColor': string;
|
55
58
|
'schemas.barcodes.includetext': string;
|
56
59
|
'schemas.table.alternateBackgroundColor': string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import FormRender, { useForm } from 'form-render';
|
2
2
|
import React, { useContext, useEffect, useState } from 'react';
|
3
|
-
import type { Dict, SchemaForUI, PropPanelWidgetProps, PropPanelSchema } from '@pdfme/common';
|
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';
|
@@ -9,6 +9,7 @@ import { theme, Typography, Button, Divider } from 'antd';
|
|
9
9
|
import AlignWidget from './AlignWidget';
|
10
10
|
import WidgetRenderer from './WidgetRenderer';
|
11
11
|
import ButtonGroupWidget from './ButtonGroupWidget';
|
12
|
+
import { InternalNamePath, ValidateErrorEntity } from "rc-field-form/es/interface";
|
12
13
|
|
13
14
|
const { Text } = Typography;
|
14
15
|
|
@@ -75,22 +76,39 @@ const DetailView = (
|
|
75
76
|
}, [form, activeSchema]);
|
76
77
|
|
77
78
|
const handleWatch = (newSchema: any) => {
|
78
|
-
|
79
|
+
let changes: ChangeSchemaItem[] = [];
|
79
80
|
for (let key in newSchema) {
|
80
81
|
if (['id', 'content'].includes(key)) continue;
|
82
|
+
|
83
|
+
// [position] Return the flattened position to its original form.
|
84
|
+
if (key === 'x') key = 'position.x';
|
85
|
+
if (key === 'y') key = 'position.y';
|
86
|
+
|
81
87
|
if (newSchema[key] !== (activeSchema as any)[key]) {
|
82
88
|
let value = newSchema[key];
|
83
89
|
// FIXME memo: https://github.com/pdfme/pdfme/pull/367#issuecomment-1857468274
|
84
90
|
if (value === null && ['rotate', 'opacity'].includes(key)) value = undefined;
|
85
91
|
|
86
|
-
// [position] Return the flattened position to its original form.
|
87
|
-
if (key === 'x') key = 'position.x';
|
88
|
-
if (key === 'y') key = 'position.y';
|
89
92
|
changes.push({ key, value, schemaId: activeSchema.id });
|
90
93
|
}
|
91
94
|
}
|
95
|
+
|
92
96
|
if (changes.length) {
|
93
|
-
|
97
|
+
// Only commit these schema changes if they have passed form validation
|
98
|
+
form.validateFields()
|
99
|
+
.then(() => changeSchemas(changes))
|
100
|
+
.catch((reason: ValidateErrorEntity) => {
|
101
|
+
if (reason.errorFields.length) {
|
102
|
+
changes = changes.filter((change: ChangeSchemaItem) => !reason.errorFields.find((field: {
|
103
|
+
name: InternalNamePath;
|
104
|
+
errors: string[];
|
105
|
+
}) => field.name.includes(change.key)
|
106
|
+
));
|
107
|
+
}
|
108
|
+
if (changes.length) {
|
109
|
+
changeSchemas(changes);
|
110
|
+
}
|
111
|
+
});
|
94
112
|
}
|
95
113
|
};
|
96
114
|
|
@@ -120,9 +138,9 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
120
138
|
widget: 'select',
|
121
139
|
props: { options: typeOptions },
|
122
140
|
required: true,
|
123
|
-
span:
|
141
|
+
span: 12,
|
124
142
|
},
|
125
|
-
key: { title: i18n('fieldName'), type: 'string', required: true, span:
|
143
|
+
key: { title: i18n('fieldName'), type: 'string', required: true, span: 12 },
|
126
144
|
'-': { type: 'void', widget: 'Divider' },
|
127
145
|
align: { title: i18n('align'), type: 'void', widget: 'AlignWidget' },
|
128
146
|
x: { title: 'X', type: 'number', widget: 'inputNumber', required: true, span: 8, min: 0 },
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import React, { useEffect, useContext, ReactNode, useRef } from 'react';
|
2
|
-
import {
|
1
|
+
import React, { useEffect, useMemo, useContext, ReactNode, useRef } from 'react';
|
2
|
+
import {Dict, Mode, ZOOM, UIRenderProps, SchemaForUI, BasePdf, Schema, Plugin, UIOptions} from '@pdfme/common';
|
3
3
|
import { theme as antdTheme } from 'antd';
|
4
4
|
import { SELECTABLE_CLASSNAME } from '../constants';
|
5
5
|
import { PluginsRegistry, OptionsContext, I18nContext } from '../contexts';
|
@@ -17,6 +17,27 @@ type RendererProps = Omit<
|
|
17
17
|
scale: number;
|
18
18
|
};
|
19
19
|
|
20
|
+
type ReRenderCheckProps = {
|
21
|
+
plugin: Plugin<any>,
|
22
|
+
value: string,
|
23
|
+
mode: Mode,
|
24
|
+
scale: number,
|
25
|
+
schema: SchemaForUI,
|
26
|
+
options: UIOptions,
|
27
|
+
}
|
28
|
+
|
29
|
+
const useRerenderDependencies = ({ plugin, value, mode, scale, schema, options }: ReRenderCheckProps) => {
|
30
|
+
const dependencies = useMemo(() => {
|
31
|
+
if (plugin.uninterruptedEditMode && mode === 'designer') {
|
32
|
+
return [mode];
|
33
|
+
} else {
|
34
|
+
return [value, mode, scale, JSON.stringify(schema), JSON.stringify(options)];
|
35
|
+
}
|
36
|
+
}, [value, mode, scale, schema, options]);
|
37
|
+
|
38
|
+
return dependencies;
|
39
|
+
};
|
40
|
+
|
20
41
|
const Wrapper = ({
|
21
42
|
children,
|
22
43
|
outline,
|
@@ -56,20 +77,22 @@ const Renderer = (props: RendererProps) => {
|
|
56
77
|
|
57
78
|
const ref = useRef<HTMLDivElement>(null);
|
58
79
|
const _cache = useRef<Map<any, any>>(new Map());
|
80
|
+
const plugin = Object.values(pluginsRegistry).find(
|
81
|
+
(plugin) => plugin?.propPanel.defaultSchema.type === schema.type
|
82
|
+
) as Plugin<any>;
|
59
83
|
|
60
|
-
|
61
|
-
|
62
|
-
const render = Object.values(pluginsRegistry).find(
|
63
|
-
(plugin) => plugin?.propPanel.defaultSchema.type === schema.type
|
64
|
-
)?.ui;
|
65
|
-
|
66
|
-
if (!render) {
|
67
|
-
console.error(`[@pdfme/ui] Renderer for type ${schema.type} not found.
|
84
|
+
if (!plugin || !plugin.ui) {
|
85
|
+
console.error(`[@pdfme/ui] Renderer for type ${schema.type} not found.
|
68
86
|
Check this document: https://pdfme.com/docs/custom-schemas`);
|
69
|
-
|
70
|
-
|
87
|
+
return <></>;
|
88
|
+
}
|
71
89
|
|
90
|
+
const reRenderDependencies = useRerenderDependencies({plugin, value, mode, scale, schema, options});
|
91
|
+
|
92
|
+
useEffect(() => {
|
93
|
+
if (ref.current && schema.type) {
|
72
94
|
ref.current.innerHTML = '';
|
95
|
+
const render = plugin.ui;
|
73
96
|
|
74
97
|
void render({
|
75
98
|
key: schema.key,
|
@@ -79,7 +102,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
79
102
|
rootElement: ref.current,
|
80
103
|
mode,
|
81
104
|
onChange,
|
82
|
-
stopEditing
|
105
|
+
stopEditing,
|
83
106
|
tabIndex,
|
84
107
|
placeholder,
|
85
108
|
options,
|
@@ -94,7 +117,7 @@ Check this document: https://pdfme.com/docs/custom-schemas`);
|
|
94
117
|
ref.current.innerHTML = '';
|
95
118
|
}
|
96
119
|
};
|
97
|
-
},
|
120
|
+
}, reRenderDependencies);
|
98
121
|
|
99
122
|
return (
|
100
123
|
<Wrapper {...props}>
|
package/src/i18n.ts
CHANGED
@@ -53,6 +53,9 @@ const dictEn: { [key in keyof Dict]: string } = {
|
|
53
53
|
'schemas.text.fit': 'Fit',
|
54
54
|
'schemas.text.dynamicFontSize': 'Dynamic Font Size',
|
55
55
|
'schemas.text.format': 'Format',
|
56
|
+
'schemas.mvt.typingInstructions': 'Add variables by typing words surrounded by curly brackets, e.g.',
|
57
|
+
'schemas.mvt.sampleField': 'name',
|
58
|
+
'schemas.mvt.variablesSampleData': 'Variables Sample Data',
|
56
59
|
'schemas.barcodes.barColor': 'Bar Color',
|
57
60
|
'schemas.barcodes.includetext': 'Include Text',
|
58
61
|
'schemas.table.alternateBackgroundColor': 'Alternate Background Color',
|
@@ -113,6 +116,9 @@ const dictZh: { [key in keyof Dict]: string } = {
|
|
113
116
|
'schemas.text.fit': '适应',
|
114
117
|
'schemas.text.dynamicFontSize': '动态字体大小',
|
115
118
|
'schemas.text.format': '格式',
|
119
|
+
'schemas.mvt.typingInstructions': '通过输入用花括号括起来的单词来添加变量,例如',
|
120
|
+
'schemas.mvt.sampleField': '姓名',
|
121
|
+
'schemas.mvt.variablesSampleData': '变量样本数据',
|
116
122
|
'schemas.barcodes.barColor': '条码颜色',
|
117
123
|
'schemas.barcodes.includetext': '包括文本',
|
118
124
|
'schemas.table.alternateBackgroundColor': '交替背景颜色',
|
@@ -173,6 +179,9 @@ const dictJa: { [key in keyof Dict]: string } = {
|
|
173
179
|
'schemas.text.fit': 'フィット',
|
174
180
|
'schemas.text.dynamicFontSize': '動的フォントサイズ',
|
175
181
|
'schemas.text.format': '書式',
|
182
|
+
'schemas.mvt.typingInstructions': '中括弧で囲まれた単語を入力して変数を追加します。例:',
|
183
|
+
'schemas.mvt.sampleField': '名前',
|
184
|
+
'schemas.mvt.variablesSampleData': '変数サンプルデータ',
|
176
185
|
'schemas.barcodes.barColor': 'バーの色',
|
177
186
|
'schemas.barcodes.includetext': 'テキストを含める',
|
178
187
|
'schemas.table.alternateBackgroundColor': '交互の背景色',
|
@@ -233,6 +242,9 @@ const dictKo: { [key in keyof Dict]: string } = {
|
|
233
242
|
'schemas.text.fit': '맞춤',
|
234
243
|
'schemas.text.dynamicFontSize': '동적 폰트 크기',
|
235
244
|
'schemas.text.format': '형식',
|
245
|
+
'schemas.mvt.typingInstructions': '중괄호로 묶인 단어를 입력하여 변수를 추가하세요.',
|
246
|
+
'schemas.mvt.sampleField': '이름',
|
247
|
+
'schemas.mvt.variablesSampleData': '변수 샘플 데이터',
|
236
248
|
'schemas.barcodes.barColor': '바코드 색상',
|
237
249
|
'schemas.barcodes.includetext': '텍스트 포함',
|
238
250
|
'schemas.table.alternateBackgroundColor': '대체 배경색',
|
@@ -293,6 +305,9 @@ const dictAr: { [key in keyof Dict]: string } = {
|
|
293
305
|
'schemas.text.fit': 'ملاءمة',
|
294
306
|
'schemas.text.dynamicFontSize': 'حجم الخط الديناميكي',
|
295
307
|
'schemas.text.format': 'تنسيق',
|
308
|
+
'schemas.mvt.typingInstructions': 'قم بإضافة المتغيرات عن طريق كتابة الكلمات المحاطة بأقواس متعرجة، على سبيل المثال:',
|
309
|
+
'schemas.mvt.sampleField': 'اسم',
|
310
|
+
'schemas.mvt.variablesSampleData': 'بيانات عينة المتغيرات',
|
296
311
|
'schemas.barcodes.barColor': 'لون الشريط',
|
297
312
|
'schemas.barcodes.includetext': 'تضمين النص',
|
298
313
|
'schemas.table.alternateBackgroundColor': 'لون الخلفية البديل',
|
@@ -353,6 +368,9 @@ const dictTh: { [key in keyof Dict]: string } = {
|
|
353
368
|
'schemas.text.fit': 'พอดี',
|
354
369
|
'schemas.text.dynamicFontSize': 'ขนาดตัวอักษรแบบไดนามิก',
|
355
370
|
'schemas.text.format': 'รูปแบบ',
|
371
|
+
'schemas.mvt.typingInstructions': 'เพิ่มตัวแปรโดยพิมพ์คำที่ล้อมรอบด้วยวงเล็บปีกกา เช่น',
|
372
|
+
'schemas.mvt.sampleField': 'ชื่อ',
|
373
|
+
'schemas.mvt.variablesSampleData': 'ข้อมูลตัวอย่างตัวแปร',
|
356
374
|
'schemas.barcodes.barColor': 'สีบาร์',
|
357
375
|
'schemas.barcodes.includetext': 'รวมข้อความ',
|
358
376
|
'schemas.table.alternateBackgroundColor': 'สีพื้นหลังสลับกัน',
|
@@ -415,6 +433,9 @@ const dictIt: { [key in keyof Dict]: string } = {
|
|
415
433
|
'schemas.text.fit': 'Adatta',
|
416
434
|
'schemas.text.dynamicFontSize': 'Dimensione font dinamica',
|
417
435
|
'schemas.text.format': 'Formato',
|
436
|
+
'schemas.mvt.typingInstructions': 'Aggiungi variabili digitando parole circondate da parentesi graffe, ad es.',
|
437
|
+
'schemas.mvt.sampleField': 'nome',
|
438
|
+
'schemas.mvt.variablesSampleData': 'Dati di esempio variabili',
|
418
439
|
'schemas.barcodes.barColor': 'Colore barra',
|
419
440
|
'schemas.barcodes.includetext': 'Includi testo',
|
420
441
|
'schemas.table.alternateBackgroundColor': 'Colore di Sfondo Alternato',
|
@@ -475,6 +496,9 @@ const dictPl: { [key in keyof Dict]: string } = {
|
|
475
496
|
'schemas.text.fit': 'Dopasowanie',
|
476
497
|
'schemas.text.dynamicFontSize': 'Dynamiczny rozmiar czcionki',
|
477
498
|
'schemas.text.format': 'Format',
|
499
|
+
'schemas.mvt.typingInstructions': 'Dodaj zmienne, wpisując słowa ujęte w nawiasy klamrowe, np.',
|
500
|
+
'schemas.mvt.sampleField': 'nazwa',
|
501
|
+
'schemas.mvt.variablesSampleData': 'Zmienne Przykładowe dane',
|
478
502
|
'schemas.barcodes.barColor': 'Kolor paska',
|
479
503
|
'schemas.barcodes.includetext': 'Dołącz tekst',
|
480
504
|
'schemas.table.alternateBackgroundColor': 'Alternatywny kolor tła',
|
@@ -537,6 +561,9 @@ const dictDe: { [key in keyof Dict]: string } = {
|
|
537
561
|
'schemas.text.fit': 'Anpassen',
|
538
562
|
'schemas.text.dynamicFontSize': 'Dynamische Schriftgröße',
|
539
563
|
'schemas.text.format': 'Format',
|
564
|
+
'schemas.mvt.typingInstructions': 'Fügen Sie Variablen hinzu, indem Sie Wörter in geschweiften Klammern eingeben, z. B.',
|
565
|
+
'schemas.mvt.sampleField': 'Name',
|
566
|
+
'schemas.mvt.variablesSampleData': 'Variablen Beispieldaten',
|
540
567
|
'schemas.barcodes.barColor': 'Strichcodefarbe',
|
541
568
|
'schemas.barcodes.includetext': 'Text anzeigen',
|
542
569
|
'schemas.table.alternateBackgroundColor': 'Wechselnde Hintergrundfarbe',
|
@@ -599,6 +626,9 @@ const dictEs: { [key in keyof Dict]: string } = {
|
|
599
626
|
'schemas.text.fit': 'Ajustar',
|
600
627
|
'schemas.text.dynamicFontSize': 'Tamaño de fuente dinámico',
|
601
628
|
'schemas.text.format': 'Formato',
|
629
|
+
'schemas.mvt.typingInstructions': 'Agregue variables escribiendo palabras entre llaves, p.',
|
630
|
+
'schemas.mvt.sampleField': 'nombre',
|
631
|
+
'schemas.mvt.variablesSampleData': 'Variables Datos de muestra',
|
602
632
|
'schemas.barcodes.barColor': 'Color de la barra',
|
603
633
|
'schemas.barcodes.includetext': 'Incluir texto',
|
604
634
|
'schemas.table.alternateBackgroundColor': 'Color de fondo alternativo',
|
@@ -625,7 +655,7 @@ const dictFr: { [key in keyof Dict]: string } = {
|
|
625
655
|
fieldsList: 'Liste des champs',
|
626
656
|
editField: 'Éditer le champ',
|
627
657
|
type: 'Type',
|
628
|
-
errorOccurred:'Une erreur est survenue',
|
658
|
+
errorOccurred: 'Une erreur est survenue',
|
629
659
|
errorBulkUpdateFieldName: "Impossible de confirmer le changement car le nombre d'éléments a changé.",
|
630
660
|
commitBulkUpdateFieldName: 'Confirmer les changements',
|
631
661
|
bulkUpdateFieldName: 'Modifier les noms de champs en masse',
|
@@ -659,6 +689,9 @@ const dictFr: { [key in keyof Dict]: string } = {
|
|
659
689
|
'schemas.text.fit': 'Ajustement',
|
660
690
|
'schemas.text.dynamicFontSize': 'Taille de police dynamique',
|
661
691
|
'schemas.text.format': 'Format',
|
692
|
+
'schemas.mvt.typingInstructions': 'Ajoutez des variables en tapant des mots entourés d\'accolades, par ex.',
|
693
|
+
'schemas.mvt.sampleField': 'nom',
|
694
|
+
'schemas.mvt.variablesSampleData': 'Variables Exemples de données',
|
662
695
|
'schemas.barcodes.barColor': 'Couleur de la barre',
|
663
696
|
'schemas.barcodes.includetext': 'Inclure le texte',
|
664
697
|
'schemas.table.alternateBackgroundColor': 'Couleur de fond alternative',
|