Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

utils.ts

25 lines696 Bytes

1/// <reference lib="dom" />
2import type { LitElement } from 'lit'
3​
4const registered = new Set<string>()
5const mountedElements = new Set<LitElement>()
6​
7export function defineOnce(name: string, ctor: CustomElementConstructor) {
8 if (!registered.has(name) && !window.customElements.get(name)) {
9 window.customElements.define(name, ctor)
10 registered.add(name)
11 }
13​
14export async function mount<T extends LitElement>(tag: string): Promise<T> {
15 const el = document.createElement(tag) as T
16 document.body.appendChild(el)
17 await el.updateComplete
18 mountedElements.add(el)
19 return el
21​
22export function cleanup() {
23 for (const el of mountedElements) el.remove()
24 mountedElements.clear()