Skip to content

CodeLayout

Editor shell layout component.

Props

PropertyDescriptionTypeDefault
layoutConfigBase layout configCodeLayoutConfig
langConfigLanguage configCodeLayoutLangConfig
mainMenuConfigMain menu (in top left) configMenuOptions
emptyTextThe empty text when no panel in the groupstring'Drag a view here to display'
saveBeforeUnloadShould the canSaveLayout event be triggered when window. beforeuploadbooleantrue

Events

Event nameDescriptionParam
canLoadLayoutThis event is triggered when a component is loaded, and loading layout operations can be performed in this eventref: CodeLayoutInstance
canSaveLayoutThis event is triggered when the component is unmount, and loading and saving operations can be performed in this eventref: CodeLayoutInstance

Slots

Slot nameDescriptionParam
panelRenderPanel content rendering solt{ panel: CodeLayoutPanelInternal, open: boolean }
titleBarIconTitle bar rendering icon position-
titleBarMenuTitle bar rendering main menu position-
titleBarCenterTitle bar center position-
titleBarRightRight position of title bar-
activityBarTopBarAt the btopottom of the main activity bar-
activityBarBottomAt the bottom of the main activity bar-
activityBarSecondaryTopBarAt the btopottom of the secondary activity bar-
activityBarSecondarBottomAt the bottom of the secondary activity bar-
emptyGroupEmpty group render slot{ panel: CodeLayoutGridInternal }
centerAreaCentral area, where SliptLayout or other editor components can be placed-
statusBarStatus bar position-
emptyGroupCustomize rendering of empty group content{ grid: CodeLayoutGrid }

CodeLayoutInstance

addGroup: (panel: CodeLayoutPanel, target: CodeLayoutGrid) => CodeLayoutPanelInternal

Description:

Add top level group to layout.

Param:

NameDescription
panelGroup define.
targetTarget grid.

Returns:

TypeDescription
CodeLayoutPanelInternalGroup instance.

removeGroup(panel: CodeLayoutPanelInternal): void

Description:

Remove top level group from layout.

Param:

NameDescription
panelGroup instance.

relayoutAll: () => void

Description:

Force relayout all group.

Generally, adding panels to a group will automatically relayout, but it can also be manually called up.

relayoutGroup(name: string): void

Description:

Force relayout a group.

Generally, adding panels to a group will automatically relayout, but it can also be manually called up.

Param:

NameDescription
nameGroup name.

getRootGrid(target: CodeLayoutGrid): CodeLayoutGridInternal

Description:

Get the internal root grid instance.

Param:

NameDescription
targetGrid name.

Returns:

TypeDescription
CodeLayoutGridInternalTop level grid instance

getPanelByName(name: string): CodeLayoutPanelInternal | undefined

Description:

Get panel instance by name.

Param:

NameDescription
nameThe panel name.

Returns:

TypeDescription
CodeLayoutPanelInternal or undefinedFound panel instance, if this panel is not found in the component, return undefined

clearLayout(): void

Description:

Clear all panels.

