@datalabz_/dashboard-kit 6.0.7 → 6.0.9

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 +325 -25
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.7",
3
+ "version": "6.0.9",
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 = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = 'b94b380'; // replaced at deploy: sed -i "s/b94b380/$(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 = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = 'b94b380'; // replaced at deploy: sed -i "s/b94b380/$(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 = '35ea6ab'; // replaced at deploy: sed -i "s/35ea6ab/$(git rev-parse --short HEAD)/g" v6.js
23
+ let _gitVer = 'b94b380'; // replaced at deploy: sed -i "s/b94b380/$(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;
908
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
+ }
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
  }
@@ -1537,6 +1605,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1537
1605
  // What a click point drawn by this load reports: this section, and the header filters and the
1538
1606
  // context as the load started, not edits made since.
1539
1607
  const ctx = { id: sec.id, localFilters: _headerSnapshot(), context: _contextSnapshot() };
1608
+ // Kept on the section for a render call that arrives without it (_ctxOf).
1609
+ sec.ctx = ctx;
1540
1610
  try {
1541
1611
  await sec.load({
1542
1612
  runQuery,
@@ -1877,6 +1947,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1877
1947
  }
1878
1948
  }
1879
1949
 
1950
+ // A render call by its global name, or as DashboardKit.<render>, carries no ctx. Its section is
1951
+ // then the panel the container sits in, with the context that section's latest load started with.
1952
+ // A container outside every panel has none, and its points read the filters as they are now.
1953
+ function _ctxOf(container) {
1954
+ const panel = container.closest ? container.closest('.dk-panel') : null;
1955
+ const sec = panel && _sections.find(function (s) { return 'dk-panel-' + s.id === panel.id; });
1956
+ return sec ? sec.ctx : undefined;
1957
+ }
1958
+
1880
1959
  function _forgetPoints(container) {
1881
1960
  if (container.id) delete _pointsByContainer[container.id];
1882
1961
  _schedulePoints();
@@ -1933,6 +2012,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1933
2012
 
1934
2013
  function _registerPointsUnsafe(container, selector, ctx, spec) {
1935
2014
  if (!container.id) return;
2015
+ ctx = ctx || _ctxOf(container);
1936
2016
  const count = {};
1937
2017
  spec.names.forEach(function (n) { count[n] = (count[n] || 0) + 1; });
1938
2018
  const localFilters = ctx ? ctx.localFilters : _headerSnapshot();
@@ -2196,7 +2276,18 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2196
2276
  return 'The dashboard could not be opened (HTTP ' + status + ').';
2197
2277
  }
2198
2278
 
2279
+ // A dashboard opened once opens again from _dashboardDocs, for as long as this page and its token last: a click on
2280
+ // the next row needs the same document, only other filters. Its data is never kept — B queries on every open, as it
2281
+ // would anyway. Only a document the viewer was given is kept, so a refusal is asked again; a new token empties it.
2199
2282
  async function _fetchDashboard(id) {
2283
+ const key = _dashboardsApi + '|' + id;
2284
+ if (_dashboardDocs[key]) return _dashboardDocs[key];
2285
+ const doc = await _fetchDashboardOnce(id);
2286
+ _dashboardDocs[key] = doc;
2287
+ return doc;
2288
+ }
2289
+
2290
+ async function _fetchDashboardOnce(id) {
2200
2291
  const headers = { 'x-access-token': _authToken };
2201
2292
  if (_dashboardsPermissionKey) headers['x-permission-key'] = _dashboardsPermissionKey;
2202
2293
  let res;
@@ -2213,15 +2304,27 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2213
2304
  return doc;
2214
2305
  }
2215
2306
 
2307
+ // Closed at once — the page under it takes clicks and keys from now on — and removed once it has slid out. Without a
2308
+ // transition (reduced motion) there is no transitionend, so a timer removes it too.
2216
2309
  function _closePopup() {
2217
2310
  const p = _popup;
2218
2311
  if (!p) return;
2219
2312
  _popup = null;
2220
- p.el.remove();
2313
+ p.el.classList.remove('dk-od-in');
2314
+ p.el.setAttribute('inert', '');
2315
+ p.under.forEach(function (n) { n.removeAttribute('inert'); n.removeAttribute('data-dk-od-inert'); });
2316
+ const box = p.el.querySelector('.dk-od-box');
2317
+ const remove = function () { p.el.remove(); };
2318
+ box.addEventListener('transitionend', function (e) { if (e.target === box) remove(); });
2319
+ setTimeout(remove, 400);
2221
2320
  document.body.style.overflow = p.overflow;
2222
2321
  if (p.trigger && p.trigger.isConnected && p.trigger.focus) p.trigger.focus();
2223
2322
  }
2224
2323
 
2324
+ // Lucide "arrow-left" (ISC): closing returns to the dashboard that opened this one, as Esc does.
2325
+ const BACK_ICON = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" ' +
2326
+ 'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m12 19-7-7 7-7"/><path d="M19 12H5"/></svg>';
2327
+
2225
2328
  function _showPopup(trigger) {
2226
2329
  _closePopup();
2227
2330
  const el = document.createElement('div');
@@ -2229,22 +2332,31 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2229
2332
  el.setAttribute('role', 'dialog');
2230
2333
  el.setAttribute('aria-modal', 'true');
2231
2334
  el.innerHTML =
2232
- '<div class="dk-od-box"><div class="dk-od-head"><span class="dk-od-title"></span>' +
2233
- '<button type="button" class="dk-od-close">Close</button></div><div class="dk-od-body"></div></div>';
2335
+ '<div class="dk-od-box"><div class="dk-od-head">' +
2336
+ '<button type="button" class="dk-od-close" title="Back (Esc)">' + BACK_ICON + 'Back</button>' +
2337
+ '<span class="dk-od-title"></span><div class="dk-od-dates" hidden></div>' +
2338
+ '</div><div class="dk-od-body"></div></div>';
2234
2339
  document.body.appendChild(el);
2235
2340
  const p = {
2236
2341
  el: el,
2237
2342
  trigger: trigger,
2238
2343
  overflow: document.body.style.overflow,
2239
2344
  title: el.querySelector('.dk-od-title'),
2345
+ dates: el.querySelector('.dk-od-dates'),
2240
2346
  body: el.querySelector('.dk-od-body'),
2241
2347
  };
2242
2348
  p.title.textContent = 'Opening dashboard…';
2243
2349
  document.body.style.overflow = 'hidden';
2244
- el.addEventListener('mousedown', function (e) { if (e.target === el) _closePopup(); });
2350
+ // The page under the popup is out of reach while it is open: Tab, a click and a screen reader stay in the popup
2351
+ // instead of landing on controls nobody can see. Only what this sets is unset on close.
2352
+ p.under = Array.from(document.body.children).filter(function (n) { return n !== el && !n.hasAttribute('inert'); });
2353
+ p.under.forEach(function (n) { n.setAttribute('inert', ''); n.setAttribute('data-dk-od-inert', ''); });
2245
2354
  const close = el.querySelector('.dk-od-close');
2246
2355
  close.addEventListener('click', _closePopup);
2247
- close.focus();
2356
+ // Laid out off-screen first, so adding dk-od-in slides it in rather than placing it.
2357
+ void el.offsetWidth;
2358
+ el.classList.add('dk-od-in');
2359
+ close.focus({ preventScroll: true });
2248
2360
  _popup = p;
2249
2361
  return p;
2250
2362
  }
@@ -2274,6 +2386,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2274
2386
  const doc = await _fetchDashboard(setup.dashboardId);
2275
2387
  if (_popup !== p) return;
2276
2388
  p.title.textContent = doc.name || 'Dashboard';
2389
+ p.title.title = p.title.textContent; // the whole name, where the head cuts it short
2277
2390
 
2278
2391
  // What the host sent this dashboard, with this dashboard's own values. B gets its own setup
2279
2392
  // and one level more depth; at MAX_DEPTH it gets none and its cells stay plain text.
@@ -2293,18 +2406,180 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2293
2406
  const frame = document.createElement('iframe');
2294
2407
  frame.title = doc.name || 'Dashboard';
2295
2408
  frame.setAttribute('sandbox', 'allow-scripts allow-downloads');
2409
+ let loaded = false;
2296
2410
  frame.addEventListener('load', function () {
2411
+ loaded = true;
2297
2412
  if (_popup === p) frame.contentWindow.postMessage(message, '*');
2298
2413
  });
2299
2414
  frame.srcdoc = doc.html;
2300
2415
  p.frame = frame;
2301
2416
  p.body.textContent = '';
2302
2417
  p.body.appendChild(frame);
2418
+
2419
+ // A period picked in the popup goes to B alone; A and its own period stay as they are. The boot
2420
+ // message takes it too, so a frame that has not loaded yet starts on it.
2421
+ _popupDates(p, point.context, function (dateFrom, dateTo) {
2422
+ message.filters.dateFrom = dateFrom;
2423
+ message.filters.dateTo = dateTo;
2424
+ if (!loaded || _popup !== p) return;
2425
+ frame.contentWindow.postMessage({
2426
+ type: 'CUSTOM_DASHBOARDS_PARAMS',
2427
+ filters: {
2428
+ dateFrom: dateFrom,
2429
+ dateTo: dateTo,
2430
+ timezone: message.filters.timezone,
2431
+ hierarchyId: message.filters.hierarchyId,
2432
+ },
2433
+ }, '*');
2434
+ });
2303
2435
  } catch (err) {
2304
2436
  _popupError(p, (err && err.message) || String(err));
2305
2437
  }
2306
2438
  }
