-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an interactive playground to the documentation site (#216)
Oh boy was this more of a pain than I expected. Creates an interactive playground similar to the typespec or typescript ones, based on https://github.com/microsoft/monaco-editor The actual code generation is off-loaded to a web worker, which actually made the react side of things much simpler and easier to reason about, and reduces blocking on the UI thread/main event loop. Prettier is used instead of Biome due to difficulties getting the WASM to load correctly in the browser / with nextjs. Unfortunately Prettier hits a maximum recursion limit when formatting some of the larger files (in firefox at least), so it would be good to revisit this and try and get Biome working. When loading the larger files, the performance of the editor gets a bit shaky. I'm unsure if there is a way to offload more of the editor to web workers to reduce strain on the UI thread. **Demo Video** https://github.com/user-attachments/assets/5b34f63e-9eaf-4e27-88e9-5a6a0bf5b9fe
- Loading branch information
Showing
43 changed files
with
2,483 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {copyFile} from "node:fs/promises" | ||
import {dirname, resolve} from "node:path" | ||
import {fileURLToPath} from "node:url" | ||
import {sampleFilenames} from "../src/lib/playground/consts" | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = dirname(__filename) | ||
|
||
for (const sample of sampleFilenames) { | ||
const sourcePath = resolve( | ||
__dirname, | ||
`../../../integration-tests-definitions/${sample}`, | ||
) | ||
const destinationPath = resolve(__dirname, `../public/samples/${sample}`) | ||
|
||
try { | ||
await copyFile(sourcePath, destinationPath) | ||
console.log(`Copied ${sample} to ${destinationPath}`) | ||
} catch (err) { | ||
console.error(`Failed to copy ${sample}:`, err) | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.loader { | ||
width: 1rem; | ||
height: 1rem; | ||
border: 5px solid #363636; | ||
border-bottom-color: transparent; | ||
border-radius: 50%; | ||
display: inline-block; | ||
box-sizing: border-box; | ||
animation: rotation 1s linear infinite; | ||
} | ||
|
||
@keyframes rotation { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import styles from "./loading-spinner.module.css" | ||
|
||
export const LoadingSpinner = () => { | ||
return <span className={styles.loader} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.editorContainer { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-template-rows: auto; | ||
|
||
/* | ||
TODO: rendering side-by-side results in weird stuff happening | ||
when breakpoints change, stick with the vertical stack for now. | ||
@media (min-width: 1536px) { | ||
grid-template-columns: 1fr 1fr; | ||
} | ||
*/ | ||
} |
Oops, something went wrong.