@pdfme/schemas 5.3.11-dev.2 → 5.3.11-dev.20
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/src/barcodes/helper.js +6 -3
- package/dist/cjs/src/barcodes/helper.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +5 -1
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +5 -3
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/checkbox/index.js +2 -1
- package/dist/cjs/src/checkbox/index.js.map +1 -1
- package/dist/cjs/src/date/helper.js +1 -1
- package/dist/cjs/src/date/helper.js.map +1 -1
- package/dist/cjs/src/graphics/image.js +8 -3
- package/dist/cjs/src/graphics/image.js.map +1 -1
- package/dist/cjs/src/graphics/svg.js +3 -2
- package/dist/cjs/src/graphics/svg.js.map +1 -1
- package/dist/cjs/src/multiVariableText/helper.js +5 -3
- package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
- package/dist/cjs/src/multiVariableText/propPanel.js +24 -12
- package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/cjs/src/multiVariableText/uiRender.js +17 -12
- package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/cjs/src/radioGroup/index.js.map +1 -1
- package/dist/cjs/src/select/index.js +9 -3
- package/dist/cjs/src/select/index.js.map +1 -1
- package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/cjs/src/tables/classes.js.map +1 -1
- package/dist/cjs/src/tables/pdfRender.js +16 -2
- package/dist/cjs/src/tables/pdfRender.js.map +1 -1
- package/dist/cjs/src/tables/propPanel.js +1 -1
- package/dist/cjs/src/tables/propPanel.js.map +1 -1
- package/dist/cjs/src/tables/tableHelper.js +6 -1
- package/dist/cjs/src/tables/tableHelper.js.map +1 -1
- package/dist/cjs/src/tables/uiRender.js +4 -2
- package/dist/cjs/src/tables/uiRender.js.map +1 -1
- package/dist/cjs/src/text/extraFormatter.js +1 -0
- package/dist/cjs/src/text/extraFormatter.js.map +1 -1
- package/dist/cjs/src/text/helper.js +19 -3
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +5 -1
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +9 -8
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/utils.js +3 -3
- package/dist/cjs/src/utils.js.map +1 -1
- package/dist/esm/src/barcodes/helper.js +6 -3
- package/dist/esm/src/barcodes/helper.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +5 -1
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +5 -3
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/checkbox/index.js +2 -1
- package/dist/esm/src/checkbox/index.js.map +1 -1
- package/dist/esm/src/date/helper.js +2 -2
- package/dist/esm/src/date/helper.js.map +1 -1
- package/dist/esm/src/graphics/image.js +8 -3
- package/dist/esm/src/graphics/image.js.map +1 -1
- package/dist/esm/src/graphics/svg.js +3 -2
- package/dist/esm/src/graphics/svg.js.map +1 -1
- package/dist/esm/src/multiVariableText/helper.js +5 -3
- package/dist/esm/src/multiVariableText/helper.js.map +1 -1
- package/dist/esm/src/multiVariableText/propPanel.js +24 -12
- package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/esm/src/multiVariableText/uiRender.js +17 -12
- package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/esm/src/radioGroup/index.js.map +1 -1
- package/dist/esm/src/select/index.js +9 -3
- package/dist/esm/src/select/index.js.map +1 -1
- package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/esm/src/tables/classes.js.map +1 -1
- package/dist/esm/src/tables/pdfRender.js +16 -2
- package/dist/esm/src/tables/pdfRender.js.map +1 -1
- package/dist/esm/src/tables/propPanel.js +1 -1
- package/dist/esm/src/tables/propPanel.js.map +1 -1
- package/dist/esm/src/tables/tableHelper.js +6 -1
- package/dist/esm/src/tables/tableHelper.js.map +1 -1
- package/dist/esm/src/tables/uiRender.js +4 -2
- package/dist/esm/src/tables/uiRender.js.map +1 -1
- package/dist/esm/src/text/extraFormatter.js +1 -0
- package/dist/esm/src/text/extraFormatter.js.map +1 -1
- package/dist/esm/src/text/helper.js +19 -3
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +5 -1
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +8 -6
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/utils.js +3 -3
- package/dist/esm/src/utils.js.map +1 -1
- package/dist/node/src/barcodes/helper.js +6 -3
- package/dist/node/src/barcodes/helper.js.map +1 -1
- package/dist/node/src/barcodes/pdfRender.js +5 -1
- package/dist/node/src/barcodes/pdfRender.js.map +1 -1
- package/dist/node/src/barcodes/uiRender.js +5 -3
- package/dist/node/src/barcodes/uiRender.js.map +1 -1
- package/dist/node/src/checkbox/index.js +2 -1
- package/dist/node/src/checkbox/index.js.map +1 -1
- package/dist/node/src/date/helper.js +1 -1
- package/dist/node/src/date/helper.js.map +1 -1
- package/dist/node/src/graphics/image.js +8 -3
- package/dist/node/src/graphics/image.js.map +1 -1
- package/dist/node/src/graphics/svg.js +3 -2
- package/dist/node/src/graphics/svg.js.map +1 -1
- package/dist/node/src/multiVariableText/helper.js +5 -3
- package/dist/node/src/multiVariableText/helper.js.map +1 -1
- package/dist/node/src/multiVariableText/propPanel.js +24 -12
- package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/node/src/multiVariableText/uiRender.js +17 -12
- package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/node/src/radioGroup/index.js.map +1 -1
- package/dist/node/src/select/index.js +9 -3
- package/dist/node/src/select/index.js.map +1 -1
- package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/node/src/tables/classes.js.map +1 -1
- package/dist/node/src/tables/pdfRender.js +16 -2
- package/dist/node/src/tables/pdfRender.js.map +1 -1
- package/dist/node/src/tables/propPanel.js +1 -1
- package/dist/node/src/tables/propPanel.js.map +1 -1
- package/dist/node/src/tables/tableHelper.js +6 -1
- package/dist/node/src/tables/tableHelper.js.map +1 -1
- package/dist/node/src/tables/uiRender.js +4 -2
- package/dist/node/src/tables/uiRender.js.map +1 -1
- package/dist/node/src/text/extraFormatter.js +1 -0
- package/dist/node/src/text/extraFormatter.js.map +1 -1
- package/dist/node/src/text/helper.js +19 -3
- package/dist/node/src/text/helper.js.map +1 -1
- package/dist/node/src/text/pdfRender.js +5 -1
- package/dist/node/src/text/pdfRender.js.map +1 -1
- package/dist/node/src/text/propPanel.js.map +1 -1
- package/dist/node/src/text/uiRender.js +9 -8
- package/dist/node/src/text/uiRender.js.map +1 -1
- package/dist/node/src/utils.js +3 -3
- package/dist/node/src/utils.js.map +1 -1
- package/dist/types/src/barcodes/helper.d.ts +22 -0
- package/dist/types/src/checkbox/index.d.ts +1 -2
- package/dist/types/src/graphics/image.d.ts +1 -2
- package/dist/types/src/graphics/svg.d.ts +1 -2
- package/dist/types/src/radioGroup/index.d.ts +1 -2
- package/dist/types/src/shapes/rectAndEllipse.d.ts +91 -7
- package/dist/types/src/tables/classes.d.ts +2 -1
- package/dist/types/src/tables/dynamicTemplate.d.ts +1 -1
- package/dist/types/src/tables/tableHelper.d.ts +1 -1
- package/dist/types/src/text/extraFormatter.d.ts +2 -3
- package/dist/types/src/text/helper.d.ts +1 -1
- package/dist/types/src/text/uiRender.d.ts +0 -3
- package/dist/types/src/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/barcodes/helper.ts +39 -5
- package/src/barcodes/pdfRender.ts +7 -4
- package/src/barcodes/uiRender.ts +3 -3
- package/src/checkbox/index.ts +4 -5
- package/src/date/helper.ts +15 -8
- package/src/graphics/image.ts +6 -4
- package/src/graphics/svg.ts +6 -6
- package/src/multiVariableText/helper.ts +6 -4
- package/src/multiVariableText/propPanel.ts +29 -14
- package/src/multiVariableText/uiRender.ts +22 -15
- package/src/radioGroup/index.ts +3 -4
- package/src/select/index.ts +12 -6
- package/src/shapes/rectAndEllipse.ts +4 -4
- package/src/tables/classes.ts +6 -2
- package/src/tables/dynamicTemplate.ts +1 -1
- package/src/tables/pdfRender.ts +28 -3
- package/src/tables/propPanel.ts +1 -1
- package/src/tables/tableHelper.ts +8 -2
- package/src/tables/uiRender.ts +2 -2
- package/src/text/extraFormatter.ts +3 -3
- package/src/text/helper.ts +19 -6
- package/src/text/pdfRender.ts +7 -3
- package/src/text/propPanel.ts +6 -4
- package/src/text/uiRender.ts +11 -7
- package/src/utils.ts +9 -5
- package/dist/cjs/src/graphics/cacheKey.js +0 -6
- package/dist/cjs/src/graphics/cacheKey.js.map +0 -1
- package/dist/esm/src/graphics/cacheKey.js +0 -2
- package/dist/esm/src/graphics/cacheKey.js.map +0 -1
- package/dist/node/src/graphics/cacheKey.js +0 -6
- package/dist/node/src/graphics/cacheKey.js.map +0 -1
- package/dist/types/src/graphics/cacheKey.d.ts +0 -2
- package/src/graphics/cacheKey.ts +0 -3
@@ -23,16 +23,17 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
23
23
|
await parentUiRender({
|
24
24
|
value: isEditable(mode, schema) ? text : substituteVariables(text, value),
|
25
25
|
schema,
|
26
|
-
mode: mode
|
26
|
+
mode: mode === 'form' ? 'viewer' : mode, // if no variables for form it's just a viewer
|
27
27
|
rootElement,
|
28
|
-
onChange: (arg: { key: string; value:
|
28
|
+
onChange: (arg: { key: string; value: unknown } | { key: string; value: unknown }[]) => {
|
29
29
|
if (!Array.isArray(arg)) {
|
30
|
-
const numVariables = countUniqueVariableNames(arg.value);
|
31
|
-
onChange
|
30
|
+
const numVariables = countUniqueVariableNames(arg.value as string);
|
31
|
+
if (onChange) {
|
32
32
|
onChange([
|
33
33
|
{ key: 'text', value: arg.value },
|
34
|
-
{ key: 'readOnly', value: numVariables
|
34
|
+
{ key: 'readOnly', value: numVariables === 0 },
|
35
35
|
]);
|
36
|
+
}
|
36
37
|
} else {
|
37
38
|
throw new Error('onChange is not an array, the parent text plugin has changed...');
|
38
39
|
}
|
@@ -40,7 +41,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
40
41
|
...rest,
|
41
42
|
});
|
42
43
|
|
43
|
-
const textBlock = rootElement.querySelector('#text-' + schema.id) as HTMLDivElement;
|
44
|
+
const textBlock = rootElement.querySelector('#text-' + String(schema.id)) as HTMLDivElement;
|
44
45
|
if (!textBlock) {
|
45
46
|
throw new Error('Text block not found. Ensure the text block has an id of "text-" + schema.id');
|
46
47
|
}
|
@@ -55,7 +56,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
55
56
|
if (onChange) {
|
56
57
|
onChange([
|
57
58
|
{ key: 'text', value: text },
|
58
|
-
{ key: 'readOnly', value: newNumVariables
|
59
|
+
{ key: 'readOnly', value: newNumVariables === 0 },
|
59
60
|
]);
|
60
61
|
}
|
61
62
|
numVariables = newNumVariables;
|
@@ -74,11 +75,17 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
74
75
|
rootElement.parentElement.style.outline = '';
|
75
76
|
}
|
76
77
|
|
77
|
-
const variables: Record<string, string> = value
|
78
|
+
const variables: Record<string, string> = value
|
79
|
+
? (JSON.parse(value) as Record<string, string>) || {}
|
80
|
+
: {};
|
78
81
|
const variableIndices = getVariableIndices(rawText);
|
79
82
|
const substitutedText = substituteVariables(rawText, variables);
|
80
83
|
const font = options?.font || getDefaultFont();
|
81
|
-
const fontKitFont = await getFontKitFont(
|
84
|
+
const fontKitFont = await getFontKitFont(
|
85
|
+
schema.fontName,
|
86
|
+
font,
|
87
|
+
_cache as Map<string, import('fontkit').Font>,
|
88
|
+
);
|
82
89
|
|
83
90
|
const textBlock = buildStyledTextContainer(arg, fontKitFont, substitutedText);
|
84
91
|
|
@@ -96,8 +103,8 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
96
103
|
const newValue = (e.target as HTMLSpanElement).textContent || '';
|
97
104
|
if (newValue !== variables[variableIndices[i]]) {
|
98
105
|
variables[variableIndices[i]] = newValue;
|
99
|
-
onChange
|
100
|
-
stopEditing
|
106
|
+
if (onChange) onChange({ key: 'content', value: JSON.stringify(variables) });
|
107
|
+
if (stopEditing) stopEditing();
|
101
108
|
}
|
102
109
|
});
|
103
110
|
textBlock.appendChild(span);
|
@@ -145,10 +152,10 @@ const countUniqueVariableNames = (content: string) => {
|
|
145
152
|
*/
|
146
153
|
const keyPressShouldBeChecked = (event: KeyboardEvent) => {
|
147
154
|
if (
|
148
|
-
event.key
|
149
|
-
event.key
|
150
|
-
event.key
|
151
|
-
event.key
|
155
|
+
event.key === 'ArrowUp' ||
|
156
|
+
event.key === 'ArrowDown' ||
|
157
|
+
event.key === 'ArrowLeft' ||
|
158
|
+
event.key === 'ArrowRight'
|
152
159
|
) {
|
153
160
|
return false;
|
154
161
|
}
|
package/src/radioGroup/index.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { Plugin } from '@pdfme/common';
|
2
|
-
import { Schema } from '@pdfme/common';
|
1
|
+
import { Plugin, Schema, UIRenderProps, PDFRenderProps } from '@pdfme/common';
|
3
2
|
import { Circle, CircleDot } from 'lucide';
|
4
3
|
import svg from '../graphics/svg.js';
|
5
4
|
import { isEditable, createSvgStr } from '../utils.js';
|
@@ -29,7 +28,7 @@ const radioButtonStates = new Map<string, RadioButtonState>();
|
|
29
28
|
const eventListeners = new Map<string, EventListener>();
|
30
29
|
|
31
30
|
const schema: Plugin<RadioGroup> = {
|
32
|
-
ui: (arg) => {
|
31
|
+
ui: (arg: UIRenderProps<RadioGroup>) => {
|
33
32
|
const { schema, value, onChange, rootElement, mode } = arg;
|
34
33
|
const container = document.createElement('div');
|
35
34
|
container.style.width = '100%';
|
@@ -80,7 +79,7 @@ const schema: Plugin<RadioGroup> = {
|
|
80
79
|
|
81
80
|
rootElement.appendChild(container);
|
82
81
|
},
|
83
|
-
pdf: (arg) =>
|
82
|
+
pdf: (arg: PDFRenderProps<RadioGroup>) =>
|
84
83
|
svg.pdf(Object.assign(arg, { value: getIcon({ value: arg.value, color: arg.schema.color }) })),
|
85
84
|
propPanel: {
|
86
85
|
schema: ({ i18n }) => ({
|
package/src/select/index.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type * as CSS from 'csstype';
|
2
2
|
import { propPanel as parentPropPanel } from '../text/propPanel.js';
|
3
|
-
import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common';
|
3
|
+
import { Plugin, PropPanelWidgetProps, SchemaForUI, UIRenderProps } from '@pdfme/common';
|
4
4
|
import text from '../text/index.js';
|
5
5
|
import { TextSchema } from '../text/types.js';
|
6
6
|
import { ChevronDown } from 'lucide';
|
@@ -112,7 +112,7 @@ const addOptions = (props: PropPanelWidgetProps) => {
|
|
112
112
|
};
|
113
113
|
|
114
114
|
const schema: Plugin<Select> = {
|
115
|
-
ui: async (arg) => {
|
115
|
+
ui: async (arg: UIRenderProps<Select>) => {
|
116
116
|
const { schema, value, onChange, rootElement, mode } = arg;
|
117
117
|
await text.ui(Object.assign(arg, { mode: 'viewer' }));
|
118
118
|
|
@@ -150,11 +150,13 @@ const schema: Plugin<Select> = {
|
|
150
150
|
|
151
151
|
selectElement.addEventListener('change', (e) => {
|
152
152
|
if (onChange && e.target instanceof HTMLSelectElement) {
|
153
|
-
onChange
|
153
|
+
if (onChange) onChange({ key: 'content', value: e.target.value });
|
154
154
|
}
|
155
155
|
});
|
156
156
|
|
157
|
-
|
157
|
+
// Ensure schema.options is an array before mapping
|
158
|
+
const options = Array.isArray(schema.options) ? schema.options : [];
|
159
|
+
selectElement.innerHTML = options
|
158
160
|
.map(
|
159
161
|
(option) =>
|
160
162
|
`<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`,
|
@@ -172,8 +174,12 @@ const schema: Plugin<Select> = {
|
|
172
174
|
throw Error('Oops, is text schema no longer a function?');
|
173
175
|
}
|
174
176
|
|
177
|
+
// Safely call the parent schema function with proper type checking
|
178
|
+
const parentSchema = parentPropPanel.schema(propPanelProps);
|
179
|
+
|
180
|
+
// Create a type-safe return object
|
175
181
|
return {
|
176
|
-
...
|
182
|
+
...parentSchema,
|
177
183
|
'-------': { type: 'void', widget: 'Divider' },
|
178
184
|
|
179
185
|
optionsContainer: {
|
@@ -186,7 +192,7 @@ const schema: Plugin<Select> = {
|
|
186
192
|
};
|
187
193
|
},
|
188
194
|
defaultSchema: {
|
189
|
-
...text.propPanel.defaultSchema,
|
195
|
+
...(text.propPanel.defaultSchema as TextSchema),
|
190
196
|
type: 'select',
|
191
197
|
content: 'option1',
|
192
198
|
options: ['option1', 'option2'],
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Plugin, Schema, mm2pt } from '@pdfme/common';
|
1
|
+
import { Plugin, Schema, mm2pt, UIRenderProps, PDFRenderProps } from '@pdfme/common';
|
2
2
|
import { HEX_COLOR_PATTERN } from '../constants.js';
|
3
3
|
import { hex2PrintingColor, convertForPdfLayoutProps, createSvgStr } from '../utils.js';
|
4
4
|
import { toRadians } from '@pdfme/pdf-lib';
|
@@ -12,7 +12,7 @@ interface ShapeSchema extends Schema {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
const shape: Plugin<ShapeSchema> = {
|
15
|
-
ui: (arg) => {
|
15
|
+
ui: (arg: UIRenderProps<ShapeSchema>) => {
|
16
16
|
const { schema, rootElement } = arg;
|
17
17
|
const div = document.createElement('div');
|
18
18
|
div.style.width = '100%';
|
@@ -28,7 +28,7 @@ const shape: Plugin<ShapeSchema> = {
|
|
28
28
|
|
29
29
|
rootElement.appendChild(div);
|
30
30
|
},
|
31
|
-
pdf: (arg) => {
|
31
|
+
pdf: (arg: PDFRenderProps<ShapeSchema>) => {
|
32
32
|
const { schema, page, options } = arg;
|
33
33
|
if (!schema.color && !schema.borderColor) return;
|
34
34
|
const { colorType } = options;
|
@@ -119,7 +119,7 @@ const shape: Plugin<ShapeSchema> = {
|
|
119
119
|
const getPropPanelSchema = (type: 'rectangle' | 'ellipse') => ({
|
120
120
|
...shape.propPanel,
|
121
121
|
defaultSchema: {
|
122
|
-
...shape.propPanel.defaultSchema,
|
122
|
+
...(shape.propPanel.defaultSchema as ShapeSchema),
|
123
123
|
type,
|
124
124
|
},
|
125
125
|
});
|
package/src/tables/classes.ts
CHANGED
@@ -114,7 +114,7 @@ export class Table {
|
|
114
114
|
input: TableInput;
|
115
115
|
content: ContentSettings;
|
116
116
|
font: Font;
|
117
|
-
_cache: Map<
|
117
|
+
_cache: Map<string | number, FontKitFont>;
|
118
118
|
}) {
|
119
119
|
const { input, content, font, _cache } = arg;
|
120
120
|
const table = new Table(input, content);
|
@@ -145,7 +145,11 @@ export class Table {
|
|
145
145
|
}
|
146
146
|
}
|
147
147
|
|
148
|
-
async function calculateWidths(arg: {
|
148
|
+
async function calculateWidths(arg: {
|
149
|
+
table: Table;
|
150
|
+
font: Font;
|
151
|
+
_cache: Map<string | number, FontKitFont>;
|
152
|
+
}) {
|
149
153
|
const { table, font, _cache } = arg;
|
150
154
|
|
151
155
|
const getFontKitFontByFontName = (fontName: string | undefined) =>
|
@@ -9,7 +9,7 @@ export const getDynamicHeightsForTable = async (
|
|
9
9
|
schema: Schema;
|
10
10
|
basePdf: BasePdf;
|
11
11
|
options: CommonOptions;
|
12
|
-
_cache: Map<
|
12
|
+
_cache: Map<string | number, unknown>;
|
13
13
|
},
|
14
14
|
): Promise<number[]> => {
|
15
15
|
if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
|
package/src/tables/pdfRender.ts
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
import type { TableSchema } from './types.js';
|
2
|
-
import type { PDFRenderProps } from '@pdfme/common';
|
2
|
+
import type { PDFRenderProps, Schema, BasePdf, CommonOptions } from '@pdfme/common';
|
3
3
|
import { Cell, Table, Row, Column } from './classes.js';
|
4
4
|
import { rectangle } from '../shapes/rectAndEllipse.js';
|
5
5
|
import cell from './cell.js';
|
6
6
|
import { getBodyWithRange } from './helper.js';
|
7
7
|
import { createSingleTable } from './tableHelper.js';
|
8
8
|
|
9
|
+
// Define the CreateTableArgs interface locally since it's not exported from tableHelper.js
|
10
|
+
interface CreateTableArgs {
|
11
|
+
schema: Schema;
|
12
|
+
basePdf: BasePdf;
|
13
|
+
options: CommonOptions;
|
14
|
+
_cache: Map<string | number, unknown>;
|
15
|
+
}
|
16
|
+
|
9
17
|
type Pos = { x: number; y: number };
|
10
18
|
|
11
19
|
const rectanglePdfRender = rectangle.pdf;
|
@@ -108,12 +116,29 @@ async function drawTable(arg: PDFRenderProps<TableSchema>, table: Table): Promis
|
|
108
116
|
}
|
109
117
|
|
110
118
|
export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
|
111
|
-
const { value, schema } = arg;
|
119
|
+
const { value, schema, basePdf, options, _cache } = arg;
|
112
120
|
|
113
121
|
const body = getBodyWithRange(
|
114
122
|
typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
|
115
123
|
schema.__bodyRange,
|
116
124
|
);
|
117
|
-
|
125
|
+
|
126
|
+
// Create a properly typed CreateTableArgs object
|
127
|
+
const createTableArgs: CreateTableArgs = {
|
128
|
+
schema,
|
129
|
+
basePdf,
|
130
|
+
options,
|
131
|
+
_cache,
|
132
|
+
};
|
133
|
+
|
134
|
+
// Ensure body is properly typed before passing to createSingleTable
|
135
|
+
// Ensure body is properly typed as string[][] before passing to createSingleTable
|
136
|
+
const typedBody: string[][] = Array.isArray(body)
|
137
|
+
? body.map((row) => (Array.isArray(row) ? row.map((cell) => String(cell)) : []))
|
138
|
+
: [];
|
139
|
+
const table = await createSingleTable(typedBody, createTableArgs);
|
140
|
+
|
141
|
+
// Use the original arg directly since drawTable expects PDFRenderProps<TableSchema>
|
142
|
+
// which is the same type as our arg parameter
|
118
143
|
await drawTable(arg, table);
|
119
144
|
};
|
package/src/tables/propPanel.ts
CHANGED
@@ -10,7 +10,7 @@ import { HEX_COLOR_PATTERN } from '../constants.js';
|
|
10
10
|
|
11
11
|
export const propPanel: PropPanel<TableSchema> = {
|
12
12
|
schema: ({ activeSchema, options, i18n }) => {
|
13
|
-
// @ts-expect-error
|
13
|
+
// @ts-expect-error Type casting is necessary here as the activeSchema type is generic
|
14
14
|
const tableSchema = activeSchema as TableSchema;
|
15
15
|
const head = tableSchema.head || [];
|
16
16
|
const showHead = tableSchema.showHead || false;
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
getFallbackFontName,
|
8
8
|
cloneDeep,
|
9
9
|
} from '@pdfme/common';
|
10
|
+
import type { Font as FontKitFont } from 'fontkit';
|
10
11
|
import type {
|
11
12
|
TableSchema,
|
12
13
|
CellStyle,
|
@@ -24,7 +25,7 @@ interface CreateTableArgs {
|
|
24
25
|
schema: Schema;
|
25
26
|
basePdf: BasePdf;
|
26
27
|
options: CommonOptions;
|
27
|
-
_cache: Map<
|
28
|
+
_cache: Map<string | number, unknown>;
|
28
29
|
}
|
29
30
|
|
30
31
|
interface UserOptions {
|
@@ -278,5 +279,10 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
|
|
278
279
|
|
279
280
|
const content = parseContent4Table(input, fallbackFontName);
|
280
281
|
|
281
|
-
return Table.create({
|
282
|
+
return Table.create({
|
283
|
+
input,
|
284
|
+
content,
|
285
|
+
font,
|
286
|
+
_cache: _cache as unknown as Map<string | number, FontKitFont>,
|
287
|
+
});
|
282
288
|
}
|
package/src/tables/uiRender.ts
CHANGED
@@ -250,7 +250,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
250
250
|
text: '+',
|
251
251
|
onClick: () => {
|
252
252
|
const newRow = Array(schema.head.length).fill('') as string[];
|
253
|
-
onChange
|
253
|
+
if (onChange) onChange({ key: 'content', value: JSON.stringify(body.concat([newRow])) });
|
254
254
|
},
|
255
255
|
});
|
256
256
|
|
@@ -266,7 +266,7 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
266
266
|
text: '-',
|
267
267
|
onClick: () => {
|
268
268
|
const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
|
269
|
-
onChange
|
269
|
+
if (onChange) onChange({ key: 'content', value: JSON.stringify(newTableBody) });
|
270
270
|
},
|
271
271
|
});
|
272
272
|
return removeRowButton;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
// No imports needed from @pdfme/common
|
2
2
|
import {
|
3
3
|
TextAlignCenterIcon,
|
4
4
|
TextAlignLeftIcon,
|
@@ -40,9 +40,9 @@ interface GroupButtonString {
|
|
40
40
|
value: string;
|
41
41
|
}
|
42
42
|
|
43
|
-
|
43
|
+
type GroupButton = GroupButtonBoolean | GroupButtonString;
|
44
44
|
|
45
|
-
export function getExtraFormatterSchema(i18n: (key:
|
45
|
+
export function getExtraFormatterSchema(i18n: (key: string) => string): {
|
46
46
|
title: string;
|
47
47
|
widget: string;
|
48
48
|
buttons: GroupButton[];
|
package/src/text/helper.ts
CHANGED
@@ -112,7 +112,7 @@ const getCacheKey = (fontName: string) => `getFontKitFont-${fontName}`;
|
|
112
112
|
export const getFontKitFont = async (
|
113
113
|
fontName: string | undefined,
|
114
114
|
font: Font,
|
115
|
-
_cache: Map<
|
115
|
+
_cache: Map<string | number, fontkit.Font>,
|
116
116
|
) => {
|
117
117
|
const fntNm = fontName || getFallbackFontName(font);
|
118
118
|
const cacheKey = getCacheKey(fntNm);
|
@@ -128,9 +128,14 @@ export const getFontKitFont = async (
|
|
128
128
|
: b64toUint8Array(fontData);
|
129
129
|
}
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
)
|
131
|
+
// Convert fontData to Buffer if it's not already a Buffer
|
132
|
+
let fontDataBuffer: Buffer;
|
133
|
+
if (fontData instanceof Buffer) {
|
134
|
+
fontDataBuffer = fontData;
|
135
|
+
} else {
|
136
|
+
fontDataBuffer = Buffer.from(fontData as ArrayBufferLike);
|
137
|
+
}
|
138
|
+
const fontKitFont = fontkit.create(fontDataBuffer) as fontkit.Font;
|
134
139
|
_cache.set(cacheKey, fontKitFont);
|
135
140
|
|
136
141
|
return fontKitFont;
|
@@ -489,7 +494,11 @@ export const filterStartJP = (lines: string[]): string[] => {
|
|
489
494
|
});
|
490
495
|
|
491
496
|
if (charToAppend) {
|
492
|
-
|
497
|
+
// Handle the case where filtered might be empty
|
498
|
+
const firstItem = filtered.length > 0 ? filtered[0] : '';
|
499
|
+
// Ensure we're concatenating strings
|
500
|
+
const combinedItem = String(charToAppend) + String(firstItem);
|
501
|
+
return [combinedItem, ...filtered.slice(1)].reverse();
|
493
502
|
} else {
|
494
503
|
return filtered.reverse();
|
495
504
|
}
|
@@ -530,7 +539,11 @@ export const filterEndJP = (lines: string[]): string[] => {
|
|
530
539
|
});
|
531
540
|
|
532
541
|
if (charToPrepend) {
|
533
|
-
|
542
|
+
// Handle the case where filtered might be empty
|
543
|
+
const lastItem = filtered.length > 0 ? filtered[filtered.length - 1] : '';
|
544
|
+
// Ensure we're concatenating strings
|
545
|
+
const combinedItem = String(lastItem) + String(charToPrepend);
|
546
|
+
return [...filtered.slice(0, -1), combinedItem];
|
534
547
|
} else {
|
535
548
|
return filtered;
|
536
549
|
}
|
package/src/text/pdfRender.ts
CHANGED
@@ -33,7 +33,7 @@ import { convertForPdfLayoutProps, rotatePoint, hex2PrintingColor } from '../uti
|
|
33
33
|
const embedAndGetFontObj = async (arg: {
|
34
34
|
pdfDoc: PDFDocument;
|
35
35
|
font: Font;
|
36
|
-
_cache: Map<
|
36
|
+
_cache: Map<PDFDocument, { [key: string]: PDFFont }>;
|
37
37
|
}) => {
|
38
38
|
const { pdfDoc, font, _cache } = arg;
|
39
39
|
if (_cache.has(pdfDoc)) {
|
@@ -94,8 +94,12 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
94
94
|
const { font = getDefaultFont(), colorType } = options;
|
95
95
|
|
96
96
|
const [pdfFontObj, fontKitFont] = await Promise.all([
|
97
|
-
embedAndGetFontObj({
|
98
|
-
|
97
|
+
embedAndGetFontObj({
|
98
|
+
pdfDoc,
|
99
|
+
font,
|
100
|
+
_cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }>,
|
101
|
+
}),
|
102
|
+
getFontKitFont(schema.fontName, font, _cache as Map<string, FontKitFont>),
|
99
103
|
]);
|
100
104
|
const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
|
101
105
|
|
package/src/text/propPanel.ts
CHANGED
@@ -27,9 +27,9 @@ const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
|
27
27
|
|
28
28
|
const checkbox = document.createElement('input');
|
29
29
|
checkbox.type = 'checkbox';
|
30
|
-
checkbox.checked = Boolean((activeSchema as
|
31
|
-
checkbox.onchange = (e:
|
32
|
-
const val = e.target.checked
|
30
|
+
checkbox.checked = Boolean((activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize);
|
31
|
+
checkbox.onchange = (e: Event) => {
|
32
|
+
const val = (e.target as HTMLInputElement).checked
|
33
33
|
? {
|
34
34
|
min: DEFAULT_DYNAMIC_MIN_FONT_SIZE,
|
35
35
|
max: DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
@@ -54,7 +54,9 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
54
54
|
const fontNames = Object.keys(font);
|
55
55
|
const fallbackFontName = getFallbackFontName(font);
|
56
56
|
|
57
|
-
const enableDynamicFont = Boolean(
|
57
|
+
const enableDynamicFont = Boolean(
|
58
|
+
(activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize,
|
59
|
+
);
|
58
60
|
|
59
61
|
const textSchema: Record<string, PropPanelSchema> = {
|
60
62
|
fontName: {
|
package/src/text/uiRender.ts
CHANGED
@@ -69,7 +69,11 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
69
69
|
return text;
|
70
70
|
};
|
71
71
|
const font = options?.font || getDefaultFont();
|
72
|
-
const fontKitFont = await getFontKitFont(
|
72
|
+
const fontKitFont = await getFontKitFont(
|
73
|
+
schema.fontName,
|
74
|
+
font,
|
75
|
+
_cache as Map<string, import('fontkit').Font>,
|
76
|
+
);
|
73
77
|
const textBlock = buildStyledTextContainer(
|
74
78
|
arg,
|
75
79
|
fontKitFont,
|
@@ -96,8 +100,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
96
100
|
textBlock.tabIndex = tabIndex || 0;
|
97
101
|
textBlock.innerText = mode === 'designer' ? value : processedText;
|
98
102
|
textBlock.addEventListener('blur', (e: Event) => {
|
99
|
-
onChange
|
100
|
-
stopEditing
|
103
|
+
if (onChange) onChange({ key: 'content', value: getText(e.target as HTMLDivElement) });
|
104
|
+
if (stopEditing) stopEditing();
|
101
105
|
});
|
102
106
|
|
103
107
|
if (schema.dynamicFontSize) {
|
@@ -105,7 +109,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
105
109
|
|
106
110
|
textBlock.addEventListener('keyup', () => {
|
107
111
|
setTimeout(() => {
|
108
|
-
|
112
|
+
// Use a regular function instead of an async one since we don't need await
|
113
|
+
(() => {
|
109
114
|
if (!textBlock.textContent) return;
|
110
115
|
dynamicFontSize = calculateDynamicFontSize({
|
111
116
|
textSchema: schema,
|
@@ -159,8 +164,7 @@ export const buildStyledTextContainer = (
|
|
159
164
|
fontKitFont: FontKitFont,
|
160
165
|
value: string,
|
161
166
|
) => {
|
162
|
-
const { schema, rootElement, mode
|
163
|
-
const font = options?.font || getDefaultFont();
|
167
|
+
const { schema, rootElement, mode } = arg;
|
164
168
|
|
165
169
|
let dynamicFontSize: undefined | number = undefined;
|
166
170
|
|
@@ -278,7 +282,7 @@ export const mapVerticalAlignToFlex = (verticalAlignmentValue: string | undefine
|
|
278
282
|
return 'flex-start';
|
279
283
|
};
|
280
284
|
|
281
|
-
|
285
|
+
const getBackgroundColor = (value: string, schema: { backgroundColor?: string }) => {
|
282
286
|
if (!value || !schema.backgroundColor) return 'transparent';
|
283
287
|
return schema.backgroundColor;
|
284
288
|
};
|
package/src/utils.ts
CHANGED
@@ -162,7 +162,7 @@ export const readFile = (input: File | FileList | null): Promise<string | ArrayB
|
|
162
162
|
}
|
163
163
|
};
|
164
164
|
|
165
|
-
fileReader.onerror = (
|
165
|
+
fileReader.onerror = () => {
|
166
166
|
reject(new Error('[@pdfme/schemas] File reading failed'));
|
167
167
|
};
|
168
168
|
|
@@ -238,12 +238,16 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
|
|
238
238
|
.join(' ');
|
239
239
|
|
240
240
|
// Helper function to process a single element
|
241
|
-
const processElement = (element:
|
241
|
+
const processElement = (element: unknown): string => {
|
242
242
|
if (!Array.isArray(element)) {
|
243
243
|
return String(element);
|
244
244
|
}
|
245
245
|
|
246
|
-
const [tag, attributes = {}, children = []] = element
|
246
|
+
const [tag, attributes = {}, children = []] = element as [
|
247
|
+
unknown,
|
248
|
+
Record<string, string>,
|
249
|
+
unknown[],
|
250
|
+
];
|
247
251
|
const tagName = String(tag);
|
248
252
|
|
249
253
|
// Format attributes string
|
@@ -260,10 +264,10 @@ export const createSvgStr = (icon: IconNode, attrs?: Record<string, string>): st
|
|
260
264
|
|
261
265
|
// Return properly formatted element string
|
262
266
|
if (childrenString) {
|
263
|
-
return `<${tagName}${attrString ? ' ' + attrString : ''}>${childrenString}</${tagName}>`;
|
267
|
+
return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}>${childrenString}</${String(tagName)}>`;
|
264
268
|
} else {
|
265
269
|
// Self-closing tag for empty children
|
266
|
-
return `<${tagName}${attrString ? ' ' + attrString : ''}/>`;
|
270
|
+
return `<${String(tagName)}${attrString ? ' ' + String(attrString) : ''}/>`;
|
267
271
|
}
|
268
272
|
};
|
269
273
|
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAA1E,QAAA,WAAW,eAA+D"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cacheKey.js","sourceRoot":"","sources":["../../../../src/graphics/cacheKey.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;AAA1E,QAAA,WAAW,eAA+D"}
|
package/src/graphics/cacheKey.ts
DELETED