rift-ds 1.31.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +1 -1
  2. package/behaviors/chat-card.css +4 -1
  3. package/behaviors/deferComponent.d.ts +43 -0
  4. package/behaviors/deferComponent.js +35 -0
  5. package/bin/templates/blocks/components/blocks/AppShell.module.css +10 -1
  6. package/chat/ChatLauncher.d.ts +9 -1
  7. package/chat/ChatLauncher.js +51 -33
  8. package/chat/ChatWidget.css +13 -4
  9. package/chat/ChatWidget.js +15 -15
  10. package/chat/deferredChatWidget.d.ts +10 -0
  11. package/chat/deferredChatWidget.js +10 -0
  12. package/chat/index.d.ts +1 -0
  13. package/chat/index.js +2 -0
  14. package/chat/registry.json.d.ts +2 -1
  15. package/chat/registry.json.js +1 -1
  16. package/components/Accordion/Accordion.css +8 -0
  17. package/components/AgentPlan/AgentPlan.css +8 -0
  18. package/components/AgentRail/AgentRail.css +3 -3
  19. package/components/AiButton/AiButton.css +19 -0
  20. package/components/AiButton/AiButton.d.ts +10 -1
  21. package/components/AiButton/AiButton.js +6 -1
  22. package/components/ArtifactPanel/ArtifactPanel.js +5 -5
  23. package/components/Attachment/AttachmentViewer.js +7 -7
  24. package/components/BentoTile/BentoTile.css +1 -1
  25. package/components/BentoTile/BentoTile.js +5 -5
  26. package/components/Button/Button.css +28 -1
  27. package/components/Button/Button.d.ts +7 -2
  28. package/components/Button/Button.js +7 -3
  29. package/components/ChatHeader/ChatHeader.d.ts +1 -1
  30. package/components/ChatThread/ChatThread.css +1 -1
  31. package/components/Chip/Chip.css +26 -0
  32. package/components/CircularButton/CircularButton.d.ts +16 -96
  33. package/components/CircularButton/CircularButton.js +11 -94
  34. package/components/Combobox/Combobox.css +12 -0
  35. package/components/CommandPalette/CommandPalette.css +1 -1
  36. package/components/CommandPalette/CommandPalette.js +3 -3
  37. package/components/CommandPaletteTrigger/CommandPaletteTrigger.css +9 -0
  38. package/components/CommandPaletteTrigger/CommandPaletteTrigger.d.ts +10 -2
  39. package/components/CommandPaletteTrigger/CommandPaletteTrigger.js +7 -2
  40. package/components/Composer/Composer.css +3 -3
  41. package/components/Composer/Composer.js +9 -9
  42. package/components/ContextMenu/ContextMenu.css +24 -0
  43. package/components/DataTable/DataTable.css +2 -2
  44. package/components/DataTable/DataTable.js +15 -15
  45. package/components/DateInput/DateInput.css +20 -0
  46. package/components/DescriptionList/DescriptionListCopy.d.ts +1 -1
  47. package/components/DescriptionList/DescriptionListCopy.js +3 -3
  48. package/components/Dialog/Dialog.css +1 -1
  49. package/components/Dialog/Dialog.js +3 -3
  50. package/components/DocumentChip/DocumentChip.css +12 -0
  51. package/components/DocumentViewer/DocumentViewer.js +10 -10
  52. package/components/Drawer/Drawer.css +1 -1
  53. package/components/Drawer/Drawer.js +3 -3
  54. package/components/Dropdown/Dropdown.css +30 -0
  55. package/components/DropdownMenu/DropdownMenu.css +24 -0
  56. package/components/FileInput/FileInput.css +9 -0
  57. package/components/FilterBar/FilterBar.css +12 -0
  58. package/components/{CircularButton/CircularButton.css → IconButton/IconButton.css} +91 -81
  59. package/components/IconButton/IconButton.d.ts +108 -0
  60. package/components/IconButton/IconButton.js +101 -0
  61. package/components/Input/Input.css +53 -0
  62. package/components/Input/Input.js +3 -3
  63. package/components/MaskedInput/MaskedInput.js +3 -3
  64. package/components/ModelPicker/ModelPicker.css +12 -1
  65. package/components/NavList/NavList.css +1 -1
  66. package/components/Pagination/Pagination.css +1 -1
  67. package/components/QuestionCard/QuestionCard.js +3 -3
  68. package/components/RadioButton/RadioButton.css +14 -12
  69. package/components/RichDropdown/RichDropdown.css +7 -0
  70. package/components/SegmentedControl/SegmentedControl.css +16 -5
  71. package/components/SegmentedControl/SegmentedControl.js +7 -4
  72. package/components/SiteHeader/SiteHeader.css +12 -5
  73. package/components/SiteHeader/SiteHeader.js +3 -3
  74. package/components/SourceTrail/SourceTrail.css +8 -0
  75. package/components/SplitButton/SplitButton.css +14 -14
  76. package/components/SplitButton/SplitButton.js +3 -3
  77. package/components/TableToolbar/TableToolbar.css +2 -2
  78. package/components/TableToolbar/TableToolbar.js +36 -37
  79. package/components/ThreadPanel/ThreadPanel.css +8 -0
  80. package/components/ThreadTabs/ThreadTabs.css +7 -0
  81. package/components/TimePicker/TimePicker.css +12 -0
  82. package/components/ToolCall/ToolCall.css +8 -0
  83. package/components/Tooltip/Tooltip.js +3 -2
  84. package/components/WorldMap/WorldMap.js +5 -5
  85. package/components/registry.d.ts +3 -1
  86. package/components/registry.json +19 -10
  87. package/components/registry.json.d.ts +19 -10
  88. package/components/registry.json.js +1 -1
  89. package/index.d.ts +1 -0
  90. package/index.js +2 -0
  91. package/package.json +6 -2
