@candor-ui/react 1.9.0 → 2.0.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.
@@ -70,8 +70,13 @@ function useChipMotion(items, keyOf) {
70
70
  return next;
71
71
  });
72
72
  }
73
- if (gone.length)
74
- setLeaving((list) => [...list.filter((item) => !now.has(keyOf(item))), ...gone]);
73
+ // A chip added again while its ghost is still leaving takes the ghost's place: the ghost goes at once.
74
+ if (gone.length || added.length) {
75
+ setLeaving((list) => {
76
+ const kept = list.filter((item) => !now.has(keyOf(item)));
77
+ return kept.length === list.length && gone.length === 0 ? list : [...kept, ...gone];
78
+ });
79
+ }
75
80
  }, [items, keyOf]);
76
81
  React.useEffect(() => {
77
82
  if (leaving.length === 0)
@@ -108,7 +108,7 @@ function PromptBody({ request, mode, suggestions, editable, onAllow, onDeny, bus
108
108
  if (request.defaultToNo)
109
109
  denyRef.current?.focus();
110
110
  }, [request.id, request.defaultToNo]);
111
- // A press on inert space outside the prompt, while it waits, nudges it rather than dismissing anything.
111
+ // A press on inert space outside every prompt, while it waits, nudges it rather than dismissing anything.
112
112
  const section = React.useRef(null);
113
113
  const [nudged, setNudged] = React.useState(false);
114
114
  React.useEffect(() => {
@@ -118,6 +118,9 @@ function PromptBody({ request, mode, suggestions, editable, onAllow, onDeny, bus
118
118
  const target = e.target;
119
119
  if (!target || section.current?.contains(target))
120
120
  return;
121
+ // A press anywhere inside another prompt is that prompt's business, not an outside press for this one.
122
+ if (target.closest('[data-slot="permission-prompt"]'))
123
+ return;
121
124
  if (target.closest(INTERACTIVE))
122
125
  return;
123
126
  setNudged(true);
@@ -19,7 +19,7 @@ export declare const threadStrings: {
19
19
  * reader instead of following.
20
20
  *
21
21
  * While the reader is scrolled up, "Jump to latest" pulses once each time a
22
- * new message arrives, then stays still; the jump itself scrolls smoothly
22
+ * new message arrives (a child of the thread, or any element marked `data-slot="message"` inside it), then stays still; the jump itself scrolls smoothly
23
23
  * unless the OS asks for reduced motion or data-motion is "none".
24
24
  */
25
25
  declare function Thread({ children, empty, footer, className, contentClassName, virtualize, anchor, scrollerRef, onDrop, fade, }: {
@@ -25,7 +25,7 @@ export const threadStrings = {
25
25
  * reader instead of following.
26
26
  *
27
27
  * While the reader is scrolled up, "Jump to latest" pulses once each time a
28
- * new message arrives, then stays still; the jump itself scrolls smoothly
28
+ * new message arrives (a child of the thread, or any element marked `data-slot="message"` inside it), then stays still; the jump itself scrolls smoothly
29
29
  * unless the OS asks for reduced motion or data-motion is "none".
30
30
  */
31
31
  function Thread({ children, empty, footer, className, contentClassName, virtualize = false, anchor, scrollerRef, onDrop, fade = true, }) {
@@ -45,16 +45,66 @@ function Thread({ children, empty, footer, className, contentClassName, virtuali
45
45
  const still = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches || el.closest('[data-motion="none"]') !== null;
46
46
  el.scrollTo({ top: el.scrollHeight, behavior: still ? "auto" : behavior });
47
47
  }, []);
48
- // New messages that arrive while the reader is scrolled up: the Jump to latest control pulses once for each.
48
+ // A new message while the reader is scrolled up: the Jump to latest control pulses once for each arrival, even when
49
+ // the messages sit inside a wrapper component or a fragment. A second arrival while it still pulses restarts it.
50
+ const [arrived, setArrived] = React.useState(false);
51
+ const arrivedRef = React.useRef(false);
52
+ const frame = React.useRef(0);
53
+ React.useEffect(() => {
54
+ arrivedRef.current = arrived;
55
+ }, [arrived]);
56
+ React.useEffect(() => () => cancelAnimationFrame(frame.current), []);
57
+ const arrive = React.useCallback(() => {
58
+ if (pinnedRef.current)
59
+ return;
60
+ if (!arrivedRef.current) {
61
+ arrivedRef.current = true;
62
+ setArrived(true);
63
+ return;
64
+ }
65
+ // Already pulsing: switch it off and on again next frame, so the ring plays again.
66
+ arrivedRef.current = false;
67
+ setArrived(false);
68
+ cancelAnimationFrame(frame.current);
69
+ frame.current = requestAnimationFrame(() => {
70
+ arrivedRef.current = true;
71
+ setArrived(true);
72
+ });
73
+ }, []);
74
+ // Virtualized, every child is one message and the rows come and go as the reader scrolls, so the children are counted.
49
75
  const count = React.Children.count(children);
50
76
  const lastCount = React.useRef(count);
51
- const [arrived, setArrived] = React.useState(false);
52
77
  React.useEffect(() => {
53
78
  const grew = count > lastCount.current;
54
79
  lastCount.current = count;
55
- if (grew && !pinnedRef.current)
56
- setArrived(true);
57
- }, [count]);
80
+ if (grew && virtualize)
81
+ arrive();
82
+ }, [count, virtualize, arrive]);
83
+ // Otherwise the list itself is watched. A message is an element marked data-slot="message" anywhere inside the log, or a
84
+ // direct child of it that holds none. It is an arrival only when there are more messages than before and an added one
85
+ // comes after every message that was already there: unfolding earlier turns inserts in the middle, and swapping a
86
+ // reply for another version (a keyed remount) doesn't change the count. Text streaming into a message adds neither.
87
+ React.useEffect(() => {
88
+ const el = content.current;
89
+ if (virtualize || !el || typeof MutationObserver === "undefined")
90
+ return;
91
+ const messages = () => Array.from(el.querySelectorAll("*")).filter((node) => node.matches('[data-slot="message"]') || (node.parentElement === el && node.querySelector('[data-slot="message"]') === null));
92
+ const seen = { messages: messages() };
93
+ const observer = new MutationObserver(() => {
94
+ const before = seen.messages;
95
+ const known = (seen.messages = messages());
96
+ if (known.length <= before.length)
97
+ return;
98
+ const had = new Set(before);
99
+ const survivors = before.filter((node) => node.isConnected);
100
+ const added = known.filter((node) => !had.has(node));
101
+ const atTheEnd = added.some((node) => survivors.every((old) => old.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING));
102
+ if (atTheEnd)
103
+ arrive();
104
+ });
105
+ observer.observe(el, { childList: true, subtree: true });
106
+ return () => observer.disconnect();
107
+ }, [virtualize, arrive]);
58
108
  React.useEffect(() => {
59
109
  if (!arrived)
60
110
  return;
package/dist/styles.css CHANGED
@@ -241,9 +241,12 @@
241
241
  * Font: Inter when the font-inter item is installed (styles/candor-font-inter.css),
242
242
  * else the system's sans-serif. Point --cd-font at your own font to use it instead.
243
243
  *
244
- * Density: data-density="compact" on <html> (or any container) tightens type for
245
- * dense apps: 14px conversation text and 13px body and label text, with a narrower
246
- * thread and sidebar.
244
+ * Density: data-density="compact" | "spacious" on <html> (or any container); no
245
+ * attribute is the default. Compact tightens type for dense apps: 14px conversation
246
+ * text and 13px body and label text, with a narrower thread and sidebar. Spacious is
247
+ * the other way, for reading-first apps: 16px conversation
248
+ * text and 15px body and label text, with a wider thread and sidebar. Both set the
249
+ * same four tokens, so one overrides the other when nested.
247
250
  *
248
251
  * Motion: data-motion="none" | "subtle" | "expressive" on <html> (or any container).
249
252
  * Subtle is the default: a change that happened is shown settling (a collapse,
@@ -334,6 +337,13 @@
334
337
  --cd-thread-width: 44rem;
335
338
  --cd-sidebar-width: 14rem;
336
339
  }
340
+ /* The spacious preset: the same four tokens as compact, set the other way. Prose is pinned here too, at 16px. */
341
+ [data-density="spacious"] {
342
+ --cd-text-prose: 1rem;
343
+ --cd-text-md: 0.9375rem;
344
+ --cd-thread-width: 52rem;
345
+ --cd-sidebar-width: 18rem;
346
+ }
337
347
  @media (prefers-color-scheme: dark) {
338
348
  :root:not([data-theme]) {
339
349
  --cd-shadow: oklch(0 0 0 / 0.35);
@@ -565,6 +575,7 @@
565
575
  @media (prefers-reduced-motion: reduce) {
566
576
  *, *::before, *::after {
567
577
  animation-duration: 0.001ms !important;
578
+ animation-delay: 0s !important;
568
579
  animation-iteration-count: 1 !important;
569
580
  transition-duration: 0.001ms !important;
570
581
  scroll-behavior: auto !important;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candor-ui/react",
3
- "version": "1.9.0",
3
+ "version": "2.0.0",
4
4
  "description": "Candor UI's free tier as an npm package: React components for agents that do real work, on shadcn/ui and Tailwind 4.",
5
5
  "license": "MIT",
6
6
  "author": "Methodic LLC",