@pdfme/common 5.3.17 → 5.3.18-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/cjs/__tests__/helper.test.js +146 -0
- package/dist/cjs/__tests__/helper.test.js.map +1 -1
- package/dist/cjs/__tests__/pluginRegistry.test.js +83 -0
- package/dist/cjs/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/cjs/src/helper.js +5 -3
- package/dist/cjs/src/helper.js.map +1 -1
- package/dist/cjs/src/index.js +3 -1
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/pluginRegistry.js +33 -0
- package/dist/cjs/src/pluginRegistry.js.map +1 -0
- package/dist/cjs/src/schema.js +14 -2
- package/dist/cjs/src/schema.js.map +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/esm/__tests__/helper.test.js +147 -1
- package/dist/esm/__tests__/helper.test.js.map +1 -1
- package/dist/esm/__tests__/pluginRegistry.test.js +81 -0
- package/dist/esm/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/esm/src/helper.js +5 -3
- package/dist/esm/src/helper.js.map +1 -1
- package/dist/esm/src/index.js +2 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/pluginRegistry.js +29 -0
- package/dist/esm/src/pluginRegistry.js.map +1 -0
- package/dist/esm/src/schema.js +13 -1
- package/dist/esm/src/schema.js.map +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/node/__tests__/helper.test.js +146 -0
- package/dist/node/__tests__/helper.test.js.map +1 -1
- package/dist/node/__tests__/pluginRegistry.test.js +83 -0
- package/dist/node/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/node/src/helper.js +5 -3
- package/dist/node/src/helper.js.map +1 -1
- package/dist/node/src/index.js +3 -1
- package/dist/node/src/index.js.map +1 -1
- package/dist/node/src/pluginRegistry.js +33 -0
- package/dist/node/src/pluginRegistry.js.map +1 -0
- package/dist/node/src/schema.js +14 -2
- package/dist/node/src/schema.js.map +1 -1
- package/dist/node/src/version.js +1 -1
- package/dist/types/__tests__/pluginRegistry.test.d.ts +1 -0
- package/dist/types/src/index.d.ts +4 -3
- package/dist/types/src/pluginRegistry.d.ts +5 -0
- package/dist/types/src/schema.d.ts +3569 -152
- package/dist/types/src/types.d.ts +11 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/helper.ts +4 -4
- package/src/index.ts +5 -1
- package/src/pluginRegistry.ts +32 -0
- package/src/schema.ts +14 -1
- package/src/types.ts +10 -1
- package/src/version.ts +1 -1
@@ -126,8 +126,18 @@ export type Plugin<T = Schema> = {
|
|
126
126
|
uninterruptedEditMode?: boolean;
|
127
127
|
};
|
128
128
|
export type Plugins = {
|
129
|
-
[key: string]: Plugin<any
|
129
|
+
[key: string]: Plugin<any>;
|
130
130
|
};
|
131
|
+
export interface PluginRegistry {
|
132
|
+
plugins: {
|
133
|
+
[key: string]: Plugin;
|
134
|
+
};
|
135
|
+
exists(): boolean;
|
136
|
+
values(): Plugin[];
|
137
|
+
entries(): [string, Plugin][];
|
138
|
+
findByType(type: string): Plugin | undefined;
|
139
|
+
findWithLabelByType(type: string): [string, Plugin | undefined];
|
140
|
+
}
|
131
141
|
export type Lang = z.infer<typeof Lang>;
|
132
142
|
export type Dict = z.infer<typeof Dict>;
|
133
143
|
export type Mode = z.infer<typeof Mode>;
|
@@ -1 +1 @@
|
|
1
|
-
export declare const PDFME_VERSION = "5.3.
|
1
|
+
export declare const PDFME_VERSION = "5.3.18";
|
package/package.json
CHANGED
package/src/helper.ts
CHANGED
@@ -235,15 +235,15 @@ const checkProps = <T>(data: unknown, zodSchema: z.ZodType<T>) => {
|
|
235
235
|
ERROR MESSAGE: ${issue.message}
|
236
236
|
--------------------------`,
|
237
237
|
);
|
238
|
-
|
239
|
-
const message = messages.join('\n');
|
240
238
|
throw Error(`[@pdfme/common] Invalid argument:
|
241
239
|
--------------------------
|
242
|
-
${
|
240
|
+
${messages.join('\n')}`);
|
241
|
+
} else {
|
242
|
+
throw Error(`[@pdfme/common] Unexpected parsing error: ${e instanceof Error ? e.message : String(e)}`);
|
243
243
|
}
|
244
244
|
}
|
245
245
|
|
246
|
-
// Check
|
246
|
+
// Check fonts if template and options exist
|
247
247
|
if (data && typeof data === 'object' && 'template' in data && 'options' in data) {
|
248
248
|
const { template, options } = data as { template: Template; options: { font?: Font } };
|
249
249
|
if (options && options.font) {
|
package/src/index.ts
CHANGED
@@ -34,6 +34,7 @@ import type {
|
|
34
34
|
CommonOptions,
|
35
35
|
GeneratorOptions,
|
36
36
|
Plugins,
|
37
|
+
PluginRegistry,
|
37
38
|
GenerateProps,
|
38
39
|
UIOptions,
|
39
40
|
UIProps,
|
@@ -64,6 +65,7 @@ import {
|
|
64
65
|
} from './helper.js';
|
65
66
|
import { getDynamicTemplate } from './dynamicTemplate.js';
|
66
67
|
import { replacePlaceholders } from './expression.js';
|
68
|
+
import { pluginRegistry } from './pluginRegistry.js';
|
67
69
|
|
68
70
|
export {
|
69
71
|
PDFME_VERSION,
|
@@ -97,6 +99,7 @@ export {
|
|
97
99
|
checkPreviewProps,
|
98
100
|
checkDesignerProps,
|
99
101
|
checkGenerateProps,
|
102
|
+
pluginRegistry,
|
100
103
|
};
|
101
104
|
|
102
105
|
export type {
|
@@ -113,7 +116,9 @@ export type {
|
|
113
116
|
Template,
|
114
117
|
CommonOptions,
|
115
118
|
GeneratorOptions,
|
119
|
+
Plugin,
|
116
120
|
Plugins,
|
121
|
+
PluginRegistry,
|
117
122
|
GenerateProps,
|
118
123
|
UIOptions,
|
119
124
|
UIProps,
|
@@ -128,5 +133,4 @@ export type {
|
|
128
133
|
PDFRenderProps,
|
129
134
|
UIRenderProps,
|
130
135
|
Mode,
|
131
|
-
Plugin,
|
132
136
|
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Plugins, Plugin, PluginRegistry } from './types.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Wraps plugins collection with utility methods
|
5
|
+
*/
|
6
|
+
export const pluginRegistry = (plugins: Plugins): PluginRegistry => {
|
7
|
+
return {
|
8
|
+
plugins: plugins,
|
9
|
+
entries: (): [string, Plugin][] => Object.entries(plugins),
|
10
|
+
values: (): Plugin[] => Object.values(plugins),
|
11
|
+
exists: (): boolean => Object.values(plugins).length > 0,
|
12
|
+
findWithLabelByType(type: string): [string, Plugin | undefined] {
|
13
|
+
for (const [label, plugin] of Object.entries(this.plugins) as [string, Plugin][]) {
|
14
|
+
if (!plugin || typeof plugin !== 'object') continue;
|
15
|
+
if (!plugin.propPanel || typeof plugin.propPanel !== 'object') continue;
|
16
|
+
|
17
|
+
const defaultSchema = plugin.propPanel.defaultSchema as Record<string, unknown>;
|
18
|
+
|
19
|
+
if (defaultSchema && 'type' in defaultSchema && defaultSchema.type === type) {
|
20
|
+
return [label, plugin];
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return ['', undefined];
|
24
|
+
},
|
25
|
+
findByType(type: string): Plugin | undefined {
|
26
|
+
const [, plugin] = this.findWithLabelByType(type)
|
27
|
+
return plugin;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
|
package/src/schema.ts
CHANGED
@@ -152,12 +152,25 @@ export const Font = z.record(
|
|
152
152
|
}),
|
153
153
|
);
|
154
154
|
|
155
|
+
export const Plugin = z
|
156
|
+
.object({
|
157
|
+
ui: z.function().args(z.any()).returns(z.any()),
|
158
|
+
pdf: z.function().args(z.any()).returns(z.any()),
|
159
|
+
propPanel: z.object({
|
160
|
+
schema: z.unknown(),
|
161
|
+
widgets: z.record(z.any()).optional(),
|
162
|
+
defaultSchema: Schema,
|
163
|
+
}),
|
164
|
+
icon: z.string().optional(),
|
165
|
+
})
|
166
|
+
.passthrough();
|
167
|
+
|
155
168
|
export const CommonOptions = z.object({ font: Font.optional() }).passthrough();
|
156
169
|
|
157
170
|
const CommonProps = z.object({
|
158
171
|
template: Template,
|
159
172
|
options: CommonOptions.optional(),
|
160
|
-
plugins: z.record(
|
173
|
+
plugins: z.record(Plugin).optional(),
|
161
174
|
});
|
162
175
|
|
163
176
|
// -------------------generate-------------------
|
package/src/types.ts
CHANGED
@@ -154,7 +154,16 @@ export type Plugin<T = Schema> = {
|
|
154
154
|
};
|
155
155
|
|
156
156
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
157
|
-
export type Plugins = { [key: string]: Plugin<any>
|
157
|
+
export type Plugins = { [key: string]: Plugin<any> };
|
158
|
+
|
159
|
+
export interface PluginRegistry {
|
160
|
+
plugins: { [key: string]: Plugin };
|
161
|
+
exists(): boolean;
|
162
|
+
values(): Plugin[];
|
163
|
+
entries(): [string, Plugin][];
|
164
|
+
findByType(type: string): Plugin | undefined;
|
165
|
+
findWithLabelByType(type: string): [string, Plugin|undefined];
|
166
|
+
}
|
158
167
|
|
159
168
|
export type Lang = z.infer<typeof Lang>;
|
160
169
|
export type Dict = z.infer<typeof Dict>;
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const PDFME_VERSION = '5.3.
|
1
|
+
export const PDFME_VERSION = '5.3.18';
|