@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.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
YatlRowClickEvent: () => YatlRowClickEvent,
|
|
37
37
|
YatlSearchEvent: () => YatlSearchEvent,
|
|
38
38
|
YatlSortEvent: () => YatlSortEvent,
|
|
39
|
+
YatlStateChangeEvent: () => YatlStateChangeEvent,
|
|
39
40
|
YatlTable: () => YatlTable,
|
|
40
41
|
createRegexTokenizer: () => createRegexTokenizer,
|
|
41
42
|
findColumn: () => findColumn,
|
|
@@ -140,6 +141,14 @@ var _YatlSearchEvent = class _YatlSearchEvent extends YatlEvent {
|
|
|
140
141
|
};
|
|
141
142
|
_YatlSearchEvent.EVENT_NAME = "yatl-search";
|
|
142
143
|
var YatlSearchEvent = _YatlSearchEvent;
|
|
144
|
+
var _YatlStateChangeEvent = class _YatlStateChangeEvent extends YatlEvent {
|
|
145
|
+
constructor(state2, triggers) {
|
|
146
|
+
super(_YatlStateChangeEvent.EVENT_NAME, { state: state2, triggers });
|
|
147
|
+
this.triggers = triggers;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
_YatlStateChangeEvent.EVENT_NAME = "yatl-state-change";
|
|
151
|
+
var YatlStateChangeEvent = _YatlStateChangeEvent;
|
|
143
152
|
|
|
144
153
|
// src/utils.ts
|
|
145
154
|
var import_lit = require("lit");
|
|
@@ -216,23 +225,6 @@ function highlightText(text, ranges) {
|
|
|
216
225
|
function widthsToGridTemplates(widths, defaultWidth = "1fr") {
|
|
217
226
|
return widths.map((width) => width ? `${width}px` : defaultWidth);
|
|
218
227
|
}
|
|
219
|
-
function didSortStateChange(newState, oldState) {
|
|
220
|
-
if (!oldState) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
const allKeys = /* @__PURE__ */ new Set([
|
|
224
|
-
...oldState.map((s) => s.field),
|
|
225
|
-
...newState.map((s) => s.field)
|
|
226
|
-
]);
|
|
227
|
-
for (const key of allKeys) {
|
|
228
|
-
const oldSort = findColumn(key, oldState)?.sortState;
|
|
229
|
-
const newSort = findColumn(key, newState)?.sortState;
|
|
230
|
-
if (oldSort?.order !== newSort?.order || oldSort?.priority !== newSort?.priority) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
228
|
function isCompareable(value) {
|
|
237
229
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
238
230
|
}
|
|
@@ -558,10 +550,11 @@ var DEFAULT_STORAGE_OPTIONS = {
|
|
|
558
550
|
var SAVE_TRIGGERS = /* @__PURE__ */ new Set([
|
|
559
551
|
"searchQuery",
|
|
560
552
|
"filters",
|
|
561
|
-
// Covers column order
|
|
562
553
|
"columns",
|
|
563
|
-
|
|
564
|
-
"
|
|
554
|
+
"columnSort",
|
|
555
|
+
"columnOrder",
|
|
556
|
+
"columnVisibility",
|
|
557
|
+
"columnWidths",
|
|
565
558
|
"storageOptions"
|
|
566
559
|
]);
|
|
567
560
|
var MATCH_WEIGHTS = {
|
|
@@ -578,6 +571,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
578
571
|
this._enableSearchScoring = false;
|
|
579
572
|
this._columns = [];
|
|
580
573
|
this._columnStates = [];
|
|
574
|
+
this._columnOrder = [];
|
|
581
575
|
this._storageOptions = null;
|
|
582
576
|
this._data = [];
|
|
583
577
|
this._searchQuery = "";
|
|
@@ -620,12 +614,12 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
620
614
|
return;
|
|
621
615
|
}
|
|
622
616
|
const multiSort = event.shiftKey;
|
|
623
|
-
const state2 =
|
|
624
|
-
if (!state2?.
|
|
617
|
+
const state2 = this.getColumnState(column.field);
|
|
618
|
+
if (!state2?.sort) {
|
|
625
619
|
this.sort(column.field, "asc", !multiSort);
|
|
626
|
-
} else if (state2.
|
|
620
|
+
} else if (state2.sort.order === "asc") {
|
|
627
621
|
this.sort(column.field, "desc", !multiSort);
|
|
628
|
-
} else if (state2.
|
|
622
|
+
} else if (state2.sort.order) {
|
|
629
623
|
this.sort(column.field, null, !multiSort);
|
|
630
624
|
}
|
|
631
625
|
};
|
|
@@ -655,18 +649,16 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
655
649
|
const finalWidth = parseFloat(
|
|
656
650
|
this.resizeState.currentWidths[this.resizeState.columnIndex]
|
|
657
651
|
);
|
|
658
|
-
const
|
|
659
|
-
const state2 = findColumn(this.resizeState.columnField,
|
|
652
|
+
const columnWidths = this.columnWidths;
|
|
653
|
+
const state2 = findColumn(this.resizeState.columnField, columnWidths);
|
|
660
654
|
state2.width = finalWidth;
|
|
661
|
-
this.
|
|
655
|
+
this.columnWidths = columnWidths;
|
|
662
656
|
this.dispatchEvent(new YatlColumnResizeEvent(state2.field, state2.width));
|
|
663
657
|
}
|
|
664
658
|
this.resizeState = null;
|
|
665
659
|
};
|
|
666
660
|
this.handleDragColumnStart = (event, field) => {
|
|
667
661
|
const target = event.target;
|
|
668
|
-
console.log("Starting drag event");
|
|
669
|
-
console.log(target);
|
|
670
662
|
if (target?.classList.contains("resizer")) {
|
|
671
663
|
event.preventDefault();
|
|
672
664
|
return;
|
|
@@ -701,24 +693,23 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
701
693
|
}
|
|
702
694
|
event.preventDefault();
|
|
703
695
|
event.stopPropagation();
|
|
704
|
-
const
|
|
705
|
-
const dragIndex =
|
|
706
|
-
const dropIndex =
|
|
696
|
+
const newColumnOrder = [...this.columnOrder];
|
|
697
|
+
const dragIndex = newColumnOrder.findIndex((col) => col === this.dragColumn);
|
|
698
|
+
const dropIndex = newColumnOrder.findIndex((col) => col === field);
|
|
707
699
|
if (dragIndex > -1 && dropIndex > -1) {
|
|
708
|
-
const [draggedColumn] =
|
|
700
|
+
const [draggedColumn] = newColumnOrder.splice(dragIndex, 1);
|
|
709
701
|
const droppedColumn = findColumn(field, this.columns);
|
|
710
702
|
if (!droppedColumn) return;
|
|
711
|
-
|
|
712
|
-
const newColumnOrder = columns.map((col) => col.field);
|
|
703
|
+
newColumnOrder.splice(dropIndex, 0, draggedColumn);
|
|
713
704
|
const reorderEvent = new YatlColumnReorderEvent(
|
|
714
|
-
draggedColumn
|
|
705
|
+
draggedColumn,
|
|
715
706
|
droppedColumn.field,
|
|
716
707
|
newColumnOrder
|
|
717
708
|
);
|
|
718
709
|
if (!this.dispatchEvent(reorderEvent)) {
|
|
719
710
|
return;
|
|
720
711
|
}
|
|
721
|
-
this.
|
|
712
|
+
this.columnOrder = [...newColumnOrder];
|
|
722
713
|
}
|
|
723
714
|
};
|
|
724
715
|
this.handleDragColumnEnd = () => {
|
|
@@ -760,26 +751,95 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
760
751
|
}
|
|
761
752
|
const oldValue = this._columns;
|
|
762
753
|
this._columns = columns;
|
|
763
|
-
this.createColumnStates();
|
|
764
754
|
this.filterDirty = true;
|
|
765
755
|
this.requestUpdate("columns", oldValue);
|
|
766
756
|
}
|
|
767
|
-
get
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
757
|
+
get columnOrder() {
|
|
758
|
+
const finalOrder = /* @__PURE__ */ new Set();
|
|
759
|
+
for (const field of this._columnOrder) {
|
|
760
|
+
const col = findColumn(field, this.columns);
|
|
761
|
+
if (col) {
|
|
762
|
+
finalOrder.add(field);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
for (const col of this.columns) {
|
|
766
|
+
if (!finalOrder.has(col.field)) {
|
|
767
|
+
finalOrder.add(col.field);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return [...finalOrder];
|
|
771
|
+
}
|
|
772
|
+
set columnOrder(columns) {
|
|
773
|
+
if (this._columnOrder === columns) {
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
const oldValue = this._columnOrder;
|
|
777
|
+
this._columnOrder = [...columns];
|
|
778
|
+
this.requestUpdate("columnOrder", oldValue);
|
|
779
|
+
}
|
|
780
|
+
get columnVisibility() {
|
|
781
|
+
return this.columnOrder.map((field) => ({
|
|
782
|
+
field,
|
|
783
|
+
visible: this.getColumnState(field).visible
|
|
771
784
|
}));
|
|
772
785
|
}
|
|
773
|
-
set
|
|
774
|
-
|
|
786
|
+
set columnVisibility(columns) {
|
|
787
|
+
const oldValue = this.columnVisibility;
|
|
788
|
+
let changed = false;
|
|
789
|
+
for (const column of columns) {
|
|
790
|
+
const state2 = this.getColumnState(column.field);
|
|
791
|
+
if (state2 && state2.visible !== column.visible) {
|
|
792
|
+
changed = true;
|
|
793
|
+
state2.visible = column.visible;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (!changed) {
|
|
775
797
|
return;
|
|
776
798
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
799
|
+
this.requestUpdate("columnVisibility", oldValue);
|
|
800
|
+
}
|
|
801
|
+
get columnSort() {
|
|
802
|
+
return this.columnOrder.map((field) => ({
|
|
803
|
+
field,
|
|
804
|
+
sort: this.getColumnState(field).sort
|
|
805
|
+
}));
|
|
806
|
+
}
|
|
807
|
+
set columnSort(columns) {
|
|
808
|
+
const oldValue = this.columnSort;
|
|
809
|
+
let changed = false;
|
|
810
|
+
for (const column of columns) {
|
|
811
|
+
const state2 = this.getColumnState(column.field);
|
|
812
|
+
if (state2 && (state2.sort?.order !== column.sort?.order || state2.sort?.priority !== column.sort?.priority)) {
|
|
813
|
+
changed = true;
|
|
814
|
+
state2.sort = column.sort;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (!changed) {
|
|
818
|
+
return;
|
|
781
819
|
}
|
|
782
|
-
this.
|
|
820
|
+
this.sortDirty = true;
|
|
821
|
+
this.requestUpdate("columnSort", oldValue);
|
|
822
|
+
}
|
|
823
|
+
get columnWidths() {
|
|
824
|
+
return this.columnOrder.map((field) => ({
|
|
825
|
+
field,
|
|
826
|
+
width: this.getColumnState(field).width
|
|
827
|
+
}));
|
|
828
|
+
}
|
|
829
|
+
set columnWidths(columns) {
|
|
830
|
+
const oldValue = this.columnWidths;
|
|
831
|
+
let changed = false;
|
|
832
|
+
for (const column of columns) {
|
|
833
|
+
const state2 = this.getColumnState(column.field);
|
|
834
|
+
if (state2 && state2.width !== column.width) {
|
|
835
|
+
changed = true;
|
|
836
|
+
state2.width = column.width;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (!changed) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
this.requestUpdate("columnWidths", oldValue);
|
|
783
843
|
}
|
|
784
844
|
get searchQuery() {
|
|
785
845
|
return this._searchQuery;
|
|
@@ -871,18 +931,17 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
871
931
|
* Gets a copy of the current state of the table.
|
|
872
932
|
*/
|
|
873
933
|
getState() {
|
|
874
|
-
const states = this.columnStates;
|
|
875
934
|
return {
|
|
876
935
|
searchQuery: this.searchQuery,
|
|
877
936
|
filters: this.filters,
|
|
878
|
-
columnOrder: this.
|
|
937
|
+
columnOrder: this.columnOrder,
|
|
879
938
|
columns: this.columns.map((column) => {
|
|
880
|
-
const
|
|
939
|
+
const state2 = this.getColumnState(column.field);
|
|
881
940
|
return {
|
|
882
941
|
field: column.field,
|
|
883
|
-
visible:
|
|
884
|
-
|
|
885
|
-
width:
|
|
942
|
+
visible: state2.visible,
|
|
943
|
+
sort: state2.sort,
|
|
944
|
+
width: state2.width
|
|
886
945
|
};
|
|
887
946
|
})
|
|
888
947
|
};
|
|
@@ -899,15 +958,12 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
899
958
|
this.filters = state2.filters;
|
|
900
959
|
}
|
|
901
960
|
if ("columnOrder" in state2 && state2.columnOrder !== void 0) {
|
|
902
|
-
this.
|
|
961
|
+
this.columnOrder = state2.columnOrder;
|
|
903
962
|
}
|
|
904
963
|
if ("columns" in state2 && state2.columns !== void 0) {
|
|
905
964
|
const newColumnStates = [];
|
|
906
965
|
for (const newState of state2.columns) {
|
|
907
|
-
const currentState =
|
|
908
|
-
field: newState.field,
|
|
909
|
-
visible: true
|
|
910
|
-
};
|
|
966
|
+
const currentState = this.getColumnState(newState.field);
|
|
911
967
|
newColumnStates.push(currentState);
|
|
912
968
|
if (!newState) {
|
|
913
969
|
continue;
|
|
@@ -915,14 +971,15 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
915
971
|
if ("visible" in newState && newState.visible !== void 0) {
|
|
916
972
|
currentState.visible = newState.visible;
|
|
917
973
|
}
|
|
918
|
-
if ("
|
|
919
|
-
currentState.
|
|
974
|
+
if ("sort" in newState && newState.sort !== void 0) {
|
|
975
|
+
currentState.sort = newState.sort;
|
|
920
976
|
}
|
|
921
977
|
if ("width" in newState && newState.width !== void 0) {
|
|
922
978
|
currentState.width = newState.width;
|
|
923
979
|
}
|
|
924
980
|
}
|
|
925
|
-
this.
|
|
981
|
+
this._columnStates = newColumnStates;
|
|
982
|
+
this.requestUpdate();
|
|
926
983
|
}
|
|
927
984
|
}
|
|
928
985
|
/**
|
|
@@ -933,35 +990,35 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
933
990
|
* @param clear - Clear all other sorting
|
|
934
991
|
*/
|
|
935
992
|
sort(field, order, clear = true) {
|
|
936
|
-
const
|
|
937
|
-
const state2 = findColumn(field,
|
|
993
|
+
const sortStates = this.columnSort;
|
|
994
|
+
const state2 = findColumn(field, sortStates);
|
|
938
995
|
if (!state2) {
|
|
939
996
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
940
997
|
}
|
|
941
|
-
if (order === state2.
|
|
998
|
+
if (order === state2.sort?.order) {
|
|
942
999
|
return;
|
|
943
1000
|
}
|
|
944
1001
|
if (!this.dispatchEvent(new YatlSortEvent(field, order))) {
|
|
945
1002
|
return;
|
|
946
1003
|
}
|
|
947
|
-
if (order && !state2.
|
|
948
|
-
const priorities =
|
|
1004
|
+
if (order && !state2.sort) {
|
|
1005
|
+
const priorities = sortStates.map((col) => col.sort?.priority).filter((priority2) => priority2 !== void 0);
|
|
949
1006
|
const maxPriority = this.columns.length + 1;
|
|
950
1007
|
const priority = Math.min(maxPriority, ...priorities) - 1;
|
|
951
|
-
state2.
|
|
952
|
-
} else if (order && state2.
|
|
953
|
-
state2.
|
|
1008
|
+
state2.sort = { order, priority };
|
|
1009
|
+
} else if (order && state2.sort) {
|
|
1010
|
+
state2.sort.order = order;
|
|
954
1011
|
} else {
|
|
955
|
-
state2.
|
|
1012
|
+
state2.sort = null;
|
|
956
1013
|
}
|
|
957
1014
|
if (clear) {
|
|
958
|
-
for (const state3 of
|
|
1015
|
+
for (const state3 of sortStates) {
|
|
959
1016
|
if (state3.field !== field) {
|
|
960
|
-
state3.
|
|
1017
|
+
state3.sort = null;
|
|
961
1018
|
}
|
|
962
1019
|
}
|
|
963
1020
|
}
|
|
964
|
-
this.
|
|
1021
|
+
this.columnSort = sortStates;
|
|
965
1022
|
}
|
|
966
1023
|
/**
|
|
967
1024
|
* Sets the visibility of a specified column.
|
|
@@ -969,8 +1026,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
969
1026
|
* @param visible - `true` to show the column, `false` to hide it.
|
|
970
1027
|
*/
|
|
971
1028
|
setColumnVisibility(field, visible) {
|
|
972
|
-
const
|
|
973
|
-
const state2 = findColumn(field,
|
|
1029
|
+
const visibilityStates = this.columnVisibility;
|
|
1030
|
+
const state2 = findColumn(field, visibilityStates);
|
|
974
1031
|
if (!state2) {
|
|
975
1032
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
976
1033
|
}
|
|
@@ -981,14 +1038,14 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
981
1038
|
return;
|
|
982
1039
|
}
|
|
983
1040
|
state2.visible = visible;
|
|
984
|
-
this.
|
|
1041
|
+
this.columnVisibility = visibilityStates;
|
|
985
1042
|
}
|
|
986
1043
|
/**
|
|
987
1044
|
* Toggles the visibility of hte specified column
|
|
988
1045
|
* @param field - The field name of the column to toggle.
|
|
989
1046
|
*/
|
|
990
1047
|
toggleColumnVisibility(field) {
|
|
991
|
-
const state2 =
|
|
1048
|
+
const state2 = this.getColumnState(field);
|
|
992
1049
|
this.setColumnVisibility(field, !state2);
|
|
993
1050
|
}
|
|
994
1051
|
/**
|
|
@@ -1093,27 +1150,6 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1093
1150
|
this.tableElement.scrollTop = px;
|
|
1094
1151
|
}
|
|
1095
1152
|
}
|
|
1096
|
-
/**
|
|
1097
|
-
* Sets the display order of the columns in the table.
|
|
1098
|
-
*
|
|
1099
|
-
* @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.
|
|
1100
|
-
* @throws {TypeError} If `fields` is not an array.
|
|
1101
|
-
*/
|
|
1102
|
-
setColumnOrder(fields) {
|
|
1103
|
-
const newColumns = [];
|
|
1104
|
-
for (const field of fields) {
|
|
1105
|
-
const col = findColumn(field, this.columns);
|
|
1106
|
-
if (col) {
|
|
1107
|
-
newColumns.push(col);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
for (const col of this.columns) {
|
|
1111
|
-
if (!findColumn(col.field, newColumns)) {
|
|
1112
|
-
newColumns.push(col);
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
this.columns = [...newColumns];
|
|
1116
|
-
}
|
|
1117
1153
|
/**
|
|
1118
1154
|
* Finds the first row
|
|
1119
1155
|
* @param field
|
|
@@ -1181,8 +1217,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1181
1217
|
part="header-sort-icon"
|
|
1182
1218
|
class=${(0, import_class_map.classMap)({
|
|
1183
1219
|
"sort-icon": true,
|
|
1184
|
-
ascending: state2.
|
|
1185
|
-
descending: state2.
|
|
1220
|
+
ascending: state2.sort?.order === "asc",
|
|
1221
|
+
descending: state2.sort?.order === "desc"
|
|
1186
1222
|
})}
|
|
1187
1223
|
></div>` : import_lit3.nothing;
|
|
1188
1224
|
}
|
|
@@ -1194,8 +1230,9 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1194
1230
|
@mousedown=${(event) => this.handleResizeMouseDown(event, column.field)}
|
|
1195
1231
|
></div>` : import_lit3.nothing;
|
|
1196
1232
|
}
|
|
1197
|
-
renderHeaderCell(
|
|
1198
|
-
const
|
|
1233
|
+
renderHeaderCell(field) {
|
|
1234
|
+
const column = findColumn(field, this.columns);
|
|
1235
|
+
const state2 = this.getColumnState(column.field);
|
|
1199
1236
|
if (state2.visible == false) {
|
|
1200
1237
|
return import_lit3.nothing;
|
|
1201
1238
|
}
|
|
@@ -1230,7 +1267,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1230
1267
|
renderHeader() {
|
|
1231
1268
|
return import_lit3.html`
|
|
1232
1269
|
<div part="header" class="header row">
|
|
1233
|
-
${this.
|
|
1270
|
+
${this.columnOrder.map((field) => this.renderHeaderCell(field))}
|
|
1234
1271
|
</div>
|
|
1235
1272
|
`;
|
|
1236
1273
|
}
|
|
@@ -1244,9 +1281,10 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1244
1281
|
const indices = this.rowMetadata.get(row).highlightIndices;
|
|
1245
1282
|
return this.enableSearchHighlight && indices ? highlightText(String(value), indices[column.field]) : value;
|
|
1246
1283
|
}
|
|
1247
|
-
renderCell(
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1284
|
+
renderCell(field, row) {
|
|
1285
|
+
const column = findColumn(field, this.columns);
|
|
1286
|
+
const state2 = this.getColumnState(column.field);
|
|
1287
|
+
if (!state2.visible) {
|
|
1250
1288
|
return import_lit3.nothing;
|
|
1251
1289
|
}
|
|
1252
1290
|
let value = getNestedValue(row, column.field);
|
|
@@ -1284,7 +1322,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1284
1322
|
data-index=${metadata.index}
|
|
1285
1323
|
data-filtered-index=${index}
|
|
1286
1324
|
>
|
|
1287
|
-
${this.
|
|
1325
|
+
${this.columnOrder.map((field) => this.renderCell(field, row))}
|
|
1288
1326
|
</div>
|
|
1289
1327
|
`;
|
|
1290
1328
|
}
|
|
@@ -1345,7 +1383,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1345
1383
|
`;
|
|
1346
1384
|
}
|
|
1347
1385
|
render() {
|
|
1348
|
-
const
|
|
1386
|
+
const gridWidths = this.getGridWidths();
|
|
1387
|
+
const gridTemplate = widthsToGridTemplates(gridWidths).join(" ");
|
|
1349
1388
|
return import_lit3.html`
|
|
1350
1389
|
<div
|
|
1351
1390
|
part="table"
|
|
@@ -1360,12 +1399,30 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1360
1399
|
// #region --- Lifecycle Methods ---
|
|
1361
1400
|
updated(changedProperties) {
|
|
1362
1401
|
super.updated(changedProperties);
|
|
1363
|
-
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1402
|
+
super.updated(changedProperties);
|
|
1403
|
+
const stateProps = [
|
|
1404
|
+
"columnOrder",
|
|
1405
|
+
"columnVisibility",
|
|
1406
|
+
"columnSort",
|
|
1407
|
+
"columnWidths",
|
|
1408
|
+
"searchQuery",
|
|
1409
|
+
"filters"
|
|
1410
|
+
];
|
|
1411
|
+
const changedStateProp = stateProps.filter(
|
|
1412
|
+
(prop) => changedProperties.has(prop)
|
|
1366
1413
|
);
|
|
1367
|
-
if (
|
|
1368
|
-
this.
|
|
1414
|
+
if (changedStateProp.length) {
|
|
1415
|
+
this.dispatchEvent(
|
|
1416
|
+
new YatlStateChangeEvent(this.getState(), changedStateProp)
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
if (this.storageOptions?.key) {
|
|
1420
|
+
const shouldSave = Array.from(changedProperties.keys()).some(
|
|
1421
|
+
(prop) => SAVE_TRIGGERS.has(prop)
|
|
1422
|
+
);
|
|
1423
|
+
if (shouldSave) {
|
|
1424
|
+
this.scheduleSave();
|
|
1425
|
+
}
|
|
1369
1426
|
}
|
|
1370
1427
|
}
|
|
1371
1428
|
disconnectedCallback() {
|
|
@@ -1554,12 +1611,12 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1554
1611
|
compareRows(a, b, field) {
|
|
1555
1612
|
let aValue, bValue;
|
|
1556
1613
|
const columnData = findColumn(field, this.columnData);
|
|
1557
|
-
if (!columnData.state.
|
|
1614
|
+
if (!columnData.state.sort) {
|
|
1558
1615
|
return 0;
|
|
1559
1616
|
}
|
|
1560
1617
|
const aMetadata = this.rowMetadata.get(a);
|
|
1561
1618
|
const bMetadata = this.rowMetadata.get(b);
|
|
1562
|
-
if (columnData.state.
|
|
1619
|
+
if (columnData.state.sort?.order === "asc") {
|
|
1563
1620
|
aValue = aMetadata.sortValues[columnData.field];
|
|
1564
1621
|
bValue = bMetadata.sortValues[columnData.field];
|
|
1565
1622
|
} else {
|
|
@@ -1583,9 +1640,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1583
1640
|
this.filterRows();
|
|
1584
1641
|
return;
|
|
1585
1642
|
}
|
|
1586
|
-
const sortedColumns = this.columnData.filter((col) => col.state.visible && col.state.
|
|
1587
|
-
(a, b) => b.state.sortState.priority - a.state.sortState.priority
|
|
1588
|
-
);
|
|
1643
|
+
const sortedColumns = this.columnData.filter((col) => col.state.visible && col.state.sort).sort((a, b) => b.state.sort.priority - a.state.sort.priority);
|
|
1589
1644
|
this._filteredData = this._filteredData.toSorted((a, b) => {
|
|
1590
1645
|
const aMetadata = this.rowMetadata.get(a);
|
|
1591
1646
|
const bMetadata = this.rowMetadata.get(b);
|
|
@@ -1606,18 +1661,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1606
1661
|
this.sortDirty = false;
|
|
1607
1662
|
}
|
|
1608
1663
|
// #endregion
|
|
1609
|
-
// #region ---
|
|
1610
|
-
createColumnStates() {
|
|
1611
|
-
this.columnStates = this.columns.map((column) => {
|
|
1612
|
-
const previousState = findColumn(column.field, this._columnStates);
|
|
1613
|
-
return {
|
|
1614
|
-
field: column.field,
|
|
1615
|
-
visible: previousState?.visible ?? true,
|
|
1616
|
-
sortState: previousState?.sortState,
|
|
1617
|
-
width: previousState?.width
|
|
1618
|
-
};
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1664
|
+
// #region --- Utilities ---
|
|
1621
1665
|
createMetadata() {
|
|
1622
1666
|
this.rowMetadata = /* @__PURE__ */ new WeakMap();
|
|
1623
1667
|
let index = 0;
|
|
@@ -1670,20 +1714,19 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1670
1714
|
this.queryTokens.push(...this.searchTokenizer(this.searchQuery));
|
|
1671
1715
|
}
|
|
1672
1716
|
}
|
|
1673
|
-
// #endregion
|
|
1674
|
-
// #region --- Utilities ---
|
|
1675
1717
|
get columnData() {
|
|
1676
1718
|
return this.columns.map((column) => ({
|
|
1677
1719
|
field: column.field,
|
|
1678
1720
|
options: column,
|
|
1679
|
-
state:
|
|
1680
|
-
field: column.field,
|
|
1681
|
-
visible: true
|
|
1682
|
-
}
|
|
1721
|
+
state: this.getColumnState(column.field)
|
|
1683
1722
|
}));
|
|
1684
1723
|
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1724
|
+
/**
|
|
1725
|
+
* Gets the width of each column in the
|
|
1726
|
+
* order they will appear in the grid.
|
|
1727
|
+
*/
|
|
1728
|
+
getGridWidths() {
|
|
1729
|
+
return this.columnOrder.map((field) => this.getColumnState(field)).filter((state2) => state2.visible).map((state2) => state2.width);
|
|
1687
1730
|
}
|
|
1688
1731
|
scheduleSave() {
|
|
1689
1732
|
window.clearTimeout(this.saveTimer);
|
|
@@ -1691,6 +1734,19 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1691
1734
|
this.saveStateToStorage();
|
|
1692
1735
|
}, STATE_SAVE_DEBOUNCE);
|
|
1693
1736
|
}
|
|
1737
|
+
getColumnState(field) {
|
|
1738
|
+
let state2 = findColumn(field, this._columnStates);
|
|
1739
|
+
if (!state2) {
|
|
1740
|
+
state2 = {
|
|
1741
|
+
field,
|
|
1742
|
+
visible: true,
|
|
1743
|
+
sort: null,
|
|
1744
|
+
width: null
|
|
1745
|
+
};
|
|
1746
|
+
this._columnStates.push(state2);
|
|
1747
|
+
}
|
|
1748
|
+
return state2;
|
|
1749
|
+
}
|
|
1694
1750
|
// #endregion
|
|
1695
1751
|
// #region --- Storage Methods ---
|
|
1696
1752
|
saveStateToStorage() {
|
|
@@ -1710,7 +1766,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1710
1766
|
field: columnState.field
|
|
1711
1767
|
};
|
|
1712
1768
|
if (options.saveColumnSortOrders) {
|
|
1713
|
-
savedColumnState.
|
|
1769
|
+
savedColumnState.sort = columnState.sort;
|
|
1714
1770
|
}
|
|
1715
1771
|
if (options.saveColumnVisibility) {
|
|
1716
1772
|
savedColumnState.visible = columnState.visible;
|
|
@@ -1755,7 +1811,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1755
1811
|
columnStateToRestore.width = savedColumnState.width;
|
|
1756
1812
|
}
|
|
1757
1813
|
if (options.saveColumnSortOrders) {
|
|
1758
|
-
columnStateToRestore.
|
|
1814
|
+
columnStateToRestore.sort = savedColumnState.sort;
|
|
1759
1815
|
}
|
|
1760
1816
|
tableStateToRestore.columns.push(columnStateToRestore);
|
|
1761
1817
|
}
|
|
@@ -1774,14 +1830,14 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1774
1830
|
if (!header) {
|
|
1775
1831
|
return;
|
|
1776
1832
|
}
|
|
1777
|
-
const columnIndex = this.
|
|
1833
|
+
const columnIndex = this.columnOrder.findIndex((col) => col === field);
|
|
1778
1834
|
if (columnIndex < 0) {
|
|
1779
1835
|
return;
|
|
1780
1836
|
}
|
|
1781
1837
|
this.tableElement.querySelectorAll(".header .cell").forEach((element) => {
|
|
1782
1838
|
const field2 = element.dataset.field;
|
|
1783
1839
|
if (field2) {
|
|
1784
|
-
const state2 =
|
|
1840
|
+
const state2 = this.getColumnState(field2);
|
|
1785
1841
|
if (state2) {
|
|
1786
1842
|
state2.width = element.getBoundingClientRect().width;
|
|
1787
1843
|
}
|
|
@@ -1793,7 +1849,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1793
1849
|
startWidth: header.getBoundingClientRect().width,
|
|
1794
1850
|
columnIndex,
|
|
1795
1851
|
columnField: field,
|
|
1796
|
-
currentWidths: widthsToGridTemplates(this.
|
|
1852
|
+
currentWidths: widthsToGridTemplates(this.getGridWidths())
|
|
1797
1853
|
};
|
|
1798
1854
|
this.tableElement.style.setProperty(
|
|
1799
1855
|
"--grid-template",
|
|
@@ -1860,7 +1916,16 @@ __decorateClass([
|
|
|
1860
1916
|
], YatlTable.prototype, "columns", 1);
|
|
1861
1917
|
__decorateClass([
|
|
1862
1918
|
(0, import_decorators.property)({ attribute: false })
|
|
1863
|
-
], YatlTable.prototype, "
|
|
1919
|
+
], YatlTable.prototype, "columnOrder", 1);
|
|
1920
|
+
__decorateClass([
|
|
1921
|
+
(0, import_decorators.property)({ attribute: false })
|
|
1922
|
+
], YatlTable.prototype, "columnVisibility", 1);
|
|
1923
|
+
__decorateClass([
|
|
1924
|
+
(0, import_decorators.property)({ attribute: false })
|
|
1925
|
+
], YatlTable.prototype, "columnSort", 1);
|
|
1926
|
+
__decorateClass([
|
|
1927
|
+
(0, import_decorators.property)({ attribute: false })
|
|
1928
|
+
], YatlTable.prototype, "columnWidths", 1);
|
|
1864
1929
|
__decorateClass([
|
|
1865
1930
|
(0, import_decorators.property)({ type: String, attribute: "search-query" })
|
|
1866
1931
|
], YatlTable.prototype, "searchQuery", 1);
|
|
@@ -1895,6 +1960,7 @@ YatlTable = __decorateClass([
|
|
|
1895
1960
|
YatlRowClickEvent,
|
|
1896
1961
|
YatlSearchEvent,
|
|
1897
1962
|
YatlSortEvent,
|
|
1963
|
+
YatlStateChangeEvent,
|
|
1898
1964
|
YatlTable,
|
|
1899
1965
|
createRegexTokenizer,
|
|
1900
1966
|
findColumn,
|