feat(webui): simplify automation management and unify disclosure motion
Replace the dense automation workspace with a calm list and on-demand details, show current linked-chat titles, and remember manual system-task expansion preferences. Reuse disclosure transitions across expandable controls, preserve drafts and focus through closing, and release large diffs after their exit animation. Refs NAN-116
This commit is contained in:
1 parent
90b889394f
commit
1640784d45
37 files changed
+1746
-721
No files matched your search
@@ -24,6 +24,7 @@ const DialogOverlay = React.forwardRef<
|
||||
ref={ref}
|
||||
className={cn(
|
||||
modalOverlayClassName,
|
||||
"motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -31,15 +32,30 @@ const DialogOverlay = React.forwardRef<
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
// The portal's presence ref must reach the animated content, not the plain
|
||||
// positioning wrapper; otherwise the wrapper unmounts before the exit finishes.
|
||||
const DialogPositionedContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
||||
positionerStyle?: React.CSSProperties;
|
||||
}
|
||||
>(({ positionerStyle, ...props }, ref) => (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" style={positionerStyle}>
|
||||
<DialogPrimitive.Content ref={ref} {...props} />
|
||||
</div>
|
||||
));
|
||||
DialogPositionedContent.displayName = "DialogPositionedContent";
|
||||
|
||||
interface DialogContentProps
|
||||
extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
||||
showCloseButton?: boolean;
|
||||
overlayClassName?: string;
|
||||
}
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
DialogContentProps
|
||||
>(({ className, children, showCloseButton = true, onOpenAutoFocus, ...props }, ref) => {
|
||||
>(({ className, children, showCloseButton = true, overlayClassName, onOpenAutoFocus, ...props }, ref) => {
|
||||
const { t } = useTranslation();
|
||||
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
|
||||
const contentNode = React.useRef<HTMLDivElement | null>(null);
|
||||
@@ -74,9 +90,9 @@ const DialogContent = React.forwardRef<
|
||||
}, [ref]);
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" style={layout}>
|
||||
<DialogPrimitive.Content
|
||||
<DialogOverlay className={overlayClassName} />
|
||||
<DialogPositionedContent
|
||||
positionerStyle={layout}
|
||||
ref={contentRef}
|
||||
onOpenAutoFocus={(event) => {
|
||||
if (onOpenAutoFocus) onOpenAutoFocus(event);
|
||||
@@ -87,7 +103,7 @@ const DialogContent = React.forwardRef<
|
||||
}}
|
||||
className={cn(
|
||||
modalSurfaceClassName,
|
||||
"relative grid w-full max-w-lg origin-center gap-4 rounded-modal p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
|
||||
"relative grid w-full max-w-lg origin-center gap-4 rounded-modal p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -101,8 +117,7 @@ const DialogContent = React.forwardRef<
|
||||
<span className="sr-only">{t("common.close")}</span>
|
||||
</DialogPrimitive.Close>
|
||||
) : null}
|
||||
</DialogPrimitive.Content>
|
||||
</div>
|
||||
</DialogPositionedContent>
|
||||
</DialogPortal>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { useEffect, useId, useRef, useState, type KeyboardEventHandler, type ReactNode } from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Keep the content mounted so both directions animate and form drafts survive closing. */
|
||||
export function DisclosureContent({
|
||||
open, children, id, className, onKeyDown, onExitComplete,
|
||||
}: {
|
||||
open: boolean;
|
||||
children: ReactNode;
|
||||
id?: string;
|
||||
className?: string;
|
||||
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
||||
onExitComplete?: () => void;
|
||||
}) {
|
||||
const node = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (open || !onExitComplete) return;
|
||||
// Read the actual CSS transitions, including a reversal in progress. With
|
||||
// reduced motion (or no transition), there is nothing to wait for.
|
||||
const animations = node.current?.getAnimations?.() ?? [];
|
||||
if (!animations.length) {
|
||||
onExitComplete();
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
void Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
|
||||
if (!cancelled) onExitComplete();
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
}, [open, onExitComplete]);
|
||||
return (
|
||||
<div
|
||||
ref={node}
|
||||
id={id}
|
||||
className="inline-disclosure"
|
||||
data-state={open ? "open" : "closed"}
|
||||
aria-hidden={open ? undefined : true}
|
||||
onKeyDown={onKeyDown}
|
||||
{...(!open ? { inert: "" } : {})}
|
||||
>
|
||||
<div className="inline-disclosure-clip">
|
||||
<div className={cn("inline-disclosure-content", className)}>{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Disclosure({
|
||||
summary, children, className, summaryClassName, contentClassName,
|
||||
}: {
|
||||
summary: ReactNode;
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
summaryClassName?: string;
|
||||
contentClassName?: string;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={className}>
|
||||
<button
|
||||
type="button"
|
||||
className={cn("group/disclosure w-full select-none text-start", summaryClassName)}
|
||||
data-state={open ? "open" : "closed"}
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
>
|
||||
{summary}
|
||||
</button>
|
||||
<DisclosureContent id={id} open={open} className={contentClassName}>
|
||||
{children}
|
||||
</DisclosureContent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useLayoutEffect, useRef, useState } from "react";
|
||||
|
||||
/** Animate a line-limited preview without swapping or duplicating its text. */
|
||||
export function ExpandableText({
|
||||
children, expanded, lines, className, id,
|
||||
}: {
|
||||
children: string;
|
||||
expanded: boolean;
|
||||
lines: number;
|
||||
className?: string;
|
||||
id?: string;
|
||||
}) {
|
||||
const content = useRef<HTMLParagraphElement>(null);
|
||||
const [size, setSize] = useState<{ full: number; preview: number }>();
|
||||
useLayoutEffect(() => {
|
||||
const node = content.current;
|
||||
if (!node) return;
|
||||
const measure = () => {
|
||||
const full = node.scrollHeight;
|
||||
const lineHeight = parseFloat(getComputedStyle(node).lineHeight);
|
||||
if (!full || !Number.isFinite(lineHeight)) return;
|
||||
const preview = Math.min(full, lineHeight * lines);
|
||||
setSize((current) => current?.full === full && current.preview === preview
|
||||
? current : { full, preview });
|
||||
};
|
||||
measure();
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
||||
observer?.observe(node);
|
||||
window.addEventListener("resize", measure);
|
||||
return () => {
|
||||
observer?.disconnect();
|
||||
window.removeEventListener("resize", measure);
|
||||
};
|
||||
}, [children, lines, className]);
|
||||
|
||||
return (
|
||||
<div
|
||||
id={id}
|
||||
className="expandable-text flow-root overflow-hidden"
|
||||
data-state={expanded ? "open" : "closed"}
|
||||
style={{ height: size ? expanded ? size.full : size.preview : undefined }}
|
||||
>
|
||||
<p ref={content} className={className}>{children}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user