Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,61 @@
|
||||
// Generated, do not edit. sha256:6f5f28d079f7f6e64bd296677a36276bfb053415d4ab690712c66e663e2b15d6
|
||||
export const valueOf = (col, row) => (col.sortValue ? col.sortValue(row) : row[col.key]);
|
||||
|
||||
export function compare(a, b, dir) {
|
||||
if (a == null && b == null) return 0;
|
||||
if (a == null) return 1;
|
||||
if (b == null) return -1;
|
||||
const r = (typeof a === 'number' && typeof b === 'number')
|
||||
? a - b
|
||||
: String(a).localeCompare(String(b), 'nl', { numeric: true });
|
||||
return dir === 'desc' ? -r : r;
|
||||
}
|
||||
|
||||
export function sortRows(rows, columns, sort) {
|
||||
if (!sort) return rows.slice();
|
||||
const col = columns.find(c => c.key === sort.key);
|
||||
if (!col) return rows.slice();
|
||||
return rows.slice().sort((x, y) => compare(valueOf(col, x), valueOf(col, y), sort.dir));
|
||||
}
|
||||
|
||||
export function rowText(row, columns) {
|
||||
return columns.map(c => {
|
||||
const v = c.render ? c.render(row) : valueOf(c, row);
|
||||
return String(v == null ? '' : v).replace(/<[^>]*>/g, ' ');
|
||||
}).join(' ').toLowerCase();
|
||||
}
|
||||
|
||||
export function filterRows(rows, columns, { search = '', groupKey = null, hidden = new Set() } = {}) {
|
||||
const q = search.trim().toLowerCase();
|
||||
let out = q ? rows.filter(r => rowText(r, columns).includes(q)) : rows;
|
||||
if (groupKey && hidden.size) {
|
||||
const col = columns.find(c => c.key === groupKey);
|
||||
if (col) out = out.filter(r => !hidden.has(String(col.group.value(r))));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function groupValues(rows, col, order = 'asc') {
|
||||
const seen = new Map();
|
||||
for (const r of rows) {
|
||||
const v = col.group.value(r);
|
||||
const tok = String(v);
|
||||
if (!seen.has(tok)) seen.set(tok, v);
|
||||
}
|
||||
return [...seen.entries()]
|
||||
.map(([token, value]) => ({ token, value, label: col.group.label ? col.group.label(value) : value }))
|
||||
.sort((a, b) => compare(a.value, b.value, order));
|
||||
}
|
||||
|
||||
export const toggleToken = (token, list = []) =>
|
||||
(list.includes(token) ? list.filter(t => t !== token) : [...list, token]);
|
||||
|
||||
export function cycleGroupToken(token, hiddenList = [], collapsedList = []) {
|
||||
const hidden = new Set(hiddenList);
|
||||
const collapsed = new Set(collapsedList);
|
||||
const shown = !hidden.has(token);
|
||||
if (shown && !collapsed.has(token)) collapsed.add(token);
|
||||
else if (shown) { collapsed.delete(token); hidden.add(token); }
|
||||
else { hidden.delete(token); collapsed.delete(token); }
|
||||
return { hidden: [...hidden], collapsed: [...collapsed] };
|
||||
}
|
||||
Reference in new issue
Block a user