{"version":3,"file":"error-boundary.cjs","sources":["../src/error-boundary.ts"],"sourcesContent":["// @ts-nocheck\nimport { Component, ReactNode } from \"react\";\nimport { Callout } from \"@blueprintjs/core\";\nimport h from \"@macrostrat/hyper\";\n\nfunction ErrorCallout(props) {\n  const { error, title = \"Unknown error\" } = props;\n\n  return h(\n    Callout,\n    {\n      title,\n      icon: \"error\",\n      intent: \"danger\",\n    },\n    h(\n      \"p\",\n      null,\n      props.description ?? error?.toString() ?? \"No description available\",\n    ),\n  );\n}\n\ntype ErrorBoundaryProps = {\n  description?: string;\n  title?: string;\n  fallback?: ReactNode;\n  override?: boolean;\n  onCatch?(error: Error, info: any): void;\n};\ntype ErrorBoundaryState = {\n  error: Error | null;\n};\n\nclass ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n  constructor(props) {\n    super(props);\n    this.state = { error: null };\n  }\n\n  static getDerivedStateFromError(error) {\n    // Update state so the next render will show the fallback UI.\n    return { error };\n  }\n\n  componentDidCatch(error, info) {\n    // You can also log the error to an error reporting service\n    console.log(error);\n    this.props.onCatch?.(error, info);\n  }\n\n  render() {\n    const { error } = this.state;\n    const { override = false } = this.props;\n    if (error != null || override) {\n      if (this.props.fallback != null) return this.props.fallback;\n\n      // You can render any custom fallback UI\n      return h(ErrorCallout, {\n        error,\n        description:\n          this.props.description ??\n          error?.toString() ??\n          \"No description available\",\n        title: this.props.title ?? \"A rendering error has occured\",\n      });\n    }\n\n    return this.props.children;\n  }\n}\n\nexport { ErrorBoundary, ErrorCallout };\n"],"names":["h","Callout","Component"],"mappings":";;;;;;;AAKA,SAAS,aAAa,OAAO;AAC3B,QAAM,EAAE,OAAO,QAAQ,gBAAA,IAAoB;AAE3C,SAAOA,WAAAA;AAAAA,IACLC,KAAAA;AAAAA,IACA;AAAA,MACE;AAAA,MACA,MAAM;AAAA,MACN,QAAQ;AAAA,IAAA;AAAA,IAEVD,WAAAA;AAAAA,MACE;AAAA,MACA;AAAA,MACA,MAAM,eAAe,OAAO,cAAc;AAAA,IAAA;AAAA,EAC5C;AAEJ;AAaA,MAAM,sBAAsBE,MAAAA,UAAkD;AAAA,EAC5E,YAAY,OAAO;AACjB,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,OAAO,KAAA;AAAA,EACxB;AAAA,EAEA,OAAO,yBAAyB,OAAO;AAErC,WAAO,EAAE,MAAA;AAAA,EACX;AAAA,EAEA,kBAAkB,OAAO,MAAM;AAE7B,YAAQ,IAAI,KAAK;AACjB,SAAK,MAAM,UAAU,OAAO,IAAI;AAAA,EAClC;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,KAAK;AACvB,UAAM,EAAE,WAAW,MAAA,IAAU,KAAK;AAClC,QAAI,SAAS,QAAQ,UAAU;AAC7B,UAAI,KAAK,MAAM,YAAY,KAAM,QAAO,KAAK,MAAM;AAGnD,aAAOF,WAAAA,QAAE,cAAc;AAAA,QACrB;AAAA,QACA,aACE,KAAK,MAAM,eACX,OAAO,cACP;AAAA,QACF,OAAO,KAAK,MAAM,SAAS;AAAA,MAAA,CAC5B;AAAA,IACH;AAEA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;;;"}