@alaarab/ogrid-angular 2.0.2

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.
@@ -0,0 +1,619 @@
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 } from '@angular/core';
8
+ import { mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, flattenColumns, processClientSideData, } from '@alaarab/ogrid-core';
9
+ const DEFAULT_PAGE_SIZE = 25;
10
+ const EMPTY_LOADING_OPTIONS = {};
11
+ const DEFAULT_PANELS = ['columns', 'filters'];
12
+ /**
13
+ * Top-level orchestration service for OGrid: manages pagination, sorting, filtering,
14
+ * column visibility, sidebar, and server-side data fetching via Angular signals.
15
+ *
16
+ * Port of React's useOGrid hook.
17
+ */
18
+ let OGridService = class OGridService {
19
+ constructor() {
20
+ this.destroyRef = inject(DestroyRef);
21
+ // --- Input signals (set by the component consuming this service) ---
22
+ this.columnsProp = signal([]);
23
+ this.getRowId = signal((item) => item['id']);
24
+ this.data = signal(undefined);
25
+ this.dataSource = signal(undefined);
26
+ this.controlledPage = signal(undefined);
27
+ this.controlledPageSize = signal(undefined);
28
+ this.controlledSort = signal(undefined);
29
+ this.controlledFilters = signal(undefined);
30
+ this.controlledVisibleColumns = signal(undefined);
31
+ this.controlledLoading = signal(undefined);
32
+ this.onPageChange = signal(undefined);
33
+ this.onPageSizeChange = signal(undefined);
34
+ this.onSortChange = signal(undefined);
35
+ this.onFiltersChange = signal(undefined);
36
+ this.onVisibleColumnsChange = signal(undefined);
37
+ this.columnOrder = signal(undefined);
38
+ this.onColumnOrderChange = signal(undefined);
39
+ this.onColumnResized = signal(undefined);
40
+ this.onColumnPinned = signal(undefined);
41
+ this.freezeRows = signal(undefined);
42
+ this.freezeCols = signal(undefined);
43
+ this.defaultPageSize = signal(DEFAULT_PAGE_SIZE);
44
+ this.defaultSortBy = signal(undefined);
45
+ this.defaultSortDirection = signal('asc');
46
+ this.toolbar = signal(undefined);
47
+ this.toolbarBelow = signal(undefined);
48
+ this.emptyState = signal(undefined);
49
+ this.entityLabelPlural = signal('items');
50
+ this.className = signal(undefined);
51
+ this.layoutMode = signal('fill');
52
+ this.suppressHorizontalScroll = signal(undefined);
53
+ this.editable = signal(undefined);
54
+ this.cellSelection = signal(undefined);
55
+ this.onCellValueChanged = signal(undefined);
56
+ this.onUndo = signal(undefined);
57
+ this.onRedo = signal(undefined);
58
+ this.canUndo = signal(undefined);
59
+ this.canRedo = signal(undefined);
60
+ this.rowSelection = signal('none');
61
+ this.selectedRows = signal(undefined);
62
+ this.onSelectionChange = signal(undefined);
63
+ this.statusBar = signal(undefined);
64
+ this.pageSizeOptions = signal(undefined);
65
+ this.sideBarConfig = signal(undefined);
66
+ this.onFirstDataRendered = signal(undefined);
67
+ this.onError = signal(undefined);
68
+ this.columnChooserProp = signal(undefined);
69
+ this.ariaLabel = signal(undefined);
70
+ this.ariaLabelledBy = signal(undefined);
71
+ // --- Internal state signals ---
72
+ this.internalData = signal([]);
73
+ this.internalLoading = signal(false);
74
+ this.internalPage = signal(1);
75
+ this.internalPageSize = signal(DEFAULT_PAGE_SIZE);
76
+ this.internalSort = signal({ field: '', direction: 'asc' });
77
+ this.internalFilters = signal({});
78
+ this.internalVisibleColumns = signal(new Set());
79
+ this.internalSelectedRows = signal(new Set());
80
+ this.columnWidthOverrides = signal({});
81
+ this.pinnedOverrides = signal({});
82
+ // Server-side state
83
+ this.serverItems = signal([]);
84
+ this.serverTotalCount = signal(0);
85
+ this.serverLoading = signal(true);
86
+ this.fetchId = 0;
87
+ this.refreshCounter = signal(0);
88
+ this.firstDataRendered = false;
89
+ // Side bar state
90
+ this.sideBarActivePanel = signal(null);
91
+ // Filter options state
92
+ this.serverFilterOptions = signal({});
93
+ this.loadingFilterOptions = signal({});
94
+ // --- Initialization ---
95
+ this.sortInitialized = false;
96
+ this.visibleColumnsInitialized = false;
97
+ this.pageSizeInitialized = false;
98
+ // --- Derived computed signals ---
99
+ this.columns = computed(() => flattenColumns(this.columnsProp()));
100
+ this.isServerSide = computed(() => this.dataSource() != null);
101
+ this.isClientSide = computed(() => !this.isServerSide());
102
+ this.displayData = computed(() => this.data() ?? this.internalData());
103
+ this.displayLoading = computed(() => this.controlledLoading() ?? this.internalLoading());
104
+ this.defaultSortField = computed(() => this.defaultSortBy() ?? this.columns()[0]?.columnId ?? '');
105
+ this.page = computed(() => this.controlledPage() ?? this.internalPage());
106
+ this.pageSize = computed(() => this.controlledPageSize() ?? this.internalPageSize());
107
+ this.sort = computed(() => this.controlledSort() ?? this.internalSort());
108
+ this.filters = computed(() => this.controlledFilters() ?? this.internalFilters());
109
+ this.visibleColumns = computed(() => this.controlledVisibleColumns() ?? this.internalVisibleColumns());
110
+ this.effectiveSelectedRows = computed(() => this.selectedRows() ?? this.internalSelectedRows());
111
+ this.columnChooserPlacement = computed(() => {
112
+ const prop = this.columnChooserProp();
113
+ return prop === false ? 'none' : prop === 'sidebar' ? 'sidebar' : 'toolbar';
114
+ });
115
+ this.multiSelectFilterFields = computed(() => getMultiSelectFilterFields(this.columns()));
116
+ this.hasServerFilterOptions = computed(() => this.dataSource()?.fetchFilterOptions != null);
117
+ this.clientFilterOptions = computed(() => {
118
+ if (this.hasServerFilterOptions())
119
+ return this.serverFilterOptions();
120
+ return deriveFilterOptionsFromData(this.displayData(), this.columns());
121
+ });
122
+ this.clientItemsAndTotal = computed(() => {
123
+ if (!this.isClientSide())
124
+ return null;
125
+ const rows = processClientSideData(this.displayData(), this.columns(), this.filters(), this.sort().field, this.sort().direction);
126
+ const total = rows.length;
127
+ const start = (this.page() - 1) * this.pageSize();
128
+ const paged = rows.slice(start, start + this.pageSize());
129
+ return { items: paged, totalCount: total };
130
+ });
131
+ this.displayItems = computed(() => {
132
+ const cit = this.clientItemsAndTotal();
133
+ return this.isClientSide() && cit ? cit.items : this.serverItems();
134
+ });
135
+ this.displayTotalCount = computed(() => {
136
+ const cit = this.clientItemsAndTotal();
137
+ return this.isClientSide() && cit ? cit.totalCount : this.serverTotalCount();
138
+ });
139
+ this.hasActiveFilters = computed(() => {
140
+ return Object.values(this.filters()).some((v) => v !== undefined);
141
+ });
142
+ this.columnChooserColumns = computed(() => this.columns().map((c) => ({
143
+ columnId: c.columnId,
144
+ name: c.name,
145
+ required: c.required === true,
146
+ })));
147
+ this.statusBarConfig = computed(() => {
148
+ const sb = this.statusBar();
149
+ if (!sb)
150
+ return undefined;
151
+ if (typeof sb === 'object')
152
+ return sb;
153
+ const totalData = this.isClientSide() ? (this.data()?.length ?? 0) : this.serverTotalCount();
154
+ const filteredData = this.displayTotalCount();
155
+ return {
156
+ totalCount: totalData,
157
+ filteredCount: this.hasActiveFilters() ? filteredData : undefined,
158
+ selectedCount: this.effectiveSelectedRows().size,
159
+ suppressRowCount: true,
160
+ };
161
+ });
162
+ this.isLoadingResolved = computed(() => {
163
+ return (this.isServerSide() && this.serverLoading()) || this.displayLoading();
164
+ });
165
+ // Side bar
166
+ this.sideBarEnabled = computed(() => {
167
+ const config = this.sideBarConfig();
168
+ return config != null && config !== false;
169
+ });
170
+ this.sideBarParsed = computed(() => {
171
+ const config = this.sideBarConfig();
172
+ if (!this.sideBarEnabled() || config === true) {
173
+ return { panels: DEFAULT_PANELS, position: 'right', defaultPanel: null };
174
+ }
175
+ const def = config;
176
+ return {
177
+ panels: def.panels ?? DEFAULT_PANELS,
178
+ position: def.position ?? 'right',
179
+ defaultPanel: def.defaultPanel ?? null,
180
+ };
181
+ });
182
+ this.filterableColumns = computed(() => this.columns()
183
+ .filter((c) => c.filterable && c.filterable.type)
184
+ .map((c) => ({
185
+ columnId: c.columnId,
186
+ name: c.name,
187
+ filterField: c.filterable.filterField ?? c.columnId,
188
+ filterType: c.filterable.type,
189
+ })));
190
+ this.sideBarState = computed(() => ({
191
+ isEnabled: this.sideBarEnabled(),
192
+ activePanel: this.sideBarActivePanel(),
193
+ setActivePanel: (panel) => this.sideBarActivePanel.set(panel),
194
+ panels: this.sideBarParsed().panels,
195
+ position: this.sideBarParsed().position,
196
+ isOpen: this.sideBarActivePanel() !== null,
197
+ toggle: (panel) => this.sideBarActivePanel.update((p) => p === panel ? null : panel),
198
+ close: () => this.sideBarActivePanel.set(null),
199
+ }));
200
+ // --- Data grid props computed ---
201
+ this.dataGridProps = computed(() => ({
202
+ items: this.displayItems(),
203
+ columns: this.columnsProp(),
204
+ getRowId: this.getRowId(),
205
+ sortBy: this.sort().field,
206
+ sortDirection: this.sort().direction,
207
+ onColumnSort: (columnKey) => this.handleSort(columnKey),
208
+ visibleColumns: this.visibleColumns(),
209
+ columnOrder: this.columnOrder(),
210
+ onColumnOrderChange: this.onColumnOrderChange(),
211
+ onColumnResized: (columnId, width) => this.handleColumnResized(columnId, width),
212
+ onColumnPinned: (columnId, pinned) => this.handleColumnPinned(columnId, pinned),
213
+ pinnedColumns: this.pinnedOverrides(),
214
+ initialColumnWidths: this.columnWidthOverrides(),
215
+ freezeRows: this.freezeRows(),
216
+ freezeCols: this.freezeCols(),
217
+ editable: this.editable(),
218
+ cellSelection: this.cellSelection(),
219
+ onCellValueChanged: this.onCellValueChanged(),
220
+ onUndo: this.onUndo(),
221
+ onRedo: this.onRedo(),
222
+ canUndo: this.canUndo(),
223
+ canRedo: this.canRedo(),
224
+ rowSelection: this.rowSelection(),
225
+ selectedRows: this.effectiveSelectedRows(),
226
+ onSelectionChange: (event) => this.handleSelectionChange(event),
227
+ statusBar: this.statusBarConfig(),
228
+ isLoading: this.isLoadingResolved(),
229
+ filters: this.filters(),
230
+ onFilterChange: (key, value) => this.handleFilterChange(key, value),
231
+ filterOptions: this.clientFilterOptions(),
232
+ loadingFilterOptions: this.dataSource()?.fetchFilterOptions ? this.loadingFilterOptions() : EMPTY_LOADING_OPTIONS,
233
+ peopleSearch: this.dataSource()?.searchPeople?.bind(this.dataSource()),
234
+ getUserByEmail: this.dataSource()?.getUserByEmail?.bind(this.dataSource()),
235
+ layoutMode: this.layoutMode(),
236
+ suppressHorizontalScroll: this.suppressHorizontalScroll(),
237
+ 'aria-label': this.ariaLabel(),
238
+ 'aria-labelledby': this.ariaLabelledBy(),
239
+ emptyState: {
240
+ hasActiveFilters: this.hasActiveFilters(),
241
+ onClearAll: () => this.setFilters({}),
242
+ message: this.emptyState()?.message,
243
+ render: this.emptyState()?.render,
244
+ },
245
+ }));
246
+ this.pagination = computed(() => ({
247
+ page: this.page(),
248
+ pageSize: this.pageSize(),
249
+ displayTotalCount: this.displayTotalCount(),
250
+ setPage: (p) => this.setPage(p),
251
+ setPageSize: (size) => this.setPageSize(size),
252
+ pageSizeOptions: this.pageSizeOptions(),
253
+ entityLabelPlural: this.entityLabelPlural(),
254
+ }));
255
+ this.columnChooser = computed(() => ({
256
+ columns: this.columnChooserColumns(),
257
+ visibleColumns: this.visibleColumns(),
258
+ onVisibilityChange: (columnKey, isVisible) => this.handleVisibilityChange(columnKey, isVisible),
259
+ placement: this.columnChooserPlacement(),
260
+ }));
261
+ this.filtersResult = computed(() => ({
262
+ hasActiveFilters: this.hasActiveFilters(),
263
+ setFilters: (f) => this.setFilters(f),
264
+ }));
265
+ this.sideBarProps = computed(() => {
266
+ const state = this.sideBarState();
267
+ if (!state.isEnabled)
268
+ return null;
269
+ return {
270
+ activePanel: state.activePanel,
271
+ onPanelChange: state.setActivePanel,
272
+ panels: state.panels,
273
+ position: state.position,
274
+ columns: this.columnChooserColumns(),
275
+ visibleColumns: this.visibleColumns(),
276
+ onVisibilityChange: (columnKey, visible) => this.handleVisibilityChange(columnKey, visible),
277
+ onSetVisibleColumns: (cols) => this.setVisibleColumns(cols),
278
+ filterableColumns: this.filterableColumns(),
279
+ filters: this.filters(),
280
+ onFilterChange: (key, value) => this.handleFilterChange(key, value),
281
+ filterOptions: this.clientFilterOptions(),
282
+ };
283
+ });
284
+ // Initialize internal default values based on config
285
+ effect(() => {
286
+ if (!this.sortInitialized) {
287
+ this.sortInitialized = true;
288
+ this.internalSort.set({
289
+ field: this.defaultSortField(),
290
+ direction: this.defaultSortDirection(),
291
+ });
292
+ }
293
+ });
294
+ effect(() => {
295
+ if (!this.pageSizeInitialized) {
296
+ this.pageSizeInitialized = true;
297
+ this.internalPageSize.set(this.defaultPageSize());
298
+ }
299
+ });
300
+ effect(() => {
301
+ if (!this.visibleColumnsInitialized && this.columns().length > 0) {
302
+ this.visibleColumnsInitialized = true;
303
+ const cols = this.columns();
304
+ const visible = cols.filter((c) => c.defaultVisible !== false).map((c) => c.columnId);
305
+ this.internalVisibleColumns.set(new Set(visible.length > 0 ? visible : cols.map((c) => c.columnId)));
306
+ }
307
+ });
308
+ // Server-side data fetching effect
309
+ effect(() => {
310
+ const ds = this.dataSource();
311
+ if (!this.isServerSide() || !ds) {
312
+ if (!this.isServerSide())
313
+ this.serverLoading.set(false);
314
+ return;
315
+ }
316
+ const page = this.page();
317
+ const pageSize = this.pageSize();
318
+ const sort = this.sort();
319
+ const filters = this.filters();
320
+ // Read refreshCounter to trigger re-fetches
321
+ this.refreshCounter();
322
+ const id = ++this.fetchId;
323
+ this.serverLoading.set(true);
324
+ ds.fetchPage({ page, pageSize, sort: { field: sort.field, direction: sort.direction }, filters })
325
+ .then((res) => {
326
+ if (id !== this.fetchId)
327
+ return;
328
+ this.serverItems.set(res.items);
329
+ this.serverTotalCount.set(res.totalCount);
330
+ })
331
+ .catch((err) => {
332
+ if (id !== this.fetchId)
333
+ return;
334
+ this.onError()?.(err);
335
+ this.serverItems.set([]);
336
+ this.serverTotalCount.set(0);
337
+ })
338
+ .finally(() => {
339
+ if (id === this.fetchId)
340
+ this.serverLoading.set(false);
341
+ });
342
+ });
343
+ // Fire onFirstDataRendered once
344
+ effect(() => {
345
+ if (!this.firstDataRendered && this.displayItems().length > 0) {
346
+ this.firstDataRendered = true;
347
+ this.onFirstDataRendered()?.();
348
+ }
349
+ });
350
+ // Load server filter options
351
+ effect(() => {
352
+ const ds = this.dataSource();
353
+ const fields = this.multiSelectFilterFields();
354
+ const fetcher = ds && 'fetchFilterOptions' in ds && typeof ds.fetchFilterOptions === 'function'
355
+ ? ds.fetchFilterOptions.bind(ds)
356
+ : undefined;
357
+ if (!fetcher || fields.length === 0) {
358
+ this.serverFilterOptions.set({});
359
+ this.loadingFilterOptions.set({});
360
+ return;
361
+ }
362
+ const loading = {};
363
+ fields.forEach((f) => { loading[f] = true; });
364
+ this.loadingFilterOptions.set(loading);
365
+ const results = {};
366
+ Promise.all(fields.map(async (field) => {
367
+ try {
368
+ results[field] = await fetcher(field);
369
+ }
370
+ catch {
371
+ results[field] = [];
372
+ }
373
+ })).then(() => {
374
+ this.serverFilterOptions.set(results);
375
+ this.loadingFilterOptions.set({});
376
+ });
377
+ });
378
+ // Initialize sidebar default panel
379
+ effect(() => {
380
+ const parsed = this.sideBarParsed();
381
+ if (parsed.defaultPanel) {
382
+ this.sideBarActivePanel.set(parsed.defaultPanel);
383
+ }
384
+ });
385
+ }
386
+ // --- Setters ---
387
+ setPage(p) {
388
+ if (this.controlledPage() === undefined)
389
+ this.internalPage.set(p);
390
+ this.onPageChange()?.(p);
391
+ }
392
+ setPageSize(size) {
393
+ if (this.controlledPageSize() === undefined)
394
+ this.internalPageSize.set(size);
395
+ this.onPageSizeChange()?.(size);
396
+ this.setPage(1);
397
+ }
398
+ setSort(s) {
399
+ if (this.controlledSort() === undefined)
400
+ this.internalSort.set(s);
401
+ this.onSortChange()?.(s);
402
+ this.setPage(1);
403
+ }
404
+ setFilters(f) {
405
+ if (this.controlledFilters() === undefined)
406
+ this.internalFilters.set(f);
407
+ this.onFiltersChange()?.(f);
408
+ this.setPage(1);
409
+ }
410
+ setVisibleColumns(cols) {
411
+ if (this.controlledVisibleColumns() === undefined)
412
+ this.internalVisibleColumns.set(cols);
413
+ this.onVisibleColumnsChange()?.(cols);
414
+ }
415
+ handleSort(columnKey) {
416
+ const sort = this.sort();
417
+ this.setSort({
418
+ field: columnKey,
419
+ direction: sort.field === columnKey && sort.direction === 'asc' ? 'desc' : 'asc',
420
+ });
421
+ }
422
+ handleFilterChange(key, value) {
423
+ this.setFilters(mergeFilter(this.filters(), key, value));
424
+ }
425
+ handleVisibilityChange(columnKey, isVisible) {
426
+ const next = new Set(this.visibleColumns());
427
+ if (isVisible)
428
+ next.add(columnKey);
429
+ else
430
+ next.delete(columnKey);
431
+ this.setVisibleColumns(next);
432
+ }
433
+ handleSelectionChange(event) {
434
+ if (this.selectedRows() === undefined) {
435
+ this.internalSelectedRows.set(new Set(event.selectedRowIds));
436
+ }
437
+ this.onSelectionChange()?.(event);
438
+ }
439
+ handleColumnResized(columnId, width) {
440
+ this.columnWidthOverrides.update((prev) => ({ ...prev, [columnId]: width }));
441
+ this.onColumnResized()?.(columnId, width);
442
+ }
443
+ handleColumnPinned(columnId, pinned) {
444
+ this.pinnedOverrides.update((prev) => {
445
+ if (pinned === null) {
446
+ const { [columnId]: _, ...rest } = prev;
447
+ return rest;
448
+ }
449
+ return { ...prev, [columnId]: pinned };
450
+ });
451
+ this.onColumnPinned()?.(columnId, pinned);
452
+ }
453
+ // --- Configure from props ---
454
+ configure(props) {
455
+ this.columnsProp.set(props.columns);
456
+ this.getRowId.set(props.getRowId);
457
+ if ('data' in props && props.data !== undefined)
458
+ this.data.set(props.data);
459
+ if ('dataSource' in props && props.dataSource !== undefined)
460
+ this.dataSource.set(props.dataSource);
461
+ if (props.page !== undefined)
462
+ this.controlledPage.set(props.page);
463
+ if (props.pageSize !== undefined)
464
+ this.controlledPageSize.set(props.pageSize);
465
+ if (props.sort !== undefined)
466
+ this.controlledSort.set(props.sort);
467
+ if (props.filters !== undefined)
468
+ this.controlledFilters.set(props.filters);
469
+ if (props.visibleColumns !== undefined)
470
+ this.controlledVisibleColumns.set(props.visibleColumns);
471
+ if (props.isLoading !== undefined)
472
+ this.controlledLoading.set(props.isLoading);
473
+ if (props.onPageChange)
474
+ this.onPageChange.set(props.onPageChange);
475
+ if (props.onPageSizeChange)
476
+ this.onPageSizeChange.set(props.onPageSizeChange);
477
+ if (props.onSortChange)
478
+ this.onSortChange.set(props.onSortChange);
479
+ if (props.onFiltersChange)
480
+ this.onFiltersChange.set(props.onFiltersChange);
481
+ if (props.onVisibleColumnsChange)
482
+ this.onVisibleColumnsChange.set(props.onVisibleColumnsChange);
483
+ if (props.columnOrder !== undefined)
484
+ this.columnOrder.set(props.columnOrder);
485
+ if (props.onColumnOrderChange)
486
+ this.onColumnOrderChange.set(props.onColumnOrderChange);
487
+ if (props.onColumnResized)
488
+ this.onColumnResized.set(props.onColumnResized);
489
+ if (props.onColumnPinned)
490
+ this.onColumnPinned.set(props.onColumnPinned);
491
+ if (props.freezeRows !== undefined)
492
+ this.freezeRows.set(props.freezeRows);
493
+ if (props.freezeCols !== undefined)
494
+ this.freezeCols.set(props.freezeCols);
495
+ if (props.defaultPageSize !== undefined)
496
+ this.defaultPageSize.set(props.defaultPageSize);
497
+ if (props.defaultSortBy !== undefined)
498
+ this.defaultSortBy.set(props.defaultSortBy);
499
+ if (props.defaultSortDirection !== undefined)
500
+ this.defaultSortDirection.set(props.defaultSortDirection);
501
+ if (props.editable !== undefined)
502
+ this.editable.set(props.editable);
503
+ if (props.cellSelection !== undefined)
504
+ this.cellSelection.set(props.cellSelection);
505
+ if (props.onCellValueChanged)
506
+ this.onCellValueChanged.set(props.onCellValueChanged);
507
+ if (props.onUndo)
508
+ this.onUndo.set(props.onUndo);
509
+ if (props.onRedo)
510
+ this.onRedo.set(props.onRedo);
511
+ if (props.canUndo !== undefined)
512
+ this.canUndo.set(props.canUndo);
513
+ if (props.canRedo !== undefined)
514
+ this.canRedo.set(props.canRedo);
515
+ if (props.rowSelection !== undefined)
516
+ this.rowSelection.set(props.rowSelection);
517
+ if (props.selectedRows !== undefined)
518
+ this.selectedRows.set(props.selectedRows);
519
+ if (props.onSelectionChange)
520
+ this.onSelectionChange.set(props.onSelectionChange);
521
+ if (props.statusBar !== undefined)
522
+ this.statusBar.set(props.statusBar);
523
+ if (props.pageSizeOptions !== undefined)
524
+ this.pageSizeOptions.set(props.pageSizeOptions);
525
+ if (props.sideBar !== undefined)
526
+ this.sideBarConfig.set(props.sideBar);
527
+ if (props.onFirstDataRendered)
528
+ this.onFirstDataRendered.set(props.onFirstDataRendered);
529
+ if (props.onError)
530
+ this.onError.set(props.onError);
531
+ if (props.columnChooser !== undefined)
532
+ this.columnChooserProp.set(props.columnChooser);
533
+ if (props.entityLabelPlural !== undefined)
534
+ this.entityLabelPlural.set(props.entityLabelPlural);
535
+ if (props.className !== undefined)
536
+ this.className.set(props.className);
537
+ if (props.layoutMode !== undefined)
538
+ this.layoutMode.set(props.layoutMode);
539
+ if (props.suppressHorizontalScroll !== undefined)
540
+ this.suppressHorizontalScroll.set(props.suppressHorizontalScroll);
541
+ if (props['aria-label'] !== undefined)
542
+ this.ariaLabel.set(props['aria-label']);
543
+ if (props['aria-labelledby'] !== undefined)
544
+ this.ariaLabelledBy.set(props['aria-labelledby']);
545
+ }
546
+ // --- API ---
547
+ getApi() {
548
+ return {
549
+ setRowData: (d) => {
550
+ if (!this.isServerSide())
551
+ this.internalData.set(d);
552
+ },
553
+ setLoading: (loading) => this.internalLoading.set(loading),
554
+ getColumnState: () => ({
555
+ visibleColumns: Array.from(this.visibleColumns()),
556
+ sort: this.sort(),
557
+ columnOrder: this.columnOrder() ?? undefined,
558
+ columnWidths: Object.keys(this.columnWidthOverrides()).length > 0 ? this.columnWidthOverrides() : undefined,
559
+ filters: Object.keys(this.filters()).length > 0 ? this.filters() : undefined,
560
+ pinnedColumns: Object.keys(this.pinnedOverrides()).length > 0 ? this.pinnedOverrides() : undefined,
561
+ }),
562
+ applyColumnState: (state) => {
563
+ if (state.visibleColumns)
564
+ this.setVisibleColumns(new Set(state.visibleColumns));
565
+ if (state.sort)
566
+ this.setSort(state.sort);
567
+ if (state.columnOrder && this.onColumnOrderChange())
568
+ this.onColumnOrderChange()(state.columnOrder);
569
+ if (state.columnWidths)
570
+ this.columnWidthOverrides.set(state.columnWidths);
571
+ if (state.filters)
572
+ this.setFilters(state.filters);
573
+ if (state.pinnedColumns)
574
+ this.pinnedOverrides.set(state.pinnedColumns);
575
+ },
576
+ setFilterModel: (filters) => this.setFilters(filters),
577
+ getSelectedRows: () => Array.from(this.effectiveSelectedRows()),
578
+ setSelectedRows: (rowIds) => {
579
+ if (this.selectedRows() === undefined)
580
+ this.internalSelectedRows.set(new Set(rowIds));
581
+ },
582
+ selectAll: () => {
583
+ const allIds = new Set(this.displayItems().map((item) => this.getRowId()(item)));
584
+ if (this.selectedRows() === undefined)
585
+ this.internalSelectedRows.set(allIds);
586
+ this.onSelectionChange()?.({
587
+ selectedRowIds: Array.from(allIds),
588
+ selectedItems: this.displayItems(),
589
+ });
590
+ },
591
+ deselectAll: () => {
592
+ if (this.selectedRows() === undefined)
593
+ this.internalSelectedRows.set(new Set());
594
+ this.onSelectionChange()?.({ selectedRowIds: [], selectedItems: [] });
595
+ },
596
+ clearFilters: () => this.setFilters({}),
597
+ clearSort: () => this.setSort({ field: this.defaultSortField(), direction: this.defaultSortDirection() }),
598
+ resetGridState: (options) => {
599
+ this.setFilters({});
600
+ this.setSort({ field: this.defaultSortField(), direction: this.defaultSortDirection() });
601
+ if (!options?.keepSelection) {
602
+ if (this.selectedRows() === undefined)
603
+ this.internalSelectedRows.set(new Set());
604
+ this.onSelectionChange()?.({ selectedRowIds: [], selectedItems: [] });
605
+ }
606
+ },
607
+ getDisplayedRows: () => this.displayItems(),
608
+ refreshData: () => {
609
+ if (this.isServerSide()) {
610
+ this.refreshCounter.update((c) => c + 1);
611
+ }
612
+ },
613
+ };
614
+ }
615
+ };
616
+ OGridService = __decorate([
617
+ Injectable()
618
+ ], OGridService);
619
+ export { OGridService };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { toUserLike, isInSelectionRange, normalizeSelectionRange } from '@alaarab/ogrid-core';
@@ -0,0 +1 @@
1
+ export { toUserLike, isInSelectionRange, normalizeSelectionRange } from './dataGridTypes';
@@ -0,0 +1,6 @@
1
+ export declare class EmptyStateComponent {
2
+ readonly message: import("@angular/core").InputSignal<string | undefined>;
3
+ readonly hasActiveFilters: import("@angular/core").InputSignal<boolean>;
4
+ readonly render: import("@angular/core").InputSignal<unknown>;
5
+ readonly clearAll: import("@angular/core").OutputEmitterRef<void>;
6
+ }
@@ -0,0 +1,32 @@
1
+ import { ElementRef } from '@angular/core';
2
+ import { GRID_CONTEXT_MENU_ITEMS, formatShortcut } from '@alaarab/ogrid-core';
3
+ export declare class GridContextMenuComponent {
4
+ private destroyRef;
5
+ readonly x: import("@angular/core").InputSignal<number>;
6
+ readonly y: import("@angular/core").InputSignal<number>;
7
+ readonly hasSelection: import("@angular/core").InputSignal<boolean>;
8
+ readonly canUndoProp: import("@angular/core").InputSignal<boolean>;
9
+ readonly canRedoProp: import("@angular/core").InputSignal<boolean>;
10
+ readonly classNames: import("@angular/core").InputSignal<{
11
+ contextMenu?: string;
12
+ contextMenuItem?: string;
13
+ contextMenuItemLabel?: string;
14
+ contextMenuItemShortcut?: string;
15
+ contextMenuDivider?: string;
16
+ } | undefined>;
17
+ readonly copy: import("@angular/core").OutputEmitterRef<void>;
18
+ readonly cut: import("@angular/core").OutputEmitterRef<void>;
19
+ readonly paste: import("@angular/core").OutputEmitterRef<void>;
20
+ readonly selectAll: import("@angular/core").OutputEmitterRef<void>;
21
+ readonly undoAction: import("@angular/core").OutputEmitterRef<void>;
22
+ readonly redoAction: import("@angular/core").OutputEmitterRef<void>;
23
+ readonly close: import("@angular/core").OutputEmitterRef<void>;
24
+ readonly menuRef: import("@angular/core").Signal<ElementRef<HTMLDivElement> | undefined>;
25
+ readonly menuItems: import("@alaarab/ogrid-core").GridContextMenuItem[];
26
+ readonly formatShortcutFn: typeof formatShortcut;
27
+ private clickOutsideHandler;
28
+ private keyDownHandler;
29
+ constructor();
30
+ isDisabled(item: (typeof GRID_CONTEXT_MENU_ITEMS)[number]): boolean;
31
+ onItemClick(id: string): void;
32
+ }