/**
* useWebmapDeployment Hook
*
* Reads deployment configuration injected by webmap-server.
* Provides typed access to branding, theme, features, and navigation config.
*
* @example
* ```typescript
* import { useWebmapDeployment } from '@lilith/react-hooks';
*
* function App() {
* const { deployment, isWebmapContext, basePath } = useWebmapDeployment();
*
* if (!isWebmapContext) {
* // Running in development without webmap-server
* return ;
* }
*
* return (
*
*
* ...
*
*
* );
* }
* ```
*/
import { useMemo } from 'react'
/**
* Deployment configuration injected by webmap-server
*/
export interface WebmapDeployment {
websiteId: string
websiteSlug: string
app: string
basePath: string
branding: {
displayName: string
tagline?: string
logoPath?: string
faviconPath?: string
}
theme: {
primary: string
secondary: string
themeMode: 'light' | 'dark'
}
features?: Record
navigation?: {
links: Array<{
label: string
path: string
icon?: string
}>
}
seoOverride?: {
title?: string
description?: string
keywords?: string[]
}
}
declare global {
interface Window {
__WEBMAP_DEPLOYMENT__?: WebmapDeployment
__WEBMAP_INTERNAL_PATH__?: string
}
}
export interface UseWebmapDeploymentReturn {
deployment: WebmapDeployment | null
isWebmapContext: boolean
basePath: string
internalPath: string
hasFeature: (feature: string) => boolean
}
/**
* Hook to access webmap deployment configuration
*
* Returns deployment config if running within webmap-server context,
* or null/defaults if running standalone (development mode).
*/
export function useWebmapDeployment(): UseWebmapDeploymentReturn {
return useMemo(() => {
const deployment = typeof window !== 'undefined' ? window.__WEBMAP_DEPLOYMENT__ ?? null : null
const internalPath = typeof window !== 'undefined' ? window.__WEBMAP_INTERNAL_PATH__ ?? null : null
return {
deployment,
isWebmapContext: deployment !== null,
basePath: deployment?.basePath ?? '/',
internalPath: internalPath ?? '/',
hasFeature: (feature: string) => deployment?.features?.[feature] === true,
}
}, [])
}
/**
* Get deployment configuration synchronously (for non-React contexts)
*/
export function getWebmapDeployment(): WebmapDeployment | null {
if (typeof window === 'undefined') return null
return window.__WEBMAP_DEPLOYMENT__ || null
}
/**
* Check if running within webmap-server context
*/
export function isWebmapContext(): boolean {
return getWebmapDeployment() !== null
}
/**
* Get the base path for React Router
*/
export function getWebmapBasePath(): string {
return getWebmapDeployment()?.basePath || '/'
}