{"version":3,"file":"ModuleSlot.mjs","sources":["../../../src/lib/vdom/ModuleSlot.tsx"],"sourcesContent":["/**\n * @file Module Slot Component\n * @module vdom/ModuleSlot\n * @description Dynamic module insertion points with fallback rendering,\n * lazy loading integration, and content projection capabilities.\n * Enables flexible module composition patterns.\n *\n * @author Agent 5 - PhD Virtual DOM Expert\n * @version 1.0.0\n */\n\nimport {\n  Suspense,\n  lazy,\n  useMemo,\n  useEffect,\n  useState,\n  useLayoutEffect,\n  type ReactNode,\n  type FC,\n  type ComponentType,\n  type ElementType,\n} from 'react';\nimport React from 'react';\nimport { createPortal } from 'react-dom';\nimport { isReactEnvironmentHealthy } from '@/lib/core/react-env';\nimport { createModuleId } from './types';\nimport { useOptionalModuleContext } from './ModuleBoundary';\nimport { useModuleSystem } from './ModuleProviderExports';\nimport { devWarn } from '@/lib/core/config/env-helper';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Module slot props.\n */\nexport interface ModuleSlotProps {\n  /** Slot name */\n  name: string;\n  /** Default content if slot is empty */\n  children?: ReactNode;\n  /** Fallback during lazy loading */\n  fallback?: ReactNode;\n  /** Whether slot is required */\n  required?: boolean;\n  /** Placeholder when slot is empty and not required */\n  placeholder?: ReactNode;\n  /** Wrapper element */\n  as?: ElementType;\n  /** Additional class name */\n  className?: string;\n  /** Additional styles */\n  style?: React.CSSProperties;\n  /** Data attributes */\n  data?: Record<string, string>;\n}\n\n/**\n * Dynamic module slot props for loading external modules.\n */\nexport interface DynamicModuleSlotProps {\n  /** Module ID to load */\n  moduleId: string;\n  /** Props to pass to loaded module */\n  moduleProps?: Record<string, unknown>;\n  /** Fallback during loading */\n  fallback?: ReactNode;\n  /** Error fallback */\n  errorFallback?: ReactNode | ((error: Error) => ReactNode);\n  /** Callback when module loads */\n  onLoad?: () => void;\n  /** Callback on load error */\n  onError?: (error: Error) => void;\n  /** Wrapper element */\n  as?: ElementType;\n  /** Additional class name */\n  className?: string;\n  /** Additional styles */\n  style?: React.CSSProperties;\n}\n\n/**\n * Module outlet props for named outlets.\n */\nexport interface ModuleOutletProps {\n  /** Outlet name */\n  name: string;\n  /** Default content */\n  children?: ReactNode;\n  /** Wrapper element */\n  as?: ElementType;\n  /** Additional class name */\n  className?: string;\n  /** Additional styles */\n  style?: React.CSSProperties;\n}\n\n// ============================================================================\n// ModuleSlot Component\n// ============================================================================\n\n/**\n * Named slot within a module boundary for content projection.\n * Allows parent modules to inject content into child modules.\n *\n * @example\n * ```tsx\n * // In child module\n * <ModuleBoundary id=\"card\" name=\"Card Module\">\n *   <div className=\"card\">\n *     <ModuleSlot name=\"header\" as=\"header\">\n *       Default Header\n *     </ModuleSlot>\n *     <ModuleSlot name=\"content\" required>\n *       {children}\n *     </ModuleSlot>\n *     <ModuleSlot name=\"footer\" as=\"footer\" placeholder={<EmptyFooter />} />\n *   </div>\n * </ModuleBoundary>\n *\n * // In parent module\n * const context = useModuleContext();\n * context.setSlot('header', <CustomHeader />);\n * ```\n */\nexport const ModuleSlot: FC<ModuleSlotProps> = ({\n  name,\n  children,\n  fallback,\n  required = false,\n  placeholder,\n  as: Wrapper = 'div',\n  className,\n  style,\n  data,\n}) => {\n  const context = useOptionalModuleContext();\n  const slotContent = context?.getSlot(name);\n\n  // Determine what to render\n  let content: ReactNode;\n\n  if (slotContent != null) {\n    // Slot has been filled\n    content = slotContent;\n  } else if (children != null) {\n    // Use default children\n    content = children;\n  } else if (required) {\n    // Required slot without content\n    devWarn(`Required slot \"${name}\" is empty`);\n    content = null;\n  } else if (placeholder != null) {\n    // Show placeholder\n    content = placeholder;\n  } else {\n    // Empty slot\n    content = null;\n  }\n\n  // Build data attributes\n  const dataAttributes: Record<string, string> = {\n    'data-module-slot': name,\n    ...(data\n      ? Object.fromEntries(Object.entries(data).map(([key, value]) => [`data-${key}`, value]))\n      : {}),\n  };\n\n  // Don't render wrapper if no content\n  if (\n    content == null &&\n    (className === undefined || className === null) &&\n    (style === undefined || style === null)\n  ) {\n    return null;\n  }\n\n  return (\n    <Wrapper className={className} style={style} {...dataAttributes}>\n      {fallback !== null && fallback !== undefined ? (\n        <Suspense fallback={fallback}>{content}</Suspense>\n      ) : (\n        content\n      )}\n    </Wrapper>\n  );\n};\n\nModuleSlot.displayName = 'ModuleSlot';\n\n// ============================================================================\n// DynamicModuleSlot Component\n// ============================================================================\n\n/**\n * Dynamically loads and renders a module by ID.\n * Integrates with the module loader for code splitting.\n *\n * @example\n * ```tsx\n * <DynamicModuleSlot\n *   moduleId=\"dashboard-widget\"\n *   moduleProps={{ userId: currentUser.id }}\n *   fallback={<WidgetSkeleton />}\n *   errorFallback={(error) => <WidgetError error={error} />}\n *   onLoad={() => analytics.track('widget_loaded')}\n * />\n * ```\n */\nexport const DynamicModuleSlot: FC<DynamicModuleSlotProps> = ({\n  moduleId: rawModuleId,\n  moduleProps = {},\n  fallback = null,\n  errorFallback,\n  onLoad,\n  onError,\n  as: Wrapper = 'div',\n  className,\n  style,\n}) => {\n  const system = useModuleSystem();\n  const moduleId = useMemo(() => createModuleId(rawModuleId), [rawModuleId]);\n\n  const [state, setState] = useState<{\n    status: 'loading' | 'loaded' | 'error';\n    Component: ComponentType<Record<string, unknown>> | null;\n    error: Error | null;\n  }>({\n    status: 'loading',\n    Component: null,\n    error: null,\n  });\n\n  // Load module\n  useEffect(() => {\n    let isMounted = true;\n\n    const loadModule = async (): Promise<void> => {\n      try {\n        const component = await system.loader.load(moduleId);\n\n        if (isMounted) {\n          setState({\n            status: 'loaded',\n            Component: component as ComponentType<Record<string, unknown>>,\n            error: null,\n          });\n          onLoad?.();\n        }\n      } catch (error) {\n        const err = error instanceof Error ? error : new Error(String(error));\n        if (isMounted) {\n          setState({\n            status: 'error',\n            Component: null,\n            error: err,\n          });\n          onError?.(err);\n        }\n      }\n    };\n\n    void loadModule();\n\n    return () => {\n      isMounted = false;\n    };\n  }, [moduleId, system.loader, onLoad, onError]);\n\n  // Render based on state\n  if (state.status === 'loading') {\n    return (\n      <Wrapper className={className} style={style}>\n        {fallback}\n      </Wrapper>\n    );\n  }\n\n  if (state.status === 'error' && state.error) {\n    const errorContent =\n      typeof errorFallback === 'function'\n        ? errorFallback(state.error)\n        : (errorFallback ?? <div role=\"alert\">Failed to load module: {state.error.message}</div>);\n\n    return (\n      <Wrapper className={className} style={style}>\n        {errorContent}\n      </Wrapper>\n    );\n  }\n\n  if (state.Component) {\n    const { Component } = state;\n    return (\n      <Wrapper className={className} style={style} data-module-id={moduleId}>\n        <Component {...moduleProps} />\n      </Wrapper>\n    );\n  }\n\n  return null;\n};\n\nDynamicModuleSlot.displayName = 'DynamicModuleSlot';\n\n// ============================================================================\n// LazyModuleSlot Component\n// ============================================================================\n\n/**\n * Props for LazyModuleSlot.\n */\nexport interface LazyModuleSlotProps {\n  /** Lazy import function */\n  loader: () => Promise<{ default: ComponentType<unknown> }>;\n  /** Props to pass to loaded component */\n  componentProps?: Record<string, unknown>;\n  /** Fallback during loading */\n  fallback?: ReactNode;\n  /** Wrapper element */\n  as?: ElementType;\n  /** Additional class name */\n  className?: string;\n  /** Additional styles */\n  style?: React.CSSProperties;\n}\n\n// Create a cache for lazy components to avoid recreating them\nconst lazyComponentCache = new Map<\n  () => Promise<{ default: ComponentType<unknown> }>,\n  ReturnType<typeof lazy>\n>();\n\n/**\n * Slot that lazily loads a component using React.lazy().\n *\n * @example\n * ```tsx\n * <LazyModuleSlot\n *   loader={() => import('./HeavyComponent')}\n *   fallback={<ComponentSkeleton />}\n *   componentProps={{ theme: 'dark' }}\n * />\n * ```\n */\nexport const LazyModuleSlot: FC<LazyModuleSlotProps> = ({\n  loader,\n  componentProps = {},\n  fallback = null,\n  as: Wrapper = 'div',\n  className,\n  style,\n}) => {\n  // Get or create lazy component from cache using useMemo\n  const LazyComponent = useMemo(() => {\n    if (!lazyComponentCache.has(loader)) {\n      lazyComponentCache.set(loader, lazy(loader));\n    }\n    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n    return lazyComponentCache.get(loader)!;\n  }, [loader]);\n\n  return (\n    <Wrapper className={className} style={style}>\n      <Suspense fallback={fallback}>\n        {/* eslint-disable-next-line react-hooks/static-components */}\n        <LazyComponent {...componentProps} />\n      </Suspense>\n    </Wrapper>\n  );\n};\n\nLazyModuleSlot.displayName = 'LazyModuleSlot';\n\n// ============================================================================\n// ModuleOutlet Component\n// ============================================================================\n\n/**\n * Named outlet for rendering module content.\n * Similar to router outlets but for module composition.\n *\n * @example\n * ```tsx\n * // In layout\n * <div className=\"layout\">\n *   <ModuleOutlet name=\"sidebar\" />\n *   <main>\n *     <ModuleOutlet name=\"content\">\n *       <DefaultContent />\n *     </ModuleOutlet>\n *   </main>\n * </div>\n * ```\n */\nexport const ModuleOutlet: FC<ModuleOutletProps> = ({\n  name,\n  children,\n  as: Wrapper = 'div',\n  className,\n  style,\n}) => {\n  const context = useOptionalModuleContext();\n  const outletContent = context?.getSlot(`outlet:${name}`);\n\n  return (\n    <Wrapper className={className} style={style} data-module-outlet={name}>\n      {outletContent ?? children}\n    </Wrapper>\n  );\n};\n\nModuleOutlet.displayName = 'ModuleOutlet';\n\n// ============================================================================\n// ConditionalModuleSlot Component\n// ============================================================================\n\n/**\n * Props for ConditionalModuleSlot.\n */\nexport interface ConditionalModuleSlotProps {\n  /** Condition to check */\n  when: boolean;\n  /** Module ID to load when condition is true */\n  moduleId: string;\n  /** Props to pass to module */\n  moduleProps?: Record<string, unknown>;\n  /** Content to show when condition is false */\n  otherwise?: ReactNode;\n  /** Fallback during loading */\n  fallback?: ReactNode;\n}\n\n/**\n * Conditionally loads and renders a module.\n *\n * @example\n * ```tsx\n * <ConditionalModuleSlot\n *   when={user.isPremium}\n *   moduleId=\"premium-features\"\n *   moduleProps={{ user }}\n *   otherwise={<UpgradePrompt />}\n * />\n * ```\n */\nexport const ConditionalModuleSlot: FC<ConditionalModuleSlotProps> = ({\n  when,\n  moduleId,\n  moduleProps,\n  otherwise,\n  fallback,\n}) => {\n  if (!when) {\n    return <>{otherwise}</>;\n  }\n\n  return <DynamicModuleSlot moduleId={moduleId} moduleProps={moduleProps} fallback={fallback} />;\n};\n\nConditionalModuleSlot.displayName = 'ConditionalModuleSlot';\n\n// ============================================================================\n// ModulePortalSlot Component\n// ============================================================================\n\n/**\n * Props for ModulePortalSlot.\n */\nexport interface ModulePortalSlotProps {\n  /** Portal target element ID */\n  target: string;\n  /** Content to render in portal */\n  children: ReactNode;\n  /**\n   * Whether to render children inline as fallback when portal cannot be created.\n   * This prevents blank pages when React environment issues occur.\n   * @default true\n   */\n  fallbackToInline?: boolean;\n  /**\n   * Custom fallback content to render when portal fails.\n   */\n  fallback?: ReactNode;\n}\n\n/**\n * Renders content into a portal target outside the module boundary.\n * Includes fallback rendering to prevent blank pages when React\n * environment issues occur (e.g., multiple React instances).\n *\n * @example\n * ```tsx\n * // In module\n * <ModulePortalSlot target=\"modal-root\">\n *   <Modal>\n *     <ModalContent />\n *   </Modal>\n * </ModulePortalSlot>\n *\n * // In document\n * <div id=\"modal-root\"></div>\n * ```\n */\nexport const ModulePortalSlot: FC<ModulePortalSlotProps> = ({\n  target,\n  children,\n  fallbackToInline = true,\n  fallback,\n}) => {\n  const [targetElement, setTargetElement] = useState<Element | null>(null);\n  const [portalError, setPortalError] = useState<boolean>(false);\n  const [isEnvHealthy, setIsEnvHealthy] = useState<boolean | null>(null);\n\n  // Check React environment health\n  useEffect(() => {\n    try {\n      // Only check on client-side\n      if (typeof window === 'undefined') {\n        queueMicrotask(() => setIsEnvHealthy(true));\n        return;\n      }\n      const healthy = isReactEnvironmentHealthy();\n      queueMicrotask(() => setIsEnvHealthy(healthy));\n    } catch {\n      queueMicrotask(() => {\n        setIsEnvHealthy(false);\n        setPortalError(true);\n      });\n    }\n  }, []);\n\n  useLayoutEffect(() => {\n    // Skip if environment is unhealthy\n    if (isEnvHealthy === false) {\n      queueMicrotask(() => setPortalError(true));\n      return;\n    }\n\n    try {\n      const element = document.getElementById(target);\n      if (element !== null) {\n        // Use microtask to avoid synchronous setState in effect\n        queueMicrotask(() => {\n          setTargetElement(element);\n        });\n      } else {\n        devWarn(`Portal target \"${target}\" not found`);\n        // Set error flag if target not found and fallback is enabled\n        if (fallbackToInline) {\n          queueMicrotask(() => setPortalError(true));\n        }\n      }\n    } catch (err) {\n      devWarn(`Portal creation failed: ${err instanceof Error ? err.message : 'Unknown error'}`);\n      queueMicrotask(() => setPortalError(true));\n    }\n  }, [target, isEnvHealthy, fallbackToInline]);\n\n  // Render fallback if portal fails or environment is unhealthy\n  if (portalError || isEnvHealthy === false) {\n    if (fallback !== undefined) {\n      return <>{fallback}</>;\n    }\n    if (fallbackToInline) {\n      return (\n        <div data-portal-fallback=\"true\" data-portal-target={target}>\n          {children}\n        </div>\n      );\n    }\n    return null;\n  }\n\n  // Render children inline while waiting for portal target\n  if (!targetElement) {\n    if (fallbackToInline) {\n      return (\n        <div data-portal-pending=\"true\" data-portal-target={target} style={{ display: 'contents' }}>\n          {children}\n        </div>\n      );\n    }\n    return null;\n  }\n\n  // Use React.createPortal\n  try {\n    return createPortal(children, targetElement);\n  } catch (err) {\n    devWarn(`Portal rendering failed: ${err instanceof Error ? err.message : 'Unknown error'}`);\n    // Fallback to inline rendering on portal error\n    if (fallbackToInline) {\n      return (\n        <div data-portal-error=\"true\" data-portal-target={target}>\n          {children}\n        </div>\n      );\n    }\n    return null;\n  }\n};\n\nModulePortalSlot.displayName = 'ModulePortalSlot';\n"],"names":["ModuleSlot","name","children","fallback","required","placeholder","Wrapper","className","style","data","slotContent","useOptionalModuleContext","content","devWarn","dataAttributes","key","value","jsx","Suspense","DynamicModuleSlot","rawModuleId","moduleProps","errorFallback","onLoad","onError","system","useModuleSystem","moduleId","useMemo","createModuleId","state","setState","useState","useEffect","isMounted","component","error","err","errorContent","jsxs","Component","lazyComponentCache","LazyModuleSlot","loader","componentProps","LazyComponent","lazy","ModuleOutlet","outletContent","ConditionalModuleSlot","when","otherwise","ModulePortalSlot","target","fallbackToInline","targetElement","setTargetElement","portalError","setPortalError","isEnvHealthy","setIsEnvHealthy","healthy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