@linzjs/step-ag-grid 29.12.0 → 29.14.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 +26 -2
- package/dist/src/components/Grid.d.ts +37 -67
- package/dist/src/components/GridCell.d.ts +2 -19
- package/dist/src/components/GridCellFiller.d.ts +1 -1
- package/dist/src/components/GridCellMultiEditor.d.ts +1 -2
- package/dist/src/components/GridPopoverHook.d.ts +1 -1
- package/dist/src/components/GridRangeSelectContextMenu.d.ts +10 -0
- package/dist/src/components/gridFilter/GridFilterButtons.d.ts +1 -1
- package/dist/src/components/gridFilter/useGridFilter.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormDropDown.d.ts +2 -2
- package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMessage.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelectGrid.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormPopoverMenu.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormSubComponentTextArea.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
- package/dist/src/components/gridHook/useGridContextMenu.d.ts +13 -8
- package/dist/src/components/gridHook/useGridCopy.d.ts +15 -0
- package/dist/src/components/gridHook/useGridCopySettings.d.ts +11 -0
- package/dist/src/components/gridHook/useGridRangeSelection.d.ts +25 -0
- package/dist/src/components/gridPopoverEdit/GridButton.d.ts +1 -2
- package/dist/src/components/gridPopoverEdit/GridEditBoolean.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelectGrid.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverEditBearing.d.ts +4 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverEditDropDown.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverMenu.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverMessage.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverTextArea.d.ts +2 -2
- package/dist/src/components/gridPopoverEdit/GridPopoverTextInput.d.ts +2 -2
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +1 -2
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/types.d.ts +27 -0
- package/dist/src/contexts/GridContext.d.ts +13 -12
- package/dist/src/contexts/GridPopoverContext.d.ts +1 -1
- package/dist/src/lui/timeoutHook.d.ts +0 -6
- package/dist/src/lui/tsUtils.d.ts +5 -0
- package/dist/src/utils/__tests__/random.ts +19 -0
- package/dist/src/utils/textValidator.d.ts +1 -1
- package/dist/src/utils/util.d.ts +1 -0
- package/dist/step-ag-grid.cjs +650 -242
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +651 -245
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +4 -2
- package/src/components/Grid.tsx +312 -221
- package/src/components/GridCell.tsx +1 -25
- package/src/components/GridCellFiller.tsx +1 -1
- package/src/components/GridCellMultiEditor.tsx +2 -2
- package/src/components/GridPopoverHook.tsx +1 -1
- package/src/components/GridRangeSelectContextMenu.tsx +73 -0
- package/src/components/gridFilter/GridFilterButtons.tsx +1 -1
- package/src/components/gridFilter/useGridFilter.ts +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +2 -4
- package/src/components/gridForm/GridFormEditBearing.tsx +1 -1
- package/src/components/gridForm/GridFormMessage.tsx +1 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +1 -1
- package/src/components/gridForm/GridFormMultiSelectGrid.tsx +1 -1
- package/src/components/gridForm/GridFormPopoverMenu.tsx +3 -2
- package/src/components/gridForm/GridFormSubComponentTextArea.tsx +1 -1
- package/src/components/gridForm/GridFormSubComponentTextInput.tsx +1 -1
- package/src/components/gridForm/GridFormTextArea.tsx +1 -1
- package/src/components/gridForm/GridFormTextInput.tsx +1 -1
- package/src/components/gridHook/useGridContextMenu.tsx +23 -10
- package/src/components/gridHook/useGridCopy.ts +279 -0
- package/src/components/gridHook/useGridCopySettings.ts +28 -0
- package/src/components/gridHook/useGridRangeSelection.ts +235 -0
- package/src/components/gridPopoverEdit/GridButton.tsx +2 -2
- package/src/components/gridPopoverEdit/GridEditBoolean.tsx +2 -2
- package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +2 -2
- package/src/components/gridPopoverEdit/GridPopoutEditMultiSelectGrid.ts +2 -2
- package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +5 -2
- package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +2 -2
- package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +2 -2
- package/src/components/gridPopoverEdit/GridPopoverMessage.ts +2 -2
- package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +2 -2
- package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +2 -2
- package/src/components/gridRender/GridRenderGenericCell.tsx +1 -2
- package/src/components/index.ts +1 -0
- package/src/components/types.ts +34 -0
- package/src/contexts/GridContext.tsx +57 -148
- package/src/contexts/GridContextProvider.tsx +16 -13
- package/src/contexts/GridPopoverContext.tsx +1 -1
- package/src/contexts/GridPopoverContextProvider.tsx +1 -1
- package/src/lui/timeoutHook.tsx +0 -19
- package/src/lui/tsUtils.ts +8 -0
- package/src/react-menu3/components/MenuButton.tsx +2 -2
- package/src/react-menu3/hooks/useItemState.ts +1 -1
- package/src/stories/grid/GridCopy.stories.tsx +175 -0
- package/src/stories/grid/GridPopoverEditBearing.stories.tsx +4 -4
- package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +3 -3
- package/src/stories/grid/GridReadOnly.stories.tsx +4 -3
- package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +2 -2
- package/src/styles/ContextMenu.scss +61 -0
- package/src/styles/Grid.scss +26 -2
- package/src/utils/__tests__/random.ts +19 -0
- package/src/utils/bearing.ts +2 -2
- package/src/utils/textValidator.test.ts +1 -1
- package/src/utils/textValidator.ts +1 -1
- package/src/utils/util.ts +2 -0
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ColDef,
|
|
3
|
-
EditableCallback,
|
|
4
3
|
GetQuickFilterTextParams,
|
|
5
4
|
ICellEditorParams,
|
|
6
5
|
ICellRendererParams,
|
|
7
|
-
} from 'ag-grid-community';
|
|
8
|
-
import {
|
|
9
6
|
SuppressKeyboardEventParams,
|
|
10
7
|
ValueFormatterFunc,
|
|
11
8
|
ValueFormatterParams,
|
|
12
|
-
ValueGetterFunc,
|
|
13
9
|
} from 'ag-grid-community';
|
|
14
10
|
import { forwardRef, ReactElement, useContext } from 'react';
|
|
15
11
|
|
|
16
12
|
import { GridPopoverContextProvider } from '../contexts/GridPopoverContextProvider';
|
|
17
13
|
import { GridUpdatingContext } from '../contexts/GridUpdatingContext';
|
|
18
14
|
import { fnOrVar } from '../utils/util';
|
|
19
|
-
import { GridBaseRow } from './Grid';
|
|
20
15
|
import { GridCellMultiSelectClassRules } from './GridCellMultiSelectClassRules';
|
|
21
16
|
import { GridIcon } from './GridIcon';
|
|
22
17
|
import { GridLoadableCell } from './GridLoadableCell';
|
|
23
18
|
import { GenericCellColDef, GenericCellRendererParams } from './gridRender';
|
|
19
|
+
import { ColDefT, GridBaseRow } from './types';
|
|
24
20
|
|
|
25
21
|
export interface GenericCellEditorProps<E> {
|
|
26
22
|
multiEdit?: boolean;
|
|
@@ -74,26 +70,6 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
|
74
70
|
);
|
|
75
71
|
};
|
|
76
72
|
|
|
77
|
-
// This is so that typescript retains the row type to pass to the GridCells
|
|
78
|
-
export interface ColDefT<TData extends GridBaseRow, ValueType = any> extends ColDef<TData, ValueType> {
|
|
79
|
-
editable?: boolean | EditableCallback<TData, ValueType>;
|
|
80
|
-
valueGetter?: string | ValueGetterFunc<TData, ValueType>;
|
|
81
|
-
valueFormatter?: string | ValueFormatterFunc<TData, ValueType>;
|
|
82
|
-
cellRenderer?:
|
|
83
|
-
| ((props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined)
|
|
84
|
-
| string;
|
|
85
|
-
cellRendererParams?: {
|
|
86
|
-
rightHoverElement?: ReactElement;
|
|
87
|
-
originalCellRenderer?: any;
|
|
88
|
-
editAction?: (selectedRows: TData[]) => void;
|
|
89
|
-
shortcutKeys?: Record<string, () => void>;
|
|
90
|
-
error?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
|
|
91
|
-
warning?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
|
|
92
|
-
info?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
|
|
93
|
-
};
|
|
94
|
-
editor?: (editorProps: any) => ReactElement;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
73
|
export const suppressCellKeyboardEvents = (e: SuppressKeyboardEventParams) => {
|
|
98
74
|
const shortcutKeys = e.colDef.cellRendererParams?.shortcutKeys ?? {};
|
|
99
75
|
const exec = shortcutKeys[e.event.key];
|
|
@@ -2,10 +2,10 @@ import { CellEditorSelectorResult } from 'ag-grid-community';
|
|
|
2
2
|
import { ICellEditorParams } from 'ag-grid-community';
|
|
3
3
|
import { ComponentProps, ReactElement } from 'react';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { ColDefT, GenericCellEditorComponentWrapper, GridCell } from './GridCell';
|
|
5
|
+
import { GenericCellEditorComponentWrapper, GridCell } from './GridCell';
|
|
7
6
|
import { GridCellMultiSelectClassRules } from './GridCellMultiSelectClassRules';
|
|
8
7
|
import { GenericCellColDef } from './gridRender';
|
|
8
|
+
import { ColDefT, GridBaseRow } from './types';
|
|
9
9
|
|
|
10
10
|
export const Editor = <FN extends (param: any) => ReactElement>(props: {
|
|
11
11
|
multiEdit: boolean;
|
|
@@ -4,7 +4,7 @@ import { useGridPopoverContext } from '../contexts/GridPopoverContext';
|
|
|
4
4
|
import { ControlledMenu } from '../react-menu3';
|
|
5
5
|
import { MenuCloseEvent } from '../react-menu3/types';
|
|
6
6
|
import { CloseReason } from '../react-menu3/utils';
|
|
7
|
-
import { GridBaseRow } from './
|
|
7
|
+
import { GridBaseRow } from './types';
|
|
8
8
|
|
|
9
9
|
export interface GridPopoverHookProps<TData> {
|
|
10
10
|
className: string | undefined;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { LuiIcon } from '@linzjs/lui';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { ReactElement, useCallback, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
import { typedEntries } from '../lui/tsUtils';
|
|
6
|
+
import { MenuDivider, MenuHeader, MenuItem } from '../react-menu3';
|
|
7
|
+
import { GridContextMenuComponentProps } from './gridHook';
|
|
8
|
+
import { CopyOptionsKey, gridCopyOptions } from './gridHook/useGridCopySettings';
|
|
9
|
+
import { GridBaseRow } from './types';
|
|
10
|
+
|
|
11
|
+
export interface CopyOptionsContext {
|
|
12
|
+
onCopy: (type?: CopyOptionsKey) => void;
|
|
13
|
+
copyType: CopyOptionsKey;
|
|
14
|
+
setCopyType: (copyType: CopyOptionsKey) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const GridRangeSelectContextMenu = <TData extends GridBaseRow>({
|
|
18
|
+
event,
|
|
19
|
+
context,
|
|
20
|
+
}: GridContextMenuComponentProps<TData, CopyOptionsContext>): ReactElement => {
|
|
21
|
+
const developerContextMenu: boolean =
|
|
22
|
+
!!(event?.event as { ctrlKey?: boolean })?.ctrlKey && !!(event?.event as { shiftKey?: boolean })?.shiftKey;
|
|
23
|
+
const onCopy = useMemo(() => context?.onCopy, [context?.onCopy]);
|
|
24
|
+
const onClick = useCallback(
|
|
25
|
+
(type: CopyOptionsKey) => {
|
|
26
|
+
onCopy?.(type);
|
|
27
|
+
},
|
|
28
|
+
[onCopy],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<MenuHeader>Copy as</MenuHeader>
|
|
34
|
+
{typedEntries(gridCopyOptions).map(([key, { icon, text, developer }]) => {
|
|
35
|
+
return (
|
|
36
|
+
(!developer || developerContextMenu) && (
|
|
37
|
+
<MenuItem key={key} onClick={() => void onClick(key)}>
|
|
38
|
+
<div className={'copyMenuMenuItem'}>
|
|
39
|
+
<LuiIcon name={icon} alt={text} size={'md'} />
|
|
40
|
+
<div className={'copyMenuMenuItem__text'}>{text}</div>
|
|
41
|
+
</div>
|
|
42
|
+
</MenuItem>
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
})}
|
|
46
|
+
<MenuDivider />
|
|
47
|
+
<MenuHeader>Set copy default</MenuHeader>
|
|
48
|
+
{typedEntries(gridCopyOptions).map(([key, { text, developer }]) => {
|
|
49
|
+
return (
|
|
50
|
+
!developer && (
|
|
51
|
+
<MenuItem
|
|
52
|
+
key={'default_' + key}
|
|
53
|
+
onClick={(e) => {
|
|
54
|
+
context?.setCopyType(key);
|
|
55
|
+
e.keepOpen = true;
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
<div
|
|
59
|
+
className={clsx(
|
|
60
|
+
'copyMenuMenuItem',
|
|
61
|
+
context?.copyType === key ? '' : 'copyMenuMenuItem__buttonDefault--hidden',
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
<LuiIcon name={'ic_tick'} alt={'CSV'} size={'sm'} />
|
|
65
|
+
<div className={'copyMenuMenuItem__text'}>{text}</div>
|
|
66
|
+
</div>
|
|
67
|
+
</MenuItem>
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -4,7 +4,7 @@ import clsx, { ClassValue } from 'clsx';
|
|
|
4
4
|
import { ReactElement, useMemo, useState } from 'react';
|
|
5
5
|
|
|
6
6
|
import { GridFilterExternal } from '../../contexts/GridContext';
|
|
7
|
-
import { GridBaseRow } from '../
|
|
7
|
+
import { GridBaseRow } from '../types';
|
|
8
8
|
import { useGridFilter } from './useGridFilter';
|
|
9
9
|
|
|
10
10
|
export interface GridFilterButtonsOption<TData extends GridBaseRow> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { GridFilterExternal, useGridContext } from '../../contexts/GridContext';
|
|
4
|
-
import { GridBaseRow } from '../
|
|
4
|
+
import { GridBaseRow } from '../types';
|
|
5
5
|
|
|
6
6
|
export const useGridFilter = <TData extends GridBaseRow>(filter: GridFilterExternal<TData> | undefined) => {
|
|
7
7
|
const { addExternalFilter, removeExternalFilter } = useGridContext<TData>();
|
|
@@ -9,11 +9,11 @@ import { usePrevious } from '../../lui/reactUtils';
|
|
|
9
9
|
import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from '../../react-menu3';
|
|
10
10
|
import { ClickEvent } from '../../react-menu3/types';
|
|
11
11
|
import { textMatch } from '../../utils/textMatcher';
|
|
12
|
-
import { isNotEmpty } from '../../utils/util';
|
|
12
|
+
import { isNotEmpty, MaybePromise } from '../../utils/util';
|
|
13
13
|
import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
|
|
14
|
-
import { GridBaseRow } from '../Grid';
|
|
15
14
|
import { CellEditorCommon } from '../GridCell';
|
|
16
15
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
16
|
+
import { GridBaseRow } from '../types';
|
|
17
17
|
|
|
18
18
|
export interface GridPopoutEditDropDownSelectedItem<TData extends GridBaseRow, TOption> {
|
|
19
19
|
// Note the row that was clicked on will be first
|
|
@@ -47,8 +47,6 @@ export const MenuHeaderItem = (title: string) => {
|
|
|
47
47
|
|
|
48
48
|
export type SelectOption<TOptionValue = any> = FinalSelectOption<TOptionValue>;
|
|
49
49
|
|
|
50
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
51
|
-
|
|
52
50
|
export interface GridFormDropDownProps<TData extends GridBaseRow, TOptionValue> extends CellEditorCommon {
|
|
53
51
|
// This overrides CellEditorCommon to provide some common class options
|
|
54
52
|
className?: // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
@@ -3,9 +3,9 @@ import { useCallback, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
4
4
|
import { TextInputFormatted } from '../../lui/TextInputFormatted';
|
|
5
5
|
import { bearingNumberParser, bearingStringValidator } from '../../utils/bearing';
|
|
6
|
-
import { GridBaseRow } from '../Grid';
|
|
7
6
|
import { CellEditorCommon } from '../GridCell';
|
|
8
7
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
8
|
+
import { GridBaseRow } from '../types';
|
|
9
9
|
|
|
10
10
|
export interface GridFormEditBearingProps<TData extends GridBaseRow> extends CellEditorCommon {
|
|
11
11
|
formatValue?: (value: any) => string;
|
|
@@ -3,9 +3,9 @@ import { ReactElement, useEffect, useState } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
5
5
|
import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
|
|
6
|
-
import { GridBaseRow } from '../Grid';
|
|
7
6
|
import { CellEditorCommon } from '../GridCell';
|
|
8
7
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
8
|
+
import { GridBaseRow } from '../types';
|
|
9
9
|
|
|
10
10
|
export interface GridFormMessageProps<TData extends GridBaseRow> extends CellEditorCommon {
|
|
11
11
|
message: (selectedRows: TData[]) => Promise<string | ReactElement> | string | ReactElement;
|
|
@@ -21,10 +21,10 @@ import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from '../../react-me
|
|
|
21
21
|
import { ClickEvent } from '../../react-menu3/types';
|
|
22
22
|
import { textMatch } from '../../utils/textMatcher';
|
|
23
23
|
import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
|
|
24
|
-
import { GridBaseRow } from '../Grid';
|
|
25
24
|
import { CellEditorCommon } from '../GridCell';
|
|
26
25
|
import { GridIcon } from '../GridIcon';
|
|
27
26
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
27
|
+
import { GridBaseRow } from '../types';
|
|
28
28
|
import { MenuSeparatorString } from './GridFormDropDown';
|
|
29
29
|
|
|
30
30
|
type HeaderGroupType = Record<string, MultiSelectOption[]> | undefined;
|
|
@@ -5,10 +5,10 @@ import { ReactElement, useCallback, useEffect, useRef, useState } from 'react';
|
|
|
5
5
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
6
6
|
import { MenuItem } from '../../react-menu3';
|
|
7
7
|
import { ClickEvent } from '../../react-menu3/types';
|
|
8
|
-
import { GridBaseRow } from '../Grid';
|
|
9
8
|
import { CellEditorCommon } from '../GridCell';
|
|
10
9
|
import { GridIcon } from '../GridIcon';
|
|
11
10
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
11
|
+
import { GridBaseRow } from '../types';
|
|
12
12
|
|
|
13
13
|
export interface MultiSelectGridOption {
|
|
14
14
|
value: any;
|
|
@@ -5,10 +5,11 @@ import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
|
5
5
|
import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
|
|
6
6
|
import { FocusableItem, MenuDivider, MenuItem, SubMenu } from '../../react-menu3';
|
|
7
7
|
import { ClickEvent } from '../../react-menu3/types';
|
|
8
|
+
import { MaybePromise } from '../../utils/util';
|
|
8
9
|
import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
|
|
9
|
-
import { GridBaseRow } from '../Grid';
|
|
10
10
|
import { CellEditorCommon } from '../GridCell';
|
|
11
11
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
12
|
+
import { GridBaseRow } from '../types';
|
|
12
13
|
|
|
13
14
|
export interface GridFormPopoverMenuProps<TData extends GridBaseRow> extends CellEditorCommon {
|
|
14
15
|
options: (selectedRows: TData[]) => Promise<MenuOption<TData>[]> | MenuOption<TData>[];
|
|
@@ -33,7 +34,7 @@ export interface SelectedMenuOptionResult<TData extends GridBaseRow> extends Men
|
|
|
33
34
|
export interface MenuOption<TData extends GridBaseRow> {
|
|
34
35
|
label: ReactElement | string | MenuSeparatorType;
|
|
35
36
|
subMenu?: () => ReactElement;
|
|
36
|
-
action?: (props: { selectedRows: TData[]; menuOption: SelectedMenuOptionResult<TData> }) =>
|
|
37
|
+
action?: (props: { selectedRows: TData[]; menuOption: SelectedMenuOptionResult<TData> }) => MaybePromise<void>;
|
|
37
38
|
disabled?: string | boolean;
|
|
38
39
|
hidden?: boolean;
|
|
39
40
|
subComponent?: (props: any) => ReactElement;
|
|
@@ -4,8 +4,8 @@ import { ReactElement, useCallback, useContext, useEffect } from 'react';
|
|
|
4
4
|
import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
|
|
5
5
|
import { TextAreaInput } from '../../lui/TextAreaInput';
|
|
6
6
|
import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
|
|
7
|
-
import { GridBaseRow } from '../Grid';
|
|
8
7
|
import { CellEditorCommon } from '../GridCell';
|
|
8
|
+
import { GridBaseRow } from '../types';
|
|
9
9
|
|
|
10
10
|
export interface GridSubComponentTextAreaProps<TData extends GridBaseRow>
|
|
11
11
|
extends TextInputValidatorProps<TData>,
|
|
@@ -3,8 +3,8 @@ import { ReactElement, useCallback, useContext, useEffect } from 'react';
|
|
|
3
3
|
import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
|
|
4
4
|
import { TextInputFormatted } from '../../lui/TextInputFormatted';
|
|
5
5
|
import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
|
|
6
|
-
import { GridBaseRow } from '../Grid';
|
|
7
6
|
import { CellEditorCommon } from '../GridCell';
|
|
7
|
+
import { GridBaseRow } from '../types';
|
|
8
8
|
|
|
9
9
|
export interface GridFormSubComponentTextInputProps<TData extends GridBaseRow>
|
|
10
10
|
extends TextInputValidatorProps<TData>,
|
|
@@ -3,9 +3,9 @@ import { ReactElement, useCallback, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
4
4
|
import { TextAreaInput } from '../../lui/TextAreaInput';
|
|
5
5
|
import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
|
|
6
|
-
import { GridBaseRow } from '../Grid';
|
|
7
6
|
import { CellEditorCommon } from '../GridCell';
|
|
8
7
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
8
|
+
import { GridBaseRow } from '../types';
|
|
9
9
|
|
|
10
10
|
export interface GridFormTextAreaProps<TData extends GridBaseRow>
|
|
11
11
|
extends TextInputValidatorProps<TData>,
|
|
@@ -3,9 +3,9 @@ import { useCallback, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
4
4
|
import { TextInputFormatted } from '../../lui/TextInputFormatted';
|
|
5
5
|
import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
|
|
6
|
-
import { GridBaseRow } from '../Grid';
|
|
7
6
|
import { CellEditorCommon } from '../GridCell';
|
|
8
7
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
8
|
+
import { GridBaseRow } from '../types';
|
|
9
9
|
|
|
10
10
|
export interface GridFormTextInputProps<TData extends GridBaseRow>
|
|
11
11
|
extends TextInputValidatorProps<TData>,
|
|
@@ -1,29 +1,37 @@
|
|
|
1
|
+
import '../../styles/ContextMenu.scss';
|
|
2
|
+
|
|
1
3
|
import { ColDef } from 'ag-grid-community';
|
|
2
4
|
import { CellContextMenuEvent } from 'ag-grid-community';
|
|
3
5
|
import { ReactElement, useCallback, useContext, useRef, useState } from 'react';
|
|
4
6
|
|
|
5
7
|
import { GridContext } from '../../contexts/GridContext';
|
|
6
8
|
import { ControlledMenu } from '../../react-menu3';
|
|
7
|
-
import { GridBaseRow } from '../
|
|
9
|
+
import { GridBaseRow } from '../types';
|
|
8
10
|
|
|
9
|
-
export interface GridContextMenuComponentProps<TData extends GridBaseRow> {
|
|
11
|
+
export interface GridContextMenuComponentProps<TData extends GridBaseRow, Context extends object = object> {
|
|
10
12
|
selectedRows: TData[];
|
|
11
13
|
clickedRow: TData;
|
|
12
14
|
colDef: ColDef;
|
|
13
15
|
close: () => void;
|
|
16
|
+
event?: CellContextMenuEvent;
|
|
17
|
+
context?: Context;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
export type GridContextMenuComponent<TData extends GridBaseRow> = (
|
|
17
|
-
props: GridContextMenuComponentProps<TData>,
|
|
20
|
+
export type GridContextMenuComponent<TData extends GridBaseRow, Context extends object = object> = (
|
|
21
|
+
props: GridContextMenuComponentProps<TData, Context>,
|
|
18
22
|
) => ReactElement | null;
|
|
19
23
|
|
|
20
|
-
export
|
|
24
|
+
export interface useGridContextMenuProps<TData extends GridBaseRow, Context extends object = object> {
|
|
25
|
+
contextMenuSelectRow?: boolean;
|
|
26
|
+
contextMenu?: GridContextMenuComponent<TData, Context>;
|
|
27
|
+
context?: Context;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const useGridContextMenu = <TData extends GridBaseRow, Context extends object = object>({
|
|
21
31
|
contextMenuSelectRow,
|
|
22
32
|
contextMenu: ContextMenu,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
contextMenu?: GridContextMenuComponent<TData>;
|
|
26
|
-
}) => {
|
|
33
|
+
context,
|
|
34
|
+
}: useGridContextMenuProps<TData, Context>) => {
|
|
27
35
|
const { redrawRows, prePopupOps, resetFocusedCellAfterCellEditing, getSelectedRows } = useContext(GridContext);
|
|
28
36
|
|
|
29
37
|
const [isOpen, setOpen] = useState(false);
|
|
@@ -33,6 +41,7 @@ export const useGridContextMenu = <TData extends GridBaseRow>({
|
|
|
33
41
|
const clickedColDefRef = useRef<ColDef>(null!);
|
|
34
42
|
const selectedRowsRef = useRef<any[]>([]);
|
|
35
43
|
const clickedRowRef = useRef<any>(null);
|
|
44
|
+
const eventRef = useRef<CellContextMenuEvent | undefined>(undefined);
|
|
36
45
|
|
|
37
46
|
const openMenu = useCallback(
|
|
38
47
|
(e: PointerEvent | null | undefined) => {
|
|
@@ -59,6 +68,7 @@ export const useGridContextMenu = <TData extends GridBaseRow>({
|
|
|
59
68
|
clickedColDefRef.current = event.colDef;
|
|
60
69
|
selectedRowsRef.current = getSelectedRows();
|
|
61
70
|
clickedRowRef.current = event.data;
|
|
71
|
+
eventRef.current = event;
|
|
62
72
|
|
|
63
73
|
// This is actually a pointer event
|
|
64
74
|
openMenu(event.event as PointerEvent);
|
|
@@ -69,9 +79,10 @@ export const useGridContextMenu = <TData extends GridBaseRow>({
|
|
|
69
79
|
return {
|
|
70
80
|
openMenu,
|
|
71
81
|
cellContextMenu,
|
|
72
|
-
|
|
82
|
+
contextMenuComponent: ContextMenu ? (
|
|
73
83
|
<>
|
|
74
84
|
<ControlledMenu
|
|
85
|
+
className={'GridContextMenu'}
|
|
75
86
|
anchorPoint={anchorPoint}
|
|
76
87
|
state={isOpen ? 'open' : 'closed'}
|
|
77
88
|
direction="right"
|
|
@@ -82,7 +93,9 @@ export const useGridContextMenu = <TData extends GridBaseRow>({
|
|
|
82
93
|
selectedRows={selectedRowsRef.current}
|
|
83
94
|
clickedRow={clickedRowRef.current}
|
|
84
95
|
colDef={clickedColDefRef.current}
|
|
96
|
+
event={eventRef.current}
|
|
85
97
|
close={closeMenu}
|
|
98
|
+
context={context}
|
|
86
99
|
/>
|
|
87
100
|
)}
|
|
88
101
|
</ControlledMenu>
|