Repository navigation
revert(chat-ui): restore the package deleted in #6435 #6463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "name": "@superset/chat-ui", | ||
| "private": true, | ||
| "version": "0.1.0", | ||
| "type": "module", | ||
| "exports": { | ||
| "./*": "./src/components/*/index.ts" | ||
| }, | ||
| "scripts": { | ||
| "clean": "git clean -xdf .cache .turbo dist node_modules", | ||
| "typecheck": "tsc --noEmit --emitDeclarationOnly false" | ||
| }, | ||
| "dependencies": { | ||
| "@lexical/react": "0.41.0", | ||
| "@shadcn/react": "0.2.1", | ||
| "@superset/chat": "workspace:*", | ||
| "@superset/ui": "workspace:*", | ||
| "lexical": "0.41.0", | ||
| "lucide-react": "0.563.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@storybook/react-vite": "10.4.2", | ||
| "@superset/typescript": "workspace:*", | ||
| "@types/node": "24.12.0", | ||
| "@types/react": "19.2.14", | ||
| "@types/react-dom": "19.2.3", | ||
| "react": "19.2.3", | ||
| "react-dom": "19.2.3", | ||
| "storybook": "10.4.2", | ||
| "typescript": "6.0.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "19.2.3" | ||
| } | ||
| } |
120 changes: 120 additions & 0 deletions
120
packages/chat-ui/src/components/ComposerDropZone/ComposerDropZone.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| "use client"; | ||
|
|
||
| import { cn } from "@superset/ui/utils"; | ||
| import { | ||
| createContext, | ||
| type ReactNode, | ||
| useContext, | ||
| useEffect, | ||
| useMemo, | ||
| useRef, | ||
| useState, | ||
| } from "react"; | ||
|
|
||
| type DropZoneContextValue = { | ||
| register(sink: (files: FileList) => void): () => void; | ||
| }; | ||
|
|
||
| const ComposerDropZoneContext = createContext<DropZoneContextValue | null>( | ||
| null, | ||
| ); | ||
|
|
||
| export function useComposerDropZone(): DropZoneContextValue | null { | ||
| return useContext(ComposerDropZoneContext); | ||
| } | ||
|
|
||
| export type ComposerDropZoneProps = { | ||
| children: ReactNode; | ||
| label?: string; | ||
| className?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Layout-level file drop target: mount around the whole content area (like the | ||
| * new-workspace screen) and any composer rendered inside registers itself as | ||
| * the drop sink automatically. | ||
| */ | ||
| export function ComposerDropZone({ | ||
| children, | ||
| label = "Drop files to attach", | ||
| className, | ||
| }: ComposerDropZoneProps) { | ||
| const sinkRef = useRef<((files: FileList) => void) | null>(null); | ||
| // dragover + timeout reset instead of an enter/leave counter, so | ||
| // Esc-cancelled drags and drops outside the window can't wedge the overlay. | ||
| const [isDraggingFiles, setIsDraggingFiles] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| let timer: number | null = null; | ||
| const onDragOver = (event: DragEvent) => { | ||
| if (!Array.from(event.dataTransfer?.types ?? []).includes("Files")) | ||
| return; | ||
| setIsDraggingFiles(true); | ||
| if (timer !== null) window.clearTimeout(timer); | ||
| timer = window.setTimeout(() => setIsDraggingFiles(false), 200); | ||
| }; | ||
| const onDrop = () => { | ||
| if (timer !== null) window.clearTimeout(timer); | ||
| timer = null; | ||
| setIsDraggingFiles(false); | ||
| }; | ||
| document.addEventListener("dragover", onDragOver); | ||
| document.addEventListener("drop", onDrop); | ||
| return () => { | ||
| document.removeEventListener("dragover", onDragOver); | ||
| document.removeEventListener("drop", onDrop); | ||
| if (timer !== null) window.clearTimeout(timer); | ||
| }; | ||
| }, []); | ||
|
|
||
| const contextValue = useMemo<DropZoneContextValue>( | ||
| () => ({ | ||
| register(sink) { | ||
| sinkRef.current = sink; | ||
| return () => { | ||
| if (sinkRef.current === sink) sinkRef.current = null; | ||
| }; | ||
| }, | ||
| }), | ||
| [], | ||
| ); | ||
|
|
||
| return ( | ||
| <ComposerDropZoneContext.Provider value={contextValue}> | ||
| {/* biome-ignore lint/a11y/noStaticElementInteractions: drag-and-drop target; keyboard users attach via the composer's file picker */} | ||
| <div | ||
| className={cn("relative", className)} | ||
| onDragOver={(event) => { | ||
| if (event.dataTransfer.types.includes("Files")) | ||
| event.preventDefault(); | ||
| }} | ||
| onDrop={(event) => { | ||
| // The composer's editor may have consumed this already; | ||
| // preventDefault marks it and the event still bubbles here. | ||
| if (event.defaultPrevented) return; | ||
| if (event.dataTransfer.files.length === 0) return; | ||
| event.preventDefault(); | ||
| sinkRef.current?.(event.dataTransfer.files); | ||
| }} | ||
| > | ||
| {children} | ||
| <div | ||
| aria-hidden={!isDraggingFiles} | ||
| className={cn( | ||
| "pointer-events-none absolute inset-0 z-40 flex items-center justify-center bg-primary/10 transition-opacity duration-150 motion-reduce:transition-none", | ||
| isDraggingFiles ? "opacity-100" : "opacity-0", | ||
| )} | ||
| > | ||
| <span | ||
| className={cn( | ||
| "inline-flex items-center rounded-md border border-border/50 bg-secondary px-3 py-1 text-sm text-foreground shadow transition-transform duration-150 motion-reduce:transition-none", | ||
| isDraggingFiles ? "scale-100" : "scale-95", | ||
| )} | ||
| > | ||
| {label} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </ComposerDropZoneContext.Provider> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export { | ||
| ComposerDropZone, | ||
| type ComposerDropZoneProps, | ||
| useComposerDropZone, | ||
| } from "./ComposerDropZone"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Prevent the browser default for file drops outside the zone.
The document-level
droplistener only clears overlay state. It does not callpreventDefault. The innerdivprevents the default only for drops inside its own subtree. If the user misses the zone and drops a file on surrounding chrome, the browser applies its default action and navigates the window to the dropped file. The user then loses the current view and any unsent composer text.The same applies to
dragover: the browser needspreventDefaultondragoverto make a drop target valid, and needs it ondropto suppress navigation.🛡️ Proposed fix
const onDragOver = (event: DragEvent) => { if (!Array.from(event.dataTransfer?.types ?? []).includes("Files")) return; + event.preventDefault(); setIsDraggingFiles(true); if (timer !== null) window.clearTimeout(timer); timer = window.setTimeout(() => setIsDraggingFiles(false), 200); }; - const onDrop = () => { + const onDrop = (event: DragEvent) => { + if (Array.from(event.dataTransfer?.types ?? []).includes("Files")) + event.preventDefault(); if (timer !== null) window.clearTimeout(timer); timer = null; setIsDraggingFiles(false); };The inner
onDrophandler keeps working, because it runs during bubbling before the document listener and itsdefaultPreventedcheck is unaffected.📝 Committable suggestion
🤖 Prompt for AI Agents