package/README.md CHANGED
@@ -118,7 +118,7 @@ import 'rift-ds/tokens/presets/presets.css';
118
118
  <summary>The full list</summary>
119
119
 
120
120
  <!-- component-list:start -->
121
- Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Checklist · Chip · Circular button · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Currency input · Data table · Date input · Date picker · Date range picker · Deadline · Decision row · Description list · Dialog · Divider · Document chip · Document viewer · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Error summary · Event calendar · Field · Figure · File input · File row · Filter bar · Form section · Funnel chart · Gantt chart · Gauge · Globe · Grid · Heading · Hover card · Icon · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link · Link list · List · Map callout · Map legend · Masked input · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Org chart · Page header · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Resource timeline · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Shader scene · Sidebar panel · Signature pad · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stack · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Text · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · Wizard · World map
121
+ Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Checklist · Chip · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Currency input · Data table · Date input · Date picker · Date range picker · Deadline · Decision row · Description list · Dialog · Divider · Document chip · Document viewer · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Error summary · Event calendar · Field · Figure · File input · File row · Filter bar · Form section · Funnel chart · Gantt chart · Gauge · Globe · Grid · Heading · Hover card · Icon · Icon button · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link · Link list · List · Map callout · Map legend · Masked input · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Org chart · Page header · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Resource timeline · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Shader scene · Sidebar panel · Signature pad · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stack · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Text · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · Wizard · World map
122
122
  <!-- component-list:end -->
123
123
 
124
124
  </details>
@@ -106,7 +106,10 @@
106
106
  align-items: center;
107
107
  gap: var(--gap-200);
108
108
  height: var(--control-height-compact);
109
- padding: 0 var(--padding-300);
109
+ /* Compact Button's padding, with its icon side rule: the leading icon's
110
+ edge takes the step below the text side (12 → 8). */
111
+ padding-block: 0;
112
+ padding-inline: var(--padding-200) var(--padding-300);
110
113
  border-radius: var(--radius-pill);
111
114
  background-color: var(--ds-chat-card-readout-bg);
112
115
  color: var(--ds-chat-card-readout-text);
@@ -0,0 +1,43 @@
1
+ import { ComponentType, LazyExoticComponent } from 'react';
2
+ export interface DeferredComponent<Props> {
3
+ /** The component, loaded when it first renders. Render it inside a Suspense. */
4
+ Component: LazyExoticComponent<ComponentType<Props>>;
5
+ /**
6
+ * Start the load now. Safe to call any number of times, and to pass as an
7
+ * event handler: it takes no arguments, returns nothing and never throws.
8
+ */
9
+ preload: () => void;
10
+ }
11
+ /**
12
+ * A component that loads when it first renders, and a `preload` that starts
13
+ * the load early.
14
+ *
15
+ * `load` resolves to the component itself, so a named export is picked out
16
+ * of its module where the import is written:
17
+ *
18
+ * ```tsx
19
+ * const DeferredPanel = deferComponent<PanelProps>(() =>
20
+ * import('./Panel').then((module) => module.Panel),
21
+ * );
22
+ * ```
23
+ *
24
+ * A failed `preload` is not an error: the next `preload`, or the first
25
+ * render, asks again. A load that fails once the component has rendered is
26
+ * one: like any lazy component, it is thrown to the nearest error boundary,
27
+ * and stays failed there.
28
+ */
29
+ export declare function deferComponent<Props>(load: () => Promise<ComponentType<Props>>): DeferredComponent<Props>;
30
+ /**
31
+ * Call `preload` as soon as the page is interactive: in the browser's first
32
+ * idle moment after this component mounts, and no later than a short
33
+ * deadline if the page never goes idle. It runs once per mount, and calls
34
+ * the latest function it was given, so an inline function is fine.
35
+ *
36
+ * Waiting for the page to finish loading and then go idle was tried first
37
+ * and measured: on a slow phone the page stays busy for seconds, the
38
+ * preload started late and then queued behind everything else the page
39
+ * fetches after load, and a first press arrived before the code did. The
40
+ * code is off the page's critical path either way; what matters is that
41
+ * its fetch starts early.
42
+ */
43
+ export declare function usePreloadWhenIdle(preload: () => void): void;
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { lazy, useRef, useEffect } from "react";
3
+ function deferComponent(load) {
4
+ let pending;
5
+ const start = () => pending ??= load().then((component) => ({ default: component }));
6
+ return {
7
+ Component: lazy(start),
8
+ preload: () => {
9
+ start().catch(() => {
10
+ pending = void 0;
11
+ });
12
+ }
13
+ };
14
+ }
15
+ const PRELOAD_DEADLINE_MS = 300;
16
+ function usePreloadWhenIdle(preload) {
17
+ const latest = useRef(preload);
18
+ useEffect(() => {
19
+ latest.current = preload;
20
+ });
21
+ useEffect(() => {
22
+ if (navigator.connection?.saveData) return;
23
+ const run = () => latest.current();
24
+ if (typeof window.requestIdleCallback === "function") {
25
+ const idle = window.requestIdleCallback(run, { timeout: PRELOAD_DEADLINE_MS });
26
+ return () => window.cancelIdleCallback(idle);
27
+ }
28
+ const timer = window.setTimeout(run, 1);
29
+ return () => window.clearTimeout(timer);
30
+ }, []);
31
+ }
32
+ export {
33
+ deferComponent,
34
+ usePreloadWhenIdle
35
+ };
@@ -150,6 +150,13 @@
150
150
  display: none;
