{"version":3,"file":"chunk-ErrorFallback.mjs","names":["SystemButton.Clipboard"],"sources":["../../src/components/ErrorFallback/parse-stack.ts","../../src/components/ErrorFallback/ErrorFallback.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport ErrorStackParser from 'error-stack-parser';\n\n// Kept out of `ErrorStack.tsx`: react-refresh only fast-refreshes a module whose exports are all\n// components, so a context and its hook exported beside them force a full page reload on every edit.\n\nexport type ParsedStackFrame = ReturnType<typeof ErrorStackParser.parse>[number];\n\n/**\n * Parses `captureOwnerStack()` output (React dev) into frames for {@link ErrorStack}.\n * Prefixes a synthetic Error line when needed so `error-stack-parser` can read V8-style stacks.\n */\nexport const parseCaptureOwnerStack = (stack: string | null): ParsedStackFrame[] | null => {\n  if (stack == null || stack.length === 0) {\n    return null;\n  }\n\n  const err = new Error();\n  err.stack = stack;\n  try {\n    return ErrorStackParser.parse(err);\n  } catch {\n    err.stack = `Error\\n${stack}`;\n    try {\n      return ErrorStackParser.parse(err);\n    } catch {\n      return null;\n    }\n  }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport ErrorStackParser from 'error-stack-parser';\nimport React, { type PropsWithChildren } from 'react';\nimport { type FallbackProps } from 'react-error-boundary';\nimport { useTranslation } from 'react-i18next';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\nimport { safeStringify } from '@dxos/util';\n\nimport { translationKey } from '#translations';\n\nimport { recipes } from '../../recipes.ts';\nimport * as SystemButton from '../SystemButton/SystemButton.tsx';\nimport { type ParsedStackFrame } from './parse-stack.ts';\n\n//\n// ErrorFallback\n//\n\nexport type ErrorFallbackProps = ThemedClassName<\n  PropsWithChildren<\n    Pick<FallbackProps, 'error'> & {\n      /** Heading above the message; the translated \"Runtime Error\" by default. */\n      title?: string;\n      /** Context shown as JSON under a copyable `Data` section. */\n      data?: unknown;\n    }\n  >\n>;\n\n/**\n * Fallback for an `ErrorBoundary`: a heading, the message, then (in development) the parsed stack and any `data`, each\n * under a button that copies it.\n */\nexport const ErrorFallback = ({ classNames, children, error, title, data }: ErrorFallbackProps) => {\n  const { t } = useTranslation(translationKey);\n  const isDev = process.env.NODE_ENV === 'development';\n  const message = error instanceof Error ? error.message : String(error);\n\n  return (\n    <div\n      role='alert'\n      data-testid='error-boundary-fallback'\n      data-scope='error-fallback'\n      data-part='root'\n      className={mx(recipes.errorFallback(), classNames)}\n    >\n      <h1 data-scope='error-fallback' data-part='title' className={recipes.errorFallbackTitle()}>\n        {title ?? t('error-fallback.title.label')}\n      </h1>\n      <p data-scope='error-fallback' data-part='message' className={recipes.errorFallbackMessage()}>\n        {message}\n      </p>\n\n      {isDev && error instanceof Error && (\n        <ErrorFallbackSection title={t('error-fallback.stack.label')} onCopy={() => error.stack ?? error.message}>\n          <ErrorStack error={error} />\n        </ErrorFallbackSection>\n      )}\n\n      {data !== undefined && (\n        <ErrorFallbackSection title={t('error-fallback.data.label')} onCopy={() => JSON.stringify(data, undefined, 2)}>\n          <pre data-scope='error-fallback' data-part='data' className={recipes.errorFallbackData()}>\n            {safeStringify(data, undefined, 2)}\n          </pre>\n        </ErrorFallbackSection>\n      )}\n\n      {children}\n    </div>\n  );\n};\n\nErrorFallback.displayName = 'ErrorFallback';\n\nconst ErrorFallbackSection = ({\n  children,\n  title,\n  onCopy,\n}: PropsWithChildren<{ title: string; onCopy: () => string }>) => (\n  <section data-scope='error-fallback' data-part='section' className={recipes.errorFallbackSection()}>\n    <SystemButton.Clipboard variant='ghost' iconOnly={false} label={title} onCopy={onCopy} />\n    {children}\n  </section>\n);\n\n//\n// ErrorStack\n//\n\n/** The parts of a parsed frame the stack shows; `parseCaptureOwnerStack` and `error-stack-parser` frames qualify. */\nexport type ErrorStackFrame = Pick<ParsedStackFrame, 'functionName' | 'fileName' | 'lineNumber' | 'columnNumber'>;\n\nexport type ErrorStackProps = ThemedClassName<{\n  /** When set, these frames are shown instead of parsing `error`. */\n  frames?: ErrorStackFrame[];\n  /** Used when `frames` is omitted. */\n  error?: Error;\n}>;\n\n/**\n * A parsed stack trace as a tree of frames; frames served from the workspace (Vite `/@fs/` URLs) link to the source\n * line in VS Code.\n */\nexport const ErrorStack = ({ classNames, error, frames: framesProp }: ErrorStackProps) => {\n  const frames: ErrorStackFrame[] = framesProp ?? (error ? ErrorStackParser.parse(error) : []);\n  if (frames.length === 0) {\n    return null;\n  }\n\n  return (\n    <ol data-scope='error-stack' data-part='root' className={mx(recipes.errorStack(), classNames)}>\n      {frames.map((frame, index) => {\n        const local = frame.fileName\n          ? parseLocalFrame(frame.fileName, frame.lineNumber, frame.columnNumber)\n          : undefined;\n        const functionName = frame.functionName ?? '<anonymous>';\n        return (\n          <li\n            key={index}\n            data-scope='error-stack'\n            data-part='frame'\n            data-local={local ? '' : undefined}\n            className={recipes.errorStackFrame()}\n          >\n            {local ? (\n              <a href={local.href} className={recipes.errorStackLink()}>\n                {functionName}\n              </a>\n            ) : (\n              <span className={recipes.errorStackFunction()}>{functionName}</span>\n            )}\n            <span className={recipes.errorStackFile()}>{local?.fileName ?? ''}</span>\n            <span className={recipes.errorStackLine()}>{local ? `${frame.lineNumber}:${frame.columnNumber}` : ''}</span>\n          </li>\n        );\n      })}\n    </ol>\n  );\n};\n\nErrorStack.displayName = 'ErrorStack';\n\n/** A stack frame resolved to a workspace source location. */\ntype LocalFrame = { href: string; fileName: string };\n\n/** Resolves a Vite `/@fs/` URL to a `vscode://` deep link and a path relative to `packages/`. */\nconst parseLocalFrame = (fileUrl: string, line?: number, column?: number): LocalFrame | undefined => {\n  try {\n    const { pathname } = new URL(fileUrl);\n    if (!pathname.startsWith('/@fs/')) {\n      return undefined;\n    }\n\n    const localPath = pathname.slice('/@fs'.length);\n    const packagesIndex = localPath.indexOf('/packages/');\n    return {\n      href: `vscode://file/${localPath}:${line ?? 1}:${column ?? 1}`,\n      fileName: packagesIndex === -1 ? localPath : localPath.substring(packagesIndex + '/packages/'.length),\n    };\n  } catch {\n    return undefined;\n  }\n};\n\nexport { type ParsedStackFrame, parseCaptureOwnerStack } from './parse-stack.ts';\nexport { ErrorBoundary, type ErrorBoundaryProps, type FallbackProps } from '@dxos/react-error-boundary';\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,0BAA0B,UAAoD;CACzF,IAAI,SAAS,QAAQ,MAAM,WAAW,GACpC,OAAO;CAGT,MAAM,sBAAM,IAAI,MAAM;CACtB,IAAI,QAAQ;CACZ,IAAI;EACF,OAAO,iBAAiB,MAAM,GAAG;CACnC,QAAQ;EACN,IAAI,QAAQ,UAAU;EACtB,IAAI;GACF,OAAO,iBAAiB,MAAM,GAAG;EACnC,QAAQ;GACN,OAAO;EACT;CACF;AACF;;;;;;;ACMA,IAAa,iBAAiB,EAAE,YAAY,UAAU,OAAO,OAAO,WAA+B;CACjG,MAAM,EAAE,MAAM,eAAe,cAAc;CAC3C,MAAM,QAAA,QAAA,IAAA,aAAiC;CACvC,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAErE,OACE,qBAAC,OAAD;EACE,MAAK;EACL,eAAY;EACZ,cAAW;EACX,aAAU;EACV,WAAW,GAAG,QAAQ,cAAc,GAAG,UAAU;EALnD,UAAA;GAOE,oBAAC,MAAD;IAAI,cAAW;IAAiB,aAAU;IAAQ,WAAW,QAAQ,mBAAmB;IACrF,UAAA,SAAS,EAAE,4BAA4B;GACtC,CAAA;GACJ,oBAAC,KAAD;IAAG,cAAW;IAAiB,aAAU;IAAU,WAAW,QAAQ,qBAAqB;IACxF,UAAA;GACA,CAAA;GAEF,SAAS,iBAAiB,SACzB,oBAAC,sBAAD;IAAsB,OAAO,EAAE,4BAA4B;IAAG,cAAc,MAAM,SAAS,MAAM;IAC/F,UAAA,oBAAC,YAAD,EAAmB,MAAQ,CAAA;GACP,CAAA;GAGvB,SAAS,KAAA,KACR,oBAAC,sBAAD;IAAsB,OAAO,EAAE,2BAA2B;IAAG,cAAc,KAAK,UAAU,MAAM,KAAA,GAAW,CAAC;IAC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