-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(panel): support add, remove and update Panel features, builtin O…
…UTPUT and PROBLEMS panel Add basic Panel view, and suppurted add, remove, get, update and so on operations for Panel. re #19, re #22
- Loading branch information
Showing
9 changed files
with
322 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as React from 'react'; | ||
import { IActionBarItem } from 'mo/components/actionBar'; | ||
import { PanelStatus } from 'mo/model/workbench/panel'; | ||
import { Controller } from 'mo/react/controller'; | ||
import { panelService } from 'mo/services'; | ||
import { singleton } from 'tsyringe'; | ||
|
||
export interface IPanelController { | ||
onTabChange(key: string | undefined): void; | ||
onToolbarClick(e: React.MouseEvent, item: IActionBarItem): void; | ||
} | ||
|
||
@singleton() | ||
export class PanelController extends Controller implements IPanelController { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
public readonly onTabChange = (key: string): void => { | ||
const state = panelService.getState(); | ||
if (key) { | ||
panelService.setState({ | ||
current: state.data?.find((item) => item.id === key), | ||
}); | ||
} | ||
}; | ||
|
||
public readonly onToolbarClick = ( | ||
e: React.MouseEvent, | ||
item: IActionBarItem | ||
): void => { | ||
if (item.id === 'Closeable') { | ||
panelService.setState({ | ||
status: PanelStatus.Close, | ||
}); | ||
} else if (item.id === 'Resize') { | ||
panelService.setState({ | ||
status: PanelStatus.Maximize, | ||
}); | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import { IActionBarItem } from 'mo/components/actionBar'; | ||
import { ITab } from 'mo/components/tabs/tab'; | ||
import { injectable } from 'tsyringe'; | ||
import Output from 'mo/workbench/panel/output'; | ||
import Problems from 'mo/workbench/panel/problems'; | ||
|
||
export interface IPanelItem<T = any> extends ITab<any> { | ||
id: string; | ||
title?: string; | ||
toolbox?: IActionBarItem[]; | ||
data?: T; | ||
render?(item: IPanelItem): ReactNode; | ||
} | ||
|
||
export enum PanelEvent { | ||
onClick = 'panel.onClick', | ||
} | ||
|
||
export enum PanelStatus { | ||
Close = 'close', | ||
Open = 'open', | ||
Maximize = 'maximize', | ||
} | ||
|
||
export interface IPanel { | ||
current?: IPanelItem; | ||
data?: IPanelItem[]; | ||
toolbox?: IActionBarItem[]; | ||
status?: PanelStatus; | ||
} | ||
|
||
export const PANEL_PROBLEMS: IPanelItem = { | ||
id: 'ProblemsPane', | ||
name: 'problems', | ||
renderPanel: 'Problems', | ||
data: null, | ||
render: (item) => <Problems {...item} />, | ||
}; | ||
|
||
export const PANEL_OUTPUT: IPanelItem = { | ||
id: 'OutputPane', | ||
name: 'output', | ||
renderPanel: 'output', | ||
data: 'output', | ||
render: (item) => <Output {...item} />, | ||
}; | ||
|
||
export const PANEL_TOOLBOX_CLOSE = { | ||
id: 'Close', | ||
title: 'Close Panel', | ||
iconName: 'codicon-close', | ||
}; | ||
|
||
export const PANEL_TOOLBOX_RESIZE = { | ||
id: 'Resize', | ||
title: 'Maximize Panel Size', | ||
iconName: 'codicon-chevron-up', | ||
}; | ||
|
||
@injectable() | ||
export class PanelModel implements IPanel { | ||
public current: IPanelItem | undefined = PANEL_OUTPUT; | ||
public data: IPanelItem[] = ([] = [PANEL_PROBLEMS, PANEL_OUTPUT]); | ||
public status = PanelStatus.Open; | ||
public toolbox: IActionBarItem[] = [ | ||
PANEL_TOOLBOX_RESIZE, | ||
PANEL_TOOLBOX_CLOSE, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import { prefixClaName } from 'mo/common/className'; | ||
import { IPanelItem } from 'mo/model/workbench/panel'; | ||
import MonacoEditor from 'mo/components/monaco'; | ||
|
||
const defaultClassName = prefixClaName('output'); | ||
|
||
function Output(props: IPanelItem) { | ||
const { data } = props; | ||
return ( | ||
<div className={defaultClassName}> | ||
<MonacoEditor | ||
options={{ | ||
value: data, | ||
readOnly: true, | ||
lineDecorationsWidth: 0, | ||
lineNumbers: 'off', | ||
automaticLayout: true, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(Output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import { prefixClaName } from 'mo/common/className'; | ||
import { getBEMElement, prefixClaName } from 'mo/common/className'; | ||
import { IPanel } from 'mo/model/workbench/panel'; | ||
import { IPanelController } from 'mo/controller/panel'; | ||
import { Tabs } from 'mo/components/tabs'; | ||
import ActionBar from 'mo/components/actionBar'; | ||
|
||
const defaultClassName = prefixClaName('panel'); | ||
const panelHeaderClassName = getBEMElement(defaultClassName, 'header'); | ||
|
||
function Panel(props) { | ||
const panelToolbarClassName = getBEMElement(defaultClassName, 'toolbar'); | ||
|
||
const panelContainerClassName = getBEMElement(defaultClassName, 'container'); | ||
|
||
function Panel(props: IPanel & IPanelController) { | ||
console.log('Panel render:', props); | ||
const { data, current, toolbox = [], onTabChange, onToolbarClick } = props; | ||
let toolboxData = toolbox; | ||
if (current && current.toolbox) { | ||
toolboxData = current.toolbox.concat(toolbox); | ||
} | ||
|
||
return <div className={defaultClassName}>Panel</div>; | ||
return ( | ||
<div className={defaultClassName}> | ||
<div className={panelHeaderClassName}> | ||
<Tabs data={data} onSelectTab={onTabChange} /> | ||
<ActionBar | ||
className={panelToolbarClassName} | ||
data={toolboxData || []} | ||
onClick={onToolbarClick} | ||
/> | ||
</div> | ||
<div className={panelContainerClassName}> | ||
{current?.render?.(current)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(Panel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import { prefixClaName } from 'mo/common/className'; | ||
import { IPanelItem } from 'mo/model/workbench/panel'; | ||
|
||
const defaultClassName = prefixClaName('problems'); | ||
|
||
function Problems(props: IPanelItem) { | ||
const { data } = props; | ||
return ( | ||
<div className={defaultClassName} style={{ margin: '0 18px' }}> | ||
Problems {data} | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(Problems); |
Oops, something went wrong.