@timlassiter11/yatl 1.2.2 → 1.2.4

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 CHANGED
@@ -72,7 +72,7 @@ type ColumnRole = 'display' | 'internal';
72
72
  * @param field - The field of the column.
73
73
  * @param row - The row data.
74
74
  */
75
- type CellPartsCallback<T> = (value: unknown, field: NestedKeyOf<T>, row: T) => string | string[];
75
+ type CellPartsCallback<T> = (value: unknown, field: NestedKeyOf<T>, row: T) => string | string[] | undefined;
76
76
  /**
77
77
  * Callback for providing the full contents of a rendered cell.
78
78
  * @param value - The value of the cell.
@@ -234,7 +234,7 @@ type RowSelectionMethod = 'single' | 'multi';
234
234
  * @param row - The row data.
235
235
  * @returns the part string or list of part strings that should be added to this row.
236
236
  */
237
- type RowPartsCallback<T> = (row: T) => string | string[];
237
+ type RowPartsCallback<T> = (row: T) => string | string[] | undefined;
238
238
  /**
239
239
  * Options used to configure what state information
240
240
  * should be saved and restored automatically.
@@ -756,6 +756,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
756
756
  static styles: lit.CSSResult[];
757
757
  private tableElement;
758
758
  private virtualizer?;
759
+ private get virtualizerRef();
759
760
  private resizeState;
760
761
  private dragColumn;
761
762
  private useYatlUi;
@@ -1044,6 +1045,14 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
1044
1045
  */
1045
1046
  findRowIndex(field: NestedKeyOf<T>, value: unknown): number;
1046
1047
  updateRow(rowId: RowId, data: Partial<T>): void;
1048
+ /**
1049
+ * This will force the underlying virtual scroller
1050
+ * to re-calculate row sizes and positions and re-render.
1051
+ * This is specifically here to fix virtual scroll tables
1052
+ * that are affected by scale animations.
1053
+ * E.g. when put in a yatl-dialog.
1054
+ */
1055
+ reflowVirtualizer(): void;
1047
1056
  /**
1048
1057
  * Updates the data of a row at a specific original index.
1049
1058
  * @param index - The original index of the row to update.
package/dist/index.d.ts CHANGED
@@ -72,7 +72,7 @@ type ColumnRole = 'display' | 'internal';
72
72
  * @param field - The field of the column.
73
73
  * @param row - The row data.
74
74
  */
75
- type CellPartsCallback<T> = (value: unknown, field: NestedKeyOf<T>, row: T) => string | string[];
75
+ type CellPartsCallback<T> = (value: unknown, field: NestedKeyOf<T>, row: T) => string | string[] | undefined;
76
76
  /**
77
77
  * Callback for providing the full contents of a rendered cell.
78
78
  * @param value - The value of the cell.
@@ -234,7 +234,7 @@ type RowSelectionMethod = 'single' | 'multi';
234
234
  * @param row - The row data.
235
235
  * @returns the part string or list of part strings that should be added to this row.
236
236
  */
237
- type RowPartsCallback<T> = (row: T) => string | string[];
237
+ type RowPartsCallback<T> = (row: T) => string | string[] | undefined;
238
238
  /**
239
239
  * Options used to configure what state information
240
240
  * should be saved and restored automatically.
@@ -756,6 +756,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
756
756
  static styles: lit.CSSResult[];
757
757
  private tableElement;
758
758
  private virtualizer?;
759
+ private get virtualizerRef();
759
760
  private resizeState;
760
761
  private dragColumn;
761
762
  private useYatlUi;
@@ -1044,6 +1045,14 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
1044
1045
  */
1045
1046
  findRowIndex(field: NestedKeyOf<T>, value: unknown): number;
1046
1047
  updateRow(rowId: RowId, data: Partial<T>): void;
