Files
boursecu_user/src/views/base/home/layouts/registry.ts
T

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-06-16 19:47:28 +03:30
import { defineAsyncComponent, type Component } from 'vue'
import type { HomeLayoutConfig, HomeLayoutId } from './types'
import { boursecuHomeLayoutConfig } from './configs/boursecu'
2026-06-16 19:47:28 +03:30
export const DEFAULT_HOME_LAYOUT_ID: HomeLayoutId = 'boursecu'
const HOME_LAYOUT_CONFIGS: Record<HomeLayoutId, HomeLayoutConfig> = {
boursecu: boursecuHomeLayoutConfig,
}
2026-06-16 19:47:28 +03:30
let cachedLayoutRenderer: Component | null = null
2026-06-16 19:47:28 +03:30
function getLayoutRenderer(): Component {
if (!cachedLayoutRenderer) {
cachedLayoutRenderer = defineAsyncComponent(() => import('./HomeLayoutRenderer.vue'))
}
return cachedLayoutRenderer
}
export function isHomeLayoutId(value: unknown): value is HomeLayoutId {
return typeof value === 'string' && value in HOME_LAYOUT_CONFIGS
}
export function getHomeLayoutId(): HomeLayoutId {
return 'boursecu'
}
export function getHomeLayoutConfig(layoutId = getHomeLayoutId()): HomeLayoutConfig {
return HOME_LAYOUT_CONFIGS[layoutId] ?? boursecuHomeLayoutConfig
}
2026-06-16 19:47:28 +03:30
export function resolveHomeLayoutComponent(_layoutId = getHomeLayoutId()): Component {
return getLayoutRenderer()
}
export function registerHomeLayoutConfig(layoutId: HomeLayoutId, config: HomeLayoutConfig) {
HOME_LAYOUT_CONFIGS[layoutId] = config
}