{"version":3,"sources":["../../src/components/Include.tsx"],"sourcesContent":["import { Suspense, use } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { ModuleCacheContext } from '../moduleCache';\nimport { EvaluationContext } from '../sandboxTypes';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { IncludeModeContext, RenderExportedComponentContext, type IncludeMode } from './includeContexts';\nimport { SafeInclude } from './SafeInclude';\nimport type { SourceReader } from '../sourceCache';\n\n// The contexts live in `./includeContexts` so `Include` and `SafeInclude` do not import each\n// other (`check:circular`); re-exported here because this is the public entry point and the\n// import path must not change.\nexport { IncludeModeContext, RenderExportedComponentContext } from './includeContexts';\nexport type { IncludeMode, RenderFileContextType } from './includeContexts';\n\n/** Low-level: render one export of an already-resolving module evaluation. Most\n *  code should use {@link Include}, which resolves the module and adds Suspense. */\nexport const RenderExportedComponent = ({\n  evaluationContextPromise,\n  exportedSymbol = 'default',\n}: {\n  evaluationContextPromise: Promise<EvaluationContext>;\n  exportedSymbol: string;\n}) => {\n  const evaluationContext = use(evaluationContextPromise);\n  // TODO: handle case where exported symbol not found.\n  const Component = exportedSymbol === '*' ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];\n  return (\n    <RenderExportedComponentContext value={{ evaluationContext }}>\n      <Component />\n    </RenderExportedComponentContext>\n  );\n};\n\n/** Render another repo file's exported component inline, resolving + evaluating it\n *  through the module cache (with Suspense + an error boundary).\n *\n *  Under `mode=\"interpreted\"` (or inside an {@link IncludeModeContext} set to it) the file is\n *  instead rendered **as data** through the safe renderer — no author JavaScript executes,\n *  and the file need not be an evaluable module at all. */\nexport const Include = ({\n  filename,\n  readSource,\n  exportedSymbol = 'default',\n  LoadingComponent = defaultLoadingComponent,\n  ErrorComponent = defaultErrorComponent,\n  baseModule,\n  mode,\n  components,\n}: {\n  filename: string;\n  exportedSymbol?: string;\n  LoadingComponent?: typeof defaultLoadingComponent;\n  ErrorComponent?: typeof defaultErrorComponent;\n  baseModule?: EvaluationContext;\n  /** Override {@link IncludeModeContext} for this one include. */\n  mode?: IncludeMode;\n  /** Interpreted mode only: components merged OVER the surrounding MDXProvider map.\n   *\n   *  An app's SAFE component set is not always the same as the one it hands\n   *  `boot({ mdxComponents })`. Grove is the worked example: under the safe renderer it also\n   *  needs sanitizing wrappers for structural tags (`main`, `section`, …), and it must NOT\n   *  register those globally, because MDX consults the provider for intrinsics on the\n   *  COMPILED path too — so a global registration would silently strip `style` and other\n   *  non-allow-listed props from compiled authors who legitimately pass them. Ignored in\n   *  compiled mode, where components come from the provider as they always have. */\n  components?: Record<string, unknown>;\n  /** Interpreted mode only: read the raw bytes yourself — e.g. through a mount fs you\n   *  already hold, or a cache you share with the rest of your app. The default reader\n   *  handles both an app-source path and an absolute path in a mount, so this is for\n   *  control, not for reach. Ignored in compiled mode. */\n  readSource?: SourceReader;\n}) => {\n  // Both contexts are read unconditionally, before the branch, so hook order is stable\n  // whichever renderer this include resolves to.\n  const contextMode = use(IncludeModeContext);\n  const moduleCache = use(ModuleCacheContext);\n  // The prop wins over the context so a single file can opt out either way: an interpreter\n  // app including one trusted, executable component of its own, or a compiled app rendering\n  // one file it does not trust (the shape Grove's non-executable proof page needs).\n  if ((mode ?? contextMode) === 'interpreted') {\n    return (\n      <SafeInclude\n        filename={filename}\n        components={components}\n        readSource={readSource}\n        LoadingComponent={LoadingComponent}\n        ErrorComponent={ErrorComponent}\n      />\n    );\n  }\n  // @ts-ignore\n  const evaluationContextPromise = moduleCache!.getEvaluationContext(filename, baseModule ?? module);\n  return (\n    <ErrorBoundary fallbackRender={ErrorComponent}>\n      <Suspense fallback={<LoadingComponent />}>\n        <RenderExportedComponent evaluationContextPromise={evaluationContextPromise} exportedSymbol={exportedSymbol} />\n      </Suspense>\n    </ErrorBoundary>\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BM;AA9BN,mBAA8B;AAC9B,kCAA8B;AAE9B,yBAAmC;AAEnC,sBAA+D;AAC/D,6BAAqF;AACrF,yBAA4B;AAM5B,IAAAA,0BAAmE;AAK5D,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA,iBAAiB;AACnB,MAGM;AACJ,QAAM,wBAAoB,kBAAI,wBAAwB;AAEtD,QAAM,YAAY,mBAAmB,MAAM,kBAAkB,UAAU,kBAAkB,QAAQ,cAAc;AAC/G,SACE,4CAAC,yDAA+B,OAAO,EAAE,kBAAkB,GACzD,sDAAC,aAAU,GACb;AAEJ;AAQO,MAAM,UAAU,CAAC;AAAA,EACtB;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,MAuBM;AAGJ,QAAM,kBAAc,kBAAI,yCAAkB;AAC1C,QAAM,kBAAc,kBAAI,qCAAkB;AAI1C,OAAK,QAAQ,iBAAiB,eAAe;AAC3C,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AAEA,QAAM,2BAA2B,YAAa,qBAAqB,UAAU,cAAc,MAAM;AACjG,SACE,4CAAC,6CAAc,gBAAgB,gBAC7B,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC,sDAAC,2BAAwB,0BAAoD,gBAAgC,GAC/G,GACF;AAEJ;","names":["import_includeContexts"]}