()
| 56 | } |
| 57 | |
| 58 | export function Tabs(): React.JSX.Element { |
| 59 | const { |
| 60 | tabs, |
| 61 | activeTabId, |
| 62 | setActiveTab, |
| 63 | closeTab, |
| 64 | reorderTabs, |
| 65 | togglePinTab, |
| 66 | closeOtherTabs, |
| 67 | closeRightTabs, |
| 68 | closeAllTabs, |
| 69 | goBack, |
| 70 | goForward, |
| 71 | canGoBack, |
| 72 | canGoForward, |
| 73 | keepTab, |
| 74 | history, |
| 75 | historyIndex, |
| 76 | clearHistory, |
| 77 | navigateToHistoryIndex |
| 78 | } = useTabsStore() |
| 79 | const { revealPanel } = useLayoutStore() |
| 80 | // 直接使用 pagesService,避免订阅 pagesStore 导致不必要的重渲染 |
| 81 | const { createPage, openPage } = pagesService |
| 82 | |
| 83 | const sensors = useSensors( |
| 84 | useSensor(PointerSensor, { |
| 85 | activationConstraint: { distance: 5 } |
| 86 | }) |
| 87 | ) |
| 88 | |
| 89 | const handleDragEnd = (event: DragEndEvent): void => { |
| 90 | const { active, over } = event |
| 91 | if (!over || active.id === over.id) return |
| 92 | |
| 93 | const oldIndex = tabs.findIndex((t) => t.id === active.id) |
| 94 | const newIndex = tabs.findIndex((t) => t.id === over.id) |
| 95 | reorderTabs(oldIndex, newIndex) |
| 96 | } |
| 97 | |
| 98 | const getContextMenuItems = (tabId: string): MenuProps['items'] => { |
| 99 | const tab = tabs.find((t) => t.id === tabId) |
| 100 | const items: MenuProps['items'] = [] |
| 101 | |
| 102 | if (tab?.preview) { |
| 103 | items.push({ |
| 104 | key: 'keep', |
| 105 | label: '保持打开', |
| 106 | onClick: ({ domEvent }) => { |
| 107 | domEvent.stopPropagation() |
| 108 | keepTab(tabId) |
| 109 | } |
| 110 | }) |
| 111 | items.push({ type: 'divider' }) |
| 112 | } |
| 113 | |
| 114 | items.push( |
| 115 | { |
nothing calls this directly
no test coverage detected