@makoai/app-sdk 2.26.0 → 2.27.0

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.
@@ -0,0 +1,83 @@
1
+ // Periods for the date filters (2.27): a week, month, quarter or year, or a
2
+ // custom range. Dates are ISO 'YYYY-MM-DD' strings in UTC, both ends
3
+ // inclusive. Pure functions only, no imports. Ported 1:1 from the workspace's
4
+ // apps/attrition-por-cohorte/src/ui/period.ts.
5
+
6
+ export type Unit = "week" | "month" | "quarter" | "year";
7
+ export type Period = { unit: Unit | "custom"; from: string; to: string };
8
+
9
+ const d = (iso: string) => new Date(iso + "T00:00:00Z");
10
+ const iso = (x: Date) => x.toISOString().slice(0, 10);
11
+ export const addDays = (s: string, n: number) => { const x = d(s); x.setUTCDate(x.getUTCDate() + n); return iso(x); };
12
+ export const addMonths = (s: string, n: number) => {
13
+ const x = d(s);
14
+ return iso(new Date(Date.UTC(x.getUTCFullYear(), x.getUTCMonth() + n, 1)));
15
+ };
16
+ /** Today as a UTC day key, the same string as `toDayKey(new Date())`. */
17
+ export const todayIso = () => new Date().toISOString().slice(0, 10);
18
+
19
+ /** The first day of the unit that holds a date. Weeks start on Monday. */
20
+ export function startOf(unit: Unit, s: string): string {
21
+ const x = d(s);
22
+ const y = x.getUTCFullYear(), m = x.getUTCMonth();
23
+ if (unit === "week") return addDays(s, -((x.getUTCDay() + 6) % 7));
24
+ if (unit === "month") return iso(new Date(Date.UTC(y, m, 1)));
25
+ if (unit === "quarter") return iso(new Date(Date.UTC(y, m - (m % 3), 1)));
26
+ return `${y}-01-01`;
27
+ }
28
+ const stepMonths: Record<Exclude<Unit, "week">, number> = { month: 1, quarter: 3, year: 12 };
29
+ /** The last day of the unit that starts on `start`. */
30
+ export function endOf(unit: Unit, start: string): string {
31
+ if (unit === "week") return addDays(start, 6);
32
+ return addDays(addMonths(start, stepMonths[unit]), -1);
33
+ }
34
+ /** The week, month, quarter or year that holds a date: `periodOf("month", "2026-11-19")`. */
35
+ export const periodOf = (unit: Unit, s: string): Period => {
36
+ const from = startOf(unit, s);
37
+ return { unit, from, to: endOf(unit, from) };
38
+ };
39
+
40
+ // Months between two month starts, for stepping a custom range made of whole months.
41
+ const monthSpan = (from: string, to: string) => {
42
+ const a = d(from), b = d(to);
43
+ return (b.getUTCFullYear() - a.getUTCFullYear()) * 12 + b.getUTCMonth() - a.getUTCMonth();
44
+ };
45
+ const wholeMonths = (p: Period) => p.from.slice(8) === "01" && addDays(p.to, 1).slice(8) === "01";
46
+
47
+ /** The period k steps later (k < 0: earlier). A custom range moves by its own length. */
48
+ export function shift(p: Period, k: number): Period {
49
+ if (p.unit === "week") return periodOf("week", addDays(p.from, 7 * k));
50
+ if (p.unit !== "custom") return periodOf(p.unit, addMonths(p.from, stepMonths[p.unit] * k));
51
+ if (wholeMonths(p)) {
52
+ const n = monthSpan(p.from, addDays(p.to, 1));
53
+ return { unit: "custom", from: addMonths(p.from, n * k), to: addDays(addMonths(p.from, n * (k + 1)), -1) };
54
+ }
55
+ const days = Math.round((d(p.to).getTime() - d(p.from).getTime()) / 864e5) + 1;
56
+ return { unit: "custom", from: addDays(p.from, days * k), to: addDays(p.to, days * k) };
57
+ }
58
+
59
+ /** In progress: today falls inside it, so its numbers are not final yet. */
60
+ export const isCurrent = (p: Period, today = todayIso()) => p.from <= today && today <= p.to;
61
+ /** Up to today: a period in progress stops at today. */
62
+ export const clipToday = (p: Period, today = todayIso()) => ({ from: p.from, to: p.to < today ? p.to : today });
63
+
64
+ const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
65
+ const day = (s: string, withYear = true) => `${Number(s.slice(8))} ${MON[Number(s.slice(5, 7)) - 1]}${withYear ? ` ${s.slice(0, 4)}` : ""}`;
66
+ const month = (s: string, withYear = true) => `${MON[Number(s.slice(5, 7)) - 1]}${withYear ? ` ${s.slice(0, 4)}` : ""}`;
67
+
68
+ /** "Nov 2026", "Q4 2026", "2026", "17–23 Nov 2026", "Sep – Nov 2026". */
69
+ export function periodLabel(p: Period): string {
70
+ if (p.unit === "year") return p.from.slice(0, 4);
71
+ if (p.unit === "quarter") return `Q${Math.floor(Number(p.from.slice(5, 7)) / 3) + 1} ${p.from.slice(0, 4)}`;
72
+ if (p.unit === "month") return month(p.from);
73
+ const sameYear = p.from.slice(0, 4) === p.to.slice(0, 4);
74
+ if (p.unit === "custom" && wholeMonths(p)) {
75
+ const last = addDays(p.to, 1 - Number(p.to.slice(8)));
76
+ if (last === p.from) return month(p.from);
77
+ return `${month(p.from, !sameYear)} – ${month(last)}`;
78
+ }
79
+ const sameMonth = sameYear && p.from.slice(5, 7) === p.to.slice(5, 7);
80
+ return sameMonth ? `${Number(p.from.slice(8))}–${day(p.to)}` : `${day(p.from, !sameYear)} – ${day(p.to)}`;
81
+ }
82
+
83
+ export const UNIT_LABEL: Record<Unit, string> = { week: "Week", month: "Month", quarter: "Quarter", year: "Year" };
package/index.d.ts CHANGED
@@ -406,6 +406,13 @@ export function getViewer(): Promise<Viewer | null>;
406
406
 
