Skip to content

Commit 9619452

Browse files
authored
Merge branch 'main' into fix/scaling-to-root-font-size
2 parents 41b54e0 + 62f422a commit 9619452

20 files changed

+347
-73
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "root",
3-
"version": "6.0.4-alpha10",
3+
"version": "6.0.4-alpha11",
44
"scripts": {
55
"start": "npm run storybook",
66
"version": "./update-version.sh",

packages/cells/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@glideapps/glide-data-grid-cells",
3-
"version": "6.0.4-alpha10",
3+
"version": "6.0.4-alpha11",
44
"description": "Extra cells for glide-data-grid",
55
"sideEffects": [
66
"**/*.css"
@@ -50,7 +50,7 @@
5050
"canvas"
5151
],
5252
"dependencies": {
53-
"@glideapps/glide-data-grid": "6.0.4-alpha10",
53+
"@glideapps/glide-data-grid": "6.0.4-alpha11",
5454
"@linaria/react": "^4.5.4",
5555
"@toast-ui/editor": "3.2.2",
5656
"@toast-ui/react-editor": "3.2.3",

packages/core/API.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ The data grid uses the `Theme` provided to the DataEditer in the `theme` prop. T
371371
| bgHeader | string | --gdg-bg-header | The header background color |
372372
| bgHeaderHasFocus | string | --gdg-bg-header-has | The header background color when its column contains the selected cell |
373373
| bgHeaderHovered | string | --gdg-bg-header-hovered | The header background color when it is hovered |
374+
| bgGroupHeader | string \| undefined | --gdg-bg-group-header | The group header background color, if none provided the `bgHeader` is used instead. |
375+
| bgGroupHeaderHovered | string \| undefined | --gdg-bg-group-header-hovered | The group header background color when it is hovered, if none provided the `bgHeaderHovered` is used instead. |
374376
| bgBubble | string | --gdg-bg-bubble | The background color used in bubbles |
375377
| bgBubbleSelected | string | --gdg-bg-bubble-selected | The background color used in bubbles when the cell is selected |
376378
| bgSearchResult | string | --gdg-bg-search-result | The background color used for cells which match the search string |
@@ -418,7 +420,12 @@ scrollTo: (
418420
row: number,
419421
dir?: "horizontal" | "vertical" | "both",
420422
paddingX?: number,
421-
paddingY?: number
423+
paddingY?: number,
424+
options?: {
425+
hAlign?: "start" | "center" | "end";
426+
vAlign?: "start" | "center" | "end";
427+
behavior?: ScrollBehavior; // "auto" | "smooth" | "instant"
428+
}
422429
) => void;
423430
```
424431

@@ -432,7 +439,11 @@ Requests the data grid to scroll to a particular location. If only one direction
432439
## appendRow
433440

434441
```ts
435-
appendRow: (col: number, openOverlay: boolean = true) => Promise<void>;
442+
appendRow: (
443+
col: number,
444+
openOverlay: boolean = true,
445+
behavior?: ScrollBehavior; // "auto" | "smooth" | "instant"
446+
) => Promise<void>;
436447
```
437448

438449
Appends a row to the data grid.
@@ -729,6 +740,8 @@ drawHeader?: (args: {
729740
theme: Theme;
730741
rect: Rectangle;
731742
hoverAmount: number;
743+
hoverX: number | undefined;
744+
hoverY: number | undefined;
732745
isSelected: boolean;
733746
isHovered: boolean;
734747
hasSelectedCell: boolean;

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@glideapps/glide-data-grid",
3-
"version": "6.0.4-alpha10",
3+
"version": "6.0.4-alpha11",
44
"description": "React data grid for beautifully displaying and editing large amounts of data with amazing performance.",
55
"sideEffects": [
66
"**/*.css"

packages/core/src/common/styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export function makeCSSStyle(theme: Theme): Record<string, string> {
1717
"--gdg-fg-icon-header": theme.fgIconHeader,
1818
"--gdg-text-header": theme.textHeader,
1919
"--gdg-text-group-header": theme.textGroupHeader ?? theme.textHeader,
20+
"--gdg-bg-group-header": theme.bgGroupHeader ?? theme.bgHeader,
21+
"--gdg-bg-group-header-hovered": theme.bgGroupHeaderHovered ?? theme.bgHeaderHovered,
2022
"--gdg-text-header-selected": theme.textHeaderSelected,
2123
"--gdg-bg-cell": theme.bgCell,
2224
"--gdg-bg-cell-medium": theme.bgCellMedium,
@@ -60,6 +62,8 @@ export interface Theme {
6062
fgIconHeader: string;
6163
textHeader: string;
6264
textGroupHeader?: string;
65+
bgGroupHeader?: string;
66+
bgGroupHeaderHovered?: string;
6367
textHeaderSelected: string;
6468
bgCell: string;
6569
bgCellMedium: string;

packages/core/src/data-editor/data-editor.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ type ScrollToFn = (
687687
options?: {
688688
hAlign?: "start" | "center" | "end";
689689
vAlign?: "start" | "center" | "end";
690+
behavior?: ScrollBehavior;
690691
}
691692
) => void;
692693

@@ -697,7 +698,7 @@ export interface DataEditorRef {
697698
* @param col The column index to focus in the new row.
698699
* @returns A promise which waits for the append to complete.
699700
*/
700-
appendRow: (col: number, openOverlay?: boolean) => Promise<void>;
701+
appendRow: (col: number, openOverlay?: boolean, behavior?: ScrollBehavior) => Promise<void>;
701702
/**
702703
* Triggers cells to redraw.
703704
*/
@@ -1611,10 +1612,11 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
16111612
scrollX /= scale;
16121613
scrollY /= scale;
16131614
}
1614-
scrollRef.current.scrollTo(
1615-
scrollX + scrollRef.current.scrollLeft,
1616-
scrollY + scrollRef.current.scrollTop
1617-
);
1615+
scrollRef.current.scrollTo({
1616+
left: scrollX + scrollRef.current.scrollLeft,
1617+
top: scrollY + scrollRef.current.scrollTop,
1618+
behavior: options?.behavior ?? "auto",
1619+
});
16181620
}
16191621
}
16201622
}
@@ -1641,7 +1643,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
16411643
getCellContentRef.current = getCellContent;
16421644
rowsRef.current = rows;
16431645
const appendRow = React.useCallback(
1644-
async (col: number, openOverlay: boolean = true): Promise<void> => {
1646+
async (col: number, openOverlay: boolean = true, behavior?: ScrollBehavior): Promise<void> => {
16451647
const c = mangledCols[col];
16461648
if (c?.trailingRowOptions?.disabled === true) {
16471649
return;
@@ -1667,7 +1669,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
16671669
}
16681670

16691671
const row = typeof r === "number" ? r : bottom ? rows : 0;
1670-
scrollToRef.current(col - rowMarkerOffset, row);
1672+
scrollToRef.current(col - rowMarkerOffset, row, "both", 0, 0, behavior ? { behavior } : undefined);
16711673
setCurrent(
16721674
{
16731675
cell: [col, row],
@@ -3335,6 +3337,9 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
33353337
if (onKeyDownIn !== undefined) {
33363338
onKeyDownIn({
33373339
...event,
3340+
...event.location && {
3341+
location: [event.location[0] - rowMarkerOffset, event.location[1]] as any,
3342+
},
33383343
cancel: () => {
33393344
cancelled = true;
33403345
},

packages/core/src/data-editor/row-grouping-api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import type { Item } from "../internal/data-grid/data-grid-types.js";
3-
import { flattenRowGroups, mapRowIndexToPath, type RowGroup, type RowGroupingOptions } from "./row-grouping.js";
3+
import { flattenRowGroups, mapRowIndexToPath, type RowGroup, type RowGroupingOptions, type MapResult } from "./row-grouping.js";
44

5-
export type RowGroupingMapperResult<T> = {
5+
export interface RowGroupingMapperResult<T> extends Omit<MapResult, 'originalIndex'> {
66
path: readonly number[];
77
originalIndex: T;
88
isGroupHeader: boolean;
99
groupRows: number;
10-
};
10+
}
1111

1212
export type RowGroupingMapper = {
1313
(itemOrRow: number): RowGroupingMapperResult<number>;

packages/core/src/data-editor/row-grouping.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import type { DataEditorProps } from "./data-editor.js";
44
import type { DataGridProps } from "../internal/data-grid/data-grid.js";
55
import { whenDefined } from "../common/utils.js";
66

7+
type Mutable<T> = {
8+
-readonly [K in keyof T]: T[K];
9+
};
10+
711
export type RowGroup = {
812
/**
913
* The index of the header if the groups are all flattened and expanded
@@ -100,6 +104,7 @@ export function expandRowGroups(groups: readonly RowGroup[]): ExpandedRowGroup[]
100104
}
101105

102106
export interface FlattenedRowGroup {
107+
readonly rowIndex: number;
103108
readonly headerIndex: number;
104109
readonly contentIndex: number; // the content index of the first row in the group
105110
readonly isCollapsed: boolean;
@@ -128,6 +133,7 @@ export function flattenRowGroups(rowGrouping: RowGroupingOptions, rows: number):
128133
rowsInGroup--; // the header isn't in the group
129134

130135
flattened.push({
136+
rowIndex: -1, // we will fill this in later
131137
headerIndex: group.headerIndex,
132138
contentIndex: -1, // we will fill this in later
133139
skip: skipChildren,
@@ -153,10 +159,14 @@ export function flattenRowGroups(rowGrouping: RowGroupingOptions, rows: number):
153159
processGroup(expandedGroups[i], nextHeaderIndex);
154160
}
155161

162+
let rowIndex = 0;
156163
let contentIndex = 0;
157-
for (const g of flattened) {
158-
(g as any).contentIndex = contentIndex;
164+
for (const g of flattened as Mutable<(typeof flattened)[number]>[]) {
165+
g.contentIndex = contentIndex;
159166
contentIndex += g.rows;
167+
168+
g.rowIndex = rowIndex;
169+
rowIndex += g.isCollapsed ? 1 : g.rows + 1;
160170
}
161171

162172
return flattened
@@ -167,7 +177,7 @@ export function flattenRowGroups(rowGrouping: RowGroupingOptions, rows: number):
167177
});
168178
}
169179

170-
interface MapResult {
180+
export interface MapResult {
171181
readonly path: readonly number[];
172182
readonly isGroupHeader: boolean;
173183
readonly originalIndex: number;
@@ -199,18 +209,19 @@ export function mapRowIndexToPath(row: number, flattenedRowGroups?: readonly Fla
199209
contentIndex: -1,
200210
groupRows: group.rows,
201211
};
202-
toGo--;
203212
if (!group.isCollapsed) {
204-
if (toGo < group.rows)
213+
if (toGo <= group.rows)
205214
return {
206-
path: [...group.path, toGo],
215+
path: [...group.path, toGo - 1],
207216
originalIndex: group.headerIndex + toGo,
208217
isGroupHeader: false,
209-
groupIndex: toGo,
210-
contentIndex: group.contentIndex + toGo,
218+
groupIndex: toGo - 1,
219+
contentIndex: group.contentIndex + toGo - 1,
211220
groupRows: group.rows,
212221
};
213-
toGo -= group.rows;
222+
toGo = toGo - group.rows - 1;
223+
} else {
224+
toGo--;
214225
}
215226
}
216227
// this shouldn't happen
@@ -244,6 +255,13 @@ export function useRowGroupingInner(
244255
[options, rows]
245256
);
246257

258+
const flattenedRowGroupsMap = React.useMemo(() => {
259+
return flattenedRowGroups?.reduce<{ [rowIndex: number]: FlattenedRowGroup | undefined }>((acc, group) => {
260+
acc[group.rowIndex] = group;
261+
return acc;
262+
}, {});
263+
}, [flattenedRowGroups]);
264+
247265
const effectiveRows = React.useMemo(() => {
248266
if (flattenedRowGroups === undefined) return rows;
249267
return flattenedRowGroups.reduce((acc, group) => acc + (group.isCollapsed ? 1 : group.rows + 1), 0);
@@ -253,11 +271,10 @@ export function useRowGroupingInner(
253271
if (options === undefined) return rowHeightIn;
254272
if (typeof rowHeightIn === "number" && options.height === rowHeightIn) return rowHeightIn;
255273
return (rowIndex: number) => {
256-
const { isGroupHeader } = mapRowIndexToPath(rowIndex, flattenedRowGroups);
257-
if (isGroupHeader) return options.height;
274+
if (flattenedRowGroupsMap?.[rowIndex]) return options.height;
258275
return typeof rowHeightIn === "number" ? rowHeightIn : rowHeightIn(rowIndex);
259276
};
260-
}, [flattenedRowGroups, options, rowHeightIn]);
277+
}, [flattenedRowGroupsMap, options, rowHeightIn]);
261278

262279
const rowNumberMapperOut = React.useCallback(
263280
(row: number): number | undefined => {

packages/core/src/docs/08-theming.stories.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ The global theme is provided by the DataEditor by default and can be overriden b
254254
| bgIconHeader | --gdg-bg-icon-header | string | The background color for header icons |
255255
| fgIconHeader | --gdg-fg-icon-header | string | The foreground color for header icons |
256256
| textHeader | --gdg-text-header | string | The header text color |
257-
| textGroupHeader | --gdg-text-group-header | string \\| undefined | The group header text color, if none provided the \`textHeader\` is used instead. |
257+
| bgGroupHeader | --gdg-bg-group-header | string | The group header background color, if none provided the \`bgHeader\` is used instead. |
258+
| bgGroupHeaderHovered | --gdg-bg-group-header-hovered | string | The group header background color when it is hovered, if none provided the \`bgHeaderHovered\` is used instead. |
259+
| textGroupHeader | --gdg-text-group-header | string | The group header text color, if none provided the \`textHeader\` is used instead. |
258260
| textHeaderSelected | --gdg-text-header-selected | string | The text color used for selected headers |
259261
| bgCell | --gdg-bg-cell | string | The primary background color of the data grid. |
260262
| bgCellMedium | --gdg-bg-cell-medium | string | Used for disabled or otherwise off colored cells. |
@@ -281,10 +283,10 @@ If an option is missing from any theme it will be filled in with the default the
281283
</Marked>
282284
<Highlight>
283285
{`
284-
return <DataEditor
286+
return <DataEditor
285287
theme={{
286288
bgCell: "#F2F9FF"
287-
}}
289+
}}
288290
getCellContent={getContent} columns={columns} rows={data.length} />
289291
`}
290292
</Highlight>
@@ -376,7 +378,7 @@ const getContent = React.useCallback((cell: Item): GridCell => {
376378
textDark: "#FF0000",
377379
}
378380
}
379-
381+
380382
const d = getDataForCell(col, row);
381383
return {
382384
kind: GridCellKind.Text,

0 commit comments

Comments
 (0)