@pdfme/common 6.0.3 → 6.0.5-dev.1
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/constants.d.ts +20 -0
- package/dist/dynamicTemplate.d.ts +27 -0
- package/dist/expression.d.ts +6 -0
- package/dist/helper.d.ts +36 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +950 -0
- package/dist/index.js.map +1 -0
- package/dist/pluginRegistry.d.ts +5 -0
- package/dist/schema.d.ts +820 -0
- package/{src/types.ts → dist/types.d.ts} +124 -99
- package/dist/version.d.ts +1 -0
- package/package.json +5 -5
- package/set-version.js +0 -36
- package/src/constants.ts +0 -30
- package/src/dynamicTemplate.ts +0 -321
- package/src/expression.ts +0 -469
- package/src/helper.ts +0 -347
- package/src/index.ts +0 -138
- package/src/pluginRegistry.ts +0 -30
- package/src/schema.ts +0 -223
- package/src/version.ts +0 -1
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -16
- package/vite.config.mts +0 -33
|
@@ -1,45 +1,55 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, BlankPdf, CustomPdf, CommonOptions, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType, LegacySchemaPageArray, SchemaPageArray } from './schema.js';
|
|
4
|
+
export interface UIOptionsThemeToken {
|
|
5
|
+
colorPrimary?: string;
|
|
6
|
+
colorPrimaryBg?: string;
|
|
7
|
+
colorWhite?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface UIOptionsTheme {
|
|
11
|
+
token?: UIOptionsThemeToken;
|
|
12
|
+
components?: Record<string, Record<string, unknown>>;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface PropPanelRule {
|
|
16
|
+
validator?: (...args: any[]) => unknown;
|
|
17
|
+
message?: string;
|
|
18
|
+
pattern?: RegExp | string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface PropPanelSchema {
|
|
22
|
+
title?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
widget?: string;
|
|
25
|
+
default?: unknown;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
format?: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
hidden?: boolean | string;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
bind?: string | false | string[];
|
|
32
|
+
span?: number;
|
|
33
|
+
column?: number;
|
|
34
|
+
min?: number;
|
|
35
|
+
max?: number;
|
|
36
|
+
props?: Record<string, unknown>;
|
|
37
|
+
rules?: PropPanelRule[];
|
|
38
|
+
properties?: Record<string, PropPanelSchema>;
|
|
39
|
+
items?: PropPanelSchema | PropPanelSchema[];
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
30
42
|
export type ChangeSchemaItem = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
key: string;
|
|
44
|
+
value: unknown;
|
|
45
|
+
schemaId: string;
|
|
34
46
|
};
|
|
35
47
|
export type ChangeSchemas = (objs: ChangeSchemaItem[]) => void;
|
|
36
|
-
|
|
37
48
|
export type UITheme = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
colorPrimary: string;
|
|
50
|
+
colorPrimaryBg: string;
|
|
51
|
+
colorWhite: string;
|
|
41
52
|
};
|
|
42
|
-
|
|
43
53
|
/**
|
|
44
54
|
* Properties used for PDF rendering.
|
|
45
55
|
* @template T Type of the extended Schema object.
|
|
@@ -53,17 +63,15 @@ export type UITheme = {
|
|
|
53
63
|
* @property {Map<string | number, unknown>} _cache Cache shared only during the execution of the generate function (useful for caching images, etc. if needed).
|
|
54
64
|
*/
|
|
55
65
|
export interface PDFRenderProps<T extends Schema> {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_cache: Map<string | number, unknown>;
|
|
66
|
+
value: string;
|
|
67
|
+
schema: T;
|
|
68
|
+
basePdf: BasePdf;
|
|
69
|
+
pdfLib: typeof import('@pdfme/pdf-lib');
|
|
70
|
+
pdfDoc: PDFDocument;
|
|
71
|
+
page: PDFPage;
|
|
72
|
+
options: GeneratorOptions;
|
|
73
|
+
_cache: Map<string | number, unknown>;
|
|
65
74
|
}
|
|
66
|
-
|
|
67
75
|
/**
|
|
68
76
|
* Type for properties used in UI rendering.
|
|
69
77
|
*
|
|
@@ -84,22 +92,27 @@ export interface PDFRenderProps<T extends Schema> {
|
|
|
84
92
|
* @property {Map<string | number, unknown>} _cache - Cache shared only during the execution of the render function (useful for caching images, etc. if needed).
|
|
85
93
|
*/
|
|
86
94
|
export type UIRenderProps<T extends Schema> = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
schema: T;
|
|
96
|
+
basePdf: BasePdf;
|
|
97
|
+
mode: Mode;
|
|
98
|
+
tabIndex?: number;
|
|
99
|
+
placeholder?: string;
|
|
100
|
+
stopEditing?: () => void;
|
|
101
|
+
value: string;
|
|
102
|
+
onChange?: (arg: {
|
|
103
|
+
key: string;
|
|
104
|
+
value: unknown;
|
|
105
|
+
} | {
|
|
106
|
+
key: string;
|
|
107
|
+
value: unknown;
|
|
108
|
+
}[]) => void;
|
|
109
|
+
rootElement: HTMLDivElement;
|
|
110
|
+
options: UIOptions;
|
|
111
|
+
theme: UITheme;
|
|
112
|
+
i18n: (key: string) => string;
|
|
113
|
+
scale: number;
|
|
114
|
+
_cache: Map<string | number, unknown>;
|
|
101
115
|
};
|
|
102
|
-
|
|
103
116
|
/**
|
|
104
117
|
* Type for properties used in configuring the property panel.
|
|
105
118
|
*
|
|
@@ -114,18 +127,23 @@ export type UIRenderProps<T extends Schema> = {
|
|
|
114
127
|
* @property {(key: keyof Dict | string) => string} i18n - Internationalization dictionary for UI labels and texts.
|
|
115
128
|
*/
|
|
116
129
|
type PropPanelProps = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
rootElement: HTMLDivElement;
|
|
131
|
+
activeSchema: SchemaForUI;
|
|
132
|
+
activeElements: HTMLElement[];
|
|
133
|
+
changeSchemas: ChangeSchemas;
|
|
134
|
+
schemas: SchemaForUI[];
|
|
135
|
+
options: UIOptions;
|
|
136
|
+
theme: UITheme;
|
|
137
|
+
i18n: (key: string) => string;
|
|
138
|
+
};
|
|
139
|
+
type PropPanelWidgetRuntimeProps = {
|
|
140
|
+
schema?: PropPanelSchema;
|
|
141
|
+
value?: unknown;
|
|
142
|
+
onChange?: (...args: any[]) => unknown;
|
|
143
|
+
error?: unknown;
|
|
144
|
+
[key: string]: unknown;
|
|
125
145
|
};
|
|
126
|
-
|
|
127
|
-
export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps;
|
|
128
|
-
|
|
146
|
+
export type PropPanelWidgetProps = PropPanelWidgetRuntimeProps & PropPanelProps;
|
|
129
147
|
/**
|
|
130
148
|
* Used for customizing the property panel.
|
|
131
149
|
* @template T - Type of the extended Schema object.
|
|
@@ -134,14 +152,10 @@ export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps;
|
|
|
134
152
|
* @property {T} defaultSchema - The default schema set when adding the schema.
|
|
135
153
|
*/
|
|
136
154
|
export interface PropPanel<T extends Schema> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
widgets?: Record<string, (props: PropPanelWidgetProps) => void>;
|
|
142
|
-
defaultSchema: T;
|
|
155
|
+
schema: ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>) | Record<string, PropPanelSchema>;
|
|
156
|
+
widgets?: Record<string, (props: PropPanelWidgetProps) => void>;
|
|
157
|
+
defaultSchema: T;
|
|
143
158
|
}
|
|
144
|
-
|
|
145
159
|
/**
|
|
146
160
|
* The Plugin interface is used for PDF and UI rendering, as well as defining the property panel.
|
|
147
161
|
* The 'pdf' is used in the generator package, 'ui' is used in the viewer, form, and designer packages, and 'propPanel' is used in the designer package.
|
|
@@ -154,31 +168,31 @@ export interface PropPanel<T extends Schema> {
|
|
|
154
168
|
* @property {boolean} [uninterruptedEditMode] When editing in the UI, should the field avoid re-rendering while in edit mode?
|
|
155
169
|
*/
|
|
156
170
|
export interface Plugin<T extends Schema = Schema> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
pdf(arg: PDFRenderProps<T & Schema>): Promise<void> | void;
|
|
172
|
+
ui(arg: UIRenderProps<T & Schema>): Promise<void> | void;
|
|
173
|
+
propPanel: PropPanel<T & Schema>;
|
|
174
|
+
icon?: string;
|
|
175
|
+
uninterruptedEditMode?: boolean;
|
|
162
176
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
export type Plugins = {
|
|
178
|
+
[key: string]: Plugin;
|
|
179
|
+
};
|
|
166
180
|
export interface PluginRegistry {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
181
|
+
plugins: {
|
|
182
|
+
[key: string]: Plugin;
|
|
183
|
+
};
|
|
184
|
+
exists(): boolean;
|
|
185
|
+
values(): Plugin[];
|
|
186
|
+
entries(): [string, Plugin][];
|
|
187
|
+
findByType(type: string): Plugin | undefined;
|
|
188
|
+
findWithLabelByType(type: string): [string, Plugin | undefined];
|
|
173
189
|
}
|
|
174
|
-
|
|
175
190
|
export type Lang = z.infer<typeof Lang>;
|
|
176
191
|
export type Dict = z.infer<typeof Dict>;
|
|
177
192
|
export type Mode = z.infer<typeof Mode>;
|
|
178
193
|
export type Size = z.infer<typeof Size>;
|
|
179
194
|
export type Schema = z.infer<typeof Schema>;
|
|
180
195
|
export type SchemaForUI = z.infer<typeof SchemaForUI>;
|
|
181
|
-
|
|
182
196
|
/**
|
|
183
197
|
* Represents the Font type definition.
|
|
184
198
|
* @property {Object} [x: string] - Object key is the font name.
|
|
@@ -194,10 +208,21 @@ export type CustomPdf = z.infer<typeof CustomPdf>;
|
|
|
194
208
|
export type Template = z.infer<typeof Template>;
|
|
195
209
|
export type CommonOptions = z.infer<typeof CommonOptions>;
|
|
196
210
|
export type GeneratorOptions = z.infer<typeof GeneratorOptions>;
|
|
197
|
-
export type GenerateProps = Omit<z.infer<typeof GenerateProps>, 'plugins'> & {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export type
|
|
201
|
-
|
|
211
|
+
export type GenerateProps = Omit<z.infer<typeof GenerateProps>, 'plugins'> & {
|
|
212
|
+
plugins?: Plugins;
|
|
213
|
+
};
|
|
214
|
+
export type UIOptions = z.infer<typeof UIOptions> & {
|
|
215
|
+
theme?: UIOptionsTheme;
|
|
216
|
+
};
|
|
217
|
+
export type UIProps = Omit<z.infer<typeof UIProps>, 'plugins'> & {
|
|
218
|
+
plugins?: Plugins;
|
|
219
|
+
};
|
|
220
|
+
export type PreviewProps = Omit<z.infer<typeof PreviewProps>, 'plugins'> & {
|
|
221
|
+
plugins?: Plugins;
|
|
222
|
+
};
|
|
223
|
+
export type DesignerProps = Omit<z.infer<typeof DesignerProps>, 'plugins'> & {
|
|
224
|
+
plugins?: Plugins;
|
|
225
|
+
};
|
|
202
226
|
export type SchemaPageArray = z.infer<typeof SchemaPageArray>;
|
|
203
227
|
export type LegacySchemaPageArray = z.infer<typeof LegacySchemaPageArray>;
|
|
228
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PDFME_VERSION = "6.0.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfme/common",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.5-dev.1",
|
|
4
4
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
25
29
|
"main": "./dist/index.js",
|
|
26
30
|
"module": "./dist/index.js",
|
|
27
31
|
"types": "./dist/index.d.ts",
|
|
@@ -51,9 +55,5 @@
|
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
57
|
"@types/estree": "^1.0.6"
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"antd": "^5.11.2 || ^6.0.0",
|
|
57
|
-
"form-render": "^2.2.20"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/set-version.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { execSync } from 'node:child_process';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
|
|
8
|
-
const updateVersion = (version) => {
|
|
9
|
-
const filePath = path.join(__dirname, 'src/version.ts');
|
|
10
|
-
let content = '';
|
|
11
|
-
|
|
12
|
-
if (!fs.existsSync(filePath)) {
|
|
13
|
-
content = `export const PDFME_VERSION = '${version}';\n`;
|
|
14
|
-
} else {
|
|
15
|
-
content = fs.readFileSync(filePath, 'utf8');
|
|
16
|
-
const versionRegex = /export const PDFME_VERSION = '.*';/;
|
|
17
|
-
if (versionRegex.test(content)) {
|
|
18
|
-
content = content.replace(versionRegex, `export const PDFME_VERSION = '${version}';`);
|
|
19
|
-
} else {
|
|
20
|
-
content += `\nexport const PDFME_VERSION = '${version}';\n`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
25
|
-
console.log(`Replaced PDFME_VERSION with '${version}' in ${filePath}`);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const gitTag = execSync('git describe --tags $(git rev-list --tags --max-count=1)', {
|
|
30
|
-
encoding: 'utf8',
|
|
31
|
-
}).trim();
|
|
32
|
-
updateVersion(gitTag);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error('Error replacing PDFME_VERSION:', error);
|
|
35
|
-
updateVersion('x.x.x');
|
|
36
|
-
}
|