@lavalogic/scoria 0.0.29 → 0.0.30
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/Components/Base/Pagination.svelte +237 -0
- package/dist/Components/Base/Pagination.svelte.d.ts +33 -0
- package/dist/Components/Dial.svelte +2 -2
- package/dist/Components/Table/Body/QuickSearchCell.svelte +14 -4
- package/dist/Components/Table/Body/Rows/ColumnListRow.svelte +25 -14
- package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +49 -0
- package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte.d.ts +28 -0
- package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +15 -44
- package/dist/Components/Table/Body/Rows/Columns/TableSelect.svelte +7 -1
- package/dist/Components/Table/Body/Rows/TableRow.svelte +5 -5
- package/dist/Components/Table/Body/TableBody.svelte +1 -1
- package/dist/Components/Table/ColumnDefinitions/ExampleItemColumnDef.svelte.js +2 -1
- package/dist/Components/Table/Misc/FilterInput.svelte +6 -0
- package/dist/Components/Table/Types/Columns/ColumnPinningState.d.ts +2 -2
- package/dist/Components/Table/Types/Columns/Definitions/Accessors/AccessorDef.svelte.d.ts +1 -1
- package/dist/Components/Table/Types/Columns/Definitions/Accessors/TextInputDef.svelte.d.ts +1 -0
- package/dist/Components/Table/Types/Columns/Definitions/ColumnDef.svelte.d.ts +8 -3
- package/dist/Components/Table/Types/Columns/Definitions/ColumnDef.svelte.js +8 -0
- package/dist/Components/Table/Types/Context/TableContext.svelte.d.ts +9 -11
- package/dist/Components/Table/Types/Context/TableContext.svelte.js +153 -143
- package/dist/Components/Table/Types/DataRepository/LocalTableDataRepository.svelte.js +6 -7
- package/dist/Components/Table/Types/Filtering/FilterValueType.d.ts +8 -0
- package/dist/Components/Table/Types/Filtering/FilterValueType.js +8 -0
- package/dist/Components/Table/Types/Filtering/NumberDateFilterMode.d.ts +0 -1
- package/dist/Components/Table/Types/Filtering/NumberDateFilterMode.js +1 -1
- package/dist/Delay/Delay.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +22 -21
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import QuerySelect from '../../QuerySelect.svelte';
|
|
27
27
|
import { AccessorDef } from '../Types/Columns/Definitions/Accessors/AccessorDef.svelte.js';
|
|
28
28
|
import { AbstractDisplayDef } from '../Types/Columns/Definitions/Display/AbstractDisplayDef.svelte.js';
|
|
29
|
+
import { dev } from '$app/environment';
|
|
29
30
|
|
|
30
31
|
export const stringFilterTypes = [
|
|
31
32
|
{ value: StringFilterMode.Equals, label: 'Equals' },
|
|
@@ -175,6 +176,11 @@
|
|
|
175
176
|
} else if (def instanceof SelectDef) {
|
|
176
177
|
untrack(async () => {
|
|
177
178
|
try {
|
|
179
|
+
if (dev) {
|
|
180
|
+
// eslint-disable-next-line no-debugger
|
|
181
|
+
debugger;
|
|
182
|
+
}
|
|
183
|
+
// TODO see if we can change the below not to use array.includes
|
|
178
184
|
const x = (await options).filter((it) => {
|
|
179
185
|
return (filteringStateValue as unknown as Array<string | number> | undefined)?.includes(
|
|
180
186
|
it.value
|
|
@@ -3,7 +3,7 @@ import type { AccessorType } from './AccessorType.js';
|
|
|
3
3
|
export interface AccessorDefProps<T extends object> extends ColumnDefProps<T> {
|
|
4
4
|
readonly id: string & keyof T;
|
|
5
5
|
}
|
|
6
|
-
export declare abstract class AccessorDef<T extends object,
|
|
6
|
+
export declare abstract class AccessorDef<T extends object, filterValueType = unknown> extends ColumnDef<T, filterValueType> {
|
|
7
7
|
readonly columnType: "Accessor";
|
|
8
8
|
abstract readonly accessorType: AccessorType;
|
|
9
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StringFilterValueType } from '../../../Filtering/FilterFn.js';
|
|
2
2
|
import { AccessorDef, type AccessorDefProps } from './AccessorDef.svelte.js';
|
|
3
3
|
export interface TextInputDefProps<T extends object> extends AccessorDefProps<T> {
|
|
4
|
+
filterValueType?: 'String';
|
|
4
5
|
}
|
|
5
6
|
export declare class TextInputDef<T extends object> extends AccessorDef<T, StringFilterValueType> {
|
|
6
7
|
readonly accessorType: "Text";
|
|
@@ -5,6 +5,7 @@ import type { FilterFn } from '../../Filtering/FilterFn.js';
|
|
|
5
5
|
import { ColumnType } from '../ColumnType.js';
|
|
6
6
|
import type { AccessorFn } from './AccessorFn.js';
|
|
7
7
|
import type { ValidationFn } from './ValidationFn.js';
|
|
8
|
+
import type { FilterValueType } from '../../Filtering/FilterValueType.js';
|
|
8
9
|
export interface ColumnDefProps<T extends object> {
|
|
9
10
|
id: string;
|
|
10
11
|
header: string | Snippet;
|
|
@@ -17,9 +18,10 @@ export interface ColumnDefProps<T extends object> {
|
|
|
17
18
|
resizable?: boolean;
|
|
18
19
|
isValid?: ValidationFn<T>;
|
|
19
20
|
filterFn?: FilterFn<T, unknown> | CustomFilterFn;
|
|
21
|
+
filterValueType?: FilterValueType;
|
|
20
22
|
accessorFn?: AccessorFn<T>;
|
|
21
23
|
}
|
|
22
|
-
export declare abstract class ColumnDef<T extends object,
|
|
24
|
+
export declare abstract class ColumnDef<T extends object, __filterValueType = unknown> {
|
|
23
25
|
protected constructor(props: ColumnDefProps<T>);
|
|
24
26
|
readonly id: string;
|
|
25
27
|
private _index;
|
|
@@ -31,8 +33,8 @@ export declare abstract class ColumnDef<T extends object, FilterValueType = unkn
|
|
|
31
33
|
readonly isValid: ValidationFn<T> | undefined;
|
|
32
34
|
readonly accessorFn: AccessorFn<T> | undefined;
|
|
33
35
|
private _filterFn;
|
|
34
|
-
get filterFn(): FilterFn<T,
|
|
35
|
-
set filterFn(v: FilterFn<T,
|
|
36
|
+
get filterFn(): FilterFn<T, __filterValueType> | CustomFilterFn | undefined;
|
|
37
|
+
set filterFn(v: FilterFn<T, __filterValueType> | CustomFilterFn | undefined);
|
|
36
38
|
private _minSize;
|
|
37
39
|
get minSize(): Pixels;
|
|
38
40
|
set minSize(v: Pixels);
|
|
@@ -45,6 +47,9 @@ export declare abstract class ColumnDef<T extends object, FilterValueType = unkn
|
|
|
45
47
|
private _visible;
|
|
46
48
|
get visible(): boolean;
|
|
47
49
|
set visible(v: boolean);
|
|
50
|
+
private _filterValueType;
|
|
51
|
+
get filterValueType(): FilterValueType | undefined;
|
|
52
|
+
set filterValueType(v: FilterValueType | undefined);
|
|
48
53
|
toJSON(): object;
|
|
49
54
|
readonly editable: boolean;
|
|
50
55
|
readonly resizable: boolean;
|
|
@@ -13,6 +13,7 @@ export class ColumnDef {
|
|
|
13
13
|
this.editable = $derived(props.editable ?? false);
|
|
14
14
|
this.resizable = $derived(props.resizable ?? true);
|
|
15
15
|
this.header = $derived(props.header);
|
|
16
|
+
this._filterValueType = $derived(props.filterValueType);
|
|
16
17
|
}
|
|
17
18
|
id;
|
|
18
19
|
_index;
|
|
@@ -69,6 +70,13 @@ export class ColumnDef {
|
|
|
69
70
|
}
|
|
70
71
|
this._isResizing = v;
|
|
71
72
|
}
|
|
73
|
+
_filterValueType;
|
|
74
|
+
get filterValueType() {
|
|
75
|
+
return this._filterValueType;
|
|
76
|
+
}
|
|
77
|
+
set filterValueType(v) {
|
|
78
|
+
this._filterValueType = v;
|
|
79
|
+
}
|
|
72
80
|
toJSON() {
|
|
73
81
|
return { columnType: this.columnType, id: this.id, header: this.header };
|
|
74
82
|
}
|
|
@@ -33,7 +33,7 @@ export declare class TableContext<T extends object> {
|
|
|
33
33
|
private _onEditCell;
|
|
34
34
|
static readonly identifier: unique symbol;
|
|
35
35
|
static init<T extends object>(defaultColumnDefs: DefsWrapper<T>, tableName: string, dataRepo: IDataRepository<T>, options: TableInitOptions<T>): TableContext<T>;
|
|
36
|
-
constructor(INTERNAL_ONLY: symbol, defaultColumnDefs: DefsWrapper<T>, tableName: string, dataRepo: IDataRepository<T>, allowCopy: boolean, enableResize: boolean, allowColumnReordering: boolean, allowQuickFiltering: boolean, allowAdvancedFiltering: boolean, toolbarPosition: ToolbarPosition, displayFooter: boolean, selectionExtractor: TableInitOptions<T>['selectionExtractor'], getUserId: () => string | undefined, _onEditCell?: TableInitOptions<T>['onEditCell']);
|
|
36
|
+
protected constructor(INTERNAL_ONLY: symbol, defaultColumnDefs: DefsWrapper<T>, tableName: string, dataRepo: IDataRepository<T>, allowCopy: boolean, enableResize: boolean, allowColumnReordering: boolean, allowQuickFiltering: boolean, allowAdvancedFiltering: boolean, toolbarPosition: ToolbarPosition, displayFooter: boolean, selectionExtractor: TableInitOptions<T>['selectionExtractor'], getUserId: () => string | undefined, _onEditCell?: TableInitOptions<T>['onEditCell']);
|
|
37
37
|
private readonly userId;
|
|
38
38
|
private isSelectable;
|
|
39
39
|
__queryValues: SvelteMap<string, unknown>;
|
|
@@ -52,16 +52,11 @@ export declare class TableContext<T extends object> {
|
|
|
52
52
|
private _showSelectedOnly;
|
|
53
53
|
get showSelectedOnly(): boolean;
|
|
54
54
|
set showSelectedOnly(v: boolean);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
get selectFilter(): FilterFn<T, SelectFilterValueType<T>> | undefined;
|
|
61
|
-
private readonly _boolFilter;
|
|
62
|
-
get boolFilter(): FilterFn<T, BoolFilterValueType> | undefined;
|
|
63
|
-
private readonly _stringFilter;
|
|
64
|
-
get stringFilter(): FilterFn<T, StringFilterValueType> | undefined;
|
|
55
|
+
readonly dateFilter: FilterFn<T, DateFilterValueType> | undefined;
|
|
56
|
+
readonly numberFilter: FilterFn<T, NumberFilterValueType> | undefined;
|
|
57
|
+
readonly selectFilter: FilterFn<T, SelectFilterValueType<T>> | undefined;
|
|
58
|
+
readonly boolFilter: FilterFn<T, BoolFilterValueType> | undefined;
|
|
59
|
+
readonly stringFilter: FilterFn<T, StringFilterValueType> | undefined;
|
|
65
60
|
private _limitFooter;
|
|
66
61
|
get limitFooter(): boolean;
|
|
67
62
|
set limitFooter(v: boolean);
|
|
@@ -147,6 +142,8 @@ export declare class TableContext<T extends object> {
|
|
|
147
142
|
private columnDefsById;
|
|
148
143
|
private readonly getSortingFn;
|
|
149
144
|
readonly originalRowIndices: Map<T, number>;
|
|
145
|
+
readonly filteredIndeces: number[];
|
|
146
|
+
readonly filteredData: T[];
|
|
150
147
|
readonly sortedData: T[];
|
|
151
148
|
readonly sortedRowModel: RowModel<T>;
|
|
152
149
|
_currentPageData: T[];
|
|
@@ -214,6 +211,7 @@ export declare class TableContext<T extends object> {
|
|
|
214
211
|
* This listener should be added and removed based on isMousingDown
|
|
215
212
|
*/
|
|
216
213
|
readonly setFocusEnd: (coords: CellCoordinates) => void;
|
|
214
|
+
private createRow;
|
|
217
215
|
private columnDefReturnsTextValue;
|
|
218
216
|
private _updateLocalStorageSettings;
|
|
219
217
|
private _moveFocusEndRow;
|
|
@@ -14,6 +14,8 @@ import { DateInputDef } from '../Columns/Definitions/Accessors/DateInputDef.svel
|
|
|
14
14
|
import { ProgressBarDef } from '../Columns/Definitions/Display/ProgressBarDef.svelte.js';
|
|
15
15
|
import { DisplayDef } from '../Columns/Definitions/Display/DisplayDef.svelte.js';
|
|
16
16
|
import { browser } from '$app/environment';
|
|
17
|
+
import { NumberDateFilterMode } from '../Filtering/NumberDateFilterMode.js';
|
|
18
|
+
import { FilterValueType } from '../Filtering/FilterValueType.js';
|
|
17
19
|
const SORTING_ICON_WIDTH = 24;
|
|
18
20
|
const InternalSymbol = Symbol();
|
|
19
21
|
export class TableContext {
|
|
@@ -88,12 +90,13 @@ export class TableContext {
|
|
|
88
90
|
this.columnPresets = [...this.columnPresets, defaultPreset];
|
|
89
91
|
};
|
|
90
92
|
this.setupDefaultColumnDefs()
|
|
91
|
-
.then(() => {
|
|
93
|
+
.then((defs) => {
|
|
94
|
+
this.isSelectable = defs.some((it) => it.id.startsWith('is-selectable-'));
|
|
92
95
|
if (this.allowColumnReordering) {
|
|
93
96
|
const savedPresets = localStorage.getItem(`${this.userId}-${tableName}-presets`);
|
|
94
97
|
if (savedPresets) {
|
|
95
98
|
const presets = JSON.parse(savedPresets);
|
|
96
|
-
if (presets[0] && areDefsEquivalent(
|
|
99
|
+
if (presets[0] && areDefsEquivalent(defs, presets[0].columnDefs)) {
|
|
97
100
|
return this.reassignDefsToPresets(presets).then(() => presets);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
@@ -133,7 +136,7 @@ export class TableContext {
|
|
|
133
136
|
// #endregion
|
|
134
137
|
// #region stores
|
|
135
138
|
userId;
|
|
136
|
-
isSelectable = $
|
|
139
|
+
isSelectable = $state(false);
|
|
137
140
|
__queryValues = new SvelteMap();
|
|
138
141
|
_paginationRepo = $state();
|
|
139
142
|
get paginationRepo() {
|
|
@@ -170,26 +173,11 @@ export class TableContext {
|
|
|
170
173
|
set showSelectedOnly(v) {
|
|
171
174
|
this._showSelectedOnly = v;
|
|
172
175
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
get numberFilter() {
|
|
179
|
-
return this._numberFilter;
|
|
180
|
-
}
|
|
181
|
-
_selectFilter = $derived(this.paginationRepo?.selectFilter);
|
|
182
|
-
get selectFilter() {
|
|
183
|
-
return this._selectFilter;
|
|
184
|
-
}
|
|
185
|
-
_boolFilter = $derived(this.paginationRepo?.boolFilter);
|
|
186
|
-
get boolFilter() {
|
|
187
|
-
return this._boolFilter;
|
|
188
|
-
}
|
|
189
|
-
_stringFilter = $derived(this.paginationRepo?.stringFilter);
|
|
190
|
-
get stringFilter() {
|
|
191
|
-
return this._stringFilter;
|
|
192
|
-
}
|
|
176
|
+
dateFilter = $derived(this.paginationRepo?.dateFilter);
|
|
177
|
+
numberFilter = $derived(this.paginationRepo?.numberFilter);
|
|
178
|
+
selectFilter = $derived(this.paginationRepo?.selectFilter);
|
|
179
|
+
boolFilter = $derived(this.paginationRepo?.boolFilter);
|
|
180
|
+
stringFilter = $derived(this.paginationRepo?.stringFilter);
|
|
193
181
|
_limitFooter = $state(false);
|
|
194
182
|
get limitFooter() {
|
|
195
183
|
return this._limitFooter;
|
|
@@ -507,13 +495,62 @@ export class TableContext {
|
|
|
507
495
|
};
|
|
508
496
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
509
497
|
originalRowIndices = $derived(new Map((this.dataRepo?.data ?? []).map((item, index) => [item, index])));
|
|
498
|
+
filteredIndeces = $derived.by(() => {
|
|
499
|
+
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|
|
500
|
+
const filterState = this.dataRepo?.filtering ?? [];
|
|
501
|
+
const data = this.dataRepo?.data ?? [];
|
|
502
|
+
if (!filterState.length) {
|
|
503
|
+
return data.map((_, index) => index) ?? [];
|
|
504
|
+
}
|
|
505
|
+
const filtered = data
|
|
506
|
+
.map((item, index) => {
|
|
507
|
+
const row = this.createRow(item, index, index);
|
|
508
|
+
const x = filterState.every((filter) => {
|
|
509
|
+
const def = this.columnDefsById.get(filter.id);
|
|
510
|
+
if (!def) {
|
|
511
|
+
console.warn(`Could not find column def for filter with id ${filter.id}`);
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
if (def.filterFn) {
|
|
515
|
+
const x = def.filterFn(row, filter.id, filter.value);
|
|
516
|
+
// debugger;
|
|
517
|
+
return x;
|
|
518
|
+
}
|
|
519
|
+
console.warn(`row ${row.id} did not have a filter function`);
|
|
520
|
+
return false;
|
|
521
|
+
});
|
|
522
|
+
// debugger;
|
|
523
|
+
if (x) {
|
|
524
|
+
return index;
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
})
|
|
530
|
+
.filter((it) => it != null);
|
|
531
|
+
return filtered;
|
|
532
|
+
}
|
|
533
|
+
return this.dataRepo?.data.map((_, index) => index) ?? [];
|
|
534
|
+
});
|
|
535
|
+
filteredData = $derived.by(() => {
|
|
536
|
+
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|
|
537
|
+
const data = this.showSelectedOnly
|
|
538
|
+
? // FIXME this will show the selected items by order of insertion to the selectedItems map.
|
|
539
|
+
[...this.selectedItems.values()]
|
|
540
|
+
: (this.filteredIndeces.map((index) => {
|
|
541
|
+
return this.dataRepo.data[index];
|
|
542
|
+
}) ?? []);
|
|
543
|
+
return data;
|
|
544
|
+
}
|
|
545
|
+
return this.dataRepo?.data ?? [];
|
|
546
|
+
});
|
|
510
547
|
sortedData = $derived.by(() => {
|
|
511
548
|
if (this.paginationRepo?.paginationType == PaginationType.Local) {
|
|
512
549
|
const state = this.dataRepo?.sorting ?? [];
|
|
513
550
|
const sortedData = this.showSelectedOnly
|
|
514
551
|
? // FIXME this will show the selected items by order of insertion to the selectedItems map.
|
|
515
552
|
[...this.selectedItems.values()]
|
|
516
|
-
:
|
|
553
|
+
: this.filteredData.concat();
|
|
517
554
|
sortedData.sort((a, b) => {
|
|
518
555
|
const end = state.length;
|
|
519
556
|
for (let i = 0; i < end; i++) {
|
|
@@ -533,59 +570,12 @@ export class TableContext {
|
|
|
533
570
|
});
|
|
534
571
|
return sortedData;
|
|
535
572
|
}
|
|
536
|
-
return this.
|
|
573
|
+
return this.filteredData ?? [];
|
|
537
574
|
});
|
|
538
575
|
sortedRowModel = $derived.by(() => {
|
|
539
576
|
const rows = this.sortedData.map((item, index) => {
|
|
540
577
|
const unsortedIndex = this.originalRowIndices.get(item) ?? index;
|
|
541
|
-
|
|
542
|
-
getValue: (key) => this.columnDefsById.get(key).accessorFn?.(item, unsortedIndex) ?? item[key],
|
|
543
|
-
original: item,
|
|
544
|
-
visibleIndex: index,
|
|
545
|
-
originalIndex: unsortedIndex,
|
|
546
|
-
id: index.toString(),
|
|
547
|
-
getLeftVisibleCells: () => leftVisibleCells,
|
|
548
|
-
getRightVisibleCells: () => rightVisibleCells,
|
|
549
|
-
getCenterVisibleCells: () => centerVisibleCells
|
|
550
|
-
};
|
|
551
|
-
const makeRow = (def) => {
|
|
552
|
-
const isVisible = $derived(this.columnVisibility[def.id] != false);
|
|
553
|
-
const isSorted = $derived.by(() => {
|
|
554
|
-
const sortState = this.paginationRepo?.sorting.find((it) => it.id == def.id);
|
|
555
|
-
if (!sortState) {
|
|
556
|
-
return 'none';
|
|
557
|
-
}
|
|
558
|
-
if (sortState.desc) {
|
|
559
|
-
return 'desc';
|
|
560
|
-
}
|
|
561
|
-
return 'asc';
|
|
562
|
-
});
|
|
563
|
-
return {
|
|
564
|
-
column: {
|
|
565
|
-
columnDef: def,
|
|
566
|
-
getCanSort: () => def.enableSorting,
|
|
567
|
-
getIsResizing: () => def.isResizing,
|
|
568
|
-
getIsSorted: () => isSorted,
|
|
569
|
-
getIsVisible: () => isVisible,
|
|
570
|
-
getToggleSortingHandler: () => def.enableSorting ? this.getToggleSortingHandler(def) : undefined,
|
|
571
|
-
id: def.id
|
|
572
|
-
},
|
|
573
|
-
id: `${index}_${def.id}`,
|
|
574
|
-
row: row,
|
|
575
|
-
getValue: () => def.accessorFn?.(item, index) ?? item[def.id] // TODO
|
|
576
|
-
};
|
|
577
|
-
};
|
|
578
|
-
const makeCellFromId = (columnId) => {
|
|
579
|
-
const def = this.columnDefsById.get(columnId);
|
|
580
|
-
return makeRow(def);
|
|
581
|
-
};
|
|
582
|
-
const leftVisibleCells = $derived(this.columnPinning.left?.map(makeCellFromId) ?? []);
|
|
583
|
-
const rightVisibleCells = $derived(this.columnPinning.right?.map(makeCellFromId) ?? []);
|
|
584
|
-
const centerVisibleCells = $derived(this.columnDefs
|
|
585
|
-
.filter((it) => !(this.columnPinning.left?.includes(it.id) ||
|
|
586
|
-
this.columnPinning.right?.includes(it.id)))
|
|
587
|
-
.map(makeRow));
|
|
588
|
-
return row;
|
|
578
|
+
return this.createRow(item, index, unsortedIndex);
|
|
589
579
|
});
|
|
590
580
|
return {
|
|
591
581
|
rows,
|
|
@@ -641,11 +631,10 @@ export class TableContext {
|
|
|
641
631
|
const def = this.columnDefsById.get(columnId);
|
|
642
632
|
return makeRow(def);
|
|
643
633
|
};
|
|
644
|
-
const leftVisibleCells = $derived(this.columnPinning.left?.map(makeCellFromId) ?? []);
|
|
645
|
-
const rightVisibleCells = $derived(this.columnPinning.right?.map(makeCellFromId) ?? []);
|
|
634
|
+
const leftVisibleCells = $derived([...(this.columnPinning.left?.keys() ?? [])].map(makeCellFromId) ?? []);
|
|
635
|
+
const rightVisibleCells = $derived([...(this.columnPinning.right?.keys() ?? [])].map(makeCellFromId) ?? []);
|
|
646
636
|
const centerVisibleCells = $derived(this.columnDefs
|
|
647
|
-
.filter((it) => !(this.columnPinning.left?.
|
|
648
|
-
this.columnPinning.right?.includes(it.id)))
|
|
637
|
+
.filter((it) => !(this.columnPinning.left?.has(it.id) || this.columnPinning.right?.has(it.id)))
|
|
649
638
|
.map(makeRow));
|
|
650
639
|
return row;
|
|
651
640
|
});
|
|
@@ -1573,6 +1562,55 @@ export class TableContext {
|
|
|
1573
1562
|
this.focusEnd = coords;
|
|
1574
1563
|
};
|
|
1575
1564
|
// #region private methods
|
|
1565
|
+
createRow(item, index, unsortedIndex) {
|
|
1566
|
+
const row = {
|
|
1567
|
+
getValue: (key) => this.columnDefsById.get(key).accessorFn?.(item, unsortedIndex) ?? item[key],
|
|
1568
|
+
original: item,
|
|
1569
|
+
visibleIndex: index,
|
|
1570
|
+
originalIndex: unsortedIndex,
|
|
1571
|
+
id: index.toString(),
|
|
1572
|
+
getLeftVisibleCells: () => leftVisibleCells,
|
|
1573
|
+
getRightVisibleCells: () => rightVisibleCells,
|
|
1574
|
+
getCenterVisibleCells: () => centerVisibleCells
|
|
1575
|
+
};
|
|
1576
|
+
const makeRow = (def) => {
|
|
1577
|
+
const isVisible = $derived(this.columnVisibility[def.id] != false);
|
|
1578
|
+
const isSorted = $derived.by(() => {
|
|
1579
|
+
const sortState = this.paginationRepo?.sorting.find((it) => it.id == def.id);
|
|
1580
|
+
if (!sortState) {
|
|
1581
|
+
return 'none';
|
|
1582
|
+
}
|
|
1583
|
+
if (sortState.desc) {
|
|
1584
|
+
return 'desc';
|
|
1585
|
+
}
|
|
1586
|
+
return 'asc';
|
|
1587
|
+
});
|
|
1588
|
+
return {
|
|
1589
|
+
column: {
|
|
1590
|
+
columnDef: def,
|
|
1591
|
+
getCanSort: () => def.enableSorting,
|
|
1592
|
+
getIsResizing: () => def.isResizing,
|
|
1593
|
+
getIsSorted: () => isSorted,
|
|
1594
|
+
getIsVisible: () => isVisible,
|
|
1595
|
+
getToggleSortingHandler: () => def.enableSorting ? this.getToggleSortingHandler(def) : undefined,
|
|
1596
|
+
id: def.id
|
|
1597
|
+
},
|
|
1598
|
+
id: `${index}_${def.id}`,
|
|
1599
|
+
row: row,
|
|
1600
|
+
getValue: () => def.accessorFn?.(item, index) ?? item[def.id] // TODO
|
|
1601
|
+
};
|
|
1602
|
+
};
|
|
1603
|
+
const makeCellFromId = (columnId) => {
|
|
1604
|
+
const def = this.columnDefsById.get(columnId);
|
|
1605
|
+
return makeRow(def);
|
|
1606
|
+
};
|
|
1607
|
+
const leftVisibleCells = $derived([...(this.columnPinning.left?.keys() ?? [])].map(makeCellFromId) ?? []);
|
|
1608
|
+
const rightVisibleCells = $derived([...(this.columnPinning.right?.keys() ?? [])].map(makeCellFromId) ?? []);
|
|
1609
|
+
const centerVisibleCells = $derived(this.columnDefs
|
|
1610
|
+
.filter((it) => !(this.columnPinning.left?.has(it.id) || this.columnPinning.right?.has(it.id)))
|
|
1611
|
+
.map(makeRow));
|
|
1612
|
+
return row;
|
|
1613
|
+
}
|
|
1576
1614
|
columnDefReturnsTextValue = (it) => {
|
|
1577
1615
|
if (!this.dataRepo) {
|
|
1578
1616
|
return false;
|
|
@@ -1793,10 +1831,10 @@ export class TableContext {
|
|
|
1793
1831
|
const midDefs = [];
|
|
1794
1832
|
const rightDefs = [];
|
|
1795
1833
|
this.columnDefs.forEach((def) => {
|
|
1796
|
-
if (this.columnPinning.left?.
|
|
1834
|
+
if (this.columnPinning.left?.has(def.id)) {
|
|
1797
1835
|
leftDefs.push(def);
|
|
1798
1836
|
}
|
|
1799
|
-
else if (this.columnPinning.right?.
|
|
1837
|
+
else if (this.columnPinning.right?.has(def.id)) {
|
|
1800
1838
|
rightDefs.push(def);
|
|
1801
1839
|
}
|
|
1802
1840
|
else {
|
|
@@ -1825,10 +1863,6 @@ export class TableContext {
|
|
|
1825
1863
|
// const helper = createColumnHelper<T>();
|
|
1826
1864
|
this.assertNoDuplicateIds();
|
|
1827
1865
|
const adjustedDefsPromises = this.defaultColumnDefs.defs.map(async (def) => {
|
|
1828
|
-
// extra width for when filtering between values
|
|
1829
|
-
const needsExtraWidth = this.allowQuickFiltering && 'type' in def && def.type === 'Number';
|
|
1830
|
-
const hasNoText = !needsExtraWidth &&
|
|
1831
|
-
(def.columnType === ColumnType.Expand || def.columnType === ColumnType.RowSelect);
|
|
1832
1866
|
if (def instanceof AccessorDef) {
|
|
1833
1867
|
// if (hasNoDefaultAccessor(temporary)) {
|
|
1834
1868
|
// temporary.accessorKey = def.id as string & keyof T;
|
|
@@ -1860,6 +1894,31 @@ export class TableContext {
|
|
|
1860
1894
|
def.filterFn = this.dateFilter;
|
|
1861
1895
|
}
|
|
1862
1896
|
}
|
|
1897
|
+
else if (this.paginationRepo?.paginationType == PaginationType.Local && !def.filterFn) {
|
|
1898
|
+
switch (def.filterValueType) {
|
|
1899
|
+
case undefined:
|
|
1900
|
+
case 'String': {
|
|
1901
|
+
def.filterFn = this.stringFilter;
|
|
1902
|
+
break;
|
|
1903
|
+
}
|
|
1904
|
+
case 'Bool': {
|
|
1905
|
+
def.filterFn = this.boolFilter;
|
|
1906
|
+
break;
|
|
1907
|
+
}
|
|
1908
|
+
case 'Date': {
|
|
1909
|
+
def.filterFn = this.dateFilter;
|
|
1910
|
+
break;
|
|
1911
|
+
}
|
|
1912
|
+
case 'Number': {
|
|
1913
|
+
def.filterFn = this.numberFilter;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
case 'Select': {
|
|
1917
|
+
def.filterFn = this.selectFilter;
|
|
1918
|
+
break;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1863
1922
|
return def;
|
|
1864
1923
|
});
|
|
1865
1924
|
const adjustedDefs = (await Promise.all(adjustedDefsPromises))
|
|
@@ -1899,14 +1958,16 @@ export class TableContext {
|
|
|
1899
1958
|
}
|
|
1900
1959
|
_setNewPinningState() {
|
|
1901
1960
|
this.columnPinning = {
|
|
1902
|
-
|
|
1961
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
1962
|
+
left: new Map(this.columnPinning.left &&
|
|
1903
1963
|
this.columnDefs
|
|
1904
|
-
.filter((col) => this.columnPinning.left?.
|
|
1905
|
-
.map((col) => col.id),
|
|
1906
|
-
|
|
1964
|
+
.filter((col) => this.columnPinning.left?.has(col.id))
|
|
1965
|
+
.map((col, index) => [col.id, index])),
|
|
1966
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
1967
|
+
right: new Map(this.columnPinning.right &&
|
|
1907
1968
|
this.columnDefs
|
|
1908
|
-
.filter((col) => this.columnPinning.right?.
|
|
1909
|
-
.map((col) => col.id)
|
|
1969
|
+
.filter((col) => this.columnPinning.right?.has(col.id))
|
|
1970
|
+
.map((col, index) => [col.id, index]))
|
|
1910
1971
|
}; // TODO
|
|
1911
1972
|
}
|
|
1912
1973
|
getToggleSortingHandler = (def) => (e) => {
|
|
@@ -1994,59 +2055,11 @@ function encapsulate(value) {
|
|
|
1994
2055
|
return `"${value.replace(/[\n]/gm, ' ').replace(/["]/g, '""')}"`;
|
|
1995
2056
|
}
|
|
1996
2057
|
function generateTableOptions(contextObj) {
|
|
1997
|
-
const _pageCount = $derived(contextObj.paginationRepo?.lastPage ?? 1);
|
|
1998
|
-
const _prm = $derived.by(() => {
|
|
1999
|
-
return contextObj.dataRepo?.paginationType === PaginationType.Local
|
|
2000
|
-
? contextObj.paginationRowModel // TODO getPaginationRowModel()
|
|
2001
|
-
: undefined;
|
|
2002
|
-
});
|
|
2003
2058
|
const _pagination = $derived.by(() => {
|
|
2004
2059
|
void contextObj.paginationRepo?.paginationState?.pageSize;
|
|
2005
2060
|
void contextObj.paginationRepo?.paginationState?.pageIndex;
|
|
2006
2061
|
return contextObj.paginationRepo?.paginationState;
|
|
2007
2062
|
});
|
|
2008
|
-
// TODO
|
|
2009
|
-
function todo(fnName) {
|
|
2010
|
-
return () => {
|
|
2011
|
-
throw new Error('TODO ' + fnName);
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
// const leftSizePx = $derived.by(() => {
|
|
2015
|
-
// if (contextObj.columnPinning.left?.length) {
|
|
2016
|
-
// return contextObj.columnDefs.reduce((total, current) => {
|
|
2017
|
-
// if (contextObj.columnPinning.left!.includes(current.id)) {
|
|
2018
|
-
// return total + contextObj.measureHeaderWidth(current);
|
|
2019
|
-
// }
|
|
2020
|
-
// return total;
|
|
2021
|
-
// }, 0);
|
|
2022
|
-
// }
|
|
2023
|
-
// return 0;
|
|
2024
|
-
// });
|
|
2025
|
-
// const rightSizePx = $derived.by(() => {
|
|
2026
|
-
// if (contextObj.columnPinning.right?.length) {
|
|
2027
|
-
// return contextObj.columnDefs.reduce((total, current) => {
|
|
2028
|
-
// if (contextObj.columnPinning.right!.includes(current.id)) {
|
|
2029
|
-
// return total + contextObj.measureHeaderWidth(current);
|
|
2030
|
-
// }
|
|
2031
|
-
// return total;
|
|
2032
|
-
// }, 0);
|
|
2033
|
-
// }
|
|
2034
|
-
// return 0;
|
|
2035
|
-
// });
|
|
2036
|
-
// const centerSizePx = $derived.by(() => {
|
|
2037
|
-
// if (contextObj.columnPinning.right?.length) {
|
|
2038
|
-
// return contextObj.columnDefs.reduce((total, current) => {
|
|
2039
|
-
// if (
|
|
2040
|
-
// contextObj.columnPinning.left?.includes(current.id) ||
|
|
2041
|
-
// contextObj.columnPinning.right?.includes(current.id)
|
|
2042
|
-
// ) {
|
|
2043
|
-
// return total;
|
|
2044
|
-
// }
|
|
2045
|
-
// return total + contextObj.measureHeaderWidth(current);
|
|
2046
|
-
// }, 0);
|
|
2047
|
-
// }
|
|
2048
|
-
// return 0;
|
|
2049
|
-
// });
|
|
2050
2063
|
const makeHeader = (def) => {
|
|
2051
2064
|
// const size = $derived(contextObj.measureHeaderWidth(def));
|
|
2052
2065
|
const isVisible = $derived(contextObj.columnVisibility[def.id] != false);
|
|
@@ -2100,8 +2113,7 @@ function generateTableOptions(contextObj) {
|
|
|
2100
2113
|
};
|
|
2101
2114
|
const leftHeaderGroups = $derived.by(() => {
|
|
2102
2115
|
const headers = contextObj.columnDefs
|
|
2103
|
-
.filter((it) => contextObj.columnVisibility[it.id] != false &&
|
|
2104
|
-
contextObj.columnPinning.left?.includes(it.id))
|
|
2116
|
+
.filter((it) => contextObj.columnVisibility[it.id] != false && contextObj.columnPinning.left?.has(it.id))
|
|
2105
2117
|
.map(makeHeader);
|
|
2106
2118
|
return [
|
|
2107
2119
|
{
|
|
@@ -2113,8 +2125,7 @@ function generateTableOptions(contextObj) {
|
|
|
2113
2125
|
});
|
|
2114
2126
|
const rightHeaderGroups = $derived.by(() => {
|
|
2115
2127
|
const headers = contextObj.columnDefs
|
|
2116
|
-
.filter((it) => contextObj.columnVisibility[it.id] != false &&
|
|
2117
|
-
contextObj.columnPinning.right?.includes(it.id))
|
|
2128
|
+
.filter((it) => contextObj.columnVisibility[it.id] != false && contextObj.columnPinning.right?.has(it.id))
|
|
2118
2129
|
.map(makeHeader);
|
|
2119
2130
|
return [
|
|
2120
2131
|
{
|
|
@@ -2127,8 +2138,7 @@ function generateTableOptions(contextObj) {
|
|
|
2127
2138
|
const centerHeaderGroups = $derived.by(() => {
|
|
2128
2139
|
const headers = contextObj.columnDefs
|
|
2129
2140
|
.filter((it) => contextObj.columnVisibility[it.id] != false &&
|
|
2130
|
-
!(contextObj.columnPinning.left?.
|
|
2131
|
-
contextObj.columnPinning.right?.includes(it.id)))
|
|
2141
|
+
!(contextObj.columnPinning.left?.has(it.id) || contextObj.columnPinning.right?.has(it.id)))
|
|
2132
2142
|
.map(makeHeader);
|
|
2133
2143
|
return [
|
|
2134
2144
|
{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Delay } from '../../../../Delay/Delay.js';
|
|
1
2
|
import { FilterType } from '../Filtering/FilterType.js';
|
|
2
3
|
import { NumberDateFilterMode } from '../Filtering/NumberDateFilterMode.js';
|
|
3
4
|
import { StringFilterMode } from '../Filtering/StringFilterMode.js';
|
|
@@ -40,9 +41,6 @@ export class LocalTableDataRepository extends TableDataRepository {
|
|
|
40
41
|
get totalRows() {
|
|
41
42
|
return this._totalRows;
|
|
42
43
|
}
|
|
43
|
-
// public set totalRows(v : number) {
|
|
44
|
-
// this._totalRows = v;
|
|
45
|
-
// }
|
|
46
44
|
_filtering = $state([]);
|
|
47
45
|
get filtering() {
|
|
48
46
|
return this._filtering;
|
|
@@ -72,18 +70,19 @@ export class LocalTableDataRepository extends TableDataRepository {
|
|
|
72
70
|
value = value.trim();
|
|
73
71
|
}
|
|
74
72
|
const oldIndex = this.filtering.findIndex((it) => it.id === id);
|
|
75
|
-
|
|
73
|
+
const newFiltering = this.filtering.concat();
|
|
74
|
+
if (oldIndex === -1 || newFiltering[oldIndex].value != value) {
|
|
76
75
|
if (oldIndex > -1) {
|
|
77
|
-
|
|
76
|
+
newFiltering.splice(oldIndex, 1);
|
|
78
77
|
}
|
|
79
78
|
const hasNoValue = value == null ||
|
|
80
79
|
(typeof value === 'object' && Array.isArray(value) && value.length === 0) ||
|
|
81
80
|
(typeof value === 'string' && value.length === 0);
|
|
82
81
|
if (!hasNoValue) {
|
|
83
|
-
|
|
82
|
+
newFiltering.push({ id, value });
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
|
-
this.filtering =
|
|
85
|
+
this.filtering = newFiltering;
|
|
87
86
|
};
|
|
88
87
|
_pageStartIndex = $derived(this.paginationState.pageIndex * this.paginationState.pageSize);
|
|
89
88
|
get pageStartIndex() {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const FilterValueType: {
|
|
2
|
+
readonly String: "String";
|
|
3
|
+
readonly Number: "Number";
|
|
4
|
+
readonly Date: "Date";
|
|
5
|
+
readonly Bool: "Bool";
|
|
6
|
+
readonly Select: "Select";
|
|
7
|
+
};
|
|
8
|
+
export type FilterValueType = (typeof FilterValueType)[keyof typeof FilterValueType];
|