Switch to vite and preact

This commit is contained in:
Misode
2021-06-23 20:44:28 +02:00
parent e551b7ef75
commit 09c851914f
89 changed files with 6398 additions and 15531 deletions

36
src/app/schema/Mounter.ts Normal file
View File

@@ -0,0 +1,36 @@
import { hexId } from '../Utils'
export class Mounter {
private registry: { [id: string]: (el: Element) => void } = {}
register(callback: (el: Element) => void): string {
const id = hexId()
this.registry[id] = callback
return id
}
on(type: string, callback: (el: Element) => void): string {
return this.register(el => {
el.addEventListener(type, evt => {
callback(el)
evt.stopPropagation()
})
})
}
onChange(callback: (el: Element) => void): string {
return this.on('change', callback)
}
onClick(callback: (el: Element) => void): string {
return this.on('click', callback)
}
mounted(el: Element): void {
el.querySelectorAll('[data-id]').forEach(el => {
const id = el.getAttribute('data-id')!
this.registry[id]?.(el)
})
this.registry = {}
}
}