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

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2026-06-16 19:47:28 +03:30
import { defineAsyncComponent, type Component } from 'vue'
import { getConfigApp, isBoursecuProject } from '@/utils/config'
import type { HomeLayoutConfig, HomeLayoutId } from './types'
import { defaultHomeLayoutConfig } from './configs/default'
import { boursecuHomeLayoutConfig } from './configs/boursecu'
2026-06-16 19:47:28 +03:30
export const DEFAULT_HOME_LAYOUT_ID: HomeLayoutId = 'default'
const HOME_LAYOUT_CONFIGS: Record<HomeLayoutId, HomeLayoutConfig> = {
default: defaultHomeLayoutConfig,
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 {
const adminLayout = getConfigApp('home_layout')
if (isHomeLayoutId(adminLayout)) {
return adminLayout
}
if (isBoursecuProject()) {
return 'boursecu'
}
return DEFAULT_HOME_LAYOUT_ID
}
export function getHomeLayoutConfig(layoutId = getHomeLayoutId()): HomeLayoutConfig {
return HOME_LAYOUT_CONFIGS[layoutId] ?? HOME_LAYOUT_CONFIGS[DEFAULT_HOME_LAYOUT_ID]
}
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
}