@linzjs/step-ag-grid 32.7.0 → 33.0.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/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
- package/dist/step-ag-grid.cjs +115 -181
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +115 -181
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +17 -17
- package/src/components/Grid.tsx +6 -4
- package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
- package/src/components/gridHook/useGridRangeSelection.ts +8 -6
- package/src/react-menu3/components/ControlledMenu.tsx +5 -3
- package/src/react-menu3/components/MenuList.tsx +6 -3
- package/src/react-menu3/hooks/useItems.ts +1 -1
- package/src/stories/components/ActionButton.stories.tsx +12 -11
- package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
- package/src/stories/grid/GridCopy.stories.tsx +38 -35
- package/src/stories/grid/GridDragRow.stories.tsx +41 -36
- package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
- package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
- package/src/stories/grid/GridInlineText.stories.tsx +42 -35
- package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
- package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
- package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
- package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
- package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
- package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
- package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
- package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
- package/src/stories/grid/GridSorting.stories.tsx +81 -79
- package/src/stories/grid/GridViewList.stories.tsx +31 -26
- package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
- package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
- package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
- package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
- package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
- package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
- package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
- package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
- package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
- package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
- package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
- package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
- package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
- package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
- package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
- package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
- package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
- package/src/styles/GridLoadableCell.scss +1 -1
- package/src/utils/useSharedInterval.ts +3 -3
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@linzjs/step-ag-grid",
|
|
3
3
|
"repository": "github:linz/step-ag-grid.git",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "33.0.0",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"aggrid",
|
|
8
8
|
"ag-grid",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"build-storybook": "storybook build",
|
|
60
60
|
"deploy-storybook": "npx --yes -p @storybook/storybook-deployer storybook-to-ghpages",
|
|
61
61
|
"chromatic": "chromatic --exit-zero-on-changes",
|
|
62
|
-
"update": "npx npm-check-updates -i --format group -c
|
|
62
|
+
"update": "npx npm-check-updates -i --format group -c 7d",
|
|
63
63
|
"prepare": "husky"
|
|
64
64
|
},
|
|
65
65
|
"browserslist": {
|
|
@@ -75,19 +75,19 @@
|
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@chromatic-com/storybook": "^5.3.
|
|
79
|
-
"@linzjs/lui": "^
|
|
80
|
-
"@linzjs/windows": "^
|
|
78
|
+
"@chromatic-com/storybook": "^5.3.1",
|
|
79
|
+
"@linzjs/lui": "^27.0.0",
|
|
80
|
+
"@linzjs/windows": "^16.1.0",
|
|
81
81
|
"@rollup/plugin-commonjs": "^29.0.3",
|
|
82
82
|
"@rollup/plugin-json": "^6.1.0",
|
|
83
83
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
84
84
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
85
|
-
"@storybook/addon-docs": "^10.
|
|
86
|
-
"@storybook/addon-links": "^10.
|
|
87
|
-
"@storybook/react-vite": "^10.
|
|
85
|
+
"@storybook/addon-docs": "^10.6.0",
|
|
86
|
+
"@storybook/addon-links": "^10.6.0",
|
|
87
|
+
"@storybook/react-vite": "^10.6.0",
|
|
88
88
|
"@testing-library/dom": "^10.4.1",
|
|
89
|
-
"@testing-library/react": "16.3.
|
|
90
|
-
"@testing-library/user-event": "^14.6.
|
|
89
|
+
"@testing-library/react": "16.3.3",
|
|
90
|
+
"@testing-library/user-event": "^14.6.7",
|
|
91
91
|
"@types/debounce-promise": "^3.1.9",
|
|
92
92
|
"@types/jest": "^30.0.0",
|
|
93
93
|
"@types/jsdom": "^28.0.3",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@types/node": "^24.13.3",
|
|
96
96
|
"@types/react": "^18.3.31",
|
|
97
97
|
"@types/react-dom": "^18.3.7",
|
|
98
|
-
"@vitejs/plugin-react": "6.
|
|
98
|
+
"@vitejs/plugin-react": "6.1.1",
|
|
99
99
|
"@vitest/ui": "^4.1.11",
|
|
100
100
|
"chromatic": "^17.8.0",
|
|
101
101
|
"cross-env": "^10.1.0",
|
|
@@ -103,18 +103,18 @@
|
|
|
103
103
|
"jsdom": "29.1.1",
|
|
104
104
|
"lodash-es": "^4.18.1",
|
|
105
105
|
"npm-run-all": "^4.1.5",
|
|
106
|
-
"oxfmt": "^0.
|
|
107
|
-
"oxlint": "^1.
|
|
108
|
-
"postcss": "^8.5.
|
|
106
|
+
"oxfmt": "^0.67.0",
|
|
107
|
+
"oxlint": "^1.82.0",
|
|
108
|
+
"postcss": "^8.5.28",
|
|
109
109
|
"postcss-scss": "^4.0.9",
|
|
110
110
|
"react": ">=19",
|
|
111
111
|
"react-dom": "^19.2.8",
|
|
112
|
-
"rollup": "4.
|
|
112
|
+
"rollup": "4.63.1",
|
|
113
113
|
"rollup-plugin-copy": "^3.5.0",
|
|
114
114
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
115
115
|
"rollup-plugin-postcss": "^4.0.2",
|
|
116
|
-
"sass": "^1.
|
|
117
|
-
"storybook": "^10.
|
|
116
|
+
"sass": "^1.104.0",
|
|
117
|
+
"storybook": "^10.6.0",
|
|
118
118
|
"typescript": "^7.0.2",
|
|
119
119
|
"vite": "^8.2.2",
|
|
120
120
|
"vitest": "^4.1.11"
|
package/src/components/Grid.tsx
CHANGED
|
@@ -601,7 +601,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
601
601
|
if (sizeColumns === 'fit') {
|
|
602
602
|
delay(() => {
|
|
603
603
|
// Don't update if currently editing, that will stop the edit
|
|
604
|
-
if (!anyUpdating() &&
|
|
604
|
+
if (!anyUpdating() && !gridDivRef.current?.ownerDocument.querySelectorAll('.szh-menu--state-open').length) {
|
|
605
605
|
if (!api.isDestroyed()) {
|
|
606
606
|
api.redrawRows();
|
|
607
607
|
}
|
|
@@ -863,16 +863,18 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
863
863
|
const startDragYRef = useRef<number | null>(null);
|
|
864
864
|
|
|
865
865
|
const clearHighlightRowClasses = useCallback(() => {
|
|
866
|
-
|
|
866
|
+
const gridRoot = gridDivRef.current;
|
|
867
|
+
gridRoot?.querySelectorAll(`.ag-row-highlight-above`)?.forEach((el) => {
|
|
867
868
|
el.classList.remove('ag-row-highlight-above');
|
|
868
869
|
});
|
|
869
|
-
|
|
870
|
+
gridRoot?.querySelectorAll(`.ag-row-highlight-below`)?.forEach((el) => {
|
|
870
871
|
el.classList.remove('ag-row-highlight-below');
|
|
871
872
|
});
|
|
872
873
|
}, []);
|
|
873
874
|
|
|
874
875
|
const clearDragRowClasses = useCallback(() => {
|
|
875
|
-
|
|
876
|
+
const gridRoot = gridDivRef.current;
|
|
877
|
+
gridRoot?.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
|
|
876
878
|
el.classList.remove('ag-row-dragging');
|
|
877
879
|
});
|
|
878
880
|
}, []);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './GridFilterColumnsMultiSelect.scss';
|
|
2
2
|
|
|
3
3
|
import { LuiCheckboxInput } from '@linzjs/lui';
|
|
4
|
-
import type { IDoesFilterPassParams,
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import type { IDoesFilterPassParams, IFilterParams } from 'ag-grid-community';
|
|
5
|
+
import { CustomFilterProps, useGridFilter } from 'ag-grid-react';
|
|
6
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
8
|
export interface CheckboxMultiFilterParams extends IFilterParams {
|
|
9
9
|
labels?: Record<string, string>;
|
|
@@ -15,28 +15,106 @@ export interface CheckboxMultiFilterModel {
|
|
|
15
15
|
values: string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface FilterUIProps {
|
|
19
|
-
allValues: string[];
|
|
20
|
-
selected: Set<string>;
|
|
21
|
-
labels: Record<string, string>;
|
|
22
|
-
labelFormatter?: (value: string) => string;
|
|
23
|
-
onToggleAll: (checked: boolean) => void;
|
|
24
|
-
onToggleOne: (value: string, checked: boolean) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
18
|
const EMPTY_KEY = '__EMPTY__';
|
|
28
19
|
const DEFAULT_EMPTY_LABEL = '-';
|
|
29
20
|
const filterStateMap = new Map<string, boolean>();
|
|
30
21
|
const filterClickCountMap = new Map<string, number>();
|
|
31
22
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
const normalizeCellValue = (value: unknown): string => {
|
|
24
|
+
if (typeof value === 'string') return value.trim() === '' ? EMPTY_KEY : value;
|
|
25
|
+
return EMPTY_KEY;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const loadFieldValues = (params: CheckboxMultiFilterParams): string[] => {
|
|
29
|
+
const field = params.colDef.field as string;
|
|
30
|
+
const values = new Set<string>();
|
|
31
|
+
|
|
32
|
+
params.api.forEachNode((node) => {
|
|
33
|
+
const data = node.data ?? {};
|
|
34
|
+
values.add(normalizeCellValue((data as Record<string, unknown>)[field]));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { customOrder } = params;
|
|
38
|
+
const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
|
|
39
|
+
|
|
40
|
+
return Array.from(values).sort((a, b) => {
|
|
41
|
+
if (orderMap) {
|
|
42
|
+
const aIdx = orderMap.get(a) ?? Infinity;
|
|
43
|
+
const bIdx = orderMap.get(b) ?? Infinity;
|
|
44
|
+
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
|
|
48
|
+
if (b === EMPTY_KEY) return 1;
|
|
49
|
+
return a.localeCompare(b);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type GridFilterColumnsMultiSelectProps = CustomFilterProps<any, any, CheckboxMultiFilterModel> &
|
|
54
|
+
CheckboxMultiFilterParams;
|
|
55
|
+
|
|
56
|
+
export const GridFilterColumnsMultiSelect = (props: GridFilterColumnsMultiSelectProps) => {
|
|
57
|
+
const { model, onModelChange, colDef, column, labels: labelsParam, labelFormatter } = props;
|
|
58
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
59
|
+
|
|
60
|
+
// Loaded once when the filter is first opened, matching the previous IFilterComp's init() behaviour.
|
|
61
|
+
const allValues = useMemo(() => loadFieldValues(props), []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
62
|
+
const labels = useMemo<Record<string, string>>(
|
|
63
|
+
() => ({ [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labelsParam }),
|
|
64
|
+
[labelsParam],
|
|
65
|
+
);
|
|
66
|
+
const selected = useMemo(() => new Set(model?.values ?? allValues), [model, allValues]);
|
|
67
|
+
|
|
68
|
+
useGridFilter({
|
|
69
|
+
doesFilterPass: (p: IDoesFilterPassParams): boolean => {
|
|
70
|
+
if (selected.size === 0) return false;
|
|
71
|
+
|
|
72
|
+
const field = colDef.field as string;
|
|
73
|
+
if (!p.data || typeof p.data !== 'object') return selected.has(EMPTY_KEY);
|
|
74
|
+
|
|
75
|
+
const raw = (p.data as Record<string, unknown>)[field];
|
|
76
|
+
return selected.has(normalizeCellValue(raw));
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// AG Grid's header filter button re-opens the popup on every click; intercept it so a second
|
|
81
|
+
// click, while the popup is already open, closes it instead. Scoped via containerRef's
|
|
82
|
+
// ownerDocument rather than the global `document` so it keeps working when the grid is popped out.
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const ownerDocument = containerRef.current?.ownerDocument;
|
|
85
|
+
const columnId = column.getColId();
|
|
86
|
+
const filterButton = ownerDocument?.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
|
|
87
|
+
if (!filterButton) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const listener = (e: Event) => {
|
|
92
|
+
const clickCount = filterClickCountMap.get(columnId) || 0;
|
|
93
|
+
filterClickCountMap.set(columnId, clickCount + 1);
|
|
94
|
+
|
|
95
|
+
if (clickCount === 0) {
|
|
96
|
+
e.stopImmediatePropagation();
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
props.api.hidePopupMenu();
|
|
99
|
+
filterStateMap.set(columnId, false);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const isOpen = filterStateMap.get(columnId) || false;
|
|
104
|
+
if (isOpen) {
|
|
105
|
+
e.stopImmediatePropagation();
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
props.api.hidePopupMenu();
|
|
108
|
+
filterStateMap.set(columnId, false);
|
|
109
|
+
} else {
|
|
110
|
+
filterStateMap.set(columnId, true);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
filterButton.addEventListener('click', listener, true);
|
|
115
|
+
return () => filterButton.removeEventListener('click', listener, true);
|
|
116
|
+
}, [column, props.api]);
|
|
117
|
+
|
|
40
118
|
const allChecked = allValues.length > 0 && selected.size === allValues.length;
|
|
41
119
|
|
|
42
120
|
const getDisplayLabel = (raw: string): string => {
|
|
@@ -44,15 +122,19 @@ const FilterUI: React.FC<FilterUIProps> = ({
|
|
|
44
122
|
return labelFormatter ? labelFormatter(base) : base;
|
|
45
123
|
};
|
|
46
124
|
|
|
125
|
+
const applySelection = (next: Set<string>): void => {
|
|
126
|
+
onModelChange(next.size === allValues.length ? null : { values: Array.from(next) });
|
|
127
|
+
};
|
|
128
|
+
|
|
47
129
|
return (
|
|
48
|
-
<div className="GridFilterColsMultiSelect">
|
|
130
|
+
<div className="GridFilterColsMultiSelect" ref={containerRef}>
|
|
49
131
|
<span className="LuiSelect-label-text">Filter column</span>
|
|
50
132
|
<LuiCheckboxInput
|
|
51
133
|
className="LuiCheckboxInput-selectAll"
|
|
52
134
|
label={'Select All'}
|
|
53
135
|
value="true"
|
|
54
136
|
isChecked={allChecked}
|
|
55
|
-
onChange={(e) =>
|
|
137
|
+
onChange={(e) => applySelection(e.target.checked ? new Set(allValues) : new Set())}
|
|
56
138
|
/>
|
|
57
139
|
{allValues.map((val) => (
|
|
58
140
|
<LuiCheckboxInput
|
|
@@ -61,189 +143,18 @@ const FilterUI: React.FC<FilterUIProps> = ({
|
|
|
61
143
|
label={getDisplayLabel(val)}
|
|
62
144
|
value={val}
|
|
63
145
|
isChecked={selected.has(val)}
|
|
64
|
-
onChange={(e) =>
|
|
146
|
+
onChange={(e) => {
|
|
147
|
+
const next = new Set(selected);
|
|
148
|
+
if (e.target.checked) next.add(val);
|
|
149
|
+
else next.delete(val);
|
|
150
|
+
applySelection(next);
|
|
151
|
+
}}
|
|
65
152
|
/>
|
|
66
153
|
))}
|
|
67
154
|
</div>
|
|
68
155
|
);
|
|
69
156
|
};
|
|
70
157
|
|
|
71
|
-
export class GridFilterColumnsMultiSelect implements IFilterComp {
|
|
72
|
-
private params!: CheckboxMultiFilterParams;
|
|
73
|
-
private selectedValues = new Set<string>();
|
|
74
|
-
private labels: Record<string, string> = {};
|
|
75
|
-
private allValues: string[] = [];
|
|
76
|
-
private gui!: HTMLElement;
|
|
77
|
-
private labelFormatter?: (value: string) => string;
|
|
78
|
-
private reactRoot: Root | null = null;
|
|
79
|
-
private filterButtonClickListener: ((e: Event) => void) | null = null;
|
|
80
|
-
private filterButton: Element | null = null;
|
|
81
|
-
|
|
82
|
-
private normalizeCellValue(value: unknown): string {
|
|
83
|
-
if (typeof value === 'string') return value.trim() === '' ? EMPTY_KEY : value;
|
|
84
|
-
return EMPTY_KEY;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private loadFieldValues(): string[] {
|
|
88
|
-
const field = this.params.colDef.field as string;
|
|
89
|
-
const values = new Set<string>();
|
|
90
|
-
|
|
91
|
-
this.params.api.forEachNode((node) => {
|
|
92
|
-
const data = node.data ?? {};
|
|
93
|
-
const raw = (data as Record<string, unknown>)[field];
|
|
94
|
-
const norm = this.normalizeCellValue(raw);
|
|
95
|
-
values.add(norm);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const { customOrder } = this.params;
|
|
99
|
-
const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
|
|
100
|
-
|
|
101
|
-
return Array.from(values).sort((a, b) => {
|
|
102
|
-
if (orderMap) {
|
|
103
|
-
const aIdx = orderMap.get(a) ?? Infinity;
|
|
104
|
-
const bIdx = orderMap.get(b) ?? Infinity;
|
|
105
|
-
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
|
|
109
|
-
if (b === EMPTY_KEY) return 1;
|
|
110
|
-
return a.localeCompare(b);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
init(params: CheckboxMultiFilterParams): void {
|
|
115
|
-
this.params = params;
|
|
116
|
-
this.labels = { ...params.labels };
|
|
117
|
-
this.labelFormatter = params.labelFormatter;
|
|
118
|
-
|
|
119
|
-
if (!(EMPTY_KEY in this.labels)) {
|
|
120
|
-
this.labels[EMPTY_KEY] = DEFAULT_EMPTY_LABEL;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.allValues = this.loadFieldValues();
|
|
124
|
-
this.selectedValues = new Set(this.allValues);
|
|
125
|
-
|
|
126
|
-
this.gui = document.createElement('div');
|
|
127
|
-
this.reactRoot = createRoot(this.gui);
|
|
128
|
-
this.render();
|
|
129
|
-
this.setupFilterButtonListener();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private setupFilterButtonListener(): void {
|
|
133
|
-
const columnId = this.params.column.getColId();
|
|
134
|
-
this.filterButton = document.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
|
|
135
|
-
|
|
136
|
-
if (this.filterButton) {
|
|
137
|
-
this.filterButtonClickListener = (e: Event) => {
|
|
138
|
-
const clickCount = filterClickCountMap.get(columnId) || 0;
|
|
139
|
-
filterClickCountMap.set(columnId, clickCount + 1);
|
|
140
|
-
|
|
141
|
-
if (clickCount === 0) {
|
|
142
|
-
e.stopImmediatePropagation();
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
this.params.api.hidePopupMenu();
|
|
145
|
-
filterStateMap.set(columnId, false);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const isOpen = filterStateMap.get(columnId) || false;
|
|
150
|
-
if (isOpen) {
|
|
151
|
-
e.stopImmediatePropagation();
|
|
152
|
-
e.preventDefault();
|
|
153
|
-
this.params.api.hidePopupMenu();
|
|
154
|
-
filterStateMap.set(columnId, false);
|
|
155
|
-
} else {
|
|
156
|
-
filterStateMap.set(columnId, true);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
this.filterButton.addEventListener('click', this.filterButtonClickListener, true);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private render(): void {
|
|
165
|
-
if (!this.reactRoot) return;
|
|
166
|
-
this.reactRoot.render(
|
|
167
|
-
<FilterUI
|
|
168
|
-
allValues={this.allValues}
|
|
169
|
-
selected={this.selectedValues}
|
|
170
|
-
labels={this.labels}
|
|
171
|
-
labelFormatter={this.labelFormatter}
|
|
172
|
-
onToggleAll={this.handleToggleAll.bind(this)}
|
|
173
|
-
onToggleOne={this.handleToggleOne.bind(this)}
|
|
174
|
-
/>,
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private handleToggleAll(checked: boolean): void {
|
|
179
|
-
if (checked) {
|
|
180
|
-
this.allValues.forEach((val) => this.selectedValues.add(val));
|
|
181
|
-
} else {
|
|
182
|
-
this.selectedValues.clear();
|
|
183
|
-
}
|
|
184
|
-
this.render();
|
|
185
|
-
this.params.filterChangedCallback();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private handleToggleOne(value: string, checked: boolean): void {
|
|
189
|
-
if (checked) {
|
|
190
|
-
this.selectedValues.add(value);
|
|
191
|
-
} else {
|
|
192
|
-
this.selectedValues.delete(value);
|
|
193
|
-
}
|
|
194
|
-
this.render();
|
|
195
|
-
this.params.filterChangedCallback();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
getGui(): HTMLElement {
|
|
199
|
-
return this.gui;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
isFilterActive(): boolean {
|
|
203
|
-
return this.selectedValues.size !== this.allValues.length;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
doesFilterPass(p: IDoesFilterPassParams): boolean {
|
|
207
|
-
if (this.selectedValues.size === 0) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const field = this.params.colDef.field as string;
|
|
212
|
-
if (!p.data || typeof p.data !== 'object') {
|
|
213
|
-
return this.selectedValues.has(EMPTY_KEY);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const raw = (p.data as Record<string, unknown>)[field];
|
|
217
|
-
const norm = this.normalizeCellValue(raw);
|
|
218
|
-
return this.selectedValues.has(norm);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
getModel(): CheckboxMultiFilterModel | null {
|
|
222
|
-
if (this.selectedValues.size !== this.allValues.length) {
|
|
223
|
-
return { values: Array.from(this.selectedValues) };
|
|
224
|
-
}
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
setModel(model: CheckboxMultiFilterModel | null): void {
|
|
229
|
-
this.selectedValues = new Set(model?.values || []);
|
|
230
|
-
this.render();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
destroy(): void {
|
|
234
|
-
if (this.filterButtonClickListener && this.filterButton) {
|
|
235
|
-
this.filterButton.removeEventListener('click', this.filterButtonClickListener, true);
|
|
236
|
-
this.filterButtonClickListener = null;
|
|
237
|
-
this.filterButton = null;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (this.reactRoot) {
|
|
241
|
-
this.reactRoot.unmount();
|
|
242
|
-
this.reactRoot = null;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
158
|
export const createCheckboxMultiFilterParams = (
|
|
248
159
|
labels: Record<string, string> = {},
|
|
249
160
|
labelFormatter?: (value: string) => string,
|
|
@@ -198,13 +198,14 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
198
198
|
);
|
|
199
199
|
|
|
200
200
|
useEffect(() => {
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
const doc = gridDivRef.current?.ownerDocument;
|
|
202
|
+
doc?.addEventListener('mousedown', trackMouseDown, { capture: true });
|
|
203
|
+
doc?.addEventListener('mouseup', trackMouseUp, { capture: true });
|
|
203
204
|
return () => {
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
doc?.removeEventListener('mousemove', trackMouseDown, { capture: true });
|
|
206
|
+
doc?.removeEventListener('mouseup', trackMouseUp, { capture: true });
|
|
206
207
|
};
|
|
207
|
-
}, [trackMouseDown, trackMouseUp]);
|
|
208
|
+
}, [trackMouseDown, trackMouseUp, gridDivRef]);
|
|
208
209
|
|
|
209
210
|
const onCellMouseOver = useCallback(
|
|
210
211
|
(e: CellMouseOverEvent, mouseDown?: boolean) => {
|
|
@@ -239,7 +240,7 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
239
240
|
) {
|
|
240
241
|
e.api.stopEditing();
|
|
241
242
|
hasSelectedMoreThanOneCellRef.current = true;
|
|
242
|
-
|
|
243
|
+
gridDivRef.current?.ownerDocument.defaultView?.getSelection()?.removeAllRanges();
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
updateRangeSelectionCellClasses();
|
|
@@ -251,6 +252,7 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
251
252
|
rangeEndRef,
|
|
252
253
|
rangeSortedNodesRef,
|
|
253
254
|
rangeStartRef,
|
|
255
|
+
gridDivRef,
|
|
254
256
|
],
|
|
255
257
|
);
|
|
256
258
|
|
|
@@ -288,7 +288,7 @@ export const ControlledMenuFr = (
|
|
|
288
288
|
const onBlur = (e: FocusEvent) => {
|
|
289
289
|
if (
|
|
290
290
|
isMenuOpen(state) &&
|
|
291
|
-
!e.currentTarget.contains(e.relatedTarget ||
|
|
291
|
+
!e.currentTarget.contains(e.relatedTarget || e.currentTarget.ownerDocument.activeElement) &&
|
|
292
292
|
!isWithinMenu(e.relatedTarget)
|
|
293
293
|
) {
|
|
294
294
|
safeCall(onClose, { reason: CloseReason.BLUR });
|
|
@@ -348,8 +348,10 @@ export const ControlledMenuFr = (
|
|
|
348
348
|
|
|
349
349
|
if (portal) {
|
|
350
350
|
if (typeof portal === 'boolean') {
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
const thisDocument =
|
|
352
|
+
containerRef.current?.ownerDocument ?? (typeof document !== 'undefined' ? document : undefined);
|
|
353
|
+
if (portal && thisDocument) {
|
|
354
|
+
return createPortal(menuList, thisDocument.body);
|
|
353
355
|
}
|
|
354
356
|
} else {
|
|
355
357
|
return portal.target ? createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
|
|
@@ -192,10 +192,11 @@ export const MenuList = ({
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
if (!scrollNodes.menu) {
|
|
195
|
+
const thisWindow = containerRef.current.ownerDocument.defaultView ?? window;
|
|
195
196
|
scrollNodes.menu =
|
|
196
197
|
(boundingBoxRef
|
|
197
198
|
? boundingBoxRef.current // user explicitly sets boundingBoxRef
|
|
198
|
-
: getScrollAncestor(rootMenuRef?.current)) ||
|
|
199
|
+
: getScrollAncestor(rootMenuRef?.current)) || thisWindow; // try to discover bounding box automatically
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
const positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
|
|
@@ -298,7 +299,8 @@ export const MenuList = ({
|
|
|
298
299
|
let { menu: menuScroll } = scrollNodes;
|
|
299
300
|
if (!isOpen || !menuScroll) return;
|
|
300
301
|
|
|
301
|
-
|
|
302
|
+
const thisWindow = containerRef?.current?.ownerDocument.defaultView ?? window;
|
|
303
|
+
menuScroll = menuScroll.addEventListener ? menuScroll : thisWindow;
|
|
302
304
|
if (!scrollNodes.anchors) {
|
|
303
305
|
scrollNodes.anchors = [];
|
|
304
306
|
let anchorScroll = getScrollAncestor(rootAnchorRef && rootAnchorRef.current);
|
|
@@ -323,6 +325,7 @@ export const MenuList = ({
|
|
|
323
325
|
const scrollObservers = scrollNodes.anchors.concat(viewScroll !== 'initial' ? menuScroll : []);
|
|
324
326
|
scrollObservers.forEach((o: any) => o.addEventListener('scroll', handleScroll));
|
|
325
327
|
return () => scrollObservers.forEach((o) => o.removeEventListener('scroll', handleScroll));
|
|
328
|
+
// oxlint-disable-next-line react/refs react-hooks/exhaustive-deps
|
|
326
329
|
}, [rootAnchorRef, scrollNodes, isOpen, onClose, viewScroll, handlePosition]);
|
|
327
330
|
|
|
328
331
|
const hasOverflow = !!overflowData && overflowData.overflowAmt != null && overflowData.overflowAmt > 0;
|
|
@@ -425,7 +428,7 @@ export const MenuList = ({
|
|
|
425
428
|
const id = setTimeout(
|
|
426
429
|
() => {
|
|
427
430
|
// If focus has already been set to a children element, don't set focus on menu or item
|
|
428
|
-
if (menuRef.current && !menuRef.current.contains(
|
|
431
|
+
if (menuRef.current && !menuRef.current.contains(menuRef.current.ownerDocument.activeElement)) {
|
|
429
432
|
// Handle popover portal focus
|
|
430
433
|
const popupElement = focusRef.current?.nextSibling;
|
|
431
434
|
if (!focusFirstInput(popupElement)) {
|
|
@@ -29,7 +29,7 @@ export const useItems = (menuRef: MutableRefObject<any>, focusRef: MutableRefObj
|
|
|
29
29
|
const index = items.indexOf(item);
|
|
30
30
|
if (index > -1) {
|
|
31
31
|
items.splice(index, 1);
|
|
32
|
-
if (item.contains(
|
|
32
|
+
if (item.contains(item.ownerDocument.activeElement)) {
|
|
33
33
|
focusRef?.current?.focus();
|
|
34
34
|
setHoverItem(undefined);
|
|
35
35
|
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import '@
|
|
2
|
-
|
|
3
|
-
import { Meta, StoryFn } from '@storybook/react-vite';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
2
|
import { useCallback } from 'react';
|
|
5
3
|
|
|
6
4
|
import { ActionButton } from '../../lui/ActionButton';
|
|
7
5
|
import { wait } from '../../utils/util';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
title: 'Components / ActionButton',
|
|
11
|
-
component: ActionButton,
|
|
12
|
-
args: {},
|
|
13
|
-
} as Meta<typeof ActionButton>;
|
|
14
|
-
|
|
15
|
-
const ActionButtonTemplate: StoryFn<typeof ActionButton> = () => {
|
|
7
|
+
const ActionButtonTemplate = () => {
|
|
16
8
|
const performAction = useCallback(async () => {
|
|
17
9
|
await wait(1000);
|
|
18
10
|
}, []);
|
|
@@ -54,4 +46,13 @@ const ActionButtonTemplate: StoryFn<typeof ActionButton> = () => {
|
|
|
54
46
|
);
|
|
55
47
|
};
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
const meta: Meta<typeof ActionButtonTemplate> = {
|
|
50
|
+
title: 'Components / ActionButton',
|
|
51
|
+
component: ActionButtonTemplate,
|
|
52
|
+
args: {},
|
|
53
|
+
};
|
|
54
|
+
export default meta;
|
|
55
|
+
|
|
56
|
+
type Story = StoryObj<typeof meta>;
|
|
57
|
+
|
|
58
|
+
export const ActionButtonSimple: Story = {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Panel,
|
|
3
|
+
PanelContent,
|
|
4
|
+
PanelHeader,
|
|
5
|
+
PanelsContextProvider,
|
|
6
|
+
RibbonButtonOpenPanel,
|
|
7
|
+
RibbonContainer,
|
|
8
|
+
} from '@linzjs/windows';
|
|
9
|
+
import type { Decorator } from '@storybook/react-vite';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adds an "Open in panel" button above the story. The panel it opens has a built-in
|
|
13
|
+
* Pop-out/Pop-in toggle (via @linzjs/windows) that moves its content into a real,
|
|
14
|
+
* separate browser window - useful for manually testing grid behaviour when popped out.
|
|
15
|
+
*/
|
|
16
|
+
export const withOpenInPanelDecorator: Decorator = (Story) => (
|
|
17
|
+
<PanelsContextProvider baseZIndex={500} panelStateOptions={null}>
|
|
18
|
+
<RibbonContainer>
|
|
19
|
+
<RibbonButtonOpenPanel
|
|
20
|
+
title="Open in panel"
|
|
21
|
+
uniqueId={'openInPanel'}
|
|
22
|
+
icon={'ic_launch_modal'}
|
|
23
|
+
componentFn={() => (
|
|
24
|
+
<Panel title={'Open in panel'} size={{ width: 1100, height: 600 }}>
|
|
25
|
+
<PanelHeader />
|
|
26
|
+
<PanelContent>
|
|
27
|
+
<Story />
|
|
28
|
+
</PanelContent>
|
|
29
|
+
</Panel>
|
|
30
|
+
)}
|
|
31
|
+
/>
|
|
32
|
+
</RibbonContainer>
|
|
33
|
+
<Story />
|
|
34
|
+
</PanelsContextProvider>
|
|
35
|
+
);
|