@timlassiter11/yatl 0.3.2 → 0.3.3
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/README.md +8 -5
- package/dist/{datatable.css → data-table.css} +1 -1
- package/dist/data-table.css.map +1 -0
- package/dist/{datatable.d.mts → data-table.d.mts} +177 -103
- package/dist/{datatable.d.ts → data-table.d.ts} +177 -103
- package/dist/data-table.global.js +4 -0
- package/dist/data-table.global.js.map +1 -0
- package/dist/data-table.js +4 -0
- package/dist/data-table.js.map +1 -0
- package/dist/data-table.mjs +4 -0
- package/dist/data-table.mjs.map +1 -0
- package/package.json +10 -10
- package/dist/datatable.css.map +0 -1
- package/dist/datatable.global.js +0 -4
- package/dist/datatable.global.js.map +0 -1
- package/dist/datatable.js +0 -4
- package/dist/datatable.js.map +0 -1
- package/dist/datatable.mjs +0 -4
- package/dist/datatable.mjs.map +0 -1
|
@@ -1,35 +1,60 @@
|
|
|
1
|
-
type NestedKeyOf<
|
|
2
|
-
[
|
|
3
|
-
}[keyof
|
|
1
|
+
type NestedKeyOf<ObjectType extends object> = {
|
|
2
|
+
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
|
|
3
|
+
}[keyof ObjectType & (string | number)];
|
|
4
4
|
declare const createRegexTokenizer: (exp?: string) => (value: string) => {
|
|
5
5
|
value: string;
|
|
6
6
|
quoted: boolean;
|
|
7
7
|
}[];
|
|
8
8
|
|
|
9
|
+
interface VirtualScrollOptions {
|
|
10
|
+
generator: (index: number) => HTMLElement;
|
|
11
|
+
container: HTMLElement;
|
|
12
|
+
element?: HTMLElement;
|
|
13
|
+
nodePadding?: number;
|
|
14
|
+
}
|
|
15
|
+
interface IVirtualScroll {
|
|
16
|
+
start(rowCount: number): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
scrollToIndex(index: number): void;
|
|
19
|
+
scrollToPx(px: number): void;
|
|
20
|
+
}
|
|
21
|
+
interface IVirtualScrollConstructor {
|
|
22
|
+
new (options: VirtualScrollOptions): IVirtualScroll;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Defines options for loading data into the table
|
|
27
|
+
* */
|
|
28
|
+
interface LoadOptions {
|
|
29
|
+
/** If the data should replace or be added to the end of the current data */
|
|
30
|
+
append?: boolean;
|
|
31
|
+
/** If the current scroll position should be kepts */
|
|
32
|
+
keepScroll?: boolean;
|
|
33
|
+
}
|
|
9
34
|
/**
|
|
10
35
|
* Defines the possible sorting orders for columns.
|
|
11
36
|
*/
|
|
12
|
-
type SortOrder = 'asc' | 'desc'
|
|
37
|
+
type SortOrder = 'asc' | 'desc';
|
|
13
38
|
/**
|
|
14
39
|
* Callback for formatting a row's HTML element.
|
|
15
40
|
* @param row - The row data.
|
|
16
41
|
* @param element - The row element.
|
|
17
42
|
*/
|
|
18
|
-
type RowFormatterCallback<T> = (row: T, element: HTMLElement) => void;
|
|
43
|
+
type RowFormatterCallback<T extends object> = (row: T, element: HTMLElement) => void;
|
|
19
44
|
/**
|
|
20
45
|
* Callback for formatting the value of a cell.
|
|
21
46
|
* Called when the cell is created and when exporting to CSV.
|
|
22
47
|
* @param value - The value of the cell.
|
|
23
48
|
* @param row - The row data.
|
|
24
49
|
*/
|
|
25
|
-
type ValueFormatterCallback<T> = (value: any, row: T) => string;
|
|
50
|
+
type ValueFormatterCallback<T extends object> = (value: any, row: T) => string;
|
|
26
51
|
/**
|
|
27
52
|
* Callback for formatting a cell's HTML element.
|
|
28
53
|
* @param value - The value of the field.
|
|
29
54
|
* @param row - The row data.
|
|
30
55
|
* @param element - The cell element.
|
|
31
56
|
*/
|
|
32
|
-
type CellFormatterCallback<T> = (value: any, row: T, element: HTMLElement) => void;
|
|
57
|
+
type CellFormatterCallback<T extends object> = (value: any, row: T, element: HTMLElement) => void;
|
|
33
58
|
/**
|
|
34
59
|
* Callback for comparing two values.
|
|
35
60
|
* @param a - The first value.
|
|
@@ -44,8 +69,25 @@ type ComparatorCallback = (a: any, b: any) => number;
|
|
|
44
69
|
* @returns The derived value for sorting (e.g., a number or a standardized string).
|
|
45
70
|
*/
|
|
46
71
|
type SortValueCallback = (value: any) => number | string;
|
|
72
|
+
/**
|
|
73
|
+
* A filter object containing keys for the fields to be filtered,
|
|
74
|
+
* and the values used to compare against.
|
|
75
|
+
*/
|
|
76
|
+
type Filters<T extends object> = Partial<{
|
|
77
|
+
[K in keyof T]: any;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* A single query token derived from a larger string
|
|
81
|
+
*/
|
|
47
82
|
interface QueryToken {
|
|
83
|
+
/**
|
|
84
|
+
* The value to use for the token
|
|
85
|
+
*/
|
|
48
86
|
value: string;
|
|
87
|
+
/**
|
|
88
|
+
* If the token should be treated as quoted.
|
|
89
|
+
* Quoted tokens are searched for exactly, no partial matches.
|
|
90
|
+
*/
|
|
49
91
|
quoted: boolean;
|
|
50
92
|
}
|
|
51
93
|
/**
|
|
@@ -71,7 +113,7 @@ type ColumnFilterCallback = (value: any, filter: any) => boolean;
|
|
|
71
113
|
/**
|
|
72
114
|
* Column options for the table.
|
|
73
115
|
*/
|
|
74
|
-
interface ColumnOptions<T> {
|
|
116
|
+
interface ColumnOptions<T extends object> {
|
|
75
117
|
/**
|
|
76
118
|
* The field name in the data object.
|
|
77
119
|
*/
|
|
@@ -92,15 +134,6 @@ interface ColumnOptions<T> {
|
|
|
92
134
|
* Whether the column's data should be tokenized for searching.
|
|
93
135
|
*/
|
|
94
136
|
tokenize?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* The initial sort order of the column.
|
|
97
|
-
*/
|
|
98
|
-
sortOrder?: SortOrder;
|
|
99
|
-
/**
|
|
100
|
-
* The initial sort priority of the column for sorting.
|
|
101
|
-
* Lower numbers are sorted first.
|
|
102
|
-
*/
|
|
103
|
-
sortPriority?: number;
|
|
104
137
|
/**
|
|
105
138
|
* Whether the column should be visible by default.
|
|
106
139
|
*/
|
|
@@ -110,64 +143,29 @@ interface ColumnOptions<T> {
|
|
|
110
143
|
* Defaults to the table's resizable option.
|
|
111
144
|
*/
|
|
112
145
|
resizable?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* The initial width of the column.
|
|
115
|
-
* Can be a number (in pixels) or a string (e.g. "100px", "50%").
|
|
116
|
-
*/
|
|
117
|
-
width?: string | number;
|
|
118
146
|
/**
|
|
119
147
|
* A function to format the value for display.
|
|
120
148
|
*/
|
|
121
|
-
valueFormatter?: ValueFormatterCallback<T
|
|
149
|
+
valueFormatter?: ValueFormatterCallback<T> | null;
|
|
122
150
|
/**
|
|
123
151
|
* A function to format the element for display.
|
|
124
152
|
*/
|
|
125
|
-
elementFormatter?: CellFormatterCallback<T
|
|
153
|
+
elementFormatter?: CellFormatterCallback<T> | null;
|
|
126
154
|
/**
|
|
127
155
|
* A function to use for sorting the column.
|
|
128
156
|
* This overrides the default sorting behavior.
|
|
129
157
|
*/
|
|
130
|
-
sorter?: ComparatorCallback;
|
|
158
|
+
sorter?: ComparatorCallback | null;
|
|
131
159
|
/**
|
|
132
160
|
* A function to derive a comparable value from the cell's original value, specifically for sorting this column.
|
|
133
161
|
* This can be used to preprocess and cache values (e.g., convert to lowercase, extract numbers) before comparison.
|
|
134
162
|
*/
|
|
135
|
-
sortValue?: SortValueCallback;
|
|
163
|
+
sortValue?: SortValueCallback | null;
|
|
136
164
|
/**
|
|
137
165
|
* A custom function to determine if a cell's value in this column matches a given filter criterion.
|
|
138
166
|
* This is used when `DataTable.filter()` is called with an object-based filter that targets this column's field.
|
|
139
|
-
* @param value - The cell's value.
|
|
140
|
-
* @param filterCriterion - The criterion provided for this column in the main filter object.
|
|
141
|
-
*/
|
|
142
|
-
filter?: ColumnFilterCallback;
|
|
143
|
-
}
|
|
144
|
-
/** Represents the current state of a column, often used for saving and restoring column configurations. */
|
|
145
|
-
interface ColumnState {
|
|
146
|
-
/**
|
|
147
|
-
* The unique field name of the column.
|
|
148
|
-
*/
|
|
149
|
-
readonly field: string;
|
|
150
|
-
/**
|
|
151
|
-
* The user friendly title of the column.
|
|
152
|
-
*/
|
|
153
|
-
readonly title: string;
|
|
154
|
-
/**
|
|
155
|
-
* The current visibility of the column.
|
|
156
167
|
*/
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The current sort order of the column.
|
|
160
|
-
*/
|
|
161
|
-
sortOrder: SortOrder;
|
|
162
|
-
/**
|
|
163
|
-
* The current sort priority of the column.
|
|
164
|
-
* Lower numbers are sorted first.
|
|
165
|
-
*/
|
|
166
|
-
sortPriority: number;
|
|
167
|
-
/**
|
|
168
|
-
* The currently set width of the column.
|
|
169
|
-
*/
|
|
170
|
-
width: string;
|
|
168
|
+
filter?: ColumnFilterCallback | null;
|
|
171
169
|
}
|
|
172
170
|
/**
|
|
173
171
|
* Defines CSS classes to be applied to different parts of the table.
|
|
@@ -205,9 +203,9 @@ interface TableClasses {
|
|
|
205
203
|
/**
|
|
206
204
|
* Options for configuring the table.
|
|
207
205
|
*/
|
|
208
|
-
interface TableOptions<T> {
|
|
206
|
+
interface TableOptions<T extends object> {
|
|
209
207
|
/**
|
|
210
|
-
*
|
|
208
|
+
* Data to load into the table
|
|
211
209
|
*/
|
|
212
210
|
data?: T[];
|
|
213
211
|
/**
|
|
@@ -245,7 +243,7 @@ interface TableOptions<T> {
|
|
|
245
243
|
* Additional fields to include in the search.
|
|
246
244
|
* Used for fields that are not displayed as columns.
|
|
247
245
|
*/
|
|
248
|
-
extraSearchFields?:
|
|
246
|
+
extraSearchFields?: NestedKeyOf<T>[];
|
|
249
247
|
/**
|
|
250
248
|
* The text to display when there is no data in the table.
|
|
251
249
|
*/
|
|
@@ -261,21 +259,64 @@ interface TableOptions<T> {
|
|
|
261
259
|
/**
|
|
262
260
|
* A function to format each row's HTML element.
|
|
263
261
|
*/
|
|
264
|
-
rowFormatter?: RowFormatterCallback<T
|
|
262
|
+
rowFormatter?: RowFormatterCallback<T> | null;
|
|
265
263
|
/**
|
|
266
264
|
* A function to use for tokenizing values for searching.
|
|
267
265
|
*/
|
|
268
266
|
tokenizer?: TokenizerCallback;
|
|
267
|
+
virtualScrollClass?: IVirtualScrollConstructor;
|
|
269
268
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Represents the current sort state
|
|
271
|
+
*/
|
|
272
|
+
interface SortState {
|
|
273
|
+
/**
|
|
274
|
+
* The sort order
|
|
275
|
+
*/
|
|
276
|
+
order: SortOrder;
|
|
277
|
+
/**
|
|
278
|
+
* The sort priority.
|
|
279
|
+
* Lower priority means
|
|
280
|
+
*/
|
|
281
|
+
priority: number;
|
|
275
282
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
283
|
+
/** Represents the current state of a column, often used for saving and restoring column configurations. */
|
|
284
|
+
interface ColumnState<T extends object> {
|
|
285
|
+
/**
|
|
286
|
+
* The unique field name of the column.
|
|
287
|
+
*/
|
|
288
|
+
field: NestedKeyOf<T>;
|
|
289
|
+
/**
|
|
290
|
+
* The user friendly title of the column.
|
|
291
|
+
*/
|
|
292
|
+
title: string;
|
|
293
|
+
/**
|
|
294
|
+
* The current visibility of the column.
|
|
295
|
+
*/
|
|
296
|
+
visible: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* The current sort order of the column.
|
|
299
|
+
*/
|
|
300
|
+
sortState: SortState | null;
|
|
301
|
+
/**
|
|
302
|
+
* The currently set width of the column.
|
|
303
|
+
*/
|
|
304
|
+
width: string;
|
|
305
|
+
}
|
|
306
|
+
interface TableState<T extends object> {
|
|
307
|
+
columns: ColumnState<T>[];
|
|
308
|
+
searchQuery?: string | RegExp;
|
|
309
|
+
filters?: Filters<T> | FilterCallback;
|
|
310
|
+
scrollPosition: {
|
|
311
|
+
top: number;
|
|
312
|
+
left: number;
|
|
313
|
+
};
|
|
314
|
+
columnOrder: NestedKeyOf<T>[];
|
|
315
|
+
}
|
|
316
|
+
type RestorableColumnState<T extends object> = Partial<Omit<ColumnState<T>, 'field'>> & Pick<ColumnState<T>, 'field'>;
|
|
317
|
+
type RestorableTableState<T extends object> = Partial<Omit<TableState<T>, 'columns'>> & {
|
|
318
|
+
columns?: RestorableColumnState<T>[];
|
|
319
|
+
};
|
|
279
320
|
|
|
280
321
|
/**
|
|
281
322
|
* Represents a dynamic and interactive table with features like sorting, searching, filtering,
|
|
@@ -300,7 +341,7 @@ type Filters<T> = Partial<{
|
|
|
300
341
|
* });
|
|
301
342
|
* ```
|
|
302
343
|
*/
|
|
303
|
-
declare class DataTable<T> extends EventTarget {
|
|
344
|
+
declare class DataTable<T extends object> extends EventTarget {
|
|
304
345
|
#private;
|
|
305
346
|
private static readonly MatchWeights;
|
|
306
347
|
private readonly DEFAULT_OPTIONS;
|
|
@@ -313,14 +354,10 @@ declare class DataTable<T> extends EventTarget {
|
|
|
313
354
|
* @throws {TypeError} If the provided table element is not an HTMLTableElement or if columns option is not an array.
|
|
314
355
|
*/
|
|
315
356
|
constructor(table: string | HTMLTableElement, columns: ColumnOptions<T>[], options?: TableOptions<T>);
|
|
316
|
-
get options(): RequiredOptions<T>;
|
|
317
357
|
/**
|
|
318
|
-
* Gets
|
|
319
|
-
* This can be used to save and restore column configurations like visibility, sort order, and width.
|
|
320
|
-
* When setting, it attempts to apply the states to existing columns.
|
|
358
|
+
* Gets the current options applied to the table.
|
|
321
359
|
*/
|
|
322
|
-
get
|
|
323
|
-
set columnStates(states: ColumnState[]);
|
|
360
|
+
get tableOptions(): RequiredTableOptions<T>;
|
|
324
361
|
/**
|
|
325
362
|
* Gets the currently filtered and sorted rows displayed in the table.
|
|
326
363
|
*/
|
|
@@ -333,8 +370,18 @@ declare class DataTable<T> extends EventTarget {
|
|
|
333
370
|
* Gets the underlying HTMLTableElement managed by this DataTable instance.
|
|
334
371
|
*/
|
|
335
372
|
get table(): HTMLTableElement;
|
|
336
|
-
|
|
337
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Gets the current state of the table.
|
|
375
|
+
*/
|
|
376
|
+
getState(): TableState<T>;
|
|
377
|
+
/**
|
|
378
|
+
* Restores the table to the provided state.
|
|
379
|
+
* @param state - The state to restore the table to.
|
|
380
|
+
*/
|
|
381
|
+
restoreState(state: RestorableTableState<T>): void;
|
|
382
|
+
updateTableOptions(options: UpdatableTableOptions<T>): void;
|
|
383
|
+
getColumnOptions(column: NestedKeyOf<T>): Required<Omit<ColumnOptions<T>, "field">>;
|
|
384
|
+
updateColumnOptions(column: NestedKeyOf<T>, options: UpdateableColumnOptions<T>): void;
|
|
338
385
|
/**
|
|
339
386
|
* Loads data into the table
|
|
340
387
|
* @param rows - An array of data to be loaded
|
|
@@ -347,7 +394,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
347
394
|
* @param text - The text or HTML message to display.
|
|
348
395
|
* @param classes - A string or array of strings for CSS classes to apply to the message row.
|
|
349
396
|
*/
|
|
350
|
-
showMessage(text: string, classes: string
|
|
397
|
+
showMessage(text: string, ...classes: string[]): void;
|
|
351
398
|
/**
|
|
352
399
|
* Clears the current message and dispalsy the normal table data.
|
|
353
400
|
*/
|
|
@@ -372,23 +419,23 @@ declare class DataTable<T> extends EventTarget {
|
|
|
372
419
|
* @param colName - The field name of the column to sort by.
|
|
373
420
|
* @param order - The sort order: 'asc', 'desc', or `null` to remove sorting for this column.
|
|
374
421
|
*/
|
|
375
|
-
sort(colName:
|
|
422
|
+
sort(colName: NestedKeyOf<T>, order: SortOrder | null): void;
|
|
376
423
|
/**
|
|
377
424
|
* Sets the visibility of a specified column.
|
|
378
425
|
* @param colName - The field name of the column.
|
|
379
426
|
* @param visisble - `true` to show the column, `false` to hide it.
|
|
380
427
|
*/
|
|
381
|
-
setColumnVisibility(colName:
|
|
428
|
+
setColumnVisibility(colName: NestedKeyOf<T>, visisble: boolean): void;
|
|
382
429
|
/**
|
|
383
430
|
* Shows a previously hidden column.
|
|
384
431
|
* @param field - The field name of the column to show.
|
|
385
432
|
*/
|
|
386
|
-
showColumn(field:
|
|
433
|
+
showColumn(field: NestedKeyOf<T>): void;
|
|
387
434
|
/**
|
|
388
435
|
* Hides a visible column.
|
|
389
436
|
* @param field - The field name of the column to hide.
|
|
390
437
|
*/
|
|
391
|
-
hideColumn(field:
|
|
438
|
+
hideColumn(field: NestedKeyOf<T>): void;
|
|
392
439
|
/**
|
|
393
440
|
* Export the current visible table data to a CSV file.
|
|
394
441
|
* @param filename - The name of the file to save.
|
|
@@ -409,7 +456,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
409
456
|
* @param fields - An array of field names representing the new order of columns. Columns not included in the array will be placed at the end.
|
|
410
457
|
* @throws {TypeError} If `fields` is not an array.
|
|
411
458
|
*/
|
|
412
|
-
setColumnOrder(fields:
|
|
459
|
+
setColumnOrder(fields: NestedKeyOf<T>[]): void;
|
|
413
460
|
/**
|
|
414
461
|
* Refreshes the table display. This re-applies filters, sorting, and updates headers and rows.
|
|
415
462
|
*/
|
|
@@ -442,7 +489,7 @@ declare class DataTable<T> extends EventTarget {
|
|
|
442
489
|
* }
|
|
443
490
|
* ```
|
|
444
491
|
*/
|
|
445
|
-
updateRow(index: number, data: T): void;
|
|
492
|
+
updateRow(index: number, data: Partial<T>): void;
|
|
446
493
|
/**
|
|
447
494
|
* Deletes a row at a specific original index from the table.
|
|
448
495
|
* @param index - The original index of the row to delete.
|
|
@@ -454,14 +501,10 @@ declare class DataTable<T> extends EventTarget {
|
|
|
454
501
|
* @param callback - A function to execute. It receives the DataTable instance as its argument.
|
|
455
502
|
* @example dataTable.withoutUpdates(dt => { dt.sort('name', 'asc'); dt.filter({ age: '>30' }); });
|
|
456
503
|
*/
|
|
457
|
-
withoutUpdates(callback: (
|
|
504
|
+
withoutUpdates(callback: (dataTable: DataTable<T>) => void): void;
|
|
458
505
|
addEventListener<K extends keyof DataTableEventMap<T>>(type: K, listener: (this: DataTable<T>, ev: CustomEvent<DataTableEventMap<T>[K]>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
459
506
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
460
507
|
}
|
|
461
|
-
type ColumnField<T> = NestedKeyOf<T>;
|
|
462
|
-
type InternalClasses = Required<{
|
|
463
|
-
[K in keyof TableClasses]: string[];
|
|
464
|
-
}>;
|
|
465
508
|
/**
|
|
466
509
|
* Defines the mapping between event names and their detail object types.
|
|
467
510
|
*/
|
|
@@ -475,7 +518,7 @@ interface DataTableEventMap<T> {
|
|
|
475
518
|
'dt.rows.changed': object;
|
|
476
519
|
'dt.col.sort': {
|
|
477
520
|
column: string;
|
|
478
|
-
order: SortOrder;
|
|
521
|
+
order: SortOrder | null;
|
|
479
522
|
};
|
|
480
523
|
'dt.col.visibility': {
|
|
481
524
|
column: string;
|
|
@@ -490,31 +533,62 @@ interface DataTableEventMap<T> {
|
|
|
490
533
|
dropColumn: string;
|
|
491
534
|
order: string[];
|
|
492
535
|
};
|
|
536
|
+
'dt.search': {
|
|
537
|
+
query: string | RegExp | null;
|
|
538
|
+
};
|
|
493
539
|
}
|
|
494
|
-
type
|
|
495
|
-
|
|
540
|
+
type ConcreteTableClasses = Required<{
|
|
541
|
+
[K in keyof TableClasses]: string[];
|
|
542
|
+
}>;
|
|
543
|
+
type RequiredTableOptions<T extends object> = Required<Omit<TableOptions<T>, 'data' | 'classes' | 'virtualScroll'>> & {
|
|
544
|
+
classes: ConcreteTableClasses;
|
|
496
545
|
virtualScroll: number;
|
|
497
546
|
};
|
|
498
|
-
type
|
|
499
|
-
type
|
|
547
|
+
type UpdateableColumnOptions<T extends object> = Pick<ColumnOptions<T>, 'title' | 'searchable' | 'resizable' | 'sortable' | 'tokenize' | 'valueFormatter' | 'elementFormatter' | 'sorter'>;
|
|
548
|
+
type UpdatableTableOptions<T extends object> = Pick<TableOptions<T>, 'virtualScroll' | 'highlightSearch' | 'tokenizeSearch' | 'enableSearchScoring' | 'rearrangeable' | 'extraSearchFields' | 'noMatchText' | 'noDataText' | 'classes'>;
|
|
549
|
+
|
|
550
|
+
declare class VirtualScroll implements IVirtualScroll {
|
|
551
|
+
#private;
|
|
552
|
+
static AVERAGE_RENDER_COUNT: number;
|
|
553
|
+
constructor({ generator, container, element, nodePadding, }: VirtualScrollOptions);
|
|
554
|
+
private get rowHeight();
|
|
555
|
+
get started(): boolean;
|
|
556
|
+
scrollToIndex(index: number): void;
|
|
557
|
+
/**
|
|
558
|
+
* @param px
|
|
559
|
+
*/
|
|
560
|
+
scrollToPx(px: number): void;
|
|
561
|
+
start(rowCount: number): void;
|
|
562
|
+
stop(): void;
|
|
563
|
+
}
|
|
564
|
+
declare class VirtualScrollError extends Error {
|
|
565
|
+
constructor(message: string);
|
|
566
|
+
}
|
|
500
567
|
|
|
501
|
-
interface
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
568
|
+
interface LocalStorageAdapterOptions {
|
|
569
|
+
saveSearch?: boolean;
|
|
570
|
+
saveColumnTitle?: boolean;
|
|
571
|
+
saveColumnSorting?: boolean;
|
|
572
|
+
saveColumnOrder?: boolean;
|
|
573
|
+
saveColumnVisibility?: boolean;
|
|
574
|
+
saveColumnWidth?: boolean;
|
|
575
|
+
}
|
|
576
|
+
interface IDataTable<T extends object> extends EventTarget {
|
|
577
|
+
getState(): TableState<T>;
|
|
578
|
+
restoreState(state: RestorableTableState<T>): void;
|
|
506
579
|
}
|
|
580
|
+
|
|
507
581
|
/**
|
|
508
582
|
* Monitors a {@link DataTable} instance for changes and saves the state to local storage.
|
|
509
583
|
*/
|
|
510
|
-
declare class LocalStorageAdapter<T> {
|
|
584
|
+
declare class LocalStorageAdapter<T extends object> {
|
|
511
585
|
#private;
|
|
512
586
|
/**
|
|
513
587
|
* @param dataTable - The DataTable instance to monitor.
|
|
514
588
|
* @param storageKey - The key to use for saving the state in localStorage.
|
|
515
589
|
* @param options - The options for configuring what is stored.
|
|
516
590
|
*/
|
|
517
|
-
constructor(dataTable:
|
|
591
|
+
constructor(dataTable: IDataTable<T>, storageKey: string, options?: LocalStorageAdapterOptions);
|
|
518
592
|
/**
|
|
519
593
|
* Saves the current column state to localStorage.
|
|
520
594
|
*/
|
|
@@ -529,4 +603,4 @@ declare class LocalStorageAdapter<T> {
|
|
|
529
603
|
clearState(): void;
|
|
530
604
|
}
|
|
531
605
|
|
|
532
|
-
export { type CellFormatterCallback, type ColumnFilterCallback, type ColumnOptions, type ColumnState, type ComparatorCallback, DataTable, type DataTableEventMap, type FilterCallback, type Filters, type LoadOptions, LocalStorageAdapter, type QueryToken, type RowFormatterCallback, type SortOrder, type SortValueCallback, type TableClasses, type TableOptions, type TokenizerCallback, type ValueFormatterCallback, createRegexTokenizer };
|
|
606
|
+
export { type CellFormatterCallback, type ColumnFilterCallback, type ColumnOptions, type ColumnState, type ComparatorCallback, DataTable, type DataTableEventMap, type FilterCallback, type Filters, type IDataTable, type IVirtualScroll, type IVirtualScrollConstructor, type LoadOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowFormatterCallback, type SortOrder, type SortState, type SortValueCallback, type TableClasses, type TableOptions, type TableState, type TokenizerCallback, type ValueFormatterCallback, VirtualScroll, VirtualScrollError, type VirtualScrollOptions, createRegexTokenizer };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var yatl=(()=>{var ye=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames,Ee=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable;var Qe=a=>{throw TypeError(a)};var Ue=(a,n,e)=>n in a?ye(a,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[n]=e,X=(a,n)=>{for(var e in n||(n={}))ze.call(n,e)&&Ue(a,e,n[e]);if(Ee)for(var e of Ee(n))Xe.call(n,e)&&Ue(a,e,n[e]);return a};var Ge=(a,n)=>{var e={};for(var s in a)ze.call(a,s)&&n.indexOf(s)<0&&(e[s]=a[s]);if(a!=null&&Ee)for(var s of Ee(a))n.indexOf(s)<0&&Xe.call(a,s)&&(e[s]=a[s]);return e};var lt=(a,n)=>{for(var e in n)ye(a,e,{get:n[e],enumerable:!0})},dt=(a,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of at(n))!ze.call(a,i)&&i!==e&&ye(a,i,{get:()=>n[i],enumerable:!(s=nt(n,i))||s.enumerable});return a};var ct=a=>dt(ye({},"__esModule",{value:!0}),a);var ke=(a,n,e)=>n.has(a)||Qe("Cannot "+e);var t=(a,n,e)=>(ke(a,n,"read from private field"),e?e.call(a):n.get(a)),u=(a,n,e)=>n.has(a)?Qe("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(a):n.set(a,e),p=(a,n,e,s)=>(ke(a,n,"write to private field"),s?s.call(a,e):n.set(a,e),e),h=(a,n,e)=>(ke(a,n,"access private method"),e);var ht={};lt(ht,{DataTable:()=>He,LocalStorageAdapter:()=>je,VirtualScroll:()=>de,VirtualScrollError:()=>te,createRegexTokenizer:()=>Fe});var D=a=>{if(typeof a=="string"&&a!=="")return a.split(" ");if(Array.isArray(a))return a;if(!a)return[];throw new TypeError("classes must be string or array of strings")},Be=a=>a.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()),Fe=(a="\\S+")=>{let n=new RegExp(`"[^"]*"|${a}`,"g");return e=>(e.match(n)||[]).map(i=>(i=i.toLocaleLowerCase().trim(),i.startsWith('"')&&i.endsWith('"')?{value:i.slice(1,-1),quoted:!0}:{value:i,quoted:!1}))};function Je(a){return typeof a=="boolean"?a?1:Number.MAX_SAFE_INTEGER:a}function Ye(a,n={}){return{scroller:[...D(n.scroller),...D(a.scroller)],thead:[...D(n.thead),...D(a.thead)],tbody:[...D(n.tbody),...D(a.tbody)],tr:[...D(n.tr),...D(a.tr)],th:[...D(n.th),...D(a.th)],td:[...D(n.td),...D(a.td)],mark:[...D(n.mark),...D(a.mark)]}}var ce,z,W,q,_,$,he,P,G,fe,B,J,ee,ue,j,le,Ze,Q=class Q{constructor({generator:n,container:e,element:s=e,nodePadding:i=10}){u(this,j);u(this,z);u(this,W);u(this,q);u(this,_,0);u(this,$,0);u(this,he,2);u(this,P,0);u(this,G,!1);u(this,fe,0);u(this,B);u(this,J);u(this,ee);u(this,ue,()=>{t(this,z).scrollTop!==t(this,fe)&&(p(this,fe,t(this,z).scrollTop),t(this,P)&&cancelAnimationFrame(t(this,P)),p(this,P,requestAnimationFrame(()=>h(this,j,le).call(this))))});p(this,z,e),p(this,W,s),p(this,q,n),p(this,he,i),p(this,B,document.createElement("div")),t(this,B).style.visibility="hidden",p(this,J,document.createElement("div")),t(this,J).style.visibility="hidden",p(this,ee,new ResizeObserver(()=>h(this,j,le).call(this)))}get rowHeight(){return t(this,$)||h(this,j,Ze).call(this),t(this,$)}get started(){return t(this,G)}scrollToIndex(n){if(n<0||n>=t(this,_))throw new RangeError("Index out of bounds.");this.scrollToPx(this.rowHeight*n)}scrollToPx(n){t(this,z).scrollTop=n,h(this,j,le).call(this)}start(n){t(this,G)||(t(this,z).addEventListener("scroll",t(this,ue)),t(this,ee).observe(t(this,z)),p(this,G,!0)),t(this,z).classList.add("dt-virtual-scroll"),p(this,_,n),h(this,j,le).call(this)}stop(){t(this,P)&&cancelAnimationFrame(t(this,P)),t(this,z).classList.remove("dt-virtual-scroll"),t(this,z).removeEventListener("scroll",t(this,ue)),t(this,ee).disconnect(),p(this,G,!1)}};ce=new WeakMap,z=new WeakMap,W=new WeakMap,q=new WeakMap,_=new WeakMap,$=new WeakMap,he=new WeakMap,P=new WeakMap,G=new WeakMap,fe=new WeakMap,B=new WeakMap,J=new WeakMap,ee=new WeakMap,ue=new WeakMap,j=new WeakSet,le=function(){let n=t(this,z).scrollTop,e=t(this,_),s=this.rowHeight,i=t(this,he);if(!this.started||!e||!s)return;let r=s*e;t(this,W).innerHTML=`<div style="height: ${r}px;"></div>`;let o=t(this,W).offsetHeight,l=t(this,z).offsetHeight;!t(Q,ce)&&o<Math.round(r-1)&&(p(Q,ce,!0),console.error("Max element height exceeded. Virtual scroll may not work."));let f=i*2,d=Math.floor(n/s)-i;d<0&&(f+=d),d=Math.max(0,d);let g=Math.ceil(l/s)+f;g=Math.min(e-d,g),d%2===1&&d--;let T=d*s,v=r-(T+g*s);t(this,W).innerHTML="";let E=new Array(g).fill(null).map((x,y)=>t(this,q).call(this,y+d));t(this,B).style.height=T+"px",t(this,J).style.height=v+"px",t(this,W).append(t(this,B)),t(this,W).append(...E),t(this,W).append(t(this,J))},Ze=function(){if(t(this,_)===0){p(this,$,0);return}let n=Math.min(Q.AVERAGE_RENDER_COUNT,t(this,_)),e=[];for(let i=0;i<n;++i)e.push(t(this,q).call(this,i));let s=document.createElement("div");s.style.position="absolute",s.style.visibility="hidden",s.style.height="auto",s.style.width="100%",s.style.top="-9999px",s.style.left="-9999px",s.style.maxHeight="none",s.style.overflow="visible",s.style.display="block";try{s.append(...e),document.body.append(s),p(this,$,s.offsetHeight/n)}finally{s.remove()}if(t(this,$)<=0)throw new te(`First ${n} rows had no rendered height. Virtual scroll can't be used.`);t(this,$)*t(this,_)>33554400&&console.warn("Virtual scroll height exceeded maximum known element height.")},u(Q,ce,!1),Q.AVERAGE_RENDER_COUNT=1e3;var de=Q,te=class extends Error{constructor(n){super(n)}};var C,Y,N,L,b,k,R,oe,M,V,F,H,m,A,c,et,tt,Ie,Ne,Ve,Ae,st,K,it,me,se,pe,We,rt,_e,ie,$e,we,Se,ge,be,xe,Ce,Le,Oe,Re,Me,De,re=class re extends EventTarget{constructor(e,s,i={}){super();u(this,c);this.DEFAULT_OPTIONS={virtualScroll:1e3,highlightSearch:!0,tokenizeSearch:!1,enableSearchScoring:!1,sortable:!0,resizable:!0,rearrangeable:!0,extraSearchFields:[],noDataText:"No records found",noMatchText:"No matching records found",classes:{scroller:["dt-scroller"],thead:["dt-headers"],tbody:[],tr:[],th:[],td:[],mark:[]},rowFormatter:null,tokenizer:Fe(),virtualScrollClass:de};u(this,C);u(this,Y);u(this,N);u(this,L);u(this,b,new Map);u(this,k,new Map);u(this,R,[]);u(this,oe);u(this,M);u(this,V);u(this,F);u(this,H);u(this,m);u(this,A,!1);u(this,we,e=>{var o;if((o=window.getSelection())!=null&&o.toString())return;let s,i,r;if(e.target instanceof HTMLTableCellElement?(i=e.target,s=i.parentElement,r=i.dataset.dtField):e.target instanceof HTMLTableRowElement&&(s=e.target),s){let l=parseInt(s.dataset.dtIndex||"");if(!isNaN(l)){let f=t(this,R).find(d=>d._metadata.index===l);if(f){let d=new CustomEvent("dt.row.clicked",{cancelable:!1,detail:{row:f,index:l,column:r,originalEvent:e}});this.dispatchEvent(d)}}}});u(this,Se,e=>{if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("dt-resizer")||!(e.currentTarget instanceof HTMLElement)||!e.currentTarget.dataset.dtField)return;e.stopImmediatePropagation(),e.preventDefault();let s=e.currentTarget.dataset.dtField,i=t(this,b).get(s);i&&(p(this,H,i),i.resizeStartX=e.clientX,i.resizeStartWidth=i.headerElement.offsetWidth,document.addEventListener("mousemove",t(this,ge)),document.addEventListener("mouseup",t(this,be)))});u(this,ge,e=>{if(!t(this,H))return;e.stopImmediatePropagation(),e.preventDefault();let s=e.clientX-t(this,H).resizeStartX,i=t(this,H).resizeStartWidth+s;h(this,c,$e).call(this,t(this,H),i)});u(this,be,e=>{if(!t(this,H))return;e.stopImmediatePropagation(),e.preventDefault(),document.removeEventListener("mousemove",t(this,ge)),document.removeEventListener("mouseup",t(this,be));let s=new CustomEvent("dt.col.resize",{cancelable:!1,detail:{column:t(this,H).field,width:t(this,H).headerElement.offsetWidth}});this.dispatchEvent(s),p(this,H,void 0)});u(this,xe,e=>{if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("dt-resizer")||!(e.currentTarget instanceof HTMLElement)||!e.currentTarget.dataset.dtField)return;let s=e.currentTarget.dataset.dtField;if(!s)return;let i=t(this,b).get(s);i&&h(this,c,$e).call(this,i)});u(this,Ce,e=>{let i=e.target.dataset.dtField;e.dataTransfer&&i&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i))});u(this,Le,e=>(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="move"),!1));u(this,Oe,e=>{e.target.classList.add("dt-drag-over")});u(this,Re,e=>{e.target.classList.remove("dt-drag-over")});u(this,Me,e=>{var d;let s=(d=e.dataTransfer)==null?void 0:d.getData("text/plain"),r=e.currentTarget.dataset.dtField;if(!s||!r)return;e.preventDefault(),e.stopPropagation();let o=[...t(this,b).values()],l=o.findIndex(g=>g.field===s),f=o.findIndex(g=>g.field===r);if(l>-1&&f>-1){let[g]=o.splice(l,1),T=t(this,b).get(r);if(!T)return;o.splice(f,0,g);let v=o.map(x=>x.field),E=new CustomEvent("dt.col.reorder",{cancelable:!0,detail:{draggedColumn:g.field,dropColumn:T.field,order:v}});if(!this.dispatchEvent(E))return;this.setColumnOrder(v)}});u(this,De,()=>{let e=document.querySelectorAll(".dt-drag-over");for(let s of e)s.classList.remove("dt-drag-over")});p(this,m,X({},this.DEFAULT_OPTIONS));let x=i,{data:r,sortable:o,resizable:l,virtualScrollClass:f}=x,d=Ge(x,["data","sortable","resizable","virtualScrollClass"]);if(o!==void 0&&(t(this,m).sortable=o),l!==void 0&&(t(this,m).resizable=l),f!==void 0&&(t(this,m).virtualScrollClass=f),typeof e=="string"){let y=document.querySelector(e);if(!y)throw new SyntaxError(`Failed to find table using selector ${e}`);p(this,C,y)}else p(this,C,e);if(!(t(this,C)instanceof HTMLTableElement))throw new TypeError("Invalid table element type. Must be HTMLTableElement");let{scroller:g,thead:T,headerRow:v,tbody:E}=h(this,c,et).call(this);p(this,L,g),p(this,Y,T),p(this,N,E),h(this,c,tt).call(this,s,v),this.updateTableOptions(X(X({},t(this,m)),d)),this.loadData(r!=null?r:[])}get tableOptions(){return structuredClone(t(this,m))}get rows(){return[...t(this,R)]}get data(){return[...t(this,k).values()]}get table(){return t(this,C)}getState(){let e=[...t(this,b).values()];return{searchQuery:t(this,oe),filters:t(this,V),scrollPosition:{top:t(this,L).scrollTop,left:t(this,L).scrollLeft},columnOrder:e.map(s=>s.field),columns:e.map(s=>({field:s.field,title:s.options.title,visible:s.options.visible,sortState:s.sortState,width:s.headerElement.style.width}))}}restoreState(e){this.withoutUpdates(()=>{var s,i,r;if("searchQuery"in e&&this.search(e.searchQuery),"filters"in e&&p(this,V,e.filters),"scrollPosition"in e&&e.scrollPosition&&(t(this,L).scrollTop=e.scrollPosition.top),"columnOrder"in e&&e.columnOrder&&this.setColumnOrder(e.columnOrder),"columns"in e&&e.columns)for(let o of e.columns){let l=t(this,b).get(o.field);if(!l){console.warn(`Attempting to restore state for non-existent column ${o.field}`);continue}l.options.visible=(s=o.visible)!=null?s:l.options.visible,l.sortState=(i=o.sortState)!=null?i:l.sortState,l.headerElement.style.width=(r=o.width)!=null?r:l.headerElement.style.width}})}updateTableOptions(e){let s=!1,i=!1,r=!1;p(this,A,!0);let{virtualScroll:o,highlightSearch:l,tokenizeSearch:f,enableSearchScoring:d,rearrangeable:g,extraSearchFields:T,noMatchText:v,noDataText:E,classes:x}=e;if(o!==void 0&&(t(this,m).virtualScroll=Je(o),s=!0),l!==void 0&&(t(this,m).highlightSearch=l,s=!0),f!==void 0&&(t(this,m).tokenizeSearch=f,r=!0,this.search(t(this,oe))),d!==void 0&&(t(this,m).enableSearchScoring=d,i=!0),g!==void 0){t(this,m).rearrangeable=g;for(let y of t(this,b).values())y.headerElement.draggable=g}if(T!==void 0&&(t(this,m).extraSearchFields=T,r=!0),v!==void 0&&(t(this,m).noMatchText=v,this.rows.length===0&&(s=!0)),E!==void 0&&(t(this,m).noDataText=E,this.rows.length===0&&(s=!0)),x!==void 0){t(this,m).classes=Ye(t(this,m).classes,x),t(this,L).className=t(this,m).classes.scroller.join(" "),t(this,Y).className=t(this,m).classes.thead.join(" "),t(this,N).className=t(this,m).classes.tbody.join(" ");for(let y of t(this,b).values())y.headerElement.className=t(this,m).classes.th.join(" "),this.updateColumnOptions(y.field,{sortable:y.options.sortable});s=!0}t(this,m).enableSearchScoring&&!t(this,m).tokenizeSearch&&(t(this,m).enableSearchScoring=!1,console.warn("Search scoring enabled with tokenization disabled... Ignoring")),p(this,A,!1),r?this.loadData(this.data):i?h(this,c,K).call(this):s&&h(this,c,pe).call(this)}getColumnOptions(e){let s=t(this,b).get(e);if(!s)throw new Error(`Cannot get options for non-existent column "${e}"`);return s.options}updateColumnOptions(e,s){let i=t(this,b).get(e);if(!i)throw new Error(`Cannot update options for non-existent column "${e}"`);let r=!1,o=!1,l=!1,f=!1,d=!1,{title:g,searchable:T,resizable:v,sortable:E,tokenize:x,valueFormatter:y,elementFormatter:S,sorter:O}=s;g!==void 0&&(i.titleElement.textContent=g,i.options.title=g),T!==void 0&&(i.options.searchable=T,l=!0),E!==void 0&&(i.options.sortable=E,r=!0),v!==void 0&&(i.options.resizable=v,r=!0),x!==void 0&&(i.options.tokenize=x,o=!0),y!==void 0&&(i.options.valueFormatter=y,d=!0),S!==void 0&&(i.options.elementFormatter=S,d=!0),O!==void 0&&(i.options.sorter=O,f=!0),o?this.loadData(this.data):l?h(this,c,K).call(this):f?h(this,c,me).call(this):d?h(this,c,pe).call(this):r&&h(this,c,se).call(this)}loadData(e,s={}){let i=t(this,L).scrollTop,r=t(this,L).scrollLeft;s.append||(t(this,k).clear(),p(this,R,[]));let o=t(this,k).size;for(let l of e){let f=h(this,c,Ie).call(this,l,o);t(this,k).set(o,f),o++}h(this,c,se).call(this),h(this,c,K).call(this),s.keepScroll&&(t(this,L).scrollTop=i,t(this,L).scrollLeft=r)}showMessage(e,...s){let i=t(this,b).size;t(this,N).innerHTML=`<tr class="${s.join(" ")}"><td colSpan=${i}>${e}</td></tr>`}clearMessage(){h(this,c,pe).call(this)}search(e){let s=new CustomEvent("dt.search",{cancelable:!0,detail:{query:e!=null?e:null}});this.dispatchEvent(s)&&(p(this,oe,e),e===""&&(e=void 0),typeof e=="string"?t(this,m).tokenizeSearch?p(this,M,t(this,m).tokenizer(e)):p(this,M,[{value:e.toLocaleLowerCase(),quoted:!0}]):p(this,M,e),h(this,c,K).call(this))}filter(e){p(this,V,e),h(this,c,K).call(this)}sort(e,s){var f;let i=t(this,b).get(e);if(!i)throw new Error(`Cannot get options for non-existent column "${e}"`);if(s===((f=i.sortState)==null?void 0:f.order))return;let r=new CustomEvent("dt.col.sort",{cancelable:!0,detail:{column:i.field,order:s}});if(!this.dispatchEvent(r))return;if(s&&!i.sortState){let d=[...t(this,b).values()].map(v=>{var E;return(E=v.sortState)==null?void 0:E.priority}).filter(v=>v!==void 0),g=t(this,b).size+1,T=Math.min(g,...d)-1;i.sortState={order:s,priority:T}}else s&&i.sortState?i.sortState.order=s:i.sortState=null;let o=t(this,L).scrollTop,l=t(this,L).scrollLeft;h(this,c,se).call(this),h(this,c,me).call(this),t(this,L).scrollTop=o,t(this,L).scrollLeft=l}setColumnVisibility(e,s){let i=t(this,b).get(e);if(!i)throw new Error(`Cannot get options for non-existent column "${e}"`);if(i.options.visible===s)return;let r=new CustomEvent("dt.col.visibility",{cancelable:!0,detail:{column:i.field,visible:s}});this.dispatchEvent(r)&&(i.options.visible=s,h(this,c,se).call(this),h(this,c,me).call(this))}showColumn(e){this.setColumnVisibility(e,!0)}hideColumn(e){this.setColumnVisibility(e,!1)}export(e,s=!1){let r=[...(s?t(this,k):t(this,R)).values()],o=[...t(this,b).values()].filter(T=>s||T.options.visible).map(T=>`"${T.options.title}"`).join(","),l=r.map(T=>{let v=[];for(let E of t(this,b).keys()){let x=t(this,b).get(E);if(!x)continue;let y=T[E];(s||!x.headerElement.hidden)&&(typeof x.options.valueFormatter=="function"&&(y=x.options.valueFormatter(y,T)),y=String(y).replace('"','""'),v.push(`"${y}"`))}return v.join(",")}).join(`
|
|
2
|
+
`),f=o+`
|
|
3
|
+
`+l,d=new Blob([f],{type:"text/csv;charset=utf-8,"}),g=document.createElement("a");g.style.display="none",g.href=URL.createObjectURL(d),g.download=`${e}.csv`,document.body.append(g),g.click(),g.remove()}scrollToRow(e){var r;let i=(r=e._metadata)==null?void 0:r.index;if(typeof i=="number")this.scrollToOriginalIndex(i);else throw new Error("Row not in table")}scrollToOriginalIndex(e){let s=t(this,k).get(e);if(s){let i=t(this,R).indexOf(s);if(i>=0){this.scrollToFilteredIndex(i);return}else throw new Error("Cannot scroll to filtered out row")}else throw new RangeError(`Row index ${e} out of range`)}scrollToFilteredIndex(e){let s=t(this,R)[e];if(!s)throw new RangeError(`Row index ${e} out of range`);if(t(this,F))t(this,F).scrollToIndex(e);else{let i=t(this,N).querySelector(`tr[data-dt-index="${s._metadata.index}"]`);if(i){i.scrollIntoView(!0);let r=parseFloat(getComputedStyle(t(this,Y)).height);t(this,L).scrollTop-=r}}}scrollToPx(e){if(t(this,F))t(this,F).scrollToPx(e);else{let s=parseFloat(getComputedStyle(t(this,Y)).height);t(this,L).scrollTop=e-s}}setColumnOrder(e){if(!Array.isArray(e))throw new TypeError("fields must be an array of field names");let s=new Map;for(let i of e){let r=t(this,b).get(i);r&&s.set(i,r)}for(let[i,r]of t(this,b))s.has(i)||s.set(i,r);p(this,b,s),this.refresh()}refresh(){h(this,c,se).call(this),h(this,c,K).call(this)}indexOf(e,s){let r=[...t(this,k).values()].find(o=>{if(e in o)return o[e]===s});return r?r._metadata.index:-1}updateRow(e,s){let i=t(this,k).get(e);i&&(Object.assign(i,s),h(this,c,Ie).call(this,i,e),h(this,c,K).call(this))}deleteRow(e){t(this,k).delete(e),h(this,c,K).call(this)}withoutUpdates(e){p(this,A,!0);try{e(this)}finally{p(this,A,!1),this.refresh()}}addEventListener(e,s,i){super.addEventListener(e,s,i)}};C=new WeakMap,Y=new WeakMap,N=new WeakMap,L=new WeakMap,b=new WeakMap,k=new WeakMap,R=new WeakMap,oe=new WeakMap,M=new WeakMap,V=new WeakMap,F=new WeakMap,H=new WeakMap,m=new WeakMap,A=new WeakMap,c=new WeakSet,et=function(){var o;t(this,C).classList.add("data-table");let e=document.createElement("div");e.style.overflow="auto",e.style.height="100%",t(this,C).style.height!==""&&(e.style.height=t(this,C).style.height,t(this,C).style.height="");let s=document.createElement("thead"),i=document.createElement("tr"),r=document.createElement("tbody");return r.addEventListener("click",t(this,we)),t(this,C).innerHTML="",s.append(i),t(this,C).append(s),t(this,C).append(r),(o=t(this,C).parentElement)==null||o.insertBefore(e,t(this,C)),e.append(t(this,C)),{scroller:e,thead:s,headerRow:i,tbody:r}},tt=function(e,s){var r,o,l,f,d,g,T,v,E,x,y;t(this,b).clear();let i=!1;for(let S of e){let O=document.createElement("th"),Te=document.createElement("div"),ae=document.createElement("div"),ve=document.createElement("span"),ot=t(this,m).tokenizeSearch&&(r=S.tokenize)!=null?r:!1,I={field:S.field,options:{title:(o=S.title)!=null?o:Be(S.field),visible:(l=S.visible)!=null?l:!0,sortable:(f=S.sortable)!=null?f:t(this,m).sortable,searchable:(d=S.searchable)!=null?d:!1,tokenize:ot,resizable:(g=S.resizable)!=null?g:t(this,m).resizable,valueFormatter:(T=S.valueFormatter)!=null?T:null,elementFormatter:(v=S.elementFormatter)!=null?v:null,sorter:(E=S.sorter)!=null?E:null,sortValue:(x=S.sortValue)!=null?x:null,filter:(y=S.filter)!=null?y:null},headerElement:O,titleElement:ve,sortState:null,resizeStartWidth:null,resizeStartX:null};t(this,b).set(S.field,I),O.dataset.dtField=S.field,O.hidden=!I.options.visible,Te.classList.add("dt-header-content"),O.append(Te),ae.classList.add("dt-header-title-wrapper"),Te.append(ae),ve.classList.add("dt-header-title"),ve.innerHTML=I.options.title,ae.append(ve);let Ke=document.createElement("div");Ke.classList.add("dt-sort-icon"),ae.append(Ke);let Pe=document.createElement("div");Pe.classList.add("dt-resizer"),Te.append(Pe),s.append(O),I.options.visible&&(i=!0),this.updateColumnOptions(S.field,I.options),t(this,m).rearrangeable&&(O.draggable=!0),ae.addEventListener("click",()=>{O.classList.contains("dt-sortable")&&(I.sortState?I.sortState.order==="asc"?this.sort(I.field,"desc"):I.sortState.order&&this.sort(I.field,null):this.sort(I.field,"asc"))}),O.addEventListener("dragstart",t(this,Ce)),O.addEventListener("dragenter",t(this,Oe)),O.addEventListener("dragover",t(this,Le)),O.addEventListener("dragleave",t(this,Re)),O.addEventListener("drop",t(this,Me)),O.addEventListener("dragend",t(this,De)),O.addEventListener("mousedown",t(this,Se)),O.addEventListener("dblclick",t(this,xe))}if(t(this,b).size===0)console.warn("No columns found. At least one column is required.");else if(!i){console.warn("At least a single column must be visible. Showing the first column.");let S=e[0].field;this.showColumn(S)}},Ie=function(e,s){let i={index:s++,tokens:{},compareValues:{},sortValues:{}};e._metadata=i;for(let[r,o]of t(this,b)){let l=h(this,c,ie).call(this,e,r);typeof o.options.sortValue=="function"?i.sortValues[r]=o.options.sortValue(l):typeof l=="string"?i.sortValues[r]=l.toLocaleLowerCase():i.sortValues[r]=l,typeof l=="string"&&(i.compareValues[r]=l.toLocaleLowerCase()),o.options.searchable&&o.options.tokenize&&l&&(i.tokens[r]=t(this,m).tokenizer(l).map(f=>f.value))}for(let r of t(this,m).extraSearchFields){let o=h(this,c,ie).call(this,e,r);typeof o=="string"&&(i.compareValues[r]=o.toLocaleLowerCase())}return e},Ne=function(e,s){if(!e||!s)return 0;let i=0,r=0;if(s===e)r=re.MatchWeights.EXACT,i=e.length;else if(s.startsWith(e))r=re.MatchWeights.PREFIX,i=e.length;else if(s.includes(e))r=re.MatchWeights.SUBSTRING,i=e.length;else return 0;let l=1/(1+(s.length-e.length));return i*r*l},Ve=function(e,s,i){return e instanceof RegExp?e.test(s)?1:0:t(this,m).enableSearchScoring?e.quoted||!i?h(this,c,Ne).call(this,e.value,s):i.map(r=>h(this,c,Ne).call(this,e.value,r)).reduce((r,o)=>r+=o,0):e.quoted||!i?s.includes(e.value)?1:0:i.some(r=>r==e.value)?1:0},Ae=function(e,s,i=null){return Array.isArray(s)?s.length===0?!0:s.some(r=>h(this,c,Ae).call(this,e,r)):typeof i=="function"?i(e,s):s instanceof RegExp?s.test(String(e)):s===e},st=function(e,s){if(!t(this,V))return!0;if(typeof t(this,V)=="function")return t(this,V).call(this,e,s);for(let i in t(this,V)){let r=t(this,V)[i],o=h(this,c,ie).call(this,e,i);if(typeof r=="function"){if(!r(o))return!1}else{let l=t(this,b).get(i),f=l?l.options.filter:void 0;if(!h(this,c,Ae).call(this,o,r,f))return!1}}return!0},K=function(){if(t(this,A))return;let s=[...[...t(this,b).values()].filter(o=>o.options.searchable).map(o=>o.field),...t(this,m).extraSearchFields],i=[...t(this,k).values()];p(this,R,i.filter((o,l)=>{if(o._metadata.searchScore=0,!h(this,c,st).call(this,o,l))return!1;if(!t(this,M))return!0;for(let f of s){let d=h(this,c,ie).call(this,o,f),g=o._metadata.compareValues[f],T=o._metadata.tokens[f];if(typeof d!="string"||typeof g!="string")continue;let v=0;if(t(this,M)instanceof RegExp)v=h(this,c,Ve).call(this,t(this,M),d,T);else for(let E of t(this,M))v+=h(this,c,Ve).call(this,E,g,T);o._metadata.searchScore+=v}return o._metadata.searchScore>0})),h(this,c,me).call(this);let r=new CustomEvent("dt.rows.changed",{cancelable:!1,detail:{dataTable:this}});this.dispatchEvent(r)},it=function(e,s,i){var d,g;let r,o;if(!i.sortState)return 0;if(((d=i.sortState)==null?void 0:d.order)==="asc"?(r=e._metadata.sortValues[i.field],o=s._metadata.sortValues[i.field]):((g=i.sortState)==null?void 0:g.order)==="desc"&&(r=s._metadata.sortValues[i.field],o=e._metadata.sortValues[i.field]),typeof i.options.sorter=="function"){let T=i.options.sorter(r,o);if(T!==0)return T}let l=r==null,f=o==null;return l&&!f?-1:f&&!l?1:r<o?-1:r>o?1:0},me=function(){if(t(this,A))return;let e=[...t(this,b).values()].filter(s=>!s.headerElement.hidden&&s.sortState).sort((s,i)=>i.sortState.priority-s.sortState.priority);t(this,R).sort((s,i)=>{if(t(this,m).enableSearchScoring&&t(this,M)){let r=s._metadata.searchScore||0,o=i._metadata.searchScore||0;if(r>o)return-1;if(r<o)return 1}for(let r of e){let o=h(this,c,it).call(this,s,i,r);if(o!==0)return o}return s._metadata.index-i._metadata.index}),h(this,c,pe).call(this)},se=function(){var e,s,i,r,o,l,f;if(!t(this,A))for(let d of t(this,b).values())(e=d.headerElement.parentElement)==null||e.append(d.headerElement),d.headerElement.hidden=!d.options.visible,d.options.resizable?d.headerElement.classList.add("dt-resizeable"):d.headerElement.classList.remove("dt-resizeable"),d.options.sortable?d.headerElement.classList.add("dt-sortable"):d.headerElement.classList.remove("dt-sortable"),d.sortState?d.sortState.order==="asc"?((r=d.headerElement)==null||r.classList.add("dt-ascending"),(o=d.headerElement)==null||o.classList.remove("dt-descending")):d.sortState.order==="desc"&&((l=d.headerElement)==null||l.classList.add("dt-descending"),(f=d.headerElement)==null||f.classList.remove("dt-ascending")):((s=d.headerElement)==null||s.classList.remove("dt-ascending"),(i=d.headerElement)==null||i.classList.remove("dt-descending"))},pe=function(){if(t(this,A))return;let e=this.rows.length>=t(this,m).virtualScroll;if(e&&!t(this,F)?p(this,F,new(t(this,m)).virtualScrollClass({container:t(this,L),element:t(this,N),generator:s=>h(this,c,_e).call(this,s)})):!e&&t(this,F)&&(t(this,F).stop(),p(this,F,void 0)),t(this,N).innerHTML="",t(this,F))try{t(this,F).start(t(this,R).length)}catch(s){s instanceof te&&(console.warn("Failed to start virtual scroll... falling back to standard rendering"),console.warn(s.stack))}else{if(t(this,R).length>qe){let i=qe.toLocaleString();console.warn(`Virtual scroll disabled with more than ${i} rows... Good luck with that!`)}let s=t(this,R).map((i,r)=>h(this,c,_e).call(this,r));t(this,N).append(...s)}t(this,k).size===0?this.showMessage(t(this,m).noDataText,"dt-empty"):t(this,R).length===0&&this.showMessage(t(this,m).noMatchText,"dt-empty")},We=function(e,s){var i;if(e.children.length===0){let r=(i=e.textContent)!=null?i:"",o=t(this,m).classes.mark.join(" ");r=r.replace(s,l=>`<mark class="${o}">${l}</mark>`),e.innerHTML=r}else for(let r of e.children)r instanceof HTMLElement&&h(this,c,We).call(this,r,s)},rt=function(e,s,i,r){if(e.title=String(s),typeof i.options.valueFormatter=="function"&&(s=i.options.valueFormatter(s,r)),e.textContent=s==null?"-":s,typeof i.options.elementFormatter=="function"&&i.options.elementFormatter(s,r,e),t(this,m).highlightSearch&&t(this,M)&&i.options.searchable){let o;if(t(this,M)instanceof RegExp)o=t(this,M);else{let l=t(this,M).map(f=>f.value).join("|");o=new RegExp(l,"gi")}h(this,c,We).call(this,e,o)}e.hidden=!i.options.visible},_e=function(e){let s=t(this,R)[e],i=document.createElement("tr");i.classList.add(...t(this,m).classes.tr),i.dataset.dtIndex=String(s._metadata.index);for(let[r,o]of t(this,b)){let l=h(this,c,ie).call(this,s,r),f=document.createElement("td");f.classList.add(...t(this,m).classes.td),f.dataset.dtField=r;let d=o.headerElement.style.width;d&&d!=="0px"&&(f.style.maxWidth=d),h(this,c,rt).call(this,f,l,o,s),i.append(f)}if(typeof t(this,m).rowFormatter=="function")try{t(this,m).rowFormatter(s,i)}catch(r){console.error("Row formatter callback failed with the following error"),console.error(r)}return i},ie=function(e,s){let i=s.split("."),r=e;for(let o of i)if(r&&typeof r=="object")r=r[o];else return;return r},$e=function(e,s){let i,r;s==null?(i="",r=""):s<=0?(i="0px",r=""):(i=`${s}px`,r=`${s}px`);let o=e.headerElement.offsetWidth;e.headerElement.style.width=i,e.headerElement.style.maxWidth=i;let l=t(this,N).querySelectorAll(`td[data-dt-field="${e.field}"]`);for(let g of l)g.style.maxWidth=r;let f=e.headerElement.offsetWidth-o,d=t(this,C).offsetWidth+f;t(this,C).style.width=`${d}px`},we=new WeakMap,Se=new WeakMap,ge=new WeakMap,be=new WeakMap,xe=new WeakMap,Ce=new WeakMap,Le=new WeakMap,Oe=new WeakMap,Re=new WeakMap,Me=new WeakMap,De=new WeakMap,re.MatchWeights={EXACT:100,PREFIX:50,SUBSTRING:10};var He=re,qe=1e4;var ne,Z,w,U,je=class{constructor(n,e,s){u(this,ne);u(this,Z);u(this,w,{saveSearch:!0,saveColumnTitle:!0,saveColumnSorting:!0,saveColumnVisibility:!0,saveColumnWidth:!0,saveColumnOrder:!0});u(this,U,()=>setTimeout(()=>this.saveState(),0));p(this,ne,n),p(this,Z,e),p(this,w,X(X({},t(this,w)),s)),this.restoreState(),t(this,w).saveSearch&&n.addEventListener("dt.search",t(this,U)),t(this,w).saveColumnSorting&&n.addEventListener("dt.col.sort",t(this,U)),t(this,w).saveColumnVisibility&&n.addEventListener("dt.col.visibility",t(this,U)),t(this,w).saveColumnWidth&&n.addEventListener("dt.col.resize",t(this,U)),t(this,w).saveColumnOrder&&n.addEventListener("dt.col.reorder",t(this,U))}saveState(){var s;let n={columns:[]},e=t(this,ne).getState();t(this,w).saveSearch&&(n.searchQuery=e.searchQuery),t(this,w).saveColumnOrder&&(n.columnOrder=e.columnOrder);for(let i of e.columns){let r={field:i.field};t(this,w).saveColumnTitle&&(r.title=i.title),t(this,w).saveColumnSorting&&(r.sortState=i.sortState),t(this,w).saveColumnVisibility&&(r.visible=i.visible),t(this,w).saveColumnWidth&&(r.width=i.width),(s=n.columns)==null||s.push(r)}localStorage.setItem(t(this,Z),JSON.stringify(n))}restoreState(){let n=localStorage.getItem(t(this,Z));if(n)try{let e=JSON.parse(n),s={};if(t(this,w).saveSearch&&(s.searchQuery=e.searchQuery),t(this,w).saveColumnOrder&&(s.columnOrder=e.columnOrder),e.columns){s.columns=[];for(let i of e.columns){let r={field:i.field};t(this,w).saveColumnTitle&&(r.title=i.title),t(this,w).saveColumnVisibility&&(r.visible=i.visible),t(this,w).saveColumnWidth&&(r.width=i.width),t(this,w).saveColumnSorting&&(r.sortState=i.sortState),s.columns.push(r)}}t(this,ne).restoreState(s)}catch(e){console.error("Failed to restore DataTable state:",e)}}clearState(){localStorage.removeItem(t(this,Z))}};ne=new WeakMap,Z=new WeakMap,w=new WeakMap,U=new WeakMap;return ct(ht);})();
|
|
4
|
+
//# sourceMappingURL=data-table.global.js.map
|