@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.
@@ -1,45 +1,55 @@
1
1
  import { z } from 'zod';
2
2
  import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
3
- import type { ThemeConfig } from 'antd';
4
- import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render';
5
- import {
6
- Lang,
7
- Dict,
8
- Mode,
9
- Size,
10
- Schema,
11
- Font,
12
- SchemaForUI,
13
- BasePdf,
14
- BlankPdf,
15
- CustomPdf,
16
- CommonOptions,
17
- Template,
18
- GeneratorOptions,
19
- GenerateProps,
20
- UIOptions,
21
- UIProps,
22
- PreviewProps,
23
- DesignerProps,
24
- ColorType,
25
- LegacySchemaPageArray,
26
- SchemaPageArray,
27
- } from './schema.js';
28
-
29
- export type PropPanelSchema = _PropPanelSchema;
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
- key: string;
32
- value: unknown;
33
- schemaId: string;
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
- colorPrimary: string;
39
- colorPrimaryBg: string;
40
- colorWhite: string;
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
- value: string;
57
- schema: T;
58
- basePdf: BasePdf;
59
- pdfLib: typeof import('@pdfme/pdf-lib');
60
- pdfDoc: PDFDocument;
61
- page: PDFPage;
62
- options: GeneratorOptions;
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
- schema: T;
88
- basePdf: BasePdf;
89
- mode: Mode;
90
- tabIndex?: number;
91
- placeholder?: string;
92
- stopEditing?: () => void;
93
- value: string;
94
- onChange?: (arg: { key: string; value: unknown } | { key: string; value: unknown }[]) => void;
95
- rootElement: HTMLDivElement;
96
- options: UIOptions;
97
- theme: UITheme;
98
- i18n: (key: string) => string;
99
- scale: number;
100
- _cache: Map<string | number, unknown>;
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
- rootElement: HTMLDivElement;
118
- activeSchema: SchemaForUI;
119
- activeElements: HTMLElement[];
120
- changeSchemas: ChangeSchemas;
121
- schemas: SchemaForUI[];
122
- options: UIOptions;
123
- theme: UITheme;
124
- i18n: (key: string) => string;
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
- schema:
138
- | ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>)
139
- | Record<string, PropPanelSchema>;
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
- pdf(arg: PDFRenderProps<T & Schema>): Promise<void> | void;
158
- ui(arg: UIRenderProps<T & Schema>): Promise<void> | void;
159
- propPanel: PropPanel<T & Schema>;
160
- icon?: string;
161
- uninterruptedEditMode?: boolean;
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
- export type Plugins = { [key: string]: Plugin };
165
-
177
+ export type Plugins = {
178
+ [key: string]: Plugin;
179
+ };
166
180
  export interface PluginRegistry {
167
- plugins: { [key: string]: Plugin };
168
- exists(): boolean;
169
- values(): Plugin[];
170
- entries(): [string, Plugin][];
171
- findByType(type: string): Plugin | undefined;
172
- findWithLabelByType(type: string): [string, Plugin | undefined];
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'> & { plugins?: Plugins };
198
- export type UIOptions = z.infer<typeof UIOptions> & { theme?: ThemeConfig };
199
- export type UIProps = Omit<z.infer<typeof UIProps>, 'plugins'> & { plugins?: Plugins };
200
- export type PreviewProps = Omit<z.infer<typeof PreviewProps>, 'plugins'> & { plugins?: Plugins };
201
- export type DesignerProps = Omit<z.infer<typeof DesignerProps>, 'plugins'> & { plugins?: Plugins };
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",
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
- }