@alaarab/ogrid-react-xlsx-browser 2.16.0 → 2.17.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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/ogrid-xlsx.css +1 -1
- package/dist/ogrid-xlsx.d.ts +1 -0
- package/dist/ogrid-xlsx.js +47 -41
- package/dist/types/XlsxGrid.d.ts +18 -0
- package/dist/types/XlsxWorkbookGrid.d.ts +23 -0
- package/dist/types/exportToXlsx.d.ts +34 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/sheetMapper.d.ts +90 -0
- package/package.json +12 -8
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type ExcelJS from 'exceljs';
|
|
2
|
+
import { type SheetToGridDataOptions } from './sheetMapper.js';
|
|
3
|
+
export interface XlsxGridProps {
|
|
4
|
+
workbook: ExcelJS.Workbook;
|
|
5
|
+
sheetName: string;
|
|
6
|
+
/** CSS height for the grid container. Defaults to '100%'. */
|
|
7
|
+
height?: number | string;
|
|
8
|
+
/** Override grid density. Defaults to 'compact' (matches Excel-like row size). */
|
|
9
|
+
density?: 'compact' | 'normal' | 'comfortable';
|
|
10
|
+
/** See {@link SheetToGridDataOptions.headerRow}. Defaults to 'auto'. */
|
|
11
|
+
headerRow?: SheetToGridDataOptions['headerRow'];
|
|
12
|
+
/**
|
|
13
|
+
* Load limits for untrusted files; see {@link SheetToGridDataOptions}.
|
|
14
|
+
* When a sheet exceeds them a notice above the grid says what was cut.
|
|
15
|
+
*/
|
|
16
|
+
limits?: Pick<SheetToGridDataOptions, 'maxRows' | 'maxCols' | 'maxCells'>;
|
|
17
|
+
}
|
|
18
|
+
export declare function XlsxGrid({ workbook, sheetName, height, density, headerRow, limits, }: XlsxGridProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type ExcelJS from 'exceljs';
|
|
2
|
+
import { type XlsxGridProps } from './XlsxGrid.js';
|
|
3
|
+
import { type SheetToGridDataOptions } from './sheetMapper.js';
|
|
4
|
+
type Source = {
|
|
5
|
+
blob: Blob;
|
|
6
|
+
} | {
|
|
7
|
+
workbook: ExcelJS.Workbook;
|
|
8
|
+
};
|
|
9
|
+
export type XlsxWorkbookGridProps = Source & {
|
|
10
|
+
/** CSS height of the whole component. Defaults to '100%'. */
|
|
11
|
+
height?: number | string;
|
|
12
|
+
/** Initial sheet to display. Defaults to the first sheet. */
|
|
13
|
+
initialSheet?: string;
|
|
14
|
+
density?: 'compact' | 'normal' | 'comfortable';
|
|
15
|
+
/** Called when the user switches sheets. */
|
|
16
|
+
onSheetChange?: (sheetName: string) => void;
|
|
17
|
+
/** See {@link SheetToGridDataOptions.headerRow}. Defaults to 'auto'. */
|
|
18
|
+
headerRow?: SheetToGridDataOptions['headerRow'];
|
|
19
|
+
/** Per-sheet load limits; see {@link XlsxGridProps.limits}. */
|
|
20
|
+
limits?: XlsxGridProps['limits'];
|
|
21
|
+
};
|
|
22
|
+
export declare function XlsxWorkbookGrid(props: XlsxWorkbookGridProps): import("react").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ExcelJS from 'exceljs';
|
|
2
|
+
import { type CsvColumn } from '@alaarab/ogrid-core';
|
|
3
|
+
export declare const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
4
|
+
export interface XlsxExportOptions {
|
|
5
|
+
/** Worksheet name. Defaults to 'Sheet1'. */
|
|
6
|
+
sheetName?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Formula cells to emit, in the same `{col, row, formula}` shape
|
|
9
|
+
* `sheetToGridData` produces on import (0-based data coordinates, header
|
|
10
|
+
* row excluded). Each is written as `{ formula, result }` — Excel shows the
|
|
11
|
+
* cached result immediately and recalculates on open. The public grid API
|
|
12
|
+
* does not expose formulas, so pass this through from the `initialFormulas`
|
|
13
|
+
* you already hold (e.g. from an imported workbook).
|
|
14
|
+
*/
|
|
15
|
+
formulas?: Array<{
|
|
16
|
+
col: number;
|
|
17
|
+
row: number;
|
|
18
|
+
formula: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build an ExcelJS workbook from grid data: a header row from column names,
|
|
23
|
+
* then one row per item. Values are written as native JS types (number, Date,
|
|
24
|
+
* boolean, string) so ExcelJS assigns the matching cell type — symmetric with
|
|
25
|
+
* how `sheetToGridData` detects column types on import.
|
|
26
|
+
*/
|
|
27
|
+
export declare function workbookFromGridData<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => unknown, options?: XlsxExportOptions): ExcelJS.Workbook;
|
|
28
|
+
/** Serialize a workbook to a Blob with the .xlsx MIME type. */
|
|
29
|
+
export declare function xlsxBlobFromWorkbook(wb: ExcelJS.Workbook): Promise<Blob>;
|
|
30
|
+
/**
|
|
31
|
+
* Export grid data as a downloaded .xlsx file (browser-only). Mirrors
|
|
32
|
+
* `exportToCsv(items, columns, getValue, filename)` from @alaarab/ogrid-core.
|
|
33
|
+
*/
|
|
34
|
+
export declare function exportToXlsx<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => unknown, filename?: string, options?: XlsxExportOptions): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type ExcelJS from 'exceljs';
|
|
2
|
+
import { type XlsxWorkbookGridProps } from './XlsxWorkbookGrid.js';
|
|
3
|
+
export { XlsxGrid, type XlsxGridProps } from './XlsxGrid.js';
|
|
4
|
+
export { XlsxWorkbookGrid, type XlsxWorkbookGridProps } from './XlsxWorkbookGrid.js';
|
|
5
|
+
export { workbookFromBlob, sheetToGridData, listSheets, type SheetGridData, type SheetRow, type SheetToGridDataOptions, DEFAULT_MAX_ROWS, DEFAULT_MAX_COLS, DEFAULT_MAX_CELLS, } from './sheetMapper.js';
|
|
6
|
+
export { exportToXlsx, workbookFromGridData, xlsxBlobFromWorkbook, XLSX_MIME_TYPE, type XlsxExportOptions, } from './exportToXlsx.js';
|
|
7
|
+
export interface MountOptions {
|
|
8
|
+
/** Pre-parsed workbook (use this OR blob, not both). */
|
|
9
|
+
workbook?: ExcelJS.Workbook;
|
|
10
|
+
/** Raw blob — parsed lazily inside the component. */
|
|
11
|
+
blob?: Blob;
|
|
12
|
+
initialSheet?: string;
|
|
13
|
+
density?: 'compact' | 'normal' | 'comfortable';
|
|
14
|
+
height?: number | string;
|
|
15
|
+
onSheetChange?: (sheetName: string) => void;
|
|
16
|
+
/** See {@link SheetToGridDataOptions.headerRow}. Defaults to 'auto'. */
|
|
17
|
+
headerRow?: 'auto' | 'header' | 'none';
|
|
18
|
+
/** Load limits for untrusted files; see {@link XlsxWorkbookGridProps.limits}. */
|
|
19
|
+
limits?: XlsxWorkbookGridProps['limits'];
|
|
20
|
+
}
|
|
21
|
+
/** Imperative mount for non-React hosts. Returns an unmount function. */
|
|
22
|
+
export declare function mount(node: Element, opts: MountOptions): () => void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import ExcelJS from 'exceljs';
|
|
2
|
+
import type { IColumnDef } from '@alaarab/ogrid-core';
|
|
3
|
+
/**
|
|
4
|
+
* Output of sheetToGridData. Feeds straight into <OGrid> as
|
|
5
|
+
* `columns={data.columns}` `data={data.rows}` `initialFormulas={data.initialFormulas}`.
|
|
6
|
+
*/
|
|
7
|
+
export interface SheetGridData {
|
|
8
|
+
columns: IColumnDef<SheetRow>[];
|
|
9
|
+
rows: SheetRow[];
|
|
10
|
+
initialFormulas: Array<{
|
|
11
|
+
col: number;
|
|
12
|
+
row: number;
|
|
13
|
+
formula: string;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Set when the sheet's populated area exceeded `maxRows`/`maxCols`/
|
|
17
|
+
* `maxCells` and was cut down. Holds the untruncated extent so callers can
|
|
18
|
+
* tell the user what was left out.
|
|
19
|
+
*/
|
|
20
|
+
truncated?: {
|
|
21
|
+
rowCount: number;
|
|
22
|
+
columnCount: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Row shape — keyed by column letter (A, B, C, ..., AA, AB, ...).
|
|
26
|
+
* `__rowIdx` is a synthetic id (0-based) so getRowId can be `(r) => r.__rowIdx`. */
|
|
27
|
+
export type SheetRow = Record<string, unknown> & {
|
|
28
|
+
__rowIdx: number;
|
|
29
|
+
};
|
|
30
|
+
/** Options accepted by {@link sheetToGridData}. */
|
|
31
|
+
export interface SheetToGridDataOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Whether to promote row 1 of the worksheet into column names.
|
|
34
|
+
*
|
|
35
|
+
* - `'auto'` (default): promote when row 1 looks like a header row —
|
|
36
|
+
* every non-empty cell is a non-empty string and the sheet has at
|
|
37
|
+
* least 2 rows. Otherwise keep A/B/C as column names.
|
|
38
|
+
* - `'header'`: always promote row 1, coercing values to strings.
|
|
39
|
+
* Falls back to the column letter when a cell is empty.
|
|
40
|
+
* - `'none'`: legacy behaviour — column names stay as A/B/C and
|
|
41
|
+
* row 1 is returned as the first data row.
|
|
42
|
+
*
|
|
43
|
+
* `columnId` is always the column letter so the `cellReferences`
|
|
44
|
+
* strip and any `INDIRECT("A1")`-style formula references keep
|
|
45
|
+
* resolving the same way.
|
|
46
|
+
*/
|
|
47
|
+
headerRow?: 'auto' | 'header' | 'none';
|
|
48
|
+
/** Maximum worksheet rows to load (default 1,048,576, Excel's own limit). */
|
|
49
|
+
maxRows?: number;
|
|
50
|
+
/** Maximum worksheet columns to load (default 1,000). */
|
|
51
|
+
maxCols?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Maximum rows × columns to load (default 5,000,000). A few-KB xlsx with
|
|
54
|
+
* one far-away cell has a used range of billions of cells; this keeps an
|
|
55
|
+
* untrusted file from freezing the page. Rows are dropped from the bottom
|
|
56
|
+
* to fit.
|
|
57
|
+
*/
|
|
58
|
+
maxCells?: number;
|
|
59
|
+
}
|
|
60
|
+
export declare const DEFAULT_MAX_ROWS = 1048576;
|
|
61
|
+
export declare const DEFAULT_MAX_COLS = 1000;
|
|
62
|
+
export declare const DEFAULT_MAX_CELLS = 5000000;
|
|
63
|
+
/**
|
|
64
|
+
* Read an xlsx Blob into an ExcelJS Workbook. Falls back to a CSV/TSV
|
|
65
|
+
* parser when the bytes don't look like a zip-backed xlsx (xlsx files
|
|
66
|
+
* start with `PK\x03\x04`). The fallback synthesizes a single-sheet
|
|
67
|
+
* workbook so downstream code paths stay identical.
|
|
68
|
+
*/
|
|
69
|
+
export declare function workbookFromBlob(blob: Blob): Promise<ExcelJS.Workbook>;
|
|
70
|
+
/**
|
|
71
|
+
* Map one ExcelJS worksheet to OGrid columns + rows + initialFormulas.
|
|
72
|
+
*
|
|
73
|
+
* Column ids are Excel letters (A, B, …, AA) so the grid's
|
|
74
|
+
* `cellReferences` mode shows A1/B1 notation that matches the
|
|
75
|
+
* source workbook exactly.
|
|
76
|
+
*
|
|
77
|
+
* Row keys are the same letters; ogrid's default valueGetter reads
|
|
78
|
+
* `row[columnId]` so no per-column getter is needed.
|
|
79
|
+
*
|
|
80
|
+
* Type detection samples up to SAMPLE_SIZE rows per column. All-numbers
|
|
81
|
+
* → 'numeric', all-Date instances → 'date', mixed/text → 'text'.
|
|
82
|
+
*
|
|
83
|
+
* Formulas (cell value `{formula, result}`) get pulled into
|
|
84
|
+
* initialFormulas; the cached `result` still goes into the row so the
|
|
85
|
+
* grid renders the right thing on first paint, before the engine
|
|
86
|
+
* recalculates.
|
|
87
|
+
*/
|
|
88
|
+
export declare function sheetToGridData(sheet: ExcelJS.Worksheet | null | undefined, options?: SheetToGridDataOptions): SheetGridData;
|
|
89
|
+
/** List sheet names in display order. */
|
|
90
|
+
export declare function listSheets(workbook: ExcelJS.Workbook): string[];
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alaarab/ogrid-react-xlsx-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Self-contained browser ESM bundle of @alaarab/ogrid-react-xlsx. React + ReactDOM + ExcelJS + every @alaarab/ogrid-* dep inlined into one file. Drop into a static vendor/ directory and `import()` from a no-bundler app.",
|
|
6
6
|
"main": "dist/ogrid-xlsx.js",
|
|
7
7
|
"module": "dist/ogrid-xlsx.js",
|
|
8
|
+
"types": "dist/ogrid-xlsx.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
11
|
+
"types": "./dist/ogrid-xlsx.d.ts",
|
|
10
12
|
"import": "./dist/ogrid-xlsx.js",
|
|
11
13
|
"default": "./dist/ogrid-xlsx.js"
|
|
12
14
|
},
|
|
13
15
|
"./ogrid-xlsx.css": "./dist/ogrid-xlsx.css"
|
|
14
16
|
},
|
|
15
17
|
"scripts": {
|
|
16
|
-
"build": "rimraf dist && tsup",
|
|
18
|
+
"build": "rimraf dist && tsup && node scripts/copy-types.mjs",
|
|
17
19
|
"test": "echo 'no tests — this package only re-bundles @alaarab/ogrid-react-xlsx; tests live there'"
|
|
18
20
|
},
|
|
19
21
|
"keywords": [
|
|
@@ -33,16 +35,18 @@
|
|
|
33
35
|
"README.md",
|
|
34
36
|
"LICENSE"
|
|
35
37
|
],
|
|
36
|
-
"sideEffects":
|
|
38
|
+
"sideEffects": [
|
|
39
|
+
"**/*.css"
|
|
40
|
+
],
|
|
37
41
|
"engines": {
|
|
38
42
|
"node": ">=18"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@alaarab/ogrid-react-xlsx": "2.
|
|
42
|
-
"@types/react": "^19.2.
|
|
43
|
-
"@types/react-dom": "^19.2.
|
|
44
|
-
"react": "^19.2.
|
|
45
|
-
"react-dom": "^19.2.
|
|
45
|
+
"@alaarab/ogrid-react-xlsx": "2.17.1",
|
|
46
|
+
"@types/react": "^19.2.18",
|
|
47
|
+
"@types/react-dom": "^19.2.7",
|
|
48
|
+
"react": "^19.2.8",
|
|
49
|
+
"react-dom": "^19.2.8",
|
|
46
50
|
"rimraf": "^6.1.3",
|
|
47
51
|
"tsup": "^8.5.1"
|
|
48
52
|
},
|