basalt-ui 2.8.1 → 2.9.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/AGENTS.md +2 -2
- package/CHANGELOG.md +24 -0
- package/MIGRATING.md +58 -27
- package/README.md +7 -8
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/templates/AGENTS-block.md.tpl +2 -2
- package/configs/oxlint-plugin.js +25 -68
- package/configs/oxlint-plugin.test.ts +19 -27
- package/dist/charts/BandStrip.d.ts +1 -1
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +1 -10
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +2 -9
- package/dist/charts/band-fold.d.ts +15 -0
- package/dist/charts/band-fold.d.ts.map +1 -0
- package/dist/charts/band-fold.js +19 -0
- package/dist/charts/index.d.ts +1 -0
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/index.js +3 -1
- package/dist/cli/audit-allows.d.ts.map +1 -1
- package/dist/cli/audit-allows.js +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +4 -1
- package/dist/cli/config.d.ts +4 -4
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +6 -12
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/install-root.d.ts +10 -0
- package/dist/cli/install-root.d.ts.map +1 -0
- package/dist/cli/install-root.js +32 -0
- package/dist/cli/sync.d.ts +0 -2
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +8 -11
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +1 -6
- package/dist/common/errors.d.ts +1 -6
- package/dist/common/errors.d.ts.map +1 -1
- package/dist/common/errors.js +0 -7
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -9
- package/dist/common/props.d.ts +2 -2
- package/dist/common/vx-family.d.ts +1 -1
- package/dist/content/toc-click-pin.d.ts +45 -0
- package/dist/content/toc-click-pin.d.ts.map +1 -0
- package/dist/content/toc-click-pin.js +111 -0
- package/dist/content/toc-spy.d.ts +25 -0
- package/dist/content/toc-spy.d.ts.map +1 -0
- package/dist/content/toc-spy.js +43 -0
- package/dist/content/toc.d.ts +1 -4
- package/dist/content/toc.d.ts.map +1 -1
- package/dist/content/toc.js +38 -49
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +1 -1
- package/dist/dashboard/index.d.ts +1 -1
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +1 -3
- package/dist/dashboard/section.d.ts +10 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +20 -3
- package/dist/dashboard/stat-card.d.ts +2 -8
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +1 -1
- package/dist/guard/index.d.ts +13 -9
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +74 -37
- package/dist/guard/types.d.ts +8 -7
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +1 -33
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.d.ts +1 -11
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +1 -2
- package/dist/shell/index.d.ts +1 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +3 -0
- package/dist/shell/nav-types.d.ts +1 -1
- package/dist/shell/page-bar.d.ts +6 -0
- package/dist/shell/page-bar.d.ts.map +1 -1
- package/dist/shell/page-bar.js +12 -2
- package/dist/state/fields.d.ts +1 -1
- package/dist/state/fields.d.ts.map +1 -1
- package/dist/state/fields.js +3 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +5 -11
- package/dist/table/data-table.d.ts +2 -2
- package/dist/tokens/core.d.ts +0 -10
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -44
- package/llms.txt +24 -8
- package/package.json +8 -5
- package/src/charts/BandStrip.tsx +4 -16
- package/src/charts/MirroredBars.tsx +2 -11
- package/src/charts/band-fold.ts +26 -0
- package/src/charts/index.ts +1 -0
- package/src/cli/audit-allows.ts +1 -3
- package/src/cli/check-theme.ts +7 -1
- package/src/cli/config.ts +4 -4
- package/src/cli/doctor.ts +6 -17
- package/src/cli/help.ts +1 -4
- package/src/cli/index.ts +1 -2
- package/src/cli/install-root.ts +40 -0
- package/src/cli/sync.ts +9 -12
- package/src/cli/tokens-css.ts +0 -5
- package/src/common/errors.ts +1 -18
- package/src/common/index.ts +1 -8
- package/src/common/props.ts +2 -2
- package/src/common/vx-family.ts +1 -1
- package/src/content/toc-click-pin.ts +156 -0
- package/src/content/toc-spy.ts +61 -0
- package/src/content/toc.tsx +47 -95
- package/src/controls/form-layout.tsx +1 -1
- package/src/controls/number-filter.tsx +6 -1
- package/src/dashboard/index.ts +1 -6
- package/src/dashboard/section.tsx +39 -8
- package/src/dashboard/stat-card.tsx +4 -11
- package/src/guard/index.ts +114 -89
- package/src/guard/types.ts +8 -7
- package/src/guard/vx-names.ts +1 -33
- package/src/index.ts +1 -2
- package/src/router-tanstack/search-store.ts +2 -14
- package/src/shell/index.tsx +2 -0
- package/src/shell/nav-types.ts +1 -1
- package/src/shell/page-bar.tsx +21 -2
- package/src/state/fields.ts +7 -2
- package/src/surfaces.ts +5 -11
- package/src/table/data-table.tsx +2 -2
- package/src/tokens/core.ts +6 -67
- package/dist/tokens.css +0 -331
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long the scroller must be quiet before a pinned click counts as settled: the fallback for a
|
|
3
|
+
* browser without a reliable `scrollend`, and the only signal for a click that needs no scroll.
|
|
4
|
+
*/
|
|
5
|
+
export declare const QUIET_MS = 200;
|
|
6
|
+
/** Scroll movement tolerated while held (sub-pixel offsets, fractional DPR). */
|
|
7
|
+
export declare const HOLD_EPSILON_PX = 2;
|
|
8
|
+
/** The document-level events that mean the reader is about to scroll (or may have). */
|
|
9
|
+
export declare const INTENT_EVENTS: readonly ["wheel", "touchstart", "keydown", "pointerdown"];
|
|
10
|
+
/**
|
|
11
|
+
* Did the reader just do something that scrolls (or may scroll) the page? `link` is the rail link
|
|
12
|
+
* that was activated: pointing at it is the click itself, and Enter on it is not a scroll key.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isScrollIntent(event: Event, link: Element | null): boolean;
|
|
15
|
+
type ClickPinState = {
|
|
16
|
+
readonly kind: 'idle';
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'pinned';
|
|
19
|
+
readonly id: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'held';
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly top: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class ClickPin {
|
|
26
|
+
private readonly onIdle;
|
|
27
|
+
private current;
|
|
28
|
+
private stop;
|
|
29
|
+
/** `onIdle` runs when the machine hands the rail back, so the spy can re-resolve. */
|
|
30
|
+
constructor(onIdle: () => void);
|
|
31
|
+
get state(): ClickPinState;
|
|
32
|
+
/** The entry the click owns (pinned or held), or `null` when the spy answers. A pure query. */
|
|
33
|
+
get activeId(): string | null;
|
|
34
|
+
/** `link` is the rail link just activated; `scroller` the element the spy watches (`null` = document). */
|
|
35
|
+
click(id: string, link: Element | null, scroller: HTMLElement | null): void;
|
|
36
|
+
/** Items changed: a click on an id that no longer exists cannot stand. */
|
|
37
|
+
prune(ids: readonly string[]): void;
|
|
38
|
+
release(): void;
|
|
39
|
+
/** Unmount: idle, timer and listeners gone, no callback. */
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
42
|
+
/** `onIdle` must be stable (a state setter): it is captured once, at construction. */
|
|
43
|
+
export declare function useClickPin(onIdle: () => void): ClickPin;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=toc-click-pin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-click-pin.d.ts","sourceRoot":"","sources":["../../src/content/toc-click-pin.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,gFAAgF;AAChF,eAAO,MAAM,eAAe,IAAI,CAAA;AAsBhC,uFAAuF;AACvF,eAAO,MAAM,aAAa,4DAA6D,CAAA;AAEvF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAY1E;AAMD,KAAK,aAAa,GACd;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAExE,qBAAa,QAAQ;IAKP,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,IAAI,CAA4B;IAExC,qFAAqF;gBACxD,MAAM,EAAE,MAAM,IAAI;IAE/C,IAAI,KAAK,IAAI,aAAa,CAEzB;IAED,+FAA+F;IAC/F,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,0GAA0G;IAC1G,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI;IAwC3E,0EAA0E;IAC1E,KAAK,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAInC,OAAO,IAAI,IAAI;IAMf,4DAA4D;IAC5D,OAAO,IAAI,IAAI;CAKhB;AAED,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,QAAQ,CAIxD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
const QUIET_MS = 200;
|
|
3
|
+
const HOLD_EPSILON_PX = 2;
|
|
4
|
+
const SCROLL_KEYS = /* @__PURE__ */ new Set([
|
|
5
|
+
"PageUp",
|
|
6
|
+
"PageDown",
|
|
7
|
+
"Home",
|
|
8
|
+
"End",
|
|
9
|
+
"ArrowUp",
|
|
10
|
+
"ArrowDown",
|
|
11
|
+
" "
|
|
12
|
+
]);
|
|
13
|
+
const isEditable = (event) => event.composedPath().some(
|
|
14
|
+
(node) => node instanceof HTMLElement && (node.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(node.tagName))
|
|
15
|
+
);
|
|
16
|
+
const INTENT_EVENTS = ["wheel", "touchstart", "keydown", "pointerdown"];
|
|
17
|
+
function isScrollIntent(event, link) {
|
|
18
|
+
switch (event.type) {
|
|
19
|
+
case "wheel":
|
|
20
|
+
case "touchstart":
|
|
21
|
+
return true;
|
|
22
|
+
case "pointerdown":
|
|
23
|
+
return !(event.target instanceof Node && link?.contains(event.target));
|
|
24
|
+
case "keydown":
|
|
25
|
+
return event instanceof KeyboardEvent && SCROLL_KEYS.has(event.key) && !isEditable(event);
|
|
26
|
+
default:
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function scrollTopOf(scroller) {
|
|
31
|
+
return scroller ? scroller.scrollTop : window.scrollY;
|
|
32
|
+
}
|
|
33
|
+
class ClickPin {
|
|
34
|
+
/** `onIdle` runs when the machine hands the rail back, so the spy can re-resolve. */
|
|
35
|
+
constructor(onIdle) {
|
|
36
|
+
this.onIdle = onIdle;
|
|
37
|
+
}
|
|
38
|
+
current = { kind: "idle" };
|
|
39
|
+
stop = null;
|
|
40
|
+
get state() {
|
|
41
|
+
return this.current;
|
|
42
|
+
}
|
|
43
|
+
/** The entry the click owns (pinned or held), or `null` when the spy answers. A pure query. */
|
|
44
|
+
get activeId() {
|
|
45
|
+
return this.current.kind === "idle" ? null : this.current.id;
|
|
46
|
+
}
|
|
47
|
+
/** `link` is the rail link just activated; `scroller` the element the spy watches (`null` = document). */
|
|
48
|
+
click(id, link, scroller) {
|
|
49
|
+
this.stop?.();
|
|
50
|
+
this.current = { kind: "pinned", id };
|
|
51
|
+
const target = scroller ?? window;
|
|
52
|
+
let quiet;
|
|
53
|
+
const hold = () => {
|
|
54
|
+
clearTimeout(quiet);
|
|
55
|
+
if (this.current.kind !== "pinned") return;
|
|
56
|
+
this.current = { kind: "held", id, top: scrollTopOf(scroller) };
|
|
57
|
+
};
|
|
58
|
+
const onScroll = () => {
|
|
59
|
+
const state = this.current;
|
|
60
|
+
if (state.kind === "pinned") {
|
|
61
|
+
clearTimeout(quiet);
|
|
62
|
+
quiet = setTimeout(hold, QUIET_MS);
|
|
63
|
+
} else if (state.kind === "held" && Math.abs(scrollTopOf(scroller) - state.top) > HOLD_EPSILON_PX) {
|
|
64
|
+
this.release();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const onIntent = (event) => {
|
|
68
|
+
if (isScrollIntent(event, link)) this.release();
|
|
69
|
+
};
|
|
70
|
+
quiet = setTimeout(hold, QUIET_MS);
|
|
71
|
+
target.addEventListener("scrollend", hold, { once: true });
|
|
72
|
+
target.addEventListener("scroll", onScroll, { passive: true });
|
|
73
|
+
for (const type of INTENT_EVENTS) document.addEventListener(type, onIntent, { capture: true });
|
|
74
|
+
this.stop = () => {
|
|
75
|
+
clearTimeout(quiet);
|
|
76
|
+
target.removeEventListener("scrollend", hold);
|
|
77
|
+
target.removeEventListener("scroll", onScroll);
|
|
78
|
+
for (const type of INTENT_EVENTS) {
|
|
79
|
+
document.removeEventListener(type, onIntent, { capture: true });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Items changed: a click on an id that no longer exists cannot stand. */
|
|
84
|
+
prune(ids) {
|
|
85
|
+
if (this.current.kind !== "idle" && !ids.includes(this.current.id)) this.release();
|
|
86
|
+
}
|
|
87
|
+
release() {
|
|
88
|
+
if (this.current.kind === "idle") return;
|
|
89
|
+
this.dispose();
|
|
90
|
+
this.onIdle();
|
|
91
|
+
}
|
|
92
|
+
/** Unmount: idle, timer and listeners gone, no callback. */
|
|
93
|
+
dispose() {
|
|
94
|
+
this.stop?.();
|
|
95
|
+
this.stop = null;
|
|
96
|
+
this.current = { kind: "idle" };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function useClickPin(onIdle) {
|
|
100
|
+
const [pin] = useState(() => new ClickPin(onIdle));
|
|
101
|
+
useEffect(() => () => pin.dispose(), [pin]);
|
|
102
|
+
return pin;
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
ClickPin,
|
|
106
|
+
HOLD_EPSILON_PX,
|
|
107
|
+
INTENT_EVENTS,
|
|
108
|
+
QUIET_MS,
|
|
109
|
+
isScrollIntent,
|
|
110
|
+
useClickPin
|
|
111
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The TOC scroll-spy's pure half: scroll geometry in, the reader's section out. */
|
|
2
|
+
/** Sub-pixel / fractional-DPR slack when asking "is the scrollport at its end". */
|
|
3
|
+
export declare const BOTTOM_EPSILON_PX = 2;
|
|
4
|
+
/** Distance below the scrollport's top where a heading counts as reached (the observer's top inset). */
|
|
5
|
+
export declare const ACTIVATION_TOP_PX = 80;
|
|
6
|
+
/** The observer's band: below the activation line, down to 30% of the scrollport. */
|
|
7
|
+
export declare const OBSERVER_ROOT_MARGIN = "-80px 0px -70% 0px";
|
|
8
|
+
export type ScrollMetrics = {
|
|
9
|
+
readonly top: number;
|
|
10
|
+
readonly scrollTop: number;
|
|
11
|
+
readonly clientHeight: number;
|
|
12
|
+
readonly scrollHeight: number;
|
|
13
|
+
};
|
|
14
|
+
/** The scrollport's geometry; `null` is the document, whose "top" is the viewport's. */
|
|
15
|
+
export declare function scrollMetrics(port: HTMLElement | null): ScrollMetrics;
|
|
16
|
+
/** Is there a scroll range at all? Content that fits has no "top" or "bottom" to be at. */
|
|
17
|
+
export declare function canScroll(m: ScrollMetrics): boolean;
|
|
18
|
+
export declare function isAtBottom(m: ScrollMetrics): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The reader's section. Nothing to scroll: the first heading. At the end: the last (its section may
|
|
21
|
+
* be too short to ever reach the band). Otherwise the topmost heading inside the band, else the last
|
|
22
|
+
* heading at or above the activation line, else the first.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pickActive(elements: readonly HTMLElement[], intersecting: ReadonlySet<string>, m: ScrollMetrics): string | undefined;
|
|
25
|
+
//# sourceMappingURL=toc-spy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-spy.d.ts","sourceRoot":"","sources":["../../src/content/toc-spy.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,wGAAwG;AACxG,eAAO,MAAM,iBAAiB,KAAK,CAAA;AACnC,qFAAqF;AACrF,eAAO,MAAM,oBAAoB,uBAAyC,CAAA;AAE1E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,aAAa,CAerE;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAEnD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,EACjC,CAAC,EAAE,aAAa,GACf,MAAM,GAAG,SAAS,CAQpB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const BOTTOM_EPSILON_PX = 2;
|
|
2
|
+
const ACTIVATION_TOP_PX = 80;
|
|
3
|
+
const OBSERVER_ROOT_MARGIN = `-${ACTIVATION_TOP_PX}px 0px -70% 0px`;
|
|
4
|
+
function scrollMetrics(port) {
|
|
5
|
+
if (port) {
|
|
6
|
+
return {
|
|
7
|
+
top: port.getBoundingClientRect().top,
|
|
8
|
+
scrollTop: port.scrollTop,
|
|
9
|
+
clientHeight: port.clientHeight,
|
|
10
|
+
scrollHeight: port.scrollHeight
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
top: 0,
|
|
15
|
+
scrollTop: window.scrollY,
|
|
16
|
+
clientHeight: window.innerHeight,
|
|
17
|
+
scrollHeight: document.documentElement.scrollHeight
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function canScroll(m) {
|
|
21
|
+
return m.scrollHeight - m.clientHeight > BOTTOM_EPSILON_PX;
|
|
22
|
+
}
|
|
23
|
+
function isAtBottom(m) {
|
|
24
|
+
return canScroll(m) && m.scrollTop + m.clientHeight >= m.scrollHeight - BOTTOM_EPSILON_PX;
|
|
25
|
+
}
|
|
26
|
+
function pickActive(elements, intersecting, m) {
|
|
27
|
+
if (!canScroll(m)) return elements[0]?.id;
|
|
28
|
+
if (isAtBottom(m)) return elements[elements.length - 1]?.id;
|
|
29
|
+
const topmost = elements.find((el) => intersecting.has(el.id));
|
|
30
|
+
if (topmost) return topmost.id;
|
|
31
|
+
const line = m.top + ACTIVATION_TOP_PX;
|
|
32
|
+
const passed = elements.filter((el) => el.getBoundingClientRect().top <= line);
|
|
33
|
+
return (passed[passed.length - 1] ?? elements[0])?.id;
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
ACTIVATION_TOP_PX,
|
|
37
|
+
BOTTOM_EPSILON_PX,
|
|
38
|
+
OBSERVER_ROOT_MARGIN,
|
|
39
|
+
canScroll,
|
|
40
|
+
isAtBottom,
|
|
41
|
+
pickActive,
|
|
42
|
+
scrollMetrics
|
|
43
|
+
};
|
package/dist/content/toc.d.ts
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
* a viewport-rooted observer measures the wrong band. `null` means the document scrolls, which is
|
|
18
18
|
* the shell-less case and behaves exactly as before.
|
|
19
19
|
*
|
|
20
|
-
* The active
|
|
21
|
-
* link set that navigates within one page, rather than `"page"`/`"true"`) — both a genuine a11y fix
|
|
22
|
-
* (previously `activeId` drove `classes.active` alone, so a screen reader had no signal at all) and
|
|
23
|
-
* the one DOM-observable hook for `activeId` that does not depend on a CSS Modules class hash.
|
|
20
|
+
* The active item carries `aria-current="location"` (WAI-ARIA APG: a link set within one page).
|
|
24
21
|
*
|
|
25
22
|
* @example
|
|
26
23
|
* import { TableOfContents, headingSlug } from 'basalt-ui/content'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/content/toc.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/content/toc.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,OAAO,CAAA;AAQlD,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACrD,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAsBD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,YAAY,EACZ,MAAuB,EACvB,KAAqB,EACrB,UAAU,EACV,SAAS,GACV,EAAE,oBAAoB,sCAuItB"}
|
package/dist/content/toc.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
|
|
3
3
|
import { useReducedMotion } from "@mantine/hooks";
|
|
4
4
|
import { scrollParentOf } from "../common/scroll-parent.js";
|
|
5
5
|
import classes from "./toc.module.css";
|
|
6
|
+
import { useClickPin } from "./toc-click-pin.js";
|
|
7
|
+
import { OBSERVER_ROOT_MARGIN, pickActive, scrollMetrics } from "./toc-spy.js";
|
|
6
8
|
const DEFAULT_LEVELS = [2, 3];
|
|
7
9
|
const DEFAULT_TITLE = "On this page";
|
|
8
|
-
const CLICK_PIN_MAX_MS = 1e3;
|
|
9
10
|
function headingLabel(node) {
|
|
10
11
|
const clone = node.cloneNode(true);
|
|
11
12
|
for (const anchor of clone.querySelectorAll("[data-heading-anchor]")) anchor.remove();
|
|
@@ -31,13 +32,16 @@ function TableOfContents({
|
|
|
31
32
|
const [collected, setCollected] = useState([]);
|
|
32
33
|
const [activeId, setActiveId] = useState(null);
|
|
33
34
|
const reduceMotion = useReducedMotion();
|
|
34
|
-
const pinnedRef = useRef(null);
|
|
35
|
-
const releasePinRef = useRef(null);
|
|
36
35
|
const navRef = useRef(null);
|
|
36
|
+
const elementsRef = useRef([]);
|
|
37
37
|
const portRef = useRef(null);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const intersectingRef = useRef(/* @__PURE__ */ new Set());
|
|
39
|
+
const [idleTick, bumpIdle] = useReducer((n) => n + 1, 0);
|
|
40
|
+
const pin = useClickPin(bumpIdle);
|
|
41
|
+
const scrollerOf = useCallback(
|
|
42
|
+
() => scrollParentOf(containerRef?.current ?? navRef.current),
|
|
43
|
+
[containerRef]
|
|
44
|
+
);
|
|
41
45
|
useEffect(() => {
|
|
42
46
|
if (items !== void 0) return;
|
|
43
47
|
const container = containerRef?.current;
|
|
@@ -49,33 +53,29 @@ function TableOfContents({
|
|
|
49
53
|
return () => observer.disconnect();
|
|
50
54
|
}, [items, containerRef, levels]);
|
|
51
55
|
const resolvedItems = items ?? collected;
|
|
56
|
+
const resolve = useCallback(() => {
|
|
57
|
+
if (pin.activeId !== null) {
|
|
58
|
+
setActiveId(pin.activeId);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const id = pickActive(
|
|
62
|
+
elementsRef.current,
|
|
63
|
+
intersectingRef.current,
|
|
64
|
+
scrollMetrics(portRef.current)
|
|
65
|
+
);
|
|
66
|
+
if (id !== void 0) setActiveId(id);
|
|
67
|
+
}, [pin]);
|
|
52
68
|
useEffect(() => {
|
|
69
|
+
pin.prune(resolvedItems.map((item) => item.id));
|
|
53
70
|
if (resolvedItems.length === 0) return;
|
|
54
71
|
const elements = resolvedItems.map((item) => document.getElementById(item.id)).filter((el) => el !== null);
|
|
55
72
|
if (elements.length === 0) return;
|
|
56
|
-
const port =
|
|
57
|
-
portRef.current = port;
|
|
73
|
+
const port = scrollerOf();
|
|
58
74
|
const scroller = port ?? window;
|
|
59
|
-
const intersecting =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const seen = port ? port.clientHeight + port.scrollTop : window.innerHeight + window.scrollY;
|
|
64
|
-
if (seen >= box.scrollHeight - 2) {
|
|
65
|
-
const last = elements[elements.length - 1];
|
|
66
|
-
if (last) setActiveId(last.id);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (intersecting.size > 0) {
|
|
70
|
-
const topmost = elements.find((el) => intersecting.has(el.id));
|
|
71
|
-
if (topmost) setActiveId(topmost.id);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const originTop = port ? port.getBoundingClientRect().top : 0;
|
|
75
|
-
const passed = elements.filter((el) => el.getBoundingClientRect().top < originTop);
|
|
76
|
-
const current = passed[passed.length - 1] ?? elements[0];
|
|
77
|
-
if (current) setActiveId(current.id);
|
|
78
|
-
};
|
|
75
|
+
const intersecting = intersectingRef.current;
|
|
76
|
+
intersecting.clear();
|
|
77
|
+
elementsRef.current = elements;
|
|
78
|
+
portRef.current = port;
|
|
79
79
|
const observer = new IntersectionObserver(
|
|
80
80
|
(entries) => {
|
|
81
81
|
for (const entry of entries) {
|
|
@@ -86,38 +86,27 @@ function TableOfContents({
|
|
|
86
86
|
},
|
|
87
87
|
// `root: null` IS the viewport — the shell-less case, unchanged. Inside a shell the root has
|
|
88
88
|
// to be the scrollport or the `-70%` dead zone is measured against a box nothing scrolls.
|
|
89
|
-
{ root: port, rootMargin:
|
|
89
|
+
{ root: port, rootMargin: OBSERVER_ROOT_MARGIN }
|
|
90
90
|
);
|
|
91
91
|
for (const el of elements) observer.observe(el);
|
|
92
92
|
scroller.addEventListener("scroll", resolve, { passive: true });
|
|
93
93
|
return () => {
|
|
94
94
|
observer.disconnect();
|
|
95
95
|
scroller.removeEventListener("scroll", resolve);
|
|
96
|
-
|
|
96
|
+
elementsRef.current = [];
|
|
97
97
|
};
|
|
98
|
-
}, [resolvedItems,
|
|
98
|
+
}, [resolvedItems, scrollerOf, pin, resolve]);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const frame = requestAnimationFrame(resolve);
|
|
101
|
+
return () => cancelAnimationFrame(frame);
|
|
102
|
+
}, [idleTick, resolve]);
|
|
99
103
|
if (resolvedItems.length === 0) return null;
|
|
100
|
-
const pinActive = (id) => {
|
|
101
|
-
releasePinRef.current?.();
|
|
102
|
-
setActiveId(id);
|
|
103
|
-
pinnedRef.current = id;
|
|
104
|
-
const scroller = portRef.current ?? window;
|
|
105
|
-
let timer = null;
|
|
106
|
-
const release = () => {
|
|
107
|
-
pinnedRef.current = null;
|
|
108
|
-
if (timer !== null) clearTimeout(timer);
|
|
109
|
-
scroller.removeEventListener("scrollend", release);
|
|
110
|
-
releasePinRef.current = null;
|
|
111
|
-
};
|
|
112
|
-
timer = setTimeout(release, CLICK_PIN_MAX_MS);
|
|
113
|
-
scroller.addEventListener("scrollend", release, { once: true });
|
|
114
|
-
releasePinRef.current = release;
|
|
115
|
-
};
|
|
116
104
|
const handleClick = (id) => (event) => {
|
|
117
105
|
event.preventDefault();
|
|
118
106
|
const el = document.getElementById(id);
|
|
119
107
|
if (el) {
|
|
120
|
-
|
|
108
|
+
setActiveId(id);
|
|
109
|
+
pin.click(id, event.currentTarget, scrollerOf());
|
|
121
110
|
el.scrollIntoView({ behavior: reduceMotion ? "auto" : "smooth" });
|
|
122
111
|
history.replaceState(null, "", `#${id}`);
|
|
123
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-filter.d.ts","sourceRoot":"","sources":["../../src/controls/number-filter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"number-filter.d.ts","sourceRoot":"","sources":["../../src/controls/number-filter.tsx"],"names":[],"mappings":"AAkEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAQlD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD;6FAC6F;AAC7F,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC,CAAA;IACxC;yFACqF;IACrF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;IACzB,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB;kEAC8D;IAC9D,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAqChE"}
|
|
@@ -133,7 +133,7 @@ function NumberStepper({
|
|
|
133
133
|
return /* @__PURE__ */ jsx(
|
|
134
134
|
FilterPill,
|
|
135
135
|
{
|
|
136
|
-
label: String(value),
|
|
136
|
+
label: field.options.find((option) => option.value === String(value))?.label ?? String(value),
|
|
137
137
|
numeric: true,
|
|
138
138
|
active: !isDefault,
|
|
139
139
|
...icon !== void 0 && { icon },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { WidgetHeader } from './widget-header.js';
|
|
2
2
|
export { DeltaBadge } from './delta-badge.js';
|
|
3
3
|
export { Section } from './section.js';
|
|
4
|
-
export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize
|
|
4
|
+
export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize } from './stat-card.js';
|
|
5
5
|
export { StatGroup } from './stat-group.js';
|
|
6
6
|
export { EmptyState } from './empty-state.js';
|
|
7
7
|
export { SettingsSection, SettingsRow, DangerZone } from './settings-section.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/dashboard/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { WidgetHeader } from "./widget-header.js";
|
|
2
2
|
import { DeltaBadge } from "./delta-badge.js";
|
|
3
3
|
import { Section } from "./section.js";
|
|
4
|
-
import {
|
|
5
|
-
StatCard
|
|
6
|
-
} from "./stat-card.js";
|
|
4
|
+
import { StatCard } from "./stat-card.js";
|
|
7
5
|
import { StatGroup } from "./stat-group.js";
|
|
8
6
|
import { EmptyState } from "./empty-state.js";
|
|
9
7
|
import { SettingsSection, SettingsRow, DangerZone } from "./settings-section.js";
|
|
@@ -41,6 +41,12 @@ export type SectionProps = Omit<WidgetHeaderProps, 'tier' | 'classNames' | 'acti
|
|
|
41
41
|
/** Persists the fold state at `basalt:section:<persistKey>`. Omit for a local, unpersisted fold
|
|
42
42
|
* (`useState`). */
|
|
43
43
|
persistKey?: string;
|
|
44
|
+
/** Controlled fold state (Mantine naming). Given one, the section follows it — a click only
|
|
45
|
+
* calls `onOpenChange`, and the value is mirrored into the local/persisted fold so dropping
|
|
46
|
+
* `open` keeps what the reader last saw. Omit for the uncontrolled, optionally persisted fold. */
|
|
47
|
+
open?: boolean;
|
|
48
|
+
/** Called with the next fold state on every toggle, controlled or not. */
|
|
49
|
+
onOpenChange?: (open: boolean) => void;
|
|
44
50
|
/** The fold state a section opens on, respected only while no persisted value exists — a section
|
|
45
51
|
* a reader has closed stays closed. `false` is what a long secondary block wants. @default true */
|
|
46
52
|
defaultOpen?: boolean;
|
|
@@ -48,9 +54,11 @@ export type SectionProps = Omit<WidgetHeaderProps, 'tier' | 'classNames' | 'acti
|
|
|
48
54
|
* still states its headline figures, which is what makes collapsing it a real option. Keep it to
|
|
49
55
|
* one row — the body is what `children` is for. */
|
|
50
56
|
summary?: ReactNode;
|
|
51
|
-
/** Turns the root into a scroll anchor (`id` + `scroll-margin-top`
|
|
57
|
+
/** Turns the root into a scroll anchor (`id` + `scroll-margin-top`). Inside `BasaltShell` the
|
|
58
|
+
* offset is the clearance token; without a shell it also clears `PageBar`, which assumes the
|
|
59
|
+
* document is the scrollport. */
|
|
52
60
|
id?: string;
|
|
53
61
|
children: ReactNode;
|
|
54
62
|
};
|
|
55
|
-
export declare function Section({ actions, query, empty, tabs, collapsible, persistKey, defaultOpen, summary, id, children, className, style, classNames, ...headerProps }: SectionProps): import("react").JSX.Element;
|
|
63
|
+
export declare function Section({ actions, query, empty, tabs, collapsible, persistKey, defaultOpen, open: openProp, onOpenChange, summary, id, children, className, style, classNames, ...headerProps }: SectionProps): import("react").JSX.Element;
|
|
56
64
|
//# sourceMappingURL=section.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../src/dashboard/section.tsx"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../src/dashboard/section.tsx"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGxD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAA;AAMpD,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC,GACnF,WAAW,GACX,eAAe,CAAC,WAAW,CAAC,GAAG;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC/B;;;;OAIG;IACH,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,gGAAgG;IAChG,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;8CAC0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;uBACmB;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;sGAEkG;IAClG,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,0EAA0E;IAC1E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC;uGACmG;IACnG,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;uDAEmD;IACnD,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB;;qCAEiC;IACjC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,SAAS,CAAA;CACpB,CAAA;AA6CH,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,KAAK,EACL,KAAK,EACL,IAAI,EACJ,WAAmB,EACnB,UAAU,EACV,WAAkB,EAClB,IAAI,EAAE,QAAQ,EACd,YAAY,EACZ,OAAO,EACP,EAAE,EACF,QAAQ,EACR,SAAS,EACT,KAAK,EACL,UAAU,EACV,GAAG,WAAW,EACf,EAAE,YAAY,+BAmGd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useId } from "react";
|
|
2
|
+
import { useEffect, useId } from "react";
|
|
3
3
|
import { cx } from "../common/props.js";
|
|
4
4
|
import { BASALT_PREFIX } from "../common/errors.js";
|
|
5
5
|
import { useValidateProps } from "../common/validate.js";
|
|
@@ -8,6 +8,7 @@ import { BarActionSlot } from "../controls/actions.js";
|
|
|
8
8
|
import { useFilterSurface } from "../controls/filter-context.js";
|
|
9
9
|
import { QueryState } from "./query-state.js";
|
|
10
10
|
import { usePersistedOrLocal } from "../state/persisted-or-local.js";
|
|
11
|
+
import { PAGE_BAR_HEIGHT_VAR, useInPageBarShell } from "../shell/index.js";
|
|
11
12
|
import { WidgetHeader } from "./widget-header.js";
|
|
12
13
|
import classes from "./section.module.css";
|
|
13
14
|
function ChevronToggle({
|
|
@@ -42,6 +43,11 @@ function ChevronToggle({
|
|
|
42
43
|
}
|
|
43
44
|
);
|
|
44
45
|
}
|
|
46
|
+
const ANCHOR_CLEARANCE = "var(--vx-space-sticky-header-clearance)";
|
|
47
|
+
function anchorOffset(inShell) {
|
|
48
|
+
if (inShell) return ANCHOR_CLEARANCE;
|
|
49
|
+
return `calc(var(${PAGE_BAR_HEIGHT_VAR}, 0px) + ${ANCHOR_CLEARANCE})`;
|
|
50
|
+
}
|
|
45
51
|
function Section({
|
|
46
52
|
actions,
|
|
47
53
|
query,
|
|
@@ -50,6 +56,8 @@ function Section({
|
|
|
50
56
|
collapsible = false,
|
|
51
57
|
persistKey,
|
|
52
58
|
defaultOpen = true,
|
|
59
|
+
open: openProp,
|
|
60
|
+
onOpenChange,
|
|
53
61
|
summary,
|
|
54
62
|
id,
|
|
55
63
|
children,
|
|
@@ -66,14 +74,23 @@ function Section({
|
|
|
66
74
|
],
|
|
67
75
|
[persistKey, collapsible, title]
|
|
68
76
|
);
|
|
69
|
-
const [
|
|
77
|
+
const [stateOpen, setStateOpen] = usePersistedOrLocal({
|
|
70
78
|
scope: "section",
|
|
71
79
|
persistKey,
|
|
72
80
|
initial: defaultOpen
|
|
73
81
|
});
|
|
82
|
+
const open = openProp ?? stateOpen;
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (openProp !== void 0 && openProp !== stateOpen) setStateOpen(openProp);
|
|
85
|
+
}, [openProp, stateOpen, setStateOpen]);
|
|
86
|
+
const setOpen = (next) => {
|
|
87
|
+
if (openProp === void 0) setStateOpen(next);
|
|
88
|
+
onOpenChange?.(next);
|
|
89
|
+
};
|
|
74
90
|
const bodyId = useId();
|
|
75
91
|
const tier = useFilterSurface() === "pill" ? "section" : "group";
|
|
76
|
-
const
|
|
92
|
+
const inShell = useInPageBarShell();
|
|
93
|
+
const anchorStyle = id === void 0 ? void 0 : { scrollMarginTop: anchorOffset(inShell) };
|
|
77
94
|
const rootStyle = anchorStyle === void 0 && style === void 0 ? void 0 : { ...anchorStyle, ...style };
|
|
78
95
|
const headerActions = tabs !== void 0 || actions !== void 0 || collapsible ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
79
96
|
tabs !== void 0 && open && /* @__PURE__ */ jsx(CtlSlot, { children: tabs }),
|
|
@@ -2,12 +2,6 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import type { WidgetHeaderDeltaProps, WidgetHeaderMetricProps, WidgetHeaderTitleProps } from './widget-header.js';
|
|
3
3
|
import type { BasaltProps, SlotStylesProps, Tone } from '../common/props.js';
|
|
4
4
|
import type { QueryStateLike } from './query-state.js';
|
|
5
|
-
/**
|
|
6
|
-
* A threshold verdict on the card's value. `undefined` is never tinted — see the module docblock.
|
|
7
|
-
* Alias of the common `Tone` vocabulary (audit A13) — byte-identical, kept as its own name so a
|
|
8
|
-
* consumer's existing `StatCardTone` reference never breaks.
|
|
9
|
-
*/
|
|
10
|
-
export type StatCardTone = Tone;
|
|
11
5
|
/**
|
|
12
6
|
* The four boxes `StatCard` paints, and the whole styling seam it offers (`common/props.ts`).
|
|
13
7
|
* `value` is not its own slot: the hero number is painted by `WidgetHeader`'s internal metrics row,
|
|
@@ -25,7 +19,7 @@ export type StatCardSlot = 'root' | 'header' | 'body' | 'sparkline';
|
|
|
25
19
|
export type StatCardBreakdownRow = {
|
|
26
20
|
readonly label: string;
|
|
27
21
|
readonly value: string;
|
|
28
|
-
readonly tone?:
|
|
22
|
+
readonly tone?: Tone;
|
|
29
23
|
};
|
|
30
24
|
/**
|
|
31
25
|
* The measured box a `sparkline` render prop receives.
|
|
@@ -126,7 +120,7 @@ export type StatCardProps = BasaltProps & SlotStylesProps<StatCardSlot> & Widget
|
|
|
126
120
|
* assistive tech. Omitting it is NOT `'good'`: omitted covers a reading that is fine AND one that
|
|
127
121
|
* is absent, and stays untinted so a card with nothing measured can never render green. Pass
|
|
128
122
|
* `'good'` only to assert a measured value that has earned the verdict. */
|
|
129
|
-
tone?:
|
|
123
|
+
tone?: Tone;
|
|
130
124
|
};
|
|
131
125
|
export declare function StatCard({ title, icon, subtitle, info, value, unit, breakdown, query, delta, deltaPeriod, deltaPolarity, deltaFormat, deltaGlyph, sparkline, sparklinePlacement, actions, tone, className, style, classNames, }: StatCardProps): import("react").JSX.Element;
|
|
132
126
|
//# sourceMappingURL=stat-card.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stat-card.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-card.tsx"],"names":[],"mappings":"AAiGA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"stat-card.d.ts","sourceRoot":"","sources":["../../src/dashboard/stat-card.tsx"],"names":[],"mappings":"AAiGA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAInD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAA;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA;CACrB,CAAA;AAcD;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAChE,CAAA;AA6DD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GACrC,eAAe,CAAC,YAAY,CAAC,GAC7B,sBAAsB,GACtB,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,GACtC,sBAAsB,GAAG;IACvB;iEAC6D;IAC7D,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAA;IAC3C;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC/B;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,qBAAqB,KAAK,SAAS,CAAC,CAAA;IACpE;4GACwG;IACxG,kBAAkB,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;IACtC;mGAC+F;IAC/F,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB;;;+EAG2E;IAC3E,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AAEH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,EACL,KAAK,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,kBAA4B,EAC5B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,GACX,EAAE,aAAa,+BA0Kf"}
|
|
@@ -159,7 +159,7 @@ function StatCard({
|
|
|
159
159
|
insetBlock: 0,
|
|
160
160
|
insetInlineStart: 0,
|
|
161
161
|
width: TONE_RAIL_WIDTH,
|
|
162
|
-
// `
|
|
162
|
+
// `Tone`'s members are `VX.status` keys by construction, so the rail reads the
|
|
163
163
|
// per-scheme `--vx-status-*` solid directly — never a hex, so it re-resolves in both
|
|
164
164
|
// schemes and under a consumer's `derive` retune. Contrast against
|
|
165
165
|
// `--vx-surface-panel` is measured in `theme/contrast.test.ts`.
|