From fcd05937040a3fc042a88cb1b28ac8258e7d8017 Mon Sep 17 00:00:00 2001 From: Brenley Dueck Date: Mon, 26 Oct 2026 16:50:03 -0500 Subject: [PATCH] feat: embed the Solid playground in the reactivity page --- eslint.config.ts | 1 + osmium/package.json | 1 + osmium/src/mdx-components.tsx | 1 + osmium/src/ui/playground.tsx | 52 ++++++++++++++++++++++++ pnpm-lock.yaml | 12 ++++++ src/playgrounds/line-item.tsx | 22 ++++++++++ src/routes/(2)concepts/(0)reactivity.mdx | 4 ++ tsconfig.json | 2 +- 8 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 osmium/src/ui/playground.tsx create mode 100644 src/playgrounds/line-item.tsx diff --git a/eslint.config.ts b/eslint.config.ts index 2a56d00b79..41c0f83543 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -18,6 +18,7 @@ export default tseslint.config( ".netlify/", "public/", "scripts/", + "src/playgrounds/", ], }, { diff --git a/osmium/package.json b/osmium/package.json index d4000e5dbc..e8614da380 100644 --- a/osmium/package.json +++ b/osmium/package.json @@ -28,6 +28,7 @@ }, "license": "MIT", "dependencies": { + "@amoutonbrady/lz-string": "0.2.0", "@fontsource-variable/geist": "^5.3.0", "@fontsource-variable/geist-mono": "^5.3.0", "@kobalte/core": "^0.13.12", diff --git a/osmium/src/mdx-components.tsx b/osmium/src/mdx-components.tsx index 94c03caced..2e374f4603 100644 --- a/osmium/src/mdx-components.tsx +++ b/osmium/src/mdx-components.tsx @@ -26,6 +26,7 @@ export { Callout } from "./ui/callout"; export { DeepDive } from "./ui/deep-dive"; export { QuickLinks } from "./ui/quick-links"; export { ImageLink } from "./ui/image-link"; +export { Playground } from "./ui/playground"; const EraserLinkImpl = clientOnly(() => import("./ui/eraser-link")); diff --git a/osmium/src/ui/playground.tsx b/osmium/src/ui/playground.tsx new file mode 100644 index 0000000000..439d44272d --- /dev/null +++ b/osmium/src/ui/playground.tsx @@ -0,0 +1,52 @@ +import { compressToURL } from "@amoutonbrady/lz-string"; +import { createMemo } from "solid-js"; + +const PLAYGROUND_URL = + import.meta.env.VITE_PLAYGROUND_URL ?? "https://playground.solidjs.com/"; +const DEFAULT_SOLID_VERSION = "2.0.0-rc.18"; + +export type PlaygroundProps = { + code?: string; + files?: Record; + solidVersion?: string; + title?: string; + height?: string; +}; + +export const Playground = (props: PlaygroundProps) => { + const src = createMemo(() => { + const files = props.files ?? { "main.tsx": props.code ?? "" }; + const version = props.solidVersion ?? DEFAULT_SOLID_VERSION; + const tabs = Object.entries(files).map(([name, source]) => ({ + name, + source, + })); + // The playground runs the Solid version that import_map.json pins for solid-js. + tabs.push({ + name: "import_map.json", + source: JSON.stringify( + { imports: { "solid-js": `https://esm.sh/solid-js@${version}` } }, + null, + 2 + ), + }); + return `${PLAYGROUND_URL}#${compressToURL(JSON.stringify(tabs))}`; + }); + + return ( +
+