@timlassiter11/yatl 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -48
- package/dist/index.d.mts +84 -29
- package/dist/index.d.ts +84 -29
- package/dist/index.js +77 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -61
- package/dist/index.mjs.map +1 -1
- package/dist/yatl.min.global.js +18 -17
- package/dist/yatl.min.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -228,6 +228,12 @@ function widthsToGridTemplates(widths, defaultWidth = "1fr") {
|
|
|
228
228
|
function isCompareable(value) {
|
|
229
229
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
230
230
|
}
|
|
231
|
+
function isInternalColumn(col) {
|
|
232
|
+
return col.role === "internal";
|
|
233
|
+
}
|
|
234
|
+
function isDisplayColumn(col) {
|
|
235
|
+
return col.role !== "internal";
|
|
236
|
+
}
|
|
231
237
|
|
|
232
238
|
// src/yatl-table.ts
|
|
233
239
|
var import_lit3 = require("lit");
|
|
@@ -404,7 +410,8 @@ var yatl_table_styles_default = import_lit2.css`
|
|
|
404
410
|
:host {
|
|
405
411
|
display: block;
|
|
406
412
|
height: 100%;
|
|
407
|
-
width:
|
|
413
|
+
width: fit-content;
|
|
414
|
+
overflow: auto;
|
|
408
415
|
}
|
|
409
416
|
|
|
410
417
|
.table {
|
|
@@ -575,7 +582,6 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
575
582
|
this._storageOptions = null;
|
|
576
583
|
this._data = [];
|
|
577
584
|
this._searchQuery = "";
|
|
578
|
-
this._searchIncludedFields = [];
|
|
579
585
|
this._searchTokenizer = whitespaceTokenizer;
|
|
580
586
|
this._filters = null;
|
|
581
587
|
this._filteredData = [];
|
|
@@ -598,6 +604,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
598
604
|
this.resizeState = null;
|
|
599
605
|
// Column drag & drop state
|
|
600
606
|
this.dragColumn = null;
|
|
607
|
+
this.sortable = false;
|
|
608
|
+
this.resizable = false;
|
|
601
609
|
this.enableVirtualScroll = false;
|
|
602
610
|
this.enableSearchHighlight = true;
|
|
603
611
|
this.enableColumnReorder = true;
|
|
@@ -610,7 +618,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
610
618
|
// #region --- Event Handlers ---
|
|
611
619
|
this.handleHeaderClicked = (event, column) => {
|
|
612
620
|
const target = event.target;
|
|
613
|
-
|
|
621
|
+
const currentTarget = event.currentTarget;
|
|
622
|
+
if (!currentTarget.classList.contains("sortable") || target.classList.contains("resizer")) {
|
|
614
623
|
return;
|
|
615
624
|
}
|
|
616
625
|
const multiSort = event.shiftKey;
|
|
@@ -757,12 +766,12 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
757
766
|
get columnOrder() {
|
|
758
767
|
const finalOrder = /* @__PURE__ */ new Set();
|
|
759
768
|
for (const field of this._columnOrder) {
|
|
760
|
-
const col = findColumn(field, this.
|
|
769
|
+
const col = findColumn(field, this.getColumns("display"));
|
|
761
770
|
if (col) {
|
|
762
771
|
finalOrder.add(field);
|
|
763
772
|
}
|
|
764
773
|
}
|
|
765
|
-
for (const col of this.
|
|
774
|
+
for (const col of this.getColumns("display")) {
|
|
766
775
|
if (!finalOrder.has(col.field)) {
|
|
767
776
|
finalOrder.add(col.field);
|
|
768
777
|
}
|
|
@@ -787,10 +796,10 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
787
796
|
const oldValue = this.columnVisibility;
|
|
788
797
|
let changed = false;
|
|
789
798
|
for (const column of columns) {
|
|
790
|
-
const
|
|
791
|
-
if (
|
|
799
|
+
const columnState = this.getColumnState(column.field);
|
|
800
|
+
if (columnState && columnState.visible !== column.visible) {
|
|
792
801
|
changed = true;
|
|
793
|
-
|
|
802
|
+
columnState.visible = column.visible;
|
|
794
803
|
}
|
|
795
804
|
}
|
|
796
805
|
if (!changed) {
|
|
@@ -799,19 +808,24 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
799
808
|
this.requestUpdate("columnVisibility", oldValue);
|
|
800
809
|
}
|
|
801
810
|
get columnSort() {
|
|
802
|
-
return this.columnOrder.map((field) =>
|
|
803
|
-
field
|
|
804
|
-
|
|
805
|
-
|
|
811
|
+
return this.columnOrder.map((field) => {
|
|
812
|
+
const sortState = this.getColumnState(field).sort;
|
|
813
|
+
return {
|
|
814
|
+
field,
|
|
815
|
+
// We need to make a copy of sort state so
|
|
816
|
+
// if the user changes it, it doesn't change our copy.
|
|
817
|
+
sort: sortState ? { ...sortState } : null
|
|
818
|
+
};
|
|
819
|
+
});
|
|
806
820
|
}
|
|
807
821
|
set columnSort(columns) {
|
|
808
822
|
const oldValue = this.columnSort;
|
|
809
823
|
let changed = false;
|
|
810
824
|
for (const column of columns) {
|
|
811
|
-
const
|
|
812
|
-
if (
|
|
825
|
+
const columnState = this.getColumnState(column.field);
|
|
826
|
+
if (columnState && (columnState.sort?.order !== column.sort?.order || columnState.sort?.priority !== column.sort?.priority)) {
|
|
813
827
|
changed = true;
|
|
814
|
-
|
|
828
|
+
columnState.sort = column.sort;
|
|
815
829
|
}
|
|
816
830
|
}
|
|
817
831
|
if (!changed) {
|
|
@@ -830,10 +844,10 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
830
844
|
const oldValue = this.columnWidths;
|
|
831
845
|
let changed = false;
|
|
832
846
|
for (const column of columns) {
|
|
833
|
-
const
|
|
834
|
-
if (
|
|
847
|
+
const columnState = this.getColumnState(column.field);
|
|
848
|
+
if (columnState && columnState.width !== column.width) {
|
|
835
849
|
changed = true;
|
|
836
|
-
|
|
850
|
+
columnState.width = column.width;
|
|
837
851
|
}
|
|
838
852
|
}
|
|
839
853
|
if (!changed) {
|
|
@@ -854,18 +868,6 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
854
868
|
this.filterDirty = true;
|
|
855
869
|
this.requestUpdate("searchQuery", oldValue);
|
|
856
870
|
}
|
|
857
|
-
get searchIncludedFields() {
|
|
858
|
-
return this._searchIncludedFields;
|
|
859
|
-
}
|
|
860
|
-
set searchIncludedFields(fields) {
|
|
861
|
-
if (this._searchIncludedFields === fields) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
const oldValue = this._searchIncludedFields;
|
|
865
|
-
this._searchIncludedFields = fields;
|
|
866
|
-
this.filterDirty = true;
|
|
867
|
-
this.requestUpdate("searchIncludedFields", oldValue);
|
|
868
|
-
}
|
|
869
871
|
get searchTokenizer() {
|
|
870
872
|
return this._searchTokenizer;
|
|
871
873
|
}
|
|
@@ -1018,7 +1020,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1018
1020
|
}
|
|
1019
1021
|
}
|
|
1020
1022
|
}
|
|
1021
|
-
this.columnSort = sortStates;
|
|
1023
|
+
this.columnSort = [...sortStates];
|
|
1022
1024
|
}
|
|
1023
1025
|
/**
|
|
1024
1026
|
* Sets the visibility of a specified column.
|
|
@@ -1070,8 +1072,10 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1070
1072
|
export(filename, all = false) {
|
|
1071
1073
|
const data = all ? this.data : this.filteredData;
|
|
1072
1074
|
const rows = [...data.values()];
|
|
1073
|
-
const columnData = this.
|
|
1074
|
-
const csvHeaders = columnData.filter(
|
|
1075
|
+
const columnData = this.getColumnData(this.getColumns("display"));
|
|
1076
|
+
const csvHeaders = columnData.filter(
|
|
1077
|
+
(col) => all || isDisplayColumn(col.options) && col.state?.visible
|
|
1078
|
+
).map((col) => `"${col.options.title}"`).join(",");
|
|
1075
1079
|
const csvRows = rows.map((row) => {
|
|
1076
1080
|
const list = [];
|
|
1077
1081
|
for (const col of columnData) {
|
|
@@ -1213,7 +1217,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1213
1217
|
// #endregion
|
|
1214
1218
|
// #region --- Render Methods ---
|
|
1215
1219
|
renderColumnSortIcon(column, state2) {
|
|
1216
|
-
return column.sortable ? import_lit3.html`<div
|
|
1220
|
+
return column.sortable ?? this.sortable ? import_lit3.html`<div
|
|
1217
1221
|
part="header-sort-icon"
|
|
1218
1222
|
class=${(0, import_class_map.classMap)({
|
|
1219
1223
|
"sort-icon": true,
|
|
@@ -1223,7 +1227,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1223
1227
|
></div>` : import_lit3.nothing;
|
|
1224
1228
|
}
|
|
1225
1229
|
renderColumnResizer(column, _state) {
|
|
1226
|
-
return column.resizable ? import_lit3.html`<div
|
|
1230
|
+
return column.resizable ?? this.resizable ? import_lit3.html`<div
|
|
1227
1231
|
part="header-resizer"
|
|
1228
1232
|
class="resizer"
|
|
1229
1233
|
@click=${(event) => event.stopPropagation()}
|
|
@@ -1231,7 +1235,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1231
1235
|
></div>` : import_lit3.nothing;
|
|
1232
1236
|
}
|
|
1233
1237
|
renderHeaderCell(field) {
|
|
1234
|
-
const column = findColumn(field, this.
|
|
1238
|
+
const column = findColumn(field, this.getColumns("display"));
|
|
1235
1239
|
const state2 = this.getColumnState(column.field);
|
|
1236
1240
|
if (state2.visible == false) {
|
|
1237
1241
|
return import_lit3.nothing;
|
|
@@ -1241,7 +1245,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1241
1245
|
part="cell header-cell"
|
|
1242
1246
|
class=${(0, import_class_map.classMap)({
|
|
1243
1247
|
cell: true,
|
|
1244
|
-
sortable: column.sortable ??
|
|
1248
|
+
sortable: column.sortable ?? this.sortable
|
|
1245
1249
|
})}
|
|
1246
1250
|
draggable=${(0, import_if_defined.ifDefined)(this.enableColumnReorder ? true : void 0)}
|
|
1247
1251
|
data-field=${column.field}
|
|
@@ -1282,7 +1286,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1282
1286
|
return this.enableSearchHighlight && indices ? highlightText(String(value), indices[column.field]) : value;
|
|
1283
1287
|
}
|
|
1284
1288
|
renderCell(field, row) {
|
|
1285
|
-
const column = findColumn(field, this.
|
|
1289
|
+
const column = findColumn(field, this.getColumns("display"));
|
|
1286
1290
|
const state2 = this.getColumnState(column.field);
|
|
1287
1291
|
if (!state2.visible) {
|
|
1288
1292
|
return import_lit3.nothing;
|
|
@@ -1570,8 +1574,8 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1570
1574
|
return true;
|
|
1571
1575
|
}
|
|
1572
1576
|
filterRows() {
|
|
1573
|
-
const
|
|
1574
|
-
const fields =
|
|
1577
|
+
const columnData = this.getColumnData(this.columns);
|
|
1578
|
+
const fields = columnData.filter((col) => col.options.searchable).map((c) => c.field);
|
|
1575
1579
|
this._filteredData = this.data.filter((row, index) => {
|
|
1576
1580
|
const metadata = this.rowMetadata.get(row);
|
|
1577
1581
|
metadata.searchScore = 0;
|
|
@@ -1610,7 +1614,10 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1610
1614
|
// #region --- Sort Methods ---
|
|
1611
1615
|
compareRows(a, b, field) {
|
|
1612
1616
|
let aValue, bValue;
|
|
1613
|
-
const columnData = findColumn(
|
|
1617
|
+
const columnData = findColumn(
|
|
1618
|
+
field,
|
|
1619
|
+
this.getColumnData(this.getColumns("display"))
|
|
1620
|
+
);
|
|
1614
1621
|
if (!columnData.state.sort) {
|
|
1615
1622
|
return 0;
|
|
1616
1623
|
}
|
|
@@ -1640,7 +1647,7 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1640
1647
|
this.filterRows();
|
|
1641
1648
|
return;
|
|
1642
1649
|
}
|
|
1643
|
-
const sortedColumns = this.
|
|
1650
|
+
const sortedColumns = this.getColumnData(this.columns).filter((col) => col.state.visible && col.state.sort).sort((a, b) => b.state.sort.priority - a.state.sort.priority);
|
|
1644
1651
|
this._filteredData = this._filteredData.toSorted((a, b) => {
|
|
1645
1652
|
const aMetadata = this.rowMetadata.get(a);
|
|
1646
1653
|
const bMetadata = this.rowMetadata.get(b);
|
|
@@ -1675,14 +1682,16 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1675
1682
|
this.rowMetadata.set(row, metadata);
|
|
1676
1683
|
for (const column of this.columns) {
|
|
1677
1684
|
const value = getNestedValue(row, column.field);
|
|
1678
|
-
if (
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1685
|
+
if (isDisplayColumn(column)) {
|
|
1686
|
+
if (typeof column.sortValue === "function") {
|
|
1687
|
+
metadata.sortValues[column.field] = column.sortValue(value);
|
|
1688
|
+
} else if (typeof value === "string") {
|
|
1689
|
+
metadata.sortValues[column.field] = value.toLocaleLowerCase();
|
|
1690
|
+
} else if (isCompareable(value)) {
|
|
1691
|
+
metadata.sortValues[column.field] = value;
|
|
1692
|
+
} else {
|
|
1693
|
+
metadata.sortValues[column.field] = String(value);
|
|
1694
|
+
}
|
|
1686
1695
|
}
|
|
1687
1696
|
if (typeof value === "string") {
|
|
1688
1697
|
metadata.searchValues[column.field] = value.toLocaleLowerCase();
|
|
@@ -1694,12 +1703,6 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1694
1703
|
);
|
|
1695
1704
|
}
|
|
1696
1705
|
}
|
|
1697
|
-
for (const field of this.searchIncludedFields) {
|
|
1698
|
-
const value = getNestedValue(row, field);
|
|
1699
|
-
if (typeof value === "string") {
|
|
1700
|
-
metadata.searchValues[field] = value.toLocaleLowerCase();
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
1706
|
}
|
|
1704
1707
|
}
|
|
1705
1708
|
updateInternalQuery() {
|
|
@@ -1714,8 +1717,18 @@ var YatlTable = class extends import_lit3.LitElement {
|
|
|
1714
1717
|
this.queryTokens.push(...this.searchTokenizer(this.searchQuery));
|
|
1715
1718
|
}
|
|
1716
1719
|
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1720
|
+
getColumns(kind = "all") {
|
|
1721
|
+
switch (kind) {
|
|
1722
|
+
case "display":
|
|
1723
|
+
return this.columns.filter(isDisplayColumn);
|
|
1724
|
+
case "internal":
|
|
1725
|
+
return this.columns.filter(isInternalColumn);
|
|
1726
|
+
case "all":
|
|
1727
|
+
return this.columns;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
getColumnData(columns) {
|
|
1731
|
+
return columns.map((column) => ({
|
|
1719
1732
|
field: column.field,
|
|
1720
1733
|
options: column,
|
|
1721
1734
|
state: this.getColumnState(column.field)
|
|
@@ -1884,6 +1897,12 @@ __decorateClass([
|
|
|
1884
1897
|
__decorateClass([
|
|
1885
1898
|
(0, import_decorators.state)()
|
|
1886
1899
|
], YatlTable.prototype, "_filteredData", 2);
|
|
1900
|
+
__decorateClass([
|
|
1901
|
+
(0, import_decorators.property)({ type: Boolean, attribute: "sortable" })
|
|
1902
|
+
], YatlTable.prototype, "sortable", 2);
|
|
1903
|
+
__decorateClass([
|
|
1904
|
+
(0, import_decorators.property)({ type: Boolean, attribute: "resizable" })
|
|
1905
|
+
], YatlTable.prototype, "resizable", 2);
|
|
1887
1906
|
__decorateClass([
|
|
1888
1907
|
(0, import_decorators.property)({ type: Boolean, attribute: "enable-virtual-scroll" })
|
|
1889
1908
|
], YatlTable.prototype, "enableVirtualScroll", 2);
|
|
@@ -1929,9 +1948,6 @@ __decorateClass([
|
|
|
1929
1948
|
__decorateClass([
|
|
1930
1949
|
(0, import_decorators.property)({ type: String, attribute: "search-query" })
|
|
1931
1950
|
], YatlTable.prototype, "searchQuery", 1);
|
|
1932
|
-
__decorateClass([
|
|
1933
|
-
(0, import_decorators.property)({ type: Array, attribute: "search-included-fields" })
|
|
1934
|
-
], YatlTable.prototype, "searchIncludedFields", 1);
|
|
1935
1951
|
__decorateClass([
|
|
1936
1952
|
(0, import_decorators.property)({ attribute: false })
|
|
1937
1953
|
], YatlTable.prototype, "searchTokenizer", 1);
|