@pdfme/schemas 4.3.2-dev.1 → 4.3.2-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.
- package/dist/cjs/__tests__/multiVariableText.test.js +10 -0
- package/dist/cjs/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/cjs/src/index.js +2 -3
- 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/tables/dynamicTemplate.js +5 -61
- package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/cjs/src/tables/tableHelper.js +10 -50
- package/dist/cjs/src/tables/tableHelper.js.map +1 -1
- package/dist/cjs/src/tables/uiRender.js +16 -15
- package/dist/cjs/src/tables/uiRender.js.map +1 -1
- package/dist/cjs/src/utils.js +1 -3
- package/dist/cjs/src/utils.js.map +1 -1
- package/dist/esm/__tests__/multiVariableText.test.js +10 -0
- package/dist/esm/__tests__/multiVariableText.test.js.map +1 -1
- package/dist/esm/src/index.js +4 -2
- 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/tables/dynamicTemplate.js +4 -59
- package/dist/esm/src/tables/dynamicTemplate.js.map +1 -1
- package/dist/esm/src/tables/tableHelper.js +10 -49
- package/dist/esm/src/tables/tableHelper.js.map +1 -1
- package/dist/esm/src/tables/uiRender.js +16 -15
- package/dist/esm/src/tables/uiRender.js.map +1 -1
- package/dist/esm/src/utils.js +0 -1
- package/dist/esm/src/utils.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/tables/dynamicTemplate.d.ts +3 -9
- package/dist/types/src/tables/tableHelper.d.ts +0 -1
- package/dist/types/src/utils.d.ts +0 -1
- package/package.json +1 -1
- package/src/index.ts +4 -4
- package/src/multiVariableText/helper.ts +2 -2
- package/src/tables/dynamicTemplate.ts +7 -69
- package/src/tables/tableHelper.ts +11 -62
- package/src/tables/uiRender.ts +18 -16
- package/src/utils.ts +1 -2
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
CommonOptions,
|
6
6
|
getDefaultFont,
|
7
7
|
getFallbackFontName,
|
8
|
+
cloneDeep,
|
8
9
|
} from '@pdfme/common';
|
9
10
|
import type {
|
10
11
|
TableSchema,
|
@@ -15,7 +16,6 @@ import type {
|
|
15
16
|
StylesProps,
|
16
17
|
Section,
|
17
18
|
} from './types';
|
18
|
-
import { cloneDeep } from '../utils';
|
19
19
|
import { Cell, Column, Row, Table } from './classes';
|
20
20
|
|
21
21
|
type StyleProp = 'styles' | 'headStyles' | 'bodyStyles' | 'alternateRowStyles' | 'columnStyles';
|
@@ -164,28 +164,6 @@ function mapCellStyle(style: CellStyle): Partial<Styles> {
|
|
164
164
|
};
|
165
165
|
}
|
166
166
|
|
167
|
-
function createTableWithAvailableHeight(
|
168
|
-
tableBody: Row[],
|
169
|
-
availableHeight: number,
|
170
|
-
args: CreateTableArgs
|
171
|
-
) {
|
172
|
-
let limit = availableHeight;
|
173
|
-
const newTableBody: string[][] = [];
|
174
|
-
let index = 0;
|
175
|
-
while (limit > 0 && index < tableBody.length) {
|
176
|
-
const row = tableBody.slice(0, index + 1).pop();
|
177
|
-
if (!row) break;
|
178
|
-
const rowHeight = row.height;
|
179
|
-
if (limit - rowHeight < 0) {
|
180
|
-
break;
|
181
|
-
}
|
182
|
-
newTableBody.push(row.raw);
|
183
|
-
limit -= rowHeight;
|
184
|
-
index++;
|
185
|
-
}
|
186
|
-
return createSingleTable(newTableBody, args);
|
187
|
-
}
|
188
|
-
|
189
167
|
function getTableOptions(schema: TableSchema, body: string[][]): UserOptions {
|
190
168
|
const columnStylesWidth = schema.headWidthPercentages.reduce(
|
191
169
|
(acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }),
|
@@ -272,7 +250,16 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
|
|
272
250
|
const { options, _cache, basePdf } = args;
|
273
251
|
if (!isBlankPdf(basePdf)) throw new Error('[@pdfme/schema/table] Custom PDF is not supported');
|
274
252
|
|
275
|
-
const
|
253
|
+
const schema = cloneDeep(args.schema) as TableSchema;
|
254
|
+
const { start } = schema.__bodyRange || { start: 0 };
|
255
|
+
if (start % 2 === 1) {
|
256
|
+
const alternateBackgroundColor = schema.bodyStyles.alternateBackgroundColor;
|
257
|
+
schema.bodyStyles.alternateBackgroundColor = schema.bodyStyles.backgroundColor;
|
258
|
+
schema.bodyStyles.backgroundColor = alternateBackgroundColor;
|
259
|
+
}
|
260
|
+
schema.showHead = start === 0;
|
261
|
+
|
262
|
+
const input = parseInput(schema, body);
|
276
263
|
|
277
264
|
const font = options.font || getDefaultFont();
|
278
265
|
|
@@ -282,41 +269,3 @@ export function createSingleTable(body: string[][], args: CreateTableArgs) {
|
|
282
269
|
|
283
270
|
return Table.create({ input, content, font, _cache });
|
284
271
|
}
|
285
|
-
|
286
|
-
export async function createMultiTables(body: string[][], args: CreateTableArgs): Promise<Table[]> {
|
287
|
-
const { basePdf, schema } = args;
|
288
|
-
|
289
|
-
if (!isBlankPdf(basePdf)) throw new Error('[@pdfme/schema/table] Custom PDF is not supported');
|
290
|
-
const pageHeight = basePdf.height;
|
291
|
-
const paddingBottom = basePdf.padding[2];
|
292
|
-
const paddingTop = basePdf.padding[0];
|
293
|
-
let availableHeight = pageHeight - paddingBottom - schema.position.y;
|
294
|
-
|
295
|
-
const testTable = await createSingleTable(body, args);
|
296
|
-
let remainingBody = testTable.body;
|
297
|
-
const tables: Table[] = [];
|
298
|
-
|
299
|
-
while (remainingBody.length > 0) {
|
300
|
-
const tableHeight =
|
301
|
-
tables.length === 0
|
302
|
-
? availableHeight - testTable.getHeadHeight()
|
303
|
-
: availableHeight - paddingTop;
|
304
|
-
|
305
|
-
const table = await createTableWithAvailableHeight(remainingBody, tableHeight, args);
|
306
|
-
|
307
|
-
tables.push(table);
|
308
|
-
|
309
|
-
remainingBody = remainingBody.slice(table.body.length);
|
310
|
-
|
311
|
-
if (remainingBody.length > 0) {
|
312
|
-
const _schema = cloneDeep(schema);
|
313
|
-
_schema.showHead = false;
|
314
|
-
_schema.position.y = paddingTop;
|
315
|
-
args.schema = _schema;
|
316
|
-
|
317
|
-
availableHeight = pageHeight - paddingTop - paddingBottom;
|
318
|
-
}
|
319
|
-
}
|
320
|
-
|
321
|
-
return tables;
|
322
|
-
}
|
package/src/tables/uiRender.ts
CHANGED
@@ -6,6 +6,8 @@ import { getBody, getBodyWithRange } from './helper.js';
|
|
6
6
|
import cell from './cell.js';
|
7
7
|
import { Row } from './classes';
|
8
8
|
|
9
|
+
const buttonSize = 30;
|
10
|
+
|
9
11
|
type RowType = InstanceType<typeof Row>;
|
10
12
|
|
11
13
|
const cellUiRender = cell.ui;
|
@@ -218,11 +220,11 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
218
220
|
schema.__bodyRange.end >= (JSON.parse(value || '[]') as string[][]).length
|
219
221
|
) {
|
220
222
|
const addRowButton = document.createElement('button');
|
221
|
-
addRowButton.style.width =
|
222
|
-
addRowButton.style.height =
|
223
|
+
addRowButton.style.width = `${buttonSize}px`;
|
224
|
+
addRowButton.style.height = `${buttonSize}px`;
|
223
225
|
addRowButton.style.position = 'absolute';
|
224
226
|
addRowButton.style.top = `${table.getHeight()}mm`;
|
225
|
-
addRowButton.style.left =
|
227
|
+
addRowButton.style.left = `calc(50% - ${buttonSize / 2}px)`;
|
226
228
|
addRowButton.innerText = '+';
|
227
229
|
addRowButton.onclick = () => {
|
228
230
|
const newRow = Array(schema.head.length).fill('') as string[];
|
@@ -235,11 +237,11 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
235
237
|
table.body.forEach((row, i) => {
|
236
238
|
offsetY = offsetY + row.height;
|
237
239
|
const removeRowButton = document.createElement('button');
|
238
|
-
removeRowButton.style.width =
|
239
|
-
removeRowButton.style.height =
|
240
|
+
removeRowButton.style.width = `${buttonSize}px`;
|
241
|
+
removeRowButton.style.height = `${buttonSize}px`;
|
240
242
|
removeRowButton.style.position = 'absolute';
|
241
|
-
removeRowButton.style.top = `${offsetY - px2mm(
|
242
|
-
removeRowButton.style.right =
|
243
|
+
removeRowButton.style.top = `${offsetY - px2mm(buttonSize)}mm`;
|
244
|
+
removeRowButton.style.right = `-${buttonSize}px`;
|
243
245
|
removeRowButton.innerText = '-';
|
244
246
|
removeRowButton.onclick = () => {
|
245
247
|
const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
|
@@ -251,11 +253,11 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
251
253
|
|
252
254
|
if (mode === 'designer' && onChange) {
|
253
255
|
const addColumnButton = document.createElement('button');
|
254
|
-
addColumnButton.style.width =
|
255
|
-
addColumnButton.style.height =
|
256
|
+
addColumnButton.style.width = `${buttonSize}px`;
|
257
|
+
addColumnButton.style.height = `${buttonSize}px`;
|
256
258
|
addColumnButton.style.position = 'absolute';
|
257
|
-
addColumnButton.style.top = `${table.getHeadHeight() - px2mm(
|
258
|
-
addColumnButton.style.right =
|
259
|
+
addColumnButton.style.top = `${table.getHeadHeight() - px2mm(buttonSize)}mm`;
|
260
|
+
addColumnButton.style.right = `-${buttonSize}px`;
|
259
261
|
addColumnButton.innerText = '+';
|
260
262
|
addColumnButton.onclick = (e) => {
|
261
263
|
e.preventDefault();
|
@@ -278,11 +280,11 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
278
280
|
table.columns.forEach((column, i) => {
|
279
281
|
offsetX = offsetX + column.width;
|
280
282
|
const removeColumnButton = document.createElement('button');
|
281
|
-
removeColumnButton.style.width =
|
282
|
-
removeColumnButton.style.height =
|
283
|
+
removeColumnButton.style.width = `${buttonSize}px`;
|
284
|
+
removeColumnButton.style.height = `${buttonSize}px`;
|
283
285
|
removeColumnButton.style.position = 'absolute';
|
284
|
-
removeColumnButton.style.top =
|
285
|
-
removeColumnButton.style.left = `${offsetX - px2mm(
|
286
|
+
removeColumnButton.style.top = `-${buttonSize}px`;
|
287
|
+
removeColumnButton.style.left = `${offsetX - px2mm(buttonSize)}mm`;
|
286
288
|
removeColumnButton.innerText = '-';
|
287
289
|
removeColumnButton.onclick = (e) => {
|
288
290
|
e.preventDefault();
|
@@ -390,4 +392,4 @@ export const uiRender = async (arg: UIRenderProps<TableSchema>) => {
|
|
390
392
|
if (schema.height !== tableHeight && onChange) {
|
391
393
|
onChange({ key: 'height', value: tableHeight });
|
392
394
|
}
|
393
|
-
};
|
395
|
+
};
|
package/src/utils.ts
CHANGED