Skip to content

Commit 6141663

Browse files
committed
feat: test editor logic
1 parent 70f85e4 commit 6141663

File tree

4 files changed

+38
-58
lines changed

4 files changed

+38
-58
lines changed

src/components/tabs/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import TabButton from './tabButton';
1212

1313
import './style.scss';
1414
export interface ITab {
15+
path?: string;
1516
key?: string;
1617
name?: string;
1718
modified?: boolean;
@@ -25,8 +26,7 @@ export interface ITabsProps {
2526
closable?: boolean;
2627
data: ITab[];
2728
activeTab?: string;
28-
// TODO 支持Card editable-card 默认 inline
29-
type?: 'line' | 'card' |'editable-card';
29+
type?: 'line' | 'editable-card';
3030
onCloseTab?: (key?: string) => void ;
3131
onMoveTab?: (tabs: ITab[]) => void;
3232
onSelectTab?: (event: React.MouseEvent, key?: string) => void;
@@ -40,7 +40,6 @@ export const tabItemCloseClassName = getBEMElement(tabItemClassName, 'close')
4040

4141
const Tabs = (props: ITabsProps) => {
4242
const { closable, data, activeTab, type = 'line', onCloseTab, onSelectTab } = props;
43-
// const [activeTab, setActiveTab] = useState<string | number | void>(newActiveTab)
4443
const onMoveTab = useCallback(
4544
(dragIndex, hoverIndex) => {
4645
const dragTab = data[dragIndex];

src/extensions/search/searchPane.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,19 @@ export default class SearchPane extends React.Component<
8080
};
8181

8282
const newEditor = function () {
83-
const id = Math.random() * 10 + 1;
83+
const key = Math.random() * 10 + 1;
8484
const tabData = {
85-
activeTab: `${0}`,
86-
id: id,
85+
key: `${key}`,
8786
name: `editor.js`,
8887
modified: true,
89-
value: 'hello javascript',
88+
value: `hello javascript${key}`,
89+
path: 'desktop/molecule/editor1'
9090
};
9191
console.log('open editor:', tabData);
9292
editorService.open(tabData, 1);
9393
};
9494

9595
const openCommand = function () {
96-
// MonacoEditor.editor.getModel().
9796
};
9897
return (
9998
<div className={prefixClaName('search-pane', 'sidebar')}>

src/style/theme.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@
169169
color: #fff;
170170
}
171171

172-
&--line {
172+
&--editable-card {
173173
#{$tab}__item {
174174
&--active {
175-
border-bottom: 1px solid #e7e7e7;
176-
color: #e7e7e7;
175+
177176
}
178177
}
179178
}
@@ -186,7 +185,8 @@
186185

187186
&--active {
188187
background: #1e1e1e;
189-
color: #fff;
188+
border-bottom: 1px solid #e7e7e7;
189+
color: #e7e7e7;
190190
}
191191

192192
&--close {

src/workbench/editor/editor.tsx

+28-46
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,46 @@ import 'mo/workbench/editor/style.scss';
22
import * as React from 'react';
33
import SplitPane from 'react-split-pane';
44

5-
import MonacoEditor from 'mo/components/monaco-editor';
65
import { getBEMElement, prefixClaName } from 'mo/common/className';
7-
6+
import MonacoEditor from 'mo/components/monaco-editor';
87
import Tabs from 'mo/components/tabs';
8+
99
import Welcome from './welcome';
1010
import { IEditor, IEditorGroup } from 'mo/model';
1111

1212
const defaultEditorClassName = prefixClaName('editor');
1313
const groupClassName = getBEMElement(defaultEditorClassName, 'group');
14-
const groupContainerClassName = getBEMElement(
15-
defaultEditorClassName,
16-
'group-container'
17-
);
18-
const groupHeaderClassName = getBEMElement(
19-
defaultEditorClassName,
20-
'group-header'
21-
);
22-
const groupTabsClassName = getBEMElement(defaultEditorClassName, 'group-tabs');
23-
const groupBreadcrumbsClassName = getBEMElement(
24-
defaultEditorClassName,
25-
'group-breadcrumbs'
26-
);
2714

2815
function renderEditorGroup(group: IEditorGroup, onMoveTab, onSelectTab) {
2916
const editor = group.activeTab;
30-
// Todo 测试editor tabs
17+
18+
const tabs = group.tabs.map((item, index) => {
19+
return Object.assign({}, item, {
20+
key: item.key,
21+
tip: item.path,
22+
renderPanel: <MonacoEditor
23+
options={{
24+
value: item.value,
25+
language: item.language || 'sql',
26+
automaticLayout: true,
27+
}}
28+
editorInstanceRef={(editorInstance) => {
29+
// This assignment will trigger moleculeCtx update, and subNodes update
30+
group.editorInstance = editorInstance;
31+
}}
32+
/>
33+
})
34+
})
3135
return (
3236
<div className={groupClassName} key={`group-${group.id}`}>
33-
<div className={groupHeaderClassName}>
34-
<div className={groupTabsClassName}>
35-
<Tabs
36-
data={group.tabs}
37-
onMoveTab={onMoveTab}
38-
onTabChange={onSelectTab}
39-
/>
40-
</div>
41-
<div className={groupBreadcrumbsClassName}></div>
42-
</div>
43-
<div className={groupContainerClassName}>
44-
{
45-
// Default we use monaco editor, but also you can customize by renderPane() function
46-
editor.renderPanel ? (
47-
editor.renderPanel()
48-
) : (
49-
<MonacoEditor
50-
options={{
51-
value: editor.value,
52-
language: editor.language || 'sql',
53-
automaticLayout: true,
54-
}}
55-
editorInstanceRef={(editorInstance) => {
56-
// This assignment will trigger moleculeCtx update, and subNodes update
57-
group.editorInstance = editorInstance;
58-
}}
59-
/>
60-
)
61-
}
62-
</div>
37+
<Tabs
38+
type="editable-card"
39+
data={tabs}
40+
onMoveTab={onMoveTab}
41+
onSelectTab={onSelectTab}
42+
activeTab={editor.key}
43+
onCloseTab={(tabKey) => console.log(tabKey)}
44+
/>
6345
</div>
6446
);
6547
}

0 commit comments

Comments
 (0)