@genesislcap/grid-pro 15.12.0-FUI-2601.1 → 15.13.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.
@@ -1,274 +0,0 @@
1
- import { applyVisibleOrder, getPickerItems, partitionPickerItems, reorderVisibleIds, } from './columns-tool-panel.utils';
2
- const PANEL_STYLES = `
3
- .grid-pro-columns-tool-panel {
4
- display: flex;
5
- flex-direction: column;
6
- height: 100%;
7
- min-width: 200px;
8
- padding: 8px;
9
- box-sizing: border-box;
10
- color: var(--ag-foreground-color, var(--neutral-foreground-rest));
11
- background: var(--ag-control-panel-background-color, var(--neutral-layer-2));
12
- font-family: var(--ag-font-family, var(--body-font));
13
- font-size: var(--ag-data-font-size, var(--type-ramp-minus-1-font-size));
14
- }
15
- .grid-pro-columns-search {
16
- width: 100%;
17
- margin-bottom: 8px;
18
- padding: 6px 8px;
19
- box-sizing: border-box;
20
- border: 1px solid var(--ag-input-border-color, var(--neutral-stroke-rest));
21
- border-radius: 4px;
22
- background: var(--ag-background-color, var(--neutral-layer-card-container));
23
- color: inherit;
24
- font: inherit;
25
- }
26
- .grid-pro-columns-list {
27
- display: flex;
28
- flex-direction: column;
29
- gap: 2px;
30
- overflow: auto;
31
- }
32
- .grid-pro-columns-divider {
33
- height: 1px;
34
- margin: 8px 0;
35
- background: var(--ag-border-color, var(--neutral-stroke-divider-rest));
36
- flex-shrink: 0;
37
- }
38
- .grid-pro-columns-item {
39
- display: flex;
40
- align-items: center;
41
- gap: 6px;
42
- padding: 4px 6px;
43
- border-radius: 4px;
44
- cursor: default;
45
- user-select: none;
46
- }
47
- .grid-pro-columns-item[draggable='true'] {
48
- cursor: grab;
49
- }
50
- .grid-pro-columns-item.dragging {
51
- opacity: 0.5;
52
- }
53
- .grid-pro-columns-item.drag-over {
54
- background: var(--ag-row-hover-color, var(--neutral-fill-hover));
55
- }
56
- .grid-pro-columns-handle {
57
- opacity: 0.45;
58
- letter-spacing: -1px;
59
- font-size: 12px;
60
- }
61
- .grid-pro-columns-item[draggable='false'] .grid-pro-columns-handle {
62
- visibility: hidden;
63
- }
64
- .grid-pro-columns-label {
65
- overflow: hidden;
66
- text-overflow: ellipsis;
67
- white-space: nowrap;
68
- }
69
- `;
70
- /**
71
- * Custom columns tool panel. Replaces AG Grid Enterprise `agColumnsToolPanel`.
72
- *
73
- * @public
74
- * @remarks
75
- * Registered as `gridProColumnsToolPanel` (`GridProToolPanelTypes.columns`).
76
- * `resolveGridProSideBar` rewrites `sideBar: ['columns']` / `agColumnsToolPanel` to this
77
- * component so hosts do not need `ColumnsToolPanelModule` — only `SideBarModule`.
78
- *
79
- * Layout: search → visible columns (drag to reorder) → divider → hidden columns.
80
- * Checkboxes toggle visibility via `api.setColumnsVisible`; drag is limited to the
81
- * visible list and disabled while a search filter is active.
82
- */
83
- export class ColumnsToolPanel {
84
- constructor() {
85
- this.search = '';
86
- /** Source colId while a visible-row drag is in progress. */
87
- this.dragColId = null;
88
- /** Stable listener refs so `destroy` can remove the same functions `init` added. */
89
- this.boundRefresh = () => this.refresh();
90
- }
91
- /**
92
- * AG Grid `IToolPanelComp` entry. Builds the DOM once and subscribes to column
93
- * events so the picker stays in sync with header menu / API visibility changes.
94
- */
95
- init(params) {
96
- this.params = params;
97
- this.api = params.api;
98
- this.buildGui();
99
- this.refresh();
100
- this.api.addEventListener('columnVisible', this.boundRefresh);
101
- this.api.addEventListener('columnMoved', this.boundRefresh);
102
- this.api.addEventListener('newColumnsLoaded', this.boundRefresh);
103
- this.api.addEventListener('displayedColumnsChanged', this.boundRefresh);
104
- }
105
- /**
106
- * Rebuilds both lists from current grid column state.
107
- * Displayed columns stay first (grid order); hidden columns follow so search
108
- * and drag operate on a single ordered picker model.
109
- */
110
- refresh() {
111
- var _a, _b, _c, _d, _e, _f, _g;
112
- if (!this.api || !this.selectedList) {
113
- return;
114
- }
115
- const activeElement = document.activeElement;
116
- const activeTestId = activeElement && ((_a = this.eGui) === null || _a === void 0 ? void 0 : _a.contains(activeElement))
117
- ? activeElement.getAttribute('data-test-id')
118
- : null;
119
- const displayed = (_d = (_c = (_b = this.api).getAllDisplayedColumns) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : [];
120
- const all = (_g = (_f = (_e = this.api).getColumns) === null || _f === void 0 ? void 0 : _f.call(_e)) !== null && _g !== void 0 ? _g : [];
121
- const displayedIds = new Set(displayed.map((column) => column.getColId()));
122
- // Displayed first (current visual order), then any non-displayed columns.
123
- const ordered = [...displayed, ...all.filter((column) => !displayedIds.has(column.getColId()))];
124
- const items = getPickerItems(ordered);
125
- const { selected, unselected } = partitionPickerItems(items, this.search);
126
- this.renderList(this.selectedList, selected, true);
127
- this.renderList(this.unselectedList, unselected, false);
128
- this.divider.style.display = selected.length && unselected.length ? '' : 'none';
129
- if (activeTestId) {
130
- const restoredElement = this.eGui.querySelector(`[data-test-id="${activeTestId}"]`);
131
- restoredElement === null || restoredElement === void 0 ? void 0 : restoredElement.focus();
132
- }
133
- }
134
- /** Root element AG Grid mounts into the sidebar. */
135
- getGui() {
136
- return this.eGui;
137
- }
138
- destroy() {
139
- if (this.api) {
140
- this.api.removeEventListener('columnVisible', this.boundRefresh);
141
- this.api.removeEventListener('columnMoved', this.boundRefresh);
142
- this.api.removeEventListener('newColumnsLoaded', this.boundRefresh);
143
- this.api.removeEventListener('displayedColumnsChanged', this.boundRefresh);
144
- }
145
- this.api = null;
146
- }
147
- /** One-time DOM: scoped styles, search, visible list, divider, hidden list. */
148
- buildGui() {
149
- this.eGui = document.createElement('div');
150
- this.eGui.className = 'grid-pro-columns-tool-panel';
151
- this.eGui.setAttribute('data-test-id', 'grid-pro-columns-tool-panel');
152
- const style = document.createElement('style');
153
- style.textContent = PANEL_STYLES;
154
- this.eGui.appendChild(style);
155
- this.searchInput = document.createElement('input');
156
- this.searchInput.type = 'search';
157
- this.searchInput.className = 'grid-pro-columns-search';
158
- this.searchInput.placeholder = 'Search';
159
- this.searchInput.setAttribute('data-test-id', 'grid-pro-columns-search');
160
- this.searchInput.addEventListener('input', () => {
161
- this.search = this.searchInput.value;
162
- this.refresh();
163
- });
164
- this.eGui.appendChild(this.searchInput);
165
- this.selectedList = document.createElement('div');
166
- this.selectedList.className = 'grid-pro-columns-list';
167
- this.selectedList.setAttribute('data-test-id', 'grid-pro-columns-selected');
168
- this.eGui.appendChild(this.selectedList);
169
- this.divider = document.createElement('div');
170
- this.divider.className = 'grid-pro-columns-divider';
171
- this.divider.setAttribute('data-test-id', 'grid-pro-columns-divider');
172
- this.eGui.appendChild(this.divider);
173
- this.unselectedList = document.createElement('div');
174
- this.unselectedList.className = 'grid-pro-columns-list';
175
- this.unselectedList.setAttribute('data-test-id', 'grid-pro-columns-unselected');
176
- this.eGui.appendChild(this.unselectedList);
177
- }
178
- renderList(container, items, selected) {
179
- container.replaceChildren();
180
- for (const item of items) {
181
- container.appendChild(this.createItem(item, selected));
182
- }
183
- }
184
- /**
185
- * One picker row: drag handle + visibility checkbox + header label.
186
- * Drag is only bound for visible rows when search is empty so reorder
187
- * matches full grid order, not a filtered subset.
188
- */
189
- createItem(item, selected) {
190
- const row = document.createElement('div');
191
- row.className = 'grid-pro-columns-item';
192
- row.dataset.colId = item.colId;
193
- row.setAttribute('data-test-id', `grid-pro-columns-item-${item.colId}`);
194
- const handle = document.createElement('span');
195
- handle.className = 'grid-pro-columns-handle';
196
- handle.textContent = '⋮⋮';
197
- row.appendChild(handle);
198
- const checkbox = document.createElement('input');
199
- checkbox.type = 'checkbox';
200
- checkbox.checked = item.visible;
201
- checkbox.disabled = item.lockVisible;
202
- checkbox.setAttribute('data-test-id', `grid-pro-columns-check-${item.colId}`);
203
- checkbox.addEventListener('change', () => {
204
- if (item.lockVisible || !this.api) {
205
- return;
206
- }
207
- this.api.setColumnsVisible([item.colId], checkbox.checked);
208
- });
209
- row.appendChild(checkbox);
210
- const label = document.createElement('span');
211
- label.className = 'grid-pro-columns-label';
212
- label.textContent = item.headerName;
213
- row.appendChild(label);
214
- if (selected && !this.search.trim()) {
215
- this.bindDrag(row, item.colId);
216
- }
217
- return row;
218
- }
219
- /** HTML5 drag-and-drop between visible rows; drop target colId is `colId`. */
220
- bindDrag(row, colId) {
221
- row.draggable = true;
222
- row.addEventListener('dragstart', (event) => {
223
- var _a;
224
- this.dragColId = colId;
225
- (_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.setData('text/plain', colId);
226
- row.classList.add('dragging');
227
- });
228
- row.addEventListener('dragend', () => {
229
- this.dragColId = null;
230
- row.classList.remove('dragging');
231
- });
232
- row.addEventListener('dragover', (event) => {
233
- event.preventDefault();
234
- row.classList.add('drag-over');
235
- });
236
- row.addEventListener('dragleave', () => {
237
- row.classList.remove('drag-over');
238
- });
239
- row.addEventListener('drop', (event) => {
240
- var _a;
241
- event.preventDefault();
242
- row.classList.remove('drag-over');
243
- const fromId = this.dragColId || ((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData('text/plain'));
244
- if (fromId) {
245
- this.reorderSelected(fromId, colId);
246
- }
247
- });
248
- }
249
- /**
250
- * Applies a new visible-column order via `applyColumnState({ applyOrder: true })`.
251
- * Hidden columns keep their relative positions; only the visible slice is permuted.
252
- */
253
- reorderSelected(fromId, toId) {
254
- var _a, _b, _c, _d, _e, _f;
255
- if (!this.api || !this.api.getColumnState || !this.api.applyColumnState) {
256
- return;
257
- }
258
- const displayed = (_c = (_b = (_a = this.api).getAllDisplayedColumns) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
259
- const all = (_f = (_e = (_d = this.api).getColumns) === null || _e === void 0 ? void 0 : _e.call(_d)) !== null && _f !== void 0 ? _f : [];
260
- const displayedIds = new Set(displayed.map((column) => column.getColId()));
261
- const ordered = [...displayed, ...all.filter((column) => !displayedIds.has(column.getColId()))];
262
- const items = getPickerItems(ordered);
263
- const allVisibleIds = items.filter((item) => item.visible).map((item) => item.colId);
264
- const { selected } = partitionPickerItems(items, this.search);
265
- const nextOrder = reorderVisibleIds(allVisibleIds, selected.map((item) => item.colId), fromId, toId);
266
- if (!nextOrder) {
267
- return;
268
- }
269
- this.api.applyColumnState({
270
- state: applyVisibleOrder(this.api.getColumnState(), nextOrder),
271
- applyOrder: true,
272
- });
273
- }
274
- }
@@ -1,129 +0,0 @@
1
- import { GridProToolPanelTypes } from '../grid-pro.types';
2
- export const gridProColumnsToolPanelDef = {
3
- id: 'columns',
4
- labelDefault: 'Columns',
5
- labelKey: 'columns',
6
- iconKey: 'columns',
7
- toolPanel: GridProToolPanelTypes.columns,
8
- };
9
- const filtersToolPanelDef = {
10
- id: 'filters',
11
- labelDefault: 'Filters',
12
- labelKey: 'filters',
13
- iconKey: 'filter',
14
- toolPanel: 'agFiltersToolPanel',
15
- };
16
- export function toPickerItem(col) {
17
- const colDef = col.getColDef();
18
- if (colDef.suppressColumnsToolPanel) {
19
- return null;
20
- }
21
- if (typeof col.isPrimary === 'function' && !col.isPrimary()) {
22
- return null;
23
- }
24
- const colId = col.getColId();
25
- const headerName = String(colDef.headerName || colDef.field || colId || '');
26
- return {
27
- colId,
28
- headerName,
29
- visible: col.isVisible(),
30
- lockVisible: Boolean(colDef.lockVisible),
31
- };
32
- }
33
- export function getPickerItems(columns) {
34
- return columns.map(toPickerItem).filter((item) => item != null);
35
- }
36
- export function partitionPickerItems(items, search) {
37
- const query = search.trim().toLowerCase();
38
- const matches = (item) => !query || item.headerName.toLowerCase().includes(query);
39
- return {
40
- selected: items.filter((item) => item.visible && matches(item)),
41
- unselected: items
42
- .filter((item) => !item.visible && matches(item))
43
- .sort((a, b) => a.headerName.localeCompare(b.headerName, undefined, { sensitivity: 'base' })),
44
- };
45
- }
46
- export function reorderVisibleIds(allVisibleIds, shownIds, fromId, toId) {
47
- const shown = [...shownIds];
48
- const fromIndex = shown.indexOf(fromId);
49
- const toIndex = shown.indexOf(toId);
50
- if (fromIndex < 0 || toIndex < 0 || fromId === toId) {
51
- return null;
52
- }
53
- shown.splice(fromIndex, 1);
54
- shown.splice(toIndex, 0, fromId);
55
- let index = 0;
56
- return allVisibleIds.map((id) => {
57
- if (!shownIds.includes(id)) {
58
- return id;
59
- }
60
- const nextId = shown[index];
61
- index += 1;
62
- return nextId;
63
- });
64
- }
65
- export function applyVisibleOrder(columnState, visibleOrder) {
66
- const byId = new Map(columnState.map((state) => [state.colId, state]));
67
- let index = 0;
68
- return columnState.map((state) => {
69
- if (state.hide) {
70
- return state;
71
- }
72
- const nextId = visibleOrder[index];
73
- index += 1;
74
- return (nextId && byId.get(nextId)) || state;
75
- });
76
- }
77
- function isColumnsToolPanel(panel) {
78
- if (panel === 'columns' || panel === 'agColumnsToolPanel') {
79
- return true;
80
- }
81
- if (typeof panel === 'string') {
82
- return false;
83
- }
84
- return (panel.toolPanel === 'agColumnsToolPanel' ||
85
- panel.toolPanel === GridProToolPanelTypes.columns ||
86
- panel.id === 'columns');
87
- }
88
- function toColumnsToolPanel(panel) {
89
- if (typeof panel === 'string') {
90
- return Object.assign({}, gridProColumnsToolPanelDef);
91
- }
92
- return Object.assign(Object.assign(Object.assign({}, gridProColumnsToolPanelDef), panel), { toolPanel: GridProToolPanelTypes.columns });
93
- }
94
- /**
95
- * Rewrites `sideBar: ['columns']` / `agColumnsToolPanel` to the custom Grid Pro picker.
96
- */
97
- export function resolveGridProSideBar(sideBar) {
98
- var _a;
99
- if (!sideBar) {
100
- return sideBar;
101
- }
102
- if (sideBar === true || sideBar === 'true') {
103
- return {
104
- toolPanels: [gridProColumnsToolPanelDef, filtersToolPanelDef],
105
- defaultToolPanel: 'filters',
106
- };
107
- }
108
- if (sideBar === 'columns' || sideBar === 'agColumnsToolPanel') {
109
- return { toolPanels: [gridProColumnsToolPanelDef] };
110
- }
111
- if (typeof sideBar === 'string') {
112
- return sideBar;
113
- }
114
- if (Array.isArray(sideBar)) {
115
- if (!sideBar.some(isColumnsToolPanel)) {
116
- return sideBar;
117
- }
118
- return {
119
- toolPanels: sideBar.map((panel) => isColumnsToolPanel(panel) ? toColumnsToolPanel(panel) : panel),
120
- };
121
- }
122
- if (!((_a = sideBar.toolPanels) === null || _a === void 0 ? void 0 : _a.length)) {
123
- return sideBar;
124
- }
125
- if (!sideBar.toolPanels.some(isColumnsToolPanel)) {
126
- return sideBar;
127
- }
128
- return Object.assign(Object.assign({}, sideBar), { toolPanels: sideBar.toolPanels.map((panel) => isColumnsToolPanel(panel) ? toColumnsToolPanel(panel) : panel) });
129
- }
@@ -1,2 +0,0 @@
1
- export * from './columns-tool-panel';
2
- export * from './columns-tool-panel.utils';