@reactloom/data-grid 0.0.0-stage → 1.0.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.
Files changed (79) hide show
  1. package/README.md +65 -2
  2. package/dist/LICENSE +21 -0
  3. package/dist/_internal/hooks/use-controllable-state.js +24 -0
  4. package/dist/_internal/hooks/use-controllable-state.js.map +1 -0
  5. package/dist/_internal/primitives/visually-hidden.js +29 -0
  6. package/dist/_internal/primitives/visually-hidden.js.map +1 -0
  7. package/dist/_internal/utils/cx.js +10 -0
  8. package/dist/_internal/utils/cx.js.map +1 -0
  9. package/dist/_internal/utils/data-attr.js +8 -0
  10. package/dist/_internal/utils/data-attr.js.map +1 -0
  11. package/dist/_internal/utils/warn.js +13 -0
  12. package/dist/_internal/utils/warn.js.map +1 -0
  13. package/dist/cell-editor.d.ts +26 -0
  14. package/dist/cell-editor.d.ts.map +1 -0
  15. package/dist/cell-editor.js +109 -0
  16. package/dist/cell-editor.js.map +1 -0
  17. package/dist/clipboard.d.ts +10 -0
  18. package/dist/clipboard.d.ts.map +1 -0
  19. package/dist/clipboard.js +54 -0
  20. package/dist/clipboard.js.map +1 -0
  21. package/dist/column-filters.d.ts +4 -0
  22. package/dist/column-filters.d.ts.map +1 -0
  23. package/dist/column-filters.js +30 -0
  24. package/dist/column-filters.js.map +1 -0
  25. package/dist/column-layout.d.ts +18 -0
  26. package/dist/column-layout.d.ts.map +1 -0
  27. package/dist/column-layout.js +59 -0
  28. package/dist/column-layout.js.map +1 -0
  29. package/dist/csv.d.ts +26 -0
  30. package/dist/csv.d.ts.map +1 -0
  31. package/dist/csv.js +60 -0
  32. package/dist/csv.js.map +1 -0
  33. package/dist/data-grid.d.ts +11 -0
  34. package/dist/data-grid.d.ts.map +1 -0
  35. package/dist/data-grid.js +1610 -0
  36. package/dist/data-grid.js.map +1 -0
  37. package/dist/data-grid.module.js +70 -0
  38. package/dist/data-grid.module.js.map +1 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +6 -0
  42. package/dist/pivot-table.d.ts +26 -0
  43. package/dist/pivot-table.d.ts.map +1 -0
  44. package/dist/pivot-table.js +174 -0
  45. package/dist/pivot-table.js.map +1 -0
  46. package/dist/pivot-table.module.js +30 -0
  47. package/dist/pivot-table.module.js.map +1 -0
  48. package/dist/server.d.ts +34 -0
  49. package/dist/server.d.ts.map +1 -0
  50. package/dist/server.js +97 -0
  51. package/dist/server.js.map +1 -0
  52. package/dist/spreadsheet.d.ts +18 -0
  53. package/dist/spreadsheet.d.ts.map +1 -0
  54. package/dist/spreadsheet.js +329 -0
  55. package/dist/spreadsheet.js.map +1 -0
  56. package/dist/spreadsheet.module.js +30 -0
  57. package/dist/spreadsheet.module.js.map +1 -0
  58. package/dist/styles.css +3 -0
  59. package/dist/tree.d.ts +24 -0
  60. package/dist/tree.d.ts.map +1 -0
  61. package/dist/tree.js +75 -0
  62. package/dist/tree.js.map +1 -0
  63. package/dist/types.d.ts +365 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +43 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/use-grid-navigation.d.ts +36 -0
  68. package/dist/use-grid-navigation.d.ts.map +1 -0
  69. package/dist/use-grid-navigation.js +188 -0
  70. package/dist/use-grid-navigation.js.map +1 -0
  71. package/dist/xlsx.d.ts +12 -0
  72. package/dist/xlsx.d.ts.map +1 -0
  73. package/dist/xlsx.js +57 -0
  74. package/dist/xlsx.js.map +1 -0
  75. package/dist/zip.d.ts +6 -0
  76. package/dist/zip.d.ts.map +1 -0
  77. package/dist/zip.js +54 -0
  78. package/dist/zip.js.map +1 -0
  79. package/package.json +108 -3
