@cognite/aura 1.46385.0 → 1.46447.0
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/components/ui/core/data-grid/data-grid-cell.d.ts +0 -2
- package/dist/components/ui/core/data-grid/data-grid-cell.js +3 -7
- package/dist/components/ui/core/data-grid/data-grid-cell.js.map +1 -1
- package/dist/components/ui/core/data-grid/data-grid-column-resizer.d.ts +8 -0
- package/dist/components/ui/core/data-grid/data-grid-column-resizer.js +24 -0
- package/dist/components/ui/core/data-grid/data-grid-column-resizer.js.map +1 -0
- package/dist/components/ui/core/data-grid/data-grid-header-row.d.ts +3 -4
- package/dist/components/ui/core/data-grid/data-grid-header-row.js +47 -28
- package/dist/components/ui/core/data-grid/data-grid-header-row.js.map +1 -1
- package/dist/components/ui/core/data-grid/data-grid-row.d.ts +1 -4
- package/dist/components/ui/core/data-grid/data-grid-row.js +25 -16
- package/dist/components/ui/core/data-grid/data-grid-row.js.map +1 -1
- package/dist/components/ui/core/data-grid/data-grid-selection-toolbar.d.ts +11 -0
- package/dist/components/ui/core/data-grid/data-grid-selection-toolbar.js +128 -0
- package/dist/components/ui/core/data-grid/data-grid-selection-toolbar.js.map +1 -0
- package/dist/components/ui/core/data-grid/data-grid-selection.types.d.ts +24 -0
- package/dist/components/ui/core/data-grid/data-grid-selection.types.js +3 -0
- package/dist/components/ui/core/data-grid/data-grid-selection.types.js.map +1 -0
- package/dist/components/ui/core/data-grid/data-grid.d.ts +9 -2
- package/dist/components/ui/core/data-grid/data-grid.js +165 -168
- package/dist/components/ui/core/data-grid/data-grid.js.map +1 -1
- package/dist/components/ui/core/data-grid/data-grid.utils.d.ts +1 -4
- package/dist/components/ui/core/data-grid/data-grid.utils.js +5 -38
- package/dist/components/ui/core/data-grid/data-grid.utils.js.map +1 -1
- package/dist/components/ui/core/data-grid/index.d.ts +1 -0
- package/dist/components/ui/core/data-grid/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -3,8 +3,6 @@ type DataGridCellProps = ComponentProps<"div"> & {
|
|
|
3
3
|
isPinned?: boolean;
|
|
4
4
|
isLastPinned?: boolean;
|
|
5
5
|
colIndex?: number;
|
|
6
|
-
textValue?: string;
|
|
7
|
-
truncate?: boolean;
|
|
8
6
|
};
|
|
9
7
|
declare const DataGridCell: ForwardRefExoticComponent<DataGridCellProps & RefAttributes<HTMLDivElement>>;
|
|
10
8
|
export { DataGridCell, type DataGridCellProps };
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cn } from "../../../../lib/utils.js";
|
|
4
|
-
const DataGridCell = /*#__PURE__*/ forwardRef(function DataGridCell({ className, children, isPinned, isLastPinned, colIndex,
|
|
4
|
+
const DataGridCell = /*#__PURE__*/ forwardRef(function DataGridCell({ className, children, isPinned, isLastPinned, colIndex, style, ...props }, ref) {
|
|
5
5
|
return /*#__PURE__*/ _jsx("div", {
|
|
6
6
|
ref: ref,
|
|
7
7
|
"data-slot": "data-grid-cell",
|
|
8
8
|
role: "cell",
|
|
9
9
|
"aria-colindex": colIndex,
|
|
10
|
-
|
|
11
|
-
className: cn('flex items-center pr-3 text-sm font-normal', colIndex === 1 ? 'pl-4' : 'pl-3', 'min-w-0', isPinned && 'sticky z-10 bg-inherit', isLastPinned && 'shadow-pinned-column', className),
|
|
10
|
+
className: cn('flex items-center pr-3 text-sm font-normal', colIndex === 1 ? 'pl-4' : 'pl-3', 'min-w-0 overflow-hidden', isPinned && 'sticky z-10 bg-inherit', isLastPinned && 'shadow-pinned-column', className),
|
|
12
11
|
style: style,
|
|
13
12
|
...props,
|
|
14
|
-
children:
|
|
15
|
-
className: "block min-w-0 flex-1 truncate",
|
|
16
|
-
children: textValue
|
|
17
|
-
}) : children
|
|
13
|
+
children: children
|
|
18
14
|
});
|
|
19
15
|
});
|
|
20
16
|
DataGridCell.displayName = 'DataGridCell';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-cell.tsx"],"sourcesContent":["import {\n type ComponentProps,\n type ComponentRef,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react';\n\nimport { cn } from '../../../../lib/utils';\n\ntype DataGridCellProps = ComponentProps<'div'> & {\n isPinned?: boolean;\n isLastPinned?: boolean;\n colIndex?: number;\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-cell.tsx"],"sourcesContent":["import {\n type ComponentProps,\n type ComponentRef,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react';\n\nimport { cn } from '../../../../lib/utils';\n\ntype DataGridCellProps = ComponentProps<'div'> & {\n isPinned?: boolean;\n isLastPinned?: boolean;\n colIndex?: number;\n};\n\nconst DataGridCell: ForwardRefExoticComponent<\n DataGridCellProps & RefAttributes<HTMLDivElement>\n> = forwardRef<ComponentRef<'div'>, DataGridCellProps>(function DataGridCell(\n { className, children, isPinned, isLastPinned, colIndex, style, ...props },\n ref\n) {\n return (\n <div\n ref={ref}\n data-slot=\"data-grid-cell\"\n role=\"cell\"\n aria-colindex={colIndex}\n className={cn(\n 'flex items-center pr-3 text-sm font-normal',\n colIndex === 1 ? 'pl-4' : 'pl-3',\n 'min-w-0 overflow-hidden',\n isPinned && 'sticky z-10 bg-inherit',\n isLastPinned && 'shadow-pinned-column',\n className\n )}\n style={style}\n {...props}\n >\n {children}\n </div>\n );\n});\nDataGridCell.displayName = 'DataGridCell';\n\nexport { DataGridCell, type DataGridCellProps };\n"],"names":["forwardRef","cn","DataGridCell","className","children","isPinned","isLastPinned","colIndex","style","props","ref","div","data-slot","role","aria-colindex","displayName"],"mappings":";AAAA,SAKEA,UAAU,QACL,QAAQ;AAEf,SAASC,EAAE,QAAQ,2BAAwB;AAQ3C,MAAMC,6BAEFF,WAAmD,SAASE,aAC9D,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGC,OAAO,EAC1EC,GAAG;IAEH,qBACE,KAACC;QACCD,KAAKA;QACLE,aAAU;QACVC,MAAK;QACLC,iBAAeP;QACfJ,WAAWF,GACT,8CACAM,aAAa,IAAI,SAAS,QAC1B,2BACAF,YAAY,0BACZC,gBAAgB,wBAChBH;QAEFK,OAAOA;QACN,GAAGC,KAAK;kBAERL;;AAGP;AACAF,aAAaa,WAAW,GAAG;AAE3B,SAASb,YAAY,GAA2B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { Header } from "@tanstack/react-table";
|
|
3
|
+
type DataGridColumnResizerProps<TData> = {
|
|
4
|
+
header: Header<TData, unknown>;
|
|
5
|
+
columnLabel: string;
|
|
6
|
+
};
|
|
7
|
+
declare function DataGridColumnResizer<TData>({ header, columnLabel }: DataGridColumnResizerProps<TData>): ReactElement;
|
|
8
|
+
export { DataGridColumnResizer, type DataGridColumnResizerProps };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../../../lib/utils.js";
|
|
3
|
+
function DataGridColumnResizer({ header, columnLabel }) {
|
|
4
|
+
const isResizing = header.column.getIsResizing();
|
|
5
|
+
const resizeHandler = header.getResizeHandler();
|
|
6
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
7
|
+
role: "separator",
|
|
8
|
+
"aria-orientation": "vertical",
|
|
9
|
+
"aria-label": `Resize ${columnLabel}`,
|
|
10
|
+
"data-slot": "data-grid-column-resizer",
|
|
11
|
+
"data-resizing": isResizing ? '' : undefined,
|
|
12
|
+
className: cn('absolute top-0 right-0 z-20 h-full w-2', 'cursor-col-resize touch-none select-none', 'opacity-0', 'group-hover/header:opacity-100 data-resizing:opacity-100', 'before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border'),
|
|
13
|
+
onMouseDown: resizeHandler,
|
|
14
|
+
onTouchStart: resizeHandler,
|
|
15
|
+
onClick: (event)=>event.stopPropagation(),
|
|
16
|
+
onDoubleClick: (event)=>{
|
|
17
|
+
event.stopPropagation();
|
|
18
|
+
header.column.resetSize();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { DataGridColumnResizer };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=data-grid-column-resizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-column-resizer.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\n\nimport type { Header } from '@tanstack/react-table';\n\nimport { cn } from '../../../../lib/utils';\n\ntype DataGridColumnResizerProps<TData> = {\n header: Header<TData, unknown>;\n columnLabel: string;\n};\n\nfunction DataGridColumnResizer<TData>({\n header,\n columnLabel,\n}: DataGridColumnResizerProps<TData>): ReactElement {\n const isResizing = header.column.getIsResizing();\n const resizeHandler = header.getResizeHandler();\n\n return (\n <div\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={`Resize ${columnLabel}`}\n data-slot=\"data-grid-column-resizer\"\n data-resizing={isResizing ? '' : undefined}\n className={cn(\n 'absolute top-0 right-0 z-20 h-full w-2',\n 'cursor-col-resize touch-none select-none',\n 'opacity-0',\n 'group-hover/header:opacity-100 data-resizing:opacity-100',\n 'before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border'\n )}\n onMouseDown={resizeHandler}\n onTouchStart={resizeHandler}\n onClick={(event) => event.stopPropagation()}\n onDoubleClick={(event) => {\n event.stopPropagation();\n header.column.resetSize();\n }}\n />\n );\n}\n\nexport { DataGridColumnResizer, type DataGridColumnResizerProps };\n"],"names":["cn","DataGridColumnResizer","header","columnLabel","isResizing","column","getIsResizing","resizeHandler","getResizeHandler","div","role","aria-orientation","aria-label","data-slot","data-resizing","undefined","className","onMouseDown","onTouchStart","onClick","event","stopPropagation","onDoubleClick","resetSize"],"mappings":";AAIA,SAASA,EAAE,QAAQ,2BAAwB;AAO3C,SAASC,sBAA6B,EACpCC,MAAM,EACNC,WAAW,EACuB;IAClC,MAAMC,aAAaF,OAAOG,MAAM,CAACC,aAAa;IAC9C,MAAMC,gBAAgBL,OAAOM,gBAAgB;IAE7C,qBACE,KAACC;QACCC,MAAK;QACLC,oBAAiB;QACjBC,cAAY,CAAC,OAAO,EAAET,aAAa;QACnCU,aAAU;QACVC,iBAAeV,aAAa,KAAKW;QACjCC,WAAWhB,GACT,0CACA,4CACA,aACA,4DACA;QAEFiB,aAAaV;QACbW,cAAcX;QACdY,SAAS,CAACC,QAAUA,MAAMC,eAAe;QACzCC,eAAe,CAACF;YACdA,MAAMC,eAAe;YACrBnB,OAAOG,MAAM,CAACkB,SAAS;QACzB;;AAGN;AAEA,SAAStB,qBAAqB,GAAoC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
2
|
import { type HeaderGroup } from "@tanstack/react-table";
|
|
3
3
|
type DataGridHeaderRowProps<TData> = {
|
|
4
4
|
headerGroup: HeaderGroup<TData>;
|
|
5
5
|
headerRowIndex: number;
|
|
6
6
|
resolvedHeaderHeight: number;
|
|
7
|
-
gridTemplateColumns: string;
|
|
8
7
|
pinnedColumnIds: Set<string>;
|
|
9
8
|
lastPinnedColumnId: string | undefined;
|
|
10
|
-
|
|
9
|
+
isResizingColumn: boolean;
|
|
11
10
|
};
|
|
12
|
-
declare function DataGridHeaderRow<TData>({ headerGroup, headerRowIndex, resolvedHeaderHeight,
|
|
11
|
+
declare function DataGridHeaderRow<TData>({ headerGroup, headerRowIndex, resolvedHeaderHeight, pinnedColumnIds, lastPinnedColumnId, isResizingColumn }: DataGridHeaderRowProps<TData>): ReactElement;
|
|
13
12
|
export { DataGridHeaderRow, type DataGridHeaderRowProps };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { IconArrowDown, IconSelector } from "@tabler/icons-react";
|
|
3
4
|
import { flexRender } from "@tanstack/react-table";
|
|
4
5
|
import { cn, focusState } from "../../../../lib/utils.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
6
|
+
import { DataGridColumnResizer } from "./data-grid-column-resizer.js";
|
|
7
|
+
import { PINNED_COLUMN_Z_INDEX, getAriaSort } from "./data-grid.utils.js";
|
|
8
|
+
function DataGridHeaderRow({ headerGroup, headerRowIndex, resolvedHeaderHeight, pinnedColumnIds, lastPinnedColumnId, isResizingColumn }) {
|
|
9
|
+
const headerRowInstanceId = useId();
|
|
7
10
|
return /*#__PURE__*/ _jsx("div", {
|
|
8
11
|
"data-slot": "data-grid-header-row",
|
|
9
12
|
role: "row",
|
|
@@ -11,7 +14,7 @@ function DataGridHeaderRow({ headerGroup, headerRowIndex, resolvedHeaderHeight,
|
|
|
11
14
|
className: cn('sticky z-20 grid bg-background', headerRowIndex === 0 ? 'border-y' : 'border-b'),
|
|
12
15
|
style: {
|
|
13
16
|
top: headerRowIndex * resolvedHeaderHeight,
|
|
14
|
-
gridTemplateColumns,
|
|
17
|
+
gridTemplateColumns: 'var(--data-grid-template-columns)',
|
|
15
18
|
minHeight: resolvedHeaderHeight
|
|
16
19
|
},
|
|
17
20
|
children: headerGroup.headers.map((header)=>{
|
|
@@ -23,40 +26,56 @@ function DataGridHeaderRow({ headerGroup, headerRowIndex, resolvedHeaderHeight,
|
|
|
23
26
|
const isGroupedHeader = header.colSpan > 1;
|
|
24
27
|
const renderedHeader = header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext());
|
|
25
28
|
const isPlainTextHeader = typeof renderedHeader === 'string' || typeof renderedHeader === 'number';
|
|
26
|
-
|
|
29
|
+
const showResizer = isLeafHeader && header.column.getCanResize();
|
|
30
|
+
const isResizing = showResizer && header.column.getIsResizing();
|
|
31
|
+
const headerTitleId = `${headerRowInstanceId}-${header.id}-title`;
|
|
32
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
27
33
|
"data-slot": "data-grid-column-header",
|
|
28
34
|
role: "columnheader",
|
|
29
35
|
"aria-colindex": header.index + 1,
|
|
30
36
|
"aria-colspan": header.colSpan > 1 ? header.colSpan : undefined,
|
|
31
37
|
"aria-sort": getAriaSort(sortDirection, canSort),
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
"aria-labelledby": showResizer ? headerTitleId : undefined,
|
|
39
|
+
className: cn('group/header relative flex min-w-0 items-center overflow-hidden pr-3 text-left text-sm font-medium text-muted-foreground', header.index === 0 ? 'pl-4' : 'pl-3', isGroupedHeader && 'justify-center text-base font-semibold text-foreground/70', header.isPlaceholder && 'pointer-events-none', isPinned && 'sticky left-0 z-10 bg-background', isLastPinned && 'shadow-pinned-column', (canSort || showResizer) && !isResizingColumn && 'hover:bg-medium-background-hover', isResizing && 'bg-medium-background-hover'),
|
|
34
40
|
style: {
|
|
35
41
|
gridColumn: `span ${header.colSpan} / span ${header.colSpan}`,
|
|
36
|
-
...
|
|
42
|
+
...isPinned ? {
|
|
43
|
+
position: 'sticky',
|
|
44
|
+
left: header.column.getStart('left'),
|
|
45
|
+
zIndex: PINNED_COLUMN_Z_INDEX
|
|
46
|
+
} : {}
|
|
37
47
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
children: [
|
|
49
|
+
/*#__PURE__*/ _jsx("div", {
|
|
50
|
+
id: showResizer ? headerTitleId : undefined,
|
|
51
|
+
className: "flex min-w-0 items-center",
|
|
52
|
+
children: canSort ? /*#__PURE__*/ _jsxs("button", {
|
|
53
|
+
type: "button",
|
|
54
|
+
className: cn('group/sort inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1 rounded-sm select-none', focusState),
|
|
55
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
56
|
+
children: [
|
|
57
|
+
isPlainTextHeader ? /*#__PURE__*/ _jsx("span", {
|
|
58
|
+
className: "block min-w-0 truncate",
|
|
59
|
+
children: renderedHeader
|
|
60
|
+
}) : renderedHeader,
|
|
61
|
+
sortDirection ? /*#__PURE__*/ _jsx(IconArrowDown, {
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
className: cn('size-3.5 shrink-0', sortDirection === 'asc' && 'rotate-180')
|
|
64
|
+
}) : /*#__PURE__*/ _jsx(IconSelector, {
|
|
65
|
+
"aria-hidden": "true",
|
|
66
|
+
className: "size-3.5 shrink-0 opacity-30 group-hover/header:opacity-100 group-focus-visible/sort:opacity-100"
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
}) : isPlainTextHeader ? /*#__PURE__*/ _jsx("span", {
|
|
48
70
|
className: "block min-w-0 truncate",
|
|
49
71
|
children: renderedHeader
|
|
50
|
-
}) : renderedHeader
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
]
|
|
59
|
-
})
|
|
72
|
+
}) : renderedHeader
|
|
73
|
+
}),
|
|
74
|
+
showResizer && /*#__PURE__*/ _jsx(DataGridColumnResizer, {
|
|
75
|
+
header: header,
|
|
76
|
+
columnLabel: isPlainTextHeader ? String(renderedHeader) : header.column.id
|
|
77
|
+
})
|
|
78
|
+
]
|
|
60
79
|
}, header.id);
|
|
61
80
|
})
|
|
62
81
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-header-row.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-header-row.tsx"],"sourcesContent":["import { type ReactElement, useId } from 'react';\n\nimport { IconArrowDown, IconSelector } from '@tabler/icons-react';\nimport { type HeaderGroup, flexRender } from '@tanstack/react-table';\n\nimport { cn, focusState } from '../../../../lib/utils';\n\nimport { DataGridColumnResizer } from './data-grid-column-resizer';\nimport { PINNED_COLUMN_Z_INDEX, getAriaSort } from './data-grid.utils';\n\ntype DataGridHeaderRowProps<TData> = {\n headerGroup: HeaderGroup<TData>;\n headerRowIndex: number;\n resolvedHeaderHeight: number;\n pinnedColumnIds: Set<string>;\n lastPinnedColumnId: string | undefined;\n isResizingColumn: boolean;\n};\n\nfunction DataGridHeaderRow<TData>({\n headerGroup,\n headerRowIndex,\n resolvedHeaderHeight,\n pinnedColumnIds,\n lastPinnedColumnId,\n isResizingColumn,\n}: DataGridHeaderRowProps<TData>): ReactElement {\n const headerRowInstanceId = useId();\n\n return (\n <div\n data-slot=\"data-grid-header-row\"\n role=\"row\"\n aria-rowindex={headerRowIndex + 1}\n className={cn(\n 'sticky z-20 grid bg-background',\n headerRowIndex === 0 ? 'border-y' : 'border-b'\n )}\n style={{\n top: headerRowIndex * resolvedHeaderHeight,\n gridTemplateColumns: 'var(--data-grid-template-columns)',\n minHeight: resolvedHeaderHeight,\n }}\n >\n {headerGroup.headers.map((header) => {\n const isLeafHeader = header.colSpan === 1;\n const isPinned = isLeafHeader && pinnedColumnIds.has(header.column.id);\n const isLastPinned =\n isPinned && lastPinnedColumnId === header.column.id;\n const sortDirection = header.column.getIsSorted();\n const canSort = isLeafHeader && header.column.getCanSort();\n const isGroupedHeader = header.colSpan > 1;\n const renderedHeader = header.isPlaceholder\n ? null\n : flexRender(header.column.columnDef.header, header.getContext());\n const isPlainTextHeader =\n typeof renderedHeader === 'string' ||\n typeof renderedHeader === 'number';\n const showResizer = isLeafHeader && header.column.getCanResize();\n const isResizing = showResizer && header.column.getIsResizing();\n const headerTitleId = `${headerRowInstanceId}-${header.id}-title`;\n\n return (\n <div\n key={header.id}\n data-slot=\"data-grid-column-header\"\n role=\"columnheader\"\n aria-colindex={header.index + 1}\n aria-colspan={header.colSpan > 1 ? header.colSpan : undefined}\n aria-sort={getAriaSort(sortDirection, canSort)}\n aria-labelledby={showResizer ? headerTitleId : undefined}\n className={cn(\n 'group/header relative flex min-w-0 items-center overflow-hidden pr-3 text-left text-sm font-medium text-muted-foreground',\n header.index === 0 ? 'pl-4' : 'pl-3',\n isGroupedHeader &&\n 'justify-center text-base font-semibold text-foreground/70',\n header.isPlaceholder && 'pointer-events-none',\n isPinned && 'sticky left-0 z-10 bg-background',\n isLastPinned && 'shadow-pinned-column',\n (canSort || showResizer) &&\n !isResizingColumn &&\n 'hover:bg-medium-background-hover',\n isResizing && 'bg-medium-background-hover'\n )}\n style={{\n gridColumn: `span ${header.colSpan} / span ${header.colSpan}`,\n ...(isPinned\n ? {\n position: 'sticky',\n left: header.column.getStart('left'),\n zIndex: PINNED_COLUMN_Z_INDEX,\n }\n : {}),\n }}\n >\n <div\n id={showResizer ? headerTitleId : undefined}\n className=\"flex min-w-0 items-center\"\n >\n {canSort ? (\n <button\n type=\"button\"\n className={cn(\n 'group/sort inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1 rounded-sm select-none',\n focusState\n )}\n onClick={header.column.getToggleSortingHandler()}\n >\n {isPlainTextHeader ? (\n <span className=\"block min-w-0 truncate\">\n {renderedHeader}\n </span>\n ) : (\n renderedHeader\n )}\n {sortDirection ? (\n <IconArrowDown\n aria-hidden=\"true\"\n className={cn(\n 'size-3.5 shrink-0',\n sortDirection === 'asc' && 'rotate-180'\n )}\n />\n ) : (\n <IconSelector\n aria-hidden=\"true\"\n className=\"size-3.5 shrink-0 opacity-30 group-hover/header:opacity-100 group-focus-visible/sort:opacity-100\"\n />\n )}\n </button>\n ) : isPlainTextHeader ? (\n <span className=\"block min-w-0 truncate\">{renderedHeader}</span>\n ) : (\n renderedHeader\n )}\n </div>\n {showResizer && (\n <DataGridColumnResizer\n header={header}\n columnLabel={\n isPlainTextHeader ? String(renderedHeader) : header.column.id\n }\n />\n )}\n </div>\n );\n })}\n </div>\n );\n}\n\nexport { DataGridHeaderRow, type DataGridHeaderRowProps };\n"],"names":["useId","IconArrowDown","IconSelector","flexRender","cn","focusState","DataGridColumnResizer","PINNED_COLUMN_Z_INDEX","getAriaSort","DataGridHeaderRow","headerGroup","headerRowIndex","resolvedHeaderHeight","pinnedColumnIds","lastPinnedColumnId","isResizingColumn","headerRowInstanceId","div","data-slot","role","aria-rowindex","className","style","top","gridTemplateColumns","minHeight","headers","map","header","isLeafHeader","colSpan","isPinned","has","column","id","isLastPinned","sortDirection","getIsSorted","canSort","getCanSort","isGroupedHeader","renderedHeader","isPlaceholder","columnDef","getContext","isPlainTextHeader","showResizer","getCanResize","isResizing","getIsResizing","headerTitleId","aria-colindex","index","aria-colspan","undefined","aria-sort","aria-labelledby","gridColumn","position","left","getStart","zIndex","button","type","onClick","getToggleSortingHandler","span","aria-hidden","columnLabel","String"],"mappings":";AAAA,SAA4BA,KAAK,QAAQ,QAAQ;AAEjD,SAASC,aAAa,EAAEC,YAAY,QAAQ,sBAAsB;AAClE,SAA2BC,UAAU,QAAQ,wBAAwB;AAErE,SAASC,EAAE,EAAEC,UAAU,QAAQ,2BAAwB;AAEvD,SAASC,qBAAqB,QAAQ,gCAA6B;AACnE,SAASC,qBAAqB,EAAEC,WAAW,QAAQ,uBAAoB;AAWvE,SAASC,kBAAyB,EAChCC,WAAW,EACXC,cAAc,EACdC,oBAAoB,EACpBC,eAAe,EACfC,kBAAkB,EAClBC,gBAAgB,EACc;IAC9B,MAAMC,sBAAsBhB;IAE5B,qBACE,KAACiB;QACCC,aAAU;QACVC,MAAK;QACLC,iBAAeT,iBAAiB;QAChCU,WAAWjB,GACT,kCACAO,mBAAmB,IAAI,aAAa;QAEtCW,OAAO;YACLC,KAAKZ,iBAAiBC;YACtBY,qBAAqB;YACrBC,WAAWb;QACb;kBAECF,YAAYgB,OAAO,CAACC,GAAG,CAAC,CAACC;YACxB,MAAMC,eAAeD,OAAOE,OAAO,KAAK;YACx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VC,MAAM/B,OAAOK,MAAM,CAAC2B,QAAQ,CAAC;wBAC7BC,QAAQtD;oBACV,IACA,CAAC,CAAC;gBACR;;kCAEA,KAACU;wBACCiB,IAAIY,cAAcI,gBAAgBI;wBAClCjC,WAAU;kCAETiB,wBACC,MAACwB;4BACCC,MAAK;4BACL1C,WAAWjB,GACT,sGACAC;4BAEF2D,SAASpC,OAAOK,MAAM,CAACgC,uBAAuB;;gCAE7CpB,kCACC,KAACqB;oCAAK7C,WAAU;8CACboB;qCAGHA;gCAEDL,8BACC,KAACnC;oCACCkE,eAAY;oCACZ9C,WAAWjB,GACT,qBACAgC,kBAAkB,SAAS;mDAI/B,KAAClC;oCACCiE,eAAY;oCACZ9C,WAAU;;;6BAIdwB,kCACF,KAACqB;4BAAK7C,WAAU;sCAA0BoB;6BAE1CA;;oBAGHK,6BACC,KAACxC;wBACCsB,QAAQA;wBACRwC,aACEvB,oBAAoBwB,OAAO5B,kBAAkBb,OAAOK,MAAM,CAACC,EAAE;;;eA5E9DN,OAAOM,EAAE;QAkFpB;;AAGN;AAEA,SAASzB,iBAAiB,GAAgC"}
|
|
@@ -5,14 +5,11 @@ type DataGridRowProps<TData> = {
|
|
|
5
5
|
row: Row<TData>;
|
|
6
6
|
virtualRow: VirtualItem;
|
|
7
7
|
headerGroupCount: number;
|
|
8
|
-
gridTemplateColumns: string;
|
|
9
8
|
pinnedColumnIds: Set<string>;
|
|
10
9
|
lastPinnedColumnId: string | undefined;
|
|
11
|
-
pinnedLeftByColumnId: Map<string, number>;
|
|
12
|
-
customCellColumnIds: Set<string>;
|
|
13
10
|
maxDepth: number;
|
|
14
11
|
hasExpanding: boolean;
|
|
15
12
|
onRowClick?: (row: Row<TData>) => void;
|
|
16
13
|
};
|
|
17
|
-
declare function DataGridRow<TData>({ row, virtualRow, headerGroupCount,
|
|
14
|
+
declare function DataGridRow<TData>({ row, virtualRow, headerGroupCount, pinnedColumnIds, lastPinnedColumnId, maxDepth, hasExpanding, onRowClick }: DataGridRowProps<TData>): ReactElement;
|
|
18
15
|
export { DataGridRow, type DataGridRowProps };
|
|
@@ -5,8 +5,8 @@ import { cn, focusState } from "../../../../lib/utils.js";
|
|
|
5
5
|
import { Button } from "../button/button.js";
|
|
6
6
|
import { DataGridCell } from "./data-grid-cell.js";
|
|
7
7
|
import { isDataGridRowHighlighted } from "./data-grid-selection-state.js";
|
|
8
|
-
import {
|
|
9
|
-
function DataGridRow({ row, virtualRow, headerGroupCount,
|
|
8
|
+
import { PINNED_COLUMN_Z_INDEX, getTextValue, isAccessorColumn, isFromExpandToggleTarget, isFromIgnoredCellTarget } from "./data-grid.utils.js";
|
|
9
|
+
function DataGridRow({ row, virtualRow, headerGroupCount, pinnedColumnIds, lastPinnedColumnId, maxDepth, hasExpanding, onRowClick }) {
|
|
10
10
|
const canExpand = row.getCanExpand();
|
|
11
11
|
const isRowInteractive = onRowClick !== undefined;
|
|
12
12
|
const isHighlighted = isDataGridRowHighlighted(row);
|
|
@@ -26,7 +26,7 @@ function DataGridRow({ row, virtualRow, headerGroupCount, gridTemplateColumns, p
|
|
|
26
26
|
"aria-selected": row.getIsSelected() ? true : undefined,
|
|
27
27
|
className: cn('group absolute left-0 right-0 grid border-b bg-background transition-colors', 'hover:bg-active-muted-background', isHighlighted && 'bg-medium-background hover:bg-medium-background-hover', isRowInteractive && cn('cursor-pointer focus-visible:bg-active-muted-background', focusState)),
|
|
28
28
|
style: {
|
|
29
|
-
gridTemplateColumns,
|
|
29
|
+
gridTemplateColumns: 'var(--data-grid-template-columns)',
|
|
30
30
|
height: virtualRow.size,
|
|
31
31
|
transform: `translateY(${virtualRow.start}px)`
|
|
32
32
|
},
|
|
@@ -42,31 +42,39 @@ function DataGridRow({ row, virtualRow, headerGroupCount, gridTemplateColumns, p
|
|
|
42
42
|
children: visibleCells.map((cell, cellIndex)=>{
|
|
43
43
|
const isPinned = pinnedColumnIds.has(cell.column.id);
|
|
44
44
|
const isLastPinned = isPinned && lastPinnedColumnId === cell.column.id;
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const cellContext = cell.getContext();
|
|
46
|
+
const cellRenderer = cell.column.columnDef.cell;
|
|
47
|
+
let renderedCell;
|
|
48
|
+
let cellTitle;
|
|
49
|
+
if (typeof cellRenderer === 'function') {
|
|
50
|
+
const cellContent = cellRenderer(cellContext);
|
|
51
|
+
cellTitle = getTextValue(cellContent);
|
|
52
|
+
renderedCell = cellContent;
|
|
53
|
+
} else {
|
|
54
|
+
renderedCell = flexRender(cellRenderer, cellContext);
|
|
55
|
+
cellTitle = getTextValue(renderedCell);
|
|
56
|
+
}
|
|
50
57
|
const isTreeColumn = cellIndex === treeColumnIndex;
|
|
51
58
|
const depth = Math.min(row.depth, maxDepth);
|
|
52
59
|
const indentPx = isTreeColumn && depth > 0 ? depth * 16 : 0;
|
|
53
60
|
const showChevron = isTreeColumn && canExpand;
|
|
54
61
|
const showChevronSpacer = isTreeColumn && hasExpanding && !canExpand && depth > 0;
|
|
55
|
-
const pinnedStyle =
|
|
62
|
+
const pinnedStyle = isPinned ? {
|
|
63
|
+
position: 'sticky',
|
|
64
|
+
left: cell.column.getStart('left'),
|
|
65
|
+
zIndex: PINNED_COLUMN_Z_INDEX
|
|
66
|
+
} : undefined;
|
|
56
67
|
const cellStyle = indentPx > 0 || pinnedStyle ? {
|
|
57
68
|
...pinnedStyle,
|
|
58
69
|
...indentPx > 0 ? {
|
|
59
70
|
paddingInlineStart: `${indentPx + 12}px`
|
|
60
71
|
} : {}
|
|
61
72
|
} : undefined;
|
|
62
|
-
const needsTreeIndicator = showChevron || showChevronSpacer;
|
|
63
73
|
return /*#__PURE__*/ _jsxs(DataGridCell, {
|
|
64
74
|
"data-row-activation": isAccessorColumn(cell.column.columnDef) ? undefined : 'ignore',
|
|
65
75
|
isPinned: isPinned,
|
|
66
76
|
isLastPinned: isLastPinned,
|
|
67
77
|
colIndex: cellIndex + 1,
|
|
68
|
-
textValue: textValue,
|
|
69
|
-
truncate: needsTreeIndicator ? false : textValue !== undefined,
|
|
70
78
|
style: cellStyle,
|
|
71
79
|
children: [
|
|
72
80
|
showChevron && /*#__PURE__*/ _jsx(Button, {
|
|
@@ -90,10 +98,11 @@ function DataGridRow({ row, virtualRow, headerGroupCount, gridTemplateColumns, p
|
|
|
90
98
|
className: "mr-2 inline-block h-7 w-7 shrink-0",
|
|
91
99
|
"aria-hidden": "true"
|
|
92
100
|
}),
|
|
93
|
-
|
|
94
|
-
className: "block min-w-0 flex-1 truncate",
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
/*#__PURE__*/ _jsx("span", {
|
|
102
|
+
className: "block min-w-0 flex-1 not-has-[*]:truncate",
|
|
103
|
+
title: cellTitle,
|
|
104
|
+
children: renderedCell
|
|
105
|
+
})
|
|
97
106
|
]
|
|
98
107
|
}, cell.id);
|
|
99
108
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-row.tsx"],"sourcesContent":["import type {\n CSSProperties,\n KeyboardEvent,\n MouseEvent,\n ReactElement,\n} from 'react';\n\nimport { IconChevronRight } from '@tabler/icons-react';\nimport { type Cell, type Row, flexRender } from '@tanstack/react-table';\nimport type { VirtualItem } from '@tanstack/react-virtual';\n\nimport { cn, focusState } from '../../../../lib/utils';\nimport { Button } from '../button/button';\n\nimport { DataGridCell } from './data-grid-cell';\nimport { isDataGridRowHighlighted } from './data-grid-selection-state';\nimport {\n getPinnedColumnStyle,\n getTextValue,\n isAccessorColumn,\n isFromExpandToggleTarget,\n isFromIgnoredCellTarget,\n} from './data-grid.utils';\n\ntype DataGridRowProps<TData> = {\n row: Row<TData>;\n virtualRow: VirtualItem;\n headerGroupCount: number;\n gridTemplateColumns: string;\n pinnedColumnIds: Set<string>;\n lastPinnedColumnId: string | undefined;\n pinnedLeftByColumnId: Map<string, number>;\n customCellColumnIds: Set<string>;\n maxDepth: number;\n hasExpanding: boolean;\n onRowClick?: (row: Row<TData>) => void;\n};\n\nfunction DataGridRow<TData>({\n row,\n virtualRow,\n headerGroupCount,\n gridTemplateColumns,\n pinnedColumnIds,\n lastPinnedColumnId,\n pinnedLeftByColumnId,\n customCellColumnIds,\n maxDepth,\n hasExpanding,\n onRowClick,\n}: DataGridRowProps<TData>): ReactElement {\n const canExpand = row.getCanExpand();\n const isRowInteractive = onRowClick !== undefined;\n const isHighlighted = isDataGridRowHighlighted(row);\n\n const handleRowActivation = isRowInteractive\n ? (triggerTarget?: EventTarget | null) => {\n if (isFromIgnoredCellTarget(triggerTarget)) return;\n if (isFromExpandToggleTarget(triggerTarget)) return;\n onRowClick?.(row);\n }\n : undefined;\n\n const visibleCells = row.getVisibleCells();\n const resolvedTreeColumnIndex = visibleCells.findIndex((cell) =>\n isAccessorColumn(cell.column.columnDef)\n );\n const treeColumnIndex =\n resolvedTreeColumnIndex >= 0 ? resolvedTreeColumnIndex : 0;\n\n return (\n <div\n data-slot=\"data-grid-row\"\n role=\"row\"\n aria-rowindex={virtualRow.index + 1 + headerGroupCount}\n aria-expanded={canExpand ? row.getIsExpanded() : undefined}\n aria-selected={row.getIsSelected() ? true : undefined}\n className={cn(\n 'group absolute left-0 right-0 grid border-b bg-background transition-colors',\n 'hover:bg-active-muted-background',\n isHighlighted &&\n 'bg-medium-background hover:bg-medium-background-hover',\n isRowInteractive &&\n cn(\n 'cursor-pointer focus-visible:bg-active-muted-background',\n focusState\n )\n )}\n style={{\n gridTemplateColumns,\n height: virtualRow.size,\n transform: `translateY(${virtualRow.start}px)`,\n }}\n tabIndex={isRowInteractive ? 0 : undefined}\n onClick={\n handleRowActivation\n ? (event: MouseEvent<HTMLDivElement>) =>\n handleRowActivation(event.target)\n : undefined\n }\n onKeyDown={\n handleRowActivation\n ? (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n if (isFromIgnoredCellTarget(event.target)) return;\n if (isFromExpandToggleTarget(event.target)) return;\n event.preventDefault();\n handleRowActivation(event.target);\n }\n : undefined\n }\n >\n {visibleCells.map((cell: Cell<TData, unknown>, cellIndex: number) => {\n const isPinned = pinnedColumnIds.has(cell.column.id);\n const isLastPinned = isPinned && lastPinnedColumnId === cell.column.id;\n const renderedCell = flexRender(\n cell.column.columnDef.cell,\n cell.getContext()\n );\n const hasCustomCellRenderer = customCellColumnIds.has(cell.column.id);\n const renderedTextValue = getTextValue(renderedCell);\n const rawTextValue = getTextValue(cell.getValue());\n const textValue =\n renderedTextValue ??\n (!hasCustomCellRenderer ? rawTextValue : undefined);\n\n const isTreeColumn = cellIndex === treeColumnIndex;\n const depth = Math.min(row.depth, maxDepth);\n const indentPx = isTreeColumn && depth > 0 ? depth * 16 : 0;\n const showChevron = isTreeColumn && canExpand;\n const showChevronSpacer =\n isTreeColumn && hasExpanding && !canExpand && depth > 0;\n\n const pinnedStyle = getPinnedColumnStyle(\n isPinned,\n cell.column.id,\n pinnedLeftByColumnId\n );\n\n const cellStyle: CSSProperties | undefined =\n indentPx > 0 || pinnedStyle\n ? {\n ...pinnedStyle,\n ...(indentPx > 0\n ? { paddingInlineStart: `${indentPx + 12}px` }\n : {}),\n }\n : undefined;\n\n const needsTreeIndicator = showChevron || showChevronSpacer;\n\n return (\n <DataGridCell\n key={cell.id}\n data-row-activation={\n isAccessorColumn(cell.column.columnDef) ? undefined : 'ignore'\n }\n isPinned={isPinned}\n isLastPinned={isLastPinned}\n colIndex={cellIndex + 1}\n textValue={textValue}\n truncate={needsTreeIndicator ? false : textValue !== undefined}\n style={cellStyle}\n >\n {showChevron && (\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className=\"mr-2\"\n data-row-expand-toggle=\"true\"\n onClick={(event: MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n row.toggleExpanded();\n }}\n aria-label={row.getIsExpanded() ? 'Collapse row' : 'Expand row'}\n >\n <IconChevronRight\n width={5}\n height={8}\n className={cn(row.getIsExpanded() && 'rotate-90')}\n aria-hidden=\"true\"\n />\n </Button>\n )}\n {showChevronSpacer && (\n <span\n className=\"mr-2 inline-block h-7 w-7 shrink-0\"\n aria-hidden=\"true\"\n />\n )}\n {needsTreeIndicator && textValue !== undefined ? (\n <span className=\"block min-w-0 flex-1 truncate\">{textValue}</span>\n ) : (\n renderedCell\n )}\n </DataGridCell>\n );\n })}\n </div>\n );\n}\n\nexport { DataGridRow, type DataGridRowProps };\n"],"names":["IconChevronRight","flexRender","cn","focusState","Button","DataGridCell","isDataGridRowHighlighted","getPinnedColumnStyle","getTextValue","isAccessorColumn","isFromExpandToggleTarget","isFromIgnoredCellTarget","DataGridRow","row","virtualRow","headerGroupCount","gridTemplateColumns","pinnedColumnIds","lastPinnedColumnId","pinnedLeftByColumnId","customCellColumnIds","maxDepth","hasExpanding","onRowClick","canExpand","getCanExpand","isRowInteractive","undefined","isHighlighted","handleRowActivation","triggerTarget","visibleCells","getVisibleCells","resolvedTreeColumnIndex","findIndex","cell","column","columnDef","treeColumnIndex","div","data-slot","role","aria-rowindex","index","aria-expanded","getIsExpanded","aria-selected","getIsSelected","className","style","height","size","transform","start","tabIndex","onClick","event","target","onKeyDown","key","preventDefault","map","cellIndex","isPinned","has","id","isLastPinned","renderedCell","getContext","hasCustomCellRenderer","renderedTextValue","rawTextValue","getValue","textValue","isTreeColumn","depth","Math","min","indentPx","showChevron","showChevronSpacer","pinnedStyle","cellStyle","paddingInlineStart","needsTreeIndicator","data-row-activation","colIndex","truncate","variant","data-row-expand-toggle","stopPropagation","toggleExpanded","aria-label","width","aria-hidden","span"],"mappings":";AAOA,SAASA,gBAAgB,QAAQ,sBAAsB;AACvD,SAA8BC,UAAU,QAAQ,wBAAwB;AAGxE,SAASC,EAAE,EAAEC,UAAU,QAAQ,2BAAwB;AACvD,SAASC,MAAM,QAAQ,sBAAmB;AAE1C,SAASC,YAAY,QAAQ,sBAAmB;AAChD,SAASC,wBAAwB,QAAQ,iCAA8B;AACvE,SACEC,oBAAoB,EACpBC,YAAY,E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,IAAIV,YAAY;gBAExDoC,UAAUA;gBACVG,cAAcA;gBACdoB,UAAUxB,YAAY;gBACtBW,WAAWA;gBACXc,UAAUH,qBAAqB,QAAQX,cAAc9C;gBACrDsB,OAAOiC;;oBAENH,6BACC,KAAC3E;wBACC+C,MAAK;wBACLqC,SAAQ;wBACRxC,WAAU;wBACVyC,0BAAuB;wBACvBlC,SAAS,CAACC;4BACRA,MAAMkC,eAAe;4BACrB7E,IAAI8E,cAAc;wBACpB;wBACAC,cAAY/E,IAAIgC,aAAa,KAAK,iBAAiB;kCAEnD,cAAA,KAAC7C;4BACC6F,OAAO;4BACP3C,QAAQ;4BACRF,WAAW9C,GAAGW,IAAIgC,aAAa,MAAM;4BACrCiD,eAAY;;;oBAIjBd,mCACC,KAACe;wBACC/C,WAAU;wBACV8C,eAAY;;oBAGfV,sBAAsBX,cAAc9C,0BACnC,KAACoE;wBAAK/C,WAAU;kCAAiCyB;yBAEjDN;;eAxCGhC,KAAK8B,EAAE;QA4ClB;;AAGN;AAEA,SAASrD,WAAW,GAA0B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-row.tsx"],"sourcesContent":["import type {\n CSSProperties,\n KeyboardEvent,\n MouseEvent,\n ReactElement,\n ReactNode,\n} from 'react';\n\nimport { IconChevronRight } from '@tabler/icons-react';\nimport { type Cell, type Row, flexRender } from '@tanstack/react-table';\nimport type { VirtualItem } from '@tanstack/react-virtual';\n\nimport { cn, focusState } from '../../../../lib/utils';\nimport { Button } from '../button/button';\n\nimport { DataGridCell } from './data-grid-cell';\nimport { isDataGridRowHighlighted } from './data-grid-selection-state';\nimport {\n PINNED_COLUMN_Z_INDEX,\n getTextValue,\n isAccessorColumn,\n isFromExpandToggleTarget,\n isFromIgnoredCellTarget,\n} from './data-grid.utils';\n\ntype DataGridRowProps<TData> = {\n row: Row<TData>;\n virtualRow: VirtualItem;\n headerGroupCount: number;\n pinnedColumnIds: Set<string>;\n lastPinnedColumnId: string | undefined;\n maxDepth: number;\n hasExpanding: boolean;\n onRowClick?: (row: Row<TData>) => void;\n};\n\nfunction DataGridRow<TData>({\n row,\n virtualRow,\n headerGroupCount,\n pinnedColumnIds,\n lastPinnedColumnId,\n maxDepth,\n hasExpanding,\n onRowClick,\n}: DataGridRowProps<TData>): ReactElement {\n const canExpand = row.getCanExpand();\n const isRowInteractive = onRowClick !== undefined;\n const isHighlighted = isDataGridRowHighlighted(row);\n\n const handleRowActivation = isRowInteractive\n ? (triggerTarget?: EventTarget | null) => {\n if (isFromIgnoredCellTarget(triggerTarget)) return;\n if (isFromExpandToggleTarget(triggerTarget)) return;\n onRowClick?.(row);\n }\n : undefined;\n\n const visibleCells = row.getVisibleCells();\n const resolvedTreeColumnIndex = visibleCells.findIndex((cell) =>\n isAccessorColumn(cell.column.columnDef)\n );\n const treeColumnIndex =\n resolvedTreeColumnIndex >= 0 ? resolvedTreeColumnIndex : 0;\n\n return (\n <div\n data-slot=\"data-grid-row\"\n role=\"row\"\n aria-rowindex={virtualRow.index + 1 + headerGroupCount}\n aria-expanded={canExpand ? row.getIsExpanded() : undefined}\n aria-selected={row.getIsSelected() ? true : undefined}\n className={cn(\n 'group absolute left-0 right-0 grid border-b bg-background transition-colors',\n 'hover:bg-active-muted-background',\n isHighlighted &&\n 'bg-medium-background hover:bg-medium-background-hover',\n isRowInteractive &&\n cn(\n 'cursor-pointer focus-visible:bg-active-muted-background',\n focusState\n )\n )}\n style={{\n gridTemplateColumns: 'var(--data-grid-template-columns)',\n height: virtualRow.size,\n transform: `translateY(${virtualRow.start}px)`,\n }}\n tabIndex={isRowInteractive ? 0 : undefined}\n onClick={\n handleRowActivation\n ? (event: MouseEvent<HTMLDivElement>) =>\n handleRowActivation(event.target)\n : undefined\n }\n onKeyDown={\n handleRowActivation\n ? (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n if (isFromIgnoredCellTarget(event.target)) return;\n if (isFromExpandToggleTarget(event.target)) return;\n event.preventDefault();\n handleRowActivation(event.target);\n }\n : undefined\n }\n >\n {visibleCells.map((cell: Cell<TData, unknown>, cellIndex: number) => {\n const isPinned = pinnedColumnIds.has(cell.column.id);\n const isLastPinned = isPinned && lastPinnedColumnId === cell.column.id;\n const cellContext = cell.getContext();\n const cellRenderer = cell.column.columnDef.cell;\n let renderedCell: ReactNode;\n let cellTitle: string | undefined;\n\n if (typeof cellRenderer === 'function') {\n const cellContent = cellRenderer(cellContext);\n cellTitle = getTextValue(cellContent);\n renderedCell = cellContent;\n } else {\n renderedCell = flexRender(cellRenderer, cellContext);\n cellTitle = getTextValue(renderedCell);\n }\n\n const isTreeColumn = cellIndex === treeColumnIndex;\n const depth = Math.min(row.depth, maxDepth);\n const indentPx = isTreeColumn && depth > 0 ? depth * 16 : 0;\n const showChevron = isTreeColumn && canExpand;\n const showChevronSpacer =\n isTreeColumn && hasExpanding && !canExpand && depth > 0;\n\n const pinnedStyle: CSSProperties | undefined = isPinned\n ? {\n position: 'sticky',\n left: cell.column.getStart('left'),\n zIndex: PINNED_COLUMN_Z_INDEX,\n }\n : undefined;\n\n const cellStyle: CSSProperties | undefined =\n indentPx > 0 || pinnedStyle\n ? {\n ...pinnedStyle,\n ...(indentPx > 0\n ? { paddingInlineStart: `${indentPx + 12}px` }\n : {}),\n }\n : undefined;\n\n return (\n <DataGridCell\n key={cell.id}\n data-row-activation={\n isAccessorColumn(cell.column.columnDef) ? undefined : 'ignore'\n }\n isPinned={isPinned}\n isLastPinned={isLastPinned}\n colIndex={cellIndex + 1}\n style={cellStyle}\n >\n {showChevron && (\n <Button\n size=\"icon-sm\"\n variant=\"ghost\"\n className=\"mr-2\"\n data-row-expand-toggle=\"true\"\n onClick={(event: MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n row.toggleExpanded();\n }}\n aria-label={row.getIsExpanded() ? 'Collapse row' : 'Expand row'}\n >\n <IconChevronRight\n width={5}\n height={8}\n className={cn(row.getIsExpanded() && 'rotate-90')}\n aria-hidden=\"true\"\n />\n </Button>\n )}\n {showChevronSpacer && (\n <span\n className=\"mr-2 inline-block h-7 w-7 shrink-0\"\n aria-hidden=\"true\"\n />\n )}\n <span\n className=\"block min-w-0 flex-1 not-has-[*]:truncate\"\n title={cellTitle}\n >\n {renderedCell}\n </span>\n </DataGridCell>\n );\n })}\n </div>\n );\n}\n\nexport { DataGridRow, type DataGridRowProps };\n"],"names":["IconChevronRight","flexRender","cn","focusState","Button","DataGridCell","isDataGridRowHighlighted","PINNED_COLUMN_Z_INDEX","getTextValue","isAccessorColumn","isFromExpandToggleTarget","isFromIgnoredCellTarget","DataGridRow","row","virtualRow","headerGroupCount","pinnedColumnIds","lastPinnedColumnId","maxDepth","hasExpanding","onRowClick","canExpand","getCanExpand","isRowInteractive","undefined","isHighlighted","handleRowActivation","triggerTarget","visibleCells","getVisibleCells","resolvedTreeColumnIndex","findIndex","cell","column","columnDef","treeColumnIndex","div","data-slot","role","aria-rowindex","index","aria-expanded","getIsExpanded","aria-selected","getIsSelected","className","style","gridTemplateColumns","height","size","transform","start","tabIndex","onClick","event","target","onKeyDown","key","preventDefault","map","cellIndex","isPinned","has","id","isLastPinned","cellContext","getContext","cellRenderer","renderedCell","cellTitle","cellContent","isTreeColumn","depth","Math","min","indentPx","showChevron","showChevronSpacer","pinnedStyle","position","left","getStart","zIndex","cellStyle","paddingInlineStart","data-row-activation","colIndex","variant","data-row-expand-toggle","stopPropagation","toggleExpanded","aria-label","width","aria-hidden","span","title"],"mappings":";AAQA,SAASA,gBAAgB,QAAQ,sBAAsB;AACvD,SAA8BC,UAAU,QAAQ,wBAAwB;AAGxE,SAASC,EAAE,EAAEC,UAAU,QAAQ,2BAAwB;AACvD,SAASC,MAAM,QAAQ,sBAAmB;AAE1C,SAASC,YAAY,QAAQ,sBAAmB;AAChD,SAASC,wBAAwB,QAAQ,iCAA8B;AACvE,SACEC,qBAAqB,EACrBC,YAAY,EACZC,gBAAgB,EAChBC,wBAAwB,EACxBC,uBAA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AAOqC;;oBAENP,6BACC,KAACxE;wBACC6C,MAAK;wBACLsC,SAAQ;wBACR1C,WAAU;wBACV2C,0BAAuB;wBACvBnC,SAAS,CAACC;4BACRA,MAAMmC,eAAe;4BACrB5E,IAAI6E,cAAc;wBACpB;wBACAC,cAAY9E,IAAI6B,aAAa,KAAK,iBAAiB;kCAEnD,cAAA,KAAC1C;4BACC4F,OAAO;4BACP5C,QAAQ;4BACRH,WAAW3C,GAAGW,IAAI6B,aAAa,MAAM;4BACrCmD,eAAY;;;oBAIjBhB,mCACC,KAACiB;wBACCjD,WAAU;wBACVgD,eAAY;;kCAGhB,KAACC;wBACCjD,WAAU;wBACVkD,OAAO1B;kCAEND;;;eAvCEpC,KAAK+B,EAAE;QA2ClB;;AAGN;AAEA,SAASnD,WAAW,GAA0B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { RowSelectionState } from "@tanstack/react-table";
|
|
3
|
+
import type { DataGridSelectionActions } from "./data-grid-selection.types";
|
|
4
|
+
type DataGridSelectionToolbarProps = {
|
|
5
|
+
selectedCount: number;
|
|
6
|
+
rowSelection: RowSelectionState;
|
|
7
|
+
selectionActions?: DataGridSelectionActions;
|
|
8
|
+
onClear: () => void;
|
|
9
|
+
};
|
|
10
|
+
declare function DataGridSelectionToolbar({ selectedCount, rowSelection, selectionActions, onClear }: DataGridSelectionToolbarProps): ReactElement;
|
|
11
|
+
export { DataGridSelectionToolbar };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { IconDotsVertical } from "@tabler/icons-react";
|
|
4
|
+
import { ActionToolbar, ActionToolbarAction, ActionToolbarActionClear, ActionToolbarActions, ActionToolbarPrimaryAction, ActionToolbarSelection, ActionToolbarSelectionSummary } from "../action-toolbar/action-toolbar.js";
|
|
5
|
+
import { Button } from "../button/button.js";
|
|
6
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../dropdown-menu/dropdown-menu.js";
|
|
7
|
+
const MAX_SECONDARY_ACTIONS = 5;
|
|
8
|
+
function DataGridSelectionToolbar({ selectedCount, rowSelection, selectionActions, onClear }) {
|
|
9
|
+
const primaryAction = selectionActions?.primaryAction;
|
|
10
|
+
const requestedSecondaryActions = selectionActions?.secondaryActions ?? [];
|
|
11
|
+
const secondaryActions = limitSecondaryActions(requestedSecondaryActions);
|
|
12
|
+
const menuActions = selectionActions?.menuActions ?? [];
|
|
13
|
+
const secondaryActionCount = requestedSecondaryActions.length;
|
|
14
|
+
useEffect(()=>{
|
|
15
|
+
if (secondaryActionCount <= MAX_SECONDARY_ACTIONS) return;
|
|
16
|
+
console.warn(`[Aura DataGrid] The selection toolbar shows at most ${MAX_SECONDARY_ACTIONS} secondary actions. ` + 'Move the rest to menuActions.');
|
|
17
|
+
}, [
|
|
18
|
+
secondaryActionCount
|
|
19
|
+
]);
|
|
20
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
21
|
+
className: "pointer-events-none sticky bottom-4 z-20 flex justify-center px-4",
|
|
22
|
+
children: /*#__PURE__*/ _jsxs(ActionToolbar, {
|
|
23
|
+
selectedCount: selectedCount,
|
|
24
|
+
width: "full",
|
|
25
|
+
"aria-label": "Selection actions",
|
|
26
|
+
className: "pointer-events-auto",
|
|
27
|
+
children: [
|
|
28
|
+
/*#__PURE__*/ _jsxs(ActionToolbarSelection, {
|
|
29
|
+
"aria-label": "Selected rows",
|
|
30
|
+
children: [
|
|
31
|
+
/*#__PURE__*/ _jsx(ActionToolbarSelectionSummary, {}),
|
|
32
|
+
/*#__PURE__*/ _jsx(ActionToolbarActionClear, {
|
|
33
|
+
onClick: onClear
|
|
34
|
+
})
|
|
35
|
+
]
|
|
36
|
+
}),
|
|
37
|
+
/*#__PURE__*/ _jsxs(ActionToolbarActions, {
|
|
38
|
+
"aria-label": "Actions",
|
|
39
|
+
children: [
|
|
40
|
+
menuActions.length > 0 ? /*#__PURE__*/ _jsx(DataGridSelectionMenu, {
|
|
41
|
+
actions: menuActions,
|
|
42
|
+
rowSelection: rowSelection
|
|
43
|
+
}) : null,
|
|
44
|
+
secondaryActions.map((action)=>/*#__PURE__*/ _jsx(DataGridSecondaryToolbarAction, {
|
|
45
|
+
action: action,
|
|
46
|
+
rowSelection: rowSelection
|
|
47
|
+
}, actionListKey(secondaryActions, action))),
|
|
48
|
+
primaryAction ? /*#__PURE__*/ _jsxs(ActionToolbarPrimaryAction, {
|
|
49
|
+
onClick: ()=>primaryAction.onClick(rowSelection),
|
|
50
|
+
children: [
|
|
51
|
+
primaryAction.icon ? /*#__PURE__*/ _jsx("span", {
|
|
52
|
+
"aria-hidden": "true",
|
|
53
|
+
children: primaryAction.icon
|
|
54
|
+
}) : null,
|
|
55
|
+
primaryAction.label
|
|
56
|
+
]
|
|
57
|
+
}) : null
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function DataGridSecondaryToolbarAction({ action, rowSelection }) {
|
|
65
|
+
if (action.label != null) {
|
|
66
|
+
return /*#__PURE__*/ _jsxs(ActionToolbarAction, {
|
|
67
|
+
onClick: ()=>action.onClick(rowSelection),
|
|
68
|
+
children: [
|
|
69
|
+
action.icon ? /*#__PURE__*/ _jsx("span", {
|
|
70
|
+
"aria-hidden": "true",
|
|
71
|
+
children: action.icon
|
|
72
|
+
}) : null,
|
|
73
|
+
action.label
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return /*#__PURE__*/ _jsx(ActionToolbarAction, {
|
|
78
|
+
iconOnly: true,
|
|
79
|
+
"aria-label": action['aria-label'],
|
|
80
|
+
onClick: ()=>action.onClick(rowSelection),
|
|
81
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
82
|
+
"aria-hidden": "true",
|
|
83
|
+
children: action.icon
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function DataGridSelectionMenu({ actions, rowSelection }) {
|
|
88
|
+
return /*#__PURE__*/ _jsxs(DropdownMenu, {
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ _jsx(DropdownMenuTrigger, {
|
|
91
|
+
render: /*#__PURE__*/ _jsx(Button, {
|
|
92
|
+
variant: "ghostOnDark",
|
|
93
|
+
size: "icon",
|
|
94
|
+
"aria-label": "More actions",
|
|
95
|
+
children: /*#__PURE__*/ _jsx(IconDotsVertical, {
|
|
96
|
+
"aria-hidden": "true"
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
}),
|
|
100
|
+
/*#__PURE__*/ _jsx(DropdownMenuContent, {
|
|
101
|
+
side: "top",
|
|
102
|
+
align: "end",
|
|
103
|
+
children: actions.map((action)=>/*#__PURE__*/ _jsxs(DropdownMenuItem, {
|
|
104
|
+
onClick: ()=>action.onClick(rowSelection),
|
|
105
|
+
children: [
|
|
106
|
+
action.icon ? /*#__PURE__*/ _jsx("span", {
|
|
107
|
+
"aria-hidden": "true",
|
|
108
|
+
children: action.icon
|
|
109
|
+
}) : null,
|
|
110
|
+
action.label
|
|
111
|
+
]
|
|
112
|
+
}, actionListKey(actions, action)))
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function actionListKey(actions, action) {
|
|
118
|
+
const name = action.label ?? action['aria-label'] ?? '';
|
|
119
|
+
const earlierDuplicates = actions.slice(0, actions.indexOf(action)).filter((candidate)=>(candidate.label ?? candidate['aria-label']) === name).length;
|
|
120
|
+
if (earlierDuplicates === 0) return name;
|
|
121
|
+
return `${name}-${earlierDuplicates + 1}`;
|
|
122
|
+
}
|
|
123
|
+
function limitSecondaryActions(actions) {
|
|
124
|
+
return actions.slice(0, MAX_SECONDARY_ACTIONS);
|
|
125
|
+
}
|
|
126
|
+
export { DataGridSelectionToolbar };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=data-grid-selection-toolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/data-grid/data-grid-selection-toolbar.tsx"],"sourcesContent":["import { useEffect, type ReactElement } from 'react';\n\nimport { IconDotsVertical } from '@tabler/icons-react';\nimport type { RowSelectionState } from '@tanstack/react-table';\n\nimport {\n ActionToolbar,\n ActionToolbarAction,\n ActionToolbarActionClear,\n ActionToolbarActions,\n ActionToolbarPrimaryAction,\n ActionToolbarSelection,\n ActionToolbarSelectionSummary,\n} from '../action-toolbar/action-toolbar';\nimport { Button } from '../button/button';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from '../dropdown-menu/dropdown-menu';\n\nimport type {\n DataGridSecondaryAction,\n DataGridSelectionAction,\n DataGridSelectionActions,\n} from './data-grid-selection.types';\n\ntype DataGridSelectionToolbarProps = {\n selectedCount: number;\n rowSelection: RowSelectionState;\n selectionActions?: DataGridSelectionActions;\n onClear: () => void;\n};\n\nconst MAX_SECONDARY_ACTIONS = 5;\n\nfunction DataGridSelectionToolbar({\n selectedCount,\n rowSelection,\n selectionActions,\n onClear,\n}: DataGridSelectionToolbarProps): ReactElement {\n const primaryAction = selectionActions?.primaryAction;\n const requestedSecondaryActions = selectionActions?.secondaryActions ?? [];\n const secondaryActions = limitSecondaryActions(requestedSecondaryActions);\n const menuActions = selectionActions?.menuActions ?? [];\n\n const secondaryActionCount = requestedSecondaryActions.length;\n\n useEffect(() => {\n if (secondaryActionCount <= MAX_SECONDARY_ACTIONS) return;\n console.warn(\n `[Aura DataGrid] The selection toolbar shows at most ${MAX_SECONDARY_ACTIONS} secondary actions. ` +\n 'Move the rest to menuActions.'\n );\n }, [secondaryActionCount]);\n\n return (\n <div className=\"pointer-events-none sticky bottom-4 z-20 flex justify-center px-4\">\n <ActionToolbar\n selectedCount={selectedCount}\n width=\"full\"\n aria-label=\"Selection actions\"\n className=\"pointer-events-auto\"\n >\n <ActionToolbarSelection aria-label=\"Selected rows\">\n <ActionToolbarSelectionSummary />\n <ActionToolbarActionClear onClick={onClear} />\n </ActionToolbarSelection>\n <ActionToolbarActions aria-label=\"Actions\">\n {menuActions.length > 0 ? (\n <DataGridSelectionMenu\n actions={menuActions}\n rowSelection={rowSelection}\n />\n ) : null}\n {secondaryActions.map((action: DataGridSecondaryAction) => (\n <DataGridSecondaryToolbarAction\n key={actionListKey(secondaryActions, action)}\n action={action}\n rowSelection={rowSelection}\n />\n ))}\n {primaryAction ? (\n <ActionToolbarPrimaryAction\n onClick={() => primaryAction.onClick(rowSelection)}\n >\n {primaryAction.icon ? (\n <span aria-hidden=\"true\">{primaryAction.icon}</span>\n ) : null}\n {primaryAction.label}\n </ActionToolbarPrimaryAction>\n ) : null}\n </ActionToolbarActions>\n </ActionToolbar>\n </div>\n );\n}\n\nfunction DataGridSecondaryToolbarAction({\n action,\n rowSelection,\n}: {\n action: DataGridSecondaryAction;\n rowSelection: RowSelectionState;\n}): ReactElement {\n if (action.label != null) {\n return (\n <ActionToolbarAction onClick={() => action.onClick(rowSelection)}>\n {action.icon ? <span aria-hidden=\"true\">{action.icon}</span> : null}\n {action.label}\n </ActionToolbarAction>\n );\n }\n\n return (\n <ActionToolbarAction\n iconOnly\n aria-label={action['aria-label']}\n onClick={() => action.onClick(rowSelection)}\n >\n <span aria-hidden=\"true\">{action.icon}</span>\n </ActionToolbarAction>\n );\n}\n\nfunction DataGridSelectionMenu({\n actions,\n rowSelection,\n}: {\n actions: readonly DataGridSelectionAction[];\n rowSelection: RowSelectionState;\n}): ReactElement {\n return (\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button variant=\"ghostOnDark\" size=\"icon\" aria-label=\"More actions\">\n <IconDotsVertical aria-hidden=\"true\" />\n </Button>\n }\n />\n <DropdownMenuContent side=\"top\" align=\"end\">\n {actions.map((action: DataGridSelectionAction) => (\n <DropdownMenuItem\n key={actionListKey(actions, action)}\n onClick={() => action.onClick(rowSelection)}\n >\n {action.icon ? <span aria-hidden=\"true\">{action.icon}</span> : null}\n {action.label}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n\nfunction actionListKey<T extends { label?: string; 'aria-label'?: string }>(\n actions: readonly T[],\n action: T\n): string {\n const name = action.label ?? action['aria-label'] ?? '';\n const earlierDuplicates = actions\n .slice(0, actions.indexOf(action))\n .filter(\n (candidate) => (candidate.label ?? candidate['aria-label']) === name\n ).length;\n if (earlierDuplicates === 0) return name;\n return `${name}-${earlierDuplicates + 1}`;\n}\n\nfunction limitSecondaryActions(\n actions: readonly DataGridSecondaryAction[]\n): readonly DataGridSecondaryAction[] {\n return actions.slice(0, MAX_SECONDARY_ACTIONS);\n}\n\nexport { DataGridSelectionToolbar };\n"],"names":["useEffect","IconDotsVertical","ActionToolbar","ActionToolbarAction","ActionToolbarActionClear","ActionToolbarActions","ActionToolbarPrimaryAction","ActionToolbarSelection","ActionToolbarSelectionSummary","Button","DropdownMenu","DropdownMenuContent","DropdownMenuItem","DropdownMenuTrigger","MAX_SECONDARY_ACTIONS","DataGridSelectionToolbar","selectedCount","rowSelection","selectionActions","onClear","primaryAction","requestedSecondaryActions","secondaryActions","limitSecondaryActions","menuActions","secondaryActionCount","length","console","warn","div","className","width","aria-label","onClick","DataGridSelectionMenu","actions","map","action","DataGridSecondaryToolbarAction","actionListKey","icon","span","aria-hidden","label","iconOnly","render","variant","size","side","align","name","earlierDuplicates","slice","indexOf","filter","candidate"],"mappings":";AAAA,SAASA,SAAS,QAA2B,QAAQ;AAErD,SAASC,gBAAgB,QAAQ,sBAAsB;AAGvD,SACEC,aAAa,EACbC,mBAAmB,EACnBC,wBAAwB,EACxBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,sBAAsB,EACtBC,6BAA6B,QACxB,sCAAmC;AAC1C,SAASC,MAAM,QAAQ,sBAAmB;AAC1C,SACEC,YAAY,EACZC,mBAA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