Svelte bug fixes and code cleanup (#1074)

* Fix middle click tab close

* Fix swapping colors in the ColorPicker

* Cleanup

* Fix field inputs

* Fix tab key-based navigation

* Fix ColorPicker reseting Initial color when opened

* Prevent backend fighting with user dragging NumberInput

* Remaining fixes and comment cleanup
This commit is contained in:
Keavon Chambers
2023-03-10 03:47:06 -08:00
parent 2327524690
commit 9bd319fba4
26 changed files with 220 additions and 179 deletions
@@ -52,3 +52,19 @@ export function operatingSystem(detailed = false): string {
export function platformIsMac(): boolean {
return operatingSystem() === "Mac";
}
export function isEventSupported(eventName: string) {
const onEventName = `on${eventName}`;
let tag = "div";
if (["select", "change"].includes(eventName)) tag = "select";
if (["submit", "reset"].includes(eventName)) tag = "form";
if (["error", "load", "abort"].includes(eventName)) tag = "img";
const element = document.createElement(tag);
if (onEventName in element) return true;
// Check if "return;" gets converted into a function, meaning the event is supported
element.setAttribute(eventName, "return;");
return typeof (element as Record<string, any>)[onEventName] === "function";
}