@@ -0,0 +1,188 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ // src/use-grid-navigation.ts
4
+ var FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([data-grid-cell])";
5
+ /** Widgets inside a cell, in DOM order. */
6
+ var widgetsIn = (cell) => Array.from(cell.querySelectorAll(FOCUSABLE)).filter((el) => !el.closest("[aria-hidden=\"true\"]"));
7
+ /**
8
+ * The element that receives focus for a cell: a cell containing exactly one widget (sort button,
9
+ * checkbox, link) focuses that widget directly; otherwise the cell itself (APG grid pattern).
10
+ */
11
+ function focusTarget(cell) {
12
+ if (cell.hasAttribute("data-grid-content")) return cell;
13
+ const widgets = widgetsIn(cell);
14
+ return widgets.length === 1 && widgets[0] ? widgets[0] : cell;
15
+ }
16
+ /**
17
+ * Roving focus for `role="grid"`: one tab stop, arrow keys between cells, Home/End,
18
+ * Ctrl+Home/End, Page Up/Down. Enter or F2 moves into a cell's widgets; Escape returns to the cell.
19
+ */
20
+ function useGridNavigation({ gridRef, rowCount, colCount, pageRows, ensureRendered, onHeaderKey }) {
21
+ const [rawActive, setActive] = useState({
22
+ row: 0,
23
+ col: 0
24
+ });
25
+ const active = useMemo(() => ({
26
+ row: Math.min(rawActive.row, Math.max(0, rowCount - 1)),
27
+ col: Math.min(rawActive.col, Math.max(0, colCount - 1))
28
+ }), [
29
+ rawActive,
30
+ rowCount,
31
+ colCount
32
+ ]);
33
+ const pendingFocus = useRef(false);
34
+ const cellAt = useCallback((pos) => gridRef.current?.querySelector(`[data-grid-cell="${pos.row}:${pos.col}"]`) ?? gridRef.current?.querySelector(`[data-grid-cell="${pos.row}:0"][aria-colspan]`) ?? null, [gridRef]);
35
+ useEffect(() => {
36
+ const grid = gridRef.current;
37
+ if (!grid) return;
38
+ for (const cell of grid.querySelectorAll("[data-grid-cell]")) {
39
+ cell.tabIndex = -1;
40
+ for (const w of widgetsIn(cell)) w.tabIndex = -1;
41
+ }
42
+ const cell = cellAt(active);
43
+ if (cell) {
44
+ const target = focusTarget(cell);
45
+ target.tabIndex = 0;
46
+ if (pendingFocus.current) {
47
+ pendingFocus.current = false;
48
+ target.focus({ preventScroll: false });
49
+ }
50
+ } else if (pendingFocus.current) requestAnimationFrame(() => {
51
+ const later = cellAt(active);
52
+ if (later) {
53
+ pendingFocus.current = false;
54
+ focusTarget(later).focus();
55
+ }
56
+ });
57
+ });
58
+ const moveTo = useCallback((pos) => {
59
+ const next = {
60
+ row: Math.max(0, Math.min(rowCount - 1, pos.row)),
61
+ col: Math.max(0, Math.min(colCount - 1, pos.col))
62
+ };
63
+ ensureRendered?.(next.row, next.col);
64
+ pendingFocus.current = true;
65
+ setActive(next);
66
+ }, [
67
+ rowCount,
68
+ colCount,
69
+ ensureRendered
70
+ ]);
71
+ return {
72
+ active,
73
+ onKeyDown: useCallback((event) => {
74
+ const target = event.target;
75
+ const cell = target.closest("[data-grid-cell]");
76
+ if (!cell) return;
77
+ const [row = 0, ownCol = 0] = (cell.dataset.gridCell ?? "0:0").split(":").map(Number);
78
+ const spans = cell.hasAttribute("aria-colspan");
79
+ const col = spans ? active.col : ownCol;
80
+ if (!(target === cell || target === focusTarget(cell))) {
81
+ if (event.key === "Escape") {
82
+ event.preventDefault();
83
+ cell.focus();
84
+ setActive({
85
+ row,
86
+ col
87
+ });
88
+ }
89
+ return;
90
+ }
91
+ if (row === 0 && onHeaderKey?.(col, event)) return;
92
+ if (spans && (event.key === "ArrowLeft" || event.key === "ArrowRight")) return;
93
+ const rtl = getComputedStyle(cell).direction === "rtl";
94
+ const ctrl = event.ctrlKey || event.metaKey;
95
+ let next;
96
+ switch (event.key) {
97
+ case "ArrowRight":
98
+ next = {
99
+ row,
100
+ col: col + (rtl ? -1 : 1)
101
+ };
102
+ break;
103
+ case "ArrowLeft":
104
+ next = {
105
+ row,
106
+ col: col + (rtl ? 1 : -1)
107
+ };
108
+ break;
109
+ case "ArrowDown":
110
+ next = {
111
+ row: row + 1,
112
+ col
113
+ };
114
+ break;
115
+ case "ArrowUp":
116
+ next = {
117
+ row: row - 1,
118
+ col
119
+ };
120
+ break;
121
+ case "Home":
122
+ next = ctrl ? {
123
+ row: 0,
124
+ col: 0
125
+ } : {
126
+ row,
127
+ col: 0
128
+ };
129
+ break;
130
+ case "End":
131
+ next = ctrl ? {
132
+ row: rowCount - 1,
133
+ col: colCount - 1
134
+ } : {
135
+ row,
136
+ col: colCount - 1
137
+ };
138
+ break;
139
+ case "PageDown":
140
+ next = {
141
+ row: row + pageRows,
142
+ col
143
+ };
144
+ break;
145
+ case "PageUp":
146
+ next = {
147
+ row: Math.max(row === 0 ? 0 : 1, row - pageRows),
148
+ col
149
+ };
150
+ break;
151
+ case "Enter":
152
+ case "F2":
153
+ if (target === cell) {
154
+ const first = widgetsIn(cell)[0];
155
+ if (first) {
156
+ event.preventDefault();
157
+ first.focus();
158
+ }
159
+ }
160
+ return;
161
+ default: return;
162
+ }
163
+ event.preventDefault();
164
+ moveTo(next);
165
+ }, [
166
+ moveTo,
167
+ onHeaderKey,
168
+ pageRows,
169
+ rowCount,
170
+ colCount,
171
+ active.col
172
+ ]),
173
+ onFocus: useCallback((event) => {
174
+ const cell = event.target.closest("[data-grid-cell]");
175
+ if (!cell) return;
176
+ const [row = 0, col = 0] = (cell.dataset.gridCell ?? "0:0").split(":").map(Number);
177
+ const spans = cell.hasAttribute("aria-colspan");
178
+ setActive((pos) => pos.row === row && (pos.col === col || spans) ? pos : {
179
+ row,
180
+ col
181
+ });
182
+ }, []),
183
+ moveTo
184
+ };
185
+ }
186
+ export { focusTarget, useGridNavigation };
187
+
188
+ //# sourceMappingURL=use-grid-navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-grid-navigation.js","names":[],"sources":["../src/use-grid-navigation.ts"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent, type RefObject } from 'react';\n\nexport interface CellPosition {\n /** 0 = header row; 1.. = body rows in render order. */\n row: number;\n col: number;\n}\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([data-grid-cell])';\n\n/** Widgets inside a cell, in DOM order. */\nconst widgetsIn = (cell: HTMLElement) => Array.from(cell.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((el) => !el.closest('[aria-hidden=\"true\"]'));\n\n/**\n * The element that receives focus for a cell: a cell containing exactly one widget (sort button,\n * checkbox, link) focuses that widget directly; otherwise the cell itself (APG grid pattern).\n */\nexport function focusTarget(cell: HTMLElement): HTMLElement {\n // Cells with free-form content (detail rows) take focus themselves; Enter moves inside.\n if (cell.hasAttribute('data-grid-content')) return cell;\n const widgets = widgetsIn(cell);\n return widgets.length === 1 && widgets[0] ? widgets[0] : cell;\n}\n\ninterface Options {\n gridRef: RefObject<HTMLElement | null>;\n rowCount: number; // including the header row\n colCount: number;\n pageRows: number; // rows moved by Page Up / Page Down\n /** Make sure a (virtualized) row is rendered before focusing it. */\n ensureRendered?: (row: number, col: number) => void;\n /** Header-cell keys (sort / resize) handled by the grid. */\n onHeaderKey?: (col: number, event: KeyboardEvent) => boolean;\n}\n\n/**\n * Roving focus for `role=\"grid\"`: one tab stop, arrow keys between cells, Home/End,\n * Ctrl+Home/End, Page Up/Down. Enter or F2 moves into a cell's widgets; Escape returns to the cell.\n */\nexport function useGridNavigation({ gridRef, rowCount, colCount, pageRows, ensureRendered, onHeaderKey }: Options) {\n const [rawActive, setActive] = useState<CellPosition>({ row: 0, col: 0 });\n // Clamp when rows/columns shrink (filtering, paging, hiding columns).\n const active = useMemo(\n () => ({ row: Math.min(rawActive.row, Math.max(0, rowCount - 1)), col: Math.min(rawActive.col, Math.max(0, colCount - 1)) }),\n [rawActive, rowCount, colCount],\n );\n const pendingFocus = useRef(false);\n\n const cellAt = useCallback(\n (pos: CellPosition) =>\n gridRef.current?.querySelector<HTMLElement>(`[data-grid-cell=\"${pos.row}:${pos.col}\"]`) ??\n // A cell spanning the row (group rows) stands in for every column.\n gridRef.current?.querySelector<HTMLElement>(`[data-grid-cell=\"${pos.row}:0\"][aria-colspan]`) ??\n null,\n [gridRef],\n );\n\n // Keep exactly one tab stop: the active cell's focus target.\n useEffect(() => {\n const grid = gridRef.current;\n if (!grid) return;\n for (const cell of grid.querySelectorAll<HTMLElement>('[data-grid-cell]')) {\n cell.tabIndex = -1;\n for (const w of widgetsIn(cell)) w.tabIndex = -1;\n }\n const cell = cellAt(active);\n if (cell) {\n const target = focusTarget(cell);\n target.tabIndex = 0;\n if (pendingFocus.current) {\n pendingFocus.current = false;\n target.focus({ preventScroll: false });\n }\n } else if (pendingFocus.current) {\n // Not rendered yet (virtualized): try again next frame.\n requestAnimationFrame(() => {\n const later = cellAt(active);\n if (later) {\n pendingFocus.current = false;\n focusTarget(later).focus();\n }\n });\n }\n });\n\n const moveTo = useCallback(\n (pos: CellPosition) => {\n const next = { row: Math.max(0, Math.min(rowCount - 1, pos.row)), col: Math.max(0, Math.min(colCount - 1, pos.col)) };\n ensureRendered?.(next.row, next.col);\n pendingFocus.current = true;\n setActive(next);\n },\n [rowCount, colCount, ensureRendered],\n );\n\n const onKeyDown = useCallback(\n (event: KeyboardEvent<HTMLElement>) => {\n const target = event.target as HTMLElement;\n const cell = target.closest<HTMLElement>('[data-grid-cell]');\n if (!cell) return;\n const [row = 0, ownCol = 0] = (cell.dataset.gridCell ?? '0:0').split(':').map(Number);\n // A cell spanning the row (group rows) has no column of its own: keep the remembered one.\n const spans = cell.hasAttribute('aria-colspan');\n const col = spans ? active.col : ownCol;\n const atTarget = target === cell || target === focusTarget(cell);\n\n // Inside a cell's widgets (interaction mode): only Escape is ours.\n if (!atTarget) {\n if (event.key === 'Escape') {\n event.preventDefault();\n cell.focus();\n setActive({ row, col });\n }\n return;\n }\n if (row === 0 && onHeaderKey?.(col, event)) return;\n if (spans && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) return;\n\n const rtl = getComputedStyle(cell).direction === 'rtl';\n const ctrl = event.ctrlKey || event.metaKey;\n let next: CellPosition;\n switch (event.key) {\n case 'ArrowRight':\n next = { row, col: col + (rtl ? -1 : 1) };\n break;\n case 'ArrowLeft':\n next = { row, col: col + (rtl ? 1 : -1) };\n break;\n case 'ArrowDown':\n next = { row: row + 1, col };\n break;\n case 'ArrowUp':\n next = { row: row - 1, col };\n break;\n case 'Home':\n next = ctrl ? { row: 0, col: 0 } : { row, col: 0 };\n break;\n case 'End':\n next = ctrl ? { row: rowCount - 1, col: colCount - 1 } : { row, col: colCount - 1 };\n break;\n case 'PageDown':\n next = { row: row + pageRows, col };\n break;\n case 'PageUp':\n next = { row: Math.max(row === 0 ? 0 : 1, row - pageRows), col };\n break;\n case 'Enter':\n case 'F2': {\n // Move into a cell that holds several widgets (or a single one the cell itself holds).\n if (target === cell) {\n const first = widgetsIn(cell)[0];\n if (first) {\n event.preventDefault();\n first.focus();\n }\n }\n return;\n }\n default:\n return;\n }\n event.preventDefault();\n moveTo(next);\n },\n [moveTo, onHeaderKey, pageRows, rowCount, colCount, active.col],\n );\n\n /** Track pointer focus so the tab stop follows clicks. */\n const onFocus = useCallback((event: React.FocusEvent<HTMLElement>) => {\n const cell = (event.target as HTMLElement).closest<HTMLElement>('[data-grid-cell]');\n if (!cell) return;\n const [row = 0, col = 0] = (cell.dataset.gridCell ?? '0:0').split(':').map(Number);\n // A cell spanning the row keeps the column the user came from (moving on returns to it).\n const spans = cell.hasAttribute('aria-colspan');\n setActive((pos) => (pos.row === row && (pos.col === col || spans) ? pos : { row, col }));\n }, []);\n\n return { active, onKeyDown, onFocus, moveTo };\n}\n"],"mappings":";;;AAUA,IAAM,YAAY;;AAGlB,IAAM,aAAa,SAAsB,MAAM,KAAK,KAAK,iBAA8B,SAAS,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,GAAG,QAAQ,wBAAsB,CAAC;;;;;AAMrJ,SAAgB,YAAY,MAAgC;CAE1D,IAAI,KAAK,aAAa,mBAAmB,GAAG,OAAO;CACnD,MAAM,UAAU,UAAU,IAAI;CAC9B,OAAO,QAAQ,WAAW,KAAK,QAAQ,KAAK,QAAQ,KAAK;AAC3D;;;;;AAiBA,SAAgB,kBAAkB,EAAE,SAAS,UAAU,UAAU,U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KAAK;KACH,OAAO,OAAO;MAAE,KAAK,WAAW;MAAG,KAAK,WAAW;KAAE,IAAI;MAAE;MAAK,KAAK,WAAW;KAAE;KAClF;IACF,KAAK;KACH,OAAO;MAAE,KAAK,MAAM;MAAU;KAAI;KAClC;IACF,KAAK;KACH,OAAO;MAAE,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,GAAG,MAAM,QAAQ;MAAG;KAAI;KAC/D;IACF,KAAK;IACL,KAAK;KAEH,IAAI,WAAW,MAAM;MACnB,MAAM,QAAQ,UAAU,IAAI,CAAC,CAAC;MAC9B,IAAI,OAAO;OACT,MAAM,eAAe;OACrB,MAAM,MAAM;MACd;KACF;KACA;IAEF,SACE;GACJ;GACA,MAAM,eAAe;GACrB,OAAO,IAAI;EACb,GACA;GAAC;GAAQ;GAAa;GAAU;GAAU;GAAU,OAAO;EAAG,CAa/C;EAAW,SATZ,aAAa,UAAyC;GACpE,MAAM,OAAQ,MAAM,OAAuB,QAAqB,kBAAkB;GAClF,IAAI,CAAC,MAAM;GACX,MAAM,CAAC,MAAM,GAAG,MAAM,MAAM,KAAK,QAAQ,YAAY,MAAA,CAAO,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;GAEjF,MAAM,QAAQ,KAAK,aAAa,cAAc;GAC9C,WAAW,QAAS,IAAI,QAAQ,QAAQ,IAAI,QAAQ,OAAO,SAAS,MAAM;IAAE;IAAK;GAAI,CAAE;EACzF,GAAG,CAAC,CAEwB;EAAS;CAAO;AAC9C"}
package/dist/xlsx.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { DataGridColumn } from './types.js';
2
+ export interface XlsxOptions {
3
+ /** The name of the single worksheet. @default 'Data' */
4
+ sheetName?: string;
5
+ /** Include column headers as the first worksheet row. @default true */
6
+ header?: boolean;
7
+ }
8
+ /** Export a single-sheet, macro-free workbook from the same value accessors as CSV. */
9
+ export declare function toXlsx<Row>(columns: readonly DataGridColumn<Row>[], rows: readonly Row[], { sheetName, header, }?: XlsxOptions): Uint8Array<ArrayBuffer>;
10
+ /** Download a workbook in a browser. Use toXlsx to write the bytes on a server. */
11
+ export declare function downloadXlsx<Row>(columns: readonly DataGridColumn<Row>[], rows: readonly Row[], filename?: string, options?: XlsxOptions): void;
12
+ //# sourceMappingURL=xlsx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlsx.d.ts","sourceRoot":"","sources":["../src/xlsx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAoCD,uFAAuF;AACvF,wBAAgB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,EACzF,SAAkB,EAAE,MAAa,GAClC,GAAE,WAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,CA4B5C;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,QAAQ,SAAc,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAGpJ"}
package/dist/xlsx.js ADDED
@@ -0,0 +1,57 @@
1
+ import { downloadData, exportHeader, exportValue, isoDate } from "./csv.js";
2
+ import { storeZip } from "./zip.js";
3
+ // src/xlsx.ts
4
+ var main = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
5
+ var relation = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
6
+ var pkg = "http://schemas.openxmlformats.org/package/2006";
7
+ var mime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
8
+ function textXml(text) {
9
+ return [...text.replace(/_x[0-9a-f]{4}_/gi, (match) => "_x005F_" + match.slice(1))].map((character) => {
10
+ const point = character.codePointAt(0) ?? 0;
11
+ if (character === "\r" || point < 32 && character !== "\n" && character !== " " || point >= 55296 && point <= 57343 || point === 65534 || point === 65535) return `_x${point.toString(16).toUpperCase().padStart(4, "0")}_`;
12
+ return character;
13
+ }).join("").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
14
+ }
15
+ function columnName(index) {
16
+ let result = "";
17
+ for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26)) result = String.fromCharCode(65 + (n - 1) % 26) + result;
18
+ return result;
19
+ }
20
+ function cellXml(reference, value) {
21
+ if (value == null) return "";
22
+ if (typeof value === "number") return Number.isFinite(value) ? `<c r="${reference}"><v>${value}</v></c>` : "";
23
+ if (typeof value === "boolean") return `<c r="${reference}" t="b"><v>${Number(value)}</v></c>`;
24
+ const text = value instanceof Date ? isoDate(value) : String(value);
25
+ if (text.length > 32767) throw new RangeError(`Cell ${reference} exceeds the 32,767-character worksheet limit.`);
26
+ return `<c r="${reference}" t="inlineStr"><is><t xml:space="preserve">${textXml(text)}</t></is></c>`;
27
+ }
28
+ /** Export a single-sheet, macro-free workbook from the same value accessors as CSV. */
29
+ function toXlsx(columns, rows, { sheetName = "Data", header = true } = {}) {
30
+ if (!sheetName.trim() || sheetName.length > 31 || /[\\/*?:[\]]/.test(sheetName) || sheetName.startsWith("'") || sheetName.endsWith("'") || sheetName.toLowerCase() === "history" || [...sheetName].some((character) => character.charCodeAt(0) < 32)) throw new RangeError("Use a valid Excel worksheet name of up to 31 characters.");
31
+ if (columns.length > 16384 || rows.length + Number(header) > 1048576) throw new RangeError("Export exceeds Excel worksheet dimensions.");
32
+ const letters = columns.map((_, index) => columnName(index));
33
+ const rowXml = (number, valueAt) => `<row r="${number}">${columns.map((column, index) => cellXml(`${letters[index]}${number}`, valueAt(column))).join("")}</row>`;
34
+ const sheetRows = [];
35
+ if (header) sheetRows.push(rowXml(1, exportHeader));
36
+ for (const [index, row] of rows.entries()) sheetRows.push(rowXml(index + 1 + Number(header), (column) => exportValue(column, row)));
37
+ const parts = {
38
+ "[Content_Types].xml": `<Types xmlns="${pkg}/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>`,
39
+ "_rels/.rels": `<Relationships xmlns="${pkg}/relationships"><Relationship Id="rId1" Type="${relation}/officeDocument" Target="xl/workbook.xml"/></Relationships>`,
40
+ "xl/workbook.xml": `<workbook xmlns="${main}" xmlns:r="${relation}"><sheets><sheet name="${textXml(sheetName)}" sheetId="1" r:id="rId1"/></sheets></workbook>`,
41
+ "xl/_rels/workbook.xml.rels": `<Relationships xmlns="${pkg}/relationships"><Relationship Id="rId1" Type="${relation}/worksheet" Target="worksheets/sheet1.xml"/></Relationships>`,
42
+ "xl/worksheets/sheet1.xml": `<worksheet xmlns="${main}"><sheetData>${sheetRows.join("")}</sheetData></worksheet>`
43
+ };
44
+ const encoder = new TextEncoder();
45
+ return storeZip(Object.entries(parts).map(([name, xml]) => ({
46
+ name: encoder.encode(name),
47
+ data: encoder.encode(`<?xml version="1.0" encoding="UTF-8"?>${xml}`)
48
+ })));
49
+ }
50
+ /** Download a workbook in a browser. Use toXlsx to write the bytes on a server. */
51
+ function downloadXlsx(columns, rows, filename = "data.xlsx", options) {
52
+ if (typeof document === "undefined") return;
53
+ downloadData(toXlsx(columns, rows, options), filename, mime);
54
+ }
55
+ export { downloadXlsx, toXlsx };
56
+
57
+ //# sourceMappingURL=xlsx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlsx.js","names":[],"sources":["../src/xlsx.ts"],"sourcesContent":["import { downloadData, exportHeader, exportValue, isoDate } from './csv.js';\nimport type { CellValue, DataGridColumn } from './types.js';\nimport { storeZip } from './zip.js';\n\nexport interface XlsxOptions {\n /** The name of the single worksheet. @default 'Data' */\n sheetName?: string;\n /** Include column headers as the first worksheet row. @default true */\n header?: boolean;\n}\n\nconst main = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';\nconst relation = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';\nconst pkg = 'http://schemas.openxmlformats.org/package/2006';\nconst mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n\nfunction textXml(text: string): string {\n // Excel decodes _xNNNN_ escapes. Preserve literal strings and encode XML-invalid code points.\n const clean = text.replace(/_x[0-9a-f]{4}_/gi, (match) => '_x005F_' + match.slice(1));\n return [...clean].map((character) => {\n const point = character.codePointAt(0) ?? 0;\n if (character === '\\r' || (point < 32 && character !== '\\n' && character !== '\\t') ||\n (point >= 0xd800 && point <= 0xdfff) || point === 0xfffe || point === 0xffff) {\n return `_x${point.toString(16).toUpperCase().padStart(4, '0')}_`;\n }\n return character;\n }).join('').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');\n}\n\nfunction columnName(index: number): string {\n let result = '';\n for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26)) result = String.fromCharCode(65 + ((n - 1) % 26)) + result;\n return result;\n}\n\nfunction cellXml(reference: string, value: CellValue): string {\n if (value == null) return '';\n if (typeof value === 'number') return Number.isFinite(value) ? `<c r=\"${reference}\"><v>${value}</v></c>` : '';\n if (typeof value === 'boolean') return `<c r=\"${reference}\" t=\"b\"><v>${Number(value)}</v></c>`;\n const text = value instanceof Date ? isoDate(value) : String(value);\n if (text.length > 32767) throw new RangeError(`Cell ${reference} exceeds the 32,767-character worksheet limit.`);\n // Formula-looking values are written as inline text, so they stay literal in Excel.\n return `<c r=\"${reference}\" t=\"inlineStr\"><is><t xml:space=\"preserve\">${textXml(text)}</t></is></c>`;\n}\n\n/** Export a single-sheet, macro-free workbook from the same value accessors as CSV. */\nexport function toXlsx<Row>(columns: readonly DataGridColumn<Row>[], rows: readonly Row[], {\n sheetName = 'Data', header = true,\n}: XlsxOptions = {}): Uint8Array<ArrayBuffer> {\n if (!sheetName.trim() || sheetName.length > 31 || /[\\\\/*?:[\\]]/.test(sheetName) ||\n sheetName.startsWith(\"'\") || sheetName.endsWith(\"'\") || sheetName.toLowerCase() === 'history' ||\n [...sheetName].some((character) => character.charCodeAt(0) < 32)) {\n throw new RangeError('Use a valid Excel worksheet name of up to 31 characters.');\n }\n if (columns.length > 16384 || rows.length + Number(header) > 1048576) throw new RangeError('Export exceeds Excel worksheet dimensions.');\n\n const letters = columns.map((_, index) => columnName(index));\n const rowXml = (number: number, valueAt: (column: DataGridColumn<Row>) => CellValue) =>\n `<row r=\"${number}\">${columns.map((column, index) => cellXml(`${letters[index]}${number}`, valueAt(column))).join('')}</row>`;\n const sheetRows: string[] = [];\n if (header) sheetRows.push(rowXml(1, exportHeader));\n for (const [index, row] of rows.entries()) {\n sheetRows.push(rowXml(index + 1 + Number(header), (column) => exportValue(column, row)));\n }\n\n const parts = {\n '[Content_Types].xml': `<Types xmlns=\"${pkg}/content-types\"><Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/><Default Extension=\"xml\" ContentType=\"application/xml\"/><Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/><Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"/></Types>`,\n '_rels/.rels': `<Relationships xmlns=\"${pkg}/relationships\"><Relationship Id=\"rId1\" Type=\"${relation}/officeDocument\" Target=\"xl/workbook.xml\"/></Relationships>`,\n 'xl/workbook.xml': `<workbook xmlns=\"${main}\" xmlns:r=\"${relation}\"><sheets><sheet name=\"${textXml(sheetName)}\" sheetId=\"1\" r:id=\"rId1\"/></sheets></workbook>`,\n 'xl/_rels/workbook.xml.rels': `<Relationships xmlns=\"${pkg}/relationships\"><Relationship Id=\"rId1\" Type=\"${relation}/worksheet\" Target=\"worksheets/sheet1.xml\"/></Relationships>`,\n 'xl/worksheets/sheet1.xml': `<worksheet xmlns=\"${main}\"><sheetData>${sheetRows.join('')}</sheetData></worksheet>`,\n };\n const encoder = new TextEncoder();\n return storeZip(Object.entries(parts).map(([name, xml]) => ({\n name: encoder.encode(name), data: encoder.encode(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>${xml}`),\n })));\n}\n\n/** Download a workbook in a browser. Use toXlsx to write the bytes on a server. */\nexport function downloadXlsx<Row>(columns: readonly DataGridColumn<Row>[], rows: readonly Row[], filename = 'data.xlsx', options?: XlsxOptions): void {\n if (typeof document === 'undefined') return;\n downloadData(toXlsx(columns, rows, options), filename, mime);\n}\n"],"mappings":";;;AAWA,IAAM,OAAO;AACb,IAAM,WAAW;AACjB,IAAM,MAAM;AACZ,IAAM,OAAO;AAEb,SAAS,QAAQ,MAAsB;CAGrC,OAAO,CAAC,GADM,KAAK,QAAQ,qBAAqB,UAAU,YAAY,MAAM,MAAM,CAAC,CACxE,CAAK,CAAC,CAAC,KAAK,cAAc;EACnC,MAAM,QAAQ,UAAU,YAAY,CAAC,KAAK;EAC1C,IAAI,cAAc,QAAS,QAAQ,MAAM,cAAc,QAAQ,cAAc,OAC1E,SAAS,SAAU,SAAS,SAAW,UAAU,SAAU,UAAU,OACtE,OAAO,KAAK,MAAM,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,GAAG,EAAE;EAEhE,OAAO;CACT,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,QAAQ;AACvG;AAEA,SAAS,WAAW,OAAuB;CACzC,IAAI,SAAS;CACb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E;CACxH,MAAM,YAAsB,CAAC;CAC7B,IAAI,QAAQ,UAAU,KAAK,OAAO,GAAG,YAAY,CAAC;CAClD,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,QAAQ,GACtC,UAAU,KAAK,OAAO,QAAQ,IAAI,OAAO,MAAM,IAAI,WAAW,YAAY,QAAQ,GAAG,CAAC,CAAC;CAGzF,MAAM,QAAQ;EACZ,uBAAuB,iBAAiB,IAAI;EAC5C,eAAe,yBAAyB,IAAI,gDAAgD,SAAS;EACrG,mBAAmB,oBAAoB,KAAK,aAAa,SAAS,yBAAyB,QAAQ,SAAS,EAAE;EAC9G,8BAA8B,yBAAyB,IAAI,gDAAgD,SAAS;EACpH,4BAA4B,qBAAqB,KAAK,eAAe,UAAU,KAAK,EAAE,EAAE;CAC1F;CACA,MAAM,UAAU,IAAI,YAAY;CAChC,OAAO,SAAS,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU;EAC1D,MAAM,QAAQ,OAAO,IAAI;EAAG,MAAM,QAAQ,OAAO,yCAAyC,KAAK;CACjG,EAAE,CAAC;AACL;;AAGA,SAAgB,aAAkB,SAAyC,MAAsB,WAAW,aAAa,SAA6B;CACpJ,IAAI,OAAO,aAAa,aAAa;CACrC,aAAa,OAAO,SAAS,MAAM,OAAO,GAAG,UAAU,IAAI;AAC7D"}
package/dist/zip.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /** Write a small ZIP of stored (uncompressed) entries for the optional spreadsheet exporter. */
2
+ export declare function storeZip(entries: ReadonlyArray<{
3
+ name: Uint8Array;
4
+ data: Uint8Array;
5
+ }>): Uint8Array<ArrayBuffer>;
6
+ //# sourceMappingURL=zip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../src/zip.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAyChH"}
package/dist/zip.js ADDED
@@ -0,0 +1,54 @@
1
+ // src/zip.ts
2
+ /** Write a small ZIP of stored (uncompressed) entries for the optional spreadsheet exporter. */
3
+ function storeZip(entries) {
4
+ const localSize = entries.reduce((total, { name, data }) => total + 30 + name.length + data.length, 0);
5
+ const directorySize = entries.reduce((total, { name }) => total + 46 + name.length, 0);
6
+ if (localSize + directorySize + 22 >= 4294967295) throw new RangeError("Workbook exceeds the ZIP size limit.");
7
+ const bytes = new Uint8Array(localSize + directorySize + 22);
8
+ const view = new DataView(bytes.buffer);
9
+ const u16 = (offset, value) => view.setUint16(offset, value, true);
10
+ const u32 = (offset, value) => view.setUint32(offset, value, true);
11
+ let local = 0;
12
+ let central = localSize;
13
+ for (const { name, data } of entries) {
14
+ const crc = crc32(data);
15
+ u32(local, 67324752);
16
+ u16(local + 4, 20);
17
+ u16(local + 12, 33);
18
+ u32(local + 14, crc);
19
+ u32(local + 18, data.length);
20
+ u32(local + 22, data.length);
21
+ u16(local + 26, name.length);
22
+ bytes.set(name, local + 30);
23
+ bytes.set(data, local + 30 + name.length);
24
+ u32(central, 33639248);
25
+ u16(central + 4, 20);
26
+ u16(central + 6, 20);
27
+ u16(central + 14, 33);
28
+ u32(central + 16, crc);
29
+ u32(central + 20, data.length);
30
+ u32(central + 24, data.length);
31
+ u16(central + 28, name.length);
32
+ u32(central + 42, local);
33
+ bytes.set(name, central + 46);
34
+ local += 30 + name.length + data.length;
35
+ central += 46 + name.length;
36
+ }
37
+ u32(central, 101010256);
38
+ u16(central + 8, entries.length);
39
+ u16(central + 10, entries.length);
40
+ u32(central + 12, directorySize);
41
+ u32(central + 16, localSize);
42
+ return bytes;
43
+ }
44
+ function crc32(data) {
45
+ let crc = -1;
46
+ for (const byte of data) {
47
+ crc ^= byte;
48
+ for (let bit = 0; bit < 8; bit++) crc = crc >>> 1 ^ (crc & 1 ? 3988292384 : 0);
49
+ }
50
+ return (crc ^ -1) >>> 0;
51
+ }
52
+ export { storeZip };
53
+
54
+ //# sourceMappingURL=zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","names":[],"sources":["../src/zip.ts"],"sourcesContent":["/** Write a small ZIP of stored (uncompressed) entries for the optional spreadsheet exporter. */\nexport function storeZip(entries: ReadonlyArray<{ name: Uint8Array; data: Uint8Array }>): Uint8Array<ArrayBuffer> {\n const localSize = entries.reduce((total, { name, data }) => total + 30 + name.length + data.length, 0);\n const directorySize = entries.reduce((total, { name }) => total + 46 + name.length, 0);\n if (localSize + directorySize + 22 >= 0xffffffff) throw new RangeError('Workbook exceeds the ZIP size limit.');\n const bytes = new Uint8Array(localSize + directorySize + 22);\n const view = new DataView(bytes.buffer);\n const u16 = (offset: number, value: number) => view.setUint16(offset, value, true);\n const u32 = (offset: number, value: number) => view.setUint32(offset, value, true);\n let local = 0;\n let central = localSize;\n for (const { name, data } of entries) {\n const crc = crc32(data);\n u32(local, 0x04034b50); // Local file header\n u16(local + 4, 20);\n u16(local + 12, 33); // DOS date: Jan 1, 1980\n u32(local + 14, crc);\n u32(local + 18, data.length);\n u32(local + 22, data.length);\n u16(local + 26, name.length);\n bytes.set(name, local + 30);\n bytes.set(data, local + 30 + name.length);\n\n u32(central, 0x02014b50); // Central directory file header\n u16(central + 4, 20);\n u16(central + 6, 20);\n u16(central + 14, 33);\n u32(central + 16, crc);\n u32(central + 20, data.length);\n u32(central + 24, data.length);\n u16(central + 28, name.length);\n u32(central + 42, local);\n bytes.set(name, central + 46);\n local += 30 + name.length + data.length;\n central += 46 + name.length;\n }\n u32(central, 0x06054b50); // End of central directory\n u16(central + 8, entries.length);\n u16(central + 10, entries.length);\n u32(central + 12, directorySize);\n u32(central + 16, localSize);\n return bytes;\n}\n\nfunction crc32(data: Uint8Array): number {\n let crc = -1;\n for (const byte of data) {\n crc ^= byte;\n for (let bit = 0; bit < 8; bit++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M;EAC7B,IAAI,UAAU,IAAI,KAAK,MAAM;EAC7B,IAAI,UAAU,IAAI,KAAK;EACvB,MAAM,IAAI,MAAM,UAAU,EAAE;EAC5B,SAAS,KAAK,KAAK,SAAS,KAAK;EACjC,WAAW,KAAK,KAAK;CACvB;CACA,IAAI,SAAS,SAAU;CACvB,IAAI,UAAU,GAAG,QAAQ,MAAM;CAC/B,IAAI,UAAU,IAAI,QAAQ,MAAM;CAChC,IAAI,UAAU,IAAI,aAAa;CAC/B,IAAI,UAAU,IAAI,SAAS;CAC3B,OAAO;AACT;AAEA,SAAS,MAAM,MAA0B;CACvC,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,MAAM;EACvB,OAAO;EACP,KAAK,IAAI,MAAM,GAAG,MAAM,GAAG,OAAO,MAAO,QAAQ,KAAM,MAAM,IAAI,aAAa;CAChF;CACA,QAAQ,MAAM,QAAQ;AACxB"}
package/package.json CHANGED
@@ -1,6 +1,111 @@
1
1
  {
2
2
  "name": "@reactloom/data-grid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.1",
4
+ "description": "Accessible React data grid, pivot table and spreadsheet for ReactLoom: keyboard navigation, sorting, filtering, pagination, selection, column resizing, server-side data and row virtualization.",
5
+ "keywords": [
6
+ "react",
7
+ "reactloom",
8
+ "accessible",
9
+ "a11y",
10
+ "wcag",
11
+ "typescript",
12
+ "data-grid",
13
+ "datagrid",
14
+ "table",
15
+ "react-table",
16
+ "pivot-table",
17
+ "spreadsheet",
18
+ "virtualization"
19
+ ],
20
+ "homepage": "https://www.reactloom.dev/components/data-grid",
21
+ "bugs": {
22
+ "url": "https://www.reactloom.dev/docs/feedback"
23
+ },
24
+ "license": "MIT",
25
+ "type": "module",
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "files": [
30
+ "dist",
31
+ "README.md"
32
+ ],
33
+ "exports": {
34
+ ".": {
35
+ "@reactloom/source": "./src/index.ts",
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ },
39
+ "./server": {
40
+ "@reactloom/source": "./src/server.ts",
41
+ "types": "./dist/server.d.ts",
42
+ "import": "./dist/server.js"
43
+ },
44
+ "./xlsx": {
45
+ "@reactloom/source": "./src/xlsx.ts",
46
+ "types": "./dist/xlsx.d.ts",
47
+ "import": "./dist/xlsx.js"
48
+ },
49
+ "./styles.css": "./dist/styles.css",
50
+ "./package.json": "./package.json"
51
+ },
52
+ "main": "./dist/index.js",
53
+ "types": "./dist/index.d.ts",
54
+ "peerDependencies": {
55
+ "@reactloom/theme": "^1.0.0",
56
+ "@reactloom/ui": "^1.0.0",
57
+ "react": "^18.2.0 || ^19.0.0",
58
+ "react-dom": "^18.2.0 || ^19.0.0"
59
+ },
60
+ "devDependencies": {
61
+ "@size-limit/preset-small-lib": "^14.3.0",
62
+ "@storybook/react-vite": "^10.6.8",
63
+ "@testing-library/dom": "^10.4.2",
64
+ "@testing-library/react": "^16.3.3",
65
+ "@testing-library/user-event": "^14.6.13",
66
+ "@types/node": "^22.19.0",
67
+ "@types/react": "^19.3.0",
68
+ "@types/react-dom": "^19.3.0",
69
+ "@vitejs/plugin-react": "^6.3.0",
70
+ "eslint": "^10.15.0",
71
+ "react": "^19.3.1",
72
+ "react-dom": "^19.3.1",
73
+ "size-limit": "^14.3.0",
74
+ "storybook": "^10.6.8",
75
+ "typescript": "~6.0.3",
76
+ "vite": "^8.3.8",
77
+ "vitest": "^5.1.1",
78
+ "@reactloom/hooks": "0.0.0",
79
+ "@reactloom/eslint-config": "0.0.0",
80
+ "@reactloom/theme": "1.0.1",
81
+ "@reactloom/primitives": "0.0.0",
82
+ "@reactloom/utils": "0.0.0",
83
+ "@reactloom/testing": "0.0.0",
84
+ "@reactloom/tsconfig": "0.0.0",
85
+ "@reactloom/ui": "1.0.1"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
90
+ "dependencies": {
91
+ "@tanstack/react-table": "^9.3.1",
92
+ "@tanstack/react-virtual": "^3.14.26"
93
+ },
94
+ "funding": [
95
+ {
96
+ "type": "github",
97
+ "url": "https://github.com/sponsors/Bindhani1995"
98
+ },
99
+ {
100
+ "type": "ko_fi",
101
+ "url": "https://ko-fi.com/bindhani1995"
102
+ }
103
+ ],
104
+ "scripts": {
105
+ "build": "vite build && tsc -p tsconfig.build.json",
106
+ "typecheck": "tsc -p tsconfig.json",
107
+ "test": "vitest run",
108
+ "lint": "eslint src",
109
+ "size": "size-limit"
110
+ }
6
111
  }