import { Emitter, EventType } from 'mitt'; import { Thing, Handler, Runner, Callback, Any } from './types'; export declare const SLOW_TIME_MILLIS: number; export declare const NO_PAYLOAD: unique symbol; export declare const emitter: Emitter; export declare const NetworkEvents: { error: string; offline: string; online: string; leaving: string; loading: string; loaded: string; unsaved: string; saved: string; querying: string; queried: string; mutating: string; mutated: string; authenticating: string; authenticated: string; unauthenticated: string; slow: string; }; export declare const status: { [key in NetworkEvent]: boolean; } & { pending: number; requests: number; queries: number; mutations: number; }; export type Events = Record; export type NetworkEvent = keyof typeof NetworkEvents; export declare function emit(type: E, payload?: T): void; export declare function off(type: E, fn: Handler): void; /** * Registers a custom event listener on the specified event, if local is true (default), * the listener will be removed when the component wherein this is called during creation is unmounted. * * @param event - The event to listen for * @param fn - The function to run when the event is emitted * @param local - Whether to listen only during current component mounting (default is true) */ export declare function on(event: E, fn: Handler, local?: boolean): void; /** * Registers window event listener on component mount and removes it on unmount, unless local is true. * Components should use this to ensure no memory leaks happens due to event listeners. * * @param type The type of window event to listen for * @param fn The function to run when the event is emitted * @param local Whether to add/remove this on current component mount/unmount (default is true) */ export declare function onWindow(type: T, fn: Handler, local?: boolean): void; export declare function isBackspace(event: KeyboardEvent): boolean; export declare function isEnter(event: KeyboardEvent): boolean; export declare function isEscape(event: KeyboardEvent): boolean; export declare function isTab(event: KeyboardEvent): boolean; export declare function isShift(event: KeyboardEvent): boolean; export declare function isCtrl(event: KeyboardEvent): boolean; export declare function isMeta(event: KeyboardEvent): boolean; export declare function isArrow(event: KeyboardEvent): boolean; export declare function isControl(event: KeyboardEvent): boolean; export declare function isSpace(event: KeyboardEvent): boolean; export declare function isAlpha(event: KeyboardEvent, noWhitespace?: boolean): boolean; /** * Tests whether the key is a number, comma, period, or hyphen, unless onlyPositiveInteger is true. * If onlyPositiveInteger is true, only numbers are allowed. Commas, periods, and hyphens are not * allowed twice in the same event target value. * * @param event - The keyboard event to test * @param onlyPositiveInteger - Whether to only allow positive integers * @returns - True if the key is a number, comma, period, or hyphen */ export declare function isNumeric(event: KeyboardEvent, onlyPositiveInteger?: boolean): boolean; /** * Tests whether the key is a letter or number. Comma, period, or hyphen pass if onlyPositiveInteger * is true. If noWhitespace is true, spaces are not allowed. * * @param event - The keyboard event to test * @param onlyPositiveInteger - Whether to only allow positive integers (default is false) * @param noWhitespace - Whether to allow spaces (default is true) * @returns - true if the key is alphanumeric */ export declare function isAlphaNumeric(event: KeyboardEvent, onlyPositiveInteger?: boolean, noWhitespace?: boolean): boolean; /** * Blocks the event if it is not a control key or does not pass the validation test. * * @param event The event to test * @param validate The test to run * @param allowControls Whether to allow control keys (default is true) */ export declare function keyBlocker(event: KeyboardEvent, validate: (event: KeyboardEvent) => boolean, allowControls?: boolean): void; export declare function onlyNumeric(event: KeyboardEvent): void; export declare function onlyAlphaNumeric(event: KeyboardEvent): void; /** * Registers keyboard event listener on the window in a way that is removed when the component * is unmounted to ensure there are no memory leaks or listening happening when the component * is not mounted. * * @param key The key or array of keys being listened for * @param handler The function to run when conditions are satisfied * @param ctrlOnly Whether to only count when ctrl/cmd is pressed (default is false) * @param type The type of key event to listen for (default is keydown) */ export declare function onKey(key: string | string[], handler: Handler, ctrlOnly?: boolean, type?: "keyup" | "keydown" | "keypress"): void; /** * Registers mouse event listener on the window in a way that is removed when the component * is unmounted to ensure there are no memory leaks or listening happening when the component * is not mounted and support checking e.target.closest(selector(s)) to see if it's a mouse * event we actually want to respond to. * * @param selector The selector for elements to be considered "in" or "out" for the click * @param handler The function to run when conditions are satisfied * @param onMouseIn Whether to only count when mouse event is within the selector(s) (default is true) * @param type The type of mouse event to listen for (default is mousedown) */ export declare function onMouse(selector: string | string[] | undefined, handler: Handler, onMouseIn?: boolean, type?: "mousedown" | "mouseup" | "click"): void; /** * Registers handlers for mousedown (and keyup) to tell when a user has left * an area of the DOM and run a function when they do. This only registers onMounted * and unregisters the handlers onUnmounted, so it will only work in a Vue component * context. * * @param selector The query selector for elements considered "inside" * @param run The function to run when a click happens "outside" or Esc is hit * @param onEscToo Defaults to true, treats Esc key as leaving also */ export declare function onLeave(selector: string | string[], run: Runner, onEscToo?: boolean): void; /** * Registers a listener for the online event and runs the listener immediately if eager is true. * * @param listener - The function to run if/when the user comes online * @param eager - Whether to run the listener immediately if the user is already online */ export declare function onOnline(listener: (this: Window, e: Event) => Any, eager?: boolean): void; /** * Registers a listener for the offline event and runs the listener immediately if eager is true. * * @param listener - The function to run if/when the user goes offline * @param eager - Whether to run the listener immediately if the user is already offline */ export declare function onOffline(listener: (this: Window, e: Event) => Any, eager?: boolean): void; /** * Toggles the specified network status class on the body element and sets the network status. * * @param type - The network status to toggle * @param force - Whether to force the status to true or false */ export declare function toggleNetworkStatus(type: string, force?: boolean): void; /** * Waits for the user to come online, or resolves immediately if they are already online. * If the user does not come online within 5 minutes, the promise will reject. * * @returns - Promise that resolves when the user is/comes online */ export declare function isOnline(): Promise; /** * Runs a callback before the user leaves the page, if the callback returns true * or there are unsaved changes, the user will be prompted to confirm they want to leave. * * @param block - The callback to run before the user leaves */ export declare function beforeUnload(block?: Callback): void;