151
151
  }
152
152
 
153
+ /* An icon-only control wears a tooltip, which wraps it: the wrapper leaves
154
+ the row with the control, or it would hold a gap open. */
155
+ .topBarActions :global(.ds-tooltip):has(> .searchIcon),
156
+ .topBarActions :global(.ds-tooltip):has(> .aiIcon) {
157
+ display: none;
158
+ }
159
+
153
160
  .topBarActions {
154
161
  display: flex;
155
162
  align-items: center;
@@ -221,7 +228,9 @@
221
228
  }
222
229
 
223
230
  .searchIcon,
224
- .aiIcon {
231
+ .aiIcon,
232
+ .topBarActions :global(.ds-tooltip):has(> .searchIcon),
233
+ .topBarActions :global(.ds-tooltip):has(> .aiIcon) {
225
234
  display: inline-flex;
226
235
  }
227
236
 
@@ -34,6 +34,8 @@ export interface ChatLauncherProps {
34
34
  * the chat from a control of its own, such as an AiButton in its top bar:
35
35
  * that control calls `setOpen(true)` from `useChatWidget()` and sets
36
36
  * `returnFocusRef.current` to itself, so closing the panel hands focus back.
37
+ * It also calls `preloadChatWidget` on hover and focus, as the floating
38
+ * button does.
37
39
  */
38
40
  fab?: boolean;
39
41
  /** The panel's DOM id, for a host control's `aria-controls`. */
@@ -48,6 +50,12 @@ export interface ChatLauncherProps {
48
50
  panelLabel?: string;
49
51
  /** The words of the floating button's summary panel, over AiButton's English defaults: the panel's name, given the summary's title ("Summary: <title>"), its dismiss button ("Dismiss summary") and its chips' group ("Suggested prompts"). */
50
52
  aiButtonLabels?: Pick<AiButtonProps, 'summaryRegionLabel' | 'dismissLabel' | 'suggestionsLabel'>;
53
+ /**
54
+ * Accessible name of the spinner the panel shows while the chat's code is
55
+ * still arriving: the panel was opened before the preload finished, or the
56
+ * visitor asked to save data and nothing was preloaded.
57
+ */
58
+ loadingLabel?: string;
51
59
  /** Everything the widget takes. The launcher sets the responsive ones itself. */
52
60
  widget?: Omit<ChatWidgetProps, 'fullscreenEnabled' | 'placementEnabled' | 'compact' | 'phone'>;
53
61
  /** Rendered inside the panel after the widget: for a host's extra chrome. */
@@ -89,4 +97,4 @@ export interface ChatLauncherProps {
89
97
  * edge gap on the docked side. The panel's geometry reads `--ds-chat-width`,
90
98
  * `--ds-chat-inset` and `--ds-chat-float-height`, defaulted on `:root`.
91
99
  */
92
- export declare function ChatLauncher({ label, icon, summary, hidden, panelId, hostAttribute, panelLabel, aiButtonLabels, widget, children, surface, fab, }: ChatLauncherProps): import("react").JSX.Element | null;
100
+ export declare function ChatLauncher({ label, icon, summary, hidden, panelId, hostAttribute, panelLabel, aiButtonLabels, loadingLabel, widget, children, surface, fab, }: ChatLauncherProps): import("react").JSX.Element | null;
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useSyncExternalStore, useLayoutEffect, useRef, useEffect, useState } from "react";
3
+ import { useSyncExternalStore, useLayoutEffect, useRef, useEffect, useState, Suspense } from "react";
4
+ import { usePreloadWhenIdle } from "../behaviors/deferComponent.js";
4
5
  import { useScrollLock } from "../behaviors/useScrollLock.js";
5
6
  import { AiButton } from "../components/AiButton/AiButton.js";
6
- import { ChatWidget } from "./ChatWidget.js";
7
+ import { Spinner } from "../components/Spinner/Spinner.js";
7
8
  import { useChatAgentState } from "./agentState.js";
8
9
  import { useChatWidget } from "./context.js";
10
+ import { DeferredChatWidget } from "./deferredChatWidget.js";
9
11
  import { isFloatDragStart, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, dockWidthFromDrag, clampFloatPosition } from "./placement.js";
10
12
  import { useDockViewport, TAKEOVER_QUERY } from "./queries.js";
11
13
  import { keepFittingSuggestions } from "./suggestions.js";
@@ -43,6 +45,7 @@ function ChatLauncher({
43
45
  hostAttribute = "data-chat",
44
46
  panelLabel = "Chat",
45
47
  aiButtonLabels,
48
+ loadingLabel = "Loading chat",
46
49
  widget,
47
50
  children,
48
51
  surface = "raised",
@@ -50,6 +53,7 @@ function ChatLauncher({
50
53
  }) {
51
54
  const { open, setOpen, panelPhase, view, side, floating, returnFocusRef, send } = useChatWidget();
52
55
  const agentState = useChatAgentState();
56
+ usePreloadWhenIdle(DeferredChatWidget.preload);
53
57
  const launchSuggestion = (id) => {
54
58
  const chip = summary?.chips?.find((c) => c.id === id);
55
59
  if (!chip) return;
@@ -248,33 +252,41 @@ function ChatLauncher({
248
252
  if (hidden) return null;
249
253
  if (!renderPanel) {
250
254
  if (!fab) return null;
251
- return /* @__PURE__ */ jsx("div", { className: "ds-chat-launcher__fab", children: /* @__PURE__ */ jsx(
252
- AiButton,
255
+ return /* @__PURE__ */ jsx(
256
+ "div",
253
257
  {
254
- ...aiButtonLabels,
255
- label,
256
- icon,
257
- state: agentState,
258
- "aria-expanded": false,
259
- "aria-controls": panelId,
260
- summary: summary ? {
261
- overline: summary.overline,
262
- title: summary.title,
263
- caption: summary.caption,
264
- text: summary.text,
265
- suggestions: keepFittingSuggestions(
266
- summary.suggestions ?? summary.chips?.map(({ id, label: chipLabel }) => ({ id, label: chipLabel })) ?? [],
267
- (chip) => chip.label,
268
- "ChatLauncher summary chips"
269
- )
270
- } : void 0,
271
- onSummarySuggestion: launchSuggestion,
272
- onClick: (event) => {
273
- returnFocusRef.current = event.currentTarget;
274
- setOpen(true);
275
- }
258
+ className: "ds-chat-launcher__fab",
259
+ onPointerEnter: DeferredChatWidget.preload,
260
+ onFocusCapture: DeferredChatWidget.preload,
261
+ children: /* @__PURE__ */ jsx(
262
+ AiButton,
263
+ {
264
+ ...aiButtonLabels,
265
+ label,
266
+ icon,
267
+ state: agentState,
268
+ "aria-expanded": false,
269
+ "aria-controls": panelId,
270
+ summary: summary ? {
271
+ overline: summary.overline,
272
+ title: summary.title,
273
+ caption: summary.caption,
274
+ text: summary.text,
275
+ suggestions: keepFittingSuggestions(
276
+ summary.suggestions ?? summary.chips?.map(({ id, label: chipLabel }) => ({ id, label: chipLabel })) ?? [],
277
+ (chip) => chip.label,
278
+ "ChatLauncher summary chips"
279
+ )
280
+ } : void 0,
281
+ onSummarySuggestion: launchSuggestion,
282
+ onClick: (event) => {
283
+ returnFocusRef.current = event.currentTarget;
284
+ setOpen(true);
285
+ }
286
+ }
287
+ )
276
288
  }
277
- ) });
289
+ );
278
290
  }
279
291
  const handleKeyDown = (event) => {
280
292
  if (event.key === "Escape") {
@@ -336,13 +348,19 @@ function ChatLauncher({
336
348
  onKeyDown: handleKeyDown,
337
349
  children: [
338
350
  /* @__PURE__ */ jsx(
339
- ChatWidget,
351
+ Suspense,
340
352
  {
341
- ...widget,
342
- fullscreenEnabled: !takeover,
343
- placementEnabled: !takeover,
344
- compact: takeover || !isFull,
345
- phone: takeover
353
+ fallback: /* @__PURE__ */ jsx("div", { className: "ds-chat-launcher__loading", children: /* @__PURE__ */ jsx(Spinner, { size: "lg", tone: "neutral", label: loadingLabel }) }),
354
+ children: /* @__PURE__ */ jsx(
355
+ DeferredChatWidget.Component,
356
+ {
357
+ ...widget,
358
+ fullscreenEnabled: !takeover,
359
+ placementEnabled: !takeover,
360
+ compact: takeover || !isFull,
361
+ phone: takeover
362
+ }
363
+ )
346
364
  }
347
365
  ),
348
366
  children,
@@ -78,8 +78,8 @@
78
78
  display: none;
79
79
  }
80
80
 
81
- .ds-chat-widget__placement-menu .ds-circular-button[aria-expanded="true"],
82
- .ds-chat-widget__placement-menu .ds-circular-button[aria-expanded="true"]:hover {
81
+ .ds-chat-widget__placement-menu .ds-icon-button[aria-expanded="true"],
82
+ .ds-chat-widget__placement-menu .ds-icon-button[aria-expanded="true"]:hover {
83
83
  background-color: var(--color-action-passive-bg-hover);
84
84
  }
85
85
 
@@ -1025,8 +1025,8 @@
1025
1025
  /* The agent toggle's on-state: the passive wash, held down while the panel
1026
1026
  is up. Paired with the library class so it beats the variant's resting
1027
1027
  background whatever order the stylesheets load in. */
1028
- .ds-circular-button.ds-chat-widget__agent-toggle--on,
1029
- .ds-circular-button.ds-chat-widget__agent-toggle--on:hover {
1028
+ .ds-icon-button.ds-chat-widget__agent-toggle--on,
1029
+ .ds-icon-button.ds-chat-widget__agent-toggle--on:hover {
1030
1030
  background-color: var(--color-action-passive-bg-hover);
1031
1031
  }
1032
1032
 
@@ -1076,6 +1076,15 @@
1076
1076
 
1077
1077
  /* The widen grip drives --ds-chat-width frame by frame; the width glide
1078
1078
  above would rubber-band behind the pointer, so resizing suspends it. */
1079
+ /* The panel while the widget's code is still arriving (it loads on first
1080
+ open; src/behaviors/deferComponent.ts): the frame above is already
1081
+ drawn, and a spinner holds its centre. */
1082
+ .ds-chat-launcher__loading {
1083
+ flex: 1;
1084
+ display: grid;
1085
+ place-items: center;
1086
+ }
1087
+
1079
1088
  html[data-chat-resizing] .ds-chat-launcher__panel {
1080
1089
  transition: none;
1081
1090
  }
@@ -8,7 +8,7 @@ import { ChatHeader } from "../components/ChatHeader/ChatHeader.js";
8
8
  import { DocumentChip } from "../components/DocumentChip/DocumentChip.js";
9
9
  import { ChatMessage } from "../components/ChatMessage/ChatMessage.js";
10
10
  import { ChatThread } from "../components/ChatThread/ChatThread.js";
11
- import { CircularButton } from "../components/CircularButton/CircularButton.js";
11
+ import { IconButton } from "../components/IconButton/IconButton.js";
12
12
  import { PixelAvatar } from "../components/PixelAvatar/PixelAvatar.js";
13
13
  import { Composer } from "../components/Composer/Composer.js";
14
14
  import { DropdownMenu } from "../components/DropdownMenu/DropdownMenu.js";
@@ -456,11 +456,11 @@ function ChatWidget({
456
456
  const actionCount = Number(showNewChat) + Number(Boolean(renderAside)) + Number(artifacts) + Number(placementEnabled) + Number(fullscreenEnabled) + Number(closeEnabled);
457
457
  const headerActions = /* @__PURE__ */ jsxs(Fragment, { children: [
458
458
  showNewChat && /* @__PURE__ */ jsx(
459
- CircularButton,
459
+ IconButton,
460
460
  {
461
461
  icon: "edit_square",
462
462
  variant: "tertiary",
463
- ariaLabel: newChatLabel,
463
+ label: newChatLabel,
464
464
  tooltipPosition: "bottom",
465
465
  onClick: () => {
466
466
  reset();
@@ -470,12 +470,12 @@ function ChatWidget({
470
470
  }
471
471
  ),
472
472
  renderAside && /* @__PURE__ */ jsx(
473
- CircularButton,
473
+ IconButton,
474
474
  {
475
475
  icon: /* @__PURE__ */ jsx(PixelAvatar, { name: title, size: "sm" }),
476
476
  variant: "tertiary",
477
477
  className: asideShown ? "ds-chat-widget__agent-toggle--on" : void 0,
478
- ariaLabel: asideShown ? hideAgentLabel : showAgentLabel,
478
+ label: asideShown ? hideAgentLabel : showAgentLabel,
479
479
  tooltipPosition: "bottom",
480
480
  "aria-expanded": asideShown,
481
481
  "aria-controls": asideShown ? asideId : void 0,
@@ -483,12 +483,12 @@ function ChatWidget({
483
483
  }
484
484
  ),
485
485
  artifacts && /* @__PURE__ */ jsx(
486
- CircularButton,
486
+ IconButton,
487
487
  {
488
488
  icon: artifactShown ? "right_panel_close" : "right_panel_open",
489
489
  variant: "tertiary",
490
490
  className: artifactShown ? "ds-chat-widget__agent-toggle--on" : void 0,
491
- ariaLabel: artifactShown ? hideArtifactLabel : showArtifactLabel,
491
+ label: artifactShown ? hideArtifactLabel : showArtifactLabel,
492
492
  tooltipPosition: "bottom",
493
493
  "aria-expanded": artifactShown,
494
494
  "aria-controls": artifactShown ? artifactId : void 0,
@@ -504,11 +504,11 @@ function ChatWidget({
504
504
  {
505
505
  align: "end",
506
506
  trigger: /* @__PURE__ */ jsx(
507
- CircularButton,
507
+ IconButton,
508
508
  {
509
509
  icon: chatPlacement(placement).icon,
510
510
  variant: "tertiary",
511
- ariaLabel: placementLabel,
511
+ label: placementLabel,
512
512
  tooltipPosition: "bottom",
513
513
  disabled: isFull
514
514
  }
@@ -528,21 +528,21 @@ function ChatWidget({
528
528
  }
529
529
  ) }),
530
530
  fullscreenEnabled && /* @__PURE__ */ jsx(
531
- CircularButton,
531
+ IconButton,
532
532
  {
533
533
  icon: isFull ? "close_fullscreen" : "open_in_full",
534
534
  variant: "tertiary",
535
- ariaLabel: isFull ? exitFullscreenLabel : enterFullscreenLabel,
535
+ label: isFull ? exitFullscreenLabel : enterFullscreenLabel,
536
536
  tooltipPosition: "bottom",
537
537
  onClick: () => setView(isFull ? "panel" : "full")
538
538
  }
539
539
  ),
540
540
  closeEnabled && /* @__PURE__ */ jsx(
541
- CircularButton,
541
+ IconButton,
542
542
  {
543
543
  icon: "close",
544
544
  variant: "tertiary",
545
- ariaLabel: closeLabel,
545
+ label: closeLabel,
546
546
  tooltipPosition: "bottom",
547
547
  onClick: () => setOpen(false)
548
548
  }
@@ -603,11 +603,11 @@ function ChatWidget({
603
603
  {
604
604
  title: /* @__PURE__ */ jsxs("span", { className: "ds-chat-widget__brand", children: [
605
605
  renderThreads && !threadsInline && /* @__PURE__ */ jsx(
606
- CircularButton,
606
+ IconButton,
607
607
  {
608
608
  icon: "menu",
609
609
  variant: "tertiary",
610
- ariaLabel: openThreadsLabel,
610
+ label: openThreadsLabel,
611
611
  tooltipPosition: "bottom",
612
612
  onClick: () => setThreadsOpen(true)
613
613
  }
@@ -0,0 +1,10 @@
1
+ import { ChatWidgetProps } from './ChatWidget';
2
+ export declare const DeferredChatWidget: import('../behaviors/deferComponent').DeferredComponent<ChatWidgetProps>;
3
+ /**
4
+ * Start loading the chat widget's code now. The launcher's own button calls
5
+ * it on hover and focus; a host that opens the chat from a control of its
6
+ * own (`fab={false}`) calls it from that control's `onPointerEnter` and
7
+ * `onFocus`, so its press finds the code already there. Safe to call any
8
+ * number of times.
9
+ */
10
+ export declare const preloadChatWidget: () => void;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { deferComponent } from "../behaviors/deferComponent.js";
3
+ const DeferredChatWidget = deferComponent(
4
+ () => import("./ChatWidget.js").then((module) => module.ChatWidget)
5
+ );
6
+ const preloadChatWidget = DeferredChatWidget.preload;
7
+ export {
8
+ DeferredChatWidget,
9
+ preloadChatWidget
10
+ };
package/chat/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatS
20
20
  export { useGeneratedStarters, type GeneratedStarters, type GeneratedStartersOptions } from './generatedStarters';
21
21
  export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, planSequence, confirmSequence, defineContext, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, type SequenceStep, type SequencePlan, type ConfirmedStep, type ContextField, type ContextShape, type ContextValues, type ContextSchema, } from './actions';
22
22
  export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
23
+ export { preloadChatWidget } from './deferredChatWidget';
23
24
  export { useChatAgentState } from './agentState';
24
25
  export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
25
26
  export { ChatTabs, type ChatTabsProps } from './ChatTabs';
package/chat/index.js CHANGED
@@ -5,6 +5,7 @@ import { DEFAULT_SELECTION_LIMITS, sanitiseSelection, selectionLines } from "./s
5
5
  import { useGeneratedStarters } from "./generatedStarters.js";
6
6
  import { confirmSequence, confirmationLine, createConfirmationMark, defineAction, planAction, planSequence, sanitiseConfirmation, skippedText } from "./actions.js";
7
7
  import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
8
+ import { preloadChatWidget } from "./deferredChatWidget.js";
8
9
  import { useChatAgentState } from "./agentState.js";
9
10
  import { ChatThreads } from "./ChatThreads.js";
10
11
  import { ChatTabs } from "./ChatTabs.js";
@@ -107,6 +108,7 @@ export {
107
108
  pickStarters,
108
109
  planAction,
109
110
  planSequence,
111
+ preloadChatWidget,
110
112
  readGreeting,
111
113
  readSelection,
112
114
  sanitiseConfirmation,
@@ -43,7 +43,7 @@ declare const _default: {
43
43
  "ChatHeader",
44
44
  "ChatMessage",
45
45
  "ChatThread",
46
- "CircularButton",
46
+ "IconButton",
47
47
  "CodeBlock",
48
48
  "Composer",
49
49
  "DocumentChip",
@@ -56,6 +56,7 @@ declare const _default: {
56
56
  "Prose",
57
57
  "QuestionCard",
58
58
  "Reasoning",
59
+ "Spinner",
59
60
  "ThreadPanel",
60
61
  "ThreadTabs"
61
62
  ],
@@ -1,5 +1,5 @@
1
1
  const $comment = "The widget registry: the fourth kind of thing the package ships, between the components and the templates. One member by design. `parts` names the library components the widget composes (held to src/components/registry.json by scripts/validate-chat-widget.mjs), `subpaths` the package exports it occupies (held to scripts/package-manifest.mjs), `category` the component category whose section and sidebar group its page joins (held to src/components/registry.json), `peers` the optional peer dependencies each subpath needs (held to package.json). The widget's page under /components, the /docs/chat page, the chat corpus and the MCP tools read this file; never type its facts elsewhere.";
2
- const widgets = [{ "name": "ChatWidget", "slug": "ai-chat", "label": "AI chat", "category": "ai", "description": "The whole AI chat: the panel, or the page itself in an app shell mode, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.", "command": "init chat", "subpaths": { "./chat": "The widget, the provider, the launcher and the engine under them, with the hooks that let it follow the reader and write starters for what they picked.", "./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, the cards a reply opens with, the page actions a tool returns, its follow-ups, starters and feedback siblings, and the checks for what a reader highlighted, for any web-standard route.", "./chat/actions": "The action definitions a page and its route share, their dry run alone or in a sequence, the mark that says a change was confirmed on its card, and the declared shape of a page's context, with no dependencies.", "./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.", "./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.", "./chat/chat.css": "The widget's stylesheet." }, "peers": { "./chat": ["react-markdown", "remark-gfm"], "./chat/server": ["@anthropic-ai/sdk"], "./chat/upstash": ["@upstash/ratelimit", "@upstash/redis"], "./chat/demo": ["recharts"] }, "parts": ["AgentRail", "AgentStatus", "AiButton", "ArtifactCard", "ArtifactPanel", "AttachmentDropZone", "AttachmentGroup", "ChatHeader", "ChatMessage", "ChatThread", "CircularButton", "CodeBlock", "Composer", "DocumentChip", "DropdownMenu", "EmptyState", "Mention", "ModelPicker", "PixelAvatar", "PromptSuggestions", "Prose", "QuestionCard", "Reasoning", "ThreadPanel", "ThreadTabs"], "documented": ["ChatWidget", "ChatProvider", "ChatLauncher", "ChatThreads", "ChatTabs", "ChatAgentPane", "ChatArtifactPane", "ChatArtifactCard"] }];
2
+ const widgets = [{ "name": "ChatWidget", "slug": "ai-chat", "label": "AI chat", "category": "ai", "description": "The whole AI chat: the panel, or the page itself in an app shell mode, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.", "command": "init chat", "subpaths": { "./chat": "The widget, the provider, the launcher and the engine under them, with the hooks that let it follow the reader and write starters for what they picked.", "./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, the cards a reply opens with, the page actions a tool returns, its follow-ups, starters and feedback siblings, and the checks for what a reader highlighted, for any web-standard route.", "./chat/actions": "The action definitions a page and its route share, their dry run alone or in a sequence, the mark that says a change was confirmed on its card, and the declared shape of a page's context, with no dependencies.", "./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.", "./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.", "./chat/chat.css": "The widget's stylesheet." }, "peers": { "./chat": ["react-markdown", "remark-gfm"], "./chat/server": ["@anthropic-ai/sdk"], "./chat/upstash": ["@upstash/ratelimit", "@upstash/redis"], "./chat/demo": ["recharts"] }, "parts": ["AgentRail", "AgentStatus", "AiButton", "ArtifactCard", "ArtifactPanel", "AttachmentDropZone", "AttachmentGroup", "ChatHeader", "ChatMessage", "ChatThread", "IconButton", "CodeBlock", "Composer", "DocumentChip", "DropdownMenu", "EmptyState", "Mention", "ModelPicker", "PixelAvatar", "PromptSuggestions", "Prose", "QuestionCard", "Reasoning", "Spinner", "ThreadPanel", "ThreadTabs"], "documented": ["ChatWidget", "ChatProvider", "ChatLauncher", "ChatThreads", "ChatTabs", "ChatAgentPane", "ChatArtifactPane", "ChatArtifactCard"] }];
3
3
  const registry = {
4
4
  $comment,
5
5
  widgets
@@ -124,3 +124,11 @@
124
124
  color: var(--color-text-secondary);
125
125
  margin: 0;
126
126
  }
127
+
128
+ /* Icon side padding, Button's rule (design.md): a glyph's box carries its
129
+ own side bearing, so a side that holds one takes the step below the text
130
+ side. The trigger always ends on its chevron (20 → 16); the leading
131
+ side keeps the panel's inset, the line its content reads from. */
132
+ .ds-accordion__trigger {
133
+ padding-inline-end: var(--padding-400);
134
+ }
@@ -247,3 +247,11 @@
247
247
  .ds-agent-plan .material-symbols-rounded {
248
248
  color: inherit;
249
249
  }
250
+
251
+ /* Icon side padding, Button's rule (design.md): a glyph's box carries its
252
+ own side bearing, so a side that holds one takes the step below the text
253
+ side. The header's chevron end steps in from the card inset; the
254
+ leading side keeps the inset, the line the body below it reads from. */
255
+ .ds-agent-plan__header:has(.ds-agent-plan__chevron) {
256
+ padding-inline-end: calc(var(--ds-chat-card-inset) - var(--padding-100));
257
+ }
@@ -18,7 +18,7 @@
18
18
  header rather than sitting in it: the header is a centred identity
19
19
  block, and a control in that column would push the portrait off axis. */
20
20
  position: relative;
21
- /* CircularButton's default footprint, named because two rules need it:
21
+ /* IconButton's default footprint, named because two rules need it:
22
22
  the control itself, and the row the rail reserves for it when there is
23
23
  no header underneath it to float over. */
24
24
  --ds-agent-rail-control: 40px;
@@ -48,7 +48,7 @@
48
48
 
49
49
  .ds-agent-rail__collapse {
50
50
  position: absolute;
51
- /* CircularButton's default footprint and glyph, so the control sits in
51
+ /* IconButton's default footprint and glyph, so the control sits in
52
52
  the same row of controls the host puts along the card's top edge —
53
53
  `--ds-agent-rail-collapse-top` is the seat, which a host overrides to
54
54
  line the chevron up with its own header row. */
@@ -63,7 +63,7 @@
63
63
  padding: 0;
64
64
  border: none;
65
65
  border-radius: var(--radius-pill);
66
- /* A tertiary CircularButton's exact resting treatment, because that is
66
+ /* A tertiary IconButton's exact resting treatment, because that is
67
67
  what it sits in a row with: the host's own controls line up opposite it
68
68
  on the same baseline, and a dimmer icon tier beside them would read as a
69
69
  lesser control rather than the same kind of one. */
@@ -743,3 +743,22 @@
743
743
  transition: none;
744
744
  }
745
745
  }
746
+
747
+ /* Icon side padding, Button's rule: beside the label the icon's box carries
748
+ its own side bearing, so its edge takes the step below the text side
749
+ (20 → 16 at default, 12 → 8 at compact). The busy and status glyphs ride
750
+ the same slot. An icon-only button keeps its even box. */
751
+ .ds-ai-button:not(.ds-ai-button--icon-only):has(.ds-ai-button__icon) {
752
+ padding-inline-start: var(--padding-400);
753
+ }
754
+
755
+ .ds-ai-button--compact:not(.ds-ai-button--icon-only):has(.ds-ai-button__icon) {
756
+ padding-inline-start: var(--padding-200);
757
+ }
758
+
759
+ /* The icon-only form's tooltip names the button; while a panel it opened is
760
+ showing (its own request, a Popover, a sheet) the panel says it all, and
761
+ the bubble would sit on the side the panel takes. */
762
+ .ds-tooltip:has(> .ds-ai-button[aria-expanded='true']) .ds-tooltip__panel {
763
+ display: none;
764
+ }
@@ -21,8 +21,17 @@ type AiButtonOwnProps = {
21
21
  label?: string;
22
22
  /** Leading icon — Material Symbol name (string) or custom element (ReactNode) */
23
23
  icon?: string | React.ReactNode;
24
- /** Draws the button as a circle holding only its icon, for a tight bar. The label stays as its accessible name. */
24
+ /** Draws the button holding only its icon, on an even box, for a tight bar. The label stays as its accessible name. */
25
25
  iconOnly?: boolean;
26
+ /**
27
+ * The hover and focus tooltip of the icon-only form, which names itself as
28
+ * IconButton does: by default it carries `label`. Pass a string to show
29
+ * different wording, or `false` to opt out. A button with a `summary`
30
+ * shows none, since its panel opens on the same hover.
31
+ */
32
+ tooltip?: string | false;
33
+ /** Which side the tooltip opens on. `start` and `end` follow the reading direction. */
34
+ tooltipPosition?: 'top' | 'bottom' | 'left' | 'right' | 'start' | 'end';
26
35
  /** Button size */
27
36
  size?: 'default' | 'compact';
28
37
  /** Whether the button is disabled */