2307
2439
 
2440
+ // ── Drillthrough: the popup's period ─────────────────────────────────────────────
2441
+ // The popup's own date filter is the BackOffice's (bc-v6 DateFilter) to the letter: the same presets in the
2442
+ // same order, each worked out on the browser's clock, and Manual, a range picked to the minute. A date is
2443
+ // held as the browser's local time, and its wall clock is read in the host's time zone when it is sent —
2444
+ // bc-v6's moment(d).tz(tz, true) — so Today is 00:00–23:59:59.999 in the BackOffice's zone, not the
2445
+ // browser's. It starts on the period A had at the click, shown as the preset it equals, or as Manual.
2446
+ const OD_PRESETS = [
2447
+ ['today', 'Today'], ['manual', 'Manual'], ['yesterday', 'Yesterday'], ['currentWeek', 'Current week'],
2448
+ ['lastWeek', 'Last week'], ['currentMonth', 'Current month'], ['lastMonth', 'Last month'],
2449
+ ['last30Days', 'Last 30 days'], ['last60Days', 'Last 60 days'], ['last365Days', 'Last 365 days'],
2450
+ ['allTime', 'All'],
2451
+ ];
2452
+
2453
+ // [from, to] as local dates, as bc-v6's getPresetsDates has them.
2454
+ function _odPreset(key) {
2455
+ const now = new Date();
2456
+ const y = now.getFullYear(), m = now.getMonth(), d = now.getDate();
2457
+ const endOfToday = new Date(y, m, d, 23, 59, 59, 999);
2458
+ const monday = d - ((now.getDay() + 6) % 7); // ISO week: it starts on Monday
2459
+ switch (key) {
2460
+ case 'yesterday': return [new Date(y, m, d - 1), new Date(y, m, d - 1, 23, 59, 59, 999)];
2461
+ case 'currentWeek': return [new Date(y, m, monday), endOfToday];
2462
+ case 'lastWeek': return [new Date(y, m, monday - 7), new Date(y, m, monday - 1, 23, 59, 59, 999)];
2463
+ case 'currentMonth': return [new Date(y, m, 1), endOfToday];
2464
+ case 'lastMonth': return [new Date(y, m - 1, 1), new Date(y, m, 0, 23, 59, 59, 999)];
2465
+ case 'last30Days': return [new Date(y, m, d - 30), endOfToday];
2466
+ case 'last60Days': return [new Date(y, m, d - 60), endOfToday];
2467
+ case 'last365Days': return [new Date(y, m, d - 365), endOfToday];
2468
+ case 'allTime': return [new Date(0), endOfToday];
2469
+ default: return [new Date(y, m, d), endOfToday];
2470
+ }
2471
+ }
2472
+
2473
+ // The wall clock an instant shows in tz, as milliseconds of a UTC date that reads the same.
2474
+ function _odWall(t, tz) {
2475
+ const p = {};
2476
+ new Intl.DateTimeFormat('en-US', {
2477
+ timeZone: tz, hourCycle: 'h23',
2478
+ year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit',
2479
+ }).formatToParts(new Date(t)).forEach(function (x) { p[x.type] = x.value; });
2480
+ // % 24: an engine that ignores hourCycle writes midnight as 24.
2481
+ return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour % 24, +p.minute, +p.second, new Date(t).getUTCMilliseconds());
2482
+ }
2483
+
2484
+ // The local date's wall clock read in tz, exactly as bc-v6's moment(d).tz(tz, true) reads it: with tz's
2485
+ // offset at the instant d is, not at the one it becomes. The two differ only in the hour a clock change
2486
+ // skips or repeats, and there bc-v6 is what the BackOffice sends, so the kit sends the same.
2487
+ function _odToIso(d, tz) {
2488
+ const wall = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
2489
+ return new Date(wall - (_odWall(d.getTime(), tz) - d.getTime())).toISOString();
2490
+ }
2491
+
2492
+ // The other way: the local date that reads what the instant reads in tz.
2493
+ function _odFromIso(iso, tz) {
2494
+ const w = new Date(_odWall(Date.parse(iso), tz));
2495
+ return new Date(w.getUTCFullYear(), w.getUTCMonth(), w.getUTCDate(),
2496
+ w.getUTCHours(), w.getUTCMinutes(), w.getUTCSeconds(), w.getUTCMilliseconds());
2497
+ }
2498
+
2499
+ function _odInputValue(d) {
2500
+ const two = function (n) { return String(n).padStart(2, '0'); };
2501
+ return d.getFullYear() + '-' + two(d.getMonth() + 1) + '-' + two(d.getDate()) +
2502
+ 'T' + two(d.getHours()) + ':' + two(d.getMinutes());
2503
+ }
2504
+
2505
+ // A datetime-local value as a local date, to the minute (bc-v6's picker is HH:mm), or null.
2506
+ function _odInputDate(v) {
2507
+ const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(v || '');
2508
+ return m ? new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5]) : null;
2509
+ }
2510
+
2511
+ function _popupDates(p, context, onChange) {
2512
+ const tz = context && context.timezone;
2513
+ let from, to;
2514
+ try {
2515
+ from = _odFromIso(context.dateFrom, tz);
2516
+ to = _odFromIso(context.dateTo, tz);
2517
+ if (isNaN(from) || isNaN(to)) throw new Error('the period ' + context.dateFrom + ' – ' + context.dateTo + ' is not a date');
2518
+ } catch (err) {
2519
+ // B still opens on A's period; only the picker is missing, and the console says why.
2520
+ console.error('[DashboardKit] the popup has no date filter:', err);
2521
+ return;
2522
+ }
2523
+ const match = OD_PRESETS.find(function (o) {
2524
+ if (o[0] === 'manual') return false;
2525
+ const r = _odPreset(o[0]);
2526
+ return r[0].getTime() === from.getTime() && r[1].getTime() === to.getTime();
2527
+ });
2528
+
2529
+ p.dates.innerHTML =
2530
+ '<span class="dk-od-range" hidden><input type="datetime-local" class="dk-od-from" aria-label="From">' +
2531
+ '<span>–</span><input type="datetime-local" class="dk-od-to" aria-label="To"></span>' +
2532
+ '<label>Select Date <select class="dk-od-preset">' +
2533
+ OD_PRESETS.map(function (o) { return '<option value="' + o[0] + '">' + esc(o[1]) + '</option>'; }).join('') +
2534
+ '</select></label>';
2535
+ const range = p.dates.querySelector('.dk-od-range');
2536
+ const fromEl = p.dates.querySelector('.dk-od-from');
2537
+ const toEl = p.dates.querySelector('.dk-od-to');
2538
+ const select = p.dates.querySelector('.dk-od-preset');
2539
+
2540
+ // A period that is no preset opens as Manual with its range filled in, as bc-v6 restores one.
2541
+ select.value = match ? match[0] : 'manual';
2542
+ if (!match) {
2543
+ range.hidden = false;
2544
+ fromEl.value = _odInputValue(from);
2545
+ toEl.value = _odInputValue(to);
2546
+ }
2547
+
2548
+ function send(f, t) {
2549
+ onChange(_odToIso(f, tz), _odToIso(t, tz));
2550
+ }
2551
+
2552
+ // Manual opens an empty range and changes nothing until both ends are picked, as bc-v6's does.
2553
+ select.addEventListener('change', function () {
2554
+ if (select.value === 'manual') {
2555
+ range.hidden = false;
2556
+ fromEl.value = '';
2557
+ toEl.value = '';
2558
+ fromEl.removeAttribute('aria-invalid');
2559
+ toEl.removeAttribute('aria-invalid');
2560
+ return;
2561
+ }
2562
+ range.hidden = true;
2563
+ const r = _odPreset(select.value);
2564
+ send(r[0], r[1]);
2565
+ });
2566
+
2567
+ // A range that ends before it starts is marked and not sent.
2568
+ function onRange() {
2569
+ const f = _odInputDate(fromEl.value);
2570
+ const t = _odInputDate(toEl.value);
2571
+ if (!f || !t) return;
2572
+ const backwards = f.getTime() > t.getTime();
2573
+ fromEl.setAttribute('aria-invalid', String(backwards));
2574
+ toEl.setAttribute('aria-invalid', String(backwards));
2575
+ if (!backwards) send(f, t);
2576
+ }
2577
+ fromEl.addEventListener('change', onRange);
2578
+ toEl.addEventListener('change', onRange);
2579
+
2580
+ p.dates.hidden = false;
2581
+ }
2582
+
2308
2583
  // ── renderTable ───────────────────────────────────────────────────────────────
