File tree Expand file tree Collapse file tree 5 files changed +65
-3
lines changed
Expand file tree Collapse file tree 5 files changed +65
-3
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,17 @@ import { useRef } from 'react';
33import { findDOMNode } from 'react-dom' ;
44import { useDrag , useDrop } from 'react-dnd' ;
55
6+ import { IEditorGroup } from 'mo/model' ;
7+ import type { UniqueId } from 'mo/common/types' ;
68import {
79 classNames ,
810 getBEMElement ,
911 getBEMModifier ,
1012 prefixClaName ,
1113} from 'mo/common/className' ;
14+
1215import TabExtra from './tabExtra' ;
1316import { Icon } from '../icon' ;
14- import type { UniqueId } from 'mo/common/types' ;
1517
1618export interface ITabEvent {
1719 onDrag ?: (
@@ -49,7 +51,9 @@ export interface ITabProps<T = any, P = any> {
4951 icon ?: string | JSX . Element ;
5052 id : UniqueId ;
5153 name ?: string ;
52- renderPane ?: ( ( item : P ) => React . ReactNode ) | React . ReactNode ;
54+ renderPane ?:
55+ | ( ( item : P , tab ?: ITabProps , group ?: IEditorGroup ) => React . ReactNode )
56+ | React . ReactNode ;
5357 data ?: T ;
5458}
5559
Original file line number Diff line number Diff line change 1+ import 'reflect-metadata' ;
12import React from 'react' ;
23import { render , cleanup , fireEvent , waitFor } from '@testing-library/react' ;
34import { tabItemActiveClassName } from 'mo/components/tabs/tab' ;
45
56import EditorGroup from '../group' ;
7+ import { IEditorTab } from 'mo/model' ;
68
79const TEST_ID = 'test-id' ;
810const TEST_MENU = 'test-menu' ;
@@ -130,4 +132,24 @@ describe('The Editor Component', () => {
130132 expect ( fn ) . toBeCalled ( ) ;
131133 } ) ;
132134 } ) ;
135+
136+ test ( 'use renderPane method' , async ( ) => {
137+ const renderPane = jest . fn ( ( tabData , tab , group ) => {
138+ return < div className = { tab . id } > { tab . id } </ div > ;
139+ } ) ;
140+
141+ const testTab : IEditorTab = {
142+ id : TEST_ID ,
143+ name : TEST_ID ,
144+ data : { } ,
145+ renderPane,
146+ } ;
147+
148+ const { container } = render (
149+ < EditorGroup id = "test" onClickActions = { jest . fn ( ) } tab = { testTab } />
150+ ) ;
151+ const renderDiv = container . querySelector ( `.${ TEST_ID } ` ) ;
152+
153+ expect ( renderDiv ?. innerHTML ) . toEqual ( TEST_ID ) ;
154+ } ) ;
133155} ) ;
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export function Editor(
5252 < EditorGroup
5353 editorOptions = { editorOptions }
5454 currentGroup = { current ! }
55+ group = { groups [ 0 ] }
5556 { ...groups [ 0 ] }
5657 { ...getEvents ( groups [ 0 ] . id ! ) }
5758 />
@@ -74,6 +75,7 @@ export function Editor(
7475 < EditorGroup
7576 editorOptions = { editorOptions }
7677 currentGroup = { current ! }
78+ group = { g }
7779 { ...g }
7880 { ...getEvents ( g . id ! ) }
7981 />
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import { tabItemActiveClassName } from 'mo/components/tabs/tab';
2222export interface IEditorGroupProps extends IEditorGroup {
2323 currentGroup ?: IEditorGroup ;
2424 editorOptions ?: IEditorOptions ;
25+ group ?: IEditorGroup ;
2526}
2627
2728export function EditorGroup ( props : IEditorGroupProps & IEditorController ) {
@@ -30,6 +31,7 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) {
3031 data,
3132 tab,
3233 currentGroup,
34+ group,
3335 actions = [ ] ,
3436 menu = [ ] ,
3537 onMoveTab,
@@ -114,7 +116,13 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) {
114116 // Default we use monaco editor, but also you can customize by renderPanel() function or a react element
115117 tab ?. renderPane ? (
116118 typeof tab . renderPane === 'function' ? (
117- tab . renderPane ( tab . data )
119+ tab . renderPane (
120+ {
121+ ...tab . data ,
122+ } ,
123+ tab ,
124+ group
125+ )
118126 ) : (
119127 tab . renderPane
120128 )
Original file line number Diff line number Diff line change @@ -228,6 +228,31 @@ export type GenericClassDecorator<T> = (target: T) => void;`,
228228 }
229229 } ;
230230
231+ const newPane = function ( ) {
232+ const key = shortRandomId ( ) ;
233+ const name = `pane-${ key } .ts` ;
234+ const tabData : IEditorTab = {
235+ id : `${ key } ` ,
236+ name,
237+ icon : 'selection' ,
238+ data : { } ,
239+ breadcrumb : [ { id : `${ key } ` , name } ] ,
240+ renderPane : ( tabData , tab , group ) => {
241+ console . log ( tabData , tab , group ) ;
242+ const style : React . CSSProperties = {
243+ display : 'flex' ,
244+ width : '100%' ,
245+ height : '100%' ,
246+ fontSize : 48 ,
247+ alignItems : 'center' ,
248+ justifyContent : 'center' ,
249+ } ;
250+ return < div style = { style } > { name } </ div > ;
251+ } ,
252+ } ;
253+ molecule . editor . open ( tabData ) ;
254+ } ;
255+
231256 const updateEntryPage = ( ) => {
232257 const style : React . CSSProperties = {
233258 display : 'flex' ,
@@ -435,6 +460,7 @@ PARTITIONED BY (DE STRING) LIFECYCLE 1000;
435460 < Button onClick = { toggleEditorStatus } >
436461 Toggle Editor status
437462 </ Button >
463+ < Button onClick = { newPane } > New Pane</ Button >
438464 < Button onClick = { updateEntryPage } >
439465 Update Entry Page
440466 </ Button >
You can’t perform that action at this time.
0 commit comments