From 165c8641d4cec20909084bc298f2c810c50c471b Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Tue, 2 Sep 2025 10:18:48 +0200 Subject: [PATCH] fix: make URL preset work and apply fallback --- src/main.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index f8141fb..690bc69 100644 --- a/src/main.ts +++ b/src/main.ts @@ -639,19 +639,21 @@ interface ProjectWallaceJSON { const domainInput = document.getElementById('url-input'); if (domainInput) { - domainInput.addEventListener('input', (evt) => { - if (evt.currentTarget instanceof HTMLSelectElement) { - const url = evt.currentTarget.value.replace(/[./]+/g, '.'); - fetch(`/design-tokens/${url}.json`) - .then((response) => response.json()) - .then((json: ProjectWallaceJSON) => { - const colors = Object.entries(json.Color).map(([name, { $value }]) => ({ - name, - color: $value, - })); - - setPresetColors(colors); - }); + domainInput.addEventListener('input', async (event) => { + if (event.currentTarget instanceof HTMLSelectElement) { + const url = event.currentTarget.value.replace(/[./]+/g, '.'); + if (url) { + const response = await fetch(`/design-tokens/${url}.json`) + const json = await response.json() as ProjectWallaceJSON + const colors = Object.entries(json.Color).map(([name, { $value }]) => ({ + name, + color: $value, + })); + + setPresetColors(colors); + } else { + setPresetColors(radixColors) + } } }); }