@pdfme/schemas
Version:
TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!
24 lines (22 loc) • 863 B
text/typescript
import { Schema, BasePdf, CommonOptions } from '@pdfme/common';
import { createSingleTable } from './tableHelper.js';
import { getBodyWithRange, getBody } from './helper.js';
import { TableSchema } from './types.js';
export const getDynamicHeightsForTable = async (
value: string,
args: {
schema: Schema;
basePdf: BasePdf;
options: CommonOptions;
_cache: Map<string | number, unknown>;
},
): Promise<number[]> => {
if (args.schema.type !== 'table') return Promise.resolve([args.schema.height]);
const schema = args.schema as TableSchema;
const body =
schema.__bodyRange?.start === 0 ? getBody(value) : getBodyWithRange(value, schema.__bodyRange);
const table = await createSingleTable(body, args);
return schema.showHead
? table.allRows().map((row) => row.height)
: [0].concat(table.body.map((row) => row.height));
};