Skip to content

Commit 85eed7e

Browse files
committed
feat: add model layer and extract view interfaces to model file
1 parent 4fc75cf commit 85eed7e

File tree

7 files changed

+227
-30
lines changed

7 files changed

+227
-30
lines changed

src/model/activityBar.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-disable no-invalid-this */
2+
import { observable } from 'mo/common/observable';
3+
import { ActivityBarEvent, EventService } from 'mo/services';
4+
import { container, inject, injectable } from 'tsyringe';
5+
6+
7+
export interface IActivityBarItem {
8+
id?: string;
9+
name?: string;
10+
data?: any;
11+
iconName?: string;
12+
checked?: boolean;
13+
type?: 'normal' | 'global';
14+
render?: () => React.ReactNode | JSX.Element;
15+
onClick?: (event: React.MouseEvent, item: IActivityBarItem) => void;
16+
}
17+
18+
export interface IActivityBar {
19+
data: IActivityBarItem[];
20+
selected?: string;
21+
onSelect?: (key: string, item?: IActivityBarItem) => void;
22+
onClick?: (event: React.MouseEvent, item: IActivityBarItem) => void;
23+
render?: () => React.ReactNode;
24+
}
25+
26+
@observable()
27+
@injectable()
28+
export class ActivityBarModel implements IActivityBar {
29+
public data: IActivityBarItem[];
30+
public selected: string;
31+
32+
constructor(
33+
@inject('ActivityBarData') data: IActivityBarItem[] = [],
34+
@inject('ActivityBarSelected') selected: string = '',
35+
) {
36+
this.data = data;
37+
this.selected = selected;
38+
}
39+
40+
public render!: () => React.ReactNode;
41+
42+
public readonly onSelect = (key: string, item?: IActivityBarItem | undefined) => {
43+
this.selected = key;
44+
EventService.emit(ActivityBarEvent.Selected, key, item);
45+
}
46+
47+
public readonly onClick = (event: React.MouseEvent, item: IActivityBarItem) => {
48+
EventService.emit(ActivityBarEvent.OnClick, event, item);
49+
}
50+
}
51+
52+
container.register('ActivityBarData', { useValue: [] });
53+
container.register('ActivityBarSelected', { useValue: '' });

src/model/editor.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-disable no-invalid-this */
2+
import { observable } from 'mo/common/observable';
3+
import { ITab } from 'mo/components/tabs';
4+
import { container, inject, injectable } from 'tsyringe';
5+
6+
7+
export interface IEditor {
8+
current: IEditorGroup | undefined;
9+
groups: IEditorGroup [];
10+
closeAll?: () => void;
11+
onClose?: () => void;
12+
render?:() => React.ReactNode;
13+
}
14+
15+
export interface IEditorGroup<E = any> {
16+
id: number;
17+
activeTab: ITab;
18+
tabs: ITab[];
19+
breadcrumb: any[];
20+
actions: any[];
21+
menu: any[];
22+
editorInstance?: E | null;
23+
}
24+
25+
export class EditorGroupModel implements IEditorGroup {
26+
id: number;
27+
activeTab: ITab;
28+
tabs: ITab[];
29+
breadcrumb: any[];
30+
actions: any[];
31+
menu: any[];
32+
editorInstance: any;
33+
34+
constructor(
35+
id: number,
36+
activeTab: ITab,
37+
tabs: ITab[],
38+
breadcrumb: any[] = [],
39+
actions: any[] = [],
40+
menu: any[] = [],
41+
editorInstance?: any,
42+
) {
43+
this.id = id;
44+
this.tabs = tabs;
45+
this.menu = menu;
46+
this.actions = actions;
47+
this.activeTab = activeTab;
48+
this.breadcrumb = breadcrumb;
49+
this.editorInstance = editorInstance;
50+
}
51+
}
52+
53+
@observable()
54+
@injectable()
55+
export class EditorModel implements IEditor {
56+
public current: IEditorGroup | undefined;
57+
public groups!: IEditorGroup[];
58+
59+
constructor(
60+
@inject('CurrentEditorGroup') current?: IEditorGroup,
61+
@inject('EditorGroup') groups: IEditorGroup[] = [],
62+
) {
63+
this.current = current;
64+
this.groups = groups;
65+
}
66+
67+
public render!: () => React.ReactNode;
68+
}
69+
70+
container.register('CurrentEditorGroup', { useValue: '' });
71+
container.register('EditorGroup', { useValue: [] });

