@pdfme/common 3.4.3 → 4.0.0-dev.3

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.
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
3
3
  import type { ThemeConfig, GlobalToken } from 'antd';
4
4
  import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render';
5
- import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType } from './schema.js';
5
+ import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, BlankPdf, CommonOptions, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType } from './schema.js';
6
6
  export type PropPanelSchema = _PropPanelSchema;
7
7
  export type ChangeSchemas = (objs: {
8
8
  key: string;
@@ -15,6 +15,7 @@ export type ChangeSchemas = (objs: {
15
15
  * @property {string} key The key of the schema object.
16
16
  * @property {string} value The string used for PDF rendering.
17
17
  * @property {T} schema Extended Schema object for rendering.
18
+ * @property {BasePdf} basePdf Base PDF object for rendering.
18
19
  * @property {typeof import('@pdfme/pdf-lib')} pdfLib The pdf-lib library used for rendering.
19
20
  * @property {PDFDocument} pdfDoc PDFDocument object from pdf-lib.
20
21
  * @property {PDFPage} page PDFPage object from pdf-lib.
@@ -25,6 +26,7 @@ export interface PDFRenderProps<T extends Schema> {
25
26
  key: string;
26
27
  value: string;
27
28
  schema: T;
29
+ basePdf: BasePdf;
28
30
  pdfLib: typeof import('@pdfme/pdf-lib');
29
31
  pdfDoc: PDFDocument;
30
32
  page: PDFPage;
@@ -36,28 +38,37 @@ export interface PDFRenderProps<T extends Schema> {
36
38
  *
37
39
  * @template T - Type of the extended Schema object.
38
40
  * @property {T} schema - Extended Schema object for rendering.
41
+ * @property {BasePdf} basePdf Base PDF object for rendering.
39
42
  * @property {Mode} mode - String indicating the rendering state. 'designer' is only used when the field is in edit mode in the Designer.
40
43
  * @property {number} [tabIndex] - Tab index for Form.
41
44
  * @property {string} [placeholder] - Placeholder text for Form.
42
45
  * @property {() => void} [stopEditing] - Stops editing mode, can be used when the mode is 'designer'.
43
46
  * @property {string} key - The key of the schema object.
44
47
  * @property {string} value - The string used for UI rendering.
45
- * @property {(value: string) => void} [onChange] - Used to change the value. Only applicable when the mode is 'form' or 'designer'.
48
+ * @property {(arg: { key: string; value: any } | { key: string; value: any }[]) => void} [onChange] - Used to change the value and schema properties. Only applicable when the mode is 'form' or 'designer'.
46
49
  * @property {HTMLDivElement} rootElement - The root HTMLDivElement for the UI.
47
50
  * @property {UIOptions} options - Options object passed from the Viewer, Form, or Designer.
48
51
  * @property {ThemeConfig} theme - An object that merges the 'theme' passed as an options with the default theme.
49
52
  * @property {(key: keyof Dict | string) => string} i18n - An object merged based on the options 'lang' and 'labels'.
53
+ * @property {Size} pageSize - The size of the page being edited.
50
54
  * @property {Map<any, any>} _cache - Cache shared only during the execution of the render function (useful for caching images, etc. if needed).
51
55
  */
52
56
  export type UIRenderProps<T extends Schema> = {
53
57
  schema: T;
58
+ basePdf: BasePdf;
54
59
  mode: Mode;
55
60
  tabIndex?: number;
56
61
  placeholder?: string;
57
62
  stopEditing?: () => void;
58
63
  key: string;
59
64
  value: string;
60
- onChange?: (value: string) => void;
65
+ onChange?: (arg: {
66
+ key: string;
67
+ value: any;
68
+ } | {
69
+ key: string;
70
+ value: any;
71
+ }[]) => void;
61
72
  rootElement: HTMLDivElement;
62
73
  options: UIOptions;
63
74
  theme: GlobalToken;
@@ -84,7 +95,6 @@ type PropPanelProps = {
84
95
  activeElements: HTMLElement[];
85
96
  changeSchemas: ChangeSchemas;
86
97
  schemas: SchemaForUI[];
87
- pageSize: Size;
88
98
  options: UIOptions;
89
99
  theme: GlobalToken;
90
100
  i18n: (key: keyof Dict | string) => string;
@@ -95,13 +105,11 @@ export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps;
95
105
  * @template T - Type of the extended Schema object.
96
106
  * @property {Record<string, PropPanelSchema> | ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>)} schema - A function returning a form-render schema object or the schema object itself. When a function, it takes properties passed from the designer as arguments.
97
107
  * @property {Record<string, (props: PropPanelWidgetProps) => void>} [widgets] - An object of functions returning form-render widgets. The functions take, as arguments, both form-render's WidgetProps and properties passed from the designer.
98
- * @property {string} defaultValue - The default input value set when adding the schema.
99
108
  * @property {T} defaultSchema - The default schema set when adding the schema.
100
109
  */
101
110
  export interface PropPanel<T extends Schema> {
102
111
  schema: ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>) | Record<string, PropPanelSchema>;
103
112
  widgets?: Record<string, (props: PropPanelWidgetProps) => void>;
104
- defaultValue: string;
105
113
  defaultSchema: T;
106
114
  }
107
115
  /**
@@ -139,7 +147,9 @@ export type SchemaForUI = z.infer<typeof SchemaForUI>;
139
147
  export type Font = z.infer<typeof Font>;
140
148
  export type ColorType = z.infer<typeof ColorType>;
141
149
  export type BasePdf = z.infer<typeof BasePdf>;
150
+ export type BlankPdf = z.infer<typeof BlankPdf>;
142
151
  export type Template = z.infer<typeof Template>;
152
+ export type CommonOptions = z.infer<typeof CommonOptions>;
143
153
  export type GeneratorOptions = z.infer<typeof GeneratorOptions>;
144
154
  export type GenerateProps = z.infer<typeof GenerateProps> & {
145
155
  plugins?: Plugins;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/common",
3
- "version": "3.4.3",
3
+ "version": "4.0.0-dev.3",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
package/src/constants.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export const PDFME_VERSION = '4.0.0';
1
2
  export const PT_TO_PX_RATIO = 1.333;
2
3
  export const PT_TO_MM_RATIO = 0.3528;
3
4
  export const MM_TO_PT_RATIO = 2.8346; // https://www.ddc.co.jp/words/archives/20090701114500.html
package/src/helper.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { Buffer } from 'buffer';
3
- import { Schema, Template, Font, BasePdf, Plugins } from './types';
3
+ import { Schema, Template, Font, BasePdf, Plugins, BlankPdf, CommonOptions } from './types';
4
4
  import {
5
5
  Inputs as InputsSchema,
6
6
  UIOptions as UIOptionsSchema,
@@ -9,6 +9,7 @@ import {
9
9
  DesignerProps as DesignerPropsSchema,
10
10
  GenerateProps as GeneratePropsSchema,
11
11
  UIProps as UIPropsSchema,
12
+ BlankPdf as BlankPdfSchema,
12
13
  } from './schema.js';
13
14
  import {
14
15
  MM_TO_PT_RATIO,
@@ -52,6 +53,12 @@ export const pt2px = (pt: number): number => {
52
53
  return pt * PT_TO_PX_RATIO;
53
54
  };
54
55
 
56
+ export const px2mm = (px: number): number => {
57
+ // http://www.endmemo.com/sconvert/millimeterpixel.php
58
+ const ratio = 0.26458333333333;
59
+ return parseFloat(String(px)) * ratio;
60
+ };
61
+
55
62
  const blob2Base64Pdf = (blob: Blob) => {
56
63
  return new Promise<string>((resolve, reject) => {
57
64
  const reader = new FileReader();
@@ -70,6 +77,19 @@ export const isHexValid = (hex: string): boolean => {
70
77
  return /^#(?:[A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/i.test(hex);
71
78
  };
72
79
 
80
+ export const getInputFromTemplate = (template: Template): { [key: string]: string }[] => {
81
+ const input: { [key: string]: string } = {};
82
+ template.schemas.forEach((schema) => {
83
+ Object.entries(schema).forEach(([key, value]) => {
84
+ if (!value.readOnly) {
85
+ input[key] = value.content || '';
86
+ }
87
+ });
88
+ });
89
+
90
+ return [input];
91
+ };
92
+
73
93
  export const getB64BasePdf = (basePdf: BasePdf) => {
74
94
  const needFetchFromNetwork =
75
95
  typeof basePdf === 'string' && !basePdf.startsWith('data:application/pdf;');
@@ -85,6 +105,9 @@ export const getB64BasePdf = (basePdf: BasePdf) => {
85
105
  return basePdf as string;
86
106
  };
87
107
 
108
+ export const isBlankPdf = (basePdf: BasePdf): basePdf is BlankPdf =>
109
+ BlankPdfSchema.safeParse(basePdf).success;
110
+
88
111
  const getByteString = (base64: string) => Buffer.from(base64, 'base64').toString('binary');
89
112
 
90
113
  export const b64toUint8Array = (base64: string) => {
@@ -199,3 +222,118 @@ export const checkUIProps = (data: unknown) => checkProps(data, UIPropsSchema);
199
222
  export const checkPreviewProps = (data: unknown) => checkProps(data, PreviewPropsSchema);
200
223
  export const checkDesignerProps = (data: unknown) => checkProps(data, DesignerPropsSchema);
201
224
  export const checkGenerateProps = (data: unknown) => checkProps(data, GeneratePropsSchema);
225
+
226
+ interface ModifyTemplateForDynamicTableArg {
227
+ template: Template;
228
+ input: Record<string, string>;
229
+ _cache: Map<any, any>;
230
+ options: CommonOptions;
231
+ modifyTemplate: (arg: {
232
+ template: Template;
233
+ input: Record<string, string>;
234
+ _cache: Map<any, any>;
235
+ options: CommonOptions;
236
+ }) => Promise<Template>;
237
+ getDynamicHeight: (
238
+ value: string,
239
+ args: { schema: Schema; basePdf: BasePdf; options: CommonOptions; _cache: Map<any, any> }
240
+ ) => Promise<number>;
241
+ }
242
+
243
+ export const getDynamicTemplate = async (
244
+ arg: ModifyTemplateForDynamicTableArg
245
+ ): Promise<Template> => {
246
+ const { template, modifyTemplate } = arg;
247
+ if (!isBlankPdf(template.basePdf)) {
248
+ return template;
249
+ }
250
+
251
+ const modifiedTemplate = await modifyTemplate(arg);
252
+
253
+ const diffMap = await calculateDiffMap({ ...arg, template: modifiedTemplate });
254
+
255
+ return normalizePositionsAndPageBreak(modifiedTemplate, diffMap);
256
+ };
257
+
258
+ export const calculateDiffMap = async (arg: ModifyTemplateForDynamicTableArg) => {
259
+ const { template, input, _cache, options, getDynamicHeight } = arg;
260
+ const basePdf = template.basePdf;
261
+ const tmpDiffMap = new Map<number, number>();
262
+ if (!isBlankPdf(basePdf)) {
263
+ return tmpDiffMap;
264
+ }
265
+ const pageHeight = basePdf.height;
266
+ let pageIndex = 0;
267
+ for (const schemaObj of template.schemas) {
268
+ for (const [key, schema] of Object.entries(schemaObj)) {
269
+ const dynamicHeight = await getDynamicHeight(input?.[key] || '', {
270
+ schema,
271
+ basePdf,
272
+ options,
273
+ _cache,
274
+ });
275
+ if (schema.height !== dynamicHeight) {
276
+ tmpDiffMap.set(
277
+ schema.position.y + schema.height + pageHeight * pageIndex,
278
+ dynamicHeight - schema.height
279
+ );
280
+ }
281
+ }
282
+ pageIndex++;
283
+ }
284
+
285
+ const diffMap = new Map<number, number>();
286
+ const keys = Array.from(tmpDiffMap.keys()).sort((a, b) => a - b);
287
+ let additionalHeight = 0;
288
+
289
+ for (const key of keys) {
290
+ const value = tmpDiffMap.get(key) as number;
291
+ const newValue = value + additionalHeight;
292
+ diffMap.set(key + additionalHeight, newValue);
293
+ additionalHeight += newValue;
294
+ }
295
+
296
+ return diffMap;
297
+ };
298
+
299
+ export const normalizePositionsAndPageBreak = (
300
+ template: Template,
301
+ diffMap: Map<number, number>
302
+ ): Template => {
303
+ if (!isBlankPdf(template.basePdf) || diffMap.size === 0) {
304
+ return template;
305
+ }
306
+
307
+ const returnTemplate: Template = { schemas: [{}], basePdf: template.basePdf };
308
+ const pages = returnTemplate.schemas;
309
+ const pageHeight = template.basePdf.height;
310
+ const paddingTop = template.basePdf.padding[0];
311
+ const paddingBottom = template.basePdf.padding[2];
312
+
313
+ for (let i = 0; i < template.schemas.length; i += 1) {
314
+ const schemaObj = template.schemas[i];
315
+ if (!pages[i]) pages[i] = {};
316
+
317
+ for (const [key, schema] of Object.entries(schemaObj)) {
318
+ const { position, height } = schema;
319
+ let newY = position.y;
320
+ let pageCursor = i;
321
+
322
+ for (const [diffKey, diffValue] of diffMap) {
323
+ if (newY > diffKey) {
324
+ newY += diffValue;
325
+ }
326
+ }
327
+
328
+ while (newY + height >= pageHeight - paddingBottom) {
329
+ newY = newY + paddingTop - (pageHeight - paddingBottom) + paddingTop;
330
+ pageCursor++;
331
+ }
332
+
333
+ if (!pages[pageCursor]) pages[pageCursor] = {};
334
+ pages[pageCursor][key] = { ...schema, position: { ...position, y: newY } };
335
+ }
336
+ }
337
+
338
+ return returnTemplate;
339
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ PDFME_VERSION,
2
3
  MM_TO_PT_RATIO,
3
4
  PT_TO_MM_RATIO,
4
5
  PT_TO_PX_RATIO,
@@ -23,7 +24,9 @@ import type {
23
24
  Font,
24
25
  ColorType,
25
26
  BasePdf,
27
+ BlankPdf,
26
28
  Template,
29
+ CommonOptions,
27
30
  GeneratorOptions,
28
31
  Plugins,
29
32
  GenerateProps,
@@ -48,10 +51,15 @@ import {
48
51
  mm2pt,
49
52
  pt2mm,
50
53
  pt2px,
54
+ px2mm,
51
55
  isHexValid,
56
+ getInputFromTemplate,
57
+ isBlankPdf,
58
+ getDynamicTemplate,
52
59
  } from './helper.js';
53
60
 
54
61
  export {
62
+ PDFME_VERSION,
55
63
  MM_TO_PT_RATIO,
56
64
  PT_TO_MM_RATIO,
57
65
  PT_TO_PX_RATIO,
@@ -65,7 +73,11 @@ export {
65
73
  mm2pt,
66
74
  pt2mm,
67
75
  pt2px,
76
+ px2mm,
68
77
  isHexValid,
78
+ getInputFromTemplate,
79
+ isBlankPdf,
80
+ getDynamicTemplate,
69
81
  checkFont,
70
82
  checkInputs,
71
83
  checkUIOptions,
@@ -85,7 +97,9 @@ export type {
85
97
  Font,
86
98
  ColorType,
87
99
  BasePdf,
100
+ BlankPdf,
88
101
  Template,
102
+ CommonOptions,
89
103
  GeneratorOptions,
90
104
  Plugins,
91
105
  GenerateProps,
package/src/schema.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- const langs = ['en', 'ja', 'ar', 'th', 'pl', 'it', 'de'] as const;
3
+ const langs = ['en', 'ja', 'ar', 'th', 'pl', 'it', 'de', 'es', 'fr'] as const;
4
4
 
5
5
  export const Lang = z.enum(langs);
6
6
  export const Dict = z.object({
@@ -19,18 +19,21 @@ export const Dict = z.object({
19
19
  notUniq: z.string(),
20
20
  noKeyName: z.string(),
21
21
  fieldsList: z.string(),
22
- addNewField: z.string(),
23
22
  editField: z.string(),
24
23
  type: z.string(),
25
24
  errorOccurred: z.string(),
26
25
  errorBulkUpdateFieldName: z.string(),
27
26
  commitBulkUpdateFieldName: z.string(),
28
27
  bulkUpdateFieldName: z.string(),
28
+ addPageAfter: z.string(),
29
+ removePage: z.string(),
30
+ removePageConfirm: z.string(),
29
31
  hexColorPrompt: z.string(),
30
32
  // -----------------used in schemas-----------------
31
33
  'schemas.color': z.string(),
32
34
  'schemas.borderWidth': z.string(),
33
35
  'schemas.borderColor': z.string(),
36
+ 'schemas.backgroundColor': z.string(),
34
37
  'schemas.textColor': z.string(),
35
38
  'schemas.bgColor': z.string(),
36
39
  'schemas.horizontal': z.string(),
@@ -41,6 +44,7 @@ export const Dict = z.object({
41
44
  'schemas.top': z.string(),
42
45
  'schemas.middle': z.string(),
43
46
  'schemas.bottom': z.string(),
47
+ 'schemas.padding': z.string(),
44
48
 
45
49
  'schemas.text.fontName': z.string(),
46
50
  'schemas.text.size': z.string(),
@@ -55,6 +59,12 @@ export const Dict = z.object({
55
59
 
56
60
  'schemas.barcodes.barColor': z.string(),
57
61
  'schemas.barcodes.includetext': z.string(),
62
+
63
+ 'schemas.table.alternateBackgroundColor': z.string(),
64
+ 'schemas.table.tableStyle': z.string(),
65
+ 'schemas.table.headStyle': z.string(),
66
+ 'schemas.table.bodyStyle': z.string(),
67
+ 'schemas.table.columnStyle': z.string(),
58
68
  });
59
69
  export const Mode = z.enum(['viewer', 'form', 'designer']);
60
70
 
@@ -65,25 +75,42 @@ export const Size = z.object({ height: z.number(), width: z.number() });
65
75
  export const Schema = z
66
76
  .object({
67
77
  type: z.string(),
68
- readOnly: z.boolean().optional(),
69
- readOnlyValue: z.string().optional(),
78
+ icon: z.string().optional(),
79
+ content: z.string().optional(),
70
80
  position: z.object({ x: z.number(), y: z.number() }),
71
81
  width: z.number(),
72
82
  height: z.number(),
73
83
  rotate: z.number().optional(),
74
84
  opacity: z.number().optional(),
85
+ readOnly: z.boolean().optional(),
75
86
  })
76
87
  .passthrough();
77
88
 
78
89
  const SchemaForUIAdditionalInfo = z.object({
79
90
  id: z.string(),
80
91
  key: z.string(),
81
- data: z.string(),
82
92
  });
83
93
  export const SchemaForUI = Schema.merge(SchemaForUIAdditionalInfo);
84
94
 
85
95
  const ArrayBufferSchema: z.ZodSchema<ArrayBuffer> = z.any().refine((v) => v instanceof ArrayBuffer);
86
96
  const Uint8ArraySchema: z.ZodSchema<Uint8Array> = z.any().refine((v) => v instanceof Uint8Array);
97
+ export const BlankPdf = z.object({
98
+ width: z.number(),
99
+ height: z.number(),
100
+ padding: z.tuple([z.number(), z.number(), z.number(), z.number()]),
101
+ });
102
+
103
+ export const BasePdf = z.union([z.string(), ArrayBufferSchema, Uint8ArraySchema, BlankPdf]);
104
+
105
+ export const Template = z
106
+ .object({
107
+ schemas: z.array(z.record(Schema)),
108
+ basePdf: BasePdf,
109
+ pdfmeVersion: z.string().optional(),
110
+ })
111
+ .passthrough();
112
+
113
+ export const Inputs = z.array(z.record(z.any())).min(1);
87
114
 
88
115
  export const Font = z.record(
89
116
  z.object({
@@ -93,18 +120,7 @@ export const Font = z.record(
93
120
  })
94
121
  );
95
122
 
96
- export const BasePdf = z.union([z.string(), ArrayBufferSchema, Uint8ArraySchema]);
97
-
98
- export const Template = z.object({
99
- schemas: z.array(z.record(Schema)),
100
- basePdf: BasePdf,
101
- sampledata: z.array(z.record(z.string())).length(1).optional(),
102
- columns: z.array(z.string()).optional(),
103
- });
104
-
105
- export const Inputs = z.array(z.record(z.string())).min(1);
106
-
107
- const CommonOptions = z.object({ font: Font.optional() }).passthrough();
123
+ export const CommonOptions = z.object({ font: Font.optional() }).passthrough();
108
124
 
109
125
  const CommonProps = z.object({
110
126
  template: Template,
package/src/types.ts CHANGED
@@ -11,6 +11,8 @@ import {
11
11
  Font,
12
12
  SchemaForUI,
13
13
  BasePdf,
14
+ BlankPdf,
15
+ CommonOptions,
14
16
  Template,
15
17
  GeneratorOptions,
16
18
  GenerateProps,
@@ -30,6 +32,7 @@ export type ChangeSchemas = (objs: { key: string; value: any; schemaId: string }
30
32
  * @property {string} key The key of the schema object.
31
33
  * @property {string} value The string used for PDF rendering.
32
34
  * @property {T} schema Extended Schema object for rendering.
35
+ * @property {BasePdf} basePdf Base PDF object for rendering.
33
36
  * @property {typeof import('@pdfme/pdf-lib')} pdfLib The pdf-lib library used for rendering.
34
37
  * @property {PDFDocument} pdfDoc PDFDocument object from pdf-lib.
35
38
  * @property {PDFPage} page PDFPage object from pdf-lib.
@@ -40,6 +43,7 @@ export interface PDFRenderProps<T extends Schema> {
40
43
  key: string;
41
44
  value: string;
42
45
  schema: T;
46
+ basePdf: BasePdf;
43
47
  pdfLib: typeof import('@pdfme/pdf-lib');
44
48
  pdfDoc: PDFDocument;
45
49
  page: PDFPage;
@@ -53,28 +57,31 @@ export interface PDFRenderProps<T extends Schema> {
53
57
  *
54
58
  * @template T - Type of the extended Schema object.
55
59
  * @property {T} schema - Extended Schema object for rendering.
60
+ * @property {BasePdf} basePdf Base PDF object for rendering.
56
61
  * @property {Mode} mode - String indicating the rendering state. 'designer' is only used when the field is in edit mode in the Designer.
57
62
  * @property {number} [tabIndex] - Tab index for Form.
58
63
  * @property {string} [placeholder] - Placeholder text for Form.
59
64
  * @property {() => void} [stopEditing] - Stops editing mode, can be used when the mode is 'designer'.
60
65
  * @property {string} key - The key of the schema object.
61
66
  * @property {string} value - The string used for UI rendering.
62
- * @property {(value: string) => void} [onChange] - Used to change the value. Only applicable when the mode is 'form' or 'designer'.
67
+ * @property {(arg: { key: string; value: any } | { key: string; value: any }[]) => void} [onChange] - Used to change the value and schema properties. Only applicable when the mode is 'form' or 'designer'.
63
68
  * @property {HTMLDivElement} rootElement - The root HTMLDivElement for the UI.
64
69
  * @property {UIOptions} options - Options object passed from the Viewer, Form, or Designer.
65
70
  * @property {ThemeConfig} theme - An object that merges the 'theme' passed as an options with the default theme.
66
71
  * @property {(key: keyof Dict | string) => string} i18n - An object merged based on the options 'lang' and 'labels'.
72
+ * @property {Size} pageSize - The size of the page being edited.
67
73
  * @property {Map<any, any>} _cache - Cache shared only during the execution of the render function (useful for caching images, etc. if needed).
68
74
  */
69
75
  export type UIRenderProps<T extends Schema> = {
70
76
  schema: T;
77
+ basePdf: BasePdf;
71
78
  mode: Mode;
72
79
  tabIndex?: number;
73
80
  placeholder?: string;
74
81
  stopEditing?: () => void;
75
82
  key: string;
76
83
  value: string;
77
- onChange?: (value: string) => void;
84
+ onChange?: (arg: { key: string; value: any } | { key: string; value: any }[]) => void;
78
85
  rootElement: HTMLDivElement;
79
86
  options: UIOptions;
80
87
  theme: GlobalToken;
@@ -102,7 +109,6 @@ type PropPanelProps = {
102
109
  activeElements: HTMLElement[];
103
110
  changeSchemas: ChangeSchemas;
104
111
  schemas: SchemaForUI[];
105
- pageSize: Size;
106
112
  options: UIOptions;
107
113
  theme: GlobalToken;
108
114
  i18n: (key: keyof Dict | string) => string;
@@ -115,7 +121,6 @@ export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps;
115
121
  * @template T - Type of the extended Schema object.
116
122
  * @property {Record<string, PropPanelSchema> | ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>)} schema - A function returning a form-render schema object or the schema object itself. When a function, it takes properties passed from the designer as arguments.
117
123
  * @property {Record<string, (props: PropPanelWidgetProps) => void>} [widgets] - An object of functions returning form-render widgets. The functions take, as arguments, both form-render's WidgetProps and properties passed from the designer.
118
- * @property {string} defaultValue - The default input value set when adding the schema.
119
124
  * @property {T} defaultSchema - The default schema set when adding the schema.
120
125
  */
121
126
  export interface PropPanel<T extends Schema> {
@@ -124,7 +129,6 @@ export interface PropPanel<T extends Schema> {
124
129
  | Record<string, PropPanelSchema>;
125
130
 
126
131
  widgets?: Record<string, (props: PropPanelWidgetProps) => void>;
127
- defaultValue: string;
128
132
  defaultSchema: T;
129
133
  }
130
134
 
@@ -162,7 +166,9 @@ export type SchemaForUI = z.infer<typeof SchemaForUI>;
162
166
  export type Font = z.infer<typeof Font>;
163
167
  export type ColorType = z.infer<typeof ColorType>;
164
168
  export type BasePdf = z.infer<typeof BasePdf>;
169
+ export type BlankPdf = z.infer<typeof BlankPdf>;
165
170
  export type Template = z.infer<typeof Template>;
171
+ export type CommonOptions = z.infer<typeof CommonOptions>;
166
172
  export type GeneratorOptions = z.infer<typeof GeneratorOptions>;
167
173
  export type GenerateProps = z.infer<typeof GenerateProps> & { plugins?: Plugins };
168
174
  export type UIOptions = z.infer<typeof UIOptions> & { theme?: ThemeConfig };