/
vshmidt
/
cloudbeaver
Обзор
Документация
Войти
/
vshmidt
/
cloudbeaver
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
devel
webapp/packages/plugin-navigation-tree/src/TreeNew/useTreeMenu.ts
52 строки
2 KB
Alexey Potsetsuev
dbeaver/pro#7465 refactor: migrate context menu to ariakit (#3963)
13 дек 2025, 05:44
Не верифицирован
13 дек 2025, 05:44
cb23fda
Код
Авторство
О чём код?
/* * CloudBeaver - Cloud Database Manager * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ import { action } from 'mobx'; import { useId } from 'react'; import { useContextMenuPosition, useObjectRef, useObservableRef, type IContextMenuPosition } from '@cloudbeaver/core-blocks'; import type { IDataContext } from '@cloudbeaver/core-data-context'; import { DATA_CONTEXT_NAV_NODE_ID } from '@cloudbeaver/core-navigation-tree'; import type { IMenuData } from '@cloudbeaver/core-view'; export interface ITreeMenu { menu: IMenuData; position: IContextMenuPosition; openMenu(event: React.MouseEvent, nodeId: string): void; } interface ITreeMenuOptions { menu: IMenuData; setContext?: (context: IDataContext, id: string) => void; } export function useTreeMenu(options: ITreeMenuOptions): Readonly<ITreeMenu> { options = useObjectRef(options); const id = useId(); const position = useContextMenuPosition(); const state = useObservableRef( () => ({ openMenu(event: React.MouseEvent<HTMLDivElement, MouseEvent>, nodeId: string) { this.menu.context.deleteForId(this.id); this.menu.context.set(DATA_CONTEXT_NAV_NODE_ID, nodeId, this.id); if (options.setContext) { options.setContext(this.menu.context, this.id); } this.position.open(event); }, }), { openMenu: action.bound }, { id, menu: options.menu, position }, ); return state; }