@datalabz_/dashboard-kit 6.0.6 → 6.0.8

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.
Files changed (5) hide show
  1. package/README.md +8 -5
  2. package/package.json +1 -1
  3. package/v4.js +1 -1
  4. package/v5.js +1 -1
  5. package/v6.js +298 -27
package/README.md CHANGED
@@ -57,15 +57,16 @@ URLs already pinned by live dashboards.
57
57
 
58
58
  Any key in the `filters` of `CUSTOM_DASHBOARDS_PARAMS` other than `dateFrom`, `dateTo`, `timezone` and
59
59
  `hierarchyId` is a header filter of the dashboard. At its first boot the kit writes the value into the
60
- control with that `id` (for a radio group, the `name` its radios share), reads it back, and locks it. Later
61
- messages never touch it. `null`, `undefined` and an empty string are errors, and so is a value the control
60
+ control with that `id` (for a radio group, the `name` its radios share) and reads it back. Later messages
61
+ never touch it; the reader may change it, as any filter, and it applies on Refresh. The dashboard opens filtered, it
62
+ is not held there. `null`, `undefined` and an empty string are errors, and so is a value the control
62
63
  does not keep, such as an option that is not there, a date in the wrong format or text in a number field.
63
64
  An error, or a key with no control, means the dashboard does not load: it says why and posts
64
65
  `{ type: 'DK_FILTERS_REFUSED', message }` to its parent. It never opens unfiltered.
65
66
 
66
67
  A select with no option but the empty one at boot gets its options from a query that runs later, so the
67
68
  value cannot be checked against them. It goes in as an option of its own, selected, and stays selected
68
- while the dashboard fills in the rest. A static select keeps the check.
69
+ while the dashboard fills in the rest, until the reader picks another. A static select keeps the check.
69
70
 
70
71
  ## Asking a dashboard for its filters
71
72
 
@@ -89,7 +90,7 @@ The list follows the fill, so it holds only what a filter can actually be given:
89
90
  password and button controls, which the kit refuses to fill.
90
91
  - A radio group is one filter, keyed by the `name` its radios share (a radio with no name is left out): it
91
92
  is listed once, labelled by its `<fieldset><legend>`, with the radios as `options`; filling it checks
92
- the radio with that value and locks the group, and a value that is none of them is refused.
93
+ the radio with that value, and a value that is none of them is refused.
93
94
  - A select lists only options with a value, since an empty value is refused, and `optionsTotal` counts
94
95
  those. A select with none at boot is dynamic: its options come from a query that runs later, so it is
95
96
  listed with `dynamicOptions: true` and no options, and takes any value (below).
@@ -133,7 +134,9 @@ one strip are not points that can be set up.
133
134
 
134
135
  On a click the kit builds B's filters from the clicked row, the header filters and the period as the section
135
136
  last loaded with, fetches B with the viewer's token, and opens it. A `pass` key may be a header filter of B
136
- only: a context key (`dateFrom`, `dateTo`, `timezone`, `hierarchyId`) is refused. An open popup closes when the host changes the period, time zone or hierarchy; a theme change does not close it.
137
+ only: a context key (`dateFrom`, `dateTo`, `timezone`, `hierarchyId`) is refused. The popup's head has a date filter
138
+ that is bc-v6's: the same presets, worked out on the browser's clock and read in the host's time zone; it opens on A's
139
+ period and a change goes to B alone, which reloads. An open popup closes when the host changes the period, time zone or hierarchy; a theme change does not close it.
137
140
  A table cell or card value that holds a link, a button, a control, an `onclick` or a tab stop is not made a
138
141
  drillthrough link: it answers its own click. A column in which any cell does, and a card whose value does, get no
139
142
  set-up button either (`configurable: false`). A row without the key a setup names, a filter the dashboard does not have, or a dashboard the viewer cannot open shows
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalabz_/dashboard-kit",
3
- "version": "6.0.6",
3
+ "version": "6.0.8",
4
4
  "description": "DashboardKit runtime + styles, served from jsDelivr",
5
5
  "license": "UNLICENSED",
