Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/tabs/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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?: (
Expand Down Expand Up @@ -49,7 +51,9 @@ export interface ITabProps<T = any, P = any> {
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;
}

Expand Down
22 changes: 22 additions & 0 deletions src/workbench/editor/__tests__/group.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'reflect-metadata';
import React from 'react';
import { render, cleanup, fireEvent, waitFor } from '@testing-library/react';
import { tabItemActiveClassName } from 'mo/components/tabs/tab';

import EditorGroup from '../group';
import { IEditorTab } from 'mo/model';

const TEST_ID = 'test-id';
const TEST_MENU = 'test-menu';
Expand Down Expand Up @@ -130,4 +132,24 @@ describe('The Editor Component', () => {
expect(fn).toBeCalled();
});
});

test('use renderPane method', async () => {
const renderPane = jest.fn((tabData, tab, group) => {
return <div className={tab.id}>{tab.id}</div>;
});

const testTab: IEditorTab = {
id: TEST_ID,
name: TEST_ID,
data: {},
renderPane,
};

const { container } = render(
<EditorGroup id="test" onClickActions={jest.fn()} tab={testTab} />
);
const renderDiv = container.querySelector(`.${TEST_ID}`);

expect(renderDiv?.innerHTML).toEqual(TEST_ID);
});
});
2 changes: 2 additions & 0 deletions src/workbench/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function Editor(
<EditorGroup
editorOptions={editorOptions}
currentGroup={current!}
group={groups[0]}
{...groups[0]}
{...getEvents(groups[0].id!)}
/>
Expand All @@ -74,6 +75,7 @@ export function Editor(
<EditorGroup
editorOptions={editorOptions}
currentGroup={current!}
group={g}
{...g}
{...getEvents(g.id!)}
/>
Expand Down
10 changes: 9 additions & 1 deletion src/workbench/editor/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,6 +31,7 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) {
data,
tab,
currentGroup,
group,
actions = [],
menu = [],
onMoveTab,
Expand Down Expand Up @@ -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
)
Expand Down
26 changes: 26 additions & 0 deletions stories/extensions/test/testPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ export type GenericClassDecorator<T> = (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 <div style={style}>{name}</div>;
},
};
molecule.editor.open(tabData);
};

const updateEntryPage = () => {
const style: React.CSSProperties = {
display: 'flex',
Expand Down Expand Up @@ -427,6 +452,7 @@ PARTITIONED BY (DE STRING) LIFECYCLE 1000;
<Button onClick={toggleEditorStatus}>
Toggle Editor status
</Button>
<Button onClick={newPane}>New Pane</Button>
<Button onClick={updateEntryPage}>
Update Entry Page
</Button>
Expand Down