@linzjs/step-ag-grid 35.0.3 → 35.2.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/index.css +17 -0
- package/dist/src/components/Grid.d.ts +5 -1
- package/dist/src/components/GridRangeSelectContextMenu.d.ts +12 -1
- package/dist/src/components/gridFilter/GridFilterCopyButton.d.ts +9 -0
- package/dist/src/components/gridFilter/index.d.ts +1 -0
- package/dist/src/components/gridHook/copyGridCells.d.ts +19 -0
- package/dist/src/components/gridHook/copyGridCells.test.d.ts +1 -0
- package/dist/src/components/gridHook/useGridColumnStateStorage.d.ts +26 -0
- package/dist/src/components/gridHook/useGridColumnStateStorage.test.d.ts +1 -0
- package/dist/src/components/gridHook/useGridCopy.d.ts +5 -2
- package/dist/src/components/gridHook/useGridCopySettings.d.ts +2 -0
- package/dist/src/contexts/GridContext.d.ts +35 -0
- package/dist/src/contexts/GridContextProvider.copy.test.d.ts +1 -0
- package/dist/src/utils/storageKeySync.d.ts +6 -0
- package/dist/src/utils/storageKeySync.test.d.ts +1 -0
- package/dist/step-ag-grid.cjs +601 -265
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +602 -267
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +69 -27
- package/src/components/GridRangeSelectContextMenu.tsx +54 -51
- package/src/components/gridFilter/GridFilterColumnsToggle.tsx +45 -12
- package/src/components/gridFilter/GridFilterCopyButton.tsx +93 -0
- package/src/components/gridFilter/index.ts +1 -0
- package/src/components/gridHook/copyGridCells.test.ts +142 -0
- package/src/components/gridHook/copyGridCells.ts +225 -0
- package/src/components/gridHook/useGridColumnStateStorage.test.tsx +127 -0
- package/src/components/gridHook/useGridColumnStateStorage.ts +114 -0
- package/src/components/gridHook/useGridCopy.ts +88 -211
- package/src/components/gridHook/useGridCopySettings.ts +21 -6
- package/src/contexts/GridContext.tsx +44 -0
- package/src/contexts/GridContextProvider.copy.test.tsx +158 -0
- package/src/contexts/GridContextProvider.tsx +129 -2
- package/src/stories/grid/GridColumnState.stories.tsx +161 -0
- package/src/stories/grid/GridCopy.stories.tsx +35 -20
- package/src/stories/grid/GridCopyEditable.stories.tsx +131 -0
- package/src/stories/grid/GridCopyMultiple.stories.tsx +119 -0
- package/src/styles/GridFilterCopyButton.scss +22 -0
- package/src/styles/index.scss +1 -0
- package/src/utils/storageKeySync.test.ts +48 -0
- package/src/utils/storageKeySync.ts +24 -0
package/dist/index.css
CHANGED
|
@@ -653,6 +653,23 @@ div.ag-row div.ag-cell.rangeSelectBottom {
|
|
|
653
653
|
overflow: auto;
|
|
654
654
|
}
|
|
655
655
|
|
|
656
|
+
.GridFilterCopyButton.lui-split-button {
|
|
657
|
+
margin: 0 4px;
|
|
658
|
+
}
|
|
659
|
+
.GridFilterCopyButton.lui-split-button .GridFilterCopyButton-copy,
|
|
660
|
+
.GridFilterCopyButton.lui-split-button .GridFilterCopyButton-caret {
|
|
661
|
+
margin: 0;
|
|
662
|
+
display: flex;
|
|
663
|
+
align-items: center;
|
|
664
|
+
justify-content: center;
|
|
665
|
+
}
|
|
666
|
+
.GridFilterCopyButton.lui-split-button .GridFilterCopyButton-caret {
|
|
667
|
+
border-radius: 0 3px 3px 0;
|
|
668
|
+
}
|
|
669
|
+
.GridFilterCopyButton.lui-split-button .GridFilterCopyButton-caret:active:enabled {
|
|
670
|
+
border-left: 0;
|
|
671
|
+
}
|
|
672
|
+
|
|
656
673
|
.MenuItem-icon {
|
|
657
674
|
margin-right: 8px;
|
|
658
675
|
}
|
|
@@ -22,6 +22,8 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
22
22
|
autoSelectFirstRow?: boolean;
|
|
23
23
|
enableClickSelection?: boolean;
|
|
24
24
|
enableRangeSelection?: boolean;
|
|
25
|
+
/** Shows GridFilterCopyButton */
|
|
26
|
+
enableCopy?: boolean;
|
|
25
27
|
enableSelectionWithoutKeys?: boolean;
|
|
26
28
|
enableMultilineBulkEdit?: boolean;
|
|
27
29
|
externalSelectedIds?: TData['id'][];
|
|
@@ -41,6 +43,8 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
41
43
|
data: TData;
|
|
42
44
|
}) => void;
|
|
43
45
|
onColumnMoved?: GridOptions['onColumnMoved'];
|
|
46
|
+
/** Save user column widths and sort, shared by every grid with the same column ids */
|
|
47
|
+
saveColumnState?: boolean;
|
|
44
48
|
onContentSize?: (props: {
|
|
45
49
|
width: number;
|
|
46
50
|
}) => void;
|
|
@@ -65,4 +69,4 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
65
69
|
/**
|
|
66
70
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
67
71
|
*/
|
|
68
|
-
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ theme, 'data-testid': dataTestId, suppressReadOnlyStyle, defaultPostSort, rowData, rowHeight, rowSelection, sizeColumns, autoSelectFirstRow, enableRangeSelection, externalSelectedIds, externalSelectedItems, selectColumnPinned, selectable, setExternalSelectedIds, setExternalSelectedItems, singleClickEdit, enableMultilineBulkEdit, contextMenuSelectRow, contextMenu, onCellFocused: paramsOnCellFocused, onColumnMoved, suppressColumnVirtualization, maxInitialWidth, ...params }: GridProps<TData>) => ReactElement;
|
|
72
|
+
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ theme, 'data-testid': dataTestId, suppressReadOnlyStyle, defaultPostSort, rowData, rowHeight, rowSelection, sizeColumns, autoSelectFirstRow, enableRangeSelection, enableCopy, externalSelectedIds, externalSelectedItems, selectColumnPinned, selectable, setExternalSelectedIds, setExternalSelectedItems, singleClickEdit, enableMultilineBulkEdit, contextMenuSelectRow, contextMenu, onCellFocused: paramsOnCellFocused, onColumnMoved, saveColumnState, suppressColumnVirtualization, maxInitialWidth, ...params }: GridProps<TData>) => ReactElement;
|
|
@@ -7,4 +7,15 @@ export interface CopyOptionsContext {
|
|
|
7
7
|
copyType: CopyOptionsKey;
|
|
8
8
|
setCopyType: (copyType: CopyOptionsKey) => void;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export interface GridCopyOptionsMenuItemsProps extends CopyOptionsContext {
|
|
11
|
+
/** Show developer only copy options, e.g. Json */
|
|
12
|
+
developer?: boolean;
|
|
13
|
+
/** Header above the copy formats, defaults to "Copy as" */
|
|
14
|
+
header?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* "Copy as" and "Set copy default" menu items.
|
|
18
|
+
* Used by the range select context menu and GridFilterCopyButton.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GridCopyOptionsMenuItems: ({ onCopy, copyType, setCopyType, developer: showDeveloper, header, }: GridCopyOptionsMenuItemsProps) => ReactElement;
|
|
21
|
+
export declare const GridRangeSelectContextMenu: <TData extends GridBaseRow>({ event, context, }: GridContextMenuComponentProps<TData, CopyOptionsContext>) => ReactElement | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Copies the selected range to the clipboard if one is selected,
|
|
4
|
+
* otherwise the selected rows, or all rows if no rows are selected.
|
|
5
|
+
* The caret menu allows choosing the copy format and setting the default copy format.
|
|
6
|
+
*
|
|
7
|
+
* Only shown when the Grid has enableCopy.
|
|
8
|
+
*/
|
|
9
|
+
export declare const GridFilterCopyButton: () => ReactElement | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './GridFilterButtons';
|
|
2
2
|
export * from './GridFilterColumnsMultiSelect';
|
|
3
3
|
export * from './GridFilterColumnsToggle';
|
|
4
|
+
export * from './GridFilterCopyButton';
|
|
4
5
|
export * from './GridFilterDownloadCsvButton';
|
|
5
6
|
export * from './GridFilterHeaderIconButton';
|
|
6
7
|
export * from './GridFilterQuick';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useShowLUIMessage } from '@linzjs/lui';
|
|
2
|
+
import { ColDef, GridApi, IRowNode } from 'ag-grid-community';
|
|
3
|
+
import { CopyOptionsKey } from './useGridCopySettings';
|
|
4
|
+
export interface CopyGridCellsProps {
|
|
5
|
+
type: CopyOptionsKey;
|
|
6
|
+
selectedColIds: string[];
|
|
7
|
+
selectedNodes: IRowNode[];
|
|
8
|
+
selectedRowIds: unknown[];
|
|
9
|
+
getColDef: (colId?: string) => ColDef | undefined;
|
|
10
|
+
getCellValue: GridApi['getCellValue'];
|
|
11
|
+
showToast: ReturnType<typeof useShowLUIMessage>;
|
|
12
|
+
}
|
|
13
|
+
/** Columns that are included when copying, excludes the filler column and non-exportable columns */
|
|
14
|
+
export declare const isCopyableColId: (colId: string, getColDef: (colId?: string) => ColDef | undefined) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Formats the cells of the given columns and rows and writes them to the clipboard.
|
|
17
|
+
* Used by range select copy and GridContext copyToClipboard.
|
|
18
|
+
*/
|
|
19
|
+
export declare const copyGridCells: ({ type, selectedColIds, selectedNodes, selectedRowIds, getColDef, getCellValue, showToast, }: CopyGridCellsProps) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ColumnState, GridApi } from 'ag-grid-community';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
export type StoredColumn = Pick<ColumnState, 'colId' | 'width' | 'flex' | 'sort' | 'sortIndex'>;
|
|
4
|
+
export interface StoredColumnState {
|
|
5
|
+
columns: StoredColumn[];
|
|
6
|
+
/** Columns the user has resized, so auto-size leaves them alone */
|
|
7
|
+
userSizedColIds: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const columnStateStorageKey: (colIds: string[]) => string | null;
|
|
10
|
+
export declare const toStoredColumnState: (columnState: ColumnState[], userSizedColIds: Iterable<string>) => StoredColumnState;
|
|
11
|
+
export declare const parseStoredColumnState: (stored: string | null) => StoredColumnState | undefined;
|
|
12
|
+
/** Applies widths and sort only, so column visibility stays with GridFilterColumnsToggle */
|
|
13
|
+
export declare const applyStoredColumnState: (api: Pick<GridApi, 'applyColumnState'>, { columns, userSizedColIds: storedUserSizedColIds }: StoredColumnState, userSizedColIds: Map<string, number>) => void;
|
|
14
|
+
interface UseGridColumnStateStorageProps {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
gridApi: GridApi | undefined;
|
|
17
|
+
gridDivRef: RefObject<HTMLDivElement | null>;
|
|
18
|
+
userSizedColIds: {
|
|
19
|
+
current: Map<string, number>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Saves column widths and sort per set of column ids, and keeps grids with the same columns in step */
|
|
23
|
+
export declare const useGridColumnStateStorage: ({ enabled, gridApi, gridDivRef, userSizedColIds, }: UseGridColumnStateStorageProps) => {
|
|
24
|
+
saveColumnState: (api: GridApi) => void;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { CellContextMenuEvent } from 'ag-grid-community';
|
|
2
|
-
import { ClipboardEvent as ReactClipboardEvent, MutableRefObject } from 'react';
|
|
2
|
+
import { ClipboardEvent as ReactClipboardEvent, MutableRefObject, RefObject } from 'react';
|
|
3
3
|
import { GridBaseRow } from '../types';
|
|
4
4
|
import { CellLocation, GridRanges } from './useGridRangeSelection';
|
|
5
|
-
export declare const useGridCopy: <TData extends GridBaseRow>({ ranges, rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef, cellContextMenu, }: {
|
|
5
|
+
export declare const useGridCopy: <TData extends GridBaseRow>({ gridDivRef, gridDocument, ranges, rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef, cellContextMenu, }: {
|
|
6
|
+
gridDivRef: RefObject<HTMLDivElement | null>;
|
|
7
|
+
/** The grid's current document, changes when the grid is popped out */
|
|
8
|
+
gridDocument: Document | undefined;
|
|
6
9
|
ranges: () => GridRanges<TData>;
|
|
7
10
|
rangeStartRef: MutableRefObject<CellLocation | null>;
|
|
8
11
|
rangeEndRef: MutableRefObject<CellLocation | null>;
|
|
@@ -5,6 +5,8 @@ export declare const gridCopyOptions: Record<string, {
|
|
|
5
5
|
developer?: boolean;
|
|
6
6
|
}>;
|
|
7
7
|
export type CopyOptionsKey = keyof typeof gridCopyOptions;
|
|
8
|
+
/** The user's saved default copy format */
|
|
9
|
+
export declare const getDefaultCopyType: () => CopyOptionsKey;
|
|
8
10
|
export declare const useGridCopySettings: () => {
|
|
9
11
|
copyType: string;
|
|
10
12
|
setCopyType: (key: CopyOptionsKey) => void;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { ColDef, GridApi, IRowNode, ISizeColumnsToFitParams } from 'ag-grid-community';
|
|
2
2
|
import { CsvExportParams } from 'ag-grid-community';
|
|
3
|
+
import type { CopyOptionsKey } from '../components/gridHook/useGridCopySettings';
|
|
4
|
+
import type { GridRanges } from '../components/gridHook/useGridRangeSelection';
|
|
3
5
|
import { ColDefT, GridBaseRow } from '../components/types';
|
|
6
|
+
/** What copyToClipboard will copy */
|
|
7
|
+
export type GridCopyScope = 'range' | 'selection' | 'all';
|
|
8
|
+
/** Registered by the Grid so copyToClipboard copies its selected range */
|
|
9
|
+
export interface GridRangeCopy {
|
|
10
|
+
hasRange: () => boolean;
|
|
11
|
+
/** Columns and rows of the selected range */
|
|
12
|
+
getRange: () => GridRanges<any>;
|
|
13
|
+
copy: (type?: CopyOptionsKey) => void;
|
|
14
|
+
}
|
|
4
15
|
export type GridFilterExternal<TData extends GridBaseRow> = (data: TData, rowNode: IRowNode) => boolean;
|
|
5
16
|
export interface AutoSizeColumnsProps {
|
|
6
17
|
skipHeader?: boolean;
|
|
@@ -57,6 +68,30 @@ export interface GridContextType<TData extends GridBaseRow> {
|
|
|
57
68
|
invisibleColumnIds: string[] | undefined;
|
|
58
69
|
setInvisibleColumnIds: (colIds: string[]) => void;
|
|
59
70
|
downloadCsv: (csvExportParams?: CsvExportParams) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Copy to the clipboard, defaults to the user's default copy format.
|
|
73
|
+
* Copies the selected range if one is selected,
|
|
74
|
+
* otherwise the selected rows if any are selected, otherwise all rows.
|
|
75
|
+
* Rows are copied with all displayed columns.
|
|
76
|
+
*/
|
|
77
|
+
copyToClipboard: (type?: CopyOptionsKey) => void;
|
|
78
|
+
/** What copyToClipboard will copy right now */
|
|
79
|
+
getCopyScope: () => GridCopyScope;
|
|
80
|
+
/**
|
|
81
|
+
* The rows copyToClipboard would copy (see getCopyScope), with only the fields of the columns being copied.
|
|
82
|
+
* Values are the raw row data. Columns without a field are not included.
|
|
83
|
+
*/
|
|
84
|
+
getSelectedDataForCopy: () => Partial<TData>[];
|
|
85
|
+
/**
|
|
86
|
+
* The rows copyToClipboard would copy (see getCopyScope), keyed by column id.
|
|
87
|
+
* Values are the raw cell values before formatting.
|
|
88
|
+
*/
|
|
89
|
+
getCopyData: () => Record<string, unknown>[];
|
|
90
|
+
/** Used by Grid to copy its selected range */
|
|
91
|
+
setRangeCopy: (rangeCopy: GridRangeCopy | undefined) => void;
|
|
92
|
+
/** Grid enableCopy, shows GridFilterCopyButton */
|
|
93
|
+
copyEnabled: boolean;
|
|
94
|
+
setCopyEnabled: (copyEnabled: boolean) => void;
|
|
60
95
|
onBulkEditingComplete: () => Promise<void> | void;
|
|
61
96
|
setOnBulkEditingComplete: (callback: (() => Promise<void> | void) | undefined) => void;
|
|
62
97
|
showNoRowsOverlay: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type StorageKeyListener = (value: string) => void;
|
|
2
|
+
/** Notifies when another component publishes a new value for a localStorage key in this page, including popped-out windows */
|
|
3
|
+
export declare const subscribeStorageKey: (key: string, listener: StorageKeyListener) => (() => void);
|
|
4
|
+
/** Saves the value and passes it to every other subscriber of the key */
|
|
5
|
+
export declare const publishStorageKey: (storage: Storage, key: string, value: string, source?: StorageKeyListener) => void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|