Skip to content

SplitLayout

Split layout components in the file editor center.

Props

PropertyDescriptionTypeDefault
saveBeforeUnloadShould the canSaveLayout event be triggered when window. beforeuploadbooleantrue
showTabHeaderWhether to display Tab components. When it is true, it supports multiple sub panels in one grid, and the components should be rendered in the tabContentRender slot; When it is false, only grid segmentation is supported and panel and drag functions are not supported. You should render the content yourself in gridRender.booleantrue
rootGridTypeSpecify the type of the root grid, usually used to set different types in multiple components to restrict mutual draggingCodeLayoutGrid'centerArea'

Events

Event nameDescriptionParam
panelCloseThis event is triggered when the panel is closed, and can be asynchronously called to resolve or reject to prevent closurepanel: CodeLayoutSplitNPanelInternal, resolve: () => void, reject: (e?: any) => void)
panelContextMenuTrigger this event when the user clicks on the panelpanel: CodeLayoutSplitNPanelInternal, event: MouseEvent
panelActiveTrigger event when the user clicks to activate the panellastActivePanel: CodeLayoutSplitNPanelInternal, panel: CodeLayoutSplitNPanelInternal
panelDropTrigger event when the user drags and drops the panelpanel: CodeLayoutSplitNPanelInternal, referencePanel: CodeLayoutSplitNPanelInternal, referencePosition: CodeLayoutDragDropReferencePosition
gridActiveTrigger event when the user clicks to activate the gridlastActivePanel: CodeLayoutSplitNGridInternal, panel: CodeLayoutSplitNGridInternal
canLoadLayoutThis event is triggered when a component is loaded, and loading layout operations can be performed in this eventref: CodeLayoutSplitNInstance
canSaveLayoutThis event is triggered when the component is unmount, and loading and saving operations can be performed in this eventref: CodeLayoutSplitNInstance

Slots

Slot nameDescriptionParam
tabContentRenderPanel content rendering slot{ panel: CodeLayoutSplitNPanelInternal }
tabEmptyContentRenderThe rendering slot when there are no sub panels in the non shrinking grid{ grid: CodeLayoutSplitNGridInternal }
tabHeaderExtraRenderAdditional area rendering slot for Tab head{ grid: CodeLayoutSplitNGridInternal }
tabItemRenderCustom rendering of Tab item{ index: number, panel: CodeLayoutSplitNPanelInternal, active: boolean }
tabRenderCustom Tab component rendering, usually you don't need to customize{ grid: CodeLayoutSplitNGridInternal }
gridRenderWhen showTabHeader is false, render the content in this slot yourself{ grid: CodeLayoutSplitNGridInternal }

CodeLayoutSplitNInstance

getRootGrid(): CodeLayoutSplitNGridInternal

Description:

Get root grid instance.

Returns:

TypeDescription
CodeLayoutSplitNGridInternalRoot grid instance.

getPanelByName(name: string): CodeLayoutSplitNPanelInternal | undefined

Description:

Get panel instance by name.

Param:

NameDescription
nameThe panel name.

Returns:

TypeDescription
CodeLayoutSplitNPanelInternal or undefinedPanel instance, if panel is not found in the component, return undefined

getGridByName(name: string): CodeLayoutSplitNGridInternal | undefined

Description:

Get grid instance by name.

Param:

NameDescription
nameThe grid name.

Returns:

TypeDescription
CodeLayoutSplitNGridInternal or undefinedGrid instance, if grid is not found in the component, return undefined

getActiveGird(): CodeLayoutSplitNGridInternal|undefined

Description:

Obtain a grid that is currently actived by user and can be used to add panels.

activePanel(name: string): void

Description:

Activate the specified panel through Name. If the specified Name panel does not exist in the component, it has no effect.

This method will change ActiveGird.

Param:

NameDescription
namePanel name

clearLayout(): void

Description:

Clear all grid.

loadLayout(json: any, instantiatePanelCallback: (data: CodeLayoutSplitNPanel) => CodeLayoutSplitNPanel): void

Description:

Load the previous layout from JSON data, will clear all panels, instantiatePanelCallback will sequentially call all panels, where you can process panel data.

Note that since saving layout data only saves the basic position, size, and other information of each layout, and does not contain information that cannot be serialized (such as callback functions and icons), when loading layout data, it is necessary to fill in this data in instantiatePanelCallback based on the passed in panel name.

ts
const data = localStorage.getItem('LayoutData');
if (data) {
  //If load layout from data, need fill panel data
  splitLayout.value.loadLayout(JSON.parse(data), (panel) => {
    switch (panel.name) {
      case 'file1':
        panel.title = 'File 1';
        panel.tooltip = 'File path c://...';
        panel.badge = '2';
        panel.iconSmall = () => h(IconFile);
        break;
    }
    return panel;
  });
} else {
  //No data, create new layout
  //...
}

