@blocknote/xl-docx-exporter 0.21.0 → 0.23.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/GeistMono-Regular-D4rKXxwr.js +5 -0
- package/dist/GeistMono-Regular-D4rKXxwr.js.map +1 -0
- package/dist/blocknote-xl-docx-exporter.js +160 -137
- package/dist/blocknote-xl-docx-exporter.js.map +1 -1
- package/dist/blocknote-xl-docx-exporter.umd.cjs +5 -4
- package/dist/blocknote-xl-docx-exporter.umd.cjs.map +1 -1
- package/dist/{styles-CcdeAskf.js → styles-CujW8HHo.js} +3 -3
- package/dist/{styles-CcdeAskf.js.map → styles-CujW8HHo.js.map} +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +7 -3
- package/src/docx/__snapshots__/basic/document.xml +18 -5
- package/src/docx/__snapshots__/basic/styles.xml +2 -2
- package/src/docx/defaultSchema/blocks.ts +25 -10
- package/src/docx/defaultSchema/styles.ts +1 -1
- package/src/docx/docxExporter.test.ts +7 -3
- package/src/docx/docxExporter.ts +23 -5
- package/src/docx/template/word/styles.xml +2 -2
- package/types/src/docx/defaultSchema/blocks.d.ts +2 -2
- package/types/src/docx/defaultSchema/index.d.ts +25 -0
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
COLORS_DEFAULT,
|
|
4
4
|
DefaultBlockSchema,
|
|
5
5
|
DefaultProps,
|
|
6
|
+
pageBreakSchema,
|
|
7
|
+
StyledText,
|
|
6
8
|
UnreachableCaseError,
|
|
7
9
|
} from "@blocknote/core";
|
|
8
10
|
import {
|
|
@@ -11,6 +13,7 @@ import {
|
|
|
11
13
|
ExternalHyperlink,
|
|
12
14
|
IParagraphOptions,
|
|
13
15
|
ImageRun,
|
|
16
|
+
PageBreak,
|
|
14
17
|
Paragraph,
|
|
15
18
|
ParagraphChild,
|
|
16
19
|
ShadingType,
|
|
@@ -55,7 +58,7 @@ function blockPropsToStyles(
|
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
export const docxBlockMappingForDefaultSchema: BlockMapping<
|
|
58
|
-
DefaultBlockSchema,
|
|
61
|
+
DefaultBlockSchema & typeof pageBreakSchema.blockSchema,
|
|
59
62
|
any,
|
|
60
63
|
any,
|
|
61
64
|
| Promise<Paragraph[] | Paragraph | DocxTable>
|
|
@@ -131,17 +134,29 @@ export const docxBlockMappingForDefaultSchema: BlockMapping<
|
|
|
131
134
|
...caption(block.props, exporter),
|
|
132
135
|
];
|
|
133
136
|
},
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
codeBlock: (block) => {
|
|
138
|
+
const textContent = (block.content as StyledText<any>[])[0]?.text || "";
|
|
139
|
+
|
|
136
140
|
return new Paragraph({
|
|
137
|
-
// ...blockPropsToStyles(block.props, exporter.options.colors),
|
|
138
141
|
style: "Codeblock",
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
shading: {
|
|
143
|
+
type: ShadingType.SOLID,
|
|
144
|
+
fill: "161616",
|
|
145
|
+
color: "161616",
|
|
146
|
+
},
|
|
147
|
+
children: [
|
|
148
|
+
...textContent.split("\n").map((line, index) => {
|
|
149
|
+
return new TextRun({
|
|
150
|
+
text: line,
|
|
151
|
+
break: index > 0 ? 1 : 0,
|
|
152
|
+
});
|
|
153
|
+
}),
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
pageBreak: () => {
|
|
158
|
+
return new Paragraph({
|
|
159
|
+
children: [new PageBreak()],
|
|
145
160
|
});
|
|
146
161
|
},
|
|
147
162
|
image: async (block, exporter) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockNoteSchema } from "@blocknote/core";
|
|
1
|
+
import { BlockNoteSchema, defaultBlockSpecs, PageBreak } from "@blocknote/core";
|
|
2
2
|
import { testDocument } from "@shared/testDocument.js";
|
|
3
3
|
import AdmZip from "adm-zip";
|
|
4
4
|
import { Packer, Paragraph, TextRun } from "docx";
|
|
@@ -10,7 +10,9 @@ import { DOCXExporter } from "./docxExporter.js";
|
|
|
10
10
|
describe("exporter", () => {
|
|
11
11
|
it("should export a document", { timeout: 10000 }, async () => {
|
|
12
12
|
const exporter = new DOCXExporter(
|
|
13
|
-
BlockNoteSchema.create(
|
|
13
|
+
BlockNoteSchema.create({
|
|
14
|
+
blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
|
|
15
|
+
}),
|
|
14
16
|
docxDefaultSchemaMappings
|
|
15
17
|
);
|
|
16
18
|
const doc = await exporter.toDocxJsDocument(testDocument);
|
|
@@ -33,7 +35,9 @@ describe("exporter", () => {
|
|
|
33
35
|
{ timeout: 10000 },
|
|
34
36
|
async () => {
|
|
35
37
|
const exporter = new DOCXExporter(
|
|
36
|
-
BlockNoteSchema.create(
|
|
38
|
+
BlockNoteSchema.create({
|
|
39
|
+
blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
|
|
40
|
+
}),
|
|
37
41
|
docxDefaultSchemaMappings
|
|
38
42
|
);
|
|
39
43
|
|
package/src/docx/docxExporter.ts
CHANGED
|
@@ -142,17 +142,35 @@ export class DOCXExporter<
|
|
|
142
142
|
// Unfortunately, loading the variable font doesn't work
|
|
143
143
|
// "./src/fonts/Inter-VariableFont_opsz,wght.ttf",
|
|
144
144
|
|
|
145
|
-
let
|
|
145
|
+
let interFont = await loadFileBuffer(
|
|
146
146
|
await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf")
|
|
147
147
|
);
|
|
148
|
+
let geistMonoFont = await loadFileBuffer(
|
|
149
|
+
await import("@shared/assets/fonts/GeistMono-Regular.ttf")
|
|
150
|
+
);
|
|
148
151
|
|
|
149
|
-
if (
|
|
150
|
-
|
|
152
|
+
if (
|
|
153
|
+
interFont instanceof ArrayBuffer ||
|
|
154
|
+
geistMonoFont instanceof Uint8Array
|
|
155
|
+
) {
|
|
156
|
+
// conversion with Polyfill needed because docxjs requires Buffer
|
|
151
157
|
const Buffer = (await import("buffer")).Buffer;
|
|
152
|
-
|
|
158
|
+
|
|
159
|
+
if (interFont instanceof ArrayBuffer) {
|
|
160
|
+
interFont = Buffer.from(interFont);
|
|
161
|
+
}
|
|
162
|
+
if (geistMonoFont instanceof ArrayBuffer) {
|
|
163
|
+
geistMonoFont = Buffer.from(geistMonoFont);
|
|
164
|
+
}
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
return [
|
|
167
|
+
return [
|
|
168
|
+
{ name: "Inter", data: interFont as Buffer },
|
|
169
|
+
{
|
|
170
|
+
name: "GeistMono",
|
|
171
|
+
data: geistMonoFont as Buffer,
|
|
172
|
+
},
|
|
173
|
+
];
|
|
156
174
|
}
|
|
157
175
|
|
|
158
176
|
protected async createDefaultDocumentOptions(): Promise<DocumentOptions> {
|
|
@@ -983,8 +983,8 @@
|
|
|
983
983
|
<w:basedOn w:val="Normal" />
|
|
984
984
|
<w:rPr>
|
|
985
985
|
<w:noProof />
|
|
986
|
-
<w:color w:val="
|
|
987
|
-
<w:
|
|
986
|
+
<w:color w:val="ffffff"/>
|
|
987
|
+
<w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
|
|
988
988
|
</w:rPr>
|
|
989
989
|
</w:style>
|
|
990
990
|
</w:styles>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BlockMapping, DefaultBlockSchema } from "@blocknote/core";
|
|
1
|
+
import { BlockMapping, DefaultBlockSchema, pageBreakSchema } from "@blocknote/core";
|
|
2
2
|
import { Table as DocxTable, Paragraph, ParagraphChild } from "docx";
|
|
3
|
-
export declare const docxBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema, any, any, Promise<Paragraph[] | Paragraph | DocxTable> | Paragraph[] | Paragraph | DocxTable, ParagraphChild>;
|
|
3
|
+
export declare const docxBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema & typeof pageBreakSchema.blockSchema, any, any, Promise<Paragraph[] | Paragraph | DocxTable> | Paragraph[] | Paragraph | DocxTable, ParagraphChild>;
|
|
@@ -137,6 +137,10 @@ export declare const docxDefaultSchemaMappings: {
|
|
|
137
137
|
type: "numberedListItem";
|
|
138
138
|
content: "inline";
|
|
139
139
|
propSchema: {
|
|
140
|
+
start: {
|
|
141
|
+
default: undefined;
|
|
142
|
+
type: "number";
|
|
143
|
+
};
|
|
140
144
|
backgroundColor: {
|
|
141
145
|
default: "default";
|
|
142
146
|
};
|
|
@@ -153,6 +157,10 @@ export declare const docxDefaultSchemaMappings: {
|
|
|
153
157
|
type: "numberedListItem";
|
|
154
158
|
content: "inline";
|
|
155
159
|
propSchema: {
|
|
160
|
+
start: {
|
|
161
|
+
default: undefined;
|
|
162
|
+
type: "number";
|
|
163
|
+
};
|
|
156
164
|
backgroundColor: {
|
|
157
165
|
default: "default";
|
|
158
166
|
};
|
|
@@ -438,6 +446,23 @@ export declare const docxDefaultSchemaMappings: {
|
|
|
438
446
|
fileBlockAccept: string[];
|
|
439
447
|
}, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
|
|
440
448
|
};
|
|
449
|
+
}> & import("@blocknote/core").BlockSchemaFromSpecs<{
|
|
450
|
+
pageBreak: {
|
|
451
|
+
config: {
|
|
452
|
+
type: "pageBreak";
|
|
453
|
+
propSchema: {};
|
|
454
|
+
content: "none";
|
|
455
|
+
isFileBlock: false;
|
|
456
|
+
isSelectable: false;
|
|
457
|
+
};
|
|
458
|
+
implementation: import("@blocknote/core").TiptapBlockImplementation<{
|
|
459
|
+
type: "pageBreak";
|
|
460
|
+
propSchema: {};
|
|
461
|
+
content: "none";
|
|
462
|
+
isFileBlock: false;
|
|
463
|
+
isSelectable: false;
|
|
464
|
+
}, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
|
|
465
|
+
};
|
|
441
466
|
}>, any, any, import("docx").Table | import("docx").Paragraph | import("docx").Paragraph[] | Promise<import("docx").Table | import("docx").Paragraph | import("docx").Paragraph[]>, import("docx").ParagraphChild>;
|
|
442
467
|
inlineContentMapping: import("@blocknote/core").InlineContentMapping<import("@blocknote/core").InlineContentSchemaFromSpecs<{
|
|
443
468
|
text: {
|