angular-smart-table-pro 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1668 @@
1
+ import { NgTemplateOutlet, DOCUMENT, isPlatformBrowser } from '@angular/common';
2
+ import { InjectionToken, Directive, Component, ViewEncapsulation, ChangeDetectionStrategy, makeEnvironmentProviders, input, inject, TemplateRef, DestroyRef, PLATFORM_ID, contentChildren, model, output, signal, computed, effect } from '@angular/core';
3
+
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (decorator(result)) || result;
10
+ return result;
11
+ };
12
+ var DEFAULT_DATAGRID_CONFIG = {
13
+ theme: "light",
14
+ size: "md",
15
+ responsive: "auto",
16
+ dir: "auto",
17
+ locale: "en-US",
18
+ pageSize: 10,
19
+ pageSizeOptions: [5, 10, 25, 50, 100],
20
+ showToolbar: true,
21
+ showSearch: true,
22
+ showColumnFilters: false,
23
+ showColumnChooser: true,
24
+ showExport: true,
25
+ exportFormats: ["csv", "excel"],
26
+ sortable: true,
27
+ draggableColumns: true,
28
+ stickyHeader: true,
29
+ striped: false,
30
+ accentColor: null
31
+ };
32
+ var NGX_DATAGRID_CONFIG = new InjectionToken(
33
+ "NGX_DATAGRID_CONFIG"
34
+ );
35
+ function provideEasyDataGrid(config) {
36
+ return makeEnvironmentProviders([
37
+ {
38
+ provide: NGX_DATAGRID_CONFIG,
39
+ useValue: config
40
+ }
41
+ ]);
42
+ }
43
+
44
+ // src/core/grid-engine.ts
45
+ function resolveCellValue(row, key) {
46
+ if (row === null || row === void 0) return void 0;
47
+ const record = row;
48
+ if (key in record) {
49
+ return record[key];
50
+ }
51
+ const parts = key.split(".");
52
+ let current = row;
53
+ for (const part of parts) {
54
+ if (current === null || current === void 0 || typeof current !== "object") {
55
+ return void 0;
56
+ }
57
+ current = current[part];
58
+ }
59
+ return current;
60
+ }
61
+ function formatCellDisplay(row, col) {
62
+ const raw = resolveCellValue(row, col.key);
63
+ if (col.format) {
64
+ return col.format(raw, row);
65
+ }
66
+ if (raw === null || raw === void 0) return "";
67
+ if (raw instanceof Date) {
68
+ return raw.toISOString().slice(0, 10);
69
+ }
70
+ if (typeof raw === "boolean") {
71
+ return raw ? "Yes" : "No";
72
+ }
73
+ return String(raw);
74
+ }
75
+ function filterRows(rows, columns, search, columnFilters) {
76
+ const globalTerm = search.trim().toLowerCase();
77
+ const activeColFilters = Object.entries(columnFilters).map(([k, v]) => [k, v.trim().toLowerCase()]).filter(([, v]) => v.length > 0);
78
+ if (!globalTerm && activeColFilters.length === 0) {
79
+ return [...rows];
80
+ }
81
+ const colMap = new Map(columns.map((c) => [c.key, c]));
82
+ return rows.filter((row) => {
83
+ for (const [key, term] of activeColFilters) {
84
+ const col = colMap.get(key);
85
+ const text = (col ? formatCellDisplay(row, col) : String(resolveCellValue(row, key) ?? "")).toLowerCase();
86
+ if (!text.includes(term)) {
87
+ return false;
88
+ }
89
+ }
90
+ if (!globalTerm) return true;
91
+ return columns.some((col) => {
92
+ if (col.filterable === false) return false;
93
+ return formatCellDisplay(row, col).toLowerCase().includes(globalTerm);
94
+ });
95
+ });
96
+ }
97
+ function compareValues(a, b) {
98
+ if (a === b) return 0;
99
+ if (a === null || a === void 0) return 1;
100
+ if (b === null || b === void 0) return -1;
101
+ if (typeof a === "number" && typeof b === "number") {
102
+ return a - b;
103
+ }
104
+ if (a instanceof Date && b instanceof Date) {
105
+ return a.getTime() - b.getTime();
106
+ }
107
+ if (typeof a === "boolean" && typeof b === "boolean") {
108
+ return a === b ? 0 : a ? -1 : 1;
109
+ }
110
+ return String(a).localeCompare(String(b), void 0, { numeric: true, sensitivity: "base" });
111
+ }
112
+ function sortRows(rows, columns, sort) {
113
+ if (!sort) return [...rows];
114
+ const col = columns.find((c) => c.key === sort.key);
115
+ const multiplier = sort.direction === "asc" ? 1 : -1;
116
+ return [...rows].sort((rowA, rowB) => {
117
+ const base = col?.sortBy ? col.sortBy(rowA, rowB) : compareValues(resolveCellValue(rowA, sort.key), resolveCellValue(rowB, sort.key));
118
+ return base * multiplier;
119
+ });
120
+ }
121
+ function paginateRows(rows, page, pageSize) {
122
+ const safeSize = Math.max(1, pageSize);
123
+ const totalItems = rows.length;
124
+ const totalPages = Math.max(1, Math.ceil(totalItems / safeSize));
125
+ const safePage = Math.min(totalPages, Math.max(1, page));
126
+ const startIdx = (safePage - 1) * safeSize;
127
+ const items = rows.slice(startIdx, startIdx + safeSize);
128
+ return {
129
+ items,
130
+ totalItems,
131
+ totalPages,
132
+ safePage,
133
+ startItem: totalItems === 0 ? 0 : startIdx + 1,
134
+ endItem: Math.min(totalItems, startIdx + items.length)
135
+ };
136
+ }
137
+ function reorderColumns(columns, fromKey, toKey) {
138
+ if (fromKey === toKey) return [...columns];
139
+ const fromIdx = columns.findIndex((c) => c.key === fromKey);
140
+ const toIdx = columns.findIndex((c) => c.key === toKey);
141
+ if (fromIdx === -1 || toIdx === -1) return [...columns];
142
+ const next = [...columns];
143
+ const [moved] = next.splice(fromIdx, 1);
144
+ if (!moved) return [...columns];
145
+ next.splice(toIdx, 0, moved);
146
+ return next;
147
+ }
148
+ function computeVirtualWindow(rows, options) {
149
+ const rowH = Math.max(24, options.rowHeight);
150
+ const overscan = options.overscan ?? 4;
151
+ const total = rows.length;
152
+ const totalHeightPx = total * rowH;
153
+ if (total === 0) {
154
+ return {
155
+ items: [],
156
+ startIndex: 0,
157
+ endIndex: 0,
158
+ topSpacerPx: 0,
159
+ bottomSpacerPx: 0,
160
+ totalHeightPx: 0
161
+ };
162
+ }
163
+ const rawStart = Math.floor(Math.max(0, options.scrollTop) / rowH);
164
+ const visibleCount = Math.ceil(Math.max(rowH, options.viewportHeight) / rowH);
165
+ const startIndex = Math.max(0, rawStart - overscan);
166
+ const endIndex = Math.min(total, rawStart + visibleCount + overscan);
167
+ return {
168
+ items: rows.slice(startIndex, endIndex),
169
+ startIndex,
170
+ endIndex,
171
+ topSpacerPx: startIndex * rowH,
172
+ bottomSpacerPx: Math.max(0, (total - endIndex) * rowH),
173
+ totalHeightPx
174
+ };
175
+ }
176
+
177
+ // src/core/export-utils.ts
178
+ function escapeCsvField(value) {
179
+ if (/[",\n\r]/.test(value)) {
180
+ return `"${value.replace(/"/g, '""')}"`;
181
+ }
182
+ return value;
183
+ }
184
+ function escapeXml(value) {
185
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
186
+ }
187
+ function getExportableColumns(columns, includeHidden) {
188
+ return columns.filter((col) => {
189
+ if (col.exportable === false) return false;
190
+ if (!includeHidden && col.visible === false) return false;
191
+ return true;
192
+ });
193
+ }
194
+ function buildCsvContent(rows, columns, options = {}) {
195
+ const cols = getExportableColumns(columns, Boolean(options.includeHiddenColumns));
196
+ const headerLine = cols.map((c) => escapeCsvField(c.header)).join(",");
197
+ const dataLines = rows.map(
198
+ (row) => cols.map((col) => escapeCsvField(formatCellDisplay(row, col))).join(",")
199
+ );
200
+ return `\uFEFF${[headerLine, ...dataLines].join("\r\n")}`;
201
+ }
202
+ function buildExcelXmlContent(rows, columns, options = {}) {
203
+ const cols = getExportableColumns(columns, Boolean(options.includeHiddenColumns));
204
+ const sheetName = escapeXml((options.sheetName ?? "DataGrid").slice(0, 31));
205
+ const headerCells = cols.map(
206
+ (c) => `<Cell ss:StyleID="Header"><Data ss:Type="String">${escapeXml(c.header)}</Data></Cell>`
207
+ ).join("");
208
+ const bodyRows = rows.map((row) => {
209
+ const cells = cols.map((col) => {
210
+ const raw = resolveCellValue(row, col.key);
211
+ if (typeof raw === "number" && Number.isFinite(raw) && !col.format) {
212
+ return `<Cell><Data ss:Type="Number">${raw}</Data></Cell>`;
213
+ }
214
+ return `<Cell><Data ss:Type="String">${escapeXml(formatCellDisplay(row, col))}</Data></Cell>`;
215
+ }).join("");
216
+ return `<Row>${cells}</Row>`;
217
+ }).join("");
218
+ return `<?xml version="1.0" encoding="UTF-8"?>
219
+ <?mso-application progid="Excel.Sheet"?>
220
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
221
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
222
+ <Styles>
223
+ <Style ss:ID="Header">
224
+ <Font ss:Bold="1" ss:Color="#FFFFFF"/>
225
+ <Interior ss:Color="#4F46E5" ss:Pattern="Solid"/>
226
+ </Style>
227
+ </Styles>
228
+ <Worksheet ss:Name="${sheetName}">
229
+ <Table>
230
+ <Row>${headerCells}</Row>
231
+ ${bodyRows}
232
+ </Table>
233
+ </Worksheet>
234
+ </Workbook>`;
235
+ }
236
+ function triggerBrowserDownload(content, fileName, mimeType, doc) {
237
+ const targetDoc = doc ?? (typeof document !== "undefined" ? document : null);
238
+ if (!targetDoc || typeof URL === "undefined" || typeof Blob === "undefined") return;
239
+ const blob = new Blob([content], { type: mimeType });
240
+ const url = URL.createObjectURL(blob);
241
+ const link = targetDoc.createElement("a");
242
+ link.href = url;
243
+ link.download = fileName;
244
+ link.style.display = "none";
245
+ targetDoc.body.appendChild(link);
246
+ link.click();
247
+ targetDoc.body.removeChild(link);
248
+ URL.revokeObjectURL(url);
249
+ }
250
+ var NgxTableCellDirective = class {
251
+ constructor() {
252
+ this.ngxTableCell = input.required();
253
+ this.template = inject(TemplateRef);
254
+ }
255
+ };
256
+ import * as __ngCore from '@angular/core';
257
+ import { NgTemplateOutlet as __NgTemplateOutlet } from '@angular/common';
258
+ NgxTableCellDirective.ɵfac = __ngCore.ɵɵngDeclareFactory({
259
+ minVersion: "12.0.0",
260
+ version: "19.2.25",
261
+ ngImport: __ngCore,
262
+ type: NgxTableCellDirective,
263
+ deps: [],
264
+ target: __ngCore.ɵɵFactoryTarget.Directive
265
+ });
266
+ NgxTableCellDirective.ɵdir = __ngCore.ɵɵngDeclareDirective({
267
+ minVersion: "17.2.0",
268
+ version: "19.2.25",
269
+ type: NgxTableCellDirective,
270
+ isStandalone: true,
271
+ selector: "ng-template[ngxTableCell]",
272
+ inputs: {
273
+ ngxTableCell: { classPropertyName: "ngxTableCell", publicName: "ngxTableCell", isSignal: true, isRequired: true, transformFunction: null }
274
+ },
275
+ ngImport: __ngCore
276
+ });
277
+
278
+ // src/components/ngx-smart-table.styles.ts
279
+ var NGX_SMART_TABLE_STYLES = `
280
+ .nst-host {
281
+ --nst-accent: #4f46e5;
282
+ --nst-accent-soft: color-mix(in srgb, var(--nst-accent) 12%, transparent);
283
+ --nst-bg: #ffffff;
284
+ --nst-surface: #f8fafc;
285
+ --nst-surface-hover: #f1f5f9;
286
+ --nst-border: #e2e8f0;
287
+ --nst-text: #0f172a;
288
+ --nst-text-muted: #64748b;
289
+ --nst-radius: 12px;
290
+ --nst-radius-sm: 8px;
291
+ --nst-shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.1);
292
+ --nst-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
293
+
294
+ display: block;
295
+ font-family: var(--nst-font);
296
+ color: var(--nst-text);
297
+ box-sizing: border-box;
298
+ }
299
+
300
+ .nst-host *,
301
+ .nst-host *::before,
302
+ .nst-host *::after {
303
+ box-sizing: border-box;
304
+ }
305
+
306
+ .nst-host[data-theme='dark'] {
307
+ --nst-accent: #6366f1;
308
+ --nst-bg: #0f172a;
309
+ --nst-surface: #1e293b;
310
+ --nst-surface-hover: #334155;
311
+ --nst-border: #334155;
312
+ --nst-text: #f8fafc;
313
+ --nst-text-muted: #94a3b8;
314
+ --nst-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.5);
315
+ }
316
+
317
+ @media (prefers-color-scheme: dark) {
318
+ .nst-host[data-theme='auto'] {
319
+ --nst-accent: #6366f1;
320
+ --nst-bg: #0f172a;
321
+ --nst-surface: #1e293b;
322
+ --nst-surface-hover: #334155;
323
+ --nst-border: #334155;
324
+ --nst-text: #f8fafc;
325
+ --nst-text-muted: #94a3b8;
326
+ --nst-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.5);
327
+ }
328
+ }
329
+
330
+ .nst-shell {
331
+ background: var(--nst-bg);
332
+ border: 1px solid var(--nst-border);
333
+ border-radius: var(--nst-radius);
334
+ box-shadow: var(--nst-shadow);
335
+ overflow: hidden;
336
+ }
337
+
338
+ .nst-toolbar {
339
+ display: flex;
340
+ align-items: center;
341
+ justify-content: space-between;
342
+ gap: 12px;
343
+ flex-wrap: wrap;
344
+ padding: 12px 16px;
345
+ background: var(--nst-surface);
346
+ border-bottom: 1px solid var(--nst-border);
347
+ }
348
+
349
+ .nst-toolbar-start,
350
+ .nst-toolbar-actions {
351
+ display: flex;
352
+ align-items: center;
353
+ gap: 8px;
354
+ flex-wrap: wrap;
355
+ }
356
+
357
+ .nst-search-box {
358
+ display: flex;
359
+ align-items: center;
360
+ gap: 8px;
361
+ background: var(--nst-bg);
362
+ border: 1px solid var(--nst-border);
363
+ border-radius: var(--nst-radius-sm);
364
+ padding: 0 10px;
365
+ height: 36px;
366
+ min-width: 220px;
367
+ }
368
+
369
+ .nst-search-box:focus-within {
370
+ border-color: var(--nst-accent);
371
+ box-shadow: 0 0 0 3px var(--nst-accent-soft);
372
+ }
373
+
374
+ .nst-search-icon {
375
+ color: var(--nst-text-muted);
376
+ flex-shrink: 0;
377
+ }
378
+
379
+ .nst-search-input {
380
+ border: none;
381
+ outline: none;
382
+ background: transparent;
383
+ color: var(--nst-text);
384
+ font-family: inherit;
385
+ font-size: 13px;
386
+ width: 100%;
387
+ }
388
+
389
+ .nst-selected-pill {
390
+ font-size: 12px;
391
+ font-weight: 600;
392
+ color: var(--nst-accent);
393
+ background: var(--nst-accent-soft);
394
+ padding: 4px 10px;
395
+ border-radius: 999px;
396
+ }
397
+
398
+ .nst-btn {
399
+ display: inline-flex;
400
+ align-items: center;
401
+ gap: 6px;
402
+ height: 34px;
403
+ padding: 0 12px;
404
+ border: 1px solid var(--nst-border);
405
+ border-radius: var(--nst-radius-sm);
406
+ background: var(--nst-bg);
407
+ color: var(--nst-text);
408
+ font-family: inherit;
409
+ font-size: 12.5px;
410
+ font-weight: 600;
411
+ cursor: pointer;
412
+ transition: background-color 0.14s ease, border-color 0.14s ease;
413
+ }
414
+
415
+ .nst-btn:hover {
416
+ background: var(--nst-surface-hover);
417
+ }
418
+
419
+ .nst-btn--active {
420
+ border-color: var(--nst-accent);
421
+ color: var(--nst-accent);
422
+ }
423
+
424
+ .nst-btn--accent {
425
+ background: var(--nst-accent);
426
+ border-color: var(--nst-accent);
427
+ color: #ffffff;
428
+ }
429
+
430
+ .nst-btn--accent:hover {
431
+ opacity: 0.92;
432
+ background: var(--nst-accent);
433
+ }
434
+
435
+ .nst-dropdown-wrap {
436
+ position: relative;
437
+ }
438
+
439
+ .nst-chooser-menu {
440
+ position: absolute;
441
+ top: calc(100% + 6px);
442
+ inset-inline-end: 0;
443
+ min-width: 210px;
444
+ background: var(--nst-bg);
445
+ border: 1px solid var(--nst-border);
446
+ border-radius: var(--nst-radius-sm);
447
+ box-shadow: var(--nst-shadow);
448
+ padding: 8px;
449
+ z-index: 40;
450
+ display: flex;
451
+ flex-direction: column;
452
+ gap: 4px;
453
+ }
454
+
455
+ .nst-chooser-head {
456
+ display: flex;
457
+ justify-content: space-between;
458
+ align-items: center;
459
+ font-size: 11.5px;
460
+ font-weight: 700;
461
+ color: var(--nst-text-muted);
462
+ padding: 4px 6px 6px;
463
+ border-bottom: 1px solid var(--nst-border);
464
+ }
465
+
466
+ .nst-chooser-reset {
467
+ border: none;
468
+ background: transparent;
469
+ color: var(--nst-accent);
470
+ font-size: 11.5px;
471
+ font-weight: 600;
472
+ cursor: pointer;
473
+ }
474
+
475
+ .nst-chooser-item {
476
+ display: flex;
477
+ align-items: center;
478
+ gap: 8px;
479
+ padding: 5px 6px;
480
+ border-radius: 6px;
481
+ font-size: 13px;
482
+ cursor: pointer;
483
+ }
484
+
485
+ .nst-chooser-item:hover {
486
+ background: var(--nst-surface-hover);
487
+ }
488
+
489
+ .nst-scroll-region {
490
+ position: relative;
491
+ overflow-x: auto;
492
+ width: 100%;
493
+ }
494
+
495
+ .nst-scroll-region--virtual {
496
+ overflow-y: auto;
497
+ }
498
+
499
+ .nst-loading-bar {
500
+ position: sticky;
501
+ top: 0;
502
+ left: 0;
503
+ right: 0;
504
+ height: 3px;
505
+ background: linear-gradient(90deg, transparent, var(--nst-accent), transparent);
506
+ animation: nst-load 1.1s infinite linear;
507
+ z-index: 20;
508
+ }
509
+
510
+ @keyframes nst-load {
511
+ from { transform: translateX(-100%); }
512
+ to { transform: translateX(100%); }
513
+ }
514
+
515
+ .nst-table {
516
+ width: 100%;
517
+ border-collapse: collapse;
518
+ text-align: start;
519
+ font-size: 13.5px;
520
+ }
521
+
522
+ .nst-thead--sticky {
523
+ position: sticky;
524
+ top: 0;
525
+ z-index: 10;
526
+ }
527
+
528
+ .nst-th {
529
+ background: var(--nst-surface);
530
+ color: var(--nst-text-muted);
531
+ font-size: 12px;
532
+ font-weight: 700;
533
+ text-transform: uppercase;
534
+ letter-spacing: 0.03em;
535
+ padding: 11px 14px;
536
+ border-bottom: 1px solid var(--nst-border);
537
+ white-space: nowrap;
538
+ user-select: none;
539
+ }
540
+
541
+ .nst-host[data-size='compact'] .nst-th,
542
+ .nst-host[data-size='compact'] .nst-td {
543
+ padding: 7px 10px;
544
+ }
545
+
546
+ .nst-host[data-size='comfortable'] .nst-th,
547
+ .nst-host[data-size='comfortable'] .nst-td {
548
+ padding: 15px 18px;
549
+ }
550
+
551
+ .nst-th--sortable {
552
+ cursor: pointer;
553
+ }
554
+
555
+ .nst-th--sortable:hover {
556
+ background: var(--nst-surface-hover);
557
+ color: var(--nst-text);
558
+ }
559
+
560
+ .nst-th--dragging {
561
+ opacity: 0.45;
562
+ }
563
+
564
+ .nst-th--drag-over {
565
+ box-shadow: inset 3px 0 0 var(--nst-accent);
566
+ background: var(--nst-accent-soft);
567
+ }
568
+
569
+ .nst-th--select,
570
+ .nst-td--select {
571
+ width: 44px;
572
+ text-align: center;
573
+ }
574
+
575
+ .nst-th-inner {
576
+ display: flex;
577
+ align-items: center;
578
+ gap: 6px;
579
+ }
580
+
581
+ .nst-th-inner[data-align='center'] {
582
+ justify-content: center;
583
+ }
584
+
585
+ .nst-th-inner[data-align='end'] {
586
+ justify-content: flex-end;
587
+ }
588
+
589
+ .nst-drag-grip {
590
+ color: var(--nst-text-muted);
591
+ opacity: 0.55;
592
+ cursor: grab;
593
+ font-size: 12px;
594
+ letter-spacing: -1px;
595
+ }
596
+
597
+ .nst-sort-icon {
598
+ font-size: 11px;
599
+ opacity: 0.4;
600
+ }
601
+
602
+ .nst-sort-icon--active {
603
+ opacity: 1;
604
+ color: var(--nst-accent);
605
+ }
606
+
607
+ .nst-th-filter {
608
+ background: var(--nst-bg);
609
+ padding: 6px 10px;
610
+ border-bottom: 1px solid var(--nst-border);
611
+ }
612
+
613
+ .nst-col-filter-input {
614
+ width: 100%;
615
+ height: 28px;
616
+ padding: 0 8px;
617
+ border: 1px solid var(--nst-border);
618
+ border-radius: 6px;
619
+ background: var(--nst-surface);
620
+ color: var(--nst-text);
621
+ font-family: inherit;
622
+ font-size: 12px;
623
+ outline: none;
624
+ }
625
+
626
+ .nst-col-filter-input:focus {
627
+ border-color: var(--nst-accent);
628
+ }
629
+
630
+ .nst-tr {
631
+ border-bottom: 1px solid var(--nst-border);
632
+ transition: background-color 0.1s ease;
633
+ }
634
+
635
+ .nst-table--striped .nst-tr:nth-child(even) {
636
+ background: color-mix(in srgb, var(--nst-surface) 55%, transparent);
637
+ }
638
+
639
+ .nst-tr:hover {
640
+ background: var(--nst-surface-hover);
641
+ }
642
+
643
+ .nst-tr--selected {
644
+ background: var(--nst-accent-soft) !important;
645
+ }
646
+
647
+ .nst-td {
648
+ padding: 11px 14px;
649
+ color: var(--nst-text);
650
+ vertical-align: middle;
651
+ }
652
+
653
+ .nst-td[data-align='center'] {
654
+ text-align: center;
655
+ }
656
+
657
+ .nst-td[data-align='end'] {
658
+ text-align: end;
659
+ }
660
+
661
+ .nst-cell-num {
662
+ font-variant-numeric: tabular-nums;
663
+ font-weight: 600;
664
+ }
665
+
666
+ .nst-badge {
667
+ display: inline-flex;
668
+ align-items: center;
669
+ padding: 3px 9px;
670
+ border-radius: 999px;
671
+ font-size: 11.5px;
672
+ font-weight: 600;
673
+ background: var(--nst-surface);
674
+ color: var(--nst-text);
675
+ }
676
+
677
+ .nst-badge[data-tone='success'] {
678
+ background: rgba(16, 185, 129, 0.14);
679
+ color: #10b981;
680
+ }
681
+
682
+ .nst-badge[data-tone='warning'] {
683
+ background: rgba(245, 158, 11, 0.16);
684
+ color: #d97706;
685
+ }
686
+
687
+ .nst-badge[data-tone='danger'] {
688
+ background: rgba(239, 68, 68, 0.15);
689
+ color: #ef4444;
690
+ }
691
+
692
+ .nst-badge[data-tone='info'] {
693
+ background: rgba(59, 130, 246, 0.15);
694
+ color: #3b82f6;
695
+ }
696
+
697
+ .nst-bool {
698
+ color: var(--nst-text-muted);
699
+ font-weight: 700;
700
+ }
701
+
702
+ .nst-bool--true {
703
+ color: #10b981;
704
+ }
705
+
706
+ .nst-checkbox {
707
+ width: 15px;
708
+ height: 15px;
709
+ accent-color: var(--nst-accent);
710
+ cursor: pointer;
711
+ }
712
+
713
+ .nst-empty {
714
+ text-align: center;
715
+ padding: 36px 16px;
716
+ color: var(--nst-text-muted);
717
+ font-size: 13.5px;
718
+ }
719
+
720
+ .nst-spacer-row td {
721
+ padding: 0 !important;
722
+ border: none !important;
723
+ }
724
+
725
+ .nst-pagination {
726
+ display: flex;
727
+ align-items: center;
728
+ justify-content: space-between;
729
+ gap: 12px;
730
+ flex-wrap: wrap;
731
+ padding: 10px 16px;
732
+ background: var(--nst-surface);
733
+ border-top: 1px solid var(--nst-border);
734
+ font-size: 12.5px;
735
+ color: var(--nst-text-muted);
736
+ }
737
+
738
+ .nst-page-controls {
739
+ display: flex;
740
+ align-items: center;
741
+ gap: 12px;
742
+ }
743
+
744
+ .nst-pagesize-label {
745
+ display: inline-flex;
746
+ align-items: center;
747
+ gap: 6px;
748
+ }
749
+
750
+ .nst-pagesize-select {
751
+ height: 30px;
752
+ padding: 0 8px;
753
+ border: 1px solid var(--nst-border);
754
+ border-radius: 6px;
755
+ background: var(--nst-bg);
756
+ color: var(--nst-text);
757
+ font-family: inherit;
758
+ font-size: 12.5px;
759
+ }
760
+
761
+ .nst-page-btns {
762
+ display: inline-flex;
763
+ align-items: center;
764
+ gap: 4px;
765
+ }
766
+
767
+ .nst-page-btn {
768
+ min-width: 30px;
769
+ height: 30px;
770
+ padding: 0 8px;
771
+ border: 1px solid var(--nst-border);
772
+ border-radius: 6px;
773
+ background: var(--nst-bg);
774
+ color: var(--nst-text);
775
+ font-family: inherit;
776
+ font-size: 12.5px;
777
+ font-weight: 600;
778
+ cursor: pointer;
779
+ }
780
+
781
+ .nst-page-btn:hover:not(:disabled):not(.nst-page-btn--active) {
782
+ background: var(--nst-surface-hover);
783
+ }
784
+
785
+ .nst-page-btn--active {
786
+ background: var(--nst-accent);
787
+ border-color: var(--nst-accent);
788
+ color: #ffffff;
789
+ }
790
+
791
+ .nst-page-btn:disabled {
792
+ opacity: 0.4;
793
+ cursor: not-allowed;
794
+ }
795
+
796
+ /* Responsive Card Layout on Mobile */
797
+ @media (max-width: 680px) {
798
+ .nst-host[data-responsive='auto'] .nst-table thead,
799
+ .nst-host[data-responsive='cards'] .nst-table thead {
800
+ display: none;
801
+ }
802
+
803
+ .nst-host[data-responsive='auto'] .nst-tr,
804
+ .nst-host[data-responsive='cards'] .nst-tr {
805
+ display: block;
806
+ margin: 10px 12px;
807
+ border: 1px solid var(--nst-border);
808
+ border-radius: var(--nst-radius-sm);
809
+ padding: 8px 12px;
810
+ background: var(--nst-bg);
811
+ }
812
+
813
+ .nst-host[data-responsive='auto'] .nst-td,
814
+ .nst-host[data-responsive='cards'] .nst-td {
815
+ display: flex;
816
+ justify-content: space-between;
817
+ align-items: center;
818
+ padding: 6px 0;
819
+ border-bottom: 1px dashed var(--nst-border);
820
+ }
821
+
822
+ .nst-host[data-responsive='auto'] .nst-td:last-child,
823
+ .nst-host[data-responsive='cards'] .nst-td:last-child {
824
+ border-bottom: none;
825
+ }
826
+
827
+ .nst-host[data-responsive='auto'] .nst-td::before,
828
+ .nst-host[data-responsive='cards'] .nst-td::before {
829
+ content: attr(data-label);
830
+ font-size: 11.5px;
831
+ font-weight: 700;
832
+ color: var(--nst-text-muted);
833
+ text-transform: uppercase;
834
+ }
835
+ }
836
+
837
+ .nst-host[data-responsive='cards'] .nst-table thead {
838
+ display: none;
839
+ }
840
+
841
+ .nst-host[data-responsive='cards'] .nst-tr {
842
+ display: block;
843
+ margin: 10px 12px;
844
+ border: 1px solid var(--nst-border);
845
+ border-radius: var(--nst-radius-sm);
846
+ padding: 8px 12px;
847
+ }
848
+
849
+ .nst-host[data-responsive='cards'] .nst-td {
850
+ display: flex;
851
+ justify-content: space-between;
852
+ align-items: center;
853
+ padding: 6px 0;
854
+ border-bottom: 1px dashed var(--nst-border);
855
+ }
856
+
857
+ .nst-host[data-responsive='cards'] .nst-td::before {
858
+ content: attr(data-label);
859
+ font-size: 11.5px;
860
+ font-weight: 700;
861
+ color: var(--nst-text-muted);
862
+ }
863
+ `;
864
+
865
+ // src/components/ngx-smart-table.template.ts
866
+ var NGX_SMART_TABLE_TEMPLATE = `
867
+ <div class="nst-shell">
868
+ @if (resolvedShowToolbar()) {
869
+ <div class="nst-toolbar">
870
+ <div class="nst-toolbar-start">
871
+ @if (resolvedShowSearch()) {
872
+ <div class="nst-search-box">
873
+ <svg class="nst-search-icon" viewBox="0 0 20 20" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true">
874
+ <circle cx="8.5" cy="8.5" r="5.5" />
875
+ <path d="M13 13l4 4" stroke-linecap="round" />
876
+ </svg>
877
+ <input
878
+ type="search"
879
+ class="nst-search-input"
880
+ [value]="search()"
881
+ [placeholder]="searchPlaceholder()"
882
+ (input)="onSearchInput($event)"
883
+ />
884
+ </div>
885
+ }
886
+
887
+ @if (selectedRows().length > 0) {
888
+ <span class="nst-selected-pill">
889
+ {{ selectedRows().length }} {{ isPersianUi() ? '\u0645\u0648\u0631\u062F \u0627\u0646\u062A\u062E\u0627\u0628\u200C\u0634\u062F\u0647' : 'selected' }}
890
+ </span>
891
+ }
892
+ </div>
893
+
894
+ <div class="nst-toolbar-actions">
895
+ @if (resolvedShowColumnChooser()) {
896
+ <div class="nst-dropdown-wrap">
897
+ <button
898
+ type="button"
899
+ class="nst-btn"
900
+ [class.nst-btn--active]="columnChooserOpen()"
901
+ (click)="toggleColumnChooser($event)"
902
+ >
903
+ <svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8">
904
+ <rect x="2" y="3" width="16" height="14" rx="2" />
905
+ <path d="M7.5 3v14M12.5 3v14" />
906
+ </svg>
907
+ <span>{{ isPersianUi() ? '\u0633\u062A\u0648\u0646\u200C\u0647\u0627' : 'Columns' }}</span>
908
+ </button>
909
+
910
+ @if (columnChooserOpen()) {
911
+ <div class="nst-chooser-menu" (click)="$event.stopPropagation()">
912
+ <div class="nst-chooser-head">
913
+ <span>{{ isPersianUi() ? '\u0646\u0645\u0627\u06CC\u0634 \u0633\u062A\u0648\u0646\u200C\u0647\u0627' : 'Visible Columns' }}</span>
914
+ <button type="button" class="nst-chooser-reset" (click)="resetColumns()">
915
+ {{ isPersianUi() ? '\u0628\u0627\u0632\u0646\u0634\u0627\u0646\u06CC' : 'Reset' }}
916
+ </button>
917
+ </div>
918
+ @for (col of orderedColumns(); track col.key) {
919
+ <label class="nst-chooser-item">
920
+ <input
921
+ type="checkbox"
922
+ [checked]="isColumnVisible(col.key)"
923
+ (change)="toggleColumnVisibility(col.key)"
924
+ />
925
+ <span>{{ col.header }}</span>
926
+ </label>
927
+ }
928
+ </div>
929
+ }
930
+ </div>
931
+ }
932
+
933
+ @if (canExportFormat('csv')) {
934
+ <button type="button" class="nst-btn" (click)="exportCsv()">
935
+ <svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8">
936
+ <path d="M10 3v9m0 0l-3.5-3.5M10 12l3.5-3.5M4 15.5h12" stroke-linecap="round" stroke-linejoin="round" />
937
+ </svg>
938
+ <span>CSV</span>
939
+ </button>
940
+ }
941
+ @if (canExportFormat('excel')) {
942
+ <button type="button" class="nst-btn nst-btn--accent" (click)="exportExcel()">
943
+ <svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8">
944
+ <path d="M10 3v9m0 0l-3.5-3.5M10 12l3.5-3.5M4 15.5h12" stroke-linecap="round" stroke-linejoin="round" />
945
+ </svg>
946
+ <span>Excel</span>
947
+ </button>
948
+ }
949
+ </div>
950
+ </div>
951
+ }
952
+
953
+ <div
954
+ class="nst-scroll-region"
955
+ [class.nst-scroll-region--virtual]="virtualScroll()"
956
+ [style.maxHeight.px]="virtualScroll() ? viewportHeight() : null"
957
+ (scroll)="onVirtualScroll($event)"
958
+ >
959
+ @if (loading()) {
960
+ <div class="nst-loading-bar" aria-label="Loading"></div>
961
+ }
962
+
963
+ <table class="nst-table" [class.nst-table--striped]="resolvedStriped()">
964
+ <thead [class.nst-thead--sticky]="resolvedStickyHeader()">
965
+ <tr>
966
+ @if (selectionMode() !== 'none') {
967
+ <th class="nst-th nst-th--select">
968
+ @if (selectionMode() === 'multiple') {
969
+ <input
970
+ type="checkbox"
971
+ class="nst-checkbox"
972
+ [checked]="allVisibleSelected()"
973
+ [indeterminate]="someVisibleSelected() && !allVisibleSelected()"
974
+ aria-label="Select all rows"
975
+ (change)="toggleSelectAll()"
976
+ />
977
+ }
978
+ </th>
979
+ }
980
+
981
+ @for (col of visibleColumns(); track col.key) {
982
+ <th
983
+ class="nst-th"
984
+ [style.width]="col.width ?? null"
985
+ [style.minWidth]="col.minWidth ?? null"
986
+ [class.nst-th--sortable]="isColumnSortable(col)"
987
+ [class.nst-th--dragging]="draggedColumnKey() === col.key"
988
+ [class.nst-th--drag-over]="dragOverColumnKey() === col.key"
989
+ [attr.draggable]="resolvedDraggableColumns() && col.draggable !== false"
990
+ (dragstart)="onColumnDragStart($event, col.key)"
991
+ (dragover)="onColumnDragOver($event, col.key)"
992
+ (drop)="onColumnDrop($event, col.key)"
993
+ (dragend)="onColumnDragEnd()"
994
+ (click)="onSortClick(col)"
995
+ >
996
+ <div class="nst-th-inner" [attr.data-align]="col.align ?? 'start'">
997
+ @if (resolvedDraggableColumns() && col.draggable !== false) {
998
+ <span class="nst-drag-grip" aria-hidden="true">\u22EE\u22EE</span>
999
+ }
1000
+ <span class="nst-th-title">{{ col.header }}</span>
1001
+ @if (isColumnSortable(col)) {
1002
+ <span class="nst-sort-icon" [class.nst-sort-icon--active]="sort()?.key === col.key">
1003
+ @if (sort()?.key === col.key && sort()?.direction === 'asc') {
1004
+ \u25B2
1005
+ } @else if (sort()?.key === col.key && sort()?.direction === 'desc') {
1006
+ \u25BC
1007
+ } @else {
1008
+ \u21C5
1009
+ }
1010
+ </span>
1011
+ }
1012
+ </div>
1013
+ </th>
1014
+ }
1015
+ </tr>
1016
+
1017
+ @if (resolvedShowColumnFilters()) {
1018
+ <tr class="nst-filter-row">
1019
+ @if (selectionMode() !== 'none') {
1020
+ <th class="nst-th-filter"></th>
1021
+ }
1022
+ @for (col of visibleColumns(); track col.key) {
1023
+ <th class="nst-th-filter">
1024
+ @if (col.filterable !== false) {
1025
+ <input
1026
+ type="text"
1027
+ class="nst-col-filter-input"
1028
+ [value]="columnFilters()[col.key] ?? ''"
1029
+ [placeholder]="(isPersianUi() ? '\u0641\u06CC\u0644\u062A\u0631 ' : 'Filter ') + col.header"
1030
+ (input)="onColumnFilterInput(col.key, $event)"
1031
+ />
1032
+ }
1033
+ </th>
1034
+ }
1035
+ </tr>
1036
+ }
1037
+ </thead>
1038
+
1039
+ <tbody>
1040
+ @if (virtualScroll() && virtualWindow().topSpacerPx > 0) {
1041
+ <tr class="nst-spacer-row" aria-hidden="true">
1042
+ <td [attr.colspan]="totalColumnSpan()" [style.height.px]="virtualWindow().topSpacerPx"></td>
1043
+ </tr>
1044
+ }
1045
+
1046
+ @for (row of renderedRows(); track trackRow($index, row); let rowIdx = $index) {
1047
+ <tr
1048
+ class="nst-tr"
1049
+ [class.nst-tr--selected]="isRowSelected(row)"
1050
+ [style.height.px]="virtualScroll() ? rowHeight() : null"
1051
+ (click)="onRowClicked(row)"
1052
+ >
1053
+ @if (selectionMode() !== 'none') {
1054
+ <td class="nst-td nst-td--select" (click)="$event.stopPropagation()">
1055
+ <input
1056
+ [type]="selectionMode() === 'single' ? 'radio' : 'checkbox'"
1057
+ class="nst-checkbox"
1058
+ [checked]="isRowSelected(row)"
1059
+ (change)="toggleRowSelection(row)"
1060
+ />
1061
+ </td>
1062
+ }
1063
+
1064
+ @for (col of visibleColumns(); track col.key) {
1065
+ <td
1066
+ class="nst-td"
1067
+ [attr.data-label]="col.header"
1068
+ [attr.data-align]="col.align ?? 'start'"
1069
+ >
1070
+ @if (getCellTemplate(col.key); as tpl) {
1071
+ <ng-container
1072
+ [ngTemplateOutlet]="tpl"
1073
+ [ngTemplateOutletContext]="{
1074
+ $implicit: row,
1075
+ row: row,
1076
+ value: getRawCellValue(row, col.key),
1077
+ index: rowIdx
1078
+ }"
1079
+ />
1080
+ } @else if (col.type === 'badge') {
1081
+ <span class="nst-badge" [attr.data-tone]="getBadgeTone(row, col)">
1082
+ {{ formatCell(row, col) }}
1083
+ </span>
1084
+ } @else if (col.type === 'boolean') {
1085
+ <span class="nst-bool" [class.nst-bool--true]="!!getRawCellValue(row, col.key)">
1086
+ {{ getRawCellValue(row, col.key) ? '\u2713' : '\u2014' }}
1087
+ </span>
1088
+ } @else {
1089
+ <span class="nst-cell-text" [class.nst-cell-num]="col.type === 'number'">
1090
+ {{ formatCell(row, col) }}
1091
+ </span>
1092
+ }
1093
+ </td>
1094
+ }
1095
+ </tr>
1096
+ } @empty {
1097
+ <tr>
1098
+ <td class="nst-empty" [attr.colspan]="totalColumnSpan()">
1099
+ {{ emptyText() || (isPersianUi() ? '\u062F\u0627\u062F\u0647\u200C\u0627\u06CC \u0628\u0631\u0627\u06CC \u0646\u0645\u0627\u06CC\u0634 \u06CC\u0627\u0641\u062A \u0646\u0634\u062F' : 'No matching records found') }}
1100
+ </td>
1101
+ </tr>
1102
+ }
1103
+
1104
+ @if (virtualScroll() && virtualWindow().bottomSpacerPx > 0) {
1105
+ <tr class="nst-spacer-row" aria-hidden="true">
1106
+ <td [attr.colspan]="totalColumnSpan()" [style.height.px]="virtualWindow().bottomSpacerPx"></td>
1107
+ </tr>
1108
+ }
1109
+ </tbody>
1110
+ </table>
1111
+ </div>
1112
+
1113
+ @if (!virtualScroll() && pageable()) {
1114
+ <div class="nst-pagination">
1115
+ <div class="nst-page-info">
1116
+ @if (isPersianUi()) {
1117
+ \u0646\u0645\u0627\u06CC\u0634 {{ paginationInfo().startItem }} \u062A\u0627 {{ paginationInfo().endItem }} \u0627\u0632 {{ paginationInfo().totalItems }}
1118
+ } @else {
1119
+ Showing <strong>{{ paginationInfo().startItem }}\u2013{{ paginationInfo().endItem }}</strong> of
1120
+ <strong>{{ paginationInfo().totalItems }}</strong>
1121
+ }
1122
+ </div>
1123
+
1124
+ <div class="nst-page-controls">
1125
+ <label class="nst-pagesize-label">
1126
+ <span>{{ isPersianUi() ? '\u062A\u0639\u062F\u0627\u062F:' : 'Rows:' }}</span>
1127
+ <select class="nst-pagesize-select" [value]="pageSize()" (change)="onPageSizeChange($event)">
1128
+ @for (opt of resolvedPageSizeOptions(); track opt) {
1129
+ <option [value]="opt" [selected]="opt === pageSize()">{{ opt }}</option>
1130
+ }
1131
+ </select>
1132
+ </label>
1133
+
1134
+ <div class="nst-page-btns">
1135
+ <button
1136
+ type="button"
1137
+ class="nst-page-btn"
1138
+ [disabled]="paginationInfo().safePage <= 1"
1139
+ aria-label="Previous page"
1140
+ (click)="goToPage(paginationInfo().safePage - 1)"
1141
+ >
1142
+ {{ resolvedDir() === 'rtl' ? '\u203A' : '\u2039' }}
1143
+ </button>
1144
+
1145
+ @for (p of visiblePageNumbers(); track p) {
1146
+ <button
1147
+ type="button"
1148
+ class="nst-page-btn"
1149
+ [class.nst-page-btn--active]="p === paginationInfo().safePage"
1150
+ (click)="goToPage(p)"
1151
+ >
1152
+ {{ p }}
1153
+ </button>
1154
+ }
1155
+
1156
+ <button
1157
+ type="button"
1158
+ class="nst-page-btn"
1159
+ [disabled]="paginationInfo().safePage >= paginationInfo().totalPages"
1160
+ aria-label="Next page"
1161
+ (click)="goToPage(paginationInfo().safePage + 1)"
1162
+ >
1163
+ {{ resolvedDir() === 'rtl' ? '\u2039' : '\u203A' }}
1164
+ </button>
1165
+ </div>
1166
+ </div>
1167
+ </div>
1168
+ }
1169
+ </div>
1170
+ `;
1171
+
1172
+ // src/components/ngx-smart-table.component.ts
1173
+ var NgxSmartTableComponent = class {
1174
+ constructor() {
1175
+ this.destroyRef = inject(DestroyRef);
1176
+ this.platformId = inject(PLATFORM_ID);
1177
+ this.doc = inject(DOCUMENT);
1178
+ this.injectedConfig = inject(NGX_DATAGRID_CONFIG, { optional: true });
1179
+ this.isBrowser = isPlatformBrowser(this.platformId);
1180
+ this.cellTemplates = contentChildren(NgxTableCellDirective);
1181
+ this.data = input.required();
1182
+ this.columns = input.required();
1183
+ this.rowKey = input("id");
1184
+ this.serverSide = input(false);
1185
+ this.totalItems = input(null);
1186
+ this.loading = input(false);
1187
+ this.pageable = input(true);
1188
+ this.page = model(1);
1189
+ this.pageSize = model(
1190
+ this.injectedConfig?.pageSize ?? DEFAULT_DATAGRID_CONFIG.pageSize
1191
+ );
1192
+ this.pageSizeOptions = input(void 0);
1193
+ this.selectionMode = input("none");
1194
+ this.selectedRows = model([]);
1195
+ this.virtualScroll = input(false);
1196
+ this.rowHeight = input(46);
1197
+ this.viewportHeight = input(420);
1198
+ this.overscan = input(4);
1199
+ this.showToolbar = input(void 0);
1200
+ this.showSearch = input(void 0);
1201
+ this.showColumnFilters = input(void 0);
1202
+ this.showColumnChooser = input(void 0);
1203
+ this.showExport = input(void 0);
1204
+ this.exportFormats = input(void 0);
1205
+ this.sortable = input(void 0);
1206
+ this.draggableColumns = input(void 0);
1207
+ this.stickyHeader = input(void 0);
1208
+ this.striped = input(void 0);
1209
+ this.exportFileName = input("table-export");
1210
+ this.emptyText = input("");
1211
+ this.theme = input(void 0);
1212
+ this.size = input(void 0);
1213
+ this.responsive = input(void 0);
1214
+ this.dir = input(void 0);
1215
+ this.locale = input(void 0);
1216
+ this.accentColor = input(void 0);
1217
+ this.queryChange = output();
1218
+ this.rowClick = output();
1219
+ this.columnsChange = output();
1220
+ this.search = model("");
1221
+ this.columnFilters = model({});
1222
+ this.sort = model(null);
1223
+ this.columnOrder = signal([]);
1224
+ this.hiddenColumnKeys = signal(/* @__PURE__ */ new Set());
1225
+ this.columnChooserOpen = signal(false);
1226
+ this.draggedColumnKey = signal(null);
1227
+ this.dragOverColumnKey = signal(null);
1228
+ this.scrollTop = signal(0);
1229
+ this.resolvedTheme = computed(
1230
+ () => this.theme() ?? this.injectedConfig?.theme ?? DEFAULT_DATAGRID_CONFIG.theme
1231
+ );
1232
+ this.resolvedSize = computed(
1233
+ () => this.size() ?? this.injectedConfig?.size ?? DEFAULT_DATAGRID_CONFIG.size
1234
+ );
1235
+ this.resolvedResponsive = computed(
1236
+ () => this.responsive() ?? this.injectedConfig?.responsive ?? DEFAULT_DATAGRID_CONFIG.responsive
1237
+ );
1238
+ this.resolvedLocale = computed(
1239
+ () => this.locale() ?? this.injectedConfig?.locale ?? DEFAULT_DATAGRID_CONFIG.locale
1240
+ );
1241
+ this.isPersianUi = computed(
1242
+ () => this.resolvedLocale().toLowerCase().startsWith("fa")
1243
+ );
1244
+ this.resolvedDir = computed(() => {
1245
+ const cfg = this.dir() ?? this.injectedConfig?.dir ?? DEFAULT_DATAGRID_CONFIG.dir;
1246
+ if (cfg === "ltr" || cfg === "rtl") return cfg;
1247
+ const loc = this.resolvedLocale().toLowerCase();
1248
+ return loc.startsWith("fa") || loc.startsWith("ar") || loc.startsWith("he") ? "rtl" : "ltr";
1249
+ });
1250
+ this.resolvedAccentColor = computed(
1251
+ () => this.accentColor() ?? this.injectedConfig?.accentColor ?? DEFAULT_DATAGRID_CONFIG.accentColor
1252
+ );
1253
+ this.resolvedShowToolbar = computed(
1254
+ () => this.showToolbar() ?? this.injectedConfig?.showToolbar ?? DEFAULT_DATAGRID_CONFIG.showToolbar
1255
+ );
1256
+ this.resolvedShowSearch = computed(
1257
+ () => this.showSearch() ?? this.injectedConfig?.showSearch ?? DEFAULT_DATAGRID_CONFIG.showSearch
1258
+ );
1259
+ this.resolvedShowColumnFilters = computed(
1260
+ () => this.showColumnFilters() ?? this.injectedConfig?.showColumnFilters ?? DEFAULT_DATAGRID_CONFIG.showColumnFilters
1261
+ );
1262
+ this.resolvedShowColumnChooser = computed(
1263
+ () => this.showColumnChooser() ?? this.injectedConfig?.showColumnChooser ?? DEFAULT_DATAGRID_CONFIG.showColumnChooser
1264
+ );
1265
+ this.resolvedShowExport = computed(
1266
+ () => this.showExport() ?? this.injectedConfig?.showExport ?? DEFAULT_DATAGRID_CONFIG.showExport
1267
+ );
1268
+ this.resolvedExportFormats = computed(
1269
+ () => this.exportFormats() ?? this.injectedConfig?.exportFormats ?? DEFAULT_DATAGRID_CONFIG.exportFormats
1270
+ );
1271
+ this.resolvedSortable = computed(
1272
+ () => this.sortable() ?? this.injectedConfig?.sortable ?? DEFAULT_DATAGRID_CONFIG.sortable
1273
+ );
1274
+ this.resolvedDraggableColumns = computed(
1275
+ () => this.draggableColumns() ?? this.injectedConfig?.draggableColumns ?? DEFAULT_DATAGRID_CONFIG.draggableColumns
1276
+ );
1277
+ this.resolvedStickyHeader = computed(
1278
+ () => this.stickyHeader() ?? this.injectedConfig?.stickyHeader ?? DEFAULT_DATAGRID_CONFIG.stickyHeader
1279
+ );
1280
+ this.resolvedStriped = computed(
1281
+ () => this.striped() ?? this.injectedConfig?.striped ?? DEFAULT_DATAGRID_CONFIG.striped
1282
+ );
1283
+ this.resolvedPageSizeOptions = computed(
1284
+ () => this.pageSizeOptions() ?? this.injectedConfig?.pageSizeOptions ?? DEFAULT_DATAGRID_CONFIG.pageSizeOptions
1285
+ );
1286
+ this.searchPlaceholder = computed(
1287
+ () => this.isPersianUi() ? "\u062C\u0633\u062A\u062C\u0648 \u062F\u0631 \u062C\u062F\u0648\u0644..." : "Search table..."
1288
+ );
1289
+ this.orderedColumns = computed(() => {
1290
+ const custom = this.columnOrder();
1291
+ return custom.length > 0 ? custom : this.columns();
1292
+ });
1293
+ this.visibleColumns = computed(() => {
1294
+ const hidden = this.hiddenColumnKeys();
1295
+ return this.orderedColumns().filter((col) => !hidden.has(col.key));
1296
+ });
1297
+ this.totalColumnSpan = computed(
1298
+ () => this.visibleColumns().length + (this.selectionMode() !== "none" ? 1 : 0)
1299
+ );
1300
+ this.processedRows = computed(() => {
1301
+ const raw = this.data();
1302
+ if (this.serverSide()) {
1303
+ return raw;
1304
+ }
1305
+ const filtered = filterRows(raw, this.orderedColumns(), this.search(), this.columnFilters());
1306
+ return sortRows(filtered, this.orderedColumns(), this.resolvedSortable() ? this.sort() : null);
1307
+ });
1308
+ this.paginationInfo = computed(() => {
1309
+ const rows = this.processedRows();
1310
+ if (this.serverSide()) {
1311
+ const total = this.totalItems() ?? rows.length;
1312
+ const safeSize = Math.max(1, this.pageSize());
1313
+ const totalPages = Math.max(1, Math.ceil(total / safeSize));
1314
+ const safePage = Math.min(totalPages, Math.max(1, this.page()));
1315
+ const startItem = total === 0 ? 0 : (safePage - 1) * safeSize + 1;
1316
+ const endItem = Math.min(total, startItem + rows.length - 1);
1317
+ return {
1318
+ items: rows,
1319
+ totalItems: total,
1320
+ totalPages,
1321
+ safePage,
1322
+ startItem,
1323
+ endItem: total === 0 ? 0 : endItem
1324
+ };
1325
+ }
1326
+ if (!this.pageable()) {
1327
+ return {
1328
+ items: rows,
1329
+ totalItems: rows.length,
1330
+ totalPages: 1,
1331
+ safePage: 1,
1332
+ startItem: rows.length === 0 ? 0 : 1,
1333
+ endItem: rows.length
1334
+ };
1335
+ }
1336
+ return paginateRows(rows, this.page(), this.pageSize());
1337
+ });
1338
+ this.virtualWindow = computed(
1339
+ () => computeVirtualWindow(this.processedRows(), {
1340
+ scrollTop: this.scrollTop(),
1341
+ viewportHeight: this.viewportHeight(),
1342
+ rowHeight: this.rowHeight(),
1343
+ overscan: Math.max(0, this.overscan())
1344
+ })
1345
+ );
1346
+ this.renderedRows = computed(
1347
+ () => this.virtualScroll() ? this.virtualWindow().items : this.paginationInfo().items
1348
+ );
1349
+ this.visiblePageNumbers = computed(() => {
1350
+ const total = this.paginationInfo().totalPages;
1351
+ const current = this.paginationInfo().safePage;
1352
+ const maxButtons = 5;
1353
+ let start = Math.max(1, current - Math.floor(maxButtons / 2));
1354
+ const end = Math.min(total, start + maxButtons - 1);
1355
+ start = Math.max(1, end - maxButtons + 1);
1356
+ return Array.from({ length: end - start + 1 }, (_, i) => start + i);
1357
+ });
1358
+ this.allVisibleSelected = computed(() => {
1359
+ const visible = this.renderedRows();
1360
+ return visible.length > 0 && visible.every((row) => this.isRowSelected(row));
1361
+ });
1362
+ this.someVisibleSelected = computed(() => {
1363
+ const visible = this.renderedRows();
1364
+ return visible.some((row) => this.isRowSelected(row));
1365
+ });
1366
+ effect(() => {
1367
+ const cols = this.columns();
1368
+ this.columnOrder.set([...cols]);
1369
+ const initialHidden = new Set(cols.filter((c) => c.visible === false).map((c) => c.key));
1370
+ this.hiddenColumnKeys.set(initialHidden);
1371
+ });
1372
+ if (this.isBrowser) {
1373
+ const closeChooser = () => {
1374
+ if (this.columnChooserOpen()) {
1375
+ this.columnChooserOpen.set(false);
1376
+ }
1377
+ };
1378
+ this.doc.addEventListener("click", closeChooser);
1379
+ this.destroyRef.onDestroy(() => this.doc.removeEventListener("click", closeChooser));
1380
+ }
1381
+ }
1382
+ getCellTemplate(key) {
1383
+ const found = this.cellTemplates().find((item) => item.ngxTableCell() === key);
1384
+ return found?.template ?? null;
1385
+ }
1386
+ getRawCellValue(row, key) {
1387
+ return resolveCellValue(row, key);
1388
+ }
1389
+ formatCell(row, col) {
1390
+ return formatCellDisplay(row, col);
1391
+ }
1392
+ getBadgeTone(row, col) {
1393
+ const val = resolveCellValue(row, col.key);
1394
+ return col.badgeTone ? col.badgeTone(val, row) : "neutral";
1395
+ }
1396
+ trackRow(index, row) {
1397
+ const id = resolveCellValue(row, this.rowKey());
1398
+ return id !== void 0 ? id : index;
1399
+ }
1400
+ isColumnVisible(key) {
1401
+ return !this.hiddenColumnKeys().has(key);
1402
+ }
1403
+ isColumnSortable(col) {
1404
+ return this.resolvedSortable() && col.sortable !== false;
1405
+ }
1406
+ canExportFormat(format) {
1407
+ return this.resolvedShowExport() && this.resolvedExportFormats().includes(format);
1408
+ }
1409
+ toggleColumnChooser(event) {
1410
+ event.stopPropagation();
1411
+ this.columnChooserOpen.update((v) => !v);
1412
+ }
1413
+ toggleColumnVisibility(key) {
1414
+ this.hiddenColumnKeys.update((prev) => {
1415
+ const next = new Set(prev);
1416
+ if (next.has(key)) {
1417
+ next.delete(key);
1418
+ } else if (this.visibleColumns().length > 1) {
1419
+ next.add(key);
1420
+ }
1421
+ return next;
1422
+ });
1423
+ }
1424
+ resetColumns() {
1425
+ const cols = this.columns();
1426
+ this.columnOrder.set([...cols]);
1427
+ this.hiddenColumnKeys.set(new Set(cols.filter((c) => c.visible === false).map((c) => c.key)));
1428
+ this.columnsChange.emit(this.orderedColumns());
1429
+ }
1430
+ onSearchInput(event) {
1431
+ const value = event.target.value;
1432
+ this.search.set(value);
1433
+ this.page.set(1);
1434
+ this.emitQuery();
1435
+ }
1436
+ onColumnFilterInput(key, event) {
1437
+ const value = event.target.value;
1438
+ this.columnFilters.update((prev) => ({ ...prev, [key]: value }));
1439
+ this.page.set(1);
1440
+ this.emitQuery();
1441
+ }
1442
+ onSortClick(col) {
1443
+ if (!this.isColumnSortable(col)) return;
1444
+ const current = this.sort();
1445
+ let next;
1446
+ if (!current || current.key !== col.key) {
1447
+ next = { key: col.key, direction: "asc" };
1448
+ } else if (current.direction === "asc") {
1449
+ next = { key: col.key, direction: "desc" };
1450
+ } else {
1451
+ next = null;
1452
+ }
1453
+ this.sort.set(next);
1454
+ this.emitQuery();
1455
+ }
1456
+ onColumnDragStart(event, key) {
1457
+ if (!this.resolvedDraggableColumns()) return;
1458
+ this.draggedColumnKey.set(key);
1459
+ if (event.dataTransfer) {
1460
+ event.dataTransfer.effectAllowed = "move";
1461
+ event.dataTransfer.setData("text/plain", key);
1462
+ }
1463
+ }
1464
+ onColumnDragOver(event, key) {
1465
+ if (!this.resolvedDraggableColumns() || !this.draggedColumnKey()) return;
1466
+ event.preventDefault();
1467
+ this.dragOverColumnKey.set(key);
1468
+ }
1469
+ onColumnDrop(event, targetKey) {
1470
+ event.preventDefault();
1471
+ const sourceKey = this.draggedColumnKey();
1472
+ this.draggedColumnKey.set(null);
1473
+ this.dragOverColumnKey.set(null);
1474
+ if (!sourceKey || sourceKey === targetKey) return;
1475
+ const reordered = reorderColumns(this.orderedColumns(), sourceKey, targetKey);
1476
+ this.columnOrder.set(reordered);
1477
+ this.columnsChange.emit(reordered);
1478
+ }
1479
+ onColumnDragEnd() {
1480
+ this.draggedColumnKey.set(null);
1481
+ this.dragOverColumnKey.set(null);
1482
+ }
1483
+ isRowSelected(row) {
1484
+ const key = resolveCellValue(row, this.rowKey());
1485
+ return this.selectedRows().some((item) => {
1486
+ if (key !== void 0) {
1487
+ return resolveCellValue(item, this.rowKey()) === key;
1488
+ }
1489
+ return item === row;
1490
+ });
1491
+ }
1492
+ toggleRowSelection(row) {
1493
+ const mode = this.selectionMode();
1494
+ if (mode === "none") return;
1495
+ if (mode === "single") {
1496
+ this.selectedRows.set(this.isRowSelected(row) ? [] : [row]);
1497
+ return;
1498
+ }
1499
+ const key = resolveCellValue(row, this.rowKey());
1500
+ if (this.isRowSelected(row)) {
1501
+ this.selectedRows.update(
1502
+ (list) => list.filter(
1503
+ (item) => key !== void 0 ? resolveCellValue(item, this.rowKey()) !== key : item !== row
1504
+ )
1505
+ );
1506
+ } else {
1507
+ this.selectedRows.update((list) => [...list, row]);
1508
+ }
1509
+ }
1510
+ toggleSelectAll() {
1511
+ if (this.selectionMode() !== "multiple") return;
1512
+ const visible = this.renderedRows();
1513
+ if (this.allVisibleSelected()) {
1514
+ const visibleKeys = new Set(visible.map((r) => resolveCellValue(r, this.rowKey())));
1515
+ this.selectedRows.update(
1516
+ (list) => list.filter((item) => {
1517
+ const k = resolveCellValue(item, this.rowKey());
1518
+ return k !== void 0 ? !visibleKeys.has(k) : !visible.includes(item);
1519
+ })
1520
+ );
1521
+ return;
1522
+ }
1523
+ const merged = [...this.selectedRows()];
1524
+ for (const row of visible) {
1525
+ if (!this.isRowSelected(row)) {
1526
+ merged.push(row);
1527
+ }
1528
+ }
1529
+ this.selectedRows.set(merged);
1530
+ }
1531
+ onRowClicked(row) {
1532
+ this.rowClick.emit(row);
1533
+ }
1534
+ goToPage(targetPage) {
1535
+ const safe = Math.min(this.paginationInfo().totalPages, Math.max(1, targetPage));
1536
+ if (safe === this.page()) return;
1537
+ this.page.set(safe);
1538
+ this.emitQuery();
1539
+ }
1540
+ onPageSizeChange(event) {
1541
+ const nextSize = Number(event.target.value);
1542
+ if (!Number.isFinite(nextSize) || nextSize <= 0) return;
1543
+ this.pageSize.set(nextSize);
1544
+ this.page.set(1);
1545
+ this.emitQuery();
1546
+ }
1547
+ onVirtualScroll(event) {
1548
+ if (!this.virtualScroll()) return;
1549
+ this.scrollTop.set(event.target.scrollTop);
1550
+ }
1551
+ exportCsv(options = {}) {
1552
+ const rows = options.onlySelected && this.selectedRows().length > 0 ? this.selectedRows() : this.selectedRows().length > 0 ? this.selectedRows() : this.processedRows();
1553
+ const cols = this.orderedColumns().map((c) => ({
1554
+ ...c,
1555
+ visible: this.isColumnVisible(c.key)
1556
+ }));
1557
+ const csv = buildCsvContent(rows, cols, options);
1558
+ const file = `${options.fileName ?? this.exportFileName()}.csv`;
1559
+ if (this.isBrowser) {
1560
+ triggerBrowserDownload(csv, file, "text/csv;charset=utf-8;", this.doc);
1561
+ }
1562
+ return csv;
1563
+ }
1564
+ exportExcel(options = {}) {
1565
+ const rows = options.onlySelected && this.selectedRows().length > 0 ? this.selectedRows() : this.selectedRows().length > 0 ? this.selectedRows() : this.processedRows();
1566
+ const cols = this.orderedColumns().map((c) => ({
1567
+ ...c,
1568
+ visible: this.isColumnVisible(c.key)
1569
+ }));
1570
+ const xml = buildExcelXmlContent(rows, cols, options);
1571
+ const file = `${options.fileName ?? this.exportFileName()}.xls`;
1572
+ if (this.isBrowser) {
1573
+ triggerBrowserDownload(xml, file, "application/vnd.ms-excel;charset=utf-8;", this.doc);
1574
+ }
1575
+ return xml;
1576
+ }
1577
+ emitQuery() {
1578
+ this.queryChange.emit({
1579
+ page: this.page(),
1580
+ pageSize: this.pageSize(),
1581
+ search: this.search(),
1582
+ filters: this.columnFilters(),
1583
+ sort: this.sort()
1584
+ });
1585
+ }
1586
+ };
1587
+
1588
+ NgxSmartTableComponent.ɵfac = __ngCore.ɵɵngDeclareFactory({
1589
+ minVersion: "12.0.0",
1590
+ version: "19.2.25",
1591
+ ngImport: __ngCore,
1592
+ type: NgxSmartTableComponent,
1593
+ deps: [],
1594
+ target: __ngCore.ɵɵFactoryTarget.Component
1595
+ });
1596
+ NgxSmartTableComponent.ɵcmp = __ngCore.ɵɵngDeclareComponent({
1597
+ minVersion: "17.2.0",
1598
+ version: "19.2.25",
1599
+ type: NgxSmartTableComponent,
1600
+ isStandalone: true,
1601
+ selector: "ngx-smart-table",
1602
+ inputs: {
1603
+ data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null },
1604
+ columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: true, transformFunction: null },
1605
+ rowKey: { classPropertyName: "rowKey", publicName: "rowKey", isSignal: true, isRequired: false, transformFunction: null },
1606
+ serverSide: { classPropertyName: "serverSide", publicName: "serverSide", isSignal: true, isRequired: false, transformFunction: null },
1607
+ totalItems: { classPropertyName: "totalItems", publicName: "totalItems", isSignal: true, isRequired: false, transformFunction: null },
1608
+ loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null },
1609
+ pageable: { classPropertyName: "pageable", publicName: "pageable", isSignal: true, isRequired: false, transformFunction: null },
1610
+ page: { classPropertyName: "page", publicName: "page", isSignal: true, isRequired: false, transformFunction: null },
1611
+ pageSize: { classPropertyName: "pageSize", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null },
1612
+ pageSizeOptions: { classPropertyName: "pageSizeOptions", publicName: "pageSizeOptions", isSignal: true, isRequired: false, transformFunction: null },
1613
+ selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null },
1614
+ selectedRows: { classPropertyName: "selectedRows", publicName: "selectedRows", isSignal: true, isRequired: false, transformFunction: null },
1615
+ virtualScroll: { classPropertyName: "virtualScroll", publicName: "virtualScroll", isSignal: true, isRequired: false, transformFunction: null },
1616
+ rowHeight: { classPropertyName: "rowHeight", publicName: "rowHeight", isSignal: true, isRequired: false, transformFunction: null },
1617
+ viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null },
1618
+ overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null },
1619
+ showToolbar: { classPropertyName: "showToolbar", publicName: "showToolbar", isSignal: true, isRequired: false, transformFunction: null },
1620
+ showSearch: { classPropertyName: "showSearch", publicName: "showSearch", isSignal: true, isRequired: false, transformFunction: null },
1621
+ showColumnFilters: { classPropertyName: "showColumnFilters", publicName: "showColumnFilters", isSignal: true, isRequired: false, transformFunction: null },
1622
+ showColumnChooser: { classPropertyName: "showColumnChooser", publicName: "showColumnChooser", isSignal: true, isRequired: false, transformFunction: null },
1623
+ showExport: { classPropertyName: "showExport", publicName: "showExport", isSignal: true, isRequired: false, transformFunction: null },
1624
+ exportFormats: { classPropertyName: "exportFormats", publicName: "exportFormats", isSignal: true, isRequired: false, transformFunction: null },
1625
+ sortable: { classPropertyName: "sortable", publicName: "sortable", isSignal: true, isRequired: false, transformFunction: null },
1626
+ draggableColumns: { classPropertyName: "draggableColumns", publicName: "draggableColumns", isSignal: true, isRequired: false, transformFunction: null },
1627
+ stickyHeader: { classPropertyName: "stickyHeader", publicName: "stickyHeader", isSignal: true, isRequired: false, transformFunction: null },
1628
+ striped: { classPropertyName: "striped", publicName: "striped", isSignal: true, isRequired: false, transformFunction: null },
1629
+ exportFileName: { classPropertyName: "exportFileName", publicName: "exportFileName", isSignal: true, isRequired: false, transformFunction: null },
1630
+ emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: false, transformFunction: null },
1631
+ theme: { classPropertyName: "theme", publicName: "theme", isSignal: true, isRequired: false, transformFunction: null },
1632
+ size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null },
1633
+ responsive: { classPropertyName: "responsive", publicName: "responsive", isSignal: true, isRequired: false, transformFunction: null },
1634
+ dir: { classPropertyName: "dir", publicName: "dir", isSignal: true, isRequired: false, transformFunction: null },
1635
+ locale: { classPropertyName: "locale", publicName: "locale", isSignal: true, isRequired: false, transformFunction: null },
1636
+ accentColor: { classPropertyName: "accentColor", publicName: "accentColor", isSignal: true, isRequired: false, transformFunction: null },
1637
+ search: { classPropertyName: "search", publicName: "search", isSignal: true, isRequired: false, transformFunction: null },
1638
+ columnFilters: { classPropertyName: "columnFilters", publicName: "columnFilters", isSignal: true, isRequired: false, transformFunction: null },
1639
+ sort: { classPropertyName: "sort", publicName: "sort", isSignal: true, isRequired: false, transformFunction: null }
1640
+ },
1641
+ outputs: {"pageChange":"pageChange","pageSizeChange":"pageSizeChange","selectedRowsChange":"selectedRowsChange","searchChange":"searchChange","columnFiltersChange":"columnFiltersChange","sortChange":"sortChange","queryChange":"queryChange","rowClick":"rowClick","columnsChange":"columnsChange"},
1642
+ host: {
1643
+ properties: {
1644
+ "attr.data-theme": "resolvedTheme()",
1645
+ "attr.data-size": "resolvedSize()",
1646
+ "attr.data-responsive": "resolvedResponsive()",
1647
+ "attr.dir": "resolvedDir()",
1648
+ "style.--nst-accent": "resolvedAccentColor()"
1649
+ },
1650
+ classAttribute: "nst-host"
1651
+ },
1652
+ queries: [
1653
+ { propertyName: "cellTemplates", predicate: NgxTableCellDirective, descendants: true, isSignal: true }
1654
+ ],
1655
+ exportAs: ["ngxSmartTable"],
1656
+ ngImport: __ngCore,
1657
+ template: NGX_SMART_TABLE_TEMPLATE,
1658
+ styles: [NGX_SMART_TABLE_STYLES],
1659
+ dependencies: [
1660
+ { kind: "directive", type: __NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }
1661
+ ],
1662
+ changeDetection: __ngCore.ChangeDetectionStrategy.OnPush,
1663
+ encapsulation: __ngCore.ViewEncapsulation.None
1664
+ });
1665
+
1666
+ export { DEFAULT_DATAGRID_CONFIG, NGX_DATAGRID_CONFIG, NgxSmartTableComponent, NgxTableCellDirective, buildCsvContent, buildExcelXmlContent, computeVirtualWindow, filterRows, formatCellDisplay, paginateRows, provideEasyDataGrid, reorderColumns, resolveCellValue, sortRows, triggerBrowserDownload };
1667
+ //# sourceMappingURL=index.js.map
1668
+ //# sourceMappingURL=index.js.map