-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
458 additions
and
31 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
<div class="py-1 px-6 pr-10 bg-stone-800 relative mb-4"> | ||
<div><slot /></div> | ||
</div> |
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,50 @@ | ||
export function Icon({ type }) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="h-5 w-5 inline" | ||
view-box="0 0 20 20" | ||
fill="currentColor" | ||
> | ||
{ | ||
{ | ||
refresh: ( | ||
<path | ||
fill-rule="evenodd" | ||
d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z" | ||
clip-rule="evenodd" | ||
/> | ||
), | ||
play: ( | ||
<path | ||
fill-rule="evenodd" | ||
d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" | ||
clip-rule="evenodd" | ||
/> | ||
), | ||
pause: ( | ||
<path | ||
fill-rule="evenodd" | ||
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z" | ||
clip-rule="evenodd" | ||
/> | ||
), | ||
stop: ( | ||
<path | ||
fill-rule="evenodd" | ||
d="M2 10a8 8 0 1116 0 8 8 0 01-16 0zm5-2.25A.75.75 0 017.75 7h4.5a.75.75 0 01.75.75v4.5a.75.75 0 01-.75.75h-4.5a.75.75 0 01-.75-.75v-4.5z" | ||
clip-rule="evenodd" | ||
/> | ||
), | ||
skip: ( | ||
<path | ||
fill-rule="evenodd" | ||
d="M52.5 440.6c-9.5 7.9-22.8 9.7-34.1 4.4S0 428.4 0 416V96C0 83.6 7.2 72.3 18.4 67s24.5-3.6 34.1 4.4l192 160L256 241V96c0-17.7 14.3-32 32-32s32 14.3 32 32V416c0 17.7-14.3 32-32 32s-32-14.3-32-32V271l-11.5 9.6-192 160z" | ||
clip-rule="evenodd" | ||
/> | ||
), | ||
}[type] | ||
} | ||
</svg> | ||
); | ||
} |
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,69 @@ | ||
import { createSignal } from "solid-js"; | ||
import "@kabelsalat/graphviz"; | ||
import { SalatRepl } from "@kabelsalat/core"; | ||
import { Icon } from "./Icon"; | ||
|
||
let vizSettings = { | ||
resolveModules: false, | ||
dagify: false, | ||
rankdir: "LR", | ||
size: 12, | ||
}; | ||
|
||
export function MiniRepl(props) { | ||
const initialCode = props.code; | ||
let [code, setCode] = createSignal(initialCode); | ||
let [started, setStarted] = createSignal(false); | ||
const repl = new SalatRepl({ onToggle: (_started) => setStarted(_started) }); | ||
let container; | ||
async function run() { | ||
const node = repl.evaluate(code()); | ||
node.render(container, vizSettings); // update viz | ||
repl.play(node); | ||
} | ||
let handleKeydown = (e) => { | ||
// console.log("key", e.code); | ||
if (e.key === "Enter" && (e.ctrlKey || e.altKey)) { | ||
run(); | ||
} else if (e.code === "Period" && (e.ctrlKey || e.altKey)) { | ||
repl.stop(); | ||
e.preventDefault(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div class="flex flex-col overflow-hidden rounded-md my-4 border border-teal-500 text-teal-600 font-mono"> | ||
<div class="flex bg-teal-600 text-white"> | ||
<button | ||
class="w-14 hover:bg-teal-700 flex justify-center p-1 border-r border-teal-500 " | ||
onClick={() => (started() ? repl.stop() : run())} | ||
> | ||
{!started() ? <Icon type="play" /> : <Icon type="stop" />} | ||
</button> | ||
<button | ||
class="w-14 hover:bg-teal-700 flex justify-center py-1" | ||
onClick={() => run()} | ||
> | ||
<Icon type="refresh" /> | ||
</button> | ||
</div> | ||
<div class="flex border-b border-teal-500 overflow-hidden"> | ||
<textarea | ||
rows={Math.min(code().split("\n").length, 10)} | ||
class="bg-stone-900 shrink-0 p-4 focus:ring-0 outline-0 grow" | ||
spellcheck="false" | ||
value={code()} | ||
onInput={(e) => setCode(e.target.value)} | ||
onKeyDown={handleKeydown} | ||
></textarea> | ||
</div> | ||
<div | ||
class={`bg-stone-900 overflow-auto text-gray-500 p-4 grow-0 text-center max-h-[400px]`} | ||
ref={(el) => { | ||
container = el; | ||
repl.evaluate(code()).render(container, vizSettings); | ||
}} | ||
></div> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.