diff --git a/src/components/tabs/tab.tsx b/src/components/tabs/tab.tsx index 24da7f7e7..f6ea45db5 100644 --- a/src/components/tabs/tab.tsx +++ b/src/components/tabs/tab.tsx @@ -3,15 +3,17 @@ import { useRef } from 'react'; import { findDOMNode } from 'react-dom'; import { useDrag, useDrop } from 'react-dnd'; +import { IEditorGroup } from 'mo/model'; +import type { UniqueId } from 'mo/common/types'; import { classNames, getBEMElement, getBEMModifier, prefixClaName, } from 'mo/common/className'; + import TabExtra from './tabExtra'; import { Icon } from '../icon'; -import type { UniqueId } from 'mo/common/types'; export interface ITabEvent { onDrag?: ( @@ -49,7 +51,9 @@ export interface ITabProps { icon?: string | JSX.Element; id: UniqueId; name?: string; - renderPane?: ((item: P) => React.ReactNode) | React.ReactNode; + renderPane?: + | ((item: P, tab?: ITabProps, group?: IEditorGroup) => React.ReactNode) + | React.ReactNode; data?: T; } diff --git a/src/workbench/editor/editor.tsx b/src/workbench/editor/editor.tsx index 8ca56511f..670f74910 100644 --- a/src/workbench/editor/editor.tsx +++ b/src/workbench/editor/editor.tsx @@ -52,6 +52,7 @@ export function Editor( @@ -74,6 +75,7 @@ export function Editor( diff --git a/src/workbench/editor/group.tsx b/src/workbench/editor/group.tsx index 935570e0c..79d566f26 100644 --- a/src/workbench/editor/group.tsx +++ b/src/workbench/editor/group.tsx @@ -22,6 +22,7 @@ import { tabItemActiveClassName } from 'mo/components/tabs/tab'; export interface IEditorGroupProps extends IEditorGroup { currentGroup?: IEditorGroup; editorOptions?: IEditorOptions; + group?: IEditorGroup; } export function EditorGroup(props: IEditorGroupProps & IEditorController) { @@ -30,6 +31,7 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) { data, tab, currentGroup, + group, actions = [], menu = [], onMoveTab, @@ -114,7 +116,13 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) { // Default we use monaco editor, but also you can customize by renderPanel() function or a react element tab?.renderPane ? ( typeof tab.renderPane === 'function' ? ( - tab.renderPane(tab.data) + tab.renderPane( + { + ...tab.data, + }, + tab, + group + ) ) : ( tab.renderPane ) diff --git a/stories/extensions/test/testPane.tsx b/stories/extensions/test/testPane.tsx index c7b75e400..3d1348dbc 100644 --- a/stories/extensions/test/testPane.tsx +++ b/stories/extensions/test/testPane.tsx @@ -219,6 +219,30 @@ export type GenericClassDecorator = (target: T) => void;`, }); } }; + const newPane = function () { + const key = shortRandomId(); + const name = `pane-${key}.ts`; + const tabData: IEditorTab = { + id: `${key}`, + name, + icon: 'selection', + data: {}, + breadcrumb: [{ id: `${key}`, name }], + renderPane: (tabData, tab, group) => { + console.log(tabData, tab, group); + const style: React.CSSProperties = { + display: 'flex', + width: '100%', + height: '100%', + fontSize: 48, + alignItems: 'center', + justifyContent: 'center', + }; + return
{name}
; + }, + }; + molecule.editor.open(tabData); + }; const updateEntryPage = () => { const style: React.CSSProperties = { @@ -427,6 +451,7 @@ PARTITIONED BY (DE STRING) LIFECYCLE 1000; +