-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add more actions menu on SelectionTools * feat: add view source context action * feat: normalize hotkey by platform * feat: add context menu to components tree * feat: add context menu to viewport
- Loading branch information
Showing
18 changed files
with
559 additions
and
60 deletions.
There are no files selected for viewing
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,125 @@ | ||
import React from 'react'; | ||
import { getWidget } from '../widgets'; | ||
import { Menu, MenuProps } from 'antd'; | ||
import { observer, useWorkspace } from '@music163/tango-context'; | ||
import { ISelectedItemData, isString } from '@music163/tango-helpers'; | ||
import { Box, css } from 'coral-system'; | ||
import { IconFont } from '@music163/tango-ui'; | ||
|
||
const contextMenuStyle = css` | ||
.ant-dropdown-menu { | ||
width: 240px; | ||
} | ||
.ant-dropdown-menu-title-content { | ||
padding-left: 20px; | ||
} | ||
.ant-dropdown-menu-item-icon + .ant-dropdown-menu-title-content { | ||
padding-left: 0; | ||
} | ||
.ant-dropdown-menu-submenu-popup { | ||
padding: 0; | ||
margin-top: -4px; | ||
} | ||
`; | ||
|
||
const ParentNodesMenuItem = ({ | ||
record, | ||
onClick, | ||
key, | ||
}: { | ||
record: ISelectedItemData; | ||
onClick: () => any; | ||
key?: string; | ||
}) => { | ||
const workspace = useWorkspace(); | ||
const componentPrototype = workspace.componentPrototypes.get(record.name); | ||
const icon = componentPrototype?.icon || 'icon-placeholder'; | ||
|
||
const iconRender = icon.startsWith('icon-') ? ( | ||
<IconFont className="material-icon" type={icon} /> | ||
) : ( | ||
<img className="material-icon" src={icon} alt={componentPrototype.name} /> | ||
); | ||
|
||
return ( | ||
<Menu.Item key={key || record.id} icon={iconRender} onClick={onClick}> | ||
{record.name} | ||
{!!record.codeId && ` (${record.codeId})`} | ||
</Menu.Item> | ||
); | ||
}; | ||
|
||
const ParentNodesMenu = observer(() => { | ||
const workspace = useWorkspace(); | ||
const selectSource = workspace.selectSource; | ||
const parents = selectSource.first?.parents; | ||
|
||
if (!parents?.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Menu.SubMenu key="parentNodes" title="选取父节点"> | ||
{parents.map((item, index) => ( | ||
<ParentNodesMenuItem | ||
key={item.id} | ||
record={item} | ||
onClick={() => { | ||
selectSource.select({ | ||
...item, | ||
parents: parents.slice(index + 1), | ||
}); | ||
}} | ||
/> | ||
))} | ||
</Menu.SubMenu> | ||
); | ||
}); | ||
|
||
export interface ContextMenuProps extends MenuProps { | ||
/** | ||
* 动作列表,默认列出全部 | ||
*/ | ||
actions?: Array<string | React.ReactElement>; | ||
/** | ||
* 是否显示父节点选项 | ||
*/ | ||
showParents?: boolean; | ||
className?: string; | ||
style?: React.CSSProperties; | ||
menuStyle?: React.CSSProperties; | ||
} | ||
|
||
export const ContextMenu = observer( | ||
({ | ||
showParents, | ||
actions: actionsProp, | ||
className, | ||
style, | ||
menuStyle, | ||
...rest | ||
}: ContextMenuProps) => { | ||
const actions = actionsProp || Object.keys(getWidget('contextMenu')); | ||
const menus = actions.map((item) => { | ||
if (isString(item)) { | ||
const widget = getWidget(['contextMenu', item].join('.')); | ||
return widget ? React.createElement(widget) : null; | ||
} | ||
return item; | ||
}); | ||
if (showParents) { | ||
menus.unshift(<ParentNodesMenu />); | ||
} | ||
|
||
return ( | ||
<Box display="inline-block" css={contextMenuStyle} className={className} style={style}> | ||
<Menu activeKey={null} {...rest} style={menuStyle}> | ||
{menus} | ||
</Menu> | ||
</Box> | ||
); | ||
}, | ||
); |
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,19 @@ | ||
import React from 'react'; | ||
import { useWorkspace, observer } from '@music163/tango-context'; | ||
import { ContextAction } from '@music163/tango-ui'; | ||
import { CopyOutlined } from '@ant-design/icons'; | ||
|
||
export const CopyNodeContextAction = observer(() => { | ||
const workspace = useWorkspace(); | ||
return ( | ||
<ContextAction | ||
icon={<CopyOutlined />} | ||
hotkey="Command+C" | ||
onClick={() => { | ||
workspace.copySelectedNode(); | ||
}} | ||
> | ||
复制节点 | ||
</ContextAction> | ||
); | ||
}); |
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,19 @@ | ||
import React from 'react'; | ||
import { useWorkspace, observer } from '@music163/tango-context'; | ||
import { ContextAction } from '@music163/tango-ui'; | ||
import { DeleteOutlined } from '@ant-design/icons'; | ||
|
||
export const DeleteNodeContextAction = observer(() => { | ||
const workspace = useWorkspace(); | ||
return ( | ||
<ContextAction | ||
icon={<DeleteOutlined />} | ||
hotkey="Backspace" | ||
onClick={() => { | ||
workspace.removeSelectedNode(); | ||
}} | ||
> | ||
删除节点 | ||
</ContextAction> | ||
); | ||
}); |
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,4 @@ | ||
export * from './copy-node'; | ||
export * from './delete-node'; | ||
export * from './paste-node'; | ||
export * from './view-source'; |
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,19 @@ | ||
import React from 'react'; | ||
import { useWorkspace, observer } from '@music163/tango-context'; | ||
import { ContextAction } from '@music163/tango-ui'; | ||
import { SnippetsOutlined } from '@ant-design/icons'; | ||
|
||
export const PasteNodeContextAction = observer(() => { | ||
const workspace = useWorkspace(); | ||
return ( | ||
<ContextAction | ||
icon={<SnippetsOutlined />} | ||
hotkey="Command+V" | ||
onClick={() => { | ||
workspace.pasteSelectedNode(); | ||
}} | ||
> | ||
粘贴节点 | ||
</ContextAction> | ||
); | ||
}); |
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,18 @@ | ||
import React from 'react'; | ||
import { useDesigner, observer } from '@music163/tango-context'; | ||
import { ContextAction } from '@music163/tango-ui'; | ||
import { CodeOutlined } from '@ant-design/icons'; | ||
|
||
export const ViewSourceContextAction = observer(() => { | ||
const designer = useDesigner(); | ||
return ( | ||
<ContextAction | ||
icon={<CodeOutlined />} | ||
onClick={() => { | ||
designer.setActiveView('code'); | ||
}} | ||
> | ||
查看源码 | ||
</ContextAction> | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './copy-node'; | ||
export * from './delete-node'; | ||
export * from './more-actions'; | ||
export * from './select-parent-node'; | ||
export * from './view-source'; |
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,16 @@ | ||
import React from 'react'; | ||
import { observer } from '@music163/tango-context'; | ||
import { SelectAction } from '@music163/tango-ui'; | ||
import { MoreOutlined } from '@ant-design/icons'; | ||
import { Dropdown } from 'antd'; | ||
import { ContextMenu } from '../components'; | ||
|
||
export const MoreActionsAction = observer(() => { | ||
return ( | ||
<Dropdown placement="bottomRight" overlay={<ContextMenu showParents />}> | ||
<SelectAction tooltip="更多"> | ||
<MoreOutlined /> | ||
</SelectAction> | ||
</Dropdown> | ||
); | ||
}); |
Oops, something went wrong.