@stackone/malachite 2.93.0 → 2.93.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/COMPONENTS.md CHANGED
@@ -8,7 +8,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
8
8
 
9
9
  - **`Chat`** — A chat column: `Chat.Thread` scrolls and pins itself to the newest message, `Chat.Composer` keeps its own height and owns the Enter/Shift+Enter convention, and `Chat.Message`, `Chat.ToolCall` and `Chat.Thinking` render one turn each. A user turn sits right and hugs its text; an assistant turn runs full width, and `variant="card"` frames it with its state, copy and rating controls, and a token/model line. `variant="bubble"` is a third treatment, not a repaint of either: tinted bubbles whose flattened corner points at whoever spoke, so authorship reads before the words do. `Chat.Context` lists what the conversation can see — a removable chip per source, and an add affordance only when a handler is given. `Chat.Thinking` and a loading turn draw bars in the shape of the answer rather than a spinner. `Chat.Reasoning` shows what a model reasoned, open while it arrives and shut once it stops, until the reader toggles it. `Chat.ToolCall` mounts its payloads only once opened, since a result can be tens of KB; `blocked` is a call something refused to run, as distinct from `error`. The row under a composer is `ComposerChip`, `ContextMeter` and `ModelPicker` — PillButton tabs, so it reads as attached to the field; `ModelPicker` opens a portalled menu with a submenu per model. The transcript is a live `log` region, so a streamed reply is announced, and it shows a centred empty state until the first turn. _Key props:_ `Chat`: `children`, `className`. `Thread`: `aria-label`, `emptyTitle`, `emptyDescription`, `emptyIcon`. `Message`: `role`, `variant` (`plain` | `card`), `content`, `children`, `name`, `avatarSrc`, `status` (`streaming` | `completed` | `error`), `loading`, `onCopy`, `onFeedback`, `usage`. `ToolCall`: `name`, `status` (`running` | `completed` | `error` | `blocked`), `callId`, `input` and `output` (an object, or a string shown as it is), `adornment`, `children`, `defaultExpanded`. `Reasoning`: `text`, `streaming`, `title`. `Thinking`: `label`. `Composer`: `value`, `onChange`, `onSend`, `onStop`, `busy`, `disabled`, `placeholder`, `maxLength`, `rows`, `children`. `ComposerChip`: `label`, `icon`, `trailingIcon`, `onClick`, `disabled`. `ContextMeter`: `used`, `limit`, `cached`, `label`. `ModelPicker`: `models`, `value`, `optionValue`, `onChange`, `openUp`, `disabled`. `Context`: `label`, `items` (`{id, label, onRemove?}`), `onAdd`, `className`.
10
10
  - **`Surface`** — Rounded, bordered card container with the standard elevation shadow. Use `overflow="clip"` to keep the rounded clipping while letting a `position: sticky` descendant still pin (`hidden` would trap it); `visible` disables clipping. _Key props:_ `children`, `padding`, `overflow`, `shadow` (`false` sits the card flat, without the elevation shadow), `tone` (`default` | `highlight`; `highlight` paints the warm ground with no border, and sits flat unless `shadow` is passed, for a static block that stands out from the page, such as a hero or a guide's section header; its ground is too close to `Surface.Row`'s hover for clickable rows inside it), `className`, `style`.
11
- - **`SurfaceRow`** — A full-bleed row inside a Surface (used as `Surface.Row`). Owns hover highlight, colour transition and an optional bottom divider. Pass `onClick`/`href` to make the whole row clickable (renders as a real button/anchor, so keyboard nav works). For a selectable row use `role="radio"` + `selected` and put a presentational `<Radio>` inside as the indicator; `selected` then paints the same treatment `Table` gives `selectedRowKey`. Under `role="checkbox"` it only announces — a multi-select row carries its own checkbox, and a highlight marking one of many says nothing when most rows are checked. `selection` overrides that either way (`highlight` / `announce`). `selected="mixed"` marks a partly selected checkbox row (`aria-checked="mixed"`); it never paints or marks a row current, and counts as not selected under any other role. Use `trailing` for a control that must stay interactive — it renders outside the row button, which a nested control could not be. An `onClick` row with `trailing` is still clickable across its whole box, padding and the space around the slot included (an `href` row leaves that to its link, so a modified click still opens a new tab), with its focus ring at the row's edge; a click inside the slot (or in a menu it portals out) is the slot's own, and a disabled row drops both the click and the ring. `revealTrailing` shows that control only on hover, keyboard focus or while a menu it opened is open, keeping it in the tab order and always showing it on a touch screen. `tone="muted"` tints a row whose subject is inactive, which `disabled` does not: a muted row stays clickable. `leading` puts the row's own indicator (a presentational `Checkbox`) inside the row button ahead of the children (with `leading` or `dimmed`, pass one child; it fills the row), and `dimmed` fades the children but not `leading` or `trailing`, for a row switched off but still a click from on. _Key props:_ `divider`, `disabled`, `tone` (`default` | `muted`), `inset` (`none` | `compact` — the row owns an 8px by 16px inset, wrapping `trailing` too, so its content needs no padding wrapper), `onClick`, `href`, `target`, `rel`, `selected` (`boolean` | `"mixed"`), `selection` (`highlight` | `tint` | `announce`; `tint` paints the selected treatment without the accent bar, for a menu whose choice is already marked inside the row), `trailing`, `revealTrailing`, `leading`, `dimmed`, `role`, `className`, `style`.
11
+ - **`SurfaceRow`** — A full-bleed row inside a Surface (used as `Surface.Row`). Owns hover highlight, colour transition and an optional bottom divider. Pass `onClick`/`href` to make the whole row clickable (renders as a real button/anchor, so keyboard nav works). For a selectable row use `role="radio"` + `selected` and put a presentational `<Radio>` inside as the indicator; `selected` then paints the same treatment `Table` gives `selectedRowKey`. Under `role="checkbox"` it only announces — a multi-select row carries its own checkbox, and a highlight marking one of many says nothing when most rows are checked. `selection` overrides that either way (`highlight` / `announce`). `selected="mixed"` marks a partly selected checkbox row (`aria-checked="mixed"`); it never paints or marks a row current, and counts as not selected under any other role. Use `trailing` for a control that must stay interactive — it renders outside the row button, which a nested control could not be. An `onClick` row with `trailing` is still clickable across its whole box, padding and the space around the slot included (an `href` row leaves that to its link, so a modified click still opens a new tab), with its focus ring at the row's edge; a click inside the slot (or in a menu it portals out) is the slot's own, and a disabled row drops both the click and the ring. `revealTrailing` shows that control only on hover, keyboard focus or while a menu it opened is open, keeping it in the tab order and always showing it on a touch screen. `tone="muted"` tints a row whose subject is inactive, which `disabled` does not: a muted row stays clickable. `leading` puts the row's own indicator (a presentational `Checkbox`) inside the row button ahead of the children (with `leading` or `dimmed`, pass one child; it fills the row), and `dimmed` fades the children but not `leading` or `trailing`, for a row switched off but still a click from on. _Key props:_ `divider`, `disabled`, `hover` (default on; `false` leaves the hover to something inside the row), `tone` (`default` | `muted`), `inset` (`none` | `compact` — the row owns an 8px by 16px inset, wrapping `trailing` too, so its content needs no padding wrapper), `onClick`, `href`, `target`, `rel`, `selected` (`boolean` | `"mixed"`), `selection` (`highlight` | `tint` | `announce`; `tint` paints the selected treatment without the accent bar, for a menu whose choice is already marked inside the row), `trailing`, `revealTrailing`, `leading`, `dimmed`, `role`, `className`, `style`.
12
12
  - **`SurfaceExpandableRow`** — A row that opens to reveal a body (used as `Surface.ExpandableRow`), for a line that carries its own controls. Not `Accordion`, which puts its header inside the toggle button, so a header holding a dropdown or a second button would be invalid: here the row surface takes the click and a cell opts out by wrapping its controls in `ExpandableRow.Controls`, while the arrow stays a real button so the keyboard reaches it. That opt-out is explicit rather than sniffing the event target for an interactive ancestor, because a control rendering into a shadow root retargets the event to its host. `sticky` pins the row while its body scrolls, offset by `stickyTopOffset` for whatever is already pinned above it; it only pins while open, since a closed row has nothing to scroll past. _Key props:_ `header`, `children`, `expanded`, `onToggle`, `sticky`, `stickyTopOffset`, `divider`, `tone`, `aria-label`, `className`, `style`.
