basalt-ui 2.27.2 → 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/CHANGELOG.md +99 -0
- package/MIGRATING.md +168 -12
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +40 -36
- package/agent/skills/basalt-design/references/recipes.md +47 -0
- package/configs/oxlint-basalt.json +2 -1
- package/configs/oxlint-plugin.js +110 -2
- package/configs/oxlint-plugin.test.ts +99 -4
- package/dist/agent/chat/thread-message.d.ts +1 -160
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +7 -162
- package/dist/agent/chat/virtualize.d.ts +5 -5
- package/dist/charts/ChartCard.d.ts +5 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +46 -13
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +11 -4
- package/dist/charts/Sparkline.d.ts +9 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +104 -41
- package/dist/charts/chart-box.module.css +50 -0
- package/dist/charts/chart-box.module.css.d.ts +5 -0
- package/dist/charts/chart-card.module.css +12 -4
- package/dist/charts/chart-card.module.css.d.ts +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +20 -18
- package/dist/charts/labels.d.ts +13 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +131 -20
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +1 -1
- package/dist/charts/ref-label.d.ts +31 -8
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +40 -9
- package/dist/charts/sparkline.module.css +6 -0
- package/dist/charts/state.d.ts +3 -3
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +20 -2
- package/dist/cli/shot/capture.d.ts +6 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +18 -5
- package/dist/common/empty-copy.d.ts +16 -0
- package/dist/common/empty-copy.d.ts.map +1 -0
- package/dist/common/empty-copy.js +9 -0
- package/dist/common/virtual-rows.d.ts +196 -0
- package/dist/common/virtual-rows.d.ts.map +1 -0
- package/dist/common/virtual-rows.js +290 -0
- package/dist/controls/controls.module.css +33 -1
- package/dist/controls/controls.module.css.d.ts +2 -0
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -2
- package/dist/controls/filter-pill.d.ts +27 -3
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +15 -4
- package/dist/controls/form-layout.d.ts +9 -3
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/controls/form-layout.js +74 -12
- package/dist/controls/form-layout.module.css +112 -7
- package/dist/controls/form-layout.module.css.d.ts +1 -0
- package/dist/controls/multi-select-filter.d.ts +2 -2
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +12 -6
- package/dist/controls/range-filter.d.ts +1 -1
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +8 -2
- package/dist/dashboard/bar-list.d.ts +1 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +6 -2
- package/dist/dashboard/bar-list.module.css +0 -2
- package/dist/dashboard/board-nav.d.ts +22 -0
- package/dist/dashboard/board-nav.d.ts.map +1 -0
- package/dist/dashboard/board-nav.js +49 -0
- package/dist/dashboard/board.d.ts +52 -0
- package/dist/dashboard/board.d.ts.map +1 -0
- package/dist/dashboard/board.js +228 -0
- package/dist/dashboard/board.module.css +160 -0
- package/dist/dashboard/board.module.css.d.ts +26 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +13 -6
- package/dist/dashboard/event-list-model.d.ts +51 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -0
- package/dist/dashboard/event-list-model.js +72 -0
- package/dist/dashboard/event-list-rows.d.ts +23 -0
- package/dist/dashboard/event-list-rows.d.ts.map +1 -0
- package/dist/dashboard/event-list-rows.js +93 -0
- package/dist/dashboard/event-list-scroll.d.ts +27 -0
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
- package/dist/dashboard/event-list-scroll.js +103 -0
- package/dist/dashboard/event-list-skeleton.d.ts +10 -0
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
- package/dist/dashboard/event-list-skeleton.js +36 -0
- package/dist/dashboard/event-list.d.ts +65 -0
- package/dist/dashboard/event-list.d.ts.map +1 -0
- package/dist/dashboard/event-list.js +178 -0
- package/dist/dashboard/event-list.module.css +283 -0
- package/dist/dashboard/event-list.module.css.d.ts +33 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +5 -3
- package/dist/dashboard/meter.module.css +2 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/settings-section.d.ts +4 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +1 -1
- package/dist/dashboard/settings-section.module.css +19 -4
- package/dist/dashboard/stat-card-parts.d.ts +5 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +8 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +25 -6
- package/dist/dashboard/stat-card.module.css +31 -7
- package/dist/dashboard/stat-card.module.css.d.ts +3 -0
- package/dist/dashboard/stat-strip.module.css +4 -1
- package/dist/dashboard/widget-header.module.css +17 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/shell/app-main.module.css +18 -0
- package/dist/styles.css +46 -0
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +8 -2
- package/dist/table/cell-kinds.d.ts +44 -0
- package/dist/table/cell-kinds.d.ts.map +1 -0
- package/dist/table/cell-kinds.js +169 -0
- package/dist/table/cell-kinds.module.css +55 -0
- package/dist/table/cell-kinds.module.css.d.ts +15 -0
- package/dist/table/data-table-fold.d.ts +147 -0
- package/dist/table/data-table-fold.d.ts.map +1 -0
- package/dist/table/data-table-fold.js +288 -0
- package/dist/table/data-table-state.d.ts +10 -3
- package/dist/table/data-table-state.d.ts.map +1 -1
- package/dist/table/data-table-state.js +11 -6
- package/dist/table/data-table.d.ts +11 -26
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +354 -254
- package/dist/table/data-table.module.css +210 -3
- package/dist/table/data-table.module.css.d.ts +12 -0
- package/dist/table/table-features.d.ts +34 -4
- package/dist/table/table-features.d.ts.map +1 -1
- package/dist/table/table-features.js +10 -0
- package/dist/theme/card-inset.module.css +35 -0
- package/dist/theme/controls.module.css +32 -0
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +5 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +14 -10
- package/dist/tokens/core.d.ts +1 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +1 -0
- package/dist/tokens/derive.js +1 -1
- package/dist/tokens/palette.d.ts +2 -1
- package/dist/tokens/palette.d.ts.map +1 -1
- package/llms.txt +34 -5
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +10 -403
- package/src/agent/chat/virtualize.ts +5 -5
- package/src/charts/ChartCard.tsx +79 -17
- package/src/charts/Lines.tsx +13 -4
- package/src/charts/Sparkline.tsx +131 -45
- package/src/charts/chart-box.module.css +50 -0
- package/src/charts/chart-box.module.css.d.ts +5 -0
- package/src/charts/chart-card.module.css +12 -4
- package/src/charts/chart-card.module.css.d.ts +1 -0
- package/src/charts/compile.ts +22 -18
- package/src/charts/labels.ts +175 -24
- package/src/charts/legend.tsx +3 -2
- package/src/charts/ref-label.ts +86 -17
- package/src/charts/sparkline.module.css +6 -0
- package/src/charts/state.tsx +36 -7
- package/src/cli/shot/capture.ts +29 -6
- package/src/common/empty-copy.ts +17 -0
- package/src/common/virtual-rows.tsx +682 -0
- package/src/controls/controls.module.css +33 -1
- package/src/controls/controls.module.css.d.ts +2 -0
- package/src/controls/enum-filter.tsx +8 -2
- package/src/controls/filter-pill.tsx +80 -27
- package/src/controls/form-layout.module.css +112 -7
- package/src/controls/form-layout.module.css.d.ts +1 -0
- package/src/controls/form-layout.tsx +115 -22
- package/src/controls/multi-select-filter.tsx +22 -11
- package/src/controls/range-filter.tsx +9 -3
- package/src/dashboard/bar-list.module.css +0 -2
- package/src/dashboard/bar-list.tsx +8 -5
- package/src/dashboard/board-nav.ts +67 -0
- package/src/dashboard/board.module.css +160 -0
- package/src/dashboard/board.module.css.d.ts +26 -0
- package/src/dashboard/board.tsx +394 -0
- package/src/dashboard/empty-state.tsx +16 -9
- package/src/dashboard/event-list-model.ts +113 -0
- package/src/dashboard/event-list-rows.tsx +120 -0
- package/src/dashboard/event-list-scroll.ts +145 -0
- package/src/dashboard/event-list-skeleton.tsx +58 -0
- package/src/dashboard/event-list.module.css +283 -0
- package/src/dashboard/event-list.module.css.d.ts +33 -0
- package/src/dashboard/event-list.tsx +309 -0
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-parts.tsx +9 -2
- package/src/dashboard/meter.module.css +2 -1
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/settings-section.module.css +19 -4
- package/src/dashboard/settings-section.tsx +7 -2
- package/src/dashboard/stat-card-parts.tsx +20 -3
- package/src/dashboard/stat-card.module.css +31 -7
- package/src/dashboard/stat-card.module.css.d.ts +3 -0
- package/src/dashboard/stat-card.tsx +24 -5
- package/src/dashboard/stat-strip.module.css +4 -1
- package/src/dashboard/widget-header.module.css +17 -1
- package/src/guard/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/shell/app-main.module.css +18 -0
- package/src/styles.css +46 -0
- package/src/surfaces.ts +7 -1
- package/src/table/cell-kinds.module.css +55 -0
- package/src/table/cell-kinds.module.css.d.ts +15 -0
- package/src/table/cell-kinds.tsx +234 -0
- package/src/table/data-table-fold.tsx +514 -0
- package/src/table/data-table-state.ts +24 -13
- package/src/table/data-table.module.css +210 -3
- package/src/table/data-table.module.css.d.ts +12 -0
- package/src/table/data-table.tsx +406 -359
- package/src/table/table-features.ts +44 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
- package/src/theme/card-inset.module.css +35 -0
- package/src/theme/controls.module.css +32 -0
- package/src/theme/ctl-theme.tsx +8 -0
- package/src/theme/index.ts +12 -8
- package/src/tokens/core.ts +1 -0
- package/src/tokens/derive.ts +1 -1
- package/src/tokens/palette.ts +4 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { date, dateTime, relativeTime, time, weekday } from "../format/index.js";
|
|
2
|
+
const toEventDate = (at) => at instanceof Date ? at : new Date(at);
|
|
3
|
+
const isValidEventDate = (at) => Number.isFinite(at.getTime());
|
|
4
|
+
const NO_TIME = "\u2014";
|
|
5
|
+
function dayKey(at) {
|
|
6
|
+
const month = String(at.getMonth() + 1).padStart(2, "0");
|
|
7
|
+
const day = String(at.getDate()).padStart(2, "0");
|
|
8
|
+
return `${at.getFullYear()}-${month}-${day}`;
|
|
9
|
+
}
|
|
10
|
+
function groupByDay(items) {
|
|
11
|
+
const runs = [];
|
|
12
|
+
const leading = [];
|
|
13
|
+
for (const item of items) {
|
|
14
|
+
const at = toEventDate(item.at);
|
|
15
|
+
const last = runs[runs.length - 1];
|
|
16
|
+
if (!isValidEventDate(at)) {
|
|
17
|
+
if (last === void 0) leading.push(item);
|
|
18
|
+
else last.items.push(item);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const key = dayKey(at);
|
|
22
|
+
if (last !== void 0 && last.key === key) last.items.push(item);
|
|
23
|
+
else runs.push({ day: at, key, items: runs.length === 0 ? [...leading, item] : [item] });
|
|
24
|
+
}
|
|
25
|
+
if (runs.length === 0) {
|
|
26
|
+
return leading.length === 0 ? [] : [{ day: new Date(Number.NaN), key: "invalid", id: "invalid#0", items: leading }];
|
|
27
|
+
}
|
|
28
|
+
const seen = /* @__PURE__ */ new Map();
|
|
29
|
+
return runs.map((run) => {
|
|
30
|
+
const n = seen.get(run.key) ?? 0;
|
|
31
|
+
seen.set(run.key, n + 1);
|
|
32
|
+
return { ...run, id: `${run.key}#${n}` };
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function defaultDayLabel(day, now) {
|
|
36
|
+
if (!isValidEventDate(day)) return NO_TIME;
|
|
37
|
+
if (now === null) return `${weekday(day)}, ${date(day)}`;
|
|
38
|
+
const key = dayKey(day);
|
|
39
|
+
if (key === dayKey(now)) return "Today";
|
|
40
|
+
const before = new Date(now);
|
|
41
|
+
before.setDate(before.getDate() - 1);
|
|
42
|
+
if (key === dayKey(before)) return "Yesterday";
|
|
43
|
+
return `${weekday(day)}, ${date(day)}`;
|
|
44
|
+
}
|
|
45
|
+
function formatEventTime(at, mode, now) {
|
|
46
|
+
if (!isValidEventDate(at)) return NO_TIME;
|
|
47
|
+
if (typeof mode === "function") return mode(at);
|
|
48
|
+
if (mode === "relative" && now !== null) return relativeTime(at, { now: now.getTime() });
|
|
49
|
+
if (mode === "relative") return dateTime(at, { format: "short" });
|
|
50
|
+
if (mode === "date-time") return dateTime(at, { format: "short" });
|
|
51
|
+
return time(at, { format: "short" });
|
|
52
|
+
}
|
|
53
|
+
const present = (node) => node !== void 0 && node !== null && typeof node !== "boolean" && node !== "";
|
|
54
|
+
function rowAttributes(ctx, first, last) {
|
|
55
|
+
return {
|
|
56
|
+
"data-density": ctx.density,
|
|
57
|
+
"data-lead": ctx.lead ? "" : void 0,
|
|
58
|
+
"data-rail": ctx.rail ? "" : void 0,
|
|
59
|
+
"data-first": first ? "" : void 0,
|
|
60
|
+
"data-last": last ? "" : void 0
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
dayKey,
|
|
65
|
+
defaultDayLabel,
|
|
66
|
+
formatEventTime,
|
|
67
|
+
groupByDay,
|
|
68
|
+
isValidEventDate,
|
|
69
|
+
present,
|
|
70
|
+
rowAttributes,
|
|
71
|
+
toEventDate
|
|
72
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** `EventList`'s row, day header and the flat rows of its windowed path. */
|
|
2
|
+
import type { VirtualRow } from '../common/virtual-rows.js';
|
|
3
|
+
import type { EventListProps } from './event-list.js';
|
|
4
|
+
import type { EventGroup, RowContext } from './event-list-model.js';
|
|
5
|
+
export type EventItem = EventListProps['items'][number];
|
|
6
|
+
export declare function EventRow({ item, ctx, first, last, tag: Tag, }: {
|
|
7
|
+
item: EventItem;
|
|
8
|
+
ctx: RowContext;
|
|
9
|
+
first: boolean;
|
|
10
|
+
last: boolean;
|
|
11
|
+
tag: 'li' | 'div';
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
/** The flat rows of the windowed path: a sticky header row per day, then its items. */
|
|
14
|
+
export declare function buildRows(groups: readonly EventGroup<EventItem>[], showHeaders: boolean, ctx: RowContext, headerText: (day: Date) => string): VirtualRow[];
|
|
15
|
+
export declare function DayHeader({ text, count, id, as: Tag, windowed, }: {
|
|
16
|
+
text: string;
|
|
17
|
+
count: number;
|
|
18
|
+
id?: string;
|
|
19
|
+
as?: 'h3' | 'div';
|
|
20
|
+
/** A windowed header is its own list item, its inner element a level-3 heading like the plain `<h3>`. */
|
|
21
|
+
windowed?: boolean;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
//# sourceMappingURL=event-list-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-list-rows.d.ts","sourceRoot":"","sources":["../../src/dashboard/event-list-rows.tsx"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAQlD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEhE,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvD,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,GAAG,EAAE,GAAG,GACT,EAAE;IACD,IAAI,EAAE,SAAS,CAAA;IACf,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE,IAAI,GAAG,KAAK,CAAA;CAClB,+BAkCA;AAID,uFAAuF;AACvF,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,UAAU,CAAC,SAAS,CAAC,EAAE,EACxC,WAAW,EAAE,OAAO,EACpB,GAAG,EAAE,UAAU,EACf,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,GAChC,UAAU,EAAE,CAkBd;AAED,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,KAAK,EACL,EAAE,EACF,EAAE,EAAE,GAAW,EACf,QAAgB,GACjB,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,EAAE,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;IACjB,yGAAyG;IACzG,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,+BAeA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classes from "./event-list.module.css";
|
|
3
|
+
import {
|
|
4
|
+
formatEventTime,
|
|
5
|
+
isValidEventDate,
|
|
6
|
+
present,
|
|
7
|
+
rowAttributes,
|
|
8
|
+
toEventDate
|
|
9
|
+
} from "./event-list-model.js";
|
|
10
|
+
function EventRow({
|
|
11
|
+
item,
|
|
12
|
+
ctx,
|
|
13
|
+
first,
|
|
14
|
+
last,
|
|
15
|
+
tag: Tag
|
|
16
|
+
}) {
|
|
17
|
+
const at = toEventDate(item.at);
|
|
18
|
+
const valid = isValidEventDate(at);
|
|
19
|
+
const stamp = formatEventTime(at, ctx.timeMode, ctx.now);
|
|
20
|
+
const hasMeta = present(item.body) || present(item.chips);
|
|
21
|
+
return /* @__PURE__ */ jsxs(
|
|
22
|
+
Tag,
|
|
23
|
+
{
|
|
24
|
+
className: classes.row,
|
|
25
|
+
role: Tag === "div" ? "listitem" : void 0,
|
|
26
|
+
"data-event-id": item.id,
|
|
27
|
+
"data-untimed": stamp === "" ? "" : void 0,
|
|
28
|
+
"data-chips-only": stamp === "" && !present(item.body) && present(item.chips) ? "" : void 0,
|
|
29
|
+
...rowAttributes(ctx, first, last),
|
|
30
|
+
children: [
|
|
31
|
+
ctx.lead && /* @__PURE__ */ jsx("span", { className: classes.leading, children: item.leading }),
|
|
32
|
+
/* @__PURE__ */ jsxs("span", { className: classes.line, children: [
|
|
33
|
+
present(item.actor) && /* @__PURE__ */ jsxs("span", { className: classes.actor, children: [
|
|
34
|
+
item.actor,
|
|
35
|
+
" "
|
|
36
|
+
] }),
|
|
37
|
+
item.title
|
|
38
|
+
] }),
|
|
39
|
+
stamp !== "" && /* @__PURE__ */ jsx("time", { className: classes.time, ...valid && { dateTime: at.toISOString() }, children: stamp }),
|
|
40
|
+
hasMeta && /* @__PURE__ */ jsxs("div", { className: classes.meta, children: [
|
|
41
|
+
present(item.body) && /* @__PURE__ */ jsx("span", { className: classes.body, children: item.body }),
|
|
42
|
+
present(item.chips) && /* @__PURE__ */ jsx("span", { className: classes.chips, children: item.chips })
|
|
43
|
+
] })
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const countLabel = (n) => `\xB7 ${n} ${n === 1 ? "event" : "events"}`;
|
|
49
|
+
function buildRows(groups, showHeaders, ctx, headerText) {
|
|
50
|
+
return groups.flatMap((g) => {
|
|
51
|
+
const itemRows = g.items.map((item, i) => ({
|
|
52
|
+
key: `item:${item.id}`,
|
|
53
|
+
node: /* @__PURE__ */ jsx(EventRow, { item, ctx, first: i === 0, last: i === g.items.length - 1, tag: "div" })
|
|
54
|
+
}));
|
|
55
|
+
if (!showHeaders) return itemRows;
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
key: `day:${g.id}`,
|
|
59
|
+
sticky: true,
|
|
60
|
+
node: /* @__PURE__ */ jsx(DayHeader, { text: headerText(g.day), count: g.items.length, windowed: true })
|
|
61
|
+
},
|
|
62
|
+
...itemRows
|
|
63
|
+
];
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function DayHeader({
|
|
67
|
+
text,
|
|
68
|
+
count,
|
|
69
|
+
id,
|
|
70
|
+
as: Tag = "div",
|
|
71
|
+
windowed = false
|
|
72
|
+
}) {
|
|
73
|
+
const header = /* @__PURE__ */ jsxs(
|
|
74
|
+
Tag,
|
|
75
|
+
{
|
|
76
|
+
id,
|
|
77
|
+
"data-day-header": "",
|
|
78
|
+
...windowed && { role: "heading", "aria-level": 3 },
|
|
79
|
+
className: classes.header,
|
|
80
|
+
children: [
|
|
81
|
+
text,
|
|
82
|
+
/* @__PURE__ */ jsx("span", { className: classes.count, children: countLabel(count) })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
if (!windowed) return header;
|
|
87
|
+
return /* @__PURE__ */ jsx("div", { role: "listitem", children: header });
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
DayHeader,
|
|
91
|
+
EventRow,
|
|
92
|
+
buildRows
|
|
93
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list's own scroll node keeps the visible row across a prepend: the count grew and the old
|
|
3
|
+
* first id is still in the list, so the height delta goes onto `scrollTop`. Memory resets whenever
|
|
4
|
+
* there is nothing to anchor (disabled, no rows, node absent), so a reload is never read as a
|
|
5
|
+
* prepend. The node sets `overflow-anchor: none` so the browser cannot add the same delta twice.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePrependAnchor(node: HTMLElement | null, enabled: boolean, items: readonly {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
}[]): void;
|
|
10
|
+
/**
|
|
11
|
+
* An oldest-first list with its own scroll node opens on the newest end — and keeps opening there
|
|
12
|
+
* while the layout is still settling (fonts, the narrow time move, wrapping grow `scrollHeight`
|
|
13
|
+
* after the first jump), until the user touches it, the item count changes (an `earlier` load), or
|
|
14
|
+
* a few seconds pass. Plain path only: the windowed seam opens itself with `initialScroll`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useOpenAtEnd(node: HTMLElement | null, active: boolean, count: number): void;
|
|
17
|
+
/** Marks the scroll node `data-scrolled` while it is off the top, so CSS can lift the sticky day header. */
|
|
18
|
+
export declare function useScrolledEdge(node: HTMLElement | null): void;
|
|
19
|
+
/**
|
|
20
|
+
* While rows are plain DOM the content height is kept on the node as `--event-list-held`; the
|
|
21
|
+
* windowed wrapper takes it as a minimum height, so swapping plain rows for the lazy seam never
|
|
22
|
+
* collapses the scroller (the browser would clamp `scrollTop` to 0 before the peer resolves). It is
|
|
23
|
+
* only for that handoff: it is released as soon as the windowed rows have rendered, and whenever
|
|
24
|
+
* there are no rows, so a shorter list never leaves blank space below its last row.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useHeldHeight(node: HTMLElement | null, mode: 'plain' | 'windowed' | 'none'): void;
|
|
27
|
+
//# sourceMappingURL=event-list-scroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-list-scroll.d.ts","sourceRoot":"","sources":["../../src/dashboard/event-list-scroll.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,WAAW,GAAG,IAAI,EACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,GACxC,IAAI,CAsBN;AAQD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAuC3F;AAED,4GAA4G;AAC5G,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAY9D;AAID;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,CAuBjG"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "../common/isomorphic-layout-effect.js";
|
|
3
|
+
function usePrependAnchor(node, enabled, items) {
|
|
4
|
+
const prev = useRef(null);
|
|
5
|
+
const firstId = items[0]?.id;
|
|
6
|
+
const count = items.length;
|
|
7
|
+
useIsomorphicLayoutEffect(() => {
|
|
8
|
+
const root = enabled ? node : null;
|
|
9
|
+
if (root === null || firstId === void 0) {
|
|
10
|
+
prev.current = null;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const before = prev.current;
|
|
14
|
+
if (before !== null && before.firstId !== firstId && count > before.count && items.some((item) => item.id === before.firstId)) {
|
|
15
|
+
root.scrollTop += root.scrollHeight - before.scrollHeight;
|
|
16
|
+
}
|
|
17
|
+
prev.current = { firstId, count, scrollHeight: root.scrollHeight };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const USER_INPUT = ["wheel", "touchstart", "pointerdown", "keydown"];
|
|
21
|
+
const OPEN_AT_END_MS = 3e3;
|
|
22
|
+
function useOpenAtEnd(node, active, count) {
|
|
23
|
+
const latest = useRef(count);
|
|
24
|
+
useIsomorphicLayoutEffect(() => {
|
|
25
|
+
if (node === null || !active) return;
|
|
26
|
+
const el = node;
|
|
27
|
+
el.scrollTo({ top: el.scrollHeight, behavior: "instant" });
|
|
28
|
+
}, [node, active]);
|
|
29
|
+
useIsomorphicLayoutEffect(() => {
|
|
30
|
+
latest.current = count;
|
|
31
|
+
});
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (node === null || !active) return;
|
|
34
|
+
const opened = latest.current;
|
|
35
|
+
const el = node;
|
|
36
|
+
let stopped = false;
|
|
37
|
+
const toEnd = () => {
|
|
38
|
+
el.scrollTo({ top: el.scrollHeight, behavior: "instant" });
|
|
39
|
+
};
|
|
40
|
+
const reapply = () => {
|
|
41
|
+
if (stopped) return;
|
|
42
|
+
if (latest.current === opened) toEnd();
|
|
43
|
+
else stop();
|
|
44
|
+
};
|
|
45
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(reapply);
|
|
46
|
+
const timer = setTimeout(() => stop(), OPEN_AT_END_MS);
|
|
47
|
+
function stop() {
|
|
48
|
+
stopped = true;
|
|
49
|
+
observer?.disconnect();
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
for (const type of USER_INPUT) el.removeEventListener(type, stop);
|
|
52
|
+
}
|
|
53
|
+
for (const type of USER_INPUT) el.addEventListener(type, stop, { passive: true });
|
|
54
|
+
observer?.observe(el);
|
|
55
|
+
if (el.firstElementChild !== null) observer?.observe(el.firstElementChild);
|
|
56
|
+
toEnd();
|
|
57
|
+
void document.fonts?.ready?.then(reapply);
|
|
58
|
+
return stop;
|
|
59
|
+
}, [node, active]);
|
|
60
|
+
}
|
|
61
|
+
function useScrolledEdge(node) {
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (node === null) return;
|
|
64
|
+
const el = node;
|
|
65
|
+
const mark = () => {
|
|
66
|
+
if (el.scrollTop > 0) el.setAttribute("data-scrolled", "");
|
|
67
|
+
else el.removeAttribute("data-scrolled");
|
|
68
|
+
};
|
|
69
|
+
mark();
|
|
70
|
+
el.addEventListener("scroll", mark, { passive: true });
|
|
71
|
+
return () => el.removeEventListener("scroll", mark);
|
|
72
|
+
}, [node]);
|
|
73
|
+
}
|
|
74
|
+
const HELD = "--event-list-held";
|
|
75
|
+
function useHeldHeight(node, mode) {
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const content = node?.firstElementChild;
|
|
78
|
+
if (node === null || content === null || content === void 0) return;
|
|
79
|
+
const el = node;
|
|
80
|
+
if (mode === "none") {
|
|
81
|
+
el.style.removeProperty(HELD);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => run());
|
|
85
|
+
function run() {
|
|
86
|
+
if (mode === "plain") {
|
|
87
|
+
el.style.setProperty(HELD, `${content?.getBoundingClientRect().height ?? 0}px`);
|
|
88
|
+
} else if (observer === null || content?.querySelector("[data-index]") !== null) {
|
|
89
|
+
el.style.removeProperty(HELD);
|
|
90
|
+
observer?.disconnect();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
observer?.observe(content);
|
|
94
|
+
run();
|
|
95
|
+
return () => observer?.disconnect();
|
|
96
|
+
}, [node, mode]);
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
useHeldHeight,
|
|
100
|
+
useOpenAtEnd,
|
|
101
|
+
usePrependAnchor,
|
|
102
|
+
useScrolledEdge
|
|
103
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RowContext } from './event-list-model.js';
|
|
2
|
+
/** Skeleton rows in the loaded shape (header bars when grouped, glyph, sentence, time, meta and, on
|
|
3
|
+
* a timeline, chips), enough to fill a bounded height. */
|
|
4
|
+
export declare function SkeletonRows({ count, ctx, grouped, height, }: {
|
|
5
|
+
count: number;
|
|
6
|
+
ctx: RowContext;
|
|
7
|
+
grouped: boolean;
|
|
8
|
+
height: number | string | undefined;
|
|
9
|
+
}): import("react").JSX.Element[];
|
|
10
|
+
//# sourceMappingURL=event-list-skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-list-skeleton.d.ts","sourceRoot":"","sources":["../../src/dashboard/event-list-skeleton.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAOpD;0DAC0D;AAC1D,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,GAAG,EACH,OAAO,EACP,MAAM,GACP,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,UAAU,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACpC,iCAkCA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Skeleton } from "@mantine/core";
|
|
3
|
+
import classes from "./event-list.module.css";
|
|
4
|
+
import { rowAttributes } from "./event-list-model.js";
|
|
5
|
+
const SKELETON_GROUP = 3;
|
|
6
|
+
const SKELETON_ROW_PX = { feed: 48, timeline: 76 };
|
|
7
|
+
function SkeletonRows({
|
|
8
|
+
count,
|
|
9
|
+
ctx,
|
|
10
|
+
grouped,
|
|
11
|
+
height
|
|
12
|
+
}) {
|
|
13
|
+
const total = typeof height === "number" ? Math.max(count, Math.ceil(height / SKELETON_ROW_PX[ctx.density]) + 1) : count;
|
|
14
|
+
return Array.from({ length: total }, (_, i) => /* @__PURE__ */ jsxs("div", { className: classes.skeletonGroup, "aria-hidden": true, children: [
|
|
15
|
+
grouped && i % SKELETON_GROUP === 0 && /* @__PURE__ */ jsx("div", { className: classes.header, children: /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonHeader }) }),
|
|
16
|
+
/* @__PURE__ */ jsxs(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
className: classes.row,
|
|
20
|
+
...rowAttributes(ctx, i % SKELETON_GROUP === 0, i === total - 1),
|
|
21
|
+
children: [
|
|
22
|
+
ctx.lead && /* @__PURE__ */ jsx("span", { className: classes.leading, children: /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonGlyph, circle: true }) }),
|
|
23
|
+
/* @__PURE__ */ jsx("span", { className: classes.line, children: /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonLine }) }),
|
|
24
|
+
/* @__PURE__ */ jsx("span", { className: classes.time, children: /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonTime }) }),
|
|
25
|
+
/* @__PURE__ */ jsxs("div", { className: classes.meta, children: [
|
|
26
|
+
/* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonMeta }),
|
|
27
|
+
ctx.density === "timeline" && /* @__PURE__ */ jsx(Skeleton, { className: classes.skeletonChip })
|
|
28
|
+
] })
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
] }, i));
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
SkeletonRows
|
|
36
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { BasaltProps } from '../common/props.js';
|
|
3
|
+
export type EventListProps = BasaltProps & {
|
|
4
|
+
/** Accessible name of the list. Default "Events". */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** Events in display order — kept as given, never re-sorted. `id`s must be unique within the list. */
|
|
7
|
+
items: readonly {
|
|
8
|
+
id: string;
|
|
9
|
+
at: Date | number;
|
|
10
|
+
actor?: ReactNode;
|
|
11
|
+
title: ReactNode;
|
|
12
|
+
body?: ReactNode;
|
|
13
|
+
/** A glyph or avatar in the leading column. */
|
|
14
|
+
leading?: ReactNode;
|
|
15
|
+
chips?: ReactNode;
|
|
16
|
+
}[];
|
|
17
|
+
/** `feed`: one clamped line, about 52 px a two-line row. `timeline`: a rail, full sentences, body and chips in full. */
|
|
18
|
+
density?: 'feed' | 'timeline';
|
|
19
|
+
/** The 1 px line through the leading column joining rows within a day group. Default: `density === 'timeline'`. */
|
|
20
|
+
rail?: boolean;
|
|
21
|
+
/** Day headers (`micro` mono, muted, with the row count) or one flat list. Default `day`. */
|
|
22
|
+
group?: 'day' | 'none';
|
|
23
|
+
/**
|
|
24
|
+
* The instant "Today" and relative times are measured from. Default: the client clock, read once
|
|
25
|
+
* after mount; until then (the server render, the hydrating paint) days read as dates and a
|
|
26
|
+
* `relative` time as a date-time, so server and client markup match.
|
|
27
|
+
*/
|
|
28
|
+
now?: number | Date;
|
|
29
|
+
/** Overrides the `Today` / `Yesterday` / short-date header text. Without a clock yet, `now` is the day itself. */
|
|
30
|
+
dayLabel?: (day: Date, now: Date) => string;
|
|
31
|
+
/**
|
|
32
|
+
* The time column. Default `clock` when grouped by day, `date-time` when not. A function formats it
|
|
33
|
+
* yourself; one returning an empty string renders no time for that row (an untimed entry).
|
|
34
|
+
*/
|
|
35
|
+
time?: 'clock' | 'relative' | 'date-time' | ((at: Date) => string);
|
|
36
|
+
/** Which end of `items` is earlier. Does not sort. Default `newest-first`. */
|
|
37
|
+
order?: 'newest-first' | 'oldest-first';
|
|
38
|
+
/**
|
|
39
|
+
* A quiet "Show earlier (N)" control at the earlier end (bottom for newest-first, top for
|
|
40
|
+
* oldest-first). With `height`, prepending (oldest-first) keeps the visible row where it is and a
|
|
41
|
+
* list opens on its newest end; a content-sized list leaves scrolling to the page.
|
|
42
|
+
*/
|
|
43
|
+
earlier?: {
|
|
44
|
+
onLoad: () => void;
|
|
45
|
+
loading?: boolean;
|
|
46
|
+
remaining?: number;
|
|
47
|
+
};
|
|
48
|
+
/** The list owns a scroll node of this height (modal, aside, card). Omitted: content-sized. */
|
|
49
|
+
height?: number | string;
|
|
50
|
+
/** Renders row-shaped skeletons. */
|
|
51
|
+
loading?: boolean;
|
|
52
|
+
/** Skeleton rows while loading. Default 5. */
|
|
53
|
+
loadingRows?: number;
|
|
54
|
+
/**
|
|
55
|
+
* The empty state, an `EmptyState` in a ring-edged tile that sizes to its content (no void in a
|
|
56
|
+
* bounded `height`). Default: "Nothing has happened yet" with a one-line why.
|
|
57
|
+
*/
|
|
58
|
+
empty?: {
|
|
59
|
+
title: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
action?: ReactNode;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export declare function EventList({ label, items, density, rail, group, now, dayLabel, time, order, earlier, height, loading, loadingRows, empty, className, style, }: EventListProps): import("react").JSX.Element;
|
|
65
|
+
//# sourceMappingURL=event-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-list.d.ts","sourceRoot":"","sources":["../../src/dashboard/event-list.tsx"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAmBlD,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IACzC,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sGAAsG;IACtG,KAAK,EAAE,SAAS;QACd,EAAE,EAAE,MAAM,CAAA;QACV,EAAE,EAAE,IAAI,GAAG,MAAM,CAAA;QACjB,KAAK,CAAC,EAAE,SAAS,CAAA;QACjB,KAAK,EAAE,SAAS,CAAA;QAChB,IAAI,CAAC,EAAE,SAAS,CAAA;QAChB,+CAA+C;QAC/C,OAAO,CAAC,EAAE,SAAS,CAAA;QACnB,KAAK,CAAC,EAAE,SAAS,CAAA;KAClB,EAAE,CAAA;IACH,wHAAwH;IACxH,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC7B,mHAAmH;IACnH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,6FAA6F;IAC7F,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACtB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,kHAAkH;IAClH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,KAAK,MAAM,CAAA;IAC3C;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,WAAW,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,KAAK,MAAM,CAAC,CAAA;IAClE,8EAA8E;IAC9E,KAAK,CAAC,EAAE,cAAc,GAAG,cAAc,CAAA;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACvE,+FAA+F;IAC/F,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE,CAAA;CACpE,CAAA;AA+BD,wBAAgB,SAAS,CAAC,EACxB,KAAgB,EAChB,KAAK,EACL,OAAgB,EAChB,IAAI,EACJ,KAAa,EACb,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,KAAsB,EACtB,OAAO,EACP,MAAM,EACN,OAAe,EACf,WAAe,EACf,KAAqB,EACrB,SAAS,EACT,KAAK,GACN,EAAE,cAAc,+BAoJhB"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, VisuallyHidden } from "@mantine/core";
|
|
3
|
+
import { useId, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { cx } from "../common/props.js";
|
|
5
|
+
import { VirtualRows } from "../common/virtual-rows.js";
|
|
6
|
+
import classes from "./event-list.module.css";
|
|
7
|
+
import { EmptyState } from "./empty-state.js";
|
|
8
|
+
import { buildRows, DayHeader, EventRow } from "./event-list-rows.js";
|
|
9
|
+
import {
|
|
10
|
+
defaultDayLabel,
|
|
11
|
+
groupByDay,
|
|
12
|
+
isValidEventDate,
|
|
13
|
+
present,
|
|
14
|
+
toEventDate
|
|
15
|
+
} from "./event-list-model.js";
|
|
16
|
+
import { useHeldHeight, useOpenAtEnd, usePrependAnchor, useScrolledEdge } from "./event-list-scroll.js";
|
|
17
|
+
import { SkeletonRows } from "./event-list-skeleton.js";
|
|
18
|
+
const VIRTUALIZE_THRESHOLD = 200;
|
|
19
|
+
const subscribeNever = () => () => {
|
|
20
|
+
};
|
|
21
|
+
function useClientClock() {
|
|
22
|
+
const at = useRef(null);
|
|
23
|
+
return useSyncExternalStore(
|
|
24
|
+
subscribeNever,
|
|
25
|
+
() => at.current ??= Date.now(),
|
|
26
|
+
() => null
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function usePlainBefore(hasRows, windowed) {
|
|
30
|
+
const [plain, setPlain] = useState(false);
|
|
31
|
+
const next = hasRows ? plain || !windowed : false;
|
|
32
|
+
if (next !== plain) setPlain(next);
|
|
33
|
+
return next;
|
|
34
|
+
}
|
|
35
|
+
const DEFAULT_EMPTY = {
|
|
36
|
+
title: "Nothing has happened yet",
|
|
37
|
+
description: "Events appear here as they happen."
|
|
38
|
+
};
|
|
39
|
+
function EventList({
|
|
40
|
+
label = "Events",
|
|
41
|
+
items,
|
|
42
|
+
density = "feed",
|
|
43
|
+
rail,
|
|
44
|
+
group = "day",
|
|
45
|
+
now,
|
|
46
|
+
dayLabel,
|
|
47
|
+
time,
|
|
48
|
+
order = "newest-first",
|
|
49
|
+
earlier,
|
|
50
|
+
height,
|
|
51
|
+
loading = false,
|
|
52
|
+
loadingRows = 5,
|
|
53
|
+
empty = DEFAULT_EMPTY,
|
|
54
|
+
className,
|
|
55
|
+
style
|
|
56
|
+
}) {
|
|
57
|
+
const clock = useClientClock();
|
|
58
|
+
const [scrollEl, setScrollEl] = useState(null);
|
|
59
|
+
const labelId = useId();
|
|
60
|
+
const nowDate = now !== void 0 ? new Date(now) : clock === null ? null : new Date(clock);
|
|
61
|
+
const grouped = group === "day";
|
|
62
|
+
const withRail = rail ?? density === "timeline";
|
|
63
|
+
const ctx = {
|
|
64
|
+
density,
|
|
65
|
+
rail: withRail,
|
|
66
|
+
lead: withRail || items.some((i) => present(i.leading)),
|
|
67
|
+
timeMode: time ?? (grouped ? "clock" : "date-time"),
|
|
68
|
+
now: nowDate
|
|
69
|
+
};
|
|
70
|
+
const oldestFirst = order === "oldest-first";
|
|
71
|
+
const hasRows = !loading && items.length > 0;
|
|
72
|
+
const virtualised = hasRows && items.length > VIRTUALIZE_THRESHOLD;
|
|
73
|
+
const ownScroll = height !== void 0;
|
|
74
|
+
const opensAtEnd = oldestFirst && ownScroll;
|
|
75
|
+
const plainBefore = usePlainBefore(hasRows, virtualised);
|
|
76
|
+
usePrependAnchor(scrollEl, opensAtEnd && hasRows && !virtualised, items);
|
|
77
|
+
useOpenAtEnd(scrollEl, opensAtEnd && hasRows && !virtualised, items.length);
|
|
78
|
+
useScrolledEdge(ownScroll ? scrollEl : null);
|
|
79
|
+
useHeldHeight(scrollEl, !hasRows ? "none" : virtualised ? "windowed" : "plain");
|
|
80
|
+
const control = earlier === void 0 || !hasRows ? null : /* @__PURE__ */ jsx("div", { className: classes.earlier, "data-end": oldestFirst ? "top" : "bottom", children: /* @__PURE__ */ jsx(
|
|
81
|
+
Button,
|
|
82
|
+
{
|
|
83
|
+
variant: "subtle",
|
|
84
|
+
color: "gray",
|
|
85
|
+
size: "compact-sm",
|
|
86
|
+
className: classes.earlierButton,
|
|
87
|
+
loading: earlier.loading === true,
|
|
88
|
+
onClick: earlier.onLoad,
|
|
89
|
+
children: earlier.remaining === void 0 ? "Show earlier" : `Show earlier (${earlier.remaining})`
|
|
90
|
+
}
|
|
91
|
+
) });
|
|
92
|
+
let content;
|
|
93
|
+
if (loading) {
|
|
94
|
+
content = /* @__PURE__ */ jsxs("div", { "aria-busy": "true", children: [
|
|
95
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: `Loading ${label}` }),
|
|
96
|
+
/* @__PURE__ */ jsx(SkeletonRows, { count: loadingRows, ctx, grouped, height })
|
|
97
|
+
] });
|
|
98
|
+
} else if (items.length === 0) {
|
|
99
|
+
content = // oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- a polite live region whose name is the visually hidden label inside
|
|
100
|
+
/* @__PURE__ */ jsxs("div", { className: classes.empty, role: "status", children: [
|
|
101
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: label }),
|
|
102
|
+
/* @__PURE__ */ jsx(
|
|
103
|
+
EmptyState,
|
|
104
|
+
{
|
|
105
|
+
tier: "section",
|
|
106
|
+
title: empty.title,
|
|
107
|
+
...empty.description !== void 0 && { description: empty.description },
|
|
108
|
+
...empty.action !== void 0 && { action: empty.action }
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
] });
|
|
112
|
+
} else {
|
|
113
|
+
const groups = grouped ? groupByDay(items) : [{ day: toEventDate(items[0]?.at ?? 0), key: "all", id: "all#0", items }];
|
|
114
|
+
const showHeaders = grouped && groups.some((g) => isValidEventDate(g.day));
|
|
115
|
+
const headerText = (day) => !isValidEventDate(day) ? "" : dayLabel === void 0 ? defaultDayLabel(day, nowDate) : dayLabel(day, nowDate ?? day);
|
|
116
|
+
if (virtualised) {
|
|
117
|
+
const seam = {
|
|
118
|
+
rows: buildRows(groups, showHeaders, ctx, headerText),
|
|
119
|
+
overscan: 8,
|
|
120
|
+
estimateSize: density === "timeline" ? 96 : 60,
|
|
121
|
+
className: classes.virtual,
|
|
122
|
+
anchorTo: oldestFirst ? "end" : "start",
|
|
123
|
+
// The shell scrollport is never jumped: only an own scroll node opens on its newest end.
|
|
124
|
+
// And only when the rows first appeared windowed: a list crossing 200 on an `earlier` load
|
|
125
|
+
// does not jump to the newest end.
|
|
126
|
+
initialScroll: opensAtEnd && !plainBefore ? "end" : "start",
|
|
127
|
+
// Own scroll node → the seam windows against it; none → the nearest scrolling ancestor.
|
|
128
|
+
...ownScroll && { scrollRoot: scrollEl }
|
|
129
|
+
};
|
|
130
|
+
content = // oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- the seam renders divs, so the list role is explicit
|
|
131
|
+
/* @__PURE__ */ jsx("div", { role: "list", "aria-label": label, children: /* @__PURE__ */ jsx(VirtualRows, { scroll: "parent", ...seam }) });
|
|
132
|
+
} else {
|
|
133
|
+
content = groups.map((g) => {
|
|
134
|
+
const headerId = `${labelId}-${g.id}`;
|
|
135
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.group, children: [
|
|
136
|
+
showHeaders && /* @__PURE__ */ jsx(DayHeader, { id: headerId, text: headerText(g.day), count: g.items.length, as: "h3" }),
|
|
137
|
+
/* @__PURE__ */ jsx(
|
|
138
|
+
"ol",
|
|
139
|
+
{
|
|
140
|
+
className: classes.list,
|
|
141
|
+
role: "list",
|
|
142
|
+
...showHeaders ? { "aria-labelledby": headerId } : { "aria-label": label },
|
|
143
|
+
children: g.items.map((item, i) => /* @__PURE__ */ jsx(
|
|
144
|
+
EventRow,
|
|
145
|
+
{
|
|
146
|
+
item,
|
|
147
|
+
ctx,
|
|
148
|
+
first: i === 0,
|
|
149
|
+
last: i === g.items.length - 1,
|
|
150
|
+
tag: "li"
|
|
151
|
+
},
|
|
152
|
+
item.id
|
|
153
|
+
))
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
] }, g.id);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const boxed = ownScroll && (loading || items.length > 0);
|
|
161
|
+
const scrollStyle = boxed ? { height } : void 0;
|
|
162
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(classes.frame, className), style, "data-density": density, children: [
|
|
163
|
+
oldestFirst && control,
|
|
164
|
+
/* @__PURE__ */ jsx(
|
|
165
|
+
"div",
|
|
166
|
+
{
|
|
167
|
+
ref: setScrollEl,
|
|
168
|
+
className: cx(classes.root, boxed && classes.scroll),
|
|
169
|
+
style: scrollStyle,
|
|
170
|
+
children: /* @__PURE__ */ jsx("div", { children: content })
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
!oldestFirst && control
|
|
174
|
+
] });
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
EventList
|
|
178
|
+
};
|