6
6
  "files": [
package/v4.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = 'cc1be64'; // replaced at deploy: sed -i "s/cc1be64/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = '25c4aef'; // replaced at deploy: sed -i "s/25c4aef/$(git rev-parse --short HEAD)/g" v4.js
24
24
  let _calls = []; // System Info call log
25
25
  let _sectionErrors = {}; // sectionId → error count
26
26
  let _generation = 0;
package/v5.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = 'cc1be64'; // replaced at deploy: sed -i "s/cc1be64/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = '25c4aef'; // replaced at deploy: sed -i "s/25c4aef/$(git rev-parse --short HEAD)/g" v4.js
24
24
  let _calls = []; // System Info call log
25
25
  let _sectionErrors = {}; // sectionId → error count
26
26
  let _generation = 0;
package/v6.js CHANGED
@@ -20,7 +20,7 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = 'cc1be64'; // replaced at deploy: sed -i "s/cc1be64/$(git rev-parse --short HEAD)/g" v6.js
23
+ let _gitVer = '25c4aef'; // replaced at deploy: sed -i "s/25c4aef/$(git rev-parse --short HEAD)/g" v6.js
24
24
  let _calls = []; // System Info call log
25
25
  let _sectionErrors = {}; // sectionId → error count
26
26
  let _generation = 0;
@@ -34,6 +34,7 @@
34
34
  let _drillPoints = {}; // point key → { dashboardId, pass }
35
35
  let _depth = 0; // how many dashboards deep this one is opened
36
36
  let _popup = null; // the open drillthrough popup
37
+ let _dashboardDocs = {}; // dashboardsApi|id → a dashboard document already fetched (_fetchDashboard)
37
38
 
38
39
  // ── Inject CSS ───────────────────────────────────────────────────────────────
39
40
  // The kit carries its own CSS: Claude artifacts may load scripts from jsDelivr but not
@@ -147,7 +148,8 @@ header {
147
148
  flex: 1;
148
149
  min-width: 8px;
149
150
  }
150
- header label {
151
+ header label,
152
+ .dk-od-dates label {
151
153
  display: inline-flex;
152
154
  align-items: center;
153
155
  gap: 5px;
@@ -155,7 +157,9 @@ header label {
155
157
  font-size: 12px;
156
158
  }
157
159
  header input,
158
- header select {
160
+ header select,
161
+ .dk-od-dates input,
162
+ .dk-od-dates select {
159
163
  background: var(--raised);
160
164
  color: var(--text);
161
165
  border: 1px solid var(--border);
@@ -885,15 +889,18 @@ html[data-dk-setup="true"] .dk-resp-toggle {
885
889
  .dk-od-value:not(.dk-od-keep) {
886
890
  color: var(--brand);
887
891
  }
892
+ /* The opened dashboard is the next page, not a dialog over this one: it fills the frame, with nothing dimmed behind,
893
+ and slides in from the right (dk-od-in) and back out on Back. The shadow on its left edge shows it passing over
894
+ this page while it moves; in place, that edge is the frame's own and the shadow falls outside it. */
888
895
  .dk-od {
889
896
  position: fixed;
890
897
  inset: 0;
891
898
  z-index: 1000;
892
899
  display: flex;
893
- align-items: center;
894
- justify-content: center;
895
- padding: 8px;
896
- background: rgba(10, 14, 20, 0.6);
900
+ overflow: hidden;
901
+ }
902
+ .dk-od:not(.dk-od-in) {
903
+ pointer-events: none;
897
904
  }
898
905
  .dk-od-box {
899
906
  display: flex;
@@ -902,31 +909,86 @@ html[data-dk-setup="true"] .dk-resp-toggle {
902
909
  height: 100%;
903
910
  background: var(--bg);
904
911
  color: var(--text);
905
- border: 1px solid var(--border);
906
- border-radius: 10px;
907
912
  overflow: hidden;
913
+ box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
914
+ transform: translateX(100%);
915
+ transition: transform 180ms ease-in;
916
+ }
917
+ .dk-od-in .dk-od-box {
918
+ transform: none;
919
+ transition: transform 220ms ease-out;
920
+ }
921
+ @media (prefers-reduced-motion: reduce) {
922
+ .dk-od-box,
923
+ .dk-od-in .dk-od-box {
924
+ transition: none;
925
+ }
908
926
  }
927
+ /* Back on the left, the title taking what is left (cut short, whole on hover), the period on the right: a range opened
928
+ with Manual grows leftwards into the title, never into the button. */
909
929
  .dk-od-head {
910
930
  display: flex;
911
931
  align-items: center;
912
- justify-content: space-between;
913
932
  gap: 12px;
914
933
  padding: 12px 16px;
915
934
  background: var(--surface);
916
935
  border-bottom: 1px solid var(--border);
917
936
  }
918
937
  .dk-od-title {
938
+ flex: 1 1 auto;
939
+ min-width: 0;
940
+ overflow: hidden;
941
+ text-overflow: ellipsis;
942
+ white-space: nowrap;
919
943
  font-weight: 600;
920
944
  font-size: 16px;
921
945
  }
946
+ /* The popup's own period: the range (Manual only) and then the preset, as the BackOffice has them. */
947
+ .dk-od-dates {
948
+ display: flex;
949
+ align-items: center;
950
+ justify-content: flex-end;
951
+ gap: 8px;
952
+ font-size: 12px;
953
+ }
954
+ .dk-od-dates label {
955
+ white-space: nowrap;
956
+ }
957
+ .dk-od-dates[hidden],
958
+ .dk-od-range[hidden] {
959
+ display: none;
960
+ }
961
+ .dk-od-range {
962
+ display: inline-flex;
963
+ align-items: center;
964
+ gap: 4px;
965
+ color: var(--muted);
966
+ }
967
+ .dk-od-dates input[aria-invalid="true"] {
968
+ border-color: var(--err);
969
+ }
970
+ :root:not([data-theme="light"]) .dk-od-dates input {
971
+ color-scheme: dark;
972
+ }
922
973
  .dk-od-close {
923
- padding: 4px 12px;
974
+ flex: none;
975
+ display: inline-flex;
976
+ align-items: center;
977
+ justify-content: center;
978
+ gap: 4px;
979
+ height: 22px;
980
+ padding: 0 8px 0 6px;
981
+ font: inherit;
982
+ font-size: 12px;
924
983
  background: transparent;
925
- color: var(--text);
926
- border: 1px solid var(--border);
984
+ color: var(--brand);
985
+ border: 1px solid var(--brand);
927
986
  border-radius: 4px;
928
987
  cursor: pointer;
929
988
  }
989
+ .dk-od-close:hover {
990
+ background: color-mix(in srgb, var(--brand) 15%, transparent);
991
+ }
930
992
  .dk-od-body {
931
993
  flex: 1;
932
994
  min-height: 0;
@@ -1234,7 +1296,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1234
1296
  }
1235
1297
 
1236
1298
  // What DK_FILTERS_INFO carries: the dashboard as it starts, not as it is now. Once it has booted
1237
- // that is the list taken then, before the fill wrote or locked anything, so what a reader typed
1299
+ // that is the list taken then, before the fill wrote anything, so what a reader typed
1238
1300
  // since is never in it, and what a host stores with the dashboard does not depend on who asked.
1239
1301
  function _filtersInfo() {
1240
1302
  return (_bootFilters || _dashboardFilters()).map(function (f) { return Object.assign({}, f); });
@@ -1270,7 +1332,11 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1270
1332
  if (e.data.type !== 'CUSTOM_DASHBOARDS_PARAMS') return;
1271
1333
  if (_filtersRefused) return;
1272
1334
 
1273
- if (typeof e.data.token === 'string') _authToken = e.data.token;
1335
+ if (typeof e.data.token === 'string') {
1336
+ // Another viewer's token may not open what this one was given.
1337
+ if (e.data.token !== _authToken) _dashboardDocs = {};
1338
+ _authToken = e.data.token;
1339
+ }
1274
1340
 
1275
1341
  // The token rides on every call to the endpoint, so only the parent may set
1276
1342
  // it, and only to an https URL (http for localhost dev). Anything else is
@@ -1315,7 +1381,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1315
1381
  if (_popup && JSON.stringify(_contextSnapshot()) !== contextBefore) _closePopup();
1316
1382
 
1317
1383
  if (!_hasBooted && _authToken && _dateFromIso && _dateToIso && _timezone) {
1318
- // Before the fill locks anything and before a section runs. A fault in describing the filters
1384
+ // Before the fill writes anything and before a section runs. A fault in describing the filters
1319
1385
  // must never keep the dashboard from booting, so it only costs the list.
1320
1386
  try { _bootFilters = _dashboardFilters(); }
1321
1387
  catch (err) { console.error('[DashboardKit] could not describe the filters:', err); _bootFilters = null; }
@@ -1335,7 +1401,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1335
1401
 
1336
1402
  // ── Filters a parent passes ───────────────────────────────────────────────────
1337
1403
  // dateFrom, dateTo, timezone and hierarchyId are context the host owns. Any other key in
1338
- // `filters` is a header filter: written into the control with that id, read back, and locked.
1404
+ // `filters` is a header filter: written into the control with that id and read back. The reader may change it
1405
+ // afterwards, as any filter: the dashboard opens filtered, it is not held there.
1339
1406
  // What the control kept was valid; what the browser dropped (an <option> that is not there, a
1340
1407
  // date in the wrong format, text in a number field) was not. Anything else is a refusal and the
1341
1408
  // dashboard does not boot — it never opens unfiltered. No input or change event is fired:
@@ -1386,6 +1453,9 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1386
1453
  keep.observe(el, watch);
1387
1454
  });
1388
1455
  keep.observe(el, watch);
1456
+ // Kept until the reader picks something else: from then on the choice is theirs, and options the dashboard
1457
+ // rebuilds must not put the passed value back over it.
1458
+ el.addEventListener('change', function () { keep.disconnect(); }, { once: true });
1389
1459
  return null;
1390
1460
  }
1391
1461
 
@@ -1430,13 +1500,11 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1430
1500
  const hit = (typeof v === 'string' || typeof v === 'number') ? group.find(function (r) { return r.value === String(v); }) : null;
1431
1501
  if (!hit) return 'The filter "' + k + '" cannot take ' + _show(v) + ': it is not one of its options.';
1432
1502
  hit.checked = true;
1433
- group.forEach(function (r) { r.disabled = true; });
1434
1503
  continue;
1435
1504
  }
1436
1505
  if (!el || !/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName)) return 'The dashboard has no filter "' + k + '".';
1437
1506
  const why = _writeControl(el, values[k]);
1438
1507
  if (why) return 'The filter "' + k + '" cannot take ' + _show(values[k]) + ': ' + why + '.';
1439
- el.disabled = true;
1440
1508
  }
1441
1509
  return null;
1442
1510
  }
@@ -1795,10 +1863,14 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1795
1863
  const sec = _sections.find(function (s) { return s.id === sectionId; });
1796
1864
  // failedCall is err.dkCall from runQuery; without one the rejection didn't
1797
1865
  // come from a gateway call at all — that's kind 'script'. The operator gets
1798
- // a fixed phrase; the raw text goes to the parent via "Ask AI to fix" and to
1799
- // System Info. No panel Retry: the header's Refresh covers it.
1866
+ // a fixed phrase, with the wait when no response arrived; the raw text goes to
1867
+ // the parent via "Ask AI to fix" and to System Info. No panel Retry: the
1868
+ // header's Refresh covers it.
1869
+ const cause = failedCall && failedCall.kind === 'transport'
1870
+ ? ': Network error after ' + (failedCall.clientMs / 1000).toFixed(2) + 's.'
1871
+ : '';
1800
1872
  container.innerHTML =
1801
- '<div class="dk-error"><span>This view couldn\'t load</span>' +
1873
+ '<div class="dk-error"><span>This view couldn\'t load' + cause + '</span>' +
1802
1874
  '<button class="dk-error-report-btn" type="button">Ask AI to fix</button></div>';
1803
1875
 
1804
1876
  const reportBtn = container.querySelector('.dk-error-report-btn');
@@ -2192,7 +2264,18 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2192
2264
  return 'The dashboard could not be opened (HTTP ' + status + ').';
2193
2265
  }
2194
2266
 
2267
+ // A dashboard opened once opens again from _dashboardDocs, for as long as this page and its token last: a click on
2268
+ // the next row needs the same document, only other filters. Its data is never kept — B queries on every open, as it
2269
+ // would anyway. Only a document the viewer was given is kept, so a refusal is asked again; a new token empties it.
2195
2270
  async function _fetchDashboard(id) {
2271
+ const key = _dashboardsApi + '|' + id;
2272
+ if (_dashboardDocs[key]) return _dashboardDocs[key];
2273
+ const doc = await _fetchDashboardOnce(id);
2274
+ _dashboardDocs[key] = doc;
2275
+ return doc;
2276
+ }
2277
+
2278
+ async function _fetchDashboardOnce(id) {
2196
2279
  const headers = { 'x-access-token': _authToken };
2197
2280
  if (_dashboardsPermissionKey) headers['x-permission-key'] = _dashboardsPermissionKey;
2198
2281
  let res;
@@ -2209,15 +2292,27 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2209
2292
  return doc;
2210
2293
  }
2211
2294
 
2295
+ // Closed at once — the page under it takes clicks and keys from now on — and removed once it has slid out. Without a
2296
+ // transition (reduced motion) there is no transitionend, so a timer removes it too.
2212
2297
  function _closePopup() {
2213
2298
  const p = _popup;
2214
2299
  if (!p) return;
2215
2300
  _popup = null;
2216
- p.el.remove();
2301
+ p.el.classList.remove('dk-od-in');
2302
+ p.el.setAttribute('inert', '');
2303
+ p.under.forEach(function (n) { n.removeAttribute('inert'); n.removeAttribute('data-dk-od-inert'); });
2304
+ const box = p.el.querySelector('.dk-od-box');
2305
+ const remove = function () { p.el.remove(); };
2306
+ box.addEventListener('transitionend', function (e) { if (e.target === box) remove(); });
2307
+ setTimeout(remove, 400);
2217
2308
  document.body.style.overflow = p.overflow;
2218
2309
  if (p.trigger && p.trigger.isConnected && p.trigger.focus) p.trigger.focus();
2219
2310
  }
2220
2311
 
2312
+ // Lucide "arrow-left" (ISC): closing returns to the dashboard that opened this one, as Esc does.
2313
+ const BACK_ICON = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" ' +
2314
+ 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m12 19-7-7 7-7"/><path d="M19 12H5"/></svg>';
2315
+
2221
2316
  function _showPopup(trigger) {
2222
2317
  _closePopup();
2223
2318
  const el = document.createElement('div');
@@ -2225,22 +2320,31 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2225
2320
  el.setAttribute('role', 'dialog');
2226
2321
  el.setAttribute('aria-modal', 'true');
2227
2322
  el.innerHTML =
2228
- '<div class="dk-od-box"><div class="dk-od-head"><span class="dk-od-title"></span>' +
2229
- '<button type="button" class="dk-od-close">Close</button></div><div class="dk-od-body"></div></div>';
2323
+ '<div class="dk-od-box"><div class="dk-od-head">' +
2324
+ '<button type="button" class="dk-od-close" title="Back (Esc)">' + BACK_ICON + 'Back</button>' +
2325
+ '<span class="dk-od-title"></span><div class="dk-od-dates" hidden></div>' +
2326
+ '</div><div class="dk-od-body"></div></div>';
2230
2327
  document.body.appendChild(el);
2231
2328
  const p = {
2232
2329
  el: el,
2233
2330
  trigger: trigger,
2234
2331
  overflow: document.body.style.overflow,
2235
2332
  title: el.querySelector('.dk-od-title'),
2333
+ dates: el.querySelector('.dk-od-dates'),
2236
2334
  body: el.querySelector('.dk-od-body'),
2237
2335
  };
2238
2336
  p.title.textContent = 'Opening dashboard…';
2239
2337
  document.body.style.overflow = 'hidden';
2240
- el.addEventListener('mousedown', function (e) { if (e.target === el) _closePopup(); });
2338
+ // The page under the popup is out of reach while it is open: Tab, a click and a screen reader stay in the popup
2339
+ // instead of landing on controls nobody can see. Only what this sets is unset on close.
2340
+ p.under = Array.from(document.body.children).filter(function (n) { return n !== el && !n.hasAttribute('inert'); });
2341
+ p.under.forEach(function (n) { n.setAttribute('inert', ''); n.setAttribute('data-dk-od-inert', ''); });
2241
2342
  const close = el.querySelector('.dk-od-close');
2242
2343
  close.addEventListener('click', _closePopup);
2243
- close.focus();
2344
+ // Laid out off-screen first, so adding dk-od-in slides it in rather than placing it.
2345
+ void el.offsetWidth;
2346
+ el.classList.add('dk-od-in');
2347
+ close.focus({ preventScroll: true });
2244
2348
  _popup = p;
2245
2349
  return p;
2246
2350
  }
@@ -2270,6 +2374,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2270
2374
  const doc = await _fetchDashboard(setup.dashboardId);
2271
2375
  if (_popup !== p) return;
2272
2376
  p.title.textContent = doc.name || 'Dashboard';
2377
+ p.title.title = p.title.textContent; // the whole name, where the head cuts it short
2273
2378
 
2274
2379
  // What the host sent this dashboard, with this dashboard's own values. B gets its own setup
2275
2380
  // and one level more depth; at MAX_DEPTH it gets none and its cells stay plain text.
@@ -2289,18 +2394,180 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2289
2394
  const frame = document.createElement('iframe');
2290
2395
  frame.title = doc.name || 'Dashboard';
2291
2396
  frame.setAttribute('sandbox', 'allow-scripts allow-downloads');
2397
+ let loaded = false;
2292
2398
  frame.addEventListener('load', function () {
2399
+ loaded = true;
2293
2400
  if (_popup === p) frame.contentWindow.postMessage(message, '*');
2294
2401
  });
2295
2402
  frame.srcdoc = doc.html;
2296
2403
  p.frame = frame;
2297
2404
  p.body.textContent = '';
2298
2405
  p.body.appendChild(frame);
2406
+
2407
+ // A period picked in the popup goes to B alone; A and its own period stay as they are. The boot
2408
+ // message takes it too, so a frame that has not loaded yet starts on it.
2409
+ _popupDates(p, point.context, function (dateFrom, dateTo) {
2410
+ message.filters.dateFrom = dateFrom;
2411
+ message.filters.dateTo = dateTo;
2412
+ if (!loaded || _popup !== p) return;
2413
+ frame.contentWindow.postMessage({
2414
+ type: 'CUSTOM_DASHBOARDS_PARAMS',
2415
+ filters: {
2416
+ dateFrom: dateFrom,
2417
+ dateTo: dateTo,
2418
+ timezone: message.filters.timezone,
2419
+ hierarchyId: message.filters.hierarchyId,
2420
+ },
2421
+ }, '*');
2422
+ });
2299
2423
  } catch (err) {
2300
2424
  _popupError(p, (err && err.message) || String(err));
2301
2425
  }
