@timlassiter11/yatl 1.0.6 → 1.0.7
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.d.mts +21 -28
- package/dist/index.d.ts +21 -28
- package/dist/index.js +80 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -66
- package/dist/index.mjs.map +1 -1
- package/dist/yatl.min.global.js +20 -23
- package/dist/yatl.min.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,10 @@ type NestedKeyOf<ObjectType> = ObjectType extends object ? {
|
|
|
9
9
|
* Default type for the table.
|
|
10
10
|
*/
|
|
11
11
|
type UnspecifiedRecord = Record<string, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Record that maps a column's field to arbitrary data.
|
|
14
|
+
*/
|
|
15
|
+
type ColumnPropertyRecord<TData, TProp> = Partial<Record<NestedKeyOf<TData>, TProp>>;
|
|
12
16
|
/**
|
|
13
17
|
* Defines the possible sorting orders for columns.
|
|
14
18
|
*/
|
|
@@ -103,7 +107,7 @@ type ColumnFilterCallback = (value: unknown, filter: unknown) => boolean;
|
|
|
103
107
|
/**
|
|
104
108
|
* Represents the current sort state
|
|
105
109
|
*/
|
|
106
|
-
|
|
110
|
+
type SortState = {
|
|
107
111
|
/**
|
|
108
112
|
* The sort order
|
|
109
113
|
*/
|
|
@@ -113,7 +117,7 @@ interface SortState {
|
|
|
113
117
|
* Lower priority means
|
|
114
118
|
*/
|
|
115
119
|
priority: number;
|
|
116
|
-
}
|
|
120
|
+
} | null;
|
|
117
121
|
type ColumnRole = 'display' | 'internal';
|
|
118
122
|
/**
|
|
119
123
|
* Shared options between both internal and displayed columns.
|
|
@@ -337,6 +341,8 @@ declare const whitespaceTokenizer: (value: string) => {
|
|
|
337
341
|
value: string;
|
|
338
342
|
quoted: boolean;
|
|
339
343
|
}[];
|
|
344
|
+
declare function isInternalColumn<T>(col: ColumnOptions<T> | undefined | null): col is InternalColumnOptions<T>;
|
|
345
|
+
declare function isDisplayColumn<T>(col: ColumnOptions<T> | undefined | null): col is DisplayColumnOptions<T>;
|
|
340
346
|
|
|
341
347
|
/**
|
|
342
348
|
* Represents a dynamic and interactive table with features like sorting, searching, filtering,
|
|
@@ -445,6 +451,10 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
445
451
|
*/
|
|
446
452
|
get columns(): ColumnOptions<T>[];
|
|
447
453
|
set columns(columns: ColumnOptions<T>[]);
|
|
454
|
+
/**
|
|
455
|
+
* Gets a list of columns with the display role
|
|
456
|
+
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
457
|
+
*/
|
|
448
458
|
get displayColumns(): DisplayColumnOptions<T>[];
|
|
449
459
|
/**
|
|
450
460
|
* The current order of the columns.
|
|
@@ -456,38 +466,20 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
456
466
|
* The current visibility state of all columns.
|
|
457
467
|
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
458
468
|
*/
|
|
459
|
-
get columnVisibility():
|
|
460
|
-
|
|
461
|
-
visible: boolean;
|
|
462
|
-
}[];
|
|
463
|
-
set columnVisibility(columns: {
|
|
464
|
-
field: NestedKeyOf<T>;
|
|
465
|
-
visible: boolean;
|
|
466
|
-
}[]);
|
|
469
|
+
get columnVisibility(): Partial<Record<NestedKeyOf<T>, boolean>>;
|
|
470
|
+
set columnVisibility(columns: Partial<Record<NestedKeyOf<T>, boolean>>);
|
|
467
471
|
/**
|
|
468
472
|
* The current sort state of all columns.
|
|
469
473
|
* **This will always be orderd by {@link YatlTable.columnOrder}**
|
|
470
474
|
*/
|
|
471
|
-
get columnSort():
|
|
472
|
-
|
|
473
|
-
sort: SortState | null;
|
|
474
|
-
}[];
|
|
475
|
-
set columnSort(columns: {
|
|
476
|
-
field: NestedKeyOf<T>;
|
|
477
|
-
sort: SortState | null;
|
|
478
|
-
}[]);
|
|
475
|
+
get columnSort(): Partial<Record<NestedKeyOf<T>, SortState>>;
|
|
476
|
+
set columnSort(columns: Partial<Record<NestedKeyOf<T>, SortState>>);
|
|
479
477
|
/**
|
|
480
478
|
* The current width of all columns.
|
|
481
479
|
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
482
480
|
*/
|
|
483
|
-
get columnWidths():
|
|
484
|
-
|
|
485
|
-
width: number | null;
|
|
486
|
-
}[];
|
|
487
|
-
set columnWidths(columns: {
|
|
488
|
-
field: NestedKeyOf<T>;
|
|
489
|
-
width: number | null;
|
|
490
|
-
}[]);
|
|
481
|
+
get columnWidths(): Partial<Record<NestedKeyOf<T>, number | null>>;
|
|
482
|
+
set columnWidths(columns: Partial<Record<NestedKeyOf<T>, number | null>>);
|
|
491
483
|
/**
|
|
492
484
|
* The current text string used to filter the table data.
|
|
493
485
|
* Setting this property triggers a new search and render cycle.
|
|
@@ -666,6 +658,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
666
658
|
private sortRows;
|
|
667
659
|
private createMetadata;
|
|
668
660
|
private updateInternalQuery;
|
|
661
|
+
private hasVisibleColumn;
|
|
669
662
|
/**
|
|
670
663
|
* Gets the width of each column in the
|
|
671
664
|
* order they will appear in the grid.
|
|
@@ -710,8 +703,8 @@ interface EventMap<T> {
|
|
|
710
703
|
}
|
|
711
704
|
declare global {
|
|
712
705
|
interface HTMLElementTagNameMap {
|
|
713
|
-
'yatl-table': YatlTable
|
|
706
|
+
'yatl-table': YatlTable<any>;
|
|
714
707
|
}
|
|
715
708
|
}
|
|
716
709
|
|
|
717
|
-
export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, whitespaceTokenizer };
|
|
710
|
+
export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ type NestedKeyOf<ObjectType> = ObjectType extends object ? {
|
|
|
9
9
|
* Default type for the table.
|
|
10
10
|
*/
|
|
11
11
|
type UnspecifiedRecord = Record<string, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Record that maps a column's field to arbitrary data.
|
|
14
|
+
*/
|
|
15
|
+
type ColumnPropertyRecord<TData, TProp> = Partial<Record<NestedKeyOf<TData>, TProp>>;
|
|
12
16
|
/**
|
|
13
17
|
* Defines the possible sorting orders for columns.
|
|
14
18
|
*/
|
|
@@ -103,7 +107,7 @@ type ColumnFilterCallback = (value: unknown, filter: unknown) => boolean;
|
|
|
103
107
|
/**
|
|
104
108
|
* Represents the current sort state
|
|
105
109
|
*/
|
|
106
|
-
|
|
110
|
+
type SortState = {
|
|
107
111
|
/**
|
|
108
112
|
* The sort order
|
|
109
113
|
*/
|
|
@@ -113,7 +117,7 @@ interface SortState {
|
|
|
113
117
|
* Lower priority means
|
|
114
118
|
*/
|
|
115
119
|
priority: number;
|
|
116
|
-
}
|
|
120
|
+
} | null;
|
|
117
121
|
type ColumnRole = 'display' | 'internal';
|
|
118
122
|
/**
|
|
119
123
|
* Shared options between both internal and displayed columns.
|
|
@@ -337,6 +341,8 @@ declare const whitespaceTokenizer: (value: string) => {
|
|
|
337
341
|
value: string;
|
|
338
342
|
quoted: boolean;
|
|
339
343
|
}[];
|
|
344
|
+
declare function isInternalColumn<T>(col: ColumnOptions<T> | undefined | null): col is InternalColumnOptions<T>;
|
|
345
|
+
declare function isDisplayColumn<T>(col: ColumnOptions<T> | undefined | null): col is DisplayColumnOptions<T>;
|
|
340
346
|
|
|
341
347
|
/**
|
|
342
348
|
* Represents a dynamic and interactive table with features like sorting, searching, filtering,
|
|
@@ -445,6 +451,10 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
445
451
|
*/
|
|
446
452
|
get columns(): ColumnOptions<T>[];
|
|
447
453
|
set columns(columns: ColumnOptions<T>[]);
|
|
454
|
+
/**
|
|
455
|
+
* Gets a list of columns with the display role
|
|
456
|
+
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
457
|
+
*/
|
|
448
458
|
get displayColumns(): DisplayColumnOptions<T>[];
|
|
449
459
|
/**
|
|
450
460
|
* The current order of the columns.
|
|
@@ -456,38 +466,20 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
456
466
|
* The current visibility state of all columns.
|
|
457
467
|
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
458
468
|
*/
|
|
459
|
-
get columnVisibility():
|
|
460
|
-
|
|
461
|
-
visible: boolean;
|
|
462
|
-
}[];
|
|
463
|
-
set columnVisibility(columns: {
|
|
464
|
-
field: NestedKeyOf<T>;
|
|
465
|
-
visible: boolean;
|
|
466
|
-
}[]);
|
|
469
|
+
get columnVisibility(): Partial<Record<NestedKeyOf<T>, boolean>>;
|
|
470
|
+
set columnVisibility(columns: Partial<Record<NestedKeyOf<T>, boolean>>);
|
|
467
471
|
/**
|
|
468
472
|
* The current sort state of all columns.
|
|
469
473
|
* **This will always be orderd by {@link YatlTable.columnOrder}**
|
|
470
474
|
*/
|
|
471
|
-
get columnSort():
|
|
472
|
-
|
|
473
|
-
sort: SortState | null;
|
|
474
|
-
}[];
|
|
475
|
-
set columnSort(columns: {
|
|
476
|
-
field: NestedKeyOf<T>;
|
|
477
|
-
sort: SortState | null;
|
|
478
|
-
}[]);
|
|
475
|
+
get columnSort(): Partial<Record<NestedKeyOf<T>, SortState>>;
|
|
476
|
+
set columnSort(columns: Partial<Record<NestedKeyOf<T>, SortState>>);
|
|
479
477
|
/**
|
|
480
478
|
* The current width of all columns.
|
|
481
479
|
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
482
480
|
*/
|
|
483
|
-
get columnWidths():
|
|
484
|
-
|
|
485
|
-
width: number | null;
|
|
486
|
-
}[];
|
|
487
|
-
set columnWidths(columns: {
|
|
488
|
-
field: NestedKeyOf<T>;
|
|
489
|
-
width: number | null;
|
|
490
|
-
}[]);
|
|
481
|
+
get columnWidths(): Partial<Record<NestedKeyOf<T>, number | null>>;
|
|
482
|
+
set columnWidths(columns: Partial<Record<NestedKeyOf<T>, number | null>>);
|
|
491
483
|
/**
|
|
492
484
|
* The current text string used to filter the table data.
|
|
493
485
|
* Setting this property triggers a new search and render cycle.
|
|
@@ -666,6 +658,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
|
|
|
666
658
|
private sortRows;
|
|
667
659
|
private createMetadata;
|
|
668
660
|
private updateInternalQuery;
|
|
661
|
+
private hasVisibleColumn;
|
|
669
662
|
/**
|
|
670
663
|
* Gets the width of each column in the
|
|
671
664
|
* order they will appear in the grid.
|
|
@@ -710,8 +703,8 @@ interface EventMap<T> {
|
|
|
710
703
|
}
|
|
711
704
|
declare global {
|
|
712
705
|
interface HTMLElementTagNameMap {
|
|
713
|
-
'yatl-table': YatlTable
|
|
706
|
+
'yatl-table': YatlTable<any>;
|
|
714
707
|
}
|
|
715
708
|
}
|
|
716
709
|
|
|
717
|
-
export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, whitespaceTokenizer };
|
|
710
|
+
export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,8 @@ __export(src_exports, {
|
|
|
39
39
|
YatlStateChangeEvent: () => YatlStateChangeEvent,
|
|
40
40
|
YatlTable: () => YatlTable,
|
|
41
41
|
createRegexTokenizer: () => createRegexTokenizer,
|
|
42
|
+
isDisplayColumn: () => isDisplayColumn,
|
|
43
|
+
isInternalColumn: () => isInternalColumn,
|
|
42
44
|
whitespaceTokenizer: () => whitespaceTokenizer
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -183,9 +185,6 @@ function getNestedValue(obj, path) {
|
|
|
183
185
|
}
|
|
184
186
|
return current;
|
|
185
187
|
}
|
|
186
|
-
function findColumn(field, columns) {
|
|
187
|
-
return columns.find((c) => c.field === field);
|
|
188
|
-
}
|
|
189
188
|
function highlightText(text, ranges) {
|
|
190
189
|
if (!text || !ranges || ranges.length === 0) {
|
|
191
190
|
return text;
|
|
@@ -227,6 +226,9 @@ function widthsToGridTemplates(widths, defaultWidth = "1fr") {
|
|
|
227
226
|
function isCompareable(value) {
|
|
228
227
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
229
228
|
}
|
|
229
|
+
function isInternalColumn(col) {
|
|
230
|
+
return col?.role === "internal";
|
|
231
|
+
}
|
|
230
232
|
function isDisplayColumn(col) {
|
|
231
233
|
return col?.role !== "internal";
|
|
232
234
|
}
|
|
@@ -657,10 +659,11 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
657
659
|
this.resizeState.currentWidths[this.resizeState.columnIndex]
|
|
658
660
|
);
|
|
659
661
|
const columnWidths = this.columnWidths;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
this.
|
|
663
|
-
|
|
662
|
+
columnWidths[this.resizeState.columnField] = finalWidth;
|
|
663
|
+
this.columnWidths = { ...columnWidths };
|
|
664
|
+
this.dispatchEvent(
|
|
665
|
+
new YatlColumnResizeEvent(this.resizeState.columnField, finalWidth)
|
|
666
|
+
);
|
|
664
667
|
}
|
|
665
668
|
setTimeout(() => {
|
|
666
669
|
this.resizeState = null;
|
|
@@ -767,8 +770,12 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
767
770
|
}
|
|
768
771
|
this.requestUpdate("columns", oldValue);
|
|
769
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* Gets a list of columns with the display role
|
|
775
|
+
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
776
|
+
*/
|
|
770
777
|
get displayColumns() {
|
|
771
|
-
return this.
|
|
778
|
+
return this.columnOrder.map((field) => this._columnDefinitionMap.get(field)).filter(isDisplayColumn);
|
|
772
779
|
}
|
|
773
780
|
get columnOrder() {
|
|
774
781
|
const finalOrder = /* @__PURE__ */ new Set();
|
|
@@ -778,8 +785,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
778
785
|
finalOrder.add(field);
|
|
779
786
|
}
|
|
780
787
|
}
|
|
781
|
-
for (const col of this.
|
|
782
|
-
if (!finalOrder.has(col.field)) {
|
|
788
|
+
for (const col of this.columns) {
|
|
789
|
+
if (isDisplayColumn(col) && !finalOrder.has(col.field)) {
|
|
783
790
|
finalOrder.add(col.field);
|
|
784
791
|
}
|
|
785
792
|
}
|
|
@@ -794,19 +801,21 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
794
801
|
this.requestUpdate("columnOrder", oldValue);
|
|
795
802
|
}
|
|
796
803
|
get columnVisibility() {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
804
|
+
const data = {};
|
|
805
|
+
for (const field of this.columnOrder) {
|
|
806
|
+
data[field] = this.getOrCreateColumnState(field).visible;
|
|
807
|
+
}
|
|
808
|
+
return data;
|
|
801
809
|
}
|
|
802
810
|
set columnVisibility(columns) {
|
|
803
811
|
const oldValue = this.columnVisibility;
|
|
804
812
|
let changed = false;
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
813
|
+
const entries = Object.entries(columns);
|
|
814
|
+
for (const [field, visible] of entries) {
|
|
815
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
816
|
+
if (columnState.visible !== visible) {
|
|
808
817
|
changed = true;
|
|
809
|
-
columnState.visible =
|
|
818
|
+
columnState.visible = visible;
|
|
810
819
|
}
|
|
811
820
|
}
|
|
812
821
|
if (!changed) {
|
|
@@ -815,24 +824,22 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
815
824
|
this.requestUpdate("columnVisibility", oldValue);
|
|
816
825
|
}
|
|
817
826
|
get columnSort() {
|
|
818
|
-
|
|
827
|
+
const data = {};
|
|
828
|
+
for (const field of this.columnOrder) {
|
|
819
829
|
const sortState = this.getOrCreateColumnState(field).sort;
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
// if the user changes it, it doesn't change our copy.
|
|
824
|
-
sort: sortState ? { ...sortState } : null
|
|
825
|
-
};
|
|
826
|
-
});
|
|
830
|
+
data[field] = sortState ? { ...sortState } : null;
|
|
831
|
+
}
|
|
832
|
+
return data;
|
|
827
833
|
}
|
|
828
834
|
set columnSort(columns) {
|
|
829
835
|
const oldValue = this.columnSort;
|
|
830
836
|
let changed = false;
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
837
|
+
const entries = Object.entries(columns);
|
|
838
|
+
for (const [field, state2] of entries) {
|
|
839
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
840
|
+
if (columnState && (columnState.sort?.order !== state2?.order || columnState.sort?.priority !== state2?.priority)) {
|
|
834
841
|
changed = true;
|
|
835
|
-
columnState.sort =
|
|
842
|
+
columnState.sort = state2;
|
|
836
843
|
}
|
|
837
844
|
}
|
|
838
845
|
if (!changed) {
|
|
@@ -842,19 +849,21 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
842
849
|
this.requestUpdate("columnSort", oldValue);
|
|
843
850
|
}
|
|
844
851
|
get columnWidths() {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
852
|
+
const data = {};
|
|
853
|
+
for (const field of this.columnOrder) {
|
|
854
|
+
data[field] = this.getOrCreateColumnState(field).width;
|
|
855
|
+
}
|
|
856
|
+
return data;
|
|
849
857
|
}
|
|
850
858
|
set columnWidths(columns) {
|
|
851
859
|
const oldValue = this.columnWidths;
|
|
852
860
|
let changed = false;
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
861
|
+
const entries = Object.entries(columns);
|
|
862
|
+
for (const [field, width] of entries) {
|
|
863
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
864
|
+
if (columnState.width !== width) {
|
|
856
865
|
changed = true;
|
|
857
|
-
columnState.width =
|
|
866
|
+
columnState.width = width;
|
|
858
867
|
}
|
|
859
868
|
}
|
|
860
869
|
if (!changed) {
|
|
@@ -1006,34 +1015,35 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1006
1015
|
*/
|
|
1007
1016
|
sort(field, order, clear = true) {
|
|
1008
1017
|
const sortStates = this.columnSort;
|
|
1009
|
-
|
|
1010
|
-
if (
|
|
1018
|
+
let state2 = sortStates[field];
|
|
1019
|
+
if (state2 === void 0) {
|
|
1011
1020
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
1012
1021
|
}
|
|
1013
|
-
if (order === state2
|
|
1022
|
+
if (order === state2?.order) {
|
|
1014
1023
|
return;
|
|
1015
1024
|
}
|
|
1016
1025
|
if (!this.dispatchEvent(new YatlSortEvent(field, order))) {
|
|
1017
1026
|
return;
|
|
1018
1027
|
}
|
|
1019
|
-
if (order && !state2
|
|
1020
|
-
const priorities =
|
|
1028
|
+
if (order && !state2) {
|
|
1029
|
+
const priorities = [...this._columnStateMap.values()].map((state3) => state3.sort?.priority).filter((priority2) => priority2 !== void 0);
|
|
1021
1030
|
const maxPriority = this.columns.length + 1;
|
|
1022
1031
|
const priority = Math.min(maxPriority, ...priorities) - 1;
|
|
1023
|
-
state2
|
|
1024
|
-
} else if (order && state2
|
|
1025
|
-
state2.
|
|
1032
|
+
state2 = { order, priority };
|
|
1033
|
+
} else if (order && state2) {
|
|
1034
|
+
state2.order = order;
|
|
1026
1035
|
} else {
|
|
1027
|
-
state2
|
|
1036
|
+
state2 = null;
|
|
1028
1037
|
}
|
|
1038
|
+
sortStates[field] = state2;
|
|
1029
1039
|
if (clear) {
|
|
1030
|
-
for (const
|
|
1031
|
-
if (
|
|
1032
|
-
|
|
1040
|
+
for (const otherField of this.columnOrder) {
|
|
1041
|
+
if (otherField !== field) {
|
|
1042
|
+
sortStates[otherField] = null;
|
|
1033
1043
|
}
|
|
1034
1044
|
}
|
|
1035
1045
|
}
|
|
1036
|
-
this.columnSort =
|
|
1046
|
+
this.columnSort = { ...sortStates };
|
|
1037
1047
|
}
|
|
1038
1048
|
/**
|
|
1039
1049
|
* Sets the visibility of a specified column.
|
|
@@ -1042,18 +1052,18 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1042
1052
|
*/
|
|
1043
1053
|
setColumnVisibility(field, visible) {
|
|
1044
1054
|
const visibilityStates = this.columnVisibility;
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1055
|
+
const currentVisibility = visibilityStates[field];
|
|
1056
|
+
if (currentVisibility === void 0) {
|
|
1047
1057
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
1048
1058
|
}
|
|
1049
|
-
if (
|
|
1059
|
+
if (currentVisibility === visible) {
|
|
1050
1060
|
return;
|
|
1051
1061
|
}
|
|
1052
1062
|
if (!this.dispatchEvent(new YatlColumnToggleEvent(field, visible))) {
|
|
1053
1063
|
return;
|
|
1054
1064
|
}
|
|
1055
|
-
|
|
1056
|
-
this.columnVisibility =
|
|
1065
|
+
visibilityStates[field] = visible;
|
|
1066
|
+
this.columnVisibility = { ...visibilityStates };
|
|
1057
1067
|
}
|
|
1058
1068
|
/**
|
|
1059
1069
|
* Toggles the visibility of hte specified column
|
|
@@ -1085,7 +1095,9 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1085
1095
|
export(filename, all = false) {
|
|
1086
1096
|
const data = all ? this.data : this.filteredData;
|
|
1087
1097
|
const columnData = this.displayColumns;
|
|
1088
|
-
const csvHeaders = columnData.filter(
|
|
1098
|
+
const csvHeaders = columnData.filter(
|
|
1099
|
+
(column) => all || this.getOrCreateColumnState(column.field).visible
|
|
1100
|
+
).map((column) => `"${column.title}"`).join(",");
|
|
1089
1101
|
const csvRows = data.map((row) => {
|
|
1090
1102
|
const list = [];
|
|
1091
1103
|
for (const column of columnData) {
|
|
@@ -1284,9 +1296,9 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1284
1296
|
}
|
|
1285
1297
|
renderHeader() {
|
|
1286
1298
|
const classes = {
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1299
|
+
header: true,
|
|
1300
|
+
row: true,
|
|
1301
|
+
reorderable: this.enableColumnReorder
|
|
1290
1302
|
};
|
|
1291
1303
|
return import_lit3.html`
|
|
1292
1304
|
<div part="header" class=${(0, import_class_map.classMap)(classes)}>
|
|
@@ -1353,7 +1365,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1353
1365
|
`;
|
|
1354
1366
|
}
|
|
1355
1367
|
renderBody() {
|
|
1356
|
-
if (this.
|
|
1368
|
+
if (!this.hasVisibleColumn()) {
|
|
1357
1369
|
return import_lit3.html`
|
|
1358
1370
|
<div part="message" class="message">No visible columns.</div>
|
|
1359
1371
|
`;
|
|
@@ -1417,11 +1429,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1417
1429
|
class="table"
|
|
1418
1430
|
style=${(0, import_style_map.styleMap)({ "--grid-template": gridTemplate })}
|
|
1419
1431
|
>
|
|
1420
|
-
${this.renderHeader()}
|
|
1421
|
-
<slot>
|
|
1422
|
-
${this.renderBody()}
|
|
1423
|
-
${this.renderFooter()}
|
|
1424
|
-
</slot>
|
|
1432
|
+
${this.renderHeader()}
|
|
1433
|
+
<slot> ${this.renderBody()} ${this.renderFooter()} </slot>
|
|
1425
1434
|
</div>
|
|
1426
1435
|
`;
|
|
1427
1436
|
}
|
|
@@ -1734,6 +1743,9 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1734
1743
|
this.queryTokens.push(...this.searchTokenizer(this.searchQuery));
|
|
1735
1744
|
}
|
|
1736
1745
|
}
|
|
1746
|
+
hasVisibleColumn() {
|
|
1747
|
+
return this.columnOrder.map((field) => this.getOrCreateColumnState(field)).filter((state2) => state2.visible).length > 0;
|
|
1748
|
+
}
|
|
1737
1749
|
/**
|
|
1738
1750
|
* Gets the width of each column in the
|
|
1739
1751
|
* order they will appear in the grid.
|
|
@@ -1983,6 +1995,8 @@ YatlTable = __decorateClass([
|
|
|
1983
1995
|
YatlStateChangeEvent,
|
|
1984
1996
|
YatlTable,
|
|
1985
1997
|
createRegexTokenizer,
|
|
1998
|
+
isDisplayColumn,
|
|
1999
|
+
isInternalColumn,
|
|
1986
2000
|
whitespaceTokenizer
|
|
1987
2001
|
});
|
|
1988
2002
|
//# sourceMappingURL=index.js.map
|