@rowsncolumns/spreadsheet 10.10.1 → 10.10.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/dist/cjs/components/outline-gutter/index.d.ts +25 -8
- package/dist/cjs/components/outline-gutter/index.d.ts.map +1 -1
- package/dist/cjs/components/outline-gutter/index.js +108 -85
- package/dist/esm/components/outline-gutter/index.d.ts +25 -8
- package/dist/esm/components/outline-gutter/index.d.ts.map +1 -1
- package/dist/esm/components/outline-gutter/index.js +68 -56
- package/package.json +1 -1
|
@@ -2,7 +2,22 @@ import React from "react";
|
|
|
2
2
|
import { COLUMN_HEADER_HEIGHT, ROW_HEADER_WIDTH } from "../../config";
|
|
3
3
|
import type { DimensionProperties } from "../../types";
|
|
4
4
|
type DimensionMetadata = (DimensionProperties | null | undefined)[] | null | undefined;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The grid's sizing, which the gutters need to line up with the canvas.
|
|
7
|
+
* Pass the same values given to `CanvasGrid`; every one defaults to the
|
|
8
|
+
* grid's own default.
|
|
9
|
+
*/
|
|
10
|
+
export type OutlineGutterSizingProps = {
|
|
11
|
+
defaultColumnWidth?: number;
|
|
12
|
+
defaultRowHeight?: number;
|
|
13
|
+
rowHeaderWidth?: number;
|
|
14
|
+
columnHeaderHeight?: number;
|
|
15
|
+
/** `false` when the grid hides its row and column headers. */
|
|
16
|
+
showHeaders?: boolean;
|
|
17
|
+
/** The grid's zoom (`CanvasGrid` `scale`). */
|
|
18
|
+
scale?: number;
|
|
19
|
+
};
|
|
20
|
+
export type ColumnOutlineGutterProps = OutlineGutterSizingProps & {
|
|
6
21
|
sheetId: number;
|
|
7
22
|
columnMetadata?: DimensionMetadata;
|
|
8
23
|
/** Row metadata for the same sheet. Used to compute the row outline
|
|
@@ -11,25 +26,27 @@ export type ColumnOutlineGutterProps = {
|
|
|
11
26
|
rowMetadata?: DimensionMetadata;
|
|
12
27
|
/** True when summaries sit right of the group (Excel default). */
|
|
13
28
|
summaryRight?: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
/** `level` is the outline level of the group whose button was pressed. */
|
|
30
|
+
onCollapseColumnGroup?(sheetId: number, summaryColumnIndex: number, level?: number): void;
|
|
31
|
+
onExpandColumnGroup?(sheetId: number, summaryColumnIndex: number, level?: number): void;
|
|
16
32
|
/** Excel-style level selector. Renders N+1 numbered buttons in the
|
|
17
33
|
* gutter's leftInset area. */
|
|
18
34
|
onSetOutlineDepth?(sheetId: number, axis: "row" | "column", depth: number): void;
|
|
19
35
|
};
|
|
20
|
-
export declare const ColumnOutlineGutter: React.MemoExoticComponent<({ sheetId, columnMetadata, rowMetadata, summaryRight, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, }: ColumnOutlineGutterProps) => React.JSX.Element | null>;
|
|
21
|
-
export type RowOutlineGutterProps = {
|
|
36
|
+
export declare const ColumnOutlineGutter: React.MemoExoticComponent<({ sheetId, columnMetadata, rowMetadata, summaryRight, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, defaultColumnWidth, rowHeaderWidth, showHeaders, scale, }: ColumnOutlineGutterProps) => React.JSX.Element | null>;
|
|
37
|
+
export type RowOutlineGutterProps = OutlineGutterSizingProps & {
|
|
22
38
|
sheetId: number;
|
|
23
39
|
rowMetadata?: DimensionMetadata;
|
|
24
40
|
/** True when summaries sit below the group (Excel default). */
|
|
25
41
|
summaryBelow?: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
/** `level` is the outline level of the group whose button was pressed. */
|
|
43
|
+
onCollapseRowGroup?(sheetId: number, summaryRowIndex: number, level?: number): void;
|
|
44
|
+
onExpandRowGroup?(sheetId: number, summaryRowIndex: number, level?: number): void;
|
|
28
45
|
/** Excel-style level selector. Renders N+1 numbered buttons at the
|
|
29
46
|
* top of the row gutter strip (in the topInset area). */
|
|
30
47
|
onSetOutlineDepth?(sheetId: number, axis: "row" | "column", depth: number): void;
|
|
31
48
|
};
|
|
32
|
-
export declare const RowOutlineGutter: React.MemoExoticComponent<({ sheetId, rowMetadata, summaryBelow, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, }: RowOutlineGutterProps) => React.JSX.Element | null>;
|
|
49
|
+
export declare const RowOutlineGutter: React.MemoExoticComponent<({ sheetId, rowMetadata, summaryBelow, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, defaultRowHeight, columnHeaderHeight, showHeaders, scale, }: RowOutlineGutterProps) => React.JSX.Element | null>;
|
|
33
50
|
/**
|
|
34
51
|
* Pixel width / height the outline gutter will reserve for the given
|
|
35
52
|
* axis. Returns 0 when the metadata has no `outlineLevel > 0`. Use
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/outline-gutter/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/outline-gutter/index.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAA0D,MAAM,OAAO,CAAC;AAE/E,OAAO,EACL,oBAAoB,EAKpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAwDvD,KAAK,iBAAiB,GAClB,CAAC,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC1C,IAAI,GACJ,SAAS,CAAC;AAgId;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAkBF,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC;;wEAEoE;IACpE,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,qBAAqB,CAAC,CACpB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR,mBAAmB,CAAC,CAClB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR;kCAC8B;IAC9B,iBAAiB,CAAC,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,KAAK,GAAG,QAAQ,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;CACT,CAAC;AAEF,eAAO,MAAM,mBAAmB,6MAa3B,wBAAwB,8BAuN5B,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,GAAG;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,kBAAkB,CAAC,CACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR,gBAAgB,CAAC,CACf,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR;6DACyD;IACzD,iBAAiB,CAAC,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,KAAK,GAAG,QAAQ,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;CACT,CAAC;AAEF,eAAO,MAAM,gBAAgB,yLAYxB,qBAAqB,8BAwMzB,CAAC;AAGF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,CAAC,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,KACtE,MAIF,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
//
|
|
17
17
|
// Buttons are positioned by `getRowOffset` / `getColumnOffset` so they
|
|
18
18
|
// stay aligned with the cell their summary lives on; scroll position
|
|
19
|
-
// shifts the buttons horizontally / vertically.
|
|
19
|
+
// shifts the buttons horizontally / vertically. Those offsets have to
|
|
20
|
+
// use the grid's own sizing (default sizes, header sizes, zoom), so the
|
|
21
|
+
// host passes the same values it gives `CanvasGrid` — see
|
|
22
|
+
// `OutlineGutterSizingProps`.
|
|
20
23
|
//
|
|
21
24
|
// Bracket lines and the "1 / 2 / 3" level bar are intentionally minimal
|
|
22
25
|
// here — the goal is a functional MVP. Polish can layer on later.
|
|
@@ -156,12 +159,80 @@ var findSummaries = function (metadata, summaryAfter) {
|
|
|
156
159
|
}
|
|
157
160
|
return out;
|
|
158
161
|
};
|
|
162
|
+
var resolveSharedSummaries = function (summaries, metadata, summaryAfter) {
|
|
163
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
164
|
+
var _d;
|
|
165
|
+
var levelsAtIndex = new Map();
|
|
166
|
+
try {
|
|
167
|
+
for (var summaries_1 = tslib_1.__values(summaries), summaries_1_1 = summaries_1.next(); !summaries_1_1.done; summaries_1_1 = summaries_1.next()) {
|
|
168
|
+
var s = summaries_1_1.value;
|
|
169
|
+
levelsAtIndex.set(s.index, ((_d = levelsAtIndex.get(s.index)) !== null && _d !== void 0 ? _d : 0) + 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
173
|
+
finally {
|
|
174
|
+
try {
|
|
175
|
+
if (summaries_1_1 && !summaries_1_1.done && (_a = summaries_1.return)) _a.call(summaries_1);
|
|
176
|
+
}
|
|
177
|
+
finally { if (e_1) throw e_1.error; }
|
|
178
|
+
}
|
|
179
|
+
var resolved = summaries.map(function (s) {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
if (((_a = levelsAtIndex.get(s.index)) !== null && _a !== void 0 ? _a : 0) < 2) {
|
|
182
|
+
return tslib_1.__assign(tslib_1.__assign({}, s), { showButton: true, shared: false });
|
|
183
|
+
}
|
|
184
|
+
var _c = tslib_1.__read(summaryAfter
|
|
185
|
+
? [s.startIndex, s.index - 1]
|
|
186
|
+
: [s.index + 1, s.startIndex], 2), from = _c[0], to = _c[1];
|
|
187
|
+
var collapsed = to >= from;
|
|
188
|
+
for (var c = from; c <= to && collapsed; c++) {
|
|
189
|
+
if (!((_b = metadata === null || metadata === void 0 ? void 0 : metadata[c]) === null || _b === void 0 ? void 0 : _b.hiddenByGroup))
|
|
190
|
+
collapsed = false;
|
|
191
|
+
}
|
|
192
|
+
return tslib_1.__assign(tslib_1.__assign({}, s), { collapsed: collapsed, showButton: true, shared: true });
|
|
193
|
+
});
|
|
194
|
+
var collapsedLevelAtIndex = new Map();
|
|
195
|
+
try {
|
|
196
|
+
for (var resolved_1 = tslib_1.__values(resolved), resolved_1_1 = resolved_1.next(); !resolved_1_1.done; resolved_1_1 = resolved_1.next()) {
|
|
197
|
+
var s = resolved_1_1.value;
|
|
198
|
+
if (!s.collapsed)
|
|
199
|
+
continue;
|
|
200
|
+
var prev = collapsedLevelAtIndex.get(s.index);
|
|
201
|
+
if (prev === undefined || s.level < prev) {
|
|
202
|
+
collapsedLevelAtIndex.set(s.index, s.level);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
207
|
+
finally {
|
|
208
|
+
try {
|
|
209
|
+
if (resolved_1_1 && !resolved_1_1.done && (_b = resolved_1.return)) _b.call(resolved_1);
|
|
210
|
+
}
|
|
211
|
+
finally { if (e_2) throw e_2.error; }
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
for (var resolved_2 = tslib_1.__values(resolved), resolved_2_1 = resolved_2.next(); !resolved_2_1.done; resolved_2_1 = resolved_2.next()) {
|
|
215
|
+
var s = resolved_2_1.value;
|
|
216
|
+
var outer = collapsedLevelAtIndex.get(s.index);
|
|
217
|
+
if (outer !== undefined && s.level > outer)
|
|
218
|
+
s.showButton = false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
222
|
+
finally {
|
|
223
|
+
try {
|
|
224
|
+
if (resolved_2_1 && !resolved_2_1.done && (_c = resolved_2.return)) _c.call(resolved_2);
|
|
225
|
+
}
|
|
226
|
+
finally { if (e_3) throw e_3.error; }
|
|
227
|
+
}
|
|
228
|
+
return resolved;
|
|
229
|
+
};
|
|
159
230
|
/**
|
|
160
231
|
* Walk a sparse `DimensionProperties` array once and report the
|
|
161
232
|
* largest `outlineLevel` seen. Returns 0 when no grouping is in use.
|
|
162
233
|
*/
|
|
163
234
|
var computeMaxOutlineLevel = function (metadata) {
|
|
164
|
-
var
|
|
235
|
+
var e_4, _a;
|
|
165
236
|
var _b;
|
|
166
237
|
if (!(metadata === null || metadata === void 0 ? void 0 : metadata.length))
|
|
167
238
|
return 0;
|
|
@@ -174,60 +245,36 @@ var computeMaxOutlineLevel = function (metadata) {
|
|
|
174
245
|
max = level;
|
|
175
246
|
}
|
|
176
247
|
}
|
|
177
|
-
catch (
|
|
248
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
178
249
|
finally {
|
|
179
250
|
try {
|
|
180
251
|
if (metadata_1_1 && !metadata_1_1.done && (_a = metadata_1.return)) _a.call(metadata_1);
|
|
181
252
|
}
|
|
182
|
-
finally { if (
|
|
253
|
+
finally { if (e_4) throw e_4.error; }
|
|
183
254
|
}
|
|
184
255
|
return max;
|
|
185
256
|
};
|
|
186
257
|
exports.ColumnOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
187
|
-
var sheetId = _a.sheetId, columnMetadata = _a.columnMetadata, rowMetadata = _a.rowMetadata, _b = _a.summaryRight, summaryRight = _b === void 0 ? true : _b, onCollapseColumnGroup = _a.onCollapseColumnGroup, onExpandColumnGroup = _a.onExpandColumnGroup, onSetOutlineDepth = _a.onSetOutlineDepth;
|
|
258
|
+
var sheetId = _a.sheetId, columnMetadata = _a.columnMetadata, rowMetadata = _a.rowMetadata, _b = _a.summaryRight, summaryRight = _b === void 0 ? true : _b, onCollapseColumnGroup = _a.onCollapseColumnGroup, onExpandColumnGroup = _a.onExpandColumnGroup, onSetOutlineDepth = _a.onSetOutlineDepth, _c = _a.defaultColumnWidth, defaultColumnWidth = _c === void 0 ? config_1.DEFAULT_COLUMN_WIDTH : _c, _d = _a.rowHeaderWidth, rowHeaderWidth = _d === void 0 ? config_1.ROW_HEADER_WIDTH : _d, _e = _a.showHeaders, showHeaders = _e === void 0 ? true : _e, _f = _a.scale, scale = _f === void 0 ? 1 : _f;
|
|
188
259
|
// Shift the strip right by the row outline gutter's width when one
|
|
189
260
|
// exists, so the strip's content lines up with the canvas (which
|
|
190
261
|
// sits to the right of the row gutter).
|
|
191
262
|
var leftInset = (0, react_1.useMemo)(function () { return (0, exports.computeOutlineGutterSize)(rowMetadata); }, [rowMetadata]);
|
|
192
263
|
var maxColumnOutlineLevel = (0, react_1.useMemo)(function () { return computeMaxOutlineLevel(columnMetadata); }, [columnMetadata]);
|
|
193
|
-
var columnOffsets = (0, react_1.useMemo)(function () { return (0, offsets_1.buildOffsetIndex)(columnMetadata,
|
|
264
|
+
var columnOffsets = (0, react_1.useMemo)(function () { return (0, offsets_1.buildOffsetIndex)(columnMetadata, defaultColumnWidth); }, [columnMetadata, defaultColumnWidth]);
|
|
265
|
+
// The canvas draws every size (headers included) times its zoom, and
|
|
266
|
+
// its scroll position is in those scaled pixels.
|
|
267
|
+
var headerWidth = showHeaders ? rowHeaderWidth : 0;
|
|
194
268
|
var getColumnOffset = (0, react_1.useCallback)(function (columnIndex) {
|
|
195
|
-
return (0, offsets_1.offsetAt)(columnOffsets, columnIndex) +
|
|
196
|
-
}, [columnOffsets]);
|
|
269
|
+
return ((0, offsets_1.offsetAt)(columnOffsets, columnIndex) + headerWidth) * scale;
|
|
270
|
+
}, [columnOffsets, headerWidth, scale]);
|
|
197
271
|
var scrollLeft = useGridScrollPosition().scrollLeft;
|
|
198
|
-
var
|
|
272
|
+
var _g = tslib_1.__read((0, use_resize_observer_1.useResizeObserver)(), 2), stripRef = _g[0], stripRect = _g[1];
|
|
199
273
|
var summaries = (0, react_1.useMemo)(function () {
|
|
200
274
|
return maxColumnOutlineLevel > 0
|
|
201
|
-
? findSummaries(columnMetadata, summaryRight)
|
|
275
|
+
? resolveSharedSummaries(findSummaries(columnMetadata, summaryRight), columnMetadata, summaryRight)
|
|
202
276
|
: [];
|
|
203
277
|
}, [columnMetadata, maxColumnOutlineLevel, summaryRight]);
|
|
204
|
-
// When nested groups share the same summary cell (common with
|
|
205
|
-
// `summaryRight=true`: outer and inner end at the same column), we
|
|
206
|
-
// render the bracket for every level but only the OUTERMOST
|
|
207
|
-
// (lowest level number) gets a +/- button — matches Excel.
|
|
208
|
-
// Granular collapse of inner groups uses the level-selector
|
|
209
|
-
// buttons instead.
|
|
210
|
-
var buttonLevelForIndex = (0, react_1.useMemo)(function () {
|
|
211
|
-
var e_2, _a;
|
|
212
|
-
var m = new Map();
|
|
213
|
-
try {
|
|
214
|
-
for (var summaries_1 = tslib_1.__values(summaries), summaries_1_1 = summaries_1.next(); !summaries_1_1.done; summaries_1_1 = summaries_1.next()) {
|
|
215
|
-
var s = summaries_1_1.value;
|
|
216
|
-
var existing = m.get(s.index);
|
|
217
|
-
if (existing === undefined || s.level < existing) {
|
|
218
|
-
m.set(s.index, s.level);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
223
|
-
finally {
|
|
224
|
-
try {
|
|
225
|
-
if (summaries_1_1 && !summaries_1_1.done && (_a = summaries_1.return)) _a.call(summaries_1);
|
|
226
|
-
}
|
|
227
|
-
finally { if (e_2) throw e_2.error; }
|
|
228
|
-
}
|
|
229
|
-
return m;
|
|
230
|
-
}, [summaries]);
|
|
231
278
|
if (maxColumnOutlineLevel <= 0)
|
|
232
279
|
return null;
|
|
233
280
|
// N+1 level-selector buttons. `depth=1` collapses every group;
|
|
@@ -239,15 +286,14 @@ exports.ColumnOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
239
286
|
// Summary +/- buttons, the bracket line, and dots all get clipped
|
|
240
287
|
// to this boundary so they never bleed into the level-selector
|
|
241
288
|
// lane or the row-header column above the grid.
|
|
242
|
-
var summaryMinX = leftInset +
|
|
289
|
+
var summaryMinX = leftInset + headerWidth * scale;
|
|
243
290
|
// Right edge of the strip in its own coord space. Anything past it
|
|
244
291
|
// is clipped by `overflow-hidden`, so it is never rendered.
|
|
245
292
|
var viewportMaxX = leftInset +
|
|
246
293
|
resolveViewportSize(stripRect.width, typeof window === "undefined" ? undefined : window.innerWidth);
|
|
247
294
|
// Columns intersecting the strip, for the per-column dots.
|
|
248
|
-
var firstVisibleColumn = Math.max(1, (0, offsets_1.cellAtOffset)(columnOffsets, scrollLeft) - OVERSCAN_CELLS);
|
|
249
|
-
var lastVisibleColumn = (0, offsets_1.cellAtOffset)(columnOffsets, scrollLeft + viewportMaxX - summaryMinX) +
|
|
250
|
-
OVERSCAN_CELLS;
|
|
295
|
+
var firstVisibleColumn = Math.max(1, (0, offsets_1.cellAtOffset)(columnOffsets, scrollLeft / scale) - OVERSCAN_CELLS);
|
|
296
|
+
var lastVisibleColumn = (0, offsets_1.cellAtOffset)(columnOffsets, (scrollLeft + viewportMaxX - summaryMinX) / scale) + OVERSCAN_CELLS;
|
|
251
297
|
return (react_1.default.createElement("div", { ref: stripRef, "data-testid": "column-outline-gutter", className: "bg-rnc-background relative overflow-hidden border-l border-r border-r-rnc-border border-l-rnc-border border-solid border-t-rnc-border border-t border-b-0", style: {
|
|
252
298
|
height: gutterHeight,
|
|
253
299
|
paddingLeft: leftInset,
|
|
@@ -261,7 +307,7 @@ exports.ColumnOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
261
307
|
onSetOutlineDepth === null || onSetOutlineDepth === void 0 ? void 0 : onSetOutlineDepth(sheetId, "column", depth);
|
|
262
308
|
} }, depth)); })),
|
|
263
309
|
summaries.map(function (_a) {
|
|
264
|
-
var index = _a.index, startIndex = _a.startIndex, collapsed = _a.collapsed, level = _a.level;
|
|
310
|
+
var index = _a.index, startIndex = _a.startIndex, collapsed = _a.collapsed, level = _a.level, showButton = _a.showButton, shared = _a.shared;
|
|
265
311
|
// Anchor positions inside the cell area; add `leftInset` so
|
|
266
312
|
// x=0 of the strip lines up with the grid's content origin.
|
|
267
313
|
var buttonX = getColumnOffset(index) - scrollLeft + leftInset;
|
|
@@ -324,57 +370,36 @@ exports.ColumnOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
324
370
|
top: lineCenterY + 3,
|
|
325
371
|
} }));
|
|
326
372
|
}))) : null,
|
|
327
|
-
showSummary &&
|
|
328
|
-
? "Expand column group at ".concat(index)
|
|
329
|
-
: "Collapse column group at ".concat(index), size: "xs", variant: "outline", className: "absolute p-0 min-w-0 min-h-0", style: {
|
|
373
|
+
showSummary && showButton ? (react_1.default.createElement(ui_1.Button, { "aria-label": "".concat(collapsed ? "Expand" : "Collapse", " column group at ").concat(index).concat(shared ? " level ".concat(level) : ""), size: "xs", variant: "outline", className: "absolute p-0 min-w-0 min-h-0", style: {
|
|
330
374
|
left: buttonX,
|
|
331
375
|
top: y,
|
|
332
376
|
}, onClick: function (e) {
|
|
333
377
|
e.stopPropagation();
|
|
334
378
|
if (collapsed)
|
|
335
|
-
onExpandColumnGroup === null || onExpandColumnGroup === void 0 ? void 0 : onExpandColumnGroup(sheetId, index);
|
|
379
|
+
onExpandColumnGroup === null || onExpandColumnGroup === void 0 ? void 0 : onExpandColumnGroup(sheetId, index, level);
|
|
336
380
|
else
|
|
337
|
-
onCollapseColumnGroup === null || onCollapseColumnGroup === void 0 ? void 0 : onCollapseColumnGroup(sheetId, index);
|
|
381
|
+
onCollapseColumnGroup === null || onCollapseColumnGroup === void 0 ? void 0 : onCollapseColumnGroup(sheetId, index, level);
|
|
338
382
|
} }, collapsed ? (react_1.default.createElement(icons_1.PlusIcon, { className: "w-3 h-3" })) : (react_1.default.createElement(icons_1.MinusIcon, { className: "w-3 h-3" })))) : null));
|
|
339
383
|
})));
|
|
340
384
|
});
|
|
341
385
|
exports.ColumnOutlineGutter.displayName = "ColumnOutlineGutter";
|
|
342
386
|
exports.RowOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
343
|
-
var sheetId = _a.sheetId, rowMetadata = _a.rowMetadata, _b = _a.summaryBelow, summaryBelow = _b === void 0 ? true : _b, onCollapseRowGroup = _a.onCollapseRowGroup, onExpandRowGroup = _a.onExpandRowGroup, onSetOutlineDepth = _a.onSetOutlineDepth;
|
|
387
|
+
var sheetId = _a.sheetId, rowMetadata = _a.rowMetadata, _b = _a.summaryBelow, summaryBelow = _b === void 0 ? true : _b, onCollapseRowGroup = _a.onCollapseRowGroup, onExpandRowGroup = _a.onExpandRowGroup, onSetOutlineDepth = _a.onSetOutlineDepth, _c = _a.defaultRowHeight, defaultRowHeight = _c === void 0 ? config_1.DEFAULT_ROW_HEIGHT : _c, _d = _a.columnHeaderHeight, columnHeaderHeight = _d === void 0 ? config_1.COLUMN_HEADER_HEIGHT : _d, _e = _a.showHeaders, showHeaders = _e === void 0 ? true : _e, _f = _a.scale, scale = _f === void 0 ? 1 : _f;
|
|
344
388
|
var topInset = 0;
|
|
345
389
|
var maxRowOutlineLevel = (0, react_1.useMemo)(function () { return computeMaxOutlineLevel(rowMetadata); }, [rowMetadata]);
|
|
346
|
-
var rowOffsets = (0, react_1.useMemo)(function () { return (0, offsets_1.buildOffsetIndex)(rowMetadata,
|
|
390
|
+
var rowOffsets = (0, react_1.useMemo)(function () { return (0, offsets_1.buildOffsetIndex)(rowMetadata, defaultRowHeight); }, [rowMetadata, defaultRowHeight]);
|
|
391
|
+
// Same scaling as the column gutter: canvas sizes and scroll are zoomed.
|
|
392
|
+
var headerHeight = showHeaders ? columnHeaderHeight : 0;
|
|
347
393
|
var getRowOffset = (0, react_1.useCallback)(function (rowIndex) {
|
|
348
|
-
return (0, offsets_1.offsetAt)(rowOffsets, rowIndex) +
|
|
349
|
-
}, [rowOffsets]);
|
|
394
|
+
return ((0, offsets_1.offsetAt)(rowOffsets, rowIndex) + headerHeight) * scale;
|
|
395
|
+
}, [rowOffsets, headerHeight, scale]);
|
|
350
396
|
var scrollTop = useGridScrollPosition().scrollTop;
|
|
351
|
-
var
|
|
397
|
+
var _g = tslib_1.__read((0, use_resize_observer_1.useResizeObserver)(), 2), stripRef = _g[0], stripRect = _g[1];
|
|
352
398
|
var summaries = (0, react_1.useMemo)(function () {
|
|
353
|
-
return maxRowOutlineLevel > 0
|
|
399
|
+
return maxRowOutlineLevel > 0
|
|
400
|
+
? resolveSharedSummaries(findSummaries(rowMetadata, summaryBelow), rowMetadata, summaryBelow)
|
|
401
|
+
: [];
|
|
354
402
|
}, [rowMetadata, maxRowOutlineLevel, summaryBelow]);
|
|
355
|
-
// Dedup buttons by index (outermost level wins) — matches Excel.
|
|
356
|
-
// See the matching `ColumnOutlineGutter` block for the rationale.
|
|
357
|
-
var buttonLevelForIndex = (0, react_1.useMemo)(function () {
|
|
358
|
-
var e_3, _a;
|
|
359
|
-
var m = new Map();
|
|
360
|
-
try {
|
|
361
|
-
for (var summaries_2 = tslib_1.__values(summaries), summaries_2_1 = summaries_2.next(); !summaries_2_1.done; summaries_2_1 = summaries_2.next()) {
|
|
362
|
-
var s = summaries_2_1.value;
|
|
363
|
-
var existing = m.get(s.index);
|
|
364
|
-
if (existing === undefined || s.level < existing) {
|
|
365
|
-
m.set(s.index, s.level);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
370
|
-
finally {
|
|
371
|
-
try {
|
|
372
|
-
if (summaries_2_1 && !summaries_2_1.done && (_a = summaries_2.return)) _a.call(summaries_2);
|
|
373
|
-
}
|
|
374
|
-
finally { if (e_3) throw e_3.error; }
|
|
375
|
-
}
|
|
376
|
-
return m;
|
|
377
|
-
}, [summaries]);
|
|
378
403
|
if (maxRowOutlineLevel <= 0)
|
|
379
404
|
return null;
|
|
380
405
|
// N+1 level-selector buttons, stacked horizontally at the top of
|
|
@@ -386,14 +411,14 @@ exports.RowOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
386
411
|
// Summary +/- buttons, the bracket line, and dots all get clipped
|
|
387
412
|
// to this boundary so they never bleed into the level-selector
|
|
388
413
|
// row or the column-header band beside the grid.
|
|
389
|
-
var summaryMinY = topInset +
|
|
414
|
+
var summaryMinY = topInset + headerHeight * scale;
|
|
390
415
|
// Bottom edge of the strip in its own coord space. Anything below
|
|
391
416
|
// it is clipped by `overflow-hidden`, so it is never rendered.
|
|
392
417
|
var viewportMaxY = topInset +
|
|
393
418
|
resolveViewportSize(stripRect.height, typeof window === "undefined" ? undefined : window.innerHeight);
|
|
394
419
|
// Rows intersecting the strip, for the per-row dots.
|
|
395
|
-
var firstVisibleRow = Math.max(1, (0, offsets_1.cellAtOffset)(rowOffsets, scrollTop) - OVERSCAN_CELLS);
|
|
396
|
-
var lastVisibleRow = (0, offsets_1.cellAtOffset)(rowOffsets, scrollTop + viewportMaxY - summaryMinY) +
|
|
420
|
+
var firstVisibleRow = Math.max(1, (0, offsets_1.cellAtOffset)(rowOffsets, scrollTop / scale) - OVERSCAN_CELLS);
|
|
421
|
+
var lastVisibleRow = (0, offsets_1.cellAtOffset)(rowOffsets, (scrollTop + viewportMaxY - summaryMinY) / scale) +
|
|
397
422
|
OVERSCAN_CELLS;
|
|
398
423
|
return (react_1.default.createElement("div", { ref: stripRef, "data-testid": "row-outline-gutter", className: "bg-rnc-background relative overflow-hidden border-t border-b border-t-rnc-border border-b-rnc-border border-solid border-l-rnc-border border-l border-r-0", style: {
|
|
399
424
|
width: gutterWidth,
|
|
@@ -408,7 +433,7 @@ exports.RowOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
408
433
|
onSetOutlineDepth === null || onSetOutlineDepth === void 0 ? void 0 : onSetOutlineDepth(sheetId, "row", depth);
|
|
409
434
|
} }, depth)); })),
|
|
410
435
|
summaries.map(function (_a) {
|
|
411
|
-
var index = _a.index, startIndex = _a.startIndex, collapsed = _a.collapsed, level = _a.level;
|
|
436
|
+
var index = _a.index, startIndex = _a.startIndex, collapsed = _a.collapsed, level = _a.level, showButton = _a.showButton, shared = _a.shared;
|
|
412
437
|
var buttonY = getRowOffset(index) - scrollTop + topInset;
|
|
413
438
|
var lineStartY = getRowOffset(startIndex) - scrollTop + topInset + 2;
|
|
414
439
|
// The whole group sits below the strip: nothing to paint.
|
|
@@ -465,17 +490,15 @@ exports.RowOutlineGutter = (0, react_1.memo)(function (_a) {
|
|
|
465
490
|
top: cy - 1,
|
|
466
491
|
} }));
|
|
467
492
|
}))) : null,
|
|
468
|
-
showSummary &&
|
|
469
|
-
? "Expand row group at ".concat(index)
|
|
470
|
-
: "Collapse row group at ".concat(index), className: "absolute p-0 min-w-0 min-h-0", size: "xs", variant: "outline", style: {
|
|
493
|
+
showSummary && showButton ? (react_1.default.createElement(ui_1.Button, { "aria-label": "".concat(collapsed ? "Expand" : "Collapse", " row group at ").concat(index).concat(shared ? " level ".concat(level) : ""), className: "absolute p-0 min-w-0 min-h-0", size: "xs", variant: "outline", style: {
|
|
471
494
|
left: x,
|
|
472
495
|
top: buttonY,
|
|
473
496
|
}, onClick: function (e) {
|
|
474
497
|
e.stopPropagation();
|
|
475
498
|
if (collapsed)
|
|
476
|
-
onExpandRowGroup === null || onExpandRowGroup === void 0 ? void 0 : onExpandRowGroup(sheetId, index);
|
|
499
|
+
onExpandRowGroup === null || onExpandRowGroup === void 0 ? void 0 : onExpandRowGroup(sheetId, index, level);
|
|
477
500
|
else
|
|
478
|
-
onCollapseRowGroup === null || onCollapseRowGroup === void 0 ? void 0 : onCollapseRowGroup(sheetId, index);
|
|
501
|
+
onCollapseRowGroup === null || onCollapseRowGroup === void 0 ? void 0 : onCollapseRowGroup(sheetId, index, level);
|
|
479
502
|
} }, collapsed ? (react_1.default.createElement(icons_1.PlusIcon, { className: "w-3 h-3" })) : (react_1.default.createElement(icons_1.MinusIcon, { className: "w-3 h-3" })))) : null));
|
|
480
503
|
})));
|
|
481
504
|
});
|
|
@@ -2,7 +2,22 @@ import React from "react";
|
|
|
2
2
|
import { COLUMN_HEADER_HEIGHT, ROW_HEADER_WIDTH } from "../../config";
|
|
3
3
|
import type { DimensionProperties } from "../../types";
|
|
4
4
|
type DimensionMetadata = (DimensionProperties | null | undefined)[] | null | undefined;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The grid's sizing, which the gutters need to line up with the canvas.
|
|
7
|
+
* Pass the same values given to `CanvasGrid`; every one defaults to the
|
|
8
|
+
* grid's own default.
|
|
9
|
+
*/
|
|
10
|
+
export type OutlineGutterSizingProps = {
|
|
11
|
+
defaultColumnWidth?: number;
|
|
12
|
+
defaultRowHeight?: number;
|
|
13
|
+
rowHeaderWidth?: number;
|
|
14
|
+
columnHeaderHeight?: number;
|
|
15
|
+
/** `false` when the grid hides its row and column headers. */
|
|
16
|
+
showHeaders?: boolean;
|
|
17
|
+
/** The grid's zoom (`CanvasGrid` `scale`). */
|
|
18
|
+
scale?: number;
|
|
19
|
+
};
|
|
20
|
+
export type ColumnOutlineGutterProps = OutlineGutterSizingProps & {
|
|
6
21
|
sheetId: number;
|
|
7
22
|
columnMetadata?: DimensionMetadata;
|
|
8
23
|
/** Row metadata for the same sheet. Used to compute the row outline
|
|
@@ -11,25 +26,27 @@ export type ColumnOutlineGutterProps = {
|
|
|
11
26
|
rowMetadata?: DimensionMetadata;
|
|
12
27
|
/** True when summaries sit right of the group (Excel default). */
|
|
13
28
|
summaryRight?: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
/** `level` is the outline level of the group whose button was pressed. */
|
|
30
|
+
onCollapseColumnGroup?(sheetId: number, summaryColumnIndex: number, level?: number): void;
|
|
31
|
+
onExpandColumnGroup?(sheetId: number, summaryColumnIndex: number, level?: number): void;
|
|
16
32
|
/** Excel-style level selector. Renders N+1 numbered buttons in the
|
|
17
33
|
* gutter's leftInset area. */
|
|
18
34
|
onSetOutlineDepth?(sheetId: number, axis: "row" | "column", depth: number): void;
|
|
19
35
|
};
|
|
20
|
-
export declare const ColumnOutlineGutter: React.MemoExoticComponent<({ sheetId, columnMetadata, rowMetadata, summaryRight, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, }: ColumnOutlineGutterProps) => React.JSX.Element | null>;
|
|
21
|
-
export type RowOutlineGutterProps = {
|
|
36
|
+
export declare const ColumnOutlineGutter: React.MemoExoticComponent<({ sheetId, columnMetadata, rowMetadata, summaryRight, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, defaultColumnWidth, rowHeaderWidth, showHeaders, scale, }: ColumnOutlineGutterProps) => React.JSX.Element | null>;
|
|
37
|
+
export type RowOutlineGutterProps = OutlineGutterSizingProps & {
|
|
22
38
|
sheetId: number;
|
|
23
39
|
rowMetadata?: DimensionMetadata;
|
|
24
40
|
/** True when summaries sit below the group (Excel default). */
|
|
25
41
|
summaryBelow?: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
/** `level` is the outline level of the group whose button was pressed. */
|
|
43
|
+
onCollapseRowGroup?(sheetId: number, summaryRowIndex: number, level?: number): void;
|
|
44
|
+
onExpandRowGroup?(sheetId: number, summaryRowIndex: number, level?: number): void;
|
|
28
45
|
/** Excel-style level selector. Renders N+1 numbered buttons at the
|
|
29
46
|
* top of the row gutter strip (in the topInset area). */
|
|
30
47
|
onSetOutlineDepth?(sheetId: number, axis: "row" | "column", depth: number): void;
|
|
31
48
|
};
|
|
32
|
-
export declare const RowOutlineGutter: React.MemoExoticComponent<({ sheetId, rowMetadata, summaryBelow, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, }: RowOutlineGutterProps) => React.JSX.Element | null>;
|
|
49
|
+
export declare const RowOutlineGutter: React.MemoExoticComponent<({ sheetId, rowMetadata, summaryBelow, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, defaultRowHeight, columnHeaderHeight, showHeaders, scale, }: RowOutlineGutterProps) => React.JSX.Element | null>;
|
|
33
50
|
/**
|
|
34
51
|
* Pixel width / height the outline gutter will reserve for the given
|
|
35
52
|
* axis. Returns 0 when the metadata has no `outlineLevel > 0`. Use
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/outline-gutter/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/outline-gutter/index.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAA0D,MAAM,OAAO,CAAC;AAE/E,OAAO,EACL,oBAAoB,EAKpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAwDvD,KAAK,iBAAiB,GAClB,CAAC,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC1C,IAAI,GACJ,SAAS,CAAC;AAgId;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAkBF,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC;;wEAEoE;IACpE,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,qBAAqB,CAAC,CACpB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR,mBAAmB,CAAC,CAClB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR;kCAC8B;IAC9B,iBAAiB,CAAC,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,KAAK,GAAG,QAAQ,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;CACT,CAAC;AAEF,eAAO,MAAM,mBAAmB,6MAa3B,wBAAwB,8BAuN5B,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,GAAG;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,kBAAkB,CAAC,CACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR,gBAAgB,CAAC,CACf,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,IAAI,CAAC;IACR;6DACyD;IACzD,iBAAiB,CAAC,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,KAAK,GAAG,QAAQ,EACtB,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;CACT,CAAC;AAEF,eAAO,MAAM,gBAAgB,yLAYxB,qBAAqB,8BAwMzB,CAAC;AAGF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,CAAC,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,KACtE,MAIF,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
//
|
|
16
16
|
// Buttons are positioned by `getRowOffset` / `getColumnOffset` so they
|
|
17
17
|
// stay aligned with the cell their summary lives on; scroll position
|
|
18
|
-
// shifts the buttons horizontally / vertically.
|
|
18
|
+
// shifts the buttons horizontally / vertically. Those offsets have to
|
|
19
|
+
// use the grid's own sizing (default sizes, header sizes, zoom), so the
|
|
20
|
+
// host passes the same values it gives `CanvasGrid` — see
|
|
21
|
+
// `OutlineGutterSizingProps`.
|
|
19
22
|
//
|
|
20
23
|
// Bracket lines and the "1 / 2 / 3" level bar are intentionally minimal
|
|
21
24
|
// here — the goal is a functional MVP. Polish can layer on later.
|
|
@@ -144,6 +147,41 @@ const findSummaries = (metadata, summaryAfter) => {
|
|
|
144
147
|
}
|
|
145
148
|
return out;
|
|
146
149
|
};
|
|
150
|
+
const resolveSharedSummaries = (summaries, metadata, summaryAfter) => {
|
|
151
|
+
const levelsAtIndex = new Map();
|
|
152
|
+
for (const s of summaries) {
|
|
153
|
+
levelsAtIndex.set(s.index, (levelsAtIndex.get(s.index) ?? 0) + 1);
|
|
154
|
+
}
|
|
155
|
+
const resolved = summaries.map((s) => {
|
|
156
|
+
if ((levelsAtIndex.get(s.index) ?? 0) < 2) {
|
|
157
|
+
return { ...s, showButton: true, shared: false };
|
|
158
|
+
}
|
|
159
|
+
const [from, to] = summaryAfter
|
|
160
|
+
? [s.startIndex, s.index - 1]
|
|
161
|
+
: [s.index + 1, s.startIndex];
|
|
162
|
+
let collapsed = to >= from;
|
|
163
|
+
for (let c = from; c <= to && collapsed; c++) {
|
|
164
|
+
if (!metadata?.[c]?.hiddenByGroup)
|
|
165
|
+
collapsed = false;
|
|
166
|
+
}
|
|
167
|
+
return { ...s, collapsed, showButton: true, shared: true };
|
|
168
|
+
});
|
|
169
|
+
const collapsedLevelAtIndex = new Map();
|
|
170
|
+
for (const s of resolved) {
|
|
171
|
+
if (!s.collapsed)
|
|
172
|
+
continue;
|
|
173
|
+
const prev = collapsedLevelAtIndex.get(s.index);
|
|
174
|
+
if (prev === undefined || s.level < prev) {
|
|
175
|
+
collapsedLevelAtIndex.set(s.index, s.level);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const s of resolved) {
|
|
179
|
+
const outer = collapsedLevelAtIndex.get(s.index);
|
|
180
|
+
if (outer !== undefined && s.level > outer)
|
|
181
|
+
s.showButton = false;
|
|
182
|
+
}
|
|
183
|
+
return resolved;
|
|
184
|
+
};
|
|
147
185
|
/**
|
|
148
186
|
* Walk a sparse `DimensionProperties` array once and report the
|
|
149
187
|
* largest `outlineLevel` seen. Returns 0 when no grouping is in use.
|
|
@@ -159,35 +197,22 @@ const computeMaxOutlineLevel = (metadata) => {
|
|
|
159
197
|
}
|
|
160
198
|
return max;
|
|
161
199
|
};
|
|
162
|
-
export const ColumnOutlineGutter = memo(({ sheetId, columnMetadata, rowMetadata, summaryRight = true, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, }) => {
|
|
200
|
+
export const ColumnOutlineGutter = memo(({ sheetId, columnMetadata, rowMetadata, summaryRight = true, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, defaultColumnWidth = DEFAULT_COLUMN_WIDTH, rowHeaderWidth = ROW_HEADER_WIDTH, showHeaders = true, scale = 1, }) => {
|
|
163
201
|
// Shift the strip right by the row outline gutter's width when one
|
|
164
202
|
// exists, so the strip's content lines up with the canvas (which
|
|
165
203
|
// sits to the right of the row gutter).
|
|
166
204
|
const leftInset = useMemo(() => computeOutlineGutterSize(rowMetadata), [rowMetadata]);
|
|
167
205
|
const maxColumnOutlineLevel = useMemo(() => computeMaxOutlineLevel(columnMetadata), [columnMetadata]);
|
|
168
|
-
const columnOffsets = useMemo(() => buildOffsetIndex(columnMetadata,
|
|
169
|
-
|
|
206
|
+
const columnOffsets = useMemo(() => buildOffsetIndex(columnMetadata, defaultColumnWidth), [columnMetadata, defaultColumnWidth]);
|
|
207
|
+
// The canvas draws every size (headers included) times its zoom, and
|
|
208
|
+
// its scroll position is in those scaled pixels.
|
|
209
|
+
const headerWidth = showHeaders ? rowHeaderWidth : 0;
|
|
210
|
+
const getColumnOffset = useCallback((columnIndex) => (offsetAt(columnOffsets, columnIndex) + headerWidth) * scale, [columnOffsets, headerWidth, scale]);
|
|
170
211
|
const { scrollLeft } = useGridScrollPosition();
|
|
171
212
|
const [stripRef, stripRect] = useResizeObserver();
|
|
172
213
|
const summaries = useMemo(() => maxColumnOutlineLevel > 0
|
|
173
|
-
? findSummaries(columnMetadata, summaryRight)
|
|
214
|
+
? resolveSharedSummaries(findSummaries(columnMetadata, summaryRight), columnMetadata, summaryRight)
|
|
174
215
|
: [], [columnMetadata, maxColumnOutlineLevel, summaryRight]);
|
|
175
|
-
// When nested groups share the same summary cell (common with
|
|
176
|
-
// `summaryRight=true`: outer and inner end at the same column), we
|
|
177
|
-
// render the bracket for every level but only the OUTERMOST
|
|
178
|
-
// (lowest level number) gets a +/- button — matches Excel.
|
|
179
|
-
// Granular collapse of inner groups uses the level-selector
|
|
180
|
-
// buttons instead.
|
|
181
|
-
const buttonLevelForIndex = useMemo(() => {
|
|
182
|
-
const m = new Map();
|
|
183
|
-
for (const s of summaries) {
|
|
184
|
-
const existing = m.get(s.index);
|
|
185
|
-
if (existing === undefined || s.level < existing) {
|
|
186
|
-
m.set(s.index, s.level);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return m;
|
|
190
|
-
}, [summaries]);
|
|
191
216
|
if (maxColumnOutlineLevel <= 0)
|
|
192
217
|
return null;
|
|
193
218
|
// N+1 level-selector buttons. `depth=1` collapses every group;
|
|
@@ -199,15 +224,14 @@ export const ColumnOutlineGutter = memo(({ sheetId, columnMetadata, rowMetadata,
|
|
|
199
224
|
// Summary +/- buttons, the bracket line, and dots all get clipped
|
|
200
225
|
// to this boundary so they never bleed into the level-selector
|
|
201
226
|
// lane or the row-header column above the grid.
|
|
202
|
-
const summaryMinX = leftInset +
|
|
227
|
+
const summaryMinX = leftInset + headerWidth * scale;
|
|
203
228
|
// Right edge of the strip in its own coord space. Anything past it
|
|
204
229
|
// is clipped by `overflow-hidden`, so it is never rendered.
|
|
205
230
|
const viewportMaxX = leftInset +
|
|
206
231
|
resolveViewportSize(stripRect.width, typeof window === "undefined" ? undefined : window.innerWidth);
|
|
207
232
|
// Columns intersecting the strip, for the per-column dots.
|
|
208
|
-
const firstVisibleColumn = Math.max(1, cellAtOffset(columnOffsets, scrollLeft) - OVERSCAN_CELLS);
|
|
209
|
-
const lastVisibleColumn = cellAtOffset(columnOffsets, scrollLeft + viewportMaxX - summaryMinX) +
|
|
210
|
-
OVERSCAN_CELLS;
|
|
233
|
+
const firstVisibleColumn = Math.max(1, cellAtOffset(columnOffsets, scrollLeft / scale) - OVERSCAN_CELLS);
|
|
234
|
+
const lastVisibleColumn = cellAtOffset(columnOffsets, (scrollLeft + viewportMaxX - summaryMinX) / scale) + OVERSCAN_CELLS;
|
|
211
235
|
return (React.createElement("div", { ref: stripRef, "data-testid": "column-outline-gutter", className: "bg-rnc-background relative overflow-hidden border-l border-r border-r-rnc-border border-l-rnc-border border-solid border-t-rnc-border border-t border-b-0", style: {
|
|
212
236
|
height: gutterHeight,
|
|
213
237
|
paddingLeft: leftInset,
|
|
@@ -220,7 +244,7 @@ export const ColumnOutlineGutter = memo(({ sheetId, columnMetadata, rowMetadata,
|
|
|
220
244
|
e.stopPropagation();
|
|
221
245
|
onSetOutlineDepth?.(sheetId, "column", depth);
|
|
222
246
|
} }, depth)))),
|
|
223
|
-
summaries.map(({ index, startIndex, collapsed, level }) => {
|
|
247
|
+
summaries.map(({ index, startIndex, collapsed, level, showButton, shared }) => {
|
|
224
248
|
// Anchor positions inside the cell area; add `leftInset` so
|
|
225
249
|
// x=0 of the strip lines up with the grid's content origin.
|
|
226
250
|
const buttonX = getColumnOffset(index) - scrollLeft + leftInset;
|
|
@@ -283,41 +307,31 @@ export const ColumnOutlineGutter = memo(({ sheetId, columnMetadata, rowMetadata,
|
|
|
283
307
|
top: lineCenterY + 3,
|
|
284
308
|
} }));
|
|
285
309
|
}))) : null,
|
|
286
|
-
showSummary &&
|
|
287
|
-
? `Expand column group at ${index}`
|
|
288
|
-
: `Collapse column group at ${index}`, size: "xs", variant: "outline", className: "absolute p-0 min-w-0 min-h-0", style: {
|
|
310
|
+
showSummary && showButton ? (React.createElement(Button, { "aria-label": `${collapsed ? "Expand" : "Collapse"} column group at ${index}${shared ? ` level ${level}` : ""}`, size: "xs", variant: "outline", className: "absolute p-0 min-w-0 min-h-0", style: {
|
|
289
311
|
left: buttonX,
|
|
290
312
|
top: y,
|
|
291
313
|
}, onClick: (e) => {
|
|
292
314
|
e.stopPropagation();
|
|
293
315
|
if (collapsed)
|
|
294
|
-
onExpandColumnGroup?.(sheetId, index);
|
|
316
|
+
onExpandColumnGroup?.(sheetId, index, level);
|
|
295
317
|
else
|
|
296
|
-
onCollapseColumnGroup?.(sheetId, index);
|
|
318
|
+
onCollapseColumnGroup?.(sheetId, index, level);
|
|
297
319
|
} }, collapsed ? (React.createElement(PlusIcon, { className: "w-3 h-3" })) : (React.createElement(MinusIcon, { className: "w-3 h-3" })))) : null));
|
|
298
320
|
})));
|
|
299
321
|
});
|
|
300
322
|
ColumnOutlineGutter.displayName = "ColumnOutlineGutter";
|
|
301
|
-
export const RowOutlineGutter = memo(({ sheetId, rowMetadata, summaryBelow = true, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, }) => {
|
|
323
|
+
export const RowOutlineGutter = memo(({ sheetId, rowMetadata, summaryBelow = true, onCollapseRowGroup, onExpandRowGroup, onSetOutlineDepth, defaultRowHeight = DEFAULT_ROW_HEIGHT, columnHeaderHeight = COLUMN_HEADER_HEIGHT, showHeaders = true, scale = 1, }) => {
|
|
302
324
|
const topInset = 0;
|
|
303
325
|
const maxRowOutlineLevel = useMemo(() => computeMaxOutlineLevel(rowMetadata), [rowMetadata]);
|
|
304
|
-
const rowOffsets = useMemo(() => buildOffsetIndex(rowMetadata,
|
|
305
|
-
|
|
326
|
+
const rowOffsets = useMemo(() => buildOffsetIndex(rowMetadata, defaultRowHeight), [rowMetadata, defaultRowHeight]);
|
|
327
|
+
// Same scaling as the column gutter: canvas sizes and scroll are zoomed.
|
|
328
|
+
const headerHeight = showHeaders ? columnHeaderHeight : 0;
|
|
329
|
+
const getRowOffset = useCallback((rowIndex) => (offsetAt(rowOffsets, rowIndex) + headerHeight) * scale, [rowOffsets, headerHeight, scale]);
|
|
306
330
|
const { scrollTop } = useGridScrollPosition();
|
|
307
331
|
const [stripRef, stripRect] = useResizeObserver();
|
|
308
|
-
const summaries = useMemo(() => maxRowOutlineLevel > 0
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const buttonLevelForIndex = useMemo(() => {
|
|
312
|
-
const m = new Map();
|
|
313
|
-
for (const s of summaries) {
|
|
314
|
-
const existing = m.get(s.index);
|
|
315
|
-
if (existing === undefined || s.level < existing) {
|
|
316
|
-
m.set(s.index, s.level);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return m;
|
|
320
|
-
}, [summaries]);
|
|
332
|
+
const summaries = useMemo(() => maxRowOutlineLevel > 0
|
|
333
|
+
? resolveSharedSummaries(findSummaries(rowMetadata, summaryBelow), rowMetadata, summaryBelow)
|
|
334
|
+
: [], [rowMetadata, maxRowOutlineLevel, summaryBelow]);
|
|
321
335
|
if (maxRowOutlineLevel <= 0)
|
|
322
336
|
return null;
|
|
323
337
|
// N+1 level-selector buttons, stacked horizontally at the top of
|
|
@@ -329,14 +343,14 @@ export const RowOutlineGutter = memo(({ sheetId, rowMetadata, summaryBelow = tru
|
|
|
329
343
|
// Summary +/- buttons, the bracket line, and dots all get clipped
|
|
330
344
|
// to this boundary so they never bleed into the level-selector
|
|
331
345
|
// row or the column-header band beside the grid.
|
|
332
|
-
const summaryMinY = topInset +
|
|
346
|
+
const summaryMinY = topInset + headerHeight * scale;
|
|
333
347
|
// Bottom edge of the strip in its own coord space. Anything below
|
|
334
348
|
// it is clipped by `overflow-hidden`, so it is never rendered.
|
|
335
349
|
const viewportMaxY = topInset +
|
|
336
350
|
resolveViewportSize(stripRect.height, typeof window === "undefined" ? undefined : window.innerHeight);
|
|
337
351
|
// Rows intersecting the strip, for the per-row dots.
|
|
338
|
-
const firstVisibleRow = Math.max(1, cellAtOffset(rowOffsets, scrollTop) - OVERSCAN_CELLS);
|
|
339
|
-
const lastVisibleRow = cellAtOffset(rowOffsets, scrollTop + viewportMaxY - summaryMinY) +
|
|
352
|
+
const firstVisibleRow = Math.max(1, cellAtOffset(rowOffsets, scrollTop / scale) - OVERSCAN_CELLS);
|
|
353
|
+
const lastVisibleRow = cellAtOffset(rowOffsets, (scrollTop + viewportMaxY - summaryMinY) / scale) +
|
|
340
354
|
OVERSCAN_CELLS;
|
|
341
355
|
return (React.createElement("div", { ref: stripRef, "data-testid": "row-outline-gutter", className: "bg-rnc-background relative overflow-hidden border-t border-b border-t-rnc-border border-b-rnc-border border-solid border-l-rnc-border border-l border-r-0", style: {
|
|
342
356
|
width: gutterWidth,
|
|
@@ -350,7 +364,7 @@ export const RowOutlineGutter = memo(({ sheetId, rowMetadata, summaryBelow = tru
|
|
|
350
364
|
e.stopPropagation();
|
|
351
365
|
onSetOutlineDepth?.(sheetId, "row", depth);
|
|
352
366
|
} }, depth)))),
|
|
353
|
-
summaries.map(({ index, startIndex, collapsed, level }) => {
|
|
367
|
+
summaries.map(({ index, startIndex, collapsed, level, showButton, shared }) => {
|
|
354
368
|
const buttonY = getRowOffset(index) - scrollTop + topInset;
|
|
355
369
|
const lineStartY = getRowOffset(startIndex) - scrollTop + topInset + 2;
|
|
356
370
|
// The whole group sits below the strip: nothing to paint.
|
|
@@ -407,17 +421,15 @@ export const RowOutlineGutter = memo(({ sheetId, rowMetadata, summaryBelow = tru
|
|
|
407
421
|
top: cy - 1,
|
|
408
422
|
} }));
|
|
409
423
|
}))) : null,
|
|
410
|
-
showSummary &&
|
|
411
|
-
? `Expand row group at ${index}`
|
|
412
|
-
: `Collapse row group at ${index}`, className: "absolute p-0 min-w-0 min-h-0", size: "xs", variant: "outline", style: {
|
|
424
|
+
showSummary && showButton ? (React.createElement(Button, { "aria-label": `${collapsed ? "Expand" : "Collapse"} row group at ${index}${shared ? ` level ${level}` : ""}`, className: "absolute p-0 min-w-0 min-h-0", size: "xs", variant: "outline", style: {
|
|
413
425
|
left: x,
|
|
414
426
|
top: buttonY,
|
|
415
427
|
}, onClick: (e) => {
|
|
416
428
|
e.stopPropagation();
|
|
417
429
|
if (collapsed)
|
|
418
|
-
onExpandRowGroup?.(sheetId, index);
|
|
430
|
+
onExpandRowGroup?.(sheetId, index, level);
|
|
419
431
|
else
|
|
420
|
-
onCollapseRowGroup?.(sheetId, index);
|
|
432
|
+
onCollapseRowGroup?.(sheetId, index, level);
|
|
421
433
|
} }, collapsed ? (React.createElement(PlusIcon, { className: "w-3 h-3" })) : (React.createElement(MinusIcon, { className: "w-3 h-3" })))) : null));
|
|
422
434
|
})));
|
|
423
435
|
});
|