diff --git a/decohub/mod.ts b/decohub/mod.ts index 69863b647..d1c84f38c 100644 --- a/decohub/mod.ts +++ b/decohub/mod.ts @@ -1,4 +1,5 @@ -import type { App, FnContext } from "deco/mod.ts"; +import { buildSourceMap } from "deco/blocks/utils.tsx"; +import { context, type App, type FnContext } from "deco/mod.ts"; import { Markdown } from "./components/Markdown.tsx"; import manifest, { Manifest } from "./manifest.gen.ts"; @@ -8,10 +9,35 @@ export type State = {}; /** * @title Deco Hub */ -export default function App( +const ADMIN_APP = "decohub/apps/admin.ts"; +export default async function App( state: State, -): App { - return { manifest, state }; +): Promise> { + const resolvedImport = import.meta.resolve("../admin/mod.ts"); + return { + manifest: { + ...manifest, + apps: { + ...manifest.apps, + ...context.play // this is an optimization to not include the admin code for everyone in case of play is not being used. + ? { + [ADMIN_APP]: await import( + resolvedImport + ), + } + : {}, + }, + } as Manifest, + state, + ...context.play + ? { + sourceMap: { + ...buildSourceMap(manifest), + [ADMIN_APP]: resolvedImport, + }, + } + : {}, + }; } export type AppContext = FnContext;