2309
2584
  // columns: [{ key, label, format?, sortable?, tooltip? }]
2310
2585
  // format receives (value, row) — read row.<key> for per-row currency, etc.
@@ -2614,6 +2889,10 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2614
2889
 
2615
2890
  const clone = document.documentElement.cloneNode(true);
2616
2891
  clone.querySelectorAll('.dk-pt-btn, .dk-od').forEach(function (n) { n.remove(); });
2892
+ clone.querySelectorAll('[data-dk-od-inert]').forEach(function (n) {
2893
+ n.removeAttribute('inert');
2894
+ n.removeAttribute('data-dk-od-inert');
2895
+ });
2617
2896
  clone.querySelectorAll('.dk-od-cell, .dk-od-value').forEach(function (n) {
2618
2897
  n.classList.remove('dk-od-cell', 'dk-od-value', 'dk-od-keep');
2619
2898
  });
@@ -2936,7 +3215,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2936
3215
  };
2937
3216
  },
2938
3217
  // Helpers are also passed into each load() function — that is the canonical
2939
- // way to use them. They are mirrored here so DashboardKit.<helper>(…) works too.
3218
+ // way to use them. They are mirrored here so DashboardKit.<helper>(…) works too,
3219
+ // and set as global names below.
2940
3220
  runQuery,
