@blocknote/xl-pdf-exporter 0.30.0 → 0.31.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/dist/blocknote-xl-pdf-exporter.cjs.map +1 -1
- package/dist/blocknote-xl-pdf-exporter.js.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -4
- package/src/pdf/__snapshots__/example.jsx +308 -128
- package/src/pdf/__snapshots__/exampleWithHeaderAndFooter.jsx +308 -128
- package/src/pdf/defaultSchema/blocks.tsx +19 -12
- package/src/pdf/pdfExporter.test.tsx +9 -9
- package/src/pdf/pdfExporter.tsx +20 -17
- package/src/pdf/util/listItem.tsx +4 -2
- package/src/pdf/util/table/Table.tsx +4 -2
package/src/pdf/pdfExporter.tsx
CHANGED
|
@@ -42,7 +42,7 @@ type Options = ExporterOptions & {
|
|
|
42
42
|
export class PDFExporter<
|
|
43
43
|
B extends BlockSchema,
|
|
44
44
|
S extends StyleSchema,
|
|
45
|
-
I extends InlineContentSchema
|
|
45
|
+
I extends InlineContentSchema,
|
|
46
46
|
> extends Exporter<
|
|
47
47
|
B,
|
|
48
48
|
I,
|
|
@@ -92,7 +92,7 @@ export class PDFExporter<
|
|
|
92
92
|
TextProps["style"], // RS
|
|
93
93
|
React.ReactElement<Text> // TS
|
|
94
94
|
>["mappings"],
|
|
95
|
-
options?: Partial<Options
|
|
95
|
+
options?: Partial<Options>,
|
|
96
96
|
) {
|
|
97
97
|
const defaults = {
|
|
98
98
|
emojiSource: {
|
|
@@ -125,7 +125,7 @@ export class PDFExporter<
|
|
|
125
125
|
*/
|
|
126
126
|
public async transformBlocks(
|
|
127
127
|
blocks: Block<B, I, S>[], // Or BlockFromConfig<B[keyof B], I, S>?
|
|
128
|
-
nestingLevel = 0
|
|
128
|
+
nestingLevel = 0,
|
|
129
129
|
): Promise<React.ReactElement<Text>[]> {
|
|
130
130
|
const ret: React.ReactElement<Text>[] = [];
|
|
131
131
|
let numberedListIndex = 0;
|
|
@@ -140,7 +140,7 @@ export class PDFExporter<
|
|
|
140
140
|
const self = await this.mapBlock(
|
|
141
141
|
b as any,
|
|
142
142
|
nestingLevel,
|
|
143
|
-
numberedListIndex
|
|
143
|
+
numberedListIndex,
|
|
144
144
|
); // TODO: any
|
|
145
145
|
|
|
146
146
|
if (b.type === "pageBreak") {
|
|
@@ -156,7 +156,8 @@ export class PDFExporter<
|
|
|
156
156
|
paddingVertical: 3 * PIXELS_PER_POINT,
|
|
157
157
|
...this.styles.block,
|
|
158
158
|
...style,
|
|
159
|
-
}}
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
160
161
|
{self}
|
|
161
162
|
</View>
|
|
162
163
|
{children.length > 0 && (
|
|
@@ -164,11 +165,12 @@ export class PDFExporter<
|
|
|
164
165
|
style={{
|
|
165
166
|
marginLeft: FONT_SIZE * 1.5 * PIXELS_PER_POINT,
|
|
166
167
|
...this.styles.blockChildren,
|
|
167
|
-
}}
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
168
170
|
{children}
|
|
169
171
|
</View>
|
|
170
172
|
)}
|
|
171
|
-
|
|
173
|
+
</>,
|
|
172
174
|
);
|
|
173
175
|
}
|
|
174
176
|
|
|
@@ -184,7 +186,7 @@ export class PDFExporter<
|
|
|
184
186
|
Font.registerEmojiSource(this.options.emojiSource);
|
|
185
187
|
}
|
|
186
188
|
let font = await loadFontDataUrl(
|
|
187
|
-
await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf")
|
|
189
|
+
await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf"),
|
|
188
190
|
);
|
|
189
191
|
Font.register({
|
|
190
192
|
family: "Inter",
|
|
@@ -192,7 +194,7 @@ export class PDFExporter<
|
|
|
192
194
|
});
|
|
193
195
|
|
|
194
196
|
font = await loadFontDataUrl(
|
|
195
|
-
await import("@shared/assets/fonts/inter/Inter_18pt-Italic.ttf")
|
|
197
|
+
await import("@shared/assets/fonts/inter/Inter_18pt-Italic.ttf"),
|
|
196
198
|
);
|
|
197
199
|
Font.register({
|
|
198
200
|
family: "Inter",
|
|
@@ -201,7 +203,7 @@ export class PDFExporter<
|
|
|
201
203
|
});
|
|
202
204
|
|
|
203
205
|
font = await loadFontDataUrl(
|
|
204
|
-
await import("@shared/assets/fonts/inter/Inter_18pt-Bold.ttf")
|
|
206
|
+
await import("@shared/assets/fonts/inter/Inter_18pt-Bold.ttf"),
|
|
205
207
|
);
|
|
206
208
|
Font.register({
|
|
207
209
|
family: "Inter",
|
|
@@ -210,7 +212,7 @@ export class PDFExporter<
|
|
|
210
212
|
});
|
|
211
213
|
|
|
212
214
|
font = await loadFontDataUrl(
|
|
213
|
-
await import("@shared/assets/fonts/inter/Inter_18pt-BoldItalic.ttf")
|
|
215
|
+
await import("@shared/assets/fonts/inter/Inter_18pt-BoldItalic.ttf"),
|
|
214
216
|
);
|
|
215
217
|
Font.register({
|
|
216
218
|
family: "Inter",
|
|
@@ -220,7 +222,7 @@ export class PDFExporter<
|
|
|
220
222
|
});
|
|
221
223
|
|
|
222
224
|
font = await loadFontDataUrl(
|
|
223
|
-
await import("@shared/assets/fonts/GeistMono-Regular.ttf")
|
|
225
|
+
await import("@shared/assets/fonts/GeistMono-Regular.ttf"),
|
|
224
226
|
);
|
|
225
227
|
Font.register({
|
|
226
228
|
family: "GeistMono",
|
|
@@ -246,7 +248,7 @@ export class PDFExporter<
|
|
|
246
248
|
* The React component passed must be a React-PDF component
|
|
247
249
|
*/
|
|
248
250
|
footer?: React.ReactElement;
|
|
249
|
-
} = {}
|
|
251
|
+
} = {},
|
|
250
252
|
) {
|
|
251
253
|
await this.registerFonts();
|
|
252
254
|
|
|
@@ -269,7 +271,8 @@ export class PDFExporter<
|
|
|
269
271
|
right: this.styles.page.paddingHorizontal || 0,
|
|
270
272
|
},
|
|
271
273
|
this.styles.footer,
|
|
272
|
-
]}
|
|
274
|
+
]}
|
|
275
|
+
>
|
|
273
276
|
{options.footer}
|
|
274
277
|
</View>
|
|
275
278
|
)}
|
|
@@ -279,7 +282,7 @@ export class PDFExporter<
|
|
|
279
282
|
}
|
|
280
283
|
|
|
281
284
|
protected blocknoteDefaultPropsToReactPDFStyle(
|
|
282
|
-
props: Partial<DefaultProps
|
|
285
|
+
props: Partial<DefaultProps>,
|
|
283
286
|
): Style {
|
|
284
287
|
return {
|
|
285
288
|
textAlign: props.textAlignment,
|
|
@@ -299,8 +302,8 @@ export class PDFExporter<
|
|
|
299
302
|
props.textAlignment === "right"
|
|
300
303
|
? "flex-end"
|
|
301
304
|
: props.textAlignment === "center"
|
|
302
|
-
|
|
303
|
-
|
|
305
|
+
? "center"
|
|
306
|
+
: undefined,
|
|
304
307
|
};
|
|
305
308
|
}
|
|
306
309
|
}
|
|
@@ -26,7 +26,8 @@ export const CHECK_MARKER_UNCHECKED = (
|
|
|
26
26
|
height="12"
|
|
27
27
|
viewBox="0 -960 960 960"
|
|
28
28
|
width="12"
|
|
29
|
-
fill="undefined"
|
|
29
|
+
fill="undefined"
|
|
30
|
+
>
|
|
30
31
|
<Path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Z" />
|
|
31
32
|
</Svg>
|
|
32
33
|
);
|
|
@@ -38,7 +39,8 @@ export const CHECK_MARKER_CHECKED = (
|
|
|
38
39
|
height="12"
|
|
39
40
|
viewBox="0 -960 960 960"
|
|
40
41
|
width="12"
|
|
41
|
-
fill="undefined"
|
|
42
|
+
fill="undefined"
|
|
43
|
+
>
|
|
42
44
|
<Path d="m424-312 282-282-56-56-226 226-114-114-56 56 170 170ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z" />
|
|
43
45
|
</Svg>
|
|
44
46
|
);
|
|
@@ -66,7 +66,8 @@ export const Table = (props: {
|
|
|
66
66
|
styles.row,
|
|
67
67
|
rowIndex === props.data.rows.length - 1 ? styles.bottomCell : {},
|
|
68
68
|
]}
|
|
69
|
-
key={rowIndex}
|
|
69
|
+
key={rowIndex}
|
|
70
|
+
>
|
|
70
71
|
{row.cells.map((c, colIndex) => {
|
|
71
72
|
const cell = mapTableCell(c);
|
|
72
73
|
|
|
@@ -101,7 +102,8 @@ export const Table = (props: {
|
|
|
101
102
|
textAlign: cell.props.textAlignment,
|
|
102
103
|
},
|
|
103
104
|
]}
|
|
104
|
-
key={colIndex}
|
|
105
|
+
key={colIndex}
|
|
106
|
+
>
|
|
105
107
|
{props.transformer.transformInlineContent(cell.content)}
|
|
106
108
|
</View>
|
|
107
109
|
);
|