@pdfme/schemas 5.3.8-dev.6 → 5.3.8-dev.60
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__/barcode.test.js +115 -116
- package/dist/cjs/__tests__/barcode.test.js.map +1 -1
- package/dist/cjs/__tests__/multiVariableText.test.js +15 -15
- package/dist/cjs/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/cjs/__tests__/text.test.js +71 -71
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/__tests__/utils.test.js +76 -15
- package/dist/cjs/__tests__/utils.test.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +3 -3
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/checkbox/index.js +4 -4
- package/dist/cjs/src/checkbox/index.js.map +1 -1
- package/dist/cjs/src/date/date.js +2 -2
- package/dist/cjs/src/date/date.js.map +1 -1
- package/dist/cjs/src/date/dateTime.js +2 -2
- package/dist/cjs/src/date/dateTime.js.map +1 -1
- package/dist/cjs/src/date/helper.js +11 -11
- package/dist/cjs/src/date/helper.js.map +1 -1
- package/dist/cjs/src/date/time.js +2 -2
- package/dist/cjs/src/date/time.js.map +1 -1
- package/dist/cjs/src/graphics/svg.js +25 -2
- package/dist/cjs/src/graphics/svg.js.map +1 -1
- package/dist/cjs/src/index.js +30 -30
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/multiVariableText/helper.js +2 -2
- package/dist/cjs/src/multiVariableText/helper.js.map +1 -1
- package/dist/cjs/src/multiVariableText/pdfRender.js +5 -5
- package/dist/cjs/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/cjs/src/multiVariableText/propPanel.js +19 -14
- package/dist/cjs/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/cjs/src/multiVariableText/uiRender.js +24 -14
- package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/cjs/src/radioGroup/index.js +4 -4
- package/dist/cjs/src/radioGroup/index.js.map +1 -1
- package/dist/cjs/src/select/index.js +9 -9
- package/dist/cjs/src/select/index.js.map +1 -1
- package/dist/cjs/src/shapes/line.js +1 -1
- package/dist/cjs/src/shapes/rectAndEllipse.js +8 -4
- package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/cjs/src/tables/classes.js +4 -4
- package/dist/cjs/src/tables/classes.js.map +1 -1
- package/dist/cjs/src/tables/dynamicTemplate.js +2 -2
- package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/cjs/src/tables/helper.js +25 -25
- package/dist/cjs/src/tables/helper.js.map +1 -1
- package/dist/cjs/src/tables/pdfRender.js +8 -8
- package/dist/cjs/src/tables/pdfRender.js.map +1 -1
- package/dist/cjs/src/tables/tableHelper.js +5 -5
- package/dist/cjs/src/tables/tableHelper.js.map +1 -1
- package/dist/cjs/src/text/extraFormatter.js +14 -14
- package/dist/cjs/src/text/extraFormatter.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +1 -1
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +2 -2
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/cjs/src/utils.js +52 -12
- package/dist/cjs/src/utils.js.map +1 -1
- package/dist/esm/__tests__/barcode.test.js +10 -11
- package/dist/esm/__tests__/barcode.test.js.map +1 -1
- package/dist/esm/__tests__/multiVariableText.test.js +1 -1
- package/dist/esm/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +2 -2
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/__tests__/utils.test.js +65 -4
- package/dist/esm/__tests__/utils.test.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +3 -3
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/checkbox/index.js +2 -2
- package/dist/esm/src/checkbox/index.js.map +1 -1
- package/dist/esm/src/date/date.js +1 -1
- package/dist/esm/src/date/date.js.map +1 -1
- package/dist/esm/src/date/dateTime.js +1 -1
- package/dist/esm/src/date/dateTime.js.map +1 -1
- package/dist/esm/src/date/helper.js +4 -4
- package/dist/esm/src/date/helper.js.map +1 -1
- package/dist/esm/src/date/time.js +1 -1
- package/dist/esm/src/date/time.js.map +1 -1
- package/dist/esm/src/graphics/svg.js +25 -2
- package/dist/esm/src/graphics/svg.js.map +1 -1
- package/dist/esm/src/index.js +14 -14
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/multiVariableText/helper.js +2 -2
- package/dist/esm/src/multiVariableText/helper.js.map +1 -1
- package/dist/esm/src/multiVariableText/pdfRender.js +2 -2
- package/dist/esm/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/esm/src/multiVariableText/propPanel.js +15 -10
- package/dist/esm/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/esm/src/multiVariableText/uiRender.js +18 -8
- package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/esm/src/radioGroup/index.js +2 -2
- package/dist/esm/src/radioGroup/index.js.map +1 -1
- package/dist/esm/src/select/index.js +2 -2
- package/dist/esm/src/select/index.js.map +1 -1
- package/dist/esm/src/shapes/line.js +1 -1
- package/dist/esm/src/shapes/rectAndEllipse.js +8 -4
- package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/esm/src/tables/classes.js +1 -1
- package/dist/esm/src/tables/classes.js.map +1 -1
- package/dist/esm/src/tables/dynamicTemplate.js +1 -1
- package/dist/esm/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/esm/src/tables/helper.js +5 -5
- package/dist/esm/src/tables/helper.js.map +1 -1
- package/dist/esm/src/tables/pdfRender.js +4 -4
- package/dist/esm/src/tables/pdfRender.js.map +1 -1
- package/dist/esm/src/tables/tableHelper.js +1 -1
- package/dist/esm/src/tables/tableHelper.js.map +1 -1
- package/dist/esm/src/text/extraFormatter.js +2 -2
- package/dist/esm/src/text/extraFormatter.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +1 -1
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +1 -1
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/esm/src/utils.js +52 -12
- package/dist/esm/src/utils.js.map +1 -1
- package/dist/node/__tests__/barcode.test.js +115 -116
- package/dist/node/__tests__/barcode.test.js.map +1 -1
- package/dist/node/__tests__/multiVariableText.test.js +15 -15
- package/dist/node/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/node/__tests__/text.test.js +71 -71
- package/dist/node/__tests__/text.test.js.map +1 -1
- package/dist/node/__tests__/utils.test.js +76 -15
- package/dist/node/__tests__/utils.test.js.map +1 -1
- package/dist/node/src/barcodes/propPanel.js +3 -3
- package/dist/node/src/barcodes/propPanel.js.map +1 -1
- package/dist/node/src/checkbox/index.js +4 -4
- package/dist/node/src/checkbox/index.js.map +1 -1
- package/dist/node/src/date/date.js +2 -2
- package/dist/node/src/date/date.js.map +1 -1
- package/dist/node/src/date/dateTime.js +2 -2
- package/dist/node/src/date/dateTime.js.map +1 -1
- package/dist/node/src/date/helper.js +11 -11
- package/dist/node/src/date/helper.js.map +1 -1
- package/dist/node/src/date/time.js +2 -2
- package/dist/node/src/date/time.js.map +1 -1
- package/dist/node/src/graphics/svg.js +25 -2
- package/dist/node/src/graphics/svg.js.map +1 -1
- package/dist/node/src/index.js +30 -30
- package/dist/node/src/index.js.map +1 -1
- package/dist/node/src/multiVariableText/helper.js +2 -2
- package/dist/node/src/multiVariableText/helper.js.map +1 -1
- package/dist/node/src/multiVariableText/pdfRender.js +5 -5
- package/dist/node/src/multiVariableText/pdfRender.js.map +1 -1
- package/dist/node/src/multiVariableText/propPanel.js +19 -14
- package/dist/node/src/multiVariableText/propPanel.js.map +1 -1
- package/dist/node/src/multiVariableText/uiRender.js +24 -14
- package/dist/node/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/node/src/radioGroup/index.js +4 -4
- package/dist/node/src/radioGroup/index.js.map +1 -1
- package/dist/node/src/select/index.js +9 -9
- package/dist/node/src/select/index.js.map +1 -1
- package/dist/node/src/shapes/line.js +1 -1
- package/dist/node/src/shapes/rectAndEllipse.js +8 -4
- package/dist/node/src/shapes/rectAndEllipse.js.map +1 -1
- package/dist/node/src/tables/classes.js +4 -4
- package/dist/node/src/tables/classes.js.map +1 -1
- package/dist/node/src/tables/dynamicTemplate.js +2 -2
- package/dist/node/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/node/src/tables/helper.js +25 -25
- package/dist/node/src/tables/helper.js.map +1 -1
- package/dist/node/src/tables/pdfRender.js +8 -8
- package/dist/node/src/tables/pdfRender.js.map +1 -1
- package/dist/node/src/tables/tableHelper.js +5 -5
- package/dist/node/src/tables/tableHelper.js.map +1 -1
- package/dist/node/src/text/extraFormatter.js +14 -14
- package/dist/node/src/text/extraFormatter.js.map +1 -1
- package/dist/node/src/text/pdfRender.js +1 -1
- package/dist/node/src/text/pdfRender.js.map +1 -1
- package/dist/node/src/text/propPanel.js +2 -2
- package/dist/node/src/text/propPanel.js.map +1 -1
- package/dist/node/src/text/uiRender.js.map +1 -1
- package/dist/node/src/utils.js +52 -12
- package/dist/node/src/utils.js.map +1 -1
- package/dist/types/src/barcodes/helper.d.ts +1 -1
- package/dist/types/src/barcodes/index.d.ts +1 -1
- package/dist/types/src/barcodes/pdfRender.d.ts +1 -1
- package/dist/types/src/barcodes/propPanel.d.ts +1 -1
- package/dist/types/src/barcodes/uiRender.d.ts +1 -1
- package/dist/types/src/date/date.d.ts +1 -1
- package/dist/types/src/date/dateTime.d.ts +1 -1
- package/dist/types/src/date/helper.d.ts +1 -1
- package/dist/types/src/date/time.d.ts +1 -1
- package/dist/types/src/date/types.d.ts +6 -1
- package/dist/types/src/index.d.ts +15 -15
- package/dist/types/src/multiVariableText/helper.d.ts +1 -1
- package/dist/types/src/multiVariableText/index.d.ts +1 -1
- package/dist/types/src/multiVariableText/pdfRender.d.ts +1 -1
- package/dist/types/src/multiVariableText/propPanel.d.ts +1 -1
- package/dist/types/src/multiVariableText/types.d.ts +1 -1
- package/dist/types/src/multiVariableText/uiRender.d.ts +1 -1
- package/dist/types/src/select/index.d.ts +1 -1
- package/dist/types/src/tables/cell.d.ts +1 -1
- package/dist/types/src/tables/classes.d.ts +1 -1
- package/dist/types/src/tables/helper.d.ts +4 -4
- package/dist/types/src/tables/pdfRender.d.ts +1 -1
- package/dist/types/src/tables/propPanel.d.ts +1 -1
- package/dist/types/src/tables/tableHelper.d.ts +1 -1
- package/dist/types/src/tables/types.d.ts +1 -1
- package/dist/types/src/text/constants.d.ts +1 -1
- package/dist/types/src/text/helper.d.ts +1 -1
- package/dist/types/src/text/index.d.ts +1 -1
- package/dist/types/src/text/pdfRender.d.ts +1 -1
- package/dist/types/src/text/propPanel.d.ts +1 -1
- package/dist/types/src/text/uiRender.d.ts +1 -1
- package/eslint.config.mjs +22 -0
- package/package.json +3 -4
- package/src/barcodes/helper.ts +2 -3
- package/src/barcodes/index.ts +2 -2
- package/src/barcodes/pdfRender.ts +2 -2
- package/src/barcodes/propPanel.ts +4 -5
- package/src/barcodes/uiRender.ts +1 -1
- package/src/checkbox/index.ts +2 -2
- package/src/date/date.ts +1 -1
- package/src/date/dateTime.ts +1 -1
- package/src/date/helper.ts +20 -13
- package/src/date/time.ts +1 -1
- package/src/date/types.ts +7 -1
- package/src/graphics/imagehelper.ts +1 -1
- package/src/graphics/svg.ts +27 -2
- package/src/index.ts +14 -14
- package/src/multiVariableText/helper.ts +15 -7
- package/src/multiVariableText/index.ts +1 -1
- package/src/multiVariableText/pdfRender.ts +3 -3
- package/src/multiVariableText/propPanel.ts +19 -16
- package/src/multiVariableText/types.ts +1 -1
- package/src/multiVariableText/uiRender.ts +26 -23
- package/src/radioGroup/index.ts +3 -3
- package/src/select/index.ts +4 -4
- package/src/shapes/line.ts +1 -1
- package/src/shapes/rectAndEllipse.ts +10 -4
- package/src/tables/cell.ts +5 -5
- package/src/tables/classes.ts +7 -7
- package/src/tables/dynamicTemplate.ts +3 -3
- package/src/tables/helper.ts +7 -7
- package/src/tables/pdfRender.ts +9 -9
- package/src/tables/propPanel.ts +1 -1
- package/src/tables/tableHelper.ts +15 -12
- package/src/tables/types.ts +1 -1
- package/src/tables/uiRender.ts +6 -6
- package/src/text/constants.ts +1 -1
- package/src/text/extraFormatter.ts +2 -2
- package/src/text/helper.ts +6 -6
- package/src/text/index.ts +1 -1
- package/src/text/pdfRender.ts +4 -4
- package/src/text/propPanel.ts +2 -2
- package/src/text/uiRender.ts +14 -6
- package/src/utils.ts +60 -15
- package/tsconfig.esm.json +2 -1
- package/.eslintrc.cjs +0 -3
package/src/index.ts
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
import multiVariableText from './multiVariableText/index';
|
2
|
-
import text from './text/index';
|
3
|
-
import image from './graphics/image';
|
4
|
-
import svg from './graphics/svg';
|
5
|
-
import barcodes from './barcodes/index';
|
6
|
-
import line from './shapes/line';
|
7
|
-
import table from './tables/index';
|
8
|
-
import { rectangle, ellipse } from './shapes/rectAndEllipse';
|
9
|
-
import dateTime from './date/dateTime';
|
10
|
-
import date from './date/date';
|
11
|
-
import time from './date/time';
|
12
|
-
import select from './select/index';
|
13
|
-
import radioGroup from './radioGroup/index';
|
14
|
-
import checkbox from './checkbox/index';
|
1
|
+
import multiVariableText from './multiVariableText/index.js';
|
2
|
+
import text from './text/index.js';
|
3
|
+
import image from './graphics/image.js';
|
4
|
+
import svg from './graphics/svg.js';
|
5
|
+
import barcodes from './barcodes/index.js';
|
6
|
+
import line from './shapes/line.js';
|
7
|
+
import table from './tables/index.js';
|
8
|
+
import { rectangle, ellipse } from './shapes/rectAndEllipse.js';
|
9
|
+
import dateTime from './date/dateTime.js';
|
10
|
+
import date from './date/date.js';
|
11
|
+
import time from './date/time.js';
|
12
|
+
import select from './select/index.js';
|
13
|
+
import radioGroup from './radioGroup/index.js';
|
14
|
+
import checkbox from './checkbox/index.js';
|
15
15
|
|
16
16
|
const builtInPlugins = { Text: text };
|
17
17
|
|
@@ -1,14 +1,18 @@
|
|
1
|
-
import { MultiVariableTextSchema } from
|
1
|
+
import { MultiVariableTextSchema } from './types.js';
|
2
2
|
|
3
|
-
export const substituteVariables = (
|
3
|
+
export const substituteVariables = (
|
4
|
+
text: string,
|
5
|
+
variablesIn: string | Record<string, string>,
|
6
|
+
): string => {
|
4
7
|
if (!text) {
|
5
|
-
return
|
8
|
+
return '';
|
6
9
|
}
|
7
10
|
|
8
11
|
let substitutedText = text;
|
9
12
|
|
10
13
|
if (variablesIn) {
|
11
|
-
const variables: Record<string, string> =
|
14
|
+
const variables: Record<string, string> =
|
15
|
+
typeof variablesIn === 'string' ? JSON.parse(variablesIn) || {} : variablesIn;
|
12
16
|
|
13
17
|
Object.keys(variables).forEach((variableName) => {
|
14
18
|
// handle special characters in variable name
|
@@ -33,13 +37,17 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
|
|
33
37
|
try {
|
34
38
|
values = value ? JSON.parse(value) : {};
|
35
39
|
} catch (e) {
|
36
|
-
throw new SyntaxError(
|
40
|
+
throw new SyntaxError(
|
41
|
+
`[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`,
|
42
|
+
);
|
37
43
|
}
|
38
44
|
|
39
45
|
for (const variable of schema.variables) {
|
40
46
|
if (!values[variable]) {
|
41
47
|
if (schema.required) {
|
42
|
-
throw new Error(
|
48
|
+
throw new Error(
|
49
|
+
`[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`,
|
50
|
+
);
|
43
51
|
}
|
44
52
|
// If not required, then simply don't render this field if an input is missing
|
45
53
|
return false;
|
@@ -47,4 +55,4 @@ export const validateVariables = (value: string, schema: MultiVariableTextSchema
|
|
47
55
|
}
|
48
56
|
|
49
57
|
return true;
|
50
|
-
}
|
58
|
+
};
|
@@ -2,7 +2,7 @@ import type { Plugin } from '@pdfme/common';
|
|
2
2
|
import { pdfRender } from './pdfRender.js';
|
3
3
|
import { propPanel } from './propPanel.js';
|
4
4
|
import { uiRender } from './uiRender.js';
|
5
|
-
import type { MultiVariableTextSchema } from './types';
|
5
|
+
import type { MultiVariableTextSchema } from './types.js';
|
6
6
|
import { Type } from 'lucide';
|
7
7
|
import { createSvgStr } from '../utils.js';
|
8
8
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PDFRenderProps } from '@pdfme/common';
|
2
|
-
import { MultiVariableTextSchema } from './types';
|
3
|
-
import { pdfRender as parentPdfRender } from '../text/pdfRender';
|
4
|
-
import { substituteVariables, validateVariables } from './helper';
|
2
|
+
import { MultiVariableTextSchema } from './types.js';
|
3
|
+
import { pdfRender as parentPdfRender } from '../text/pdfRender.js';
|
4
|
+
import { substituteVariables, validateVariables } from './helper.js';
|
5
5
|
|
6
6
|
export const pdfRender = async (arg: PDFRenderProps<MultiVariableTextSchema>) => {
|
7
7
|
const { value, schema, ...rest } = arg;
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { propPanel as parentPropPanel } from '../text/propPanel';
|
1
|
+
import { propPanel as parentPropPanel } from '../text/propPanel.js';
|
2
2
|
import { PropPanel, PropPanelWidgetProps } from '@pdfme/common';
|
3
|
-
import { MultiVariableTextSchema } from './types';
|
3
|
+
import { MultiVariableTextSchema } from './types.js';
|
4
4
|
|
5
5
|
const mapDynamicVariables = (props: PropPanelWidgetProps) => {
|
6
6
|
const { rootElement, changeSchemas, activeSchema, i18n, options } = props;
|
7
7
|
|
8
|
-
const mvtSchema =
|
8
|
+
const mvtSchema = activeSchema as any;
|
9
9
|
const text = mvtSchema.text || '';
|
10
10
|
const variables = JSON.parse(mvtSchema.content) || {};
|
11
11
|
const variablesChanged = updateVariablesFromText(text, variables);
|
@@ -14,11 +14,13 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
|
|
14
14
|
if (variablesChanged) {
|
15
15
|
changeSchemas([
|
16
16
|
{ key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
|
17
|
-
{ key: 'variables', value: varNames, schemaId: activeSchema.id }
|
17
|
+
{ key: 'variables', value: varNames, schemaId: activeSchema.id },
|
18
18
|
]);
|
19
19
|
}
|
20
20
|
|
21
|
-
const placeholderRowEl = document
|
21
|
+
const placeholderRowEl = document
|
22
|
+
.getElementById('placeholder-dynamic-var')
|
23
|
+
?.closest('.ant-form-item') as HTMLElement;
|
22
24
|
if (!placeholderRowEl) {
|
23
25
|
throw new Error('Failed to find Ant form placeholder row to create dynamic variables inputs.');
|
24
26
|
}
|
@@ -36,10 +38,12 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
|
|
36
38
|
textarea.value = variables[variableName];
|
37
39
|
textarea.addEventListener('change', (e: Event) => {
|
38
40
|
variables[variableName] = (e.target as HTMLTextAreaElement).value;
|
39
|
-
changeSchemas([
|
41
|
+
changeSchemas([
|
42
|
+
{ key: 'content', value: JSON.stringify(variables), schemaId: activeSchema.id },
|
43
|
+
]);
|
40
44
|
});
|
41
45
|
|
42
|
-
const label = varRow.querySelector('label') as HTMLLabelElement
|
46
|
+
const label = varRow.querySelector('label') as HTMLLabelElement;
|
43
47
|
label.innerText = variableName;
|
44
48
|
|
45
49
|
varRow.style.display = 'block';
|
@@ -47,10 +51,11 @@ const mapDynamicVariables = (props: PropPanelWidgetProps) => {
|
|
47
51
|
}
|
48
52
|
} else {
|
49
53
|
const para = document.createElement('p');
|
50
|
-
para.innerHTML =
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
para.innerHTML =
|
55
|
+
i18n('schemas.mvt.typingInstructions') +
|
56
|
+
` <code style="color:${options?.theme?.token?.colorPrimary || '#168fe3'}; font-weight:bold;">{` +
|
57
|
+
i18n('schemas.mvt.sampleField') +
|
58
|
+
'}</code>';
|
54
59
|
rootElement.appendChild(para);
|
55
60
|
}
|
56
61
|
};
|
@@ -73,7 +78,7 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
|
|
73
78
|
type: 'object',
|
74
79
|
widget: 'mapDynamicVariables',
|
75
80
|
bind: false,
|
76
|
-
span: 24
|
81
|
+
span: 24,
|
77
82
|
},
|
78
83
|
placeholderDynamicVar: {
|
79
84
|
title: 'Placeholder Dynamic Variable',
|
@@ -88,9 +93,8 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
|
|
88
93
|
},
|
89
94
|
span: 24,
|
90
95
|
},
|
91
|
-
}
|
96
|
+
},
|
92
97
|
},
|
93
|
-
|
94
98
|
};
|
95
99
|
},
|
96
100
|
widgets: { ...parentPropPanel.widgets, mapDynamicVariables },
|
@@ -106,7 +110,6 @@ export const propPanel: PropPanel<MultiVariableTextSchema> = {
|
|
106
110
|
},
|
107
111
|
};
|
108
112
|
|
109
|
-
|
110
113
|
const updateVariablesFromText = (text: string, variables: any): boolean => {
|
111
114
|
const regex = /\{([^{}]+)}/g;
|
112
115
|
const matches = text.match(regex);
|
@@ -138,4 +141,4 @@ const updateVariablesFromText = (text: string, variables: any): boolean => {
|
|
138
141
|
}
|
139
142
|
|
140
143
|
return changed;
|
141
|
-
}
|
144
|
+
};
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { getDefaultFont, UIRenderProps } from '@pdfme/common';
|
2
|
-
import { MultiVariableTextSchema } from './types';
|
2
|
+
import { MultiVariableTextSchema } from './types.js';
|
3
3
|
import {
|
4
4
|
uiRender as parentUiRender,
|
5
5
|
buildStyledTextContainer,
|
6
|
-
makeElementPlainTextContentEditable
|
7
|
-
} from '../text/uiRender';
|
8
|
-
import { isEditable } from '../utils';
|
9
|
-
import { getFontKitFont } from '../text/helper';
|
10
|
-
import { substituteVariables } from './helper';
|
6
|
+
makeElementPlainTextContentEditable,
|
7
|
+
} from '../text/uiRender.js';
|
8
|
+
import { isEditable } from '../utils.js';
|
9
|
+
import { getFontKitFont } from '../text/helper.js';
|
10
|
+
import { substituteVariables } from './helper.js';
|
11
11
|
|
12
12
|
export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
13
13
|
const { value, schema, rootElement, mode, onChange, ...rest } = arg;
|
@@ -25,10 +25,14 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
25
25
|
schema,
|
26
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: any
|
28
|
+
onChange: (arg: { key: string; value: any } | { key: string; value: any }[]) => {
|
29
29
|
if (!Array.isArray(arg)) {
|
30
30
|
const numVariables = countUniqueVariableNames(arg.value);
|
31
|
-
onChange &&
|
31
|
+
onChange &&
|
32
|
+
onChange([
|
33
|
+
{ key: 'text', value: arg.value },
|
34
|
+
{ key: 'readOnly', value: numVariables == 0 },
|
35
|
+
]);
|
32
36
|
} else {
|
33
37
|
throw new Error('onChange is not an array, the parent text plugin has changed...');
|
34
38
|
}
|
@@ -49,7 +53,10 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
49
53
|
if (numVariables !== newNumVariables) {
|
50
54
|
// If variables were modified during this keypress, we trigger a change
|
51
55
|
if (onChange) {
|
52
|
-
onChange([
|
56
|
+
onChange([
|
57
|
+
{ key: 'text', value: text },
|
58
|
+
{ key: 'readOnly', value: newNumVariables == 0 },
|
59
|
+
]);
|
53
60
|
}
|
54
61
|
numVariables = newNumVariables;
|
55
62
|
}
|
@@ -59,16 +66,7 @@ export const uiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
59
66
|
};
|
60
67
|
|
61
68
|
const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
62
|
-
const {
|
63
|
-
value,
|
64
|
-
schema,
|
65
|
-
rootElement,
|
66
|
-
onChange,
|
67
|
-
stopEditing,
|
68
|
-
theme,
|
69
|
-
_cache,
|
70
|
-
options,
|
71
|
-
} = arg;
|
69
|
+
const { value, schema, rootElement, onChange, stopEditing, theme, _cache, options } = arg;
|
72
70
|
const rawText = schema.text;
|
73
71
|
|
74
72
|
if (rootElement.parentElement) {
|
@@ -92,7 +90,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
92
90
|
inVarString = true;
|
93
91
|
let span = document.createElement('span');
|
94
92
|
span.style.outline = `${theme.colorPrimary} dashed 1px`;
|
95
|
-
makeElementPlainTextContentEditable(span)
|
93
|
+
makeElementPlainTextContentEditable(span);
|
96
94
|
span.textContent = variables[variableIndices[i]];
|
97
95
|
span.addEventListener('blur', (e: Event) => {
|
98
96
|
const newValue = (e.target as HTMLSpanElement).textContent || '';
|
@@ -114,7 +112,7 @@ const formUiRender = async (arg: UIRenderProps<MultiVariableTextSchema>) => {
|
|
114
112
|
textBlock.appendChild(span);
|
115
113
|
}
|
116
114
|
}
|
117
|
-
}
|
115
|
+
};
|
118
116
|
|
119
117
|
const getVariableIndices = (content: string) => {
|
120
118
|
const regex = /\{([^}]+)}/g;
|
@@ -146,7 +144,12 @@ const countUniqueVariableNames = (content: string) => {
|
|
146
144
|
* Regex would otherwise be performed on every key press (which isn't terrible, but this code helps).
|
147
145
|
*/
|
148
146
|
const keyPressShouldBeChecked = (event: KeyboardEvent) => {
|
149
|
-
if (
|
147
|
+
if (
|
148
|
+
event.key == 'ArrowUp' ||
|
149
|
+
event.key == 'ArrowDown' ||
|
150
|
+
event.key == 'ArrowLeft' ||
|
151
|
+
event.key == 'ArrowRight'
|
152
|
+
) {
|
150
153
|
return false;
|
151
154
|
}
|
152
155
|
|
@@ -164,4 +167,4 @@ const keyPressShouldBeChecked = (event: KeyboardEvent) => {
|
|
164
167
|
}
|
165
168
|
|
166
169
|
return true;
|
167
|
-
}
|
170
|
+
};
|
package/src/radioGroup/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Plugin } from '@pdfme/common';
|
2
2
|
import { Schema } from '@pdfme/common';
|
3
3
|
import { Circle, CircleDot } from 'lucide';
|
4
|
-
import svg from '../graphics/svg';
|
4
|
+
import svg from '../graphics/svg.js';
|
5
5
|
import { isEditable, createSvgStr } from '../utils.js';
|
6
6
|
import { HEX_COLOR_PATTERN } from '../constants.js';
|
7
7
|
|
@@ -65,7 +65,7 @@ const schema: Plugin<RadioGroup> = {
|
|
65
65
|
onChange({ key: 'content', value: 'true' });
|
66
66
|
radioButtonStates.set(schema.name, { value: 'true', onChange });
|
67
67
|
eventEmitter.dispatchEvent(
|
68
|
-
new CustomEvent(`group-${schema.group}`, { detail: schema.name })
|
68
|
+
new CustomEvent(`group-${schema.group}`, { detail: schema.name }),
|
69
69
|
);
|
70
70
|
}
|
71
71
|
});
|
@@ -89,7 +89,7 @@ const schema: Plugin<RadioGroup> = {
|
|
89
89
|
type: 'string',
|
90
90
|
widget: 'color',
|
91
91
|
props: {
|
92
|
-
disabledAlpha: true
|
92
|
+
disabledAlpha: true,
|
93
93
|
},
|
94
94
|
required: true,
|
95
95
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
package/src/select/index.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import type * as CSS from 'csstype';
|
2
|
-
import { propPanel as parentPropPanel } from '../text/propPanel';
|
2
|
+
import { propPanel as parentPropPanel } from '../text/propPanel.js';
|
3
3
|
import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common';
|
4
|
-
import text from '../text';
|
5
|
-
import { TextSchema } from '../text/types';
|
4
|
+
import text from '../text/index.js';
|
5
|
+
import { TextSchema } from '../text/types.js';
|
6
6
|
import { ChevronDown } from 'lucide';
|
7
7
|
import { createSvgStr } from '../utils.js';
|
8
8
|
|
@@ -157,7 +157,7 @@ const schema: Plugin<Select> = {
|
|
157
157
|
selectElement.innerHTML = schema.options
|
158
158
|
.map(
|
159
159
|
(option) =>
|
160
|
-
`<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option
|
160
|
+
`<option value="${option}" ${option === value ? 'selected' : ''}>${option}</option>`,
|
161
161
|
)
|
162
162
|
.join('');
|
163
163
|
rootElement.appendChild(selectElement);
|
package/src/shapes/line.ts
CHANGED
@@ -58,8 +58,14 @@ const shape: Plugin<ShapeSchema> = {
|
|
58
58
|
});
|
59
59
|
} else if (schema.type === 'rectangle') {
|
60
60
|
page.drawRectangle({
|
61
|
-
x:
|
62
|
-
|
61
|
+
x:
|
62
|
+
position.x +
|
63
|
+
borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) +
|
64
|
+
Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
65
|
+
y:
|
66
|
+
position.y +
|
67
|
+
borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) +
|
68
|
+
Math.tan(toRadians(rotate)) * Math.PI ** 2,
|
63
69
|
width: width - borderWidth,
|
64
70
|
height: height - borderWidth,
|
65
71
|
...drawOptions,
|
@@ -80,7 +86,7 @@ const shape: Plugin<ShapeSchema> = {
|
|
80
86
|
type: 'string',
|
81
87
|
widget: 'color',
|
82
88
|
props: {
|
83
|
-
disabledAlpha: true
|
89
|
+
disabledAlpha: true,
|
84
90
|
},
|
85
91
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
86
92
|
},
|
@@ -89,7 +95,7 @@ const shape: Plugin<ShapeSchema> = {
|
|
89
95
|
type: 'string',
|
90
96
|
widget: 'color',
|
91
97
|
props: {
|
92
|
-
disabledAlpha: true
|
98
|
+
disabledAlpha: true,
|
93
99
|
},
|
94
100
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
95
101
|
},
|
package/src/tables/cell.ts
CHANGED
@@ -9,7 +9,7 @@ import { uiRender as textUiRender } from '../text/uiRender.js';
|
|
9
9
|
import { pdfRender as textPdfRender } from '../text/pdfRender.js';
|
10
10
|
import line from '../shapes/line.js';
|
11
11
|
import { rectangle } from '../shapes/rectAndEllipse.js';
|
12
|
-
import type { CellSchema } from './types';
|
12
|
+
import type { CellSchema } from './types.js';
|
13
13
|
import { getCellPropPanelSchema, getDefaultCellStyles } from './helper.js';
|
14
14
|
const linePdfRender = line.pdf;
|
15
15
|
const rectanglePdfRender = rectangle.pdf;
|
@@ -19,7 +19,7 @@ const renderLine = async (
|
|
19
19
|
schema: CellSchema,
|
20
20
|
position: { x: number; y: number },
|
21
21
|
width: number,
|
22
|
-
height: number
|
22
|
+
height: number,
|
23
23
|
) =>
|
24
24
|
linePdfRender({
|
25
25
|
...arg,
|
@@ -45,7 +45,7 @@ const createLineDiv = (
|
|
45
45
|
right: string | null,
|
46
46
|
bottom: string | null,
|
47
47
|
left: string | null,
|
48
|
-
borderColor: string
|
48
|
+
borderColor: string,
|
49
49
|
) => {
|
50
50
|
const div = document.createElement('div');
|
51
51
|
div.style.width = width;
|
@@ -86,7 +86,7 @@ const cellSchema: Plugin<CellSchema> = {
|
|
86
86
|
schema,
|
87
87
|
{ x: position.x + width - borderWidth.right, y: position.y },
|
88
88
|
borderWidth.right,
|
89
|
-
height
|
89
|
+
height,
|
90
90
|
),
|
91
91
|
// BOTTOM
|
92
92
|
renderLine(
|
@@ -94,7 +94,7 @@ const cellSchema: Plugin<CellSchema> = {
|
|
94
94
|
schema,
|
95
95
|
{ x: position.x, y: position.y + height - borderWidth.bottom },
|
96
96
|
width,
|
97
|
-
borderWidth.bottom
|
97
|
+
borderWidth.bottom,
|
98
98
|
),
|
99
99
|
// LEFT
|
100
100
|
renderLine(arg, schema, { x: position.x, y: position.y }, borderWidth.left, height),
|
package/src/tables/classes.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Font, mm2pt, pt2mm } from '@pdfme/common';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
|
-
import { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper';
|
4
|
-
import type { Styles, TableInput, Settings, Section, StylesProps } from './types';
|
3
|
+
import { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper.js';
|
4
|
+
import type { Styles, TableInput, Settings, Section, StylesProps } from './types.js';
|
5
5
|
|
6
6
|
type ContentSettings = { body: Row[]; head: Row[]; columns: Column[] };
|
7
7
|
|
@@ -175,7 +175,7 @@ async function calculateWidths(arg: { table: Table; font: Font; _cache: Map<any,
|
|
175
175
|
// first resize attempt: with respect to minReadableWidth and minWidth
|
176
176
|
if (resizeWidth) {
|
177
177
|
resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) =>
|
178
|
-
Math.max(column.minReadableWidth, column.minWidth)
|
178
|
+
Math.max(column.minReadableWidth, column.minWidth),
|
179
179
|
);
|
180
180
|
}
|
181
181
|
|
@@ -257,7 +257,7 @@ function applyColSpans(table: Table) {
|
|
257
257
|
|
258
258
|
async function fitContent(
|
259
259
|
table: Table,
|
260
|
-
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont
|
260
|
+
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
|
261
261
|
) {
|
262
262
|
const rowSpanHeight = { count: 0, height: 0 };
|
263
263
|
for (const row of table.allRows()) {
|
@@ -293,7 +293,7 @@ async function fitContent(
|
|
293
293
|
function resizeColumns(
|
294
294
|
columns: Column[],
|
295
295
|
resizeWidth: number,
|
296
|
-
getMinWidth: (column: Column) => number
|
296
|
+
getMinWidth: (column: Column) => number,
|
297
297
|
) {
|
298
298
|
const initialResizeWidth = resizeWidth;
|
299
299
|
const sumWrappedWidth = columns.reduce((acc, column) => acc + column.wrappedWidth, 0);
|
@@ -333,7 +333,7 @@ function resizeColumns(
|
|
333
333
|
|
334
334
|
async function calculate(
|
335
335
|
table: Table,
|
336
|
-
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont
|
336
|
+
getFontKitFontByFontName: (fontName: string | undefined) => Promise<FontKitFont>,
|
337
337
|
) {
|
338
338
|
for (const row of table.allRows()) {
|
339
339
|
for (const column of table.columns) {
|
@@ -347,7 +347,7 @@ async function calculate(
|
|
347
347
|
|
348
348
|
const longestWordWidth = getStringWidth(
|
349
349
|
Object.assign(cell, { text: cell.text.join(' ').split(/\s+/) }),
|
350
|
-
fontKitFont
|
350
|
+
fontKitFont,
|
351
351
|
);
|
352
352
|
cell.minReadableWidth = longestWordWidth + hPadding;
|
353
353
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema, BasePdf, CommonOptions } from '@pdfme/common';
|
2
|
-
import { createSingleTable } from './tableHelper';
|
2
|
+
import { createSingleTable } from './tableHelper.js';
|
3
3
|
import { getBodyWithRange, getBody } from './helper.js';
|
4
|
-
import { TableSchema } from './types';
|
4
|
+
import { TableSchema } from './types.js';
|
5
5
|
|
6
6
|
export const getDynamicHeightsForTable = async (
|
7
7
|
value: string,
|
@@ -10,7 +10,7 @@ export const getDynamicHeightsForTable = async (
|
|
10
10
|
basePdf: BasePdf;
|
11
11
|
options: CommonOptions;
|
12
12
|
_cache: Map<any, any>;
|
13
|
-
}
|
13
|
+
},
|
14
14
|
): Promise<number[]> => {
|
15
15
|
if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
|
16
16
|
const schema = args.schema as TableSchema;
|
package/src/tables/helper.ts
CHANGED
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
VERTICAL_ALIGN_TOP,
|
11
11
|
VERTICAL_ALIGN_MIDDLE,
|
12
12
|
VERTICAL_ALIGN_BOTTOM,
|
13
|
-
} from '../text/constants';
|
13
|
+
} from '../text/constants.js';
|
14
14
|
import { HEX_COLOR_PATTERN } from '../constants.js';
|
15
15
|
|
16
16
|
export const getDefaultCellStyles = () => ({
|
@@ -112,7 +112,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
112
112
|
type: 'string',
|
113
113
|
widget: 'color',
|
114
114
|
props: {
|
115
|
-
disabledAlpha: true
|
115
|
+
disabledAlpha: true,
|
116
116
|
},
|
117
117
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
118
118
|
},
|
@@ -121,7 +121,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
121
121
|
type: 'string',
|
122
122
|
widget: 'color',
|
123
123
|
props: {
|
124
|
-
disabledAlpha: true
|
124
|
+
disabledAlpha: true,
|
125
125
|
},
|
126
126
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
127
127
|
},
|
@@ -130,7 +130,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
130
130
|
type: 'string',
|
131
131
|
widget: 'color',
|
132
132
|
props: {
|
133
|
-
disabledAlpha: true
|
133
|
+
disabledAlpha: true,
|
134
134
|
},
|
135
135
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
136
136
|
},
|
@@ -141,7 +141,7 @@ export const getCellPropPanelSchema = (arg: {
|
|
141
141
|
type: 'string',
|
142
142
|
widget: 'color',
|
143
143
|
props: {
|
144
|
-
disabledAlpha: true
|
144
|
+
disabledAlpha: true,
|
145
145
|
},
|
146
146
|
rules: [{ pattern: HEX_COLOR_PATTERN, message: i18n('validation.hexColor') }],
|
147
147
|
},
|
@@ -194,7 +194,7 @@ export const getColumnStylesPropPanelSchema = ({
|
|
194
194
|
},
|
195
195
|
},
|
196
196
|
}),
|
197
|
-
{}
|
197
|
+
{},
|
198
198
|
),
|
199
199
|
},
|
200
200
|
});
|
@@ -208,7 +208,7 @@ export const getBody = (value: string | string[][]): string[][] => {
|
|
208
208
|
|
209
209
|
export const getBodyWithRange = (
|
210
210
|
value: string | string[][],
|
211
|
-
range?: { start: number; end?: number | undefined }
|
211
|
+
range?: { start: number; end?: number | undefined },
|
212
212
|
) => {
|
213
213
|
const body = getBody(value);
|
214
214
|
if (!range) return body;
|
package/src/tables/pdfRender.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { TableSchema } from './types';
|
1
|
+
import type { TableSchema } from './types.js';
|
2
2
|
import type { PDFRenderProps } from '@pdfme/common';
|
3
|
-
import { Cell, Table, Row, Column } from './classes';
|
4
|
-
import { rectangle } from '../shapes/rectAndEllipse';
|
5
|
-
import cell from './cell';
|
6
|
-
import { getBodyWithRange } from './helper';
|
7
|
-
import { createSingleTable } from './tableHelper';
|
3
|
+
import { Cell, Table, Row, Column } from './classes.js';
|
4
|
+
import { rectangle } from '../shapes/rectAndEllipse.js';
|
5
|
+
import cell from './cell.js';
|
6
|
+
import { getBodyWithRange } from './helper.js';
|
7
|
+
import { createSingleTable } from './tableHelper.js';
|
8
8
|
|
9
9
|
type Pos = { x: number; y: number };
|
10
10
|
|
@@ -41,7 +41,7 @@ async function drawRow(
|
|
41
41
|
table: Table,
|
42
42
|
row: Row,
|
43
43
|
cursor: Pos,
|
44
|
-
columns: Column[]
|
44
|
+
columns: Column[],
|
45
45
|
) {
|
46
46
|
cursor.x = table.settings.margin.left;
|
47
47
|
for (const column of columns) {
|
@@ -65,7 +65,7 @@ async function drawTableBorder(
|
|
65
65
|
arg: PDFRenderProps<TableSchema>,
|
66
66
|
table: Table,
|
67
67
|
startPos: Pos,
|
68
|
-
cursor: Pos
|
68
|
+
cursor: Pos,
|
69
69
|
) {
|
70
70
|
const lineWidth = table.settings.tableLineWidth;
|
71
71
|
const lineColor = table.settings.tableLineColor;
|
@@ -112,7 +112,7 @@ export const pdfRender = async (arg: PDFRenderProps<TableSchema>) => {
|
|
112
112
|
|
113
113
|
const body = getBodyWithRange(
|
114
114
|
typeof value !== 'string' ? JSON.stringify(value || '[]') : value,
|
115
|
-
schema.__bodyRange
|
115
|
+
schema.__bodyRange,
|
116
116
|
);
|
117
117
|
const table = await createSingleTable(body, arg);
|
118
118
|
await drawTable(arg, table);
|
package/src/tables/propPanel.ts
CHANGED