@blocknote/xl-pdf-exporter 0.19.0
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/LICENSE +661 -0
- package/dist/Inter_18pt-Bold-BOnnSImi.js +5 -0
- package/dist/Inter_18pt-Bold-BOnnSImi.js.map +1 -0
- package/dist/Inter_18pt-BoldItalic-DPKIpVzB.js +5 -0
- package/dist/Inter_18pt-BoldItalic-DPKIpVzB.js.map +1 -0
- package/dist/Inter_18pt-Italic-BVnfHlUD.js +5 -0
- package/dist/Inter_18pt-Italic-BVnfHlUD.js.map +1 -0
- package/dist/Inter_18pt-Regular-byxnNS-8.js +5 -0
- package/dist/Inter_18pt-Regular-byxnNS-8.js.map +1 -0
- package/dist/blocknote-xl-pdf-exporter.js +2503 -0
- package/dist/blocknote-xl-pdf-exporter.js.map +1 -0
- package/dist/blocknote-xl-pdf-exporter.umd.cjs +69 -0
- package/dist/blocknote-xl-pdf-exporter.umd.cjs.map +1 -0
- package/dist/webpack-stats.json +1 -0
- package/package.json +88 -0
- package/src/index.ts +1 -0
- package/src/pdf/__snapshots__/example.jsx +592 -0
- package/src/pdf/__snapshots__/exampleWithHeaderAndFooter.jsx +602 -0
- package/src/pdf/defaultSchema/blocks.tsx +177 -0
- package/src/pdf/defaultSchema/index.ts +9 -0
- package/src/pdf/defaultSchema/inlinecontent.tsx +23 -0
- package/src/pdf/defaultSchema/styles.tsx +68 -0
- package/src/pdf/index.ts +2 -0
- package/src/pdf/pdfExporter.test.tsx +208 -0
- package/src/pdf/pdfExporter.tsx +297 -0
- package/src/pdf/types.ts +3 -0
- package/src/pdf/util/listItem.tsx +70 -0
- package/src/pdf/util/table/Table.tsx +76 -0
- package/src/vite-env.d.ts +11 -0
- package/types/src/Exporter.d.ts +26 -0
- package/types/src/context/BlockNoteContext.d.ts +59 -0
- package/types/src/context/BlockNoteContext.test.d.ts +1 -0
- package/types/src/context/ServerBlockNoteEditor.d.ts +137 -0
- package/types/src/context/ServerBlockNoteEditor.test.d.ts +1 -0
- package/types/src/context/react/ReactServer.test.d.ts +2 -0
- package/types/src/docx/blocks.d.ts +433 -0
- package/types/src/docx/defaultSchema/blocks.d.ts +4 -0
- package/types/src/docx/defaultSchema/index.d.ts +559 -0
- package/types/src/docx/defaultSchema/inlinecontent.d.ts +4 -0
- package/types/src/docx/defaultSchema/styles.d.ts +4 -0
- package/types/src/docx/docxExporter.d.ts +14 -0
- package/types/src/docx/docxExporter.test.d.ts +1 -0
- package/types/src/docx/imageUtil.d.ts +4 -0
- package/types/src/docx/index.d.ts +2 -0
- package/types/src/docx/inlinecontent.d.ts +12 -0
- package/types/src/docx/styles.d.ts +55 -0
- package/types/src/docx/util/Table.d.ts +4 -0
- package/types/src/docxExporter.d.ts +255 -0
- package/types/src/docxExporter.test.d.ts +1 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/mapping.d.ts +29 -0
- package/types/src/pdf/blocks.d.ts +434 -0
- package/types/src/pdf/defaultSchema/blocks.d.ts +4 -0
- package/types/src/pdf/defaultSchema/index.d.ts +510 -0
- package/types/src/pdf/defaultSchema/inlinecontent.d.ts +4 -0
- package/types/src/pdf/defaultSchema/styles.d.ts +3 -0
- package/types/src/pdf/index.d.ts +2 -0
- package/types/src/pdf/inlinecontent.d.ts +13 -0
- package/types/src/pdf/pdfExporter.d.ts +81 -0
- package/types/src/pdf/pdfExporter.test.d.ts +1 -0
- package/types/src/pdf/styles.d.ts +55 -0
- package/types/src/pdf/types.d.ts +2 -0
- package/types/src/pdf/util/listItem.d.ts +9 -0
- package/types/src/pdf/util/loadFontDataUrl.d.ts +3 -0
- package/types/src/pdf/util/table/Table.d.ts +5 -0
- package/types/src/pdfExporter.d.ts +256 -0
- package/types/src/pdfExporter.test.d.ts +1 -0
- package/types/src/react-email/defaultSchema/blocks.d.ts +5 -0
- package/types/src/react-email/defaultSchema/index.d.ts +560 -0
- package/types/src/react-email/defaultSchema/inlinecontent.d.ts +5 -0
- package/types/src/react-email/defaultSchema/styles.d.ts +4 -0
- package/types/src/react-email/reactEmailExporter.d.ts +13 -0
- package/types/src/react-email/reactEmailExporter.test.d.ts +8 -0
- package/types/src/testDocument.d.ts +505 -0
- package/types/src/transformer.d.ts +20 -0
- package/types/src/util/fileUtil.d.ts +22 -0
- package/types/src/util/imageUtil.d.ts +4 -0
- package/types/src/yjs/index.d.ts +2 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BlockMapping,
|
|
3
|
+
DefaultBlockSchema,
|
|
4
|
+
DefaultProps,
|
|
5
|
+
} from "@blocknote/core";
|
|
6
|
+
import { Image, Link, Path, Svg, Text, View } from "@react-pdf/renderer";
|
|
7
|
+
import {
|
|
8
|
+
BULLET_MARKER,
|
|
9
|
+
CHECK_MARKER_CHECKED,
|
|
10
|
+
CHECK_MARKER_UNCHECKED,
|
|
11
|
+
ListItem,
|
|
12
|
+
} from "../util/listItem.js";
|
|
13
|
+
import { Table } from "../util/table/Table.js";
|
|
14
|
+
|
|
15
|
+
const PIXELS_PER_POINT = 0.75;
|
|
16
|
+
const FONT_SIZE = 16;
|
|
17
|
+
|
|
18
|
+
export const pdfBlockMappingForDefaultSchema: BlockMapping<
|
|
19
|
+
DefaultBlockSchema,
|
|
20
|
+
any,
|
|
21
|
+
any,
|
|
22
|
+
React.ReactElement<Text>,
|
|
23
|
+
React.ReactElement<Text> | React.ReactElement<Link>
|
|
24
|
+
> = {
|
|
25
|
+
paragraph: (block, exporter) => {
|
|
26
|
+
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
|
|
27
|
+
return <Text>{exporter.transformInlineContent(block.content)}</Text>;
|
|
28
|
+
},
|
|
29
|
+
bulletListItem: (block, exporter) => {
|
|
30
|
+
// const style = t(block.props);
|
|
31
|
+
return (
|
|
32
|
+
<ListItem listMarker={BULLET_MARKER}>
|
|
33
|
+
<Text>{exporter.transformInlineContent(block.content)}</Text>
|
|
34
|
+
</ListItem>
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
numberedListItem: (block, exporter, _nestingLevel, numberedListIndex) => {
|
|
38
|
+
// const style = blocknoteDefaultPropsToReactPDFStyle(block.props);
|
|
39
|
+
// console.log("NUMBERED LIST ITEM", block.props.textAlignment, style);
|
|
40
|
+
return (
|
|
41
|
+
<ListItem listMarker={`${numberedListIndex}.`}>
|
|
42
|
+
<Text>{exporter.transformInlineContent(block.content)}</Text>
|
|
43
|
+
</ListItem>
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
// would be nice to have pdf checkboxes:
|
|
47
|
+
// https://github.com/diegomura/react-pdf/issues/2103
|
|
48
|
+
checkListItem: (block, exporter) => {
|
|
49
|
+
return (
|
|
50
|
+
<ListItem
|
|
51
|
+
listMarker={
|
|
52
|
+
block.props.checked ? CHECK_MARKER_CHECKED : CHECK_MARKER_UNCHECKED
|
|
53
|
+
}>
|
|
54
|
+
<Text>{exporter.transformInlineContent(block.content)}</Text>
|
|
55
|
+
</ListItem>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
heading: (block, exporter) => {
|
|
59
|
+
const fontSizeEM =
|
|
60
|
+
block.props.level === 1 ? 2 : block.props.level === 2 ? 1.5 : 1.17;
|
|
61
|
+
return (
|
|
62
|
+
<Text
|
|
63
|
+
style={{
|
|
64
|
+
fontSize: fontSizeEM * FONT_SIZE * PIXELS_PER_POINT,
|
|
65
|
+
fontWeight: 700,
|
|
66
|
+
}}>
|
|
67
|
+
{exporter.transformInlineContent(block.content)}
|
|
68
|
+
</Text>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
codeBlock: (block) => {
|
|
72
|
+
return <Text>{block.type + " not implemented"}</Text>;
|
|
73
|
+
},
|
|
74
|
+
audio: (block, exporter) => {
|
|
75
|
+
return (
|
|
76
|
+
<View wrap={false}>
|
|
77
|
+
{file(
|
|
78
|
+
block.props,
|
|
79
|
+
"Open audio file",
|
|
80
|
+
<Svg height={14} width={14} viewBox="0 0 24 24" fill="currentColor">
|
|
81
|
+
<Path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></Path>
|
|
82
|
+
</Svg>,
|
|
83
|
+
exporter
|
|
84
|
+
)}
|
|
85
|
+
{caption(block.props, exporter)}
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
video: (block, exporter) => {
|
|
90
|
+
return (
|
|
91
|
+
<View wrap={false}>
|
|
92
|
+
{file(
|
|
93
|
+
block.props,
|
|
94
|
+
"Open video file",
|
|
95
|
+
<Svg height={14} width={14} viewBox="0 0 24 24" fill="currentColor">
|
|
96
|
+
<Path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z" />
|
|
97
|
+
</Svg>,
|
|
98
|
+
exporter
|
|
99
|
+
)}
|
|
100
|
+
{caption(block.props, exporter)}
|
|
101
|
+
</View>
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
file: (block, exporter) => {
|
|
105
|
+
return (
|
|
106
|
+
<View wrap={false}>
|
|
107
|
+
{file(
|
|
108
|
+
block.props,
|
|
109
|
+
"Open file",
|
|
110
|
+
<Svg height={16} width={16} viewBox="0 0 24 24" fill="currentColor">
|
|
111
|
+
<Path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z" />
|
|
112
|
+
</Svg>,
|
|
113
|
+
exporter
|
|
114
|
+
)}
|
|
115
|
+
{caption(block.props, exporter)}
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
image: async (block, t) => {
|
|
120
|
+
return (
|
|
121
|
+
<View wrap={false}>
|
|
122
|
+
<Image
|
|
123
|
+
src={await t.resolveFile(block.props.url)}
|
|
124
|
+
style={{
|
|
125
|
+
width: block.props.previewWidth * PIXELS_PER_POINT,
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
{caption(block.props, t)}
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
table: (block, t) => {
|
|
133
|
+
return <Table data={block.content} transformer={t} />;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
function file(
|
|
138
|
+
props: Partial<DefaultProps & { name: string; url: string }>,
|
|
139
|
+
defaultText: string,
|
|
140
|
+
icon: React.ReactElement<Svg>,
|
|
141
|
+
_exporter: any
|
|
142
|
+
) {
|
|
143
|
+
const PIXELS_PER_POINT = 0.75;
|
|
144
|
+
return (
|
|
145
|
+
<Link src={props.url}>
|
|
146
|
+
<View
|
|
147
|
+
style={{
|
|
148
|
+
display: "flex",
|
|
149
|
+
gap: 8 * PIXELS_PER_POINT,
|
|
150
|
+
flexDirection: "row",
|
|
151
|
+
}}>
|
|
152
|
+
{icon}
|
|
153
|
+
<Text>{props.name || defaultText}</Text>
|
|
154
|
+
</View>
|
|
155
|
+
</Link>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function caption(
|
|
160
|
+
props: Partial<DefaultProps & { caption: string; previewWidth: number }>,
|
|
161
|
+
_exporter: any
|
|
162
|
+
) {
|
|
163
|
+
if (!props.caption) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
return (
|
|
167
|
+
<Text
|
|
168
|
+
style={{
|
|
169
|
+
width: props.previewWidth
|
|
170
|
+
? props.previewWidth * PIXELS_PER_POINT
|
|
171
|
+
: undefined,
|
|
172
|
+
fontSize: FONT_SIZE * 0.8 * PIXELS_PER_POINT,
|
|
173
|
+
}}>
|
|
174
|
+
{props.caption}
|
|
175
|
+
</Text>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { pdfBlockMappingForDefaultSchema } from "./blocks.js";
|
|
2
|
+
import { pdfInlineContentMappingForDefaultSchema } from "./inlinecontent.js";
|
|
3
|
+
import { pdfStyleMappingForDefaultSchema } from "./styles.js";
|
|
4
|
+
|
|
5
|
+
export const pdfDefaultSchemaMappings = {
|
|
6
|
+
blockMapping: pdfBlockMappingForDefaultSchema,
|
|
7
|
+
inlineContentMapping: pdfInlineContentMappingForDefaultSchema,
|
|
8
|
+
styleMapping: pdfStyleMappingForDefaultSchema,
|
|
9
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultInlineContentSchema,
|
|
3
|
+
InlineContentMapping,
|
|
4
|
+
} from "@blocknote/core";
|
|
5
|
+
import { Link, Text } from "@react-pdf/renderer";
|
|
6
|
+
|
|
7
|
+
export const pdfInlineContentMappingForDefaultSchema: InlineContentMapping<
|
|
8
|
+
DefaultInlineContentSchema,
|
|
9
|
+
any,
|
|
10
|
+
React.ReactElement<Link> | React.ReactElement<Text>,
|
|
11
|
+
React.ReactElement<Text>
|
|
12
|
+
> = {
|
|
13
|
+
link: (ic, exporter) => {
|
|
14
|
+
return (
|
|
15
|
+
<Link href={ic.href}>
|
|
16
|
+
{ic.content.map((content) => exporter.transformStyledText(content))}
|
|
17
|
+
</Link>
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
text: (ic, exporter) => {
|
|
21
|
+
return exporter.transformStyledText(ic);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DefaultStyleSchema, StyleMapping } from "@blocknote/core";
|
|
2
|
+
import { TextProps } from "@react-pdf/renderer";
|
|
3
|
+
|
|
4
|
+
export const pdfStyleMappingForDefaultSchema: StyleMapping<
|
|
5
|
+
DefaultStyleSchema,
|
|
6
|
+
TextProps["style"]
|
|
7
|
+
> = {
|
|
8
|
+
bold: (val) => {
|
|
9
|
+
if (!val) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
fontWeight: "bold",
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
italic: (val) => {
|
|
17
|
+
if (!val) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
fontStyle: "italic",
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
underline: (val) => {
|
|
25
|
+
if (!val) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
textDecoration: "underline", // TODO: could conflict with strike
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
strike: (val) => {
|
|
33
|
+
if (!val) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
textDecoration: "line-through",
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
backgroundColor: (val, exporter) => {
|
|
41
|
+
if (!val) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
backgroundColor:
|
|
46
|
+
exporter.options.colors[val as keyof typeof exporter.options.colors]
|
|
47
|
+
.background,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
textColor: (val, exporter) => {
|
|
51
|
+
if (!val) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
color:
|
|
56
|
+
exporter.options.colors[val as keyof typeof exporter.options.colors]
|
|
57
|
+
.text,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
code: (val) => {
|
|
61
|
+
if (!val) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
fontFamily: "Courier",
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
package/src/pdf/index.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BlockNoteSchema,
|
|
3
|
+
createBlockSpec,
|
|
4
|
+
createInlineContentSpec,
|
|
5
|
+
createStyleSpec,
|
|
6
|
+
defaultBlockSpecs,
|
|
7
|
+
defaultInlineContentSpecs,
|
|
8
|
+
defaultStyleSpecs,
|
|
9
|
+
} from "@blocknote/core";
|
|
10
|
+
import { Text } from "@react-pdf/renderer";
|
|
11
|
+
import { testDocument } from "@shared/testDocument.js";
|
|
12
|
+
import { prettyDOM, render } from "@testing-library/react";
|
|
13
|
+
import { describe, expect, it } from "vitest";
|
|
14
|
+
import { pdfDefaultSchemaMappings } from "./defaultSchema/index.js";
|
|
15
|
+
import { PDFExporter } from "./pdfExporter.js";
|
|
16
|
+
// import * as ReactPDF from "@react-pdf/renderer";
|
|
17
|
+
// expect.extend({ toMatchImageSnapshot });
|
|
18
|
+
// import { toMatchImageSnapshot } from "jest-image-snapshot";
|
|
19
|
+
// import { pdf } from "pdf-to-img";
|
|
20
|
+
|
|
21
|
+
describe("exporter", () => {
|
|
22
|
+
it("typescript: schema with extra block", async () => {
|
|
23
|
+
// const exporter = createPdfExporterForDefaultSchema();
|
|
24
|
+
// const ps = exporter.transform(testDocument);
|
|
25
|
+
|
|
26
|
+
const schema = BlockNoteSchema.create({
|
|
27
|
+
blockSpecs: {
|
|
28
|
+
...defaultBlockSpecs,
|
|
29
|
+
extraBlock: createBlockSpec(
|
|
30
|
+
{
|
|
31
|
+
content: "none",
|
|
32
|
+
type: "extraBlock",
|
|
33
|
+
propSchema: {},
|
|
34
|
+
},
|
|
35
|
+
{} as any
|
|
36
|
+
),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
new PDFExporter(
|
|
41
|
+
schema,
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
pdfDefaultSchemaMappings
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
new PDFExporter(schema, {
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
blockMapping: pdfDefaultSchemaMappings.blockMapping,
|
|
49
|
+
inlineContentMapping: pdfDefaultSchemaMappings.inlineContentMapping,
|
|
50
|
+
styleMapping: pdfDefaultSchemaMappings.styleMapping,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
new PDFExporter(schema, {
|
|
54
|
+
blockMapping: {
|
|
55
|
+
...pdfDefaultSchemaMappings.blockMapping,
|
|
56
|
+
extraBlock: (_b, _t) => {
|
|
57
|
+
throw new Error("sdf");
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
inlineContentMapping: pdfDefaultSchemaMappings.inlineContentMapping,
|
|
61
|
+
styleMapping: pdfDefaultSchemaMappings.styleMapping,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("typescript: schema with extra inline content", async () => {
|
|
66
|
+
const schema = BlockNoteSchema.create({
|
|
67
|
+
inlineContentSpecs: {
|
|
68
|
+
...defaultInlineContentSpecs,
|
|
69
|
+
extraInlineContent: createInlineContentSpec(
|
|
70
|
+
{
|
|
71
|
+
type: "extraInlineContent",
|
|
72
|
+
content: "styled",
|
|
73
|
+
propSchema: {},
|
|
74
|
+
},
|
|
75
|
+
{} as any
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
new PDFExporter(
|
|
81
|
+
schema,
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
pdfDefaultSchemaMappings
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
new PDFExporter(schema, {
|
|
87
|
+
blockMapping: pdfDefaultSchemaMappings.blockMapping,
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
inlineContentMapping: pdfDefaultSchemaMappings.inlineContentMapping,
|
|
90
|
+
styleMapping: pdfDefaultSchemaMappings.styleMapping,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// no error
|
|
94
|
+
new PDFExporter(schema, {
|
|
95
|
+
blockMapping: pdfDefaultSchemaMappings.blockMapping,
|
|
96
|
+
styleMapping: pdfDefaultSchemaMappings.styleMapping,
|
|
97
|
+
inlineContentMapping: {
|
|
98
|
+
...pdfDefaultSchemaMappings.inlineContentMapping,
|
|
99
|
+
extraInlineContent: () => {
|
|
100
|
+
throw new Error("extraInlineContent not implemented");
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("typescript: schema with extra style", async () => {
|
|
107
|
+
const schema = BlockNoteSchema.create({
|
|
108
|
+
styleSpecs: {
|
|
109
|
+
...defaultStyleSpecs,
|
|
110
|
+
extraStyle: createStyleSpec(
|
|
111
|
+
{
|
|
112
|
+
type: "extraStyle",
|
|
113
|
+
propSchema: "boolean",
|
|
114
|
+
},
|
|
115
|
+
{} as any
|
|
116
|
+
),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
new PDFExporter(
|
|
121
|
+
schema,
|
|
122
|
+
// @ts-expect-error
|
|
123
|
+
pdfDefaultSchemaMappings
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
new PDFExporter(schema, {
|
|
127
|
+
blockMapping: pdfDefaultSchemaMappings.blockMapping,
|
|
128
|
+
inlineContentMapping: pdfDefaultSchemaMappings.inlineContentMapping,
|
|
129
|
+
// @ts-expect-error
|
|
130
|
+
styleMapping: pdfDefaultSchemaMappings.styleMapping,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// no error
|
|
134
|
+
new PDFExporter(schema, {
|
|
135
|
+
blockMapping: pdfDefaultSchemaMappings.blockMapping,
|
|
136
|
+
inlineContentMapping: pdfDefaultSchemaMappings.inlineContentMapping,
|
|
137
|
+
styleMapping: {
|
|
138
|
+
...pdfDefaultSchemaMappings.styleMapping,
|
|
139
|
+
extraStyle: () => {
|
|
140
|
+
throw new Error("extraStyle not implemented");
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("typescript: schema with block and style removed", async () => {
|
|
147
|
+
const schema = BlockNoteSchema.create({
|
|
148
|
+
blockSpecs: {},
|
|
149
|
+
styleSpecs: {},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// still works (no error)
|
|
153
|
+
new PDFExporter(schema, pdfDefaultSchemaMappings);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should export a document", async () => {
|
|
157
|
+
const exporter = new PDFExporter(
|
|
158
|
+
BlockNoteSchema.create(),
|
|
159
|
+
pdfDefaultSchemaMappings
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const transformed = await exporter.toReactPDFDocument(testDocument);
|
|
163
|
+
const view = render(transformed);
|
|
164
|
+
const str = prettyDOM(view.container, undefined, { highlight: false });
|
|
165
|
+
expect(str).toMatchFileSnapshot("__snapshots__/example.jsx");
|
|
166
|
+
|
|
167
|
+
// would be nice to compare pdf images, but currently doesn't work on mac os (due to node canvas installation issue)
|
|
168
|
+
|
|
169
|
+
// await ReactPDF.render(transformed, `${__dirname}/example.pdf`);
|
|
170
|
+
// eslint-disable-next-line
|
|
171
|
+
// const b = await ReactPDF(transformed);
|
|
172
|
+
|
|
173
|
+
// await toMatchBinaryFileSnapshot(b, `__snapshots__/example.pdf`);
|
|
174
|
+
// expect(b.toString("utf-8")).toMatchFileSnapshot(
|
|
175
|
+
// `__snapshots__/example.pdf`
|
|
176
|
+
// );
|
|
177
|
+
// const doc = await pdf(`${__dirname}/example.pdf`);
|
|
178
|
+
|
|
179
|
+
// // expect(doc.length).toBe(2);
|
|
180
|
+
// // expect(doc.metadata).toEqual({ ... });
|
|
181
|
+
|
|
182
|
+
// for await (const page of doc) {
|
|
183
|
+
// expect(page).toMatchImageSnapshot();
|
|
184
|
+
// }
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should export a document with header and footer", async () => {
|
|
188
|
+
const exporter = new PDFExporter(
|
|
189
|
+
BlockNoteSchema.create(),
|
|
190
|
+
pdfDefaultSchemaMappings
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const transformed = await exporter.toReactPDFDocument(testDocument, {
|
|
194
|
+
header: <Text>Header</Text>,
|
|
195
|
+
footer: <Text>Footer</Text>,
|
|
196
|
+
});
|
|
197
|
+
const view = render(transformed);
|
|
198
|
+
const str = prettyDOM(view.container, undefined, { highlight: false });
|
|
199
|
+
expect(str).toMatchFileSnapshot(
|
|
200
|
+
"__snapshots__/exampleWithHeaderAndFooter.jsx"
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// await ReactPDF.render(
|
|
204
|
+
// transformed,
|
|
205
|
+
// `${__dirname}/exampleWithHeaderAndFooter.pdf`
|
|
206
|
+
// );
|
|
207
|
+
});
|
|
208
|
+
});
|