2941
3221
  setSectionState,
2942
3222
  renderTable,
@@ -2953,6 +3233,26 @@ html[data-dk-setup="true"] .dk-resp-toggle {
2953
3233
  escHtml: esc,
2954
3234
  };
2955
3235
 
3236
+ // Set when the page loads the kit twice: the global names then still hold the first copy's helpers.
3237
+ const earlier = global.DashboardKit;
2956
3238
  global.DashboardKit = DashboardKit;
2957
3239
 
3240
+ // The helpers as global names too, so a call outside the load() that lists it — a helper the
3241
+ // load() left out of its list, or one called from a function at the top of the script — finds it
3242
+ // instead of throwing a ReferenceError that shows only once its tab is opened. A load() argument
3243
+ // of the same name still wins inside that load(). Assigned, never declared: an assigned property
3244
+ // is configurable, so a page's own `function escHtml` or `const formatDate` still declares over
3245
+ // it, where a declaration here would make that a SyntaxError. A name the window already holds for
3246
+ // something else is left as it is.
3247
+ ['runQuery', 'renderTable', 'renderKpiCard', 'renderKpiStrip', 'renderInfoGrid', 'renderTotalsStrip',
3248
+ 'formatCurrency', 'formatInteger', 'formatPercent', 'formatDate', 'formatDatetime', 'colorClass',
3249
+ 'escHtml'].forEach(function (name) {
3250
+ const ours = earlier && global[name] === earlier[name];
3251
+ if (Object.prototype.hasOwnProperty.call(global, name) && !ours) {
3252
+ console.warn('[DashboardKit] window.' + name + ' is already taken; use DashboardKit.' + name);
3253
+ } else {
3254
+ global[name] = DashboardKit[name];
3255
+ }
3256
+ });
3257
+
2958
3258
  }(window));