# Layout and customization `RLayout` retains the existing Vue 3 + TSX structure, route permissions, menu conversion, and page caching. Preview configuration immediately at `/layout-demo` or the “布局” (Layout) tab in the top settings drawer. ## Navigation and content - `side`: Complete sidebar menu. - `top`: Complete top navigation; Naive UI handles horizontal overflow and submenus. - `mixed`: First-level top navigation with visible children of the active group in the sidebar. Single-page menus do not occupy sidebar space. - `right`: Complete sidebar menu to the right of the content. - `split`: A fixed full-width top bar, with only the active group's children on the left. When the fixed top bar is disabled, top navigation scrolls with content. - At ≤768px, use the complete-menu drawer without overwriting saved desktop mode. Selecting a drawer item closes it automatically. - Sidebar/drawer logos remain fixed above the menu; scrolling begins at the menu region. The native-scrollbar option affects only the menu list. - Content supports fluid fill or centered fixed width, maximum widths of 640–2560px, spacing of 0–48px, and fixed or scrolling headers/footers. Tab and copyright visibility retain existing settings. - Maximized content shares Pinia state with pages and tab menus. The exit button floats at the top right. On narrow screens the shell reserves no space for it. Click it or press Esc to restore the layout. - Content loading uses the visible scrolling viewport. Remounting shows the indicator immediately; brief manual loading waits 120ms. Fixed headers, tabs, and footers are not covered by the overlay. - “外观 → 页面切换动画” (Appearance → Page transition) retains previous options and adds upward fade-in and leftward slide-in. Only content animates; reduced-motion system settings use immediate transitions. Interactions draw on [Vben layout preferences](https://doc.vben.pro/en/guide/essentials/settings.html), reusing existing Naive UI components without a second layout framework. ## Layout definitions and the designer The authenticated workspace loads `useLayout` from `@/layout/api`. Each Pinia instance owns its registry. Put a default-exported `LayoutDefinition` in `apps/admin/src/layout/definitions/.layout.tsx` (JS, JSX and TS entries are also supported). Use a stable lowercase kebab-case ID. Definitions can contain their renderer or import it from a sibling module. The five built-in definitions share navigation and frame components. The `custom-top` example composes tabs and header actions in one row above top navigation. Use `registerLayout(definition)` for an explicitly installed module and `updateLayout(id)` to select a registered layout. Both `autoRegister` and `selectable` default to true. A definition with `autoRegister: false` requires explicit registration. The picker and programmatic selection respect `selectable`. The saved custom ID and the built-in fallback mode serve desktop restoration and v1 preference-file portability respectively. Updating only spacing or width preserves the selected definition. Provide an optional `preview` to describe the settings thumbnail. For example, `{ rows: [['breadcrumb', 'actions']], bottomRows: [['tabs']], sidebar: 'right', footer: true }` places the breadcrumb and actions above the content and tabs below it. Rows also support `navigation`. Use `sidebar` to place navigation on the left or right, or set it to `none`. Set `wideHeaderRows` to the number of leading rows that span both the content and the sidebar. A definition without preview metadata uses its built-in fallback thumbnail. The designer generates this metadata from the same arrangement as its TSX renderer. Compose renderers with `LayoutFrame`, `LayoutRow`, `LayoutTabs`, `LayoutHeaderActions`, `LayoutBreadcrumb`, `LayoutTopNavigation` and `LayoutFooter` from `@/layout/blocks`. A frame provides the page outlet by default. When composing your own content region, render exactly one `LayoutOutlet`. The application host keeps routed pages and their cache mounted as presentation changes. The compact breakpoint uses the full-menu drawer. Built-in and generated layouts declare `sharedFrame: true` because their root is always a direct `LayoutFrame` with its standard page outlet. Omit this flag for layouts with an outer DOM wrapper, local providers or a custom content region. A frame or outlet with a template ref, directive, transition or scoped root style also needs its own DOM node. Browsers with state-preserving DOM moves can transfer an active iframe to a different outlet immediately. On other browsers the host keeps the visible layout and its iframe until the embedded content closes or the page reloads, then applies the most recent selection. An ordinary route change can release the iframe. Layouts sharing the existing frame can switch immediately. An encapsulated web component with a closed shadow root can mark its host with `data-layout-preserve-embed` while its embedded document is active. The lab generates a TSX definition from rows above and below the routed page, sidebar placement and an optional footer. The frame's `bottom` slot hosts rows below the page regardless of copyright visibility. Desktop users can try the draft around the current page and keep editing. Ending the preview or leaving the lab restores the selected layout. Opening the lab as a top-level page on the loopback Vite development server enables create-only writes to the definitions directory. Production, remote and embedded previews download the same source. The writer validates a declarative draft and generates the source on the server. Discovery imports matching modules before applying registration flags, so review external TSX as executable project source before placing it in this directory. Changes to deployed layout definitions take effect in the next build. ## Configuration and extension ```tsx import { useSettingActions } from '@/store' const { updateSettingState } = useSettingActions() updateSettingState('layoutConfig', { mode: 'mixed', contentWidth: 'fixed', contentMaxWidth: 1200, contentPadding: 16, }) ``` Configuration belongs to the `setting` store and retains its persistence key. Historical caches receive defaults and normalized ranges without clearing user preferences. `src/store/modules/setting/constant.ts` owns defaults. Restoring the default layout resets only `layoutConfig`. The settings drawer lists the registered layouts and marks unavailable choices as disabled. Bottom controls export layout, appearance, menu, watermark, and general preferences as `ray-template-preferences.json`, or import the same format. Files must pass version/field validation before applying in the current browser; no reload is required. Login, lock-screen, route configuration, and page-cache data are excluded. Use named slots to replace regions: ```tsx {{ header: () => , sidebar: () => , tabs: () => , footer: () => , default: () => , }} ``` Replaced slots honor the current mode and visibility settings: top-navigation mode has no sidebar; disabled tabs/copyright do not render their regions. Custom content must handle request cancellation and routed content. Without replacement, the default providers and route cache remain active. Layout scroll references remain `LAYOUT_CONTENT_REF` for content and `LAYOUT_SIDER_REF` for the sidebar. `useContentScroll` / `useSiderScroll` read the current reference when invoked, supporting mode changes and remounts. ## Style ownership `index.scss` owns the shell, content scrolling, and maximization. Top navigation, menus, tabs, and loading-state styles stay with their components. The settings drawer and layout lab share `LayoutSettings` and `LayoutSettings.scss`. Responsive option cards show the registered layout structure. Long names wrap and expand the card height. Card groups reserve space for keyboard focus outlines, and `aria-pressed` represents selection.