@alaarab/ogrid-angular 2.1.3 → 2.1.5
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/esm/index.js +4606 -30
- package/dist/types/components/base-datagrid-table.component.d.ts +8 -8
- package/package.json +4 -4
- package/dist/esm/components/base-column-chooser.component.js +0 -78
- package/dist/esm/components/base-column-header-filter.component.js +0 -281
- package/dist/esm/components/base-datagrid-table.component.js +0 -648
- package/dist/esm/components/base-inline-cell-editor.component.js +0 -253
- package/dist/esm/components/base-ogrid.component.js +0 -36
- package/dist/esm/components/base-pagination-controls.component.js +0 -72
- package/dist/esm/components/base-popover-cell-editor.component.js +0 -114
- package/dist/esm/components/empty-state.component.js +0 -58
- package/dist/esm/components/grid-context-menu.component.js +0 -153
- package/dist/esm/components/inline-cell-editor-template.js +0 -107
- package/dist/esm/components/marching-ants-overlay.component.js +0 -164
- package/dist/esm/components/ogrid-layout.component.js +0 -188
- package/dist/esm/components/sidebar.component.js +0 -274
- package/dist/esm/components/status-bar.component.js +0 -71
- package/dist/esm/services/column-reorder.service.js +0 -180
- package/dist/esm/services/datagrid-editing.service.js +0 -52
- package/dist/esm/services/datagrid-interaction.service.js +0 -667
- package/dist/esm/services/datagrid-layout.service.js +0 -151
- package/dist/esm/services/datagrid-state.service.js +0 -591
- package/dist/esm/services/ogrid.service.js +0 -746
- package/dist/esm/services/virtual-scroll.service.js +0 -91
- package/dist/esm/styles/ogrid-theme-vars.js +0 -53
- package/dist/esm/types/columnTypes.js +0 -1
- package/dist/esm/types/dataGridTypes.js +0 -1
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/utils/dataGridViewModel.js +0 -6
- package/dist/esm/utils/debounce.js +0 -68
- package/dist/esm/utils/index.js +0 -8
- package/dist/esm/utils/latestRef.js +0 -41
|
@@ -1,591 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Injectable, signal, computed, effect, DestroyRef, inject, NgZone } from '@angular/core';
|
|
8
|
-
import { getDataGridStatusBarConfig, parseValue, computeAggregations, getCellValue, normalizeSelectionRange, } from '@alaarab/ogrid-core';
|
|
9
|
-
import { DataGridLayoutHelper } from './datagrid-layout.service';
|
|
10
|
-
import { DataGridEditingHelper } from './datagrid-editing.service';
|
|
11
|
-
import { DataGridInteractionHelper } from './datagrid-interaction.service';
|
|
12
|
-
// Stable no-op functions to avoid allocating new closures on every getState() call
|
|
13
|
-
const NOOP = () => { };
|
|
14
|
-
const NOOP_ASYNC = async () => { };
|
|
15
|
-
const NOOP_MOUSE = (_e, _r, _c) => { };
|
|
16
|
-
const NOOP_KEY = (_e) => { };
|
|
17
|
-
const NOOP_CTX = (_e) => { };
|
|
18
|
-
/**
|
|
19
|
-
* Single orchestration service for DataGridTable. Takes grid props,
|
|
20
|
-
* returns all derived state and handlers so Angular UI packages can be thin view layers.
|
|
21
|
-
*
|
|
22
|
-
* Port of React's useDataGridState hook.
|
|
23
|
-
*/
|
|
24
|
-
let DataGridStateService = class DataGridStateService {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.destroyRef = inject(DestroyRef);
|
|
27
|
-
this.ngZone = inject(NgZone);
|
|
28
|
-
// --- Input signals ---
|
|
29
|
-
this.props = signal(null);
|
|
30
|
-
this.wrapperEl = signal(null);
|
|
31
|
-
// --- Internal state (still owned by main service for backward compat) ---
|
|
32
|
-
this.internalSelectedRows = signal(new Set());
|
|
33
|
-
// Row selection
|
|
34
|
-
this.lastClickedRow = -1;
|
|
35
|
-
// Header menu state (for column pinning UI)
|
|
36
|
-
this.headerMenuIsOpenSig = signal(false);
|
|
37
|
-
this.headerMenuOpenForColumnSig = signal(null);
|
|
38
|
-
this.headerMenuAnchorElementSig = signal(null);
|
|
39
|
-
// --- Derived computed ---
|
|
40
|
-
this.propsResolved = computed(() => {
|
|
41
|
-
const p = this.props();
|
|
42
|
-
if (!p)
|
|
43
|
-
throw new Error('DataGridStateService: props must be set before use');
|
|
44
|
-
return p;
|
|
45
|
-
});
|
|
46
|
-
this.cellSelection = computed(() => {
|
|
47
|
-
const p = this.props();
|
|
48
|
-
return p ? p.cellSelection !== false : true;
|
|
49
|
-
});
|
|
50
|
-
// Narrow signal extractors — prevent full props() dependency in effects/computed
|
|
51
|
-
this.originalOnCellValueChanged = computed(() => this.props()?.onCellValueChanged);
|
|
52
|
-
// Undo/redo wrapped callback — only recomputes when the actual callback reference changes
|
|
53
|
-
this.wrappedOnCellValueChanged = computed(() => {
|
|
54
|
-
const original = this.originalOnCellValueChanged();
|
|
55
|
-
if (!original)
|
|
56
|
-
return undefined;
|
|
57
|
-
return (event) => {
|
|
58
|
-
this.interactionHelper.undoRedoStack.record(event);
|
|
59
|
-
if (!this.interactionHelper.undoRedoStack.isBatching) {
|
|
60
|
-
this.interactionHelper.undoLengthSig.set(this.interactionHelper.undoRedoStack.historyLength);
|
|
61
|
-
this.interactionHelper.redoLengthSig.set(this.interactionHelper.undoRedoStack.redoLength);
|
|
62
|
-
}
|
|
63
|
-
original(event);
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
// --- Delegated computed signals from layoutHelper ---
|
|
67
|
-
this.flatColumnsRaw = computed(() => this.layoutHelper.flatColumnsRaw());
|
|
68
|
-
this.flatColumns = computed(() => this.layoutHelper.flatColumns());
|
|
69
|
-
this.visibleCols = computed(() => this.layoutHelper.visibleCols());
|
|
70
|
-
this.visibleColumnCount = computed(() => this.layoutHelper.visibleColumnCount());
|
|
71
|
-
this.hasCheckboxCol = computed(() => this.layoutHelper.hasCheckboxCol());
|
|
72
|
-
this.hasRowNumbersCol = computed(() => this.layoutHelper.hasRowNumbersCol());
|
|
73
|
-
this.specialColsCount = computed(() => this.layoutHelper.specialColsCount());
|
|
74
|
-
this.totalColCount = computed(() => this.layoutHelper.totalColCount());
|
|
75
|
-
this.colOffset = computed(() => this.layoutHelper.colOffset());
|
|
76
|
-
this.rowIndexByRowId = computed(() => this.layoutHelper.rowIndexByRowId());
|
|
77
|
-
this.selectedRowIds = computed(() => {
|
|
78
|
-
const p = this.props();
|
|
79
|
-
if (!p)
|
|
80
|
-
return new Set();
|
|
81
|
-
const controlled = p.selectedRows;
|
|
82
|
-
if (controlled != null) {
|
|
83
|
-
return controlled instanceof Set ? controlled : new Set(controlled);
|
|
84
|
-
}
|
|
85
|
-
return this.internalSelectedRows();
|
|
86
|
-
});
|
|
87
|
-
this.allSelected = computed(() => {
|
|
88
|
-
const p = this.props();
|
|
89
|
-
if (!p || p.items.length === 0)
|
|
90
|
-
return false;
|
|
91
|
-
const selected = this.selectedRowIds();
|
|
92
|
-
return p.items.every((item) => selected.has(p.getRowId(item)));
|
|
93
|
-
});
|
|
94
|
-
this.someSelected = computed(() => {
|
|
95
|
-
const p = this.props();
|
|
96
|
-
if (!p)
|
|
97
|
-
return false;
|
|
98
|
-
const selected = this.selectedRowIds();
|
|
99
|
-
return !this.allSelected() && p.items.some((item) => selected.has(p.getRowId(item)));
|
|
100
|
-
});
|
|
101
|
-
this.hasCellSelection = computed(() => this.interactionHelper.hasCellSelection());
|
|
102
|
-
this.canUndo = computed(() => this.interactionHelper.canUndo());
|
|
103
|
-
this.canRedo = computed(() => this.interactionHelper.canRedo());
|
|
104
|
-
// Table layout (delegated to layoutHelper)
|
|
105
|
-
this.minTableWidth = computed(() => this.layoutHelper.minTableWidth());
|
|
106
|
-
this.desiredTableWidth = computed(() => this.layoutHelper.desiredTableWidth());
|
|
107
|
-
this.aggregation = computed(() => {
|
|
108
|
-
const p = this.props();
|
|
109
|
-
if (!p)
|
|
110
|
-
return null;
|
|
111
|
-
return computeAggregations(p.items, this.visibleCols(), this.cellSelection() ? this.interactionHelper.selectionRangeSig() : null);
|
|
112
|
-
});
|
|
113
|
-
this.statusBarConfig = computed(() => {
|
|
114
|
-
const p = this.props();
|
|
115
|
-
if (!p)
|
|
116
|
-
return null;
|
|
117
|
-
const base = getDataGridStatusBarConfig(p.statusBar, p.items.length, this.selectedRowIds().size);
|
|
118
|
-
if (!base)
|
|
119
|
-
return null;
|
|
120
|
-
return { ...base, aggregation: this.aggregation() ?? undefined };
|
|
121
|
-
});
|
|
122
|
-
this.showEmptyInGrid = computed(() => {
|
|
123
|
-
const p = this.props();
|
|
124
|
-
if (!p)
|
|
125
|
-
return false;
|
|
126
|
-
return p.items.length === 0 && !!p.emptyState && !p.isLoading;
|
|
127
|
-
});
|
|
128
|
-
// --- Instantiate sub-helpers ---
|
|
129
|
-
this.layoutHelper = new DataGridLayoutHelper(this.props, this.wrapperEl, this.ngZone);
|
|
130
|
-
this.interactionHelper = new DataGridInteractionHelper();
|
|
131
|
-
this.editingHelper = new DataGridEditingHelper(() => this.visibleCols(), () => this.props()?.items ?? [], () => this.wrappedOnCellValueChanged(), (cell) => this.setActiveCell(cell));
|
|
132
|
-
// Setup window event listeners for cell selection drag
|
|
133
|
-
// Run outside NgZone to avoid 60Hz change detection during drag
|
|
134
|
-
effect((onCleanup) => {
|
|
135
|
-
const onMove = (e) => this.onWindowMouseMove(e);
|
|
136
|
-
const onUp = () => this.onWindowMouseUp();
|
|
137
|
-
this.ngZone.runOutsideAngular(() => {
|
|
138
|
-
window.addEventListener('mousemove', onMove, true);
|
|
139
|
-
window.addEventListener('mouseup', onUp, true);
|
|
140
|
-
});
|
|
141
|
-
onCleanup(() => {
|
|
142
|
-
window.removeEventListener('mousemove', onMove, true);
|
|
143
|
-
window.removeEventListener('mouseup', onUp, true);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
// Cleanup on destroy — cancel pending work and release references
|
|
147
|
-
this.destroyRef.onDestroy(() => {
|
|
148
|
-
this.interactionHelper.destroy();
|
|
149
|
-
this.layoutHelper.destroy();
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
// --- Row selection methods ---
|
|
153
|
-
updateSelection(newSelectedIds) {
|
|
154
|
-
const p = this.props();
|
|
155
|
-
if (!p)
|
|
156
|
-
return;
|
|
157
|
-
if (p.selectedRows === undefined) {
|
|
158
|
-
this.internalSelectedRows.set(newSelectedIds);
|
|
159
|
-
}
|
|
160
|
-
p.onSelectionChange?.({
|
|
161
|
-
selectedRowIds: Array.from(newSelectedIds),
|
|
162
|
-
selectedItems: p.items.filter((item) => newSelectedIds.has(p.getRowId(item))),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
handleRowCheckboxChange(rowId, checked, rowIndex, shiftKey) {
|
|
166
|
-
const p = this.props();
|
|
167
|
-
if (!p)
|
|
168
|
-
return;
|
|
169
|
-
const rowSelection = p.rowSelection ?? 'none';
|
|
170
|
-
if (rowSelection === 'single') {
|
|
171
|
-
this.updateSelection(checked ? new Set([rowId]) : new Set());
|
|
172
|
-
this.lastClickedRow = rowIndex;
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const next = new Set(this.selectedRowIds());
|
|
176
|
-
if (shiftKey && this.lastClickedRow >= 0 && this.lastClickedRow !== rowIndex) {
|
|
177
|
-
const start = Math.min(this.lastClickedRow, rowIndex);
|
|
178
|
-
const end = Math.max(this.lastClickedRow, rowIndex);
|
|
179
|
-
for (let i = start; i <= end; i++) {
|
|
180
|
-
if (i < p.items.length) {
|
|
181
|
-
const id = p.getRowId(p.items[i]);
|
|
182
|
-
if (checked)
|
|
183
|
-
next.add(id);
|
|
184
|
-
else
|
|
185
|
-
next.delete(id);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
if (checked)
|
|
191
|
-
next.add(rowId);
|
|
192
|
-
else
|
|
193
|
-
next.delete(rowId);
|
|
194
|
-
}
|
|
195
|
-
this.lastClickedRow = rowIndex;
|
|
196
|
-
this.updateSelection(next);
|
|
197
|
-
}
|
|
198
|
-
handleSelectAll(checked) {
|
|
199
|
-
const p = this.props();
|
|
200
|
-
if (!p)
|
|
201
|
-
return;
|
|
202
|
-
if (checked) {
|
|
203
|
-
this.updateSelection(new Set(p.items.map((item) => p.getRowId(item))));
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this.updateSelection(new Set());
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// --- Cell editing (delegated to editingHelper) ---
|
|
210
|
-
setEditingCell(cell) {
|
|
211
|
-
this.editingHelper.setEditingCell(cell);
|
|
212
|
-
}
|
|
213
|
-
setPendingEditorValue(value) {
|
|
214
|
-
this.editingHelper.setPendingEditorValue(value);
|
|
215
|
-
}
|
|
216
|
-
setActiveCell(cell) {
|
|
217
|
-
this.interactionHelper.setActiveCell(cell);
|
|
218
|
-
}
|
|
219
|
-
setSelectionRange(range) {
|
|
220
|
-
this.interactionHelper.setSelectionRange(range);
|
|
221
|
-
}
|
|
222
|
-
commitCellEdit(item, columnId, oldValue, newValue, rowIndex, globalColIndex) {
|
|
223
|
-
this.editingHelper.commitCellEdit(item, columnId, oldValue, newValue, rowIndex, globalColIndex);
|
|
224
|
-
}
|
|
225
|
-
cancelPopoverEdit() {
|
|
226
|
-
this.editingHelper.cancelPopoverEdit();
|
|
227
|
-
}
|
|
228
|
-
// --- Cell selection / mouse handling (delegated to interactionHelper) ---
|
|
229
|
-
handleCellMouseDown(e, rowIndex, globalColIndex) {
|
|
230
|
-
this.interactionHelper.handleCellMouseDown(e, rowIndex, globalColIndex, this.colOffset(), this.wrapperEl());
|
|
231
|
-
}
|
|
232
|
-
handleSelectAllCells() {
|
|
233
|
-
const p = this.props();
|
|
234
|
-
if (!p)
|
|
235
|
-
return;
|
|
236
|
-
this.interactionHelper.handleSelectAllCells(p.items.length, this.visibleColumnCount(), this.colOffset());
|
|
237
|
-
}
|
|
238
|
-
// --- Context menu (delegated to interactionHelper) ---
|
|
239
|
-
setContextMenuPosition(pos) {
|
|
240
|
-
this.interactionHelper.setContextMenuPosition(pos);
|
|
241
|
-
}
|
|
242
|
-
handleCellContextMenu(e) {
|
|
243
|
-
this.interactionHelper.handleCellContextMenu(e);
|
|
244
|
-
}
|
|
245
|
-
closeContextMenu() {
|
|
246
|
-
this.interactionHelper.closeContextMenu();
|
|
247
|
-
}
|
|
248
|
-
// --- Clipboard (delegated to interactionHelper) ---
|
|
249
|
-
handleCopy() {
|
|
250
|
-
const p = this.props();
|
|
251
|
-
if (!p)
|
|
252
|
-
return;
|
|
253
|
-
this.interactionHelper.handleCopy(p.items, this.visibleCols(), this.colOffset());
|
|
254
|
-
}
|
|
255
|
-
handleCut() {
|
|
256
|
-
const p = this.props();
|
|
257
|
-
if (!p)
|
|
258
|
-
return;
|
|
259
|
-
this.interactionHelper.handleCut(p.items, this.visibleCols(), this.colOffset(), p.editable, this.wrappedOnCellValueChanged());
|
|
260
|
-
}
|
|
261
|
-
async handlePaste() {
|
|
262
|
-
const p = this.props();
|
|
263
|
-
if (!p)
|
|
264
|
-
return;
|
|
265
|
-
await this.interactionHelper.handlePaste(p.items, this.visibleCols(), this.colOffset(), p.editable, this.wrappedOnCellValueChanged());
|
|
266
|
-
}
|
|
267
|
-
clearClipboardRanges() {
|
|
268
|
-
this.interactionHelper.clearClipboardRanges();
|
|
269
|
-
}
|
|
270
|
-
// --- Undo/Redo (delegated to interactionHelper) ---
|
|
271
|
-
beginBatch() {
|
|
272
|
-
this.interactionHelper.beginBatch();
|
|
273
|
-
}
|
|
274
|
-
endBatch() {
|
|
275
|
-
this.interactionHelper.endBatch();
|
|
276
|
-
}
|
|
277
|
-
undo() {
|
|
278
|
-
const p = this.props();
|
|
279
|
-
this.interactionHelper.undo(p?.onCellValueChanged);
|
|
280
|
-
}
|
|
281
|
-
redo() {
|
|
282
|
-
const p = this.props();
|
|
283
|
-
this.interactionHelper.redo(p?.onCellValueChanged);
|
|
284
|
-
}
|
|
285
|
-
// --- Keyboard navigation (delegated to interactionHelper) ---
|
|
286
|
-
handleGridKeyDown(e) {
|
|
287
|
-
const p = this.props();
|
|
288
|
-
if (!p)
|
|
289
|
-
return;
|
|
290
|
-
this.interactionHelper.handleGridKeyDown(e, p.items, p.getRowId, this.visibleCols(), this.colOffset(), this.hasCheckboxCol(), this.visibleColumnCount(), p.editable, this.wrappedOnCellValueChanged(), p.onCellValueChanged, p.rowSelection ?? 'none', this.selectedRowIds(), this.wrapperEl(), (rowId, checked, rowIndex, shiftKey) => this.handleRowCheckboxChange(rowId, checked, rowIndex, shiftKey), this.editingHelper.editingCellSig(), (cell) => this.setEditingCell(cell));
|
|
291
|
-
}
|
|
292
|
-
// --- Fill handle (delegated to interactionHelper + setupFillHandleDrag) ---
|
|
293
|
-
handleFillHandleMouseDown(e) {
|
|
294
|
-
this.interactionHelper.handleFillHandleMouseDown(e);
|
|
295
|
-
this.setupFillHandleDrag();
|
|
296
|
-
}
|
|
297
|
-
// --- Column pinning ---
|
|
298
|
-
pinColumn(columnId, side) {
|
|
299
|
-
const props = this.props();
|
|
300
|
-
props?.onColumnPinned?.(columnId, side);
|
|
301
|
-
}
|
|
302
|
-
unpinColumn(columnId) {
|
|
303
|
-
const props = this.props();
|
|
304
|
-
props?.onColumnPinned?.(columnId, null);
|
|
305
|
-
}
|
|
306
|
-
isPinned(columnId) {
|
|
307
|
-
const props = this.props();
|
|
308
|
-
return props?.pinnedColumns?.[columnId];
|
|
309
|
-
}
|
|
310
|
-
getPinState(columnId) {
|
|
311
|
-
const pinned = this.isPinned(columnId);
|
|
312
|
-
return {
|
|
313
|
-
canPinLeft: pinned !== 'left',
|
|
314
|
-
canPinRight: pinned !== 'right',
|
|
315
|
-
canUnpin: !!pinned,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
// --- Header menu ---
|
|
319
|
-
openHeaderMenu(columnId, anchorEl) {
|
|
320
|
-
this.headerMenuOpenForColumnSig.set(columnId);
|
|
321
|
-
this.headerMenuAnchorElementSig.set(anchorEl);
|
|
322
|
-
this.headerMenuIsOpenSig.set(true);
|
|
323
|
-
}
|
|
324
|
-
closeHeaderMenu() {
|
|
325
|
-
this.headerMenuIsOpenSig.set(false);
|
|
326
|
-
this.headerMenuOpenForColumnSig.set(null);
|
|
327
|
-
this.headerMenuAnchorElementSig.set(null);
|
|
328
|
-
}
|
|
329
|
-
headerMenuPinLeft() {
|
|
330
|
-
const col = this.headerMenuOpenForColumnSig();
|
|
331
|
-
if (col && this.isPinned(col) !== 'left') {
|
|
332
|
-
this.pinColumn(col, 'left');
|
|
333
|
-
this.closeHeaderMenu();
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
headerMenuPinRight() {
|
|
337
|
-
const col = this.headerMenuOpenForColumnSig();
|
|
338
|
-
if (col && this.isPinned(col) !== 'right') {
|
|
339
|
-
this.pinColumn(col, 'right');
|
|
340
|
-
this.closeHeaderMenu();
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
headerMenuUnpin() {
|
|
344
|
-
const col = this.headerMenuOpenForColumnSig();
|
|
345
|
-
if (col && this.isPinned(col)) {
|
|
346
|
-
this.unpinColumn(col);
|
|
347
|
-
this.closeHeaderMenu();
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
// --- Get state result ---
|
|
351
|
-
getState() {
|
|
352
|
-
const p = this.props();
|
|
353
|
-
const cellSel = this.cellSelection();
|
|
354
|
-
const layout = {
|
|
355
|
-
flatColumns: this.flatColumns(),
|
|
356
|
-
visibleCols: this.visibleCols(),
|
|
357
|
-
visibleColumnCount: this.visibleColumnCount(),
|
|
358
|
-
totalColCount: this.totalColCount(),
|
|
359
|
-
colOffset: this.colOffset(),
|
|
360
|
-
hasCheckboxCol: this.hasCheckboxCol(),
|
|
361
|
-
hasRowNumbersCol: this.hasRowNumbersCol(),
|
|
362
|
-
rowIndexByRowId: this.rowIndexByRowId(),
|
|
363
|
-
containerWidth: this.layoutHelper.containerWidthSig(),
|
|
364
|
-
minTableWidth: this.minTableWidth(),
|
|
365
|
-
desiredTableWidth: this.desiredTableWidth(),
|
|
366
|
-
columnSizingOverrides: this.layoutHelper.columnSizingOverridesSig(),
|
|
367
|
-
setColumnSizingOverrides: (overrides) => this.layoutHelper.columnSizingOverridesSig.set(overrides),
|
|
368
|
-
onColumnResized: p?.onColumnResized,
|
|
369
|
-
onAutosizeColumn: p?.onAutosizeColumn,
|
|
370
|
-
};
|
|
371
|
-
const rowSelection = {
|
|
372
|
-
selectedRowIds: this.selectedRowIds(),
|
|
373
|
-
updateSelection: (ids) => this.updateSelection(ids),
|
|
374
|
-
handleRowCheckboxChange: (rowId, checked, rowIndex, shiftKey) => this.handleRowCheckboxChange(rowId, checked, rowIndex, shiftKey),
|
|
375
|
-
handleSelectAll: (checked) => this.handleSelectAll(checked),
|
|
376
|
-
allSelected: this.allSelected(),
|
|
377
|
-
someSelected: this.someSelected(),
|
|
378
|
-
};
|
|
379
|
-
const editing = {
|
|
380
|
-
editingCell: this.editingHelper.editingCellSig(),
|
|
381
|
-
setEditingCell: (cell) => this.setEditingCell(cell),
|
|
382
|
-
pendingEditorValue: this.editingHelper.pendingEditorValueSig(),
|
|
383
|
-
setPendingEditorValue: (v) => this.setPendingEditorValue(v),
|
|
384
|
-
commitCellEdit: (item, colId, oldVal, newVal, rowIdx, globalColIdx) => this.commitCellEdit(item, colId, oldVal, newVal, rowIdx, globalColIdx),
|
|
385
|
-
cancelPopoverEdit: () => this.cancelPopoverEdit(),
|
|
386
|
-
popoverAnchorEl: this.editingHelper.popoverAnchorElSig(),
|
|
387
|
-
setPopoverAnchorEl: (el) => this.editingHelper.popoverAnchorElSig.set(el),
|
|
388
|
-
};
|
|
389
|
-
const interaction = {
|
|
390
|
-
activeCell: cellSel ? this.interactionHelper.activeCellSig() : null,
|
|
391
|
-
setActiveCell: cellSel ? (cell) => this.setActiveCell(cell) : undefined,
|
|
392
|
-
selectionRange: cellSel ? this.interactionHelper.selectionRangeSig() : null,
|
|
393
|
-
setSelectionRange: cellSel ? (range) => this.setSelectionRange(range) : undefined,
|
|
394
|
-
handleCellMouseDown: cellSel ? (e, r, c) => this.handleCellMouseDown(e, r, c) : NOOP_MOUSE,
|
|
395
|
-
handleSelectAllCells: cellSel ? () => this.handleSelectAllCells() : NOOP,
|
|
396
|
-
hasCellSelection: cellSel ? this.hasCellSelection() : false,
|
|
397
|
-
handleGridKeyDown: cellSel ? (e) => this.handleGridKeyDown(e) : NOOP_KEY,
|
|
398
|
-
handleFillHandleMouseDown: cellSel ? (e) => this.handleFillHandleMouseDown(e) : undefined,
|
|
399
|
-
handleCopy: cellSel ? () => this.handleCopy() : NOOP,
|
|
400
|
-
handleCut: cellSel ? () => this.handleCut() : NOOP,
|
|
401
|
-
handlePaste: cellSel ? () => this.handlePaste() : NOOP_ASYNC,
|
|
402
|
-
cutRange: cellSel ? this.interactionHelper.cutRangeSig() : null,
|
|
403
|
-
copyRange: cellSel ? this.interactionHelper.copyRangeSig() : null,
|
|
404
|
-
clearClipboardRanges: cellSel ? () => this.clearClipboardRanges() : NOOP,
|
|
405
|
-
canUndo: this.canUndo(),
|
|
406
|
-
canRedo: this.canRedo(),
|
|
407
|
-
onUndo: () => this.undo(),
|
|
408
|
-
onRedo: () => this.redo(),
|
|
409
|
-
isDragging: cellSel ? this.interactionHelper.isDraggingSig() : false,
|
|
410
|
-
};
|
|
411
|
-
const contextMenu = {
|
|
412
|
-
menuPosition: cellSel ? this.interactionHelper.contextMenuPositionSig() : null,
|
|
413
|
-
setMenuPosition: cellSel ? (pos) => this.setContextMenuPosition(pos) : undefined,
|
|
414
|
-
handleCellContextMenu: cellSel ? (e) => this.handleCellContextMenu(e) : NOOP_CTX,
|
|
415
|
-
closeContextMenu: cellSel ? () => this.closeContextMenu() : NOOP,
|
|
416
|
-
};
|
|
417
|
-
const viewModels = {
|
|
418
|
-
headerFilterInput: {
|
|
419
|
-
sortBy: p?.sortBy,
|
|
420
|
-
sortDirection: p?.sortDirection ?? 'asc',
|
|
421
|
-
onColumnSort: (columnKey, direction) => p?.onColumnSort(columnKey, direction),
|
|
422
|
-
filters: p?.filters ?? {},
|
|
423
|
-
onFilterChange: (key, value) => p?.onFilterChange(key, value),
|
|
424
|
-
filterOptions: p?.filterOptions ?? {},
|
|
425
|
-
loadingFilterOptions: p?.loadingFilterOptions ?? {},
|
|
426
|
-
peopleSearch: p?.peopleSearch,
|
|
427
|
-
},
|
|
428
|
-
cellDescriptorInput: {
|
|
429
|
-
editingCell: this.editingHelper.editingCellSig(),
|
|
430
|
-
activeCell: cellSel ? this.interactionHelper.activeCellSig() : null,
|
|
431
|
-
selectionRange: cellSel ? this.interactionHelper.selectionRangeSig() : null,
|
|
432
|
-
cutRange: cellSel ? this.interactionHelper.cutRangeSig() : null,
|
|
433
|
-
copyRange: cellSel ? this.interactionHelper.copyRangeSig() : null,
|
|
434
|
-
colOffset: this.colOffset(),
|
|
435
|
-
itemsLength: p?.items.length ?? 0,
|
|
436
|
-
getRowId: p?.getRowId ?? ((item) => item['id']),
|
|
437
|
-
editable: p?.editable,
|
|
438
|
-
onCellValueChanged: this.wrappedOnCellValueChanged(),
|
|
439
|
-
isDragging: cellSel ? this.interactionHelper.isDraggingSig() : false,
|
|
440
|
-
},
|
|
441
|
-
statusBarConfig: this.statusBarConfig(),
|
|
442
|
-
showEmptyInGrid: this.showEmptyInGrid(),
|
|
443
|
-
onCellError: p?.onCellError,
|
|
444
|
-
};
|
|
445
|
-
// --- Pinning ---
|
|
446
|
-
const openForColumn = this.headerMenuOpenForColumnSig();
|
|
447
|
-
const currentPinState = openForColumn ? (p?.pinnedColumns?.[openForColumn]) : undefined;
|
|
448
|
-
const pinning = {
|
|
449
|
-
pinnedColumns: p?.pinnedColumns ?? {},
|
|
450
|
-
pinColumn: (columnId, side) => this.pinColumn(columnId, side),
|
|
451
|
-
unpinColumn: (columnId) => this.unpinColumn(columnId),
|
|
452
|
-
isPinned: (columnId) => this.isPinned(columnId),
|
|
453
|
-
headerMenu: {
|
|
454
|
-
isOpen: this.headerMenuIsOpenSig(),
|
|
455
|
-
openForColumn,
|
|
456
|
-
anchorElement: this.headerMenuAnchorElementSig(),
|
|
457
|
-
open: (columnId, anchorEl) => this.openHeaderMenu(columnId, anchorEl),
|
|
458
|
-
close: () => this.closeHeaderMenu(),
|
|
459
|
-
handlePinLeft: () => this.headerMenuPinLeft(),
|
|
460
|
-
handlePinRight: () => this.headerMenuPinRight(),
|
|
461
|
-
handleUnpin: () => this.headerMenuUnpin(),
|
|
462
|
-
canPinLeft: currentPinState !== 'left',
|
|
463
|
-
canPinRight: currentPinState !== 'right',
|
|
464
|
-
canUnpin: !!currentPinState,
|
|
465
|
-
},
|
|
466
|
-
};
|
|
467
|
-
return { layout, rowSelection, editing, interaction, contextMenu, viewModels, pinning };
|
|
468
|
-
}
|
|
469
|
-
// --- Private helpers (drag selection delegated to interactionHelper) ---
|
|
470
|
-
onWindowMouseMove(e) {
|
|
471
|
-
this.interactionHelper.onWindowMouseMove(e, this.colOffset(), this.wrapperEl());
|
|
472
|
-
}
|
|
473
|
-
onWindowMouseUp() {
|
|
474
|
-
this.interactionHelper.onWindowMouseUp(this.colOffset(), this.wrapperEl());
|
|
475
|
-
}
|
|
476
|
-
setupFillHandleDrag() {
|
|
477
|
-
const p = this.props();
|
|
478
|
-
const fillDragStart = this.interactionHelper.fillDragStart;
|
|
479
|
-
if (!fillDragStart || p?.editable === false || !this.wrappedOnCellValueChanged())
|
|
480
|
-
return;
|
|
481
|
-
const colOff = this.colOffset();
|
|
482
|
-
const fillStart = fillDragStart;
|
|
483
|
-
let fillDragEnd = { endRow: fillStart.startRow, endCol: fillStart.startCol };
|
|
484
|
-
let liveFillRange = null;
|
|
485
|
-
let lastFillMousePos = null;
|
|
486
|
-
const resolveRange = (cx, cy) => {
|
|
487
|
-
const target = document.elementFromPoint(cx, cy);
|
|
488
|
-
const cell = target?.closest?.('[data-row-index][data-col-index]');
|
|
489
|
-
const wrapper = this.wrapperEl();
|
|
490
|
-
if (!cell || !wrapper?.contains(cell))
|
|
491
|
-
return null;
|
|
492
|
-
const r = parseInt(cell.getAttribute('data-row-index') ?? '', 10);
|
|
493
|
-
const c = parseInt(cell.getAttribute('data-col-index') ?? '', 10);
|
|
494
|
-
if (Number.isNaN(r) || Number.isNaN(c) || c < colOff)
|
|
495
|
-
return null;
|
|
496
|
-
const dataCol = c - colOff;
|
|
497
|
-
return normalizeSelectionRange({
|
|
498
|
-
startRow: fillStart.startRow, startCol: fillStart.startCol,
|
|
499
|
-
endRow: r, endCol: dataCol,
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
const onMove = (e) => {
|
|
503
|
-
lastFillMousePos = { cx: e.clientX, cy: e.clientY };
|
|
504
|
-
if (this.interactionHelper.fillRafId)
|
|
505
|
-
cancelAnimationFrame(this.interactionHelper.fillRafId);
|
|
506
|
-
this.interactionHelper.fillRafId = requestAnimationFrame(() => {
|
|
507
|
-
this.interactionHelper.fillRafId = 0;
|
|
508
|
-
if (!lastFillMousePos)
|
|
509
|
-
return;
|
|
510
|
-
const newRange = resolveRange(lastFillMousePos.cx, lastFillMousePos.cy);
|
|
511
|
-
if (!newRange)
|
|
512
|
-
return;
|
|
513
|
-
if (liveFillRange && liveFillRange.startRow === newRange.startRow &&
|
|
514
|
-
liveFillRange.startCol === newRange.startCol &&
|
|
515
|
-
liveFillRange.endRow === newRange.endRow &&
|
|
516
|
-
liveFillRange.endCol === newRange.endCol)
|
|
517
|
-
return;
|
|
518
|
-
liveFillRange = newRange;
|
|
519
|
-
fillDragEnd = { endRow: newRange.endRow, endCol: newRange.endCol };
|
|
520
|
-
this.interactionHelper.applyDragAttrs(newRange, colOff, this.wrapperEl());
|
|
521
|
-
});
|
|
522
|
-
};
|
|
523
|
-
const onUp = () => {
|
|
524
|
-
window.removeEventListener('mousemove', onMove, true);
|
|
525
|
-
window.removeEventListener('mouseup', onUp, true);
|
|
526
|
-
this.interactionHelper.fillMoveHandler = null;
|
|
527
|
-
this.interactionHelper.fillUpHandler = null;
|
|
528
|
-
if (this.interactionHelper.fillRafId) {
|
|
529
|
-
cancelAnimationFrame(this.interactionHelper.fillRafId);
|
|
530
|
-
this.interactionHelper.fillRafId = 0;
|
|
531
|
-
}
|
|
532
|
-
if (lastFillMousePos) {
|
|
533
|
-
const flushed = resolveRange(lastFillMousePos.cx, lastFillMousePos.cy);
|
|
534
|
-
if (flushed) {
|
|
535
|
-
liveFillRange = flushed;
|
|
536
|
-
fillDragEnd = { endRow: flushed.endRow, endCol: flushed.endCol };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
this.interactionHelper.clearDragAttrs(this.wrapperEl());
|
|
540
|
-
const norm = normalizeSelectionRange({
|
|
541
|
-
startRow: fillStart.startRow, startCol: fillStart.startCol,
|
|
542
|
-
endRow: fillDragEnd.endRow, endCol: fillDragEnd.endCol,
|
|
543
|
-
});
|
|
544
|
-
this.setSelectionRange(norm);
|
|
545
|
-
this.setActiveCell({ rowIndex: fillDragEnd.endRow, columnIndex: fillDragEnd.endCol + colOff });
|
|
546
|
-
// Apply fill values
|
|
547
|
-
if (!p)
|
|
548
|
-
return;
|
|
549
|
-
const items = p.items;
|
|
550
|
-
const visibleCols = this.visibleCols();
|
|
551
|
-
const startItem = items[norm.startRow];
|
|
552
|
-
const startColDef = visibleCols[norm.startCol];
|
|
553
|
-
const onCellValueChanged = this.wrappedOnCellValueChanged();
|
|
554
|
-
if (startItem && startColDef && onCellValueChanged) {
|
|
555
|
-
const startValue = getCellValue(startItem, startColDef);
|
|
556
|
-
this.beginBatch();
|
|
557
|
-
for (let row = norm.startRow; row <= norm.endRow; row++) {
|
|
558
|
-
for (let col = norm.startCol; col <= norm.endCol; col++) {
|
|
559
|
-
if (row === fillStart.startRow && col === fillStart.startCol)
|
|
560
|
-
continue;
|
|
561
|
-
if (row >= items.length || col >= visibleCols.length)
|
|
562
|
-
continue;
|
|
563
|
-
const item = items[row];
|
|
564
|
-
const colDef = visibleCols[col];
|
|
565
|
-
const colEditable = colDef.editable === true || (typeof colDef.editable === 'function' && colDef.editable(item));
|
|
566
|
-
if (!colEditable)
|
|
567
|
-
continue;
|
|
568
|
-
const oldValue = getCellValue(item, colDef);
|
|
569
|
-
const result = parseValue(startValue, oldValue, item, colDef);
|
|
570
|
-
if (!result.valid)
|
|
571
|
-
continue;
|
|
572
|
-
onCellValueChanged({ item, columnId: colDef.columnId, oldValue, newValue: result.value, rowIndex: row });
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
this.endBatch();
|
|
576
|
-
}
|
|
577
|
-
this.interactionHelper.fillDragStart = null;
|
|
578
|
-
};
|
|
579
|
-
// Track handlers for cleanup on destroy
|
|
580
|
-
this.interactionHelper.fillMoveHandler = onMove;
|
|
581
|
-
this.interactionHelper.fillUpHandler = onUp;
|
|
582
|
-
this.ngZone.runOutsideAngular(() => {
|
|
583
|
-
window.addEventListener('mousemove', onMove, true);
|
|
584
|
-
window.addEventListener('mouseup', onUp, true);
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
DataGridStateService = __decorate([
|
|
589
|
-
Injectable()
|
|
590
|
-
], DataGridStateService);
|
|
591
|
-
export { DataGridStateService };
|