src/model/editorGroup.ts

-30
This file was deleted.

src/model/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './activityBar';
2+
export * from './editor';
3+
export * from './menuBar';
4+
export * from './sidebar';
5+
export * from './statusBar';

src/model/menuBar.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { observable } from 'mo/common/observable';
2+
import { container, injectable, inject } from 'tsyringe';
3+
4+
export interface IMenuBarItem {
5+
id?: string;
6+
name?: string;
7+
data?: any;
8+
iconName?: string;
9+
render?: () => React.ReactNode | JSX.Element;
10+
onClick?:(e: React.MouseEvent, option: IMenuBarItem) => any;
11+
}
12+
13+
export interface IMenuBar {
14+
data: IMenuBarItem[];
15+
onClick:(event: React.MouseEvent<any, any>, item: IMenuBarItem) => void;
16+
render?: () => React.ReactNode | JSX.Element;
17+
}
18+
19+
@observable()
20+
@injectable()
21+
export class MenuBarModel implements IMenuBar {
22+
public data: IMenuBarItem[];
23+
24+
constructor(@inject('MenuBarData') data: IMenuBarItem[] = []) {
25+
this.data = data;
26+
}
27+
28+
public render!: () => React.ReactNode;
29+
30+
public readonly onClick = (event: React.MouseEvent, item: IMenuBarItem) => {
31+
console.log('onClick:', event);
32+
}
33+
}
34+
35+
container.register('MenuBarData', { useValue: [] });

src/model/sidebar.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { observable } from 'mo/common/observable';
2+
import { container, inject, injectable } from 'tsyringe';
3+
4+
export interface ISidebarPane {
5+
id?: string;
6+
name?: string;
7+
render?: () => React.ReactElement | undefined;
8+
}
9+
10+
export interface ISidebar {
11+
selected: string;
12+
panes: ISidebarPane[];
13+
render?: () => React.ReactNode;
14+
}
15+
16+
@observable()
17+
@injectable()
18+
export class SidebarModel implements ISidebar {
19+
public selected: string;
20+
public panes: ISidebarPane[];
21+
22+
constructor(
23+
@inject('SidebarPane') panes: ISidebarPane[] = [],
24+
@inject('Selected') selected: string = '',
25+
) {
26+
this.panes = panes;
27+
this.selected = selected;
28+
}
29+
30+
public render!: () => React.ReactNode;
31+
}
32+
33+
container.register('SidebarPane', { useValue: [] });
34+
container.register('Selected', { useValue: '' });

src/model/statusBar.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { observable } from 'mo/common/observable';
2+
import { container, inject, injectable } from 'tsyringe';
3+
4+
export interface IStatusBarItem {
5+
}
6+
7+
export interface IStatusBar {
8+
data: IStatusBarItem[];
9+
onClick:(event: React.MouseEvent<any, any>) => void;
10+
render?: () => React.ReactNode | JSX.Element;
11+
}
12+
13+
@observable()
14+
@injectable()
15+
export class StatusBarModel implements IStatusBar {
16+
public data: IStatusBarItem[] = [];
17+
18+
constructor(@inject('StatusBarData') data: IStatusBarItem[] = []) {
19+
this.data = data;
20+
}
21+
22+
public render!: () => React.ReactNode;
23+
24+
public onClick = (event: React.MouseEvent) => {
25+
console.log('onClick:', event);
26+
}
27+
}
28+
29+
container.register('StatusBarData', { useValue: [] });

0 commit comments

Comments
 (0)