@candor-ui/react 1.9.0 → 1.9.1
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/dist/chat/composer.js +7 -2
- package/dist/chat/permission-prompt.js +4 -1
- package/dist/chat/thread.d.ts +1 -1
- package/dist/chat/thread.js +56 -6
- package/dist/styles.css +1 -0
- package/package.json +1 -1
package/dist/chat/composer.js
CHANGED
|
@@ -70,8 +70,13 @@ function useChipMotion(items, keyOf) {
|
|
|
70
70
|
return next;
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
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);
|
package/dist/chat/thread.d.ts
CHANGED
|
@@ -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, }: {
|
package/dist/chat/thread.js
CHANGED
|
@@ -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
|
-
//
|
|
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 &&
|
|
56
|
-
|
|
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
|
@@ -565,6 +565,7 @@
|
|
|
565
565
|
@media (prefers-reduced-motion: reduce) {
|
|
566
566
|
*, *::before, *::after {
|
|
567
567
|
animation-duration: 0.001ms !important;
|
|
568
|
+
animation-delay: 0s !important;
|
|
568
569
|
animation-iteration-count: 1 !important;
|
|
569
570
|
transition-duration: 0.001ms !important;
|
|
570
571
|
scroll-behavior: auto !important;
|
package/package.json
CHANGED