@timlassiter11/yatl 1.0.5 → 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/README.md +1 -1
- package/dist/index.d.mts +21 -28
- package/dist/index.d.ts +21 -28
- package/dist/index.js +80 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -62
- package/dist/index.mjs.map +1 -1
- package/dist/yatl.min.global.js +20 -19
- package/dist/yatl.min.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -149,9 +149,6 @@ function getNestedValue(obj, path) {
|
|
|
149
149
|
}
|
|
150
150
|
return current;
|
|
151
151
|
}
|
|
152
|
-
function findColumn(field, columns) {
|
|
153
|
-
return columns.find((c) => c.field === field);
|
|
154
|
-
}
|
|
155
152
|
function highlightText(text, ranges) {
|
|
156
153
|
if (!text || !ranges || ranges.length === 0) {
|
|
157
154
|
return text;
|
|
@@ -193,6 +190,9 @@ function widthsToGridTemplates(widths, defaultWidth = "1fr") {
|
|
|
193
190
|
function isCompareable(value) {
|
|
194
191
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
195
192
|
}
|
|
193
|
+
function isInternalColumn(col) {
|
|
194
|
+
return col?.role === "internal";
|
|
195
|
+
}
|
|
196
196
|
function isDisplayColumn(col) {
|
|
197
197
|
return col?.role !== "internal";
|
|
198
198
|
}
|
|
@@ -623,10 +623,11 @@ var YatlTable = class extends LitElement {
|
|
|
623
623
|
this.resizeState.currentWidths[this.resizeState.columnIndex]
|
|
624
624
|
);
|
|
625
625
|
const columnWidths = this.columnWidths;
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
this.
|
|
629
|
-
|
|
626
|
+
columnWidths[this.resizeState.columnField] = finalWidth;
|
|
627
|
+
this.columnWidths = { ...columnWidths };
|
|
628
|
+
this.dispatchEvent(
|
|
629
|
+
new YatlColumnResizeEvent(this.resizeState.columnField, finalWidth)
|
|
630
|
+
);
|
|
630
631
|
}
|
|
631
632
|
setTimeout(() => {
|
|
632
633
|
this.resizeState = null;
|
|
@@ -733,8 +734,12 @@ var YatlTable = class extends LitElement {
|
|
|
733
734
|
}
|
|
734
735
|
this.requestUpdate("columns", oldValue);
|
|
735
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* Gets a list of columns with the display role
|
|
739
|
+
* **This will always be ordered by {@link YatlTable.columnOrder}**
|
|
740
|
+
*/
|
|
736
741
|
get displayColumns() {
|
|
737
|
-
return this.
|
|
742
|
+
return this.columnOrder.map((field) => this._columnDefinitionMap.get(field)).filter(isDisplayColumn);
|
|
738
743
|
}
|
|
739
744
|
get columnOrder() {
|
|
740
745
|
const finalOrder = /* @__PURE__ */ new Set();
|
|
@@ -744,8 +749,8 @@ var YatlTable = class extends LitElement {
|
|
|
744
749
|
finalOrder.add(field);
|
|
745
750
|
}
|
|
746
751
|
}
|
|
747
|
-
for (const col of this.
|
|
748
|
-
if (!finalOrder.has(col.field)) {
|
|
752
|
+
for (const col of this.columns) {
|
|
753
|
+
if (isDisplayColumn(col) && !finalOrder.has(col.field)) {
|
|
749
754
|
finalOrder.add(col.field);
|
|
750
755
|
}
|
|
751
756
|
}
|
|
@@ -760,19 +765,21 @@ var YatlTable = class extends LitElement {
|
|
|
760
765
|
this.requestUpdate("columnOrder", oldValue);
|
|
761
766
|
}
|
|
762
767
|
get columnVisibility() {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
768
|
+
const data = {};
|
|
769
|
+
for (const field of this.columnOrder) {
|
|
770
|
+
data[field] = this.getOrCreateColumnState(field).visible;
|
|
771
|
+
}
|
|
772
|
+
return data;
|
|
767
773
|
}
|
|
768
774
|
set columnVisibility(columns) {
|
|
769
775
|
const oldValue = this.columnVisibility;
|
|
770
776
|
let changed = false;
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
const entries = Object.entries(columns);
|
|
778
|
+
for (const [field, visible] of entries) {
|
|
779
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
780
|
+
if (columnState.visible !== visible) {
|
|
774
781
|
changed = true;
|
|
775
|
-
columnState.visible =
|
|
782
|
+
columnState.visible = visible;
|
|
776
783
|
}
|
|
777
784
|
}
|
|
778
785
|
if (!changed) {
|
|
@@ -781,24 +788,22 @@ var YatlTable = class extends LitElement {
|
|
|
781
788
|
this.requestUpdate("columnVisibility", oldValue);
|
|
782
789
|
}
|
|
783
790
|
get columnSort() {
|
|
784
|
-
|
|
791
|
+
const data = {};
|
|
792
|
+
for (const field of this.columnOrder) {
|
|
785
793
|
const sortState = this.getOrCreateColumnState(field).sort;
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
// if the user changes it, it doesn't change our copy.
|
|
790
|
-
sort: sortState ? { ...sortState } : null
|
|
791
|
-
};
|
|
792
|
-
});
|
|
794
|
+
data[field] = sortState ? { ...sortState } : null;
|
|
795
|
+
}
|
|
796
|
+
return data;
|
|
793
797
|
}
|
|
794
798
|
set columnSort(columns) {
|
|
795
799
|
const oldValue = this.columnSort;
|
|
796
800
|
let changed = false;
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
801
|
+
const entries = Object.entries(columns);
|
|
802
|
+
for (const [field, state2] of entries) {
|
|
803
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
804
|
+
if (columnState && (columnState.sort?.order !== state2?.order || columnState.sort?.priority !== state2?.priority)) {
|
|
800
805
|
changed = true;
|
|
801
|
-
columnState.sort =
|
|
806
|
+
columnState.sort = state2;
|
|
802
807
|
}
|
|
803
808
|
}
|
|
804
809
|
if (!changed) {
|
|
@@ -808,19 +813,21 @@ var YatlTable = class extends LitElement {
|
|
|
808
813
|
this.requestUpdate("columnSort", oldValue);
|
|
809
814
|
}
|
|
810
815
|
get columnWidths() {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
816
|
+
const data = {};
|
|
817
|
+
for (const field of this.columnOrder) {
|
|
818
|
+
data[field] = this.getOrCreateColumnState(field).width;
|
|
819
|
+
}
|
|
820
|
+
return data;
|
|
815
821
|
}
|
|
816
822
|
set columnWidths(columns) {
|
|
817
823
|
const oldValue = this.columnWidths;
|
|
818
824
|
let changed = false;
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
825
|
+
const entries = Object.entries(columns);
|
|
826
|
+
for (const [field, width] of entries) {
|
|
827
|
+
const columnState = this.getOrCreateColumnState(field);
|
|
828
|
+
if (columnState.width !== width) {
|
|
822
829
|
changed = true;
|
|
823
|
-
columnState.width =
|
|
830
|
+
columnState.width = width;
|
|
824
831
|
}
|
|
825
832
|
}
|
|
826
833
|
if (!changed) {
|
|
@@ -972,34 +979,35 @@ var YatlTable = class extends LitElement {
|
|
|
972
979
|
*/
|
|
973
980
|
sort(field, order, clear = true) {
|
|
974
981
|
const sortStates = this.columnSort;
|
|
975
|
-
|
|
976
|
-
if (
|
|
982
|
+
let state2 = sortStates[field];
|
|
983
|
+
if (state2 === void 0) {
|
|
977
984
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
978
985
|
}
|
|
979
|
-
if (order === state2
|
|
986
|
+
if (order === state2?.order) {
|
|
980
987
|
return;
|
|
981
988
|
}
|
|
982
989
|
if (!this.dispatchEvent(new YatlSortEvent(field, order))) {
|
|
983
990
|
return;
|
|
984
991
|
}
|
|
985
|
-
if (order && !state2
|
|
986
|
-
const priorities =
|
|
992
|
+
if (order && !state2) {
|
|
993
|
+
const priorities = [...this._columnStateMap.values()].map((state3) => state3.sort?.priority).filter((priority2) => priority2 !== void 0);
|
|
987
994
|
const maxPriority = this.columns.length + 1;
|
|
988
995
|
const priority = Math.min(maxPriority, ...priorities) - 1;
|
|
989
|
-
state2
|
|
990
|
-
} else if (order && state2
|
|
991
|
-
state2.
|
|
996
|
+
state2 = { order, priority };
|
|
997
|
+
} else if (order && state2) {
|
|
998
|
+
state2.order = order;
|
|
992
999
|
} else {
|
|
993
|
-
state2
|
|
1000
|
+
state2 = null;
|
|
994
1001
|
}
|
|
1002
|
+
sortStates[field] = state2;
|
|
995
1003
|
if (clear) {
|
|
996
|
-
for (const
|
|
997
|
-
if (
|
|
998
|
-
|
|
1004
|
+
for (const otherField of this.columnOrder) {
|
|
1005
|
+
if (otherField !== field) {
|
|
1006
|
+
sortStates[otherField] = null;
|
|
999
1007
|
}
|
|
1000
1008
|
}
|
|
1001
1009
|
}
|
|
1002
|
-
this.columnSort =
|
|
1010
|
+
this.columnSort = { ...sortStates };
|
|
1003
1011
|
}
|
|
1004
1012
|
/**
|
|
1005
1013
|
* Sets the visibility of a specified column.
|
|
@@ -1008,18 +1016,18 @@ var YatlTable = class extends LitElement {
|
|
|
1008
1016
|
*/
|
|
1009
1017
|
setColumnVisibility(field, visible) {
|
|
1010
1018
|
const visibilityStates = this.columnVisibility;
|
|
1011
|
-
const
|
|
1012
|
-
if (
|
|
1019
|
+
const currentVisibility = visibilityStates[field];
|
|
1020
|
+
if (currentVisibility === void 0) {
|
|
1013
1021
|
throw new Error(`Cannot get options for non-existent column "${field}"`);
|
|
1014
1022
|
}
|
|
1015
|
-
if (
|
|
1023
|
+
if (currentVisibility === visible) {
|
|
1016
1024
|
return;
|
|
1017
1025
|
}
|
|
1018
1026
|
if (!this.dispatchEvent(new YatlColumnToggleEvent(field, visible))) {
|
|
1019
1027
|
return;
|
|
1020
1028
|
}
|
|
1021
|
-
|
|
1022
|
-
this.columnVisibility =
|
|
1029
|
+
visibilityStates[field] = visible;
|
|
1030
|
+
this.columnVisibility = { ...visibilityStates };
|
|
1023
1031
|
}
|
|
1024
1032
|
/**
|
|
1025
1033
|
* Toggles the visibility of hte specified column
|
|
@@ -1051,7 +1059,9 @@ var YatlTable = class extends LitElement {
|
|
|
1051
1059
|
export(filename, all = false) {
|
|
1052
1060
|
const data = all ? this.data : this.filteredData;
|
|
1053
1061
|
const columnData = this.displayColumns;
|
|
1054
|
-
const csvHeaders = columnData.filter(
|
|
1062
|
+
const csvHeaders = columnData.filter(
|
|
1063
|
+
(column) => all || this.getOrCreateColumnState(column.field).visible
|
|
1064
|
+
).map((column) => `"${column.title}"`).join(",");
|
|
1055
1065
|
const csvRows = data.map((row) => {
|
|
1056
1066
|
const list = [];
|
|
1057
1067
|
for (const column of columnData) {
|
|
@@ -1250,9 +1260,9 @@ var YatlTable = class extends LitElement {
|
|
|
1250
1260
|
}
|
|
1251
1261
|
renderHeader() {
|
|
1252
1262
|
const classes = {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1263
|
+
header: true,
|
|
1264
|
+
row: true,
|
|
1265
|
+
reorderable: this.enableColumnReorder
|
|
1256
1266
|
};
|
|
1257
1267
|
return html2`
|
|
1258
1268
|
<div part="header" class=${classMap(classes)}>
|
|
@@ -1319,7 +1329,7 @@ var YatlTable = class extends LitElement {
|
|
|
1319
1329
|
`;
|
|
1320
1330
|
}
|
|
1321
1331
|
renderBody() {
|
|
1322
|
-
if (this.
|
|
1332
|
+
if (!this.hasVisibleColumn()) {
|
|
1323
1333
|
return html2`
|
|
1324
1334
|
<div part="message" class="message">No visible columns.</div>
|
|
1325
1335
|
`;
|
|
@@ -1383,7 +1393,8 @@ var YatlTable = class extends LitElement {
|
|
|
1383
1393
|
class="table"
|
|
1384
1394
|
style=${styleMap({ "--grid-template": gridTemplate })}
|
|
1385
1395
|
>
|
|
1386
|
-
${this.renderHeader()}
|
|
1396
|
+
${this.renderHeader()}
|
|
1397
|
+
<slot> ${this.renderBody()} ${this.renderFooter()} </slot>
|
|
1387
1398
|
</div>
|
|
1388
1399
|
`;
|
|
1389
1400
|
}
|
|
@@ -1696,6 +1707,9 @@ var YatlTable = class extends LitElement {
|
|
|
1696
1707
|
this.queryTokens.push(...this.searchTokenizer(this.searchQuery));
|
|
1697
1708
|
}
|
|
1698
1709
|
}
|
|
1710
|
+
hasVisibleColumn() {
|
|
1711
|
+
return this.columnOrder.map((field) => this.getOrCreateColumnState(field)).filter((state2) => state2.visible).length > 0;
|
|
1712
|
+
}
|
|
1699
1713
|
/**
|
|
1700
1714
|
* Gets the width of each column in the
|
|
1701
1715
|
* order they will appear in the grid.
|
|
@@ -1944,6 +1958,8 @@ export {
|
|
|
1944
1958
|
YatlStateChangeEvent,
|
|
1945
1959
|
YatlTable,
|
|
1946
1960
|
createRegexTokenizer,
|
|
1961
|
+
isDisplayColumn,
|
|
1962
|
+
isInternalColumn,
|
|
1947
1963
|
whitespaceTokenizer
|
|
1948
1964
|
};
|
|
1949
1965
|
//# sourceMappingURL=index.mjs.map
|