@blocknote/xl-pdf-exporter 0.32.0 → 0.34.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.
@@ -8,12 +8,14 @@ import {
8
8
  defaultStyleSpecs,
9
9
  PageBreak,
10
10
  } from "@blocknote/core";
11
+ import { ColumnBlock, ColumnListBlock } from "@blocknote/xl-multi-column";
11
12
  import { Text } from "@react-pdf/renderer";
12
13
  import { testDocument } from "@shared/testDocument.js";
13
14
  import reactElementToJSXString from "react-element-to-jsx-string";
14
15
  import { describe, expect, it } from "vitest";
15
16
  import { pdfDefaultSchemaMappings } from "./defaultSchema/index.js";
16
17
  import { PDFExporter } from "./pdfExporter.js";
18
+ import { partialBlocksToBlocksForTesting } from "@shared/formatConversionTestUtil.js";
17
19
  // import * as ReactPDF from "@react-pdf/renderer";
18
20
  // expect.extend({ toMatchImageSnapshot });
19
21
  // import { toMatchImageSnapshot } from "jest-image-snapshot";
@@ -28,6 +30,8 @@ describe("exporter", () => {
28
30
  blockSpecs: {
29
31
  ...defaultBlockSpecs,
30
32
  pageBreak: PageBreak,
33
+ column: ColumnBlock,
34
+ columnList: ColumnListBlock,
31
35
  extraBlock: createBlockSpec(
32
36
  {
33
37
  content: "none",
@@ -158,7 +162,12 @@ describe("exporter", () => {
158
162
  it("should export a document", async () => {
159
163
  const exporter = new PDFExporter(
160
164
  BlockNoteSchema.create({
161
- blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
165
+ blockSpecs: {
166
+ ...defaultBlockSpecs,
167
+ pageBreak: PageBreak,
168
+ column: ColumnBlock,
169
+ columnList: ColumnListBlock,
170
+ },
162
171
  }),
163
172
  pdfDefaultSchemaMappings,
164
173
  );
@@ -191,7 +200,12 @@ describe("exporter", () => {
191
200
  it("should export a document with header and footer", async () => {
192
201
  const exporter = new PDFExporter(
193
202
  BlockNoteSchema.create({
194
- blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
203
+ blockSpecs: {
204
+ ...defaultBlockSpecs,
205
+ pageBreak: PageBreak,
206
+ column: ColumnBlock,
207
+ columnList: ColumnListBlock,
208
+ },
195
209
  }),
196
210
  pdfDefaultSchemaMappings,
197
211
  );
@@ -210,4 +224,77 @@ describe("exporter", () => {
210
224
  // `${__dirname}/exampleWithHeaderAndFooter.pdf`
211
225
  // );
212
226
  });
227
+ it("should export a document with a multi-column block", async () => {
228
+ const schema = BlockNoteSchema.create({
229
+ blockSpecs: {
230
+ ...defaultBlockSpecs,
231
+ pageBreak: PageBreak,
232
+ column: ColumnBlock,
233
+ columnList: ColumnListBlock,
234
+ },
235
+ });
236
+ const exporter = new PDFExporter(schema, pdfDefaultSchemaMappings);
237
+ const transformed = await exporter.toReactPDFDocument(
238
+ partialBlocksToBlocksForTesting(schema, [
239
+ {
240
+ type: "columnList",
241
+ children: [
242
+ {
243
+ type: "column",
244
+ props: {
245
+ width: 0.8,
246
+ },
247
+ children: [
248
+ {
249
+ type: "paragraph",
250
+ content: "This paragraph is in a column!",
251
+ },
252
+ ],
253
+ },
254
+ {
255
+ type: "column",
256
+ props: {
257
+ width: 1.4,
258
+ },
259
+ children: [
260
+ {
261
+ type: "heading",
262
+ content: "So is this heading!",
263
+ },
264
+ ],
265
+ },
266
+ {
267
+ type: "column",
268
+ props: {
269
+ width: 0.8,
270
+ },
271
+ children: [
272
+ {
273
+ type: "paragraph",
274
+ content: "You can have multiple blocks in a column too",
275
+ },
276
+ {
277
+ type: "bulletListItem",
278
+ content: "Block 1",
279
+ },
280
+ {
281
+ type: "bulletListItem",
282
+ content: "Block 2",
283
+ },
284
+ {
285
+ type: "bulletListItem",
286
+ content: "Block 3",
287
+ },
288
+ ],
289
+ },
290
+ ],
291
+ },
292
+ ]),
293
+ );
294
+ const str = reactElementToJSXString(transformed);
295
+
296
+ await expect(str).toMatchFileSnapshot(
297
+ "__snapshots__/exampleWithMultiColumn.jsx",
298
+ );
299
+ });
213
300
  });
@@ -10,7 +10,6 @@ import {
10
10
  StyleSchema,
11
11
  StyledText,
12
12
  } from "@blocknote/core";
13
- import { Fragment } from "react";
14
13
  import {
15
14
  Document,
16
15
  Font,
@@ -22,6 +21,7 @@ import {
22
21
  View,
23
22
  } from "@react-pdf/renderer";
24
23
  import { corsProxyResolveFileUrl } from "@shared/api/corsProxy.js";
24
+ import { Fragment } from "react";
25
25
  import { loadFontDataUrl } from "../../../../shared/util/fileUtil.js";
26
26
 
27
27
  import { Style } from "./types.js";
@@ -146,9 +146,10 @@ export class PDFExporter<
146
146
  b as any,
147
147
  nestingLevel,
148
148
  numberedListIndex,
149
+ children,
149
150
  ); // TODO: any
150
151
 
151
- if (b.type === "pageBreak") {
152
+ if (["pageBreak", "columnList", "column"].includes(b.type)) {
152
153
  ret.push(self);
153
154
  continue;
154
155
  }
@@ -1,3 +1,4 @@
1
1
  import { BlockMapping, DefaultBlockSchema, pageBreakSchema } from "@blocknote/core";
2
+ import { multiColumnSchema } from "@blocknote/xl-multi-column";
2
3
  import { Link, Text } from "@react-pdf/renderer";
3
- export declare const pdfBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema & typeof pageBreakSchema.blockSchema, any, any, React.ReactElement<Text>, React.ReactElement<Text> | React.ReactElement<Link>>;
4
+ export declare const pdfBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema & typeof pageBreakSchema.blockSchema & typeof multiColumnSchema.blockSchema, any, any, React.ReactElement<Text>, React.ReactElement<Text> | React.ReactElement<Link>>;