@timlassiter11/yatl 1.0.0 → 1.0.1
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 +52 -20
- package/dist/index.d.ts +52 -20
- package/dist/index.js +212 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +211 -146
- package/dist/index.mjs.map +1 -1
- package/dist/yatl.min.global.js +40 -40
- package/dist/yatl.min.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -106,6 +106,14 @@ var _YatlSearchEvent = class _YatlSearchEvent extends YatlEvent {
|
|
|
106
106
|
};
|
|
107
107
|
_YatlSearchEvent.EVENT_NAME = "yatl-search";
|
|
108
108
|
var YatlSearchEvent = _YatlSearchEvent;
|
|
109
|
+
var _YatlStateChangeEvent = class _YatlStateChangeEvent extends YatlEvent {
|
|
110
|
+
constructor(state2, triggers) {
|
|
111
|
+
super(_YatlStateChangeEvent.EVENT_NAME, { state: state2, triggers });
|
|
112
|
+
this.triggers = triggers;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
_YatlStateChangeEvent.EVENT_NAME = "yatl-state-change";
|
|
116
|
+
var YatlStateChangeEvent = _YatlStateChangeEvent;
|
|
109
117
|
|
|
110
118
|
// src/utils.ts
|
|
111
119
|
import { html } from "lit";
|
|
@@ -182,23 +190,6 @@ function highlightText(text, ranges) {
|
|
|
182
190
|
function widthsToGridTemplates(widths, defaultWidth = "1fr") {
|
|
183
191
|
return widths.map((width) => width ? `${width}px` : defaultWidth);
|
|
184
192
|
}
|
|
185
|
-
function didSortStateChange(newState, oldState) {
|
|
186
|
-
if (!oldState) {
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
const allKeys = /* @__PURE__ */ new Set([
|
|
190
|
-
...oldState.map((s) => s.field),
|
|
191
|
-
...newState.map((s) => s.field)
|
|
192
|
-
]);
|
|
193
|
-
for (const key of allKeys) {
|
|
194
|
-
const oldSort = findColumn(key, oldState)?.sortState;
|
|
195
|
-
const newSort = findColumn(key, newState)?.sortState;
|
|
196
|
-
if (oldSort?.order !== newSort?.order || oldSort?.priority !== newSort?.priority) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
193
|
function isCompareable(value) {
|
|
203
194
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
204
195
|
}
|
|
@@ -524,10 +515,11 @@ var DEFAULT_STORAGE_OPTIONS = {
|
|
|
524
515
|
var SAVE_TRIGGERS = /* @__PURE__ */ new Set([
|
|
525
516
|
"searchQuery",
|
|
526
517
|
"filters",
|
|
527
|
-
// Covers column order
|
|
528
518
|
"columns",
|
|
529
|
-
|
|
530
|
-
"
|
|
519
|
+
"columnSort",
|
|
520
|
+
"columnOrder",
|
|
521
|
+
"columnVisibility",
|
|
522
|
+
"columnWidths",
|
|
531
523
|
"storageOptions"
|
|
532
524
|
]);
|
|
533
525
|
var MATCH_WEIGHTS = {
|
|
@@ -544,6 +536,7 @@ var YatlTable = class extends LitElement {
|
|
|
544
536
|
this._enableSearchScoring = false;
|
|
545
537
|
this._columns = [];
|
|
546
538
|
this._columnStates = [];
|
|
539
|
+
this._columnOrder = [];
|
|
547
540
|
this._storageOptions = null;
|
|
548
541
|
this._data = [];
|
|
549
542
|
this._searchQuery = "";
|
|
@@ -586,12 +579,12 @@ var YatlTable = class extends LitElement {
|
|
|
586
579
|
return;
|
|
587
580
|
}
|
|
588
581
|
const multiSort = event.shiftKey;
|
|
589
|
-
const state2 =
|
|
590
|
-
if (!state2?.
|
|
582
|
+
const state2 = this.getColumnState(column.field);
|
|
583
|
+
if (!state2?.sort) {
|
|
591
584
|
this.sort(column.field, "asc", !multiSort);
|
|
592
|
-
} else if (state2.
|
|
585
|
+
} else if (state2.sort.order === "asc") {
|
|
593
586
|
this.sort(column.field, "desc", !multiSort);
|
|
594
|
-
} else if (state2.
|
|
587
|
+
} else if (state2.sort.order) {
|
|
595
588
|
this.sort(column.field, null, !multiSort);
|
|
596
589
|
}
|
|
597
590
|
};
|
|
@@ -621,18 +614,16 @@ var YatlTable = class extends LitElement {
|
|
|
621
614
|
const finalWidth = parseFloat(
|
|
622
615
|
this.resizeState.currentWidths[this.resizeState.columnIndex]
|
|
623
616
|
);
|
|
624
|
-
const
|
|
625
|
-
const state2 = findColumn(this.resizeState.columnField,
|
|
617
|
+
const columnWidths = this.columnWidths;
|
|
618
|
+
const state2 = findColumn(this.resizeState.columnField, columnWidths);
|
|
626
619
|
state2.width = finalWidth;
|
|
627
|
-
this.
|
|
620
|
+
this.columnWidths = columnWidths;
|
|
628
621
|
this.dispatchEvent(new YatlColumnResizeEvent(state2.field, state2.width));
|
|
629
622
|
}
|
|
630
623
|
this.resizeState = null;
|
|
631
624
|
};
|
|
632
625
|
this.handleDragColumnStart = (event, field) => {
|
|
633
626
|
const target = event.target;
|
|
634
|
-
console.log("Starting drag event");
|
|
635
|
-
console.log(target);
|
|
636
627
|
if (target?.classList.contains("resizer")) {
|
|
637
628
|
event.preventDefault();
|
|
638
629
|
return;
|
|
@@ -667,24 +658,23 @@ var YatlTable = class extends LitElement {
|
|
|
667
658
|
}
|
|
668
659
|
event.preventDefault();
|
|
669
660
|
event.stopPropagation();
|
|
670
|
-
const
|
|
671
|
-
const dragIndex =
|
|
672
|
-
const dropIndex =
|
|
661
|
+
const newColumnOrder = [...this.columnOrder];
|
|
662
|
+
const dragIndex = newColumnOrder.findIndex((col) => col === this.dragColumn);
|
|
663
|
+
const dropIndex = newColumnOrder.findIndex((col) => col === field);
|
|
673
664
|
if (dragIndex > -1 && dropIndex > -1) {
|
|
674
|
-
const [draggedColumn] =
|
|
665
|
+
const [draggedColumn] = newColumnOrder.splice(dragIndex, 1);
|
|
675
666
|
const droppedColumn = findColumn(field, this.columns);
|
|
676
667
|
if (!droppedColumn) return;
|
|
677
|
-
|
|
678
|
-
const newColumnOrder = columns.map((col) => col.field);
|
|
668
|
+
newColumnOrder.splice(dropIndex, 0, draggedColumn);
|
|
679
669
|
const reorderEvent = new YatlColumnReorderEvent(
|
|
680
|
-
draggedColumn
|
|
670
|
+
draggedColumn,
|
|
681
671
|
droppedColumn.field,
|
|
682
672
|
newColumnOrder
|
|
683
673
|
);
|
|
684
674
|
if (!this.dispatchEvent(reorderEvent)) {
|
|
685
675
|
return;
|
|
686
676
|
}
|
|
687
|
-
this.
|
|
677
|
+
this.columnOrder = [...newColumnOrder];
|
|
688
678
|
}
|
|
689
679
|
};
|
|
690
680
|
this.handleDragColumnEnd = () => {
|
|
@@ -726,26 +716,95 @@ var YatlTable = class extends LitElement {
|
|
|
726
716
|
}
|
|
727
717
|
const oldValue = this._columns;
|
|
728
718
|
this._columns = columns;
|
|
729
|
-
this.createColumnStates();
|
|
730
719
|
this.filterDirty = true;
|
|
731
720
|
this.requestUpdate("columns", oldValue);
|
|
732
721
|
}
|
|
733
|
-
get
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
722
|
+
get columnOrder() {
|
|
723
|
+
const finalOrder = /* @__PURE__ */ new Set();
|
|
724
|
+
for (const field of this._columnOrder) {
|
|
725
|
+
const col = findColumn(field, this.columns);
|
|
726
|
+
if (col) {
|
|
727
|
+
finalOrder.add(field);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
for (const col of this.columns) {
|
|
731
|
+
if (!finalOrder.has(col.field)) {
|
|
732
|
+
finalOrder.add(col.field);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return [...finalOrder];
|
|
736
|
+
}
|
|
737
|
+
set columnOrder(columns) {
|
|
738
|
+
if (this._columnOrder === columns) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const oldValue = this._columnOrder;
|
|
742
|
+
this._columnOrder = [...columns];
|
|
743
|
+
this.requestUpdate("columnOrder", oldValue);
|
|
744
|
+
}
|
|
745
|
+
get columnVisibility() {
|
|
746
|
+
return this.columnOrder.map((field) => ({
|
|
747
|
+
field,
|
|
748
|
+
visible: this.getColumnState(field).visible
|
|
737
749
|
}));
|
|
738
750
|
}
|
|
739
|
-
set
|
|
740
|
-
|
|
751
|
+
set columnVisibility(columns) {
|
|
752
|
+
const oldValue = this.columnVisibility;
|
|
753
|
+
let changed = false;
|
|
754
|
+
for (const column of columns) {
|
|
755
|
+
const state2 = this.getColumnState(column.field);
|
|
756
|
+
if (state2 && state2.visible !== column.visible) {
|
|
757
|
+
changed = true;
|
|
758
|
+
state2.visible = column.visible;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (!changed) {
|
|
741
762
|
return;
|
|
742
763
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
764
|
+
this.requestUpdate("columnVisibility", oldValue);
|
|
765
|
+
}
|
|
766
|
+
get columnSort() {
|
|
767
|
+
return this.columnOrder.map((field) => ({
|
|
768
|
+
field,
|
|
769
|
+
sort: this.getColumnState(field).sort
|
|
770
|
+
}));
|
|
771
|
+
}
|
|
772
|
+
set columnSort(columns) {
|
|
773
|
+
const oldValue = this.columnSort;
|
|
774
|
+
let changed = false;
|
|
775
|
+
for (const column of columns) {
|
|
776
|
+
const state2 = this.getColumnState(column.field);
|
|
777
|
+
if (state2 && (state2.sort?.order !== column.sort?.order || state2.sort?.priority !== column.sort?.priority)) {
|
|
778
|
+
changed = true;
|
|
779
|
+
state2.sort = column.sort;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (!changed) {
|
|
783
|
+
return;
|
|
747
784
|
}
|
|
748
|
-
this.
|
|
785
|
+
this.sortDirty = true;
|
|
786
|
+
this.requestUpdate("columnSort", oldValue);
|
|
787
|
+
}
|
|
788
|
+
get columnWidths() {
|
|
789
|
+
return this.columnOrder.map((field) => ({
|
|
790
|
+
field,
|
|
791
|
+
width: this.getColumnState(field).width
|
|
792
|
+
}));
|
|
793
|
+
}
|
|
794
|
+
set columnWidths(columns) {
|
|
795
|
+
const oldValue = this.columnWidths;
|
|
796
|
+
let changed = false;
|
|
797
|
+
for (const column of columns) {
|
|
798
|
+
const state2 = this.getColumnState(column.field);
|
|
799
|
+
if (state2 && state2.width !== column.width) {
|
|
800
|
+
changed = true;
|
|
801
|
+
state2.width = column.width;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (!changed) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this.requestUpdate("columnWidths", oldValue);
|
|
749
808
|
}
|
|
750
809
|
get searchQuery() {
|
|
751
810
|
return this._searchQuery;
|
|
@@ -837,18 +896,17 @@ var YatlTable = class extends LitElement {
|
|
|
837
896
|
* Gets a copy of the current state of the table.
|
|
838
897
|
*/
|
|
839
898
|
getState() {
|
|
840
|
-
const states = this.columnStates;
|
|
841
899
|
return {
|
|
842
900
|
searchQuery: this.searchQuery,
|
|
843
901
|
filters: this.filters,
|
|
844
|
-
columnOrder: this.
|
|
902
|
+
columnOrder: this.columnOrder,
|
|
845
903
|
columns: this.columns.map((column) => {
|
|
846
|
-
const
|
|
904
|
+
const state2 = this.getColumnState(column.field);
|
|
847
905
|
return {
|
|
848
906
|
field: column.field,
|
|
849
|
-
visible:
|
|
850
|
-
|
|
851
|
-
width:
|
|
907
|
+
visible: state2.visible,
|
|
908
|
+
sort: state2.sort,
|
|
909
|
+
width: state2.width
|
|
852
910
|
};
|
|
853
911
|
})
|
|
854
912
|
};
|
|
@@ -865,15 +923,12 @@ var YatlTable = class extends LitElement {
|
|
|
865
923
|
this.filters = state2.filters;
|
|
866
924
|
}
|
|
867
925
|
if ("columnOrder" in state2 && state2.columnOrder !== void 0) {
|
|
868
|
-
this.
|
|
926
|
+
this.columnOrder = state2.columnOrder;
|
|
869
927
|
}
|
|
870
928
|
if ("columns" in state2 && state2.columns !== void 0) {
|
|
871
929
|
const newColumnStates = [];
|
|
872
930
|
for (const newState of state2.columns) {
|
|
873
|
-
const currentState =
|
|
874
|
-
field: newState.field,
|
|
875
|
-
visible: true
|
|
876
|
-
};
|
|
931
|
+
const currentState = this.getColumnState(newState.field);
|
|
877
932
|
newColumnStates.push(currentState);
|
|
878
933
|
if (!newState) {
|
|
879
934
|
continue;
|
|
@@ -881,14 +936,15 @@ var YatlTable = class extends LitElement {
|
|
|
881
936
|
if ("visible" in newState && newState.visible !== void 0) {
|
|
882
937
|
currentState.visible = newState.visible;
|
|
883
938
|
}
|
|
884
|
-
if ("
|
|
885
|
-
currentState.
|
|
939
|
+
if ("sort" in newState && newState.sort !== void 0) {
|
|
940
|
+
currentState.sort = newState.sort;
|
|
886
941
|
}
|
|
887
942
|
if ("width" in newState && newState.width !== void 0) {
|
|
888
943
|
currentState.width = newState.width;
|
|
889
944
|
}
|
|
890
945
|
}
|
|
891
|
-
this.
|
|
946
|
+
this._columnStates = newColumnStates;
|
|
947
|
+
this.requestUpdate();
|
|
892
948
|
}
|
|
893
949
|
}
|
|
894
950
|
/**
|
|
@@ -899,35 +955,35 @@ var YatlTable = class extends LitElement {
|
|
|
899
955
|
* @param clear - Clear all other sorting
|
|
900
956
|
*/
|
|
901
957
|
sort(field, order, clear = true) {
|
|
902
|
-
const
|
|
903
|
-
const state2 = findColumn(field,
|
|
958
|
+
const sortStates = this.columnSort;
|
|
959
|
+
const state2 = findColumn(field, sortStates);
|
|
904
960
|
if (!state2) {
|
|
905
961
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
906
962
|
}
|
|
907
|
-
if (order === state2.
|
|
963
|
+
if (order === state2.sort?.order) {
|
|
908
964
|
return;
|
|
909
965
|
}
|
|
910
966
|
if (!this.dispatchEvent(new YatlSortEvent(field, order))) {
|
|
911
967
|
return;
|
|
912
968
|
}
|
|
913
|
-
if (order && !state2.
|
|
914
|
-
const priorities =
|
|
969
|
+
if (order && !state2.sort) {
|
|
970
|
+
const priorities = sortStates.map((col) => col.sort?.priority).filter((priority2) => priority2 !== void 0);
|
|
915
971
|
const maxPriority = this.columns.length + 1;
|
|
916
972
|
const priority = Math.min(maxPriority, ...priorities) - 1;
|
|
917
|
-
state2.
|
|
918
|
-
} else if (order && state2.
|
|
919
|
-
state2.
|
|
973
|
+
state2.sort = { order, priority };
|
|
974
|
+
} else if (order && state2.sort) {
|
|
975
|
+
state2.sort.order = order;
|
|
920
976
|
} else {
|
|
921
|
-
state2.
|
|
977
|
+
state2.sort = null;
|
|
922
978
|
}
|
|
923
979
|
if (clear) {
|
|
924
|
-
for (const state3 of
|
|
980
|
+
for (const state3 of sortStates) {
|
|
925
981
|
if (state3.field !== field) {
|
|
926
|
-
state3.
|
|
982
|
+
state3.sort = null;
|
|
927
983
|
}
|
|
928
984
|
}
|
|
929
985
|
}
|
|
930
|
-
this.
|
|
986
|
+
this.columnSort = sortStates;
|
|
931
987
|
}
|
|
932
988
|
/**
|
|
933
989
|
* Sets the visibility of a specified column.
|
|
@@ -935,8 +991,8 @@ var YatlTable = class extends LitElement {
|
|
|
935
991
|
* @param visible - `true` to show the column, `false` to hide it.
|
|
936
992
|
*/
|
|
937
993
|
setColumnVisibility(field, visible) {
|
|
938
|
-
const
|
|
939
|
-
const state2 = findColumn(field,
|
|
994
|
+
const visibilityStates = this.columnVisibility;
|
|
995
|
+
const state2 = findColumn(field, visibilityStates);
|
|
940
996
|
if (!state2) {
|
|
941
997
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
942
998
|
}
|
|
@@ -947,14 +1003,14 @@ var YatlTable = class extends LitElement {
|
|
|
947
1003
|
return;
|
|
948
1004
|
}
|
|
949
1005
|
state2.visible = visible;
|
|
950
|
-
this.
|
|
1006
|
+
this.columnVisibility = visibilityStates;
|
|
951
1007
|
}
|
|
952
1008
|
/**
|
|
953
1009
|
* Toggles the visibility of hte specified column
|
|
954
1010
|
* @param field - The field name of the column to toggle.
|
|
955
1011
|
*/
|
|
956
1012
|
toggleColumnVisibility(field) {
|
|
957
|
-
const state2 =
|
|
1013
|
+
const state2 = this.getColumnState(field);
|
|
958
1014
|
this.setColumnVisibility(field, !state2);
|
|
959
1015
|
}
|
|
960
1016
|
/**
|
|
@@ -1059,27 +1115,6 @@ var YatlTable = class extends LitElement {
|
|
|
1059
1115
|
this.tableElement.scrollTop = px;
|
|
1060
1116
|
}
|
|
1061
1117
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Sets the display order of the columns in the table.
|
|
1064
|
-
*
|
|
1065
|
-
* @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.
|
|
1066
|
-
* @throws {TypeError} If `fields` is not an array.
|
|
1067
|
-
*/
|
|
1068
|
-
setColumnOrder(fields) {
|
|
1069
|
-
const newColumns = [];
|
|
1070
|
-
for (const field of fields) {
|
|
1071
|
-
const col = findColumn(field, this.columns);
|
|
1072
|
-
if (col) {
|
|
1073
|
-
newColumns.push(col);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
for (const col of this.columns) {
|
|
1077
|
-
if (!findColumn(col.field, newColumns)) {
|
|
1078
|
-
newColumns.push(col);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
this.columns = [...newColumns];
|
|
1082
|
-
}
|
|
1083
1118
|
/**
|
|
1084
1119
|
* Finds the first row
|
|
1085
1120
|
* @param field
|
|
@@ -1147,8 +1182,8 @@ var YatlTable = class extends LitElement {
|
|
|
1147
1182
|
part="header-sort-icon"
|
|
1148
1183
|
class=${classMap({
|
|
1149
1184
|
"sort-icon": true,
|
|
1150
|
-
ascending: state2.
|
|
1151
|
-
descending: state2.
|
|
1185
|
+
ascending: state2.sort?.order === "asc",
|
|
1186
|
+
descending: state2.sort?.order === "desc"
|
|
1152
1187
|
})}
|
|
1153
1188
|
></div>` : nothing;
|
|
1154
1189
|
}
|
|
@@ -1160,8 +1195,9 @@ var YatlTable = class extends LitElement {
|
|
|
1160
1195
|
@mousedown=${(event) => this.handleResizeMouseDown(event, column.field)}
|
|
1161
1196
|
></div>` : nothing;
|
|
1162
1197
|
}
|
|
1163
|
-
renderHeaderCell(
|
|
1164
|
-
const
|
|
1198
|
+
renderHeaderCell(field) {
|
|
1199
|
+
const column = findColumn(field, this.columns);
|
|
1200
|
+
const state2 = this.getColumnState(column.field);
|
|
1165
1201
|
if (state2.visible == false) {
|
|
1166
1202
|
return nothing;
|
|
1167
1203
|
}
|
|
@@ -1196,7 +1232,7 @@ var YatlTable = class extends LitElement {
|
|
|
1196
1232
|
renderHeader() {
|
|
1197
1233
|
return html2`
|
|
1198
1234
|
<div part="header" class="header row">
|
|
1199
|
-
${this.
|
|
1235
|
+
${this.columnOrder.map((field) => this.renderHeaderCell(field))}
|
|
1200
1236
|
</div>
|
|
1201
1237
|
`;
|
|
1202
1238
|
}
|
|
@@ -1210,9 +1246,10 @@ var YatlTable = class extends LitElement {
|
|
|
1210
1246
|
const indices = this.rowMetadata.get(row).highlightIndices;
|
|
1211
1247
|
return this.enableSearchHighlight && indices ? highlightText(String(value), indices[column.field]) : value;
|
|
1212
1248
|
}
|
|
1213
|
-
renderCell(
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1249
|
+
renderCell(field, row) {
|
|
1250
|
+
const column = findColumn(field, this.columns);
|
|
1251
|
+
const state2 = this.getColumnState(column.field);
|
|
1252
|
+
if (!state2.visible) {
|
|
1216
1253
|
return nothing;
|
|
1217
1254
|
}
|
|
1218
1255
|
let value = getNestedValue(row, column.field);
|
|
@@ -1250,7 +1287,7 @@ var YatlTable = class extends LitElement {
|
|
|
1250
1287
|
data-index=${metadata.index}
|
|
1251
1288
|
data-filtered-index=${index}
|
|
1252
1289
|
>
|
|
1253
|
-
${this.
|
|
1290
|
+
${this.columnOrder.map((field) => this.renderCell(field, row))}
|
|
1254
1291
|
</div>
|
|
1255
1292
|
`;
|
|
1256
1293
|
}
|
|
@@ -1311,7 +1348,8 @@ var YatlTable = class extends LitElement {
|
|
|
1311
1348
|
`;
|
|
1312
1349
|
}
|
|
1313
1350
|
render() {
|
|
1314
|
-
const
|
|
1351
|
+
const gridWidths = this.getGridWidths();
|
|
1352
|
+
const gridTemplate = widthsToGridTemplates(gridWidths).join(" ");
|
|
1315
1353
|
return html2`
|
|
1316
1354
|
<div
|
|
1317
1355
|
part="table"
|
|
@@ -1326,12 +1364,30 @@ var YatlTable = class extends LitElement {
|
|
|
1326
1364
|
// #region --- Lifecycle Methods ---
|
|
1327
1365
|
updated(changedProperties) {
|
|
1328
1366
|
super.updated(changedProperties);
|
|
1329
|
-
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1367
|
+
super.updated(changedProperties);
|
|
1368
|
+
const stateProps = [
|
|
1369
|
+
"columnOrder",
|
|
1370
|
+
"columnVisibility",
|
|
1371
|
+
"columnSort",
|
|
1372
|
+
"columnWidths",
|
|
1373
|
+
"searchQuery",
|
|
1374
|
+
"filters"
|
|
1375
|
+
];
|
|
1376
|
+
const changedStateProp = stateProps.filter(
|
|
1377
|
+
(prop) => changedProperties.has(prop)
|
|
1332
1378
|
);
|
|
1333
|
-
if (
|
|
1334
|
-
this.
|
|
1379
|
+
if (changedStateProp.length) {
|
|
1380
|
+
this.dispatchEvent(
|
|
1381
|
+
new YatlStateChangeEvent(this.getState(), changedStateProp)
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
if (this.storageOptions?.key) {
|
|
1385
|
+
const shouldSave = Array.from(changedProperties.keys()).some(
|
|
1386
|
+
(prop) => SAVE_TRIGGERS.has(prop)
|
|
1387
|
+
);
|
|
1388
|
+
if (shouldSave) {
|
|
1389
|
+
this.scheduleSave();
|
|
1390
|
+
}
|
|
1335
1391
|
}
|
|
1336
1392
|
}
|
|
1337
1393
|
disconnectedCallback() {
|
|
@@ -1520,12 +1576,12 @@ var YatlTable = class extends LitElement {
|
|
|
1520
1576
|
compareRows(a, b, field) {
|
|
1521
1577
|
let aValue, bValue;
|
|
1522
1578
|
const columnData = findColumn(field, this.columnData);
|
|
1523
|
-
if (!columnData.state.
|
|
1579
|
+
if (!columnData.state.sort) {
|
|
1524
1580
|
return 0;
|
|
1525
1581
|
}
|
|
1526
1582
|
const aMetadata = this.rowMetadata.get(a);
|
|
1527
1583
|
const bMetadata = this.rowMetadata.get(b);
|
|
1528
|
-
if (columnData.state.
|
|
1584
|
+
if (columnData.state.sort?.order === "asc") {
|
|
1529
1585
|
aValue = aMetadata.sortValues[columnData.field];
|
|
1530
1586
|
bValue = bMetadata.sortValues[columnData.field];
|
|
1531
1587
|
} else {
|
|
@@ -1549,9 +1605,7 @@ var YatlTable = class extends LitElement {
|
|
|
1549
1605
|
this.filterRows();
|
|
1550
1606
|
return;
|
|
1551
1607
|
}
|
|
1552
|
-
const sortedColumns = this.columnData.filter((col) => col.state.visible && col.state.
|
|
1553
|
-
(a, b) => b.state.sortState.priority - a.state.sortState.priority
|
|
1554
|
-
);
|
|
1608
|
+
const sortedColumns = this.columnData.filter((col) => col.state.visible && col.state.sort).sort((a, b) => b.state.sort.priority - a.state.sort.priority);
|
|
1555
1609
|
this._filteredData = this._filteredData.toSorted((a, b) => {
|
|
1556
1610
|
const aMetadata = this.rowMetadata.get(a);
|
|
1557
1611
|
const bMetadata = this.rowMetadata.get(b);
|
|
@@ -1572,18 +1626,7 @@ var YatlTable = class extends LitElement {
|
|
|
1572
1626
|
this.sortDirty = false;
|
|
1573
1627
|
}
|
|
1574
1628
|
// #endregion
|
|
1575
|
-
// #region ---
|
|
1576
|
-
createColumnStates() {
|
|
1577
|
-
this.columnStates = this.columns.map((column) => {
|
|
1578
|
-
const previousState = findColumn(column.field, this._columnStates);
|
|
1579
|
-
return {
|
|
1580
|
-
field: column.field,
|
|
1581
|
-
visible: previousState?.visible ?? true,
|
|
1582
|
-
sortState: previousState?.sortState,
|
|
1583
|
-
width: previousState?.width
|
|
1584
|
-
};
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1629
|
+
// #region --- Utilities ---
|
|
1587
1630
|
createMetadata() {
|
|
1588
1631
|
this.rowMetadata = /* @__PURE__ */ new WeakMap();
|
|
1589
1632
|
let index = 0;
|
|
@@ -1636,20 +1679,19 @@ var YatlTable = class extends LitElement {
|
|
|
1636
1679
|
this.queryTokens.push(...this.searchTokenizer(this.searchQuery));
|
|
1637
1680
|
}
|
|
1638
1681
|
}
|
|
1639
|
-
// #endregion
|
|
1640
|
-
// #region --- Utilities ---
|
|
1641
1682
|
get columnData() {
|
|
1642
1683
|
return this.columns.map((column) => ({
|
|
1643
1684
|
field: column.field,
|
|
1644
1685
|
options: column,
|
|
1645
|
-
state:
|
|
1646
|
-
field: column.field,
|
|
1647
|
-
visible: true
|
|
1648
|
-
}
|
|
1686
|
+
state: this.getColumnState(column.field)
|
|
1649
1687
|
}));
|
|
1650
1688
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1689
|
+
/**
|
|
1690
|
+
* Gets the width of each column in the
|
|
1691
|
+
* order they will appear in the grid.
|
|
1692
|
+
*/
|
|
1693
|
+
getGridWidths() {
|
|
1694
|
+
return this.columnOrder.map((field) => this.getColumnState(field)).filter((state2) => state2.visible).map((state2) => state2.width);
|
|
1653
1695
|
}
|
|
1654
1696
|
scheduleSave() {
|
|
1655
1697
|
window.clearTimeout(this.saveTimer);
|
|
@@ -1657,6 +1699,19 @@ var YatlTable = class extends LitElement {
|
|
|
1657
1699
|
this.saveStateToStorage();
|
|
1658
1700
|
}, STATE_SAVE_DEBOUNCE);
|
|
1659
1701
|
}
|
|
1702
|
+
getColumnState(field) {
|
|
1703
|
+
let state2 = findColumn(field, this._columnStates);
|
|
1704
|
+
if (!state2) {
|
|
1705
|
+
state2 = {
|
|
1706
|
+
field,
|
|
1707
|
+
visible: true,
|
|
1708
|
+
sort: null,
|
|
1709
|
+
width: null
|
|
1710
|
+
};
|
|
1711
|
+
this._columnStates.push(state2);
|
|
1712
|
+
}
|
|
1713
|
+
return state2;
|
|
1714
|
+
}
|
|
1660
1715
|
// #endregion
|
|
1661
1716
|
// #region --- Storage Methods ---
|
|
1662
1717
|
saveStateToStorage() {
|
|
@@ -1676,7 +1731,7 @@ var YatlTable = class extends LitElement {
|
|
|
1676
1731
|
field: columnState.field
|
|
1677
1732
|
};
|
|
1678
1733
|
if (options.saveColumnSortOrders) {
|
|
1679
|
-
savedColumnState.
|
|
1734
|
+
savedColumnState.sort = columnState.sort;
|
|
1680
1735
|
}
|
|
1681
1736
|
if (options.saveColumnVisibility) {
|
|
1682
1737
|
savedColumnState.visible = columnState.visible;
|
|
@@ -1721,7 +1776,7 @@ var YatlTable = class extends LitElement {
|
|
|
1721
1776
|
columnStateToRestore.width = savedColumnState.width;
|
|
1722
1777
|
}
|
|
1723
1778
|
if (options.saveColumnSortOrders) {
|
|
1724
|
-
columnStateToRestore.
|
|
1779
|
+
columnStateToRestore.sort = savedColumnState.sort;
|
|
1725
1780
|
}
|
|
1726
1781
|
tableStateToRestore.columns.push(columnStateToRestore);
|
|
1727
1782
|
}
|
|
@@ -1740,14 +1795,14 @@ var YatlTable = class extends LitElement {
|
|
|
1740
1795
|
if (!header) {
|
|
1741
1796
|
return;
|
|
1742
1797
|
}
|
|
1743
|
-
const columnIndex = this.
|
|
1798
|
+
const columnIndex = this.columnOrder.findIndex((col) => col === field);
|
|
1744
1799
|
if (columnIndex < 0) {
|
|
1745
1800
|
return;
|
|
1746
1801
|
}
|
|
1747
1802
|
this.tableElement.querySelectorAll(".header .cell").forEach((element) => {
|
|
1748
1803
|
const field2 = element.dataset.field;
|
|
1749
1804
|
if (field2) {
|
|
1750
|
-
const state2 =
|
|
1805
|
+
const state2 = this.getColumnState(field2);
|
|
1751
1806
|
if (state2) {
|
|
1752
1807
|
state2.width = element.getBoundingClientRect().width;
|
|
1753
1808
|
}
|
|
@@ -1759,7 +1814,7 @@ var YatlTable = class extends LitElement {
|
|
|
1759
1814
|
startWidth: header.getBoundingClientRect().width,
|
|
1760
1815
|
columnIndex,
|
|
1761
1816
|
columnField: field,
|
|
1762
|
-
currentWidths: widthsToGridTemplates(this.
|
|
1817
|
+
currentWidths: widthsToGridTemplates(this.getGridWidths())
|
|
1763
1818
|
};
|
|
1764
1819
|
this.tableElement.style.setProperty(
|
|
1765
1820
|
"--grid-template",
|
|
@@ -1826,7 +1881,16 @@ __decorateClass([
|
|
|
1826
1881
|
], YatlTable.prototype, "columns", 1);
|
|
1827
1882
|
__decorateClass([
|
|
1828
1883
|
property({ attribute: false })
|
|
1829
|
-
], YatlTable.prototype, "
|
|
1884
|
+
], YatlTable.prototype, "columnOrder", 1);
|
|
1885
|
+
__decorateClass([
|
|
1886
|
+
property({ attribute: false })
|
|
1887
|
+
], YatlTable.prototype, "columnVisibility", 1);
|
|
1888
|
+
__decorateClass([
|
|
1889
|
+
property({ attribute: false })
|
|
1890
|
+
], YatlTable.prototype, "columnSort", 1);
|
|
1891
|
+
__decorateClass([
|
|
1892
|
+
property({ attribute: false })
|
|
1893
|
+
], YatlTable.prototype, "columnWidths", 1);
|
|
1830
1894
|
__decorateClass([
|
|
1831
1895
|
property({ type: String, attribute: "search-query" })
|
|
1832
1896
|
], YatlTable.prototype, "searchQuery", 1);
|
|
@@ -1860,6 +1924,7 @@ export {
|
|
|
1860
1924
|
YatlRowClickEvent,
|
|
1861
1925
|
YatlSearchEvent,
|
|
1862
1926
|
YatlSortEvent,
|
|
1927
|
+
YatlStateChangeEvent,
|
|
1863
1928
|
YatlTable,
|
|
1864
1929
|
createRegexTokenizer,
|
|
1865
1930
|
findColumn,
|