macbetter 0.0.0-stage → 0.1.0-beta.2
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/LICENSE +201 -0
- package/README.md +92 -2
- package/dist/components/accessory-tile.d.ts +50 -0
- package/dist/components/accessory-tile.js +46 -0
- package/dist/components/activity-indicator.d.ts +15 -0
- package/dist/components/activity-indicator.js +15 -0
- package/dist/components/alert.d.ts +29 -0
- package/dist/components/alert.js +30 -0
- package/dist/components/artifact-card.d.ts +41 -0
- package/dist/components/artifact-card.js +57 -0
- package/dist/components/artwork.d.ts +44 -0
- package/dist/components/artwork.js +935 -0
- package/dist/components/attachment.d.ts +48 -0
- package/dist/components/attachment.js +65 -0
- package/dist/components/automation-row.d.ts +24 -0
- package/dist/components/automation-row.js +12 -0
- package/dist/components/avatar.d.ts +33 -0
- package/dist/components/avatar.js +45 -0
- package/dist/components/badge.d.ts +24 -0
- package/dist/components/badge.js +19 -0
- package/dist/components/button.d.ts +20 -0
- package/dist/components/button.js +10 -0
- package/dist/components/calendar.d.ts +30 -0
- package/dist/components/calendar.js +47 -0
- package/dist/components/camera-view.d.ts +40 -0
- package/dist/components/camera-view.js +44 -0
- package/dist/components/card.d.ts +14 -0
- package/dist/components/card.js +21 -0
- package/dist/components/carousel.d.ts +18 -0
- package/dist/components/carousel.js +33 -0
- package/dist/components/chat.d.ts +29 -0
- package/dist/components/chat.js +29 -0
- package/dist/components/checkbox.d.ts +13 -0
- package/dist/components/checkbox.js +16 -0
- package/dist/components/code-block.d.ts +39 -0
- package/dist/components/code-block.js +65 -0
- package/dist/components/code-field.d.ts +16 -0
- package/dist/components/code-field.js +29 -0
- package/dist/components/color-well.d.ts +23 -0
- package/dist/components/color-well.js +27 -0
- package/dist/components/combo-box.d.ts +42 -0
- package/dist/components/combo-box.js +102 -0
- package/dist/components/command-palette.d.ts +33 -0
- package/dist/components/command-palette.js +55 -0
- package/dist/components/confirmation.d.ts +24 -0
- package/dist/components/confirmation.js +50 -0
- package/dist/components/content-unavailable.d.ts +19 -0
- package/dist/components/content-unavailable.js +21 -0
- package/dist/components/context-menu.d.ts +9 -0
- package/dist/components/context-menu.js +15 -0
- package/dist/components/date-picker.d.ts +53 -0
- package/dist/components/date-picker.js +86 -0
- package/dist/components/description-list.d.ts +18 -0
- package/dist/components/description-list.js +17 -0
- package/dist/components/device-frame.d.ts +18 -0
- package/dist/components/device-frame.js +16 -0
- package/dist/components/dialog.d.ts +27 -0
- package/dist/components/dialog.js +35 -0
- package/dist/components/disclosure.d.ts +32 -0
- package/dist/components/disclosure.js +35 -0
- package/dist/components/dock.d.ts +28 -0
- package/dist/components/dock.js +80 -0
- package/dist/components/door-control.d.ts +20 -0
- package/dist/components/door-control.js +43 -0
- package/dist/components/energy-readout.d.ts +32 -0
- package/dist/components/energy-readout.js +27 -0
- package/dist/components/field.d.ts +28 -0
- package/dist/components/field.js +32 -0
- package/dist/components/gauge.d.ts +25 -0
- package/dist/components/gauge.js +42 -0
- package/dist/components/generated-image.d.ts +39 -0
- package/dist/components/generated-image.js +47 -0
- package/dist/components/glass.d.ts +34 -0
- package/dist/components/glass.js +31 -0
- package/dist/components/home-backdrop.d.ts +23 -0
- package/dist/components/home-backdrop.js +12 -0
- package/dist/components/home-section.d.ts +19 -0
- package/dist/components/home-section.js +21 -0
- package/dist/components/home-status.d.ts +24 -0
- package/dist/components/home-status.js +14 -0
- package/dist/components/hover-card.d.ts +14 -0
- package/dist/components/hover-card.js +16 -0
- package/dist/components/inspector.d.ts +29 -0
- package/dist/components/inspector.js +40 -0
- package/dist/components/level-control.d.ts +19 -0
- package/dist/components/level-control.js +13 -0
- package/dist/components/light-color-picker.d.ts +33 -0
- package/dist/components/light-color-picker.js +56 -0
- package/dist/components/list.d.ts +42 -0
- package/dist/components/list.js +42 -0
- package/dist/components/listbox.d.ts +16 -0
- package/dist/components/listbox.js +28 -0
- package/dist/components/lock-control.d.ts +20 -0
- package/dist/components/lock-control.js +35 -0
- package/dist/components/menu-bar.d.ts +14 -0
- package/dist/components/menu-bar.js +16 -0
- package/dist/components/menu.d.ts +40 -0
- package/dist/components/menu.js +54 -0
- package/dist/components/message.d.ts +65 -0
- package/dist/components/message.js +69 -0
- package/dist/components/model-picker.d.ts +61 -0
- package/dist/components/model-picker.js +59 -0
- package/dist/components/navigation-bar.d.ts +24 -0
- package/dist/components/navigation-bar.js +54 -0
- package/dist/components/outline.d.ts +21 -0
- package/dist/components/outline.js +40 -0
- package/dist/components/page-control.d.ts +10 -0
- package/dist/components/page-control.js +8 -0
- package/dist/components/plan.d.ts +25 -0
- package/dist/components/plan.js +43 -0
- package/dist/components/popover.d.ts +16 -0
- package/dist/components/popover.js +24 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +27 -0
- package/dist/components/prompt-input.d.ts +93 -0
- package/dist/components/prompt-input.js +172 -0
- package/dist/components/radio.d.ts +16 -0
- package/dist/components/radio.js +13 -0
- package/dist/components/rating.d.ts +10 -0
- package/dist/components/rating.js +12 -0
- package/dist/components/reasoning.d.ts +28 -0
- package/dist/components/reasoning.js +52 -0
- package/dist/components/response.d.ts +14 -0
- package/dist/components/response.js +14 -0
- package/dist/components/scene-tile.d.ts +22 -0
- package/dist/components/scene-tile.js +13 -0
- package/dist/components/scroll-view.d.ts +21 -0
- package/dist/components/scroll-view.js +13 -0
- package/dist/components/search-field.d.ts +16 -0
- package/dist/components/search-field.js +12 -0
- package/dist/components/secure-field.d.ts +23 -0
- package/dist/components/secure-field.js +21 -0
- package/dist/components/segmented-control.d.ts +12 -0
- package/dist/components/segmented-control.js +10 -0
- package/dist/components/select.d.ts +45 -0
- package/dist/components/select.js +79 -0
- package/dist/components/sensor-readout.d.ts +29 -0
- package/dist/components/sensor-readout.js +12 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +11 -0
- package/dist/components/setup-code.d.ts +29 -0
- package/dist/components/setup-code.js +47 -0
- package/dist/components/sheet.d.ts +31 -0
- package/dist/components/sheet.js +51 -0
- package/dist/components/shimmer.d.ts +18 -0
- package/dist/components/shimmer.js +17 -0
- package/dist/components/sidebar.d.ts +30 -0
- package/dist/components/sidebar.js +26 -0
- package/dist/components/slider.d.ts +27 -0
- package/dist/components/slider.js +43 -0
- package/dist/components/sources.d.ts +51 -0
- package/dist/components/sources.js +46 -0
- package/dist/components/split-view.d.ts +11 -0
- package/dist/components/split-view.js +13 -0
- package/dist/components/squircle.d.ts +41 -0
- package/dist/components/squircle.js +63 -0
- package/dist/components/stepper.d.ts +30 -0
- package/dist/components/stepper.js +28 -0
- package/dist/components/suggestion.d.ts +23 -0
- package/dist/components/suggestion.js +29 -0
- package/dist/components/switch.d.ts +10 -0
- package/dist/components/switch.js +10 -0
- package/dist/components/tab-bar.d.ts +20 -0
- package/dist/components/tab-bar.js +17 -0
- package/dist/components/table.d.ts +49 -0
- package/dist/components/table.js +179 -0
- package/dist/components/tabs.d.ts +16 -0
- package/dist/components/tabs.js +19 -0
- package/dist/components/text-area.d.ts +14 -0
- package/dist/components/text-area.js +9 -0
- package/dist/components/text-field.d.ts +26 -0
- package/dist/components/text-field.js +23 -0
- package/dist/components/thermostat-control.d.ts +30 -0
- package/dist/components/thermostat-control.js +139 -0
- package/dist/components/toast.d.ts +30 -0
- package/dist/components/toast.js +114 -0
- package/dist/components/toggle.d.ts +21 -0
- package/dist/components/toggle.js +19 -0
- package/dist/components/token-field.d.ts +31 -0
- package/dist/components/token-field.js +78 -0
- package/dist/components/tool-call.d.ts +48 -0
- package/dist/components/tool-call.js +77 -0
- package/dist/components/toolbar.d.ts +27 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/components/tooltip.js +18 -0
- package/dist/components/window.d.ts +56 -0
- package/dist/components/window.js +61 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +98 -0
- package/dist/lib/agent-glyphs.d.ts +10 -0
- package/dist/lib/agent-glyphs.js +19 -0
- package/dist/lib/cx.d.ts +9 -0
- package/dist/lib/cx.js +14 -0
- package/dist/lib/derive.d.ts +53 -0
- package/dist/lib/derive.js +255 -0
- package/dist/lib/field-glyphs.d.ts +13 -0
- package/dist/lib/field-glyphs.js +28 -0
- package/dist/lib/menu-glyphs.d.ts +6 -0
- package/dist/lib/menu-glyphs.js +15 -0
- package/dist/lib/platform.d.ts +18 -0
- package/dist/lib/platform.js +17 -0
- package/dist/lib/squircle.d.ts +23 -0
- package/dist/lib/squircle.js +69 -0
- package/dist/lib/theme.d.ts +42 -0
- package/dist/lib/theme.js +62 -0
- package/dist/styles/base.css +115 -0
- package/dist/styles/components/accessory-tile.css +461 -0
- package/dist/styles/components/activity-indicator.css +63 -0
- package/dist/styles/components/alert.css +433 -0
- package/dist/styles/components/artifact-card.css +238 -0
- package/dist/styles/components/artwork.css +380 -0
- package/dist/styles/components/attachment.css +540 -0
- package/dist/styles/components/automation-row.css +52 -0
- package/dist/styles/components/avatar.css +230 -0
- package/dist/styles/components/badge.css +204 -0
- package/dist/styles/components/button.css +298 -0
- package/dist/styles/components/calendar.css +287 -0
- package/dist/styles/components/camera-view.css +239 -0
- package/dist/styles/components/card.css +100 -0
- package/dist/styles/components/carousel.css +210 -0
- package/dist/styles/components/chat.css +209 -0
- package/dist/styles/components/checkbox.css +212 -0
- package/dist/styles/components/code-block.css +162 -0
- package/dist/styles/components/code-field.css +163 -0
- package/dist/styles/components/color-well.css +452 -0
- package/dist/styles/components/combo-box.css +222 -0
- package/dist/styles/components/command-palette.css +379 -0
- package/dist/styles/components/confirmation.css +189 -0
- package/dist/styles/components/content-unavailable.css +105 -0
- package/dist/styles/components/context-menu.css +43 -0
- package/dist/styles/components/date-picker.css +356 -0
- package/dist/styles/components/description-list.css +92 -0
- package/dist/styles/components/device-frame.css +202 -0
- package/dist/styles/components/dialog.css +366 -0
- package/dist/styles/components/disclosure.css +197 -0
- package/dist/styles/components/dock.css +404 -0
- package/dist/styles/components/door-control.css +187 -0
- package/dist/styles/components/energy-readout.css +161 -0
- package/dist/styles/components/field.css +175 -0
- package/dist/styles/components/gauge.css +239 -0
- package/dist/styles/components/generated-image.css +248 -0
- package/dist/styles/components/glass.css +113 -0
- package/dist/styles/components/home-backdrop.css +81 -0
- package/dist/styles/components/home-section.css +100 -0
- package/dist/styles/components/home-status.css +215 -0
- package/dist/styles/components/hover-card.css +145 -0
- package/dist/styles/components/index.css +94 -0
- package/dist/styles/components/inspector.css +236 -0
- package/dist/styles/components/level-control.css +247 -0
- package/dist/styles/components/light-color-picker.css +94 -0
- package/dist/styles/components/list.css +411 -0
- package/dist/styles/components/listbox.css +168 -0
- package/dist/styles/components/lock-control.css +164 -0
- package/dist/styles/components/menu-bar.css +94 -0
- package/dist/styles/components/menu.css +454 -0
- package/dist/styles/components/message.css +236 -0
- package/dist/styles/components/model-picker.css +64 -0
- package/dist/styles/components/navigation-bar.css +249 -0
- package/dist/styles/components/outline.css +248 -0
- package/dist/styles/components/page-control.css +127 -0
- package/dist/styles/components/plan.css +212 -0
- package/dist/styles/components/popover.css +186 -0
- package/dist/styles/components/progress.css +228 -0
- package/dist/styles/components/prompt-input.css +503 -0
- package/dist/styles/components/radio.css +281 -0
- package/dist/styles/components/rating.css +122 -0
- package/dist/styles/components/reasoning.css +214 -0
- package/dist/styles/components/response.css +303 -0
- package/dist/styles/components/scene-tile.css +295 -0
- package/dist/styles/components/scroll-view.css +195 -0
- package/dist/styles/components/search-field.css +128 -0
- package/dist/styles/components/secure-field.css +189 -0
- package/dist/styles/components/segmented-control.css +183 -0
- package/dist/styles/components/select.css +290 -0
- package/dist/styles/components/sensor-readout.css +231 -0
- package/dist/styles/components/separator.css +62 -0
- package/dist/styles/components/setup-code.css +138 -0
- package/dist/styles/components/sheet.css +345 -0
- package/dist/styles/components/shimmer.css +60 -0
- package/dist/styles/components/sidebar.css +261 -0
- package/dist/styles/components/slider.css +208 -0
- package/dist/styles/components/sources.css +349 -0
- package/dist/styles/components/split-view.css +75 -0
- package/dist/styles/components/squircle.css +44 -0
- package/dist/styles/components/stepper.css +278 -0
- package/dist/styles/components/suggestion.css +203 -0
- package/dist/styles/components/switch.css +115 -0
- package/dist/styles/components/tab-bar.css +223 -0
- package/dist/styles/components/table.css +313 -0
- package/dist/styles/components/tabs.css +262 -0
- package/dist/styles/components/text-area.css +94 -0
- package/dist/styles/components/text-field.css +294 -0
- package/dist/styles/components/thermostat-control.css +214 -0
- package/dist/styles/components/toast.css +418 -0
- package/dist/styles/components/toggle.css +312 -0
- package/dist/styles/components/token-field.css +193 -0
- package/dist/styles/components/tool-call.css +391 -0
- package/dist/styles/components/toolbar.css +370 -0
- package/dist/styles/components/tooltip.css +69 -0
- package/dist/styles/components/window.css +428 -0
- package/dist/styles/index.css +17 -0
- package/dist/styles/materials.css +263 -0
- package/dist/styles/platforms.css +214 -0
- package/dist/styles/themes/ember.css +24 -0
- package/dist/styles/themes/graphite.css +16 -0
- package/dist/styles/themes/nebula.css +16 -0
- package/dist/styles/themes/system.css +28 -0
- package/dist/styles/tokens.css +299 -0
- package/package.json +82 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type ThermostatMode = "off" | "heat" | "cool" | "auto";
|
|
3
|
+
type ThermostatState = "idle" | "heating" | "cooling";
|
|
4
|
+
type ThermostatControlProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
5
|
+
mode: ThermostatMode;
|
|
6
|
+
onModeChange?: (mode: ThermostatMode) => void;
|
|
7
|
+
/** The target in degrees Celsius, as HomeKit stores it. Used in heat and cool. */
|
|
8
|
+
target?: number;
|
|
9
|
+
onTargetChange?: (celsius: number) => void;
|
|
10
|
+
/** Heating and cooling thresholds in degrees Celsius, used in auto. */
|
|
11
|
+
range?: [number, number];
|
|
12
|
+
onRangeChange?: (celsius: [number, number]) => void;
|
|
13
|
+
/** The measured temperature, in degrees Celsius. */
|
|
14
|
+
current: number;
|
|
15
|
+
/** What the system is doing now, from HomeKit's current heating cooling state. */
|
|
16
|
+
state?: ThermostatState;
|
|
17
|
+
/** How temperatures read. Values in and out stay in Celsius. */
|
|
18
|
+
unit?: "celsius" | "fahrenheit";
|
|
19
|
+
min?: number;
|
|
20
|
+
max?: number;
|
|
21
|
+
/** One step, in the display unit. Defaults to 0.5 °C or 1 °F. */
|
|
22
|
+
step?: number;
|
|
23
|
+
/** Names the control, like "Hallway thermostat". */
|
|
24
|
+
name?: string;
|
|
25
|
+
modes?: ThermostatMode[];
|
|
26
|
+
hideModes?: boolean;
|
|
27
|
+
};
|
|
28
|
+
declare function ThermostatControl({ mode, onModeChange, target, onTargetChange, range, onRangeChange, current, state, unit, min, max, step, name, modes, hideModes, className, ...props }: ThermostatControlProps): React.JSX.Element;
|
|
29
|
+
export { ThermostatControl };
|
|
30
|
+
export type { ThermostatControlProps, ThermostatMode, ThermostatState };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Client-only: it keeps the dial in step with the slider and maps pointer angles to values.
|
|
4
|
+
import { createSliderController, Slider as SliderPrimitive, SliderControl as SliderControlPrimitive, SliderThumb as SliderThumbPrimitive, SliderTrack as SliderTrackPrimitive, } from "@ui-sdk/react/slider";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { join } from "../lib/cx.js";
|
|
7
|
+
import { SegmentedControl, SegmentedControlItem } from "./segmented-control.js";
|
|
8
|
+
const MODE_LABELS = { off: "Off", heat: "Heat", cool: "Cool", auto: "Auto" };
|
|
9
|
+
// The dial runs 270°, clockwise from the lower left, leaving the gap at the bottom.
|
|
10
|
+
const START = 135;
|
|
11
|
+
const SWEEP = 270;
|
|
12
|
+
const SIZE = 240;
|
|
13
|
+
const CENTER = SIZE / 2;
|
|
14
|
+
const RADIUS = 100;
|
|
15
|
+
function polar(angle, radius = RADIUS) {
|
|
16
|
+
const rad = (angle * Math.PI) / 180;
|
|
17
|
+
return { x: CENTER + radius * Math.cos(rad), y: CENTER + radius * Math.sin(rad) };
|
|
18
|
+
}
|
|
19
|
+
function arc(from, to) {
|
|
20
|
+
const a = polar(START + SWEEP * from);
|
|
21
|
+
const b = polar(START + SWEEP * Math.max(to, from + 0.0001));
|
|
22
|
+
const large = SWEEP * (to - from) > 180 ? 1 : 0;
|
|
23
|
+
return `M${a.x.toFixed(2)} ${a.y.toFixed(2)}A${RADIUS} ${RADIUS} 0 ${large} 1 ${b.x.toFixed(2)} ${b.y.toFixed(2)}`;
|
|
24
|
+
}
|
|
25
|
+
const toF = (c) => (c * 9) / 5 + 32;
|
|
26
|
+
const toC = (f) => ((f - 32) * 5) / 9;
|
|
27
|
+
function ThermostatControl({ mode, onModeChange, target = 21, onTargetChange, range = [19, 24], onRangeChange, current, state = "idle", unit = "celsius", min = 10, max = 32, step, name = "Thermostat", modes = ["off", "heat", "cool", "auto"], hideModes, className, ...props }) {
|
|
28
|
+
const fahrenheit = unit === "fahrenheit";
|
|
29
|
+
const unitStep = step ?? (fahrenheit ? 1 : 0.5);
|
|
30
|
+
const snap = (value) => Math.round(value / unitStep) * unitStep;
|
|
31
|
+
const toDisplay = (c) => snap(fahrenheit ? toF(c) : c);
|
|
32
|
+
const fromDisplay = (d) => Math.round((fahrenheit ? toC(d) : d) * 100) / 100;
|
|
33
|
+
const lo = toDisplay(min);
|
|
34
|
+
const hi = toDisplay(max);
|
|
35
|
+
const gap = unitStep * (fahrenheit ? 3 : 2);
|
|
36
|
+
// Follows the props, and moves on its own when nobody controls it.
|
|
37
|
+
const [inner, setInner] = React.useState({ mode, target, range });
|
|
38
|
+
React.useEffect(() => setInner((s) => ({ ...s, mode })), [mode]);
|
|
39
|
+
React.useEffect(() => setInner((s) => ({ ...s, target })), [target]);
|
|
40
|
+
const [r0, r1] = range;
|
|
41
|
+
React.useEffect(() => setInner((s) => ({ ...s, range: [r0, r1] })), [r0, r1]);
|
|
42
|
+
const activeMode = inner.mode;
|
|
43
|
+
const auto = activeMode === "auto";
|
|
44
|
+
const off = activeMode === "off";
|
|
45
|
+
const value = auto
|
|
46
|
+
? [toDisplay(inner.range[0]), toDisplay(inner.range[1])]
|
|
47
|
+
: toDisplay(inner.target);
|
|
48
|
+
const values = Array.isArray(value) ? value : [value];
|
|
49
|
+
const fraction = (d) => Math.min(1, Math.max(0, (d - lo) / (hi - lo)));
|
|
50
|
+
const [controller] = React.useState(() => createSliderController());
|
|
51
|
+
const drag = React.useRef(null);
|
|
52
|
+
const setDisplay = (next) => {
|
|
53
|
+
if (Array.isArray(next)) {
|
|
54
|
+
const celsius = [fromDisplay(next[0]), fromDisplay(next[1])];
|
|
55
|
+
setInner((s) => ({ ...s, range: celsius }));
|
|
56
|
+
onRangeChange?.(celsius);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const celsius = fromDisplay(next);
|
|
60
|
+
setInner((s) => ({ ...s, target: celsius }));
|
|
61
|
+
onTargetChange?.(celsius);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const valueAt = (event) => {
|
|
65
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
66
|
+
const x = ((event.clientX - box.left) / box.width) * SIZE - CENTER;
|
|
67
|
+
const y = ((event.clientY - box.top) / box.height) * SIZE - CENTER;
|
|
68
|
+
let angle = ((Math.atan2(y, x) * 180) / Math.PI - START + 720) % 360;
|
|
69
|
+
if (angle > SWEEP)
|
|
70
|
+
angle = angle > SWEEP + (360 - SWEEP) / 2 ? 0 : SWEEP;
|
|
71
|
+
return snap(lo + (angle / SWEEP) * (hi - lo));
|
|
72
|
+
};
|
|
73
|
+
const moveTo = (event, thumb) => {
|
|
74
|
+
const d = valueAt(event);
|
|
75
|
+
if (!auto) {
|
|
76
|
+
controller.setValue(d, { reason: "drag", event: event.nativeEvent });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const [heat, cool] = values;
|
|
80
|
+
const next = thumb === 0 ? [Math.min(d, cool - gap), cool] : [heat, Math.max(d, heat + gap)];
|
|
81
|
+
controller.setValue(next, { reason: "drag", event: event.nativeEvent });
|
|
82
|
+
};
|
|
83
|
+
const onPointerDown = (event) => {
|
|
84
|
+
if (off || event.button !== 0)
|
|
85
|
+
return;
|
|
86
|
+
const d = valueAt(event);
|
|
87
|
+
const thumb = auto ? (Math.abs(d - values[0]) <= Math.abs(d - values[1]) ? 0 : 1) : 0;
|
|
88
|
+
drag.current = thumb;
|
|
89
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
controller.focus(thumb);
|
|
92
|
+
moveTo(event, thumb);
|
|
93
|
+
};
|
|
94
|
+
const format = (d) => `${d.toLocaleString(undefined, { maximumFractionDigits: fahrenheit ? 0 : 1 })}°`;
|
|
95
|
+
const now = toDisplay(current);
|
|
96
|
+
const caption = off
|
|
97
|
+
? "Currently"
|
|
98
|
+
: auto
|
|
99
|
+
? state === "heating"
|
|
100
|
+
? "Heating"
|
|
101
|
+
: state === "cooling"
|
|
102
|
+
? "Cooling"
|
|
103
|
+
: "Auto"
|
|
104
|
+
: activeMode === "heat"
|
|
105
|
+
? state === "heating"
|
|
106
|
+
? "Heating to"
|
|
107
|
+
: "Heat to"
|
|
108
|
+
: state === "cooling"
|
|
109
|
+
? "Cooling to"
|
|
110
|
+
: "Cool to";
|
|
111
|
+
const big = off ? format(now) : auto ? `${format(values[0]).slice(0, -1)}–${format(values[1])}` : format(values[0]);
|
|
112
|
+
const footer = off ? "Off" : `Currently ${format(now)}`;
|
|
113
|
+
const status = state === "heating" ? "Heating" : state === "cooling" ? "Cooling" : "Idle";
|
|
114
|
+
const nowAngle = START + SWEEP * fraction(now);
|
|
115
|
+
const tickIn = polar(nowAngle, RADIUS - 15);
|
|
116
|
+
const tickOut = polar(nowAngle, RADIUS + 15);
|
|
117
|
+
const [f0, f1] = [fraction(values[0]), fraction(values[values.length - 1])];
|
|
118
|
+
const middle = (f0 + f1) / 2;
|
|
119
|
+
return (_jsxs("div", { "data-mode": activeMode, "data-state": off ? undefined : state, className: join("mb-thermostat-control", className), ...props, children: [_jsxs("div", { className: "mb-thermostat-control-dial", children: [_jsxs("svg", { viewBox: `0 0 ${SIZE} ${SIZE}`, "aria-hidden": "true", className: "mb-thermostat-control-svg", onPointerDown: onPointerDown, onPointerMove: (event) => {
|
|
120
|
+
if (drag.current !== null)
|
|
121
|
+
moveTo(event, drag.current);
|
|
122
|
+
}, onPointerUp: () => {
|
|
123
|
+
drag.current = null;
|
|
124
|
+
}, onPointerCancel: () => {
|
|
125
|
+
drag.current = null;
|
|
126
|
+
}, children: [_jsx("path", { d: arc(0, 1), className: "mb-thermostat-control-track" }), off ? null : auto ? (_jsxs(_Fragment, { children: [_jsx("path", { d: arc(f0, middle), className: "mb-thermostat-control-arc", "data-tone": "heat" }), _jsx("path", { d: arc(middle, f1), className: "mb-thermostat-control-arc", "data-tone": "cool" })] })) : activeMode === "heat" ? (_jsx("path", { d: arc(0, f0), className: "mb-thermostat-control-arc", "data-tone": "heat" })) : (_jsx("path", { d: arc(f0, 1), className: "mb-thermostat-control-arc", "data-tone": "cool" })), _jsx("line", { x1: tickIn.x, y1: tickIn.y, x2: tickOut.x, y2: tickOut.y, className: "mb-thermostat-control-current" }), off
|
|
127
|
+
? null
|
|
128
|
+
: values.map((d, index) => {
|
|
129
|
+
const point = polar(START + SWEEP * fraction(d));
|
|
130
|
+
return (_jsx("circle", { cx: point.x, cy: point.y, r: 14, "data-thumb": index, className: "mb-thermostat-control-knob" }, index));
|
|
131
|
+
})] }), _jsxs("div", { className: "mb-thermostat-control-readout", children: [_jsx("span", { className: "mb-thermostat-control-caption", children: caption }), _jsx("span", { className: "mb-thermostat-control-target", "data-range": auto ? "" : undefined, children: big }), _jsx("span", { className: "mb-thermostat-control-now", children: footer })] }), _jsx(SliderPrimitive, { "aria-label": name, controller: controller, value: value, onValueChange: (next) => setDisplay(next), min: lo, max: hi, step: unitStep, minStepsBetweenThumbs: auto ? Math.round(gap / unitStep) : undefined, disabled: off, format: { style: "unit", unit: fahrenheit ? "fahrenheit" : "celsius", maximumFractionDigits: 1 }, className: "mb-thermostat-control-slider", children: _jsx(SliderControlPrimitive, { className: "mb-thermostat-control-slider-control", children: _jsx(SliderTrackPrimitive, { className: "mb-thermostat-control-slider-track", children: auto ? (_jsxs(_Fragment, { children: [_jsx(SliderThumbPrimitive, { index: 0, "data-thumb": 0, "aria-label": "Heat to", className: "mb-thermostat-control-thumb" }), _jsx(SliderThumbPrimitive, { index: 1, "data-thumb": 1, "aria-label": "Cool to", className: "mb-thermostat-control-thumb" })] })) : (_jsx(SliderThumbPrimitive, { "data-thumb": 0, "aria-label": activeMode === "cool" ? "Cool to" : "Heat to", className: "mb-thermostat-control-thumb" })) }) }) })] }), off ? null : (_jsxs("span", { className: "mb-thermostat-control-status", "data-state": state, children: [_jsx("span", { "aria-hidden": "true", className: "mb-thermostat-control-status-dot" }), status] })), hideModes ? null : (_jsx(SegmentedControl, { "aria-label": "Mode", block: true, value: activeMode, onValueChange: (next) => {
|
|
132
|
+
if (!next)
|
|
133
|
+
return;
|
|
134
|
+
const nextMode = next;
|
|
135
|
+
setInner((s) => ({ ...s, mode: nextMode }));
|
|
136
|
+
onModeChange?.(nextMode);
|
|
137
|
+
}, className: "mb-thermostat-control-modes", children: modes.map((item) => (_jsx(SegmentedControlItem, { value: item, children: MODE_LABELS[item] }, item))) }))] }));
|
|
138
|
+
}
|
|
139
|
+
export { ThermostatControl };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Toast as ToastPrimitive, ToastAction as ToastActionPrimitive, ToastClose as ToastClosePrimitive, ToastDescription as ToastDescriptionPrimitive, ToastRegion, ToastTitle as ToastTitlePrimitive } from "@ui-sdk/react/toast";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** What a notification can carry in `data`, beyond its title and description. */
|
|
4
|
+
type NotificationData = {
|
|
5
|
+
/** The app icon, about 32pt on macOS and 38pt on iOS. Defaults to a glyph for the toast's type. */
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
/** When it happened, shown at the trailing edge, like "now" or "2m ago". */
|
|
8
|
+
time?: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
declare function Toast({ className, ...props }: React.ComponentProps<typeof ToastPrimitive>): React.JSX.Element;
|
|
11
|
+
declare function ToastTitle({ className, ...props }: React.ComponentProps<typeof ToastTitlePrimitive>): React.JSX.Element;
|
|
12
|
+
declare function ToastDescription({ className, ...props }: React.ComponentProps<typeof ToastDescriptionPrimitive>): React.JSX.Element;
|
|
13
|
+
declare function ToastAction({ className, ...props }: React.ComponentProps<typeof ToastActionPrimitive>): React.JSX.Element;
|
|
14
|
+
declare function ToastClose({ className, children, ...props }: React.ComponentProps<typeof ToastClosePrimitive>): React.JSX.Element;
|
|
15
|
+
/** A rounded app-icon tile, for an icon you pass in `data.icon` or the glyph of the toast's type. */
|
|
16
|
+
declare function ToastIcon({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
17
|
+
type ToasterProps = Omit<React.ComponentProps<typeof ToastRegion>, "children"> & {
|
|
18
|
+
/** Renders each toast. Defaults to a system notification: icon, title, time, description, action and close. */
|
|
19
|
+
children?: React.ComponentProps<typeof ToastRegion>["children"];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The notification host. Mount it once near the root and call `toast()` from
|
|
23
|
+
* anywhere: notifications drop in at the top right on the Mac and as banners
|
|
24
|
+
* at the top of the screen on iPhone and iPad.
|
|
25
|
+
*/
|
|
26
|
+
declare function Toaster({ align, side, className, children, ...props }: ToasterProps): React.JSX.Element;
|
|
27
|
+
export { createToaster, toast } from "@ui-sdk/react/toast";
|
|
28
|
+
export type { ToastData, ToastType, Toaster as ToasterQueue } from "@ui-sdk/react/toast";
|
|
29
|
+
export { Toast, ToastAction, ToastClose, ToastDescription, Toaster, ToastIcon, ToastTitle };
|
|
30
|
+
export type { NotificationData, ToasterProps };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Toast as ToastPrimitive, ToastAction as ToastActionPrimitive, ToastClose as ToastClosePrimitive, ToastDescription as ToastDescriptionPrimitive, ToastRegion, ToastTitle as ToastTitlePrimitive, } from "@ui-sdk/react/toast";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cx, join } from "../lib/cx.js";
|
|
6
|
+
function Toast({ className, ...props }) {
|
|
7
|
+
return _jsx(ToastPrimitive, { className: cx("mb-toast", className), ...props });
|
|
8
|
+
}
|
|
9
|
+
function ToastTitle({ className, ...props }) {
|
|
10
|
+
return _jsx(ToastTitlePrimitive, { className: cx("mb-toast-title", className), ...props });
|
|
11
|
+
}
|
|
12
|
+
function ToastDescription({ className, ...props }) {
|
|
13
|
+
return _jsx(ToastDescriptionPrimitive, { className: cx("mb-toast-description", className), ...props });
|
|
14
|
+
}
|
|
15
|
+
function ToastAction({ className, ...props }) {
|
|
16
|
+
return _jsx(ToastActionPrimitive, { className: cx("mb-toast-action", className), ...props });
|
|
17
|
+
}
|
|
18
|
+
function ToastClose({ className, children, ...props }) {
|
|
19
|
+
return (_jsx(ToastClosePrimitive, { "aria-label": "Close", className: cx("mb-toast-close", className), ...props, children: children ?? (_jsx("svg", { viewBox: "0 0 10 10", "aria-hidden": "true", children: _jsx("path", { d: "M2.5 2.5l5 5m0-5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })) }));
|
|
20
|
+
}
|
|
21
|
+
/** A rounded app-icon tile, for an icon you pass in `data.icon` or the glyph of the toast's type. */
|
|
22
|
+
function ToastIcon({ className, ...props }) {
|
|
23
|
+
return _jsx("span", { "aria-hidden": "true", className: join("mb-toast-icon", className), ...props });
|
|
24
|
+
}
|
|
25
|
+
const typeGlyphs = {
|
|
26
|
+
success: _jsx("path", { d: "M6.5 12.5l3.5 3.5 7.5-8", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
27
|
+
error: _jsx("path", { d: "M8 8l8 8m0-8l-8 8", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" }),
|
|
28
|
+
warning: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M12 6.5v7", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" }), _jsx("circle", { cx: "12", cy: "17.25", r: "1.5", fill: "currentColor" })] })),
|
|
29
|
+
info: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "7", r: "1.5", fill: "currentColor" }), _jsx("path", { d: "M12 11v6.5", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" })] })),
|
|
30
|
+
};
|
|
31
|
+
function defaultIcon(type) {
|
|
32
|
+
if (type === "loading")
|
|
33
|
+
return _jsx("span", { className: "mb-toast-spinner" });
|
|
34
|
+
const glyph = type ? typeGlyphs[type] : undefined;
|
|
35
|
+
return glyph ? _jsx("svg", { viewBox: "0 0 24 24", children: glyph }) : null;
|
|
36
|
+
}
|
|
37
|
+
function Notification({ toast }) {
|
|
38
|
+
const data = (toast.data ?? {});
|
|
39
|
+
const icon = data.icon ?? defaultIcon(toast.type);
|
|
40
|
+
return (_jsxs(Toast, { children: [icon ? _jsx(ToastIcon, { "data-type": data.icon ? undefined : toast.type, children: icon }) : null, _jsxs("div", { className: "mb-toast-content", children: [_jsxs("div", { className: "mb-toast-header", children: [_jsx(ToastTitle, {}), _jsx("span", { className: "mb-toast-time", children: data.time ?? "now" })] }), _jsx(ToastDescription, {})] }), toast.action ? _jsx(ToastAction, {}) : null, _jsx(ToastClose, {})] }));
|
|
41
|
+
}
|
|
42
|
+
/** Reads the platform of the nearest `data-platform`, so a notification host inside a phone preview acts like one. */
|
|
43
|
+
function usePlatform(ref) {
|
|
44
|
+
const [platform, setPlatform] = React.useState("macos");
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
const host = ref.current?.closest("[data-platform]");
|
|
47
|
+
if (!host)
|
|
48
|
+
return;
|
|
49
|
+
const read = () => setPlatform(host.dataset.platform ?? "macos");
|
|
50
|
+
read();
|
|
51
|
+
const observer = new MutationObserver(read);
|
|
52
|
+
observer.observe(host, { attributes: true, attributeFilter: ["data-platform"] });
|
|
53
|
+
return () => observer.disconnect();
|
|
54
|
+
}, [ref]);
|
|
55
|
+
return platform;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The region lives in the top layer, positioned against the viewport. Inside a
|
|
59
|
+
* nested platform preview (a phone on a Mac page) it treats that preview's box
|
|
60
|
+
* as its screen instead, by writing the preview's distances from each edge.
|
|
61
|
+
*/
|
|
62
|
+
function useNestedScreen(ref) {
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const sentinel = ref.current;
|
|
65
|
+
const host = sentinel?.parentElement?.closest("[data-platform]");
|
|
66
|
+
const region = sentinel?.nextElementSibling;
|
|
67
|
+
if (!host || host === document.documentElement || !(region instanceof HTMLElement))
|
|
68
|
+
return;
|
|
69
|
+
let frame = 0;
|
|
70
|
+
const write = () => {
|
|
71
|
+
frame = 0;
|
|
72
|
+
const box = host.getBoundingClientRect();
|
|
73
|
+
const rtl = getComputedStyle(region).direction === "rtl";
|
|
74
|
+
const left = box.left;
|
|
75
|
+
const right = window.innerWidth - box.right;
|
|
76
|
+
region.style.setProperty("--mb-toaster-top", `${box.top}px`);
|
|
77
|
+
region.style.setProperty("--mb-toaster-bottom", `${window.innerHeight - box.bottom}px`);
|
|
78
|
+
region.style.setProperty("--mb-toaster-inline-start", `${rtl ? right : left}px`);
|
|
79
|
+
region.style.setProperty("--mb-toaster-inline-end", `${rtl ? left : right}px`);
|
|
80
|
+
region.style.setProperty("--mb-toaster-screen-width", `${box.width}px`);
|
|
81
|
+
};
|
|
82
|
+
const schedule = () => {
|
|
83
|
+
if (!frame)
|
|
84
|
+
frame = requestAnimationFrame(write);
|
|
85
|
+
};
|
|
86
|
+
write();
|
|
87
|
+
const resize = new ResizeObserver(schedule);
|
|
88
|
+
resize.observe(host);
|
|
89
|
+
window.addEventListener("scroll", schedule, { capture: true, passive: true });
|
|
90
|
+
window.addEventListener("resize", schedule);
|
|
91
|
+
return () => {
|
|
92
|
+
cancelAnimationFrame(frame);
|
|
93
|
+
resize.disconnect();
|
|
94
|
+
window.removeEventListener("scroll", schedule, { capture: true });
|
|
95
|
+
window.removeEventListener("resize", schedule);
|
|
96
|
+
for (const name of ["top", "bottom", "inline-start", "inline-end", "screen-width"]) {
|
|
97
|
+
region.style.removeProperty(`--mb-toaster-${name}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, [ref]);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The notification host. Mount it once near the root and call `toast()` from
|
|
104
|
+
* anywhere: notifications drop in at the top right on the Mac and as banners
|
|
105
|
+
* at the top of the screen on iPhone and iPad.
|
|
106
|
+
*/
|
|
107
|
+
function Toaster({ align, side = "top", className, children, ...props }) {
|
|
108
|
+
const sentinel = React.useRef(null);
|
|
109
|
+
const platform = usePlatform(sentinel);
|
|
110
|
+
useNestedScreen(sentinel);
|
|
111
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: sentinel, hidden: true }), _jsx(ToastRegion, { side: side, align: align ?? (platform === "macos" ? "end" : "center"), className: cx("mb-toaster", className), ...props, children: children ?? ((toast) => _jsx(Notification, { toast: toast })) })] }));
|
|
112
|
+
}
|
|
113
|
+
export { createToaster, toast } from "@ui-sdk/react/toast";
|
|
114
|
+
export { Toast, ToastAction, ToastClose, ToastDescription, Toaster, ToastIcon, ToastTitle };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Toggle as TogglePrimitive, ToggleGroup as ToggleGroupPrimitive, ToggleIcon as ToggleIconPrimitive } from "@ui-sdk/react/toggle";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type ToggleVariant = "plain" | "bezeled";
|
|
4
|
+
type ToggleSize = "sm" | "md" | "lg";
|
|
5
|
+
type ToggleProps = React.ComponentProps<typeof TogglePrimitive> & {
|
|
6
|
+
/** `plain` is a toolbar button; `bezeled` is a push-on/push-off button in content. */
|
|
7
|
+
variant?: ToggleVariant;
|
|
8
|
+
/** `accent` tints the pressed content with the accent color, as Xcode's navigator buttons do. */
|
|
9
|
+
tone?: "neutral" | "accent";
|
|
10
|
+
size?: ToggleSize;
|
|
11
|
+
};
|
|
12
|
+
declare function Toggle({ variant, tone, size, className, children, ...props }: ToggleProps): React.JSX.Element;
|
|
13
|
+
declare function ToggleIcon({ className, ...props }: React.ComponentProps<typeof ToggleIconPrimitive>): React.JSX.Element;
|
|
14
|
+
type ToggleGroupProps = React.ComponentProps<typeof ToggleGroupPrimitive> & {
|
|
15
|
+
/** `bezeled` joins the toggles into one raised control, like a "select any" segmented control on macOS. */
|
|
16
|
+
variant?: ToggleVariant;
|
|
17
|
+
size?: ToggleSize;
|
|
18
|
+
};
|
|
19
|
+
declare function ToggleGroup({ variant, size, className, ...props }: ToggleGroupProps): React.JSX.Element;
|
|
20
|
+
export { Toggle, ToggleGroup, ToggleIcon };
|
|
21
|
+
export type { ToggleGroupProps, ToggleProps, ToggleSize, ToggleVariant };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Toggle as TogglePrimitive, ToggleGroup as ToggleGroupPrimitive, ToggleIcon as ToggleIconPrimitive, } from "@ui-sdk/react/toggle";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cx } from "../lib/cx.js";
|
|
5
|
+
// Bare text gets a span so the stylesheet can pad a labeled toggle differently from an icon-only one.
|
|
6
|
+
function wrapText(children) {
|
|
7
|
+
return React.Children.map(children, (child) => typeof child === "string" || typeof child === "number" ? (_jsx("span", { className: "mb-toggle-label", children: child })) : (child));
|
|
8
|
+
}
|
|
9
|
+
// No defaults written to the DOM: a toggle inside a ToggleGroup takes the group's variant and size.
|
|
10
|
+
function Toggle({ variant, tone, size, className, children, ...props }) {
|
|
11
|
+
return (_jsx(TogglePrimitive, { "data-variant": variant, "data-tone": tone, "data-size": size, className: cx("mb-toggle", className), ...props, children: typeof children === "function" ? children : wrapText(children) }));
|
|
12
|
+
}
|
|
13
|
+
function ToggleIcon({ className, ...props }) {
|
|
14
|
+
return _jsx(ToggleIconPrimitive, { className: cx("mb-toggle-icon", className), ...props });
|
|
15
|
+
}
|
|
16
|
+
function ToggleGroup({ variant = "plain", size = "md", className, ...props }) {
|
|
17
|
+
return (_jsx(ToggleGroupPrimitive, { "data-variant": variant, "data-size": size, className: cx("mb-toggle-group", className), ...props }));
|
|
18
|
+
}
|
|
19
|
+
export { Toggle, ToggleGroup, ToggleIcon };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Token, TokenInputEditor, type TokenInputProps, TokenInputToken, TokenInputTokenRemove } from "@ui-sdk/react/token-input";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type NewToken = Omit<Token, "id">;
|
|
4
|
+
type EditorProps = React.ComponentProps<typeof TokenInputEditor>;
|
|
5
|
+
type TokenFieldProps = TokenInputProps & {
|
|
6
|
+
size?: "sm" | "md" | "lg";
|
|
7
|
+
/** `auto` is bordered on macOS and filled on touch, like `TextField`. */
|
|
8
|
+
variant?: "auto" | "bordered" | "filled";
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
className?: EditorProps["className"];
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
"aria-labelledby"?: string;
|
|
14
|
+
/** Characters that turn the text typed before them into a token. Return and leaving the field do too. `false` turns it off. */
|
|
15
|
+
tokenizeOn?: readonly string[] | false;
|
|
16
|
+
/** Makes a token from typed text, or returns `null` to leave the text as it is. */
|
|
17
|
+
createToken?: (text: string) => NewToken | null;
|
|
18
|
+
/** Draws a remove button on each token. Backspace removes them either way. */
|
|
19
|
+
removable?: boolean;
|
|
20
|
+
/** More props for the editor, the element that draws the field. */
|
|
21
|
+
editorProps?: Omit<EditorProps, "placeholder" | "className">;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The macOS token field: text where each entry becomes a rounded, accent-tinted
|
|
25
|
+
* token. Type a name and a comma or Return to make one.
|
|
26
|
+
*/
|
|
27
|
+
declare function TokenField({ size, variant, placeholder, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, tokenizeOn, createToken, removable, editorProps, controller: controllerProp, onValueChange, onSubmit, renderToken, submitShortcut, children, ...options }: TokenFieldProps): React.JSX.Element;
|
|
28
|
+
declare function TokenFieldToken({ className, ...props }: React.ComponentProps<typeof TokenInputToken>): React.JSX.Element;
|
|
29
|
+
declare function TokenFieldTokenRemove({ className, children, ...props }: React.ComponentProps<typeof TokenInputTokenRemove>): React.JSX.Element;
|
|
30
|
+
export { TokenField, TokenFieldToken, TokenFieldTokenRemove };
|
|
31
|
+
export type { TokenFieldProps };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createTokenInputController, TokenInput, TokenInputEditor, TokenInputToken, TokenInputTokenRemove, } from "@ui-sdk/react/token-input";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cx } from "../lib/cx.js";
|
|
6
|
+
import { ClearGlyph } from "../lib/field-glyphs.js";
|
|
7
|
+
const defaultSeparators = [","];
|
|
8
|
+
const plainToken = (text) => ({ type: "token", value: text, label: text });
|
|
9
|
+
/**
|
|
10
|
+
* The macOS token field: text where each entry becomes a rounded, accent-tinted
|
|
11
|
+
* token. Type a name and a comma or Return to make one.
|
|
12
|
+
*/
|
|
13
|
+
function TokenField({ size = "md", variant = "auto", placeholder, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, tokenizeOn = defaultSeparators, createToken = plainToken, removable, editorProps, controller: controllerProp, onValueChange, onSubmit, renderToken, submitShortcut = "enter", children, ...options }) {
|
|
14
|
+
const [own] = React.useState(createTokenInputController);
|
|
15
|
+
const controller = controllerProp ?? own;
|
|
16
|
+
const separators = tokenizeOn || [];
|
|
17
|
+
const tokenize = React.useCallback((value, all) => {
|
|
18
|
+
let changed = false;
|
|
19
|
+
const next = [];
|
|
20
|
+
value.forEach((segment, i) => {
|
|
21
|
+
if (typeof segment !== "string")
|
|
22
|
+
return void next.push(segment);
|
|
23
|
+
const pieces = split(segment, separators);
|
|
24
|
+
const closeLast = all && i === value.length - 1;
|
|
25
|
+
const made = [];
|
|
26
|
+
for (const [p, piece] of pieces.entries()) {
|
|
27
|
+
const open = p === pieces.length - 1 && !closeLast;
|
|
28
|
+
const text = piece.trim();
|
|
29
|
+
if (open) {
|
|
30
|
+
const rest = pieces.length > 1 ? piece.trimStart() : piece;
|
|
31
|
+
if (rest)
|
|
32
|
+
made.push(rest);
|
|
33
|
+
}
|
|
34
|
+
else if (text) {
|
|
35
|
+
const token = createToken(text);
|
|
36
|
+
if (!token)
|
|
37
|
+
return void next.push(segment);
|
|
38
|
+
made.push(token);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (made.length !== 1 || made[0] !== segment)
|
|
42
|
+
changed = true;
|
|
43
|
+
next.push(...made);
|
|
44
|
+
});
|
|
45
|
+
if (changed) {
|
|
46
|
+
controller.setValue(next);
|
|
47
|
+
controller.focus({ at: "end" });
|
|
48
|
+
}
|
|
49
|
+
return changed;
|
|
50
|
+
}, [controller, createToken, separators]);
|
|
51
|
+
return (_jsxs(TokenInput, { controller: controller, submitShortcut: submitShortcut, onValueChange: (value, details) => {
|
|
52
|
+
onValueChange?.(value, details);
|
|
53
|
+
const typedSeparator = value.some((segment) => typeof segment === "string" && separators.some((s) => segment.includes(s)));
|
|
54
|
+
if (typedSeparator && details.reason !== "imperative")
|
|
55
|
+
queueMicrotask(() => tokenize(value, false));
|
|
56
|
+
}, onSubmit: (value, details) => {
|
|
57
|
+
if (!(tokenizeOn && tokenize(value, true)))
|
|
58
|
+
onSubmit?.(value, details);
|
|
59
|
+
}, renderToken: renderToken ??
|
|
60
|
+
((token) => (_jsxs(TokenFieldToken, { children: [token.label, removable ? _jsx(TokenFieldTokenRemove, {}) : null] }))), ...options, children: [_jsx(TokenInputEditor, { id: id, placeholder: placeholder, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "data-size": size, "data-variant": variant, className: cx("mb-token-field", className), ...editorProps, onBlur: (event) => {
|
|
61
|
+
editorProps?.onBlur?.(event);
|
|
62
|
+
if (tokenizeOn)
|
|
63
|
+
tokenize(controller.getValue(), true);
|
|
64
|
+
} }), children] }));
|
|
65
|
+
}
|
|
66
|
+
function split(text, separators) {
|
|
67
|
+
if (separators.length === 0)
|
|
68
|
+
return [text];
|
|
69
|
+
const pattern = new RegExp(separators.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"));
|
|
70
|
+
return text.split(pattern);
|
|
71
|
+
}
|
|
72
|
+
function TokenFieldToken({ className, ...props }) {
|
|
73
|
+
return _jsx(TokenInputToken, { className: cx("mb-token-field-token", className), ...props });
|
|
74
|
+
}
|
|
75
|
+
function TokenFieldTokenRemove({ className, children, ...props }) {
|
|
76
|
+
return (_jsx(TokenInputTokenRemove, { className: cx("mb-token-field-token-remove", className), ...props, children: children ?? _jsx(ClearGlyph, {}) }));
|
|
77
|
+
}
|
|
78
|
+
export { TokenField, TokenFieldToken, TokenFieldTokenRemove };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type ToolCallStatusValue = "pending" | "running" | "done" | "error" | "approval";
|
|
4
|
+
/** The steps an agent took: a summary line that opens a group of steps. */
|
|
5
|
+
declare function ToolActivity({ className, ...props }: React.ComponentProps<typeof Collapsible>): React.JSX.Element;
|
|
6
|
+
type ToolActivitySummaryProps = Omit<React.ComponentProps<typeof CollapsibleTrigger>, "children"> & {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
/** A small glyph before the text, like a wrench or a stack of pages. */
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
/** Shimmers the text while the agent is still working. */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** "Used Dataroom, read a file · 29s", with a chevron that turns down when the steps show. */
|
|
14
|
+
declare function ToolActivitySummary({ icon, active, className, children, ...props }: ToolActivitySummaryProps): React.JSX.Element;
|
|
15
|
+
/** The group of steps, in a rounded box with a hairline between them. */
|
|
16
|
+
declare function ToolActivityContent({ className, children, "aria-label": label, ...props }: Omit<React.ComponentProps<typeof CollapsiblePanel>, "children"> & {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}): React.JSX.Element;
|
|
19
|
+
type ToolCallProps = Omit<React.ComponentProps<typeof Collapsible>, "children"> & {
|
|
20
|
+
/** Where the step stands. Every status but `done` is said in words to assistive tech. */
|
|
21
|
+
status?: ToolCallStatusValue;
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One step. Put a ToolCallTitle in it, and a ToolCallDetail if the step has a request and
|
|
26
|
+
* response to show: the row then becomes a button that opens it. Without detail it's plain text.
|
|
27
|
+
*/
|
|
28
|
+
declare function ToolCall({ status, className, children, ...props }: ToolCallProps): React.JSX.Element;
|
|
29
|
+
/** A small glyph at the start of a step, for the tool it used. */
|
|
30
|
+
declare function ToolCallIcon({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
31
|
+
type ToolCallTitleProps = React.ComponentProps<"span"> & {
|
|
32
|
+
/** What the agent did, in secondary text before the object: "Read", "Loaded skill". */
|
|
33
|
+
verb?: React.ReactNode;
|
|
34
|
+
};
|
|
35
|
+
/** The verb and its object on one line, like "Read data-workflows.md". Without a verb it's a note. */
|
|
36
|
+
declare function ToolCallTitle({ verb, className, children, ...props }: ToolCallTitleProps): React.JSX.Element;
|
|
37
|
+
/** The status at the end of the row. ToolCall draws it for you. */
|
|
38
|
+
declare function ToolCallStatus(): React.JSX.Element | null;
|
|
39
|
+
/** What opens under a step: one or more ToolCallSections, like Request and Response. */
|
|
40
|
+
declare function ToolCallDetail({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
41
|
+
type ToolCallSectionProps = Omit<React.ComponentProps<"section">, "title"> & {
|
|
42
|
+
/** The section's heading, like "Request". */
|
|
43
|
+
title: React.ReactNode;
|
|
44
|
+
};
|
|
45
|
+
/** A titled panel on a raised fill. Put a DescriptionList or a CodeBlock in it. */
|
|
46
|
+
declare function ToolCallSection({ title, className, children, ...props }: ToolCallSectionProps): React.JSX.Element;
|
|
47
|
+
export { ToolActivity, ToolActivityContent, ToolActivitySummary, ToolCall, ToolCallDetail, ToolCallIcon, ToolCallSection, ToolCallStatus, ToolCallTitle, };
|
|
48
|
+
export type { ToolActivitySummaryProps, ToolCallProps, ToolCallSectionProps, ToolCallStatusValue, ToolCallTitleProps };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { AlertGlyph, DisclosureChevron } from "../lib/agent-glyphs.js";
|
|
6
|
+
import { cx, join } from "../lib/cx.js";
|
|
7
|
+
import { ActivityIndicator } from "./activity-indicator.js";
|
|
8
|
+
import { Shimmer } from "./shimmer.js";
|
|
9
|
+
const ListContext = React.createContext(false);
|
|
10
|
+
const StatusContext = React.createContext("done");
|
|
11
|
+
/** The steps an agent took: a summary line that opens a group of steps. */
|
|
12
|
+
function ToolActivity({ className, ...props }) {
|
|
13
|
+
return _jsx(Collapsible, { className: cx("mb-tool-activity", className), ...props });
|
|
14
|
+
}
|
|
15
|
+
/** "Used Dataroom, read a file · 29s", with a chevron that turns down when the steps show. */
|
|
16
|
+
function ToolActivitySummary({ icon, active, className, children, ...props }) {
|
|
17
|
+
return (_jsxs(CollapsibleTrigger, { className: cx("mb-tool-activity-summary", className), ...props, children: [icon ? (_jsx("span", { "aria-hidden": "true", className: "mb-tool-activity-icon", children: icon })) : null, _jsx(Shimmer, { active: !!active, className: "mb-tool-activity-label", children: children }), _jsx(DisclosureChevron, { className: "mb-tool-activity-chevron" })] }));
|
|
18
|
+
}
|
|
19
|
+
/** The group of steps, in a rounded box with a hairline between them. */
|
|
20
|
+
function ToolActivityContent({ className, children, "aria-label": label = "Steps", ...props }) {
|
|
21
|
+
return (_jsx(CollapsiblePanel, { className: cx("mb-tool-activity-panel", className), ...props, children: _jsx(ListContext.Provider, { value: true, children: _jsx("ul", { role: "list", "aria-label": label, className: "mb-tool-activity-list", children: children }) }) }));
|
|
22
|
+
}
|
|
23
|
+
const statusWords = {
|
|
24
|
+
pending: "Pending",
|
|
25
|
+
running: "In progress",
|
|
26
|
+
done: null,
|
|
27
|
+
error: "Failed",
|
|
28
|
+
approval: "Needs approval",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One step. Put a ToolCallTitle in it, and a ToolCallDetail if the step has a request and
|
|
32
|
+
* response to show: the row then becomes a button that opens it. Without detail it's plain text.
|
|
33
|
+
*/
|
|
34
|
+
function ToolCall({ status = "done", className, children, ...props }) {
|
|
35
|
+
const { open: _open, defaultOpen: _defaultOpen, onOpenChange: _onOpenChange, onOpenChangeComplete: _onOpenChangeComplete, disabled: _disabled, controller: _controller, debug: _debug, render: _render, ...plain } = props;
|
|
36
|
+
const inList = React.useContext(ListContext);
|
|
37
|
+
const all = React.Children.toArray(children);
|
|
38
|
+
const detail = all.filter((child) => React.isValidElement(child) && child.type === ToolCallDetail);
|
|
39
|
+
const row = all.filter((child) => !(React.isValidElement(child) && child.type === ToolCallDetail));
|
|
40
|
+
const content = (_jsxs(_Fragment, { children: [row, _jsx(ToolCallStatus, {})] }));
|
|
41
|
+
const element = detail.length > 0 ? (_jsxs(Collapsible, { "data-status": status, "aria-busy": status === "running" ? true : undefined, className: cx("mb-tool-call", className), ...props, children: [_jsxs(CollapsibleTrigger, { className: "mb-tool-call-row", children: [content, _jsx(DisclosureChevron, { className: "mb-tool-call-chevron" })] }), _jsx(CollapsiblePanel, { className: "mb-tool-call-panel", children: detail })] })) : (_jsx("div", { "data-status": status, "aria-busy": status === "running" ? true : undefined, className: join("mb-tool-call", typeof className === "string" ? className : undefined), ...plain, children: _jsx("div", { className: "mb-tool-call-row", children: content }) }));
|
|
42
|
+
return (_jsx(StatusContext.Provider, { value: status, children: inList ? _jsx("li", { className: "mb-tool-activity-item", children: element }) : element }));
|
|
43
|
+
}
|
|
44
|
+
/** A small glyph at the start of a step, for the tool it used. */
|
|
45
|
+
function ToolCallIcon({ className, ...props }) {
|
|
46
|
+
return _jsx("span", { "aria-hidden": "true", className: join("mb-tool-call-icon", className), ...props });
|
|
47
|
+
}
|
|
48
|
+
/** The verb and its object on one line, like "Read data-workflows.md". Without a verb it's a note. */
|
|
49
|
+
function ToolCallTitle({ verb, className, children, ...props }) {
|
|
50
|
+
const status = React.useContext(StatusContext);
|
|
51
|
+
return (_jsxs(Shimmer, { active: status === "running", "data-note": verb == null ? "" : undefined, className: join("mb-tool-call-title", className), ...props, children: [verb != null ? _jsx("span", { className: "mb-tool-call-verb", children: verb }) : null, verb != null ? " " : null, _jsx("span", { className: "mb-tool-call-object", children: children })] }));
|
|
52
|
+
}
|
|
53
|
+
/** The status at the end of the row. ToolCall draws it for you. */
|
|
54
|
+
function ToolCallStatus() {
|
|
55
|
+
const status = React.useContext(StatusContext);
|
|
56
|
+
const words = statusWords[status];
|
|
57
|
+
if (status === "running") {
|
|
58
|
+
return (_jsxs("span", { className: "mb-tool-call-status", children: [_jsx("span", { "aria-hidden": "true", children: _jsx(ActivityIndicator, { size: "sm", className: "mb-tool-call-spinner" }) }), _jsx("span", { className: "mb-visually-hidden", children: words })] }));
|
|
59
|
+
}
|
|
60
|
+
if (status === "error") {
|
|
61
|
+
return (_jsxs("span", { className: "mb-tool-call-status", "data-status": "error", children: [_jsx(AlertGlyph, { className: "mb-tool-call-alert" }), _jsx("span", { children: words })] }));
|
|
62
|
+
}
|
|
63
|
+
if (status === "approval") {
|
|
64
|
+
return (_jsx("span", { className: "mb-tool-call-status", "data-status": "approval", children: words }));
|
|
65
|
+
}
|
|
66
|
+
return words ? _jsx("span", { className: "mb-visually-hidden", children: words }) : null;
|
|
67
|
+
}
|
|
68
|
+
/** What opens under a step: one or more ToolCallSections, like Request and Response. */
|
|
69
|
+
function ToolCallDetail({ className, ...props }) {
|
|
70
|
+
return _jsx("div", { className: join("mb-tool-call-detail", className), ...props });
|
|
71
|
+
}
|
|
72
|
+
/** A titled panel on a raised fill. Put a DescriptionList or a CodeBlock in it. */
|
|
73
|
+
function ToolCallSection({ title, className, children, ...props }) {
|
|
74
|
+
const id = React.useId();
|
|
75
|
+
return (_jsxs("section", { "aria-labelledby": id, className: join("mb-tool-call-section", className), ...props, children: [_jsx("div", { id: id, className: "mb-tool-call-section-title", children: title }), _jsx("div", { className: "mb-tool-call-section-body", children: children })] }));
|
|
76
|
+
}
|
|
77
|
+
export { ToolActivity, ToolActivityContent, ToolActivitySummary, ToolCall, ToolCallDetail, ToolCallIcon, ToolCallSection, ToolCallStatus, ToolCallTitle, };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Toggle, ToggleGroup } from "@ui-sdk/react/toggle";
|
|
2
|
+
import { ToolbarButton as ToolbarButtonPrimitive, ToolbarGroup as ToolbarGroupPrimitive, ToolbarInput as ToolbarInputPrimitive, ToolbarLink as ToolbarLinkPrimitive, Toolbar as ToolbarPrimitive, ToolbarSeparator as ToolbarSeparatorPrimitive } from "@ui-sdk/react/toolbar";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
type ToolbarProps = React.ComponentProps<typeof ToolbarPrimitive> & {
|
|
5
|
+
/** `unified` sits in a macOS window's title bar; `floating` is the iOS bottom toolbar of glass capsules. */
|
|
6
|
+
variant?: "unified" | "floating";
|
|
7
|
+
};
|
|
8
|
+
declare function Toolbar({ variant, className, ...props }: ToolbarProps): React.JSX.Element;
|
|
9
|
+
declare function ToolbarButton({ className, ...props }: React.ComponentProps<typeof ToolbarButtonPrimitive>): React.JSX.Element;
|
|
10
|
+
/** A toolbar button that stays pressed, like Show Sidebar or a view mode. */
|
|
11
|
+
declare function ToolbarToggle({ className, ...props }: React.ComponentProps<typeof Toggle>): React.JSX.Element;
|
|
12
|
+
declare function ToolbarLink({ className, ...props }: React.ComponentProps<typeof ToolbarLinkPrimitive>): React.JSX.Element;
|
|
13
|
+
declare function ToolbarGroup({ className, ...props }: React.ComponentProps<typeof ToolbarGroupPrimitive>): React.JSX.Element;
|
|
14
|
+
/** One choice from a cluster of toggles, like the Finder's icon, list and column views. */
|
|
15
|
+
declare function ToolbarToggleGroup({ className, ...props }: React.ComponentProps<typeof ToggleGroup>): React.JSX.Element;
|
|
16
|
+
declare function ToolbarSeparator({ className, ...props }: React.ComponentProps<typeof ToolbarSeparatorPrimitive>): React.JSX.Element;
|
|
17
|
+
/** Flexible space: pushes what follows to the trailing edge. */
|
|
18
|
+
declare function ToolbarSpacer({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
19
|
+
type ToolbarTitleProps = React.ComponentProps<"div"> & {
|
|
20
|
+
subtitle?: React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
declare function ToolbarTitle({ subtitle, className, children, ...props }: ToolbarTitleProps): React.JSX.Element;
|
|
23
|
+
type ToolbarSearchFieldProps = React.ComponentProps<typeof ToolbarInputPrimitive>;
|
|
24
|
+
/** A search field that joins the toolbar's arrow-key navigation. Name it with `aria-label`. */
|
|
25
|
+
declare function ToolbarSearchField({ className, placeholder, ...props }: ToolbarSearchFieldProps): React.JSX.Element;
|
|
26
|
+
export { Toolbar, ToolbarButton, ToolbarGroup, ToolbarLink, ToolbarSearchField, ToolbarSeparator, ToolbarSpacer, ToolbarTitle, ToolbarToggle, ToolbarToggleGroup, };
|
|
27
|
+
export type { ToolbarProps, ToolbarSearchFieldProps, ToolbarTitleProps };
|