@blocknote/xl-docx-exporter 0.24.2 → 0.25.1
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--NrcstcO.cjs +2 -0
- package/dist/GeistMono-Regular--NrcstcO.cjs.map +1 -0
- package/dist/Inter_18pt-Regular-CCMUw8TC.cjs +2 -0
- package/dist/Inter_18pt-Regular-CCMUw8TC.cjs.map +1 -0
- package/dist/blocknote-xl-docx-exporter.cjs +3 -0
- package/dist/blocknote-xl-docx-exporter.cjs.map +1 -0
- package/dist/blocknote-xl-docx-exporter.js +196 -173
- package/dist/blocknote-xl-docx-exporter.js.map +1 -1
- package/dist/styles-C7c5RlKz.cjs +991 -0
- package/dist/styles-C7c5RlKz.cjs.map +1 -0
- package/dist/webpack-stats.json +1 -1
- package/package.json +7 -8
- package/src/docx/__snapshots__/basic/document.xml +49 -1
- package/src/docx/defaultSchema/blocks.ts +2 -2
- package/src/docx/docxExporter.test.ts +24 -11
- package/src/docx/docxExporter.ts +2 -2
- package/src/docx/template/README.md +3 -0
- package/src/docx/util/Table.tsx +81 -22
- package/dist/blocknote-xl-docx-exporter.umd.cjs +0 -992
- package/dist/blocknote-xl-docx-exporter.umd.cjs.map +0 -1
- package/src/docx/imageUtil.ts +0 -21
package/src/docx/util/Table.tsx
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Exporter,
|
|
3
|
+
InlineContentSchema,
|
|
4
|
+
mapTableCell,
|
|
5
|
+
TableContent,
|
|
6
|
+
UnreachableCaseError,
|
|
7
|
+
} from "@blocknote/core";
|
|
2
8
|
import {
|
|
3
9
|
Table as DocxTable,
|
|
4
10
|
Paragraph,
|
|
5
11
|
ParagraphChild,
|
|
12
|
+
ShadingType,
|
|
6
13
|
TableCell,
|
|
7
14
|
TableRow,
|
|
8
15
|
} from "docx";
|
|
@@ -12,32 +19,84 @@ export const Table = (
|
|
|
12
19
|
t: Exporter<any, any, any, any, ParagraphChild, any, any>
|
|
13
20
|
) => {
|
|
14
21
|
const DEFAULT_COLUMN_WIDTH = 120;
|
|
22
|
+
|
|
23
|
+
// If headerRows is 1, then the first row is a header row
|
|
24
|
+
const headerRows = new Array(data.headerRows ?? 0).fill(true);
|
|
25
|
+
// If headerCols is 1, then the first column is a header column
|
|
26
|
+
const headerCols = new Array(data.headerCols ?? 0).fill(true);
|
|
27
|
+
|
|
15
28
|
return new DocxTable({
|
|
16
29
|
layout: "autofit",
|
|
17
30
|
columnWidths: data.columnWidths.map(
|
|
18
31
|
(w) =>
|
|
19
32
|
(w ?? DEFAULT_COLUMN_WIDTH) * /* to points */ 0.75 * /* to twips */ 20
|
|
20
33
|
),
|
|
21
|
-
rows: data.rows.map(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
rows: data.rows.map((row, rowIndex) => {
|
|
35
|
+
const isHeaderRow = headerRows[rowIndex];
|
|
36
|
+
return new TableRow({
|
|
37
|
+
tableHeader: isHeaderRow,
|
|
38
|
+
children: row.cells.map((c, colIndex) => {
|
|
39
|
+
const width = data.columnWidths?.[colIndex];
|
|
40
|
+
const cell = mapTableCell(c);
|
|
41
|
+
const isHeaderColumn = headerCols[colIndex];
|
|
42
|
+
|
|
43
|
+
return new TableCell({
|
|
44
|
+
width: width
|
|
45
|
+
? {
|
|
46
|
+
size: `${width * 0.75}pt`,
|
|
47
|
+
type: "dxa",
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
columnSpan: cell.props.colspan,
|
|
51
|
+
rowSpan: cell.props.rowspan,
|
|
52
|
+
shading:
|
|
53
|
+
cell.props.backgroundColor === "default" ||
|
|
54
|
+
!cell.props.backgroundColor
|
|
55
|
+
? undefined
|
|
56
|
+
: {
|
|
57
|
+
type: ShadingType.SOLID,
|
|
58
|
+
color:
|
|
59
|
+
t.options.colors[
|
|
60
|
+
cell.props
|
|
61
|
+
.backgroundColor as keyof typeof t.options.colors
|
|
62
|
+
].background.slice(1),
|
|
63
|
+
},
|
|
64
|
+
children: [
|
|
65
|
+
new Paragraph({
|
|
66
|
+
children: t.transformInlineContent(cell.content),
|
|
67
|
+
|
|
68
|
+
alignment:
|
|
69
|
+
!cell.props.textAlignment ||
|
|
70
|
+
cell.props.textAlignment === "left"
|
|
71
|
+
? undefined
|
|
72
|
+
: cell.props.textAlignment === "center"
|
|
73
|
+
? "center"
|
|
74
|
+
: cell.props.textAlignment === "right"
|
|
75
|
+
? "right"
|
|
76
|
+
: cell.props.textAlignment === "justify"
|
|
77
|
+
? "distribute"
|
|
78
|
+
: (() => {
|
|
79
|
+
throw new UnreachableCaseError(
|
|
80
|
+
cell.props.textAlignment
|
|
81
|
+
);
|
|
82
|
+
})(),
|
|
83
|
+
run: {
|
|
84
|
+
// TODO add support for table headers exporting, bolding seems to not be working at the moment
|
|
85
|
+
bold: isHeaderRow || isHeaderColumn,
|
|
86
|
+
// TODO table paragraph color seems to not be working at the moment
|
|
87
|
+
// Probably because the runs are setting their own color
|
|
88
|
+
color:
|
|
89
|
+
cell.props.textColor === "default" || !cell.props.textColor
|
|
90
|
+
? undefined
|
|
91
|
+
: t.options.colors[
|
|
92
|
+
cell.props.textColor as keyof typeof t.options.colors
|
|
93
|
+
].text.slice(1),
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
}),
|
|
42
101
|
});
|
|
43
102
|
};
|