1048
+ /**
1049
+ * This will force the underlying virtual scroller
1050
+ * to re-calculate row sizes and positions and re-render.
1051
+ * This is specifically here to fix virtual scroll tables
1052
+ * that are affected by scale animations.
1053
+ * E.g. when put in a yatl-dialog.
1054
+ */
1055
+ reflowVirtualizer(): void;
1047
1056
  /**
1048
1057
  * Updates the data of a row at a specific original index.
1049
1058
  * @param index - The original index of the row to update.
package/dist/index.js CHANGED
@@ -407,6 +407,7 @@ var import_if_defined = require("lit/directives/if-defined.js");
407
407
  var import_repeat = require("lit/directives/repeat.js");
408
408
  var import_style_map = require("lit/directives/style-map.js");
409
409
  var import_virtualizer = require("@lit-labs/virtualizer");
410
+ var import_virtualize = require("@lit-labs/virtualizer/virtualize.js");
410
411
 
411
412
  // src/table-controller/utils.ts
412
413
  function getCompareableValue(value) {
@@ -580,6 +581,7 @@ var YatlTableController = class extends TypedEventTarget {
580
581
  for (const column of columns) {
581
582
  this._columnDefinitionMap.set(column.field, column);
582
583
  }
584
+ this.createMetadata();
583
585
  this.requestUpdate("columns");
584
586
  }
585
587
  get displayColumns() {
@@ -1601,10 +1603,7 @@ var table_styles_default = import_lit2.css`
1601
1603
  );
1602
1604
 
1603
1605
  --table-header-text: var(--yatl-table-header-text, var(--yatl-text-1));
1604
- --table-header-bg: var(
1605
- --yatl-table-header-bg,
1606
- color-mix(in srgb, var(--yatl-color-mix) 4%, var(--table-bg))
1607
- );
1606
+ --table-header-bg: var(--yatl-table-header-bg, var(--yatl-surface-lowered));
1608
1607
  --table-header-hover-bg: var(
1609
1608
  --yatl-table-header-hover-bg,
1610
1609
  color-mix(in srgb, var(--yatl-color-mix) 4%, var(--table-header-bg))
@@ -1623,6 +1622,10 @@ var table_styles_default = import_lit2.css`
1623
1622
  --yatl-table-row-hover-bg,
1624
1623
  var(--table-header-bg)
1625
1624
  );
1625
+ --table-row-border-color: var(
1626
+ --yatl-table-row-border-color,
1627
+ var(--yatl-border-color-subtle)
1628
+ );
1626
1629
  --table-row-stripe-bg: var(
1627
1630
  --yatl-table-row-stripe-bg,
1628
1631
  color-mix(in srbg, var(--yatl-color-mix) 3%, var(--table-bg))
@@ -1668,7 +1671,8 @@ var table_styles_default = import_lit2.css`
1668
1671
  .row {
1669
1672
  position: relative;
1670
1673
  background-color: var(--table-row-bg);
1671
- border-bottom: 1px solid var(--table-border-color);
1674
+ /** Use box-shadow to mimic borders. It works better when virtualized */
1675
+ box-shadow: inset 0 -1px 0 0 var(--table-row-border-color);
1672
1676
  transition: background-color 50ms;
1673
1677
  }
1674
1678
 
@@ -1684,7 +1688,7 @@ var table_styles_default = import_lit2.css`
1684
1688
  }
1685
1689
 
1686
1690
  .row:last-child {
1687
- border-bottom: none;
1691
+ box-shadow: none;
1688
1692
  }
1689
1693
 
1690
1694
  .table:not(.resizing) .row {
@@ -1697,10 +1701,18 @@ var table_styles_default = import_lit2.css`
1697
1701
  padding: var(--table-cell-padding);
1698
1702
  }
1699
1703
 
1704
+ .cell.is-number {
1705
+ justify-content: flex-end;
1706
+ }
1707
+
1700
1708
  .table.resizing * {
1701
1709
  cursor: col-resize !important;
1702
1710
  }
1703
1711
 
1712
+ .header {
1713
+ background-color: var(--table-bg);
1714
+ }
1715
+
1704
1716
  .header .cell {
1705
1717
  padding: var(--table-header-padding);
1706
1718
  }