407
407
  export function useTheme(): { theme: "light" | "dark" };
408
408
 
409
+ /** A market's lowercase code, in COUNTRY_ORDER. */
410
+ export type CountryCode = "ch" | "fr" | "es" | "it" | "pl" | "pt";
411
+ /** One colour per market (2.27), keyed by lowercase code; `all` is the all-markets line. */
412
+ export const COUNTRY_COLORS: Readonly<Record<CountryCode | "all", string>>;
413
+ /** CH, FR, ES, IT, PL, PT (2.27), as lowercase codes. */
414
+ export const COUNTRY_ORDER: readonly CountryCode[];
415
+
409
416
  /**
410
417
  * The theme tokens the SDK injects into <head> on import (Mako's house
411
418
  * palette: --background, --brand, --canvas, --positive, --chart-1…5, …).
package/index.js CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  * in a page (or this export) says which SDK a deployed app actually runs.
39
39
  * Kept in step with package.json by snapshot.test.mjs.
40
40
  */
41
- export const SDK_VERSION = "2.26.0";
41
+ export const SDK_VERSION = "2.27.0";
42
42
  if (typeof window !== "undefined") {
43
43
  try {
44
44
  window.__MAKO_APP_SDK__ = SDK_VERSION;
@@ -2065,6 +2065,23 @@ if (
2065
2065
  }
2066
2066
  }
2067
2067
 
2068
+ // ---------------------------------------------------------------------------
2069
+ // Country colours (2.27): one colour per market in every app, deck and chart,
2070
+ // keyed by the lowercase country code. `all` is the all-markets / group line.
2071
+ // ---------------------------------------------------------------------------
2072
+ export const COUNTRY_COLORS = Object.freeze({
2073
+ ch: "#dc2626",
2074
+ fr: "#2563eb",
2075
+ it: "#16a34a",
2076
+ es: "#f59e0b",
2077
+ pt: "#0891b2",
2078
+ pl: "#db2777",
2079
+ all: "#475569",
2080
+ });
2081
+
2082
+ /** The order countries take in legends, tables and filters: CH, FR, ES, IT, PL, PT. */
2083
+ export const COUNTRY_ORDER = Object.freeze(["ch", "fr", "es", "it", "pl", "pt"]);
2084
+
2068
2085
  // ---------------------------------------------------------------------------
2069
2086
  // Theme — the OS preference; v1 mirrored the host's toggle, a standalone app
2070
2087
  // follows the system.
package/lint.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  // mako-app-lint (2.21; react-version and --rules from 2.24, recharts check
3
- // 2.25): app rules a
3
+ // 2.25, distinct-sum 2.27): app rules a
4
4
  // reviewer kept repeating.
5
5
  //
6
6
  // utc-display getUTC*, timeZone: "UTC" or toISOString().slice in display
@@ -16,9 +16,16 @@
16
16
  // recharts 2 reads chart children with react-is 18, which
17
17
  // drops anything in a <> fragment (19 Nov 2026: reference
18
18
  // lines vanished from a chart).
19
+ // distinct-sum (warning) a binding column that is a distinct count
20
+ // (COUNT(DISTINCT), uniq, APPROX_COUNT_DISTINCT) summed in
21
+ // src/ (SQL SUM(col), or a JS reduce/sum/pivot next to it).
22
+ // One person in several groups counts once per group: on
23
+ // 19 Nov 2026 visibility-dashboard showed ES unique users 13%
24
+ // high. Compute the total at the shown grain (GROUPING SETS)
25
+ // or ignore the line with the reason ("user-days").
19
26
  //
20
27
  // Usage: npx mako-app-lint [app dir …] [--warn] [--rules=a,b]. Exit 1 on
21
- // findings unless --warn. --rules runs only the named rules. A line ending in `// mako-lint-ignore utc-display` is skipped (a
28
+ // findings unless --warn; warnings (distinct-sum) print and never fail. --rules runs only the named rules. A line ending in `// mako-lint-ignore utc-display` is skipped (a
22
29
  // date key the helpers cannot build, with the reason on the line above).
23
30
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
24
31
  import path from "node:path";
@@ -47,6 +54,71 @@ function walk(dir, out = []) {
47
54
  return out;
48
55
  }
49
56
 
57
+ const DISTINCT_SQL = /\b(?:count\s*\(\s*distinct\b|countDistinct\w*\s*\(|uniq(?:Exact|Combined|HLL12|Theta)?(?:If)?\s*\(|approx_count_distinct\s*\(|hll_count\.\w+\s*\(|approx_distinct\s*\()/gi;
58
+ const CAST_TYPES = /^(int64|string|float64|numeric|bigint|integer|double|int|int32|uint64|uint32)$/i;
59
+
60
+ /** Distinct-count output columns of the app's bindings: column → binding names. */
61
+ export function distinctColumns(appDir) {
62
+ const dir = path.join(appDir, "bindings");
63
+ const cols = new Map();
64
+ if (!existsSync(dir)) return cols;
65
+ for (const f of readdirSync(dir).filter(n => n.endsWith(".sql"))) {
66
+ const sql = readFileSync(path.join(dir, f), "utf8").replace(/--[^\n]*/g, "");
67
+ for (const m of sql.matchAll(DISTINCT_SQL)) {
68
+ let i = m.index + m[0].length;
69
+ for (let depth = 1; i < sql.length && depth > 0; i++) {
70
+ if (sql[i] === "(") depth++;
71
+ else if (sql[i] === ")") depth--;
72
+ }
73
+ // The alias: the last "AS name" before the next top-level comma (covers CAST(... AS INT64) AS x).
74
+ const tail = sql.slice(i, i + 160);
75
+ let end = tail.length;
76
+ for (let j = 0, d = 0; j < tail.length; j++) {
77
+ if (tail[j] === "(") d++;
78
+ else if (tail[j] === ")") d = Math.max(0, d - 1);
79
+ else if (tail[j] === "," && d === 0) { end = j; break; }
80
+ }
81
+ const as = [...tail.slice(0, end).matchAll(/\bAS\s+[`"]?(\w+)/gi)].pop();
82
+ if (!as || CAST_TYPES.test(as[1])) continue;
83
+ if (!cols.has(as[1])) cols.set(as[1], new Set());
84
+ cols.get(as[1]).add(f.slice(0, -4));
85
+ }
86
+ }
87
+ return cols;
88
+ }
89
+
90
+ const JS_SUM = /\.reduce\s*\(|\bsum(?:By|Of)?\s*\(|\bd3\.sum\b|\+=|\bpivot\s*\(/;
91
+
92
+ /** distinct-sum: a distinct-count column summed in this src file, which reads its binding. */
93
+ function distinctSumFindings(rel, text, cols) {
94
+ const out = [];
95
+ if (!cols.size) return out;
96
+ const lines = text.split("\n");
97
+ const reads = new Map();
98
+ for (const [col, bindings] of cols) {
99
+ const read = [...bindings].filter(b => new RegExp(`["'\`]${b}["'\`]|\\b(?:from|join)\\s+["]?${b}\\b`, "i").test(text));
100
+ if (read.length) reads.set(col, read);
101
+ }
102
+ if (!reads.size) return out;
103
+ lines.forEach((line, i) => {
104
+ if (/mako-lint-ignore distinct-sum/.test(line) || /mako-lint-ignore distinct-sum/.test(lines[i - 1] ?? "")) return;
105
+ for (const [col, bindings] of reads) {
106
+ const sqlSum = new RegExp(`\\bsum\\s*\\(\\s*(?:\\w+\\.)?["\`]?${col}["\`]?\\s*\\)`, "i");
107
+ const jsRef = new RegExp(`(?:[.?]\\.?${col}\\b|\\[\\s*["'\`]${col}["'\`]\\s*\\])`);
108
+ const win = lines.slice(Math.max(0, i - 1), i + 2).join(" ");
109
+ if (!sqlSum.test(line) && !(jsRef.test(line) && JS_SUM.test(win))) continue;
110
+ out.push({
111
+ file: rel,
112
+ line: i + 1,
113
+ rule: "distinct-sum",
114
+ level: "warn",
115
+ message: `${col} is a distinct count in ${bindings.join(", ")}: summed across groups it counts one entity once per group. Compute the total at the shown grain (GROUPING SETS), or add // mako-lint-ignore distinct-sum with the reason`,
116
+ });
117
+ }
118
+ });
119
+ return out;
120
+ }
121
+
50
122
  /** The lowest major a package.json range allows: "^18.2.0" → 18, ">=19" → 19; null when unreadable. */
51
123
  export function minMajor(range) {
52
124
  const m = /(\d+)/.exec(String(range ?? ""));
@@ -100,8 +172,10 @@ export function lintApp(appDir, rules) {
100
172
  const on = name => !rules || rules.includes(name);
101
173
  const findings = on("react-version") ? reactVersionFindings(appDir) : [];
102
174
  const src = path.join(appDir, "src");
175
+ const distinct = on("distinct-sum") ? distinctColumns(appDir) : new Map();
103
176
  for (const file of walk(src)) {
104
177
  const rel = path.relative(appDir, file);
178
+ if (distinct.size) findings.push(...distinctSumFindings(rel, readFileSync(file, "utf8"), distinct));
105
179
  const ui = /^src[\\/]components[\\/]ui[\\/]([a-z-]+)\.tsx$/.exec(rel);
106
180
  if (on("local-shadcn") && ui && SDK_COMPONENTS.includes(ui[1])) {
107
181
  const from = ["dropdown-menu", "checkbox"].includes(ui[1])
@@ -132,13 +206,15 @@ function main(argv) {
132
206
  const rules = rulesArg ? rulesArg.slice("--rules=".length).split(",").filter(Boolean) : undefined;
133
207
  const dirs = argv.filter(a => !a.startsWith("--"));
134
208
  let total = 0;
209
+ let warnings = 0;
135
210
  for (const dir of dirs.length ? dirs : ["."]) {
136
211
  for (const f of lintApp(path.resolve(dir), rules)) {
137
- total++;
138
- console.log(`${path.join(dir, f.file)}:${f.line} ${f.rule} ${f.message}`);
212
+ if (f.level === "warn") warnings++;
213
+ else total++;
214
+ console.log(`${path.join(dir, f.file)}:${f.line} ${f.rule}${f.level === "warn" ? " (warning)" : ""} ${f.message}`);
139
215
  }
140
216
  }
141
- if (total) console.log(`\n${total} finding${total === 1 ? "" : "s"}`);
217
+ if (total || warnings) console.log(`\n${total} finding${total === 1 ? "" : "s"}, ${warnings} warning${warnings === 1 ? "" : "s"}`);
142
218
  return total && !warn ? 1 : 0;
143
219
  }
144
220
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makoai/app-sdk",
3
- "version": "2.26.0",
3
+ "version": "2.27.0",
4
4
  "description": "Mako app SDK: data bindings (useQuery/useDuckDB), URL state, theme, and the house dashboard kit (/ui).",
5
5
  "license": "MIT",
6
6
  "repository": {
package/ui-core.js CHANGED
@@ -66,17 +66,32 @@ export function tooltipValueState(v) {
66
66
  * stays as a row with `state: "zero"`; a missing value stays with
67
67
  * `value: null` and `state: "missing"`. Render the cells with `tooltipCell`.
68
68
  *
69
+ * `absentAsZero: true` counts a null or absent key as 0: a stack segment
70
+ * with no rows in a bucket that has data shows a muted "0", not "–". NaN and
71
+ * ±Infinity stay missing. `share: true` adds `share` to every row: its value
72
+ * over the sum of the non-missing values, null when the value is missing or
73
+ * the sum is not above 0. Render it with `tooltipCell(r.share, fmtPct,
74
+ * { percent: true })`: a zero share shows a muted "0%".
75
+ *
69
76
  * Opt-outs, for a caller that truly needs the pre-2.15 behaviour:
70
77
  * `hideEmpty: true` drops zero and missing rows; `byValue: true` sorts
71
78
  * non-stacked rows highest value first (missing last).
72
- * Returns `{ key, label, color, value, state }`.
79
+ * Returns `{ key, label, color, value, state }`, plus `share` with `share: true`.
73
80
  */
74
- export function tooltipSeriesRows(datum, series, { stacked = false, hideEmpty = false, byValue = false } = {}) {
81
+ export function tooltipSeriesRows(
82
+ datum,
83
+ series,
84
+ { stacked = false, hideEmpty = false, byValue = false, absentAsZero = false, share = false } = {},
85
+ ) {
75
86
  let rows = series.map(s => {
76
- const raw = datum?.[s.key];
87
+ const raw = absentAsZero && datum?.[s.key] == null ? 0 : datum?.[s.key];
77
88
  const state = tooltipValueState(raw);
78
89
  return { key: s.key, label: s.label ?? s.key, color: s.color, value: state === "missing" ? null : Number(raw), state };
79
90
  });
91
+ if (share) {
92
+ const total = rows.reduce((a, r) => a + (r.value ?? 0), 0);
93
+ rows = rows.map(r => ({ ...r, share: r.value == null || !(total > 0) ? null : r.value / total }));
94
+ }
80
95
  if (hideEmpty) rows = rows.filter(r => r.state === "value");
81
96
  if (stacked) return rows.reverse();
82
97
  if (!byValue) return rows;
@@ -180,6 +195,27 @@ export function defaultColumnWidth(column, index = 1) {
180
195
  return COLUMN_WIDTHS.text;
181
196
  }
182
197
 
198
+ /**
199
+ * A DataTable's column groups: each run of adjacent columns with the same
200
+ * `group` is one group, spanning those columns in the header's top row. A
201
+ * column with no `group` is its own run (`group: null`) and spans both header
202
+ * rows. `start` marks a run that follows a column that is not pinned: it
203
+ * draws the line between sections. Returns null when no column has a `group`
204
+ * (a one-row header).
205
+ * Returns `[{ group: string | null, start: boolean, columns: [column, …] }]`.
206
+ */
207
+ export function columnGroupRuns(columns) {
208
+ if (!columns.some(c => c.group != null)) return null;
209
+ const runs = [];
210
+ columns.forEach((col, i) => {
211
+ const group = col.group ?? null;
212
+ const last = runs[runs.length - 1];
213
+ if (group != null && last?.group === group) last.columns.push(col);
214
+ else runs.push({ group, start: i > 0 && !columns[i - 1].sticky, columns: [col] });
215
+ });
216
+ return runs;
217
+ }
218
+
183
219
  /**
184
220
  * The fixed layout of a DataTable: one `<col>` width per column and the
185
221
  * table's minimum width (their sum). Every column is exactly its `width`
@@ -389,6 +425,33 @@ export function filterLeavesOf(node) {
389
425
  return node.children ? filterLeaves(node.children) : [node.value];
390
426
  }
391
427
 
428
+ /**
429
+ * The rows a search shows (2.27): null when `query` is blank (every row), else
430
+ * the set of node values to render. A row shows when its label holds the
431
+ * query (case-insensitive, trimmed), or when a row under it does. A group
432
+ * whose label matches shows every row under it.
433
+ */
434
+ export function filterSearch(options, query) {
435
+ const needle = String(query ?? "").trim().toLowerCase();
436
+ if (!needle) return null;
437
+ const shown = new Set();
438
+ const all = node => {
439
+ shown.add(node.value);
440
+ node.children?.forEach(all);
441
+ };
442
+ const walk = node => {
443
+ if (String(node.label ?? node.value).toLowerCase().includes(needle)) {
444
+ all(node);
445
+ return true;
446
+ }
447
+ const hit = (node.children ?? []).map(walk).some(Boolean);
448
+ if (hit) shown.add(node.value);
449
+ return hit;
450
+ };
451
+ options.forEach(walk);
452
+ return shown;
453
+ }
454
+
392
455
  /** The node with `value` anywhere in the tree. */
393
456
  export function filterFind(options, value) {
394
457
  for (const o of options) {
package/ui.css CHANGED
@@ -217,6 +217,9 @@ button, input, select, textarea { font-family: inherit; }
217
217
  padding: 7px 10px; text-align: left; white-space: nowrap; vertical-align: middle; overflow: hidden;
218
218
  border-bottom: 1px solid var(--mk-row-line); background: var(--card);
219
219
  }
220
+ /* A row tint (rowClassName) sets --mk-dt-row-bg on the <tr>. Every body cell,
221
+ * the pinned one included, paints it, so the tint survives the solid pin. */
222
+ .mk-dt-table tbody td { background: var(--mk-dt-row-bg, var(--card)); }
220
223
  .mk-dt-table thead th {
221
224
  position: sticky; top: 0; z-index: 2; padding: 0; border-bottom: 0;
222
225
  font-size: 12px; font-weight: 500; color: var(--muted-foreground);
@@ -243,11 +246,23 @@ button, input, select, textarea { font-family: inherit; }
243
246
  /* The corner cell is pinned both ways and keeps BOTH borders: one box-shadow
244
247
  * would otherwise override the other and drop the header's bottom rule. */
245
248
  .mk-dt-table thead th.mk-dt-pin { z-index: 3; box-shadow: inset -1px 0 0 var(--border), inset 0 -1px 0 var(--border); }
246
- .mk-dt-table tbody tr:hover > td { background: color-mix(in srgb, var(--muted) 50%, var(--card)); }
249
+ /* Column groups: a 2-row header. The whole <thead> sticks (two rows of
250
+ * sticky cells would stack at top: 0) and the pinned corner still sticks
251
+ * left. A group label spans its columns, centred, uppercase, with no rule
252
+ * under it. A line runs down the left of each section, head to foot. */
253
+ .mk-dt-table--grouped thead { position: sticky; top: 0; z-index: 2; }
254
+ .mk-dt-table--grouped thead th { position: static; }
255
+ .mk-dt-table--grouped thead th.mk-dt-pin { position: sticky; top: auto; left: 0; }
256
+ .mk-dt-table thead th.mk-dt-group {
257
+ height: 26px; padding: 0 10px; text-align: center; box-shadow: none;
258
+ font-size: 11px; font-weight: 600; letter-spacing: .075em; text-transform: uppercase;
259
+ }
260
+ .mk-dt-table .mk-dt-section { border-left: 1px solid var(--border); }
261
+ .mk-dt-table tbody tr:hover > td { background: color-mix(in srgb, var(--muted) 50%, var(--mk-dt-row-bg, var(--card))); }
247
262
  .mk-dt-table tbody tr:last-child > td { border-bottom: 0; }
248
263
  .mk-dt-click { cursor: pointer; }
249
264
  .mk-dt-click:focus-visible { outline: none; }
250
- .mk-dt-click:focus-visible > td { background: color-mix(in srgb, var(--muted) 70%, var(--card)); }
265
+ .mk-dt-click:focus-visible > td { background: color-mix(in srgb, var(--muted) 70%, var(--mk-dt-row-bg, var(--card))); }
251
266
  .mk-dt-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
252
267
  /* A render() that returns blocks (a name over its links) ellipsizes each line. */
253
268
  .mk-dt-cell :where(div, p) { overflow: hidden; text-overflow: ellipsis; }
@@ -322,6 +337,22 @@ button, input, select, textarea { font-family: inherit; }
322
337
  .mk-ms-box.on { background: var(--brand, var(--primary)); border-color: var(--brand, var(--primary)); color: #fff; }
323
338
  .mk-ms-swatch { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
324
339
  .mk-ms-sep { height: 1px; background: var(--border); margin: 4px -4px; flex: none; }
340
+ /* MultiSelect `searchable` (2.27): shadcn's CommandInput (36px, a search icon,
341
+ * a hairline under it), pinned at the top while the rows scroll. The
342
+ * highlighted row is cmdk's data-selected one. */
343
+ .mk-ms-search {
344
+ position: sticky; top: -4px; z-index: 1; flex: none;
345
+ display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; margin: -4px -4px 4px;
346
+ background: var(--popover); border-bottom: 1px solid var(--border);
347
+ }
348
+ .mk-ms-search-icon { flex-shrink: 0; opacity: .5; }
349
+ .mk-ms-search-input {
350
+ flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; box-shadow: none;
351
+ background: transparent; color: var(--foreground); font: inherit; font-size: 14px;
352
+ }
353
+ .mk-ms-search-input::placeholder { color: var(--muted-foreground); }
354
+ .mk-ms-opt[data-selected="true"] { background: var(--accent); }
355
+ .mk-ms-empty { padding: 24px 8px; text-align: center; font-size: 14px; color: var(--muted-foreground); }
325
356
  .mk-ms-only {
326
357
  appearance: none; border: 0; background: transparent; color: var(--muted-foreground);
327
358
  font-size: 12px; font-weight: 500; padding: 0 4px; border-radius: var(--mk-radius-sm); visibility: hidden;
package/ui.d.ts CHANGED
@@ -97,6 +97,17 @@ export interface FilterItemsProps<V extends string = string> {
97
97
  /** The "nothing ticked" draft, when the parent shows it; else FilterItems keeps it. */
98
98
  none?: boolean;
99
99
  onNoneChange?: (none: boolean) => void;
100
+ /**
101
+ * A search input above the rows (2.27), as shadcn's Command: it takes focus,
102
+ * filters rows by label as you type (a group whose label matches keeps its
103
+ * rows) and hides All while a query is typed. ArrowDown/ArrowUp move the
104
+ * highlighted row, Enter ticks it. Default false: no input, rows unchanged.
105
+ */
106
+ searchable?: boolean;
107
+ /** The search input's placeholder and accessible name. Default "Search". */
108
+ searchPlaceholder?: string;
109
+ /** Shown when no row matches. Default "No match". */
110
+ searchEmpty?: string;
100
111
  className?: string;
101
112
  "aria-label"?: string;
102
113
  }
@@ -142,6 +153,12 @@ export interface MultiSelectProps<V extends string = string> {
142
153
  maxChips?: number;
143
154
  /** Which edge the menu aligns to before flipping. Default "start". */
144
155
  align?: "start" | "end";
156
+ /** A search input at the top of the menu (2.27): search, All, a separator, the values. See FilterItemsProps. */
157
+ searchable?: boolean;
158
+ /** Default "Search". */
159
+ searchPlaceholder?: string;
160
+ /** Default "No match". */
161
+ searchEmpty?: string;
145
162
  className?: string;
146
163
  "aria-label"?: string;
147
164
  }
@@ -285,6 +302,8 @@ export interface TableTooltipProps {
285
302
  total?: TooltipRow;
286
303
  /** Rows after the total, apart: a value on another axis. */
287
304
  after?: TooltipRow[];
305
+ /** The value columns' minimum width: "9ch", or px as a number. Default 7ch. */
306
+ colWidth?: number | string;
288
307
  className?: string;
289
308
  }
290
309
  /** The house chart tooltip: a table with swatches, right-aligned numbers and a total row. */
@@ -303,6 +322,8 @@ export interface TooltipSeriesRow<K extends string = string> {
303
322
  /** null when missing. */
304
323
  value: number | null;
305
324
  state: TooltipValueState;
325
+ /** With `share: true`: value ÷ the sum of the non-missing values; null when missing or the sum is not above 0. */
326
+ share?: number | null;
306
327
  }
307
328
  export interface TooltipSeriesRowsOptions {
308
329
  /** Pass series bottom-up, as drawn; the rows read top segment first. */
@@ -311,6 +332,10 @@ export interface TooltipSeriesRowsOptions {
311
332
  hideEmpty?: boolean;
312
333
  /** Opt-out: sort non-stacked rows highest value first, missing last (pre-2.15). */
313
334
  byValue?: boolean;
335
+ /** A null or absent key counts as 0 (a muted "0"): a stack segment with no rows in the bucket. NaN stays missing. */
336
+ absentAsZero?: boolean;
337
+ /** Adds `share`: value ÷ the sum of the non-missing values; null when missing or the sum is not above 0. */
338
+ share?: boolean;
314
339
  }
315
340
  /**
316
341
  * Every series of the hovered datum, in a fixed order: stacked = top segment
@@ -383,6 +408,12 @@ export interface DataTableColumn<R = any> {
383
408
  sortable?: boolean;
384
409
  /** Header hover text, e.g. the column's definition. */
385
410
  hint?: string;
411
+ /**
412
+ * The column group's id. Adjacent columns with the same `group` share one
413
+ * label in a header row on top (see `DataTableProps.groups`); ungrouped
414
+ * columns span both header rows.
415
+ */
416
+ group?: string;
386
417
  /**
387
418
  * false leaves the column out of CSV; a function exports a readable cell (a
388
419
  * level name). Numbers export as is; a Date at local or UTC midnight exports
@@ -390,6 +421,54 @@ export interface DataTableColumn<R = any> {
390
421
  */
391
422
  csv?: false | ((row: R) => unknown);
392
423
  }
424
+ /** A column group's header: its label spans the adjacent columns with `group: id`. */
425
+ export interface DataTableGroup {
426
+ id: string;
427
+ label?: React.ReactNode;
428
+ /** On the group's header cell, e.g. a colour per section. */
429
+ className?: string;
430
+ }
431
+ /** The header runs of a DataTable's columns; null when no column has a `group`. */
432
+ export function columnGroupRuns<C extends { id: string; group?: string; sticky?: boolean }>(
433
+ columns: readonly C[],
434
+ ): { group: string | null; start: boolean; columns: C[] }[] | null;
435
+ /**
436
+ * Every piece of text a DataTable renders itself: the footer, the pager's
437
+ * aria-labels, the sort hint and the export button. Text with numbers is a
438
+ * function that gets the raw numbers, so the app formats them in its locale.
439
+ */
440
+ export interface DataTableLabels {
441
+ /** The footer with rows. Default `<b>1–50</b> of <b>312</b> customers`. */
442
+ range: (from: number, to: number, total: number, noun: string) => React.ReactNode;
443
+ /** The footer with no rows. Default "No customers". */
444
+ none: (noun: string) => React.ReactNode;
445
+ /** The body cell with no rows. Default "No rows match these filters." The `empty` prop wins over it. */
446
+ empty: React.ReactNode;
447
+ /** Default "Page 2 of 7". */
448
+ page: (page: number, pageCount: number) => string;
449
+ /** One page-size option. Default "50 per page". */
450
+ perPage: (size: number) => string;
451
+ /** The page-size select's aria-label. Default "Rows per page". */
452
+ rowsPerPage: string;
453
+ /** The « button's aria-label. Default "First page". */
454
+ first: string;
455
+ /** The ‹ button's aria-label. Default "Previous page". */
456
+ previous: string;
457
+ /** The › button's aria-label. Default "Next page". */
458
+ next: string;
459
+ /** The » button's aria-label. Default "Last page". */
460
+ last: string;
461
+ /** A sortable header's hover title. Default "MRR · click to sort". */
462
+ sortHint: (label: string) => string;
463
+ /** Default "Export CSV". */
464
+ exportCsv: string;
465
+ /** The export button's hover title. Default "Export every row on every page, as sorted". */
466
+ exportTitle: string;
467
+ /** Shown when the browser blocks the CSV download. */
468
+ exportFailed: string;
469
+ }
470
+ /** The English defaults of `DataTableLabels`. */
471
+ export const DATA_TABLE_LABELS: DataTableLabels;
393
472
  export interface DataTableProps<R = any> {
394
473
  /** Default [] (renders the empty state while loading). */
395
474
  rows?: readonly R[];
@@ -428,6 +507,12 @@ export interface DataTableProps<R = any> {
428
507
  noun?: string;
429
508
  /** Shown when there are no rows. Default "No rows match these filters." */
430
509
  empty?: React.ReactNode;
510
+ /**
511
+ * Override any footer, pager, sort-hint or export text, e.g. French:
512
+ * `{ page: (p, n) => "Page " + p + " sur " + n }`. Missing keys keep the
513
+ * English default (`DATA_TABLE_LABELS`). The README has a full French set.
514
+ */
515
+ labels?: Partial<DataTableLabels>;
431
516
  /** Fill the parent's height; the body scrolls inside the card. */
432
517
  fill?: boolean;
433
518
  /** Body scroll height when not `fill`. Default 70vh. */
@@ -436,8 +521,18 @@ export interface DataTableProps<R = any> {
436
521
  onRowClick?: (row: R, event: React.SyntheticEvent) => void;
437
522
  /** The accessible name of a clickable row, e.g. `c => \`Open ${c.name}\``. */
438
523
  rowLabel?: (row: R) => string;
524
+ /**
525
+ * A class for a body row, e.g. `d => d.status === "lost" ? "deal-lost" : undefined`.
526
+ * Tint the row by setting `--mk-dt-row-bg` in that class: every cell paints
527
+ * it, the pinned first column included. Use an opaque colour, such as
528
+ * `color-mix(in srgb, var(--negative) 12%, var(--card))`, so scrolled cells
529
+ * stay hidden behind the pin. Default undefined: rows get no class.
530
+ */
531
+ rowClassName?: (row: R) => string | undefined;
439
532
  /** Adds an "Export CSV" button: downloads every row, as sorted. */
440
533
  exportFilename?: string;
534
+ /** Labels and classes for the column groups, by `DataTableColumn.group`. A group not listed shows its id. */
535
+ groups?: readonly DataTableGroup[];
441
536
  className?: string;
442
537
  style?: React.CSSProperties;
443
538
  }