@ricsam/react-spreadsheets 0.0.6 → 0.0.8

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 CHANGED
@@ -86,6 +86,120 @@ export function Demo() {
86
86
  `FormulaWorkbook` adds Excel-style sheet tabs, renaming, deletion and zoom on
87
87
  top of `FormulaSheet`.
88
88
 
89
+ ### Formula reference highlights
90
+
91
+ Keep editor-driven reference highlights separate from the user's spreadsheet
92
+ selection. `FormulaSheet` calls `customCellStyle` with both the cell and its
93
+ engine-provided style, so a host can add a transient range fill and perimeter
94
+ without replacing table or conditional formatting:
95
+
96
+ ```tsx
97
+ type Highlight = {
98
+ start: { rowIndex: number; colIndex: number };
99
+ end: { rowIndex: number; colIndex: number };
100
+ };
101
+
102
+ function ReferenceAwareSheet({ highlight }: { highlight?: Highlight }) {
103
+ return (
104
+ <FormulaSheet
105
+ engine={engine}
106
+ workbookName="Workbook1"
107
+ sheetName="Sheet1"
108
+ style={{ height: 480 }}
109
+ customCellStyle={(cell, internalStyle) => {
110
+ if (
111
+ !highlight ||
112
+ cell.rowIndex < highlight.start.rowIndex ||
113
+ cell.rowIndex > highlight.end.rowIndex ||
114
+ cell.colIndex < highlight.start.colIndex ||
115
+ cell.colIndex > highlight.end.colIndex
116
+ ) {
117
+ return internalStyle;
118
+ }
119
+
120
+ const color = "#7c3aed";
121
+ return {
122
+ ...internalStyle,
123
+ backgroundColor: "rgb(124 58 237 / 14%)",
124
+ ...(cell.rowIndex === highlight.start.rowIndex && { borderTopColor: color }),
125
+ ...(cell.rowIndex === highlight.end.rowIndex && { borderBottomColor: color }),
126
+ ...(cell.colIndex === highlight.start.colIndex && { borderLeftColor: color }),
127
+ ...(cell.colIndex === highlight.end.colIndex && { borderRightColor: color }),
128
+ };
129
+ }}
130
+ />
131
+ );
132
+ }
133
+ ```
134
+
135
+ Update `highlight` from the formula editor's caret/reference analysis. Clearing
136
+ it removes the decoration, while the selection manager continues to own mouse,
137
+ keyboard and edit selection state independently. For `FormulaWorkbook`, pass a
138
+ controlled `activeSheet` if the editor should reveal a reference on another
139
+ sheet; the same `customCellStyle` prop is forwarded to its active sheet.
140
+
141
+ For the range currently being inserted into a formula, use selection-manager's
142
+ reference-picking mode instead. It preserves the primary/editing selection and
143
+ the grid renders the picked range with an independent animated border:
144
+
145
+ ```tsx
146
+ <Spreadsheet
147
+ rowCount={1_000}
148
+ columnCount={50}
149
+ selection={{
150
+ effects(manager) {
151
+ const stop = manager.listenToReferenceSelection((event) => {
152
+ if (event.phase === "start" || event.phase === "change") {
153
+ updateFormulaReference(event.range);
154
+ }
155
+ });
156
+
157
+ manager.beginReferenceSelection({
158
+ editedRange: {
159
+ start: { row: 1, col: 3 },
160
+ end: {
161
+ row: { type: "number", value: 1 },
162
+ col: { type: "number", value: 3 },
163
+ },
164
+ },
165
+ });
166
+ return () => {
167
+ stop();
168
+ manager.endReferenceSelection();
169
+ };
170
+ },
171
+ }}
172
+ />
173
+ ```
174
+
175
+ ### Data-aware keyboard navigation
176
+
177
+ `Cmd/Ctrl + Arrow` jumps through populated cells and reveals the destination;
178
+ adding Shift extends the primary selection. Plain `Spreadsheet` derives its
179
+ used range and jump targets from non-empty `cellData`. `FormulaSheet` also
180
+ supplies table bounds from the formula engine, so navigation inside a table
181
+ respects its data body.
182
+
183
+ Override any part of that behavior through `selection.navigation`:
184
+
185
+ ```tsx
186
+ <Spreadsheet
187
+ rowCount={100_000}
188
+ columnCount={200}
189
+ selection={{
190
+ navigation: {
191
+ getUsedRange: () => model.usedRange,
192
+ getTableAt: (cell) => model.tableAt(cell),
193
+ resolveTarget: (request) => model.resolveJump(request),
194
+ },
195
+ }}
196
+ />
197
+ ```
198
+
199
+ The imperative `SpreadsheetRef.scrollToCell({ row, col }, { align })` reveals a
200
+ cell without changing selection. Alignment is `"nearest"` by default, with
201
+ `"start"` and `"end"` available for explicit positioning.
202
+
89
203
  ## Theming
90
204
 
91
205
  All colors, fonts and sizes are CSS custom properties. The package only ever
@@ -175,11 +289,12 @@ Per-cell styling is done in JS:
175
289
  | --- | --- |
176
290
  | `cellData` | `Map<string, SerializedCellValue>` keyed by A1 reference. Omit for uncontrolled mode. |
177
291
  | `onCellDataChange` | Called with the next map after an edit, paste or fill. |
292
+ | `rowCount` / `columnCount` | Finite grid dimensions. Omit either dimension for an unbounded axis. |
178
293
  | `columnWidths` / `rowHeights` | Controlled sizing, keyed by column letter / 1-based row. |
179
294
  | `customCellStyle` | Per-cell `CSSProperties`. |
180
295
  | `customCellRenderer` | Per-cell React node. |
181
296
  | `parseValue` | Coerce raw editor strings (e.g. text → number) before storing. |
182
- | `selection` | Selection state, callbacks and `effects(selectionManager)` for copy/paste/fill hooks. |
297
+ | `selection` | Selection state, navigation model, and `effects(selectionManager)` for copy/paste/fill/reference hooks. |
183
298
  | `components` + `overlayChildren` | Floating overlays anchored to the grid, optionally snapped to cell edges. |
184
299
 
185
300
  ## Development