loadLayout(json: any, instantiatePanelCallback: (data: CodeLayoutPanel) => CodeLayoutPanel): 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
  codeLayout.value.loadLayout(JSON.parse(data), (panel) => {
    switch (panel.name) {
      case 'explorer':
        panel.title = 'Explorer';
        panel.tooltip = 'Explorer';
        panel.badge = '2';
        panel.iconLarge = () => 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

CodeLayoutConfig

Layout Type Definition

Default data can be copied when creating objects:

ts
import { defaultCodeLayoutConfig } from 'vue-code-layout';

const config = reactive<CodeLayoutConfig>({
  ...defaultCodeLayoutConfig,
  primarySideBarWidth: 40,
});
PropertyDescriptionTypeDefault
primarySideBarSwitchWithActivityBar
Control whether to switch the display of the primarySideBar when clicking on the selected item in the activity bar
booleantrue
primarySideBarPositionThe position of the primarySideBar'left'│'right''left'
primarySideBarWidthThe size of the primarySideBar (0-100, percentage)number20
primarySideBarMinWidthThe minimum size of the primarySideBar in pixelsnumber170
secondarySideBarWidthThe size of the secondarySideBar (0-100, percentage)number20
secondarySideBarMinWidthThe minimum size of the secondarySideBar in pixelsnumber170
secondarySideBarAsActivityBarWhether the secondary sidebar appears as an active bar like the primarySidebarbooleanfalse
bottomPanelHeightThe size of the bottomPanel (0-100, percentage)number30
bottomPanelMinHeightThe minimum size of the bottomPanel in pixelsnumber40
bottomAlignmentThe layout position of the bottomPanel
  • left: At the bottom left
  • center: At the bottom center
  • right: At the bottom right
  • justify: At the bottom center and justify
  • left-side: Center left
  • right-side: Center right
'left'│'center'│'right'│'justify'│'left-side'│'right-side''center'
activityBarPositionThe position of the activityBar
  • side: Main left
  • top: In primarySideBar top
  • hidden: No activityBar
'side'│'top'│'hidden''side'
secondaryActivityBarPositionThe position of the secondary activityBar (when secondarySideBarAsActivityBar is set to true)
  • side: Main left
  • top: In primarySideBar top
  • hidden: No activityBar
'side'│'top'│'hidden''side'
panelHeaderHeightThe height of the panel title in pixelsnumber24
panelMinHeightThe minimum height (in pixels) for all panelsnumber150
titleBarShow title bar?booleantrue
titleBarShowCustomizeLayoutDisplay Customize layout pop-up at the top of the title bar?booleantrue
activityBarShow activity bar?booleantrue
primarySideBarShow primarySideBar?booleantrue
secondarySideBarShow secondarySideBar?booleanfalse
bottomPanelShow bottomPanel?booleantrue
bottomPanelMaximizeCan the bottomPanel be maximized?booleantrue
statusBarShow statusBar?booleantrue
menuBarShow menuBar?booleantrue
onResetDefaultWhen the user clicks the reset button in the custom layout pop-up, this callback is triggered() => void-
onStartDragWhen the user starts dragging the panel, this callback is triggered, which can return false to prevent the user from dragging(panel: CodeLayoutPanelInternal) => boolean-
onEndDragTrigger this callback when the user completes dragging the panel(panel: CodeLayoutPanelInternal) => void-
onDropToGridWhen the user drags a panel to a root group, this callback is triggered, which can return false to prevent the user from dragging(panel: CodeLayoutPanelInternal, grid: CodeLayoutGrid) => boolean-
onDropToPanelWhen the user drags a panel to another panel, this callback is triggered, which can return false to prevent the user from dragging(reference: CodeLayoutPanelInternal, referencePosition: CodeLayoutDragDropReferencePosition, panel: CodeLayoutPanelInternal, dropTo: string) => boolean-
onGridFirstDropWhen the user drags a panel to a group, this callback is triggered to customize and modify the panel data that will eventually be added to the group(grid: CodeLayoutGrid, panel: CodeLayoutPanelInternal) => CodeLayoutPanelInternal-
onNoAutoShinkTabGroupWhen a non shrinking TAB group is set to attempt to shrink, this callback will be triggered(group: CodeLayoutPanelInternal) => void-
onNoAutoShinkNormalGroupThis callback is triggered when a regular group that is set to not shrink attempts to shrink(group: CodeLayoutPanelInternal) => void-

CodeLayoutLangConfig

Basic language defined objects.

PropertyDescriptionTypeDefault
langLanguage of componentstringen
stringsOverrideOverride some strings of current language.Partial<CodeLayoutLangDefine>-

CodeLayoutPanelInternal

Definition of panel/group instance classes.

Due to the use of the same data instance for groups and panels, some properties and methods have different usage scenarios. Annotations (only used within groups) can only be used in instances that serve as groups. Please refer to the documentation for usage.

PropertyDescriptionTypeDefault
nameName of this panel.string-
titleTitle of this panel.string-
tooltipTooltip of this panel.string-
badgeBadge of this panel.string-
openSpecify whether the current panel is openbooleanfalse
startOpenWhen creating, specify whether the current panel is openbooleanfalse
iconSmallSmall icon of panel() => VNode-
iconLargeLarge icon of panel (usually displayed in the activity bar)() => VNode-
resizeableSet user can resize this panel.booleantrue
visibleShow panel?booleantrue
draggableSpecify whether the current panel allows draggingbooleantrue
showBadgeSpecify whether the current panel's badge is displayedbooleantrue
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.CodeLayoutPanelInternal-
parentGridParent toplevel grid name of this panel.CodeLayoutGrid-
acceptSet which grids the current panel can be dragged and dropped onto.CodeLayoutGrid[]-
noHideSet whether users cannot hide this panel.booleanfalse
noAutoShinkSet whether the current grid triggers its own remove/merge operation after all subpanels/grids are removed. Set to true will keep grid display, even if it does not have child panels/grids.(Only valid for group)booleanfalse
actionsCustom user actions.CodeLayoutActionButton[]false
dataCustom data attached to the current panel.any-

addPanel(panel: CodeLayoutPanel, startOpen = false): CodeLayoutPanelInternal

Description:

(only used within groups) Add sub panels to the current group.

Param:

NameDescription
panelPanel data
startOpenIs it open state when adding

Returns:

Subpanel instance.

removePanel(panel: CodeLayoutPanel, shrink = false): CodeLayoutPanelInternal

Description:

(only used within groups) Remove panel from this group.

Param:

NameDescription
panelPanel instance.
shrinkAutomatically shrink? Default true

openPanel(closeOthers = true): void

Description:

Open this panel.

Param:

NameDescription
closeOthersWhen opening oneself, do you also close other panels at the same level, Default: false

closePanel(): void

Description:

Close this panel.

togglePanel(): void

Description:

Toggle open state of this panel.

removeSelfWithShrink(): void

Description:

Remove the current panel/grid from its parent and trigger automatic shrink/merge operations.

removeSelf(): void

Description:

Remove the current panel/grid from its parent.

reselectActiveChild(): void

Description:

(only used within groups) Re select an available panel as the active panel.

activeSelf(): void

Description:

Set parent activePanel to self.

getContainerSize(): number

Description:

Get grid hoster container size (pixel).

notifyRelayout(): void

Description:

(only used within groups) Notify hoster container force relayout.

relayoutAllWithNewPanel(panels: CodeLayoutPanelInternal[], referencePanel?: CodeLayoutPanelInternal): void

Description:

(only used within groups) Notify hoster container there has new grids was added and needs to relayout.

Param:

NameDescription
panelsNewly added panel instances
referencePanelReserve Param, no need to pass it on

relayoutAllWithRemovePanel(panel: CodeLayoutPanelInternal): void

Description:

(only used within groups) Notify hoster container there has grids was removed and needs to relayout.

relayoutAllWithResizedSize(panel: CodeLayoutPanelInternal): void

Description:

(only used within groups) Notify hoster container to relayout when container size changed.

CodeLayoutGridInternal

Definition of top-level grid group instance class.

collapse(open: boolean): void

Description:

Open or collapse the current top-level grid.

Param:

NameDescription
openIs open?

Released under the MIT License.