Fix a few more misc issues (TS errors, dupe files)

This commit is contained in:
Ryan Gossiaux
2021-12-13 18:31:08 -08:00
parent 50478bd999
commit a12b64faed
3 changed files with 2 additions and 37 deletions

View File

@@ -3,7 +3,7 @@
import { useId } from "$lib/hooks/use-id"; import { useId } from "$lib/hooks/use-id";
import { Keys } from "$lib/utils/keyboard"; import { Keys } from "$lib/utils/keyboard";
import { Focus } from "$lib/utils/calculate-active-index"; import { Focus } from "$lib/utils/calculate-active-index";
import { treeWalker } from "$lib/utils/tree-walker"; import { treeWalker } from "$lib/hooks/use-tree-walker";
import { State } from "$lib/internal/open-closed"; import { State } from "$lib/internal/open-closed";
import { getContext, tick } from "svelte"; import { getContext, tick } from "svelte";
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";

View File

@@ -23,11 +23,11 @@ export function treeWalker({
let acceptNode = Object.assign((node: HTMLElement) => accept(node), { let acceptNode = Object.assign((node: HTMLElement) => accept(node), {
acceptNode: accept, acceptNode: accept,
}); });
// @ts-ignore-error Typescript bug thinks this can only have 3 args
let walker = document.createTreeWalker( let walker = document.createTreeWalker(
root, root,
NodeFilter.SHOW_ELEMENT, NodeFilter.SHOW_ELEMENT,
acceptNode, acceptNode,
// @ts-ignore-error Typescript bug thinks this can only have 3 args
false false
); );

View File

@@ -1,35 +0,0 @@
type AcceptNode = (
node: HTMLElement
) =>
| typeof NodeFilter.FILTER_ACCEPT
| typeof NodeFilter.FILTER_SKIP
| typeof NodeFilter.FILTER_REJECT;
export function treeWalker({
container,
accept,
walk,
enabled,
}: {
container: HTMLElement | null;
accept: AcceptNode;
walk(node: HTMLElement): void;
enabled?: boolean;
}) {
let root = container;
if (!root) return;
if (enabled !== undefined && !enabled) return;
let acceptNode = Object.assign((node: HTMLElement) => accept(node), {
acceptNode: accept,
});
// @ts-ignore-error Typescript bug thinks this can only have 3 args
let walker = document.createTreeWalker(
root,
NodeFilter.SHOW_ELEMENT,
acceptNode,
false
);
while (walker.nextNode()) walk(walker.currentNode as HTMLElement);
}