@mintplayer/web-components 1.1.0 → 1.2.0
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/chunks/mp-datatable-Con0yQue.mjs +1125 -0
- package/datatable/index.mjs +1 -1
- package/datatable/src/components/mp-datatable.d.ts +105 -1
- package/datatable/src/index.d.ts +1 -1
- package/datatable/src/types/column-def.d.ts +12 -1
- package/datatable/src/types/index.d.ts +2 -1
- package/datatable/src/types/tree.d.ts +42 -0
- package/file-manager/index.mjs +1 -1
- package/package.json +1 -1
- package/chunks/mp-datatable-CpAu8JJD.mjs +0 -750
|
@@ -1,750 +0,0 @@
|
|
|
1
|
-
import { unsafeCSS as m, LitElement as b, nothing as h, html as d } from "lit";
|
|
2
|
-
import { repeat as f } from "lit/directives/repeat.js";
|
|
3
|
-
import { styleMap as u } from "lit/directives/style-map.js";
|
|
4
|
-
import "./mp-pagination-BGxsawFL.mjs";
|
|
5
|
-
import "./mp-checkbox-BokLL7BS.mjs";
|
|
6
|
-
const _ = m(`@charset "UTF-8";
|
|
7
|
-
:host {
|
|
8
|
-
display: block;
|
|
9
|
-
width: 100%;
|
|
10
|
-
position: relative;
|
|
11
|
-
--mp-datatable-border-color: var(--bs-border-color, rgba(0, 0, 0, 0.125));
|
|
12
|
-
--mp-datatable-row-hover-bg: var(--bs-table-hover-bg, rgba(0, 0, 0, 0.04));
|
|
13
|
-
--mp-datatable-row-selected-bg: var(--bs-list-group-active-bg, var(--bs-primary, #0d6efd));
|
|
14
|
-
--mp-datatable-row-selected-color: var(--bs-list-group-active-color, #fff);
|
|
15
|
-
--mp-datatable-cut-opacity: 0.55;
|
|
16
|
-
--mp-datatable-resize-handle-color: var(--bs-primary, #0d6efd);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
* {
|
|
20
|
-
box-sizing: border-box;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.datatable-shell {
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
width: 100%;
|
|
27
|
-
height: 100%;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.datatable-scroll {
|
|
31
|
-
overflow: auto;
|
|
32
|
-
flex: 1 1 auto;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.datatable-scroll.datatable-virtual {
|
|
36
|
-
max-height: var(--mp-datatable-virtual-max-height, 480px);
|
|
37
|
-
}
|
|
38
|
-
.datatable-scroll.datatable-virtual thead th {
|
|
39
|
-
position: sticky;
|
|
40
|
-
top: 0;
|
|
41
|
-
z-index: 1;
|
|
42
|
-
background-color: var(--bs-body-bg, #fff);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
tr.virtual-spacer {
|
|
46
|
-
pointer-events: none;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
tr.virtual-spacer > td {
|
|
50
|
-
border-bottom: 0;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
table {
|
|
54
|
-
width: 100%;
|
|
55
|
-
border-collapse: collapse;
|
|
56
|
-
margin: 0;
|
|
57
|
-
table-layout: auto;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
thead th {
|
|
61
|
-
background-color: var(--bs-table-bg, transparent);
|
|
62
|
-
border-bottom: 1px solid var(--mp-datatable-border-color);
|
|
63
|
-
text-align: left;
|
|
64
|
-
font-weight: 600;
|
|
65
|
-
padding: 0.5rem 0.75rem;
|
|
66
|
-
white-space: nowrap;
|
|
67
|
-
position: relative;
|
|
68
|
-
user-select: none;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
thead th[data-sortable=true] {
|
|
72
|
-
cursor: pointer;
|
|
73
|
-
padding-right: 2rem;
|
|
74
|
-
}
|
|
75
|
-
thead th[data-sortable=true]::before, thead th[data-sortable=true]::after {
|
|
76
|
-
position: absolute;
|
|
77
|
-
display: block;
|
|
78
|
-
opacity: 0.3;
|
|
79
|
-
bottom: 0.5em;
|
|
80
|
-
}
|
|
81
|
-
thead th[data-sortable=true]::before {
|
|
82
|
-
content: "↑";
|
|
83
|
-
right: 1em;
|
|
84
|
-
}
|
|
85
|
-
thead th[data-sortable=true]::after {
|
|
86
|
-
content: "↓";
|
|
87
|
-
right: 0.5em;
|
|
88
|
-
}
|
|
89
|
-
thead th[data-sortable=true][aria-sort=ascending]::after {
|
|
90
|
-
opacity: 1;
|
|
91
|
-
}
|
|
92
|
-
thead th[data-sortable=true][aria-sort=descending]::before {
|
|
93
|
-
opacity: 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
thead th[data-sortable=true]:hover {
|
|
97
|
-
background-color: var(--mp-datatable-row-hover-bg);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.header-cell {
|
|
101
|
-
display: inline-flex;
|
|
102
|
-
align-items: center;
|
|
103
|
-
gap: 0.4rem;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.sort-index {
|
|
107
|
-
position: absolute;
|
|
108
|
-
right: 0.1em;
|
|
109
|
-
bottom: 0.3em;
|
|
110
|
-
font-size: 0.65em;
|
|
111
|
-
font-weight: bold;
|
|
112
|
-
opacity: 0.7;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.resize-handle {
|
|
116
|
-
position: absolute;
|
|
117
|
-
right: 0;
|
|
118
|
-
top: 0;
|
|
119
|
-
width: 6px;
|
|
120
|
-
height: 100%;
|
|
121
|
-
cursor: col-resize;
|
|
122
|
-
user-select: none;
|
|
123
|
-
z-index: 2;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.resize-handle:hover,
|
|
127
|
-
.resize-handle.active {
|
|
128
|
-
background-color: var(--mp-datatable-resize-handle-color);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
tbody td {
|
|
132
|
-
padding: 0.5rem 0.75rem;
|
|
133
|
-
border-bottom: 1px solid var(--mp-datatable-border-color);
|
|
134
|
-
vertical-align: middle;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
tbody tr {
|
|
138
|
-
cursor: default;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
tbody tr[data-clickable=true] {
|
|
142
|
-
cursor: pointer;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
tbody tr:hover {
|
|
146
|
-
background-color: var(--mp-datatable-row-hover-bg);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
tbody tr[data-selected=true] {
|
|
150
|
-
background-color: var(--mp-datatable-row-selected-bg);
|
|
151
|
-
color: var(--mp-datatable-row-selected-color);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
tbody tr[data-cut=true] {
|
|
155
|
-
opacity: var(--mp-datatable-cut-opacity);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
tbody tr[data-focused=true] {
|
|
159
|
-
outline: 2px solid var(--bs-primary, #0d6efd);
|
|
160
|
-
outline-offset: -2px;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
.checkbox-cell {
|
|
164
|
-
width: 2.5rem;
|
|
165
|
-
text-align: center;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
.empty-state,
|
|
169
|
-
.loading-state {
|
|
170
|
-
padding: 2rem 1rem;
|
|
171
|
-
text-align: center;
|
|
172
|
-
color: var(--bs-secondary-color, #6c757d);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.datatable-footer {
|
|
176
|
-
display: flex;
|
|
177
|
-
align-items: center;
|
|
178
|
-
justify-content: space-between;
|
|
179
|
-
padding: 0.5rem 0;
|
|
180
|
-
gap: 1rem;
|
|
181
|
-
flex-wrap: wrap;
|
|
182
|
-
flex: 0 0 auto;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
.datatable-per-page,
|
|
186
|
-
.datatable-pagination {
|
|
187
|
-
flex: 0 1 auto;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@media (prefers-reduced-motion: reduce) {
|
|
191
|
-
.resize-handle {
|
|
192
|
-
transition: none !important;
|
|
193
|
-
}
|
|
194
|
-
}`);
|
|
195
|
-
function v(a, e, t) {
|
|
196
|
-
if (t) {
|
|
197
|
-
const i = a.findIndex((r) => r.property === e);
|
|
198
|
-
return i === -1 ? [...a, { property: e, direction: "ascending" }] : a[i].direction === "ascending" ? a.map(
|
|
199
|
-
(r, o) => o === i ? { ...r, direction: "descending" } : r
|
|
200
|
-
) : a.filter((r, o) => o !== i);
|
|
201
|
-
}
|
|
202
|
-
const s = a.length === 1 && a[0].property === e;
|
|
203
|
-
return [
|
|
204
|
-
{
|
|
205
|
-
property: e,
|
|
206
|
-
direction: s && a[0].direction === "ascending" ? "descending" : "ascending"
|
|
207
|
-
}
|
|
208
|
-
];
|
|
209
|
-
}
|
|
210
|
-
function y(a, e) {
|
|
211
|
-
return e.length === 0 ? a.slice() : a.map((t, s) => ({ row: t, index: s })).sort((t, s) => {
|
|
212
|
-
for (const i of e) {
|
|
213
|
-
const r = p(t.row, i.property), o = p(s.row, i.property), n = w(r, o);
|
|
214
|
-
if (n !== 0)
|
|
215
|
-
return i.direction === "ascending" ? n : -n;
|
|
216
|
-
}
|
|
217
|
-
return t.index - s.index;
|
|
218
|
-
}).map(({ row: t }) => t);
|
|
219
|
-
}
|
|
220
|
-
function p(a, e) {
|
|
221
|
-
if (!(a == null || typeof a != "object"))
|
|
222
|
-
return a[e];
|
|
223
|
-
}
|
|
224
|
-
function w(a, e) {
|
|
225
|
-
return a === e ? 0 : a == null ? 1 : e == null ? -1 : typeof a == "number" && typeof e == "number" ? a - e : a instanceof Date && e instanceof Date ? a.getTime() - e.getTime() : String(a).localeCompare(String(e));
|
|
226
|
-
}
|
|
227
|
-
let x = 0;
|
|
228
|
-
class C extends b {
|
|
229
|
-
constructor() {
|
|
230
|
-
super(...arguments), this.instanceId = `mp-datatable-${++x}`, this._columns = [], this._data = [], this._sortColumns = [], this._selectionMode = "none", this._selectedIds = /* @__PURE__ */ new Set(), this._cutIds = /* @__PURE__ */ new Set(), this._focusedRowKey = null, this._rowKey = (e, t) => {
|
|
231
|
-
const s = e;
|
|
232
|
-
return s && s.id != null ? String(s.id) : `row-${t}`;
|
|
233
|
-
}, this._columnWidths = /* @__PURE__ */ new Map(), this._loading = !1, this._emptyMessage = "No data", this._pagination = !1, this._page = 1, this._perPage = 20, this._perPageOptions = [10, 20, 50], this._autoSort = !0, this._totalRecords = null, this._virtualScroll = !1, this._itemSize = 40, this._virtualBuffer = 10, this._virtualRange = { startIndex: 0, endIndex: 0 }, this._scrollElement = null, this._resizeObserver = null, this._scrollListener = null, this._viewportHeight = 0, this._resizableColumns = !0, this.resizeState = null, this.onColumnResizeMove = (e) => {
|
|
234
|
-
if (!this.resizeState) return;
|
|
235
|
-
const t = e.clientX - this.resizeState.startX, s = Math.max(40, this.resizeState.startWidth + t);
|
|
236
|
-
this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(this.resizeState.columnName, s), this.requestUpdate();
|
|
237
|
-
}, this.onColumnResizeEnd = (e) => {
|
|
238
|
-
if (this.resizeState) {
|
|
239
|
-
this.resizeState.handle.classList.remove("active"), this.resizeState.handle.removeEventListener("pointermove", this.onColumnResizeMove), this.resizeState.handle.removeEventListener("pointerup", this.onColumnResizeEnd), this.resizeState.handle.removeEventListener("pointercancel", this.onColumnResizeEnd);
|
|
240
|
-
try {
|
|
241
|
-
this.resizeState.handle.releasePointerCapture(e.pointerId);
|
|
242
|
-
} catch {
|
|
243
|
-
}
|
|
244
|
-
this.resizeState = null;
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
static {
|
|
249
|
-
this.styles = [_];
|
|
250
|
-
}
|
|
251
|
-
static get observedAttributes() {
|
|
252
|
-
return [
|
|
253
|
-
...super.observedAttributes ?? [],
|
|
254
|
-
"selection-mode",
|
|
255
|
-
"pagination",
|
|
256
|
-
"resizable-columns",
|
|
257
|
-
"auto-sort",
|
|
258
|
-
"empty-message",
|
|
259
|
-
"virtual-scroll",
|
|
260
|
-
"item-size"
|
|
261
|
-
];
|
|
262
|
-
}
|
|
263
|
-
/** When true, the WC sorts `data` itself using `sortRows`. Set `false` if the consumer sorts externally. */
|
|
264
|
-
get autoSort() {
|
|
265
|
-
return this._autoSort;
|
|
266
|
-
}
|
|
267
|
-
set autoSort(e) {
|
|
268
|
-
this._autoSort = !!e, this.requestUpdate();
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Per-row renderer. When set, the WC delegates row content production to
|
|
272
|
-
* this callback (used by the Angular wrapper to host `*bsRowTemplate`
|
|
273
|
-
* templates). Returning `undefined` falls back to per-column `cellRenderer`s.
|
|
274
|
-
*/
|
|
275
|
-
get rowRenderer() {
|
|
276
|
-
return this._rowRenderer;
|
|
277
|
-
}
|
|
278
|
-
set rowRenderer(e) {
|
|
279
|
-
this._rowRenderer = e, this.requestUpdate();
|
|
280
|
-
}
|
|
281
|
-
/** Enable scroll-position-driven virtualization. Rows outside the viewport are not rendered. */
|
|
282
|
-
get virtualScroll() {
|
|
283
|
-
return this._virtualScroll;
|
|
284
|
-
}
|
|
285
|
-
set virtualScroll(e) {
|
|
286
|
-
const t = !!e;
|
|
287
|
-
this._virtualScroll !== t && (this._virtualScroll = t, this.requestUpdate());
|
|
288
|
-
}
|
|
289
|
-
/** Approximate row height in px (used by virtual scroll). Default `40`. */
|
|
290
|
-
get itemSize() {
|
|
291
|
-
return this._itemSize;
|
|
292
|
-
}
|
|
293
|
-
set itemSize(e) {
|
|
294
|
-
const t = Math.max(1, Math.floor(e || 0)) || 40;
|
|
295
|
-
this._itemSize !== t && (this._itemSize = t, this.requestUpdate());
|
|
296
|
-
}
|
|
297
|
-
/** Off-screen row buffer (each side) for virtual scrolling. */
|
|
298
|
-
get virtualBuffer() {
|
|
299
|
-
return this._virtualBuffer;
|
|
300
|
-
}
|
|
301
|
-
set virtualBuffer(e) {
|
|
302
|
-
const t = Math.max(0, Math.floor(e || 0));
|
|
303
|
-
this._virtualBuffer !== t && (this._virtualBuffer = t, this.requestUpdate());
|
|
304
|
-
}
|
|
305
|
-
get columns() {
|
|
306
|
-
return this._columns;
|
|
307
|
-
}
|
|
308
|
-
set columns(e) {
|
|
309
|
-
this._columns = Array.isArray(e) ? e : [], this.requestUpdate();
|
|
310
|
-
}
|
|
311
|
-
get data() {
|
|
312
|
-
return this._data;
|
|
313
|
-
}
|
|
314
|
-
set data(e) {
|
|
315
|
-
this._data = Array.isArray(e) ? e : [], this.requestUpdate();
|
|
316
|
-
}
|
|
317
|
-
get sortColumns() {
|
|
318
|
-
return [...this._sortColumns];
|
|
319
|
-
}
|
|
320
|
-
set sortColumns(e) {
|
|
321
|
-
this._sortColumns = Array.isArray(e) ? [...e] : [], this.requestUpdate();
|
|
322
|
-
}
|
|
323
|
-
get selectionMode() {
|
|
324
|
-
return this._selectionMode;
|
|
325
|
-
}
|
|
326
|
-
set selectionMode(e) {
|
|
327
|
-
this._selectionMode = e, e === "none" && this._selectedIds.clear(), this.requestUpdate();
|
|
328
|
-
}
|
|
329
|
-
get selectedIds() {
|
|
330
|
-
return [...this._selectedIds];
|
|
331
|
-
}
|
|
332
|
-
set selectedIds(e) {
|
|
333
|
-
this._selectedIds = new Set(e ?? []), this.requestUpdate();
|
|
334
|
-
}
|
|
335
|
-
get cutIds() {
|
|
336
|
-
return [...this._cutIds];
|
|
337
|
-
}
|
|
338
|
-
set cutIds(e) {
|
|
339
|
-
this._cutIds = new Set(e ?? []), this.requestUpdate();
|
|
340
|
-
}
|
|
341
|
-
get focusedRowKey() {
|
|
342
|
-
return this._focusedRowKey;
|
|
343
|
-
}
|
|
344
|
-
set focusedRowKey(e) {
|
|
345
|
-
this._focusedRowKey = e, this.requestUpdate();
|
|
346
|
-
}
|
|
347
|
-
get rowKey() {
|
|
348
|
-
return this._rowKey;
|
|
349
|
-
}
|
|
350
|
-
set rowKey(e) {
|
|
351
|
-
this._rowKey = typeof e == "function" ? e : this._rowKey, this.requestUpdate();
|
|
352
|
-
}
|
|
353
|
-
get loading() {
|
|
354
|
-
return this._loading;
|
|
355
|
-
}
|
|
356
|
-
set loading(e) {
|
|
357
|
-
this._loading = !!e, this.requestUpdate();
|
|
358
|
-
}
|
|
359
|
-
get emptyMessage() {
|
|
360
|
-
return this._emptyMessage;
|
|
361
|
-
}
|
|
362
|
-
set emptyMessage(e) {
|
|
363
|
-
this._emptyMessage = e || "No data", this.requestUpdate();
|
|
364
|
-
}
|
|
365
|
-
get pagination() {
|
|
366
|
-
return this._pagination;
|
|
367
|
-
}
|
|
368
|
-
set pagination(e) {
|
|
369
|
-
this._pagination = !!e, this.requestUpdate();
|
|
370
|
-
}
|
|
371
|
-
get page() {
|
|
372
|
-
return this._page;
|
|
373
|
-
}
|
|
374
|
-
set page(e) {
|
|
375
|
-
const t = Math.max(1, Math.floor(e || 1));
|
|
376
|
-
this._page !== t && (this._page = t, this.requestUpdate());
|
|
377
|
-
}
|
|
378
|
-
get perPage() {
|
|
379
|
-
return this._perPage;
|
|
380
|
-
}
|
|
381
|
-
set perPage(e) {
|
|
382
|
-
const t = Math.max(1, Math.floor(e || 1));
|
|
383
|
-
this._perPage !== t && (this._perPage = t, this._page = 1, this.requestUpdate());
|
|
384
|
-
}
|
|
385
|
-
get perPageOptions() {
|
|
386
|
-
return [...this._perPageOptions];
|
|
387
|
-
}
|
|
388
|
-
set perPageOptions(e) {
|
|
389
|
-
this._perPageOptions = Array.isArray(e) && e.length > 0 ? [...e] : [10, 20, 50], this.requestUpdate();
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Caller-supplied total record count for external paging. Set this when
|
|
393
|
-
* `[fetch]` returns one page at a time so the pagination footer can show
|
|
394
|
-
* the correct total. Leave as `null` (default) to use `_data.length`.
|
|
395
|
-
*/
|
|
396
|
-
get totalRecords() {
|
|
397
|
-
return this._totalRecords;
|
|
398
|
-
}
|
|
399
|
-
set totalRecords(e) {
|
|
400
|
-
const t = e == null ? null : Math.max(0, Math.floor(e));
|
|
401
|
-
this._totalRecords !== t && (this._totalRecords = t, this.requestUpdate());
|
|
402
|
-
}
|
|
403
|
-
/** True when the consumer is paging externally (totalRecords exceeds the in-memory rows). */
|
|
404
|
-
isExternallyPaged() {
|
|
405
|
-
return this._totalRecords != null && this._totalRecords > this._data.length;
|
|
406
|
-
}
|
|
407
|
-
attributeChangedCallback(e, t, s) {
|
|
408
|
-
if (super.attributeChangedCallback(e, t, s), e === "selection-mode") {
|
|
409
|
-
const i = s;
|
|
410
|
-
(i === "none" || i === "single" || i === "multiple") && (this.selectionMode = i);
|
|
411
|
-
} else if (e === "pagination")
|
|
412
|
-
this.pagination = s !== null;
|
|
413
|
-
else if (e === "resizable-columns")
|
|
414
|
-
this.resizableColumns = s !== null;
|
|
415
|
-
else if (e === "auto-sort")
|
|
416
|
-
this.autoSort = s !== "false";
|
|
417
|
-
else if (e === "empty-message")
|
|
418
|
-
this.emptyMessage = s ?? "No data";
|
|
419
|
-
else if (e === "virtual-scroll")
|
|
420
|
-
this.virtualScroll = s !== null;
|
|
421
|
-
else if (e === "item-size") {
|
|
422
|
-
const i = Number(s);
|
|
423
|
-
Number.isFinite(i) && (this.itemSize = i);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
get resizableColumns() {
|
|
427
|
-
return this._resizableColumns;
|
|
428
|
-
}
|
|
429
|
-
set resizableColumns(e) {
|
|
430
|
-
this._resizableColumns = !!e, this.requestUpdate();
|
|
431
|
-
}
|
|
432
|
-
connectedCallback() {
|
|
433
|
-
super.connectedCallback();
|
|
434
|
-
}
|
|
435
|
-
firstUpdated() {
|
|
436
|
-
this._scrollElement = this.shadowRoot?.querySelector(".datatable-scroll"), this._scrollElement && (this._scrollListener = () => this.refreshVirtualRange(), this._scrollElement.addEventListener("scroll", this._scrollListener, { passive: !0 }), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this.refreshVirtualRange()), this._resizeObserver.observe(this._scrollElement))), this.refreshVirtualRange();
|
|
437
|
-
}
|
|
438
|
-
disconnectedCallback() {
|
|
439
|
-
super.disconnectedCallback(), this._scrollElement && this._scrollListener && this._scrollElement.removeEventListener("scroll", this._scrollListener), this._scrollListener = null, this._resizeObserver?.disconnect(), this._resizeObserver = null, this._scrollElement = null;
|
|
440
|
-
}
|
|
441
|
-
refreshVirtualRange() {
|
|
442
|
-
if (!this._virtualScroll || !this._scrollElement) return;
|
|
443
|
-
const e = this._scrollElement.scrollTop, t = this._scrollElement.clientHeight;
|
|
444
|
-
this._viewportHeight = t;
|
|
445
|
-
const s = this.getEffectiveData().length, i = this._itemSize, r = Math.max(0, Math.floor(e / i) - this._virtualBuffer), o = Math.ceil(t / i), n = Math.min(s, r + o + this._virtualBuffer * 2);
|
|
446
|
-
(r !== this._virtualRange.startIndex || n !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: r, endIndex: n }, this.requestUpdate());
|
|
447
|
-
}
|
|
448
|
-
render() {
|
|
449
|
-
const e = this.computeVisibleRows(), t = this._totalRecords ?? this._data.length, s = this.pagination ? Math.max(1, Math.ceil(t / this._perPage)) : 1, i = this._selectionMode === "multiple", r = this._columns.length + (i ? 1 : 0), o = this.getVirtualSpacerHeights();
|
|
450
|
-
return d`
|
|
451
|
-
<div class="datatable-shell">
|
|
452
|
-
<div class="datatable-scroll ${this._virtualScroll ? "datatable-virtual" : ""}" role="presentation">
|
|
453
|
-
<table role="grid" aria-rowcount=${this._data.length + 1}>
|
|
454
|
-
<thead>
|
|
455
|
-
<tr role="row" aria-rowindex="1">
|
|
456
|
-
${i ? d`<th class="checkbox-cell" scope="col">
|
|
457
|
-
<mp-checkbox
|
|
458
|
-
aria-label="Deselect all"
|
|
459
|
-
aria-hidden=${this._selectedIds.size === 0 ? "true" : h}
|
|
460
|
-
style=${u({ visibility: this._selectedIds.size > 0 ? "visible" : "hidden" })}
|
|
461
|
-
.checked=${!1}
|
|
462
|
-
.indeterminate=${this._selectedIds.size > 0}
|
|
463
|
-
@change=${this.onDeselectAll}
|
|
464
|
-
></mp-checkbox>
|
|
465
|
-
</th>` : h}
|
|
466
|
-
${this._columns.map((n, l) => this.renderHeader(n, l))}
|
|
467
|
-
</tr>
|
|
468
|
-
</thead>
|
|
469
|
-
<tbody>
|
|
470
|
-
${this._loading ? d`<tr><td colspan=${r} class="loading-state">Loading…</td></tr>` : e.length === 0 ? d`<tr><td colspan=${r} class="empty-state">${this._emptyMessage}</td></tr>` : d`
|
|
471
|
-
${o.top > 0 ? d`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${r} style=${u({ height: `${o.top}px`, padding: "0", border: "0" })}></td></tr>` : h}
|
|
472
|
-
${f(
|
|
473
|
-
e,
|
|
474
|
-
({ key: n }) => n,
|
|
475
|
-
({ row: n, key: l, rowIndex: c }) => this.renderRow(n, l, c, i)
|
|
476
|
-
)}
|
|
477
|
-
${o.bottom > 0 ? d`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${r} style=${u({ height: `${o.bottom}px`, padding: "0", border: "0" })}></td></tr>` : h}
|
|
478
|
-
`}
|
|
479
|
-
</tbody>
|
|
480
|
-
</table>
|
|
481
|
-
</div>
|
|
482
|
-
${this._pagination ? this.renderFooter(s) : h}
|
|
483
|
-
</div>
|
|
484
|
-
`;
|
|
485
|
-
}
|
|
486
|
-
getVirtualSpacerHeights() {
|
|
487
|
-
if (!this._virtualScroll) return { top: 0, bottom: 0 };
|
|
488
|
-
const e = this.getEffectiveData().length, { startIndex: t, endIndex: s } = this._virtualRange;
|
|
489
|
-
return {
|
|
490
|
-
top: t * this._itemSize,
|
|
491
|
-
bottom: Math.max(0, (e - s) * this._itemSize)
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
renderHeader(e, t) {
|
|
495
|
-
const s = e.sortable ?? !0, i = this._sortColumns.findIndex((c) => c.property === e.name), r = i >= 0 ? this._sortColumns[i].direction : null, o = this._columnWidths.get(e.name) ?? e.width, n = e.headerRenderer ? e.headerRenderer(e) : e.label ?? e.name, l = {};
|
|
496
|
-
return typeof o == "number" && (l.width = `${o}px`, l.minWidth = `${o}px`), d`
|
|
497
|
-
<th
|
|
498
|
-
scope="col"
|
|
499
|
-
data-column=${e.name}
|
|
500
|
-
data-sortable=${s ? "true" : "false"}
|
|
501
|
-
aria-sort=${r ? r === "ascending" ? "ascending" : "descending" : "none"}
|
|
502
|
-
style=${u(l)}
|
|
503
|
-
@click=${(c) => this.onHeaderClick(e, c)}
|
|
504
|
-
>
|
|
505
|
-
<span class="header-cell">
|
|
506
|
-
<span>${g(n)}</span>
|
|
507
|
-
${i >= 0 && this._sortColumns.length > 1 ? d`<span class="sort-index">${i + 1}</span>` : h}
|
|
508
|
-
</span>
|
|
509
|
-
${this._resizableColumns ? d`<span
|
|
510
|
-
class="resize-handle"
|
|
511
|
-
role="separator"
|
|
512
|
-
aria-orientation="vertical"
|
|
513
|
-
aria-label="Resize column ${e.label ?? e.name}"
|
|
514
|
-
@pointerdown=${(c) => this.startColumnResize(e, c)}
|
|
515
|
-
></span>` : h}
|
|
516
|
-
</th>
|
|
517
|
-
`;
|
|
518
|
-
}
|
|
519
|
-
renderRow(e, t, s, i) {
|
|
520
|
-
const r = this._selectedIds.has(t), o = this._cutIds.has(t), n = this._focusedRowKey === t;
|
|
521
|
-
return d`
|
|
522
|
-
<tr
|
|
523
|
-
role="row"
|
|
524
|
-
aria-rowindex=${s + 2}
|
|
525
|
-
aria-selected=${this._selectionMode !== "none" ? r ? "true" : "false" : h}
|
|
526
|
-
data-row-key=${t}
|
|
527
|
-
data-selected=${r ? "true" : "false"}
|
|
528
|
-
data-cut=${o ? "true" : "false"}
|
|
529
|
-
data-focused=${n ? "true" : "false"}
|
|
530
|
-
data-clickable=${this._selectionMode !== "none" || this.hasRowClickListeners() ? "true" : "false"}
|
|
531
|
-
@click=${(l) => this.onRowClick(e, t, s, l)}
|
|
532
|
-
@dblclick=${(l) => this.onRowDblClick(e, t, s, l)}
|
|
533
|
-
@contextmenu=${(l) => this.onRowContextMenu(e, t, s, l)}
|
|
534
|
-
>
|
|
535
|
-
${i ? d`<td class="checkbox-cell" @click=${(l) => l.stopPropagation()}>
|
|
536
|
-
<mp-checkbox
|
|
537
|
-
aria-label=${`Select row ${s + 1}`}
|
|
538
|
-
.checked=${r}
|
|
539
|
-
@change=${(l) => this.onRowCheckboxToggle(e, t, s, l)}
|
|
540
|
-
></mp-checkbox>
|
|
541
|
-
</td>` : h}
|
|
542
|
-
${this._rowRenderer ? this.renderRowFromRenderer(e, s) : this._columns.map((l) => this.renderCell(e, l, s))}
|
|
543
|
-
</tr>
|
|
544
|
-
`;
|
|
545
|
-
}
|
|
546
|
-
renderRowFromRenderer(e, t) {
|
|
547
|
-
const s = this._rowRenderer(e, t);
|
|
548
|
-
if (s == null)
|
|
549
|
-
return this._columns.map((i) => this.renderCell(e, i, t));
|
|
550
|
-
if (Array.isArray(s) || R(s)) {
|
|
551
|
-
const i = [];
|
|
552
|
-
for (const r of s) i.push(r);
|
|
553
|
-
return i;
|
|
554
|
-
}
|
|
555
|
-
return s;
|
|
556
|
-
}
|
|
557
|
-
renderCell(e, t, s) {
|
|
558
|
-
const i = t.cellRenderer ? t.cellRenderer(e, t, s) : S(e, t);
|
|
559
|
-
return d`<td class=${t.cellClass ?? ""} data-column=${t.name}>${g(i)}</td>`;
|
|
560
|
-
}
|
|
561
|
-
renderFooter(e) {
|
|
562
|
-
const t = Array.from({ length: e }, (s, i) => i + 1);
|
|
563
|
-
return d`
|
|
564
|
-
<div class="datatable-footer">
|
|
565
|
-
<mp-pagination
|
|
566
|
-
class="datatable-per-page"
|
|
567
|
-
aria-label="Rows per page"
|
|
568
|
-
.pageNumbers=${this._perPageOptions}
|
|
569
|
-
.selectedPageNumber=${this._perPage}
|
|
570
|
-
.showArrows=${!1}
|
|
571
|
-
@mp-pagination-page-change=${(s) => this.setPerPage(s.detail.page)}
|
|
572
|
-
></mp-pagination>
|
|
573
|
-
<mp-pagination
|
|
574
|
-
class="datatable-pagination"
|
|
575
|
-
.pageNumbers=${t}
|
|
576
|
-
.selectedPageNumber=${this._page}
|
|
577
|
-
.numberOfBoxes=${7}
|
|
578
|
-
.showArrows=${!0}
|
|
579
|
-
@mp-pagination-page-change=${(s) => this.gotoPage(s.detail.page)}
|
|
580
|
-
></mp-pagination>
|
|
581
|
-
</div>
|
|
582
|
-
`;
|
|
583
|
-
}
|
|
584
|
-
setPerPage(e) {
|
|
585
|
-
const t = Math.max(1, Math.floor(e || 1));
|
|
586
|
-
this._perPage !== t && (this._perPage = t, this._page = 1, this.requestUpdate(), this.dispatchEvent(
|
|
587
|
-
new CustomEvent("mp-datatable-per-page-change", {
|
|
588
|
-
detail: { perPage: t },
|
|
589
|
-
bubbles: !0,
|
|
590
|
-
composed: !0
|
|
591
|
-
})
|
|
592
|
-
), this.dispatchEvent(
|
|
593
|
-
new CustomEvent("mp-datatable-page-change", {
|
|
594
|
-
detail: { page: 1 },
|
|
595
|
-
bubbles: !0,
|
|
596
|
-
composed: !0
|
|
597
|
-
})
|
|
598
|
-
));
|
|
599
|
-
}
|
|
600
|
-
getEffectiveData() {
|
|
601
|
-
let e = this._data;
|
|
602
|
-
if (this._autoSort && this._sortColumns.length > 0 && (e = y(e, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
|
|
603
|
-
const t = (this._page - 1) * this._perPage;
|
|
604
|
-
e = e.slice(t, t + this._perPage);
|
|
605
|
-
}
|
|
606
|
-
return e;
|
|
607
|
-
}
|
|
608
|
-
computeVisibleRows() {
|
|
609
|
-
const e = this.getEffectiveData(), t = this._pagination ? (this._page - 1) * this._perPage : 0;
|
|
610
|
-
let s = e, i = 0;
|
|
611
|
-
if (this._virtualScroll) {
|
|
612
|
-
const { startIndex: r, endIndex: o } = this._virtualRange;
|
|
613
|
-
s = e.slice(r, o), i = r;
|
|
614
|
-
}
|
|
615
|
-
return s.map((r, o) => {
|
|
616
|
-
const n = t + i + o;
|
|
617
|
-
return { row: r, rowIndex: n, key: this._rowKey(r, n) };
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
hasRowClickListeners() {
|
|
621
|
-
return !0;
|
|
622
|
-
}
|
|
623
|
-
onHeaderClick(e, t) {
|
|
624
|
-
if (!(e.sortable ?? !0) || t.target.closest(".resize-handle")) return;
|
|
625
|
-
const r = v(this._sortColumns, e.name, t.shiftKey);
|
|
626
|
-
this._sortColumns = r, this.requestUpdate(), this.dispatchEvent(
|
|
627
|
-
new CustomEvent("mp-datatable-sort-change", {
|
|
628
|
-
detail: { sortColumns: r },
|
|
629
|
-
bubbles: !0,
|
|
630
|
-
composed: !0
|
|
631
|
-
})
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
onRowClick(e, t, s, i) {
|
|
635
|
-
i.target.closest('input[type="checkbox"]') || (this._focusedRowKey = t, this.handleSelectionOnClick(t, i), this.requestUpdate(), this.dispatchEvent(
|
|
636
|
-
new CustomEvent("mp-datatable-row-click", {
|
|
637
|
-
detail: { row: e, rowIndex: s, rowKey: t, originalEvent: i },
|
|
638
|
-
bubbles: !0,
|
|
639
|
-
composed: !0
|
|
640
|
-
})
|
|
641
|
-
));
|
|
642
|
-
}
|
|
643
|
-
onRowDblClick(e, t, s, i) {
|
|
644
|
-
this.dispatchEvent(
|
|
645
|
-
new CustomEvent("mp-datatable-row-dblclick", {
|
|
646
|
-
detail: { row: e, rowIndex: s, rowKey: t, originalEvent: i },
|
|
647
|
-
bubbles: !0,
|
|
648
|
-
composed: !0
|
|
649
|
-
})
|
|
650
|
-
);
|
|
651
|
-
}
|
|
652
|
-
onRowContextMenu(e, t, s, i) {
|
|
653
|
-
this._selectionMode !== "none" && !this._selectedIds.has(t) && (this._selectedIds = /* @__PURE__ */ new Set([t]), this._focusedRowKey = t, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
|
|
654
|
-
new CustomEvent("mp-datatable-row-contextmenu", {
|
|
655
|
-
detail: { row: e, rowIndex: s, rowKey: t, originalEvent: i },
|
|
656
|
-
bubbles: !0,
|
|
657
|
-
composed: !0,
|
|
658
|
-
cancelable: !0
|
|
659
|
-
})
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
onRowCheckboxToggle(e, t, s, i) {
|
|
663
|
-
if (this._selectionMode !== "none") {
|
|
664
|
-
if (this._selectionMode === "single")
|
|
665
|
-
this._selectedIds = /* @__PURE__ */ new Set([t]);
|
|
666
|
-
else {
|
|
667
|
-
const r = new Set(this._selectedIds);
|
|
668
|
-
r.has(t) ? r.delete(t) : r.add(t), this._selectedIds = r;
|
|
669
|
-
}
|
|
670
|
-
this.emitSelectionChange(), this.requestUpdate();
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Clears the entire selection. The header checkbox is only rendered when
|
|
675
|
-
* at least one row is selected — a true "select all" affordance would be
|
|
676
|
-
* misleading because the WC doesn't know about rows outside the current
|
|
677
|
-
* pagination slice or virtual-scroll window. Click semantics are
|
|
678
|
-
* therefore one-way: visible → deselect-all → hidden again.
|
|
679
|
-
*/
|
|
680
|
-
onDeselectAll() {
|
|
681
|
-
this._selectedIds.size !== 0 && (this._selectedIds = /* @__PURE__ */ new Set(), this.emitSelectionChange(), this.requestUpdate());
|
|
682
|
-
}
|
|
683
|
-
handleSelectionOnClick(e, t) {
|
|
684
|
-
if (this._selectionMode !== "none") {
|
|
685
|
-
if (this._selectionMode === "single") {
|
|
686
|
-
this._selectedIds = /* @__PURE__ */ new Set([e]), this.emitSelectionChange();
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
if (t.shiftKey && this._focusedRowKey && this._focusedRowKey !== e) {
|
|
690
|
-
const s = this.computeVisibleRows(), i = s.findIndex((o) => o.key === this._focusedRowKey), r = s.findIndex((o) => o.key === e);
|
|
691
|
-
if (i >= 0 && r >= 0) {
|
|
692
|
-
const [o, n] = i < r ? [i, r] : [r, i], l = s.slice(o, n + 1).map((c) => c.key);
|
|
693
|
-
this._selectedIds = /* @__PURE__ */ new Set([...this._selectedIds, ...l]), this.emitSelectionChange();
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
if (t.ctrlKey || t.metaKey) {
|
|
698
|
-
const s = new Set(this._selectedIds);
|
|
699
|
-
s.has(e) ? s.delete(e) : s.add(e), this._selectedIds = s, this.emitSelectionChange();
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
this._selectedIds = /* @__PURE__ */ new Set([e]), this.emitSelectionChange();
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
emitSelectionChange() {
|
|
706
|
-
this.dispatchEvent(
|
|
707
|
-
new CustomEvent("mp-datatable-selection-change", {
|
|
708
|
-
detail: { selectedIds: [...this._selectedIds] },
|
|
709
|
-
bubbles: !0,
|
|
710
|
-
composed: !0
|
|
711
|
-
})
|
|
712
|
-
);
|
|
713
|
-
}
|
|
714
|
-
gotoPage(e) {
|
|
715
|
-
const t = this._totalRecords ?? this._data.length, s = Math.max(1, Math.ceil(t / this._perPage));
|
|
716
|
-
this._page = Math.max(1, Math.min(s, e)), this.requestUpdate(), this.dispatchEvent(
|
|
717
|
-
new CustomEvent("mp-datatable-page-change", {
|
|
718
|
-
detail: { page: this._page },
|
|
719
|
-
bubbles: !0,
|
|
720
|
-
composed: !0
|
|
721
|
-
})
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
startColumnResize(e, t) {
|
|
725
|
-
if (!this._resizableColumns) return;
|
|
726
|
-
t.preventDefault(), t.stopPropagation();
|
|
727
|
-
const s = t.currentTarget, i = s.closest("th");
|
|
728
|
-
if (!i) return;
|
|
729
|
-
const r = i.getBoundingClientRect().width;
|
|
730
|
-
this.resizeState = { columnName: e.name, startX: t.clientX, startWidth: r, handle: s }, s.classList.add("active"), s.setPointerCapture(t.pointerId), s.addEventListener("pointermove", this.onColumnResizeMove), s.addEventListener("pointerup", this.onColumnResizeEnd), s.addEventListener("pointercancel", this.onColumnResizeEnd);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
function S(a, e) {
|
|
734
|
-
if (a == null || typeof a != "object") return "";
|
|
735
|
-
const t = a[e.name];
|
|
736
|
-
return t == null ? "" : String(t);
|
|
737
|
-
}
|
|
738
|
-
function R(a) {
|
|
739
|
-
return a != null && typeof a != "string" && typeof a[Symbol.iterator] == "function";
|
|
740
|
-
}
|
|
741
|
-
function g(a) {
|
|
742
|
-
return a == null || a === !1 ? h : (a instanceof Node || typeof a == "object" && "_$litType$" in a, a);
|
|
743
|
-
}
|
|
744
|
-
typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", C);
|
|
745
|
-
export {
|
|
746
|
-
C as M,
|
|
747
|
-
v as c,
|
|
748
|
-
_ as d,
|
|
749
|
-
y as s
|
|
750
|
-
};
|