Run prettier over everything and fix some imports

This commit is contained in:
Ryan Gossiaux
2021-12-13 18:22:16 -08:00
parent 3bf974a654
commit 82b138f0ae
63 changed files with 3317 additions and 3319 deletions

View File

@@ -1,79 +1,79 @@
<script lang="ts">
import { useMenuContext, MenuStates, MenuItemData } from "./Menu.svelte";
import { useId } from "./use-id";
import { Focus } from "./calculate-active-index";
import { afterUpdate, onDestroy, onMount, tick } from "svelte";
export let disabled = false;
const api = useMenuContext("MenuItem");
const id = `headlessui-menu-item-${useId()}`;
import { useMenuContext, MenuStates, MenuItemData } from "./Menu.svelte";
import { useId } from "$lib/hooks/use-id";
import { Focus } from "$lib/utils/calculate-active-index";
import { afterUpdate, onDestroy, onMount, tick } from "svelte";
export let disabled = false;
const api = useMenuContext("MenuItem");
const id = `headlessui-menu-item-${useId()}`;
$: active =
$api?.activeItemIndex !== null
? $api?.items[$api?.activeItemIndex].id === id
: false;
$: active =
$api?.activeItemIndex !== null
? $api?.items[$api?.activeItemIndex].id === id
: false;
$: buttonStore = $api?.buttonStore;
$: buttonStore = $api?.buttonStore;
let elementRef: HTMLDivElement | undefined;
$: textValue = elementRef?.textContent?.toLowerCase().trim();
$: data = { disabled, textValue } as MenuItemData;
let elementRef: HTMLDivElement | undefined;
$: textValue = elementRef?.textContent?.toLowerCase().trim();
$: data = { disabled, textValue } as MenuItemData;
onMount(async () => {
await tick();
$api?.registerItem(id, data);
});
onMount(async () => {
await tick();
$api?.registerItem(id, data);
});
onDestroy(() => {
$api.unregisterItem(id);
});
onDestroy(() => {
$api.unregisterItem(id);
});
afterUpdate(async () => {
if ($api.menuState !== MenuStates.Open) return;
if (!active) return;
await tick();
elementRef?.scrollIntoView?.({ block: "nearest" });
});
afterUpdate(async () => {
if ($api.menuState !== MenuStates.Open) return;
if (!active) return;
await tick();
elementRef?.scrollIntoView?.({ block: "nearest" });
});
async function handleClick(event: MouseEvent) {
if (disabled) return event.preventDefault();
$api.closeMenu();
$buttonStore?.focus({ preventScroll: true });
}
async function handleClick(event: MouseEvent) {
if (disabled) return event.preventDefault();
$api.closeMenu();
$buttonStore?.focus({ preventScroll: true });
}
function handleFocus() {
if (disabled) return $api.goToItem(Focus.Nothing);
$api.goToItem(Focus.Specific, id);
}
function handleFocus() {
if (disabled) return $api.goToItem(Focus.Nothing);
$api.goToItem(Focus.Specific, id);
}
function handleMove() {
if (disabled) return;
if (active) return;
$api.goToItem(Focus.Specific, id);
}
function handleMove() {
if (disabled) return;
if (active) return;
$api.goToItem(Focus.Specific, id);
}
function handleLeave() {
if (disabled) return;
if (!active) return;
$api.goToItem(Focus.Nothing);
}
function handleLeave() {
if (disabled) return;
if (!active) return;
$api.goToItem(Focus.Nothing);
}
$: propsWeControl = {
id,
role: "menuitem",
tabIndex: disabled === true ? undefined : -1,
"aria-disabled": disabled === true ? true : undefined,
};
$: propsWeControl = {
id,
role: "menuitem",
tabIndex: disabled === true ? undefined : -1,
"aria-disabled": disabled === true ? true : undefined,
};
</script>
<div
{...{ ...$$restProps, ...propsWeControl }}
bind:this={elementRef}
on:click={handleClick}
on:focus={handleFocus}
on:pointermove={handleMove}
on:mousemove={handleMove}
on:pointerleave={handleLeave}
on:mouseleave={handleLeave}
{...{ ...$$restProps, ...propsWeControl }}
bind:this={elementRef}
on:click={handleClick}
on:focus={handleFocus}
on:pointermove={handleMove}
on:mousemove={handleMove}
on:pointerleave={handleLeave}
on:mouseleave={handleLeave}
>
<slot {active} {disabled} />
<slot {active} {disabled} />
</div>