@@ -1730,7 +1742,7 @@ var table_styles_default = import_lit2.css`
1730
1742
  }
1731
1743
 
1732
1744
  @layer striped {
1733
- :host([striped]) .body .row:nth-child(even) {
1745
+ :host([striped]) .row-even {
1734
1746
  background-color: var(--table-row-stripe-bg);
1735
1747
  }
1736
1748
  }
@@ -1968,7 +1980,7 @@ var YatlTable = class extends import_lit3.LitElement {
1968
1980
  // #endregion
1969
1981
  // #region --- Properties ---
1970
1982
  this._controller = new YatlTableController(this);
1971
- this.striped = true;
1983
+ this.striped = false;
1972
1984
  this.sortable = true;
1973
1985
  this.resizable = true;
1974
1986
  this.enableVirtualScroll = false;
@@ -2132,6 +2144,11 @@ var YatlTable = class extends import_lit3.LitElement {
2132
2144
  this.toggleRowSelection(row, selected);
2133
2145
  };
2134
2146
  }
2147
+ get virtualizerRef() {
2148
+ if (this.virtualizer) {
2149
+ return this.virtualizer[import_virtualize.virtualizerRef];
2150
+ }
2151
+ }
2135
2152
  get controller() {
2136
2153
  return this._controller;
2137
2154
  }
@@ -2519,6 +2536,23 @@ var YatlTable = class extends import_lit3.LitElement {
2519
2536
  updateRow(rowId, data) {
2520
2537
  return this.controller.updateRow(rowId, data);
2521
2538
  }
2539
+ /**
2540
+ * This will force the underlying virtual scroller
2541
+ * to re-calculate row sizes and positions and re-render.
2542
+ * This is specifically here to fix virtual scroll tables
2543
+ * that are affected by scale animations.
2544
+ * E.g. when put in a yatl-dialog.
2545
+ */
2546
+ reflowVirtualizer() {
2547
+ const virtualizerRef2 = this.virtualizerRef;
2548
+ if (virtualizerRef2) {
2549
+ virtualizerRef2._itemsChanged = true;
2550
+ virtualizerRef2._rangeChanged = true;
2551
+ virtualizerRef2._measureChildren();
2552
+ virtualizerRef2._itemsChanged = false;
2553
+ virtualizerRef2._rangeChanged = false;
2554
+ }
2555
+ }
2522
2556
  /**
2523
2557
  * Updates the data of a row at a specific original index.
2524
2558
  * @param index - The original index of the row to update.
@@ -2655,6 +2689,11 @@ var YatlTable = class extends import_lit3.LitElement {
2655
2689
  if (Array.isArray(userParts)) {
2656
2690
  userParts = userParts.join(" ");
2657
2691
  }
2692
+ const isNumber = typeof value === "bigint" || typeof value === "number";
2693
+ const classes = {
2694
+ cell: true,
2695
+ "is-number": isNumber
2696
+ };
2658
2697
  if (typeof column.valueFormatter === "function") {
2659
2698
  value = column.valueFormatter(value, row);
2660
2699
  }
@@ -2663,7 +2702,7 @@ var YatlTable = class extends import_lit3.LitElement {
2663
2702
  role="cell"
2664
2703
  part="cell body-cell cell-${column.field} ${userParts}"
2665
2704
  data-field=${column.field}
2666
- class="cell"
2705
+ class=${(0, import_class_map.classMap)(classes)}
2667
2706
  title=${(0, import_if_defined.ifDefined)(value ? String(value) : void 0)}
2668
2707
  @click=${(event) => this.handleCellClick(event, row, column.field)}
2669
2708
  >
@@ -2709,7 +2748,12 @@ var YatlTable = class extends import_lit3.LitElement {
2709
2748
  if (Array.isArray(userParts)) {
2710
2749
  userParts = userParts.join(" ");
2711
2750
  }
2712
- const classes = { row: true, selected };
2751
+ const classes = {
2752
+ row: true,
2753
+ selected,
2754
+ "row-even": renderIndex % 2 === 0,
2755
+ "row-odd": renderIndex % 2 !== 0
2756
+ };
2713
2757
  const rowIndex = renderIndex + 1;
2714
2758
  return import_lit3.html`
2715
2759
  <div
@@ -2954,7 +2998,7 @@ __decorateClass([
2954
2998
  (0, import_decorators.property)({ type: Boolean, attribute: "enable-column-reorder" })
2955
2999
  ], YatlTable.prototype, "enableColumnReorder", 2);
2956
3000
  __decorateClass([
2957
- (0, import_decorators.property)({ type: Boolean })
3001
+ (0, import_decorators.property)({ type: Boolean, attribute: "enable-row-number-column" })
2958
3002
  ], YatlTable.prototype, "enableRowNumberColumn", 2);
2959
3003
  __decorateClass([
2960
3004
  (0, import_decorators.property)({ type: Boolean, attribute: "enable-footer" })