Skip to content

Commit fa829a7

Browse files
committed
feat: resolve emitEvent params missing
1 parent 9c38fee commit fa829a7

File tree

6 files changed

+47
-86
lines changed

6 files changed

+47
-86
lines changed

src/common/event/eventEmitter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class EventEmitter {
66
if (events && events.length > 0) {
77
// The log for development
88
events.forEach((callEvent) => {
9+
console.log(...args)
910
callEvent(...args);
1011
});
1112
}

src/components/tabs/Tab.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export const Tab = (props) => {
6767
const hoverClientX =
6868
(clientOffset as { x: number; y: number }).x -
6969
hoverBoundingRect.left;
70-
// 往下拖动
70+
// drag down
7171
if (dragIndex < hoverIndex && hoverClientX < hoverMiddleX) {
7272
return;
7373
}
74-
// 往上拖动
74+
// drag up
7575
if (dragIndex > hoverIndex && hoverClientX > hoverMiddleX) {
7676
return;
7777
}
@@ -87,7 +87,7 @@ export const Tab = (props) => {
8787
className={classNames(tabItemClassName, {
8888
[getBEMModifier(tabItemClassName, 'active')]: active,
8989
})}
90-
onClick={(event: React.MouseEvent) => onTabChange(event, propsKey)}
90+
onClick={(event: React.MouseEvent) => onTabChange(propsKey)}
9191
onMouseOver={handleMouseOver}
9292
onMouseOut={handleMouseOut}
9393
>

src/components/tabs/index.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
classNames,
1212
} from 'mo/common/className';
1313

14-
import { Tab, tabItemClassName } from './Tab';
14+
import { Tab, tabItemClassName } from './tab';
1515

1616
import './style.scss';
1717
export interface ITab {
@@ -50,7 +50,6 @@ const Tabs = (props: ITabsProps) => {
5050
onCloseTab,
5151
onSelectTab,
5252
} = props;
53-
debugger;
5453
const onMoveTab = useCallback(
5554
(dragIndex, hoverIndex) => {
5655
const dragTab = data[dragIndex];
@@ -66,9 +65,6 @@ const Tabs = (props: ITabsProps) => {
6665
[data]
6766
);
6867

69-
const onTabClick = (e: React.MouseEvent, key?: string) => {
70-
onSelectTab?.(key);
71-
};
7268
return (
7369
<DndProvider backend={HTML5Backend}>
7470
<div
@@ -82,7 +78,7 @@ const Tabs = (props: ITabsProps) => {
8278
return (
8379
<Tab
8480
onMoveTab={onMoveTab}
85-
onTabChange={onTabClick}
81+
onTabChange={onSelectTab}
8682
onTabClose={onCloseTab}
8783
index={index}
8884
propsKey={tab.key}

src/components/tabs/style.scss

+28-60
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,15 @@
3838

3939
#{$tab} {
4040
&__item {
41-
align-items: center;
42-
4341
align-items: center;
4442
box-sizing: border-box;
4543
cursor: pointer;
46-
cursor: pointer;
4744
display: flex;
48-
display: inline-flex;
4945
font-size: 13px;
5046
height: 100%;
51-
height: 100%;
5247
max-width: 300px;
5348
min-width: 40px;
5449
padding: 0 20px;
55-
padding: 0 14px;
5650
position: relative;
5751
user-select: none;
5852

@@ -64,64 +58,38 @@
6458
&__op {
6559
margin-left: 10px;
6660
width: 20px;
67-
}
6861

69-
&__dot {
70-
display: block;
71-
height: 18px;
72-
position: relative;
73-
width: 18px;
74-
75-
&::after {
76-
border-radius: 50%;
77-
content: '';
62+
&__dot {
7863
display: block;
79-
height: 9px;
80-
left: 5px;
64+
height: 18px;
8165
position: relative;
82-
top: 5px;
83-
width: 9px;
66+
width: 18px;
67+
68+
&::after {
69+
border-radius: 50%;
70+
content: '';
71+
display: block;
72+
height: 9px;
73+
left: 5px;
74+
position: relative;
75+
top: 5px;
76+
width: 9px;
77+
}
78+
}
79+
80+
&__close {
81+
cursor: pointer;
82+
display: block;
83+
font-weight: 500;
84+
height: 18px;
85+
width: 18px;
86+
}
87+
88+
&__placeholder {
89+
display: block;
90+
height: 18px;
91+
width: 18px;
8492
}
8593
}
86-
87-
&__close {
88-
cursor: pointer;
89-
display: block;
90-
font-weight: 500;
91-
height: 18px;
92-
width: 18px;
93-
}
94-
95-
&__placeholder {
96-
display: block;
97-
height: 18px;
98-
width: 18px;
99-
}
100-
101-
// &--active::after {
102-
// bottom: 0;
103-
// content: '';
104-
// height: 1px;
105-
// left: 0;
106-
// position: absolute;
107-
// width: 100%;
108-
// }
109-
110-
// &__wrapper {
111-
// display: flex;
112-
// justify-content: flex-start;
113-
// }
114-
115-
// &__close {
116-
// font-size: 13px;
117-
// font-weight: 700;
118-
// height: 14px;
119-
// margin-left: 8px;
120-
// visibility: visible;
121-
// width: 14px;
122-
// }
123-
124-
// &__button {
125-
// }
12694
}
12795
}

src/services/workbench/editorService.ts

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Component } from 'mo/react';
1+
import { singleton, container } from 'tsyringe';
2+
import { isEmpty } from 'loadsh';
23

3-
import { ITab } from 'mo/components/tabs';
4+
import { Component } from 'mo/react';
45
import { emit } from 'mo/common/event';
5-
import { singleton, container } from 'tsyringe';
6+
import { ITab } from 'mo/components/tabs';
67
import {
78
EditorEvent,
89
EditorModel,
@@ -35,12 +36,10 @@ export class EditorService
3536

3637
@emit(EditorEvent.OnSelectTab)
3738
onSelectTab(callback: (tabKey: string) => void) {
38-
this.subscribe(EditorEvent.OnSelectTab, (args) => {
39+
this.subscribe(EditorEvent.OnSelectTab, (targetKey: string, groupId?: number) => {
3940
let group;
4041
let { groups } = this.state;
41-
const groupId = args?.[1];
42-
const targetKey = args?.[0];
43-
if (!groupId) return;
42+
if (groupId === undefined) return;
4443
group = groups?.find((group: IEditorGroup) => group.id === groupId);
4544
group.activeTab = { ...group.activeTab, key: targetKey };
4645
callback?.(targetKey);
@@ -66,26 +65,23 @@ export class EditorService
6665

6766
@emit(EditorEvent.OnMoveTab)
6867
public onMoveTab(callback: (data) => void) {
69-
this.subscribe(EditorEvent.OnMoveTab, (args) => {
68+
this.subscribe(EditorEvent.OnMoveTab, (tabs: ITab[], groupId?: number) => {
7069
let { groups } = this.state;
7170
let group;
72-
if (!args?.[1]) return;
73-
const groupId = args?.[1];
71+
if (isEmpty(groupId)) return;
7472
group = groups?.find((group: IEditorGroup) => group.id === groupId);
75-
group.tabs = args?.[0];
76-
callback?.(args?.[0]);
73+
group.tabs = tabs;
74+
callback?.(tabs);
7775
});
7876
}
7977
public closeAll() {}
8078

8179
@emit(EditorEvent.OnCloseTab)
8280
public onCloseTab(callback: (data) => void) {
83-
this.subscribe(EditorEvent.OnCloseTab, (args) => {
81+
this.subscribe(EditorEvent.OnCloseTab, (targetKey: string, groupId?: number) => {
8482
let group, lastIndex;
8583
let { groups } = this.state;
86-
const groupId = args?.[1];
87-
const targetKey = args?.[0];
88-
if (!groupId) return;
84+
if (groupId === undefined) return;
8985
group = groups?.find((group: IEditorGroup) => group.id === groupId);
9086
let newActiveKey = group?.activeTab?.key;
9187
const groupTabs = group.tabs;

src/workbench/editor/editor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SplitPane from 'react-split-pane';
55
import { getBEMElement, prefixClaName } from 'mo/common/className';
66
import MonacoEditor from 'mo/components/monaco-editor';
77
import Tabs from 'mo/components/tabs';
8-
import { tabItemClassName } from 'mo/components/tabs/Tab';
8+
import { tabItemClassName } from 'mo/components/tabs/tab';
99
import { Icon } from 'mo/components/icon';
1010
import Welcome from './welcome';
1111
import { IEditor, IEditorGroup } from 'mo/model';

0 commit comments

Comments
 (0)