@datalabz_/dashboard-kit 6.0.10 → 6.0.12

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 (4) hide show
  1. package/package.json +1 -1
  2. package/v4.js +1 -1
  3. package/v5.js +1 -1
  4. package/v6.js +67 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalabz_/dashboard-kit",
3
- "version": "6.0.10",
3
+ "version": "6.0.12",
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 = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = '79c14b3'; // replaced at deploy: sed -i "s/79c14b3/$(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 = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v4.js
23
+ let _gitVer = '79c14b3'; // replaced at deploy: sed -i "s/79c14b3/$(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,8 +20,9 @@
20
20
  let _activeTabId = '';
21
21
  let _sections = []; // { id, label, load, loaded, errors }
22
22
  let _title = '';
23
- let _gitVer = '320ab06'; // replaced at deploy: sed -i "s/320ab06/$(git rev-parse --short HEAD)/g" v6.js
23
+ let _gitVer = '79c14b3'; // replaced at deploy: sed -i "s/79c14b3/$(git rev-parse --short HEAD)/g" v6.js
24
24
  let _calls = []; // System Info call log
25
+ let _pageErrors = []; // System Info: errors no load() caught (a handler's, a timer's, the page script's)
25
26
  let _sectionErrors = {}; // sectionId → error count
26
27
  let _generation = 0;
27
28
  let _abort = new AbortController(); // this generation's requests; _invalidateAll aborts them
@@ -1089,6 +1090,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1089
1090
  return n.toFixed(typeof decimals === 'number' ? decimals : 2) + '%';
1090
1091
  }
1091
1092
 
