@ciridae/ui 0.8.0 → 0.8.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.
|
@@ -4,7 +4,8 @@ import { CommentThread } from "./comment-thread";
|
|
|
4
4
|
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
|
|
5
5
|
import { Button } from "../ui/button";
|
|
6
6
|
function FeedbackCenterCommentThread({ comments, error, feedback, isCommentSubmitting, isCommentsLoading, onRetry, onSubmitComment, }) {
|
|
7
|
-
|
|
7
|
+
// A retry in flight shows the thread's loading state, not the stale error.
|
|
8
|
+
if (error && !isCommentsLoading) {
|
|
8
9
|
return (_jsxs(Alert, { variant: "destructive", children: [_jsx(AlertCircleIcon, {}), _jsx(AlertTitle, { children: "Conversation could not be loaded" }), _jsxs(AlertDescription, { className: "grid gap-3", children: [_jsx("span", { children: error.message }), onRetry ? (_jsx(Button, { className: "justify-self-start", onClick: onRetry, size: "sm", type: "button", variant: "outline", children: "Try again" })) : null] })] }));
|
|
9
10
|
}
|
|
10
11
|
return (_jsx(CommentThread, { comments: comments, composerPlaceholder: "Write a reply...", composerSubmitLabel: "Reply", isLoading: isCommentsLoading, isSubmitting: isCommentSubmitting, onSubmit: getCommentSubmitHandler(feedback, onSubmitComment), readOnly: !onSubmitComment, showHeader: false }));
|
|
@@ -51,11 +51,12 @@ function FormSheet({ children, closeDisabled = false, isDirty, onOpenChange, ope
|
|
|
51
51
|
}
|
|
52
52
|
return (_jsxs(_Fragment, { children: [_jsxs(Sheet, { onOpenChange: handleOpenChange, open: open, children: [trigger ? _jsx(SheetTrigger, { asChild: true, children: trigger }) : null, _jsx(FormSheetContext.Provider, { value: actions, children: children })] }), _jsx(DiscardChangesPrompt, { onDiscard: discardChanges, onOpenChange: handleDiscardPromptOpenChange, open: discardPromptOpen })] }));
|
|
53
53
|
}
|
|
54
|
+
// useLayoutEffect warns during server rendering; the capture is browser-only anyway.
|
|
55
|
+
const useIsomorphicLayoutEffect = typeof document === "undefined" ? React.useEffect : React.useLayoutEffect;
|
|
54
56
|
function useFormSheetReturnFocus(open) {
|
|
55
|
-
const activeElementDuringRender = getActiveElement();
|
|
56
57
|
const focusFrameRef = React.useRef(null);
|
|
57
|
-
const returnFocusRef = React.useRef(
|
|
58
|
-
const wasOpenRef = React.useRef(
|
|
58
|
+
const returnFocusRef = React.useRef(null);
|
|
59
|
+
const wasOpenRef = React.useRef(false);
|
|
59
60
|
const schedule = React.useCallback(() => {
|
|
60
61
|
const returnFocus = returnFocusRef.current;
|
|
61
62
|
if (!returnFocus)
|
|
@@ -68,10 +69,12 @@ function useFormSheetReturnFocus(open) {
|
|
|
68
69
|
returnFocus.focus();
|
|
69
70
|
});
|
|
70
71
|
}, []);
|
|
71
|
-
|
|
72
|
+
// Layout effect: a controlled open (no trigger, so capture() never ran) must
|
|
73
|
+
// read the pre-open element before the sheet's focus scope moves focus.
|
|
74
|
+
useIsomorphicLayoutEffect(() => {
|
|
72
75
|
if (open) {
|
|
73
76
|
if (!wasOpenRef.current)
|
|
74
|
-
returnFocusRef.current =
|
|
77
|
+
returnFocusRef.current = getActiveElement();
|
|
75
78
|
wasOpenRef.current = true;
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
@@ -79,7 +82,7 @@ function useFormSheetReturnFocus(open) {
|
|
|
79
82
|
return;
|
|
80
83
|
wasOpenRef.current = false;
|
|
81
84
|
schedule();
|
|
82
|
-
}, [
|
|
85
|
+
}, [open, schedule]);
|
|
83
86
|
React.useEffect(() => () => {
|
|
84
87
|
if (wasOpenRef.current)
|
|
85
88
|
schedule();
|
|
@@ -98,9 +101,8 @@ function DiscardChangesPrompt({ onDiscard, onOpenChange, open, }) {
|
|
|
98
101
|
return (_jsx(AlertDialog, { onOpenChange: onOpenChange, open: open, children: _jsxs(AlertDialogContent, { size: "sm", children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Discard unsaved changes?" }), _jsx(AlertDialogDescription, { children: "Your changes have not been saved. Keep editing or discard them and close this panel." })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: "Keep editing" }), _jsx(AlertDialogAction, { onClick: onDiscard, variant: "destructive", children: "Discard changes" })] })] }) }));
|
|
99
102
|
}
|
|
100
103
|
function getActiveElement() {
|
|
101
|
-
// Called during render, so it must be safe on the server too.
|
|
102
104
|
if (typeof document === "undefined")
|
|
103
|
-
return null;
|
|
105
|
+
return null; // SSR-safe
|
|
104
106
|
return document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
105
107
|
}
|
|
106
108
|
export { FormSheet, useFormSheetActions };
|