2302
2426
  }
2303
2427
 
2428
+ // ── Drillthrough: the popup's period ─────────────────────────────────────────────
2429
+ // The popup's own date filter is the BackOffice's (bc-v6 DateFilter) to the letter: the same presets in the
2430
+ // same order, each worked out on the browser's clock, and Manual, a range picked to the minute. A date is
2431
+ // held as the browser's local time, and its wall clock is read in the host's time zone when it is sent —
2432
+ // bc-v6's moment(d).tz(tz, true) — so Today is 00:00–23:59:59.999 in the BackOffice's zone, not the
2433
+ // browser's. It starts on the period A had at the click, shown as the preset it equals, or as Manual.
2434
+ const OD_PRESETS = [
2435
+ ['today', 'Today'], ['manual', 'Manual'], ['yesterday', 'Yesterday'], ['currentWeek', 'Current week'],
2436
+ ['lastWeek', 'Last week'], ['currentMonth', 'Current month'], ['lastMonth', 'Last month'],
2437
+ ['last30Days', 'Last 30 days'], ['last60Days', 'Last 60 days'], ['last365Days', 'Last 365 days'],
2438
+ ['allTime', 'All'],
2439
+ ];
2440
+
2441
+ // [from, to] as local dates, as bc-v6's getPresetsDates has them.
2442
+ function _odPreset(key) {
2443
+ const now = new Date();
2444
+ const y = now.getFullYear(), m = now.getMonth(), d = now.getDate();
2445
+ const endOfToday = new Date(y, m, d, 23, 59, 59, 999);
2446
+ const monday = d - ((now.getDay() + 6) % 7); // ISO week: it starts on Monday
2447
+ switch (key) {
2448
+ case 'yesterday': return [new Date(y, m, d - 1), new Date(y, m, d - 1, 23, 59, 59, 999)];
2449
+ case 'currentWeek': return [new Date(y, m, monday), endOfToday];
2450
+ case 'lastWeek': return [new Date(y, m, monday - 7), new Date(y, m, monday - 1, 23, 59, 59, 999)];
2451
+ case 'currentMonth': return [new Date(y, m, 1), endOfToday];
2452
+ case 'lastMonth': return [new Date(y, m - 1, 1), new Date(y, m, 0, 23, 59, 59, 999)];
2453
+ case 'last30Days': return [new Date(y, m, d - 30), endOfToday];
2454
+ case 'last60Days': return [new Date(y, m, d - 60), endOfToday];
2455
+ case 'last365Days': return [new Date(y, m, d - 365), endOfToday];
2456
+ case 'allTime': return [new Date(0), endOfToday];
2457
+ default: return [new Date(y, m, d), endOfToday];
2458
+ }
2459
+ }
2460
+
2461
+ // The wall clock an instant shows in tz, as milliseconds of a UTC date that reads the same.
2462
+ function _odWall(t, tz) {
2463
+ const p = {};
2464
+ new Intl.DateTimeFormat('en-US', {
2465
+ timeZone: tz, hourCycle: 'h23',
2466
+ year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit',
2467
+ }).formatToParts(new Date(t)).forEach(function (x) { p[x.type] = x.value; });
2468
+ // % 24: an engine that ignores hourCycle writes midnight as 24.
2469
+ return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour % 24, +p.minute, +p.second, new Date(t).getUTCMilliseconds());
2470
+ }
2471
+
2472
+ // The local date's wall clock read in tz, exactly as bc-v6's moment(d).tz(tz, true) reads it: with tz's
2473
+ // offset at the instant d is, not at the one it becomes. The two differ only in the hour a clock change
2474
+ // skips or repeats, and there bc-v6 is what the BackOffice sends, so the kit sends the same.
2475
+ function _odToIso(d, tz) {
2476
+ const wall = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
2477
+ return new Date(wall - (_odWall(d.getTime(), tz) - d.getTime())).toISOString();
2478
+ }
2479
+
2480
+ // The other way: the local date that reads what the instant reads in tz.
2481
+ function _odFromIso(iso, tz) {
2482
+ const w = new Date(_odWall(Date.parse(iso), tz));
2483
+ return new Date(w.getUTCFullYear(), w.getUTCMonth(), w.getUTCDate(),
2484
+ w.getUTCHours(), w.getUTCMinutes(), w.getUTCSeconds(), w.getUTCMilliseconds());
2485
+ }
2486
+
2487
+ function _odInputValue(d) {
2488
+ const two = function (n) { return String(n).padStart(2, '0'); };
2489
+ return d.getFullYear() + '-' + two(d.getMonth() + 1) + '-' + two(d.getDate()) +
2490
+ 'T' + two(d.getHours()) + ':' + two(d.getMinutes());
2491
+ }
2492
+
2493
+ // A datetime-local value as a local date, to the minute (bc-v6's picker is HH:mm), or null.
2494
+ function _odInputDate(v) {
2495
+ const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(v || '');
2496
+ return m ? new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5]) : null;
2497
+ }
2498
+
2499
+ function _popupDates(p, context, onChange) {
2500
+ const tz = context && context.timezone;
2501
+ let from, to;
2502
+ try {
2503
+ from = _odFromIso(context.dateFrom, tz);
2504
+ to = _odFromIso(context.dateTo, tz);
2505
+ if (isNaN(from) || isNaN(to)) throw new Error('the period ' + context.dateFrom + ' – ' + context.dateTo + ' is not a date');
2506
+ } catch (err) {
2507
+ // B still opens on A's period; only the picker is missing, and the console says why.
2508
+ console.error('[DashboardKit] the popup has no date filter:', err);
2509
+ return;
2510
+ }
2511
+ const match = OD_PRESETS.find(function (o) {
2512
+ if (o[0] === 'manual') return false;
2513
+ const r = _odPreset(o[0]);
2514
+ return r[0].getTime() === from.getTime() && r[1].getTime() === to.getTime();
2515
+ });
2516
+
2517
+ p.dates.innerHTML =
2518
+ '<span class="dk-od-range" hidden><input type="datetime-local" class="dk-od-from" aria-label="From">' +
2519
+ '<span>–</span><input type="datetime-local" class="dk-od-to" aria-label="To"></span>' +
2520
+ '<label>Select Date <select class="dk-od-preset">' +
2521
+ OD_PRESETS.map(function (o) { return '<option value="' + o[0] + '">' + esc(o[1]) + '</option>'; }).join('') +
2522
+ '</select></label>';
2523
+ const range = p.dates.querySelector('.dk-od-range');
2524
+ const fromEl = p.dates.querySelector('.dk-od-from');
2525
+ const toEl = p.dates.querySelector('.dk-od-to');
2526
+ const select = p.dates.querySelector('.dk-od-preset');
2527
+
2528
+ // A period that is no preset opens as Manual with its range filled in, as bc-v6 restores one.
2529
+ select.value = match ? match[0] : 'manual';
2530
+ if (!match) {
2531
+ range.hidden = false;
2532
+ fromEl.value = _odInputValue(from);
2533
+ toEl.value = _odInputValue(to);
2534
+ }
2535
+
2536
+ function send(f, t) {
2537
+ onChange(_odToIso(f, tz), _odToIso(t, tz));
2538
+ }
2539
+
2540
+ // Manual opens an empty range and changes nothing until both ends are picked, as bc-v6's does.
2541
+ select.addEventListener('change', function () {
2542
+ if (select.value === 'manual') {
2543
+ range.hidden = false;
2544
+ fromEl.value = '';
2545
+ toEl.value = '';
2546
+ fromEl.removeAttribute('aria-invalid');
2547
+ toEl.removeAttribute('aria-invalid');
2548
+ return;
2549
+ }
2550
+ range.hidden = true;
2551
+ const r = _odPreset(select.value);
2552
+ send(r[0], r[1]);
2553
+ });
2554
+
2555
+ // A range that ends before it starts is marked and not sent.
2556
+ function onRange() {
2557
+ const f = _odInputDate(fromEl.value);
2558
+ const t = _odInputDate(toEl.value);
2559
+ if (!f || !t) return;
2560
+ const backwards = f.getTime() > t.getTime();
2561
+ fromEl.setAttribute('aria-invalid', String(backwards));
2562
+ toEl.setAttribute('aria-invalid', String(backwards));
2563
+ if (!backwards) send(f, t);
2564
+ }
2565
+ fromEl.addEventListener('change', onRange);
2566
+ toEl.addEventListener('change', onRange);
2567
+
2568
+ p.dates.hidden = false;
2569
+ }
2570
+
2304
2571
  // ── renderTable ───────────────────────────────────────────────────────────────
2305
2572
  // columns: [{ key, label, format?, sortable?, tooltip? }]
2306
2573
  // format receives (value, row) — read row.<key> for per-row currency, etc.
@@ -2610,6 +2877,10 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2610
2877
 
2611
2878
  const clone = document.documentElement.cloneNode(true);
2612
2879
  clone.querySelectorAll('.dk-pt-btn, .dk-od').forEach(function (n) { n.remove(); });
2880
+ clone.querySelectorAll('[data-dk-od-inert]').forEach(function (n) {
2881
+ n.removeAttribute('inert');
2882
+ n.removeAttribute('data-dk-od-inert');
2883
+ });
2613
2884
  clone.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
2614
2885
  n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
2615
2886
  });