@makoai/app-sdk 2.26.0 → 2.28.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.
- package/README.md +273 -1
- package/components/combobox.tsx +137 -0
- package/components/filter-bar.tsx +218 -0
- package/components/index.ts +6 -1
- package/components/period-picker.tsx +153 -0
- package/components/period.ts +83 -0
- package/index.d.ts +9 -0
- package/index.js +27 -1
- package/lint.js +81 -5
- package/package.json +5 -1
- package/ui-core.js +66 -3
- package/ui.css +86 -2
- package/ui.d.ts +143 -0
- package/ui.js +531 -93
package/components/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// @makoai/app-sdk/components (2.21, 22 components from 2.22): stock shadcn/ui (new-york-v4, as
|
|
2
2
|
// shipped by the shadcn registry; only the `cn` import path changed). One
|
|
3
3
|
// copy per component: DropdownMenu and Checkbox live in ../menu and are
|
|
4
|
-
// re-exported here.
|
|
4
|
+
// re-exported here. PeriodPicker (2.27) is the house date filter built on
|
|
5
|
+
// the stock Popover; its helpers come from ./period. A missing component or prop is an SDK pull request,
|
|
5
6
|
// never an app copy. TypeScript source: the app's Vite compiles it, and the
|
|
6
7
|
// app's CSS imports "@makoai/app-sdk/tailwind.css" so Tailwind sees it.
|
|
8
|
+
// One house component sits beside them: the page filter bar (filter-bar.tsx).
|
|
7
9
|
export * from "./alert";
|
|
8
10
|
export * from "./avatar";
|
|
9
11
|
export * from "./badge";
|
|
@@ -11,8 +13,11 @@ export * from "./button";
|
|
|
11
13
|
export * from "./card";
|
|
12
14
|
export * from "./collapsible";
|
|
13
15
|
export * from "./dialog";
|
|
16
|
+
export * from "./filter-bar";
|
|
14
17
|
export * from "./input";
|
|
15
18
|
export * from "./label";
|
|
19
|
+
export * from "./period-picker";
|
|
20
|
+
export { clipToday, isCurrent, periodLabel, periodOf, shift, todayIso, type Period, type Unit } from "./period";
|
|
16
21
|
export * from "./popover";
|
|
17
22
|
export * from "./progress";
|
|
18
23
|
export * from "./select";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// PeriodPicker (2.27): the house date filter, ‹ Nov 2026 ›. The arrows step
|
|
4
|
+
// one period, the middle opens a picker (recent weeks / months / quarters /
|
|
5
|
+
// years, or a custom range), and the period in progress is tinted. Ported
|
|
6
|
+
// 1:1 from the workspace's apps/attrition-por-cohorte/src/ui/PeriodPicker.tsx
|
|
7
|
+
// and its `.pp` styles. The app's hand-rolled popover became the stock
|
|
8
|
+
// shadcn Popover (./popover): it portals the menu, moves focus into it on
|
|
9
|
+
// open and back to the trigger on close.
|
|
10
|
+
import * as React from "react"
|
|
11
|
+
import { closePopovers } from "../ui.js"
|
|
12
|
+
import { cn } from "../menu/utils"
|
|
13
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover"
|
|
14
|
+
import { UNIT_LABEL, addDays, isCurrent, periodLabel, periodOf, shift, todayIso, type Period, type Unit } from "./period"
|
|
15
|
+
|
|
16
|
+
const RECENT: Record<Unit, number> = { week: 12, month: 12, quarter: 8, year: 4 }
|
|
17
|
+
|
|
18
|
+
export interface PeriodPickerProps {
|
|
19
|
+
value: Period
|
|
20
|
+
onChange: (p: Period) => void
|
|
21
|
+
/** The units offered in the picker. Default month, quarter, year. */
|
|
22
|
+
units?: Unit[]
|
|
23
|
+
/** Custom ranges: whole months ("month"), any days ("day"), or none (false). */
|
|
24
|
+
custom?: "month" | "day" | false
|
|
25
|
+
/** Earliest and latest day a period may reach. Default: no limit back, today forward. */
|
|
26
|
+
min?: string
|
|
27
|
+
max?: string
|
|
28
|
+
/** The trigger's screen-reader name, read as "<label>: Nov 2026". */
|
|
29
|
+
label?: string
|
|
30
|
+
/** Mako thin prop (2.27): classes on the stepper's frame, e.g. `w-full` in a phone sheet. */
|
|
31
|
+
className?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The house date filter: ‹ Nov 2026 › with the period in progress tinted. */
|
|
35
|
+
export function PeriodPicker({ value, onChange, units = ["month", "quarter", "year"], custom = "month", min, max, label = "Time", className }: PeriodPickerProps) {
|
|
36
|
+
const today = todayIso()
|
|
37
|
+
const hi = max ?? today
|
|
38
|
+
const [open, setOpen] = React.useState(false)
|
|
39
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
40
|
+
const prev = shift(value, -1), next = shift(value, 1)
|
|
41
|
+
const okPrev = !min || prev.to >= min
|
|
42
|
+
const okNext = next.from <= hi
|
|
43
|
+
const current = isCurrent(value, today)
|
|
44
|
+
const step = "w-8 border-0 bg-transparent px-0 pt-0 pb-[2px] text-[18px] leading-none text-muted-foreground enabled:cursor-pointer enabled:hover:bg-accent enabled:hover:text-foreground disabled:cursor-default disabled:opacity-30"
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Popover open={open} onOpenChange={o => { if (o) closePopovers(); setOpen(o) }}>
|
|
48
|
+
<PopoverAnchor asChild>
|
|
49
|
+
<div
|
|
50
|
+
ref={ref}
|
|
51
|
+
data-slot="period-picker"
|
|
52
|
+
className={cn(
|
|
53
|
+
"relative inline-flex h-[34px] items-stretch rounded-[8px] border border-border bg-card p-0 text-[14px] font-medium text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[border-color,box-shadow] duration-150",
|
|
54
|
+
// The ring stays while the picker is open, though focus has moved into the portalled menu.
|
|
55
|
+
"focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_35%,transparent)] focus-within:outline-none",
|
|
56
|
+
"has-[[data-state=open]]:border-ring has-[[data-state=open]]:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_35%,transparent)]",
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
<button type="button" data-slot="period-picker-prev" className={cn(step, "rounded-l-[7px]")} aria-label="Previous period" disabled={!okPrev} onClick={() => onChange(prev)}>‹</button>
|
|
61
|
+
<PopoverTrigger asChild>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
data-slot="period-picker-trigger"
|
|
65
|
+
data-current={current || undefined}
|
|
66
|
+
className="inline-flex min-w-[156px] cursor-pointer items-center gap-2 border-x border-border bg-transparent py-0 pr-[10px] pl-3 font-medium text-inherit focus-visible:outline-none data-[current]:bg-[color-mix(in_srgb,var(--brand)_10%,transparent)] data-[current]:text-brand"
|
|
67
|
+
aria-label={`${label}: ${periodLabel(value)}`}
|
|
68
|
+
title={current ? "In progress: the numbers are not final yet" : undefined}
|
|
69
|
+
>
|
|
70
|
+
{current && <span className="size-[7px] flex-none rounded-full bg-brand shadow-[0_0_0_3px_color-mix(in_srgb,var(--brand)_22%,transparent)]" aria-hidden />}
|
|
71
|
+
<span className="flex-1 whitespace-nowrap text-left tabular-nums">{periodLabel(value)}</span>
|
|
72
|
+
<svg className={cn("flex-none text-muted-foreground transition-transform duration-150", open && "rotate-180")} width="12" height="12" viewBox="0 0 24 24" aria-hidden><path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" /></svg>
|
|
73
|
+
</button>
|
|
74
|
+
</PopoverTrigger>
|
|
75
|
+
<button type="button" data-slot="period-picker-next" className={cn(step, "rounded-r-[7px]")} aria-label="Next period" disabled={!okNext} onClick={() => onChange(next)}>›</button>
|
|
76
|
+
</div>
|
|
77
|
+
</PopoverAnchor>
|
|
78
|
+
<PopoverContent
|
|
79
|
+
align="start"
|
|
80
|
+
// The app's menu sat 6px under the frame's inner edge, flush with its inner left.
|
|
81
|
+
sideOffset={5}
|
|
82
|
+
alignOffset={1}
|
|
83
|
+
aria-label="Pick a period"
|
|
84
|
+
className="z-[70] grid w-[320px] max-w-[calc(100vw-24px)] gap-[10px] rounded-[10px] p-[10px] shadow-[0_12px_28px_-8px_rgb(0_0_0/0.22)]"
|
|
85
|
+
// The arrows sit outside the menu but inside the stepper: they step the period and leave it open.
|
|
86
|
+
onInteractOutside={e => { if (ref.current?.contains(e.target as Node)) e.preventDefault() }}
|
|
87
|
+
>
|
|
88
|
+
<PickerMenu value={value} units={units} custom={custom} min={min} max={hi} today={today}
|
|
89
|
+
onPick={p => { onChange(p); setOpen(false) }} />
|
|
90
|
+
</PopoverContent>
|
|
91
|
+
</Popover>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function PickerMenu({ value, units, custom, min, max, today, onPick }: {
|
|
96
|
+
value: Period; units: Unit[]; custom: "month" | "day" | false; min?: string; max: string; today: string; onPick: (p: Period) => void
|
|
97
|
+
}) {
|
|
98
|
+
const [tab, setTab] = React.useState<Unit | "custom">(value.unit === "custom" && !custom ? units[0] : value.unit)
|
|
99
|
+
const asMonth = custom === "month"
|
|
100
|
+
const [from, setFrom] = React.useState(asMonth ? value.from.slice(0, 7) : value.from)
|
|
101
|
+
const [to, setTo] = React.useState(asMonth ? value.to.slice(0, 7) : value.to)
|
|
102
|
+
const list = tab === "custom" ? [] : (() => {
|
|
103
|
+
const out: Period[] = []
|
|
104
|
+
let p = periodOf(tab, max)
|
|
105
|
+
for (let i = 0; i < RECENT[tab] && (!min || p.to >= min); i++, p = shift(p, -1)) out.push(p)
|
|
106
|
+
return out
|
|
107
|
+
})()
|
|
108
|
+
const range = (): Period | null => {
|
|
109
|
+
if (!from || !to) return null
|
|
110
|
+
const f = asMonth ? `${from}-01` : from
|
|
111
|
+
const t = asMonth ? addDays(periodOf("month", `${to}-01`).to, 0) : to
|
|
112
|
+
return f <= t ? { unit: "custom", from: f, to: t } : null
|
|
113
|
+
}
|
|
114
|
+
const r = range()
|
|
115
|
+
const tabClass = (on: boolean) => cn(
|
|
116
|
+
"flex-1 cursor-pointer rounded-[6px] border border-transparent bg-transparent px-[6px] py-1 text-[13px] font-medium text-muted-foreground",
|
|
117
|
+
on && "border-border bg-card text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05)]",
|
|
118
|
+
)
|
|
119
|
+
const input = "h-8 rounded-[6px] border border-border bg-card px-2 text-[14px] text-foreground [font:inherit]"
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
{units.length + (custom ? 1 : 0) > 1 && <div data-slot="period-picker-tabs" className="flex gap-[2px] rounded-[8px] bg-muted p-[3px]" role="tablist">
|
|
123
|
+
{units.map(u => <button key={u} type="button" role="tab" aria-selected={tab === u} className={tabClass(tab === u)} onClick={() => setTab(u)}>{UNIT_LABEL[u]}</button>)}
|
|
124
|
+
{custom && <button type="button" role="tab" aria-selected={tab === "custom"} className={tabClass(tab === "custom")} onClick={() => setTab("custom")}>Custom</button>}
|
|
125
|
+
</div>}
|
|
126
|
+
{tab !== "custom" ? (
|
|
127
|
+
<div data-slot="period-picker-grid" className={cn("grid gap-1", tab === "month" ? "grid-cols-3" : "grid-cols-2")}>
|
|
128
|
+
{list.map(p => {
|
|
129
|
+
const on = value.unit === p.unit && value.from === p.from
|
|
130
|
+
const live = isCurrent(p, today)
|
|
131
|
+
return (
|
|
132
|
+
<button key={p.from} type="button" data-current={live || undefined}
|
|
133
|
+
className={cn(
|
|
134
|
+
"grid cursor-pointer justify-items-center rounded-[6px] border border-transparent bg-transparent px-[6px] py-[7px] text-[13px] text-inherit tabular-nums",
|
|
135
|
+
live && "text-brand",
|
|
136
|
+
on ? "border-brand bg-[color-mix(in_srgb,var(--brand)_8%,transparent)] font-semibold" : "hover:bg-accent",
|
|
137
|
+
)}
|
|
138
|
+
onClick={() => onPick(p)}>
|
|
139
|
+
{periodLabel(p)}{live && <small className="text-[10px] font-normal text-muted-foreground">in progress</small>}
|
|
140
|
+
</button>
|
|
141
|
+
)
|
|
142
|
+
})}
|
|
143
|
+
</div>
|
|
144
|
+
) : (
|
|
145
|
+
<form data-slot="period-picker-custom" className="grid grid-cols-2 gap-2" onSubmit={e => { e.preventDefault(); if (r) onPick(r) }}>
|
|
146
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">From<input className={input} type={asMonth ? "month" : "date"} value={from} min={min ? (asMonth ? min.slice(0, 7) : min) : undefined} max={asMonth ? max.slice(0, 7) : max} onChange={e => setFrom(e.target.value)} /></label>
|
|
147
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">To<input className={input} type={asMonth ? "month" : "date"} value={to} min={from || undefined} max={asMonth ? max.slice(0, 7) : max} onChange={e => setTo(e.target.value)} /></label>
|
|
148
|
+
<button type="submit" className="col-span-full h-8 cursor-pointer rounded-[6px] border-0 bg-brand font-semibold text-white disabled:cursor-default disabled:opacity-45" disabled={!r}>Apply</button>
|
|
149
|
+
</form>
|
|
150
|
+
)}
|
|
151
|
+
</>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -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,15 @@ 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
|
+
/** A lead-only market (2.28): the valuation funnel runs there, no agents. In this order. */
|
|
412
|
+
export type LeadMarketCode = "de" | "at" | "cz" | "nl" | "be" | "gb";
|
|
413
|
+
/** One colour per market (2.27; lead-only markets 2.28), keyed by lowercase code; `all` is the all-markets line. */
|
|
414
|
+
export const COUNTRY_COLORS: Readonly<Record<CountryCode | LeadMarketCode | "all", string>>;
|
|
415
|
+
/** CH, FR, ES, IT, PL, PT (2.27), as lowercase codes. */
|
|
416
|
+
export const COUNTRY_ORDER: readonly CountryCode[];
|
|
417
|
+
|
|
409
418
|
/**
|
|
410
419
|
* The theme tokens the SDK injects into <head> on import (Mako's house
|
|
411
420
|
* 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.
|
|
41
|
+
export const SDK_VERSION = "2.28.0";
|
|
42
42
|
if (typeof window !== "undefined") {
|
|
43
43
|
try {
|
|
44
44
|
window.__MAKO_APP_SDK__ = SDK_VERSION;
|
|
@@ -2065,6 +2065,32 @@ 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
|
+
// 2.28 adds the 6 lead-only markets (valuation funnel only since 18-19 Nov
|
|
2072
|
+
// 2026), in their order: DE, AT, CZ, NL, BE, GB (realadvisor.co.uk). Their
|
|
2073
|
+
// flags repeat the first six's hues, so they take free ones.
|
|
2074
|
+
// ---------------------------------------------------------------------------
|
|
2075
|
+
export const COUNTRY_COLORS = Object.freeze({
|
|
2076
|
+
ch: "#dc2626",
|
|
2077
|
+
fr: "#2563eb",
|
|
2078
|
+
it: "#16a34a",
|
|
2079
|
+
es: "#f59e0b",
|
|
2080
|
+
pt: "#0891b2",
|
|
2081
|
+
pl: "#db2777",
|
|
2082
|
+
de: "#7c3aed",
|
|
2083
|
+
at: "#65a30d",
|
|
2084
|
+
cz: "#a16207",
|
|
2085
|
+
nl: "#ea580c",
|
|
2086
|
+
be: "#c026d3",
|
|
2087
|
+
gb: "#1e40af",
|
|
2088
|
+
all: "#475569",
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
/** The order countries take in legends, tables and filters: CH, FR, ES, IT, PL, PT. */
|
|
2092
|
+
export const COUNTRY_ORDER = Object.freeze(["ch", "fr", "es", "it", "pl", "pt"]);
|
|
2093
|
+
|
|
2068
2094
|
// ---------------------------------------------------------------------------
|
|
2069
2095
|
// Theme — the OS preference; v1 mirrored the host's toggle, a standalone app
|
|
2070
2096
|
// 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
|
-
|
|
138
|
-
|
|
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.
|
|
3
|
+
"version": "2.28.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": {
|
|
@@ -55,6 +55,10 @@
|
|
|
55
55
|
"types": "./components/command.tsx",
|
|
56
56
|
"default": "./components/command.tsx"
|
|
57
57
|
},
|
|
58
|
+
"./components/combobox": {
|
|
59
|
+
"types": "./components/combobox.tsx",
|
|
60
|
+
"default": "./components/combobox.tsx"
|
|
61
|
+
},
|
|
58
62
|
"./ui.css": "./ui.css",
|
|
59
63
|
"./tailwind.css": "./tailwind.css"
|
|
60
64
|
},
|
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(
|
|
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) {
|