@internetstiftelsen/charts 0.14.1 → 0.14.2
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/README.md +2 -2
- package/dist/export-xlsx.d.ts +2 -2
- package/dist/export-xlsx.js +22 -26
- package/docs/components.md +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -394,8 +394,8 @@ await chart.export('xlsx', { download: true, sheetName: 'Data' });
|
|
|
394
394
|
await chart.export('pdf', { download: true, pdfMargin: 16 });
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
`xlsx` and `pdf` are lazy-loaded and require optional dependencies
|
|
398
|
-
`jspdf`) only when those formats are used.
|
|
397
|
+
`xlsx` and `pdf` are lazy-loaded and require optional dependencies
|
|
398
|
+
(`write-excel-file` and `jspdf`) only when those formats are used.
|
|
399
399
|
|
|
400
400
|
## Import
|
|
401
401
|
|
package/dist/export-xlsx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ChartData, ExportOptions } from './types.js';
|
|
2
|
-
type
|
|
3
|
-
export declare function exportXLSXBlob(data: ChartData, options?: ExportOptions, loader?:
|
|
2
|
+
type XlsxWriterLoader = () => Promise<unknown>;
|
|
3
|
+
export declare function exportXLSXBlob(data: ChartData, options?: ExportOptions, loader?: XlsxWriterLoader): Promise<Blob>;
|
|
4
4
|
export {};
|
package/dist/export-xlsx.js
CHANGED
|
@@ -3,42 +3,38 @@ const XLSX_MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadshee
|
|
|
3
3
|
function isObject(value) {
|
|
4
4
|
return typeof value === 'object' && value !== null;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function resolveXlsxWriter(moduleValue) {
|
|
7
|
+
if (typeof moduleValue === 'function') {
|
|
8
|
+
return moduleValue;
|
|
9
|
+
}
|
|
7
10
|
if (!isObject(moduleValue)) {
|
|
8
|
-
throw new Error('Invalid "
|
|
11
|
+
throw new Error('Invalid "write-excel-file" module export');
|
|
9
12
|
}
|
|
10
13
|
const moduleCandidate = moduleValue;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: moduleCandidate;
|
|
14
|
-
if (!xlsxCandidate.utils || !xlsxCandidate.write) {
|
|
15
|
-
throw new Error('Invalid "xlsx" module export');
|
|
14
|
+
if (typeof moduleCandidate.default === 'function') {
|
|
15
|
+
return moduleCandidate.default;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
utils: xlsxCandidate.utils,
|
|
19
|
-
write: xlsxCandidate.write,
|
|
20
|
-
};
|
|
17
|
+
throw new Error('Invalid "write-excel-file" module export');
|
|
21
18
|
}
|
|
22
|
-
async function
|
|
23
|
-
return import('
|
|
19
|
+
async function defaultXlsxWriterLoader() {
|
|
20
|
+
return import('write-excel-file/universal');
|
|
24
21
|
}
|
|
25
|
-
export async function exportXLSXBlob(data, options, loader =
|
|
26
|
-
let
|
|
22
|
+
export async function exportXLSXBlob(data, options, loader = defaultXlsxWriterLoader) {
|
|
23
|
+
let xlsxWriterModule;
|
|
27
24
|
try {
|
|
28
|
-
|
|
25
|
+
xlsxWriterModule = await loader();
|
|
29
26
|
}
|
|
30
27
|
catch {
|
|
31
|
-
throw new Error('XLSX export requires optional dependency "
|
|
28
|
+
throw new Error('XLSX export requires optional dependency "write-excel-file". Install optional dependency "write-excel-file".');
|
|
32
29
|
}
|
|
33
|
-
const
|
|
30
|
+
const writeXlsxFile = resolveXlsxWriter(xlsxWriterModule);
|
|
34
31
|
const { columns, rows } = toTabularData(data, options?.columns);
|
|
35
|
-
const worksheet = xlsx.utils.aoa_to_sheet([columns, ...rows]);
|
|
36
|
-
const workbook = xlsx.utils.book_new();
|
|
37
32
|
const sheetName = options?.sheetName?.trim() || 'Sheet1';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
const blob = await writeXlsxFile([columns, ...rows], {
|
|
34
|
+
sheet: sheetName,
|
|
35
|
+
}).toBlob();
|
|
36
|
+
if (blob.type === XLSX_MIME_TYPE) {
|
|
37
|
+
return blob;
|
|
38
|
+
}
|
|
39
|
+
return new Blob([await blob.arrayBuffer()], { type: XLSX_MIME_TYPE });
|
|
44
40
|
}
|
package/docs/components.md
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.14.
|
|
2
|
+
"version": "0.14.2",
|
|
3
3
|
"name": "@internetstiftelsen/charts",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
41
|
"jspdf": "^4.2.1",
|
|
42
|
-
"
|
|
42
|
+
"write-excel-file": "^4.0.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@eslint/js": "^10.0.1",
|
|
@@ -57,30 +57,30 @@
|
|
|
57
57
|
"@types/d3": "^7.4.3",
|
|
58
58
|
"@types/d3-cloud": "^1.2.9",
|
|
59
59
|
"@types/node": "^25.9.1",
|
|
60
|
-
"@types/react": "^19.2.
|
|
60
|
+
"@types/react": "^19.2.16",
|
|
61
61
|
"@types/react-dom": "^19.2.3",
|
|
62
62
|
"@vitejs/plugin-react-swc": "^4.3.1",
|
|
63
63
|
"class-variance-authority": "^0.7.1",
|
|
64
64
|
"clsx": "^2.1.1",
|
|
65
|
-
"eslint": "^10.4.
|
|
65
|
+
"eslint": "^10.4.1",
|
|
66
66
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
67
67
|
"eslint-plugin-react-refresh": "^0.5.2",
|
|
68
68
|
"globals": "^17.6.0",
|
|
69
69
|
"handsontable": "^17.1.0",
|
|
70
70
|
"jsdom": "^29.1.1",
|
|
71
|
-
"lucide-react": "^1.
|
|
71
|
+
"lucide-react": "^1.17.0",
|
|
72
72
|
"prettier": "3.8.3",
|
|
73
73
|
"radix-ui": "^1.4.3",
|
|
74
|
-
"react": "^19.2.
|
|
75
|
-
"react-dom": "^19.2.
|
|
74
|
+
"react": "^19.2.7",
|
|
75
|
+
"react-dom": "^19.2.7",
|
|
76
76
|
"sass": "^1.100.0",
|
|
77
77
|
"tailwind-merge": "^3.6.0",
|
|
78
78
|
"tailwindcss": "^4.3.0",
|
|
79
79
|
"tsc-alias": "^1.8.17",
|
|
80
80
|
"tw-animate-css": "^1.4.0",
|
|
81
81
|
"typescript": "~6.0.3",
|
|
82
|
-
"typescript-eslint": "^8.
|
|
83
|
-
"vite": "^8.0.
|
|
84
|
-
"vitest": "^4.1.
|
|
82
|
+
"typescript-eslint": "^8.60.1",
|
|
83
|
+
"vite": "^8.0.16",
|
|
84
|
+
"vitest": "^4.1.8"
|
|
85
85
|
}
|
|
86
86
|
}
|