@linzjs/step-ag-grid 35.1.0 → 35.2.1

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.
Files changed (33) hide show
  1. package/dist/index.css +17 -0
  2. package/dist/src/components/Grid.d.ts +3 -1
  3. package/dist/src/components/GridRangeSelectContextMenu.d.ts +12 -1
  4. package/dist/src/components/gridFilter/GridFilterCopyButton.d.ts +9 -0
  5. package/dist/src/components/gridFilter/index.d.ts +1 -0
  6. package/dist/src/components/gridHook/copyGridCells.d.ts +19 -0
  7. package/dist/src/components/gridHook/copyGridCells.test.d.ts +1 -0
  8. package/dist/src/components/gridHook/useGridCopy.d.ts +5 -2
  9. package/dist/src/components/gridHook/useGridCopySettings.d.ts +2 -0
  10. package/dist/src/contexts/GridContext.d.ts +35 -0
  11. package/dist/src/contexts/GridContextProvider.copy.test.d.ts +1 -0
  12. package/dist/step-ag-grid.cjs +434 -233
  13. package/dist/step-ag-grid.cjs.map +1 -1
  14. package/dist/step-ag-grid.esm.js +435 -235
  15. package/dist/step-ag-grid.esm.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/components/Grid.tsx +15 -0
  18. package/src/components/GridRangeSelectContextMenu.tsx +54 -51
  19. package/src/components/gridFilter/GridFilterCopyButton.tsx +93 -0
  20. package/src/components/gridFilter/index.ts +1 -0
  21. package/src/components/gridHook/copyGridCells.test.ts +142 -0
  22. package/src/components/gridHook/copyGridCells.ts +225 -0
  23. package/src/components/gridHook/useGridCopy.ts +88 -211
  24. package/src/components/gridHook/useGridCopySettings.ts +21 -6
  25. package/src/contexts/GridContext.tsx +44 -0
  26. package/src/contexts/GridContextProvider.copy.test.tsx +158 -0
  27. package/src/contexts/GridContextProvider.tsx +129 -2
  28. package/src/contexts/GridPopoverContextProvider.tsx +7 -2
  29. package/src/stories/grid/GridCopy.stories.tsx +35 -20
  30. package/src/stories/grid/GridCopyEditable.stories.tsx +131 -0
  31. package/src/stories/grid/GridCopyMultiple.stories.tsx +119 -0
  32. package/src/styles/GridFilterCopyButton.scss +22 -0
  33. package/src/styles/index.scss +1 -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'][];
@@ -67,4 +69,4 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
67
69
  /**
68
70
  * Wrapper for AgGrid to add commonly used functionality.
69
71
  */
70
- 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, saveColumnState, 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 declare const GridRangeSelectContextMenu: <TData extends GridBaseRow>({ event, context, }: GridContextMenuComponentProps<TData, CopyOptionsContext>) => ReactElement;
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;
@@ -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;