1093
+ // A ratio shown as a percentage: 0.123 → 12.30%, where formatPercent takes 12.3. Which one a
1094
+ // value is, the call says, and the ×100 is the kit's: in a page, null * 100 is 0, so a ratio
1095
+ // with no base (NULLIF) would show 0.00% instead of —. Same type-check as _fmtDate.
1096
+ function formatRatio(v, decimals) {
1097
+ const n = parseFloat(v);
1098
+ if (isNaN(n)) return '—';
1099
+ return formatPercent(n * 100, decimals);
1100
+ }
1101
+
1092
1102
  function colorClass(v) {
1093
1103
  const n = Number(v);
1094
1104
  return n > 0 ? 'pos' : n < 0 ? 'neg' : '';
@@ -1603,6 +1613,18 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1603
1613
  // its own, so without this reset a section that fails once, then succeeds
1604
1614
  // on retry, would keep showing its old error badge forever.
1605
1615
  _sectionErrors[sec.id] = 0;
1616
+ // Chart.js keeps every chart in its registry, data and all, until destroy(). The spinner below
1617
+ // replaces the panel's canvases, so their charts go first: a dashboard that forgot its own
1618
+ // Chart.getChart(id)?.destroy() would keep one dead chart per reload. One that did not forget
1619
+ // then finds none, as on a first load.
1620
+ const Chart = global.Chart;
1621
+ if (Chart && Chart.instances) {
1622
+ Object.keys(Chart.instances).forEach(function (k) {
1623
+ const chart = Chart.instances[k];
1624
+ if (!chart || !chart.canvas || !panel.contains(chart.canvas)) return;
1625
+ try { chart.destroy(); } catch (err) { console.error('[DashboardKit] could not destroy a chart:', err); }
1626
+ });
1627
+ }
1606
1628
  setSectionState(panel, 'loading');
1607
1629
  _setPill('loading', 'loading…');
1608
1630
  // What a click point drawn by this load reports: this section, and the header filters and the
@@ -1611,8 +1633,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1611
1633
  // Kept on the section for a render call that arrives without it (_ctxOf).
1612
1634
  sec.ctx = ctx;
1613
1635
  // A replaced load must not draw (see _superseded). It stops at its next query; these stop one that
1614
- // catches that itself and draws anyway, a dashboard wrapping its queries in try/catch. Only while
1615
- // the load runs: a handler it leaves behind calls and draws as it always has.
1636
+ // was awaiting something else when it was replaced and draws on its return. Only while the load
1637
+ // runs: a handler it leaves behind calls and draws as it always has.
1616
1638
  let running = true;
1617
1639
  const replaced = function () { return running && gen !== _generation; };
1618
1640
  try {
@@ -1620,6 +1642,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1620
1642
  runQuery: function (s, l, q, a, p) { return runQuery(s, l, q, a, p, running ? gen : null); },
1621
1643
  formatCurrency,
1622
1644
  formatPercent,
1645
+ formatRatio,
1623
1646
  formatInteger: fmtInt,
1624
1647
  formatDate: fmtDate,
1625
1648
  formatDatetime: fmtDatetime,
@@ -1638,8 +1661,6 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1638
1661
  sec.errors = _sectionErrors[sec.id] || 0;
1639
1662
  } catch (e) {
1640
1663
  running = false;
1641
- // Not a failure: a newer load replaced this one, and it reports its own.
1642
- if (e && e.dkSuperseded && gen !== _generation) return;
1643
1664
  // The real exception, stack and dkCall included — the panel and the report only get a phrase.
1644
1665
  console.error('[DashboardKit] section "' + sec.id + '" failed:', e);
1645
1666
  console.log('[DashboardKit] section "' + sec.id + '" failed:', e);
@@ -1712,13 +1733,14 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1712
1733
  // ── runQuery ──────────────────────────────────────────────────────────────────
1713
1734
  // A load that Refresh or new host params replaced must not draw: its rows are for the old period or
1714
1735
  // filters, and would land over the newer load's, with drillthrough points reporting either load's
1715
- // filters. So a query a replaced load made never returns: it is aborted and throws this, which the
1716
- // kit drops. A query no running load made — a handler's — is left as it always was: replacing
1717
- // its section's load never touched it, so it must not start failing now (README → Rules).
1736
+ // filters. So a query a replaced load made is aborted and never settles: the load stays on its
1737
+ // await and runs nothing after it. Not a throw: a dashboard that wraps its queries in try/catch
1738
+ // would draw its own "No data" or error text over the newer load's. A fresh promise each time:
1739
+ // one shared never-settling promise would hold every load ever left on it. A query no running
1740
+ // load made — a handler's — is left as it always was: replacing its section's load never touched
1741
+ // it, so it must not start failing now (README → Rules).
1718
1742
  function _superseded() {
1719
- const err = new Error('superseded by a newer load');
1720
- err.dkSuperseded = true;
1721
- return err;
1743
+ return new Promise(function () {});
1722
1744
  }
1723
1745
 
1724
1746
  // One retry, only where _isRetryable says the same request may succeed.
@@ -1731,7 +1753,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1731
1753
  gen = sec && sec.pending && sec.runGen === _generation ? _generation : null;
1732
1754
  }
1733
1755
  const replaced = function () { return gen !== null && gen !== _generation; };
1734
- if (replaced()) throw _superseded();
1756
+ if (replaced()) return _superseded();
1735
1757
  const signal = gen === null ? undefined : _abort.signal;
1736
1758
  const t0 = performance.now();
1737
1759
  const entry = {
@@ -1767,7 +1789,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1767
1789
  });
1768
1790
  entry.status = res.status;
1769
1791
  const text = await res.text();
1770
- if (replaced()) throw _superseded();
1792
+ if (replaced()) return _superseded();
1771
1793
  entry.bytes = text.length;
1772
1794
  let data;
1773
1795
  try { data = JSON.parse(text); } catch { data = { _raw: text }; }
@@ -1802,7 +1824,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
1802
1824
  return data.rows;