13
13
  - **`DisclosureArrow`** — The expand/collapse triangle disclosure UI shares (`Accordion`, `Surface.ExpandableRow`). Owns its colour states so they never drift between usages: `text-primary` when expanded, `text-placeholder` otherwise, and dark on hover inside a `group` ancestor — put `group` on the clickable header or row so that hover state activates. _Key props:_ `expanded`, `size`, `className`.
14
14
  - **`Card`** — Generic content card. `title` heads it, with dimmed `subtitle` text beside it and `extra` actions at the right of the title row. `variant="framed"` draws the detached `Table`’s frame instead: the title row sits on a grey frame and the children in a bordered section inside it, so a card above a table, such as a chart over a log list, reads as part of the same set. `dimmed`, `border`, `size`, `glassFooter` and `headerConfig` do not apply to a framed card. _Key props:_ `variant` (`CardVariant`: `default` | `framed`), `title`, `subtitle`, `extra`, `padding`, `footer`.
@@ -113,7 +113,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
113
113
 
114
114
  - **`LevelMeter`** — Rising bars, shortest first, that picture how much of a scale is on — an access level in a level menu or on a level chip. Each step is `on` (a solid accent-green bar), `partial` (a green outline over a faint tint, for a step only some of whose actions are on) or `off` (an empty grey outline); every step keeps 3:1 against the surface, and colours come from the theme. Styled inline so it still draws inside an `ActionMenu`, which portals outside the shadow root and its stylesheet. Beside text that already names the level it is decorative and hidden from assistive tech; give it a `label` only when it stands alone and it reads as an image of that name. As an `ActionMenu` item `icon` or a `Button` `icon`, leave `label` off: the icon joins the item name, and the text already says the level. _Key props:_ `steps` (`LevelMeterStep[]`: `on` | `partial` | `off`), `label`, `className`.
115
115
  - **`TimeBarChart`** — Counts per time bucket as stacked bars on a UTC axis, the request-volume chart above a log list. Every bucket in `range` takes a slot whether or not it has data, so gaps read as gaps; a zone-less time string is read as UTC. Hover or arrow-key through buckets for a tooltip listing every series and the total; `highlightTime` shades the bucket holding a time from elsewhere on the page, such as the hovered log row. With `onRangeSelect`, dragging across bars reports the whole buckets covered, `end` exclusive so it goes straight back in as `range`, and whether the selection takes in the last bucket. `loading` dims bars already drawn rather than replacing them, and shows a spinner only when there is nothing to dim. Series colours follow the theme’s status tokens by `tone`, and failures always stack above successes whatever order `series` comes in, so position separates them where colour alone might not; a legend names them unless `legend={false}`. A visually hidden table carries the same numbers for screen readers. _Key props:_ `series` (`{ key, label, tone }[]`, stacked by tone with `error` on top; `TimeBarChartTone`: `success` | `error` | `neutral`), `buckets` (`{ start, values }[]`), `interval` (`{ unit, step }`; `TimeBarChartUnit`: `minute` | `hour` | `day` | `week` | `month`), `range` (`end` exclusive, as a selection reports it; at most 2,000 buckets, the newest kept), `TimeBarChartSize` (`small` | `medium` | `large`), `loading`, `error`, `errorTitle`, `errorSubTitle`, `valueLabel`, `legend`, `highlightTime`, `onRangeSelect`, `aria-label`, `aria-labelledby`, `className`, `style`.
116
- - **`TimeBarChartSwatch`** — The mark a `TimeBarChart` draws a series in, by its `tone`, for naming the series somewhere other than the chart's legend, such as a count beside the chart standing in for it. It always matches the bars, the legend and the tooltip, and follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
116
+ - **`TimeBarChartSwatch`** — The mark a `TimeBarChart` draws a series in, by its `tone`, for naming the series somewhere other than the chart's legend, such as a count beside the chart standing in for it. It matches the legend and the tooltip, and the bars draw the same colour at 40%; it follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
117
117
  - **`Table`** — Data table with columns, sizing, pagination and row selection. `column.align` places a column's header as well as its cells. What lands on the aligned edge is the last thing in the header row rather than the title: the sort caret on a sortable column, the info icon on one carrying `info` without a sorter. `headerVariant` picks the header layout, and only `inline` lines header and body up exactly, because both are cells of one `<table>`. `detached` builds them from flex rows, where a sortable header cell is 32px narrower than a non-sortable one — its padding sits on the inner button rather than on the flex item — so its header cells sit 15–17px off their column at any alignment; reach for `inline` where exact alignment matters. Sorting is internal, so the array passed as `data` is not the order rendered once a column is sorted: `onVisibleOrderChange` reports the rows in render order — the whole of `data`, compared by `rowKey` so an equal order never re-fires — for a consumer stepping a master-detail view the way the user sees it. On the detached header, `title`, `subtitle` and `extra` add a title row on the frame above the column headers, the row a `framed` `Card` draws, and it docks with them under `stickyHeaderTop` (with `showHeader={false}` nothing docks and it scrolls with the rows). The inline header has no frame, so it draws none of the three and warns in development. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition` (`pagination.position`, in antd naming: a pager on each edge named, aligned as named, 16px from the rows; bottom right by default), `headerVariant`, `title`, `subtitle`, `extra`, `onVisibleOrderChange`, `scrollHeight` (a height, or `"fill"` for the room left in its scroller once the content above and below it fits, so the page itself never scrolls).
118
118
  - **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
119
119
  - **`Avatar`** — Logo/initial avatar. Renders the image when available, otherwise a coloured tile with the first letter of `name`, or with `fallback="placeholder"` the generic "no logo available" tile. Encapsulates the fallback colour. _Key props:_ `src`, `name`, `size`, `shape="square" | "circle"`, `fallback="initial" | "placeholder"`.
