forked from Zerthox/betterdiscord-types
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
742 additions
and
705 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface AddonAPI<T> { | ||
folder: string; | ||
get(idOrFile: string): T; | ||
getAll(): T[]; | ||
enable(idOrFile: string): void; | ||
disable(idOrFile: string): void; | ||
isEnabled(idOrFile: string): boolean; | ||
reload(idOrFile: string): void; | ||
toggle(idOrFile: string): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Cancel } from "."; | ||
|
||
export interface ContextMenu extends ContextMenuComponents { | ||
/** | ||
* Allows you to patch a given context menu. | ||
* Acts as a wrapper around the `Patcher`. | ||
*/ | ||
patch(navId: string, callback: ContextMenuCallback): Cancel; | ||
|
||
/* Allows you to remove the patch added to a given context menu. */ | ||
unpatch(navId: string, callback: ContextMenuCallback): Cancel; | ||
|
||
/** | ||
* Builds a single menu item. | ||
* | ||
* The only prop shown here is the type, the rest should match the actual component being built. | ||
* View those to see what options exist for each, they often have less in common than you might think. | ||
*/ | ||
buildItem(props: ContextMenuItemProps): React.ReactElement; | ||
|
||
/** | ||
* Creates the all the items **and groups** of a context menu recursively. | ||
* | ||
* There is no hard limit to the number of groups within groups or number of items in a menu. | ||
*/ | ||
buildMenuChildren(setup: ContextMenuSetup): React.ReactElement; | ||
|
||
/** | ||
* Creates the menu *component* including the wrapping `ContextMenu`. | ||
* Calls {@link ContextMenu.buildMenuChildren} under the covers. | ||
*/ | ||
buildMenu(setup: ContextMenuSetup): React.FunctionComponent<any>; | ||
|
||
/** Function that allows you to open an entire context menu. */ | ||
open( | ||
event: MouseEvent, | ||
menuComponent: React.ComponentType<any>, | ||
config: ContextMenuConfig, | ||
): any; | ||
|
||
/** Closes the current opened context menu immediately. */ | ||
close(): any; | ||
} | ||
|
||
export type ContextMenuCallback = ( | ||
tree: React.ReactElement, | ||
) => React.ReactElement; | ||
|
||
export interface ContextMenuItemProps extends Record<string, any> { | ||
type?: | ||
| "text" | ||
| "submenu" | ||
| "toggle" | ||
| "radio" | ||
| "control" | ||
| "custom" | ||
| "separator"; | ||
} | ||
|
||
export interface ContextMenuGroupProps { | ||
type: "group"; | ||
items: ContextMenuItemProps[]; | ||
} | ||
|
||
export type ContextMenuSetup = (ContextMenuItemProps | ContextMenuGroupProps)[]; | ||
|
||
export interface ContextMenuConfig { | ||
position?: "right" | "left"; | ||
align?: "top" | "bottom"; | ||
onClose?: (...args: any) => void; | ||
noBlurEvent?: boolean; | ||
} | ||
|
||
export interface ContextMenuComponents { | ||
Menu: React.ComponentType<any>; | ||
Group: React.ComponentType<any>; | ||
Item: React.ComponentType<any>; | ||
Separator: React.ComponentType<any>; | ||
CheckboxItem: React.ComponentType<any>; | ||
ControlItem: React.ComponentType<any>; | ||
RadioItem: React.ComponentType<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface Data { | ||
/** Saves JSON-serializable data. */ | ||
save(pluginName: string, key: string, data: any): void; | ||
|
||
/** Loads previously stored data. */ | ||
load(pluginName: string, key: string): any; | ||
|
||
/** Deletes a piece of stored data. This is different than saving as `null` or `undefined`. */ | ||
delete(pluginName: string, key: string): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Cancel } from "."; | ||
|
||
export interface DOM { | ||
/** Current width of the user's screen. */ | ||
get screenHeight(): number; | ||
|
||
/** Current height of the user's screen. */ | ||
get screenWidth(): number; | ||
|
||
/** Adds a `<style>` to the document with the given ID. */ | ||
addStyle(id: string, css: string): void; | ||
|
||
/** Removes a `<style>` from the document corresponding to the given ID. */ | ||
removeStyle(id: string): void; | ||
|
||
/** Adds a listener for when the node is removed from the document body. */ | ||
onRemoved(node: HTMLElement, callback: () => void): Cancel; | ||
|
||
/** Utility to help smoothly animate using JavaScript. */ | ||
animate( | ||
update: (progress: number) => void, | ||
duration: number, | ||
options?: AnimateOptions, | ||
): void; | ||
|
||
/** | ||
* Utility function to make creating DOM elements easier. | ||
* Acts similarly to `React.createElement`. | ||
*/ | ||
createElement( | ||
tag: string, | ||
options?: CreateElementOptions, | ||
child?: HTMLElement, | ||
): HTMLElement; | ||
|
||
/** | ||
* Parses a string of HTML and returns the results. | ||
* If the second parameter is `true`, the parsed HTML will be returned as a document fragment. | ||
* This is extremely useful if you have a list of elements at the top level, they can then be appended all at once to another node. | ||
* | ||
* If the second parameter is `false`, then the return value will be the list of parsed nodes | ||
* and there were multiple top level nodes, otherwise the single node is returned. | ||
*/ | ||
parseHTML<F extends boolean = false>( | ||
html: string, | ||
fragment?: F, | ||
): F extends true ? DocumentFragment : NodeList | HTMLElement; | ||
} | ||
|
||
export interface AnimateOptions { | ||
timing?: (timeFraction: number) => number; | ||
} | ||
|
||
export interface CreateElementOptions { | ||
id?: string; | ||
className?: string; | ||
target?: HTMLElement; | ||
} |
Oops, something went wrong.