@makoai/app-sdk 2.19.0 → 2.21.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 +140 -11
- package/components/badge.tsx +47 -0
- package/components/button.tsx +63 -0
- package/components/card.tsx +91 -0
- package/components/dialog.tsx +158 -0
- package/components/index.ts +19 -0
- package/components/input.tsx +20 -0
- package/components/popover.tsx +88 -0
- package/components/separator.tsx +27 -0
- package/components/skeleton.tsx +13 -0
- package/components/tabs.tsx +90 -0
- package/components/tooltip.tsx +56 -0
- package/index.d.ts +38 -0
- package/index.js +2 -1
- package/lint.js +77 -0
- package/menu/checkbox.tsx +36 -0
- package/menu/dropdown-menu.tsx +205 -0
- package/menu/filter-menu.tsx +312 -0
- package/menu/index.ts +10 -0
- package/menu/utils.ts +7 -0
- package/package.json +49 -4
- package/tailwind.css +60 -0
- package/time.js +110 -0
- package/ui-core.js +165 -0
- package/ui.css +16 -1
- package/ui.d.ts +95 -5
- package/ui.js +208 -73
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// FilterMenu: one filter dropdown for flat and nested option lists, on stock
|
|
2
|
+
// shadcn DropdownMenu. Ported 1:1 from the apps' NestedFilterMenu
|
|
3
|
+
// (web-performance, hasura-performance, quarterly-requalification-rate):
|
|
4
|
+
// "All …" first, then the options; a group opens as a hover submenu (or with
|
|
5
|
+
// the arrow key) that starts with its own "All <group>" row. Each row has a
|
|
6
|
+
// checkbox (a tick when every leaf under it is picked, a dash when some are)
|
|
7
|
+
// and an "Only" action on hover. The menu stays open across toggles. Rows
|
|
8
|
+
// carry no hover descriptions: definitions live in the filter's info note.
|
|
9
|
+
//
|
|
10
|
+
// The selection model is the kit's (2.20, `filter*` in ui-core.js): a
|
|
11
|
+
// selection is a list of leaf values, [] means All, and "nothing ticked" is
|
|
12
|
+
// a draft that emits nothing until the next tick.
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { ChevronDown, ChevronRight } from "lucide-react";
|
|
15
|
+
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
|
16
|
+
import {
|
|
17
|
+
closePopovers,
|
|
18
|
+
filterAllTick,
|
|
19
|
+
filterLeaves,
|
|
20
|
+
filterLeavesOf,
|
|
21
|
+
filterNormalize,
|
|
22
|
+
filterText,
|
|
23
|
+
filterTick,
|
|
24
|
+
filterToggle,
|
|
25
|
+
filterToggleAll,
|
|
26
|
+
type FilterTick,
|
|
27
|
+
} from "../ui.js";
|
|
28
|
+
import { Checkbox } from "./checkbox";
|
|
29
|
+
import {
|
|
30
|
+
DropdownMenu,
|
|
31
|
+
DropdownMenuContent,
|
|
32
|
+
DropdownMenuSeparator,
|
|
33
|
+
DropdownMenuSub,
|
|
34
|
+
DropdownMenuSubContent,
|
|
35
|
+
DropdownMenuSubTrigger,
|
|
36
|
+
DropdownMenuTrigger,
|
|
37
|
+
} from "./dropdown-menu";
|
|
38
|
+
|
|
39
|
+
export interface FilterMenuOption {
|
|
40
|
+
value: string;
|
|
41
|
+
label: string;
|
|
42
|
+
/** A second, muted line under a leaf's label. */
|
|
43
|
+
description?: string;
|
|
44
|
+
/** What the option covers. Not shown on the row: definitions live in the filter's info note. */
|
|
45
|
+
title?: string;
|
|
46
|
+
/** A group: a hover submenu that starts with "All <label>". */
|
|
47
|
+
children?: FilterMenuOption[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ROW =
|
|
51
|
+
"mk-fm-row relative flex cursor-pointer items-center gap-2 rounded-sm py-1.5 pr-2 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground";
|
|
52
|
+
|
|
53
|
+
const asChecked = (s: FilterTick) => (s === "on" ? true : s === "mixed" ? ("indeterminate" as const) : false);
|
|
54
|
+
|
|
55
|
+
/** The row's checkbox, drawn only: the row (or its wrapper) takes the click. */
|
|
56
|
+
function Tick(props: { state: FilterTick }) {
|
|
57
|
+
return <Checkbox checked={asChecked(props.state)} tabIndex={-1} aria-hidden className="pointer-events-none" />;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface FilterMenuItemsProps {
|
|
61
|
+
options: FilterMenuOption[];
|
|
62
|
+
/** Picked leaf values; [] (or every leaf) = All. `value` is an alias. */
|
|
63
|
+
selected?: readonly string[];
|
|
64
|
+
value?: readonly string[];
|
|
65
|
+
onChange: (selected: string[]) => void;
|
|
66
|
+
/** The first row ("All traffic"). */
|
|
67
|
+
allLabel: string;
|
|
68
|
+
/** What All emits: [] (default) or every leaf value (false). */
|
|
69
|
+
emptyMeansAll?: boolean;
|
|
70
|
+
/** The "nothing ticked" draft, when the owner shows it (FilterMenu's trigger). Uncontrolled otherwise. */
|
|
71
|
+
none?: boolean;
|
|
72
|
+
onNoneChange?: (none: boolean) => void;
|
|
73
|
+
/**
|
|
74
|
+
* The phone Filters menu, where a submenu has no room beside its parent: a
|
|
75
|
+
* group row opens in place instead (`drill.open(node)`), and `root` then
|
|
76
|
+
* lists that group's rows, "All <group>" first.
|
|
77
|
+
*/
|
|
78
|
+
drill?: { open: (node: FilterMenuOption) => void };
|
|
79
|
+
root?: FilterMenuOption;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The menu's rows ("All …", a separator, the options and their submenus), for
|
|
84
|
+
* FilterMenu's own dropdown and for an app's combined toolbar menu, where
|
|
85
|
+
* they fill one filter's submenu.
|
|
86
|
+
*/
|
|
87
|
+
export function FilterMenuItems(props: FilterMenuItemsProps) {
|
|
88
|
+
const { options, drill, emptyMeansAll = true } = props;
|
|
89
|
+
const selected = filterNormalize(options, props.selected ?? props.value ?? []);
|
|
90
|
+
const [ownNone, setOwnNone] = React.useState(false);
|
|
91
|
+
const none = props.none ?? ownNone;
|
|
92
|
+
const setNone = props.onNoneChange ?? setOwnNone;
|
|
93
|
+
|
|
94
|
+
const emit = (next: string[]) => {
|
|
95
|
+
setNone(false);
|
|
96
|
+
props.onChange(next.length ? next : emptyMeansAll ? [] : filterLeaves(options));
|
|
97
|
+
};
|
|
98
|
+
const apply = (r: { none: boolean; selected: string[] }) => (r.none ? setNone(true) : emit(r.selected));
|
|
99
|
+
const flip = (node: FilterMenuOption) => apply(filterToggle(options, selected, node, none));
|
|
100
|
+
const tick = (node: FilterMenuOption) => filterTick(node, selected, none);
|
|
101
|
+
|
|
102
|
+
const only = (node: FilterMenuOption) => (e: React.MouseEvent) => {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
emit(filterNormalize(options, filterLeavesOf(node)));
|
|
106
|
+
};
|
|
107
|
+
// A group with no children yet picks nothing: no Only, and its box is inert.
|
|
108
|
+
const empty = (node: FilterMenuOption) => filterLeavesOf(node).length === 0;
|
|
109
|
+
const onlyButton = (node: FilterMenuOption) =>
|
|
110
|
+
empty(node) ? null : (
|
|
111
|
+
<span role="button" tabIndex={-1} className="mk-fm-only" onClick={only(node)} onPointerUp={e => e.stopPropagation()}>
|
|
112
|
+
Only
|
|
113
|
+
</span>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const leafRow = (node: FilterMenuOption) => {
|
|
117
|
+
const st = tick(node);
|
|
118
|
+
return (
|
|
119
|
+
<DropdownMenuPrimitive.CheckboxItem
|
|
120
|
+
key={node.value}
|
|
121
|
+
className={ROW}
|
|
122
|
+
checked={asChecked(st)}
|
|
123
|
+
onSelect={e => {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
flip(node);
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
<Tick state={st} />
|
|
129
|
+
{node.description ? (
|
|
130
|
+
<span className="min-w-0 flex-1">
|
|
131
|
+
<span className="block truncate">{node.label}</span>
|
|
132
|
+
<span className="block text-xs text-muted-foreground">{node.description}</span>
|
|
133
|
+
</span>
|
|
134
|
+
) : (
|
|
135
|
+
<span className="flex-1 truncate">{node.label}</span>
|
|
136
|
+
)}
|
|
137
|
+
{onlyButton(node)}
|
|
138
|
+
</DropdownMenuPrimitive.CheckboxItem>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** A group's box: toggles the whole group; the rest of the row opens it. */
|
|
143
|
+
const groupBox = (node: FilterMenuOption, st: FilterTick) => (
|
|
144
|
+
<span
|
|
145
|
+
role="checkbox"
|
|
146
|
+
aria-checked={st === "on" ? true : st === "mixed" ? "mixed" : false}
|
|
147
|
+
aria-label={`All ${node.label}`}
|
|
148
|
+
aria-disabled={empty(node) || undefined}
|
|
149
|
+
className="flex"
|
|
150
|
+
onClick={e => {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
if (!empty(node)) flip(node);
|
|
154
|
+
}}
|
|
155
|
+
onPointerUp={e => e.stopPropagation()}
|
|
156
|
+
>
|
|
157
|
+
<Tick state={st} />
|
|
158
|
+
</span>
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
/** "All <group>", first in a group's own list. */
|
|
162
|
+
const groupAll = (node: FilterMenuOption, st: FilterTick) => (
|
|
163
|
+
<DropdownMenuPrimitive.CheckboxItem
|
|
164
|
+
className={ROW}
|
|
165
|
+
checked={asChecked(st)}
|
|
166
|
+
onSelect={e => {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
flip(node);
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<Tick state={st} />
|
|
172
|
+
<span className="flex-1">All {node.label}</span>
|
|
173
|
+
</DropdownMenuPrimitive.CheckboxItem>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const level = (list: FilterMenuOption[]): React.ReactNode[] =>
|
|
177
|
+
list.map(node => {
|
|
178
|
+
if (!node.children) return leafRow(node);
|
|
179
|
+
const st = tick(node);
|
|
180
|
+
if (drill)
|
|
181
|
+
return (
|
|
182
|
+
<DropdownMenuPrimitive.Item
|
|
183
|
+
key={node.value}
|
|
184
|
+
className={`${ROW} mk-fm-drill`}
|
|
185
|
+
onSelect={e => {
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
drill.open(node);
|
|
188
|
+
}}
|
|
189
|
+
onKeyDown={e => {
|
|
190
|
+
if (e.key === "ArrowRight") {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
drill.open(node);
|
|
193
|
+
}
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{groupBox(node, st)}
|
|
197
|
+
<span className="flex-1 truncate">{node.label}</span>
|
|
198
|
+
{onlyButton(node)}
|
|
199
|
+
<ChevronRight className="size-4 text-muted-foreground" aria-hidden />
|
|
200
|
+
</DropdownMenuPrimitive.Item>
|
|
201
|
+
);
|
|
202
|
+
return (
|
|
203
|
+
<DropdownMenuSub key={node.value}>
|
|
204
|
+
<DropdownMenuSubTrigger className="mk-fm-row cursor-pointer gap-2 pl-2">
|
|
205
|
+
{groupBox(node, st)}
|
|
206
|
+
<span className="flex-1 truncate">{node.label}</span>
|
|
207
|
+
{onlyButton(node)}
|
|
208
|
+
</DropdownMenuSubTrigger>
|
|
209
|
+
<DropdownMenuSubContent className="max-h-[70vh] min-w-48 overflow-y-auto">
|
|
210
|
+
{groupAll(node, st)}
|
|
211
|
+
<DropdownMenuSeparator />
|
|
212
|
+
{level(node.children)}
|
|
213
|
+
</DropdownMenuSubContent>
|
|
214
|
+
</DropdownMenuSub>
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (props.root?.children)
|
|
219
|
+
return (
|
|
220
|
+
<>
|
|
221
|
+
{groupAll(props.root, tick(props.root))}
|
|
222
|
+
<DropdownMenuSeparator />
|
|
223
|
+
{level(props.root.children)}
|
|
224
|
+
</>
|
|
225
|
+
);
|
|
226
|
+
const allSt = filterAllTick(selected, none);
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
<DropdownMenuPrimitive.CheckboxItem
|
|
230
|
+
className={ROW}
|
|
231
|
+
checked={asChecked(allSt)}
|
|
232
|
+
onSelect={e => {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
apply(filterToggleAll(selected, none));
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
<Tick state={allSt} />
|
|
238
|
+
<span className="flex-1">{props.allLabel}</span>
|
|
239
|
+
</DropdownMenuPrimitive.CheckboxItem>
|
|
240
|
+
<DropdownMenuSeparator />
|
|
241
|
+
{level(options)}
|
|
242
|
+
</>
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface FilterMenuProps extends Omit<FilterMenuItemsProps, "none" | "onNoneChange" | "drill" | "root"> {
|
|
247
|
+
/** The accessible name of the trigger ("Traffic"). */
|
|
248
|
+
label: string;
|
|
249
|
+
/** Fixed-width trigger class (no layout shift). */
|
|
250
|
+
triggerClassName?: string;
|
|
251
|
+
/** Trigger text; default filterText(): All, the one picked label, or the picked parts ("Pages + Assets: Images"). */
|
|
252
|
+
summary?: string;
|
|
253
|
+
/** "N selected" for a flat list. */
|
|
254
|
+
formatMany?: (n: number) => string;
|
|
255
|
+
/** The trigger while nothing is ticked (the draft). Default "None". */
|
|
256
|
+
noneLabel?: string;
|
|
257
|
+
/**
|
|
258
|
+
* More texts the trigger is sized to, besides allLabel and the top-level
|
|
259
|
+
* labels (e.g. its default pick, "Pages + Data"). A longer pick ends in an
|
|
260
|
+
* ellipsis inside the trigger, whole in its title.
|
|
261
|
+
*/
|
|
262
|
+
probes?: readonly string[];
|
|
263
|
+
/** Replaces allLabel and the top-level labels as what the trigger is sized to. */
|
|
264
|
+
sizeTo?: readonly string[];
|
|
265
|
+
/** Menu alignment against the trigger. Default "start". */
|
|
266
|
+
align?: "start" | "center" | "end";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The filter dropdown: the kit's trigger (`mk-ms-trigger`) over FilterMenuItems. */
|
|
270
|
+
export function FilterMenu(props: FilterMenuProps) {
|
|
271
|
+
const { options, allLabel, noneLabel = "None" } = props;
|
|
272
|
+
const selected = filterNormalize(options, props.selected ?? props.value ?? []);
|
|
273
|
+
const [none, setNone] = React.useState(false);
|
|
274
|
+
const text = none ? noneLabel : (props.summary ?? filterText(options, selected, allLabel, props.formatMany));
|
|
275
|
+
const probes = [...(props.sizeTo ?? [allLabel, ...options.map(o => o.label)]), ...(props.probes ?? [])];
|
|
276
|
+
return (
|
|
277
|
+
<DropdownMenu
|
|
278
|
+
onOpenChange={open => {
|
|
279
|
+
if (open) closePopovers();
|
|
280
|
+
else setNone(false);
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
<DropdownMenuTrigger asChild>
|
|
284
|
+
<button type="button" className={`mk-ms-trigger ${props.triggerClassName ?? ""}`} aria-label={props.label} title={text}>
|
|
285
|
+
<span className="mk-ms-value">
|
|
286
|
+
<span className="mk-ms-fit">
|
|
287
|
+
{/* The text first: a grid's baseline is its first item's, and the probes are 0 px tall. */}
|
|
288
|
+
<span className="mk-ms-text">{text}</span>
|
|
289
|
+
{probes.map((p, i) => (
|
|
290
|
+
<span key={i} className="mk-ms-probe" aria-hidden>
|
|
291
|
+
{p}
|
|
292
|
+
</span>
|
|
293
|
+
))}
|
|
294
|
+
</span>
|
|
295
|
+
</span>
|
|
296
|
+
<ChevronDown className="mk-ms-caret" size={16} />
|
|
297
|
+
</button>
|
|
298
|
+
</DropdownMenuTrigger>
|
|
299
|
+
<DropdownMenuContent align={props.align ?? "start"} className="max-h-[70vh] min-w-52 overflow-y-auto">
|
|
300
|
+
<FilterMenuItems
|
|
301
|
+
options={options}
|
|
302
|
+
selected={selected}
|
|
303
|
+
onChange={props.onChange}
|
|
304
|
+
allLabel={allLabel}
|
|
305
|
+
emptyMeansAll={props.emptyMeansAll}
|
|
306
|
+
none={none}
|
|
307
|
+
onNoneChange={setNone}
|
|
308
|
+
/>
|
|
309
|
+
</DropdownMenuContent>
|
|
310
|
+
</DropdownMenu>
|
|
311
|
+
);
|
|
312
|
+
}
|
package/menu/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @makoai/app-sdk/menu (2.20): stock shadcn/ui DropdownMenu and Checkbox
|
|
2
|
+
// (new-york, as shipped; the Checkbox adds the indeterminate dash), and the
|
|
3
|
+
// FilterMenu built on them. TypeScript source: the app's Vite compiles it.
|
|
4
|
+
// Needs the app's Tailwind to see these classes: `@source
|
|
5
|
+
// "../node_modules/@makoai/app-sdk/menu";` in its CSS (README, "Menus").
|
|
6
|
+
export * from "./dropdown-menu";
|
|
7
|
+
export { Checkbox } from "./checkbox";
|
|
8
|
+
export { cn } from "./utils";
|
|
9
|
+
export { FilterMenu, FilterMenuItems } from "./filter-menu";
|
|
10
|
+
export type { FilterMenuItemsProps, FilterMenuOption, FilterMenuProps } from "./filter-menu";
|
package/menu/utils.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makoai/app-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.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": {
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"type": "module",
|
|
20
20
|
"main": "./index.js",
|
|
21
21
|
"types": "./index.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"mako-app-lint": "./lint.js"
|
|
24
|
+
},
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
24
27
|
"types": "./index.d.ts",
|
|
@@ -36,12 +39,23 @@
|
|
|
36
39
|
"types": "./ui.d.ts",
|
|
37
40
|
"default": "./ui.js"
|
|
38
41
|
},
|
|
39
|
-
"./
|
|
42
|
+
"./menu": {
|
|
43
|
+
"types": "./menu/index.ts",
|
|
44
|
+
"default": "./menu/index.ts"
|
|
45
|
+
},
|
|
46
|
+
"./components": {
|
|
47
|
+
"types": "./components/index.ts",
|
|
48
|
+
"default": "./components/index.ts"
|
|
49
|
+
},
|
|
50
|
+
"./ui.css": "./ui.css",
|
|
51
|
+
"./tailwind.css": "./tailwind.css"
|
|
40
52
|
},
|
|
41
53
|
"files": [
|
|
42
54
|
"index.js",
|
|
43
55
|
"index.d.ts",
|
|
44
56
|
"progress.js",
|
|
57
|
+
"time.js",
|
|
58
|
+
"lint.js",
|
|
45
59
|
"data-core.js",
|
|
46
60
|
"vite.js",
|
|
47
61
|
"vite.d.ts",
|
|
@@ -51,11 +65,36 @@
|
|
|
51
65
|
"ui-core.js",
|
|
52
66
|
"ui.d.ts",
|
|
53
67
|
"ui.css",
|
|
68
|
+
"tailwind.css",
|
|
69
|
+
"menu/",
|
|
70
|
+
"components/",
|
|
54
71
|
"README.md"
|
|
55
72
|
],
|
|
56
73
|
"peerDependencies": {
|
|
74
|
+
"class-variance-authority": ">=0.7",
|
|
75
|
+
"clsx": ">=2",
|
|
76
|
+
"lucide-react": ">=0.400",
|
|
77
|
+
"radix-ui": ">=1.4",
|
|
57
78
|
"react": ">=18",
|
|
58
|
-
"react-dom": ">=18"
|
|
79
|
+
"react-dom": ">=18",
|
|
80
|
+
"tailwind-merge": ">=2"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"class-variance-authority": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"clsx": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"lucide-react": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"radix-ui": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"tailwind-merge": {
|
|
96
|
+
"optional": true
|
|
97
|
+
}
|
|
59
98
|
},
|
|
60
99
|
"publishConfig": {
|
|
61
100
|
"access": "public"
|
|
@@ -65,6 +104,12 @@
|
|
|
65
104
|
},
|
|
66
105
|
"devDependencies": {
|
|
67
106
|
"apache-arrow": "17.0.0",
|
|
68
|
-
"
|
|
107
|
+
"class-variance-authority": "^0.7.1",
|
|
108
|
+
"clsx": "^2.1.1",
|
|
109
|
+
"esbuild": "^0.28.2",
|
|
110
|
+
"jsdom": "^30.1.2",
|
|
111
|
+
"lucide-react": "^1.61.0",
|
|
112
|
+
"radix-ui": "^1.8.1",
|
|
113
|
+
"tailwind-merge": "^3.7.0"
|
|
69
114
|
}
|
|
70
115
|
}
|
package/tailwind.css
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* @makoai/app-sdk/tailwind.css (2.21): import it after Tailwind in the app's
|
|
2
|
+
CSS (`@import "@makoai/app-sdk/tailwind.css";`). It lets Tailwind see the
|
|
3
|
+
classes of the SDK's stock shadcn components (/components, /menu) and maps
|
|
4
|
+
the house theme tokens the SDK injects (--background, --brand, …) onto
|
|
5
|
+
Tailwind's colour names, so `bg-popover` or `text-muted-foreground` follow
|
|
6
|
+
the house theme in light and dark. */
|
|
7
|
+
@source "./components";
|
|
8
|
+
@source "./menu";
|
|
9
|
+
|
|
10
|
+
@theme inline {
|
|
11
|
+
--color-background: var(--background);
|
|
12
|
+
--color-foreground: var(--foreground);
|
|
13
|
+
--color-card: var(--card);
|
|
14
|
+
--color-card-foreground: var(--card-foreground);
|
|
15
|
+
--color-popover: var(--popover);
|
|
16
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
17
|
+
--color-primary: var(--primary);
|
|
18
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
19
|
+
--color-secondary: var(--secondary);
|
|
20
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
21
|
+
--color-muted: var(--muted);
|
|
22
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
23
|
+
--color-accent: var(--accent);
|
|
24
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
25
|
+
--color-destructive: var(--destructive);
|
|
26
|
+
--color-border: var(--border);
|
|
27
|
+
--color-input: var(--input);
|
|
28
|
+
--color-ring: var(--ring);
|
|
29
|
+
--color-brand: var(--brand);
|
|
30
|
+
--color-chart-1: var(--chart-1);
|
|
31
|
+
--color-chart-2: var(--chart-2);
|
|
32
|
+
--color-chart-3: var(--chart-3);
|
|
33
|
+
--color-chart-4: var(--chart-4);
|
|
34
|
+
--color-chart-5: var(--chart-5);
|
|
35
|
+
--color-positive: var(--positive);
|
|
36
|
+
--color-negative: var(--negative);
|
|
37
|
+
--color-warning: var(--warning);
|
|
38
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
39
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
40
|
+
--radius-lg: var(--radius);
|
|
41
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* The slice of preflight the shadcn components rely on, scoped to them, for
|
|
45
|
+
apps that load Tailwind without its preflight (the kit's ui.css keeps the
|
|
46
|
+
page's base rules). */
|
|
47
|
+
@layer base {
|
|
48
|
+
[data-slot], [data-slot] * {
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
border: 0 solid var(--border);
|
|
51
|
+
}
|
|
52
|
+
[data-slot] button, button[data-slot] {
|
|
53
|
+
background: transparent;
|
|
54
|
+
color: inherit;
|
|
55
|
+
font: inherit;
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
}
|
|
59
|
+
[data-slot] table { border-collapse: collapse; }
|
|
60
|
+
}
|
package/time.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Times and dates (2.21). The SDK runs DuckDB in UTC, and that stays: display
|
|
2
|
+
// code decides the zone. Two kinds of value reach an app:
|
|
3
|
+
//
|
|
4
|
+
// - Instants (an event time, "updated at", a deploy): shown in the VIEWER's
|
|
5
|
+
// zone with a zone label, "14:05 CET". formatTime().
|
|
6
|
+
// - Day buckets (a dbt `date`, a UTC `date_trunc('day', …)`): a calendar day,
|
|
7
|
+
// printed with no shift. formatDate(). A stored day never goes through the
|
|
8
|
+
// viewer's zone, so 18 Nov stays 18 Nov in Los Angeles.
|
|
9
|
+
//
|
|
10
|
+
// toDayKey() is the one place a UTC "YYYY-MM-DD" key is built (URL state,
|
|
11
|
+
// joins, Map keys). Display code never calls getUTC*, never sets
|
|
12
|
+
// timeZone: "UTC" and never slices toISOString(): `mako-app-lint` flags it.
|
|
13
|
+
|
|
14
|
+
const DAY_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
15
|
+
// "2026-11-18 14:05:00", "2026-11-18T14:05:00.123": a DuckDB TIMESTAMP rendered
|
|
16
|
+
// without a zone. DuckDB runs in UTC, so it is a UTC wall time.
|
|
17
|
+
const NAIVE_RE = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?$/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Any time value an app holds as a Date: a Date, epoch milliseconds, a bigint
|
|
21
|
+
* of epoch microseconds (DuckDB TIMESTAMP through Arrow), an ISO string with
|
|
22
|
+
* a zone, or a zone-less "YYYY-MM-DD hh:mm[:ss]" read as UTC. A bare
|
|
23
|
+
* "YYYY-MM-DD" is that day's UTC midnight. Null, "" and unparsable values
|
|
24
|
+
* give null.
|
|
25
|
+
*/
|
|
26
|
+
export function toInstant(value) {
|
|
27
|
+
if (value == null || value === "") return null;
|
|
28
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;
|
|
29
|
+
if (typeof value === "bigint") return new Date(Number(value / 1000n));
|
|
30
|
+
if (typeof value === "number") return Number.isFinite(value) ? new Date(value) : null;
|
|
31
|
+
const s = String(value).trim();
|
|
32
|
+
let m = DAY_RE.exec(s);
|
|
33
|
+
if (m) return new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
|
|
34
|
+
m = NAIVE_RE.exec(s);
|
|
35
|
+
if (m) {
|
|
36
|
+
const ms = m[7] ? Math.round(Number(`0.${m[7]}`) * 1000) : 0;
|
|
37
|
+
return new Date(Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +(m[6] ?? 0), ms));
|
|
38
|
+
}
|
|
39
|
+
const d = new Date(s);
|
|
40
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The UTC calendar day of a value, "YYYY-MM-DD": the key for URL state, joins and maps. Null when unparsable. */
|
|
44
|
+
export function toDayKey(value) {
|
|
45
|
+
if (typeof value === "string" && DAY_RE.test(value.trim())) return value.trim();
|
|
46
|
+
const d = toInstant(value);
|
|
47
|
+
if (!d) return null;
|
|
48
|
+
const p = n => String(n).padStart(2, "0");
|
|
49
|
+
return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const sameDay = (a, b, timeZone) => {
|
|
53
|
+
const f = new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" });
|
|
54
|
+
return f.format(a) === f.format(b);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An instant in the viewer's zone, with the zone's short name: "14:05 CET",
|
|
59
|
+
* "18 Nov, 14:05 CET" when it is not today there, "18 Nov 2025, 14:05 CET"
|
|
60
|
+
* in another year.
|
|
61
|
+
*
|
|
62
|
+
* Options: `date` ("auto" default, true, false), `seconds` (false),
|
|
63
|
+
* `zoneName` (true: "CET"), `locale` (the browser's), `timeZone` (the
|
|
64
|
+
* viewer's; tests and "as seen from Zurich" views only), `now` (for "auto").
|
|
65
|
+
* Null or unparsable input gives "—".
|
|
66
|
+
*/
|
|
67
|
+
export function formatTime(value, opts = {}) {
|
|
68
|
+
const d = toInstant(value);
|
|
69
|
+
if (!d) return "—";
|
|
70
|
+
const { date = "auto", seconds = false, zoneName = true, locale, timeZone, now = new Date() } = opts;
|
|
71
|
+
const showDate = date === true || (date === "auto" && !sameDay(d, now, timeZone));
|
|
72
|
+
const otherYear =
|
|
73
|
+
showDate &&
|
|
74
|
+
new Intl.DateTimeFormat("en", { timeZone, year: "numeric" }).format(d) !==
|
|
75
|
+
new Intl.DateTimeFormat("en", { timeZone, year: "numeric" }).format(now);
|
|
76
|
+
return new Intl.DateTimeFormat(locale, {
|
|
77
|
+
timeZone,
|
|
78
|
+
hour: "2-digit",
|
|
79
|
+
minute: "2-digit",
|
|
80
|
+
...(seconds ? { second: "2-digit" } : {}),
|
|
81
|
+
hourCycle: "h23",
|
|
82
|
+
...(showDate ? { day: "numeric", month: "short" } : {}),
|
|
83
|
+
...(otherYear ? { year: "numeric" } : {}),
|
|
84
|
+
...(zoneName ? { timeZoneName: "short" } : {}),
|
|
85
|
+
}).format(d);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A calendar day with no zone shift: "18 Nov 2026". Takes a "YYYY-MM-DD"
|
|
90
|
+
* string, a day's UTC midnight (a parquet `date`), or anything toInstant
|
|
91
|
+
* reads (its UTC day). Options: `year` ("auto" default: shown unless it is
|
|
92
|
+
* the current UTC year; true; false), `weekday` (false; "short" or "long"),
|
|
93
|
+
* `month` ("short" default; "long", "numeric"), `locale`, `now`.
|
|
94
|
+
* Null or unparsable input gives "—".
|
|
95
|
+
*/
|
|
96
|
+
export function formatDate(value, opts = {}) {
|
|
97
|
+
const key = toDayKey(value);
|
|
98
|
+
if (!key) return "—";
|
|
99
|
+
const { year = "auto", weekday = false, month = "short", locale, now = new Date() } = opts;
|
|
100
|
+
const [y, m, d] = key.split("-").map(Number);
|
|
101
|
+
const showYear = year === true || (year === "auto" && y !== now.getUTCFullYear());
|
|
102
|
+
// The day's UTC noon, formatted in UTC: the printed day is the stored day, whatever the viewer's zone.
|
|
103
|
+
return new Intl.DateTimeFormat(locale, {
|
|
104
|
+
timeZone: "UTC",
|
|
105
|
+
day: "numeric",
|
|
106
|
+
month,
|
|
107
|
+
...(showYear ? { year: "numeric" } : {}),
|
|
108
|
+
...(weekday ? { weekday } : {}),
|
|
109
|
+
}).format(new Date(Date.UTC(y, m - 1, d, 12)));
|
|
110
|
+
}
|