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

@@ -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);
}