{"version":3,"file":"SuspendedChart.mjs","names":[],"sources":["../../../../../../../src/plugins/AIComponents/AIMarkdown/tools/charts/SuspendedChart.tsx"],"sourcesContent":["import { Component, lazy, type ReactNode, Suspense } from 'react';\nimport { useTranslationContext } from '../../../../../context/TranslationContext';\nimport type { ToolComponentProps } from '../../AIMarkdown';\n\nconst Chart = lazy(() => import('./Chart'));\n\ntype ChartErrorBoundaryProps = {\n  children: ReactNode;\n  fallback: ReactNode;\n  resetKey: string;\n};\n\n/**\n * Isolates chart failures (chunk load errors, chart.js throwing on render) so\n * they render the raw-code fallback instead of unmounting the message.\n * Resets when the chart data changes (e.g. while a message is streaming).\n */\nclass ChartErrorBoundary extends Component<\n  ChartErrorBoundaryProps,\n  { hasError: boolean }\n> {\n  state = { hasError: false };\n\n  static getDerivedStateFromError() {\n    return { hasError: true };\n  }\n\n  componentDidUpdate(prevProps: ChartErrorBoundaryProps) {\n    if (this.state.hasError && prevProps.resetKey !== this.props.resetKey) {\n      this.setState({ hasError: false });\n    }\n  }\n\n  render() {\n    return this.state.hasError ? this.props.fallback : this.props.children;\n  }\n}\n\nexport const SuspendedChart = (props: ToolComponentProps) => {\n  const { t } = useTranslationContext();\n\n  return (\n    <ChartErrorBoundary fallback={props.fallback} resetKey={props.data}>\n      <Suspense\n        fallback={\n          <div className='str-chat__ai-chart--loading'>\n            {t('aiComponents.chart.loading.text', 'Loading chart...')}\n          </div>\n        }\n      >\n        <Chart {...props} />\n      </Suspense>\n    </ChartErrorBoundary>\n  );\n};\n"],"mappings":";;;;AAIA,IAAM,QAAQ,WAAW,OAAO,cAAU;;;;;;AAa1C,IAAM,qBAAN,cAAiC,UAG/B;CACA,QAAQ,EAAE,UAAU,MAAM;CAE1B,OAAO,2BAA2B;EAChC,OAAO,EAAE,UAAU,KAAK;CAC1B;CAEA,mBAAmB,WAAoC;EACrD,IAAI,KAAK,MAAM,YAAY,UAAU,aAAa,KAAK,MAAM,UAC3D,KAAK,SAAS,EAAE,UAAU,MAAM,CAAC;CAErC;CAEA,SAAS;EACP,OAAO,KAAK,MAAM,WAAW,KAAK,MAAM,WAAW,KAAK,MAAM;CAChE;AACF;AAEA,IAAa,kBAAkB,UAA8B;CAC3D,MAAM,EAAE,MAAM,sBAAsB;CAEpC,OACE,oBAAC,oBAAD;EAAoB,UAAU,MAAM;EAAU,UAAU,MAAM;YAC5D,oBAAC,UAAD;GACE,UACE,oBAAC,OAAD;IAAK,WAAU;cACZ,EAAE,mCAAmC,kBAAkB;GACrD,CAAA;aAGP,oBAAC,OAAD,EAAO,GAAI,MAAQ,CAAA;EACX,CAAA;CACQ,CAAA;AAExB"}