1803
1825
  } catch (err) {
1804
1826
  // Before anything is counted: an aborted fetch is no network error, and a replaced load no failure.
1805
- if (replaced()) throw _superseded();
1827
+ if (replaced()) return _superseded();
1806
1828
  // The failed-response throw lands here too — already built.
1807
1829
  if (err && err.dkCall) throw err;
1808
1830
  entry.clientMs = Math.round(performance.now() - t0);
@@ -3066,6 +3088,15 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3066
3088
  '<tr><td>Client duration</td><td>' + totMs + ' ms</td></tr>' +
3067
3089
  '<tr><td>Bytes received</td><td>' + fmtInt(totB) + '</td></tr>' +
3068
3090
  '</table></div>' +
3091
+ (_pageErrors.length
3092
+ ? '<div><h3>Page errors</h3>' + _pageErrors.map(function (p) {
3093
+ return '<details class="dk-call"><summary>' +
3094
+ '<span class="dk-s-err">' + (p.kind === 'rejection' ? 'REJECTED' : 'ERROR') + '</span>' +
3095
+ '<span style="flex:1">' + esc(p.message) + '</span>' +
3096
+ '<span style="color:var(--muted);font-size:10px">' + p.ts.slice(11, 19) + '</span>' +
3097
+ '</summary><div class="dk-call-body"><pre>' + esc(p.stack || p.message) + '</pre></div></details>';
3098
+ }).join('') + '</div>'
3099
+ : '') +
3069
3100
  '<div><h3>Calls <button id="dk-sysinfo-export" style="margin-left:8px;background:transparent;color:var(--brand);border:1px solid var(--brand);border-radius:3px;padding:0 8px;height:22px;font-size:11px;cursor:pointer">Export JSON ↓</button></h3>' +
3070
3101
  callsHtml + '</div>' +
3071
3102
  '</div>';
@@ -3089,6 +3120,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3089
3120
  return Object.assign({}, c, { requestHeaders: { 'Content-Type': 'application/json', Authorization: 'Bearer ***' } });
3090
3121
  }),
3091
3122
  };
3123
+ if (_pageErrors.length) payload.pageErrors = _pageErrors;
3092
3124
  const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
3093
3125
  const a = document.createElement('a');
3094
3126
  a.href = URL.createObjectURL(blob);
@@ -3226,6 +3258,24 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3226
3258
  return div;
3227
3259
  }
3228
3260
 
3261
+ // ── Errors no load() caught ── a section's load() failing shows in its panel; a click or change
3262
+ // handler, a timer or the page's own script failing showed nowhere but the browser console, so a
3263
+ // dead control looked like a working one in System Info. Recorded only: the page and the browser's
3264
+ // own reporting are left as they are. Capped, so a handler failing on every mousemove stays cheap.
3265
+ const PAGE_ERRORS_MAX = 50;
3266
+ function _pageError(kind, err, fallback) {
3267
+ if (_pageErrors.length >= PAGE_ERRORS_MAX) return;
3268
+ _pageErrors.push({
3269
+ ts: new Date().toISOString(),
3270
+ kind: kind,
3271
+ message: String((err && err.message) || fallback || err),
3272
+ stack: err && err.stack ? String(err.stack).slice(0, 2000) : null,
3273
+ });
3274
+ _renderSystemInfo();
3275
+ }
3276
+ global.addEventListener('error', function (e) { _pageError('error', e.error, e.message); });
3277
+ global.addEventListener('unhandledrejection', function (e) { _pageError('rejection', e.reason); });
3278
+
3229
3279
  // ── Number-input guard ── a focused type=number takes the wheel. { passive: false }
3230
3280
  // is required for preventDefault; v4.css hides the spinners.
3231
3281
  document.addEventListener(
@@ -3264,6 +3314,7 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3264
3314
  formatCurrency,
3265
3315
  formatInteger: fmtInt,
3266
3316
  formatPercent,
3317
+ formatRatio,
3267
3318
  formatDate: fmtDate,
3268
3319
  formatDatetime: fmtDatetime,
3269
3320
  colorClass,
@@ -3282,8 +3333,8 @@ html[data-dk-setup="true"] .dk-resp-toggle {
3282
3333
  // it, where a declaration here would make that a SyntaxError. A name the window already holds for
3283
3334
  // something else is left as it is.
3284
3335
  ['runQuery', 'renderTable', 'renderKpiCard', 'renderKpiStrip', 'renderInfoGrid', 'renderTotalsStrip',
3285
- 'formatCurrency', 'formatInteger', 'formatPercent', 'formatDate', 'formatDatetime', 'colorClass',
3286
- 'escHtml'].forEach(function (name) {
3336
+ 'formatCurrency', 'formatInteger', 'formatPercent', 'formatRatio', 'formatDate', 'formatDatetime',
3337
+ 'colorClass', 'escHtml'].forEach(function (name) {
3287
3338
  const ours = earlier && global[name] === earlier[name];
3288
3339
  if (Object.prototype.hasOwnProperty.call(global, name) && !ours) {
3289
3340
  console.warn('[DashboardKit] window.' + name + ' is already taken; use DashboardKit.' + name);