88217c5e7d
* Implement a first version of WithFloating and Portal * Add outside slot for Portal * Execute computePosition from WithFloating * Set up a first example of new WithFloating with the Latex menu * Use autoUpdate in WithFloating * Create sveltelib/position * Add event-store * Use event-store in close-on-click * Implement subscribeToUpdates * Introduce sass/elevation * Split close-on-click to closing-click and subscribe-trigger * Have closing-* stores return a symbol - This way they act more of an EventEmitter than a store * Allow passing show store * Remove styling on float on updatePosition removal * Implement a nice border for dropdowns * Apply different border and box-shadow to Popover in dark/light theme * Fix Ctrl+Shift+T not working * Satisfy formatters and tests * Add copyright header * move copyright header to top (dae)
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
export type EventTargetToMap<A extends EventTarget> = A extends HTMLElement
|
|
? HTMLElementEventMap
|
|
: A extends Document
|
|
? DocumentEventMap
|
|
: A extends Window
|
|
? WindowEventMap
|
|
: A extends FileReader
|
|
? FileReaderEventMap
|
|
: A extends Element
|
|
? ElementEventMap
|
|
: A extends Animation
|
|
? AnimationEventMap
|
|
: A extends EventSource
|
|
? EventSourceEventMap
|
|
: A extends AbortSignal
|
|
? AbortSignalEventMap
|
|
: A extends AbstractWorker
|
|
? AbstractWorkerEventMap
|
|
: never;
|
|
|
|
export function on<T extends EventTarget, K extends keyof EventTargetToMap<T>>(
|
|
target: T,
|
|
eventType: Exclude<K, symbol | number>,
|
|
handler: (this: T, event: EventTargetToMap<T>[K]) => void,
|
|
options?: AddEventListenerOptions,
|
|
): () => void {
|
|
target.addEventListener(eventType, handler as EventListener, options);
|
|
return () =>
|
|
target.removeEventListener(eventType, handler as EventListener, options);
|
|
}
|
|
|
|
export function preventDefault(event: Event): void {
|
|
event.preventDefault();
|
|
}
|