Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(demo): fix styles #13

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 46 additions & 27 deletions demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,39 @@
let verify = $derived(createVerify(json));
</script>

<div class="grid grid-rows-[auto_1fr] h-full">
<header class="flex justify-between p-4 border-b border-gray-400">
<div class="grid grid-rows-[auto_1fr] h-screen divide-y">
<header class="flex justify-between p-4">
<h1 class="font-bold">apple-app-site-association check</h1>
<button
type="button"
onclick={() => {
const hash = getHash(
json,
paths.map((p) => p.value)
);
const url = new URL(location.href);
url.hash = hash;
window.history.replaceState(null, "", url.href);
navigator.clipboard.writeText(url.href).then(() => {
alert("URL copied to clipboard");
});
}}
>
Share
</button>
<div class="flex gap-2 items-center">
<a
href="http://github.com/st-tech/apple-app-site-association"
target="_blank"
rel="noreferrer"
>
GitHub
</a>
<button
type="button"
onclick={() => {
const hash = getHash(
json,
paths.map((p) => p.value)
);
const url = new URL(location.href);
url.hash = hash;
window.history.replaceState(null, "", url.href);
navigator.clipboard.writeText(url.href).then(() => {
alert("URL copied to clipboard");
});
}}
>
Share
</button>
</div>
</header>
<main class="grid grid-cols-2">
<Editor bind:value={json} />
<div class="p-4">
<h2 class="font-bold">Paths</h2>
<main class="grid md:grid-cols-2">
<div class="p-4 size-full bg-slate-100 md:order-last">
<h2 class="font-bold">Test Paths</h2>
<ul class="grid grid-cols-[auto_1fr_auto] gap-1 font-mono">
{#each paths as path (path.id)}
<li class="contents">
Expand All @@ -74,10 +82,11 @@
-
</button>
<span
class="grow focus-within:outline-2 outline-blue-400/50 rounded-sm"
class="grow bg-white focus-within:outline-2 outline-blue-400/50 rounded-sm"
>
<input
bind:value={path.value}
id={path.id}
class="p-1 border-b border-gray-300 size-full focus:outline-none"
type="text"
autocomplete="off"
Expand All @@ -87,9 +96,18 @@
{#await verify(path.value)}
<span>...</span>
{:then result}
<output>{result}</output>
{:catch error}
<output>{error}</output>
<output
for={path.id}
class={result === "match"
? "text-emerald-700"
: result === "block"
? "text-orange-600"
: "text-gray-500"}
>
{result}
</output>
{:catch}
<output class="text-red-700">error</output>
{/await}
</li>
{/each}
Expand All @@ -104,5 +122,6 @@
</li>
</ul>
</div>
<Editor bind:value={json} />
</main>
</div>
2 changes: 2 additions & 0 deletions demo/src/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as monaco from "monaco-editor";
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
import JsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
import { debounce } from "./debounce";
let ref = $state<HTMLDivElement>();
let { value = $bindable("") } = $props();
let editor = $state<monaco.editor.IStandaloneCodeEditor>();
Expand Down Expand Up @@ -35,4 +36,5 @@
});
</script>

<svelte:window onresize={debounce(() => editor?.layout(), 100)} />
<div bind:this={ref} class="size-full"></div>
16 changes: 16 additions & 0 deletions demo/src/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// biome-ignore lint/suspicious/noExplicitAny:
export function debounce<Args extends any[]>(
fn: (...args: Args) => void,
delay: number,
): (...args: Args) => void {
let timer: number | null = null;
return (...args) => {
if (timer !== null) {
clearTimeout(timer);
}
timer = window.setTimeout(() => {
fn(...args);
timer = null;
}, delay);
};
}
Loading