@mmlogic/components 0.1.24 → 0.1.26
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/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mosterdcomponents.cjs.js +1 -1
- package/dist/cjs/mrd-boolean-field_19.cjs.entry.js +3142 -0
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/mrd-layout-section/mrd-layout-section.js +733 -0
- package/dist/collection/components/mrd-layout-section/mrd-layout-section.scss +354 -0
- package/dist/collection/components/mrd-longtext-field/mrd-longtext-field.js +1 -1
- package/dist/collection/components/mrd-number-field/mrd-number-field.js +1 -1
- package/dist/collection/components/mrd-table/mrd-table.js +53 -42
- package/dist/collection/components/mrd-table/mrd-table.scss +29 -71
- package/dist/collection/components/mrd-text-field/mrd-text-field.js +1 -1
- package/dist/collection/components/mrd-textarea-field/mrd-textarea-field.js +1 -1
- package/dist/collection/components/mrd-time-field/mrd-time-field.js +1 -1
- package/dist/collection/dev/app.js +109 -3
- package/dist/collection/dev/example-data.js +324 -0
- package/dist/collection/utils/cell-renderer.js +26 -0
- package/dist/components/mrd-layout-section.d.ts +11 -0
- package/dist/components/mrd-layout-section.js +1 -0
- package/dist/components/mrd-longtext-field2.js +1 -1
- package/dist/components/mrd-number-field2.js +1 -1
- package/dist/components/mrd-table.js +1 -1
- package/dist/components/mrd-table2.js +1 -0
- package/dist/components/mrd-text-field2.js +1 -1
- package/dist/components/mrd-textarea-field2.js +1 -1
- package/dist/components/mrd-time-field2.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mosterdcomponents.js +1 -1
- package/dist/esm/mrd-boolean-field_19.entry.js +3122 -0
- package/dist/mosterdcomponents/mosterdcomponents.esm.js +1 -1
- package/dist/mosterdcomponents/p-e1a5587b.entry.js +1 -0
- package/dist/types/components/mrd-layout-section/mrd-layout-section.d.ts +93 -0
- package/dist/types/components/mrd-table/mrd-table.d.ts +5 -6
- package/dist/types/components.d.ts +128 -8
- package/dist/types/types/client-layout.d.ts +19 -0
- package/dist/types/utils/cell-renderer.d.ts +9 -1
- package/package.json +1 -1
- package/dist/cjs/format-DExY8_nu.js +0 -328
- package/dist/cjs/mrd-boolean-field_17.cjs.entry.js +0 -1554
- package/dist/cjs/mrd-table.cjs.entry.js +0 -888
- package/dist/esm/format-CcRjWvcb.js +0 -319
- package/dist/esm/mrd-boolean-field_17.entry.js +0 -1536
- package/dist/esm/mrd-table.entry.js +0 -886
- package/dist/mosterdcomponents/p-17fe94c6.entry.js +0 -1
- package/dist/mosterdcomponents/p-3d856b27.entry.js +0 -1
- package/dist/mosterdcomponents/p-CcRjWvcb.js +0 -1
|
@@ -1,886 +0,0 @@
|
|
|
1
|
-
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-_tsCCkAi.js';
|
|
2
|
-
import { f as formatTime, a as formatDateTime, b as formatDate, c as formatCurrency, d as formatNumber, e as formatPercentage, t } from './format-CcRjWvcb.js';
|
|
3
|
-
import { ClientLayoutItemType } from './index.js';
|
|
4
|
-
|
|
5
|
-
class CellRenderer {
|
|
6
|
-
static render(column, row, locale) {
|
|
7
|
-
var _a, _b, _c, _d;
|
|
8
|
-
if (column.type === ClientLayoutItemType.RELATION) {
|
|
9
|
-
const name = (_b = (_a = column.relation) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
|
|
10
|
-
const link = (_c = row === null || row === void 0 ? void 0 : row._links) === null || _c === void 0 ? void 0 : _c[name];
|
|
11
|
-
if (!link)
|
|
12
|
-
return '';
|
|
13
|
-
if (Array.isArray(link))
|
|
14
|
-
return link.map((l) => { var _a; return (_a = l.name) !== null && _a !== void 0 ? _a : ''; }).filter(Boolean).join(', ');
|
|
15
|
-
return (_d = link.name) !== null && _d !== void 0 ? _d : '';
|
|
16
|
-
}
|
|
17
|
-
if (column.type !== ClientLayoutItemType.FIELD || !column.field)
|
|
18
|
-
return '';
|
|
19
|
-
const { name, dataType, listItems } = column.field;
|
|
20
|
-
const raw = row === null || row === void 0 ? void 0 : row[name];
|
|
21
|
-
if (raw == null || raw === '')
|
|
22
|
-
return '';
|
|
23
|
-
const values = Array.isArray(raw) ? raw : [raw];
|
|
24
|
-
return values
|
|
25
|
-
.map(v => CellRenderer.renderValue(dataType !== null && dataType !== void 0 ? dataType : 'TEXT', v, listItems !== null && listItems !== void 0 ? listItems : [], locale))
|
|
26
|
-
.filter(s => s !== '')
|
|
27
|
-
.join(', ');
|
|
28
|
-
}
|
|
29
|
-
static renderValue(dataType, value, listItems, locale) {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
switch (dataType) {
|
|
32
|
-
case 'INTEGER':
|
|
33
|
-
return formatNumber(Number(value), locale, { maximumFractionDigits: 0 });
|
|
34
|
-
case 'DECIMAL':
|
|
35
|
-
return formatNumber(Number(value), locale);
|
|
36
|
-
case 'PERCENTAGE':
|
|
37
|
-
return formatPercentage(Number(value), locale);
|
|
38
|
-
case 'CURRENCY': {
|
|
39
|
-
const { amount, currency } = typeof value === 'object' && value !== null
|
|
40
|
-
? value
|
|
41
|
-
: { amount: value, currency: '' };
|
|
42
|
-
return currency
|
|
43
|
-
? formatCurrency(Number(amount), currency, locale)
|
|
44
|
-
: formatNumber(Number(amount), locale);
|
|
45
|
-
}
|
|
46
|
-
case 'DATE':
|
|
47
|
-
return formatDate(value, locale);
|
|
48
|
-
case 'DATETIME':
|
|
49
|
-
return formatDateTime(value, locale);
|
|
50
|
-
case 'TIME':
|
|
51
|
-
return formatTime(value, locale);
|
|
52
|
-
case 'BOOLEAN':
|
|
53
|
-
return value ? '✓' : '';
|
|
54
|
-
case 'FILE':
|
|
55
|
-
case 'IMAGE':
|
|
56
|
-
return typeof value === 'object' && value !== null ? ((_a = value.fileName) !== null && _a !== void 0 ? _a : '') : '';
|
|
57
|
-
case 'LIST': {
|
|
58
|
-
const item = listItems.find(li => li.key === String(value));
|
|
59
|
-
return (_b = item === null || item === void 0 ? void 0 : item.label) !== null && _b !== void 0 ? _b : String(value);
|
|
60
|
-
}
|
|
61
|
-
case 'TEXTBLOCK': {
|
|
62
|
-
const stripped = String(value).replace(/<[^>]*>/g, '');
|
|
63
|
-
const txt = document.createElement('textarea');
|
|
64
|
-
txt.innerHTML = stripped;
|
|
65
|
-
return txt.value.trim();
|
|
66
|
-
}
|
|
67
|
-
case 'LONGTEXT':
|
|
68
|
-
return String(value).replace(/[\r\n]+/g, ' ').trim();
|
|
69
|
-
case 'JSON': {
|
|
70
|
-
const str = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
71
|
-
return str.replace(/[\r\n]+/g, ' ').trim();
|
|
72
|
-
}
|
|
73
|
-
default:
|
|
74
|
-
return String(value);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const mrdTableScss = () => `.sc-mrd-table-h{display:block;width:100%}.mrd-table__scroll.sc-mrd-table{overflow-y:auto;overflow-x:auto;border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);overflow-anchor:none}.mrd-table.sc-mrd-table{overflow-x:auto}.mrd-table__table.sc-mrd-table{width:auto;min-width:100%;border-collapse:collapse;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-900)}.mrd-table__scroll.sc-mrd-table .mrd-table__table.sc-mrd-table{min-width:max-content}.mrd-table__header.sc-mrd-table{position:sticky;top:0;z-index:1;background:var(--mrd-color-white);text-align:left;padding:var(--mrd-space-2) var(--mrd-space-4);border-bottom:2px solid var(--mrd-border-color);color:var(--mrd-color-neutral-600);font-weight:var(--mrd-font-weight-medium);white-space:nowrap;font-size:var(--mrd-font-size-xs);text-transform:uppercase;letter-spacing:0.04em}.mrd-table__header--sortable.sc-mrd-table{cursor:pointer;user-select:none}.mrd-table__header--sortable.sc-mrd-table:hover{background:var(--mrd-color-neutral-50);color:var(--mrd-color-neutral-800)}.mrd-table__header--sorted-asc.sc-mrd-table,.mrd-table__header--sorted-desc.sc-mrd-table{color:var(--mrd-color-primary);border-bottom-color:var(--mrd-color-primary)}.mrd-table__header-label.sc-mrd-table{margin-right:var(--mrd-space-1)}.mrd-table__sort-icon.sc-mrd-table{font-size:0.85rem;opacity:0.4;vertical-align:middle}.mrd-table__header--sorted-asc.sc-mrd-table .mrd-table__sort-icon.sc-mrd-table,.mrd-table__header--sorted-desc.sc-mrd-table .mrd-table__sort-icon.sc-mrd-table{opacity:1;color:var(--mrd-color-primary)}.mrd-table__filter-icon.sc-mrd-table{display:inline-flex;align-items:center;vertical-align:middle;margin-left:var(--mrd-space-1);color:var(--mrd-color-primary)}.mrd-table__row.sc-mrd-table{border-bottom:1px solid var(--mrd-border-color)}.mrd-table__row.sc-mrd-table:hover{background:var(--mrd-color-neutral-200) !important}.mrd-table__row--clickable.sc-mrd-table{cursor:pointer}.mrd-table__spacer.sc-mrd-table{border:none}.mrd-table__spacer.sc-mrd-table td.sc-mrd-table{padding:0;border:none}.mrd-table__cell.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-4);vertical-align:top;white-space:nowrap}.mrd-table__cell--numeric.sc-mrd-table{text-align:right;font-variant-numeric:tabular-nums}.mrd-table__row--loading.sc-mrd-table{background:transparent}.mrd-table__cell--placeholder.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-4);border-bottom:1px solid var(--mrd-border-color)}.mrd-table__placeholder-bar.sc-mrd-table{display:block;height:0.75rem;width:55%;border-radius:var(--mrd-border-radius-sm);background:linear-gradient( 90deg, var(--mrd-color-neutral-200) 25%, var(--mrd-color-neutral-100) 50%, var(--mrd-color-neutral-200) 75% );background-size:200% 100%;animation:mrd-shimmer 1.4s ease infinite}@keyframes mrd-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}.mrd-table__toolbar.sc-mrd-table{display:flex;align-items:center;justify-content:space-between;padding-bottom:var(--mrd-space-2)}.mrd-table__toolbar-left.sc-mrd-table,.mrd-table__toolbar-right.sc-mrd-table{display:flex;gap:var(--mrd-space-2);align-items:center}.mrd-table__toolbar-center.sc-mrd-table{flex:1;display:flex;justify-content:center;align-items:center;gap:var(--mrd-space-1)}.mrd-table__view-title.sc-mrd-table{font-size:var(--mrd-font-size-sm);font-weight:600;color:var(--mrd-color-neutral-800)}.mrd-table__view-switcher.sc-mrd-table{position:relative}.mrd-table__view-switcher-btn.sc-mrd-table{display:inline-flex;align-items:center;gap:var(--mrd-space-1);background:none;border:none;cursor:pointer;padding:var(--mrd-space-1) var(--mrd-space-2);color:var(--mrd-color-neutral-400);font-size:var(--mrd-font-size-sm);border-radius:var(--mrd-border-radius);transition:color 0.15s, background-color 0.15s;line-height:1.4}.mrd-table__view-switcher-btn.sc-mrd-table:hover{color:var(--mrd-color-neutral-700);background-color:var(--mrd-color-neutral-50)}.mrd-table__view-switcher-label.sc-mrd-table{font-weight:var(--mrd-font-weight-medium)}.mrd-table__view-switcher-chevron.sc-mrd-table{width:1.1rem;height:1.1rem;flex-shrink:0;transition:transform 0.15s}.mrd-table__view-switcher-btn--open.sc-mrd-table .mrd-table__view-switcher-chevron.sc-mrd-table{transform:rotate(180deg)}.mrd-table__view-switcher-dropdown.sc-mrd-table{position:absolute;top:calc(100% + 4px);left:50%;transform:translateX(-50%);min-width:160px;background:var(--mrd-color-white);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);box-shadow:var(--mrd-shadow-md, 0 4px 12px rgba(0,0,0,.12));z-index:var(--mrd-z-dropdown, 200);overflow:hidden}.mrd-table__view-switcher-item.sc-mrd-table{display:block;width:100%;padding:var(--mrd-space-2) var(--mrd-space-3);background:none;border:none;text-align:left;cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-700);white-space:nowrap;transition:background-color 0.1s, color 0.1s}.mrd-table__view-switcher-item.sc-mrd-table:hover{background-color:var(--mrd-color-neutral-50);color:var(--mrd-color-neutral-900)}.mrd-table__action.sc-mrd-table{position:relative;display:inline-flex;align-items:center;justify-content:center;width:2rem;height:2rem;padding:0;background:transparent;border:1px solid transparent;border-radius:var(--mrd-border-radius);cursor:pointer;color:var(--mrd-color-neutral-400);transition:background-color 0.15s, border-color 0.15s, color 0.15s}.mrd-table__action.sc-mrd-table:hover{background-color:var(--mrd-color-neutral-100);border-color:var(--mrd-color-neutral-300);color:var(--mrd-color-neutral-700)}.mrd-table__action.sc-mrd-table:disabled{opacity:0.4;cursor:not-allowed}.mrd-table__action--primary.sc-mrd-table{color:var(--mrd-color-neutral-500)}.mrd-table__action--primary.sc-mrd-table:hover{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__action--danger.sc-mrd-table{color:var(--mrd-color-error)}.mrd-table__action--danger.sc-mrd-table:hover{background-color:var(--mrd-color-error-light, #fef2f2);border-color:var(--mrd-color-error)}.mrd-table__action-icon.sc-mrd-table{width:1.25rem;height:1.25rem;pointer-events:none;fill:currentColor}.mrd-table__action-tooltip.sc-mrd-table{display:none;position:absolute;bottom:calc(100% + 6px);right:0;padding:var(--mrd-space-1) var(--mrd-space-2);font-size:var(--mrd-font-size-xs);white-space:nowrap;background:var(--mrd-color-tooltip, #fffce1);color:var(--mrd-color-neutral-900);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius-sm, var(--mrd-border-radius));pointer-events:none;z-index:10}.mrd-table__action.sc-mrd-table:hover .mrd-table__action-tooltip.sc-mrd-table{display:block}.mrd-table__filter-toggle--active.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-toggle--active.sc-mrd-table:hover{background:var(--mrd-color-primary-dark, var(--mrd-color-primary));border-color:var(--mrd-color-primary-dark, var(--mrd-color-primary));color:var(--mrd-color-white)}.mrd-table__filter-badge.sc-mrd-table{position:absolute;top:-6px;right:-6px;min-width:1.25rem;height:1.25rem;padding:0 3px;background:var(--mrd-color-error, #e53e3e);color:var(--mrd-color-white);border-radius:9999px;font-size:0.65rem;font-weight:var(--mrd-font-weight-medium);line-height:1.25rem;text-align:center;pointer-events:none}.mrd-table__header--filtered.sc-mrd-table{color:var(--mrd-color-primary);border-bottom-color:var(--mrd-color-primary)}.mrd-table__filter-popup.sc-mrd-table{position:fixed;width:280px;background:var(--mrd-color-white);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);box-shadow:var(--mrd-shadow-md, 0 4px 12px rgba(0,0,0,.12));z-index:var(--mrd-z-dropdown, 200);font-size:var(--mrd-font-size-sm)}.mrd-table__filter-popup-header.sc-mrd-table{display:flex;align-items:center;justify-content:space-between;padding:var(--mrd-space-2) var(--mrd-space-3);border-bottom:1px solid var(--mrd-border-color)}.mrd-table__filter-popup-title.sc-mrd-table{font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-neutral-800);font-size:var(--mrd-font-size-sm)}.mrd-table__filter-close.sc-mrd-table{background:transparent;border:none;cursor:pointer;color:var(--mrd-color-neutral-500);font-size:0.9rem;padding:2px 4px;border-radius:3px;line-height:1}.mrd-table__filter-close.sc-mrd-table:hover{background:var(--mrd-color-neutral-100);color:var(--mrd-color-neutral-800)}.mrd-table__filter-section.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-3)}.mrd-table__filter-section-label.sc-mrd-table{font-size:var(--mrd-font-size-xs);font-weight:var(--mrd-font-weight-medium);text-transform:uppercase;letter-spacing:0.04em;color:var(--mrd-color-neutral-500);margin-bottom:var(--mrd-space-2)}.mrd-table__filter-sort-buttons.sc-mrd-table{display:flex;gap:var(--mrd-space-2)}.mrd-table__filter-sort-btn.sc-mrd-table{flex:1;padding:var(--mrd-space-1) var(--mrd-space-2);background:transparent;border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);cursor:pointer;font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-700)}.mrd-table__filter-sort-btn.sc-mrd-table:hover{background:var(--mrd-color-neutral-100)}.mrd-table__filter-sort-btn--active.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-divider.sc-mrd-table{height:1px;background:var(--mrd-border-color);margin:0}.mrd-table__filter-editor.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-2)}.mrd-table__filter-select.sc-mrd-table,.mrd-table__filter-input.sc-mrd-table{width:100%;padding:var(--mrd-space-1) var(--mrd-space-2);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-900);background:var(--mrd-color-white);box-sizing:border-box}.mrd-table__filter-select.sc-mrd-table:focus,.mrd-table__filter-input.sc-mrd-table:focus{outline:none;border-color:var(--mrd-color-primary);box-shadow:0 0 0 2px rgba(0,0,0,.06)}.mrd-table__filter-range.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1)}.mrd-table__filter-range.sc-mrd-table .mrd-table__filter-input.sc-mrd-table{flex:1;min-width:0}.mrd-table__filter-range-sep.sc-mrd-table{color:var(--mrd-color-neutral-400);flex-shrink:0}.mrd-table__filter-range--stacked.sc-mrd-table{flex-direction:column;align-items:stretch;gap:var(--mrd-space-2)}.mrd-table__filter-range-label.sc-mrd-table{font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);margin-bottom:2px}.mrd-table__filter-radio-group.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-table__filter-radio-group--inline.sc-mrd-table{flex-direction:row;gap:var(--mrd-space-3)}.mrd-table__filter-radio-label.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1);cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-800)}.mrd-table__filter-list.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-1);max-height:180px;overflow-y:auto}.mrd-table__filter-list-controls.sc-mrd-table{display:flex;gap:var(--mrd-space-2);margin-bottom:var(--mrd-space-1)}.mrd-table__filter-list-btn.sc-mrd-table{font-size:var(--mrd-font-size-xs);color:var(--mrd-color-primary);background:transparent;border:none;cursor:pointer;padding:0;text-decoration:underline}.mrd-table__filter-checkbox-label.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1);cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-800)}.mrd-table__filter-no-support.sc-mrd-table{font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-500);margin:0;font-style:italic}.mrd-table__filter-popup-footer.sc-mrd-table{display:flex;justify-content:flex-end;gap:var(--mrd-space-2);padding:var(--mrd-space-2) var(--mrd-space-3);border-top:1px solid var(--mrd-border-color)}.mrd-table__filter-btn.sc-mrd-table{padding:var(--mrd-space-1) var(--mrd-space-3);border-radius:var(--mrd-border-radius);border:1px solid var(--mrd-border-color);font-size:var(--mrd-font-size-sm);cursor:pointer}.mrd-table__filter-btn--clear.sc-mrd-table{background:transparent;color:var(--mrd-color-neutral-600)}.mrd-table__filter-btn--clear.sc-mrd-table:hover{background:var(--mrd-color-neutral-100)}.mrd-table__filter-btn--apply.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-btn--apply.sc-mrd-table:hover{background:var(--mrd-color-primary-dark, var(--mrd-color-primary));border-color:var(--mrd-color-primary-dark, var(--mrd-color-primary))}.mrd-table__totals-row.sc-mrd-table{border-top:2px solid var(--mrd-border-color)}.mrd-table__totals-cell.sc-mrd-table{position:sticky;bottom:0;z-index:2;padding:var(--mrd-space-2) var(--mrd-space-4);background:var(--mrd-color-white);font-weight:var(--mrd-font-weight-medium);font-variant-numeric:tabular-nums;white-space:nowrap;border-top:2px solid var(--mrd-border-color)}.mrd-table__totals-cell--numeric.sc-mrd-table{text-align:right}.mrd-table__footer.sc-mrd-table{padding:var(--mrd-space-1) var(--mrd-space-2);font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);text-align:right}.mrd-table__empty.sc-mrd-table{padding:var(--mrd-space-4) var(--mrd-space-3);color:var(--mrd-color-neutral-500);font-size:var(--mrd-font-size-sm);text-align:center;margin:0}.mrd-table__file-btn.sc-mrd-table{display:inline-flex;align-items:center;gap:var(--mrd-space-1);background:none;border:none;padding:0;cursor:pointer;color:var(--mrd-color-primary);font-size:var(--mrd-font-size-sm);font-family:inherit;max-width:100%;overflow:hidden}.mrd-table__file-btn.sc-mrd-table:hover{text-decoration:underline;color:var(--mrd-color-primary-dark)}.mrd-table__file-icon.sc-mrd-table{flex-shrink:0;width:1rem;height:1rem}.mrd-table__textblock-btn.sc-mrd-table{display:inline;background:none;border:none;padding:0 0 0 var(--mrd-space-1);cursor:pointer;color:var(--mrd-color-primary);font-size:var(--mrd-font-size-sm);font-family:inherit;line-height:inherit;vertical-align:middle}.mrd-table__textblock-btn.sc-mrd-table:hover{color:var(--mrd-color-primary-dark)}.mrd-table__modal-backdrop.sc-mrd-table{position:fixed;inset:0;background:rgba(0, 0, 0, 0.4);z-index:var(--mrd-z-modal, 300);display:flex;align-items:center;justify-content:center}.mrd-table__modal.sc-mrd-table{background:#fff;border-radius:var(--mrd-radius-md, 0.5rem);padding:var(--mrd-space-6);max-width:min(600px, 90vw);max-height:70vh;overflow-y:auto;position:relative;box-shadow:var(--mrd-shadow-lg)}.mrd-table__modal-close.sc-mrd-table{position:absolute;top:var(--mrd-space-3);right:var(--mrd-space-3);background:none;border:none;cursor:pointer;font-size:1.25rem;line-height:1;color:var(--mrd-color-text-muted, #6b7280);padding:0}.mrd-table__modal-close.sc-mrd-table:hover{color:var(--mrd-color-text, #111827)}.mrd-table__modal-text.sc-mrd-table{margin:0;padding-right:var(--mrd-space-6);white-space:pre-wrap;word-break:break-word;font-size:var(--mrd-font-size-sm);line-height:1.6}`;
|
|
80
|
-
|
|
81
|
-
const BUFFER = 10;
|
|
82
|
-
/** Wacht deze tijd (ms) na het laatste scroll-event voordat pagina's worden
|
|
83
|
-
* aangevraagd. Pagina's die de gebruiker snel voorbij scrollt worden zo geskipt. */
|
|
84
|
-
const REQUEST_DEBOUNCE_MS = 150;
|
|
85
|
-
/** Breedte van de filterpopup in px — voor overflow-correctie. */
|
|
86
|
-
const POPUP_WIDTH = 280;
|
|
87
|
-
const TEXT_TYPES = new Set(['TEXT', 'TEXTBLOCK', 'EMAIL', 'HYPERLINK']);
|
|
88
|
-
const NUMERIC_TYPES = new Set(['INTEGER', 'DECIMAL', 'PERCENTAGE', 'CURRENCY']);
|
|
89
|
-
const DATE_TYPES = new Set(['DATE', 'DATETIME', 'TIME']);
|
|
90
|
-
const NO_FILTER_TYPES = new Set(['FILE', 'IMAGE']);
|
|
91
|
-
const MrdTable = class {
|
|
92
|
-
constructor(hostRef) {
|
|
93
|
-
registerInstance(this, hostRef);
|
|
94
|
-
this.mrdLoadPage = createEvent(this, "mrdLoadPage");
|
|
95
|
-
this.mrdRowClick = createEvent(this, "mrdRowClick");
|
|
96
|
-
this.mrdAction = createEvent(this, "mrdAction");
|
|
97
|
-
this.mrdFilter = createEvent(this, "mrdFilter");
|
|
98
|
-
this.mrdDownload = createEvent(this, "mrdDownload");
|
|
99
|
-
this.mrdSwitchView = createEvent(this, "mrdSwitchView");
|
|
100
|
-
this.mrdLoadAggregations = createEvent(this, "mrdLoadAggregations");
|
|
101
|
-
// ── Non-state internals ────────────────────────────────────────────────────
|
|
102
|
-
this.pendingPages = new Set();
|
|
103
|
-
this.debounceTimer = null;
|
|
104
|
-
this.outsideClickHandler = null;
|
|
105
|
-
this.viewSwitcherClickHandler = null;
|
|
106
|
-
this.keydownHandler = null;
|
|
107
|
-
// ── Props ──────────────────────────────────────────────────────────────────
|
|
108
|
-
this.columns = [];
|
|
109
|
-
/** Direct rows (non-paginated mode, used when totalElements === 0). */
|
|
110
|
-
this.rows = [];
|
|
111
|
-
this.locale = navigator.language;
|
|
112
|
-
/** Total number of records across all pages. 0 = non-paginated mode. */
|
|
113
|
-
this.totalElements = 0;
|
|
114
|
-
/** Records per page (must match the API page size). */
|
|
115
|
-
this.pageSize = 20;
|
|
116
|
-
/** Row height in px — used for spacer and scroll-position maths. */
|
|
117
|
-
this.rowHeight = 36;
|
|
118
|
-
/** Height of the scroll container in px. */
|
|
119
|
-
this.tableHeight = 500;
|
|
120
|
-
/** Initial sort applied on load, e.g. "timestamp,desc" or "name".
|
|
121
|
-
* Parsed by init() into sortField + sortDir. */
|
|
122
|
-
this.defaultSort = '';
|
|
123
|
-
/** Toolbar action buttons rendered above the table. */
|
|
124
|
-
this.actions = [];
|
|
125
|
-
/** Display label of the current view — shown in the toolbar center as a view picker trigger. */
|
|
126
|
-
this.viewLabel = '';
|
|
127
|
-
/** Alternative views available for this table; renders a dropdown when non-empty. */
|
|
128
|
-
this.alternativeViews = [];
|
|
129
|
-
// ── Internal state ─────────────────────────────────────────────────────────
|
|
130
|
-
this.loadedPages = new Map();
|
|
131
|
-
this.requestedPages = new Set();
|
|
132
|
-
this.renderStart = 0;
|
|
133
|
-
this.renderEnd = 0;
|
|
134
|
-
this.colWidths = [];
|
|
135
|
-
this.sortField = '';
|
|
136
|
-
this.sortDir = 'asc';
|
|
137
|
-
/** Whether the filter UI is visible on column headers. */
|
|
138
|
-
this.filterMode = false;
|
|
139
|
-
/** Active filters keyed by field name. */
|
|
140
|
-
this.activeFilters = new Map();
|
|
141
|
-
/** Field name of the currently open filter popup (null = closed). */
|
|
142
|
-
this.openFilterCol = null;
|
|
143
|
-
/** Filter state being edited in the open popup. */
|
|
144
|
-
this.pendingFilter = null;
|
|
145
|
-
/** Viewport-relative position for the filter popup. */
|
|
146
|
-
this.popupPos = { top: 0, left: 0 };
|
|
147
|
-
/** Current scroll offset of the scroll container — drives pagination footer. */
|
|
148
|
-
this.scrollTop = 0;
|
|
149
|
-
/** Full text shown in the TEXTBLOCK expand modal (null = closed). */
|
|
150
|
-
this.textblockModal = null;
|
|
151
|
-
/** Aggregation totals received from the host via setAggregations(). Null = not yet loaded. */
|
|
152
|
-
this.aggregations = null;
|
|
153
|
-
/** Whether the view switcher dropdown is open. */
|
|
154
|
-
this.viewSwitcherOpen = false;
|
|
155
|
-
this.handleScroll = (e) => {
|
|
156
|
-
const scroller = e.currentTarget;
|
|
157
|
-
const scrollTop = scroller.scrollTop;
|
|
158
|
-
const total = this.totalElements;
|
|
159
|
-
const visStart = Math.floor(scrollTop / this.rowHeight);
|
|
160
|
-
const visEnd = Math.min(visStart + this.visibleCount(), total - 1);
|
|
161
|
-
this.scrollTop = scrollTop;
|
|
162
|
-
this.renderStart = Math.max(0, visStart - BUFFER);
|
|
163
|
-
this.renderEnd = Math.min(total - 1, visEnd + BUFFER);
|
|
164
|
-
this.requestPagesForWindow(this.renderStart, this.renderEnd);
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
// ── Prop watchers ─────────────────────────────────────────────────────────
|
|
168
|
-
/** Clamp renderEnd when totalElements shrinks (e.g. after a filter is applied). */
|
|
169
|
-
totalElementsChanged(newVal) {
|
|
170
|
-
this.renderEnd = Math.min(this.renderEnd, Math.max(0, newVal - 1));
|
|
171
|
-
}
|
|
172
|
-
// ── Public API ─────────────────────────────────────────────────────────────
|
|
173
|
-
/**
|
|
174
|
-
* Initialise (or reset) the virtual scroll.
|
|
175
|
-
* Call after setting all props and registering the mrdLoadPage listener,
|
|
176
|
-
* but before calling setPage(0, rows).
|
|
177
|
-
*/
|
|
178
|
-
async init() {
|
|
179
|
-
var _a;
|
|
180
|
-
if (this.debounceTimer !== null) {
|
|
181
|
-
clearTimeout(this.debounceTimer);
|
|
182
|
-
this.debounceTimer = null;
|
|
183
|
-
}
|
|
184
|
-
this.pendingPages.clear();
|
|
185
|
-
this.loadedPages = new Map();
|
|
186
|
-
this.requestedPages = new Set();
|
|
187
|
-
this.colWidths = [];
|
|
188
|
-
if (this.defaultSort) {
|
|
189
|
-
const parts = this.defaultSort.split(',');
|
|
190
|
-
this.sortField = parts[0].trim();
|
|
191
|
-
this.sortDir = ((_a = parts[1]) === null || _a === void 0 ? void 0 : _a.trim()) === 'desc' ? 'desc' : 'asc';
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
this.sortField = '';
|
|
195
|
-
this.sortDir = 'asc';
|
|
196
|
-
}
|
|
197
|
-
this.scrollTop = 0;
|
|
198
|
-
this.renderStart = 0;
|
|
199
|
-
// No BUFFER on init — only request what fits the visible area (page 0).
|
|
200
|
-
// BUFFER is applied during scroll to pre-fetch the next page proactively.
|
|
201
|
-
this.renderEnd = Math.max(0, Math.min(this.visibleCount() - 1, this.totalElements - 1));
|
|
202
|
-
const scroller = this.el.querySelector('.mrd-table__scroll');
|
|
203
|
-
if (scroller)
|
|
204
|
-
scroller.scrollTop = 0;
|
|
205
|
-
this.aggregations = null;
|
|
206
|
-
this.emitLoadAggregations();
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Inject the rows for a given page (0-based).
|
|
210
|
-
* Creates a new Map reference so Stencil detects the state change.
|
|
211
|
-
*
|
|
212
|
-
* When the page contains fewer rows than pageSize it is the last page.
|
|
213
|
-
* renderEnd is clamped immediately so no loading-placeholder rows appear
|
|
214
|
-
* beyond the actual data — without requiring the host to update totalElements.
|
|
215
|
-
*/
|
|
216
|
-
async setPage(pageNumber, rows) {
|
|
217
|
-
if (rows.length < this.pageSize) {
|
|
218
|
-
// lastRowIdx is -1 when the page is empty; clamp renderEnd to -1 so the
|
|
219
|
-
// render loop does not execute and no shimmer rows appear.
|
|
220
|
-
const lastRowIdx = pageNumber * this.pageSize + rows.length - 1;
|
|
221
|
-
this.renderEnd = Math.min(this.renderEnd, lastRowIdx);
|
|
222
|
-
}
|
|
223
|
-
const next = new Map(this.loadedPages);
|
|
224
|
-
next.set(pageNumber, rows);
|
|
225
|
-
this.loadedPages = next;
|
|
226
|
-
}
|
|
227
|
-
/** Inject aggregation totals returned by the /aggregations endpoint. */
|
|
228
|
-
async setAggregations(data) {
|
|
229
|
-
this.aggregations = data;
|
|
230
|
-
}
|
|
231
|
-
// ── Lifecycle ──────────────────────────────────────────────────────────────
|
|
232
|
-
disconnectedCallback() {
|
|
233
|
-
if (this.outsideClickHandler) {
|
|
234
|
-
document.removeEventListener('click', this.outsideClickHandler);
|
|
235
|
-
this.outsideClickHandler = null;
|
|
236
|
-
}
|
|
237
|
-
if (this.viewSwitcherClickHandler) {
|
|
238
|
-
document.removeEventListener('click', this.viewSwitcherClickHandler);
|
|
239
|
-
this.viewSwitcherClickHandler = null;
|
|
240
|
-
}
|
|
241
|
-
if (this.keydownHandler) {
|
|
242
|
-
document.removeEventListener('keydown', this.keydownHandler);
|
|
243
|
-
this.keydownHandler = null;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
componentDidRender() {
|
|
247
|
-
if (this.colWidths.length === 0 && this.loadedPages.size > 0 && this.totalElements > 0) {
|
|
248
|
-
const ths = this.el.querySelectorAll('.mrd-table__header');
|
|
249
|
-
if (ths.length > 0) {
|
|
250
|
-
this.colWidths = Array.from(ths).map(th => th.offsetWidth);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// ── Paging / scroll helpers ────────────────────────────────────────────────
|
|
255
|
-
visibleCount() {
|
|
256
|
-
return Math.ceil(this.tableHeight / this.rowHeight);
|
|
257
|
-
}
|
|
258
|
-
sortParam() {
|
|
259
|
-
if (!this.sortField)
|
|
260
|
-
return '';
|
|
261
|
-
return this.sortDir === 'desc' ? `${this.sortField},desc` : this.sortField;
|
|
262
|
-
}
|
|
263
|
-
colName(col) {
|
|
264
|
-
var _a, _b, _c, _d;
|
|
265
|
-
return (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
|
|
266
|
-
}
|
|
267
|
-
colDataType(col) {
|
|
268
|
-
var _a, _b;
|
|
269
|
-
if (col.type === 'RELATION')
|
|
270
|
-
return 'RELATION';
|
|
271
|
-
return (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : 'TEXT';
|
|
272
|
-
}
|
|
273
|
-
// ── Aggregation helpers ────────────────────────────────────────────────────
|
|
274
|
-
buildAggregationParams() {
|
|
275
|
-
var _a;
|
|
276
|
-
const groups = { sum: [], avg: [], count: [] };
|
|
277
|
-
for (const col of this.columns) {
|
|
278
|
-
if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate))
|
|
279
|
-
continue;
|
|
280
|
-
const fn = col.field.aggregate.toLowerCase();
|
|
281
|
-
if (fn in groups)
|
|
282
|
-
groups[fn].push(col.field.name);
|
|
283
|
-
}
|
|
284
|
-
const params = {};
|
|
285
|
-
if (groups.sum.length)
|
|
286
|
-
params.sum = groups.sum;
|
|
287
|
-
if (groups.avg.length)
|
|
288
|
-
params.avg = groups.avg;
|
|
289
|
-
if (groups.count.length)
|
|
290
|
-
params.count = groups.count;
|
|
291
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
292
|
-
}
|
|
293
|
-
emitLoadAggregations() {
|
|
294
|
-
const params = this.buildAggregationParams();
|
|
295
|
-
if (params)
|
|
296
|
-
this.mrdLoadAggregations.emit(params);
|
|
297
|
-
}
|
|
298
|
-
renderAggregationValue(col) {
|
|
299
|
-
var _a, _b;
|
|
300
|
-
if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate) || !this.aggregations)
|
|
301
|
-
return '';
|
|
302
|
-
const fn = col.field.aggregate.toLowerCase();
|
|
303
|
-
const val = (_b = this.aggregations[fn]) === null || _b === void 0 ? void 0 : _b[col.field.name];
|
|
304
|
-
if (val == null)
|
|
305
|
-
return '';
|
|
306
|
-
const dt = col.field.dataType;
|
|
307
|
-
if (dt === 'INTEGER')
|
|
308
|
-
return formatNumber(val, this.locale, { maximumFractionDigits: 0 });
|
|
309
|
-
if (dt === 'PERCENTAGE')
|
|
310
|
-
return formatPercentage(val, this.locale);
|
|
311
|
-
if (dt === 'CURRENCY' && col.field.currencyCode)
|
|
312
|
-
return formatCurrency(val, col.field.currencyCode, this.locale);
|
|
313
|
-
return formatNumber(val, this.locale);
|
|
314
|
-
}
|
|
315
|
-
// ── Reset pagination ───────────────────────────────────────────────────────
|
|
316
|
-
/** Reset pagination state and scroll to top (used after sort or filter change). */
|
|
317
|
-
resetPages() {
|
|
318
|
-
if (this.debounceTimer !== null) {
|
|
319
|
-
clearTimeout(this.debounceTimer);
|
|
320
|
-
this.debounceTimer = null;
|
|
321
|
-
}
|
|
322
|
-
this.pendingPages.clear();
|
|
323
|
-
this.loadedPages = new Map();
|
|
324
|
-
this.requestedPages = new Set();
|
|
325
|
-
this.colWidths = [];
|
|
326
|
-
this.scrollTop = 0;
|
|
327
|
-
this.renderStart = 0;
|
|
328
|
-
// No BUFFER here — totalElements may be stale after a filter change.
|
|
329
|
-
// Only request what is visible; BUFFER kicks in during scroll as usual.
|
|
330
|
-
this.renderEnd = Math.max(0, Math.min(this.visibleCount() - 1, this.totalElements - 1));
|
|
331
|
-
const scroller = this.el.querySelector('.mrd-table__scroll');
|
|
332
|
-
if (scroller)
|
|
333
|
-
scroller.scrollTop = 0;
|
|
334
|
-
}
|
|
335
|
-
handleSortClick(col) {
|
|
336
|
-
const name = this.colName(col);
|
|
337
|
-
if (this.sortField === name) {
|
|
338
|
-
this.sortDir = this.sortDir === 'asc' ? 'desc' : 'asc';
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
this.sortField = name;
|
|
342
|
-
this.sortDir = 'asc';
|
|
343
|
-
}
|
|
344
|
-
this.resetPages();
|
|
345
|
-
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
346
|
-
}
|
|
347
|
-
applySort(col, dir) {
|
|
348
|
-
this.sortField = this.colName(col);
|
|
349
|
-
this.sortDir = dir;
|
|
350
|
-
this.resetPages();
|
|
351
|
-
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
352
|
-
}
|
|
353
|
-
emitPagesForWindow(start, end) {
|
|
354
|
-
const firstPage = Math.floor(start / this.pageSize);
|
|
355
|
-
const lastPage = Math.floor(end / this.pageSize);
|
|
356
|
-
const next = new Set(this.requestedPages);
|
|
357
|
-
let changed = false;
|
|
358
|
-
for (let p = firstPage; p <= lastPage; p++) {
|
|
359
|
-
if (!this.loadedPages.has(p) && !next.has(p)) {
|
|
360
|
-
next.add(p);
|
|
361
|
-
this.mrdLoadPage.emit({ page: p, sort: this.sortParam() });
|
|
362
|
-
changed = true;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
if (changed)
|
|
366
|
-
this.requestedPages = next;
|
|
367
|
-
}
|
|
368
|
-
getRow(i) {
|
|
369
|
-
var _a;
|
|
370
|
-
const page = this.loadedPages.get(Math.floor(i / this.pageSize));
|
|
371
|
-
return (_a = page === null || page === void 0 ? void 0 : page[i % this.pageSize]) !== null && _a !== void 0 ? _a : null;
|
|
372
|
-
}
|
|
373
|
-
requestPagesForWindow(start, end) {
|
|
374
|
-
const firstPage = Math.floor(start / this.pageSize);
|
|
375
|
-
const lastPage = Math.floor(end / this.pageSize);
|
|
376
|
-
let anyNew = false;
|
|
377
|
-
for (let p = firstPage; p <= lastPage; p++) {
|
|
378
|
-
if (!this.loadedPages.has(p) && !this.requestedPages.has(p) && !this.pendingPages.has(p)) {
|
|
379
|
-
this.pendingPages.add(p);
|
|
380
|
-
anyNew = true;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (!anyNew)
|
|
384
|
-
return;
|
|
385
|
-
if (this.debounceTimer !== null)
|
|
386
|
-
clearTimeout(this.debounceTimer);
|
|
387
|
-
this.debounceTimer = setTimeout(() => this.flushPendingPages(), REQUEST_DEBOUNCE_MS);
|
|
388
|
-
}
|
|
389
|
-
flushPendingPages() {
|
|
390
|
-
this.debounceTimer = null;
|
|
391
|
-
if (this.pendingPages.size === 0)
|
|
392
|
-
return;
|
|
393
|
-
const next = new Set(this.requestedPages);
|
|
394
|
-
let changed = false;
|
|
395
|
-
for (const page of this.pendingPages) {
|
|
396
|
-
if (this.loadedPages.has(page) || next.has(page))
|
|
397
|
-
continue;
|
|
398
|
-
const pageStart = page * this.pageSize;
|
|
399
|
-
const pageEnd = pageStart + this.pageSize - 1;
|
|
400
|
-
if (pageEnd < this.renderStart || pageStart > this.renderEnd)
|
|
401
|
-
continue;
|
|
402
|
-
next.add(page);
|
|
403
|
-
this.mrdLoadPage.emit({ page, sort: this.sortParam() });
|
|
404
|
-
changed = true;
|
|
405
|
-
}
|
|
406
|
-
this.pendingPages.clear();
|
|
407
|
-
if (changed)
|
|
408
|
-
this.requestedPages = next;
|
|
409
|
-
}
|
|
410
|
-
// ── Filter helpers ─────────────────────────────────────────────────────────
|
|
411
|
-
handleFilterToggle() {
|
|
412
|
-
this.filterMode = !this.filterMode;
|
|
413
|
-
if (!this.filterMode)
|
|
414
|
-
this.closeFilterPopup();
|
|
415
|
-
}
|
|
416
|
-
handleFilterOpen(col, e) {
|
|
417
|
-
e.stopPropagation();
|
|
418
|
-
const btn = e.currentTarget;
|
|
419
|
-
const rect = btn.getBoundingClientRect();
|
|
420
|
-
let left = rect.left;
|
|
421
|
-
if (left + POPUP_WIDTH > window.innerWidth - 8)
|
|
422
|
-
left = rect.right - POPUP_WIDTH;
|
|
423
|
-
this.popupPos = { top: rect.bottom + 4, left: Math.max(8, left) };
|
|
424
|
-
const name = this.colName(col);
|
|
425
|
-
const dataType = this.colDataType(col);
|
|
426
|
-
const existing = this.activeFilters.get(name);
|
|
427
|
-
// Set the default operator explicitly so it is present in the ColumnFilter
|
|
428
|
-
// even when the user never touches the operator dropdown.
|
|
429
|
-
const defaultOperator = (TEXT_TYPES.has(dataType) || dataType === 'RELATION')
|
|
430
|
-
? 'startsWith'
|
|
431
|
-
: undefined;
|
|
432
|
-
// For DATETIME, stored values are UTC ISO strings; convert back to local
|
|
433
|
-
// "YYYY-MM-DD" dates so the date inputs show what the user originally entered.
|
|
434
|
-
// If from and to cover the same local day it was an exact-date filter — restore
|
|
435
|
-
// to exact mode so the user sees the single-date input again.
|
|
436
|
-
if (dataType === 'DATETIME' && existing && existing.operator !== 'isEmpty' && existing.operator !== 'isNotEmpty') {
|
|
437
|
-
const display = Object.assign({}, existing);
|
|
438
|
-
if (typeof display.from === 'string' && display.from)
|
|
439
|
-
display.from = this.utcISOToLocalDate(display.from);
|
|
440
|
-
if (typeof display.to === 'string' && display.to)
|
|
441
|
-
display.to = this.utcISOToLocalDateExclusiveEnd(display.to);
|
|
442
|
-
if (display.from && display.to && display.from === display.to) {
|
|
443
|
-
this.pendingFilter = Object.assign(Object.assign({}, display), { value: display.from, from: undefined, to: undefined });
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
this.pendingFilter = display;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
this.pendingFilter = existing ? Object.assign({}, existing) : { field: name, dataType, operator: defaultOperator };
|
|
451
|
-
}
|
|
452
|
-
this.openFilterCol = name;
|
|
453
|
-
// Close on outside click — re-register to replace any stale handler
|
|
454
|
-
if (this.outsideClickHandler)
|
|
455
|
-
document.removeEventListener('click', this.outsideClickHandler);
|
|
456
|
-
this.outsideClickHandler = (ev) => {
|
|
457
|
-
const popup = this.el.querySelector('.mrd-table__filter-popup');
|
|
458
|
-
if (popup && !popup.contains(ev.target))
|
|
459
|
-
this.closeFilterPopup();
|
|
460
|
-
};
|
|
461
|
-
document.addEventListener('click', this.outsideClickHandler);
|
|
462
|
-
}
|
|
463
|
-
closeFilterPopup() {
|
|
464
|
-
this.openFilterCol = null;
|
|
465
|
-
this.pendingFilter = null;
|
|
466
|
-
if (this.outsideClickHandler) {
|
|
467
|
-
document.removeEventListener('click', this.outsideClickHandler);
|
|
468
|
-
this.outsideClickHandler = null;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
openTextblockModal(text) {
|
|
472
|
-
this.textblockModal = text;
|
|
473
|
-
if (this.keydownHandler)
|
|
474
|
-
document.removeEventListener('keydown', this.keydownHandler);
|
|
475
|
-
this.keydownHandler = (ev) => {
|
|
476
|
-
if (ev.key === 'Escape')
|
|
477
|
-
this.closeTextblockModal();
|
|
478
|
-
};
|
|
479
|
-
document.addEventListener('keydown', this.keydownHandler);
|
|
480
|
-
}
|
|
481
|
-
closeTextblockModal() {
|
|
482
|
-
this.textblockModal = null;
|
|
483
|
-
if (this.keydownHandler) {
|
|
484
|
-
document.removeEventListener('keydown', this.keydownHandler);
|
|
485
|
-
this.keydownHandler = null;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
setPending(key, val) {
|
|
489
|
-
this.pendingFilter = Object.assign(Object.assign({}, this.pendingFilter), { [key]: val });
|
|
490
|
-
}
|
|
491
|
-
togglePendingValue(key, checked) {
|
|
492
|
-
var _a, _b;
|
|
493
|
-
const current = (_b = (_a = this.pendingFilter) === null || _a === void 0 ? void 0 : _a.values) !== null && _b !== void 0 ? _b : [];
|
|
494
|
-
this.pendingFilter = Object.assign(Object.assign({}, this.pendingFilter), { values: checked ? [...current, key] : current.filter(k => k !== key) });
|
|
495
|
-
}
|
|
496
|
-
filterHasValue(f) {
|
|
497
|
-
if (f.operator === 'isEmpty' || f.operator === 'isNotEmpty')
|
|
498
|
-
return true;
|
|
499
|
-
if (f.values !== undefined && f.values.length > 0)
|
|
500
|
-
return true;
|
|
501
|
-
if (f.value != null && f.value !== '')
|
|
502
|
-
return true;
|
|
503
|
-
if (typeof f.value === 'boolean')
|
|
504
|
-
return true;
|
|
505
|
-
if (f.from != null && f.from !== '')
|
|
506
|
-
return true;
|
|
507
|
-
if (f.to != null && f.to !== '')
|
|
508
|
-
return true;
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
// Convert a local "YYYY-MM-DD" date string to the UTC ISO string at the
|
|
512
|
-
// start of that local day (midnight). new Date(y, m, d) uses local time.
|
|
513
|
-
dateLocalToUTCStart(dateStr) {
|
|
514
|
-
if (!dateStr)
|
|
515
|
-
return dateStr;
|
|
516
|
-
const [year, month, day] = dateStr.split('-').map(Number);
|
|
517
|
-
return new Date(year, month - 1, day).toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
518
|
-
}
|
|
519
|
-
// Start of the day AFTER the given local date (exclusive range end).
|
|
520
|
-
dateLocalToUTCEndExclusive(dateStr) {
|
|
521
|
-
if (!dateStr)
|
|
522
|
-
return dateStr;
|
|
523
|
-
const [year, month, day] = dateStr.split('-').map(Number);
|
|
524
|
-
return new Date(year, month - 1, day + 1).toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
525
|
-
}
|
|
526
|
-
// Convert a stored UTC ISO string back to the local "YYYY-MM-DD" date.
|
|
527
|
-
utcISOToLocalDate(utcStr) {
|
|
528
|
-
if (!utcStr)
|
|
529
|
-
return utcStr;
|
|
530
|
-
const d = new Date(utcStr);
|
|
531
|
-
if (isNaN(d.getTime()))
|
|
532
|
-
return utcStr;
|
|
533
|
-
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
534
|
-
}
|
|
535
|
-
// The stored "to" value is the exclusive end (midnight of the next day).
|
|
536
|
-
// Subtract one day to recover the local date the user entered.
|
|
537
|
-
utcISOToLocalDateExclusiveEnd(utcStr) {
|
|
538
|
-
if (!utcStr)
|
|
539
|
-
return utcStr;
|
|
540
|
-
const d = new Date(utcStr);
|
|
541
|
-
if (isNaN(d.getTime()))
|
|
542
|
-
return utcStr;
|
|
543
|
-
d.setDate(d.getDate() - 1);
|
|
544
|
-
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
545
|
-
}
|
|
546
|
-
applyFilter() {
|
|
547
|
-
const f = this.pendingFilter;
|
|
548
|
-
if (!(f === null || f === void 0 ? void 0 : f.field)) {
|
|
549
|
-
this.closeFilterPopup();
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
// For DATETIME fields the user enters local dates; convert to UTC ISO strings.
|
|
553
|
-
// Exact date → range covering the full local day (from = midnight, to = next midnight).
|
|
554
|
-
// "to" is always the exclusive end (midnight of the next local day).
|
|
555
|
-
let normalized = Object.assign({}, f);
|
|
556
|
-
if (f.dataType === 'DATETIME' && f.operator !== 'isEmpty' && f.operator !== 'isNotEmpty') {
|
|
557
|
-
if (typeof normalized.value === 'string' && normalized.value) {
|
|
558
|
-
normalized.from = this.dateLocalToUTCStart(normalized.value);
|
|
559
|
-
normalized.to = this.dateLocalToUTCEndExclusive(normalized.value);
|
|
560
|
-
normalized.value = undefined;
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
if (typeof normalized.from === 'string' && normalized.from)
|
|
564
|
-
normalized.from = this.dateLocalToUTCStart(normalized.from);
|
|
565
|
-
if (typeof normalized.to === 'string' && normalized.to)
|
|
566
|
-
normalized.to = this.dateLocalToUTCEndExclusive(normalized.to);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
const next = new Map(this.activeFilters);
|
|
570
|
-
if (this.filterHasValue(normalized)) {
|
|
571
|
-
next.set(normalized.field, normalized);
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
next.delete(normalized.field);
|
|
575
|
-
}
|
|
576
|
-
this.activeFilters = next;
|
|
577
|
-
this.closeFilterPopup();
|
|
578
|
-
this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
|
|
579
|
-
this.aggregations = null;
|
|
580
|
-
this.emitLoadAggregations();
|
|
581
|
-
if (this.totalElements > 0) {
|
|
582
|
-
this.resetPages();
|
|
583
|
-
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
clearFilter() {
|
|
587
|
-
const name = this.openFilterCol;
|
|
588
|
-
const next = new Map(this.activeFilters);
|
|
589
|
-
if (name)
|
|
590
|
-
next.delete(name);
|
|
591
|
-
this.activeFilters = next;
|
|
592
|
-
this.closeFilterPopup();
|
|
593
|
-
this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
|
|
594
|
-
this.aggregations = null;
|
|
595
|
-
this.emitLoadAggregations();
|
|
596
|
-
if (this.totalElements > 0) {
|
|
597
|
-
this.resetPages();
|
|
598
|
-
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
clearAllFilters() {
|
|
602
|
-
this.activeFilters = new Map();
|
|
603
|
-
this.mrdFilter.emit({ filters: [] });
|
|
604
|
-
this.aggregations = null;
|
|
605
|
-
this.emitLoadAggregations();
|
|
606
|
-
if (this.totalElements > 0) {
|
|
607
|
-
this.resetPages();
|
|
608
|
-
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
// ── View switcher ──────────────────────────────────────────────────────────
|
|
612
|
-
openViewSwitcher() {
|
|
613
|
-
this.viewSwitcherOpen = true;
|
|
614
|
-
if (this.viewSwitcherClickHandler)
|
|
615
|
-
document.removeEventListener('click', this.viewSwitcherClickHandler);
|
|
616
|
-
this.viewSwitcherClickHandler = (ev) => {
|
|
617
|
-
const wrapper = this.el.querySelector('.mrd-table__view-switcher');
|
|
618
|
-
if (wrapper && !wrapper.contains(ev.target))
|
|
619
|
-
this.closeViewSwitcher();
|
|
620
|
-
};
|
|
621
|
-
document.addEventListener('click', this.viewSwitcherClickHandler);
|
|
622
|
-
}
|
|
623
|
-
closeViewSwitcher() {
|
|
624
|
-
this.viewSwitcherOpen = false;
|
|
625
|
-
if (this.viewSwitcherClickHandler) {
|
|
626
|
-
document.removeEventListener('click', this.viewSwitcherClickHandler);
|
|
627
|
-
this.viewSwitcherClickHandler = null;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
handleViewSwitch(view) {
|
|
631
|
-
this.closeViewSwitcher();
|
|
632
|
-
this.mrdSwitchView.emit({ name: view.name, class: view.class });
|
|
633
|
-
}
|
|
634
|
-
renderViewSwitcher() {
|
|
635
|
-
return (h("div", { class: "mrd-table__view-switcher" }, h("button", { class: `mrd-table__view-switcher-btn${this.viewSwitcherOpen ? ' mrd-table__view-switcher-btn--open' : ''}`, "aria-label": this.viewLabel, onClick: (e) => {
|
|
636
|
-
e.stopPropagation();
|
|
637
|
-
this.viewSwitcherOpen ? this.closeViewSwitcher() : this.openViewSwitcher();
|
|
638
|
-
} }, h("svg", { class: "mrd-table__view-switcher-chevron", viewBox: "0 0 24 24", "aria-hidden": "true" }, h("path", { fill: "currentColor", d: "M7 10l5 5 5-5z" }))), this.viewSwitcherOpen && (h("div", { class: "mrd-table__view-switcher-dropdown", onClick: (e) => e.stopPropagation() }, this.alternativeViews.map(view => {
|
|
639
|
-
var _a;
|
|
640
|
-
return (h("button", { class: "mrd-table__view-switcher-item", onClick: () => this.handleViewSwitch(view) }, (_a = view.label) !== null && _a !== void 0 ? _a : view.name));
|
|
641
|
-
})))));
|
|
642
|
-
}
|
|
643
|
-
// ── Render: toolbar ────────────────────────────────────────────────────────
|
|
644
|
-
renderToolbar() {
|
|
645
|
-
var _a, _b;
|
|
646
|
-
const filterCount = this.activeFilters.size;
|
|
647
|
-
const hasActions = ((_a = this.actions) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
648
|
-
const hasViewSwitcher = !!this.viewLabel && ((_b = this.alternativeViews) === null || _b === void 0 ? void 0 : _b.length) > 0;
|
|
649
|
-
return (h("div", { class: "mrd-table__toolbar" }, h("div", { class: "mrd-table__toolbar-left" }, h("button", { class: `mrd-table__action mrd-table__action--secondary mrd-table__filter-toggle${this.filterMode ? ' mrd-table__filter-toggle--active' : ''}`, onClick: () => this.handleFilterToggle() }, h("svg", { class: "mrd-table__action-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, h("path", { fill: "currentColor", d: "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" })), filterCount > 0 && h("span", { class: "mrd-table__filter-badge" }, filterCount), h("span", { class: "mrd-table__action-tooltip" }, this.filterMode ? t('table_filter_hide', this.locale) : t('table_filter', this.locale), filterCount > 0 ? ` (${filterCount} ${t('table_filter_active', this.locale)})` : '')), filterCount > 0 && (h("button", { class: "mrd-table__action mrd-table__action--secondary", onClick: () => this.clearAllFilters() }, h("svg", { class: "mrd-table__action-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, h("path", { fill: "currentColor", d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" })), h("span", { class: "mrd-table__action-tooltip" }, t('table_filter_clear_all', this.locale))))), hasViewSwitcher && (h("div", { class: "mrd-table__toolbar-center" }, h("span", { class: "mrd-table__view-title" }, this.viewLabel), this.renderViewSwitcher())), hasActions && (h("div", { class: "mrd-table__toolbar-right" }, this.actions.map(a => {
|
|
650
|
-
var _a;
|
|
651
|
-
return (h("button", { class: `mrd-table__action mrd-table__action--${(_a = a.variant) !== null && _a !== void 0 ? _a : 'secondary'}`, disabled: a.disabled, onClick: () => this.mrdAction.emit({ action: a.action }) }, a.icon
|
|
652
|
-
? h("svg", { class: "mrd-table__action-icon", "aria-hidden": "true" }, h("use", { href: a.icon }))
|
|
653
|
-
: a.label, h("span", { class: "mrd-table__action-tooltip" }, a.label)));
|
|
654
|
-
})))));
|
|
655
|
-
}
|
|
656
|
-
// ── Render: filter popup ───────────────────────────────────────────────────
|
|
657
|
-
renderFilterEditor(col) {
|
|
658
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
659
|
-
const pf = (_a = this.pendingFilter) !== null && _a !== void 0 ? _a : {};
|
|
660
|
-
const dataType = this.colDataType(col);
|
|
661
|
-
if (NO_FILTER_TYPES.has(dataType)) {
|
|
662
|
-
return h("p", { class: "mrd-table__filter-no-support" }, t('filter_no_support', this.locale));
|
|
663
|
-
}
|
|
664
|
-
if (dataType === 'BOOLEAN') {
|
|
665
|
-
const boolOp = pf.operator;
|
|
666
|
-
const noValueOp = boolOp === 'isEmpty' || boolOp === 'isNotEmpty';
|
|
667
|
-
return (h("div", { class: "mrd-table__filter-radio-group" }, [
|
|
668
|
-
{ labelKey: 'filter_all', value: null },
|
|
669
|
-
{ labelKey: 'yes', value: true },
|
|
670
|
-
{ labelKey: 'no', value: false },
|
|
671
|
-
].map(opt => (h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: !noValueOp && pf.value === opt.value, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined, value: opt.value }); } }), t(opt.labelKey, this.locale)))), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isEmpty', value: undefined }); } }), t('filter_is_empty', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isNotEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isNotEmpty', value: undefined }); } }), t('filter_is_not_empty', this.locale))));
|
|
672
|
-
}
|
|
673
|
-
if (dataType === 'LIST') {
|
|
674
|
-
const items = (_c = (_b = col.field) === null || _b === void 0 ? void 0 : _b.listItems) !== null && _c !== void 0 ? _c : [];
|
|
675
|
-
const selected = (_d = pf.values) !== null && _d !== void 0 ? _d : [];
|
|
676
|
-
return (h("div", { class: "mrd-table__filter-list" }, h("div", { class: "mrd-table__filter-list-controls" }, h("button", { class: "mrd-table__filter-list-btn", onClick: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { values: items.map(i => i.key) }); } }, t('filter_select_all', this.locale)), h("button", { class: "mrd-table__filter-list-btn", onClick: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { values: [] }); } }, t('filter_select_none', this.locale))), items.map(item => (h("label", { class: "mrd-table__filter-checkbox-label" }, h("input", { type: "checkbox", checked: selected.includes(item.key), onChange: (e) => this.togglePendingValue(item.key, e.target.checked) }), item.label)))));
|
|
677
|
-
}
|
|
678
|
-
if (TEXT_TYPES.has(dataType) || dataType === 'RELATION') {
|
|
679
|
-
const op = (_e = pf.operator) !== null && _e !== void 0 ? _e : 'startsWith';
|
|
680
|
-
const noInput = op === 'isEmpty' || op === 'isNotEmpty';
|
|
681
|
-
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => this.setPending('operator', e.target.value) }, [
|
|
682
|
-
{ val: 'startsWith', labelKey: 'filter_starts_with' },
|
|
683
|
-
{ val: 'equals', labelKey: 'filter_equals' },
|
|
684
|
-
{ val: 'isEmpty', labelKey: 'filter_is_empty' },
|
|
685
|
-
{ val: 'isNotEmpty', labelKey: 'filter_is_not_empty' },
|
|
686
|
-
].map(o => h("option", { value: o.val, selected: op === o.val }, t(o.labelKey, this.locale)))), !noInput && (h("input", { type: "text", class: "mrd-table__filter-input", value: String((_f = pf.value) !== null && _f !== void 0 ? _f : ''), placeholder: t('filter_search_value', this.locale), onInput: (e) => this.setPending('value', e.target.value) }))));
|
|
687
|
-
}
|
|
688
|
-
if (NUMERIC_TYPES.has(dataType)) {
|
|
689
|
-
const numOp = pf.operator;
|
|
690
|
-
const noInput = numOp === 'isEmpty' || numOp === 'isNotEmpty';
|
|
691
|
-
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
692
|
-
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
693
|
-
const val = e.target.value;
|
|
694
|
-
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
695
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
699
|
-
}
|
|
700
|
-
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: numOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: numOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: "number", class: "mrd-table__filter-input", value: pf.value != null ? String(pf.value) : '', onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range" }, h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("span", { class: "mrd-table__filter-range-sep" }, "\u2013"), h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
701
|
-
}
|
|
702
|
-
if (dataType === 'DATETIME') {
|
|
703
|
-
const dtOp = pf.operator;
|
|
704
|
-
const noInput = dtOp === 'isEmpty' || dtOp === 'isNotEmpty';
|
|
705
|
-
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
706
|
-
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
707
|
-
const val = e.target.value;
|
|
708
|
-
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
709
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
713
|
-
}
|
|
714
|
-
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: dtOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: dtOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: "date", class: "mrd-table__filter-input", value: String((_g = pf.value) !== null && _g !== void 0 ? _g : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range mrd-table__filter-range--stacked" }, h("label", { class: "mrd-table__filter-range-label" }, t('filter_from', this.locale)), h("input", { type: "date", class: "mrd-table__filter-input", value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("label", { class: "mrd-table__filter-range-label" }, t('filter_to', this.locale)), h("input", { type: "date", class: "mrd-table__filter-input", value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
715
|
-
}
|
|
716
|
-
if (DATE_TYPES.has(dataType)) {
|
|
717
|
-
const inputType = dataType === 'DATE' ? 'date' : 'time';
|
|
718
|
-
const dtdOp = pf.operator;
|
|
719
|
-
const noInput = dtdOp === 'isEmpty' || dtdOp === 'isNotEmpty';
|
|
720
|
-
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
721
|
-
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
722
|
-
const val = e.target.value;
|
|
723
|
-
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
724
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
728
|
-
}
|
|
729
|
-
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: dtdOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: dtdOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: inputType, class: "mrd-table__filter-input", value: String((_h = pf.value) !== null && _h !== void 0 ? _h : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range" }, h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
730
|
-
}
|
|
731
|
-
return null;
|
|
732
|
-
}
|
|
733
|
-
renderFilterPopup() {
|
|
734
|
-
var _a, _b, _c, _d;
|
|
735
|
-
if (!this.openFilterCol || !this.pendingFilter)
|
|
736
|
-
return null;
|
|
737
|
-
const col = this.columns.find(c => this.colName(c) === this.openFilterCol);
|
|
738
|
-
if (!col)
|
|
739
|
-
return null;
|
|
740
|
-
const label = (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : this.openFilterCol;
|
|
741
|
-
const sortActive = this.sortField === this.openFilterCol;
|
|
742
|
-
return (h("div", { class: "mrd-table__filter-popup", style: { top: `${this.popupPos.top}px`, left: `${this.popupPos.left}px` }, onClick: (e) => e.stopPropagation() }, h("div", { class: "mrd-table__filter-popup-header" }, h("span", { class: "mrd-table__filter-popup-title" }, label), h("button", { class: "mrd-table__filter-close", onClick: () => this.closeFilterPopup() }, "\u2715")), h("div", { class: "mrd-table__filter-section" }, h("div", { class: "mrd-table__filter-section-label" }, t('filter_sorting', this.locale)), h("div", { class: "mrd-table__filter-sort-buttons" }, h("button", { class: `mrd-table__filter-sort-btn${sortActive && this.sortDir === 'asc' ? ' mrd-table__filter-sort-btn--active' : ''}`, onClick: () => this.applySort(col, 'asc') }, "\u25B2 ", t('filter_ascending', this.locale)), h("button", { class: `mrd-table__filter-sort-btn${sortActive && this.sortDir === 'desc' ? ' mrd-table__filter-sort-btn--active' : ''}`, onClick: () => this.applySort(col, 'desc') }, "\u25BC ", t('filter_descending', this.locale)))), h("div", { class: "mrd-table__filter-divider" }), h("div", { class: "mrd-table__filter-section" }, h("div", { class: "mrd-table__filter-section-label" }, t('filter_section', this.locale)), this.renderFilterEditor(col)), h("div", { class: "mrd-table__filter-popup-footer" }, h("button", { class: "mrd-table__filter-btn mrd-table__filter-btn--clear", onClick: () => this.clearFilter() }, t('filter_clear', this.locale)), h("button", { class: "mrd-table__filter-btn mrd-table__filter-btn--apply", onClick: () => this.applyFilter() }, t('filter_apply', this.locale)))));
|
|
743
|
-
}
|
|
744
|
-
// ── Render: footer ────────────────────────────────────────────────────────
|
|
745
|
-
renderFooter(rowCount, effectiveTotal) {
|
|
746
|
-
const total = this.totalElements;
|
|
747
|
-
// Non-paginated mode: show plain row count
|
|
748
|
-
if (total === 0) {
|
|
749
|
-
const count = rowCount !== null && rowCount !== void 0 ? rowCount : 0;
|
|
750
|
-
if (count === 0)
|
|
751
|
-
return null;
|
|
752
|
-
return (h("div", { class: "mrd-table__footer" }, count, " ", t('table_of', this.locale), " ", count));
|
|
753
|
-
}
|
|
754
|
-
// Paginated mode: only show once page 0 has loaded (avoids stale total during filter reset)
|
|
755
|
-
if (!this.loadedPages.has(0))
|
|
756
|
-
return null;
|
|
757
|
-
// Use effectiveTotal (derived from actual page lengths) so the counter
|
|
758
|
-
// is correct even when the host has not yet updated totalElements.
|
|
759
|
-
const displayTotal = effectiveTotal !== null && effectiveTotal !== void 0 ? effectiveTotal : total;
|
|
760
|
-
// Compute from/to independently so partial rows at top/bottom are included.
|
|
761
|
-
const from = Math.min(Math.floor(this.scrollTop / this.rowHeight) + 1, displayTotal);
|
|
762
|
-
const to = Math.min(Math.ceil((this.scrollTop + this.tableHeight) / this.rowHeight), displayTotal);
|
|
763
|
-
return (h("div", { class: "mrd-table__footer" }, from, "\u2013", to, " ", t('table_of', this.locale), " ", displayTotal));
|
|
764
|
-
}
|
|
765
|
-
// ── Render: cell ──────────────────────────────────────────────────────────
|
|
766
|
-
renderCell(col, row) {
|
|
767
|
-
var _a, _b, _c, _d;
|
|
768
|
-
const numericTypes = new Set(['INTEGER', 'DECIMAL', 'PERCENTAGE', 'CURRENCY']);
|
|
769
|
-
const dataType = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : '';
|
|
770
|
-
const isNumeric = col.type === 'FIELD' && numericTypes.has(dataType);
|
|
771
|
-
const isFile = col.type === 'FIELD' && (dataType === 'FILE' || dataType === 'IMAGE');
|
|
772
|
-
if (isFile) {
|
|
773
|
-
const name = (_d = (_c = col.field) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
|
|
774
|
-
const fileVal = row === null || row === void 0 ? void 0 : row[name];
|
|
775
|
-
const href = fileVal === null || fileVal === void 0 ? void 0 : fileVal.href;
|
|
776
|
-
const fileName = fileVal === null || fileVal === void 0 ? void 0 : fileVal.fileName;
|
|
777
|
-
return (h("td", { class: "mrd-table__cell" }, href && fileName ? (h("button", { class: "mrd-table__file-btn", title: fileName, onClick: (e) => {
|
|
778
|
-
e.stopPropagation();
|
|
779
|
-
this.mrdDownload.emit({ href, fileName });
|
|
780
|
-
} }, h("svg", { class: "mrd-table__file-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, h("path", { fill: "currentColor", d: "M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13zm-3 8l-3-3 1.41-1.41L10 14.17l4.59-4.58L16 11l-6 6z" })), t('download', this.locale))) : ''));
|
|
781
|
-
}
|
|
782
|
-
const TEXTBLOCK_MAX = 200;
|
|
783
|
-
if (dataType === 'TEXTBLOCK') {
|
|
784
|
-
const full = CellRenderer.render(col, row, this.locale);
|
|
785
|
-
if (full.length <= TEXTBLOCK_MAX) {
|
|
786
|
-
return h("td", { class: "mrd-table__cell" }, full);
|
|
787
|
-
}
|
|
788
|
-
const preview = full.slice(0, TEXTBLOCK_MAX) + '…';
|
|
789
|
-
return (h("td", { class: "mrd-table__cell" }, preview, h("button", { class: "mrd-table__textblock-btn", onClick: (e) => { e.stopPropagation(); this.openTextblockModal(full); }, "aria-label": t('textblock_show_more', this.locale) }, "\u22EF")));
|
|
790
|
-
}
|
|
791
|
-
const value = CellRenderer.render(col, row, this.locale);
|
|
792
|
-
return (h("td", { class: `mrd-table__cell${isNumeric ? ' mrd-table__cell--numeric' : ''}` }, value));
|
|
793
|
-
}
|
|
794
|
-
// ── Render: totals row ────────────────────────────────────────────────────
|
|
795
|
-
renderTotalsRow() {
|
|
796
|
-
if (!this.aggregations)
|
|
797
|
-
return null;
|
|
798
|
-
if (!this.columns.some(c => { var _a; return c.type === 'FIELD' && ((_a = c.field) === null || _a === void 0 ? void 0 : _a.aggregate); }))
|
|
799
|
-
return null;
|
|
800
|
-
return (h("tfoot", null, h("tr", { class: "mrd-table__totals-row" }, this.columns.map(col => {
|
|
801
|
-
var _a, _b;
|
|
802
|
-
const val = this.renderAggregationValue(col);
|
|
803
|
-
const isNumeric = col.type === 'FIELD' && NUMERIC_TYPES.has((_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : '');
|
|
804
|
-
return (h("td", { class: `mrd-table__totals-cell${isNumeric ? ' mrd-table__totals-cell--numeric' : ''}` }, val));
|
|
805
|
-
}))));
|
|
806
|
-
}
|
|
807
|
-
// ── Render ─────────────────────────────────────────────────────────────────
|
|
808
|
-
render() {
|
|
809
|
-
var _a, _b, _c;
|
|
810
|
-
if (!((_a = this.columns) === null || _a === void 0 ? void 0 : _a.length))
|
|
811
|
-
return null;
|
|
812
|
-
// ── Non-paginated mode ──────────────────────────────────────────────────
|
|
813
|
-
if (this.totalElements === 0) {
|
|
814
|
-
return (h(Host, null, this.renderToolbar(), h("div", { class: "mrd-table" }, h("table", { class: "mrd-table__table" }, h("thead", null, h("tr", null, this.columns.map(col => {
|
|
815
|
-
var _a, _b, _c, _d;
|
|
816
|
-
const name = this.colName(col);
|
|
817
|
-
const isFiltered = this.activeFilters.has(name);
|
|
818
|
-
const cls = [
|
|
819
|
-
'mrd-table__header',
|
|
820
|
-
isFiltered ? 'mrd-table__header--filtered' : '',
|
|
821
|
-
this.filterMode ? 'mrd-table__header--sortable' : '',
|
|
822
|
-
].filter(Boolean).join(' ');
|
|
823
|
-
return (h("th", { class: cls, onClick: this.filterMode ? (e) => this.handleFilterOpen(col, e) : undefined }, h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isFiltered && this.renderFilterIcon()));
|
|
824
|
-
}))), h("tbody", null, (_b = this.rows) === null || _b === void 0 ? void 0 : _b.map((row, i) => (h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row)))))), this.renderTotalsRow()), (!this.rows || this.rows.length === 0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale)))), this.renderFooter((_c = this.rows) === null || _c === void 0 ? void 0 : _c.length), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
825
|
-
}
|
|
826
|
-
// ── Paginated / virtual-scroll mode ────────────────────────────────────
|
|
827
|
-
// Derive the authoritative row count from loaded pages:
|
|
828
|
-
// if any loaded page is shorter than pageSize it is the last page,
|
|
829
|
-
// so the true total cannot exceed (pageNum * pageSize + pageRows.length).
|
|
830
|
-
// This self-corrects without requiring the host to update totalElements.
|
|
831
|
-
let effectiveTotal = this.totalElements;
|
|
832
|
-
for (const [pageNum, pageRows] of this.loadedPages) {
|
|
833
|
-
if (pageRows.length < this.pageSize) {
|
|
834
|
-
effectiveTotal = Math.min(effectiveTotal, pageNum * this.pageSize + pageRows.length);
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
// Clamp renderEnd to what we actually know exists (-1 when empty)
|
|
838
|
-
const clampedEnd = Math.min(this.renderEnd, effectiveTotal - 1);
|
|
839
|
-
const colCount = this.columns.length;
|
|
840
|
-
const topSpacerHeight = this.renderStart * this.rowHeight;
|
|
841
|
-
const bottomSpacerHeight = Math.max(0, (effectiveTotal - 1 - clampedEnd) * this.rowHeight);
|
|
842
|
-
const tableStyle = this.colWidths.length > 0
|
|
843
|
-
? { tableLayout: 'fixed' }
|
|
844
|
-
: undefined;
|
|
845
|
-
const renderedRows = [];
|
|
846
|
-
for (let i = this.renderStart; i <= clampedEnd; i++) {
|
|
847
|
-
const row = this.getRow(i);
|
|
848
|
-
if (row === null) {
|
|
849
|
-
renderedRows.push(h("tr", { class: "mrd-table__row mrd-table__row--loading" }, h("td", { class: "mrd-table__cell--placeholder", colSpan: colCount }, h("span", { class: "mrd-table__placeholder-bar" }))));
|
|
850
|
-
}
|
|
851
|
-
else {
|
|
852
|
-
renderedRows.push(h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row))));
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
return (h(Host, null, this.renderToolbar(), h("div", { class: "mrd-table__scroll", style: { height: `${this.tableHeight}px` }, onScroll: this.handleScroll }, h("table", { class: "mrd-table__table", style: tableStyle }, h("thead", null, h("tr", null, this.columns.map((col, idx) => {
|
|
856
|
-
var _a, _b, _c, _d;
|
|
857
|
-
const name = this.colName(col);
|
|
858
|
-
const isActive = this.sortField === name;
|
|
859
|
-
const isFiltered = this.activeFilters.has(name);
|
|
860
|
-
const cls = [
|
|
861
|
-
'mrd-table__header',
|
|
862
|
-
'mrd-table__header--sortable',
|
|
863
|
-
isActive ? `mrd-table__header--sorted-${this.sortDir}` : '',
|
|
864
|
-
isFiltered ? 'mrd-table__header--filtered' : '',
|
|
865
|
-
].filter(Boolean).join(' ');
|
|
866
|
-
return (h("th", { class: cls, style: this.colWidths[idx] ? { width: `${this.colWidths[idx]}px` } : undefined, onClick: (e) => this.filterMode ? this.handleFilterOpen(col, e) : this.handleSortClick(col) }, h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isActive && (h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, this.sortDir === 'asc' ? '▲' : '▼')), !isActive && !this.filterMode && (h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, "\u21C5")), isFiltered && this.renderFilterIcon()));
|
|
867
|
-
}))), h("tbody", null, topSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${topSpacerHeight}px` } }, h("td", { colSpan: colCount }))), renderedRows, bottomSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${bottomSpacerHeight}px` } }, h("td", { colSpan: colCount })))), this.renderTotalsRow())), effectiveTotal === 0 && this.loadedPages.has(0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale))), effectiveTotal > 0 && this.renderFooter(undefined, effectiveTotal), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
868
|
-
}
|
|
869
|
-
renderFilterIcon() {
|
|
870
|
-
return (h("span", { class: "mrd-table__filter-icon", "aria-hidden": "true" }, h("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "currentColor" }, h("path", { d: "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" }))));
|
|
871
|
-
}
|
|
872
|
-
renderTextblockModal() {
|
|
873
|
-
if (this.textblockModal === null)
|
|
874
|
-
return null;
|
|
875
|
-
return (h("div", { class: "mrd-table__modal-backdrop", onClick: () => this.closeTextblockModal(), role: "dialog", "aria-modal": "true" }, h("div", { class: "mrd-table__modal", onClick: (e) => e.stopPropagation() }, h("button", { class: "mrd-table__modal-close", onClick: () => this.closeTextblockModal(), "aria-label": t('close', this.locale) }, "\u2715"), h("p", { class: "mrd-table__modal-text" }, this.textblockModal))));
|
|
876
|
-
}
|
|
877
|
-
get el() { return getElement(this); }
|
|
878
|
-
static get watchers() { return {
|
|
879
|
-
"totalElements": [{
|
|
880
|
-
"totalElementsChanged": 0
|
|
881
|
-
}]
|
|
882
|
-
}; }
|
|
883
|
-
};
|
|
884
|
-
MrdTable.style = mrdTableScss();
|
|
885
|
-
|
|
886
|
-
export { MrdTable as mrd_table };
|