mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-04 03:25:30 +08:00
…e connecting line (#9226) ### What problem does this PR solve? Can directly generate an agent node by dragging and dropping the connecting line (#9226) ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import {
|
|
createContext,
|
|
ReactNode,
|
|
useCallback,
|
|
useContext,
|
|
useRef,
|
|
} from 'react';
|
|
|
|
interface DropdownContextType {
|
|
canShowDropdown: () => boolean;
|
|
setActiveDropdown: (type: 'handle' | 'drag') => void;
|
|
clearActiveDropdown: () => void;
|
|
}
|
|
|
|
const DropdownContext = createContext<DropdownContextType | null>(null);
|
|
|
|
export const useDropdownManager = () => {
|
|
const context = useContext(DropdownContext);
|
|
if (!context) {
|
|
throw new Error('useDropdownManager must be used within DropdownProvider');
|
|
}
|
|
return context;
|
|
};
|
|
|
|
interface DropdownProviderProps {
|
|
children: ReactNode;
|
|
}
|
|
|
|
export const DropdownProvider = ({ children }: DropdownProviderProps) => {
|
|
const activeDropdownRef = useRef<'handle' | 'drag' | null>(null);
|
|
|
|
const canShowDropdown = useCallback(() => {
|
|
const current = activeDropdownRef.current;
|
|
return !current;
|
|
}, []);
|
|
|
|
const setActiveDropdown = useCallback((type: 'handle' | 'drag') => {
|
|
activeDropdownRef.current = type;
|
|
}, []);
|
|
|
|
const clearActiveDropdown = useCallback(() => {
|
|
activeDropdownRef.current = null;
|
|
}, []);
|
|
|
|
const value: DropdownContextType = {
|
|
canShowDropdown,
|
|
setActiveDropdown,
|
|
clearActiveDropdown,
|
|
};
|
|
|
|
return (
|
|
<DropdownContext.Provider value={value}>
|
|
{children}
|
|
</DropdownContext.Provider>
|
|
);
|
|
};
|