import type { Fiber } from "react-reconciler"; import type { Jsonifiable } from "type-fest"; import type { AnyFunction } from "../types"; import { SettingsManager } from "./apis/settings"; /** * Loads a stylesheet into the document * @param path Path to the stylesheet * @returns Link element */ export declare const loadStyleSheet: (path: string) => HTMLLinkElement; /** * Wait for an element to be added to the DOM * @param selector Element selector */ export declare function waitFor(selector: string): Promise; /** * Async sleep function */ export declare function sleep(ms: number): Promise; /** * Get the React instance of an element * @param element Element to get the React instance of * @returns React instance * @throws If the React instance could not be found */ export declare function getReactInstance(element: Element): Fiber | null; /** * Get the React owner instance of an element * @param element Element to get the React owner instance of * @returns React owner instance * @throws If the React owner instance could not be found */ export declare function getOwnerInstance(element: Element): React.Component & Record; /** * Force updates a rendered React component by its DOM selector * @param selector The DOM selector to force update * @param all Whether all elements matching that selector should be force updated */ export declare function forceUpdateElement(selector: string, all?: boolean): void; /** * If the user is not in the server, join it. Otherwise, go to the server. * @param invite Invite code (eg "replugged") */ export declare function goToOrJoinServer(invite: string): Promise; export declare function openExternal(url: string): Promise; type InputType = T | React.ChangeEvent | (Record & { value?: T; checked?: T; }); type ObjectPath = T extends Record ? { [K in keyof T]-?: K extends string ? `${K}` | `${K}.${ObjectPath}` : never; }[keyof T] : never; type ValueAtPath = P extends `${infer K}.${infer NestedKey}` ? K extends keyof T ? ValueAtPath, NestedKey> : undefined : P extends keyof T ? NonNullable : undefined; type InferredPath, D extends keyof T, K extends Extract, P extends ObjectPath, F extends ValueAtPath | T[K] | undefined> = P extends `${K}.${string}` ? NonNullable> : P extends D ? NonNullable : F extends null | undefined ? T[P] | undefined : NonNullable | F; /** * React hook for managing settings. * @param settings Settings manager to use. * @param key Key of the setting to manage. * @param fallback Value to return if the key does not already exist. * @returns A tuple containing the current value of the setting, and a function to set the value. Works like `useState`. * @example * ```tsx * import { components, settings } from "replugged"; * const { TextInput } = components; * * const cfg = settings.init<{ hello: string }>("dev.replugged.Example"); * * export function Settings() { * return ; * } * ``` */ export declare function useSetting, Defaults extends keyof Settings, PathKey extends Extract, Fallback extends ValueAtPath | Settings[PathKey] | undefined, Path extends ObjectPath, Value extends InferredPath>(settings: SettingsManager, key: Path, fallback?: Fallback): { value: Value; onChange: (newValue: InputType> | InputType) => void; }; export declare function useSettingArray, Defaults extends keyof Settings, PathKey extends Extract, Fallback extends ValueAtPath | Settings[PathKey] | undefined, Path extends ObjectPath, Value extends InferredPath>(settings: SettingsManager, key: Path, fallback?: Fallback): [ Value, (newValue: InputType> | InputType) => void ]; type UnionToIntersection = (U extends never ? never : (k: U) => void) extends (k: infer I) => void ? I & { all: () => I; } : never; type ObjectType = Record; type ExtractObjectType = O extends Array ? UnionToIntersection : never; export declare function virtualMerge(...objects: O): ExtractObjectType; export type Tree = Record | null; type TreeFilter = string | ((tree: Tree) => boolean); /** * All credit goes to rauenzi for writing up this implementation. * You can find the original source here: * * * @remarks Used mainly in findInReactTree */ export declare function findInTree(tree: Tree, searchFilter: TreeFilter, args?: { walkable?: string[]; ignore?: string[]; maxRecursion: number; }): Tree | null | undefined; export type ReactTree = (Tree & React.ReactElement) | Tree; type ReactTreeFilter = string | ((reactTree: ReactTree) => boolean); /** * Find the component you are looking for in a tree, recursively. * * @param tree The tree to search through * @param searchFilter The filter. Either a string or a function. Should be unique * @param maxRecursion The max depth. Avoids call stack exceeded error. * @returns The component you are looking for */ export declare function findInReactTree(tree: ReactTree, searchFilter: ReactTreeFilter, maxRecursion?: number): ReactTree | null | undefined; type MethodNames = { [K in keyof T]: T[K] extends AnyFunction ? K : never; }[keyof T]; type BoundMethodMap = { [K in MethodNames]: T[K]; }; /** * Creates a new object containing all methods from the prototype of the given instance, * with each method bound to the original instance. * * @template T The type of the instance object * @param instance The object instance whose methods should be bound * @returns A new object containing all prototype methods bound to the original instance */ export declare function getBoundMethods(instance: T): BoundMethodMap; export declare const mapClassNames: >(object: T) => T; export {};