@ricsam/react-spreadsheets 0.0.0 → 0.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.
- package/README.md +143 -43
- package/dist/cjs/lib.cjs +4045 -0
- package/dist/cjs/lib.cjs.map +27 -0
- package/dist/cjs/package.json +5 -0
- package/dist/mjs/lib.mjs +3991 -0
- package/dist/mjs/lib.mjs.map +27 -0
- package/dist/mjs/package.json +5 -0
- package/dist/styles.css +483 -0
- package/dist/types/clipboard/clipboard-manager.d.ts +51 -0
- package/dist/types/grid/frame.d.ts +22 -0
- package/dist/types/grid/icons.d.ts +15 -0
- package/dist/types/grid/types.d.ts +178 -0
- package/dist/types/lib.d.ts +26 -0
- package/dist/types/spreadsheet/constants.d.ts +4 -0
- package/dist/types/spreadsheet/snapping.d.ts +22 -0
- package/dist/types/spreadsheet/spreadsheet.d.ts +88 -0
- package/dist/types/spreadsheet/utils.d.ts +28 -0
- package/dist/types/spreadsheet/zoom-constants.d.ts +5 -0
- package/dist/types/types.d.ts +33 -0
- package/dist/types/utils/cn.d.ts +8 -0
- package/dist/types/utils/use-click-away.d.ts +1 -0
- package/dist/types/utils/use-color-scheme.d.ts +10 -0
- package/dist/types/utils/use-resize-observer.d.ts +15 -0
- package/dist/types/workbook/border-sides.d.ts +20 -0
- package/dist/types/workbook/cell-data-type.d.ts +15 -0
- package/dist/types/workbook/cell-edit-error.d.ts +22 -0
- package/dist/types/workbook/workbook-selection-manager.d.ts +71 -0
- package/dist/types/workbook/workbook.d.ts +86 -0
- package/package.json +63 -6
package/README.md
CHANGED
|
@@ -1,45 +1,145 @@
|
|
|
1
1
|
# @ricsam/react-spreadsheets
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
React spreadsheet primitives: an infinitely scrollable, virtualized grid with
|
|
4
|
+
selection, inline editing, clipboard, fill handles, column/row resizing and
|
|
5
|
+
floating overlays — plus optional bindings for
|
|
6
|
+
[`@ricsam/formula-engine`](https://github.com/ricsam/formula-engine).
|
|
7
|
+
|
|
8
|
+
- **Infinite grid** — rows and columns are unbounded; only visible cells render.
|
|
9
|
+
- **Canvas gridlines + DOM cells** — crisp lines, fully stylable cells.
|
|
10
|
+
- **Zero styling dependencies** — one plain CSS file themed with custom properties.
|
|
11
|
+
- **Bring your own state** — controlled or uncontrolled cell data.
|
|
12
|
+
- **Optional formula engine** — drop in `FormulaSheet` / `FormulaWorkbook` for
|
|
13
|
+
formulas, spill ranges, tables, styles and multi-sheet workbooks.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @ricsam/react-spreadsheets @ricsam/selection-manager
|
|
19
|
+
# optional, for the formula-aware components
|
|
20
|
+
bun add @ricsam/formula-engine
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`react`, `react-dom` and `@ricsam/selection-manager` are peer dependencies.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Import the stylesheet once, near your app root:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import "@ricsam/react-spreadsheets/styles.css";
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Standalone grid
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { useState } from "react";
|
|
37
|
+
import { Spreadsheet, type SerializedCellValue } from "@ricsam/react-spreadsheets";
|
|
38
|
+
import "@ricsam/react-spreadsheets/styles.css";
|
|
39
|
+
|
|
40
|
+
export function Demo() {
|
|
41
|
+
const [cells, setCells] = useState<Map<string, SerializedCellValue>>(
|
|
42
|
+
() => new Map([["A1", "Region"], ["B1", "Revenue"], ["A2", "EMEA"], ["B2", 120]]),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Spreadsheet
|
|
47
|
+
style={{ height: 480 }}
|
|
48
|
+
cellData={cells}
|
|
49
|
+
onCellDataChange={setCells}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With the formula engine
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { FormulaEngine } from "@ricsam/formula-engine";
|
|
59
|
+
import { FormulaSheet } from "@ricsam/react-spreadsheets";
|
|
60
|
+
import "@ricsam/react-spreadsheets/styles.css";
|
|
61
|
+
|
|
62
|
+
const engine = FormulaEngine.buildEmpty();
|
|
63
|
+
engine.addWorkbook("Workbook1");
|
|
64
|
+
engine.addSheet({ workbookName: "Workbook1", sheetName: "Sheet1" });
|
|
65
|
+
engine.setSheetContent(
|
|
66
|
+
{ workbookName: "Workbook1", sheetName: "Sheet1" },
|
|
67
|
+
new Map([
|
|
68
|
+
["A1", 10],
|
|
69
|
+
["A2", 20],
|
|
70
|
+
["A3", "=SUM(A1:A2)"], // renders 30
|
|
71
|
+
]),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export function Demo() {
|
|
75
|
+
return (
|
|
76
|
+
<FormulaSheet
|
|
77
|
+
engine={engine}
|
|
78
|
+
workbookName="Workbook1"
|
|
79
|
+
sheetName="Sheet1"
|
|
80
|
+
style={{ height: 480 }}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`FormulaWorkbook` adds Excel-style sheet tabs, renaming, deletion and zoom on
|
|
87
|
+
top of `FormulaSheet`.
|
|
88
|
+
|
|
89
|
+
## Theming
|
|
90
|
+
|
|
91
|
+
All colors, fonts and sizes are CSS custom properties declared on `.rsp-root`.
|
|
92
|
+
Override them anywhere in your cascade:
|
|
93
|
+
|
|
94
|
+
```css
|
|
95
|
+
.rsp-root {
|
|
96
|
+
--rsp-accent: #7c3aed;
|
|
97
|
+
--rsp-bg: #ffffff;
|
|
98
|
+
--rsp-header-bg: #f4f4f5;
|
|
99
|
+
--rsp-cell-font-size: 13px;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Light and dark are resolved automatically with `light-dark()`. To pin a subtree
|
|
104
|
+
to one mode, set `color-scheme: light` (or `dark`) on `.rsp-root`; canvas
|
|
105
|
+
gridlines follow the same setting.
|
|
106
|
+
|
|
107
|
+
Per-cell styling is done in JS:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<Spreadsheet
|
|
111
|
+
cellData={cells}
|
|
112
|
+
customCellStyle={(cell) =>
|
|
113
|
+
typeof cell.value === "number" && cell.value < 0
|
|
114
|
+
? { color: "#dc2626", fontWeight: 600 }
|
|
115
|
+
: {}
|
|
116
|
+
}
|
|
117
|
+
customCellRenderer={(cell) => <span>{String(cell.value ?? "")}</span>}
|
|
118
|
+
/>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Key props
|
|
122
|
+
|
|
123
|
+
| Prop | Description |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| `cellData` | `Map<string, SerializedCellValue>` keyed by A1 reference. Omit for uncontrolled mode. |
|
|
126
|
+
| `onCellDataChange` | Called with the next map after an edit, paste or fill. |
|
|
127
|
+
| `columnWidths` / `rowHeights` | Controlled sizing, keyed by column letter / 1-based row. |
|
|
128
|
+
| `customCellStyle` | Per-cell `CSSProperties`. |
|
|
129
|
+
| `customCellRenderer` | Per-cell React node. |
|
|
130
|
+
| `parseValue` | Coerce raw editor strings (e.g. text → number) before storing. |
|
|
131
|
+
| `selection` | Selection state, callbacks and `effects(selectionManager)` for copy/paste/fill hooks. |
|
|
132
|
+
| `components` + `overlayChildren` | Floating overlays anchored to the grid, optionally snapped to cell edges. |
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
bun install
|
|
138
|
+
bun test # unit + React rendering tests
|
|
139
|
+
bun run typecheck
|
|
140
|
+
bun run build # emits dist/{mjs,cjs,types} + styles.css
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|