forked from opensumi/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabbar.view.tsx
209 lines (191 loc) · 6.59 KB
/
tabbar.view.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import cls from 'classnames';
import React, { useCallback, useEffect, useMemo } from 'react';
import {
ComponentRegistryInfo,
SlotLocation,
useAutorun,
useContextMenus,
useInjectable,
} from '@opensumi/ide-core-browser';
import { EDirection } from '@opensumi/ide-core-browser/lib/components';
import {
EnhanceIcon,
EnhanceIconWithCtxMenu,
EnhancePopover,
HorizontalVertical,
} from '@opensumi/ide-core-browser/lib/components/ai-native';
import { DesignLayoutConfig } from '@opensumi/ide-core-browser/lib/layout/constants';
import { IMenu } from '@opensumi/ide-core-browser/lib/menu/next';
import { localize } from '@opensumi/ide-core-common';
import { DesignLeftTabRenderer, DesignRightTabRenderer } from '@opensumi/ide-design/lib/browser/layout/tabbar.view';
import { IMainLayoutService } from '@opensumi/ide-main-layout';
import {
ChatTabbarRenderer2,
IconElipses,
IconTabView,
LeftTabbarRenderer,
RightTabbarRenderer,
TabbarViewBase,
} from '@opensumi/ide-main-layout/lib/browser/tabbar/bar.view';
import { BaseTabPanelView, ContainerView } from '@opensumi/ide-main-layout/lib/browser/tabbar/panel.view';
import { TabRendererBase, TabbarConfig } from '@opensumi/ide-main-layout/lib/browser/tabbar/renderer.view';
import { TabbarService, TabbarServiceFactory } from '@opensumi/ide-main-layout/lib/browser/tabbar/tabbar.service';
import { AI_CHAT_VIEW_ID } from '../../common';
import styles from './layout.module.less';
const ChatTabbarRenderer: React.FC = () => {
const { side } = React.useContext(TabbarConfig);
const tabbarService: TabbarService = useInjectable(TabbarServiceFactory)(side);
useEffect(() => {
tabbarService.setIsLatter(true);
}, [tabbarService]);
return (
<div style={{ width: 0 }}>
<TabbarViewBase tabSize={0} MoreTabView={IconElipses} TabView={IconTabView} barSize={0} panelBorderSize={1} />
</div>
);
};
export const AIChatTabRenderer = ({
className,
components,
}: {
className: string;
components: ComponentRegistryInfo[];
}) => (
<TabRendererBase
side={AI_CHAT_VIEW_ID}
direction={EDirection.LeftToRight}
id={styles.ai_chat_panel}
className={cls(className, `${AI_CHAT_VIEW_ID}-slot`)}
components={components}
TabbarView={() => <ChatTabbarRenderer />}
TabpanelView={() => (
<BaseTabPanelView
PanelView={ContainerView}
PanelViewProps={{
className: styles.ai_chat_view_container,
}}
/>
)}
/>
);
export const AIChatTabRendererWithTab = ({
className,
components,
}: {
className: string;
components: ComponentRegistryInfo[];
}) => (
<TabRendererBase
side={AI_CHAT_VIEW_ID}
direction={EDirection.RightToLeft}
id={styles.ai_chat_panel}
className={cls(className, `${AI_CHAT_VIEW_ID}-slot`, 'design_right_slot')}
components={components}
TabbarView={() => <ChatTabbarRenderer2 />}
TabpanelView={() => (
<BaseTabPanelView
PanelView={ContainerView}
PanelViewProps={{
className: styles.ai_chat_view_container,
}}
/>
)}
/>
);
export const AILeftTabRenderer = ({
className,
components,
}: {
className: string;
components: ComponentRegistryInfo[];
}) => <DesignLeftTabRenderer className={className} components={components} tabbarView={AILeftTabbarRenderer} />;
const AILeftTabbarRenderer: React.FC = () => {
const layoutService = useInjectable<IMainLayoutService>(IMainLayoutService);
const tabbarService: TabbarService = useInjectable(TabbarServiceFactory)(SlotLocation.right);
const currentContainerId = useAutorun(tabbarService.currentContainerId);
const extraMenus = React.useMemo(() => layoutService.getExtraMenu(), [layoutService]);
const [navMenu] = useContextMenus(extraMenus);
const renderOtherVisibleContainers = useCallback(
({ renderContainers }) => {
const visibleContainers = tabbarService.visibleContainers.filter((container) => !container.options?.hideTab);
return (
<>
{visibleContainers.length > 0 && <HorizontalVertical margin={'8px auto 0px'} width={'60%'} />}
{visibleContainers.map((component) => renderContainers(component, tabbarService, currentContainerId))}
</>
);
},
[currentContainerId, tabbarService],
);
return (
<LeftTabbarRenderer
renderOtherVisibleContainers={renderOtherVisibleContainers}
isRenderExtraTopMenus={false}
renderExtraMenus={
<div className={styles.extra_bottom_icon_container}>
{navMenu.length >= 0
? navMenu.map((menu) => (
<EnhanceIconWithCtxMenu
key={menu.id}
id={menu.id}
wrapperClassName={styles.extra_bottom_icon}
iconClass={menu.icon}
menuNodes={menu.children}
skew={{ x: -8, y: -4 }}
/>
))
: null}
</div>
}
/>
);
};
export const AIRightTabRenderer = ({
className,
components,
}: {
className: string;
components: ComponentRegistryInfo[];
}) => {
const tabbarService: TabbarService = useInjectable(TabbarServiceFactory)(SlotLocation.right);
const designLayoutConfig = useInjectable<DesignLayoutConfig>(DesignLayoutConfig);
const handleClose = useCallback(() => {
tabbarService.updateCurrentContainerId('');
}, []);
const ContainerViewFn = useCallback((props: { component: ComponentRegistryInfo; side: string; titleMenu: IMenu }) => {
const { component } = props;
const { options } = component;
return (
<ContainerView
{...props}
customTitleBar={
<div className={styles.header}>
<span className={styles.title}>{options && options.title}</span>
<div className={styles.side}>
<EnhancePopover id={'ai_right_panel_header_close'} title={localize('editor.title.context.close')}>
<EnhanceIcon icon='close' onClick={handleClose} />
</EnhancePopover>
</div>
</div>
}
renderContainerWrap={({ children }) => (
<div className={styles.right_slot_container_wrap}>
<div className={styles.container}>{children}</div>
</div>
)}
/>
);
}, []);
const rightTabRenderClassName = useMemo(
() => (designLayoutConfig.useMergeRightWithLeftPanel ? styles.right_tab_renderer : ''),
[designLayoutConfig],
);
return (
<DesignRightTabRenderer
components={components}
className={rightTabRenderClassName}
tabbarView={() => <RightTabbarRenderer barSize={0} style={{ width: 0 }} />}
tabpanelView={() => <BaseTabPanelView PanelView={ContainerViewFn} />}
/>
);
};