@kodaris/krubble-components 1.0.55 → 1.0.56

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.
@@ -4059,6 +4059,7 @@ let KRTable = class KRTable extends i$2 {
4059
4059
  this._filterPanelTab = 'filter';
4060
4060
  this._buckets = new Map();
4061
4061
  this._filterPanelPos = { top: 0, left: 0 };
4062
+ this._sorts = [];
4062
4063
  this._resizing = null;
4063
4064
  this._resizeObserver = null;
4064
4065
  this._searchPositionLocked = false;
@@ -4248,7 +4249,7 @@ let KRTable = class KRTable extends i$2 {
4248
4249
  const request = {
4249
4250
  page: this._page - 1,
4250
4251
  size: this._pageSize,
4251
- sorts: [],
4252
+ sorts: this._sorts,
4252
4253
  filterFields: [],
4253
4254
  queryFields: [],
4254
4255
  facetFields: []
@@ -4288,7 +4289,7 @@ let KRTable = class KRTable extends i$2 {
4288
4289
  const request = {
4289
4290
  page: this._page - 1,
4290
4291
  size: this._pageSize,
4291
- sorts: [],
4292
+ sorts: this._sorts,
4292
4293
  filterFields: [],
4293
4294
  queryFields: [],
4294
4295
  facetFields: []
@@ -4587,6 +4588,77 @@ let KRTable = class KRTable extends i$2 {
4587
4588
  document.addEventListener('mouseup', this._handleResizeEnd);
4588
4589
  }
4589
4590
  // ----------------------------------------------------------------------------
4591
+ // Sorting
4592
+ // ----------------------------------------------------------------------------
4593
+ _handleSortClick(e, column) {
4594
+ if (e.shiftKey) {
4595
+ // Multi-sort: add or cycle existing
4596
+ const existingIndex = this._sorts.findIndex(s => s.sortBy === column.id);
4597
+ if (existingIndex === -1) {
4598
+ this._sorts.push({ sortBy: column.id, sortDirection: 'asc' });
4599
+ }
4600
+ else {
4601
+ const existing = this._sorts[existingIndex];
4602
+ if (existing.sortDirection === 'asc') {
4603
+ existing.sortDirection = 'desc';
4604
+ }
4605
+ else {
4606
+ // on third click, remove sorting for the column
4607
+ this._sorts.splice(existingIndex, 1);
4608
+ }
4609
+ }
4610
+ this.requestUpdate();
4611
+ }
4612
+ else {
4613
+ // Single sort: replace all
4614
+ let existing = null;
4615
+ if (this._sorts.length === 1) {
4616
+ existing = this._sorts.find(s => s.sortBy === column.id);
4617
+ }
4618
+ if (!existing) {
4619
+ this._sorts = [{ sortBy: column.id, sortDirection: 'asc' }];
4620
+ }
4621
+ else if (existing.sortDirection === 'asc') {
4622
+ this._sorts = [{ sortBy: column.id, sortDirection: 'desc' }];
4623
+ }
4624
+ else {
4625
+ this._sorts = [];
4626
+ }
4627
+ }
4628
+ this._page = 1;
4629
+ this._fetch();
4630
+ }
4631
+ _renderSortIndicator(column) {
4632
+ if (!column.sortable) {
4633
+ return A;
4634
+ }
4635
+ const sortIndex = this._sorts.findIndex(s => s.sortBy === column.id);
4636
+ if (sortIndex === -1) {
4637
+ // Ghost arrow: visible only on hover via CSS
4638
+ return b `
4639
+ <span class="header-cell__sort" @click=${(e) => this._handleSortClick(e, column)}>
4640
+ <svg class="header-cell__sort-arrow header-cell__sort-arrow--ghost" viewBox="0 0 24 24" fill="currentColor">
4641
+ <path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/>
4642
+ </svg>
4643
+ </span>
4644
+ `;
4645
+ }
4646
+ let arrowStyle = {};
4647
+ if (this._sorts[sortIndex].sortDirection === 'desc') {
4648
+ arrowStyle = { transform: 'rotate(180deg)' };
4649
+ }
4650
+ return b `
4651
+ <span class="header-cell__sort" @click=${(e) => this._handleSortClick(e, column)}>
4652
+ <svg class="header-cell__sort-arrow" viewBox="0 0 24 24" fill="currentColor" style=${o$1(arrowStyle)}>
4653
+ <path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/>
4654
+ </svg>
4655
+ ${this._sorts.length > 1 ? b `
4656
+ <span class="header-cell__sort-priority">${sortIndex + 1}</span>
4657
+ ` : A}
4658
+ </span>
4659
+ `;
4660
+ }
4661
+ // ----------------------------------------------------------------------------
4590
4662
  // Header
4591
4663
  // ----------------------------------------------------------------------------
4592
4664
  _handleAction(action) {
@@ -4780,6 +4852,7 @@ let KRTable = class KRTable extends i$2 {
4780
4852
  _getHeaderCellClasses(column, index) {
4781
4853
  return {
4782
4854
  'header-cell': true,
4855
+ 'header-cell--sortable': !!column.sortable,
4783
4856
  'header-cell--align-center': column.align === 'center',
4784
4857
  'header-cell--align-right': column.align === 'right',
4785
4858
  'header-cell--sticky-left': column.sticky === 'left',
@@ -5267,10 +5340,14 @@ let KRTable = class KRTable extends i$2 {
5267
5340
  class=${e$1(this._getHeaderCellClasses(col, i))}
5268
5341
  style=${o$1(this._getCellStyle(col, i))}
5269
5342
  data-column-id=${col.id}
5270
- >${col.label ?? col.id}${col.resizable !== false ? b `<div
5343
+ >
5344
+ <span class="header-cell__label">${col.label ?? col.id}</span>
5345
+ ${this._renderSortIndicator(col)}
5346
+ ${col.resizable !== false ? b `<div
5271
5347
  class="header-cell__resize"
5272
5348
  @mousedown=${(e) => this._handleResizeStart(e, col.id)}
5273
- ></div>` : A}</div>
5349
+ ></div>` : A}
5350
+ </div>
5274
5351
  `)}
5275
5352
  </div>
5276
5353
  ${this._renderFilterRow()}
@@ -5679,9 +5756,7 @@ KRTable.styles = [krBaseCSS, i$5 `
5679
5756
  .header-cell {
5680
5757
  position: sticky;
5681
5758
  top: 0;
5682
- z-index: 2;
5683
5759
  height: 48px;
5684
- line-height: 48px;
5685
5760
  padding: 0 16px;
5686
5761
  white-space: nowrap;
5687
5762
  box-sizing: border-box;
@@ -5691,8 +5766,8 @@ KRTable.styles = [krBaseCSS, i$5 `
5691
5766
  border-right: 1px solid #e5e7ebba;
5692
5767
  font-weight: 600;
5693
5768
  color: #374151;
5694
- overflow: hidden;
5695
- text-overflow: ellipsis;
5769
+ display: flex;
5770
+ align-items: center;
5696
5771
  }
5697
5772
 
5698
5773
  .header-cell__resize {
@@ -5702,21 +5777,52 @@ KRTable.styles = [krBaseCSS, i$5 `
5702
5777
  bottom: 0;
5703
5778
  width: 14px;
5704
5779
  cursor: col-resize;
5780
+ z-index: 10;
5781
+ }
5782
+
5783
+ .header-cell--sortable {
5784
+ user-select: none;
5785
+ }
5786
+
5787
+ .header-cell__label {
5788
+ overflow: hidden;
5789
+ text-overflow: ellipsis;
5790
+ min-width: 0;
5791
+ line-height: 48px;
5792
+ }
5793
+
5794
+ .header-cell__sort {
5795
+ flex-grow: 1;
5705
5796
  display: flex;
5706
5797
  align-items: center;
5707
- justify-content: center;
5708
- z-index: 10;
5798
+ height: 100%;
5799
+ margin-left: 6px;
5800
+ cursor: pointer;
5709
5801
  }
5710
5802
 
5711
- .header-cell__resize::after {
5712
- content: '';
5713
- width: 2px;
5714
- height: 20px;
5715
- background: #c6c6cd;
5803
+ .header-cell__sort-arrow {
5804
+ width: 16px;
5805
+ height: 16px;
5806
+ color: #374151;
5807
+ stroke: currentColor;
5808
+ stroke-width: 1px;
5716
5809
  }
5717
5810
 
5718
- .header-cell:last-child .header-cell__resize::after {
5719
- display: none;
5811
+ .header-cell__sort-arrow--ghost {
5812
+ opacity: 0;
5813
+ color: #374151;
5814
+ transition: opacity 0.15s;
5815
+ }
5816
+
5817
+ .header-cell--sortable:hover .header-cell__sort-arrow--ghost {
5818
+ opacity: 0.4;
5819
+ }
5820
+
5821
+ .header-cell__sort-priority {
5822
+ font-size: 10px;
5823
+ font-weight: 600;
5824
+ color: #374151;
5825
+ line-height: 1;
5720
5826
  }
5721
5827
 
5722
5828
  .cell {
@@ -6182,6 +6288,9 @@ __decorate$9([
6182
6288
  __decorate$9([
6183
6289
  r$1()
6184
6290
  ], KRTable.prototype, "_buckets", void 0);
6291
+ __decorate$9([
6292
+ r$1()
6293
+ ], KRTable.prototype, "_sorts", void 0);
6185
6294
  __decorate$9([
6186
6295
  n$1({ type: Object })
6187
6296
  ], KRTable.prototype, "def", void 0);