@@ -1,23 +1,25 @@
1
- import { jsxs as v, Fragment as k, jsx as n } from "react/jsx-runtime";
2
- import { useState as L, useRef as R, useCallback as S, useEffect as ee, useInsertionEffect as te } from "react";
3
- import { createPortal as ne } from "react-dom";
4
- import { Avatar as B } from "../Avatar.js";
5
- import re from "../CustomIcons/CaretDownIcon.js";
6
- import oe from "../CustomIcons/CaretRightIcon.js";
7
- import ie from "../CustomIcons/CaretUpIcon.js";
8
- import D from "../CustomIcons/CheckIcon.js";
9
- import { PillButton as le } from "../PillButton.js";
10
- import { pushEscapeLayer as se } from "../escapeLayers.js";
11
- import { usePopupLayer as M } from "../overlayLayers.js";
12
- import { useOwnedByPopover as ae } from "../popoverTree.js";
13
- import { ensureOverlayStyles as ce } from "../portalOverlay.js";
14
- import { useTopLayer as ue } from "../topLayer.js";
15
- import { useFollowTrigger as fe } from "../useFollowTrigger.js";
16
- const h = 8, _ = 220, P = 240, N = (r, c) => ({
1
+ import { jsxs as w, Fragment as D, jsx as l } from "react/jsx-runtime";
2
+ import { useState as I, useRef as L, useCallback as E, useEffect as ie, useInsertionEffect as ce } from "react";
3
+ import { createPortal as se } from "react-dom";
4
+ import { Avatar as _ } from "../Avatar.js";
5
+ import ae from "../CustomIcons/CaretDownIcon.js";
6
+ import ue from "../CustomIcons/CaretRightIcon.js";
7
+ import me from "../CustomIcons/CaretUpIcon.js";
8
+ import N from "../CustomIcons/CheckIcon.js";
9
+ import { PillButton as fe } from "../PillButton.js";
10
+ import { pushEscapeLayer as de } from "../escapeLayers.js";
11
+ import { usePopupLayer as W } from "../overlayLayers.js";
12
+ import { useOwnedByPopover as ge } from "../popoverTree.js";
13
+ import { ensureOverlayStyles as pe } from "../portalOverlay.js";
14
+ import { useTopLayer as he } from "../topLayer.js";
15
+ import { useFollowTrigger as be } from "../useFollowTrigger.js";
16
+ const p = 8, A = 220, P = 240, F = (n, u) => ({
17
17
  position: "fixed",
18
- top: (r == null ? void 0 : r.top) ?? 0,
19
- left: (r == null ? void 0 : r.left) ?? 0,
20
- minWidth: c,
18
+ top: (n == null ? void 0 : n.top) ?? 0,
19
+ left: (n == null ? void 0 : n.left) ?? 0,
20
+ maxHeight: n == null ? void 0 : n.maxHeight,
21
+ overflowY: (n == null ? void 0 : n.maxHeight) === void 0 ? void 0 : "auto",
22
+ minWidth: u,
21
23
  background: "var(--malachite-card-background, rgb(255, 255, 255))",
22
24
  border: "1px solid var(--malachite-card-border, rgb(232, 232, 232))",
23
25
  borderRadius: 12,
@@ -26,9 +28,9 @@ const h = 8, _ = 220, P = 240, N = (r, c) => ({
26
28
  display: "flex",
27
29
  flexDirection: "column",
28
30
  gap: 2,
29
- visibility: r ? "visible" : "hidden",
30
- opacity: r ? 1 : 0
31
- }), W = {
31
+ visibility: n ? "visible" : "hidden",
32
+ opacity: n ? 1 : 0
33
+ }), Y = {
32
34
  display: "flex",
33
35
  alignItems: "center",
34
36
  gap: 8,
@@ -41,122 +43,131 @@ const h = 8, _ = 220, P = 240, N = (r, c) => ({
41
43
  cursor: "pointer",
42
44
  fontSize: "var(--malachite-font-size-small, 13px)",
43
45
  color: "var(--malachite-text-primary, rgb(10, 10, 10))"
44
- }, me = {
46
+ }, ve = {
45
47
  fontSize: "var(--malachite-font-size-xsmall, 11px)",
46
48
  color: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
47
- }, A = {
49
+ }, j = {
48
50
  marginLeft: "auto",
49
51
  display: "inline-flex",
50
52
  color: "var(--malachite-text-success, rgb(2, 122, 66))"
51
- }, Pe = ({
52
- models: r,
53
- value: c,
54
- optionValue: F,
55
- onChange: H,
56
- disabled: U = !1,
57
- openUp: E = !0,
58
- "aria-label": Y = "Model"
53
+ }, ke = ({
54
+ models: n,
55
+ value: u,
56
+ optionValue: U,
57
+ onChange: G,
58
+ disabled: K = !1,
59
+ openUp: h = !0,
60
+ "aria-label": V = "Model"
59
61
  }) => {
60
- var O;
61
- const [l, g] = L(!1), [j, G] = L(null), [K, x] = L(null), [V, C] = L(
62
+ var T;
63
+ const [i, b] = I(!1), [$, q] = I(null), [J, v] = I(null), [Q, x] = I(
62
64
  null
63
- ), y = R(null), u = R(null), w = R(null), $ = M("actionmenu", l, u), q = M("actionmenu", l, w);
64
- ue(u, l), ae(
65
- S(() => w.current, []),
66
- l
65
+ ), S = L(null), s = L(null), R = L(null), H = L(null), X = W("actionmenu", i, s), Z = W("actionmenu", i, R);
66
+ he(s, i), ge(
67
+ E(() => R.current, []),
68
+ i
67
69
  );
68
- const s = r.find((e) => e.value === c), b = S(() => {
69
- const e = y.current, t = u.current;
70
+ const a = n.find((e) => e.value === u), y = E(() => {
71
+ const e = S.current, t = s.current;
70
72
  if (!e)
71
73
  return;
72
- const o = e.getBoundingClientRect(), i = (t == null ? void 0 : t.offsetWidth) || _, a = (t == null ? void 0 : t.offsetHeight) || 0, I = window.innerWidth - i - h, m = Math.max(h, Math.min(o.right - i, I)), p = o.top - a - 4, d = o.bottom + 4, X = p >= h, Z = a === 0 || d + a <= window.innerHeight - h;
73
- G({ top: E ? X ? p : d : Z ? d : p, left: m });
74
- }, [E]), J = S(() => {
75
- x(null), C(null), b();
76
- }, [b]), Q = S(() => g(!1), []);
77
- fe(l, y, J, Q), ee(() => {
78
- if (!l) {
79
- x(null), C(null);
74
+ const r = e.getBoundingClientRect(), o = (t == null ? void 0 : t.offsetWidth) || A, c = t ? t.scrollHeight + t.offsetHeight - t.clientHeight : 0, C = window.innerWidth - o - p, f = Math.max(p, Math.min(r.right - o, C)), d = r.top - 4 - p, g = window.innerHeight - r.bottom - 4 - p, B = h ? d : g, re = h ? g : d, oe = c > B && re > B, k = h !== oe, M = k ? d : g, le = k ? r.top - 4 - Math.min(c, M) : r.bottom + 4;
75
+ q({ top: le, left: f, maxHeight: M });
76
+ }, [h]), ee = E(() => {
77
+ v(null), x(null), y();
78
+ }, [y]), te = E(() => b(!1), []);
79
+ be(i, S, ee, te), ie(() => {
80
+ if (!i) {
81
+ v(null), x(null);
80
82
  return;
81
83
  }
82
- b();
83
- const e = () => b(), t = (i) => {
84
- const a = i.composedPath();
85
- [y.current, u.current, w.current].some(
86
- (m) => m !== null && a.includes(m)
87
- ) || g(!1);
88
- }, o = se(() => g(!1));
84
+ y();
85
+ const e = () => y(), t = (o) => {
86
+ const c = o.composedPath();
87
+ [S.current, s.current, R.current].some(
88
+ (f) => f !== null && c.includes(f)
89
+ ) || b(!1);
90
+ }, r = de(() => b(!1));
89
91
  return window.addEventListener("resize", e), document.addEventListener("mousedown", t, !0), () => {
90
- window.removeEventListener("resize", e), document.removeEventListener("mousedown", t, !0), o();
92
+ window.removeEventListener("resize", e), document.removeEventListener("mousedown", t, !0), r();
91
93
  };
92
- }, [l, b]), te(() => {
93
- l && ce();
94
- }, [l]);
95
- const T = (e, t) => {
96
- var m, p, d;
97
- if (!((m = e.options) != null && m.length)) {
98
- x(null);
94
+ }, [i, y]), ce(() => {
95
+ i && pe();
96
+ }, [i]);
97
+ const O = (e, t) => {
98
+ var f, d, g;
99
+ if (!((f = e.options) != null && f.length)) {
100
+ v(null);
99
101
  return;
100
102
  }
101
- const o = t.getBoundingClientRect(), a = (((p = u.current) == null ? void 0 : p.getBoundingClientRect().left) ?? o.left) - P - 4, I = a >= h ? a : Math.min(
102
- (((d = u.current) == null ? void 0 : d.getBoundingClientRect().right) ?? o.right) + 4,
103
- window.innerWidth - P - h
103
+ const r = t.getBoundingClientRect(), c = (((d = s.current) == null ? void 0 : d.getBoundingClientRect().left) ?? r.left) - P - 4, C = c >= p ? c : Math.min(
104
+ (((g = s.current) == null ? void 0 : g.getBoundingClientRect().right) ?? r.right) + 4,
105
+ window.innerWidth - P - p
104
106
  );
105
- x(e.value), C({ top: o.top, left: I });
107
+ H.current = t, v(e.value), x({ top: r.top, left: C });
108
+ }, ne = () => {
109
+ var r, o;
110
+ const e = (r = H.current) == null ? void 0 : r.getBoundingClientRect(), t = (o = s.current) == null ? void 0 : o.getBoundingClientRect();
111
+ if (!e || !t || e.top < t.top || e.bottom > t.bottom) {
112
+ v(null), x(null);
113
+ return;
114
+ }
115
+ x((c) => c && { ...c, top: e.top });
106
116
  }, z = (e, t) => {
107
- H(e.value, t == null ? void 0 : t.value), g(!1);
108
- }, f = r.find((e) => e.value === K);
109
- return /* @__PURE__ */ v(k, { children: [
110
- /* @__PURE__ */ n("div", { ref: y, className: "inline-flex", children: /* @__PURE__ */ n(
111
- le,
117
+ G(e.value, t == null ? void 0 : t.value), b(!1);
118
+ }, m = n.find((e) => e.value === J);
119
+ return /* @__PURE__ */ w(D, { children: [
120
+ /* @__PURE__ */ l("div", { ref: S, className: "inline-flex", children: /* @__PURE__ */ l(
121
+ fe,
112
122
  {
113
- label: (s == null ? void 0 : s.label) ?? c,
114
- icon: s != null && s.iconSrc ? /* @__PURE__ */ n(B, { src: s.iconSrc, name: s.label, size: 14 }) : void 0,
115
- trailingIcon: E ? /* @__PURE__ */ n(ie, { size: 10 }) : /* @__PURE__ */ n(re, { size: 10 }),
123
+ label: (a == null ? void 0 : a.label) ?? u,
124
+ icon: a != null && a.iconSrc ? /* @__PURE__ */ l(_, { src: a.iconSrc, name: a.label, size: 14 }) : void 0,
125
+ trailingIcon: h ? /* @__PURE__ */ l(me, { size: 10 }) : /* @__PURE__ */ l(ae, { size: 10 }),
116
126
  shape: "tab",
117
127
  size: "small",
118
- disabled: U,
119
- onClick: () => g((e) => !e)
128
+ disabled: K,
129
+ onClick: () => b((e) => !e)
120
130
  }
121
131
  ) }),
122
- l && ne(
123
- /* @__PURE__ */ v(k, { children: [
124
- /* @__PURE__ */ n(
132
+ i && se(
133
+ /* @__PURE__ */ w(D, { children: [
134
+ /* @__PURE__ */ l(
125
135
  "div",
126
136
  {
127
- ref: u,
137
+ ref: s,
128
138
  role: "menu",
129
- "aria-label": Y,
130
- ...$,
131
- style: N(j, _),
132
- children: r.map((e) => {
133
- var t, o;
134
- return /* @__PURE__ */ v(
139
+ "aria-label": V,
140
+ ...X,
141
+ style: F($, A),
142
+ onScroll: ne,
143
+ children: n.map((e) => {
144
+ var t, r;
145
+ return /* @__PURE__ */ w(
135
146
  "button",
136
147
  {
137
148
  type: "button",
138
149
  role: "menuitem",
139
150
  "aria-haspopup": (t = e.options) != null && t.length ? "menu" : void 0,
140
- style: W,
141
- onMouseEnter: (i) => T(e, i.currentTarget),
142
- onFocus: (i) => T(e, i.currentTarget),
151
+ style: Y,
152
+ onMouseEnter: (o) => O(e, o.currentTarget),
153
+ onFocus: (o) => O(e, o.currentTarget),
143
154
  onClick: () => {
144
- var i;
145
- return (i = e.options) != null && i.length ? z(e, e.options[0]) : z(e);
155
+ var o;
156
+ return (o = e.options) != null && o.length ? z(e, e.options[0]) : z(e);
146
157
  },
147
158
  children: [
148
- e.iconSrc ? /* @__PURE__ */ n(B, { src: e.iconSrc, name: e.label, size: 14 }) : null,
159
+ e.iconSrc ? /* @__PURE__ */ l(_, { src: e.iconSrc, name: e.label, size: 14 }) : null,
149
160
  e.label,
150
- e.value === c ? /* @__PURE__ */ n("span", { style: A, children: /* @__PURE__ */ n(D, { size: 11 }) }) : null,
151
- (o = e.options) != null && o.length ? /* @__PURE__ */ n(
161
+ e.value === u ? /* @__PURE__ */ l("span", { style: j, children: /* @__PURE__ */ l(N, { size: 11 }) }) : null,
162
+ (r = e.options) != null && r.length ? /* @__PURE__ */ l(
152
163
  "span",
153
164
  {
154
165
  style: {
155
- marginLeft: e.value === c ? 4 : "auto",
166
+ marginLeft: e.value === u ? 4 : "auto",
156
167
  display: "inline-flex",
157
168
  color: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
158
169
  },
159
- children: /* @__PURE__ */ n(oe, { size: 10 })
170
+ children: /* @__PURE__ */ l(ue, { size: 10 })
160
171
  }
161
172
  ) : null
162
173
  ]
@@ -166,23 +177,23 @@ const h = 8, _ = 220, P = 240, N = (r, c) => ({
166
177
  })
167
178
  }
168
179
  ),
169
- (O = f == null ? void 0 : f.options) != null && O.length ? /* @__PURE__ */ n(
180
+ (T = m == null ? void 0 : m.options) != null && T.length ? /* @__PURE__ */ l(
170
181
  "div",
171
182
  {
172
- ref: w,
183
+ ref: R,
173
184
  role: "menu",
174
- "aria-label": `${f.label} options`,
175
- ...q,
176
- style: N(V, P),
177
- children: f.options.map((e) => /* @__PURE__ */ v(
185
+ "aria-label": `${m.label} options`,
186
+ ...Z,
187
+ style: F(Q, P),
188
+ children: m.options.map((e) => /* @__PURE__ */ w(
178
189
  "button",
179
190
  {
180
191
  type: "button",
181
192
  role: "menuitem",
182
- style: { ...W, alignItems: "flex-start" },
183
- onClick: () => z(f, e),
193
+ style: { ...Y, alignItems: "flex-start" },
194
+ onClick: () => z(m, e),
184
195
  children: [
185
- /* @__PURE__ */ v(
196
+ /* @__PURE__ */ w(
186
197
  "span",
187
198
  {
188
199
  style: {
@@ -192,11 +203,11 @@ const h = 8, _ = 220, P = 240, N = (r, c) => ({
192
203
  },
193
204
  children: [
194
205
  e.label,
195
- e.description ? /* @__PURE__ */ n("span", { style: me, children: e.description }) : null
206
+ e.description ? /* @__PURE__ */ l("span", { style: ve, children: e.description }) : null
196
207
  ]
197
208
  }
198
209
  ),
199
- f.value === c && e.value === F ? /* @__PURE__ */ n("span", { style: A, children: /* @__PURE__ */ n(D, { size: 11 }) }) : null
210
+ m.value === u && e.value === U ? /* @__PURE__ */ l("span", { style: j, children: /* @__PURE__ */ l(N, { size: 11 }) }) : null
200
211
  ]
201
212
  },
202
213
  e.value
@@ -209,7 +220,7 @@ const h = 8, _ = 220, P = 240, N = (r, c) => ({
209
220
  ] });
210
221
  };
211
222
  export {
212
- Pe as ChatModelPicker,
213
- Pe as default
223
+ ke as ChatModelPicker,
224
+ ke as default
214
225
  };
215
226
  //# sourceMappingURL=ChatModelPicker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChatModelPicker.js","sources":["../../../src/components/Chat/ChatModelPicker.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useInsertionEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport Avatar from '../Avatar';\nimport CaretDownIcon from '../CustomIcons/CaretDownIcon';\nimport CaretRightIcon from '../CustomIcons/CaretRightIcon';\nimport CaretUpIcon from '../CustomIcons/CaretUpIcon';\nimport CheckIcon from '../CustomIcons/CheckIcon';\nimport PillButton from '../PillButton';\nimport { pushEscapeLayer } from '../escapeLayers';\nimport { usePopupLayer } from '../overlayLayers';\nimport { useOwnedByPopover } from '../popoverTree';\nimport { ensureOverlayStyles } from '../portalOverlay';\nimport { useTopLayer } from '../topLayer';\nimport { useFollowTrigger } from '../useFollowTrigger';\n\nexport interface ChatModelSubOption {\n value: string;\n label: string;\n description?: string;\n}\n\nexport interface ChatModelOption {\n value: string;\n label: string;\n /** The provider's mark. A URL, since providers ship logos rather than icon fonts. */\n iconSrc?: string;\n /** A second choice the model offers, e.g. how long it may think. */\n options?: ChatModelSubOption[];\n}\n\nexport interface ChatModelPickerProps {\n models: ChatModelOption[];\n value: string;\n /** The chosen sub-option, when the current model offers them. */\n optionValue?: string;\n /** Called with the model, and its sub-option when it has them. */\n onChange: (model: string, option?: string) => void;\n disabled?: boolean;\n /**\n * Opens upward. On by default: this sits under a composer at the bottom of a column, so\n * downward is almost always off-screen.\n */\n openUp?: boolean;\n 'aria-label'?: string;\n}\n\nconst VIEWPORT_PADDING = 8;\nconst PANEL_MIN_WIDTH = 220;\nconst SUBMENU_MIN_WIDTH = 240;\n\n/**\n * Inline rather than Tailwind: the panel is portalled to `document.body`, which the scoped\n * shadow stylesheet does not reach. Same reason `ActionMenu` styles its popover inline.\n */\nconst panelStyle = (\n position: { top: number; left: number } | null,\n minWidth: number,\n): React.CSSProperties => ({\n position: 'fixed',\n top: position?.top ?? 0,\n left: position?.left ?? 0,\n minWidth,\n background: 'var(--malachite-card-background, rgb(255, 255, 255))',\n border: '1px solid var(--malachite-card-border, rgb(232, 232, 232))',\n borderRadius: 12,\n boxShadow: '0px 4px 12px rgba(0, 0, 0, 0.08)',\n padding: 4,\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n visibility: position ? 'visible' : 'hidden',\n opacity: position ? 1 : 0,\n});\n\nconst ROW_STYLE: React.CSSProperties = {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n padding: '6px 10px',\n borderRadius: 8,\n border: 'none',\n background: 'transparent',\n textAlign: 'left',\n width: '100%',\n cursor: 'pointer',\n fontSize: 'var(--malachite-font-size-small, 13px)',\n color: 'var(--malachite-text-primary, rgb(10, 10, 10))',\n};\n\nconst DESCRIPTION_STYLE: React.CSSProperties = {\n fontSize: 'var(--malachite-font-size-xsmall, 11px)',\n color: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n};\n\nconst CHECK_STYLE: React.CSSProperties = {\n marginLeft: 'auto',\n display: 'inline-flex',\n color: 'var(--malachite-text-success, rgb(2, 122, 66))',\n};\n\n/**\n * Which model answers, and how hard it may think.\n *\n * Its own component rather than a `Dropdown`: that one is a form select bound to\n * react-hook-form, and this is a menu whose rows open a second menu. Portalled for the same\n * reason `ActionMenu` is — a panel inside the composer would be clipped by it.\n */\nconst ChatModelPicker: React.FC<ChatModelPickerProps> = ({\n models,\n value,\n optionValue,\n onChange,\n disabled = false,\n openUp = true,\n 'aria-label': ariaLabel = 'Model',\n}) => {\n const [open, setOpen] = useState(false);\n const [position, setPosition] = useState<{ top: number; left: number } | null>(null);\n const [submenuFor, setSubmenuFor] = useState<string | null>(null);\n const [submenuPosition, setSubmenuPosition] = useState<{ top: number; left: number } | null>(\n null,\n );\n const triggerRef = useRef<HTMLDivElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const submenuRef = useRef<HTMLDivElement>(null);\n const panelIdentity = usePopupLayer('actionmenu', open, panelRef);\n const submenuIdentity = usePopupLayer('actionmenu', open, submenuRef);\n\n useTopLayer(panelRef, open);\n useOwnedByPopover(\n useCallback(() => submenuRef.current, []),\n open,\n );\n\n const selected = models.find((model) => model.value === value);\n\n const place = useCallback(() => {\n const trigger = triggerRef.current;\n const panel = panelRef.current;\n\n if (!trigger) {\n return;\n }\n\n const rect = trigger.getBoundingClientRect();\n const width = panel?.offsetWidth || PANEL_MIN_WIDTH;\n const height = panel?.offsetHeight || 0;\n const maxLeft = window.innerWidth - width - VIEWPORT_PADDING;\n const left = Math.max(VIEWPORT_PADDING, Math.min(rect.right - width, maxLeft));\n // Flips when the chosen side has no room, so the panel is never off-screen.\n const above = rect.top - height - 4;\n const below = rect.bottom + 4;\n const fitsAbove = above >= VIEWPORT_PADDING;\n const fitsBelow = height === 0 || below + height <= window.innerHeight - VIEWPORT_PADDING;\n const top = openUp ? (fitsAbove ? above : below) : fitsBelow ? below : above;\n\n setPosition({ top, left });\n }, [openUp]);\n\n // The submenu is placed from its row once; rather than leave it behind as the panel\n // follows the trigger, it closes, and hovering the row opens it again in place.\n const follow = useCallback(() => {\n setSubmenuFor(null);\n setSubmenuPosition(null);\n place();\n }, [place]);\n const close = useCallback(() => setOpen(false), []);\n\n useFollowTrigger(open, triggerRef, follow, close);\n\n useEffect(() => {\n if (!open) {\n setSubmenuFor(null);\n setSubmenuPosition(null);\n return;\n }\n\n place();\n\n const reposition = () => place();\n const closeOnOutside = (event: MouseEvent) => {\n // `composedPath`, not `event.target`: this listener is on `document`, and the\n // trigger lives in a shadow root, so the target is retargeted to the shadow HOST.\n // `contains` then says the trigger was not clicked, the menu closes on mousedown,\n // and the click that follows toggles it straight back open.\n const path = event.composedPath();\n const insideOwnUi = [triggerRef.current, panelRef.current, submenuRef.current].some(\n (node) => node !== null && path.includes(node),\n );\n\n if (!insideOwnUi) {\n setOpen(false);\n }\n };\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n\n window.addEventListener('resize', reposition);\n document.addEventListener('mousedown', closeOnOutside, true);\n\n return () => {\n window.removeEventListener('resize', reposition);\n document.removeEventListener('mousedown', closeOnOutside, true);\n popEscapeLayer();\n };\n }, [open, place]);\n\n useInsertionEffect(() => {\n if (open) {\n ensureOverlayStyles();\n }\n }, [open]);\n\n const openSubmenu = (model: ChatModelOption, row: HTMLElement) => {\n if (!model.options?.length) {\n setSubmenuFor(null);\n return;\n }\n\n const rect = row.getBoundingClientRect();\n const panelLeft = panelRef.current?.getBoundingClientRect().left ?? rect.left;\n // To the left of the parent panel by default, flipping right when that would clip.\n const toLeft = panelLeft - SUBMENU_MIN_WIDTH - 4;\n const left =\n toLeft >= VIEWPORT_PADDING\n ? toLeft\n : Math.min(\n (panelRef.current?.getBoundingClientRect().right ?? rect.right) + 4,\n window.innerWidth - SUBMENU_MIN_WIDTH - VIEWPORT_PADDING,\n );\n\n setSubmenuFor(model.value);\n setSubmenuPosition({ top: rect.top, left });\n };\n\n const choose = (model: ChatModelOption, option?: ChatModelSubOption) => {\n onChange(model.value, option?.value);\n setOpen(false);\n };\n\n const submenuModel = models.find((model) => model.value === submenuFor);\n\n return (\n <>\n <div ref={triggerRef} className=\"inline-flex\">\n <PillButton\n label={selected?.label ?? value}\n icon={\n selected?.iconSrc ? (\n <Avatar src={selected.iconSrc} name={selected.label} size={14} />\n ) : undefined\n }\n trailingIcon={openUp ? <CaretUpIcon size={10} /> : <CaretDownIcon size={10} />}\n shape=\"tab\"\n size=\"small\"\n disabled={disabled}\n onClick={() => setOpen((wasOpen) => !wasOpen)}\n />\n </div>\n {open &&\n createPortal(\n <>\n <div\n ref={panelRef}\n role=\"menu\"\n aria-label={ariaLabel}\n // `actionmenu` rather than a new kind: the identity is a\n // host-facing allow-list, so a new class would need every host to\n // update its CSS, and this panel is an action menu in shape.\n {...panelIdentity}\n style={panelStyle(position, PANEL_MIN_WIDTH)}\n >\n {models.map((model) => (\n <button\n key={model.value}\n type=\"button\"\n role=\"menuitem\"\n aria-haspopup={model.options?.length ? 'menu' : undefined}\n style={ROW_STYLE}\n onMouseEnter={(event) =>\n openSubmenu(model, event.currentTarget)\n }\n onFocus={(event) => openSubmenu(model, event.currentTarget)}\n onClick={() =>\n model.options?.length\n ? choose(model, model.options[0])\n : choose(model)\n }\n >\n {model.iconSrc ? (\n <Avatar src={model.iconSrc} name={model.label} size={14} />\n ) : null}\n {model.label}\n {model.value === value ? (\n <span style={CHECK_STYLE}>\n <CheckIcon size={11} />\n </span>\n ) : null}\n {model.options?.length ? (\n <span\n style={{\n marginLeft: model.value === value ? 4 : 'auto',\n display: 'inline-flex',\n color: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n }}\n >\n <CaretRightIcon size={10} />\n </span>\n ) : null}\n </button>\n ))}\n </div>\n {submenuModel?.options?.length ? (\n <div\n ref={submenuRef}\n role=\"menu\"\n aria-label={`${submenuModel.label} options`}\n {...submenuIdentity}\n style={panelStyle(submenuPosition, SUBMENU_MIN_WIDTH)}\n >\n {submenuModel.options.map((option) => (\n <button\n key={option.value}\n type=\"button\"\n role=\"menuitem\"\n style={{ ...ROW_STYLE, alignItems: 'flex-start' }}\n onClick={() => choose(submenuModel, option)}\n >\n <span\n style={{\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n }}\n >\n {option.label}\n {option.description ? (\n <span style={DESCRIPTION_STYLE}>\n {option.description}\n </span>\n ) : null}\n </span>\n {submenuModel.value === value &&\n option.value === optionValue ? (\n <span style={CHECK_STYLE}>\n <CheckIcon size={11} />\n </span>\n ) : null}\n </button>\n ))}\n </div>\n ) : null}\n </>,\n document.body,\n )}\n </>\n );\n};\n\nexport default ChatModelPicker;\nexport { ChatModelPicker };\n"],"names":["VIEWPORT_PADDING","PANEL_MIN_WIDTH","SUBMENU_MIN_WIDTH","panelStyle","position","minWidth","ROW_STYLE","DESCRIPTION_STYLE","CHECK_STYLE","ChatModelPicker","models","value","optionValue","onChange","disabled","openUp","ariaLabel","open","setOpen","useState","setPosition","submenuFor","setSubmenuFor","submenuPosition","setSubmenuPosition","triggerRef","useRef","panelRef","submenuRef","panelIdentity","usePopupLayer","submenuIdentity","useTopLayer","useOwnedByPopover","useCallback","selected","model","place","trigger","panel","rect","width","height","maxLeft","left","above","below","fitsAbove","fitsBelow","follow","close","useFollowTrigger","useEffect","reposition","closeOnOutside","event","path","node","popEscapeLayer","pushEscapeLayer","useInsertionEffect","ensureOverlayStyles","openSubmenu","row","_a","toLeft","_b","_c","choose","option","submenuModel","jsxs","Fragment","jsx","PillButton","Avatar","CaretUpIcon","CaretDownIcon","wasOpen","createPortal","Check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,GAAiBrB,CAAiB;AAAA,YAEnD,UAAAoE,EAAa,QAAQ,IAAI,CAACD,MACvB,gBAAAE;AAAA,cAAC;AAAA,cAAA;AAAA,gBAEG,MAAK;AAAA,gBACL,MAAK;AAAA,gBACL,OAAO,EAAE,GAAGjE,GAAW,YAAY,aAAA;AAAA,gBACnC,SAAS,MAAM8D,EAAOE,GAAcD,CAAM;AAAA,gBAE1C,UAAA;AAAA,kBAAA,gBAAAE;AAAA,oBAAC;AAAA,oBAAA;AAAA,sBACG,OAAO;AAAA,wBACH,SAAS;AAAA,wBACT,eAAe;AAAA,wBACf,KAAK;AAAA,sBAAA;AAAA,sBAGR,UAAA;AAAA,wBAAAF,EAAO;AAAA,wBACPA,EAAO,cACJ,gBAAAI,EAAC,QAAA,EAAK,OAAOlE,IACR,UAAA8D,EAAO,aACZ,IACA;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAEPC,EAAa,UAAU3D,KACxB0D,EAAO,UAAUzD,IACb,gBAAA6D,EAAC,QAAA,EAAK,OAAOjE,GACT,UAAA,gBAAAiE,EAACO,GAAA,EAAU,MAAM,GAAA,CAAI,GACzB,IACA;AAAA,gBAAA;AAAA,cAAA;AAAA,cAzBCX,EAAO;AAAA,YAAA,CA2BnB;AAAA,UAAA;AAAA,QAAA,IAEL;AAAA,MAAA,GACR;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
1
+ {"version":3,"file":"ChatModelPicker.js","sources":["../../../src/components/Chat/ChatModelPicker.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useInsertionEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport Avatar from '../Avatar';\nimport CaretDownIcon from '../CustomIcons/CaretDownIcon';\nimport CaretRightIcon from '../CustomIcons/CaretRightIcon';\nimport CaretUpIcon from '../CustomIcons/CaretUpIcon';\nimport CheckIcon from '../CustomIcons/CheckIcon';\nimport PillButton from '../PillButton';\nimport { pushEscapeLayer } from '../escapeLayers';\nimport { usePopupLayer } from '../overlayLayers';\nimport { useOwnedByPopover } from '../popoverTree';\nimport { ensureOverlayStyles } from '../portalOverlay';\nimport { useTopLayer } from '../topLayer';\nimport { useFollowTrigger } from '../useFollowTrigger';\n\nexport interface ChatModelSubOption {\n value: string;\n label: string;\n description?: string;\n}\n\nexport interface ChatModelOption {\n value: string;\n label: string;\n /** The provider's mark. A URL, since providers ship logos rather than icon fonts. */\n iconSrc?: string;\n /** A second choice the model offers, e.g. how long it may think. */\n options?: ChatModelSubOption[];\n}\n\nexport interface ChatModelPickerProps {\n models: ChatModelOption[];\n value: string;\n /** The chosen sub-option, when the current model offers them. */\n optionValue?: string;\n /** Called with the model, and its sub-option when it has them. */\n onChange: (model: string, option?: string) => void;\n disabled?: boolean;\n /**\n * Opens upward. On by default: this sits under a composer at the bottom of a column, so\n * downward is almost always off-screen.\n */\n openUp?: boolean;\n 'aria-label'?: string;\n}\n\nconst VIEWPORT_PADDING = 8;\nconst PANEL_MIN_WIDTH = 220;\nconst SUBMENU_MIN_WIDTH = 240;\n\n/**\n * Inline rather than Tailwind: the panel is portalled to `document.body`, which the scoped\n * shadow stylesheet does not reach. Same reason `ActionMenu` styles its popover inline.\n */\nconst panelStyle = (\n position: { top: number; left: number; maxHeight?: number } | null,\n minWidth: number,\n): React.CSSProperties => ({\n position: 'fixed',\n top: position?.top ?? 0,\n left: position?.left ?? 0,\n maxHeight: position?.maxHeight,\n overflowY: position?.maxHeight === undefined ? undefined : 'auto',\n minWidth,\n background: 'var(--malachite-card-background, rgb(255, 255, 255))',\n border: '1px solid var(--malachite-card-border, rgb(232, 232, 232))',\n borderRadius: 12,\n boxShadow: '0px 4px 12px rgba(0, 0, 0, 0.08)',\n padding: 4,\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n visibility: position ? 'visible' : 'hidden',\n opacity: position ? 1 : 0,\n});\n\nconst ROW_STYLE: React.CSSProperties = {\n display: 'flex',\n alignItems: 'center',\n gap: 8,\n padding: '6px 10px',\n borderRadius: 8,\n border: 'none',\n background: 'transparent',\n textAlign: 'left',\n width: '100%',\n cursor: 'pointer',\n fontSize: 'var(--malachite-font-size-small, 13px)',\n color: 'var(--malachite-text-primary, rgb(10, 10, 10))',\n};\n\nconst DESCRIPTION_STYLE: React.CSSProperties = {\n fontSize: 'var(--malachite-font-size-xsmall, 11px)',\n color: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n};\n\nconst CHECK_STYLE: React.CSSProperties = {\n marginLeft: 'auto',\n display: 'inline-flex',\n color: 'var(--malachite-text-success, rgb(2, 122, 66))',\n};\n\n/**\n * Which model answers, and how hard it may think.\n *\n * Its own component rather than a `Dropdown`: that one is a form select bound to\n * react-hook-form, and this is a menu whose rows open a second menu. Portalled for the same\n * reason `ActionMenu` is — a panel inside the composer would be clipped by it.\n */\nconst ChatModelPicker: React.FC<ChatModelPickerProps> = ({\n models,\n value,\n optionValue,\n onChange,\n disabled = false,\n openUp = true,\n 'aria-label': ariaLabel = 'Model',\n}) => {\n const [open, setOpen] = useState(false);\n const [position, setPosition] = useState<{\n top: number;\n left: number;\n maxHeight: number;\n } | null>(null);\n const [submenuFor, setSubmenuFor] = useState<string | null>(null);\n const [submenuPosition, setSubmenuPosition] = useState<{ top: number; left: number } | null>(\n null,\n );\n const triggerRef = useRef<HTMLDivElement>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const submenuRef = useRef<HTMLDivElement>(null);\n const submenuRowRef = useRef<HTMLElement | null>(null);\n const panelIdentity = usePopupLayer('actionmenu', open, panelRef);\n const submenuIdentity = usePopupLayer('actionmenu', open, submenuRef);\n\n useTopLayer(panelRef, open);\n useOwnedByPopover(\n useCallback(() => submenuRef.current, []),\n open,\n );\n\n const selected = models.find((model) => model.value === value);\n\n const place = useCallback(() => {\n const trigger = triggerRef.current;\n const panel = panelRef.current;\n\n if (!trigger) {\n return;\n }\n\n const rect = trigger.getBoundingClientRect();\n const width = panel?.offsetWidth || PANEL_MIN_WIDTH;\n // `scrollHeight`, not `offsetHeight`: once capped, the panel's own height says nothing\n // about whether the whole list would now fit. The difference is its border.\n const height = panel ? panel.scrollHeight + panel.offsetHeight - panel.clientHeight : 0;\n const maxLeft = window.innerWidth - width - VIEWPORT_PADDING;\n const left = Math.max(VIEWPORT_PADDING, Math.min(rect.right - width, maxLeft));\n const roomAbove = rect.top - 4 - VIEWPORT_PADDING;\n const roomBelow = window.innerHeight - rect.bottom - 4 - VIEWPORT_PADDING;\n const preferred = openUp ? roomAbove : roomBelow;\n const other = openUp ? roomBelow : roomAbove;\n // Flips when the chosen side has no room. With no room on either, it takes the side with\n // more and scrolls, so the panel is never off-screen however long the list.\n const flips = height > preferred && other > preferred;\n const goesUp = openUp !== flips;\n const room = goesUp ? roomAbove : roomBelow;\n const top = goesUp ? rect.top - 4 - Math.min(height, room) : rect.bottom + 4;\n\n setPosition({ top, left, maxHeight: room });\n }, [openUp]);\n\n // Rather than leave the submenu behind as the panel follows the trigger, it closes, and\n // hovering the row opens it again in place. Scrolling inside the panel is `followRowOnScroll`.\n const follow = useCallback(() => {\n setSubmenuFor(null);\n setSubmenuPosition(null);\n place();\n }, [place]);\n const close = useCallback(() => setOpen(false), []);\n\n useFollowTrigger(open, triggerRef, follow, close);\n\n useEffect(() => {\n if (!open) {\n setSubmenuFor(null);\n setSubmenuPosition(null);\n return;\n }\n\n place();\n\n const reposition = () => place();\n const closeOnOutside = (event: MouseEvent) => {\n // `composedPath`, not `event.target`: this listener is on `document`, and the\n // trigger lives in a shadow root, so the target is retargeted to the shadow HOST.\n // `contains` then says the trigger was not clicked, the menu closes on mousedown,\n // and the click that follows toggles it straight back open.\n const path = event.composedPath();\n const insideOwnUi = [triggerRef.current, panelRef.current, submenuRef.current].some(\n (node) => node !== null && path.includes(node),\n );\n\n if (!insideOwnUi) {\n setOpen(false);\n }\n };\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n\n window.addEventListener('resize', reposition);\n document.addEventListener('mousedown', closeOnOutside, true);\n\n return () => {\n window.removeEventListener('resize', reposition);\n document.removeEventListener('mousedown', closeOnOutside, true);\n popEscapeLayer();\n };\n }, [open, place]);\n\n useInsertionEffect(() => {\n if (open) {\n ensureOverlayStyles();\n }\n }, [open]);\n\n const openSubmenu = (model: ChatModelOption, row: HTMLElement) => {\n if (!model.options?.length) {\n setSubmenuFor(null);\n return;\n }\n\n const rect = row.getBoundingClientRect();\n const panelLeft = panelRef.current?.getBoundingClientRect().left ?? rect.left;\n // To the left of the parent panel by default, flipping right when that would clip.\n const toLeft = panelLeft - SUBMENU_MIN_WIDTH - 4;\n const left =\n toLeft >= VIEWPORT_PADDING\n ? toLeft\n : Math.min(\n (panelRef.current?.getBoundingClientRect().right ?? rect.right) + 4,\n window.innerWidth - SUBMENU_MIN_WIDTH - VIEWPORT_PADDING,\n );\n\n submenuRowRef.current = row;\n setSubmenuFor(model.value);\n setSubmenuPosition({ top: rect.top, left });\n };\n\n // The submenu goes with its row, and closes once the row has left the panel. Not closed\n // outright: tabbing to a row out of view opens its submenu and then scrolls it in, and closing\n // on that scroll would leave the row's efforts out of reach of the keyboard.\n const followRowOnScroll = () => {\n const row = submenuRowRef.current?.getBoundingClientRect();\n const panel = panelRef.current?.getBoundingClientRect();\n\n if (!row || !panel || row.top < panel.top || row.bottom > panel.bottom) {\n setSubmenuFor(null);\n setSubmenuPosition(null);\n return;\n }\n\n setSubmenuPosition((current) => current && { ...current, top: row.top });\n };\n\n const choose = (model: ChatModelOption, option?: ChatModelSubOption) => {\n onChange(model.value, option?.value);\n setOpen(false);\n };\n\n const submenuModel = models.find((model) => model.value === submenuFor);\n\n return (\n <>\n <div ref={triggerRef} className=\"inline-flex\">\n <PillButton\n label={selected?.label ?? value}\n icon={\n selected?.iconSrc ? (\n <Avatar src={selected.iconSrc} name={selected.label} size={14} />\n ) : undefined\n }\n trailingIcon={openUp ? <CaretUpIcon size={10} /> : <CaretDownIcon size={10} />}\n shape=\"tab\"\n size=\"small\"\n disabled={disabled}\n onClick={() => setOpen((wasOpen) => !wasOpen)}\n />\n </div>\n {open &&\n createPortal(\n <>\n <div\n ref={panelRef}\n role=\"menu\"\n aria-label={ariaLabel}\n // `actionmenu` rather than a new kind: the identity is a\n // host-facing allow-list, so a new class would need every host to\n // update its CSS, and this panel is an action menu in shape.\n {...panelIdentity}\n style={panelStyle(position, PANEL_MIN_WIDTH)}\n onScroll={followRowOnScroll}\n >\n {models.map((model) => (\n <button\n key={model.value}\n type=\"button\"\n role=\"menuitem\"\n aria-haspopup={model.options?.length ? 'menu' : undefined}\n style={ROW_STYLE}\n onMouseEnter={(event) =>\n openSubmenu(model, event.currentTarget)\n }\n onFocus={(event) => openSubmenu(model, event.currentTarget)}\n onClick={() =>\n model.options?.length\n ? choose(model, model.options[0])\n : choose(model)\n }\n >\n {model.iconSrc ? (\n <Avatar src={model.iconSrc} name={model.label} size={14} />\n ) : null}\n {model.label}\n {model.value === value ? (\n <span style={CHECK_STYLE}>\n <CheckIcon size={11} />\n </span>\n ) : null}\n {model.options?.length ? (\n <span\n style={{\n marginLeft: model.value === value ? 4 : 'auto',\n display: 'inline-flex',\n color: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n }}\n >\n <CaretRightIcon size={10} />\n </span>\n ) : null}\n </button>\n ))}\n </div>\n {submenuModel?.options?.length ? (\n <div\n ref={submenuRef}\n role=\"menu\"\n aria-label={`${submenuModel.label} options`}\n {...submenuIdentity}\n style={panelStyle(submenuPosition, SUBMENU_MIN_WIDTH)}\n >\n {submenuModel.options.map((option) => (\n <button\n key={option.value}\n type=\"button\"\n role=\"menuitem\"\n style={{ ...ROW_STYLE, alignItems: 'flex-start' }}\n onClick={() => choose(submenuModel, option)}\n >\n <span\n style={{\n display: 'flex',\n flexDirection: 'column',\n gap: 2,\n }}\n >\n {option.label}\n {option.description ? (\n <span style={DESCRIPTION_STYLE}>\n {option.description}\n </span>\n ) : null}\n </span>\n {submenuModel.value === value &&\n option.value === optionValue ? (\n <span style={CHECK_STYLE}>\n <CheckIcon size={11} />\n </span>\n ) : null}\n </button>\n ))}\n </div>\n ) : null}\n </>,\n document.body,\n )}\n </>\n );\n};\n\nexport default ChatModelPicker;\nexport { ChatModelPicker };\n"],"names":["VIEWPORT_PADDING","PANEL_MIN_WIDTH","SUBMENU_MIN_WIDTH","panelStyle","position","minWidth","ROW_STYLE","DESCRIPTION_STYLE","CHECK_STYLE","ChatModelPicker","models","value","optionValue","onChange","disabled","openUp","ariaLabel","open","setOpen","useState","setPosition","submenuFor","setSubmenuFor","submenuPosition","setSubmenuPosition","triggerRef","useRef","panelRef","submenuRef","submenuRowRef","panelIdentity","usePopupLayer","submenuIdentity","useTopLayer","useOwnedByPopover","useCallback","selected","model","place","trigger","panel","rect","width","height","maxLeft","left","roomAbove","roomBelow","preferred","other","flips","goesUp","room","top","follow","close","useFollowTrigger","useEffect","reposition","closeOnOutside","event","path","node","popEscapeLayer","pushEscapeLayer","useInsertionEffect","ensureOverlayStyles","openSubmenu","row","_a","toLeft","_b","_c","followRowOnScroll","current","choose","option","submenuModel","jsxs","Fragment","jsx","PillButton","Avatar","CaretUpIcon","CaretDownIcon","wasOpen","createPortal","CheckIcon","CaretRightIcon"],"mappings":";;;;;;;;;;;;;;;AA8CA,MAAMA,IAAmB,GACnBC,IAAkB,KAClBC,IAAoB,KAMpBC,IAAa,CACfC,GACAC,OACuB;AAAA,EACvB,UAAU;AAAA,EACV,MAAKD,KAAA,gBAAAA,EAAU,QAAO;AAAA,EACtB,OAAMA,KAAA,gBAAAA,EAAU,SAAQ;AAAA,EACxB,WAAWA,KAAA,gBAAAA,EAAU;AAAA,EACrB,YAAWA,KAAA,gBAAAA,EAAU,eAAc,SAAY,SAAY;AAAA,EAC3D,UAAAC;AAAA,EACA,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAS;AAAA,EACT,eAAe;AAAA,EACf,KAAK;AAAA,EACL,YAAYD,IAAW,YAAY;AAAA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