Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
danvim committed Nov 19, 2023
1 parent 508f380 commit 4321c8e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/PdfRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const PdfRenderer = {
bundleType: 1,
version: "1",
rendererPackageName: "react-pdfmake-reconciler",
findFiberByHostInstance: (instance) => root.getInstanceFromNode(instance),
});

const unmount = () => {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/PdfRenderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,11 @@ describe("PdfRenderer", () => {
},
]);
});

test("array", () => {
expect(
PdfRenderer.renderOnce([<pdf-array key={1}>Hello World!</pdf-array>]),
).resolves.toEqual([["Hello World!"]]);
});
});
});
10 changes: 7 additions & 3 deletions src/components/PdfTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentProps, FC, ReactElement } from "react";
import { ComponentProps, FC, Fragment, ReactElement } from "react";

export const PdfTable: FC<
{ rows: ReactElement[][] } & Omit<ComponentProps<"pdf-table">, "children"> &
Expand All @@ -7,8 +7,12 @@ export const PdfTable: FC<
return (
<pdf-table layout={layout}>
<pdf-tbody {...tbodyProps}>
{rows.map((row) => (
<pdf-array>{row}</pdf-array>
{rows.map((row, i) => (
<pdf-array key={i}>
{row.map((cell, j) => (
<Fragment key={j}>{cell}</Fragment>
))}
</pdf-array>
))}
</pdf-tbody>
</pdf-table>
Expand Down
50 changes: 27 additions & 23 deletions src/types/PdfElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@ import { PdfElement, PdfNode } from "./PdfNode.ts";

import { PdfPrefixed } from "../pdfPrefix.ts";
import { TextInstance } from "../hostConfig.ts";
import { Attributes } from "react";

interface PdfElementAttributes extends Attributes {
children?: PdfNode;
}

export interface PdfSingleChildElementProps extends PdfElementAttributes {
children: PdfElement;
}

export interface PdfElementsSansPrefix {
text: { children?: PdfNode } & (
| Omit<ContentText, "text">
| Omit<ContentLink, "text">
| Omit<ContentAnchor, "text">
| Omit<ContentTocItem, "text">
);
columns: { children?: PdfNode } & Omit<ContentColumns, "columns">;
stack: { children?: PdfNode } & Omit<ContentStack, "stack">;
ol: { children?: PdfNode } & Omit<ContentOrderedList, "ol">;
ul: { children?: PdfNode } & Omit<ContentUnorderedList, "ul">;
table: { children?: PdfNode } & Omit<ContentTable, "table">;
text: PdfElementAttributes &
(
| Omit<ContentText, "text">
| Omit<ContentLink, "text">
| Omit<ContentAnchor, "text">
| Omit<ContentTocItem, "text">
);
columns: PdfElementAttributes & Omit<ContentColumns, "columns">;
stack: PdfElementAttributes & Omit<ContentStack, "stack">;
ol: PdfElementAttributes & Omit<ContentOrderedList, "ol">;
ul: PdfElementAttributes & Omit<ContentUnorderedList, "ul">;
table: PdfElementAttributes & Omit<ContentTable, "table">;
pageReference: { children: string } & Omit<
ContentPageReference,
"pageReference"
Expand All @@ -51,32 +61,27 @@ export interface PdfElementsSansPrefix {
qr: ContentQr;
canvas: ContentCanvas;
}

export interface PdfElementWrapperProps {
children: PdfElement;
}

export interface PdfCellProps
extends TableCellProperties,
PdfElementWrapperProps {}
PdfSingleChildElementProps {}

export interface PdfColumnProps
extends ColumnProperties,
PdfElementWrapperProps {}
PdfSingleChildElementProps {}

export type PdfListItemProps = (
| OrderedListElementProperties
| UnorderedListElementProperties
) &
PdfElementWrapperProps;
PdfSingleChildElementProps;

export interface VirtualPdfElementsSansPrefix extends PdfElementsSansPrefix {
array: { children?: PdfNode };
array: PdfElementAttributes;
cell: PdfCellProps;
column: PdfColumnProps;
li: PdfListItemProps;
tbody: { children?: PdfNode } & Omit<Table, "body">;
toc: { children?: PdfNode } & Omit<TableOfContent, "title">;
tbody: PdfElementAttributes & Omit<Table, "body">;
toc: PdfElementAttributes & Omit<TableOfContent, "title">;
}

export type PdfElements = {
Expand All @@ -94,7 +99,6 @@ export type PdfReconcilerIntrinsicType = PdfPrefixed<VirtualPdfPrimitiveType>;

export interface PdfReconcilerElement {
$__reactPdfMakeType: PdfReconcilerIntrinsicType;

[K: string]: unknown;
}

Expand Down

0 comments on commit 4321c8e

Please sign in to comment.