Param:

NameDescription
jsonjson data from saveLayout.
instantiatePanelCallbackprocess layout data panel.

saveLayout(): any

Description:

Save the layout dragged by the user to the JSON data, and after the next entry, call loadLayout to reload and restore the original layout from the JSON data.

Note: Some basic layout data (CodeLayoutConfig) needs to be save after called this function.

Returns:

TypeDescription
objectjson

CodeLayoutSplitNPanelInternal

Panel type definition of SplitLayout.

PropertyDescriptionTypeDefault
nameName of this panel.string-
titleTitle of this panel.string-
tooltipTooltip of this panel.string-
badgeBadge of this panel.string-
iconSmallIcon of panel() => VNode-
sizeThe size of the current panel (in pixels), specified as 0 when created, will be automatically allocated by the componentnumber0
parentGroupParent grid instance of this panel.CodeLayoutSplitNPanelInternal-
parentGridParent toplevel grid name of this panel.CodeLayoutGrid-
acceptSet which grids the current panel can be dragged and dropped onto.CodeLayoutGrid[]-
actionsCustom user actions.CodeLayoutActionButton[]false
dataCustom data attached to the current panel.any-

closePanel(): void

Description:

Manually trigger the closing operation of the current panel.

splitCopy(direction: CodeLayoutSplitCopyDirection, instanceCb: (panel: CodeLayoutSplitNPanel) => CodeLayoutSplitNPanel): void

Description:

Clone the current panel and split it in the specified direction. Usually used when a file editor needs to be split into two windows for editing.

Param:

NameDescription
directionSplit direction
instanceCbNew panel instance callback, can modify params

For example, the following reference code is bound to the panelContextMenu event of the panel. Users can right-click on the menu item to clone and split the selected panel in four directions.

ts
function onPanelMenu(panel: CodeLayoutPanelInternal, e: MouseEvent) {
  e.stopPropagation();
  e.preventDefault();
  
  ContextMenuGlobal.showContextMenu({
    x: e.x,
    y: e.y,
    items: [
      {
        label: "Split Up",
        onClick: () => {
          (panel as CodeLayoutSplitNPanelInternal).splitCopy('top', (panel) => {
            panel.name = panel.name + '.copy';
            panel.title = panel.title + ' Clone';
            return panel;
          });
        }
      },
      {
        label: "Split Down",
        onClick: () => {
          (panel as CodeLayoutSplitNPanelInternal).splitCopy('bottom', (panel) => {
            panel.name = panel.name + '.copy';
            panel.title = panel.title + ' Clone';
            return panel;
          });
        }
      },
      {
        label: "Split Left",
        onClick: () => {
          (panel as CodeLayoutSplitNPanelInternal).splitCopy('left', (panel) => {
            panel.name = panel.name + '.copy';
            panel.title = panel.title + ' Clone';
            return panel;
          });
        }
      },
      {
        label: "Split Right",
        onClick: () => {
          (panel as CodeLayoutSplitNPanelInternal).splitCopy('right', (panel) => {
            panel.name = panel.name + '.copy';
            panel.title = panel.title + ' Clone';
            return panel;
          });
        }
      },
    ],
  });
}

CodeLayoutSplitNGridInternal

Grid type definition of SplitLayout.

PropertyDescriptionTypeDefault
canMinCloseSet whether users can close the current panel by continuously shrinking it.booleanfalse
directionLayout direction.'vertical'│'horizontal''vertical'
childGridChild grid of this grid.CodeLayoutSplitNGridInternal[]-

addGrid(grid: CodeLayoutSplitNGrid): CodeLayoutSplitNPanelInternal

Description:

Add a child grid to this grid.

Param:

NameDescription
gridGrid to add

Returns:

Child grid instance.

removePanel(grid: CodeLayoutSplitNGrid)

Description:

Remove a child grid from this grid.

Param:

NameDescription
gridGrid to remove

addPanel(panel: CodeLayoutSplitNPanel): CodeLayoutSplitNPanelInternal

Description:

Add sub panels to the current Grid.

Param:

NameDescription
panelPanel data

Returns:

Child panel instance.

removePanel(panel: CodeLayoutSplitNPanelInternal, shrink = false): CodeLayoutSplitNPanelInternal

Description:

Remove panel from this grid.

Param:

NameDescription
panelPanel instance.
shrinkAutomatically shrink? Default true

setActiveChild(child: CodeLayoutSplitNPanelInternal|null): void

Description:

Set activePanel.

Param:

NameDescription
childThe panel to be activated

reselectActiveChild(): void

Description:

Re select an available panel as the active panel.

Released under the MIT License.